@tbela99/css-parser 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/.editorconfig +484 -0
  2. package/README.md +5 -3
  3. package/dist/index-umd-web.js +3272 -1898
  4. package/dist/index.cjs +3272 -1898
  5. package/dist/index.d.ts +48 -11
  6. package/dist/lib/ast/expand.js +14 -2
  7. package/dist/lib/ast/math/expression.js +1 -1
  8. package/dist/lib/ast/minify.js +30 -16
  9. package/dist/lib/ast/types.js +1 -0
  10. package/dist/lib/ast/walk.js +12 -0
  11. package/dist/lib/parser/declaration/map.js +59 -52
  12. package/dist/lib/parser/declaration/set.js +0 -12
  13. package/dist/lib/parser/parse.js +140 -101
  14. package/dist/lib/parser/tokenize.js +15 -3
  15. package/dist/lib/renderer/color/hex.js +1 -1
  16. package/dist/lib/renderer/color/hsl.js +1 -1
  17. package/dist/lib/renderer/color/hwb.js +2 -2
  18. package/dist/lib/renderer/color/lab.js +1 -1
  19. package/dist/lib/renderer/color/lch.js +1 -1
  20. package/dist/lib/renderer/color/oklab.js +2 -2
  21. package/dist/lib/renderer/color/oklch.js +1 -1
  22. package/dist/lib/renderer/color/p3.js +1 -1
  23. package/dist/lib/renderer/color/prophotoRgb.js +1 -1
  24. package/dist/lib/renderer/color/prophotorgb.js +1 -1
  25. package/dist/lib/renderer/color/rgb.js +1 -1
  26. package/dist/lib/renderer/color/srgb.js +2 -2
  27. package/dist/lib/renderer/color/utils/constants.js +1 -1
  28. package/dist/lib/renderer/color/xyz.js +1 -1
  29. package/dist/lib/renderer/render.js +34 -6
  30. package/dist/lib/syntax/syntax.js +336 -1
  31. package/dist/lib/validation/at-rules/container.js +353 -0
  32. package/dist/lib/validation/at-rules/counter-style.js +2 -2
  33. package/dist/lib/validation/at-rules/custom-media.js +52 -0
  34. package/dist/lib/validation/at-rules/else.js +5 -0
  35. package/dist/lib/validation/at-rules/font-feature-values.js +3 -0
  36. package/dist/lib/validation/at-rules/import.js +3 -0
  37. package/dist/lib/validation/at-rules/layer.js +3 -0
  38. package/dist/lib/validation/at-rules/media.js +117 -29
  39. package/dist/lib/validation/at-rules/supports.js +11 -11
  40. package/dist/lib/validation/at-rules/when.js +178 -0
  41. package/dist/lib/validation/atrule.js +25 -10
  42. package/dist/lib/validation/config.js +20 -15
  43. package/dist/lib/validation/config.json.js +162 -42
  44. package/dist/lib/validation/declaration.js +39 -9
  45. package/dist/lib/validation/parser/parse.js +91 -13
  46. package/dist/lib/validation/parser/types.js +1 -0
  47. package/dist/lib/validation/selector.js +6 -3
  48. package/dist/lib/validation/syntax.js +50 -4
  49. package/dist/lib/validation/syntaxes/complex-selector-list.js +16 -12
  50. package/dist/lib/validation/syntaxes/complex-selector.js +17 -247
  51. package/dist/lib/validation/syntaxes/compound-selector.js +226 -0
  52. package/dist/lib/validation/syntaxes/image.js +29 -0
  53. package/dist/lib/validation/syntaxes/keyframe-block-list.js +1 -1
  54. package/dist/lib/validation/syntaxes/keyframe-selector.js +1 -1
  55. package/dist/lib/validation/syntaxes/relative-selector-list.js +43 -13
  56. package/dist/lib/validation/utils/list.js +2 -2
  57. package/dist/node/index.js +1 -1
  58. package/dist/web/index.js +1 -1
  59. package/package.json +7 -7
@@ -5,7 +5,7 @@ import '../parser/parse.js';
5
5
  import '../renderer/color/utils/constants.js';
6
6
  import '../renderer/sourcemap/lib/encode.js';
7
7
  import '../parser/utils/config.js';
8
- import { getParsedSyntax, getSyntaxConfig } from './config.js';
8
+ import { getSyntaxConfig, getParsedSyntax } from './config.js';
9
9
  import { validateAtRuleMedia } from './at-rules/media.js';
10
10
  import { validateAtRuleCounterStyle } from './at-rules/counter-style.js';
11
11
  import { validateAtRulePage } from './at-rules/page.js';
@@ -17,6 +17,10 @@ import { validateAtRuleFontFeatureValues } from './at-rules/font-feature-values.
17
17
  import { validateAtRuleNamespace } from './at-rules/namespace.js';
18
18
  import { validateAtRuleDocument } from './at-rules/document.js';
19
19
  import { validateAtRuleKeyframes } from './at-rules/keyframes.js';
20
+ import { validateAtRuleWhen } from './at-rules/when.js';
21
+ import { validateAtRuleElse } from './at-rules/else.js';
22
+ import { validateAtRuleContainer } from './at-rules/container.js';
23
+ import { validateAtRuleCustomMedia } from './at-rules/custom-media.js';
20
24
 
21
25
  function validateAtRule(atRule, options, root) {
22
26
  if (atRule.nam == 'charset') {
@@ -60,9 +64,21 @@ function validateAtRule(atRule, options, root) {
60
64
  if (atRule.nam == 'namespace') {
61
65
  return validateAtRuleNamespace(atRule);
62
66
  }
67
+ if (atRule.nam == 'when') {
68
+ return validateAtRuleWhen(atRule);
69
+ }
70
+ if (atRule.nam == 'else') {
71
+ return validateAtRuleElse(atRule);
72
+ }
73
+ if (atRule.nam == 'container') {
74
+ return validateAtRuleContainer(atRule);
75
+ }
63
76
  if (atRule.nam == 'document') {
64
77
  return validateAtRuleDocument(atRule);
65
78
  }
79
+ if (atRule.nam == 'custom-media') {
80
+ return validateAtRuleCustomMedia(atRule);
81
+ }
66
82
  if (['position-try', 'property', 'font-palette-values'].includes(atRule.nam)) {
67
83
  if (!('tokens' in atRule)) {
68
84
  return {
@@ -132,15 +148,14 @@ function validateAtRule(atRule, options, root) {
132
148
  }
133
149
  }
134
150
  if (!(name in config.atRules)) {
135
- // if (root?.typ == EnumToken.AtRuleNodeType) {
136
- //
137
- // const syntaxes: ValidationToken = (getParsedSyntax(ValidationSyntaxGroupEnum.AtRules, '@' + (root as AstAtRule).nam) as ValidationToken[])?.[0];
138
- //
139
- // if ('chi' in syntaxes) {
140
- //
141
- // return validateSyntax(syntaxes.chi as ValidationToken[], [atRule], root, options);
142
- // }
143
- // }
151
+ if (options.lenient) {
152
+ return {
153
+ valid: ValidationLevel.Lenient,
154
+ node: atRule,
155
+ syntax: null,
156
+ error: ''
157
+ };
158
+ }
144
159
  return {
145
160
  valid: ValidationLevel.Drop,
146
161
  node: atRule,
@@ -1,6 +1,6 @@
1
1
  import config from './config.json.js';
2
2
  import './parser/types.js';
3
- import { parseSyntax, walkValidationToken, renderSyntax } from './parser/parse.js';
3
+ import { parseSyntax } from './parser/parse.js';
4
4
 
5
5
  const parsedSyntaxes = new Map();
6
6
  Object.freeze(config);
@@ -9,25 +9,30 @@ function getSyntaxConfig() {
9
9
  return config;
10
10
  }
11
11
  function getParsedSyntax(group, key) {
12
- if (!(key in config[group])) {
13
- const matches = key.match(/(@?)(-[a-zA-Z]+)-(.*?)$/);
14
- if (matches != null) {
15
- key = matches[1] + matches[3];
16
- }
17
- if (!(key in config[group])) {
18
- return null;
12
+ // @ts-ignore
13
+ let obj = config[group];
14
+ const keys = Array.isArray(key) ? key : [key];
15
+ for (let i = 0; i < keys.length; i++) {
16
+ key = keys[i];
17
+ if (!(key in obj)) {
18
+ if ((i == 0 && key.charAt(0) == '@') || key.charAt(0) == '-') {
19
+ const matches = key.match(/^(@?)(-[a-zA-Z]+)-(.*?)$/);
20
+ if (matches != null) {
21
+ key = matches[1] + matches[3];
22
+ }
23
+ }
24
+ if (!(key in obj)) {
25
+ return null;
26
+ }
19
27
  }
28
+ // @ts-ignore
29
+ obj = obj[key];
20
30
  }
21
- const index = group + '.' + key;
31
+ const index = group + '.' + keys.join('.');
22
32
  // @ts-ignore
23
33
  if (!parsedSyntaxes.has(index)) {
24
34
  // @ts-ignore
25
- const syntax = parseSyntax(config[group][key].syntax);
26
- for (const node of syntax.chi) {
27
- for (const { token, parent } of walkValidationToken(node)) {
28
- token.text = renderSyntax(token);
29
- }
30
- }
35
+ const syntax = parseSyntax(obj.syntax);
31
36
  // @ts-ignore
32
37
  parsedSyntaxes.set(index, syntax.chi);
33
38
  }
@@ -995,9 +995,6 @@ var declarations = {
995
995
  "inline-size": {
996
996
  syntax: "<'width'>"
997
997
  },
998
- "input-security": {
999
- syntax: "auto | none"
1000
- },
1001
998
  inset: {
1002
999
  syntax: "<'top'>{1,4}"
1003
1000
  },
@@ -1556,6 +1553,9 @@ var declarations = {
1556
1553
  "shape-rendering": {
1557
1554
  syntax: "auto | optimizeSpeed | crispEdges | geometricPrecision"
1558
1555
  },
1556
+ "speak-as": {
1557
+ syntax: "normal | spell-out || digits || [ literal-punctuation | no-punctuation ]"
1558
+ },
1559
1559
  "stop-color": {
1560
1560
  syntax: "<'color'>"
1561
1561
  },
@@ -1668,7 +1668,7 @@ var declarations = {
1668
1668
  syntax: "none | auto | <percentage>"
1669
1669
  },
1670
1670
  "text-spacing-trim": {
1671
- syntax: "space-all | normal | space-first | trim-start | trim-both | trim-all | auto"
1671
+ syntax: "space-all | normal | space-first | trim-start"
1672
1672
  },
1673
1673
  "text-transform": {
1674
1674
  syntax: "none | capitalize | uppercase | lowercase | full-width | full-size-kana"
@@ -1764,7 +1764,7 @@ var declarations = {
1764
1764
  syntax: "normal | pre | nowrap | pre-wrap | pre-line | break-spaces | [ <'white-space-collapse'> || <'text-wrap'> ]"
1765
1765
  },
1766
1766
  "white-space-collapse": {
1767
- syntax: "collapse | discard | preserve | preserve-breaks | preserve-spaces | break-spaces"
1767
+ syntax: "collapse | preserve | preserve-breaks | preserve-spaces | break-spaces"
1768
1768
  },
1769
1769
  widows: {
1770
1770
  syntax: "<integer>"
@@ -1826,10 +1826,10 @@ var functions = {
1826
1826
  syntax: "attr( <attr-name> <type-or-unit>? [, <attr-fallback> ]? )"
1827
1827
  },
1828
1828
  blur: {
1829
- syntax: "blur( <length> )"
1829
+ syntax: "blur( <length>? )"
1830
1830
  },
1831
1831
  brightness: {
1832
- syntax: "brightness( <number-percentage> )"
1832
+ syntax: "brightness( [ <number> | <percentage> ]? )"
1833
1833
  },
1834
1834
  calc: {
1835
1835
  syntax: "calc( <calc-sum> )"
@@ -1853,7 +1853,7 @@ var functions = {
1853
1853
  syntax: "conic-gradient( [ from <angle> ]? [ at <position> ]?, <angular-color-stop-list> )"
1854
1854
  },
1855
1855
  contrast: {
1856
- syntax: "contrast( [ <number-percentage> ] )"
1856
+ syntax: "contrast( [ <number> | <percentage> ]? )"
1857
1857
  },
1858
1858
  cos: {
1859
1859
  syntax: "cos( <calc-sum> )"
@@ -1868,7 +1868,7 @@ var functions = {
1868
1868
  syntax: "cross-fade( <cf-mixing-image> , <cf-final-image>? )"
1869
1869
  },
1870
1870
  "drop-shadow": {
1871
- syntax: "drop-shadow( <length>{2,3} <color>? )"
1871
+ syntax: "drop-shadow( [ <color>? && <length>{2,3} ] )"
1872
1872
  },
1873
1873
  element: {
1874
1874
  syntax: "element( <id-selector> )"
@@ -1886,7 +1886,7 @@ var functions = {
1886
1886
  syntax: "fit-content( <length-percentage [0,∞]> )"
1887
1887
  },
1888
1888
  grayscale: {
1889
- syntax: "grayscale( <number-percentage> )"
1889
+ syntax: "grayscale( [ <number> | <percentage> ]? )"
1890
1890
  },
1891
1891
  hsl: {
1892
1892
  syntax: "hsl( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsl( <hue>, <percentage>, <percentage>, <alpha-value>? )"
@@ -1895,7 +1895,7 @@ var functions = {
1895
1895
  syntax: "hsla( <hue> <percentage> <percentage> [ / <alpha-value> ]? ) | hsla( <hue>, <percentage>, <percentage>, <alpha-value>? )"
1896
1896
  },
1897
1897
  "hue-rotate": {
1898
- syntax: "hue-rotate( <angle> )"
1898
+ syntax: "hue-rotate( [ <angle> | <zero> ]? )"
1899
1899
  },
1900
1900
  hwb: {
1901
1901
  syntax: "hwb( [<hue> | none] [<percentage> | none] [<percentage> | none] [ / [<alpha-value> | none] ]? )"
@@ -1913,7 +1913,7 @@ var functions = {
1913
1913
  syntax: "inset( <length-percentage>{1,4} [ round <'border-radius'> ]? )"
1914
1914
  },
1915
1915
  invert: {
1916
- syntax: "invert( <number-percentage> )"
1916
+ syntax: "invert( [ <number> | <percentage> ]? )"
1917
1917
  },
1918
1918
  lab: {
1919
1919
  syntax: "lab( [<percentage> | <number> | none] [ <percentage> | <number> | none] [ <percentage> | <number> | none] [ / [<alpha-value> | none] ]? )"
@@ -1961,7 +1961,7 @@ var functions = {
1961
1961
  syntax: "oklch( [ <percentage> | <number> | none] [ <percentage> | <number> | none] [ <hue> | none] [ / [<alpha-value> | none] ]? )"
1962
1962
  },
1963
1963
  opacity: {
1964
- syntax: "opacity( [ <number-percentage> ] )"
1964
+ syntax: "opacity( [ <number> | <percentage> ]? )"
1965
1965
  },
1966
1966
  paint: {
1967
1967
  syntax: "paint( <ident>, <declaration-value>? )"
@@ -1970,13 +1970,13 @@ var functions = {
1970
1970
  syntax: "palette-mix(<color-interpolation-method> , [ [normal | light | dark | <palette-identifier> | <palette-mix()> ] && <percentage [0,100]>? ]#{2})"
1971
1971
  },
1972
1972
  path: {
1973
- syntax: "path( [ <fill-rule>, ]? <string> )"
1973
+ syntax: "path( <'fill-rule'>? , <string> )"
1974
1974
  },
1975
1975
  perspective: {
1976
1976
  syntax: "perspective( [ <length [0,∞]> | none ] )"
1977
1977
  },
1978
1978
  polygon: {
1979
- syntax: "polygon( <fill-rule>? , [ <length-percentage> <length-percentage> ]# )"
1979
+ syntax: "polygon( <'fill-rule'>? , [ <length-percentage> <length-percentage> ]# )"
1980
1980
  },
1981
1981
  pow: {
1982
1982
  syntax: "pow( <calc-sum>, <calc-sum> )"
@@ -2024,7 +2024,7 @@ var functions = {
2024
2024
  syntax: "round( <rounding-strategy>?, <calc-sum>, <calc-sum> )"
2025
2025
  },
2026
2026
  saturate: {
2027
- syntax: "saturate( <number-percentage> )"
2027
+ syntax: "saturate( [ <number> | <percentage> ]? )"
2028
2028
  },
2029
2029
  scale: {
2030
2030
  syntax: "scale( [ <number> | <percentage> ]#{1,2} )"
@@ -2045,7 +2045,7 @@ var functions = {
2045
2045
  syntax: "scroll( [ <scroller> || <axis> ]? )"
2046
2046
  },
2047
2047
  sepia: {
2048
- syntax: "sepia( <number-percentage> )"
2048
+ syntax: "sepia( [ <number> | <percentage> ]? )"
2049
2049
  },
2050
2050
  sign: {
2051
2051
  syntax: "sign( <calc-sum> )"
@@ -2200,10 +2200,10 @@ var syntaxes = {
2200
2200
  syntax: "normal | multiply | screen | overlay | darken | lighten | color-dodge | color-burn | hard-light | soft-light | difference | exclusion | hue | saturation | color | luminosity"
2201
2201
  },
2202
2202
  "blur()": {
2203
- syntax: "blur( <length> )"
2203
+ syntax: "blur( <length>? )"
2204
2204
  },
2205
2205
  "brightness()": {
2206
- syntax: "brightness( <number-percentage> )"
2206
+ syntax: "brightness( [ <number> | <percentage> ]? )"
2207
2207
  },
2208
2208
  "calc()": {
2209
2209
  syntax: "calc( <calc-sum> )"
@@ -2245,7 +2245,13 @@ var syntaxes = {
2245
2245
  syntax: "<url>"
2246
2246
  },
2247
2247
  color: {
2248
- syntax: "<rgb()> | <rgba()> | <hsl()> | <hsla()> | <hwb()> | <lab()> | <lch()> | <oklab()> | <oklch()> | <color()> | <hex-color> | <named-color> | <system-color> | <deprecated-system-color> | currentcolor | transparent"
2248
+ syntax: "<color-base> | currentColor | <system-color> | <light-dark()> | <deprecated-system-color>"
2249
+ },
2250
+ "color-base": {
2251
+ syntax: "<hex-color> | <color-function> | <named-color> | <color-mix()> | transparent"
2252
+ },
2253
+ "color-function": {
2254
+ syntax: "<rgb()> | <rgba()> | <hsl()> | <hsla()> | <hwb()> | <lab()> | <lch()> | <oklab()> | <oklch()> | <color()>"
2249
2255
  },
2250
2256
  "color()": {
2251
2257
  syntax: "color( [from <color>]? <colorspace-params> [ / [ <alpha-value> | none ] ]? )"
@@ -2317,7 +2323,7 @@ var syntaxes = {
2317
2323
  syntax: "[ contextual | no-contextual ]"
2318
2324
  },
2319
2325
  "contrast()": {
2320
- syntax: "contrast( [ <number-percentage> ] )"
2326
+ syntax: "contrast( [ <number> | <percentage> ]? )"
2321
2327
  },
2322
2328
  "coord-box": {
2323
2329
  syntax: "<paint-box> | view-box"
@@ -2359,7 +2365,7 @@ var syntaxes = {
2359
2365
  syntax: "[ [ <length-percentage> | <number> ]+ ]#"
2360
2366
  },
2361
2367
  "deprecated-system-color": {
2362
- syntax: "ActiveBorder | ActiveCaption | AppWorkspace | Background | ButtonFace | ButtonHighlight | ButtonShadow | ButtonText | CaptionText | GrayText | Highlight | HighlightText | InactiveBorder | InactiveCaption | InactiveCaptionText | InfoBackground | InfoText | Menu | MenuText | Scrollbar | ThreeDDarkShadow | ThreeDFace | ThreeDHighlight | ThreeDLightShadow | ThreeDShadow | Window | WindowFrame | WindowText"
2368
+ syntax: "ActiveBorder | ActiveCaption | AppWorkspace | Background | ButtonHighlight | ButtonShadow | CaptionText | InactiveBorder | InactiveCaption | InactiveCaptionText | InfoBackground | InfoText | Menu | MenuText | Scrollbar | ThreeDDarkShadow | ThreeDFace | ThreeDHighlight | ThreeDLightShadow | ThreeDShadow | Window | WindowFrame | WindowText"
2363
2369
  },
2364
2370
  "discretionary-lig-values": {
2365
2371
  syntax: "[ discretionary-ligatures | no-discretionary-ligatures ]"
@@ -2383,7 +2389,7 @@ var syntaxes = {
2383
2389
  syntax: "block | inline | run-in"
2384
2390
  },
2385
2391
  "drop-shadow()": {
2386
- syntax: "drop-shadow( <length>{2,3} <color>? )"
2392
+ syntax: "drop-shadow( [ <color>? && <length>{2,3} ] )"
2387
2393
  },
2388
2394
  "easing-function": {
2389
2395
  syntax: "linear | <cubic-bezier-timing-function> | <step-timing-function>"
@@ -2436,9 +2442,6 @@ var syntaxes = {
2436
2442
  "feature-value-name": {
2437
2443
  syntax: "<custom-ident>"
2438
2444
  },
2439
- "fill-rule": {
2440
- syntax: "nonzero | evenodd"
2441
- },
2442
2445
  "filter-function": {
2443
2446
  syntax: "<blur()> | <brightness()> | <contrast()> | <drop-shadow()> | <grayscale()> | <hue-rotate()> | <invert()> | <opacity()> | <saturate()> | <sepia()>"
2444
2447
  },
@@ -2488,7 +2491,7 @@ var syntaxes = {
2488
2491
  syntax: "<linear-gradient()> | <repeating-linear-gradient()> | <radial-gradient()> | <repeating-radial-gradient()> | <conic-gradient()> | <repeating-conic-gradient()>"
2489
2492
  },
2490
2493
  "grayscale()": {
2491
- syntax: "grayscale( <number-percentage> )"
2494
+ syntax: "grayscale( [ <number> | <percentage> ]? )"
2492
2495
  },
2493
2496
  "grid-line": {
2494
2497
  syntax: "auto | <custom-ident> | [ <integer> && <custom-ident>? ] | [ span && [ <integer> || <custom-ident> ] ]"
@@ -2509,7 +2512,7 @@ var syntaxes = {
2509
2512
  syntax: "[ shorter | longer | increasing | decreasing ] hue"
2510
2513
  },
2511
2514
  "hue-rotate()": {
2512
- syntax: "hue-rotate( <angle> )"
2515
+ syntax: "hue-rotate( [ <angle> | <zero> ]? )"
2513
2516
  },
2514
2517
  "hwb()": {
2515
2518
  syntax: "hwb( [<hue> | none] [<percentage> | none] [<percentage> | none] [ / [<alpha-value> | none] ]? )"
@@ -2530,7 +2533,7 @@ var syntaxes = {
2530
2533
  syntax: "image-set( <image-set-option># )"
2531
2534
  },
2532
2535
  "image-set-option": {
2533
- syntax: "[ <image> | <string> ]x [ <resolution> || type(<string>) ]"
2536
+ syntax: "[ <image> | <string> ] [ <resolution> || type(<string>) ]"
2534
2537
  },
2535
2538
  "image-src": {
2536
2539
  syntax: "<url> | <string>"
@@ -2545,7 +2548,7 @@ var syntaxes = {
2545
2548
  syntax: "inset( <length-percentage>{1,4} [ round <'border-radius'> ]? )"
2546
2549
  },
2547
2550
  "invert()": {
2548
- syntax: "invert( <number-percentage> )"
2551
+ syntax: "invert( [ <number> | <percentage> ]? )"
2549
2552
  },
2550
2553
  "keyframe-block": {
2551
2554
  syntax: "<keyframe-selector># {\n <declaration-list>\n}"
@@ -2689,7 +2692,7 @@ var syntaxes = {
2689
2692
  syntax: "repeat( [ <integer [1,∞]> | auto-fill ], <line-names>+ )"
2690
2693
  },
2691
2694
  "named-color": {
2692
- syntax: "transparent | aliceblue | antiquewhite | aqua | aquamarine | azure | beige | bisque | black | blanchedalmond | blue | blueviolet | brown | burlywood | cadetblue | chartreuse | chocolate | coral | cornflowerblue | cornsilk | crimson | cyan | darkblue | darkcyan | darkgoldenrod | darkgray | darkgreen | darkgrey | darkkhaki | darkmagenta | darkolivegreen | darkorange | darkorchid | darkred | darksalmon | darkseagreen | darkslateblue | darkslategray | darkslategrey | darkturquoise | darkviolet | deeppink | deepskyblue | dimgray | dimgrey | dodgerblue | firebrick | floralwhite | forestgreen | fuchsia | gainsboro | ghostwhite | gold | goldenrod | gray | green | greenyellow | grey | honeydew | hotpink | indianred | indigo | ivory | khaki | lavender | lavenderblush | lawngreen | lemonchiffon | lightblue | lightcoral | lightcyan | lightgoldenrodyellow | lightgray | lightgreen | lightgrey | lightpink | lightsalmon | lightseagreen | lightskyblue | lightslategray | lightslategrey | lightsteelblue | lightyellow | lime | limegreen | linen | magenta | maroon | mediumaquamarine | mediumblue | mediumorchid | mediumpurple | mediumseagreen | mediumslateblue | mediumspringgreen | mediumturquoise | mediumvioletred | midnightblue | mintcream | mistyrose | moccasin | navajowhite | navy | oldlace | olive | olivedrab | orange | orangered | orchid | palegoldenrod | palegreen | paleturquoise | palevioletred | papayawhip | peachpuff | peru | pink | plum | powderblue | purple | rebeccapurple | red | rosybrown | royalblue | saddlebrown | salmon | sandybrown | seagreen | seashell | sienna | silver | skyblue | slateblue | slategray | slategrey | snow | springgreen | steelblue | tan | teal | thistle | tomato | turquoise | violet | wheat | white | whitesmoke | yellow | yellowgreen"
2695
+ syntax: "aliceblue | antiquewhite | aqua | aquamarine | azure | beige | bisque | black | blanchedalmond | blue | blueviolet | brown | burlywood | cadetblue | chartreuse | chocolate | coral | cornflowerblue | cornsilk | crimson | cyan | darkblue | darkcyan | darkgoldenrod | darkgray | darkgreen | darkgrey | darkkhaki | darkmagenta | darkolivegreen | darkorange | darkorchid | darkred | darksalmon | darkseagreen | darkslateblue | darkslategray | darkslategrey | darkturquoise | darkviolet | deeppink | deepskyblue | dimgray | dimgrey | dodgerblue | firebrick | floralwhite | forestgreen | fuchsia | gainsboro | ghostwhite | gold | goldenrod | gray | green | greenyellow | grey | honeydew | hotpink | indianred | indigo | ivory | khaki | lavender | lavenderblush | lawngreen | lemonchiffon | lightblue | lightcoral | lightcyan | lightgoldenrodyellow | lightgray | lightgreen | lightgrey | lightpink | lightsalmon | lightseagreen | lightskyblue | lightslategray | lightslategrey | lightsteelblue | lightyellow | lime | limegreen | linen | magenta | maroon | mediumaquamarine | mediumblue | mediumorchid | mediumpurple | mediumseagreen | mediumslateblue | mediumspringgreen | mediumturquoise | mediumvioletred | midnightblue | mintcream | mistyrose | moccasin | navajowhite | navy | oldlace | olive | olivedrab | orange | orangered | orchid | palegoldenrod | palegreen | paleturquoise | palevioletred | papayawhip | peachpuff | peru | pink | plum | powderblue | purple | rebeccapurple | red | rosybrown | royalblue | saddlebrown | salmon | sandybrown | seagreen | seashell | sienna | silver | skyblue | slateblue | slategray | slategrey | snow | springgreen | steelblue | tan | teal | thistle | tomato | turquoise | violet | wheat | white | whitesmoke | yellow | yellowgreen"
2693
2696
  },
2694
2697
  "namespace-prefix": {
2695
2698
  syntax: "<ident>"
@@ -2722,7 +2725,7 @@ var syntaxes = {
2722
2725
  syntax: "oklch( [ <percentage> | <number> | none] [ <percentage> | <number> | none] [ <hue> | none] [ / [<alpha-value> | none] ]? )"
2723
2726
  },
2724
2727
  "opacity()": {
2725
- syntax: "opacity( [ <number-percentage> ] )"
2728
+ syntax: "opacity( [ <number> | <percentage> ]? )"
2726
2729
  },
2727
2730
  "opacity-value": {
2728
2731
  syntax: "<number> | <percentage>"
@@ -2770,7 +2773,7 @@ var syntaxes = {
2770
2773
  syntax: "palette-mix(<color-interpolation-method> , [ [normal | light | dark | <palette-identifier> | <palette-mix()> ] && <percentage [0,100]>? ]#{2})"
2771
2774
  },
2772
2775
  "path()": {
2773
- syntax: "path( [ <fill-rule>, ]? <string> )"
2776
+ syntax: "path( <'fill-rule'>? , <string> )"
2774
2777
  },
2775
2778
  "perspective()": {
2776
2779
  syntax: "perspective( [ <length [0,∞]> | none ] )"
@@ -2779,7 +2782,7 @@ var syntaxes = {
2779
2782
  syntax: "hsl | hwb | lch | oklch"
2780
2783
  },
2781
2784
  "polygon()": {
2782
- syntax: "polygon( <fill-rule>? , [ <length-percentage> <length-percentage> ]# )"
2785
+ syntax: "polygon( <'fill-rule'>? , [ <length-percentage> <length-percentage> ]# )"
2783
2786
  },
2784
2787
  position: {
2785
2788
  syntax: "[ [ left | center | right ] || [ top | center | bottom ] | [ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ]? | [ [ left | right ] <length-percentage> ] && [ [ top | bottom ] <length-percentage> ] ]"
@@ -2878,7 +2881,7 @@ var syntaxes = {
2878
2881
  syntax: "nearest | up | down | to-zero"
2879
2882
  },
2880
2883
  "saturate()": {
2881
- syntax: "saturate( <number-percentage> )"
2884
+ syntax: "saturate( [ <number> | <percentage> ]? )"
2882
2885
  },
2883
2886
  "scale()": {
2884
2887
  syntax: "scale( [ <number> | <percentage> ]#{1,2} )"
@@ -2914,7 +2917,7 @@ var syntaxes = {
2914
2917
  syntax: "center | start | end | self-start | self-end | flex-start | flex-end"
2915
2918
  },
2916
2919
  "sepia()": {
2917
- syntax: "sepia( <number-percentage> )"
2920
+ syntax: "sepia( [ <number> | <percentage> ]? )"
2918
2921
  },
2919
2922
  shadow: {
2920
2923
  syntax: "inset? && <length>{2,4} && <color>?"
@@ -3479,19 +3482,103 @@ var atRules = {
3479
3482
  syntax: "@charset \"<charset>\";"
3480
3483
  },
3481
3484
  "@counter-style": {
3482
- syntax: "@counter-style <counter-style-name> {\n [ system: <counter-system>; ] ||\n [ symbols: <counter-symbols>; ] ||\n [ additive-symbols: <additive-symbols>; ] ||\n [ negative: <negative-symbol>; ] ||\n [ prefix: <prefix>; ] ||\n [ suffix: <suffix>; ] ||\n [ range: <range>; ] ||\n [ pad: <padding>; ] ||\n [ speak-as: <speak-as>; ] ||\n [ fallback: <counter-style-name>; ]\n}"
3485
+ syntax: "@counter-style <counter-style-name> {\n [ system: <counter-system>; ] ||\n [ symbols: <counter-symbols>; ] ||\n [ additive-symbols: <additive-symbols>; ] ||\n [ negative: <negative-symbol>; ] ||\n [ prefix: <prefix>; ] ||\n [ suffix: <suffix>; ] ||\n [ range: <range>; ] ||\n [ pad: <padding>; ] ||\n [ speak-as: <speak-as>; ] ||\n [ fallback: <counter-style-name>; ]\n}",
3486
+ descriptors: {
3487
+ "additive-symbols": {
3488
+ syntax: "[ <integer> && <symbol> ]#"
3489
+ },
3490
+ fallback: {
3491
+ syntax: "<counter-style-name>"
3492
+ },
3493
+ negative: {
3494
+ syntax: "<symbol> <symbol>?"
3495
+ },
3496
+ pad: {
3497
+ syntax: "<integer> && <symbol>"
3498
+ },
3499
+ prefix: {
3500
+ syntax: "<symbol>"
3501
+ },
3502
+ range: {
3503
+ syntax: "[ [ <integer> | infinite ]{2} ]# | auto"
3504
+ },
3505
+ "speak-as": {
3506
+ syntax: "auto | bullets | numbers | words | spell-out | <counter-style-name>"
3507
+ },
3508
+ suffix: {
3509
+ syntax: "<symbol>"
3510
+ },
3511
+ symbols: {
3512
+ syntax: "<symbol>+"
3513
+ },
3514
+ system: {
3515
+ syntax: "cyclic | numeric | alphabetic | symbolic | additive | [ fixed <integer>? ] | [ extends <counter-style-name> ]"
3516
+ }
3517
+ }
3483
3518
  },
3484
3519
  "@document": {
3485
3520
  syntax: "@document [ <url> | url-prefix(<string>) | domain(<string>) | media-document(<string>) | regexp(<string>) ]# {\n <group-rule-body>\n}"
3486
3521
  },
3487
3522
  "@font-face": {
3488
- syntax: "@font-face {\n [ font-family: <family-name>; ] ||\n [ src: <src>; ] ||\n [ unicode-range: <unicode-range>; ] ||\n [ font-variant: <font-variant>; ] ||\n [ font-feature-settings: <font-feature-settings>; ] ||\n [ font-variation-settings: <font-variation-settings>; ] ||\n [ font-stretch: <font-stretch>; ] ||\n [ font-weight: <font-weight>; ] ||\n [ font-style: <font-style>; ] ||\n [ size-adjust: <size-adjust>; ] ||\n [ ascent-override: <ascent-override>; ] ||\n [ descent-override: <descent-override>; ] ||\n [ line-gap-override: <line-gap-override>; ]\n}"
3523
+ syntax: "@font-face {\n [ font-family: <family-name>; ] ||\n [ src: <src>; ] ||\n [ unicode-range: <unicode-range>; ] ||\n [ font-variant: <font-variant>; ] ||\n [ font-feature-settings: <font-feature-settings>; ] ||\n [ font-variation-settings: <font-variation-settings>; ] ||\n [ font-stretch: <font-stretch>; ] ||\n [ font-weight: <font-weight>; ] ||\n [ font-style: <font-style>; ] ||\n [ size-adjust: <size-adjust>; ] ||\n [ ascent-override: <ascent-override>; ] ||\n [ descent-override: <descent-override>; ] ||\n [ line-gap-override: <line-gap-override>; ]\n}",
3524
+ descriptors: {
3525
+ "ascent-override": {
3526
+ syntax: "normal | <percentage>"
3527
+ },
3528
+ "descent-override": {
3529
+ syntax: "normal | <percentage>"
3530
+ },
3531
+ "font-display": {
3532
+ syntax: "[ auto | block | swap | fallback | optional ]"
3533
+ },
3534
+ "font-family": {
3535
+ syntax: "<family-name>"
3536
+ },
3537
+ "font-feature-settings": {
3538
+ syntax: "normal | <feature-tag-value>#"
3539
+ },
3540
+ "font-stretch": {
3541
+ syntax: "<font-stretch-absolute>{1,2}"
3542
+ },
3543
+ "font-style": {
3544
+ syntax: "normal | italic | oblique <angle>{0,2}"
3545
+ },
3546
+ "font-variation-settings": {
3547
+ syntax: "normal | [ <string> <number> ]#"
3548
+ },
3549
+ "font-weight": {
3550
+ syntax: "<font-weight-absolute>{1,2}"
3551
+ },
3552
+ "line-gap-override": {
3553
+ syntax: "normal | <percentage>"
3554
+ },
3555
+ "size-adjust": {
3556
+ syntax: "<percentage>"
3557
+ },
3558
+ src: {
3559
+ syntax: "[ <url> [ format( <string># ) ]? | local( <family-name> ) ]#"
3560
+ },
3561
+ "unicode-range": {
3562
+ syntax: "<unicode-range-token>#"
3563
+ }
3564
+ }
3489
3565
  },
3490
3566
  "@font-feature-values": {
3491
3567
  syntax: "@font-feature-values <family-name># {\n <feature-value-block-list>\n}"
3492
3568
  },
3493
3569
  "@font-palette-values": {
3494
- syntax: "@font-palette-values <dashed-ident> {\n <declaration-list>\n}"
3570
+ syntax: "@font-palette-values <dashed-ident> {\n <declaration-list>\n}",
3571
+ descriptors: {
3572
+ "base-palette": {
3573
+ syntax: "light | dark | <integer [0,∞]>"
3574
+ },
3575
+ "font-family": {
3576
+ syntax: "<family-name>#"
3577
+ },
3578
+ "override-colors": {
3579
+ syntax: "[ <integer [0,∞]> <color> ]#"
3580
+ }
3581
+ }
3495
3582
  },
3496
3583
  "@import": {
3497
3584
  syntax: "@import [ <string> | <url> ]\n [ layer | layer(<layer-name>) ]?\n [ supports( [ <supports-condition> | <declaration> ] ) ]?\n <media-query-list>? ;"
@@ -3509,13 +3596,38 @@ var atRules = {
3509
3596
  syntax: "@namespace <namespace-prefix>? [ <string> | <url> ];"
3510
3597
  },
3511
3598
  "@page": {
3512
- syntax: "@page <page-selector-list> {\n <page-body>\n}"
3599
+ syntax: "@page <page-selector-list> {\n <page-body>\n}",
3600
+ descriptors: {
3601
+ bleed: {
3602
+ syntax: "auto | <length>"
3603
+ },
3604
+ marks: {
3605
+ syntax: "none | [ crop || cross ]"
3606
+ },
3607
+ "page-orientation": {
3608
+ syntax: "upright | rotate-left | rotate-right "
3609
+ },
3610
+ size: {
3611
+ syntax: "<length>{1,2} | auto | [ <page-size> || [ portrait | landscape ] ]"
3612
+ }
3613
+ }
3513
3614
  },
3514
3615
  "@position-try": {
3515
3616
  syntax: "@position-try <dashed-ident> {\n <declaration-list>\n}"
3516
3617
  },
3517
3618
  "@property": {
3518
- syntax: "@property <custom-property-name> {\n <declaration-list>\n}"
3619
+ syntax: "@property <custom-property-name> {\n <declaration-list>\n}",
3620
+ descriptors: {
3621
+ inherits: {
3622
+ syntax: "true | false"
3623
+ },
3624
+ "initial-value": {
3625
+ syntax: "<declaration-value>?"
3626
+ },
3627
+ syntax: {
3628
+ syntax: "<string>"
3629
+ }
3630
+ }
3519
3631
  },
3520
3632
  "@scope": {
3521
3633
  syntax: "@scope [(<scope-start>)]? [to (<scope-end>)]? {\n <rule-list>\n}"
@@ -3527,7 +3639,15 @@ var atRules = {
3527
3639
  syntax: "@supports <supports-condition> {\n <group-rule-body>\n}"
3528
3640
  },
3529
3641
  "@view-transition": {
3530
- syntax: "@view-transition {\n <declaration-list>\n}"
3642
+ syntax: "@view-transition {\n <declaration-list>\n}",
3643
+ descriptors: {
3644
+ navigation: {
3645
+ syntax: "auto | none"
3646
+ },
3647
+ types: {
3648
+ syntax: "none | <custom-ident>+"
3649
+ }
3650
+ }
3531
3651
  }
3532
3652
  };
3533
3653
  var config = {
@@ -21,7 +21,9 @@ function validateDeclaration(declaration, options, root) {
21
21
  }
22
22
  // root is at-rule - check if declaration allowed
23
23
  if (root?.typ == EnumToken.AtRuleNodeType) {
24
+ //
24
25
  const syntax = getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, '@' + root.nam)?.[0];
26
+ // console.error({syntax});
25
27
  if (syntax != null) {
26
28
  if (!('chi' in syntax)) {
27
29
  return {
@@ -39,15 +41,36 @@ function validateDeclaration(declaration, options, root) {
39
41
  error: ''
40
42
  };
41
43
  }
42
- if (!(name in config.declarations) && !(name in config.syntaxes)) {
43
- return {
44
- valid: ValidationLevel.Drop,
45
- node: declaration,
46
- syntax: null,
47
- error: `unknown declaration "${declaration.nam}"`
48
- };
44
+ // console.error({syntax});
45
+ const config = getSyntaxConfig();
46
+ // @ts-ignore
47
+ const obj = config["atRules" /* ValidationSyntaxGroupEnum.AtRules */]['@' + root.nam];
48
+ if ('descriptors' in obj) {
49
+ const descriptors = obj.descriptors;
50
+ if (!(name in descriptors)) {
51
+ return {
52
+ valid: ValidationLevel.Drop,
53
+ node: declaration,
54
+ syntax: `<${declaration.nam}>`,
55
+ error: ` declaration <${declaration.nam}> is not allowed in <@${root.nam}>`
56
+ };
57
+ }
58
+ const syntax = getParsedSyntax("atRules" /* ValidationSyntaxGroupEnum.AtRules */, ['@' + root.nam, 'descriptors', name]);
59
+ return validateSyntax(syntax, declaration.val, root, options);
49
60
  }
50
- return validateSyntax(syntax.chi, [declaration], root, options);
61
+ // console.error({name});
62
+ // if (!(name in config.declarations) && !(name in config.syntaxes)) {
63
+ //
64
+ // return {
65
+ //
66
+ // valid: ValidationLevel.Drop,
67
+ // node: declaration,
68
+ // syntax: null,
69
+ // error: `unknown declaration "${declaration.nam}"`
70
+ // }
71
+ // }
72
+ //
73
+ // return validateSyntax((syntax as ValidationAtRuleDefinitionToken).chi as ValidationToken[], [declaration], root, options);
51
74
  }
52
75
  }
53
76
  if (name.startsWith('--')) {
@@ -62,10 +85,17 @@ function validateDeclaration(declaration, options, root) {
62
85
  return {
63
86
  valid: ValidationLevel.Drop,
64
87
  node: declaration,
65
- syntax: null,
88
+ syntax: `<${declaration.nam}>`,
66
89
  error: `unknown declaration "${declaration.nam}"`
67
90
  };
68
91
  }
92
+ // return {
93
+ //
94
+ // valid: ValidationLevel.Valid,
95
+ // node: declaration,
96
+ // syntax: null,
97
+ // error: ''
98
+ // }
69
99
  return validateSyntax(getParsedSyntax("declarations" /* ValidationSyntaxGroupEnum.Declarations */, name), declaration.val);
70
100
  }
71
101