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.
- package/binding/wasi/wasi-worker.mjs +186 -0
- package/binding/wasi/zyzz.wasi.cjs +2302 -0
- package/binding/wasi/zyzz.wasm32-wasi.wasm +0 -0
- package/binding/zyzz.linux-x64-gnu.node +0 -0
- package/dist/babel/index.d.ts.map +1 -1
- package/dist/babel/index.js +2 -4
- package/dist/babel/index.js.map +1 -1
- package/dist/babel/internal/Compilation.d.ts +0 -1
- package/dist/babel/internal/Compilation.d.ts.map +1 -1
- package/dist/compiler/Graph.d.ts +14 -11
- package/dist/compiler/Graph.d.ts.map +1 -1
- package/dist/compiler/Graph.js +57 -1442
- package/dist/compiler/Graph.js.map +1 -1
- package/dist/compiler/Native.d.ts +7 -9
- package/dist/compiler/Native.d.ts.map +1 -1
- package/dist/compiler/Native.js +12 -716
- package/dist/compiler/Native.js.map +1 -1
- package/dist/compiler/Source.d.ts +122 -24
- package/dist/compiler/Source.d.ts.map +1 -1
- package/dist/compiler/Source.js +10 -1267
- package/dist/compiler/Source.js.map +1 -1
- package/dist/compiler/Transform.d.ts +4 -3
- package/dist/compiler/Transform.d.ts.map +1 -1
- package/dist/compiler/Transform.js +13 -961
- package/dist/compiler/Transform.js.map +1 -1
- package/dist/compiler/internal/AtRules.d.ts +5 -1
- package/dist/compiler/internal/AtRules.d.ts.map +1 -1
- package/dist/compiler/internal/AtRules.js +12 -106
- package/dist/compiler/internal/AtRules.js.map +1 -1
- package/dist/compiler/internal/Context.d.ts +11 -0
- package/dist/compiler/internal/Context.d.ts.map +1 -0
- package/dist/compiler/internal/Context.js +11 -0
- package/dist/compiler/internal/Context.js.map +1 -0
- package/dist/compiler/internal/Results.d.ts +148 -0
- package/dist/compiler/internal/Results.d.ts.map +1 -0
- package/dist/compiler/internal/Results.js +259 -0
- package/dist/compiler/internal/Results.js.map +1 -0
- package/dist/compiler/internal/Syntax.d.ts +0 -2
- package/dist/compiler/internal/Syntax.d.ts.map +1 -1
- package/dist/compiler/internal/Syntax.js +0 -2
- package/dist/compiler/internal/Syntax.js.map +1 -1
- package/dist/compiler/internal/Wire.d.ts +17 -0
- package/dist/compiler/internal/Wire.d.ts.map +1 -0
- package/dist/compiler/internal/Wire.js +795 -0
- package/dist/compiler/internal/Wire.js.map +1 -0
- package/dist/internal/Addon.d.ts +28 -0
- package/dist/internal/Addon.d.ts.map +1 -0
- package/dist/internal/Addon.js +87 -0
- package/dist/internal/Addon.js.map +1 -0
- package/dist/internal/Literal.d.ts +4 -1
- package/dist/internal/Literal.d.ts.map +1 -1
- package/dist/internal/Literal.js +4 -2
- package/dist/internal/Literal.js.map +1 -1
- package/dist/internal/Token.d.ts +2 -1
- package/dist/internal/Token.d.ts.map +1 -1
- package/dist/internal/Token.js +2 -2
- package/dist/internal/Token.js.map +1 -1
- package/dist/internal/Vlq.d.ts +14 -0
- package/dist/internal/Vlq.d.ts.map +1 -0
- package/dist/internal/Vlq.js +47 -0
- package/dist/internal/Vlq.js.map +1 -0
- package/dist/internal/Wasm.d.ts +22 -0
- package/dist/internal/Wasm.d.ts.map +1 -0
- package/dist/internal/Wasm.js +83 -0
- package/dist/internal/Wasm.js.map +1 -0
- package/dist/metro/Graph.d.ts +0 -1
- package/dist/metro/Graph.d.ts.map +1 -1
- package/dist/metro/transformer.d.ts.map +1 -1
- package/dist/metro/transformer.js +0 -1
- package/dist/metro/transformer.js.map +1 -1
- package/dist/next/internal/Project.d.ts.map +1 -1
- package/dist/next/internal/Project.js +2 -5
- package/dist/next/internal/Project.js.map +1 -1
- package/dist/node/Host.d.ts.map +1 -1
- package/dist/node/Host.js +0 -2
- package/dist/node/Host.js.map +1 -1
- package/dist/node/internal/Contracts.d.ts.map +1 -1
- package/dist/node/internal/Contracts.js +3 -7
- package/dist/node/internal/Contracts.js.map +1 -1
- package/dist/node/internal/Snapshot.d.ts +0 -1
- package/dist/node/internal/Snapshot.d.ts.map +1 -1
- package/dist/node/internal/Snapshot.js +0 -6
- package/dist/node/internal/Snapshot.js.map +1 -1
- package/dist/runtime/Composition.d.ts +2 -3
- package/dist/runtime/Composition.d.ts.map +1 -1
- package/dist/runtime/Composition.js +51 -30
- package/dist/runtime/Composition.js.map +1 -1
- package/dist/runtime/Recipe.d.ts.map +1 -1
- package/dist/runtime/Recipe.js +16 -12
- package/dist/runtime/Recipe.js.map +1 -1
- package/dist/unplugin/index.d.ts.map +1 -1
- package/dist/unplugin/index.js +3 -6
- package/dist/unplugin/index.js.map +1 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +696 -201
- package/dist/vite/index.js.map +1 -1
- package/dist/web/Css.d.ts +8 -3
- package/dist/web/Css.d.ts.map +1 -1
- package/dist/web/Css.js +5 -721
- package/dist/web/Css.js.map +1 -1
- package/dist/web/internal/Block.d.ts +0 -2
- package/dist/web/internal/Block.d.ts.map +1 -1
- package/dist/web/internal/Block.js +1 -12
- package/dist/web/internal/Block.js.map +1 -1
- package/dist/web/internal/ClassName.d.ts +23 -18
- package/dist/web/internal/ClassName.d.ts.map +1 -1
- package/dist/web/internal/ClassName.js +26 -55
- package/dist/web/internal/ClassName.js.map +1 -1
- package/dist/web/internal/Contributions.d.ts +3 -5
- package/dist/web/internal/Contributions.d.ts.map +1 -1
- package/dist/web/internal/Contributions.js +0 -45
- package/dist/web/internal/Contributions.js.map +1 -1
- package/dist/web/internal/Engine.browser.d.ts +8 -0
- package/dist/web/internal/Engine.browser.d.ts.map +1 -0
- package/dist/web/internal/Engine.browser.js +42 -0
- package/dist/web/internal/Engine.browser.js.map +1 -0
- package/dist/web/internal/Engine.d.ts +9 -0
- package/dist/web/internal/Engine.d.ts.map +1 -0
- package/dist/web/internal/Engine.js +14 -0
- package/dist/web/internal/Engine.js.map +1 -0
- package/dist/web/internal/Themes.d.ts +1 -9
- package/dist/web/internal/Themes.d.ts.map +1 -1
- package/dist/web/internal/Themes.js +3 -221
- package/dist/web/internal/Themes.js.map +1 -1
- package/dist/web/internal/Wasm.generated.d.ts +4 -0
- package/dist/web/internal/Wasm.generated.d.ts.map +1 -0
- package/dist/web/internal/Wasm.generated.js +4 -0
- package/dist/web/internal/Wasm.generated.js.map +1 -0
- package/dist/web/internal/Wire.d.ts +19 -0
- package/dist/web/internal/Wire.d.ts.map +1 -0
- package/dist/web/internal/Wire.js +387 -0
- package/dist/web/internal/Wire.js.map +1 -0
- package/package.json +20 -1
- package/src/babel/index.ts +2 -5
- package/src/babel/internal/Compilation.ts +0 -1
- package/src/compiler/Graph.ts +89 -1930
- package/src/compiler/Native.ts +18 -871
- package/src/compiler/Source.ts +144 -1803
- package/src/compiler/Transform.ts +16 -1315
- package/src/compiler/internal/AtRules.ts +27 -115
- package/src/compiler/internal/Context.ts +11 -0
- package/src/compiler/internal/Results.ts +406 -0
- package/src/compiler/internal/Syntax.ts +0 -3
- package/src/compiler/internal/Wire.ts +1045 -0
- package/src/internal/Addon.ts +118 -0
- package/src/internal/Literal.ts +4 -2
- package/src/internal/Token.ts +2 -2
- package/src/internal/Vlq.ts +59 -0
- package/src/internal/Wasm.ts +111 -0
- package/src/metro/transformer.ts +0 -1
- package/src/next/internal/Project.ts +2 -9
- package/src/node/Host.ts +0 -2
- package/src/node/internal/Contracts.ts +3 -7
- package/src/node/internal/Snapshot.ts +0 -8
- package/src/runtime/Composition.ts +48 -25
- package/src/runtime/Recipe.ts +21 -14
- package/src/unplugin/index.ts +6 -6
- package/src/vite/index.ts +922 -221
- package/src/web/Css.ts +12 -908
- package/src/web/internal/Block.ts +0 -14
- package/src/web/internal/ClassName.ts +52 -85
- package/src/web/internal/Contributions.ts +3 -59
- package/src/web/internal/Engine.browser.ts +51 -0
- package/src/web/internal/Engine.ts +17 -0
- package/src/web/internal/Themes.ts +3 -279
- package/src/web/internal/Wasm.generated.ts +3 -0
- package/src/web/internal/Wire.ts +466 -0
- package/src/web/internal/wasm.d.ts +9 -0
- package/dist/compiler/internal/Applications.d.ts +0 -55
- package/dist/compiler/internal/Applications.d.ts.map +0 -1
- package/dist/compiler/internal/Applications.js +0 -393
- package/dist/compiler/internal/Applications.js.map +0 -1
- package/dist/compiler/internal/ColorProfiles.d.ts +0 -3
- package/dist/compiler/internal/ColorProfiles.d.ts.map +0 -1
- package/dist/compiler/internal/ColorProfiles.js +0 -84
- package/dist/compiler/internal/ColorProfiles.js.map +0 -1
- package/dist/compiler/internal/CompositionBindings.d.ts +0 -16
- package/dist/compiler/internal/CompositionBindings.d.ts.map +0 -1
- package/dist/compiler/internal/CompositionBindings.js +0 -89
- package/dist/compiler/internal/CompositionBindings.js.map +0 -1
- package/dist/compiler/internal/Compositions.d.ts +0 -37
- package/dist/compiler/internal/Compositions.d.ts.map +0 -1
- package/dist/compiler/internal/Compositions.js +0 -494
- package/dist/compiler/internal/Compositions.js.map +0 -1
- package/dist/compiler/internal/Configurations.d.ts +0 -26
- package/dist/compiler/internal/Configurations.d.ts.map +0 -1
- package/dist/compiler/internal/Configurations.js +0 -259
- package/dist/compiler/internal/Configurations.js.map +0 -1
- package/dist/compiler/internal/Contract.d.ts +0 -30
- package/dist/compiler/internal/Contract.d.ts.map +0 -1
- package/dist/compiler/internal/Contract.js +0 -753
- package/dist/compiler/internal/Contract.js.map +0 -1
- package/dist/compiler/internal/Contributions.d.ts +0 -54
- package/dist/compiler/internal/Contributions.d.ts.map +0 -1
- package/dist/compiler/internal/Contributions.js +0 -1151
- package/dist/compiler/internal/Contributions.js.map +0 -1
- package/dist/compiler/internal/Descriptors.d.ts +0 -15
- package/dist/compiler/internal/Descriptors.d.ts.map +0 -1
- package/dist/compiler/internal/Descriptors.js +0 -192
- package/dist/compiler/internal/Descriptors.js.map +0 -1
- package/dist/compiler/internal/Dynamic.d.ts +0 -14
- package/dist/compiler/internal/Dynamic.d.ts.map +0 -1
- package/dist/compiler/internal/Dynamic.js +0 -175
- package/dist/compiler/internal/Dynamic.js.map +0 -1
- package/dist/compiler/internal/Expression.d.ts +0 -19
- package/dist/compiler/internal/Expression.d.ts.map +0 -1
- package/dist/compiler/internal/Expression.js +0 -164
- package/dist/compiler/internal/Expression.js.map +0 -1
- package/dist/compiler/internal/Functions.d.ts +0 -5
- package/dist/compiler/internal/Functions.d.ts.map +0 -1
- package/dist/compiler/internal/Functions.js +0 -191
- package/dist/compiler/internal/Functions.js.map +0 -1
- package/dist/compiler/internal/Keyframes.d.ts +0 -5
- package/dist/compiler/internal/Keyframes.d.ts.map +0 -1
- package/dist/compiler/internal/Keyframes.js +0 -51
- package/dist/compiler/internal/Keyframes.js.map +0 -1
- package/dist/compiler/internal/Names.d.ts +0 -5
- package/dist/compiler/internal/Names.d.ts.map +0 -1
- package/dist/compiler/internal/Names.js +0 -37
- package/dist/compiler/internal/Names.js.map +0 -1
- package/dist/compiler/internal/NativeBindings.d.ts +0 -72
- package/dist/compiler/internal/NativeBindings.d.ts.map +0 -1
- package/dist/compiler/internal/NativeBindings.js +0 -171
- package/dist/compiler/internal/NativeBindings.js.map +0 -1
- package/dist/compiler/internal/NativeMedia.d.ts +0 -14
- package/dist/compiler/internal/NativeMedia.d.ts.map +0 -1
- package/dist/compiler/internal/NativeMedia.js +0 -287
- package/dist/compiler/internal/NativeMedia.js.map +0 -1
- package/dist/compiler/internal/NativeVars.d.ts +0 -28
- package/dist/compiler/internal/NativeVars.d.ts.map +0 -1
- package/dist/compiler/internal/NativeVars.js +0 -160
- package/dist/compiler/internal/NativeVars.js.map +0 -1
- package/dist/compiler/internal/PackedStyles.d.ts +0 -37
- package/dist/compiler/internal/PackedStyles.d.ts.map +0 -1
- package/dist/compiler/internal/PackedStyles.js +0 -344
- package/dist/compiler/internal/PackedStyles.js.map +0 -1
- package/dist/compiler/internal/Properties.d.ts +0 -5
- package/dist/compiler/internal/Properties.d.ts.map +0 -1
- package/dist/compiler/internal/Properties.js +0 -82
- package/dist/compiler/internal/Properties.js.map +0 -1
- package/dist/compiler/internal/RecipeConditions.d.ts +0 -41
- package/dist/compiler/internal/RecipeConditions.d.ts.map +0 -1
- package/dist/compiler/internal/RecipeConditions.js +0 -82
- package/dist/compiler/internal/RecipeConditions.js.map +0 -1
- package/dist/compiler/internal/RecipePayloads.d.ts +0 -31
- package/dist/compiler/internal/RecipePayloads.d.ts.map +0 -1
- package/dist/compiler/internal/RecipePayloads.js +0 -99
- package/dist/compiler/internal/RecipePayloads.js.map +0 -1
- package/dist/compiler/internal/Recipes.d.ts +0 -32
- package/dist/compiler/internal/Recipes.d.ts.map +0 -1
- package/dist/compiler/internal/Recipes.js +0 -339
- package/dist/compiler/internal/Recipes.js.map +0 -1
- package/dist/compiler/internal/Selectors.d.ts +0 -13
- package/dist/compiler/internal/Selectors.d.ts.map +0 -1
- package/dist/compiler/internal/Selectors.js +0 -280
- package/dist/compiler/internal/Selectors.js.map +0 -1
- package/dist/compiler/internal/Static.d.ts +0 -39
- package/dist/compiler/internal/Static.d.ts.map +0 -1
- package/dist/compiler/internal/Static.js +0 -534
- package/dist/compiler/internal/Static.js.map +0 -1
- package/dist/compiler/internal/Themes.d.ts +0 -190
- package/dist/compiler/internal/Themes.d.ts.map +0 -1
- package/dist/compiler/internal/Themes.js +0 -1577
- package/dist/compiler/internal/Themes.js.map +0 -1
- package/dist/compiler/internal/Vars.d.ts +0 -33
- package/dist/compiler/internal/Vars.d.ts.map +0 -1
- package/dist/compiler/internal/Vars.js +0 -387
- package/dist/compiler/internal/Vars.js.map +0 -1
- package/dist/compiler/internal/ViewTransitions.d.ts +0 -3
- package/dist/compiler/internal/ViewTransitions.d.ts.map +0 -1
- package/dist/compiler/internal/ViewTransitions.js +0 -68
- package/dist/compiler/internal/ViewTransitions.js.map +0 -1
- package/dist/internal/Cascade.d.ts +0 -74
- package/dist/internal/Cascade.d.ts.map +0 -1
- package/dist/internal/Cascade.js +0 -210
- package/dist/internal/Cascade.js.map +0 -1
- package/src/compiler/internal/Applications.ts +0 -610
- package/src/compiler/internal/ColorProfiles.ts +0 -93
- package/src/compiler/internal/CompositionBindings.ts +0 -120
- package/src/compiler/internal/Compositions.ts +0 -678
- package/src/compiler/internal/Configurations.ts +0 -349
- package/src/compiler/internal/Contract.ts +0 -1028
- package/src/compiler/internal/Contributions.ts +0 -1561
- package/src/compiler/internal/Descriptors.ts +0 -242
- package/src/compiler/internal/Dynamic.ts +0 -275
- package/src/compiler/internal/Expression.ts +0 -218
- package/src/compiler/internal/Functions.ts +0 -206
- package/src/compiler/internal/Keyframes.ts +0 -62
- package/src/compiler/internal/Names.ts +0 -48
- package/src/compiler/internal/NativeBindings.ts +0 -235
- package/src/compiler/internal/NativeMedia.ts +0 -342
- package/src/compiler/internal/NativeVars.ts +0 -231
- package/src/compiler/internal/PackedStyles.ts +0 -473
- package/src/compiler/internal/Properties.ts +0 -121
- package/src/compiler/internal/RecipeConditions.ts +0 -139
- package/src/compiler/internal/RecipePayloads.ts +0 -132
- package/src/compiler/internal/Recipes.ts +0 -531
- package/src/compiler/internal/Selectors.ts +0 -353
- package/src/compiler/internal/Static.ts +0 -784
- package/src/compiler/internal/Themes.ts +0 -2398
- package/src/compiler/internal/Vars.ts +0 -516
- 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
|
-
}
|