zyzz 0.0.2 → 0.0.5
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/README.md +34 -19
- package/dist/Config.d.ts +16 -167
- package/dist/Config.d.ts.map +1 -1
- package/dist/Config.js +7 -246
- package/dist/Config.js.map +1 -1
- package/dist/Style.d.ts +19 -13
- package/dist/Style.d.ts.map +1 -1
- package/dist/Style.js +73 -7
- package/dist/Style.js.map +1 -1
- package/dist/Vars.d.ts +114 -0
- package/dist/Vars.d.ts.map +1 -0
- package/dist/Vars.js +42 -0
- package/dist/Vars.js.map +1 -0
- package/dist/compiler/Graph.js +11 -8
- package/dist/compiler/Graph.js.map +1 -1
- package/dist/compiler/Native.d.ts +5 -5
- package/dist/compiler/Native.d.ts.map +1 -1
- package/dist/compiler/Native.js +21 -21
- package/dist/compiler/Native.js.map +1 -1
- package/dist/compiler/Source.d.ts +10 -6
- package/dist/compiler/Source.d.ts.map +1 -1
- package/dist/compiler/Source.js +66 -11
- package/dist/compiler/Source.js.map +1 -1
- package/dist/compiler/Transform.d.ts +1 -1
- package/dist/compiler/Transform.d.ts.map +1 -1
- package/dist/compiler/Transform.js +59 -21
- package/dist/compiler/Transform.js.map +1 -1
- package/dist/compiler/internal/Compositions.d.ts +5 -0
- package/dist/compiler/internal/Compositions.d.ts.map +1 -1
- package/dist/compiler/internal/Compositions.js +22 -3
- package/dist/compiler/internal/Compositions.js.map +1 -1
- package/dist/compiler/internal/Configurations.d.ts.map +1 -1
- package/dist/compiler/internal/Configurations.js +73 -12
- package/dist/compiler/internal/Configurations.js.map +1 -1
- package/dist/compiler/internal/Contract.d.ts +1 -1
- package/dist/compiler/internal/Contract.d.ts.map +1 -1
- package/dist/compiler/internal/Contract.js +162 -13
- package/dist/compiler/internal/Contract.js.map +1 -1
- package/dist/compiler/internal/Contributions.js +1 -1
- package/dist/compiler/internal/Contributions.js.map +1 -1
- package/dist/compiler/internal/Dynamic.js +1 -1
- package/dist/compiler/internal/Dynamic.js.map +1 -1
- package/dist/compiler/internal/Expression.d.ts +3 -0
- package/dist/compiler/internal/Expression.d.ts.map +1 -1
- package/dist/compiler/internal/Expression.js +21 -0
- package/dist/compiler/internal/Expression.js.map +1 -1
- package/dist/compiler/internal/Identifiers.d.ts +1 -1
- package/dist/compiler/internal/Identifiers.d.ts.map +1 -1
- package/dist/compiler/internal/Identifiers.js +2 -2
- package/dist/compiler/internal/Identifiers.js.map +1 -1
- package/dist/compiler/internal/NativeBindings.d.ts +1 -1
- package/dist/compiler/internal/NativeBindings.d.ts.map +1 -1
- package/dist/compiler/internal/NativeBindings.js +3 -3
- package/dist/compiler/internal/NativeBindings.js.map +1 -1
- package/dist/compiler/internal/PackedStyles.d.ts +1 -1
- package/dist/compiler/internal/PackedStyles.d.ts.map +1 -1
- package/dist/compiler/internal/PackedStyles.js +15 -25
- package/dist/compiler/internal/PackedStyles.js.map +1 -1
- package/dist/compiler/internal/Recipes.js +1 -1
- package/dist/compiler/internal/Recipes.js.map +1 -1
- package/dist/compiler/internal/Selectors.js +1 -1
- package/dist/compiler/internal/Selectors.js.map +1 -1
- package/dist/compiler/internal/Themes.d.ts +12 -3
- package/dist/compiler/internal/Themes.d.ts.map +1 -1
- package/dist/compiler/internal/Themes.js +192 -52
- package/dist/compiler/internal/Themes.js.map +1 -1
- package/dist/compiler/internal/{Variables.d.ts → Vars.d.ts} +1 -1
- package/dist/compiler/internal/Vars.d.ts.map +1 -0
- package/dist/compiler/internal/{Variables.js → Vars.js} +3 -3
- package/dist/compiler/internal/Vars.js.map +1 -0
- package/dist/default.d.ts +451 -1649
- package/dist/default.d.ts.map +1 -1
- package/dist/default.js +389 -80
- package/dist/default.js.map +2 -2
- package/dist/default.js.zyzz.json +1 -1
- package/dist/esbuild/index.d.ts +3 -0
- package/dist/esbuild/index.d.ts.map +1 -0
- package/dist/esbuild/index.js +5 -0
- package/dist/esbuild/index.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/Authoring.d.ts +1 -1
- package/dist/internal/Authoring.d.ts.map +1 -1
- package/dist/internal/Authoring.js +4 -4
- package/dist/internal/Authoring.js.map +1 -1
- package/dist/internal/Binding.d.ts +1 -1
- package/dist/internal/Binding.d.ts.map +1 -1
- package/dist/internal/Completion.d.ts +19 -0
- package/dist/internal/Completion.d.ts.map +1 -0
- package/dist/internal/Completion.js +2 -0
- package/dist/internal/Completion.js.map +1 -0
- package/dist/internal/Condition.d.ts +3 -1
- package/dist/internal/Condition.d.ts.map +1 -1
- package/dist/internal/Condition.js.map +1 -1
- package/dist/internal/Configuration.d.ts +248 -0
- package/dist/internal/Configuration.d.ts.map +1 -0
- package/dist/internal/Configuration.js +343 -0
- package/dist/internal/Configuration.js.map +1 -0
- package/dist/internal/Shorthands.d.ts +1 -1
- package/dist/internal/Shorthands.d.ts.map +1 -1
- package/dist/internal/Shorthands.js +1 -0
- package/dist/internal/Shorthands.js.map +1 -1
- package/dist/{Theme.d.ts → internal/Theme.d.ts} +24 -19
- package/dist/internal/Theme.d.ts.map +1 -0
- package/dist/{Theme.js → internal/Theme.js} +57 -14
- package/dist/internal/Theme.js.map +1 -0
- package/dist/internal/Token.d.ts +46 -16
- package/dist/internal/Token.d.ts.map +1 -1
- package/dist/internal/Token.js +89 -5
- package/dist/internal/Token.js.map +1 -1
- package/dist/internal/Typography.d.ts +31 -0
- package/dist/internal/Typography.d.ts.map +1 -0
- package/dist/internal/Typography.js +54 -0
- package/dist/internal/Typography.js.map +1 -0
- package/dist/internal/Value.d.ts +6 -1
- package/dist/internal/Value.d.ts.map +1 -1
- package/dist/internal/Value.js.map +1 -1
- package/dist/internal/VariableSets.d.ts +20 -0
- package/dist/internal/VariableSets.d.ts.map +1 -0
- package/dist/internal/VariableSets.js +317 -0
- package/dist/internal/VariableSets.js.map +1 -0
- package/dist/next/loader.js +15 -5
- package/dist/next/loader.js.map +1 -1
- package/dist/node/Host.d.ts.map +1 -1
- package/dist/node/Host.js +1 -1
- package/dist/node/Host.js.map +1 -1
- package/dist/react-native/Host.d.ts +2 -2
- package/dist/react-native/Host.d.ts.map +1 -1
- package/dist/react-native/Host.js +4 -4
- package/dist/react-native/Host.js.map +1 -1
- package/dist/react-native/StyleSheet.d.ts +9 -8
- package/dist/react-native/StyleSheet.d.ts.map +1 -1
- package/dist/react-native/StyleSheet.js +29 -23
- package/dist/react-native/StyleSheet.js.map +1 -1
- package/dist/react-native/Variants.d.ts +3 -3
- package/dist/react-native/Variants.d.ts.map +1 -1
- package/dist/react-native/Variants.js +2 -2
- package/dist/react-native/react.d.ts +1 -1
- package/dist/react-native/react.d.ts.map +1 -1
- package/dist/react-native/react.js +5 -5
- package/dist/react-native/react.js.map +1 -1
- package/dist/rollup/index.d.ts +3 -0
- package/dist/rollup/index.d.ts.map +1 -0
- package/dist/rollup/index.js +5 -0
- package/dist/rollup/index.js.map +1 -0
- package/dist/runtime/Appearance.d.ts +7 -7
- package/dist/runtime/Appearance.d.ts.map +1 -1
- package/dist/runtime/Appearance.js +15 -15
- package/dist/runtime/Appearance.js.map +1 -1
- package/dist/runtime/Dynamic.d.ts.map +1 -1
- package/dist/runtime/Dynamic.js +4 -1
- package/dist/runtime/Dynamic.js.map +1 -1
- package/dist/runtime/NativeContext.d.ts +4 -4
- package/dist/runtime/NativeContext.d.ts.map +1 -1
- package/dist/runtime/NativeContext.js +5 -5
- package/dist/runtime/NativeContext.js.map +1 -1
- package/dist/runtime/NativeDynamic.d.ts +1 -1
- package/dist/runtime/NativeDynamic.d.ts.map +1 -1
- package/dist/runtime/NativeDynamic.js.map +1 -1
- package/dist/runtime/Props.d.ts +1 -1
- package/dist/runtime/Props.js +3 -3
- package/dist/runtime/Props.js.map +1 -1
- package/dist/runtime/Selection.d.ts +14 -10
- package/dist/runtime/Selection.d.ts.map +1 -1
- package/dist/runtime/Selection.js +19 -18
- package/dist/runtime/Selection.js.map +1 -1
- package/dist/styleFunction.d.ts +14 -14
- package/dist/styleFunction.d.ts.map +1 -1
- package/dist/styleFunction.js.map +1 -1
- package/dist/unplugin/index.d.ts +20 -0
- package/dist/unplugin/index.d.ts.map +1 -0
- package/dist/unplugin/index.js +498 -0
- package/dist/unplugin/index.js.map +1 -0
- package/dist/variants.d.ts +3 -3
- package/dist/variants.d.ts.map +1 -1
- package/dist/variants.js.map +1 -1
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +6 -3
- package/dist/vite/index.js.map +1 -1
- package/dist/web/Css.d.ts +4 -3
- package/dist/web/Css.d.ts.map +1 -1
- package/dist/web/Css.js +4 -4
- package/dist/web/Css.js.map +1 -1
- package/dist/web/internal/Themes.d.ts +3 -2
- package/dist/web/internal/Themes.d.ts.map +1 -1
- package/dist/web/internal/Themes.js +42 -6
- package/dist/web/internal/Themes.js.map +1 -1
- package/dist/webpack/index.d.ts +3 -0
- package/dist/webpack/index.d.ts.map +1 -0
- package/dist/webpack/index.js +5 -0
- package/dist/webpack/index.js.map +1 -0
- package/package.json +23 -2
- package/src/Config.ts +43 -684
- package/src/Style.ts +167 -40
- package/src/Vars.ts +299 -0
- package/src/compiler/Graph.ts +14 -9
- package/src/compiler/Native.ts +29 -32
- package/src/compiler/Source.ts +85 -18
- package/src/compiler/Transform.ts +78 -22
- package/src/compiler/internal/Compositions.ts +36 -3
- package/src/compiler/internal/Configurations.ts +83 -11
- package/src/compiler/internal/Contract.ts +223 -17
- package/src/compiler/internal/Contributions.ts +1 -1
- package/src/compiler/internal/Dynamic.ts +1 -1
- package/src/compiler/internal/Expression.ts +26 -0
- package/src/compiler/internal/Identifiers.ts +2 -1
- package/src/compiler/internal/NativeBindings.ts +3 -3
- package/src/compiler/internal/PackedStyles.ts +22 -26
- package/src/compiler/internal/Recipes.ts +1 -1
- package/src/compiler/internal/Selectors.ts +1 -1
- package/src/compiler/internal/Themes.ts +266 -57
- package/src/compiler/internal/{Variables.ts → Vars.ts} +2 -2
- package/src/default.ts +868 -156
- package/src/esbuild/index.ts +5 -0
- package/src/index.ts +4 -4
- package/src/internal/Authoring.ts +5 -7
- package/src/internal/Binding.ts +1 -1
- package/src/internal/Completion.ts +42 -0
- package/src/internal/Condition.ts +31 -1
- package/src/internal/Configuration.ts +970 -0
- package/src/internal/Shorthands.ts +2 -0
- package/src/{Theme.ts → internal/Theme.ts} +174 -48
- package/src/internal/Token.ts +258 -85
- package/src/internal/Typography.ts +106 -0
- package/src/internal/Value.ts +45 -26
- package/src/internal/VariableSets.ts +458 -0
- package/src/next/loader.ts +19 -5
- package/src/node/Host.ts +1 -2
- package/src/react-native/Host.ts +6 -6
- package/src/react-native/StyleSheet.ts +49 -42
- package/src/react-native/Variants.ts +3 -3
- package/src/react-native/react.ts +6 -6
- package/src/rollup/index.ts +5 -0
- package/src/runtime/Appearance.ts +20 -20
- package/src/runtime/Dynamic.ts +4 -1
- package/src/runtime/NativeContext.ts +8 -8
- package/src/runtime/NativeDynamic.ts +2 -4
- package/src/runtime/Props.ts +3 -3
- package/src/runtime/Selection.ts +44 -33
- package/src/styleFunction.ts +22 -19
- package/src/unplugin/index.ts +600 -0
- package/src/variants.ts +7 -5
- package/src/vite/index.ts +5 -4
- package/src/web/Css.ts +10 -7
- package/src/web/internal/Themes.ts +52 -9
- package/src/webpack/index.ts +5 -0
- package/dist/Theme.d.ts.map +0 -1
- package/dist/Theme.js.map +0 -1
- package/dist/compiler/internal/Variables.d.ts.map +0 -1
- package/dist/compiler/internal/Variables.js.map +0 -1
package/src/compiler/Graph.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type * as Ast from '@oxc-project/types'
|
|
|
13
13
|
import * as Parser from 'oxc-parser'
|
|
14
14
|
import * as Syntax from './internal/Syntax.js'
|
|
15
15
|
import * as Walker from 'oxc-walker'
|
|
16
|
-
import type * as Theme from '../Theme.js'
|
|
16
|
+
import type * as Theme from '../internal/Theme.js'
|
|
17
17
|
import * as Token from '../internal/Token.js'
|
|
18
18
|
import * as Contract from './internal/Contract.js'
|
|
19
19
|
import * as Relative from './internal/Relative.js'
|
|
@@ -135,7 +135,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
|
|
|
135
135
|
Object.keys(options.native ?? {}).length ||
|
|
136
136
|
Object.entries(cache?.native ?? {}).some(([key, value]) => {
|
|
137
137
|
const next = Reflect.get(options.native ?? {}, key)
|
|
138
|
-
if (key !== 'fonts' && key !== '
|
|
138
|
+
if (key !== 'fonts' && key !== 'vars' && key !== 'units')
|
|
139
139
|
return value !== next
|
|
140
140
|
|
|
141
141
|
return (
|
|
@@ -961,7 +961,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
|
|
|
961
961
|
source: options.modules[moduleId]!,
|
|
962
962
|
}
|
|
963
963
|
|
|
964
|
-
Object.assign(themes, result.
|
|
964
|
+
Object.assign(themes, result.vars)
|
|
965
965
|
visiting.delete(moduleId)
|
|
966
966
|
|
|
967
967
|
return result
|
|
@@ -1060,7 +1060,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
|
|
|
1060
1060
|
native: {
|
|
1061
1061
|
...options.native,
|
|
1062
1062
|
...(options.native.fonts && { fonts: { ...options.native.fonts } }),
|
|
1063
|
-
...(options.native.
|
|
1063
|
+
...(options.native.vars && { vars: { ...options.native.vars } }),
|
|
1064
1064
|
...(options.native.units && { units: { ...options.native.units } }),
|
|
1065
1065
|
},
|
|
1066
1066
|
resolutions: Object.freeze(resolutions),
|
|
@@ -1121,7 +1121,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
|
|
|
1121
1121
|
? ''
|
|
1122
1122
|
: (Css.compile({
|
|
1123
1123
|
styles: { styles: [] },
|
|
1124
|
-
|
|
1124
|
+
vars: sharedThemes,
|
|
1125
1125
|
contributions: [contribution],
|
|
1126
1126
|
}).contributionCss ?? ''),
|
|
1127
1127
|
layers: contribution.kind === 'layers' ? [contribution.names] : [],
|
|
@@ -1345,7 +1345,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
|
|
|
1345
1345
|
)
|
|
1346
1346
|
identities.set(name, signature)
|
|
1347
1347
|
}
|
|
1348
|
-
for (const [name, theme] of Object.entries(module.
|
|
1348
|
+
for (const [name, theme] of Object.entries(module.vars)) {
|
|
1349
1349
|
const data = theme[Token.definition]
|
|
1350
1350
|
if (data.contract[Token.identity]?.startsWith('id-'))
|
|
1351
1351
|
register(`theme:${name}`, JSON.stringify(data.values))
|
|
@@ -1403,7 +1403,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
|
|
|
1403
1403
|
[Themes.context]: {
|
|
1404
1404
|
extracted: Object.freeze({
|
|
1405
1405
|
...extracted.get(moduleId)!,
|
|
1406
|
-
|
|
1406
|
+
vars: sharedThemes,
|
|
1407
1407
|
contributions: undefined,
|
|
1408
1408
|
}),
|
|
1409
1409
|
links: {},
|
|
@@ -1435,7 +1435,12 @@ function build(options: compile.Options, cache?: Cache): Cache {
|
|
|
1435
1435
|
}
|
|
1436
1436
|
|
|
1437
1437
|
for (const call of extracted.get(moduleId)!.calls)
|
|
1438
|
-
if (
|
|
1438
|
+
if (
|
|
1439
|
+
call.identity &&
|
|
1440
|
+
!call.composition &&
|
|
1441
|
+
!call.runtimeComposition &&
|
|
1442
|
+
!call.compositionCase
|
|
1443
|
+
)
|
|
1439
1444
|
styleClasses[call.identity] = modules[moduleId]!.classes[call.name]!
|
|
1440
1445
|
}
|
|
1441
1446
|
|
|
@@ -1581,6 +1586,6 @@ function nativeOutput(
|
|
|
1581
1586
|
get map() {
|
|
1582
1587
|
return (sourceMap ??= JSON.parse(output.map) as Mapping.EncodedSourceMap)
|
|
1583
1588
|
},
|
|
1584
|
-
|
|
1589
|
+
vars: Object.freeze({}),
|
|
1585
1590
|
})
|
|
1586
1591
|
}
|
package/src/compiler/Native.ts
CHANGED
|
@@ -13,7 +13,7 @@ import * as Walker from 'oxc-walker'
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Compiles local style and variants calls for an explicit native context.
|
|
16
|
-
* @param options - Shared source, destination mappings, and selected
|
|
16
|
+
* @param options - Shared source, destination mappings, and selected set/scheme.
|
|
17
17
|
* @returns Native callables, source map, and static recipe tables.
|
|
18
18
|
* @throws {Source.ExtractError} For invalid source authoring.
|
|
19
19
|
* @throws {CompileError} For native features outside the static source boundary.
|
|
@@ -38,7 +38,7 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
38
38
|
(extracted.themeAppearances?.length || extracted.themeScripts?.length))
|
|
39
39
|
)
|
|
40
40
|
throw new CompileError(
|
|
41
|
-
'Native static modules do not support CSS contributions, variables, or web
|
|
41
|
+
'Native static modules do not support CSS contributions, variables, or web set controls.',
|
|
42
42
|
)
|
|
43
43
|
const parsed = options[Themes.context]?.parsed ?? Syntax.parse(options)
|
|
44
44
|
const names = new Set(options[Themes.context]?.identifiers)
|
|
@@ -93,10 +93,7 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
93
93
|
|
|
94
94
|
const staticTables = new Map<Source.Call, Variants.Definition>()
|
|
95
95
|
if (options.contextual) {
|
|
96
|
-
const groups = new Map<
|
|
97
|
-
StyleSheet.compile.Options['themes'],
|
|
98
|
-
Source.Call[]
|
|
99
|
-
>()
|
|
96
|
+
const groups = new Map<StyleSheet.compile.Options['vars'], Source.Call[]>()
|
|
100
97
|
for (const call of extracted.calls) {
|
|
101
98
|
if (
|
|
102
99
|
call.recipe ||
|
|
@@ -106,12 +103,12 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
106
103
|
call.output === 'html'
|
|
107
104
|
)
|
|
108
105
|
continue
|
|
109
|
-
const
|
|
110
|
-
const group = groups.get(
|
|
106
|
+
const vars = call.nativeContext?.vars ?? options.vars
|
|
107
|
+
const group = groups.get(vars)
|
|
111
108
|
if (group) group.push(call)
|
|
112
|
-
else groups.set(
|
|
109
|
+
else groups.set(vars, [call])
|
|
113
110
|
}
|
|
114
|
-
for (const [
|
|
111
|
+
for (const [vars, calls] of groups) {
|
|
115
112
|
if (calls.length < 2) continue
|
|
116
113
|
try {
|
|
117
114
|
const compiled = StyleSheet.compile({
|
|
@@ -126,13 +123,13 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
126
123
|
})),
|
|
127
124
|
})),
|
|
128
125
|
},
|
|
129
|
-
|
|
126
|
+
vars,
|
|
130
127
|
units: options.units,
|
|
131
128
|
})
|
|
132
129
|
for (const call of calls) {
|
|
133
130
|
const styles = Object.fromEntries(
|
|
134
|
-
Object.entries(compiled.styles).map(([
|
|
135
|
-
|
|
131
|
+
Object.entries(compiled.styles).map(([set, schemes]) => [
|
|
132
|
+
set,
|
|
136
133
|
Object.freeze({
|
|
137
134
|
light: Object.freeze({ '0': schemes.light[call.name]! }),
|
|
138
135
|
dark: Object.freeze({ '0': schemes.dark[call.name]! }),
|
|
@@ -237,32 +234,32 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
237
234
|
bindings?: ReturnType<typeof NativeBindings.prepare>,
|
|
238
235
|
): string {
|
|
239
236
|
if (contextOptions.contextual) {
|
|
240
|
-
const
|
|
237
|
+
const vars = call?.nativeContext?.vars ?? contextOptions.vars
|
|
241
238
|
if (!call?.slots && !call?.recipe?.payloads?.length)
|
|
242
239
|
compiled ??= Variants.compile({
|
|
243
240
|
recipe,
|
|
244
241
|
fonts: contextOptions.fonts,
|
|
245
242
|
platform: contextOptions.platform,
|
|
246
|
-
|
|
243
|
+
vars,
|
|
247
244
|
units: contextOptions.units,
|
|
248
245
|
})
|
|
249
246
|
else {
|
|
250
247
|
try {
|
|
251
248
|
bindings = NativeBindings.prepare(recipe, call!, {
|
|
252
249
|
...contextOptions,
|
|
253
|
-
|
|
250
|
+
vars,
|
|
254
251
|
})
|
|
255
252
|
} catch (error) {
|
|
256
253
|
if (error instanceof StyleSheet.CompileError) throw error
|
|
257
254
|
throw new CompileError((error as Error).message)
|
|
258
255
|
}
|
|
259
256
|
}
|
|
260
|
-
const
|
|
261
|
-
call?.nativeContext?.
|
|
257
|
+
const defaultVars =
|
|
258
|
+
call?.nativeContext?.defaultVars ?? contextOptions.set ?? 'default'
|
|
262
259
|
const tables = new Map<string, string>()
|
|
263
|
-
const alternatives = (
|
|
264
|
-
(
|
|
265
|
-
|
|
260
|
+
const alternatives = (vars ? Object.keys(vars) : ['default']).map(
|
|
261
|
+
(set) => ({
|
|
262
|
+
set,
|
|
266
263
|
schemes: (['light', 'dark'] as const).map((colorScheme) => {
|
|
267
264
|
const value = callable(
|
|
268
265
|
recipe,
|
|
@@ -271,8 +268,8 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
271
268
|
{
|
|
272
269
|
...contextOptions,
|
|
273
270
|
contextual: false,
|
|
274
|
-
|
|
275
|
-
|
|
271
|
+
vars,
|
|
272
|
+
set,
|
|
276
273
|
colorScheme,
|
|
277
274
|
},
|
|
278
275
|
compiled,
|
|
@@ -285,8 +282,8 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
285
282
|
}),
|
|
286
283
|
)
|
|
287
284
|
const entries = alternatives.map(
|
|
288
|
-
({
|
|
289
|
-
`${JSON.stringify(
|
|
285
|
+
({ set, schemes }) =>
|
|
286
|
+
`${JSON.stringify(set)}:{${schemes.map(({ colorScheme, value }) => `${JSON.stringify(colorScheme)}:${tables.get(value)}`).join(',')}}`,
|
|
290
287
|
)
|
|
291
288
|
const parameters = [...tables.values()].map((name, index) =>
|
|
292
289
|
typed ? `${name}:T${index}` : name,
|
|
@@ -294,7 +291,7 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
294
291
|
const types = typed
|
|
295
292
|
? `<${parameters.map((_, index) => `const T${index} extends (input:never)=>import('zyzz/runtime').Native.Props<object>`).join(',')},>`
|
|
296
293
|
: ''
|
|
297
|
-
const expression = `${types}(${parameters.join(',')})=>${helper}Context.create({${entries.join(',')}},${JSON.stringify(
|
|
294
|
+
const expression = `${types}(${parameters.join(',')})=>${helper}Context.create({${entries.join(',')}},${JSON.stringify(defaultVars)})`
|
|
298
295
|
let context = contexts.get(expression)
|
|
299
296
|
if (!context) {
|
|
300
297
|
context = `${helper}ContextFactory${contexts.size}`
|
|
@@ -351,12 +348,12 @@ export function compile(options: compile.Options): compile.ReturnType {
|
|
|
351
348
|
recipe,
|
|
352
349
|
fonts: contextOptions.fonts,
|
|
353
350
|
platform: contextOptions.platform,
|
|
354
|
-
|
|
351
|
+
vars: contextOptions.vars,
|
|
355
352
|
units: contextOptions.units,
|
|
356
353
|
})
|
|
357
354
|
recipes[name] = compiled
|
|
358
355
|
const styles = StyleSheet.select(compiled.styles, {
|
|
359
|
-
|
|
356
|
+
set: contextOptions.set ?? 'default',
|
|
360
357
|
colorScheme: contextOptions.colorScheme,
|
|
361
358
|
})
|
|
362
359
|
const cached = compiledCalls.get(compiled)
|
|
@@ -743,7 +740,7 @@ export declare namespace compile {
|
|
|
743
740
|
readonly [Edits.runtime]?: boolean | undefined
|
|
744
741
|
/** Compiler-owned graph context. */
|
|
745
742
|
readonly [Themes.context]?: Themes.Context | undefined
|
|
746
|
-
/** Retain every
|
|
743
|
+
/** Retain every set and scheme for render-local selection. */
|
|
747
744
|
readonly contextual?: boolean | undefined
|
|
748
745
|
/** Scheme compiled into this module's callables. Recompile to select another scheme. */
|
|
749
746
|
readonly colorScheme: StyleSheet.ColorScheme
|
|
@@ -751,8 +748,8 @@ export declare namespace compile {
|
|
|
751
748
|
readonly moduleId: string
|
|
752
749
|
/** Shared local style and variants authoring. */
|
|
753
750
|
readonly source: string
|
|
754
|
-
/** Label selected from supplied
|
|
755
|
-
readonly
|
|
751
|
+
/** Label selected from supplied vars. Defaults to the token-fallback default table. */
|
|
752
|
+
readonly set?: string | undefined
|
|
756
753
|
}
|
|
757
754
|
/** Executable source with immutable recipe tables and authored source mappings. */
|
|
758
755
|
type ReturnType = {
|
|
@@ -762,7 +759,7 @@ export declare namespace compile {
|
|
|
762
759
|
readonly code: string
|
|
763
760
|
/** Version-three source map encoded as JSON. */
|
|
764
761
|
readonly map: string
|
|
765
|
-
/** All
|
|
762
|
+
/** All set/scheme tables for each extracted definition. */
|
|
766
763
|
readonly recipes: Readonly<Record<string, Variants.Definition>>
|
|
767
764
|
}
|
|
768
765
|
}
|
package/src/compiler/Source.ts
CHANGED
|
@@ -27,11 +27,13 @@ import * as Scope from './internal/Scope.js'
|
|
|
27
27
|
import type * as Shorthands from '../internal/Shorthands.js'
|
|
28
28
|
import * as Static from './internal/Static.js'
|
|
29
29
|
import * as Style from '../Style.js'
|
|
30
|
-
import type * as Theme from '../Theme.js'
|
|
30
|
+
import type * as Theme from '../internal/Theme.js'
|
|
31
31
|
import * as Themes from './internal/Themes.js'
|
|
32
32
|
import * as ThemeValues from '../web/internal/Themes.js'
|
|
33
33
|
import * as Token from '../internal/Token.js'
|
|
34
|
-
import * as
|
|
34
|
+
import * as Typography from '../internal/Typography.js'
|
|
35
|
+
import * as Value from '../internal/Value.js'
|
|
36
|
+
import * as Vars from './internal/Vars.js'
|
|
35
37
|
import * as Walker from 'oxc-walker'
|
|
36
38
|
|
|
37
39
|
// JavaScript extraction supplies untyped values. Keep structural checks without
|
|
@@ -47,9 +49,9 @@ export type Call = {
|
|
|
47
49
|
readonly nativeContext?:
|
|
48
50
|
| {
|
|
49
51
|
/** Default label selected when the provider omits its theme. */
|
|
50
|
-
readonly
|
|
52
|
+
readonly defaultVars: string
|
|
51
53
|
/** Compatible alternatives from the owning configuration. */
|
|
52
|
-
readonly
|
|
54
|
+
readonly vars: Readonly<Record<string, Theme.Definition>>
|
|
53
55
|
}
|
|
54
56
|
| undefined
|
|
55
57
|
/** Class identity available without source rewriting. */
|
|
@@ -97,6 +99,10 @@ export type Call = {
|
|
|
97
99
|
readonly body?: Ast.ObjectExpression | undefined
|
|
98
100
|
/** Alias targets retained for declaration source locations. */
|
|
99
101
|
readonly shorthands?: Shorthands.Map | undefined
|
|
102
|
+
/** Emitted typography field counts keyed by authored property offsets. */
|
|
103
|
+
readonly typography?: ReadonlyMap<number, number> | undefined
|
|
104
|
+
/** Emitted typography query counts keyed by authored property offsets. */
|
|
105
|
+
readonly typographyQueries?: ReadonlyMap<number, number> | undefined
|
|
100
106
|
/** Native HTML attribute output selected by the bound configuration. */
|
|
101
107
|
readonly output?: 'html' | undefined
|
|
102
108
|
/** Typed runtime slots for callback definitions. */
|
|
@@ -174,6 +180,27 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
174
180
|
|
|
175
181
|
const namespace = identity(options.moduleId)
|
|
176
182
|
const parsed = options[Themes.context]?.parsed ?? Syntax.parse(options)
|
|
183
|
+
for (const node of parsed.program.body) {
|
|
184
|
+
if (node.type !== 'ImportDeclaration' || node.source.value !== 'zyzz')
|
|
185
|
+
continue
|
|
186
|
+
for (const specifier of node.specifiers) {
|
|
187
|
+
if (specifier.type !== 'ImportSpecifier') continue
|
|
188
|
+
const name =
|
|
189
|
+
specifier.imported.type === 'Identifier'
|
|
190
|
+
? specifier.imported.name
|
|
191
|
+
: specifier.imported.value
|
|
192
|
+
if (name === 'Theme' || name === 'Variables')
|
|
193
|
+
throw new ExtractError([
|
|
194
|
+
{
|
|
195
|
+
code: 'unsupported_syntax',
|
|
196
|
+
message: `Import Vars instead of ${name}.`,
|
|
197
|
+
source: options.moduleId,
|
|
198
|
+
start: specifier.start,
|
|
199
|
+
end: specifier.end,
|
|
200
|
+
},
|
|
201
|
+
])
|
|
202
|
+
}
|
|
203
|
+
}
|
|
177
204
|
|
|
178
205
|
if (parsed.errors.length) {
|
|
179
206
|
for (const error of parsed.errors) {
|
|
@@ -216,7 +243,7 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
216
243
|
|
|
217
244
|
const variables = (() => {
|
|
218
245
|
try {
|
|
219
|
-
return
|
|
246
|
+
return Vars.collect(
|
|
220
247
|
program,
|
|
221
248
|
namespace,
|
|
222
249
|
scopeTracker,
|
|
@@ -290,7 +317,7 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
290
317
|
|
|
291
318
|
const binding =
|
|
292
319
|
node.type === 'Identifier'
|
|
293
|
-
? declaration ?? null
|
|
320
|
+
? (declaration ?? null)
|
|
294
321
|
: scopeTracker.getDeclaration(node.name)
|
|
295
322
|
|
|
296
323
|
contributions.read(node, parent, binding)
|
|
@@ -344,6 +371,7 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
344
371
|
name === 'cx' ||
|
|
345
372
|
name === 'style' ||
|
|
346
373
|
name === 'Theme' ||
|
|
374
|
+
name === 'Vars' ||
|
|
347
375
|
name === 'variable' ||
|
|
348
376
|
name === 'variants'
|
|
349
377
|
)
|
|
@@ -640,6 +668,8 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
640
668
|
}
|
|
641
669
|
const name = `style-${namespace}-${call.start}`
|
|
642
670
|
const locations: Style.SourceLocation[] = []
|
|
671
|
+
const typography = new Map<number, number>()
|
|
672
|
+
const typographyQueries = new Map<number, number>()
|
|
643
673
|
const conditionKeys = new Map<string, Ast.Node>()
|
|
644
674
|
|
|
645
675
|
function object(
|
|
@@ -690,7 +720,7 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
690
720
|
? entry.key.value
|
|
691
721
|
: undefined
|
|
692
722
|
: undefined
|
|
693
|
-
if (key !== 'selectors' && key !== '
|
|
723
|
+
if (key !== 'selectors' && key !== 'vars') {
|
|
694
724
|
properties.push(entry)
|
|
695
725
|
continue
|
|
696
726
|
}
|
|
@@ -979,11 +1009,17 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
979
1009
|
!(Binding.is(part)
|
|
980
1010
|
? (dynamicValues !== undefined &&
|
|
981
1011
|
Object.values(dynamicValues.slots).includes(part)) ||
|
|
982
|
-
targets.every(
|
|
983
|
-
|
|
1012
|
+
targets.every(
|
|
1013
|
+
(target) =>
|
|
1014
|
+
Binding.accepts(part.type, target) ||
|
|
1015
|
+
(part.type === 'color' &&
|
|
1016
|
+
Expression.acceptsColor(template, target)),
|
|
984
1017
|
)
|
|
985
|
-
: targets.every(
|
|
986
|
-
|
|
1018
|
+
: targets.every(
|
|
1019
|
+
(target) =>
|
|
1020
|
+
Token.acceptsReference(part, target) ||
|
|
1021
|
+
(part.group === 'color' &&
|
|
1022
|
+
Expression.acceptsColor(template, target)),
|
|
987
1023
|
))
|
|
988
1024
|
) {
|
|
989
1025
|
report(
|
|
@@ -1003,7 +1039,7 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
1003
1039
|
reference &&
|
|
1004
1040
|
Token.is(reference) &&
|
|
1005
1041
|
!targets.every((target) =>
|
|
1006
|
-
Token.
|
|
1042
|
+
Token.acceptsReference(reference, target),
|
|
1007
1043
|
) &&
|
|
1008
1044
|
!targets.every((target) =>
|
|
1009
1045
|
dynamicValues?.accepts(
|
|
@@ -1101,6 +1137,34 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
1101
1137
|
values[key] = value(property.value, [name, ...prefix, key])
|
|
1102
1138
|
}
|
|
1103
1139
|
|
|
1140
|
+
if (typeof values.typography === 'string') {
|
|
1141
|
+
const theme = themes?.styles.get(call.start)?.theme
|
|
1142
|
+
const mappings = theme?.[Token.definition].contract.shorthands
|
|
1143
|
+
const explicit = new Set(
|
|
1144
|
+
Object.keys(values).flatMap((key) => mappings?.[key] ?? [key]),
|
|
1145
|
+
)
|
|
1146
|
+
const parsed = Value.parse(values.typography, 'fontFamily')
|
|
1147
|
+
const keys = Typography.keys(
|
|
1148
|
+
theme,
|
|
1149
|
+
parsed && !('invalid' in parsed) ? parsed.value : values.typography,
|
|
1150
|
+
explicit,
|
|
1151
|
+
)
|
|
1152
|
+
const queries = keys.filter(Typography.condition).length
|
|
1153
|
+
for (const property of properties) {
|
|
1154
|
+
if (property.type !== 'Property') continue
|
|
1155
|
+
const key =
|
|
1156
|
+
property.key.type === 'Identifier'
|
|
1157
|
+
? property.key.name
|
|
1158
|
+
: property.key.type === 'Literal'
|
|
1159
|
+
? property.key.value
|
|
1160
|
+
: undefined
|
|
1161
|
+
if (key === 'typography') {
|
|
1162
|
+
typography.set(property.start, keys.length - queries)
|
|
1163
|
+
if (queries) typographyQueries.set(property.start, queries)
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1104
1168
|
return values
|
|
1105
1169
|
}
|
|
1106
1170
|
|
|
@@ -1110,7 +1174,7 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
1110
1174
|
try {
|
|
1111
1175
|
const definition = define(
|
|
1112
1176
|
{ [name]: values },
|
|
1113
|
-
{ locations,
|
|
1177
|
+
{ locations, vars: themes?.styles.get(call.start)?.theme },
|
|
1114
1178
|
)
|
|
1115
1179
|
|
|
1116
1180
|
function validate(style: Style.NamedStyle, path: readonly string[]) {
|
|
@@ -1166,7 +1230,7 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
1166
1230
|
matches,
|
|
1167
1231
|
value: define(
|
|
1168
1232
|
{ [`${name}-${index}`]: object(value) },
|
|
1169
|
-
{ locations,
|
|
1233
|
+
{ locations, vars: themes?.styles.get(call.start)?.theme },
|
|
1170
1234
|
),
|
|
1171
1235
|
})),
|
|
1172
1236
|
}
|
|
@@ -1185,6 +1249,8 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
1185
1249
|
? { body: argument }
|
|
1186
1250
|
: {}),
|
|
1187
1251
|
...(shorthands ? { shorthands } : {}),
|
|
1252
|
+
...(typography.size ? { typography } : {}),
|
|
1253
|
+
...(typographyQueries.size ? { typographyQueries } : {}),
|
|
1188
1254
|
...(themes?.styles.get(call.start)?.output
|
|
1189
1255
|
? { output: 'html' as const }
|
|
1190
1256
|
: {}),
|
|
@@ -1239,6 +1305,7 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
1239
1305
|
identity: namespace,
|
|
1240
1306
|
links: options[Themes.context]?.links,
|
|
1241
1307
|
program,
|
|
1308
|
+
scopes: themes?.scopeApplications,
|
|
1242
1309
|
source: options.source,
|
|
1243
1310
|
styles,
|
|
1244
1311
|
})) {
|
|
@@ -1315,7 +1382,7 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
1315
1382
|
const rendered = Css.compile({
|
|
1316
1383
|
styles: { styles: [] },
|
|
1317
1384
|
contributions: contributionData,
|
|
1318
|
-
|
|
1385
|
+
vars: themes?.themes,
|
|
1319
1386
|
}).css
|
|
1320
1387
|
AtRules.transform({
|
|
1321
1388
|
filename: options.moduleId,
|
|
@@ -1453,7 +1520,7 @@ export function extract(options: extract.Options): extract.ReturnType {
|
|
|
1453
1520
|
}
|
|
1454
1521
|
: {}),
|
|
1455
1522
|
themeReferences: Object.freeze(themes?.references ?? []),
|
|
1456
|
-
|
|
1523
|
+
vars: themes?.themes ?? Object.freeze({}),
|
|
1457
1524
|
})
|
|
1458
1525
|
}
|
|
1459
1526
|
|
|
@@ -1485,7 +1552,7 @@ export declare namespace extract {
|
|
|
1485
1552
|
readonly contributions?: readonly Css.Contribution[] | undefined
|
|
1486
1553
|
readonly contributionCalls?: readonly Contributions.Call[] | undefined
|
|
1487
1554
|
/** Explicit variable contracts replaced by fixed slot data. */
|
|
1488
|
-
readonly variableCalls?: readonly
|
|
1555
|
+
readonly variableCalls?: readonly Vars.Call[] | undefined
|
|
1489
1556
|
/** Direct calls in source order. */
|
|
1490
1557
|
readonly calls: readonly Call[]
|
|
1491
1558
|
/** Validated definitions accepted by Css.compile. */
|
|
@@ -1512,7 +1579,7 @@ export declare namespace extract {
|
|
|
1512
1579
|
/** Resolved authoring exports when extracted as part of a source graph. */
|
|
1513
1580
|
readonly themeExports?: Readonly<Record<string, Themes.Link>> | undefined
|
|
1514
1581
|
/** Stable scope keys and validated local theme definitions. */
|
|
1515
|
-
readonly
|
|
1582
|
+
readonly vars: Readonly<Record<string, Theme.Definition>>
|
|
1516
1583
|
}
|
|
1517
1584
|
}
|
|
1518
1585
|
|