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,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
|
-
}
|