zyzz 0.0.20 → 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.
Files changed (298) hide show
  1. package/Zyzz.podspec +16 -0
  2. package/dist/Style.d.ts +10 -1
  3. package/dist/Style.d.ts.map +1 -1
  4. package/dist/Style.js +1 -5
  5. package/dist/Style.js.map +1 -1
  6. package/dist/babel/NativeJsx.d.ts.map +1 -1
  7. package/dist/babel/NativeJsx.js +204 -12
  8. package/dist/babel/NativeJsx.js.map +1 -1
  9. package/dist/babel/index.d.ts +6 -2
  10. package/dist/babel/index.d.ts.map +1 -1
  11. package/dist/babel/index.js +10 -1
  12. package/dist/babel/index.js.map +1 -1
  13. package/dist/compiler/Graph.d.ts +3 -0
  14. package/dist/compiler/Graph.d.ts.map +1 -1
  15. package/dist/compiler/Graph.js +108 -37
  16. package/dist/compiler/Graph.js.map +1 -1
  17. package/dist/compiler/Native.d.ts +6 -3
  18. package/dist/compiler/Native.d.ts.map +1 -1
  19. package/dist/compiler/Native.js +142 -24
  20. package/dist/compiler/Native.js.map +1 -1
  21. package/dist/compiler/Source.d.ts +6 -0
  22. package/dist/compiler/Source.d.ts.map +1 -1
  23. package/dist/compiler/Source.js +80 -11
  24. package/dist/compiler/Source.js.map +1 -1
  25. package/dist/compiler/Transform.d.ts +4 -1
  26. package/dist/compiler/Transform.d.ts.map +1 -1
  27. package/dist/compiler/Transform.js +32 -46
  28. package/dist/compiler/Transform.js.map +1 -1
  29. package/dist/compiler/internal/Catalogs.d.ts.map +1 -1
  30. package/dist/compiler/internal/Catalogs.js +6 -1
  31. package/dist/compiler/internal/Catalogs.js.map +1 -1
  32. package/dist/compiler/internal/Compositions.d.ts.map +1 -1
  33. package/dist/compiler/internal/Compositions.js +5 -0
  34. package/dist/compiler/internal/Compositions.js.map +1 -1
  35. package/dist/compiler/internal/Configurations.d.ts +2 -0
  36. package/dist/compiler/internal/Configurations.d.ts.map +1 -1
  37. package/dist/compiler/internal/Configurations.js +23 -4
  38. package/dist/compiler/internal/Configurations.js.map +1 -1
  39. package/dist/compiler/internal/Contract.d.ts +4 -1
  40. package/dist/compiler/internal/Contract.d.ts.map +1 -1
  41. package/dist/compiler/internal/Contract.js +97 -151
  42. package/dist/compiler/internal/Contract.js.map +1 -1
  43. package/dist/compiler/internal/Contributions.d.ts.map +1 -1
  44. package/dist/compiler/internal/Contributions.js +8 -4
  45. package/dist/compiler/internal/Contributions.js.map +1 -1
  46. package/dist/compiler/internal/Descriptors.d.ts.map +1 -1
  47. package/dist/compiler/internal/Descriptors.js +11 -2
  48. package/dist/compiler/internal/Descriptors.js.map +1 -1
  49. package/dist/compiler/internal/Dynamic.d.ts +1 -1
  50. package/dist/compiler/internal/Dynamic.d.ts.map +1 -1
  51. package/dist/compiler/internal/Dynamic.js +5 -5
  52. package/dist/compiler/internal/Dynamic.js.map +1 -1
  53. package/dist/compiler/internal/Names.d.ts +5 -0
  54. package/dist/compiler/internal/Names.d.ts.map +1 -0
  55. package/dist/compiler/internal/Names.js +37 -0
  56. package/dist/compiler/internal/Names.js.map +1 -0
  57. package/dist/compiler/internal/NativeBindings.d.ts +24 -26
  58. package/dist/compiler/internal/NativeBindings.d.ts.map +1 -1
  59. package/dist/compiler/internal/NativeBindings.js +61 -8
  60. package/dist/compiler/internal/NativeBindings.js.map +1 -1
  61. package/dist/compiler/internal/NativeMedia.d.ts +14 -0
  62. package/dist/compiler/internal/NativeMedia.d.ts.map +1 -0
  63. package/dist/compiler/internal/NativeMedia.js +287 -0
  64. package/dist/compiler/internal/NativeMedia.js.map +1 -0
  65. package/dist/compiler/internal/NativeVars.d.ts +28 -0
  66. package/dist/compiler/internal/NativeVars.d.ts.map +1 -0
  67. package/dist/compiler/internal/NativeVars.js +157 -0
  68. package/dist/compiler/internal/NativeVars.js.map +1 -0
  69. package/dist/compiler/internal/PackedStyles.d.ts +2 -0
  70. package/dist/compiler/internal/PackedStyles.d.ts.map +1 -1
  71. package/dist/compiler/internal/PackedStyles.js +2 -0
  72. package/dist/compiler/internal/PackedStyles.js.map +1 -1
  73. package/dist/compiler/internal/Selectors.d.ts +1 -1
  74. package/dist/compiler/internal/Selectors.d.ts.map +1 -1
  75. package/dist/compiler/internal/Selectors.js +5 -2
  76. package/dist/compiler/internal/Selectors.js.map +1 -1
  77. package/dist/compiler/internal/Stylesheets.js +2 -2
  78. package/dist/compiler/internal/Stylesheets.js.map +1 -1
  79. package/dist/compiler/internal/Themes.d.ts +22 -1
  80. package/dist/compiler/internal/Themes.d.ts.map +1 -1
  81. package/dist/compiler/internal/Themes.js +120 -4
  82. package/dist/compiler/internal/Themes.js.map +1 -1
  83. package/dist/compiler/internal/Vars.d.ts +3 -1
  84. package/dist/compiler/internal/Vars.d.ts.map +1 -1
  85. package/dist/compiler/internal/Vars.js +14 -3
  86. package/dist/compiler/internal/Vars.js.map +1 -1
  87. package/dist/default.d.ts +4 -4
  88. package/dist/default.d.ts.map +1 -1
  89. package/dist/default.js +9 -9
  90. package/dist/default.js.map +2 -2
  91. package/dist/default.js.zyzz.json +1 -1
  92. package/dist/internal/Authoring.d.ts.map +1 -1
  93. package/dist/internal/Authoring.js +8 -3
  94. package/dist/internal/Authoring.js.map +1 -1
  95. package/dist/internal/Binding.d.ts +4 -0
  96. package/dist/internal/Binding.d.ts.map +1 -1
  97. package/dist/internal/Binding.js +2 -0
  98. package/dist/internal/Binding.js.map +1 -1
  99. package/dist/internal/Completion.d.ts +1 -1
  100. package/dist/internal/Completion.d.ts.map +1 -1
  101. package/dist/internal/Configuration.d.ts +2 -2
  102. package/dist/internal/Configuration.d.ts.map +1 -1
  103. package/dist/internal/Configuration.js +4 -2
  104. package/dist/internal/Configuration.js.map +1 -1
  105. package/dist/internal/Identity.d.ts +3 -3
  106. package/dist/internal/Identity.d.ts.map +1 -1
  107. package/dist/internal/Identity.js +11 -9
  108. package/dist/internal/Identity.js.map +1 -1
  109. package/dist/internal/Targets.d.ts.map +1 -1
  110. package/dist/internal/Targets.js +2 -0
  111. package/dist/internal/Targets.js.map +1 -1
  112. package/dist/internal/Theme.js +2 -2
  113. package/dist/internal/Theme.js.map +1 -1
  114. package/dist/internal/Token.d.ts +3 -1
  115. package/dist/internal/Token.d.ts.map +1 -1
  116. package/dist/internal/Token.js +9 -2
  117. package/dist/internal/Token.js.map +1 -1
  118. package/dist/internal/Value.d.ts +7 -0
  119. package/dist/internal/Value.d.ts.map +1 -1
  120. package/dist/internal/Value.js.map +1 -1
  121. package/dist/internal/VariableSets.js +1 -1
  122. package/dist/internal/VariableSets.js.map +1 -1
  123. package/dist/metro/Graph.d.ts +22 -7
  124. package/dist/metro/Graph.d.ts.map +1 -1
  125. package/dist/metro/Graph.js +179 -42
  126. package/dist/metro/Graph.js.map +1 -1
  127. package/dist/metro/Watch.d.ts +28 -4
  128. package/dist/metro/Watch.d.ts.map +1 -1
  129. package/dist/metro/Watch.js +39 -7
  130. package/dist/metro/Watch.js.map +1 -1
  131. package/dist/metro/index.d.ts +15 -4
  132. package/dist/metro/index.d.ts.map +1 -1
  133. package/dist/metro/index.js +27 -0
  134. package/dist/metro/index.js.map +1 -1
  135. package/dist/metro/transformer.d.ts +5 -1
  136. package/dist/metro/transformer.d.ts.map +1 -1
  137. package/dist/metro/transformer.js +5 -3
  138. package/dist/metro/transformer.js.map +1 -1
  139. package/dist/node/Host.d.ts.map +1 -1
  140. package/dist/node/Host.js +2 -0
  141. package/dist/node/Host.js.map +1 -1
  142. package/dist/react-native/StyleSheet.d.ts +3 -2
  143. package/dist/react-native/StyleSheet.d.ts.map +1 -1
  144. package/dist/react-native/StyleSheet.js +17 -34
  145. package/dist/react-native/StyleSheet.js.map +1 -1
  146. package/dist/react-native/index.d.ts +1 -1
  147. package/dist/react-native/index.d.ts.map +1 -1
  148. package/dist/react-native/index.js +1 -1
  149. package/dist/react-native/index.js.map +1 -1
  150. package/dist/react-native/index.native.d.ts +5 -0
  151. package/dist/react-native/index.native.js +20 -0
  152. package/dist/react-native/index.native.js.map +7 -0
  153. package/dist/react-native/internal/Calculation.d.ts +7 -0
  154. package/dist/react-native/internal/Calculation.d.ts.map +1 -0
  155. package/dist/react-native/internal/Calculation.js +134 -0
  156. package/dist/react-native/internal/Calculation.js.map +1 -0
  157. package/dist/react-native/internal/Device.js +191 -0
  158. package/dist/react-native/internal/Device.js.map +7 -0
  159. package/dist/react-native/internal/NativeZyzz.js +7 -0
  160. package/dist/react-native/internal/NativeZyzz.js.map +7 -0
  161. package/dist/react-native/internal/Scalar.d.ts.map +1 -1
  162. package/dist/react-native/internal/Scalar.js +9 -2
  163. package/dist/react-native/internal/Scalar.js.map +1 -1
  164. package/dist/react-native/internal/Store.d.ts +32 -0
  165. package/dist/react-native/internal/Store.d.ts.map +1 -0
  166. package/dist/react-native/internal/Store.js +57 -0
  167. package/dist/react-native/internal/Store.js.map +1 -0
  168. package/dist/react-native/internal/Tokens.d.ts +21 -0
  169. package/dist/react-native/internal/Tokens.d.ts.map +1 -0
  170. package/dist/react-native/internal/Tokens.js +58 -0
  171. package/dist/react-native/internal/Tokens.js.map +1 -0
  172. package/dist/react-native/internal/Viewport.d.ts +6 -0
  173. package/dist/react-native/internal/Viewport.d.ts.map +1 -0
  174. package/dist/react-native/internal/Viewport.js +4 -0
  175. package/dist/react-native/internal/Viewport.js.map +1 -0
  176. package/dist/react-native/react.d.ts +74 -11
  177. package/dist/react-native/react.d.ts.map +1 -1
  178. package/dist/react-native/react.js +111 -12
  179. package/dist/react-native/react.js.map +1 -1
  180. package/dist/react-native/reanimated.d.ts +39 -0
  181. package/dist/react-native/reanimated.d.ts.map +1 -0
  182. package/dist/react-native/reanimated.js +76 -0
  183. package/dist/react-native/reanimated.js.map +1 -0
  184. package/dist/runtime/NativeContext.d.ts +10 -1
  185. package/dist/runtime/NativeContext.d.ts.map +1 -1
  186. package/dist/runtime/NativeContext.js +67 -14
  187. package/dist/runtime/NativeContext.js.map +1 -1
  188. package/dist/runtime/NativeDynamic.d.ts +3 -2
  189. package/dist/runtime/NativeDynamic.d.ts.map +1 -1
  190. package/dist/runtime/NativeDynamic.js +32 -7
  191. package/dist/runtime/NativeDynamic.js.map +1 -1
  192. package/dist/runtime/NativeStatic.d.ts +23 -0
  193. package/dist/runtime/NativeStatic.d.ts.map +1 -0
  194. package/dist/runtime/NativeStatic.js +106 -0
  195. package/dist/runtime/NativeStatic.js.map +1 -0
  196. package/dist/runtime/NativeVars.d.ts +53 -0
  197. package/dist/runtime/NativeVars.d.ts.map +1 -0
  198. package/dist/runtime/NativeVars.js +77 -0
  199. package/dist/runtime/NativeVars.js.map +1 -0
  200. package/dist/runtime/index.d.ts +4 -0
  201. package/dist/runtime/index.d.ts.map +1 -1
  202. package/dist/runtime/index.js +4 -0
  203. package/dist/runtime/index.js.map +1 -1
  204. package/dist/runtime/internal/NativeMedia.d.ts +25 -0
  205. package/dist/runtime/internal/NativeMedia.d.ts.map +1 -0
  206. package/dist/runtime/internal/NativeMedia.js +36 -0
  207. package/dist/runtime/internal/NativeMedia.js.map +1 -0
  208. package/dist/variable.js +1 -1
  209. package/dist/variable.js.map +1 -1
  210. package/dist/vite/index.d.ts.map +1 -1
  211. package/dist/vite/index.js +43 -47
  212. package/dist/vite/index.js.map +1 -1
  213. package/dist/web/Css.d.ts +7 -2
  214. package/dist/web/Css.d.ts.map +1 -1
  215. package/dist/web/Css.js +76 -57
  216. package/dist/web/Css.js.map +1 -1
  217. package/dist/web/internal/ClassName.d.ts +13 -2
  218. package/dist/web/internal/ClassName.d.ts.map +1 -1
  219. package/dist/web/internal/ClassName.js +17 -30
  220. package/dist/web/internal/ClassName.js.map +1 -1
  221. package/dist/web/internal/Themes.d.ts +3 -2
  222. package/dist/web/internal/Themes.d.ts.map +1 -1
  223. package/dist/web/internal/Themes.js +54 -28
  224. package/dist/web/internal/Themes.js.map +1 -1
  225. package/dist/web/page.d.ts +2 -0
  226. package/dist/web/page.d.ts.map +1 -1
  227. package/native/NativeZyzz.cpp +215 -0
  228. package/native/NativeZyzz.h +52 -0
  229. package/native/ZyzzSpecJSI.h +65 -0
  230. package/native/android/CMakeLists.txt +8 -0
  231. package/native/android/ZyzzSpec-generated.cpp +50 -0
  232. package/native/android/ZyzzSpec.h +31 -0
  233. package/native/ios/ZyzzModuleProvider.mm +13 -0
  234. package/package.json +39 -1
  235. package/react-native.config.ts +14 -0
  236. package/src/Style.ts +15 -9
  237. package/src/babel/NativeJsx.ts +305 -28
  238. package/src/babel/index.ts +21 -3
  239. package/src/compiler/Graph.ts +135 -46
  240. package/src/compiler/Native.ts +158 -26
  241. package/src/compiler/Source.ts +115 -10
  242. package/src/compiler/Transform.ts +42 -60
  243. package/src/compiler/internal/Catalogs.ts +9 -1
  244. package/src/compiler/internal/Compositions.ts +7 -0
  245. package/src/compiler/internal/Configurations.ts +27 -4
  246. package/src/compiler/internal/Contract.ts +130 -260
  247. package/src/compiler/internal/Contributions.ts +8 -6
  248. package/src/compiler/internal/Descriptors.ts +12 -8
  249. package/src/compiler/internal/Dynamic.ts +14 -9
  250. package/src/compiler/internal/Names.ts +48 -0
  251. package/src/compiler/internal/NativeBindings.ts +98 -15
  252. package/src/compiler/internal/NativeMedia.ts +342 -0
  253. package/src/compiler/internal/NativeVars.ts +228 -0
  254. package/src/compiler/internal/PackedStyles.ts +4 -0
  255. package/src/compiler/internal/Selectors.ts +6 -1
  256. package/src/compiler/internal/Stylesheets.ts +2 -2
  257. package/src/compiler/internal/Themes.ts +193 -3
  258. package/src/compiler/internal/Vars.ts +21 -2
  259. package/src/default.ts +9 -10
  260. package/src/internal/Authoring.ts +8 -2
  261. package/src/internal/Binding.ts +5 -0
  262. package/src/internal/Completion.ts +6 -3
  263. package/src/internal/Configuration.ts +7 -4
  264. package/src/internal/Identity.ts +14 -12
  265. package/src/internal/Targets.ts +2 -0
  266. package/src/internal/Theme.ts +2 -2
  267. package/src/internal/Token.ts +11 -1
  268. package/src/internal/Value.ts +20 -0
  269. package/src/internal/VariableSets.ts +1 -1
  270. package/src/metro/Graph.ts +235 -50
  271. package/src/metro/Watch.ts +95 -10
  272. package/src/metro/index.ts +62 -4
  273. package/src/metro/transformer.ts +21 -11
  274. package/src/node/Host.ts +3 -0
  275. package/src/react-native/StyleSheet.ts +28 -44
  276. package/src/react-native/index.native.ts +10 -0
  277. package/src/react-native/index.ts +1 -1
  278. package/src/react-native/internal/Calculation.ts +159 -0
  279. package/src/react-native/internal/Device.ts +231 -0
  280. package/src/react-native/internal/NativeZyzz.ts +20 -0
  281. package/src/react-native/internal/Scalar.ts +13 -2
  282. package/src/react-native/internal/Store.ts +78 -0
  283. package/src/react-native/internal/Tokens.ts +85 -0
  284. package/src/react-native/internal/Viewport.ts +8 -0
  285. package/src/react-native/react.ts +211 -19
  286. package/src/react-native/reanimated.ts +162 -0
  287. package/src/runtime/NativeContext.ts +88 -17
  288. package/src/runtime/NativeDynamic.ts +35 -10
  289. package/src/runtime/NativeStatic.ts +145 -0
  290. package/src/runtime/NativeVars.ts +189 -0
  291. package/src/runtime/index.ts +6 -0
  292. package/src/runtime/internal/NativeMedia.ts +63 -0
  293. package/src/variable.ts +1 -1
  294. package/src/vite/index.ts +52 -60
  295. package/src/web/Css.ts +123 -74
  296. package/src/web/internal/ClassName.ts +31 -36
  297. package/src/web/internal/Themes.ts +62 -39
  298. package/src/web/page.ts +2 -0
@@ -26,7 +26,7 @@ export function read(
26
26
  if (
27
27
  ![
28
28
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
29
- 22, 23, 24, 25, 26, 27, 28, 29,
29
+ 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33,
30
30
  ].includes(data.version as number)
31
31
  )
32
32
  throw new Error('Unsupported Zyzz contract version.')
@@ -58,6 +58,13 @@ export function read(
58
58
  for (const entry of Object.values(record(data.exports))) collect(entry)
59
59
  }
60
60
 
61
+ function validateVariables(entry: Record<string, unknown>) {
62
+ if ((data.version as number) < 31 || entry.variableNaming !== undefined)
63
+ throw new Error(
64
+ 'Legacy packed variable names are unsupported. Rebuild the library with the current version of Zyzz.',
65
+ )
66
+ }
67
+
61
68
  function decode(value: unknown): unknown {
62
69
  if (!value || typeof value !== 'object') return value
63
70
  if (Array.isArray(value)) return value.map(decode)
@@ -92,6 +99,7 @@ export function read(
92
99
  if (Object.hasOwn(fields, '$variable')) {
93
100
  const reference = record(fields.$variable)
94
101
  const identity = string(reference.identity)
102
+ validateVariables(reference)
95
103
  let contract = identities.get(identity)
96
104
  if (contract && !contract.variableSet)
97
105
  throw new Error(
@@ -122,6 +130,11 @@ export function read(
122
130
  for (const [name, value] of Object.entries(record(data.themes))) {
123
131
  const entry = record(value)
124
132
  const identity = string(entry.identity)
133
+ if (
134
+ Object.keys(record(entry.tokens)).length ||
135
+ entry.variableNaming !== undefined
136
+ )
137
+ validateVariables(entry)
125
138
  if (entry.variableSet === true && (data.version as number) < 28)
126
139
  throw new Error('Vars contracts require contract version 28 or later.')
127
140
  const mappings = VariableSets.mappings(entry.mappings)
@@ -223,12 +236,18 @@ export function read(
223
236
  'Packed responsive typography and border widths require contract version 25 or later.',
224
237
  )
225
238
 
226
- themes[name] = Token.bind(definition, contract)
239
+ themes[name] = Token.bind(
240
+ definition,
241
+ contract,
242
+ entry.cssName === undefined ? undefined : string(entry.cssName),
243
+ )
227
244
  types[name] = type(input(definition))
228
245
  }
229
246
 
230
247
  function link(value: unknown): Themes.Link {
231
248
  const raw = record(value)
249
+ if (raw.nativeProvider !== undefined && (data.version as number) < 32)
250
+ throw new Error('Native providers require contract version 32 or later.')
232
251
  // Contracts before version 19 record style authoring exports as `css`.
233
252
  const entry =
234
253
  raw.kind === 'css' && (data.version as number) < 19
@@ -249,7 +268,7 @@ export function read(
249
268
  key === 'set' ||
250
269
  key === '__proto__' ||
251
270
  names.has(string(slot.name)) ||
252
- !/^--z-v[a-z0-9-]+$/.test(string(slot.name)) ||
271
+ !/^--z-[a-zA-Z0-9_-]+$/.test(string(slot.name)) ||
253
272
  ![
254
273
  '*',
255
274
  'color',
@@ -314,7 +333,7 @@ export function read(
314
333
  if (
315
334
  ![
316
335
  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
317
- 27, 28, 29,
336
+ 27, 28, 29, 30, 31, 32, 33,
318
337
  ].includes(data.version as number) ||
319
338
  ![
320
339
  'cssFunction',
@@ -324,7 +343,7 @@ export function read(
324
343
  'fontPaletteValues',
325
344
  'positionTry',
326
345
  ].includes(reference) ||
327
- !/^(?:--)?z-[a-z0-9-]+$/.test(name) ||
346
+ !/^(?:--)?z-[a-zA-Z0-9_-]+$/.test(name) ||
328
347
  !name.startsWith(
329
348
  `${reference === 'counterStyle' ? '' : '--'}z-${reference.toLowerCase()}`,
330
349
  ) ||
@@ -350,7 +369,7 @@ export function read(
350
369
 
351
370
  if (entry.kind === 'animation') {
352
371
  const name = string(entry.name)
353
- if (!/^z-k[a-z0-9-]+$/.test(name))
372
+ if (!/^z-k[a-zA-Z0-9_-]+$/.test(name))
354
373
  throw new Error('Invalid animation identity.')
355
374
 
356
375
  return {
@@ -367,7 +386,7 @@ export function read(
367
386
  'Packed callable styles require contract version 16 or later.',
368
387
  )
369
388
  const binding = string(entry.binding)
370
- if (!/^z-style-[a-z0-9_-]+$/.test(binding))
389
+ if (!/^z-style-[a-zA-Z0-9_-]+$/.test(binding))
371
390
  throw new Error('Invalid style reference identity.')
372
391
  const members =
373
392
  entry.members === undefined
@@ -383,6 +402,34 @@ export function read(
383
402
  return [key, member]
384
403
  }),
385
404
  )
405
+ const nativeContext = (() => {
406
+ if (entry.nativeContext === undefined) return undefined
407
+ if ((data.version as number) < 33)
408
+ throw new Error(
409
+ 'Native style catalogs require contract version 33 or later.',
410
+ )
411
+ if (entry.style === undefined)
412
+ throw new Error('Native style catalogs require a packed style.')
413
+ const context = record(entry.nativeContext)
414
+ const vars = Object.fromEntries(
415
+ Object.entries(record(context.vars)).map((entry) => {
416
+ const [name, value] = entry
417
+ const theme = themes[string(value)]
418
+ if (!name || !theme)
419
+ throw new Error('Unknown packed native style catalog.')
420
+ return [name, theme]
421
+ }),
422
+ )
423
+ const defaultVars = string(context.defaultVars)
424
+ if (!Object.hasOwn(vars, defaultVars))
425
+ throw new Error('Invalid packed native style default.')
426
+ const identities = new Set(
427
+ Object.values(vars).map((theme) => theme[Token.definition].contract),
428
+ )
429
+ if (identities.size !== 1)
430
+ throw new Error('Incompatible packed native style catalog.')
431
+ return { defaultVars, vars }
432
+ })()
386
433
  return {
387
434
  binding,
388
435
  call: {
@@ -396,11 +443,14 @@ export function read(
396
443
  ...(entry.style === undefined
397
444
  ? {}
398
445
  : {
399
- style: PackedStyles.read(
400
- entry.style,
401
- themes,
402
- data.version as number,
403
- ),
446
+ style: {
447
+ ...PackedStyles.read(
448
+ entry.style,
449
+ themes,
450
+ data.version as number,
451
+ ),
452
+ ...(nativeContext ? { nativeContext } : {}),
453
+ },
404
454
  }),
405
455
  ...(members ? { members } : {}),
406
456
  }
@@ -485,9 +535,11 @@ export function read(
485
535
  !!options?.themes &&
486
536
  ((data.version as number) < 4 || entry.catalogOnly === true)
487
537
  const fullConfigType = options
488
- ? entry.variableConfig === true
489
- ? `import('zyzz').Config.VariableConfig<${Configurations.type(variableOptions(options, entry.variableMappings as Vars.Mappings | false | undefined))}>`
490
- : `import('zyzz').Config.create.ReturnType<${Configurations.type(options)}>`
538
+ ? entry.nativeProvider === true
539
+ ? `import('zyzz/react-native/react').defineConfig.ReturnType<${Configurations.type(entry.variableConfig === true ? variableOptions(options, entry.variableMappings as Vars.Mappings | false | undefined) : options)}>`
540
+ : entry.variableConfig === true
541
+ ? `import('zyzz').Config.VariableConfig<${Configurations.type(variableOptions(options, entry.variableMappings as Vars.Mappings | false | undefined))}>`
542
+ : `import('zyzz').Config.create.ReturnType<${Configurations.type(options)}>`
491
543
  : ''
492
544
  // Helpers a legacy library did not compile are hidden from its consumers' types.
493
545
  const hidden = [
@@ -506,6 +558,7 @@ export function read(
506
558
  return {
507
559
  binding: string(entry.binding),
508
560
  call: {
561
+ ...(entry.nativeProvider === true ? { nativeProvider: true } : {}),
509
562
  ...(entry.variableSet === true
510
563
  ? {
511
564
  variableSet: true,
@@ -577,7 +630,22 @@ export function read(
577
630
  ]),
578
631
  )
579
632
 
580
- return { links, themes, stylesheets: Stylesheets.read(data.stylesheets) }
633
+ const classRules = Object.fromEntries(
634
+ Object.entries(
635
+ data.classRules === undefined ? {} : record(data.classRules),
636
+ ).map(([name, body]) => {
637
+ if (!name || /\s/.test(name))
638
+ throw new Error('Invalid packed class name.')
639
+ return [name, string(body)]
640
+ }),
641
+ )
642
+
643
+ return {
644
+ classRules,
645
+ links,
646
+ themes,
647
+ stylesheets: Stylesheets.read(data.stylesheets),
648
+ }
581
649
  }
582
650
 
583
651
  function record(value: unknown): Record<string, unknown> {
@@ -627,6 +695,7 @@ export function write(
627
695
  stylesheets: readonly Stylesheets.Section[] = [],
628
696
  moduleId = '',
629
697
  configurations: readonly write.Configuration[] = [],
698
+ classRules: Readonly<Record<string, string>> = {},
630
699
  ): string {
631
700
  function entry(link: Themes.Link): Record<string, unknown> {
632
701
  if (link.kind === 'variables')
@@ -664,6 +733,28 @@ export function write(
664
733
  return {
665
734
  binding: link.binding,
666
735
  kind: link.kind,
736
+ ...(link.style?.nativeContext
737
+ ? {
738
+ nativeContext: {
739
+ defaultVars: link.style.nativeContext.defaultVars,
740
+ vars: Object.fromEntries(
741
+ Object.entries(link.style.nativeContext.vars).map((entry) => {
742
+ const [name, definition] = entry
743
+ const theme = Object.entries(themes).find(
744
+ (candidate) =>
745
+ candidate[1][Token.definition].contract ===
746
+ definition[Token.definition].contract &&
747
+ JSON.stringify(input(candidate[1])) ===
748
+ JSON.stringify(input(definition)),
749
+ )
750
+ if (!theme)
751
+ throw new Error('Missing packed native style catalog.')
752
+ return [name, theme[0]]
753
+ }),
754
+ ),
755
+ },
756
+ }
757
+ : {}),
667
758
  ...(link.style ? { style: PackedStyles.write(link.style) } : {}),
668
759
  ...(link.members
669
760
  ? {
@@ -679,6 +770,7 @@ export function write(
679
770
 
680
771
  return {
681
772
  ...(link.call.variableSet ? { variableSet: true } : {}),
773
+ ...(link.call.nativeProvider ? { nativeProvider: true } : {}),
682
774
  ...(link.call.directVariables ? { directVariables: true } : {}),
683
775
  ...(link.call.variableConfig
684
776
  ? { variableConfig: true, variableMappings: link.call.variableMappings }
@@ -714,6 +806,7 @@ export function write(
714
806
  }
715
807
 
716
808
  return JSON.stringify({
809
+ ...(Object.keys(classRules).length ? { classRules } : {}),
717
810
  ...(stylesheets.length
718
811
  ? { stylesheets: Stylesheets.write(stylesheets) }
719
812
  : {}),
@@ -727,6 +820,9 @@ export function write(
727
820
  Object.entries(themes).map(([name, theme]) => [
728
821
  name,
729
822
  {
823
+ ...(theme[Token.definition].cssName !== undefined
824
+ ? { cssName: theme[Token.definition].cssName }
825
+ : {}),
730
826
  ...(theme[Token.definition].contract.shorthands
731
827
  ? { shorthands: theme[Token.definition].contract.shorthands }
732
828
  : {}),
@@ -747,243 +843,26 @@ export function write(
747
843
  },
748
844
  ]),
749
845
  ),
750
- version: (() => {
751
- function composed(value: unknown): boolean {
752
- if (Token.isExpression(value)) return true
753
- if (Token.is(value)) return composed(value.value)
754
- return (
755
- !!value &&
756
- typeof value === 'object' &&
757
- Object.values(value).some(composed)
758
- )
759
- }
760
- if (
761
- Object.values(themes).some((theme) =>
762
- composed(theme[Token.definition].values),
763
- )
764
- )
765
- return 29
766
-
767
- if (
768
- Object.values(themes).some(
769
- (theme) =>
770
- theme[Token.definition].contract.variableSet ||
771
- theme[Token.definition].queries,
772
- )
773
- )
774
- return 28
775
-
776
- if (
777
- Object.values(themes).some(
778
- (theme) =>
779
- theme[Token.definition].contract.defaultLayer !== undefined,
780
- )
781
- )
782
- return 27
783
- if (
784
- Object.values(themes).some(
785
- (theme) =>
786
- theme[Token.definition].paths ||
787
- Object.hasOwn(theme.tokens, 'borderWidth'),
788
- )
789
- )
790
- return 25
791
-
792
- if (
793
- Object.values(themes).some((theme) =>
794
- Object.hasOwn(theme.tokens, 'typography'),
795
- )
796
- )
797
- return 24
798
-
799
- function callable(link: Themes.Link): boolean {
800
- return !!link.style || Object.values(link.members ?? {}).some(callable)
801
- }
802
- function styled(link: Themes.Link): boolean {
803
- return (
804
- link.kind === 'style' ||
805
- Object.values(link.members ?? {}).some(styled)
806
- )
807
- }
808
- function branches(style: import('../../Style.js').NamedStyle): boolean {
809
- return (
810
- !!style.targets || !!style.rules?.some((rule) => branches(rule.style))
811
- )
812
- }
813
- function targeted(link: Themes.Link): boolean {
814
- return (
815
- (link.style && branches(link.style.style)) ||
816
- Object.values(link.members ?? {}).some(targeted)
817
- )
818
- }
819
- function staticRecipe(link: Themes.Link): boolean {
820
- return (
821
- !!link.style?.staticRecipe ||
822
- Object.values(link.members ?? {}).some(staticRecipe)
823
- )
824
- }
825
- function nested(link: Themes.Link): boolean {
826
- return Object.values(link.members ?? {}).some(
827
- (member) =>
828
- (link.kind === 'style-reference' && !!member.members) ||
829
- nested(member),
830
- )
831
- }
832
- function dynamic(link: Themes.Link): boolean {
833
- return (
834
- !!link.style?.dynamic ||
835
- Object.values(link.members ?? {}).some(dynamic)
836
- )
837
- }
838
- if (Object.values(links).some(dynamic)) return 23
839
- if (Object.values(links).some(nested)) return 22
840
- if (Object.values(links).some(staticRecipe)) return 21
841
- if (Object.values(links).some(targeted)) return 20
842
- // Style authoring exports serialize as `style`; older readers only know `css`.
843
- if (Object.values(links).some(styled)) return 19
844
- // Root controls call a runtime helper older releases lack, and older
845
- // readers reject the storageKey option, so both require readers to opt in.
846
- // Local configurations emit the same helper without an exported binding.
847
- if (
848
- configurations.length ||
849
- Object.values(links).some(
850
- (link) =>
851
- (link.call.appearance &&
852
- (link.kind === 'config' || link.call.root)) ||
853
- link.call.options?.storageKey !== undefined,
854
- )
855
- )
856
- return 18
857
- if (
858
- Object.values(links).some(callable) ||
859
- Object.values(themes).some(
860
- (theme) => theme[Token.definition].contract.cssOutput,
861
- )
862
- )
863
- return 17
864
- if (Object.values(links).some((link) => link.call.recipe)) return 15
865
- if (Object.values(links).some((link) => link.kind === 'variables'))
866
- return 14
867
- if (Object.values(links).some((link) => link.kind === 'style-reference'))
868
- return 13
869
-
870
- if (
871
- Object.values(links).some(
872
- (link) => link.call.function && extended(link.call.function),
873
- )
874
- )
875
- return 12
876
-
877
- if (
878
- stylesheets.some((section) => section.namespaces?.length) ||
879
- Object.values(links).some(
880
- (link) =>
881
- link.call.function &&
882
- [
883
- link.call.function.returns,
884
- ...link.call.function.parameters.map(
885
- (parameter) => parameter.syntax ?? '*',
886
- ),
887
- ].some(
888
- (syntax) =>
889
- // Version 10 readers accepted this fixed scalar subset.
890
- !(
891
- [
892
- '*',
893
- '<angle>',
894
- '<color>',
895
- '<integer>',
896
- '<length>',
897
- '<length-percentage>',
898
- '<number>',
899
- '<percentage>',
900
- '<time>',
901
- ] as readonly string[]
902
- ).includes(syntax),
903
- ),
904
- )
905
- )
906
- return 11
907
-
908
- if (
909
- Object.values(links).some(
910
- (link) =>
911
- link.call.reference === 'cssFunction' ||
912
- link.call.reference === 'customMedia',
913
- )
914
- )
915
- return 10
916
-
917
- if (Object.values(links).some((link) => link.kind === 'rule-reference'))
918
- return 9
919
-
920
- if (Object.values(links).some((link) => link.kind === 'variables'))
921
- return 8
922
-
923
- if (
924
- stylesheets.length ||
925
- Object.values(links).some((link) => link.kind === 'animation')
926
- )
927
- return 7
928
-
929
- if (
930
- Object.values(themes).some(
931
- (theme) =>
932
- theme[Token.definition].contract.shorthands ||
933
- Object.hasOwn(theme.tokens, 'margin') ||
934
- Object.hasOwn(theme.tokens, 'padding'),
935
- ) ||
936
- Object.values(links).some(
937
- (link) =>
938
- link.call.output === 'html' ||
939
- Object.values(link.members ?? {}).some(
940
- (member) => member.call.output === 'html',
941
- ),
942
- )
943
- )
944
- return 5
945
-
946
- if (
947
- stylesheets.length ||
948
- Object.values(links).some(
949
- (link) =>
950
- link.call.selection ||
951
- (link.kind === 'config' && !!link.call.options?.themes) ||
952
- link.call.initialization ||
953
- (link.kind === 'config' && link.call.script) ||
954
- link.kind === 'animation' ||
955
- link.kind === 'variables',
956
- )
957
- )
958
- return 4
959
-
960
- if (
961
- Object.values(themes).some(
962
- (theme) =>
963
- theme[Token.definition].queries ||
964
- Object.keys(theme.tokens).some((group) =>
965
- [
966
- 'fontFamily',
967
- 'fontSize',
968
- 'fontWeight',
969
- 'lineHeight',
970
- 'letterSpacing',
971
- ].includes(group),
972
- ),
973
- )
974
- )
975
- return 3
846
+ version: Object.values(links).some(nativeCatalog)
847
+ ? 33
848
+ : Object.values(links).some(nativeProvider)
849
+ ? 32
850
+ : 31,
851
+ })
976
852
 
977
- if (
978
- Object.values(links).some(
979
- (link) => link.kind === 'config' || link.call.type,
980
- )
981
- )
982
- return 2
853
+ function nativeProvider(link: Themes.Link): boolean {
854
+ return (
855
+ link.call.nativeProvider === true ||
856
+ Object.values(link.members ?? {}).some(nativeProvider)
857
+ )
858
+ }
983
859
 
984
- return 1
985
- })(),
986
- })
860
+ function nativeCatalog(link: Themes.Link): boolean {
861
+ return (
862
+ Boolean(link.style?.nativeContext) ||
863
+ Object.values(link.members ?? {}).some(nativeCatalog)
864
+ )
865
+ }
987
866
  }
988
867
 
989
868
  /** Contract writer contracts. */
@@ -1058,15 +937,6 @@ function signature(
1058
937
  }
1059
938
  }
1060
939
 
1061
- function extended(signature: NonNullable<Themes.Call['function']>): boolean {
1062
- return (
1063
- /[\\\u0080-\uffff]/.test(signature.returns) ||
1064
- signature.parameters.some((parameter) =>
1065
- /[\\\u0080-\uffff]/.test(parameter.name + (parameter.syntax ?? '*')),
1066
- )
1067
- )
1068
- }
1069
-
1070
940
  function encode(value: unknown): unknown {
1071
941
  if (Token.isExpression(value) && 'group' in value)
1072
942
  return {
@@ -286,11 +286,7 @@ export function scan(
286
286
  explicit !== undefined
287
287
  ? Identity.contribution(type, explicit)
288
288
  : variable?.id.type === 'Identifier'
289
- ? `${type === 'keyframes' ? 'z-k' : `${type === 'counterStyle' ? '' : '--'}z-${type.toLowerCase()}`}${namespace}-${Array.from(
290
- variable.id.name,
291
- )
292
- .map((value) => value.codePointAt(0)!.toString(16))
293
- .join('-')}`
289
+ ? `${type === 'keyframes' ? 'z-k-' : `${type === 'counterStyle' ? '' : '--'}z-${type.toLowerCase()}-`}${Identity.name(variable.id.name)}`
294
290
  : undefined
295
291
 
296
292
  const call: Call = {
@@ -1029,7 +1025,13 @@ export function extract(
1029
1025
  ]
1030
1026
  if (
1031
1027
  !margin &&
1032
- ['bleed', 'marks', 'pageOrientation', 'size'].includes(key)
1028
+ [
1029
+ 'bleed',
1030
+ 'marks',
1031
+ 'pageMarginSafety',
1032
+ 'pageOrientation',
1033
+ 'size',
1034
+ ].includes(key)
1033
1035
  ) {
1034
1036
  if (typeof value !== 'string' && typeof value !== 'number')
1035
1037
  throw new Error('Expected a scalar page descriptor.')
@@ -8,11 +8,11 @@ export function check(options: check.Options): void {
8
8
  /[A-Z]/g,
9
9
  (letter) => `-${letter.toLowerCase()}`,
10
10
  )
11
- const result = Tree.lexer.matchAtruleDescriptor(
12
- options.rule,
13
- name,
14
- options.value,
15
- )
11
+ // The pinned parser predates this page descriptor.
12
+ const result =
13
+ options.rule === 'page' && name === 'page-margin-safety'
14
+ ? Tree.lexer.match('none | clamp | add', options.value)
15
+ : Tree.lexer.matchAtruleDescriptor(options.rule, name, options.value)
16
16
  if (result.error)
17
17
  throw new Error(`Invalid @${options.rule} ${name}: ${result.error.message}`)
18
18
  if (
@@ -102,9 +102,13 @@ export function validate(source: string): void {
102
102
  rule.block.children.forEach((declaration) => {
103
103
  if (declaration.type !== 'Declaration') return
104
104
  if (
105
- ['bleed', 'marks', 'page-orientation', 'size'].includes(
106
- declaration.property,
107
- )
105
+ [
106
+ 'bleed',
107
+ 'marks',
108
+ 'page-margin-safety',
109
+ 'page-orientation',
110
+ 'size',
111
+ ].includes(declaration.property)
108
112
  )
109
113
  check({
110
114
  rule: 'page',
@@ -1,6 +1,7 @@
1
1
  /** Extracts typed callback slots and static object bodies without invoking callbacks. @module */
2
2
  import type * as Ast from '@oxc-project/types'
3
- import type * as Binding from '../../internal/Binding.js'
3
+ import * as Binding from '../../internal/Binding.js'
4
+ import * as Identity from '../../internal/Identity.js'
4
5
  import * as Expression from './Expression.js'
5
6
  import * as Literal from '../../internal/Literal.js'
6
7
  import * as Themes from './Themes.js'
@@ -82,14 +83,18 @@ export function read(
82
83
  member,
83
84
  )
84
85
 
85
- const slot = (slots[key] = Object.freeze({
86
- name: `--z-d${identity}-${Array.from(key)
87
- .map((character) => character.codePointAt(0)!.toString(16))
88
- .join('-')}`,
89
- type: kind === 'number' ? 'number' : 'length',
90
- ...(kind === 'zero-string' ? { zero: true } : {}),
91
- variable: true,
92
- }))
86
+ const slot = (slots[key] = Object.freeze(
87
+ Object.defineProperty(
88
+ {
89
+ name: Identity.slot(identity, key),
90
+ type: kind === 'number' ? ('number' as const) : ('length' as const),
91
+ ...(kind === 'zero-string' ? { zero: true } : {}),
92
+ variable: true as const,
93
+ },
94
+ Binding.dynamic,
95
+ { value: true },
96
+ ),
97
+ ))
93
98
 
94
99
  const values = numbers(type)
95
100
 
@@ -0,0 +1,48 @@
1
+ /** Derives emitted names from authored bindings rather than source locations. @module */
2
+ import type * as Ast from '@oxc-project/types'
3
+ import * as Walker from 'oxc-walker'
4
+ import * as Identity from '../../internal/Identity.js'
5
+
6
+ /** Collects readable declaration paths for calls in constants and namespaces. */
7
+ export function collect(program: Ast.Program): ReadonlyMap<number, string> {
8
+ const names = new Map<number, string>()
9
+ const ancestors: Ast.Node[] = []
10
+
11
+ Walker.walk(program, {
12
+ enter(node) {
13
+ if (node.type === 'CallExpression') {
14
+ const parts: string[] = []
15
+ for (const ancestor of ancestors) {
16
+ if (
17
+ ancestor.type === 'TSModuleDeclaration' &&
18
+ ancestor.id.type === 'Identifier'
19
+ )
20
+ parts.push(ancestor.id.name)
21
+ if (
22
+ ancestor.type === 'VariableDeclarator' &&
23
+ ancestor.id.type === 'Identifier'
24
+ )
25
+ parts.push(ancestor.id.name)
26
+ if (ancestor.type === 'Property' && !ancestor.computed) {
27
+ if (ancestor.key.type === 'Identifier')
28
+ parts.push(ancestor.key.name)
29
+ else if (ancestor.key.type === 'Literal')
30
+ parts.push(String(ancestor.key.value))
31
+ }
32
+ if (ancestor.type === 'FunctionDeclaration' && ancestor.id)
33
+ parts.push(ancestor.id.name)
34
+ }
35
+ names.set(
36
+ node.start,
37
+ parts.length ? parts.map(Identity.name).join('-') : 'style',
38
+ )
39
+ }
40
+ ancestors.push(node)
41
+ },
42
+ leave() {
43
+ ancestors.pop()
44
+ },
45
+ })
46
+
47
+ return names
48
+ }