zyzz 0.0.3 → 0.0.6

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.
Files changed (273) hide show
  1. package/README.md +34 -19
  2. package/dist/Config.d.ts +16 -167
  3. package/dist/Config.d.ts.map +1 -1
  4. package/dist/Config.js +7 -246
  5. package/dist/Config.js.map +1 -1
  6. package/dist/Style.d.ts +15 -12
  7. package/dist/Style.d.ts.map +1 -1
  8. package/dist/Style.js +51 -26
  9. package/dist/Style.js.map +1 -1
  10. package/dist/Vars.d.ts +114 -0
  11. package/dist/Vars.d.ts.map +1 -0
  12. package/dist/Vars.js +42 -0
  13. package/dist/Vars.js.map +1 -0
  14. package/dist/babel/index.d.ts +2 -0
  15. package/dist/babel/index.d.ts.map +1 -1
  16. package/dist/babel/index.js +10 -1
  17. package/dist/babel/index.js.map +1 -1
  18. package/dist/compiler/Graph.d.ts +2 -0
  19. package/dist/compiler/Graph.d.ts.map +1 -1
  20. package/dist/compiler/Graph.js +30 -9
  21. package/dist/compiler/Graph.js.map +1 -1
  22. package/dist/compiler/Native.d.ts +5 -5
  23. package/dist/compiler/Native.d.ts.map +1 -1
  24. package/dist/compiler/Native.js +21 -21
  25. package/dist/compiler/Native.js.map +1 -1
  26. package/dist/compiler/Source.d.ts +8 -6
  27. package/dist/compiler/Source.d.ts.map +1 -1
  28. package/dist/compiler/Source.js +52 -16
  29. package/dist/compiler/Source.js.map +1 -1
  30. package/dist/compiler/Transform.d.ts +1 -1
  31. package/dist/compiler/Transform.d.ts.map +1 -1
  32. package/dist/compiler/Transform.js +58 -22
  33. package/dist/compiler/Transform.js.map +1 -1
  34. package/dist/compiler/internal/Compositions.d.ts +5 -0
  35. package/dist/compiler/internal/Compositions.d.ts.map +1 -1
  36. package/dist/compiler/internal/Compositions.js +22 -3
  37. package/dist/compiler/internal/Compositions.js.map +1 -1
  38. package/dist/compiler/internal/Configurations.d.ts.map +1 -1
  39. package/dist/compiler/internal/Configurations.js +73 -12
  40. package/dist/compiler/internal/Configurations.js.map +1 -1
  41. package/dist/compiler/internal/Contract.d.ts +1 -1
  42. package/dist/compiler/internal/Contract.d.ts.map +1 -1
  43. package/dist/compiler/internal/Contract.js +155 -13
  44. package/dist/compiler/internal/Contract.js.map +1 -1
  45. package/dist/compiler/internal/Contributions.d.ts +1 -1
  46. package/dist/compiler/internal/Contributions.d.ts.map +1 -1
  47. package/dist/compiler/internal/Contributions.js +6 -4
  48. package/dist/compiler/internal/Contributions.js.map +1 -1
  49. package/dist/compiler/internal/Dynamic.js +1 -1
  50. package/dist/compiler/internal/Dynamic.js.map +1 -1
  51. package/dist/compiler/internal/Expression.d.ts +3 -0
  52. package/dist/compiler/internal/Expression.d.ts.map +1 -1
  53. package/dist/compiler/internal/Expression.js +21 -0
  54. package/dist/compiler/internal/Expression.js.map +1 -1
  55. package/dist/compiler/internal/Identifiers.d.ts +1 -1
  56. package/dist/compiler/internal/Identifiers.d.ts.map +1 -1
  57. package/dist/compiler/internal/Identifiers.js +2 -2
  58. package/dist/compiler/internal/Identifiers.js.map +1 -1
  59. package/dist/compiler/internal/NativeBindings.d.ts +1 -1
  60. package/dist/compiler/internal/NativeBindings.d.ts.map +1 -1
  61. package/dist/compiler/internal/NativeBindings.js +3 -3
  62. package/dist/compiler/internal/NativeBindings.js.map +1 -1
  63. package/dist/compiler/internal/PackedStyles.d.ts +1 -1
  64. package/dist/compiler/internal/PackedStyles.d.ts.map +1 -1
  65. package/dist/compiler/internal/PackedStyles.js +15 -25
  66. package/dist/compiler/internal/PackedStyles.js.map +1 -1
  67. package/dist/compiler/internal/Recipes.js +1 -1
  68. package/dist/compiler/internal/Recipes.js.map +1 -1
  69. package/dist/compiler/internal/Selectors.js +1 -1
  70. package/dist/compiler/internal/Selectors.js.map +1 -1
  71. package/dist/compiler/internal/Static.d.ts.map +1 -1
  72. package/dist/compiler/internal/Static.js +2 -0
  73. package/dist/compiler/internal/Static.js.map +1 -1
  74. package/dist/compiler/internal/Themes.d.ts +12 -3
  75. package/dist/compiler/internal/Themes.d.ts.map +1 -1
  76. package/dist/compiler/internal/Themes.js +192 -52
  77. package/dist/compiler/internal/Themes.js.map +1 -1
  78. package/dist/compiler/internal/{Variables.d.ts → Vars.d.ts} +1 -1
  79. package/dist/compiler/internal/Vars.d.ts.map +1 -0
  80. package/dist/compiler/internal/{Variables.js → Vars.js} +3 -3
  81. package/dist/compiler/internal/Vars.js.map +1 -0
  82. package/dist/default.d.ts +147 -2562
  83. package/dist/default.d.ts.map +1 -1
  84. package/dist/default.js +85 -80
  85. package/dist/default.js.map +2 -2
  86. package/dist/default.js.zyzz.json +1 -1
  87. package/dist/esbuild/index.d.ts +3 -0
  88. package/dist/esbuild/index.d.ts.map +1 -0
  89. package/dist/esbuild/index.js +5 -0
  90. package/dist/esbuild/index.js.map +1 -0
  91. package/dist/index.d.ts +4 -4
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +4 -4
  94. package/dist/index.js.map +1 -1
  95. package/dist/internal/Authoring.d.ts +1 -1
  96. package/dist/internal/Authoring.d.ts.map +1 -1
  97. package/dist/internal/Authoring.js +4 -4
  98. package/dist/internal/Authoring.js.map +1 -1
  99. package/dist/internal/Binding.d.ts +1 -1
  100. package/dist/internal/Binding.d.ts.map +1 -1
  101. package/dist/internal/Completion.d.ts +19 -0
  102. package/dist/internal/Completion.d.ts.map +1 -0
  103. package/dist/internal/Completion.js +2 -0
  104. package/dist/internal/Completion.js.map +1 -0
  105. package/dist/internal/Condition.d.ts +3 -1
  106. package/dist/internal/Condition.d.ts.map +1 -1
  107. package/dist/internal/Condition.js.map +1 -1
  108. package/dist/internal/Configuration.d.ts +248 -0
  109. package/dist/internal/Configuration.d.ts.map +1 -0
  110. package/dist/internal/Configuration.js +343 -0
  111. package/dist/internal/Configuration.js.map +1 -0
  112. package/dist/{Theme.d.ts → internal/Theme.d.ts} +15 -13
  113. package/dist/internal/Theme.d.ts.map +1 -0
  114. package/dist/{Theme.js → internal/Theme.js} +39 -12
  115. package/dist/internal/Theme.js.map +1 -0
  116. package/dist/internal/Token.d.ts +46 -16
  117. package/dist/internal/Token.d.ts.map +1 -1
  118. package/dist/internal/Token.js +89 -5
  119. package/dist/internal/Token.js.map +1 -1
  120. package/dist/internal/Typography.d.ts +13 -5
  121. package/dist/internal/Typography.d.ts.map +1 -1
  122. package/dist/internal/Typography.js +42 -6
  123. package/dist/internal/Typography.js.map +1 -1
  124. package/dist/internal/Value.d.ts +6 -1
  125. package/dist/internal/Value.d.ts.map +1 -1
  126. package/dist/internal/Value.js.map +1 -1
  127. package/dist/internal/VariableSets.d.ts +20 -0
  128. package/dist/internal/VariableSets.d.ts.map +1 -0
  129. package/dist/internal/VariableSets.js +317 -0
  130. package/dist/internal/VariableSets.js.map +1 -0
  131. package/dist/next/index.d.ts +8 -3
  132. package/dist/next/index.d.ts.map +1 -1
  133. package/dist/next/index.js +21 -10
  134. package/dist/next/index.js.map +1 -1
  135. package/dist/next/loader.d.ts +1 -0
  136. package/dist/next/loader.d.ts.map +1 -1
  137. package/dist/next/loader.js +25 -6
  138. package/dist/next/loader.js.map +1 -1
  139. package/dist/node/Host.d.ts.map +1 -1
  140. package/dist/node/Host.js +1 -1
  141. package/dist/node/Host.js.map +1 -1
  142. package/dist/node/Reset.d.ts +3 -0
  143. package/dist/node/Reset.d.ts.map +1 -0
  144. package/dist/node/Reset.js +7 -0
  145. package/dist/node/Reset.js.map +1 -0
  146. package/dist/react-native/Host.d.ts +2 -2
  147. package/dist/react-native/Host.d.ts.map +1 -1
  148. package/dist/react-native/Host.js +4 -4
  149. package/dist/react-native/Host.js.map +1 -1
  150. package/dist/react-native/StyleSheet.d.ts +9 -8
  151. package/dist/react-native/StyleSheet.d.ts.map +1 -1
  152. package/dist/react-native/StyleSheet.js +29 -23
  153. package/dist/react-native/StyleSheet.js.map +1 -1
  154. package/dist/react-native/Variants.d.ts +3 -3
  155. package/dist/react-native/Variants.d.ts.map +1 -1
  156. package/dist/react-native/Variants.js +2 -2
  157. package/dist/react-native/react.d.ts +1 -1
  158. package/dist/react-native/react.d.ts.map +1 -1
  159. package/dist/react-native/react.js +5 -5
  160. package/dist/react-native/react.js.map +1 -1
  161. package/dist/rollup/index.d.ts +3 -0
  162. package/dist/rollup/index.d.ts.map +1 -0
  163. package/dist/rollup/index.js +5 -0
  164. package/dist/rollup/index.js.map +1 -0
  165. package/dist/runtime/Appearance.d.ts +7 -7
  166. package/dist/runtime/Appearance.d.ts.map +1 -1
  167. package/dist/runtime/Appearance.js +15 -15
  168. package/dist/runtime/Appearance.js.map +1 -1
  169. package/dist/runtime/Dynamic.d.ts.map +1 -1
  170. package/dist/runtime/Dynamic.js +4 -1
  171. package/dist/runtime/Dynamic.js.map +1 -1
  172. package/dist/runtime/NativeContext.d.ts +4 -4
  173. package/dist/runtime/NativeContext.d.ts.map +1 -1
  174. package/dist/runtime/NativeContext.js +5 -5
  175. package/dist/runtime/NativeContext.js.map +1 -1
  176. package/dist/runtime/NativeDynamic.d.ts +1 -1
  177. package/dist/runtime/NativeDynamic.d.ts.map +1 -1
  178. package/dist/runtime/NativeDynamic.js.map +1 -1
  179. package/dist/runtime/Props.d.ts +1 -1
  180. package/dist/runtime/Props.js +3 -3
  181. package/dist/runtime/Props.js.map +1 -1
  182. package/dist/runtime/Selection.d.ts +14 -10
  183. package/dist/runtime/Selection.d.ts.map +1 -1
  184. package/dist/runtime/Selection.js +19 -18
  185. package/dist/runtime/Selection.js.map +1 -1
  186. package/dist/styleFunction.d.ts +14 -14
  187. package/dist/styleFunction.d.ts.map +1 -1
  188. package/dist/styleFunction.js.map +1 -1
  189. package/dist/unplugin/index.d.ts +22 -0
  190. package/dist/unplugin/index.d.ts.map +1 -0
  191. package/dist/unplugin/index.js +500 -0
  192. package/dist/unplugin/index.js.map +1 -0
  193. package/dist/variants.d.ts +3 -3
  194. package/dist/variants.d.ts.map +1 -1
  195. package/dist/variants.js.map +1 -1
  196. package/dist/vite/index.d.ts +2 -0
  197. package/dist/vite/index.d.ts.map +1 -1
  198. package/dist/vite/index.js +44 -12
  199. package/dist/vite/index.js.map +1 -1
  200. package/dist/web/Css.d.ts +4 -3
  201. package/dist/web/Css.d.ts.map +1 -1
  202. package/dist/web/Css.js +4 -4
  203. package/dist/web/Css.js.map +1 -1
  204. package/dist/web/internal/Themes.d.ts +3 -2
  205. package/dist/web/internal/Themes.d.ts.map +1 -1
  206. package/dist/web/internal/Themes.js +42 -6
  207. package/dist/web/internal/Themes.js.map +1 -1
  208. package/dist/webpack/index.d.ts +3 -0
  209. package/dist/webpack/index.d.ts.map +1 -0
  210. package/dist/webpack/index.js +5 -0
  211. package/dist/webpack/index.js.map +1 -0
  212. package/package.json +23 -2
  213. package/src/Config.ts +43 -685
  214. package/src/Style.ts +97 -34
  215. package/src/Vars.ts +299 -0
  216. package/src/babel/index.ts +23 -1
  217. package/src/compiler/Graph.ts +36 -9
  218. package/src/compiler/Native.ts +29 -32
  219. package/src/compiler/Source.ts +64 -22
  220. package/src/compiler/Transform.ts +73 -23
  221. package/src/compiler/internal/Compositions.ts +36 -3
  222. package/src/compiler/internal/Configurations.ts +83 -11
  223. package/src/compiler/internal/Contract.ts +207 -15
  224. package/src/compiler/internal/Contributions.ts +6 -3
  225. package/src/compiler/internal/Dynamic.ts +1 -1
  226. package/src/compiler/internal/Expression.ts +26 -0
  227. package/src/compiler/internal/Identifiers.ts +2 -1
  228. package/src/compiler/internal/NativeBindings.ts +3 -3
  229. package/src/compiler/internal/PackedStyles.ts +22 -26
  230. package/src/compiler/internal/Recipes.ts +1 -1
  231. package/src/compiler/internal/Selectors.ts +1 -1
  232. package/src/compiler/internal/Static.ts +1 -0
  233. package/src/compiler/internal/Themes.ts +266 -57
  234. package/src/compiler/internal/{Variables.ts → Vars.ts} +2 -2
  235. package/src/default.ts +173 -154
  236. package/src/esbuild/index.ts +5 -0
  237. package/src/index.ts +4 -4
  238. package/src/internal/Authoring.ts +5 -7
  239. package/src/internal/Binding.ts +1 -1
  240. package/src/internal/Completion.ts +42 -0
  241. package/src/internal/Condition.ts +31 -1
  242. package/src/internal/Configuration.ts +970 -0
  243. package/src/{Theme.ts → internal/Theme.ts} +75 -20
  244. package/src/internal/Token.ts +258 -85
  245. package/src/internal/Typography.ts +71 -16
  246. package/src/internal/Value.ts +45 -26
  247. package/src/internal/VariableSets.ts +458 -0
  248. package/src/next/index.ts +34 -12
  249. package/src/next/loader.ts +35 -6
  250. package/src/node/Host.ts +1 -2
  251. package/src/node/Reset.ts +7 -0
  252. package/src/react-native/Host.ts +6 -6
  253. package/src/react-native/StyleSheet.ts +49 -42
  254. package/src/react-native/Variants.ts +3 -3
  255. package/src/react-native/react.ts +6 -6
  256. package/src/rollup/index.ts +5 -0
  257. package/src/runtime/Appearance.ts +20 -20
  258. package/src/runtime/Dynamic.ts +4 -1
  259. package/src/runtime/NativeContext.ts +8 -8
  260. package/src/runtime/NativeDynamic.ts +2 -4
  261. package/src/runtime/Props.ts +3 -3
  262. package/src/runtime/Selection.ts +44 -33
  263. package/src/styleFunction.ts +22 -19
  264. package/src/unplugin/index.ts +604 -0
  265. package/src/variants.ts +7 -5
  266. package/src/vite/index.ts +48 -18
  267. package/src/web/Css.ts +10 -7
  268. package/src/web/internal/Themes.ts +52 -9
  269. package/src/webpack/index.ts +5 -0
  270. package/dist/Theme.d.ts.map +0 -1
  271. package/dist/Theme.js.map +0 -1
  272. package/dist/compiler/internal/Variables.d.ts.map +0 -1
  273. package/dist/compiler/internal/Variables.js.map +0 -1
@@ -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'
@@ -65,6 +65,8 @@ export declare namespace compile {
65
65
  | undefined
66
66
  /** Complete source graph keyed by stable package-relative module identities. */
67
67
  readonly modules: Readonly<Record<string, string>>
68
+ /** Optional reset stylesheet supplied by the host, ordered before authored layers. */
69
+ readonly reset?: string | undefined
68
70
  }
69
71
 
70
72
  /** Compiled modules and their direct source dependencies. */
@@ -119,6 +121,7 @@ type Cache = {
119
121
  development: boolean
120
122
  extracted: ReadonlyMap<string, Source.extract.ReturnType>
121
123
  libraries: Readonly<Record<string, ReturnType<typeof Contract.read>>>
124
+ reset: string | undefined
122
125
  resolutions: Readonly<Record<string, string>>
123
126
  native: compile.Options['native']
124
127
  result: compile.ReturnType
@@ -135,7 +138,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
135
138
  Object.keys(options.native ?? {}).length ||
136
139
  Object.entries(cache?.native ?? {}).some(([key, value]) => {
137
140
  const next = Reflect.get(options.native ?? {}, key)
138
- if (key !== 'fonts' && key !== 'themes' && key !== 'units')
141
+ if (key !== 'fonts' && key !== 'vars' && key !== 'units')
139
142
  return value !== next
140
143
 
141
144
  return (
@@ -148,11 +151,16 @@ function build(options: compile.Options, cache?: Cache): Cache {
148
151
  })
149
152
  )
150
153
  cache = undefined
154
+ if (options.native && options.reset !== undefined)
155
+ throw new Native.CompileError(
156
+ 'The CSS reset is only supported by web builds.',
157
+ )
151
158
  if (options.native && options.compiler === false)
152
159
  throw new Native.CompileError(
153
160
  'Native graph compilation requires source rewriting.',
154
161
  )
155
162
  if (cache?.compiler !== (options.compiler !== false)) cache = undefined
163
+ if (cache?.reset !== options.reset) cache = undefined
156
164
  if (cache?.cssOutput !== options.cssOutput) cache = undefined
157
165
  if (cache?.composition !== options.composition) cache = undefined
158
166
  const ids = Object.keys(options.modules).sort()
@@ -961,7 +969,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
961
969
  source: options.modules[moduleId]!,
962
970
  }
963
971
 
964
- Object.assign(themes, result.themes)
972
+ Object.assign(themes, result.vars)
965
973
  visiting.delete(moduleId)
966
974
 
967
975
  return result
@@ -1060,9 +1068,10 @@ function build(options: compile.Options, cache?: Cache): Cache {
1060
1068
  native: {
1061
1069
  ...options.native,
1062
1070
  ...(options.native.fonts && { fonts: { ...options.native.fonts } }),
1063
- ...(options.native.themes && { themes: { ...options.native.themes } }),
1071
+ ...(options.native.vars && { vars: { ...options.native.vars } }),
1064
1072
  ...(options.native.units && { units: { ...options.native.units } }),
1065
1073
  },
1074
+ reset: options.reset,
1066
1075
  resolutions: Object.freeze(resolutions),
1067
1076
  result: Object.freeze({
1068
1077
  contracts: Object.freeze(
@@ -1121,7 +1130,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
1121
1130
  ? ''
1122
1131
  : (Css.compile({
1123
1132
  styles: { styles: [] },
1124
- themes: sharedThemes,
1133
+ vars: sharedThemes,
1125
1134
  contributions: [contribution],
1126
1135
  }).contributionCss ?? ''),
1127
1136
  layers: contribution.kind === 'layers' ? [contribution.names] : [],
@@ -1244,6 +1253,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
1244
1253
  try {
1245
1254
  const sharedSections = ids.flatMap((id) => reachable(id, sharedVisited))
1246
1255
  const resetSource =
1256
+ (options.reset === undefined ? undefined : 'zyzz/reset.css') ??
1247
1257
  resetOwners[0] ??
1248
1258
  sharedSections.find((section) => section.key === 'optional-reset-order')
1249
1259
  ?.source
@@ -1262,6 +1272,17 @@ function build(options: compile.Options, cache?: Cache): Cache {
1262
1272
  },
1263
1273
  ]),
1264
1274
  ...sharedSections,
1275
+ ...(options.reset === undefined
1276
+ ? []
1277
+ : [
1278
+ {
1279
+ source: 'zyzz/reset.css',
1280
+ key: 'optional-reset',
1281
+ css: options.reset,
1282
+ content: options.reset,
1283
+ layers: [['reset']],
1284
+ },
1285
+ ]),
1265
1286
  ])
1266
1287
  } catch (error) {
1267
1288
  return fail(
@@ -1345,7 +1366,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
1345
1366
  )
1346
1367
  identities.set(name, signature)
1347
1368
  }
1348
- for (const [name, theme] of Object.entries(module.themes)) {
1369
+ for (const [name, theme] of Object.entries(module.vars)) {
1349
1370
  const data = theme[Token.definition]
1350
1371
  if (data.contract[Token.identity]?.startsWith('id-'))
1351
1372
  register(`theme:${name}`, JSON.stringify(data.values))
@@ -1403,7 +1424,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
1403
1424
  [Themes.context]: {
1404
1425
  extracted: Object.freeze({
1405
1426
  ...extracted.get(moduleId)!,
1406
- themes: sharedThemes,
1427
+ vars: sharedThemes,
1407
1428
  contributions: undefined,
1408
1429
  }),
1409
1430
  links: {},
@@ -1435,7 +1456,12 @@ function build(options: compile.Options, cache?: Cache): Cache {
1435
1456
  }
1436
1457
 
1437
1458
  for (const call of extracted.get(moduleId)!.calls)
1438
- if (call.identity)
1459
+ if (
1460
+ call.identity &&
1461
+ !call.composition &&
1462
+ !call.runtimeComposition &&
1463
+ !call.compositionCase
1464
+ )
1439
1465
  styleClasses[call.identity] = modules[moduleId]!.classes[call.name]!
1440
1466
  }
1441
1467
 
@@ -1504,6 +1530,7 @@ function build(options: compile.Options, cache?: Cache): Cache {
1504
1530
  extracted,
1505
1531
  libraries: Object.freeze(libraries),
1506
1532
  native: undefined,
1533
+ reset: options.reset,
1507
1534
  resolutions: Object.freeze(resolutions),
1508
1535
  result: Object.freeze({
1509
1536
  ...(sharedCss
@@ -1581,6 +1608,6 @@ function nativeOutput(
1581
1608
  get map() {
1582
1609
  return (sourceMap ??= JSON.parse(output.map) as Mapping.EncodedSourceMap)
1583
1610
  },
1584
- themes: Object.freeze({}),
1611
+ vars: Object.freeze({}),
1585
1612
  })
1586
1613
  }
@@ -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 theme/scheme.
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 theme controls.',
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 themes = call.nativeContext?.themes ?? options.themes
110
- const group = groups.get(themes)
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(themes, [call])
109
+ else groups.set(vars, [call])
113
110
  }
114
- for (const [themes, calls] of groups) {
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
- themes,
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(([theme, schemes]) => [
135
- theme,
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 themes = call?.nativeContext?.themes ?? contextOptions.themes
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
- themes,
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
- themes,
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 defaultTheme =
261
- call?.nativeContext?.defaultTheme ?? contextOptions.theme ?? 'default'
257
+ const defaultVars =
258
+ call?.nativeContext?.defaultVars ?? contextOptions.set ?? 'default'
262
259
  const tables = new Map<string, string>()
263
- const alternatives = (themes ? Object.keys(themes) : ['default']).map(
264
- (theme) => ({
265
- theme,
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
- themes,
275
- theme,
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
- ({ theme, schemes }) =>
289
- `${JSON.stringify(theme)}:{${schemes.map(({ colorScheme, value }) => `${JSON.stringify(colorScheme)}:${tables.get(value)}`).join(',')}}`,
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(defaultTheme)})`
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
- themes: contextOptions.themes,
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
- theme: contextOptions.theme ?? 'default',
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 theme and scheme for render-local selection. */
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 themes. Defaults to the token-fallback default table. */
755
- readonly theme?: string | undefined
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 theme/scheme tables for each extracted definition. */
762
+ /** All set/scheme tables for each extracted definition. */
766
763
  readonly recipes: Readonly<Record<string, Variants.Definition>>
767
764
  }
768
765
  }
@@ -27,13 +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
34
  import * as Typography from '../internal/Typography.js'
35
35
  import * as Value from '../internal/Value.js'
36
- import * as Variables from './internal/Variables.js'
36
+ import * as Vars from './internal/Vars.js'
37
37
  import * as Walker from 'oxc-walker'
38
38
 
39
39
  // JavaScript extraction supplies untyped values. Keep structural checks without
@@ -49,9 +49,9 @@ export type Call = {
49
49
  readonly nativeContext?:
50
50
  | {
51
51
  /** Default label selected when the provider omits its theme. */
52
- readonly defaultTheme: string
52
+ readonly defaultVars: string
53
53
  /** Compatible alternatives from the owning configuration. */
54
- readonly themes: Readonly<Record<string, Theme.Definition>>
54
+ readonly vars: Readonly<Record<string, Theme.Definition>>
55
55
  }
56
56
  | undefined
57
57
  /** Class identity available without source rewriting. */
@@ -101,6 +101,8 @@ export type Call = {
101
101
  readonly shorthands?: Shorthands.Map | undefined
102
102
  /** Emitted typography field counts keyed by authored property offsets. */
103
103
  readonly typography?: ReadonlyMap<number, number> | undefined
104
+ /** Emitted typography query counts keyed by authored property offsets. */
105
+ readonly typographyQueries?: ReadonlyMap<number, number> | undefined
104
106
  /** Native HTML attribute output selected by the bound configuration. */
105
107
  readonly output?: 'html' | undefined
106
108
  /** Typed runtime slots for callback definitions. */
@@ -178,6 +180,27 @@ export function extract(options: extract.Options): extract.ReturnType {
178
180
 
179
181
  const namespace = identity(options.moduleId)
180
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
+ }
181
204
 
182
205
  if (parsed.errors.length) {
183
206
  for (const error of parsed.errors) {
@@ -220,7 +243,7 @@ export function extract(options: extract.Options): extract.ReturnType {
220
243
 
221
244
  const variables = (() => {
222
245
  try {
223
- return Variables.collect(
246
+ return Vars.collect(
224
247
  program,
225
248
  namespace,
226
249
  scopeTracker,
@@ -294,7 +317,7 @@ export function extract(options: extract.Options): extract.ReturnType {
294
317
 
295
318
  const binding =
296
319
  node.type === 'Identifier'
297
- ? declaration ?? null
320
+ ? (declaration ?? null)
298
321
  : scopeTracker.getDeclaration(node.name)
299
322
 
300
323
  contributions.read(node, parent, binding)
@@ -348,6 +371,7 @@ export function extract(options: extract.Options): extract.ReturnType {
348
371
  name === 'cx' ||
349
372
  name === 'style' ||
350
373
  name === 'Theme' ||
374
+ name === 'Vars' ||
351
375
  name === 'variable' ||
352
376
  name === 'variants'
353
377
  )
@@ -447,7 +471,10 @@ export function extract(options: extract.Options): extract.ReturnType {
447
471
 
448
472
  pending.sort((a, b) => a.start - b.start)
449
473
 
450
- const staticCalls = new Set(pending.map((call) => call.start))
474
+ const staticCalls = new Set([
475
+ ...pending.map((call) => call.start),
476
+ ...contributions.calls.map((call) => call.start),
477
+ ])
451
478
  const opaque = new Set(variables.references.keys())
452
479
  const normalized = new Map<number, Ast.Node | Error>()
453
480
  const selectorKeys = new Set<number>()
@@ -645,6 +672,7 @@ export function extract(options: extract.Options): extract.ReturnType {
645
672
  const name = `style-${namespace}-${call.start}`
646
673
  const locations: Style.SourceLocation[] = []
647
674
  const typography = new Map<number, number>()
675
+ const typographyQueries = new Map<number, number>()
648
676
  const conditionKeys = new Map<string, Ast.Node>()
649
677
 
650
678
  function object(
@@ -695,7 +723,7 @@ export function extract(options: extract.Options): extract.ReturnType {
695
723
  ? entry.key.value
696
724
  : undefined
697
725
  : undefined
698
- if (key !== 'selectors' && key !== 'variables') {
726
+ if (key !== 'selectors' && key !== 'vars') {
699
727
  properties.push(entry)
700
728
  continue
701
729
  }
@@ -984,11 +1012,17 @@ export function extract(options: extract.Options): extract.ReturnType {
984
1012
  !(Binding.is(part)
985
1013
  ? (dynamicValues !== undefined &&
986
1014
  Object.values(dynamicValues.slots).includes(part)) ||
987
- targets.every((target) =>
988
- Binding.accepts(part.type, target),
1015
+ targets.every(
1016
+ (target) =>
1017
+ Binding.accepts(part.type, target) ||
1018
+ (part.type === 'color' &&
1019
+ Expression.acceptsColor(template, target)),
989
1020
  )
990
- : targets.every((target) =>
991
- Token.accepts(part.group, target),
1021
+ : targets.every(
1022
+ (target) =>
1023
+ Token.acceptsReference(part, target) ||
1024
+ (part.group === 'color' &&
1025
+ Expression.acceptsColor(template, target)),
992
1026
  ))
993
1027
  ) {
994
1028
  report(
@@ -1008,7 +1042,7 @@ export function extract(options: extract.Options): extract.ReturnType {
1008
1042
  reference &&
1009
1043
  Token.is(reference) &&
1010
1044
  !targets.every((target) =>
1011
- Token.accepts(reference.group, target),
1045
+ Token.acceptsReference(reference, target),
1012
1046
  ) &&
1013
1047
  !targets.every((target) =>
1014
1048
  dynamicValues?.accepts(
@@ -1113,10 +1147,12 @@ export function extract(options: extract.Options): extract.ReturnType {
1113
1147
  Object.keys(values).flatMap((key) => mappings?.[key] ?? [key]),
1114
1148
  )
1115
1149
  const parsed = Value.parse(values.typography, 'fontFamily')
1116
- const count = Typography.fields(
1150
+ const keys = Typography.keys(
1117
1151
  theme,
1118
1152
  parsed && !('invalid' in parsed) ? parsed.value : values.typography,
1119
- ).filter((field) => !explicit.has(field)).length
1153
+ explicit,
1154
+ )
1155
+ const queries = keys.filter(Typography.condition).length
1120
1156
  for (const property of properties) {
1121
1157
  if (property.type !== 'Property') continue
1122
1158
  const key =
@@ -1125,7 +1161,10 @@ export function extract(options: extract.Options): extract.ReturnType {
1125
1161
  : property.key.type === 'Literal'
1126
1162
  ? property.key.value
1127
1163
  : undefined
1128
- if (key === 'typography') typography.set(property.start, count)
1164
+ if (key === 'typography') {
1165
+ typography.set(property.start, keys.length - queries)
1166
+ if (queries) typographyQueries.set(property.start, queries)
1167
+ }
1129
1168
  }
1130
1169
  }
1131
1170
 
@@ -1138,7 +1177,7 @@ export function extract(options: extract.Options): extract.ReturnType {
1138
1177
  try {
1139
1178
  const definition = define(
1140
1179
  { [name]: values },
1141
- { locations, theme: themes?.styles.get(call.start)?.theme },
1180
+ { locations, vars: themes?.styles.get(call.start)?.theme },
1142
1181
  )
1143
1182
 
1144
1183
  function validate(style: Style.NamedStyle, path: readonly string[]) {
@@ -1194,7 +1233,7 @@ export function extract(options: extract.Options): extract.ReturnType {
1194
1233
  matches,
1195
1234
  value: define(
1196
1235
  { [`${name}-${index}`]: object(value) },
1197
- { locations, theme: themes?.styles.get(call.start)?.theme },
1236
+ { locations, vars: themes?.styles.get(call.start)?.theme },
1198
1237
  ),
1199
1238
  })),
1200
1239
  }
@@ -1214,6 +1253,7 @@ export function extract(options: extract.Options): extract.ReturnType {
1214
1253
  : {}),
1215
1254
  ...(shorthands ? { shorthands } : {}),
1216
1255
  ...(typography.size ? { typography } : {}),
1256
+ ...(typographyQueries.size ? { typographyQueries } : {}),
1217
1257
  ...(themes?.styles.get(call.start)?.output
1218
1258
  ? { output: 'html' as const }
1219
1259
  : {}),
@@ -1268,6 +1308,7 @@ export function extract(options: extract.Options): extract.ReturnType {
1268
1308
  identity: namespace,
1269
1309
  links: options[Themes.context]?.links,
1270
1310
  program,
1311
+ scopes: themes?.scopeApplications,
1271
1312
  source: options.source,
1272
1313
  styles,
1273
1314
  })) {
@@ -1327,6 +1368,7 @@ export function extract(options: extract.Options): extract.ReturnType {
1327
1368
  contributions,
1328
1369
  themes?.tokens ?? new Map(),
1329
1370
  contributionStarts,
1371
+ (node) => staticData.resolve(node, staticCalls),
1330
1372
  ),
1331
1373
  ...(themes?.calls ?? []).flatMap((call) =>
1332
1374
  call.options?.layers
@@ -1344,7 +1386,7 @@ export function extract(options: extract.Options): extract.ReturnType {
1344
1386
  const rendered = Css.compile({
1345
1387
  styles: { styles: [] },
1346
1388
  contributions: contributionData,
1347
- themes: themes?.themes,
1389
+ vars: themes?.themes,
1348
1390
  }).css
1349
1391
  AtRules.transform({
1350
1392
  filename: options.moduleId,
@@ -1482,7 +1524,7 @@ export function extract(options: extract.Options): extract.ReturnType {
1482
1524
  }
1483
1525
  : {}),
1484
1526
  themeReferences: Object.freeze(themes?.references ?? []),
1485
- themes: themes?.themes ?? Object.freeze({}),
1527
+ vars: themes?.themes ?? Object.freeze({}),
1486
1528
  })
1487
1529
  }
1488
1530
 
@@ -1514,7 +1556,7 @@ export declare namespace extract {
1514
1556
  readonly contributions?: readonly Css.Contribution[] | undefined
1515
1557
  readonly contributionCalls?: readonly Contributions.Call[] | undefined
1516
1558
  /** Explicit variable contracts replaced by fixed slot data. */
1517
- readonly variableCalls?: readonly Variables.Call[] | undefined
1559
+ readonly variableCalls?: readonly Vars.Call[] | undefined
1518
1560
  /** Direct calls in source order. */
1519
1561
  readonly calls: readonly Call[]
1520
1562
  /** Validated definitions accepted by Css.compile. */
@@ -1541,7 +1583,7 @@ export declare namespace extract {
1541
1583
  /** Resolved authoring exports when extracted as part of a source graph. */
1542
1584
  readonly themeExports?: Readonly<Record<string, Themes.Link>> | undefined
1543
1585
  /** Stable scope keys and validated local theme definitions. */
1544
- readonly themes: Readonly<Record<string, Theme.Definition>>
1586
+ readonly vars: Readonly<Record<string, Theme.Definition>>
1545
1587
  }
1546
1588
  }
1547
1589