zyzz 0.0.21 → 0.0.22
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/Zyzz.podspec +16 -0
- package/dist/Style.d.ts +3 -1
- package/dist/Style.d.ts.map +1 -1
- package/dist/Style.js.map +1 -1
- package/dist/babel/NativeJsx.d.ts.map +1 -1
- package/dist/babel/NativeJsx.js +204 -12
- package/dist/babel/NativeJsx.js.map +1 -1
- package/dist/babel/index.d.ts +6 -2
- package/dist/babel/index.d.ts.map +1 -1
- package/dist/babel/index.js +10 -1
- package/dist/babel/index.js.map +1 -1
- package/dist/compiler/Graph.d.ts.map +1 -1
- package/dist/compiler/Graph.js +64 -0
- package/dist/compiler/Graph.js.map +1 -1
- package/dist/compiler/Native.d.ts +6 -3
- package/dist/compiler/Native.d.ts.map +1 -1
- package/dist/compiler/Native.js +142 -24
- package/dist/compiler/Native.js.map +1 -1
- package/dist/compiler/Source.d.ts +2 -0
- package/dist/compiler/Source.d.ts.map +1 -1
- package/dist/compiler/Source.js +17 -5
- package/dist/compiler/Source.js.map +1 -1
- package/dist/compiler/internal/Configurations.d.ts +2 -0
- package/dist/compiler/internal/Configurations.d.ts.map +1 -1
- package/dist/compiler/internal/Configurations.js +21 -3
- package/dist/compiler/internal/Configurations.js.map +1 -1
- package/dist/compiler/internal/Contract.d.ts.map +1 -1
- package/dist/compiler/internal/Contract.js +75 -38
- package/dist/compiler/internal/Contract.js.map +1 -1
- package/dist/compiler/internal/Contributions.d.ts.map +1 -1
- package/dist/compiler/internal/Contributions.js +7 -1
- package/dist/compiler/internal/Contributions.js.map +1 -1
- package/dist/compiler/internal/Descriptors.d.ts.map +1 -1
- package/dist/compiler/internal/Descriptors.js +11 -2
- package/dist/compiler/internal/Descriptors.js.map +1 -1
- package/dist/compiler/internal/NativeBindings.d.ts +24 -26
- package/dist/compiler/internal/NativeBindings.d.ts.map +1 -1
- package/dist/compiler/internal/NativeBindings.js +61 -8
- package/dist/compiler/internal/NativeBindings.js.map +1 -1
- package/dist/compiler/internal/NativeMedia.d.ts +14 -0
- package/dist/compiler/internal/NativeMedia.d.ts.map +1 -0
- package/dist/compiler/internal/NativeMedia.js +287 -0
- package/dist/compiler/internal/NativeMedia.js.map +1 -0
- package/dist/compiler/internal/NativeVars.d.ts +28 -0
- package/dist/compiler/internal/NativeVars.d.ts.map +1 -0
- package/dist/compiler/internal/NativeVars.js +157 -0
- package/dist/compiler/internal/NativeVars.js.map +1 -0
- package/dist/compiler/internal/PackedStyles.d.ts +2 -0
- package/dist/compiler/internal/PackedStyles.d.ts.map +1 -1
- package/dist/compiler/internal/PackedStyles.js +2 -0
- package/dist/compiler/internal/PackedStyles.js.map +1 -1
- package/dist/compiler/internal/Themes.d.ts +22 -1
- package/dist/compiler/internal/Themes.d.ts.map +1 -1
- package/dist/compiler/internal/Themes.js +118 -3
- package/dist/compiler/internal/Themes.js.map +1 -1
- package/dist/compiler/internal/Vars.d.ts +1 -1
- package/dist/compiler/internal/Vars.d.ts.map +1 -1
- package/dist/compiler/internal/Vars.js +7 -2
- package/dist/compiler/internal/Vars.js.map +1 -1
- package/dist/default.js.zyzz.json +1 -1
- package/dist/internal/Completion.d.ts +1 -1
- package/dist/internal/Completion.d.ts.map +1 -1
- package/dist/internal/Targets.d.ts.map +1 -1
- package/dist/internal/Targets.js +2 -0
- package/dist/internal/Targets.js.map +1 -1
- package/dist/internal/Token.d.ts +0 -2
- package/dist/internal/Token.d.ts.map +1 -1
- package/dist/internal/Token.js.map +1 -1
- package/dist/internal/Value.d.ts +7 -0
- package/dist/internal/Value.d.ts.map +1 -1
- package/dist/internal/Value.js.map +1 -1
- package/dist/metro/Graph.d.ts +22 -7
- package/dist/metro/Graph.d.ts.map +1 -1
- package/dist/metro/Graph.js +179 -42
- package/dist/metro/Graph.js.map +1 -1
- package/dist/metro/Watch.d.ts +28 -4
- package/dist/metro/Watch.d.ts.map +1 -1
- package/dist/metro/Watch.js +39 -7
- package/dist/metro/Watch.js.map +1 -1
- package/dist/metro/index.d.ts +15 -4
- package/dist/metro/index.d.ts.map +1 -1
- package/dist/metro/index.js +27 -0
- package/dist/metro/index.js.map +1 -1
- package/dist/metro/transformer.d.ts +5 -1
- package/dist/metro/transformer.d.ts.map +1 -1
- package/dist/metro/transformer.js +5 -3
- package/dist/metro/transformer.js.map +1 -1
- package/dist/react-native/StyleSheet.d.ts +3 -2
- package/dist/react-native/StyleSheet.d.ts.map +1 -1
- package/dist/react-native/StyleSheet.js +17 -34
- package/dist/react-native/StyleSheet.js.map +1 -1
- package/dist/react-native/index.d.ts +1 -1
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/react-native/index.js +1 -1
- package/dist/react-native/index.js.map +1 -1
- package/dist/react-native/index.native.d.ts +5 -0
- package/dist/react-native/index.native.js +20 -0
- package/dist/react-native/index.native.js.map +7 -0
- package/dist/react-native/internal/Calculation.d.ts +7 -0
- package/dist/react-native/internal/Calculation.d.ts.map +1 -0
- package/dist/react-native/internal/Calculation.js +134 -0
- package/dist/react-native/internal/Calculation.js.map +1 -0
- package/dist/react-native/internal/Device.js +191 -0
- package/dist/react-native/internal/Device.js.map +7 -0
- package/dist/react-native/internal/NativeZyzz.js +7 -0
- package/dist/react-native/internal/NativeZyzz.js.map +7 -0
- package/dist/react-native/internal/Scalar.d.ts.map +1 -1
- package/dist/react-native/internal/Scalar.js +9 -2
- package/dist/react-native/internal/Scalar.js.map +1 -1
- package/dist/react-native/internal/Store.d.ts +32 -0
- package/dist/react-native/internal/Store.d.ts.map +1 -0
- package/dist/react-native/internal/Store.js +57 -0
- package/dist/react-native/internal/Store.js.map +1 -0
- package/dist/react-native/internal/Tokens.d.ts +21 -0
- package/dist/react-native/internal/Tokens.d.ts.map +1 -0
- package/dist/react-native/internal/Tokens.js +58 -0
- package/dist/react-native/internal/Tokens.js.map +1 -0
- package/dist/react-native/internal/Viewport.d.ts +6 -0
- package/dist/react-native/internal/Viewport.d.ts.map +1 -0
- package/dist/react-native/internal/Viewport.js +4 -0
- package/dist/react-native/internal/Viewport.js.map +1 -0
- package/dist/react-native/react.d.ts +74 -11
- package/dist/react-native/react.d.ts.map +1 -1
- package/dist/react-native/react.js +111 -12
- package/dist/react-native/react.js.map +1 -1
- package/dist/react-native/reanimated.d.ts +39 -0
- package/dist/react-native/reanimated.d.ts.map +1 -0
- package/dist/react-native/reanimated.js +76 -0
- package/dist/react-native/reanimated.js.map +1 -0
- package/dist/runtime/NativeContext.d.ts +10 -1
- package/dist/runtime/NativeContext.d.ts.map +1 -1
- package/dist/runtime/NativeContext.js +67 -14
- package/dist/runtime/NativeContext.js.map +1 -1
- package/dist/runtime/NativeDynamic.d.ts +3 -2
- package/dist/runtime/NativeDynamic.d.ts.map +1 -1
- package/dist/runtime/NativeDynamic.js +32 -7
- package/dist/runtime/NativeDynamic.js.map +1 -1
- package/dist/runtime/NativeStatic.d.ts +23 -0
- package/dist/runtime/NativeStatic.d.ts.map +1 -0
- package/dist/runtime/NativeStatic.js +106 -0
- package/dist/runtime/NativeStatic.js.map +1 -0
- package/dist/runtime/NativeVars.d.ts +53 -0
- package/dist/runtime/NativeVars.d.ts.map +1 -0
- package/dist/runtime/NativeVars.js +77 -0
- package/dist/runtime/NativeVars.js.map +1 -0
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/internal/NativeMedia.d.ts +25 -0
- package/dist/runtime/internal/NativeMedia.d.ts.map +1 -0
- package/dist/runtime/internal/NativeMedia.js +36 -0
- package/dist/runtime/internal/NativeMedia.js.map +1 -0
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +7 -35
- package/dist/vite/index.js.map +1 -1
- package/dist/web/Css.d.ts.map +1 -1
- package/dist/web/Css.js +31 -19
- package/dist/web/Css.js.map +1 -1
- package/dist/web/internal/Themes.d.ts +0 -2
- package/dist/web/internal/Themes.d.ts.map +1 -1
- package/dist/web/internal/Themes.js +30 -28
- package/dist/web/internal/Themes.js.map +1 -1
- package/dist/web/page.d.ts +2 -0
- package/dist/web/page.d.ts.map +1 -1
- package/native/NativeZyzz.cpp +215 -0
- package/native/NativeZyzz.h +52 -0
- package/native/ZyzzSpecJSI.h +65 -0
- package/native/android/CMakeLists.txt +8 -0
- package/native/android/ZyzzSpec-generated.cpp +50 -0
- package/native/android/ZyzzSpec.h +31 -0
- package/native/ios/ZyzzModuleProvider.mm +13 -0
- package/package.json +39 -1
- package/react-native.config.ts +14 -0
- package/src/Style.ts +11 -8
- package/src/babel/NativeJsx.ts +305 -28
- package/src/babel/index.ts +21 -3
- package/src/compiler/Graph.ts +75 -0
- package/src/compiler/Native.ts +158 -26
- package/src/compiler/Source.ts +32 -5
- package/src/compiler/internal/Configurations.ts +25 -3
- package/src/compiler/internal/Contract.ts +98 -50
- package/src/compiler/internal/Contributions.ts +7 -1
- package/src/compiler/internal/Descriptors.ts +12 -8
- package/src/compiler/internal/NativeBindings.ts +98 -15
- package/src/compiler/internal/NativeMedia.ts +342 -0
- package/src/compiler/internal/NativeVars.ts +228 -0
- package/src/compiler/internal/PackedStyles.ts +4 -0
- package/src/compiler/internal/Themes.ts +187 -2
- package/src/compiler/internal/Vars.ts +12 -1
- package/src/internal/Completion.ts +6 -3
- package/src/internal/Targets.ts +2 -0
- package/src/internal/Token.ts +0 -2
- package/src/internal/Value.ts +20 -0
- package/src/metro/Graph.ts +235 -50
- package/src/metro/Watch.ts +95 -10
- package/src/metro/index.ts +62 -4
- package/src/metro/transformer.ts +21 -11
- package/src/react-native/StyleSheet.ts +28 -44
- package/src/react-native/index.native.ts +10 -0
- package/src/react-native/index.ts +1 -1
- package/src/react-native/internal/Calculation.ts +159 -0
- package/src/react-native/internal/Device.ts +231 -0
- package/src/react-native/internal/NativeZyzz.ts +20 -0
- package/src/react-native/internal/Scalar.ts +13 -2
- package/src/react-native/internal/Store.ts +78 -0
- package/src/react-native/internal/Tokens.ts +85 -0
- package/src/react-native/internal/Viewport.ts +8 -0
- package/src/react-native/react.ts +211 -19
- package/src/react-native/reanimated.ts +162 -0
- package/src/runtime/NativeContext.ts +88 -17
- package/src/runtime/NativeDynamic.ts +35 -10
- package/src/runtime/NativeStatic.ts +145 -0
- package/src/runtime/NativeVars.ts +189 -0
- package/src/runtime/index.ts +6 -0
- package/src/runtime/internal/NativeMedia.ts +63 -0
- package/src/vite/index.ts +9 -42
- package/src/web/Css.ts +42 -27
- package/src/web/internal/Themes.ts +34 -57
- package/src/web/page.ts +2 -0
package/src/compiler/Native.ts
CHANGED
|
@@ -5,6 +5,8 @@ import type * as Recipe from '../internal/Recipe.js'
|
|
|
5
5
|
import * as Source from './Source.js'
|
|
6
6
|
import * as Edits from './internal/Edits.js'
|
|
7
7
|
import * as NativeBindings from './internal/NativeBindings.js'
|
|
8
|
+
import * as NativeMedia from './internal/NativeMedia.js'
|
|
9
|
+
import * as NativeVars from './internal/NativeVars.js'
|
|
8
10
|
import * as Themes from './internal/Themes.js'
|
|
9
11
|
import * as StyleSheet from '../react-native/StyleSheet.js'
|
|
10
12
|
import * as Syntax from './internal/Syntax.js'
|
|
@@ -12,7 +14,7 @@ import * as Variants from '../react-native/Variants.js'
|
|
|
12
14
|
import * as Walker from 'oxc-walker'
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
|
-
* Compiles local
|
|
17
|
+
* Compiles local styles, variants, and variable reads for an explicit native target.
|
|
16
18
|
* @param options - Shared source, destination mappings, and selected set/scheme.
|
|
17
19
|
* @returns Native callables, source map, and static recipe tables.
|
|
18
20
|
* @throws {Source.ExtractError} For invalid source authoring.
|
|
@@ -50,9 +52,13 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
50
52
|
})
|
|
51
53
|
let helper = '__zyzzNative'
|
|
52
54
|
while (
|
|
53
|
-
[
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
[
|
|
56
|
+
helper,
|
|
57
|
+
`${helper}Context`,
|
|
58
|
+
`${helper}Dynamic`,
|
|
59
|
+
`${helper}Static`,
|
|
60
|
+
`${helper}Vars`,
|
|
61
|
+
].some((name) => names.has(name))
|
|
56
62
|
)
|
|
57
63
|
helper += '_'
|
|
58
64
|
let dynamicHelper = `${helper}Dynamic`
|
|
@@ -70,6 +76,7 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
70
76
|
}
|
|
71
77
|
const recipes: Record<string, Variants.Definition> = Object.create(null)
|
|
72
78
|
let dynamic = false
|
|
79
|
+
let finite = false
|
|
73
80
|
const contexts = new Map<string, string>()
|
|
74
81
|
const compiledCalls = new WeakMap<
|
|
75
82
|
Variants.Definition,
|
|
@@ -92,6 +99,54 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
92
99
|
}
|
|
93
100
|
|
|
94
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
|
+
}
|
|
95
150
|
if (options.contextual) {
|
|
96
151
|
const groups = new Map<StyleSheet.compile.Options['vars'], Source.Call[]>()
|
|
97
152
|
for (const call of extracted.calls) {
|
|
@@ -104,6 +159,15 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
104
159
|
)
|
|
105
160
|
continue
|
|
106
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
|
+
|
|
107
171
|
const group = groups.get(vars)
|
|
108
172
|
if (group) group.push(call)
|
|
109
173
|
else groups.set(vars, [call])
|
|
@@ -233,9 +297,58 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
233
297
|
compiled?: Variants.Definition,
|
|
234
298
|
bindings?: ReturnType<typeof NativeBindings.prepare>,
|
|
235
299
|
): string {
|
|
300
|
+
const program =
|
|
301
|
+
Object.keys(recipe.axes).length > 0 ||
|
|
302
|
+
call?.slots ||
|
|
303
|
+
call?.recipe?.payloads?.length
|
|
304
|
+
|
|
236
305
|
if (contextOptions.contextual) {
|
|
237
306
|
const vars = call?.nativeContext?.vars ?? contextOptions.vars
|
|
238
|
-
|
|
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)
|
|
239
352
|
compiled ??= Variants.compile({
|
|
240
353
|
recipe,
|
|
241
354
|
fonts: contextOptions.fonts,
|
|
@@ -245,7 +358,7 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
245
358
|
})
|
|
246
359
|
else {
|
|
247
360
|
try {
|
|
248
|
-
bindings = NativeBindings.prepare(recipe, call
|
|
361
|
+
bindings = NativeBindings.prepare(recipe, call ?? {}, {
|
|
249
362
|
...contextOptions,
|
|
250
363
|
vars,
|
|
251
364
|
})
|
|
@@ -315,18 +428,36 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
315
428
|
}
|
|
316
429
|
return `${context}(${[...tables.keys()].join(',')})`
|
|
317
430
|
}
|
|
318
|
-
|
|
319
|
-
|
|
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
|
|
320
442
|
const compiled = (() => {
|
|
321
443
|
try {
|
|
322
|
-
|
|
444
|
+
const compiled = NativeBindings.compile(
|
|
445
|
+
recipe,
|
|
446
|
+
call ?? {},
|
|
447
|
+
contextOptions,
|
|
448
|
+
bindings,
|
|
449
|
+
)
|
|
450
|
+
return scalar ? compiled : NativeBindings.finite(compiled)
|
|
323
451
|
} catch (error) {
|
|
324
452
|
if (error instanceof StyleSheet.CompileError) throw error
|
|
325
453
|
throw new CompileError((error as Error).message)
|
|
326
454
|
}
|
|
327
455
|
})()
|
|
328
|
-
const value = create(dynamicHelper
|
|
456
|
+
const value = create(scalar ? dynamicHelper : `${helper}Static`, compiled)
|
|
329
457
|
if (!typed) return value
|
|
458
|
+
if (!call?.slots && !call?.recipe?.payloads?.length)
|
|
459
|
+
return `(${value} as import('zyzz/runtime').Native.Callable<{${axes}}>)`
|
|
460
|
+
|
|
330
461
|
let input = call.valuesType ?? '{}'
|
|
331
462
|
if (call.recipe) {
|
|
332
463
|
input = `{${Object.entries(recipe.axes)
|
|
@@ -371,12 +502,6 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
371
502
|
})
|
|
372
503
|
if (options.contextual) compiledCalls.set(compiled, { styles, value })
|
|
373
504
|
if (!typed) return value
|
|
374
|
-
const axes = Object.entries(compiled.axes)
|
|
375
|
-
.map(
|
|
376
|
-
([axis, choices]) =>
|
|
377
|
-
`${JSON.stringify(axis)}:readonly ${JSON.stringify(choices)}`,
|
|
378
|
-
)
|
|
379
|
-
.join(';')
|
|
380
505
|
return `(${value} as import('zyzz/runtime').Native.Callable<{${axes}}>)`
|
|
381
506
|
}
|
|
382
507
|
|
|
@@ -483,10 +608,9 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
483
608
|
throw new CompileError(
|
|
484
609
|
`Packed native callable ${name} requires a static recipe contract.`,
|
|
485
610
|
)
|
|
486
|
-
const expression = callable(
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
link.style?.dynamic
|
|
611
|
+
const expression = callable(recipe, `${specifier}:${name}`, {
|
|
612
|
+
nativeContext: link.style?.nativeContext,
|
|
613
|
+
...(link.style?.dynamic
|
|
490
614
|
? {
|
|
491
615
|
slots: link.style.dynamic.slots,
|
|
492
616
|
recipe: {
|
|
@@ -496,8 +620,8 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
496
620
|
defaultPayloads: link.style.dynamic.defaultPayloads,
|
|
497
621
|
},
|
|
498
622
|
}
|
|
499
|
-
:
|
|
500
|
-
)
|
|
623
|
+
: {}),
|
|
624
|
+
})
|
|
501
625
|
if (!link.style?.dynamic || !typed) return expression
|
|
502
626
|
const type = `typeof import(${JSON.stringify(specifier)})${path
|
|
503
627
|
.map((part) => `[${JSON.stringify(part)}]`)
|
|
@@ -698,7 +822,13 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
698
822
|
imports.length ? `import ${imports.join(',')} from 'zyzz';` : '',
|
|
699
823
|
)
|
|
700
824
|
}
|
|
701
|
-
if (
|
|
825
|
+
if (
|
|
826
|
+
extracted.calls.length ||
|
|
827
|
+
compositions.length ||
|
|
828
|
+
packed.length ||
|
|
829
|
+
variables.size ||
|
|
830
|
+
imports.size
|
|
831
|
+
) {
|
|
702
832
|
let offset = 0
|
|
703
833
|
if (options.source.startsWith('#!')) {
|
|
704
834
|
const newline = /\r\n|[\n\r\u2028\u2029]/.exec(options.source)
|
|
@@ -713,7 +843,7 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
713
843
|
offset = node.end
|
|
714
844
|
}
|
|
715
845
|
|
|
716
|
-
const prelude = `\nimport {Native as ${helper}${dynamic ? `,NativeDynamic as ${dynamicHelper}` : ''}${options.contextual ? `,NativeContext as ${helper}Context` : ''}} 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${[...compositions, ...packed].join('\n')}\n`
|
|
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`
|
|
717
847
|
module.appendLeft(offset, prelude)
|
|
718
848
|
edits.push({ start: offset, end: offset, code: prelude, expression: false })
|
|
719
849
|
}
|
|
@@ -738,6 +868,8 @@ export declare namespace compile {
|
|
|
738
868
|
type Options = Omit<StyleSheet.compile.Options, 'styles'> & {
|
|
739
869
|
/** Internal Babel emission mode; authoring types are still validated. */
|
|
740
870
|
readonly [Edits.runtime]?: boolean | undefined
|
|
871
|
+
/** Compiler-owned shared native variable profiles. */
|
|
872
|
+
readonly [NativeVars.shared]?: NativeVars.Shared | undefined
|
|
741
873
|
/** Compiler-owned graph context. */
|
|
742
874
|
readonly [Themes.context]?: Themes.Context | undefined
|
|
743
875
|
/** Retain every set and scheme for render-local selection. */
|
|
@@ -751,7 +883,7 @@ export declare namespace compile {
|
|
|
751
883
|
/** Label selected from supplied vars. Defaults to the token-fallback default table. */
|
|
752
884
|
readonly set?: string | undefined
|
|
753
885
|
}
|
|
754
|
-
/** Executable source with immutable
|
|
886
|
+
/** Executable source with immutable native data and authored source mappings. */
|
|
755
887
|
type ReturnType = {
|
|
756
888
|
/** Internal node replacements for syntax-tree adapters. */
|
|
757
889
|
readonly [Edits.key]: readonly Edits.Edit[]
|
|
@@ -759,7 +891,7 @@ export declare namespace compile {
|
|
|
759
891
|
readonly code: string
|
|
760
892
|
/** Version-three source map encoded as JSON. */
|
|
761
893
|
readonly map: string
|
|
762
|
-
/**
|
|
894
|
+
/** Set/scheme tables for definitions without variant or scalar programs. */
|
|
763
895
|
readonly recipes: Readonly<Record<string, Variants.Definition>>
|
|
764
896
|
}
|
|
765
897
|
}
|
package/src/compiler/Source.ts
CHANGED
|
@@ -269,6 +269,7 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
269
269
|
const themes = (() => {
|
|
270
270
|
try {
|
|
271
271
|
return Themes.collect(program, {
|
|
272
|
+
native: options.target === 'native',
|
|
272
273
|
staticBindings: staticData.bindings,
|
|
273
274
|
namespace: `src-${Identity.label(
|
|
274
275
|
options.moduleId
|
|
@@ -336,7 +337,7 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
336
337
|
contributions.read(node, parent, binding)
|
|
337
338
|
|
|
338
339
|
try {
|
|
339
|
-
if (variables.reference(node, parent, binding)) return
|
|
340
|
+
if (variables.reference(node, parent, ancestors, binding)) return
|
|
340
341
|
} catch (error) {
|
|
341
342
|
if (!(error instanceof Themes.InvalidError)) throw error
|
|
342
343
|
|
|
@@ -347,7 +348,16 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
347
348
|
|
|
348
349
|
if (themes)
|
|
349
350
|
try {
|
|
350
|
-
if (
|
|
351
|
+
if (
|
|
352
|
+
themes.reference(
|
|
353
|
+
node,
|
|
354
|
+
parent,
|
|
355
|
+
ancestors,
|
|
356
|
+
binding,
|
|
357
|
+
(name) => scopeTracker.getDeclaration(name) ?? null,
|
|
358
|
+
)
|
|
359
|
+
)
|
|
360
|
+
return
|
|
351
361
|
} catch (error) {
|
|
352
362
|
if (!(error instanceof Themes.InvalidError)) throw error
|
|
353
363
|
|
|
@@ -1520,7 +1530,17 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
1520
1530
|
const style = call && styles.find((style) => style.name === call.name)
|
|
1521
1531
|
return {
|
|
1522
1532
|
...link,
|
|
1523
|
-
...(call && style
|
|
1533
|
+
...(call && style
|
|
1534
|
+
? {
|
|
1535
|
+
style: PackedStyles.create(
|
|
1536
|
+
{
|
|
1537
|
+
...call,
|
|
1538
|
+
nativeContext: themes?.nativeContext(call.start, call.end),
|
|
1539
|
+
},
|
|
1540
|
+
style,
|
|
1541
|
+
),
|
|
1542
|
+
}
|
|
1543
|
+
: {}),
|
|
1524
1544
|
...(link.members
|
|
1525
1545
|
? {
|
|
1526
1546
|
members: Object.fromEntries(
|
|
@@ -1560,6 +1580,8 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
1560
1580
|
),
|
|
1561
1581
|
}
|
|
1562
1582
|
Object.defineProperty(definition, ClassName.labels, { enumerable: false })
|
|
1583
|
+
const selections =
|
|
1584
|
+
options.target === 'native' ? themes?.selectionUses : themes?.selections
|
|
1563
1585
|
|
|
1564
1586
|
return Object.freeze({
|
|
1565
1587
|
namespaces: contributionData.filter(
|
|
@@ -1611,8 +1633,8 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
1611
1633
|
...(themes?.scripts.size
|
|
1612
1634
|
? { themeScripts: Object.freeze([...themes.scripts]) }
|
|
1613
1635
|
: {}),
|
|
1614
|
-
...(
|
|
1615
|
-
? { themeSelections: Object.freeze([...
|
|
1636
|
+
...(selections?.size
|
|
1637
|
+
? { themeSelections: Object.freeze([...selections]) }
|
|
1616
1638
|
: {}),
|
|
1617
1639
|
themeCalls: Object.freeze(themes?.calls ?? []),
|
|
1618
1640
|
...(themes?.staticTokens.length
|
|
@@ -1630,6 +1652,9 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
1630
1652
|
: {}),
|
|
1631
1653
|
themeReferences: Object.freeze(themes?.references ?? []),
|
|
1632
1654
|
vars: themes?.themes ?? Object.freeze({}),
|
|
1655
|
+
...(themes?.varsReads.length
|
|
1656
|
+
? { nativeVars: Object.freeze(themes.varsReads) }
|
|
1657
|
+
: {}),
|
|
1633
1658
|
})
|
|
1634
1659
|
}
|
|
1635
1660
|
|
|
@@ -1654,6 +1679,8 @@ export declare namespace extract {
|
|
|
1654
1679
|
|
|
1655
1680
|
/** Ordered public compiler input and spans for later rewriting. */
|
|
1656
1681
|
type ReturnType = {
|
|
1682
|
+
/** Readonly native variable arguments and their complete catalogs. */
|
|
1683
|
+
readonly nativeVars?: readonly Themes.VarsRead[] | undefined
|
|
1657
1684
|
/** Module-owned namespace bindings retained when contributions are shared. */
|
|
1658
1685
|
readonly namespaces?: readonly Namespace.Definition[] | undefined
|
|
1659
1686
|
/** Static stylesheet effects and their source replacements. */
|
|
@@ -252,10 +252,28 @@ export function collect(options: collect.Options): Themes.Link {
|
|
|
252
252
|
...(input.layers ? { layers: input.layers } : {}),
|
|
253
253
|
...(input.storageKey ? { storageKey: input.storageKey } : {}),
|
|
254
254
|
}
|
|
255
|
+
const authoredType = type(
|
|
256
|
+
variableMode
|
|
257
|
+
? {
|
|
258
|
+
...normalized,
|
|
259
|
+
theme: undefined,
|
|
260
|
+
themes: undefined,
|
|
261
|
+
defaultTheme: undefined,
|
|
262
|
+
vars: 'themes' in normalized ? normalized.themes : normalized.theme,
|
|
263
|
+
...('themes' in normalized
|
|
264
|
+
? { defaultVars: normalized.defaultTheme }
|
|
265
|
+
: {}),
|
|
266
|
+
...(authored.mappings !== undefined
|
|
267
|
+
? { mappings: VariableSets.mappings(authored.mappings) }
|
|
268
|
+
: {}),
|
|
269
|
+
}
|
|
270
|
+
: normalized,
|
|
271
|
+
)
|
|
255
272
|
|
|
256
273
|
return {
|
|
257
274
|
binding: options.name,
|
|
258
275
|
call: {
|
|
276
|
+
...(options.nativeProvider ? { nativeProvider: true } : {}),
|
|
259
277
|
...(variableMode
|
|
260
278
|
? { variableConfig: true, variableMappings: authored.mappings }
|
|
261
279
|
: {}),
|
|
@@ -269,9 +287,11 @@ export function collect(options: collect.Options): Themes.Link {
|
|
|
269
287
|
options: normalized,
|
|
270
288
|
start: options.expression.start,
|
|
271
289
|
tokenType: selected?.call.tokenType ?? '{}',
|
|
272
|
-
type:
|
|
273
|
-
? `import('zyzz').
|
|
274
|
-
:
|
|
290
|
+
type: options.nativeProvider
|
|
291
|
+
? `import('zyzz/react-native').defineConfig.ReturnType<${authoredType}>`
|
|
292
|
+
: variableMode
|
|
293
|
+
? `import('zyzz').Config.VariableConfig<${authoredType}>`
|
|
294
|
+
: `import('zyzz').Config.create.ReturnType<${authoredType}>`,
|
|
275
295
|
},
|
|
276
296
|
definition,
|
|
277
297
|
kind: 'config',
|
|
@@ -289,6 +309,8 @@ export declare namespace collect {
|
|
|
289
309
|
readonly expression: Ast.CallExpression
|
|
290
310
|
/** Stable module/binding identity. */
|
|
291
311
|
readonly name: string
|
|
312
|
+
/** Native factory supplies an ordinary React Provider export. */
|
|
313
|
+
readonly nativeProvider?: boolean | undefined
|
|
292
314
|
/** Looks up preceding immutable theme definitions. */
|
|
293
315
|
readonly resolve: (node: Ast.Node) => Themes.Link | undefined
|
|
294
316
|
}
|