styleadapter

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: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TypeKey = "__type__"

	TypeMotionDiv     = "div"
	TypeSpan          = "span"
	TypeRect          = "rect"
	TypePath          = "path"
	TypeForeignObject = "foreignObject"
	TypeDiv           = "div" // inner XHTML inside foreignObject
	TypeFilter        = "filter"
	TypeMask          = "mask"
	TypeG             = "g"
)
View Source
const (
	KeyPosition      = "position"
	KeyLeft          = "left"
	KeyTop           = "top"
	KeyWidth         = "width"
	KeyHeight        = "height"
	KeyBoxSizing     = "boxSizing"
	KeyPadding       = "padding"
	KeyPaddingTop    = "paddingTop"
	KeyPaddingRight  = "paddingRight"
	KeyPaddingBottom = "paddingBottom"
	KeyPaddingLeft   = "paddingLeft"

	KeyBorder       = "border"
	KeyBorderTop    = "borderTop"
	KeyBorderRight  = "borderRight"
	KeyBorderBottom = "borderBottom"
	KeyBorderLeft   = "borderLeft"
	KeyBorderWidth  = "borderWidth"
	KeyBorderStyle  = "borderStyle"
	KeyBorderColor  = "borderColor"

	KeyBorderRadius            = "borderRadius"
	KeyBorderTopLeftRadius     = "borderTopLeftRadius"
	KeyBorderTopRightRadius    = "borderTopRightRadius"
	KeyBorderBottomRightRadius = "borderBottomRightRadius"
	KeyBorderBottomLeftRadius  = "borderBottomLeftRadius"

	KeyBoxShadow  = "boxShadow"
	KeyTextShadow = "textShadow"
	KeyGlow       = "glow"
	KeyBevel      = "bevel"
	KeyBlur       = "blur"
	KeyBlurLeft   = "blurLeft"
	KeyBlurRight  = "blurRight"
	KeyBlurTop    = "blurTop"
	KeyBlurBottom = "blurBottom"

	KeyBackground = "background"
	KeyColor      = "color"

	KeyTextAlign          = "textAlign"
	KeyAlignItems         = "alignItems"
	KeyTextDecoration     = "textDecoration"
	KeyTextDecorationLine = "textDecorationLine"
	KeyLetterSpacing      = "letterSpacing"
	KeyLineHeight         = "lineHeight"
	KeyWordSpacing        = "wordSpacing"
	KeyWhiteSpace         = "whiteSpace"
	KeyTextTransform      = "textTransform"
	KeyTextIndent         = "textIndent"
	KeyTextOverflow       = "textOverflow"
	KeyOpacity            = "opacity"

	KeyStroke      = "stroke"
	KeyStrokeWidth = "strokeWidth"
	KeyStrokeColor = "strokeColor"

	KeyTransform       = "transform"
	KeyTransformOrigin = "transformOrigin"
	KeyTranslate       = "translate"
	KeyRotate          = "rotate"
	KeyScale           = "scale"
	KeySkew            = "skew"
	KeyMatrix          = "matrix"

	KeyFontFamily  = "fontFamily"
	KeyFontSize    = "fontSize"
	KeyFontWeight  = "fontWeight"
	KeyFontStyle   = "fontStyle"
	KeyFontVariant = "fontVariant"
	KeyFontStretch = "fontStretch"
)

Canonical property name constants (camelCase).

Variables

This section is empty.

Functions

func FilterFragmentToSVG

func FilterFragmentToSVG(f StyleFragment) string

FilterFragmentToSVG emits a filter element from a filter fragment.

func FilterStyleMap

func FilterStyleMap(m map[string]json.RawMessage) map[string]json.RawMessage

FilterStyleMap removes keys that were not effectively passed.

func FragmentCSS

func FragmentCSS(f StyleFragment) string

FragmentCSS returns CSS declarations for one fragment (excluding __type__).

func FragmentsToInlineCSS

func FragmentsToInlineCSS(fragments []StyleFragment) string

FragmentsToInlineCSS builds a CSS declaration block from fragments (typically div + span). Uses the first matching fragment types in order: div, span, div inner.

func HTMLLayerCSS

func HTMLLayerCSS(fragments []StyleFragment) (boxCSS, textCSS string)

HTMLLayerCSS returns box (layout/background) and text (typography) CSS for compilehtml.

func HasStyleValue

func HasStyleValue(key string, raw json.RawMessage) bool

HasStyleValue reports whether a style property was explicitly set to a usable CSS value. Absent, null, empty, false, and zero-like dimensions are treated as not passed.

func MaskFragmentToSVG

func MaskFragmentToSVG(f StyleFragment) string

MaskFragmentToSVG emits a linear-gradient mask for directional box blur.

func Normalize

func Normalize(style psrt.Style) map[string]json.RawMessage

Normalize parses style JSON into a canonical-key map (no Webkit* keys).

func PathDecorationAttrs

func PathDecorationAttrs(f StyleFragment) string

PathDecorationAttrs returns fill/stroke/filter attrs for a ~~ block's <path> element — same as RectDecorationAttrs but without "rx" (border-radius has no meaning for an arbitrary path; the contour is already defined by the path itself).

func RectDecorationAttrs

func RectDecorationAttrs(f StyleFragment) string

RectDecorationAttrs returns fill/stroke/radius/filter only (position and size come from layout).

func RectFragmentAttrs

func RectFragmentAttrs(f StyleFragment) string

RectFragmentAttrs returns SVG attributes for a rect fragment.

func RegisterAlias

func RegisterAlias(alias, canonical string)

RegisterAlias adds or overrides an alias → canonical mapping.

func ResolveName

func ResolveName(raw string) (canonical string, ok bool)

ResolveName maps raw property names to canonical PSRT camelCase keys.

func SanitizeCSSValue

func SanitizeCSSValue(s string) string

func StringifyCSSValue

func StringifyCSSValue(r json.RawMessage) string

Types

type AdaptContext

type AdaptContext struct {
	Style      map[string]json.RawMessage
	Text       psrt.Text
	Mask       *psrt.Mask
	PathMask   *psrt.PathMask
	CanvasW    int
	CanvasH    int
	FontSizePx float64
	Zoom       float64
	// HTMLCompile marks compilehtml output (font-size in px, same as SVG).
	HTMLCompile bool
	// PageSlug and TextIndex for SVG filter ids.
	PageSlug  string
	TextIndex int
}

AdaptContext carries normalized style and layout for one text or mask block.

func (AdaptContext) FontSizePxOrCompute

func (ctx AdaptContext) FontSizePxOrCompute() float64

func (AdaptContext) ImageDims

func (ctx AdaptContext) ImageDims() percent.ImageDims

type Adapter

type Adapter interface {
	ResolveName(raw string) (string, bool)
	Normalize(style psrt.Style) map[string]json.RawMessage
	AdaptHTML(ctx AdaptContext) []StyleFragment
	AdaptSVG(ctx AdaptContext) []StyleFragment
}

Adapter converts PSRT styles to render fragments.

var Default Adapter = &defaultAdapter{}

Default is the package-level style adapter.

type BlurAdapt

type BlurAdapt struct {
	FilterID string
	MaskID   string
}

BlurAdapt carries SVG ids produced for backdrop-style box blur.

type BlurSpec

type BlurSpec struct {
	AmountPx float64
	Side     string // "", "left", "right", "top", "bottom"
}

BlurSpec is a resolved blur amount and optional single side.

type StyleFragment

type StyleFragment map[string]any

StyleFragment is a flat map with mandatory __type__ and target properties.

func AdaptHTML

func AdaptHTML(ctx AdaptContext) []StyleFragment

AdaptHTML is a convenience wrapper around Default.AdaptHTML.

func AdaptMaskHTML

func AdaptMaskHTML(ctx AdaptContext) []StyleFragment

AdaptMaskHTML returns box CSS fragments for a static mask block.

func AdaptMaskSVG

func AdaptMaskSVG(ctx AdaptContext) []StyleFragment

AdaptMaskSVG returns SVG fragments for a static mask block.

func AdaptPathMaskHTML

func AdaptPathMaskHTML(ctx AdaptContext) []StyleFragment

AdaptPathMaskHTML returns style fragments for a ~~ block (compilehtml pipeline). The block is always rendered as an inline <svg> (see compilehtml/pathmask.go), so decoration targets SVG presentation attributes in both pipelines.

func AdaptPathMaskSVG

func AdaptPathMaskSVG(ctx AdaptContext) []StyleFragment

AdaptPathMaskSVG returns style fragments for a ~~ block (compilesvg pipeline).

func AdaptSVG

func AdaptSVG(ctx AdaptContext) []StyleFragment

AdaptSVG is a convenience wrapper around Default.AdaptSVG.

func MergeFragments

func MergeFragments(fragments []StyleFragment) []StyleFragment

func NewFragment

func NewFragment(typ string) StyleFragment

func (StyleFragment) GetString

func (f StyleFragment) GetString(prop string) string

func (StyleFragment) Set

func (f StyleFragment) Set(prop string, value any)

type WebPreviewStyle

type WebPreviewStyle struct {
	Container map[string]string `json:"container"`
	Text      map[string]string `json:"text"`
	HasStroke bool              `json:"hasStroke"`
}

WebPreviewStyle is CSS for web preview (container = box/layout, text = typography + stroke).

func AdaptMaskWebPreview

func AdaptMaskWebPreview(ctx AdaptContext) WebPreviewStyle

AdaptMaskWebPreview adapts a == mask block for live web preview (fixed height %).

func AdaptWebPreview

func AdaptWebPreview(ctx AdaptContext) WebPreviewStyle

AdaptWebPreview runs AdaptHTML for live web preview (font-size in px, not cqh).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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