validation

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidValue = errors.New("invalid or unsupported values for a known CSS property")

	LENGTHUNITS = map[string]pr.Unit{"ex": pr.Ex, "em": pr.Em, "ch": pr.Ch, "rem": pr.Rem, "px": pr.Px, "pt": pr.Pt, "pc": pr.Pc, "in": pr.In, "cm": pr.Cm, "mm": pr.Mm, "q": pr.Q}
	AngleUnits  = map[string]pr.Unit{"rad": pr.Rad, "turn": pr.Turn, "deg": pr.Deg, "grad": pr.Grad}

	// http://drafts.csswg.org/csswg/css3-values/#angles
	// 1<unit> is this many radians.
	ANGLETORADIANS = map[pr.Unit]utils.Fl{
		pr.Rad:  1,
		pr.Turn: 2 * math.Pi,
		pr.Deg:  math.Pi / 180,
		pr.Grad: math.Pi / 200,
	}

	// http://drafts.csswg.org/csswg/css-values/#resolution
	RESOLUTIONTODPPX = map[string]utils.Fl{
		"dppx": 1,
		"dpi":  utils.Fl(1 / pr.LengthsToPixels[pr.In]),
		"dpcm": utils.Fl(1 / pr.LengthsToPixels[pr.Cm]),
	}
)

Functions

func ExpandFont added in v0.0.2

func ExpandFont(tokens []Token) ([][2]string, error)

ExpandFont expands the 'font' property, to be used in SVG documents. It returns a list of (name, property) pairs

func ExpandValidatePending added in v0.0.10

func ExpandValidatePending(prop pr.KnownProp, from pr.Shortand, tokens []Token) (pr.DeclaredValue, error)

func HasVar added in v0.0.10

func HasVar(token Token) bool

HasVar returns true if [token] is a var(...), or is a function with any var()

func ParseCounterStyleName

func ParseCounterStyleName(tokens []pa.Token, cs counters.CounterStyle) string

func PreprocessCounterStyleDescriptors

func PreprocessCounterStyleDescriptors(baseUrl string, descriptors []pa.Compound) counters.CounterStyleDescriptors

func Validate

func Validate(key pr.PropKey, tokens []Token) (pr.DeclaredValue, error)

func ValidateKnown added in v0.0.10

func ValidateKnown(name pr.KnownProp, tokens []Token, baseUrl string) (out pr.DeclaredValue, err error)

ValidateKnown validate one known, non shortand, property.

Types

type Declaration added in v0.0.10

type Declaration struct {
	Name  pr.PropKey
	Value pr.DeclaredValue

	// Shortand is not zero for shortands containing 'var()' tokens, waiting to be expanded and validated
	// In this case, [Value] is [pr.RawTokens] and refers to the associate shorthand, not to the expanded [Name]
	Shortand pr.Shortand

	Important bool
}

Declaration is the input form of a CSS property, possibly containing variables.

func PreprocessDeclarations

func PreprocessDeclarations(baseUrl string, declarations []pa.Compound) []Declaration

See PreprocessDeclarationsPrelude

type FontFaceDescriptors

type FontFaceDescriptors struct {
	Src                 []pr.NamedString
	FontFamily          pr.String
	FontStyle           pr.String
	FontWeight          pr.IntString
	FontStretch         pr.String
	FontFeatureSettings pr.FontFeatures
	FontVariant         []NamedProp
}

func PreprocessFontFaceDescriptors

func PreprocessFontFaceDescriptors(baseUrl string, descriptors []pa.Compound) FontFaceDescriptors

type KeyedDeclarations added in v0.0.10

type KeyedDeclarations struct {
	Selector     selector.SelectorGroup
	Declarations []Declaration
}

func PreprocessDeclarationsPrelude added in v0.0.10

func PreprocessDeclarationsPrelude(baseURL string, declarations []pa.Compound, prelude []pa.Token) ([]KeyedDeclarations, error)

PreprocessDeclarationsPrelude filter unsupported properties or parsing errors, and expand shortand properties.

Properties containing var() tokens are not validated yet. Shortand containing var() tokens are not expanded.

Log a warning for every ignored declaration.

If [prelude] is nil, the returned error is always nil. The returned slice is never empty, and has always length 1 if [prelude] is nil.

type NamedProp added in v0.0.10

type NamedProp struct {
	Name  pr.KnownProp
	Value pr.DeclaredValue
}

type Token

type Token = pa.Token

Jump to

Keyboard shortcuts

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