css_ast

package
v0.15.9 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var KnownDeclarations = map[string]D{}/* 316 elements not displayed */

Functions

func HashRules added in v0.11.19

func HashRules(hash uint32, rules []Rule) uint32

func HashTokens added in v0.11.19

func HashTokens(hash uint32, tokens []Token) uint32

func MaybeCorrectDeclarationTypo added in v0.14.12

func MaybeCorrectDeclarationTypo(text string) (string, bool)

func RulesEqual added in v0.11.19

func RulesEqual(a []Rule, b []Rule) bool

func TokensAreCommaSeparated added in v0.12.10

func TokensAreCommaSeparated(tokens []Token) bool

func TokensEqual added in v0.11.19

func TokensEqual(a []Token, b []Token) bool

func TokensEqualIgnoringWhitespace added in v0.11.19

func TokensEqualIgnoringWhitespace(a []Token, b []Token) bool

Types

type AST

type AST struct {
	ImportRecords        []ast.ImportRecord
	Rules                []Rule
	SourceMapComment     logger.Span
	ApproximateLineCount int32
}

type ComplexSelector

type ComplexSelector struct {
	Selectors []CompoundSelector
}

func (ComplexSelector) Equal added in v0.13.13

type CompoundSelector

type CompoundSelector struct {
	Combinator        string // Optional, may be ""
	TypeSelector      *NamespacedName
	SubclassSelectors []SS
	NestingSelector   NestingSelector // "&"
}

type D added in v0.7.9

type D uint16
const (
	DUnknown D = iota
	DAlignContent
	DAlignItems
	DAlignSelf
	DAlignmentBaseline
	DAll
	DAnimation
	DAnimationDelay
	DAnimationDirection
	DAnimationDuration
	DAnimationFillMode
	DAnimationIterationCount
	DAnimationName
	DAnimationPlayState
	DAnimationTimingFunction
	DBackfaceVisibility
	DBackground
	DBackgroundAttachment
	DBackgroundClip
	DBackgroundColor
	DBackgroundImage
	DBackgroundOrigin
	DBackgroundPosition
	DBackgroundPositionX
	DBackgroundPositionY
	DBackgroundRepeat
	DBackgroundSize
	DBaselineShift
	DBlockSize
	DBorder
	DBorderBlockEnd
	DBorderBlockEndColor
	DBorderBlockEndStyle
	DBorderBlockEndWidth
	DBorderBlockStart
	DBorderBlockStartColor
	DBorderBlockStartStyle
	DBorderBlockStartWidth
	DBorderBottom
	DBorderBottomColor
	DBorderBottomLeftRadius
	DBorderBottomRightRadius
	DBorderBottomStyle
	DBorderBottomWidth
	DBorderCollapse
	DBorderColor
	DBorderImage
	DBorderImageOutset
	DBorderImageRepeat
	DBorderImageSlice
	DBorderImageSource
	DBorderImageWidth
	DBorderInlineEnd
	DBorderInlineEndColor
	DBorderInlineEndStyle
	DBorderInlineEndWidth
	DBorderInlineStart
	DBorderInlineStartColor
	DBorderInlineStartStyle
	DBorderInlineStartWidth
	DBorderLeft
	DBorderLeftColor
	DBorderLeftStyle
	DBorderLeftWidth
	DBorderRadius
	DBorderRight
	DBorderRightColor
	DBorderRightStyle
	DBorderRightWidth
	DBorderSpacing
	DBorderStyle
	DBorderTop
	DBorderTopColor
	DBorderTopLeftRadius
	DBorderTopRightRadius
	DBorderTopStyle
	DBorderTopWidth
	DBorderWidth
	DBottom
	DBoxShadow
	DBoxSizing
	DBreakAfter
	DBreakBefore
	DBreakInside
	DCaptionSide
	DCaretColor
	DClear
	DClip
	DClipPath
	DClipRule
	DColor
	DColorInterpolation
	DColorInterpolationFilters
	DColumnCount
	DColumnFill
	DColumnGap
	DColumnRule
	DColumnRuleColor
	DColumnRuleStyle
	DColumnRuleWidth
	DColumnSpan
	DColumnWidth
	DColumns
	DContent
	DCounterIncrement
	DCounterReset
	DCssFloat
	DCssText
	DCursor
	DDirection
	DDisplay
	DDominantBaseline
	DEmptyCells
	DFill
	DFillOpacity
	DFillRule
	DFilter
	DFlex
	DFlexBasis
	DFlexDirection
	DFlexFlow
	DFlexGrow
	DFlexShrink
	DFlexWrap
	DFloat
	DFloodColor
	DFloodOpacity
	DFont
	DFontFamily
	DFontFeatureSettings
	DFontKerning
	DFontSize
	DFontSizeAdjust
	DFontStretch
	DFontStyle
	DFontSynthesis
	DFontVariant
	DFontVariantCaps
	DFontVariantEastAsian
	DFontVariantLigatures
	DFontVariantNumeric
	DFontVariantPosition
	DFontWeight
	DGap
	DGlyphOrientationVertical
	DGrid
	DGridArea
	DGridAutoColumns
	DGridAutoFlow
	DGridAutoRows
	DGridColumn
	DGridColumnEnd
	DGridColumnGap
	DGridColumnStart
	DGridGap
	DGridRow
	DGridRowEnd
	DGridRowGap
	DGridRowStart
	DGridTemplate
	DGridTemplateAreas
	DGridTemplateColumns
	DGridTemplateRows
	DHeight
	DHyphens
	DImageOrientation
	DImageRendering
	DInlineSize
	DInset
	DJustifyContent
	DJustifyItems
	DJustifySelf
	DLeft
	DLetterSpacing
	DLightingColor
	DLineBreak
	DLineHeight
	DListStyle
	DListStyleImage
	DListStylePosition
	DListStyleType
	DMargin
	DMarginBlockEnd
	DMarginBlockStart
	DMarginBottom
	DMarginInlineEnd
	DMarginInlineStart
	DMarginLeft
	DMarginRight
	DMarginTop
	DMarker
	DMarkerEnd
	DMarkerMid
	DMarkerStart
	DMask
	DMaskComposite
	DMaskImage
	DMaskPosition
	DMaskRepeat
	DMaskSize
	DMaskType
	DMaxBlockSize
	DMaxHeight
	DMaxInlineSize
	DMaxWidth
	DMinBlockSize
	DMinHeight
	DMinInlineSize
	DMinWidth
	DObjectFit
	DObjectPosition
	DOpacity
	DOrder
	DOrphans
	DOutline
	DOutlineColor
	DOutlineOffset
	DOutlineStyle
	DOutlineWidth
	DOverflow
	DOverflowAnchor
	DOverflowWrap
	DOverflowX
	DOverflowY
	DOverscrollBehavior
	DOverscrollBehaviorBlock
	DOverscrollBehaviorInline
	DOverscrollBehaviorX
	DOverscrollBehaviorY
	DPadding
	DPaddingBlockEnd
	DPaddingBlockStart
	DPaddingBottom
	DPaddingInlineEnd
	DPaddingInlineStart
	DPaddingLeft
	DPaddingRight
	DPaddingTop
	DPageBreakAfter
	DPageBreakBefore
	DPageBreakInside
	DPaintOrder
	DPerspective
	DPerspectiveOrigin
	DPlaceContent
	DPlaceItems
	DPlaceSelf
	DPointerEvents
	DPosition
	DQuotes
	DResize
	DRight
	DRotate
	DRowGap
	DRubyAlign
	DRubyPosition
	DScale
	DScrollBehavior
	DShapeRendering
	DStopColor
	DStopOpacity
	DStroke
	DStrokeDasharray
	DStrokeDashoffset
	DStrokeLinecap
	DStrokeLinejoin
	DStrokeMiterlimit
	DStrokeOpacity
	DStrokeWidth
	DTabSize
	DTableLayout
	DTextAlign
	DTextAlignLast
	DTextAnchor
	DTextCombineUpright
	DTextDecoration
	DTextDecorationColor
	DTextDecorationLine
	DTextDecorationStyle
	DTextEmphasis
	DTextEmphasisColor
	DTextEmphasisPosition
	DTextEmphasisStyle
	DTextIndent
	DTextJustify
	DTextOrientation
	DTextOverflow
	DTextRendering
	DTextShadow
	DTextTransform
	DTextUnderlinePosition
	DTop
	DTouchAction
	DTransform
	DTransformBox
	DTransformOrigin
	DTransformStyle
	DTransition
	DTransitionDelay
	DTransitionDuration
	DTransitionProperty
	DTransitionTimingFunction
	DTranslate
	DUnicodeBidi
	DUserSelect
	DVerticalAlign
	DVisibility
	DWhiteSpace
	DWidows
	DWidth
	DWillChange
	DWordBreak
	DWordSpacing
	DWordWrap
	DWritingMode
	DZIndex
	DZoom
)

type KeyframeBlock added in v0.7.8

type KeyframeBlock struct {
	Selectors []string
	Rules     []Rule
}

type NameToken added in v0.7.20

type NameToken struct {
	Text string
	Kind css_lexer.T
}

type NamespacedName

type NamespacedName struct {
	// If present, this is an identifier or "*" and is followed by a "|" character
	NamespacePrefix *NameToken

	// This is an identifier or "*"
	Name NameToken
}

func (NamespacedName) Equal added in v0.11.19

func (a NamespacedName) Equal(b NamespacedName) bool

type NestingSelector added in v0.14.12

type NestingSelector uint8
const (
	NestingSelectorNone                NestingSelector = iota
	NestingSelectorPrefix                              // "&a {}"
	NestingSelectorPresentButNotPrefix                 // "a& {}"
)

type R

type R interface {
	Equal(rule R) bool
	Hash() (uint32, bool)
}

type RAtCharset added in v0.7.7

type RAtCharset struct {
	Encoding string
}

func (*RAtCharset) Equal added in v0.11.19

func (a *RAtCharset) Equal(rule R) bool

func (*RAtCharset) Hash added in v0.11.19

func (r *RAtCharset) Hash() (uint32, bool)

type RAtImport

type RAtImport struct {
	ImportConditions  []Token
	ImportRecordIndex uint32
}

func (*RAtImport) Equal added in v0.11.19

func (*RAtImport) Equal(rule R) bool

func (*RAtImport) Hash added in v0.11.19

func (r *RAtImport) Hash() (uint32, bool)

type RAtKeyframes added in v0.7.8

type RAtKeyframes struct {
	AtToken string
	Name    string
	Blocks  []KeyframeBlock
}

func (*RAtKeyframes) Equal added in v0.11.19

func (a *RAtKeyframes) Equal(rule R) bool

func (*RAtKeyframes) Hash added in v0.11.19

func (r *RAtKeyframes) Hash() (uint32, bool)

type RAtLayer added in v0.14.23

type RAtLayer struct {
	Names [][]string
	Rules []Rule
}

func (*RAtLayer) Equal added in v0.14.23

func (a *RAtLayer) Equal(rule R) bool

func (*RAtLayer) Hash added in v0.14.23

func (r *RAtLayer) Hash() (uint32, bool)

type RBadDeclaration

type RBadDeclaration struct {
	Tokens []Token
}

func (*RBadDeclaration) Equal added in v0.11.19

func (a *RBadDeclaration) Equal(rule R) bool

func (*RBadDeclaration) Hash added in v0.11.19

func (r *RBadDeclaration) Hash() (uint32, bool)

type RComment added in v0.13.10

type RComment struct {
	Text string
}

func (*RComment) Equal added in v0.13.10

func (a *RComment) Equal(rule R) bool

func (*RComment) Hash added in v0.13.10

func (r *RComment) Hash() (uint32, bool)

type RDeclaration

type RDeclaration struct {
	KeyText   string
	Value     []Token
	KeyRange  logger.Range
	Key       D // Compare using this instead of "Key" for speed
	Important bool
}

func (*RDeclaration) Equal added in v0.11.19

func (a *RDeclaration) Equal(rule R) bool

func (*RDeclaration) Hash added in v0.11.19

func (r *RDeclaration) Hash() (uint32, bool)

type RKnownAt

type RKnownAt struct {
	AtToken string
	Prelude []Token
	Rules   []Rule
}

func (*RKnownAt) Equal added in v0.11.19

func (a *RKnownAt) Equal(rule R) bool

func (*RKnownAt) Hash added in v0.11.19

func (r *RKnownAt) Hash() (uint32, bool)

type RQualified

type RQualified struct {
	Prelude []Token
	Rules   []Rule
}

func (*RQualified) Equal added in v0.11.19

func (a *RQualified) Equal(rule R) bool

func (*RQualified) Hash added in v0.11.19

func (r *RQualified) Hash() (uint32, bool)

type RSelector

type RSelector struct {
	Selectors []ComplexSelector
	Rules     []Rule
	HasAtNest bool
}

func (*RSelector) Equal added in v0.11.19

func (a *RSelector) Equal(rule R) bool

func (*RSelector) Hash added in v0.11.19

func (r *RSelector) Hash() (uint32, bool)

type RUnknownAt

type RUnknownAt struct {
	AtToken string
	Prelude []Token
	Block   []Token
}

func (*RUnknownAt) Equal added in v0.11.19

func (a *RUnknownAt) Equal(rule R) bool

func (*RUnknownAt) Hash added in v0.11.19

func (r *RUnknownAt) Hash() (uint32, bool)

type Rule added in v0.12.20

type Rule struct {
	Data R
	Loc  logger.Loc
}

type SS

type SS interface {
	Equal(ss SS) bool
	Hash() uint32
}

type SSAttribute

type SSAttribute struct {
	MatcherOp       string // Either "" or one of: "=" "~=" "|=" "^=" "$=" "*="
	MatcherValue    string
	NamespacedName  NamespacedName
	MatcherModifier byte // Either 0 or one of: 'i' 'I' 's' 'S'
}

func (*SSAttribute) Equal added in v0.11.19

func (a *SSAttribute) Equal(ss SS) bool

func (*SSAttribute) Hash added in v0.11.19

func (ss *SSAttribute) Hash() uint32

type SSClass

type SSClass struct {
	Name string
}

func (*SSClass) Equal added in v0.11.19

func (a *SSClass) Equal(ss SS) bool

func (*SSClass) Hash added in v0.11.19

func (ss *SSClass) Hash() uint32

type SSHash

type SSHash struct {
	Name string
}

func (*SSHash) Equal added in v0.11.19

func (a *SSHash) Equal(ss SS) bool

func (*SSHash) Hash added in v0.11.19

func (ss *SSHash) Hash() uint32

type SSPseudoClass

type SSPseudoClass struct {
	Name      string
	Args      []Token
	IsElement bool // If true, this is prefixed by "::" instead of ":"
}

func (*SSPseudoClass) Equal added in v0.11.19

func (a *SSPseudoClass) Equal(ss SS) bool

func (*SSPseudoClass) Hash added in v0.11.19

func (ss *SSPseudoClass) Hash() uint32

type Token added in v0.7.8

type Token struct {
	// Contains the child tokens for component values that are simple blocks.
	// These are either "(", "{", "[", or function tokens. The closing token is
	// implicit and is not stored.
	Children *[]Token // 8 bytes

	// This is the raw contents of the token most of the time. However, it
	// contains the decoded string contents for "TString" tokens.
	Text string // 16 bytes

	// URL tokens have an associated import record at the top-level of the AST.
	// This index points to that import record.
	ImportRecordIndex uint32 // 4 bytes

	// The division between the number and the unit for "TDimension" tokens.
	UnitOffset uint16 // 2 bytes

	// This will never be "TWhitespace" because whitespace isn't stored as a
	// token directly. Instead it is stored in "HasWhitespaceAfter" on the
	// previous token. This is to make it easier to pattern-match against
	// tokens when handling CSS rules, since whitespace almost always doesn't
	// matter. That way you can pattern match against e.g. "rgb(r, g, b)" and
	// not have to handle all possible combinations of embedded whitespace
	// tokens.
	//
	// There is one exception to this: when in verbatim whitespace mode and
	// the token list is non-empty and is only whitespace tokens. In that case
	// a single whitespace token is emitted. This is because otherwise there
	// would be no tokens to attach the whitespace before/after flags to.
	Kind css_lexer.T // 1 byte

	// These flags indicate the presence of a "TWhitespace" token before or after
	// this token. There should be whitespace printed between two tokens if either
	// token indicates that there should be whitespace. Note that whitespace may
	// be altered by processing in certain situations (e.g. minification).
	Whitespace WhitespaceFlags // 1 byte
}

We create a lot of tokens, so make sure this layout is memory-efficient. The layout here isn't optimal because it biases for convenience (e.g. "string" could be shorter) but at least the ordering of fields was deliberately chosen to minimize size.

func CloneTokensWithImportRecords added in v0.14.0

func CloneTokensWithImportRecords(
	tokensIn []Token, importRecordsIn []ast.ImportRecord,
	tokensOut []Token, importRecordsOut []ast.ImportRecord,
) ([]Token, []ast.ImportRecord)

func (Token) DimensionUnit added in v0.7.9

func (t Token) DimensionUnit() string

func (Token) DimensionUnitIsSafeLength added in v0.13.15

func (t Token) DimensionUnitIsSafeLength() bool

func (Token) DimensionValue added in v0.7.9

func (t Token) DimensionValue() string

func (Token) Equal added in v0.11.19

func (a Token) Equal(b Token) bool

func (Token) EqualIgnoringWhitespace added in v0.11.19

func (a Token) EqualIgnoringWhitespace(b Token) bool

func (Token) FractionForPercentage added in v0.11.19

func (t Token) FractionForPercentage() (float64, bool)

func (Token) IsAngle added in v0.13.14

func (t Token) IsAngle() bool

func (Token) IsOne added in v0.12.10

func (t Token) IsOne() bool

func (Token) IsZero added in v0.12.10

func (t Token) IsZero() bool

func (Token) PercentageValue added in v0.11.19

func (t Token) PercentageValue() string

func (*Token) TurnLengthIntoNumberIfZero added in v0.11.19

func (t *Token) TurnLengthIntoNumberIfZero() bool

https://drafts.csswg.org/css-values-3/#lengths For zero lengths the unit identifier is optional (i.e. can be syntactically represented as the <number> 0).

func (*Token) TurnLengthOrPercentageIntoNumberIfZero added in v0.12.10

func (t *Token) TurnLengthOrPercentageIntoNumberIfZero() bool

type WhitespaceFlags added in v0.8.43

type WhitespaceFlags uint8
const (
	WhitespaceBefore WhitespaceFlags = 1 << iota
	WhitespaceAfter
)

Jump to

Keyboard shortcuts

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