compileasset

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssetRef

func AssetRef(resolvedURL string, asset Asset, linksOnly bool) string

AssetRef returns either the resolved URL (linksOnly) or a data URI for embedded assets.

func BackgroundColorFromStyle

func BackgroundColorFromStyle(style psrt.Style) string

BackgroundColorFromStyle extracts a CSS color from page style background keys.

func BorderRadiusCSS

func BorderRadiusCSS(c BorderRadiusCorners) string

BorderRadiusCSS returns border-radius shorthand or longhands for CSS.

func BorderRadiusHasValue

func BorderRadiusHasValue(c BorderRadiusCorners) bool

BorderRadiusHasValue reports whether any corner has a positive radius.

func BorderRadiusIsUniform

func BorderRadiusIsUniform(c BorderRadiusCorners) bool

BorderRadiusIsUniform reports whether all corners share the same radius.

func BorderRadiusNeedsInnerBoxDecoration

func BorderRadiusNeedsInnerBoxDecoration(c BorderRadiusCorners) bool

BorderRadiusNeedsInnerBoxDecoration is true when the SVG background rect cannot represent the corner radii (e.g. only bottom corners rounded). In that case background + radius must live on the foreignObject inner div via CSS.

func CSSBoxFromStyleJSON

func CSSBoxFromStyleJSON(style psrt.Style) string

CSSBoxFromStyleJSON returns CSS declarations for text box decoration (background, border, etc.).

func CSSBoxFromStyleJSONForCanvas

func CSSBoxFromStyleJSONForCanvas(style psrt.Style, canvasW, canvasH int, fontPx float64) string

CSSBoxFromStyleJSONForCanvas emits full box CSS (background, border, radius, padding) with % resolved to px.

func CSSBoxFromStyleJSONNoBackground

func CSSBoxFromStyleJSONNoBackground(style psrt.Style) string

CSSBoxFromStyleJSONNoBackground returns box CSS without background (use SVG rect instead).

func CSSBoxFromStyleJSONNoBackgroundForCanvas

func CSSBoxFromStyleJSONNoBackgroundForCanvas(style psrt.Style, canvasW, canvasH int, fontPx float64) string

CSSBoxFromStyleJSONNoBackgroundForCanvas emits box CSS with % lengths resolved to px.

func CSSFromStyleJSON

func CSSFromStyleJSON(raw []byte) string

CSSFromStyleJSON converts PSRT style JSON to CSS declarations (no selector).

func CollectAssetURLs

func CollectAssetURLs(doc psrt.Document) []string

CollectAssetURLs gathers unique URLs in deterministic order: pages in order (image then text ImageRefs), then document fonts.

func EncodeDataURI

func EncodeDataURI(mime string, b []byte) string

EncodeDataURI returns a data URI for the given MIME type and bytes.

func ExpandFontURLsForFetch

func ExpandFontURLsForFetch(ctx context.Context, client *http.Client, fontURLs []string) (fetchURLs []string, assetKeys map[string]string, err error)

ExpandFontURLsForFetch replaces Google Fonts CSS links with downloadable woff2 URLs. assetKeys maps each fetch URL to the original document font URL (for assets map lookup).

func ExplicitHeightPx

func ExplicitHeightPx(style psrt.Style, canvasW, canvasH int, fontPx float64) (int, bool)

ExplicitHeightPx returns the outer box height in pixels from style "height" when set.

func FetchFontAssets

func FetchFontAssets(ctx context.Context, client *http.Client, fontURLs []string) (map[string]Asset, error)

FetchFontAssets downloads font files; map keys are the original $FONTS URLs from the document.

func FetchURLs

func FetchURLs(client *http.Client, urls []string) (map[string]Asset, error)

FetchURLs downloads each URL via GET with client. Fail-fast on first non-success.

func FontFamilyNameForURL

func FontFamilyNameForURL(fontURL string, index int) string

FontFamilyNameForURL returns the CSS font-family name for a $FONTS entry.

func FontFetchURL

func FontFetchURL(ctx context.Context, client *http.Client, fontURL string) (string, error)

FontFetchURL returns the URL to download for a document font entry (resolves Google CSS to woff2).

func FontSrcURL

func FontSrcURL(fontURL string, asset Asset, linksOnly bool) string

FontSrcURL returns a CSS url(...) value for @font-face src.

func FontWeightIsBold

func FontWeightIsBold(style psrt.Style) bool

FontWeightIsBold reports whether the style requests a bold or semibold weight.

func FormatFloatCSS

func FormatFloatCSS(v float64) string

FormatFloatCSS formats a float for use in CSS.

func IsAssetReference

func IsAssetReference(raw string) bool

IsAssetReference reports whether raw is an http(s) URL or a local file reference.

func IsGoogleFontsCSSURL

func IsGoogleFontsCSSURL(raw string) bool

IsGoogleFontsCSSURL reports Google Fonts CSS API links (not direct .woff2 files).

func IsLocalAssetRef

func IsLocalAssetRef(raw string) bool

IsLocalAssetRef reports file:// URLs and filesystem paths (not http).

func LineHeightMultiplier

func LineHeightMultiplier(style psrt.Style, fontSizePx float64) float64

LineHeightMultiplier returns a unitless line-height factor for layout (default 1.2, matching compilehtml).

func LooksLikeHTTPURL

func LooksLikeHTTPURL(raw string) bool

LooksLikeHTTPURL reports whether raw is an http(s) URL.

func MergeFontAssets

func MergeFontAssets(assets map[string]Asset, fonts map[string]Asset)

MergeFontAssets copies font assets into the main assets map (document font URL keys).

func ParseGoogleFontFamilies

func ParseGoogleFontFamilies(cssURL string) []string

ParseGoogleFontFamilies extracts family names from a Google Fonts CSS API URL.

func PartitionAssetURLs

func PartitionAssetURLs(fonts, urls []string) (pageURLs, fontURLs []string)

PartitionAssetURLs splits collected URLs into page/image refs vs document font entries.

func ResolveAssetPath

func ResolveAssetPath(raw string) (string, error)

ResolveAssetPath turns a PSRT asset reference into an absolute filesystem path.

func ResolveAssetPathRelative

func ResolveAssetPathRelative(raw, baseDir string) (string, error)

ResolveAssetPathRelative resolves raw against baseDir when raw is not absolute.

func ResolveAssetReference

func ResolveAssetReference(raw string, consts map[string]string) string

ResolveAssetReference expands @name@ placeholders in raw using consts, then trims.

func ResolveGoogleFontsWoff2URLs

func ResolveGoogleFontsWoff2URLs(ctx context.Context, client *http.Client, cssURL string) ([]string, error)

ResolveGoogleFontsWoff2URLs fetches the CSS API response and returns woff2 file URLs to download.

func SanitizeCSSValue

func SanitizeCSSValue(s string) string

SanitizeCSSValue strips characters that break CSS declarations.

func StyleJSONWithoutBackground

func StyleJSONWithoutBackground(style psrt.Style) []byte

StyleJSONWithoutBackground returns style JSON without box/background keys (typography only).

func StyleJSONWithoutBox

func StyleJSONWithoutBox(style psrt.Style) []byte

StyleJSONWithoutBox returns typography-only style JSON (no box properties).

func StyleResolvedForCanvas

func StyleResolvedForCanvas(style psrt.Style, canvasW, canvasH int, fontPx float64) psrt.Style

StyleResolvedForCanvas applies percent handlers (padding, border-width, etc.) for render-time CSS/layout.

func TextAlignFromStyle

func TextAlignFromStyle(style psrt.Style) string

TextAlignFromStyle returns the text-align value from style JSON, if any.

func TextBlockDisplayCSS

func TextBlockDisplayCSS(style psrt.Style) string

TextBlockDisplayCSS returns display/flex rules for SVG foreignObject inner blocks. foreignObject renderers often ignore % padding and block text-align without a flex formatting context.

func TextLayerNeedsComputedHeight

func TextLayerNeedsComputedHeight(style psrt.Style, canvasW, canvasH int, textSize float64) bool

TextLayerNeedsComputedHeight reports whether a text layer needs an explicit outer height (explicit height in style or vertical padding/border) for flex vertical alignment to apply.

func VerticalAlignFromStyle

func VerticalAlignFromStyle(style psrt.Style) string

VerticalAlignFromStyle maps align-items / vertical-align to a flex justify-content keyword.

Types

type Asset

type Asset struct {
	Bytes []byte
	MIME  string
}

Asset holds downloaded bytes with a MIME type suitable for data URIs.

func ReadAssetFile

func ReadAssetFile(path string) (Asset, error)

ReadAssetFile reads a local file and detects MIME type.

type BorderRadiusCorners

type BorderRadiusCorners struct {
	TopLeft, TopRight, BottomRight, BottomLeft float64
}

BorderRadiusCorners holds four corner radii in pixels (after % resolution when applicable).

func ParseBorderRadiusCorners

func ParseBorderRadiusCorners(style psrt.Style, canvasW, canvasH int, fontPx float64) BorderRadiusCorners

ParseBorderRadiusCorners reads border-radius from style (resolved for canvas when needed).

type PaddingInsets

type PaddingInsets struct {
	Top, Right, Bottom, Left float64
}

PaddingInsets holds resolved padding in pixels (top, right, bottom, left).

func ParseBorderInsets

func ParseBorderInsets(style psrt.Style, refFontPx float64) PaddingInsets

ParseBorderInsets resolves uniform border width in pixels for layout expansion.

func ParsePaddingInsets

func ParsePaddingInsets(style psrt.Style, refFontPx float64) PaddingInsets

ParsePaddingInsets resolves padding from PSRT style JSON (px, em).

func TextBoxInsets

func TextBoxInsets(style psrt.Style, refFontPx float64) PaddingInsets

TextBoxInsets combines padding and border for foreignObject sizing.

func TextBoxInsetsForCanvas

func TextBoxInsetsForCanvas(style psrt.Style, refFontPx float64, canvasW, canvasH int) PaddingInsets

TextBoxInsetsForCanvas resolves % padding/border against canvas size, then returns pixel insets.

func (PaddingInsets) Add

func (PaddingInsets) Horizontal

func (p PaddingInsets) Horizontal() float64

func (PaddingInsets) Vertical

func (p PaddingInsets) Vertical() float64

type TextBox

type TextBox struct {
	Background   string
	BorderCSS    string
	BorderWidth  string
	BorderColor  string
	RadiusCSS    string
	RadiusPx     float64
	BoxShadowCSS string
	PaddingCSS   string
	HasRect      bool
}

TextBox describes background/border decoration for a text block.

func ParseTextBox

func ParseTextBox(style psrt.Style) TextBox

ParseTextBox reads box-related properties from PSRT style JSON (camelCase or kebab-case).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL