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
package/src/compiler/Native.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
/** Rewrites shared authoring to native tables and ordered runtime bindings. @module */
|
|
2
|
-
import type * as
|
|
3
|
-
import
|
|
4
|
-
import type * as Recipe from '../internal/Recipe.js'
|
|
5
|
-
import * as Source from './Source.js'
|
|
2
|
+
import type * as Source from './Source.js'
|
|
3
|
+
import * as Context from './internal/Context.js'
|
|
6
4
|
import * as Edits from './internal/Edits.js'
|
|
7
|
-
import * as
|
|
8
|
-
import * as
|
|
9
|
-
import * as
|
|
10
|
-
import * as Themes from './internal/Themes.js'
|
|
11
|
-
import * as StyleSheet from '../react-native/StyleSheet.js'
|
|
12
|
-
import * as Syntax from './internal/Syntax.js'
|
|
13
|
-
import * as Variants from '../react-native/Variants.js'
|
|
14
|
-
import * as Walker from 'oxc-walker'
|
|
5
|
+
import * as Results from './internal/Results.js'
|
|
6
|
+
import type * as StyleSheet from '../react-native/StyleSheet.js'
|
|
7
|
+
import type * as Variants from '../react-native/Variants.js'
|
|
15
8
|
|
|
16
9
|
/**
|
|
17
10
|
* Compiles local styles, variants, and variable reads for an explicit native target.
|
|
@@ -22,836 +15,19 @@ import * as Walker from 'oxc-walker'
|
|
|
22
15
|
* @throws {StyleSheet.CompileError} For unsupported native declaration values.
|
|
23
16
|
*/
|
|
24
17
|
export function compile(options: compile.Options): compile.ReturnType {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
options[
|
|
28
|
-
Source.extract({
|
|
29
|
-
moduleId: options.moduleId,
|
|
30
|
-
source: options.source,
|
|
31
|
-
target: 'native',
|
|
32
|
-
[Themes.context]: options[Themes.context],
|
|
33
|
-
})
|
|
34
|
-
if (
|
|
35
|
-
extracted.contributions?.length ||
|
|
36
|
-
extracted.variableCalls?.length ||
|
|
37
|
-
extracted.themeReferences.length ||
|
|
38
|
-
extracted.themeSelections?.length ||
|
|
39
|
-
(!options.contextual &&
|
|
40
|
-
(extracted.themeAppearances?.length || extracted.themeScripts?.length))
|
|
41
|
-
)
|
|
42
|
-
throw new CompileError(
|
|
43
|
-
'Native static modules do not support CSS contributions, variables, or web set controls.',
|
|
44
|
-
)
|
|
45
|
-
const parsed = options[Themes.context]?.parsed ?? Syntax.parse(options)
|
|
46
|
-
const names = new Set(options[Themes.context]?.identifiers)
|
|
47
|
-
if (!options[Themes.context]?.identifiers)
|
|
48
|
-
Walker.walk(parsed.program, {
|
|
49
|
-
enter(node) {
|
|
50
|
-
if (node.type === 'Identifier') names.add(node.name)
|
|
51
|
-
},
|
|
52
|
-
})
|
|
53
|
-
let helper = '__zyzzNative'
|
|
54
|
-
while (
|
|
55
|
-
[
|
|
56
|
-
helper,
|
|
57
|
-
`${helper}Context`,
|
|
58
|
-
`${helper}Dynamic`,
|
|
59
|
-
`${helper}Static`,
|
|
60
|
-
`${helper}Vars`,
|
|
61
|
-
].some((name) => names.has(name))
|
|
62
|
-
)
|
|
63
|
-
helper += '_'
|
|
64
|
-
let dynamicHelper = `${helper}Dynamic`
|
|
65
|
-
while (names.has(dynamicHelper)) dynamicHelper += '_'
|
|
66
|
-
const module = new MagicString(options.source)
|
|
67
|
-
const edits: Edits.Edit[] = []
|
|
68
|
-
function overwrite(
|
|
69
|
-
start: number,
|
|
70
|
-
end: number,
|
|
71
|
-
code: string,
|
|
72
|
-
expression = false,
|
|
73
|
-
) {
|
|
74
|
-
edits.push({ start, end, code, expression })
|
|
75
|
-
module.overwrite(start, end, code)
|
|
76
|
-
}
|
|
77
|
-
const recipes: Record<string, Variants.Definition> = Object.create(null)
|
|
78
|
-
let dynamic = false
|
|
79
|
-
let finite = false
|
|
80
|
-
const contexts = new Map<string, string>()
|
|
81
|
-
const compiledCalls = new WeakMap<
|
|
82
|
-
Variants.Definition,
|
|
83
|
-
{
|
|
84
|
-
styles: Readonly<Record<string, StyleSheet.NativeStyle>>
|
|
85
|
-
value: string
|
|
86
|
-
}
|
|
87
|
-
>()
|
|
88
|
-
const factories = new Map<string, { name: string; parameters: string[] }>()
|
|
89
|
-
const literals = new Map<string, string>()
|
|
90
|
-
const initializers = new Map<string, { name: string; values: string[] }>()
|
|
91
|
-
const stylesByName = new Map<
|
|
92
|
-
string,
|
|
93
|
-
(typeof extracted.styles.styles)[number][]
|
|
94
|
-
>()
|
|
95
|
-
for (const style of extracted.styles.styles) {
|
|
96
|
-
const styles = stylesByName.get(style.name)
|
|
97
|
-
if (styles) styles.push(style)
|
|
98
|
-
else stylesByName.set(style.name, [style])
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const staticTables = new Map<Source.Call, Variants.Definition>()
|
|
102
|
-
if (extracted.nativeVars?.length)
|
|
103
|
-
StyleSheet.compile({
|
|
104
|
-
fonts: options.fonts,
|
|
105
|
-
platform: options.platform,
|
|
106
|
-
styles: { styles: [] },
|
|
107
|
-
units: options.units,
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
const shared = options[NativeVars.shared]
|
|
111
|
-
const variables = new Map(shared?.definitions)
|
|
112
|
-
const imports = new Set<string>()
|
|
113
|
-
for (const read of extracted.nativeVars ?? []) {
|
|
114
|
-
const imported = shared?.reads.get(read.start)
|
|
115
|
-
if (imported) {
|
|
116
|
-
if (imported.source)
|
|
117
|
-
imports.add(
|
|
118
|
-
`import {${imported.name}} from ${JSON.stringify(imported.source)};`,
|
|
119
|
-
)
|
|
120
|
-
const type = typed
|
|
121
|
-
? ` as typeof ${options.source.slice(read.start, read.end)}`
|
|
122
|
-
: ''
|
|
123
|
-
overwrite(read.start, read.end, `(${imported.name}${type})`, true)
|
|
124
|
-
continue
|
|
125
|
-
}
|
|
126
|
-
const definition = (() => {
|
|
127
|
-
try {
|
|
128
|
-
return NativeVars.compile({
|
|
129
|
-
...read,
|
|
130
|
-
fonts: options.fonts,
|
|
131
|
-
units: options.units,
|
|
132
|
-
})
|
|
133
|
-
} catch (error) {
|
|
134
|
-
throw new CompileError((error as Error).message)
|
|
135
|
-
}
|
|
136
|
-
})()
|
|
137
|
-
const key = JSON.stringify(definition)
|
|
138
|
-
let name = variables.get(key)
|
|
139
|
-
if (!name) {
|
|
140
|
-
name = `${helper}Vars${variables.size}`
|
|
141
|
-
while (names.has(name)) name += '_'
|
|
142
|
-
names.add(name)
|
|
143
|
-
variables.set(key, name)
|
|
144
|
-
}
|
|
145
|
-
const type = typed
|
|
146
|
-
? ` as typeof ${options.source.slice(read.start, read.end)}`
|
|
147
|
-
: ''
|
|
148
|
-
overwrite(read.start, read.end, `(${name}${type})`, true)
|
|
149
|
-
}
|
|
150
|
-
if (options.contextual) {
|
|
151
|
-
const groups = new Map<StyleSheet.compile.Options['vars'], Source.Call[]>()
|
|
152
|
-
for (const call of extracted.calls) {
|
|
153
|
-
if (
|
|
154
|
-
call.recipe ||
|
|
155
|
-
call.staticRecipe ||
|
|
156
|
-
call.dynamicRecipe ||
|
|
157
|
-
call.slots ||
|
|
158
|
-
call.output === 'html'
|
|
159
|
-
)
|
|
160
|
-
continue
|
|
161
|
-
const vars = call.nativeContext?.vars ?? options.vars
|
|
162
|
-
try {
|
|
163
|
-
if (
|
|
164
|
-
NativeMedia.prepare(stylesByName.get(call.name) ?? [], vars, options)
|
|
165
|
-
)
|
|
166
|
-
continue
|
|
167
|
-
} catch (error) {
|
|
168
|
-
throw new CompileError((error as Error).message)
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const group = groups.get(vars)
|
|
172
|
-
if (group) group.push(call)
|
|
173
|
-
else groups.set(vars, [call])
|
|
174
|
-
}
|
|
175
|
-
for (const [vars, calls] of groups) {
|
|
176
|
-
if (calls.length < 2) continue
|
|
177
|
-
try {
|
|
178
|
-
const compiled = StyleSheet.compile({
|
|
179
|
-
fonts: options.fonts,
|
|
180
|
-
platform: options.platform,
|
|
181
|
-
styles: {
|
|
182
|
-
styles: calls.map((call) => ({
|
|
183
|
-
name: call.name,
|
|
184
|
-
declarations: [],
|
|
185
|
-
rules: (stylesByName.get(call.name) ?? []).map((style) => ({
|
|
186
|
-
style,
|
|
187
|
-
})),
|
|
188
|
-
})),
|
|
189
|
-
},
|
|
190
|
-
vars,
|
|
191
|
-
units: options.units,
|
|
192
|
-
})
|
|
193
|
-
for (const call of calls) {
|
|
194
|
-
const styles = Object.fromEntries(
|
|
195
|
-
Object.entries(compiled.styles).map(([set, schemes]) => [
|
|
196
|
-
set,
|
|
197
|
-
Object.freeze({
|
|
198
|
-
light: Object.freeze({ '0': schemes.light[call.name]! }),
|
|
199
|
-
dark: Object.freeze({ '0': schemes.dark[call.name]! }),
|
|
200
|
-
}),
|
|
201
|
-
]),
|
|
202
|
-
)
|
|
203
|
-
staticTables.set(
|
|
204
|
-
call,
|
|
205
|
-
Object.freeze({
|
|
206
|
-
axes: Object.freeze({}),
|
|
207
|
-
defaults: Object.freeze({}),
|
|
208
|
-
styles: Object.freeze(styles),
|
|
209
|
-
}),
|
|
210
|
-
)
|
|
211
|
-
}
|
|
212
|
-
} catch (error) {
|
|
213
|
-
// Recompile failures individually to retain authored error order and paths.
|
|
214
|
-
if (!(error instanceof StyleSheet.CompileError)) throw error
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
for (const call of extracted.calls) {
|
|
220
|
-
if (
|
|
221
|
-
(call.recipe && !call.staticRecipe && !call.dynamicRecipe) ||
|
|
222
|
-
call.output === 'html'
|
|
223
|
-
)
|
|
224
|
-
throw new CompileError(
|
|
225
|
-
'Native source compilation does not support named conditions or HTML output.',
|
|
226
|
-
)
|
|
227
|
-
const recipe = call.staticRecipe ??
|
|
228
|
-
call.dynamicRecipe ?? {
|
|
229
|
-
axes: {},
|
|
230
|
-
defaults: {},
|
|
231
|
-
rules: [
|
|
232
|
-
{
|
|
233
|
-
matches: [],
|
|
234
|
-
value: {
|
|
235
|
-
styles: stylesByName.get(call.name) ?? [],
|
|
236
|
-
},
|
|
237
|
-
},
|
|
238
|
-
],
|
|
239
|
-
}
|
|
240
|
-
overwrite(
|
|
241
|
-
call.start,
|
|
242
|
-
call.end,
|
|
243
|
-
callable(recipe, call.name, call, options, staticTables.get(call)),
|
|
244
|
-
true,
|
|
245
|
-
)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function create(name: string, data: unknown): string {
|
|
249
|
-
const literal = JSON.stringify(data)
|
|
250
|
-
if (!options[Edits.runtime] || extracted.calls.length < 2)
|
|
251
|
-
return `${name}.create(${literal})`
|
|
252
|
-
const key = `${name}:${literal}`
|
|
253
|
-
const cached = literals.get(key)
|
|
254
|
-
if (cached) return cached
|
|
255
|
-
const values: string[] = []
|
|
256
|
-
const structure = literal.replace(
|
|
257
|
-
/"(?:[^"\\]|\\.)*"|-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null/g,
|
|
258
|
-
(value: string, offset: number) => {
|
|
259
|
-
// Serialized property names precede colons; only value tokens become parameters.
|
|
260
|
-
if (literal[offset + value.length] === ':') return value
|
|
261
|
-
const parameter = `v${values.length}`
|
|
262
|
-
values.push(value)
|
|
263
|
-
return parameter
|
|
264
|
-
},
|
|
265
|
-
)
|
|
266
|
-
const expression = `${name}.create(${structure})`
|
|
267
|
-
const value =
|
|
268
|
-
values.length > 64
|
|
269
|
-
? `${name}.create(${literal})`
|
|
270
|
-
: factory(expression, values)
|
|
271
|
-
literals.set(key, value)
|
|
272
|
-
return value
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
function factory(expression: string, values: string[]): string {
|
|
276
|
-
let definition = factories.get(expression)
|
|
277
|
-
if (!definition) {
|
|
278
|
-
let name = `${helper}Factory${factories.size}`
|
|
279
|
-
while (names.has(name)) name += '_'
|
|
280
|
-
names.add(name)
|
|
281
|
-
definition = { name, parameters: values.map((_, index) => `v${index}`) }
|
|
282
|
-
factories.set(expression, definition)
|
|
283
|
-
}
|
|
284
|
-
const value = `${definition.name}(${values.join(',')})`
|
|
285
|
-
initializers.set(value, { name: definition.name, values })
|
|
286
|
-
return value
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
function callable(
|
|
290
|
-
recipe: Recipe.Definition,
|
|
291
|
-
name: string,
|
|
292
|
-
call?: Pick<
|
|
293
|
-
Source.Call,
|
|
294
|
-
'slots' | 'recipe' | 'valuesType' | 'recipeTypes' | 'nativeContext'
|
|
295
|
-
>,
|
|
296
|
-
contextOptions = options,
|
|
297
|
-
compiled?: Variants.Definition,
|
|
298
|
-
bindings?: ReturnType<typeof NativeBindings.prepare>,
|
|
299
|
-
): string {
|
|
300
|
-
const program =
|
|
301
|
-
Object.keys(recipe.axes).length > 0 ||
|
|
302
|
-
call?.slots ||
|
|
303
|
-
call?.recipe?.payloads?.length
|
|
304
|
-
|
|
305
|
-
if (contextOptions.contextual) {
|
|
306
|
-
const vars = call?.nativeContext?.vars ?? contextOptions.vars
|
|
307
|
-
const media = (() => {
|
|
308
|
-
try {
|
|
309
|
-
return NativeMedia.prepare(
|
|
310
|
-
recipe.rules.flatMap((rule) => rule.value.styles),
|
|
311
|
-
vars,
|
|
312
|
-
contextOptions,
|
|
313
|
-
)
|
|
314
|
-
} catch (error) {
|
|
315
|
-
throw new CompileError((error as Error).message)
|
|
316
|
-
}
|
|
317
|
-
})()
|
|
318
|
-
if (media) {
|
|
319
|
-
const profiles = media.selections.map((selection) => {
|
|
320
|
-
const selected = media.select(selection)
|
|
321
|
-
const next = {
|
|
322
|
-
...recipe,
|
|
323
|
-
rules: recipe.rules.map((rule) => ({
|
|
324
|
-
...rule,
|
|
325
|
-
value: {
|
|
326
|
-
...rule.value,
|
|
327
|
-
styles: rule.value.styles.map(selected.style),
|
|
328
|
-
},
|
|
329
|
-
})),
|
|
330
|
-
}
|
|
331
|
-
const source = call?.nativeContext
|
|
332
|
-
? {
|
|
333
|
-
...call,
|
|
334
|
-
nativeContext: {
|
|
335
|
-
...call.nativeContext,
|
|
336
|
-
vars: selected.vars as typeof call.nativeContext.vars,
|
|
337
|
-
},
|
|
338
|
-
}
|
|
339
|
-
: call
|
|
340
|
-
const value = callable(next, name, source, {
|
|
341
|
-
...contextOptions,
|
|
342
|
-
vars: selected.vars,
|
|
343
|
-
})
|
|
344
|
-
return `${JSON.stringify(selection)}:${value}`
|
|
345
|
-
})
|
|
346
|
-
// A single static table cannot represent the responsive callable.
|
|
347
|
-
delete recipes[name]
|
|
348
|
-
|
|
349
|
-
return `${helper}Context.responsive(${JSON.stringify(media.queries)},{${profiles.join(',')}})`
|
|
350
|
-
}
|
|
351
|
-
if (!program)
|
|
352
|
-
compiled ??= Variants.compile({
|
|
353
|
-
recipe,
|
|
354
|
-
fonts: contextOptions.fonts,
|
|
355
|
-
platform: contextOptions.platform,
|
|
356
|
-
vars,
|
|
357
|
-
units: contextOptions.units,
|
|
358
|
-
})
|
|
359
|
-
else {
|
|
360
|
-
try {
|
|
361
|
-
bindings = NativeBindings.prepare(recipe, call ?? {}, {
|
|
362
|
-
...contextOptions,
|
|
363
|
-
vars,
|
|
364
|
-
})
|
|
365
|
-
} catch (error) {
|
|
366
|
-
if (error instanceof StyleSheet.CompileError) throw error
|
|
367
|
-
throw new CompileError((error as Error).message)
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
const defaultVars =
|
|
371
|
-
call?.nativeContext?.defaultVars ?? contextOptions.set ?? 'default'
|
|
372
|
-
const tables = new Map<string, string>()
|
|
373
|
-
const alternatives = (vars ? Object.keys(vars) : ['default']).map(
|
|
374
|
-
(set) => ({
|
|
375
|
-
set,
|
|
376
|
-
schemes: (['light', 'dark'] as const).map((colorScheme) => {
|
|
377
|
-
const value = callable(
|
|
378
|
-
recipe,
|
|
379
|
-
name,
|
|
380
|
-
call,
|
|
381
|
-
{
|
|
382
|
-
...contextOptions,
|
|
383
|
-
contextual: false,
|
|
384
|
-
vars,
|
|
385
|
-
set,
|
|
386
|
-
colorScheme,
|
|
387
|
-
},
|
|
388
|
-
compiled,
|
|
389
|
-
bindings,
|
|
390
|
-
)
|
|
391
|
-
if (!tables.has(value))
|
|
392
|
-
tables.set(value, `${helper}Table${tables.size}`)
|
|
393
|
-
return { colorScheme, value }
|
|
394
|
-
}),
|
|
395
|
-
}),
|
|
396
|
-
)
|
|
397
|
-
const entries = alternatives.map(
|
|
398
|
-
({ set, schemes }) =>
|
|
399
|
-
`${JSON.stringify(set)}:{${schemes.map(({ colorScheme, value }) => `${JSON.stringify(colorScheme)}:${tables.get(value)}`).join(',')}}`,
|
|
400
|
-
)
|
|
401
|
-
const parameters = [...tables.values()].map((name, index) =>
|
|
402
|
-
typed ? `${name}:T${index}` : name,
|
|
403
|
-
)
|
|
404
|
-
const types = typed
|
|
405
|
-
? `<${parameters.map((_, index) => `const T${index} extends (input:never)=>import('zyzz/runtime').Native.Props<object>`).join(',')},>`
|
|
406
|
-
: ''
|
|
407
|
-
const expression = `${types}(${parameters.join(',')})=>${helper}Context.create({${entries.join(',')}},${JSON.stringify(defaultVars)})`
|
|
408
|
-
let context = contexts.get(expression)
|
|
409
|
-
if (!context) {
|
|
410
|
-
context = `${helper}ContextFactory${contexts.size}`
|
|
411
|
-
while (names.has(context)) context += '_'
|
|
412
|
-
names.add(context)
|
|
413
|
-
contexts.set(expression, context)
|
|
414
|
-
}
|
|
415
|
-
const inputs = [...tables.keys()].map((value) => initializers.get(value))
|
|
416
|
-
if (inputs.every((input) => input !== undefined)) {
|
|
417
|
-
const values: string[] = []
|
|
418
|
-
const arguments_ = inputs.map((input) => {
|
|
419
|
-
const parameters = input.values.map((value) => {
|
|
420
|
-
const parameter = `v${values.length}`
|
|
421
|
-
values.push(value)
|
|
422
|
-
return parameter
|
|
423
|
-
})
|
|
424
|
-
return `${input.name}(${parameters.join(',')})`
|
|
425
|
-
})
|
|
426
|
-
if (values.length <= 64)
|
|
427
|
-
return factory(`${context}(${arguments_.join(',')})`, values)
|
|
428
|
-
}
|
|
429
|
-
return `${context}(${[...tables.keys()].join(',')})`
|
|
430
|
-
}
|
|
431
|
-
const axes = Object.entries(recipe.axes)
|
|
432
|
-
.map(
|
|
433
|
-
([axis, choices]) =>
|
|
434
|
-
`${JSON.stringify(axis)}:readonly ${JSON.stringify(choices)}`,
|
|
435
|
-
)
|
|
436
|
-
.join(';')
|
|
437
|
-
|
|
438
|
-
if (program) {
|
|
439
|
-
const scalar = !!(call?.slots || call?.recipe?.payloads?.length)
|
|
440
|
-
dynamic ||= scalar
|
|
441
|
-
finite ||= !scalar
|
|
442
|
-
const compiled = (() => {
|
|
443
|
-
try {
|
|
444
|
-
const compiled = NativeBindings.compile(
|
|
445
|
-
recipe,
|
|
446
|
-
call ?? {},
|
|
447
|
-
contextOptions,
|
|
448
|
-
bindings,
|
|
449
|
-
)
|
|
450
|
-
return scalar ? compiled : NativeBindings.finite(compiled)
|
|
451
|
-
} catch (error) {
|
|
452
|
-
if (error instanceof StyleSheet.CompileError) throw error
|
|
453
|
-
throw new CompileError((error as Error).message)
|
|
454
|
-
}
|
|
455
|
-
})()
|
|
456
|
-
const value = create(scalar ? dynamicHelper : `${helper}Static`, compiled)
|
|
457
|
-
if (!typed) return value
|
|
458
|
-
if (!call?.slots && !call?.recipe?.payloads?.length)
|
|
459
|
-
return `(${value} as import('zyzz/runtime').Native.Callable<{${axes}}>)`
|
|
460
|
-
|
|
461
|
-
let input = call.valuesType ?? '{}'
|
|
462
|
-
if (call.recipe) {
|
|
463
|
-
input = `{${Object.entries(recipe.axes)
|
|
464
|
-
.map(([axis, choices]) => {
|
|
465
|
-
const types = choices.map((choice) =>
|
|
466
|
-
call.recipeTypes?.[axis]?.[choice]
|
|
467
|
-
? `{${JSON.stringify(choice)}:${call.recipeTypes[axis]![choice]}}`
|
|
468
|
-
: choice === 'true' || choice === 'false'
|
|
469
|
-
? choice
|
|
470
|
-
: JSON.stringify(choice),
|
|
471
|
-
)
|
|
472
|
-
return `${JSON.stringify(axis)}?:${types.join('|')}|null|undefined`
|
|
473
|
-
})
|
|
474
|
-
.join(';')}}`
|
|
475
|
-
}
|
|
476
|
-
return `(${value} as import('zyzz/runtime').NativeDynamic.${call.recipe ? 'RecipeCallable' : 'Callable'}<${input}>)`
|
|
477
|
-
}
|
|
478
|
-
compiled ??= Variants.compile({
|
|
479
|
-
recipe,
|
|
480
|
-
fonts: contextOptions.fonts,
|
|
481
|
-
platform: contextOptions.platform,
|
|
482
|
-
vars: contextOptions.vars,
|
|
483
|
-
units: contextOptions.units,
|
|
484
|
-
})
|
|
485
|
-
recipes[name] = compiled
|
|
486
|
-
const styles = StyleSheet.select(compiled.styles, {
|
|
487
|
-
set: contextOptions.set ?? 'default',
|
|
488
|
-
colorScheme: contextOptions.colorScheme,
|
|
489
|
-
})
|
|
490
|
-
const cached = compiledCalls.get(compiled)
|
|
491
|
-
const value =
|
|
492
|
-
cached &&
|
|
493
|
-
Object.keys(cached.styles).length === Object.keys(styles).length &&
|
|
494
|
-
Object.entries(styles).every(
|
|
495
|
-
([name, style]) => cached.styles[name] === style,
|
|
496
|
-
)
|
|
497
|
-
? cached.value
|
|
498
|
-
: create(helper, {
|
|
499
|
-
axes: compiled.axes,
|
|
500
|
-
defaults: compiled.defaults,
|
|
501
|
-
styles,
|
|
502
|
-
})
|
|
503
|
-
if (options.contextual) compiledCalls.set(compiled, { styles, value })
|
|
504
|
-
if (!typed) return value
|
|
505
|
-
return `(${value} as import('zyzz/runtime').Native.Callable<{${axes}}>)`
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
const packed: string[] = []
|
|
509
|
-
const explicit = new Set<string>()
|
|
510
|
-
function binding(node: Ast.Node) {
|
|
511
|
-
if (node.type === 'Identifier') explicit.add(node.name)
|
|
512
|
-
else if (node.type === 'ObjectPattern')
|
|
513
|
-
for (const property of node.properties)
|
|
514
|
-
binding(
|
|
515
|
-
property.type === 'RestElement' ? property.argument : property.value,
|
|
516
|
-
)
|
|
517
|
-
else if (node.type === 'ArrayPattern')
|
|
518
|
-
for (const element of node.elements) {
|
|
519
|
-
if (element) binding(element)
|
|
520
|
-
}
|
|
521
|
-
else if (node.type === 'AssignmentPattern') binding(node.left)
|
|
522
|
-
else if (node.type === 'RestElement') binding(node.argument)
|
|
523
|
-
}
|
|
524
|
-
for (const statement of parsed.program.body) {
|
|
525
|
-
if (
|
|
526
|
-
statement.type !== 'ExportNamedDeclaration' ||
|
|
527
|
-
statement.exportKind === 'type'
|
|
528
|
-
)
|
|
529
|
-
continue
|
|
530
|
-
for (const specifier of statement.specifiers)
|
|
531
|
-
if (specifier.exportKind !== 'type')
|
|
532
|
-
explicit.add(
|
|
533
|
-
specifier.exported.type === 'Identifier'
|
|
534
|
-
? specifier.exported.name
|
|
535
|
-
: specifier.exported.value,
|
|
536
|
-
)
|
|
537
|
-
const declaration = statement.declaration
|
|
538
|
-
if (declaration?.type === 'VariableDeclaration') {
|
|
539
|
-
for (const item of declaration.declarations) binding(item.id)
|
|
540
|
-
} else if (
|
|
541
|
-
declaration &&
|
|
542
|
-
'id' in declaration &&
|
|
543
|
-
declaration.id?.type === 'Identifier'
|
|
544
|
-
)
|
|
545
|
-
explicit.add(declaration.id.name)
|
|
546
|
-
}
|
|
547
|
-
for (const statement of parsed.program.body) {
|
|
548
|
-
if (
|
|
549
|
-
(statement.type !== 'ImportDeclaration' &&
|
|
550
|
-
statement.type !== 'ExportNamedDeclaration' &&
|
|
551
|
-
statement.type !== 'ExportAllDeclaration') ||
|
|
552
|
-
!statement.source
|
|
553
|
-
)
|
|
554
|
-
continue
|
|
555
|
-
if (
|
|
556
|
-
(statement.type === 'ImportDeclaration' &&
|
|
557
|
-
statement.importKind === 'type') ||
|
|
558
|
-
(statement.type !== 'ImportDeclaration' &&
|
|
559
|
-
statement.exportKind === 'type')
|
|
560
|
-
)
|
|
561
|
-
continue
|
|
562
|
-
const specifier = statement.source.value
|
|
563
|
-
const exports = options[Themes.context]?.libraries?.[specifier]
|
|
564
|
-
if (!exports) continue
|
|
565
|
-
|
|
566
|
-
let imported: string | undefined
|
|
567
|
-
function original(): string {
|
|
568
|
-
if (imported) return imported
|
|
569
|
-
imported = `${helper}Namespace${packed.length}`
|
|
570
|
-
while (names.has(imported)) imported += '_'
|
|
571
|
-
names.add(imported)
|
|
572
|
-
packed.push(`import * as ${imported} from ${JSON.stringify(specifier)};`)
|
|
573
|
-
return imported
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
function overlay(original: string, expression: string): string {
|
|
577
|
-
let overrides = `${helper}Members${packed.length}`
|
|
578
|
-
while (names.has(overrides)) overrides += '_'
|
|
579
|
-
names.add(overrides)
|
|
580
|
-
packed.push(`const ${overrides}=${expression};`)
|
|
581
|
-
// Getter descriptors retain live bindings outside the recipe contract.
|
|
582
|
-
return `Object.freeze(Object.defineProperties({...${original},...${overrides}},Object.fromEntries(Object.keys(${original}).filter(key=>!Object.hasOwn(${overrides},key)).map(key=>[key,{get:()=>Reflect.get(${original},key)}]))))`
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
function value(
|
|
586
|
-
name: string,
|
|
587
|
-
link = exports![name],
|
|
588
|
-
input?: string,
|
|
589
|
-
path: readonly string[] = [name],
|
|
590
|
-
): string | undefined {
|
|
591
|
-
if (!link || link.kind !== 'style-reference') return undefined
|
|
592
|
-
if (link.members) {
|
|
593
|
-
const source = input ?? `${original()}[${JSON.stringify(name)}]`
|
|
594
|
-
const expression = `{${Object.entries(link.members)
|
|
595
|
-
.map(
|
|
596
|
-
([member, link]) =>
|
|
597
|
-
`[${JSON.stringify(member)}]:${value(`${name}.${member}`, link, `${source}[${JSON.stringify(member)}]`, [...path, member])}`,
|
|
598
|
-
)
|
|
599
|
-
.join(',')}}`
|
|
600
|
-
return overlay(source, expression)
|
|
601
|
-
}
|
|
602
|
-
const recipe = link.style?.staticRecipe ?? link.style?.dynamic?.recipe
|
|
603
|
-
if (
|
|
604
|
-
!recipe ||
|
|
605
|
-
link.style?.output ||
|
|
606
|
-
(link.style?.slots.length && !link.style.dynamic)
|
|
607
|
-
)
|
|
608
|
-
throw new CompileError(
|
|
609
|
-
`Packed native callable ${name} requires a static recipe contract.`,
|
|
610
|
-
)
|
|
611
|
-
const expression = callable(recipe, `${specifier}:${name}`, {
|
|
612
|
-
nativeContext: link.style?.nativeContext,
|
|
613
|
-
...(link.style?.dynamic
|
|
614
|
-
? {
|
|
615
|
-
slots: link.style.dynamic.slots,
|
|
616
|
-
recipe: {
|
|
617
|
-
axes: recipe.axes,
|
|
618
|
-
defaults: recipe.defaults,
|
|
619
|
-
payloads: link.style.dynamic.payloads,
|
|
620
|
-
defaultPayloads: link.style.dynamic.defaultPayloads,
|
|
621
|
-
},
|
|
622
|
-
}
|
|
623
|
-
: {}),
|
|
624
|
-
})
|
|
625
|
-
if (!link.style?.dynamic || !typed) return expression
|
|
626
|
-
const type = `typeof import(${JSON.stringify(specifier)})${path
|
|
627
|
-
.map((part) => `[${JSON.stringify(part)}]`)
|
|
628
|
-
.join('')}`
|
|
629
|
-
return `(${expression} as import('zyzz/runtime').NativeDynamic.From<${type}>)`
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
function namespace(): string | undefined {
|
|
633
|
-
if (
|
|
634
|
-
!Object.values(exports!).some((link) => link.kind === 'style-reference')
|
|
635
|
-
)
|
|
636
|
-
return undefined
|
|
637
|
-
const imported = original()
|
|
638
|
-
const members = Object.keys(exports!).flatMap((name) => {
|
|
639
|
-
const expression = value(
|
|
640
|
-
name,
|
|
641
|
-
exports![name],
|
|
642
|
-
`${imported}[${JSON.stringify(name)}]`,
|
|
643
|
-
)
|
|
644
|
-
return expression === undefined
|
|
645
|
-
? []
|
|
646
|
-
: [`[${JSON.stringify(name)}]:${expression}`]
|
|
647
|
-
})
|
|
648
|
-
return overlay(imported, `{${members.join(',')}}`)
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
if (statement.type === 'ExportAllDeclaration') {
|
|
652
|
-
if (statement.exported) {
|
|
653
|
-
const expression = namespace()
|
|
654
|
-
if (expression === undefined) continue
|
|
655
|
-
let local = `${helper}Export${packed.length}`
|
|
656
|
-
while (names.has(local)) local += '_'
|
|
657
|
-
names.add(local)
|
|
658
|
-
const name =
|
|
659
|
-
statement.exported.type === 'Identifier'
|
|
660
|
-
? statement.exported.name
|
|
661
|
-
: statement.exported.value
|
|
662
|
-
packed.push(
|
|
663
|
-
`const ${local}=${expression};export {${local} as ${JSON.stringify(name)}};`,
|
|
664
|
-
)
|
|
665
|
-
overwrite(statement.start, statement.end, '')
|
|
666
|
-
continue
|
|
667
|
-
}
|
|
668
|
-
for (const name of Object.keys(exports)) {
|
|
669
|
-
if (name === 'default' || explicit.has(name)) continue
|
|
670
|
-
const expression = value(name)
|
|
671
|
-
if (expression === undefined) continue
|
|
672
|
-
explicit.add(name)
|
|
673
|
-
let local = `${helper}Export${packed.length}`
|
|
674
|
-
while (names.has(local)) local += '_'
|
|
675
|
-
names.add(local)
|
|
676
|
-
packed.push(
|
|
677
|
-
`const ${local}=${expression};export {${local} as ${JSON.stringify(name)}};`,
|
|
678
|
-
)
|
|
679
|
-
}
|
|
680
|
-
continue
|
|
681
|
-
}
|
|
682
|
-
const kept: string[] = []
|
|
683
|
-
for (const specifier of statement.specifiers) {
|
|
684
|
-
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
685
|
-
const expression = namespace()
|
|
686
|
-
if (expression === undefined) {
|
|
687
|
-
packed.push(
|
|
688
|
-
`import * as ${specifier.local.name} from ${JSON.stringify(statement.source.value)};`,
|
|
689
|
-
)
|
|
690
|
-
} else packed.push(`const ${specifier.local.name}=${expression};`)
|
|
691
|
-
continue
|
|
692
|
-
}
|
|
693
|
-
if (
|
|
694
|
-
(specifier.type === 'ImportSpecifier' &&
|
|
695
|
-
specifier.importKind === 'type') ||
|
|
696
|
-
(specifier.type === 'ExportSpecifier' &&
|
|
697
|
-
specifier.exportKind === 'type')
|
|
698
|
-
) {
|
|
699
|
-
kept.push(options.source.slice(specifier.start, specifier.end))
|
|
700
|
-
continue
|
|
701
|
-
}
|
|
702
|
-
const imported =
|
|
703
|
-
specifier.type === 'ImportDefaultSpecifier'
|
|
704
|
-
? 'default'
|
|
705
|
-
: specifier.type === 'ImportSpecifier'
|
|
706
|
-
? specifier.imported
|
|
707
|
-
: specifier.local
|
|
708
|
-
const name =
|
|
709
|
-
typeof imported === 'string'
|
|
710
|
-
? imported
|
|
711
|
-
: imported.type === 'Identifier'
|
|
712
|
-
? imported.name
|
|
713
|
-
: imported.value
|
|
714
|
-
const expression = value(name)
|
|
715
|
-
if (expression === undefined) {
|
|
716
|
-
if (specifier.type === 'ImportDefaultSpecifier')
|
|
717
|
-
kept.push(`default as ${specifier.local.name}`)
|
|
718
|
-
else kept.push(options.source.slice(specifier.start, specifier.end))
|
|
719
|
-
continue
|
|
720
|
-
}
|
|
721
|
-
if (specifier.type === 'ExportSpecifier') {
|
|
722
|
-
let local = `${helper}Export${packed.length}`
|
|
723
|
-
while (names.has(local)) local += '_'
|
|
724
|
-
names.add(local)
|
|
725
|
-
const exported =
|
|
726
|
-
specifier.exported.type === 'Identifier'
|
|
727
|
-
? specifier.exported.name
|
|
728
|
-
: specifier.exported.value
|
|
729
|
-
packed.push(
|
|
730
|
-
`const ${local}=${expression};export {${local} as ${JSON.stringify(exported)}};`,
|
|
731
|
-
)
|
|
732
|
-
} else packed.push(`const ${specifier.local.name}=${expression};`)
|
|
733
|
-
}
|
|
734
|
-
const keyword = statement.type === 'ImportDeclaration' ? 'import' : 'export'
|
|
735
|
-
overwrite(
|
|
736
|
-
statement.start,
|
|
737
|
-
statement.end,
|
|
738
|
-
kept.length
|
|
739
|
-
? `${keyword} {${kept.join(',')}} from ${JSON.stringify(statement.source.value)};`
|
|
740
|
-
: `import ${JSON.stringify(statement.source.value)};`,
|
|
741
|
-
)
|
|
742
|
-
}
|
|
743
|
-
const compositions: string[] = []
|
|
744
|
-
for (const statement of parsed.program.body) {
|
|
745
|
-
if (
|
|
746
|
-
statement.type === 'ExportAllDeclaration' &&
|
|
747
|
-
statement.source.value === 'zyzz' &&
|
|
748
|
-
statement.exportKind !== 'type'
|
|
749
|
-
)
|
|
750
|
-
throw new CompileError(
|
|
751
|
-
'Native modules require named re-exports from zyzz.',
|
|
752
|
-
)
|
|
753
|
-
if (
|
|
754
|
-
statement.type === 'ExportNamedDeclaration' &&
|
|
755
|
-
statement.source?.value === 'zyzz' &&
|
|
756
|
-
statement.exportKind !== 'type'
|
|
757
|
-
) {
|
|
758
|
-
const cx = statement.specifiers.filter(
|
|
759
|
-
(specifier) =>
|
|
760
|
-
specifier.exportKind !== 'type' &&
|
|
761
|
-
(specifier.local.type === 'Identifier'
|
|
762
|
-
? specifier.local.name
|
|
763
|
-
: specifier.local.value) === 'cx',
|
|
764
|
-
)
|
|
765
|
-
if (!cx.length) continue
|
|
766
|
-
let binding = `${helper}Compose`
|
|
767
|
-
while (names.has(binding)) binding += '_'
|
|
768
|
-
names.add(binding)
|
|
769
|
-
compositions.push(`const ${binding}=${helper}.compose;`)
|
|
770
|
-
const kept = statement.specifiers
|
|
771
|
-
.filter((specifier) => !cx.includes(specifier))
|
|
772
|
-
.map((specifier) =>
|
|
773
|
-
options.source.slice(specifier.start, specifier.end),
|
|
774
|
-
)
|
|
775
|
-
const exports = cx.map(
|
|
776
|
-
(specifier) =>
|
|
777
|
-
`${binding} as ${options.source.slice(specifier.exported.start, specifier.exported.end)}`,
|
|
778
|
-
)
|
|
779
|
-
overwrite(
|
|
780
|
-
statement.start,
|
|
781
|
-
statement.end,
|
|
782
|
-
`${kept.length ? `export {${kept.join(',')}} from 'zyzz';` : ''}export {${exports.join(',')}};`,
|
|
783
|
-
)
|
|
784
|
-
continue
|
|
785
|
-
}
|
|
786
|
-
if (
|
|
787
|
-
statement.type !== 'ImportDeclaration' ||
|
|
788
|
-
statement.source.value !== 'zyzz' ||
|
|
789
|
-
statement.importKind === 'type'
|
|
790
|
-
)
|
|
791
|
-
continue
|
|
792
|
-
const cx = statement.specifiers.filter(
|
|
793
|
-
(specifier) =>
|
|
794
|
-
specifier.type === 'ImportSpecifier' &&
|
|
795
|
-
specifier.importKind !== 'type' &&
|
|
796
|
-
(specifier.imported.type === 'Identifier'
|
|
797
|
-
? specifier.imported.name
|
|
798
|
-
: specifier.imported.value) === 'cx',
|
|
799
|
-
)
|
|
800
|
-
if (!cx.length) continue
|
|
801
|
-
compositions.push(
|
|
802
|
-
...cx.map(
|
|
803
|
-
(specifier) => `const ${specifier.local.name}=${helper}.compose;`,
|
|
804
|
-
),
|
|
805
|
-
)
|
|
806
|
-
const kept = statement.specifiers.filter(
|
|
807
|
-
(specifier) => !cx.includes(specifier),
|
|
808
|
-
)
|
|
809
|
-
const named = kept
|
|
810
|
-
.filter((specifier) => specifier.type === 'ImportSpecifier')
|
|
811
|
-
.map((specifier) => options.source.slice(specifier.start, specifier.end))
|
|
812
|
-
const other = kept
|
|
813
|
-
.filter((specifier) => specifier.type !== 'ImportSpecifier')
|
|
814
|
-
.map((specifier) => options.source.slice(specifier.start, specifier.end))
|
|
815
|
-
const imports = [
|
|
816
|
-
...other,
|
|
817
|
-
...(named.length ? [`{${named.join(',')}}`] : []),
|
|
818
|
-
]
|
|
819
|
-
overwrite(
|
|
820
|
-
statement.start,
|
|
821
|
-
statement.end,
|
|
822
|
-
imports.length ? `import ${imports.join(',')} from 'zyzz';` : '',
|
|
823
|
-
)
|
|
824
|
-
}
|
|
825
|
-
if (
|
|
826
|
-
extracted.calls.length ||
|
|
827
|
-
compositions.length ||
|
|
828
|
-
packed.length ||
|
|
829
|
-
variables.size ||
|
|
830
|
-
imports.size
|
|
831
|
-
) {
|
|
832
|
-
let offset = 0
|
|
833
|
-
if (options.source.startsWith('#!')) {
|
|
834
|
-
const newline = /\r\n|[\n\r\u2028\u2029]/.exec(options.source)
|
|
835
|
-
offset = newline
|
|
836
|
-
? newline.index + newline[0].length
|
|
837
|
-
: options.source.length
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
for (const node of parsed.program.body) {
|
|
841
|
-
if (node.type !== 'ExpressionStatement' || !node.directive) break
|
|
842
|
-
|
|
843
|
-
offset = node.end
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
const prelude = `\nimport {Native as ${helper}${dynamic ? `,NativeDynamic as ${dynamicHelper}` : ''}${finite ? `,NativeStatic as ${helper}Static` : ''}${options.contextual ? `,NativeContext as ${helper}Context` : ''}${variables.size ? `,NativeVars as ${helper}Vars` : ''}} from 'zyzz/runtime';\n${[...factories].map(([expression, factory]) => `const ${factory.name}=(${factory.parameters.join(',')})=>${expression};`).join('\n')}\n${[...contexts].map(([expression, name]) => `const ${name}=${expression};`).join('\n')}\n${[...variables].map(([value, name]) => `${shared?.definitions.has(value) ? 'export ' : ''}const ${name}=${helper}Vars.create(JSON.parse(${JSON.stringify(value)}));`).join('\n')}\n${[...imports, ...compositions, ...packed].join('\n')}\n`
|
|
847
|
-
module.appendLeft(offset, prelude)
|
|
848
|
-
edits.push({ start: offset, end: offset, code: prelude, expression: false })
|
|
849
|
-
}
|
|
850
|
-
return output(module, {
|
|
851
|
-
edits,
|
|
18
|
+
const output = Results.call<Results.NativeOutput>('native.compile', {
|
|
19
|
+
...Results.native(options),
|
|
20
|
+
context: options[Context.key] === true,
|
|
852
21
|
moduleId: options.moduleId,
|
|
853
|
-
|
|
22
|
+
source: options.source,
|
|
854
23
|
})
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
[Edits.key]: output.edits,
|
|
27
|
+
code: output.code,
|
|
28
|
+
map: output.map,
|
|
29
|
+
recipes: Results.frozen(output.recipes) as compile.ReturnType['recipes'],
|
|
30
|
+
}
|
|
855
31
|
}
|
|
856
32
|
|
|
857
33
|
/** Native source compilation contracts. */
|
|
@@ -868,10 +44,8 @@ export declare namespace compile {
|
|
|
868
44
|
type Options = Omit<StyleSheet.compile.Options, 'styles'> & {
|
|
869
45
|
/** Internal Babel emission mode; authoring types are still validated. */
|
|
870
46
|
readonly [Edits.runtime]?: boolean | undefined
|
|
871
|
-
/**
|
|
872
|
-
readonly [
|
|
873
|
-
/** Compiler-owned graph context. */
|
|
874
|
-
readonly [Themes.context]?: Themes.Context | undefined
|
|
47
|
+
/** Compiles the module as a member of an adapter-owned graph. */
|
|
48
|
+
readonly [Context.key]?: true | undefined
|
|
875
49
|
/** Retain every set and scheme for render-local selection. */
|
|
876
50
|
readonly contextual?: boolean | undefined
|
|
877
51
|
/** Scheme compiled into this module's callables. Recompile to select another scheme. */
|
|
@@ -901,30 +75,3 @@ export class CompileError extends Error {
|
|
|
901
75
|
/** Stable namespaced diagnostic name. */
|
|
902
76
|
override name = 'Native.CompileError'
|
|
903
77
|
}
|
|
904
|
-
|
|
905
|
-
// Keep lazy maps independent of the compiler's parser trees and extracted styles.
|
|
906
|
-
function output(
|
|
907
|
-
module: MagicString,
|
|
908
|
-
options: {
|
|
909
|
-
readonly edits: readonly Edits.Edit[]
|
|
910
|
-
readonly moduleId: string
|
|
911
|
-
readonly recipes: compile.ReturnType['recipes']
|
|
912
|
-
},
|
|
913
|
-
): compile.ReturnType {
|
|
914
|
-
let sourceMap: string | undefined
|
|
915
|
-
|
|
916
|
-
return {
|
|
917
|
-
[Edits.key]: options.edits,
|
|
918
|
-
code: module.toString(),
|
|
919
|
-
get map() {
|
|
920
|
-
return (sourceMap ??= module
|
|
921
|
-
.generateMap({
|
|
922
|
-
hires: true,
|
|
923
|
-
includeContent: true,
|
|
924
|
-
source: options.moduleId,
|
|
925
|
-
})
|
|
926
|
-
.toString())
|
|
927
|
-
},
|
|
928
|
-
recipes: options.recipes,
|
|
929
|
-
}
|
|
930
|
-
}
|