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,218 +0,0 @@
1
- /**
2
- * Reads static template primitives and transparent TypeScript syntax without execution.
3
- * @module
4
- */
5
- import type * as Ast from '@oxc-project/types'
6
- import * as Binding from '../../internal/Binding.js'
7
- import * as Literal from '../../internal/Literal.js'
8
- import * as Token from '../../internal/Token.js'
9
- import * as Tree from 'css-tree'
10
-
11
- /** Checks color substitutions inside compound CSS values without widening direct reference domains. */
12
- export function acceptsColor(
13
- expression: Token.Expression,
14
- property: keyof Literal.Properties,
15
- ): boolean {
16
- const value = expression.parts
17
- .map((part) => {
18
- if (typeof part === 'string') return part
19
- if (Binding.is(part) ? part.type === 'color' : part.group === 'color')
20
- return 'rgb(1 2 3)'
21
- return 'var(--zyzz-reference)'
22
- })
23
- .join('')
24
- .replace(/(?: !custom)?(?: !important)?$/, '')
25
-
26
- try {
27
- return (
28
- Tree.lexer.matchProperty(Literal.name(property), value).error === null
29
- )
30
- } catch {
31
- return false
32
- }
33
- }
34
-
35
- /** Validates explicit variable substitutions in compound values, including every conditional fallback. */
36
- export function acceptsVariables(
37
- expression: Token.Expression,
38
- property: keyof Literal.Properties,
39
- ): boolean {
40
- if (
41
- !['filter', 'backdropFilter', 'boxShadow', 'textShadow'].includes(property)
42
- )
43
- return false
44
- function values(value: Token.Value): readonly string[] {
45
- if (Token.is(value)) return values(value.value)
46
- if (typeof value === 'object') return Object.values(value).flatMap(values)
47
- return [String(value)]
48
- }
49
- let candidates = ['']
50
- for (const part of expression.parts) {
51
- if (Binding.is(part)) return false
52
- const alternatives = typeof part === 'string' ? [part] : values(part.value)
53
- // Bound combinations of independent responsive variables before grammar checks.
54
- if (candidates.length * alternatives.length > 256) return false
55
- candidates = candidates.flatMap((prefix) =>
56
- alternatives.map((value) => prefix + value),
57
- )
58
- }
59
- try {
60
- return candidates.every(
61
- (value) =>
62
- Tree.lexer.matchProperty(
63
- Literal.name(property),
64
- value.replace(/(?: !custom)?(?: !important)?$/, ''),
65
- ).error === null,
66
- )
67
- } catch {
68
- return false
69
- }
70
- }
71
-
72
- /** Checks every identifier-token branch before its value becomes a CSS variable. */
73
- export function acceptsIdentifier(
74
- reference: Token.Reference,
75
- property: keyof Literal.Properties,
76
- ): boolean {
77
- function check(value: Token.Value): boolean {
78
- if (Token.is(value)) return check(value.value)
79
- if (typeof value === 'object') return Object.values(value).every(check)
80
- try {
81
- return (
82
- Tree.lexer.matchProperty(Literal.name(property), String(value))
83
- .error === null
84
- )
85
- } catch {
86
- return false
87
- }
88
- }
89
- return check(reference.value)
90
- }
91
-
92
- /** Folds cooked template text and literal primitive substitutions; unresolved syntax returns undefined. */
93
- export function template(
94
- node: Ast.TemplateLiteral,
95
- depth = 0,
96
- resolve?: (
97
- node: Ast.Node,
98
- prefix: string,
99
- ) => string | Token.Reference | Binding.Reference | undefined,
100
- context = '',
101
- ): string | Token.Expression | undefined {
102
- if (depth >= 128) return undefined
103
-
104
- const parts: (string | Token.Reference | Binding.Reference)[] = []
105
-
106
- for (const [index, quasi] of node.quasis.entries()) {
107
- if (quasi.value.cooked === null) return undefined
108
-
109
- parts.push(quasi.value.cooked)
110
-
111
- const expression = node.expressions[index]
112
- if (!expression) continue
113
-
114
- const value = unwrap(expression)
115
- const prefix =
116
- context +
117
- parts
118
- .map((part) =>
119
- typeof part === 'string' ? part : 'var(--zyzz-expression)',
120
- )
121
- .join('')
122
- const reference = resolve?.(expression, prefix) ?? resolve?.(value, prefix)
123
-
124
- if (reference) {
125
- if (
126
- quoted(
127
- parts
128
- .filter((part): part is string => typeof part === 'string')
129
- .join(''),
130
- )
131
- )
132
- return undefined
133
-
134
- // var() substitutions must remain whole CSS tokens.
135
- if (
136
- /[%a-zA-Z_\d.-]/.test(
137
- node.quasis[index + 1]?.value.cooked?.[0] ?? '',
138
- ) ||
139
- /[\w.#@+\\-]$/.test(quasi.value.cooked)
140
- )
141
- return undefined
142
-
143
- parts.push(reference)
144
- } else if (value.type === 'Literal' && !('regex' in value)) {
145
- if (typeof value.value === 'number' && !Number.isFinite(value.value))
146
- return undefined
147
-
148
- parts.push(String(value.value))
149
- } else if (
150
- value.type === 'UnaryExpression' &&
151
- (value.operator === '-' || value.operator === '+') &&
152
- value.argument.type === 'Literal' &&
153
- typeof value.argument.value === 'number' &&
154
- Number.isFinite(value.argument.value)
155
- ) {
156
- parts.push(
157
- String(
158
- value.operator === '-' ? -value.argument.value : value.argument.value,
159
- ),
160
- )
161
- } else if (
162
- value.type === 'UnaryExpression' &&
163
- value.operator === '-' &&
164
- value.argument.type === 'Literal' &&
165
- typeof value.argument.value === 'bigint'
166
- ) {
167
- parts.push(String(-value.argument.value))
168
- } else if (value.type === 'TemplateLiteral') {
169
- const nested = template(value, depth + 1, resolve, prefix)
170
- if (nested === undefined) return undefined
171
-
172
- if (typeof nested === 'string') parts.push(nested)
173
- else parts.push(...nested.parts)
174
- } else return undefined
175
- }
176
-
177
- return parts.every((part) => typeof part === 'string')
178
- ? parts.join('')
179
- : Token.compose(parts)
180
- }
181
-
182
- /** Returns the expression beneath assertions without evaluating application code. */
183
- export function unwrap(node: Ast.Node): Ast.Node {
184
- while (
185
- node.type === 'TSAsExpression' ||
186
- node.type === 'TSSatisfiesExpression' ||
187
- node.type === 'TSNonNullExpression' ||
188
- node.type === 'TSTypeAssertion'
189
- )
190
- node = node.expression
191
-
192
- return node
193
- }
194
-
195
- function quoted(text: string): boolean {
196
- let quote = ''
197
-
198
- for (let index = 0; index < text.length; index++) {
199
- const char = text[index]!
200
-
201
- if (char === '\\') {
202
- index++
203
- continue
204
- }
205
-
206
- if (quote) {
207
- if (char === quote) quote = ''
208
- } else if (char === '"' || char === "'") quote = char
209
- else if (char === '/' && text[index + 1] === '*') {
210
- const end = text.indexOf('*/', index + 2)
211
- if (end < 0) return true
212
-
213
- index = end + 1
214
- }
215
- }
216
-
217
- return !!quote
218
- }
@@ -1,206 +0,0 @@
1
- /** Checks CSS function arguments and defaults against native syntax definitions. @module */
2
- import * as FunctionSyntax from '../../internal/FunctionSyntax.js'
3
- import * as Lightning from 'lightningcss'
4
- import * as Tree from 'css-tree'
5
-
6
- /** Checks complete static values while leaving computed substitutions to CSS. */
7
- export function value(syntax: string, input: string): string | undefined {
8
- const text = input.trim()
9
- const body =
10
- text.startsWith('{') && text.endsWith('}') ? text.slice(1, -1) : text
11
- const parsed = Tree.parse(body, { context: 'value' })
12
- let computed = false
13
- Tree.walk(parsed, (node) => {
14
- if (
15
- node.type === 'Function' &&
16
- /^(?:--|var$|env$|attr$)/i.test(Tree.ident.decode(node.name))
17
- )
18
- computed = true
19
- })
20
- const normalized = syntax.trim()
21
- const definition = normalized.startsWith('type(')
22
- ? normalized.slice(5, -1).trim()
23
- : normalized
24
- if (computed || definition === '*') return
25
- const alternatives: string[] = []
26
- let start = 0
27
- Tree.tokenize(definition, (type, from, to) => {
28
- if (type === Tree.tokenTypes.Delim && definition.slice(from, to) === '|') {
29
- alternatives.push(definition.slice(start, from).trim())
30
- start = to
31
- }
32
- })
33
- alternatives.push(definition.slice(start).trim())
34
- for (const alternative of alternatives) {
35
- try {
36
- if (alternative.startsWith('<')) {
37
- if (alternative.startsWith('<string>')) {
38
- if (Tree.lexer.match(alternative, body).error) continue
39
- } else
40
- Lightning.transform({
41
- filename: 'argument.css',
42
- code: new TextEncoder().encode(
43
- `@property --argument{syntax:${JSON.stringify(alternative)};inherits:false;initial-value:${body};}`,
44
- ),
45
- })
46
- return alternative
47
- }
48
- let multiplier = ''
49
- let atom = alternative
50
- Tree.tokenize(alternative, (type, from, to) => {
51
- if (
52
- type === Tree.tokenTypes.Delim &&
53
- to === alternative.length &&
54
- ['+', '#'].includes(alternative.slice(from, to))
55
- ) {
56
- multiplier = alternative.slice(from, to)
57
- atom = alternative.slice(0, from)
58
- }
59
- })
60
- const expected = Tree.ident.decode(atom)
61
- const nodes = (parsed as Tree.Value).children.toArray()
62
- let count = 0
63
- let comma = false
64
- let valid = true
65
- for (const node of nodes) {
66
- if (
67
- node.type === 'Operator' &&
68
- node.value === ',' &&
69
- multiplier === '#' &&
70
- count > 0 &&
71
- !comma
72
- ) {
73
- comma = true
74
- continue
75
- }
76
- if (
77
- node.type !== 'Identifier' ||
78
- Tree.ident.decode(node.name) !== expected ||
79
- (count > 0 && (multiplier === '' || (multiplier === '#' && !comma)))
80
- ) {
81
- valid = false
82
- break
83
- }
84
- count++
85
- comma = false
86
- }
87
- if (valid && count > 0 && !comma) return alternative
88
- } catch {
89
- /* Another syntax alternative may accept this value. */
90
- }
91
- }
92
- throw new Error('Invalid CSS function argument for its declared syntax.')
93
- }
94
-
95
- /** Validates packed function headers and body contexts before parser recovery. */
96
- export function validate(source: string): void {
97
- Tree.walk(Tree.parse(source), {
98
- visit: 'Atrule',
99
- enter(rule) {
100
- if (rule.name.toLowerCase() !== 'function') return
101
- if (!rule.prelude || !rule.block)
102
- throw new Error('CSS functions require parameters and a body.')
103
- const prelude = Tree.generate(rule.prelude)
104
- let opening = 0
105
- let closing = -1
106
- let depth = 0
107
- const commas: number[] = []
108
- Tree.tokenize(prelude, (type, start, end) => {
109
- if (closing >= 0) return
110
- if (
111
- type === Tree.tokenTypes.Function ||
112
- type === Tree.tokenTypes.LeftParenthesis
113
- ) {
114
- if (depth === 0) {
115
- const name = Tree.ident.decode(prelude.slice(start, end - 1))
116
- if (
117
- start !== 0 ||
118
- type !== Tree.tokenTypes.Function ||
119
- !name.startsWith('--') ||
120
- name.length <= 2
121
- )
122
- throw new Error('CSS function names require a dashed identifier.')
123
- opening = end
124
- }
125
- depth++
126
- } else if (type === Tree.tokenTypes.RightParenthesis) {
127
- depth--
128
- if (depth === 0) closing = start
129
- } else if (type === Tree.tokenTypes.Comma && depth === 1)
130
- commas.push(start)
131
- })
132
- if (closing < 0) throw new Error('Unclosed CSS function parameters.')
133
- const names = new Set<string>()
134
- let start = opening
135
- for (const end of [...commas, closing]) {
136
- const parameter = prelude.slice(start, end).trim()
137
- start = end + 1
138
- if (!parameter && end === closing && opening === closing) continue
139
- let name = ''
140
- let offset = 0
141
- let colon = -1
142
- let depth = 0
143
- Tree.tokenize(parameter, (type, from, to) => {
144
- if (from === 0 && type === Tree.tokenTypes.Ident) {
145
- name = Tree.ident.decode(parameter.slice(from, to))
146
- offset = to
147
- }
148
- if (
149
- type === Tree.tokenTypes.Function ||
150
- type === Tree.tokenTypes.LeftParenthesis
151
- )
152
- depth++
153
- if (type === Tree.tokenTypes.RightParenthesis) depth--
154
- if (type === Tree.tokenTypes.Colon && depth === 0 && colon < 0)
155
- colon = from
156
- })
157
- if (!name.startsWith('--') || name.length <= 2 || names.has(name))
158
- throw new Error(
159
- 'CSS function parameters require unique dashed names.',
160
- )
161
- names.add(name)
162
- const syntax =
163
- parameter.slice(offset, colon < 0 ? undefined : colon).trim() || '*'
164
- if (!FunctionSyntax.accepts(syntax))
165
- throw new Error('Invalid CSS function parameter syntax.')
166
- if (colon >= 0) value(syntax, parameter.slice(colon + 1))
167
- }
168
- const returns = prelude.slice(closing + 1).trim()
169
- if (
170
- returns &&
171
- (!returns.startsWith('returns ') ||
172
- !FunctionSyntax.accepts(returns.slice(8)))
173
- )
174
- throw new Error('Invalid CSS function return syntax.')
175
- function body(block: Tree.Block): void {
176
- const declarations = Tree.parse(Tree.generate(block).slice(1, -1), {
177
- context: 'declarationList',
178
- }) as Tree.DeclarationList
179
- declarations.children.forEach((node) => {
180
- if (
181
- node.type === 'Atrule' &&
182
- ['media', 'supports', 'container'].includes(node.name) &&
183
- node.block &&
184
- node.prelude
185
- ) {
186
- if (
187
- Tree.lexer.matchAtrulePrelude(
188
- node.name,
189
- Tree.generate(node.prelude),
190
- ).error
191
- )
192
- throw new Error('Invalid CSS function condition.')
193
- body(node.block)
194
- } else if (
195
- node.type === 'Declaration' &&
196
- !node.important &&
197
- (node.property === 'result' || node.property.startsWith('--'))
198
- ) {
199
- value('*', Tree.generate(node.value))
200
- } else throw new Error('Invalid CSS function body context.')
201
- })
202
- }
203
- body(rule.block)
204
- },
205
- })
206
- }
@@ -1,62 +0,0 @@
1
- /** Checks complete keyframe selectors, including named timeline ranges. @module */
2
- import * as Lightning from 'lightningcss'
3
-
4
- /** Rejects invalid ordinary offsets and importance in transported keyframes. */
5
- export function validate(source: string): void {
6
- Lightning.transform({
7
- filename: 'keyframes.css',
8
- code: new TextEncoder().encode(source),
9
- visitor: {
10
- Rule(rule) {
11
- if (rule.type !== 'keyframes') return
12
- for (const frame of rule.value.keyframes) {
13
- if (
14
- frame.selectors.some(
15
- (selector) =>
16
- selector.type === 'percentage' &&
17
- (selector.value < 0 || selector.value > 1),
18
- )
19
- )
20
- throw new Error('Ordinary keyframe offsets must be within 0–100%.')
21
- if (frame.declarations.importantDeclarations?.length)
22
- throw new Error('Keyframes forbid important declarations.')
23
- }
24
- },
25
- },
26
- })
27
- }
28
-
29
- /** Named timeline percentages are unrestricted; ordinary offsets remain within 0–100%. */
30
- export function accepts(selector: string): boolean {
31
- try {
32
- let valid = false
33
- Lightning.transform({
34
- filename: 'keyframe.css',
35
- code: new TextEncoder().encode(
36
- `@keyframes zyzz {${selector}{opacity:0}}`,
37
- ),
38
- visitor: {
39
- StyleSheet(sheet) {
40
- const rule = sheet.rules[0]
41
- if (
42
- sheet.rules.length !== 1 ||
43
- rule?.type !== 'keyframes' ||
44
- rule.value.keyframes.length !== 1
45
- )
46
- return
47
- const frame = rule.value.keyframes[0]!
48
- valid =
49
- frame.selectors.length > 0 &&
50
- frame.selectors.every(
51
- (selector) =>
52
- selector.type !== 'percentage' ||
53
- (selector.value >= 0 && selector.value <= 1),
54
- )
55
- },
56
- },
57
- })
58
- return valid
59
- } catch {
60
- return false
61
- }
62
- }
@@ -1,48 +0,0 @@
1
- /** Derives emitted names from authored bindings rather than source locations. @module */
2
- import type * as Ast from '@oxc-project/types'
3
- import * as Walker from 'oxc-walker'
4
- import * as Identity from '../../internal/Identity.js'
5
-
6
- /** Collects readable declaration paths for calls in constants and namespaces. */
7
- export function collect(program: Ast.Program): ReadonlyMap<number, string> {
8
- const names = new Map<number, string>()
9
- const ancestors: Ast.Node[] = []
10
-
11
- Walker.walk(program, {
12
- enter(node) {
13
- if (node.type === 'CallExpression') {
14
- const parts: string[] = []
15
- for (const ancestor of ancestors) {
16
- if (
17
- ancestor.type === 'TSModuleDeclaration' &&
18
- ancestor.id.type === 'Identifier'
19
- )
20
- parts.push(ancestor.id.name)
21
- if (
22
- ancestor.type === 'VariableDeclarator' &&
23
- ancestor.id.type === 'Identifier'
24
- )
25
- parts.push(ancestor.id.name)
26
- if (ancestor.type === 'Property' && !ancestor.computed) {
27
- if (ancestor.key.type === 'Identifier')
28
- parts.push(ancestor.key.name)
29
- else if (ancestor.key.type === 'Literal')
30
- parts.push(String(ancestor.key.value))
31
- }
32
- if (ancestor.type === 'FunctionDeclaration' && ancestor.id)
33
- parts.push(ancestor.id.name)
34
- }
35
- names.set(
36
- node.start,
37
- parts.length ? parts.map(Identity.name).join('-') : 'style',
38
- )
39
- }
40
- ancestors.push(node)
41
- },
42
- leave() {
43
- ancestors.pop()
44
- },
45
- })
46
-
47
- return names
48
- }