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,235 +0,0 @@
|
|
|
1
|
-
/** Lowers target-neutral callback declarations to ordered native binding data. @module */
|
|
2
|
-
import * as Binding from '../../internal/Binding.js'
|
|
3
|
-
import type * as Native from '../Native.js'
|
|
4
|
-
import type * as Recipe from '../../internal/Recipe.js'
|
|
5
|
-
import type * as Runtime from '../../runtime/NativeDynamic.js'
|
|
6
|
-
import * as Scalar from '../../react-native/internal/Scalar.js'
|
|
7
|
-
import type * as Source from '../Source.js'
|
|
8
|
-
import type * as Static from '../../runtime/NativeStatic.js'
|
|
9
|
-
import type * as Style from '../../Style.js'
|
|
10
|
-
import * as StyleSheet from '../../react-native/StyleSheet.js'
|
|
11
|
-
import * as Token from '../../internal/Token.js'
|
|
12
|
-
import * as Tokens from '../../react-native/internal/Tokens.js'
|
|
13
|
-
|
|
14
|
-
type Step = Runtime.Program['rules'][number]['steps'][number]
|
|
15
|
-
type PreparedStep =
|
|
16
|
-
| Extract<Step, { readonly style: string }>
|
|
17
|
-
| {
|
|
18
|
-
readonly property: keyof typeof Scalar.properties
|
|
19
|
-
readonly parts: readonly (
|
|
20
|
-
| string
|
|
21
|
-
| number
|
|
22
|
-
| Token.Reference
|
|
23
|
-
| { readonly slot: string; readonly number?: true }
|
|
24
|
-
)[]
|
|
25
|
-
}
|
|
26
|
-
type PreparedRule = {
|
|
27
|
-
readonly matches: Runtime.Program['rules'][number]['matches']
|
|
28
|
-
readonly steps: readonly PreparedStep[]
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Compiles static fragments and retains scalar assignments in authored order. */
|
|
32
|
-
export function compile(
|
|
33
|
-
recipe: Recipe.Definition,
|
|
34
|
-
call: Pick<Source.Call, 'slots' | 'recipe'>,
|
|
35
|
-
options: Native.compile.Options,
|
|
36
|
-
prepared = prepare(recipe, call, options),
|
|
37
|
-
): Runtime.create.Options {
|
|
38
|
-
const selected = options.vars?.[options.set ?? 'default']
|
|
39
|
-
const metadata =
|
|
40
|
-
selected &&
|
|
41
|
-
(Object.getOwnPropertyDescriptor(selected, Token.definition)?.value as
|
|
42
|
-
| Token.Metadata
|
|
43
|
-
| undefined)
|
|
44
|
-
return {
|
|
45
|
-
...prepared,
|
|
46
|
-
program: {
|
|
47
|
-
slots: prepared.program.slots,
|
|
48
|
-
rules: prepared.program.rules.map((rule) => ({
|
|
49
|
-
...rule,
|
|
50
|
-
steps: rule.steps.map((step) =>
|
|
51
|
-
'style' in step
|
|
52
|
-
? step
|
|
53
|
-
: {
|
|
54
|
-
...step,
|
|
55
|
-
parts: step.parts.map((part) =>
|
|
56
|
-
Token.is(part)
|
|
57
|
-
? Tokens.resolve(part, {
|
|
58
|
-
...options,
|
|
59
|
-
metadata,
|
|
60
|
-
resolution: { schemeIndependent: true },
|
|
61
|
-
})
|
|
62
|
-
: part,
|
|
63
|
-
),
|
|
64
|
-
},
|
|
65
|
-
),
|
|
66
|
-
})),
|
|
67
|
-
},
|
|
68
|
-
styles: StyleSheet.select(prepared.styles, {
|
|
69
|
-
set: options.set ?? 'default',
|
|
70
|
-
colorScheme: options.colorScheme,
|
|
71
|
-
}),
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** Removes dynamic instructions and resolves absolute line heights before publication. */
|
|
76
|
-
export function finite(options: Runtime.create.Options): Static.create.Options {
|
|
77
|
-
const styles = { ...options.styles }
|
|
78
|
-
return {
|
|
79
|
-
axes: options.axes,
|
|
80
|
-
defaults: options.defaults,
|
|
81
|
-
rules: options.program.rules.map((rule) => ({
|
|
82
|
-
matches: rule.matches,
|
|
83
|
-
steps: rule.steps.map((step) => {
|
|
84
|
-
if ('style' in step) return step.style
|
|
85
|
-
if (
|
|
86
|
-
step.property !== 'lineHeight' ||
|
|
87
|
-
!step.parts.length ||
|
|
88
|
-
step.parts.some((part) => typeof part === 'object')
|
|
89
|
-
)
|
|
90
|
-
throw new Error(
|
|
91
|
-
'Static native recipes cannot contain runtime bindings.',
|
|
92
|
-
)
|
|
93
|
-
const value = (
|
|
94
|
-
step.parts.length === 1 ? step.parts[0]! : step.parts.join('')
|
|
95
|
-
) as string | number
|
|
96
|
-
if (typeof value === 'number') return value
|
|
97
|
-
const name = String(Object.keys(styles).length)
|
|
98
|
-
styles[name] = {
|
|
99
|
-
lineHeight: Scalar.length(value, options, false, ['lineHeight']),
|
|
100
|
-
}
|
|
101
|
-
return name
|
|
102
|
-
}),
|
|
103
|
-
})),
|
|
104
|
-
styles,
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** Prepares immutable programs and all set/scheme tables before selection. */
|
|
109
|
-
export function prepare(
|
|
110
|
-
recipe: Recipe.Definition,
|
|
111
|
-
call: Pick<Source.Call, 'slots' | 'recipe'>,
|
|
112
|
-
options: Native.compile.Options,
|
|
113
|
-
) {
|
|
114
|
-
const slots = Object.fromEntries(
|
|
115
|
-
Object.entries(call.slots ?? {}).map(([name, slot]) => [name, slot.name]),
|
|
116
|
-
)
|
|
117
|
-
const available = new Set([
|
|
118
|
-
...Object.values(slots),
|
|
119
|
-
...(call.recipe?.payloads ?? []).flatMap((payload) =>
|
|
120
|
-
Object.values(payload.slots[0]!),
|
|
121
|
-
),
|
|
122
|
-
])
|
|
123
|
-
const fragments: Style.NamedStyle[] = []
|
|
124
|
-
const rules: PreparedRule[] = []
|
|
125
|
-
|
|
126
|
-
for (const rule of recipe.rules) {
|
|
127
|
-
const steps: PreparedStep[] = []
|
|
128
|
-
function fragment(style: Style.NamedStyle) {
|
|
129
|
-
const name = String(fragments.length)
|
|
130
|
-
fragments.push({ ...style, name })
|
|
131
|
-
steps.push({ style: name })
|
|
132
|
-
}
|
|
133
|
-
function visit(style: Style.NamedStyle) {
|
|
134
|
-
const declared = new Set<string>()
|
|
135
|
-
let declarations: Style.Declaration[] = []
|
|
136
|
-
function flush() {
|
|
137
|
-
if (!declarations.length) return
|
|
138
|
-
fragment({ name: style.name, declarations })
|
|
139
|
-
declarations = []
|
|
140
|
-
}
|
|
141
|
-
for (const declaration of style.declarations) {
|
|
142
|
-
if (declaration.important || declared.has(declaration.property))
|
|
143
|
-
throw new Error(
|
|
144
|
-
'Importance and fallback declarations are not supported on native.',
|
|
145
|
-
)
|
|
146
|
-
declared.add(declaration.property)
|
|
147
|
-
const parts = Token.isExpression(declaration.value)
|
|
148
|
-
? declaration.value.parts
|
|
149
|
-
: [declaration.value]
|
|
150
|
-
const dynamic = parts.some((part) => Binding.is(part))
|
|
151
|
-
if (!dynamic && declaration.property !== 'lineHeight') {
|
|
152
|
-
declarations.push(declaration)
|
|
153
|
-
continue
|
|
154
|
-
}
|
|
155
|
-
flush()
|
|
156
|
-
const property = declaration.property as keyof typeof Scalar.properties
|
|
157
|
-
if (
|
|
158
|
-
!Object.hasOwn(Scalar.properties, property) ||
|
|
159
|
-
[
|
|
160
|
-
'flex',
|
|
161
|
-
'transform',
|
|
162
|
-
'origin',
|
|
163
|
-
'shadow',
|
|
164
|
-
'textShadow',
|
|
165
|
-
'fontVariant',
|
|
166
|
-
].includes(String(Scalar.properties[property]))
|
|
167
|
-
)
|
|
168
|
-
throw new Error(
|
|
169
|
-
`Dynamic native property is unsupported: ${property}.`,
|
|
170
|
-
)
|
|
171
|
-
const values = parts.map((part) => {
|
|
172
|
-
if (typeof part === 'string' || typeof part === 'number') return part
|
|
173
|
-
if (Token.is(part)) return part
|
|
174
|
-
if (!Binding.is(part) || !available.has(part.name))
|
|
175
|
-
throw new Error(
|
|
176
|
-
'Native bindings require declared runtime scalar fields.',
|
|
177
|
-
)
|
|
178
|
-
return {
|
|
179
|
-
slot: part.name,
|
|
180
|
-
...(part.type === 'number' ? { number: true as const } : {}),
|
|
181
|
-
}
|
|
182
|
-
})
|
|
183
|
-
const calculation = values.some(
|
|
184
|
-
(value) => typeof value === 'string' && /(?:^|\s)calc\(/i.test(value),
|
|
185
|
-
)
|
|
186
|
-
if (
|
|
187
|
-
values.length > 1 &&
|
|
188
|
-
!calculation &&
|
|
189
|
-
!(
|
|
190
|
-
values.length === 2 &&
|
|
191
|
-
typeof values[0] === 'object' &&
|
|
192
|
-
['px', 'rem', '%'].includes(String(values[1]))
|
|
193
|
-
)
|
|
194
|
-
)
|
|
195
|
-
throw new Error(
|
|
196
|
-
'Native dynamic expressions support a scalar with a px, rem, or percent suffix.',
|
|
197
|
-
)
|
|
198
|
-
steps.push({ property, parts: values })
|
|
199
|
-
}
|
|
200
|
-
flush()
|
|
201
|
-
if (style.targets)
|
|
202
|
-
fragment({ name: style.name, declarations: [], targets: style.targets })
|
|
203
|
-
for (const rule of style.rules ?? []) {
|
|
204
|
-
if (rule.condition !== undefined)
|
|
205
|
-
throw new Error(
|
|
206
|
-
'Selectors, queries, and nested rules are not supported on native.',
|
|
207
|
-
)
|
|
208
|
-
visit(rule.style)
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
for (const style of rule.value.styles) visit(style)
|
|
212
|
-
rules.push({ matches: rule.matches, steps })
|
|
213
|
-
}
|
|
214
|
-
const compiled = StyleSheet.compile({
|
|
215
|
-
styles: { styles: fragments },
|
|
216
|
-
fonts: options.fonts,
|
|
217
|
-
platform: options.platform,
|
|
218
|
-
vars: options.vars,
|
|
219
|
-
units: options.units,
|
|
220
|
-
})
|
|
221
|
-
return {
|
|
222
|
-
axes: recipe.axes,
|
|
223
|
-
defaults: recipe.defaults,
|
|
224
|
-
...(call.recipe?.payloads
|
|
225
|
-
? {
|
|
226
|
-
payloads: call.recipe.payloads,
|
|
227
|
-
defaultPayloads: call.recipe.defaultPayloads,
|
|
228
|
-
}
|
|
229
|
-
: {}),
|
|
230
|
-
fonts: options.fonts,
|
|
231
|
-
units: options.units,
|
|
232
|
-
program: { slots, rules },
|
|
233
|
-
styles: compiled.styles,
|
|
234
|
-
}
|
|
235
|
-
}
|
|
@@ -1,342 +0,0 @@
|
|
|
1
|
-
/** Lowers native media rules and conditional tokens to bounded static alternatives. @module */
|
|
2
|
-
import * as CssTree from 'css-tree'
|
|
3
|
-
import type * as Media from '../../runtime/internal/NativeMedia.js'
|
|
4
|
-
import * as Scalar from '../../react-native/internal/Scalar.js'
|
|
5
|
-
import type * as Style from '../../Style.js'
|
|
6
|
-
import type * as StyleSheet from '../../react-native/StyleSheet.js'
|
|
7
|
-
import * as Token from '../../internal/Token.js'
|
|
8
|
-
|
|
9
|
-
/** Retains authored precedence while selecting each possible media outcome. */
|
|
10
|
-
export function prepare<variables extends StyleSheet.compile.Options['vars']>(
|
|
11
|
-
styles: readonly Style.NamedStyle[] | undefined,
|
|
12
|
-
vars: variables,
|
|
13
|
-
options: Scalar.Options,
|
|
14
|
-
) {
|
|
15
|
-
const catalog: StyleSheet.compile.Options['vars'] = vars
|
|
16
|
-
const expressions = new Map<string, number>()
|
|
17
|
-
const names = new Map<string, number>()
|
|
18
|
-
const queries: Media.Query[] = []
|
|
19
|
-
const visited = new Set<object>()
|
|
20
|
-
|
|
21
|
-
function add(name: string) {
|
|
22
|
-
if (names.has(name)) return
|
|
23
|
-
|
|
24
|
-
const query = parse(name, options)
|
|
25
|
-
const expression = JSON.stringify(query)
|
|
26
|
-
let index = expressions.get(expression)
|
|
27
|
-
if (index === undefined) {
|
|
28
|
-
index = queries.length
|
|
29
|
-
if (index === 8)
|
|
30
|
-
throw new Error(
|
|
31
|
-
'Native media supports at most eight distinct conditions per definition.',
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
queries.push(query)
|
|
35
|
-
expressions.set(expression, index)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
names.set(name, index)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function values(value: unknown) {
|
|
42
|
-
if (!value || typeof value !== 'object' || visited.has(value)) return
|
|
43
|
-
|
|
44
|
-
visited.add(value)
|
|
45
|
-
if (Token.is(value)) {
|
|
46
|
-
values(value.value)
|
|
47
|
-
for (const theme of Object.values(catalog ?? {})) {
|
|
48
|
-
const metadata = theme[Token.definition]
|
|
49
|
-
if (
|
|
50
|
-
metadata.contract === value.contract ||
|
|
51
|
-
(metadata.contract[Token.identity] !== undefined &&
|
|
52
|
-
metadata.contract[Token.identity] ===
|
|
53
|
-
value.contract[Token.identity])
|
|
54
|
-
)
|
|
55
|
-
values(metadata.values[value.path])
|
|
56
|
-
}
|
|
57
|
-
} else if (Token.isExpression(value)) value.parts.forEach(values)
|
|
58
|
-
else if ('default' in value) {
|
|
59
|
-
for (const [name, entry] of Object.entries(value)) {
|
|
60
|
-
if (name !== 'default') {
|
|
61
|
-
// Unsupported variable leaves keep their deferred read diagnostic.
|
|
62
|
-
try {
|
|
63
|
-
add(name)
|
|
64
|
-
} catch (error) {
|
|
65
|
-
if (!(error instanceof UnsupportedError)) throw error
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
values(entry)
|
|
69
|
-
}
|
|
70
|
-
} else if ('light' in value && 'dark' in value) {
|
|
71
|
-
values(value.light)
|
|
72
|
-
values(value.dark)
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function visit(style: Style.NamedStyle) {
|
|
77
|
-
for (const declaration of style.declarations) values(declaration.value)
|
|
78
|
-
for (const rule of style.rules ?? []) {
|
|
79
|
-
if (rule.condition?.startsWith('@media')) add(rule.condition)
|
|
80
|
-
visit(rule.style)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
styles?.forEach(visit)
|
|
85
|
-
if (!styles)
|
|
86
|
-
for (const theme of Object.values(catalog ?? {})) {
|
|
87
|
-
const metadata = theme[Token.definition]
|
|
88
|
-
Object.values(metadata.values).forEach(values)
|
|
89
|
-
}
|
|
90
|
-
if (!queries.length) return
|
|
91
|
-
|
|
92
|
-
return {
|
|
93
|
-
queries,
|
|
94
|
-
select(selection: string) {
|
|
95
|
-
const active = new Set<object>()
|
|
96
|
-
function value<entry>(entry: entry): entry {
|
|
97
|
-
if (!entry || typeof entry !== 'object') return entry
|
|
98
|
-
if (active.has(entry))
|
|
99
|
-
throw new Error('Native token aliases must not form a cycle.')
|
|
100
|
-
|
|
101
|
-
active.add(entry)
|
|
102
|
-
try {
|
|
103
|
-
if (Token.is(entry))
|
|
104
|
-
return Token.create({
|
|
105
|
-
...entry,
|
|
106
|
-
value: value(entry.value),
|
|
107
|
-
}) as entry
|
|
108
|
-
if (Token.isExpression(entry))
|
|
109
|
-
return { ...entry, parts: entry.parts.map(value) } as entry
|
|
110
|
-
if ('default' in entry) {
|
|
111
|
-
const branches = Object.entries(entry)
|
|
112
|
-
if (
|
|
113
|
-
branches.some(([name]) => name !== 'default' && !names.has(name))
|
|
114
|
-
)
|
|
115
|
-
return Object.fromEntries(
|
|
116
|
-
branches
|
|
117
|
-
.filter(([name]) => name === 'default' || !names.has(name))
|
|
118
|
-
.map(([name, branch]) => [name, value(branch)]),
|
|
119
|
-
) as entry
|
|
120
|
-
|
|
121
|
-
let selected = entry.default
|
|
122
|
-
for (const [name, branch] of branches)
|
|
123
|
-
if (name !== 'default' && selection[names.get(name)!] === '1')
|
|
124
|
-
selected = branch
|
|
125
|
-
|
|
126
|
-
return value(selected) as entry
|
|
127
|
-
}
|
|
128
|
-
if ('light' in entry && 'dark' in entry)
|
|
129
|
-
return {
|
|
130
|
-
...entry,
|
|
131
|
-
dark: value(entry.dark),
|
|
132
|
-
light: value(entry.light),
|
|
133
|
-
}
|
|
134
|
-
return entry
|
|
135
|
-
} finally {
|
|
136
|
-
active.delete(entry)
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function style(entry: Style.NamedStyle): Style.NamedStyle {
|
|
141
|
-
return {
|
|
142
|
-
...entry,
|
|
143
|
-
declarations: entry.declarations.map((declaration) => ({
|
|
144
|
-
...declaration,
|
|
145
|
-
value: value(declaration.value),
|
|
146
|
-
})),
|
|
147
|
-
...(entry.rules
|
|
148
|
-
? {
|
|
149
|
-
rules: entry.rules.flatMap((rule) => {
|
|
150
|
-
const index =
|
|
151
|
-
rule.condition === undefined
|
|
152
|
-
? undefined
|
|
153
|
-
: names.get(rule.condition)
|
|
154
|
-
if (index !== undefined && selection[index] !== '1') return []
|
|
155
|
-
|
|
156
|
-
return [
|
|
157
|
-
{
|
|
158
|
-
...(index === undefined ? rule : {}),
|
|
159
|
-
style: style(rule.style),
|
|
160
|
-
},
|
|
161
|
-
]
|
|
162
|
-
}),
|
|
163
|
-
}
|
|
164
|
-
: {}),
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
style,
|
|
170
|
-
vars:
|
|
171
|
-
catalog &&
|
|
172
|
-
(Object.fromEntries(
|
|
173
|
-
Object.entries(catalog).map(([name, theme]) => {
|
|
174
|
-
const metadata = theme[Token.definition]
|
|
175
|
-
return [
|
|
176
|
-
name,
|
|
177
|
-
Object.defineProperty({}, Token.definition, {
|
|
178
|
-
value: {
|
|
179
|
-
...metadata,
|
|
180
|
-
values: Object.fromEntries(
|
|
181
|
-
Object.entries(metadata.values).map(([path, entry]) => [
|
|
182
|
-
path,
|
|
183
|
-
value(entry),
|
|
184
|
-
]),
|
|
185
|
-
),
|
|
186
|
-
},
|
|
187
|
-
}) as typeof theme,
|
|
188
|
-
]
|
|
189
|
-
}),
|
|
190
|
-
) as variables),
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
selections: Array.from({ length: 2 ** queries.length }, (_entry, index) =>
|
|
194
|
-
index.toString(2).padStart(queries.length, '0'),
|
|
195
|
-
),
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
class UnsupportedError extends Error {
|
|
200
|
-
override name = 'NativeMedia.UnsupportedError'
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function parse(input: string, options: Scalar.Options): Media.Query {
|
|
204
|
-
if (!input.startsWith('@media'))
|
|
205
|
-
throw new UnsupportedError(
|
|
206
|
-
'Native conditional variables require media queries.',
|
|
207
|
-
)
|
|
208
|
-
const parsed = CssTree.parse(input.slice(6), { context: 'mediaQueryList' })
|
|
209
|
-
let count = 0
|
|
210
|
-
function read(node: CssTree.CssNode): Media.Query {
|
|
211
|
-
if (++count > 128)
|
|
212
|
-
throw new Error('Native media queries exceed 128 syntax nodes.')
|
|
213
|
-
if (node.type === 'MediaQueryList') {
|
|
214
|
-
const queries = node.children.toArray().map(read)
|
|
215
|
-
return queries.length === 1 ? queries[0]! : { kind: 'or', queries }
|
|
216
|
-
}
|
|
217
|
-
if (node.type === 'MediaQuery') {
|
|
218
|
-
if (
|
|
219
|
-
(node.mediaType &&
|
|
220
|
-
!['all', 'screen'].includes(node.mediaType.toLowerCase())) ||
|
|
221
|
-
node.modifier?.toLowerCase() === 'not'
|
|
222
|
-
)
|
|
223
|
-
throw new UnsupportedError(
|
|
224
|
-
'Native media types support all or screen without negation.',
|
|
225
|
-
)
|
|
226
|
-
return node.condition
|
|
227
|
-
? read(node.condition)
|
|
228
|
-
: { kind: 'compare', left: 0, operator: '=', right: 0 }
|
|
229
|
-
}
|
|
230
|
-
if (node.type === 'Condition') {
|
|
231
|
-
const parts = node.children.toArray()
|
|
232
|
-
if (parts.length === 1) return read(parts[0]!)
|
|
233
|
-
if (
|
|
234
|
-
parts.length === 2 &&
|
|
235
|
-
parts[0]?.type === 'Identifier' &&
|
|
236
|
-
parts[0].name.toLowerCase() === 'not'
|
|
237
|
-
)
|
|
238
|
-
return { kind: 'not', query: read(parts[1]!) }
|
|
239
|
-
const operator =
|
|
240
|
-
parts[1]?.type === 'Identifier'
|
|
241
|
-
? parts[1].name.toLowerCase()
|
|
242
|
-
: undefined
|
|
243
|
-
if (
|
|
244
|
-
(operator !== 'and' && operator !== 'or') ||
|
|
245
|
-
parts.length % 2 !== 1 ||
|
|
246
|
-
parts.some(
|
|
247
|
-
(part, index) =>
|
|
248
|
-
index % 2 === 1 &&
|
|
249
|
-
(part.type !== 'Identifier' ||
|
|
250
|
-
part.name.toLowerCase() !== operator),
|
|
251
|
-
)
|
|
252
|
-
)
|
|
253
|
-
throw new UnsupportedError('Unsupported native media condition.')
|
|
254
|
-
return {
|
|
255
|
-
kind: operator,
|
|
256
|
-
queries: parts.filter((_part, index) => index % 2 === 0).map(read),
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
function operand(entry: CssTree.CssNode): number | 'height' | 'width' {
|
|
260
|
-
if (
|
|
261
|
-
entry.type === 'Identifier' &&
|
|
262
|
-
(entry.name.toLowerCase() === 'height' ||
|
|
263
|
-
entry.name.toLowerCase() === 'width')
|
|
264
|
-
)
|
|
265
|
-
return entry.name.toLowerCase() as 'height' | 'width'
|
|
266
|
-
if (entry.type === 'Dimension') {
|
|
267
|
-
try {
|
|
268
|
-
return Scalar.length(
|
|
269
|
-
`${entry.value}${entry.unit.toLowerCase()}`,
|
|
270
|
-
options,
|
|
271
|
-
false,
|
|
272
|
-
[],
|
|
273
|
-
)
|
|
274
|
-
} catch (error) {
|
|
275
|
-
throw new UnsupportedError((error as Error).message)
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
if (entry.type === 'Number' && Number(entry.value) === 0) return 0
|
|
279
|
-
throw new UnsupportedError(
|
|
280
|
-
'Native media ranges require width/height and px/rem thresholds.',
|
|
281
|
-
)
|
|
282
|
-
}
|
|
283
|
-
function comparison(
|
|
284
|
-
left: CssTree.CssNode,
|
|
285
|
-
operator: string | null,
|
|
286
|
-
right: CssTree.CssNode,
|
|
287
|
-
): Media.Query {
|
|
288
|
-
if (!operator || !['<', '<=', '=', '>', '>='].includes(operator))
|
|
289
|
-
throw new UnsupportedError('Unsupported native media comparison.')
|
|
290
|
-
return {
|
|
291
|
-
kind: 'compare',
|
|
292
|
-
left: operand(left),
|
|
293
|
-
operator: operator as '<' | '<=' | '=' | '>' | '>=',
|
|
294
|
-
right: operand(right),
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
if (node.type === 'FeatureRange') {
|
|
298
|
-
const first = comparison(node.left, node.leftComparison, node.middle)
|
|
299
|
-
return node.right
|
|
300
|
-
? {
|
|
301
|
-
kind: 'and',
|
|
302
|
-
queries: [
|
|
303
|
-
first,
|
|
304
|
-
comparison(node.middle, node.rightComparison, node.right),
|
|
305
|
-
],
|
|
306
|
-
}
|
|
307
|
-
: first
|
|
308
|
-
}
|
|
309
|
-
if (node.type === 'Feature') {
|
|
310
|
-
const name = node.name.toLowerCase()
|
|
311
|
-
if (
|
|
312
|
-
name === 'orientation' &&
|
|
313
|
-
node.value?.type === 'Identifier' &&
|
|
314
|
-
['landscape', 'portrait'].includes(node.value.name.toLowerCase())
|
|
315
|
-
)
|
|
316
|
-
return {
|
|
317
|
-
kind: 'compare',
|
|
318
|
-
left: 'width',
|
|
319
|
-
operator: node.value.name.toLowerCase() === 'landscape' ? '>' : '<=',
|
|
320
|
-
right: 'height',
|
|
321
|
-
}
|
|
322
|
-
const match = /^(?:(min|max)-)?(height|width)$/.exec(name)
|
|
323
|
-
if (match)
|
|
324
|
-
return {
|
|
325
|
-
kind: 'compare',
|
|
326
|
-
left: match[2] as 'height' | 'width',
|
|
327
|
-
operator:
|
|
328
|
-
match[1] === 'min'
|
|
329
|
-
? '>='
|
|
330
|
-
: match[1] === 'max'
|
|
331
|
-
? '<='
|
|
332
|
-
: node.value
|
|
333
|
-
? '='
|
|
334
|
-
: '>',
|
|
335
|
-
right: node.value ? operand(node.value) : 0,
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
throw new UnsupportedError('Unsupported native media feature.')
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return read(parsed)
|
|
342
|
-
}
|