zyzz 0.0.28 → 0.0.30

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 (302) hide show
  1. package/binding/wasi/wasi-worker.mjs +186 -0
  2. package/binding/wasi/zyzz.wasi.cjs +2302 -0
  3. package/binding/wasi/zyzz.wasm32-wasi.wasm +0 -0
  4. package/binding/zyzz.linux-x64-gnu.node +0 -0
  5. package/dist/babel/index.d.ts.map +1 -1
  6. package/dist/babel/index.js +2 -4
  7. package/dist/babel/index.js.map +1 -1
  8. package/dist/babel/internal/Compilation.d.ts +0 -1
  9. package/dist/babel/internal/Compilation.d.ts.map +1 -1
  10. package/dist/compiler/Graph.d.ts +14 -11
  11. package/dist/compiler/Graph.d.ts.map +1 -1
  12. package/dist/compiler/Graph.js +57 -1442
  13. package/dist/compiler/Graph.js.map +1 -1
  14. package/dist/compiler/Native.d.ts +7 -9
  15. package/dist/compiler/Native.d.ts.map +1 -1
  16. package/dist/compiler/Native.js +12 -716
  17. package/dist/compiler/Native.js.map +1 -1
  18. package/dist/compiler/Source.d.ts +122 -24
  19. package/dist/compiler/Source.d.ts.map +1 -1
  20. package/dist/compiler/Source.js +10 -1267
  21. package/dist/compiler/Source.js.map +1 -1
  22. package/dist/compiler/Transform.d.ts +4 -3
  23. package/dist/compiler/Transform.d.ts.map +1 -1
  24. package/dist/compiler/Transform.js +13 -961
  25. package/dist/compiler/Transform.js.map +1 -1
  26. package/dist/compiler/internal/AtRules.d.ts +5 -1
  27. package/dist/compiler/internal/AtRules.d.ts.map +1 -1
  28. package/dist/compiler/internal/AtRules.js +12 -106
  29. package/dist/compiler/internal/AtRules.js.map +1 -1
  30. package/dist/compiler/internal/Context.d.ts +11 -0
  31. package/dist/compiler/internal/Context.d.ts.map +1 -0
  32. package/dist/compiler/internal/Context.js +11 -0
  33. package/dist/compiler/internal/Context.js.map +1 -0
  34. package/dist/compiler/internal/Results.d.ts +148 -0
  35. package/dist/compiler/internal/Results.d.ts.map +1 -0
  36. package/dist/compiler/internal/Results.js +259 -0
  37. package/dist/compiler/internal/Results.js.map +1 -0
  38. package/dist/compiler/internal/Syntax.d.ts +0 -2
  39. package/dist/compiler/internal/Syntax.d.ts.map +1 -1
  40. package/dist/compiler/internal/Syntax.js +0 -2
  41. package/dist/compiler/internal/Syntax.js.map +1 -1
  42. package/dist/compiler/internal/Wire.d.ts +17 -0
  43. package/dist/compiler/internal/Wire.d.ts.map +1 -0
  44. package/dist/compiler/internal/Wire.js +795 -0
  45. package/dist/compiler/internal/Wire.js.map +1 -0
  46. package/dist/internal/Addon.d.ts +28 -0
  47. package/dist/internal/Addon.d.ts.map +1 -0
  48. package/dist/internal/Addon.js +87 -0
  49. package/dist/internal/Addon.js.map +1 -0
  50. package/dist/internal/Literal.d.ts +4 -1
  51. package/dist/internal/Literal.d.ts.map +1 -1
  52. package/dist/internal/Literal.js +4 -2
  53. package/dist/internal/Literal.js.map +1 -1
  54. package/dist/internal/Token.d.ts +2 -1
  55. package/dist/internal/Token.d.ts.map +1 -1
  56. package/dist/internal/Token.js +2 -2
  57. package/dist/internal/Token.js.map +1 -1
  58. package/dist/internal/Vlq.d.ts +14 -0
  59. package/dist/internal/Vlq.d.ts.map +1 -0
  60. package/dist/internal/Vlq.js +47 -0
  61. package/dist/internal/Vlq.js.map +1 -0
  62. package/dist/internal/Wasm.d.ts +22 -0
  63. package/dist/internal/Wasm.d.ts.map +1 -0
  64. package/dist/internal/Wasm.js +83 -0
  65. package/dist/internal/Wasm.js.map +1 -0
  66. package/dist/metro/Graph.d.ts +0 -1
  67. package/dist/metro/Graph.d.ts.map +1 -1
  68. package/dist/metro/transformer.d.ts.map +1 -1
  69. package/dist/metro/transformer.js +0 -1
  70. package/dist/metro/transformer.js.map +1 -1
  71. package/dist/next/internal/Project.d.ts.map +1 -1
  72. package/dist/next/internal/Project.js +2 -5
  73. package/dist/next/internal/Project.js.map +1 -1
  74. package/dist/node/Host.d.ts.map +1 -1
  75. package/dist/node/Host.js +0 -2
  76. package/dist/node/Host.js.map +1 -1
  77. package/dist/node/internal/Contracts.d.ts.map +1 -1
  78. package/dist/node/internal/Contracts.js +3 -7
  79. package/dist/node/internal/Contracts.js.map +1 -1
  80. package/dist/node/internal/Snapshot.d.ts +0 -1
  81. package/dist/node/internal/Snapshot.d.ts.map +1 -1
  82. package/dist/node/internal/Snapshot.js +0 -6
  83. package/dist/node/internal/Snapshot.js.map +1 -1
  84. package/dist/runtime/Composition.d.ts +2 -3
  85. package/dist/runtime/Composition.d.ts.map +1 -1
  86. package/dist/runtime/Composition.js +51 -30
  87. package/dist/runtime/Composition.js.map +1 -1
  88. package/dist/runtime/Recipe.d.ts.map +1 -1
  89. package/dist/runtime/Recipe.js +16 -12
  90. package/dist/runtime/Recipe.js.map +1 -1
  91. package/dist/unplugin/index.d.ts.map +1 -1
  92. package/dist/unplugin/index.js +3 -6
  93. package/dist/unplugin/index.js.map +1 -1
  94. package/dist/vite/index.d.ts.map +1 -1
  95. package/dist/vite/index.js +696 -201
  96. package/dist/vite/index.js.map +1 -1
  97. package/dist/web/Css.d.ts +8 -3
  98. package/dist/web/Css.d.ts.map +1 -1
  99. package/dist/web/Css.js +5 -721
  100. package/dist/web/Css.js.map +1 -1
  101. package/dist/web/internal/Block.d.ts +0 -2
  102. package/dist/web/internal/Block.d.ts.map +1 -1
  103. package/dist/web/internal/Block.js +1 -12
  104. package/dist/web/internal/Block.js.map +1 -1
  105. package/dist/web/internal/ClassName.d.ts +23 -18
  106. package/dist/web/internal/ClassName.d.ts.map +1 -1
  107. package/dist/web/internal/ClassName.js +26 -55
  108. package/dist/web/internal/ClassName.js.map +1 -1
  109. package/dist/web/internal/Contributions.d.ts +3 -5
  110. package/dist/web/internal/Contributions.d.ts.map +1 -1
  111. package/dist/web/internal/Contributions.js +0 -45
  112. package/dist/web/internal/Contributions.js.map +1 -1
  113. package/dist/web/internal/Engine.browser.d.ts +8 -0
  114. package/dist/web/internal/Engine.browser.d.ts.map +1 -0
  115. package/dist/web/internal/Engine.browser.js +42 -0
  116. package/dist/web/internal/Engine.browser.js.map +1 -0
  117. package/dist/web/internal/Engine.d.ts +9 -0
  118. package/dist/web/internal/Engine.d.ts.map +1 -0
  119. package/dist/web/internal/Engine.js +14 -0
  120. package/dist/web/internal/Engine.js.map +1 -0
  121. package/dist/web/internal/Themes.d.ts +1 -9
  122. package/dist/web/internal/Themes.d.ts.map +1 -1
  123. package/dist/web/internal/Themes.js +3 -221
  124. package/dist/web/internal/Themes.js.map +1 -1
  125. package/dist/web/internal/Wasm.generated.d.ts +4 -0
  126. package/dist/web/internal/Wasm.generated.d.ts.map +1 -0
  127. package/dist/web/internal/Wasm.generated.js +4 -0
  128. package/dist/web/internal/Wasm.generated.js.map +1 -0
  129. package/dist/web/internal/Wire.d.ts +19 -0
  130. package/dist/web/internal/Wire.d.ts.map +1 -0
  131. package/dist/web/internal/Wire.js +387 -0
  132. package/dist/web/internal/Wire.js.map +1 -0
  133. package/package.json +20 -1
  134. package/src/babel/index.ts +2 -5
  135. package/src/babel/internal/Compilation.ts +0 -1
  136. package/src/compiler/Graph.ts +89 -1930
  137. package/src/compiler/Native.ts +18 -871
  138. package/src/compiler/Source.ts +144 -1803
  139. package/src/compiler/Transform.ts +16 -1315
  140. package/src/compiler/internal/AtRules.ts +27 -115
  141. package/src/compiler/internal/Context.ts +11 -0
  142. package/src/compiler/internal/Results.ts +406 -0
  143. package/src/compiler/internal/Syntax.ts +0 -3
  144. package/src/compiler/internal/Wire.ts +1045 -0
  145. package/src/internal/Addon.ts +118 -0
  146. package/src/internal/Literal.ts +4 -2
  147. package/src/internal/Token.ts +2 -2
  148. package/src/internal/Vlq.ts +59 -0
  149. package/src/internal/Wasm.ts +111 -0
  150. package/src/metro/transformer.ts +0 -1
  151. package/src/next/internal/Project.ts +2 -9
  152. package/src/node/Host.ts +0 -2
  153. package/src/node/internal/Contracts.ts +3 -7
  154. package/src/node/internal/Snapshot.ts +0 -8
  155. package/src/runtime/Composition.ts +48 -25
  156. package/src/runtime/Recipe.ts +21 -14
  157. package/src/unplugin/index.ts +6 -6
  158. package/src/vite/index.ts +922 -221
  159. package/src/web/Css.ts +12 -908
  160. package/src/web/internal/Block.ts +0 -14
  161. package/src/web/internal/ClassName.ts +52 -85
  162. package/src/web/internal/Contributions.ts +3 -59
  163. package/src/web/internal/Engine.browser.ts +51 -0
  164. package/src/web/internal/Engine.ts +17 -0
  165. package/src/web/internal/Themes.ts +3 -279
  166. package/src/web/internal/Wasm.generated.ts +3 -0
  167. package/src/web/internal/Wire.ts +466 -0
  168. package/src/web/internal/wasm.d.ts +9 -0
  169. package/dist/compiler/internal/Applications.d.ts +0 -55
  170. package/dist/compiler/internal/Applications.d.ts.map +0 -1
  171. package/dist/compiler/internal/Applications.js +0 -393
  172. package/dist/compiler/internal/Applications.js.map +0 -1
  173. package/dist/compiler/internal/ColorProfiles.d.ts +0 -3
  174. package/dist/compiler/internal/ColorProfiles.d.ts.map +0 -1
  175. package/dist/compiler/internal/ColorProfiles.js +0 -84
  176. package/dist/compiler/internal/ColorProfiles.js.map +0 -1
  177. package/dist/compiler/internal/CompositionBindings.d.ts +0 -16
  178. package/dist/compiler/internal/CompositionBindings.d.ts.map +0 -1
  179. package/dist/compiler/internal/CompositionBindings.js +0 -89
  180. package/dist/compiler/internal/CompositionBindings.js.map +0 -1
  181. package/dist/compiler/internal/Compositions.d.ts +0 -37
  182. package/dist/compiler/internal/Compositions.d.ts.map +0 -1
  183. package/dist/compiler/internal/Compositions.js +0 -494
  184. package/dist/compiler/internal/Compositions.js.map +0 -1
  185. package/dist/compiler/internal/Configurations.d.ts +0 -26
  186. package/dist/compiler/internal/Configurations.d.ts.map +0 -1
  187. package/dist/compiler/internal/Configurations.js +0 -259
  188. package/dist/compiler/internal/Configurations.js.map +0 -1
  189. package/dist/compiler/internal/Contract.d.ts +0 -30
  190. package/dist/compiler/internal/Contract.d.ts.map +0 -1
  191. package/dist/compiler/internal/Contract.js +0 -753
  192. package/dist/compiler/internal/Contract.js.map +0 -1
  193. package/dist/compiler/internal/Contributions.d.ts +0 -54
  194. package/dist/compiler/internal/Contributions.d.ts.map +0 -1
  195. package/dist/compiler/internal/Contributions.js +0 -1151
  196. package/dist/compiler/internal/Contributions.js.map +0 -1
  197. package/dist/compiler/internal/Descriptors.d.ts +0 -15
  198. package/dist/compiler/internal/Descriptors.d.ts.map +0 -1
  199. package/dist/compiler/internal/Descriptors.js +0 -192
  200. package/dist/compiler/internal/Descriptors.js.map +0 -1
  201. package/dist/compiler/internal/Dynamic.d.ts +0 -14
  202. package/dist/compiler/internal/Dynamic.d.ts.map +0 -1
  203. package/dist/compiler/internal/Dynamic.js +0 -175
  204. package/dist/compiler/internal/Dynamic.js.map +0 -1
  205. package/dist/compiler/internal/Expression.d.ts +0 -19
  206. package/dist/compiler/internal/Expression.d.ts.map +0 -1
  207. package/dist/compiler/internal/Expression.js +0 -164
  208. package/dist/compiler/internal/Expression.js.map +0 -1
  209. package/dist/compiler/internal/Functions.d.ts +0 -5
  210. package/dist/compiler/internal/Functions.d.ts.map +0 -1
  211. package/dist/compiler/internal/Functions.js +0 -191
  212. package/dist/compiler/internal/Functions.js.map +0 -1
  213. package/dist/compiler/internal/Keyframes.d.ts +0 -5
  214. package/dist/compiler/internal/Keyframes.d.ts.map +0 -1
  215. package/dist/compiler/internal/Keyframes.js +0 -51
  216. package/dist/compiler/internal/Keyframes.js.map +0 -1
  217. package/dist/compiler/internal/Names.d.ts +0 -5
  218. package/dist/compiler/internal/Names.d.ts.map +0 -1
  219. package/dist/compiler/internal/Names.js +0 -37
  220. package/dist/compiler/internal/Names.js.map +0 -1
  221. package/dist/compiler/internal/NativeBindings.d.ts +0 -72
  222. package/dist/compiler/internal/NativeBindings.d.ts.map +0 -1
  223. package/dist/compiler/internal/NativeBindings.js +0 -171
  224. package/dist/compiler/internal/NativeBindings.js.map +0 -1
  225. package/dist/compiler/internal/NativeMedia.d.ts +0 -14
  226. package/dist/compiler/internal/NativeMedia.d.ts.map +0 -1
  227. package/dist/compiler/internal/NativeMedia.js +0 -287
  228. package/dist/compiler/internal/NativeMedia.js.map +0 -1
  229. package/dist/compiler/internal/NativeVars.d.ts +0 -28
  230. package/dist/compiler/internal/NativeVars.d.ts.map +0 -1
  231. package/dist/compiler/internal/NativeVars.js +0 -160
  232. package/dist/compiler/internal/NativeVars.js.map +0 -1
  233. package/dist/compiler/internal/PackedStyles.d.ts +0 -37
  234. package/dist/compiler/internal/PackedStyles.d.ts.map +0 -1
  235. package/dist/compiler/internal/PackedStyles.js +0 -344
  236. package/dist/compiler/internal/PackedStyles.js.map +0 -1
  237. package/dist/compiler/internal/Properties.d.ts +0 -5
  238. package/dist/compiler/internal/Properties.d.ts.map +0 -1
  239. package/dist/compiler/internal/Properties.js +0 -82
  240. package/dist/compiler/internal/Properties.js.map +0 -1
  241. package/dist/compiler/internal/RecipeConditions.d.ts +0 -41
  242. package/dist/compiler/internal/RecipeConditions.d.ts.map +0 -1
  243. package/dist/compiler/internal/RecipeConditions.js +0 -82
  244. package/dist/compiler/internal/RecipeConditions.js.map +0 -1
  245. package/dist/compiler/internal/RecipePayloads.d.ts +0 -31
  246. package/dist/compiler/internal/RecipePayloads.d.ts.map +0 -1
  247. package/dist/compiler/internal/RecipePayloads.js +0 -99
  248. package/dist/compiler/internal/RecipePayloads.js.map +0 -1
  249. package/dist/compiler/internal/Recipes.d.ts +0 -32
  250. package/dist/compiler/internal/Recipes.d.ts.map +0 -1
  251. package/dist/compiler/internal/Recipes.js +0 -339
  252. package/dist/compiler/internal/Recipes.js.map +0 -1
  253. package/dist/compiler/internal/Selectors.d.ts +0 -13
  254. package/dist/compiler/internal/Selectors.d.ts.map +0 -1
  255. package/dist/compiler/internal/Selectors.js +0 -280
  256. package/dist/compiler/internal/Selectors.js.map +0 -1
  257. package/dist/compiler/internal/Static.d.ts +0 -39
  258. package/dist/compiler/internal/Static.d.ts.map +0 -1
  259. package/dist/compiler/internal/Static.js +0 -534
  260. package/dist/compiler/internal/Static.js.map +0 -1
  261. package/dist/compiler/internal/Themes.d.ts +0 -190
  262. package/dist/compiler/internal/Themes.d.ts.map +0 -1
  263. package/dist/compiler/internal/Themes.js +0 -1577
  264. package/dist/compiler/internal/Themes.js.map +0 -1
  265. package/dist/compiler/internal/Vars.d.ts +0 -33
  266. package/dist/compiler/internal/Vars.d.ts.map +0 -1
  267. package/dist/compiler/internal/Vars.js +0 -387
  268. package/dist/compiler/internal/Vars.js.map +0 -1
  269. package/dist/compiler/internal/ViewTransitions.d.ts +0 -3
  270. package/dist/compiler/internal/ViewTransitions.d.ts.map +0 -1
  271. package/dist/compiler/internal/ViewTransitions.js +0 -68
  272. package/dist/compiler/internal/ViewTransitions.js.map +0 -1
  273. package/dist/internal/Cascade.d.ts +0 -74
  274. package/dist/internal/Cascade.d.ts.map +0 -1
  275. package/dist/internal/Cascade.js +0 -210
  276. package/dist/internal/Cascade.js.map +0 -1
  277. package/src/compiler/internal/Applications.ts +0 -610
  278. package/src/compiler/internal/ColorProfiles.ts +0 -93
  279. package/src/compiler/internal/CompositionBindings.ts +0 -120
  280. package/src/compiler/internal/Compositions.ts +0 -678
  281. package/src/compiler/internal/Configurations.ts +0 -349
  282. package/src/compiler/internal/Contract.ts +0 -1028
  283. package/src/compiler/internal/Contributions.ts +0 -1561
  284. package/src/compiler/internal/Descriptors.ts +0 -242
  285. package/src/compiler/internal/Dynamic.ts +0 -275
  286. package/src/compiler/internal/Expression.ts +0 -218
  287. package/src/compiler/internal/Functions.ts +0 -206
  288. package/src/compiler/internal/Keyframes.ts +0 -62
  289. package/src/compiler/internal/Names.ts +0 -48
  290. package/src/compiler/internal/NativeBindings.ts +0 -235
  291. package/src/compiler/internal/NativeMedia.ts +0 -342
  292. package/src/compiler/internal/NativeVars.ts +0 -231
  293. package/src/compiler/internal/PackedStyles.ts +0 -473
  294. package/src/compiler/internal/Properties.ts +0 -121
  295. package/src/compiler/internal/RecipeConditions.ts +0 -139
  296. package/src/compiler/internal/RecipePayloads.ts +0 -132
  297. package/src/compiler/internal/Recipes.ts +0 -531
  298. package/src/compiler/internal/Selectors.ts +0 -353
  299. package/src/compiler/internal/Static.ts +0 -784
  300. package/src/compiler/internal/Themes.ts +0 -2398
  301. package/src/compiler/internal/Vars.ts +0 -516
  302. package/src/compiler/internal/ViewTransitions.ts +0 -82
@@ -1,242 +0,0 @@
1
- /** Validates descriptor grammars independently of the output parser's error recovery. @module */
2
- import * as Lightning from 'lightningcss'
3
- import * as Tree from 'css-tree'
4
-
5
- /** Checks one authored descriptor before it can introduce another CSS declaration. */
6
- export function check(options: check.Options): void {
7
- const name = options.name.replace(
8
- /[A-Z]/g,
9
- (letter) => `-${letter.toLowerCase()}`,
10
- )
11
- // The pinned parser predates this page descriptor.
12
- const result =
13
- options.rule === 'page' && name === 'page-margin-safety'
14
- ? Tree.lexer.match('none | clamp | add', options.value)
15
- : Tree.lexer.matchAtruleDescriptor(options.rule, name, options.value)
16
- if (result.error)
17
- throw new Error(`Invalid @${options.rule} ${name}: ${result.error.message}`)
18
- if (
19
- options.rule === 'page' &&
20
- ['bleed', 'size'].includes(name) &&
21
- /(?:calc|min|max|clamp)\(/i.test(options.value)
22
- )
23
- Lightning.transform({
24
- filename: 'page.css',
25
- code: new TextEncoder().encode(
26
- `@property --page-length {syntax: "<length>${name === 'size' ? '+' : ''}"; inherits: false; initial-value: ${options.value};}`,
27
- ),
28
- })
29
- }
30
-
31
- /** Checks a native custom-media query before statement serialization. */
32
- export function media(query: string): void {
33
- const result = Tree.lexer.matchAtrulePrelude('media', query)
34
- if (result.error)
35
- throw new Error(`Invalid custom-media query: ${result.error.message}`)
36
- }
37
-
38
- /** Authored descriptor grammar input. */
39
- export declare namespace check {
40
- type Options = {
41
- readonly name: string
42
- readonly rule: string
43
- readonly value: string
44
- }
45
- }
46
-
47
- /** Reviews every declaration in standard named descriptor rules. */
48
- export function validate(source: string): void {
49
- const sheet = Tree.parse(source)
50
- Tree.walk(sheet, {
51
- visit: 'Atrule',
52
- enter(rule) {
53
- const name = rule.name.toLowerCase()
54
- if (name === 'document') {
55
- if (!rule.block || !rule.prelude)
56
- throw new Error(
57
- 'Document rules require matching functions and a block.',
58
- )
59
- const result = Tree.lexer.matchAtrulePrelude(
60
- 'document',
61
- Tree.generate(rule.prelude),
62
- )
63
- if (result.error)
64
- throw new Error(
65
- `Invalid document matching functions: ${result.error.message}`,
66
- )
67
- return
68
- }
69
- if (name === 'custom-media') {
70
- if (rule.block || !rule.prelude)
71
- throw new Error(
72
- 'Custom-media requires a name and query without a block.',
73
- )
74
- const prelude = Tree.generate(rule.prelude)
75
- let first: { type: number; start: number; end: number } | undefined
76
- Tree.tokenize(prelude, (type, start, end) => {
77
- if (
78
- !first &&
79
- type !== Tree.tokenTypes.WhiteSpace &&
80
- type !== Tree.tokenTypes.Comment
81
- )
82
- first = { type, start, end }
83
- })
84
- const name = first
85
- ? Tree.ident.decode(prelude.slice(first.start, first.end))
86
- : ''
87
- if (
88
- first?.type !== Tree.tokenTypes.Ident ||
89
- !name.startsWith('--') ||
90
- name.length <= 2
91
- )
92
- throw new Error('Custom-media requires a dashed name and query.')
93
- media(prelude.slice(first.end).trim())
94
- return
95
- }
96
- if (name === 'page') {
97
- const prelude = rule.prelude ? Tree.generate(rule.prelude) : ''
98
- const result = Tree.lexer.matchAtrulePrelude('page', prelude)
99
- if (result.error)
100
- throw new Error(`Invalid page selector: ${result.error.message}`)
101
- if (!rule.block) throw new Error('Page rules require a block.')
102
- rule.block.children.forEach((declaration) => {
103
- if (declaration.type !== 'Declaration') return
104
- if (
105
- [
106
- 'bleed',
107
- 'marks',
108
- 'page-margin-safety',
109
- 'page-orientation',
110
- 'size',
111
- ].includes(declaration.property)
112
- )
113
- check({
114
- rule: 'page',
115
- name: declaration.property,
116
- value: Tree.generate(declaration.value),
117
- })
118
- })
119
- return
120
- }
121
- if (!['counter-style', 'font-face', 'font-palette-values'].includes(name))
122
- return
123
- if (!rule.block) throw new Error(`Expected @${name} descriptors.`)
124
- const prelude = rule.prelude ? Tree.generate(rule.prelude) : ''
125
- const match = Tree.lexer.matchAtrulePrelude(name, prelude)
126
- if (match.error)
127
- throw new Error(`Invalid @${name} prelude: ${match.error.message}`)
128
- const declarations = new Map<string, Tree.Value>()
129
- rule.block.children.forEach((declaration) => {
130
- if (declaration.type !== 'Declaration' || declaration.important)
131
- throw new Error(`Expected non-important @${name} descriptors.`)
132
- const value = Tree.generate(declaration.value)
133
- const parsed = Tree.parse(value, { context: 'value' }) as Tree.Value
134
- const result = Tree.lexer.matchAtruleDescriptor(
135
- name,
136
- declaration.property,
137
- parsed,
138
- )
139
- if (result.error)
140
- throw new Error(
141
- `Invalid @${name} ${declaration.property}: ${result.error.message}`,
142
- )
143
- declarations.set(declaration.property.toLowerCase(), parsed)
144
- if (name === 'font-face') {
145
- const key = declaration.property.toLowerCase()
146
- parsed.children.forEach((node) => {
147
- if (
148
- node.type === 'Percentage' &&
149
- [
150
- 'size-adjust',
151
- 'ascent-override',
152
- 'descent-override',
153
- 'line-gap-override',
154
- 'font-stretch',
155
- ].includes(key) &&
156
- Number(node.value) < 0
157
- )
158
- throw new Error(`@font-face ${key} cannot be negative.`)
159
- if (
160
- key === 'font-weight' &&
161
- node.type === 'Number' &&
162
- (Number(node.value) < 1 || Number(node.value) > 1000)
163
- )
164
- throw new Error('Font weight must be between 1 and 1000.')
165
- })
166
- }
167
-
168
- if (
169
- name === 'font-palette-values' &&
170
- declaration.property === 'override-colors'
171
- )
172
- Tree.walk(parsed, (node) => {
173
- if (
174
- result
175
- .getTrace(node)
176
- ?.some(
177
- (syntax) =>
178
- 'type' in syntax &&
179
- 'name' in syntax &&
180
- typeof syntax.name === 'string' &&
181
- ((syntax.type === 'Keyword' &&
182
- syntax.name.toLowerCase() === 'currentcolor') ||
183
- (syntax.type === 'Type' &&
184
- [
185
- 'system-color',
186
- 'light-dark()',
187
- 'light-dark-color',
188
- 'contrast-color()',
189
- 'device-cmyk()',
190
- ].includes(syntax.name))),
191
- )
192
- )
193
- throw new Error('Palette overrides require absolute colors.')
194
- })
195
- })
196
- if (name === 'counter-style') {
197
- const systemNode = declarations.get('system')?.children.first
198
- const system =
199
- systemNode?.type === 'Identifier'
200
- ? Tree.ident.decode(systemNode.name).toLowerCase()
201
- : 'symbolic'
202
- const symbols = declarations.get('symbols')?.children.size ?? 0
203
- if (system === 'numeric' || system === 'alphabetic') {
204
- if (symbols < 2)
205
- throw new Error(
206
- 'Numeric and alphabetic counters require at least two symbols.',
207
- )
208
- } else if (system === 'additive') {
209
- if (!declarations.has('additive-symbols'))
210
- throw new Error('Additive counters require additive symbols.')
211
- } else if (system !== 'extends' && !symbols)
212
- throw new Error('Counter systems require at least one symbol.')
213
- const additive = declarations.get('additive-symbols')
214
- if (additive) {
215
- let previous = Infinity
216
- additive.children.forEach((node) => {
217
- if (node.type !== 'Number') return
218
- const weight = Number(node.value)
219
- if (weight >= previous)
220
- throw new Error('Additive symbol weights must strictly descend.')
221
- previous = weight
222
- })
223
- }
224
- const range = declarations.get('range')
225
- if (range) {
226
- const bounds: number[] = []
227
- range.children.forEach((node) => {
228
- if (node.type === 'Number') bounds.push(Number(node.value))
229
- else if (
230
- node.type === 'Identifier' &&
231
- Tree.ident.decode(node.name).toLowerCase() === 'infinite'
232
- )
233
- bounds.push(bounds.length % 2 ? Infinity : -Infinity)
234
- })
235
- for (let index = 0; index < bounds.length; index += 2)
236
- if (bounds[index]! > bounds[index + 1]!)
237
- throw new Error('Counter ranges must have increasing bounds.')
238
- }
239
- }
240
- },
241
- })
242
- }
@@ -1,275 +0,0 @@
1
- /** Extracts typed callback slots and static object bodies without invoking callbacks. @module */
2
- import type * as Ast from '@oxc-project/types'
3
- import * as Binding from '../../internal/Binding.js'
4
- import * as Identity from '../../internal/Identity.js'
5
- import * as Expression from './Expression.js'
6
- import * as Literal from '../../internal/Literal.js'
7
- import * as Themes from './Themes.js'
8
-
9
- /** Fixed callback input slots retained in generated callables. */
10
- export type Slots = Readonly<Record<string, Binding.Reference>>
11
-
12
- /** Reads a finite explicitly typed parameter and a concise static object body. */
13
- export function read(
14
- node: Ast.Node,
15
- identity: string,
16
- resolveType: (node: Ast.Node) => Ast.Node = (node) => node,
17
- ) {
18
- node = Expression.unwrap(node)
19
-
20
- if (node.type !== 'ArrowFunctionExpression') return undefined
21
-
22
- if (node.async || node.params.length !== 1)
23
- throw new Themes.InvalidError(
24
- 'Dynamic styles require one typed values parameter.',
25
- node,
26
- )
27
-
28
- const parameter = node.params[0]!
29
- if (parameter.type !== 'Identifier' || !parameter.typeAnnotation)
30
- throw new Themes.InvalidError(
31
- 'Dynamic styles require an explicit finite object type on the values parameter.',
32
- parameter,
33
- )
34
-
35
- const fields = resolveType(parameter.typeAnnotation.typeAnnotation)
36
- if (fields.type !== 'TSTypeLiteral')
37
- throw new Themes.InvalidError(
38
- 'Dynamic styles require a finite object type.',
39
- parameter,
40
- )
41
-
42
- const parameterName = parameter.name
43
- const slots: Record<string, Binding.Reference> = Object.create(null)
44
- const numeric = new Map<Binding.Reference, readonly number[]>()
45
-
46
- for (const member of fields.members) {
47
- const key =
48
- member.type === 'TSPropertySignature'
49
- ? member.key.type === 'Identifier'
50
- ? member.key.name
51
- : member.key.type === 'Literal' &&
52
- typeof member.key.value === 'string'
53
- ? member.key.value
54
- : undefined
55
- : undefined
56
- if (
57
- member.type !== 'TSPropertySignature' ||
58
- member.computed ||
59
- member.optional ||
60
- !member.typeAnnotation ||
61
- key === undefined ||
62
- [
63
- 'class',
64
- 'className',
65
- 'key',
66
- 'ref',
67
- 'style',
68
- 'vars',
69
- '__proto__',
70
- ].includes(key) ||
71
- Object.hasOwn(slots, key)
72
- )
73
- throw new Themes.InvalidError(
74
- 'Dynamic values require unique required scalar fields without styling override keys.',
75
- member,
76
- )
77
-
78
- const type = resolveType(member.typeAnnotation.typeAnnotation)
79
- const kind = scalar(type)
80
- if (!kind)
81
- throw new Themes.InvalidError(
82
- 'Dynamic values require explicit string or number scalar types.',
83
- member,
84
- )
85
-
86
- const slot = (slots[key] = Object.freeze(
87
- Object.defineProperty(
88
- {
89
- name: Identity.slot(identity, key),
90
- type: kind === 'number' ? ('number' as const) : ('length' as const),
91
- ...(kind === 'zero-string' ? { zero: true } : {}),
92
- variable: true as const,
93
- },
94
- Binding.dynamic,
95
- { value: true },
96
- ),
97
- ))
98
-
99
- const values = numbers(type)
100
-
101
- if (values) numeric.set(slot, values)
102
- }
103
-
104
- const body = Expression.unwrap(node.body)
105
- if (body.type !== 'ObjectExpression')
106
- throw new Themes.InvalidError(
107
- 'Dynamic styles require a concise static object body.',
108
- node.body,
109
- )
110
-
111
- function resolve(node: Ast.Node): Binding.Reference | undefined {
112
- node = Expression.unwrap(node)
113
-
114
- if (
115
- node.type !== 'MemberExpression' ||
116
- node.object.type !== 'Identifier' ||
117
- node.object.name !== parameterName
118
- )
119
- return undefined
120
-
121
- const key = (() => {
122
- if (node.property.type === 'Identifier' && !node.computed)
123
- return node.property.name
124
-
125
- if (
126
- node.property.type === 'Literal' &&
127
- node.computed &&
128
- typeof node.property.value === 'string'
129
- )
130
- return node.property.value
131
-
132
- return undefined
133
- })()
134
-
135
- const slot = key === undefined ? undefined : slots[key]
136
- if (!slot || node.optional)
137
- throw new Themes.InvalidError(
138
- 'Dynamic reads require declared scalar fields without optional access.',
139
- node,
140
- )
141
-
142
- return slot
143
- }
144
-
145
- return {
146
- body,
147
- accepts(reference: Binding.Reference, property: string) {
148
- const values = numeric.get(reference)
149
- const rule = Literal.rules[property as keyof typeof Literal.rules]
150
- if (!values || !rule) return false
151
-
152
- if (rule.kind === 'grid-line')
153
- return values.every(
154
- (value) => Number.isSafeInteger(value) && value !== 0,
155
- )
156
-
157
- // Native conversion rejects degenerate and negative ratios.
158
- if (rule.kind === 'ratio')
159
- return values.every((value) => Number.isFinite(value) && value > 0)
160
-
161
- if (rule.kind !== 'number') return false
162
-
163
- return values.every(
164
- (value) =>
165
- (!('integer' in rule) ||
166
- !rule.integer ||
167
- Number.isSafeInteger(value)) &&
168
- (!('min' in rule) || value >= rule.min) &&
169
- (!('max' in rule) || value <= rule.max),
170
- )
171
- },
172
- resolve,
173
- slots: Object.freeze(slots),
174
- type: parameter.typeAnnotation.typeAnnotation,
175
- }
176
- }
177
-
178
- function scalar(
179
- node: Ast.Node,
180
- ): 'number' | 'string' | 'zero-string' | undefined {
181
- if (node.type === 'TSIntersectionType') {
182
- const kinds = node.types.map(scalar)
183
-
184
- return kinds.length && kinds.every((kind) => kind === kinds[0])
185
- ? kinds[0]
186
- : undefined
187
- }
188
-
189
- if (node.type === 'TSNumberKeyword') return 'number'
190
- if (node.type === 'TSStringKeyword') return 'string'
191
-
192
- if (
193
- node.type === 'TSTemplateLiteralType' &&
194
- node.types.every((type) => scalar(type) !== undefined) &&
195
- node.quasis.every((part) => !part.value.raw.includes('!'))
196
- )
197
- return 'string'
198
-
199
- if (node.type === 'TSLiteralType') {
200
- if (numbers(node)) return 'number'
201
-
202
- if (
203
- node.literal.type === 'Literal' &&
204
- typeof node.literal.value === 'number'
205
- )
206
- return 'number'
207
-
208
- if (
209
- node.literal.type === 'Literal' &&
210
- typeof node.literal.value === 'string' &&
211
- !node.literal.value.includes('!') &&
212
- !['initial', 'inherit', 'unset', 'revert', 'revert-layer'].includes(
213
- node.literal.value.trim().toLowerCase(),
214
- )
215
- )
216
- return 'string'
217
- }
218
-
219
- if (node.type === 'TSUnionType') {
220
- const kinds = node.types.map(scalar)
221
- if (
222
- kinds.some((kind) => kind === 'string' || kind === 'zero-string') &&
223
- node.types.every(
224
- (type, index) =>
225
- kinds[index] === 'string' ||
226
- kinds[index] === 'zero-string' ||
227
- numbers(type)?.every((value) => value === 0),
228
- )
229
- )
230
- return 'zero-string'
231
-
232
- if (kinds.length && kinds.every((kind) => kind === kinds[0]))
233
- return kinds[0]
234
- }
235
-
236
- return undefined
237
- }
238
-
239
- function numbers(node: Ast.Node): readonly number[] | undefined {
240
- if (node.type === 'TSIntersectionType') {
241
- const domains = node.types
242
- .filter((type) => type.type !== 'TSNumberKeyword')
243
- .map(numbers)
244
- if (!domains.length || domains.some((domain) => domain === undefined))
245
- return undefined
246
-
247
- return domains[0]!.filter((value) =>
248
- domains.every((domain) => domain!.includes(value)),
249
- )
250
- }
251
-
252
- if (node.type === 'TSUnionType') {
253
- const members = node.types.map(numbers)
254
-
255
- return members.every((member) => member !== undefined)
256
- ? members.flat()
257
- : undefined
258
- }
259
-
260
- if (node.type !== 'TSLiteralType') return undefined
261
-
262
- const literal = node.literal
263
- if (literal.type === 'Literal' && typeof literal.value === 'number')
264
- return [literal.value]
265
-
266
- if (
267
- literal.type === 'UnaryExpression' &&
268
- literal.operator === '-' &&
269
- literal.argument.type === 'Literal' &&
270
- typeof literal.argument.value === 'number'
271
- )
272
- return [-literal.argument.value]
273
-
274
- return undefined
275
- }