Documentation
¶
Overview ¶
Package webstyle writes NSGo's styles as CSS, for the backends that draw with a browser's engine: the web and WeChat mini programs, whose render layer is a web view. It is plain Go, so it is tested on any host.
Lengths are CSS pixels, which are points; what is at CSS's initial value comes back empty, so callers leave the property out.
Index ¶
- Variables
- func AnimatedInline(base driver.ViewStyle, vals driver.AnimatedValues) map[string]string
- func Color(c driver.Color) string
- func CustomCursorDeclarations(named driver.Cursor, custom *driver.CustomCursor, url1x, url2x string, ...) []string
- func DataURL(data []byte) string
- func Decoration(d driver.TextDecoration) string
- func Easing(c driver.Curve) string
- func Fill(c driver.Color) string
- func Filter(filters []driver.Filter) string
- func GlassBoxTransform(lx, ly, w, h float64, vs *driver.ViewStyle) (x, y, sw, sh float64, ok bool)
- func GlassFallbackBackdrop(vs *driver.ViewStyle) string
- func GlassFallbackRim(vs *driver.ViewStyle, dark bool) string
- func GlassFallbackTint(vs *driver.ViewStyle, dark bool) string
- func GlassUnsafeAncestor(vs *driver.ViewStyle) bool
- func Gradient(p *driver.GradientPaint, size driver.Size) string
- func LineStyle(s driver.BorderStyle) string
- func Opacity(o float32) string
- func Px(p driver.Points) string
- func Radius(vs *driver.ViewStyle) string
- func Shadow(vs *driver.ViewStyle) string
- func TextShadow(s driver.TextShadow) string
- func Transform(t driver.Transform) string
- func Transition(t driver.Transition) string
- func TransitionFor(t driver.Transition, bound uint16) string
- type GlassUniforms
Constants ¶
This section is empty.
Variables ¶
var DecorationStyles = map[driver.TextDecorationStyle]string{ 0: "solid", driver.DecorationSolid: "solid", driver.DecorationDouble: "double", driver.DecorationDotted: "dotted", driver.DecorationDashed: "dashed", driver.DecorationWavy: "wavy", }
DecorationStyles are the CSS of the decoration styles.
Functions ¶
func AnimatedInline ¶
AnimatedInline returns the inline CSS properties for a view with base style base and bound animated values vals. Only properties driven by vals are set inline; unbound properties stay empty so the view's class and its CSS transitions own them. When vals binds properties listed in base.Transition, transition is narrowed to the unbound ones (or "none" when none remain).
func CustomCursorDeclarations ¶
func CustomCursorDeclarations(named driver.Cursor, custom *driver.CustomCursor, url1x, url2x string, dpr float32) []string
CustomCursorDeclarations returns the CSS cursor property values for a view's named and custom cursors, in progressive-enhancement order: a universal url() declaration followed by -webkit-image-set() and image-set() when a 2x representation is present so HiDPI displays select it automatically. Returns nil when no cursor property should be emitted.
func DataURL ¶
DataURL encodes image bytes into a data: URL with the sniffed media type (SVG, PNG, JPEG, GIF, WebP, defaulting to image/png).
func Decoration ¶
func Decoration(d driver.TextDecoration) string
Decoration is CSS's text-decoration-line of d, "none" for none.
func GlassBoxTransform ¶
GlassBoxTransform checks whether vs's transform keeps the glass box upright (axis-aligned, flat, no rotation/skew/perspective/matrix) and returns its transformed CSS bounds (x, y, sw, sh) from layout origin (lx, ly) and layout size (w, h).
func GlassFallbackBackdrop ¶
GlassFallbackBackdrop returns the CSS backdrop-filter for a glass view when the glass shader is unavailable: the style's own BackdropFilters when set, else a material blur matching GlassEffect.
func GlassFallbackRim ¶
GlassFallbackRim returns a subtle inset specular rim box-shadow for a glass view falling back to CSS, or "" when vs has no glass effect.
func GlassFallbackTint ¶
GlassFallbackTint returns the CSS background-color for a glass view falling back to CSS: the view's own Background when set, else a subtle translucent tint matching GlassEffect and appearance.
func GlassUnsafeAncestor ¶
GlassUnsafeAncestor reports whether an ancestor view with style vs makes placing a nested HTML-in-Canvas drawable inside it unsafe: Chrome hangs when a nested drawable sits under blend/mask/translucent backdrop layers, and nesting glass inside glass risks recursive capture.
func Gradient ¶
func Gradient(p *driver.GradientPaint, size driver.Size) string
Gradient is the CSS gradient of p on a box of size.
func LineStyle ¶
func LineStyle(s driver.BorderStyle) string
LineStyle is the CSS of a border or outline style.
func TextShadow ¶
func TextShadow(s driver.TextShadow) string
TextShadow is the CSS of a text shadow.
func Transform ¶
Transform is t around the view's transform origin, in its order: perspective, translate, rotate, rotateX, rotateY, rotateZ, skew, then scale.
func Transition ¶
func Transition(t driver.Transition) string
Transition animates the listed properties from what the view shows to what the same style change sets.
func TransitionFor ¶
func TransitionFor(t driver.Transition, bound uint16) string
TransitionFor returns the CSS transition of t excluding the CSS properties currently driven by bound (AnimatedValues.Set), so unbound properties keep transitioning alongside animated values.
Types ¶
type GlassUniforms ¶
type GlassUniforms struct {
Rect [4]float32 // x, y, width, height in output pixels
Radii [4]float32 // fitted corner radii in pixels: top-left, top-right, bottom-right, bottom-left
P0 [4]float32 // bezel, refraction, rim, rim width (pixels / factors)
P1 [4]float32 // straight RGBA tint
P2 [4]float32 // low, high, curve, saturation
P3 [4]float32 // light direction (x, y, 0, 0)
Blur float32 // backdrop blur sigma in CSS points
}
GlassUniforms holds the shader parameters for Liquid Glass, matching Windows' glass shader (internal/platform/windows/glass.go) and MyGo's glass material measurements of macOS 27's NSGlassEffectView.
func ComputeGlassUniforms ¶
func ComputeGlassUniforms(vs *driver.ViewStyle, w, h, scale float32, dark bool) (GlassUniforms, bool)
ComputeGlassUniforms computes the Liquid Glass shader parameters for a box of w by h CSS points at device pixel scale. It returns false when vs has no glass effect or the box has no area.