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
@@ -32,6 +32,8 @@ 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 Literal from '../internal/Literal.js'
35
+ import * as Names from './internal/Names.js'
36
+ import * as ClassName from '../web/internal/ClassName.js'
35
37
  import * as Typography from '../internal/Typography.js'
36
38
  import * as Value from '../internal/Value.js'
37
39
  import * as Vars from './internal/Vars.js'
@@ -57,6 +59,10 @@ export type Call = {
57
59
  | undefined
58
60
  /** Class identity available without source rewriting. */
59
61
  readonly portable?: string | undefined
62
+ /** Readable authored binding used for contextual CSS names. */
63
+ readonly cssName?: string | undefined
64
+ /** Explicit configuration namespace for emitted CSS. */
65
+ readonly cssNamespace?: string | undefined
60
66
  /** Flattened definition identities for nested compositions. */
61
67
  readonly portableInputs?: readonly string[] | undefined
62
68
  /** Ownership retained by a separately compiled callable. */
@@ -214,6 +220,7 @@ export function extract(options: extract.Options): extract.ReturnType {
214
220
  }
215
221
 
216
222
  const program = parsed.program
223
+ const authoredNames = Names.collect(program)
217
224
  const scopeTracker = new Scope.Tracker({ preserveExitedScopes: true })
218
225
 
219
226
  Walker.walk(program, { scopeTracker })
@@ -262,6 +269,7 @@ export function extract(options: extract.Options): extract.ReturnType {
262
269
  const themes = (() => {
263
270
  try {
264
271
  return Themes.collect(program, {
272
+ native: options.target === 'native',
265
273
  staticBindings: staticData.bindings,
266
274
  namespace: `src-${Identity.label(
267
275
  options.moduleId
@@ -329,7 +337,7 @@ export function extract(options: extract.Options): extract.ReturnType {
329
337
  contributions.read(node, parent, binding)
330
338
 
331
339
  try {
332
- if (variables.reference(node, parent, binding)) return
340
+ if (variables.reference(node, parent, ancestors, binding)) return
333
341
  } catch (error) {
334
342
  if (!(error instanceof Themes.InvalidError)) throw error
335
343
 
@@ -340,7 +348,16 @@ export function extract(options: extract.Options): extract.ReturnType {
340
348
 
341
349
  if (themes)
342
350
  try {
343
- if (themes.reference(node, parent, ancestors, binding)) return
351
+ if (
352
+ themes.reference(
353
+ node,
354
+ parent,
355
+ ancestors,
356
+ binding,
357
+ (name) => scopeTracker.getDeclaration(name) ?? null,
358
+ )
359
+ )
360
+ return
344
361
  } catch (error) {
345
362
  if (!(error instanceof Themes.InvalidError)) throw error
346
363
 
@@ -540,6 +557,13 @@ export function extract(options: extract.Options): extract.ReturnType {
540
557
  pending,
541
558
  options[Themes.context]?.links,
542
559
  selectorKeys,
560
+ new Map(
561
+ [...(themes?.styles ?? [])].flatMap(([start, context]) => {
562
+ const id = context.theme[Token.definition].contract[Token.identity]
563
+ return id?.startsWith('id-') ? [[start, id.slice(3)] as const] : []
564
+ }),
565
+ ),
566
+ options.moduleId,
543
567
  )
544
568
  } catch (error) {
545
569
  if (!(error instanceof Themes.InvalidError)) throw error
@@ -549,7 +573,13 @@ export function extract(options: extract.Options): extract.ReturnType {
549
573
  }
550
574
  })()
551
575
 
576
+ const cssNameCounts = new Map<string, number>()
552
577
  for (const call of pending) {
578
+ const name = authoredNames.get(call.start)!
579
+ cssNameCounts.set(name, (cssNameCounts.get(name) ?? 0) + 1)
580
+ }
581
+ const cssNameIndices = new Map<string, number>()
582
+ for (const [callIndex, call] of pending.entries()) {
553
583
  const explicitId = (() => {
554
584
  try {
555
585
  return Identifiers.explicit(call)
@@ -558,10 +588,29 @@ export function extract(options: extract.Options): extract.ReturnType {
558
588
  return undefined
559
589
  }
560
590
  })()
591
+ const contractIdentity = themes?.styles.get(call.start)?.theme[
592
+ Token.definition
593
+ ].contract[Token.identity]
594
+ const cssNamespace = contractIdentity?.startsWith('id-')
595
+ ? contractIdentity.slice(3)
596
+ : undefined
597
+ const authoredName = authoredNames.get(call.start)!
598
+ const nameIndex = cssNameIndices.get(authoredName) ?? 0
599
+ cssNameIndices.set(authoredName, nameIndex + 1)
600
+ const cssName =
601
+ explicitId !== undefined
602
+ ? Identity.name(explicitId)
603
+ : `${Identity.compact(options.moduleId).slice(-6)}-${
604
+ authoredName === 'style'
605
+ ? `style-${callIndex}`
606
+ : cssNameCounts.get(authoredName)! > 1
607
+ ? `${authoredName}-${nameIndex}`
608
+ : authoredName
609
+ }`
561
610
  const definitionId =
562
611
  explicitId === undefined
563
- ? `${namespace}-${call.start}`
564
- : Identity.requireId(explicitId, 'style')
612
+ ? `${cssNamespace ? `${cssNamespace}-` : ''}${cssName}`
613
+ : `id-${cssNamespace ? `${cssNamespace}-` : ''}${Identity.requireId(explicitId, 'style').slice(3)}`
565
614
  let argument = call.arguments[0]
566
615
 
567
616
  if (call.arguments.length === 0)
@@ -1305,10 +1354,12 @@ export function extract(options: extract.Options): extract.ReturnType {
1305
1354
  !definition.styles[0]!.targets)
1306
1355
  )
1307
1356
  return undefined
1308
- return Identity.style(definition.styles[0]!)
1357
+ return Identity.style(definition.styles[0]!, cssNamespace)
1309
1358
  })(),
1310
1359
  }
1311
1360
  : {}),
1361
+ cssName,
1362
+ cssNamespace,
1312
1363
  end: call.end,
1313
1364
  name,
1314
1365
  start: call.start,
@@ -1328,6 +1379,7 @@ export function extract(options: extract.Options): extract.ReturnType {
1328
1379
  }
1329
1380
 
1330
1381
  try {
1382
+ let compositionIndex = 0
1331
1383
  for (const entry of options.target === 'native'
1332
1384
  ? []
1333
1385
  : Compositions.collect({
@@ -1339,7 +1391,16 @@ export function extract(options: extract.Options): extract.ReturnType {
1339
1391
  source: options.source,
1340
1392
  styles,
1341
1393
  })) {
1342
- calls.push(...(entry.cases ?? []).map((entry) => entry.call), entry.call)
1394
+ const authored = authoredNames.get(entry.call.start)
1395
+ const name = authored && authored !== 'style' ? authored : 'composition'
1396
+ const cssName = `${name}-${compositionIndex++}-${entry.call.cssName ?? 'style'}`
1397
+ calls.push(
1398
+ ...(entry.cases ?? []).map((value, index) => ({
1399
+ ...value.call,
1400
+ cssName: `${cssName}-${index}`,
1401
+ })),
1402
+ { ...entry.call, cssName },
1403
+ )
1343
1404
  styles.push(
1344
1405
  ...(entry.cases ?? []).map((entry) => entry.style),
1345
1406
  entry.style,
@@ -1469,7 +1530,17 @@ export function extract(options: extract.Options): extract.ReturnType {
1469
1530
  const style = call && styles.find((style) => style.name === call.name)
1470
1531
  return {
1471
1532
  ...link,
1472
- ...(call && style ? { style: PackedStyles.create(call, style) } : {}),
1533
+ ...(call && style
1534
+ ? {
1535
+ style: PackedStyles.create(
1536
+ {
1537
+ ...call,
1538
+ nativeContext: themes?.nativeContext(call.start, call.end),
1539
+ },
1540
+ style,
1541
+ ),
1542
+ }
1543
+ : {}),
1473
1544
  ...(link.members
1474
1545
  ? {
1475
1546
  members: Object.fromEntries(
@@ -1483,6 +1554,35 @@ export function extract(options: extract.Options): extract.ReturnType {
1483
1554
  }
1484
1555
  }
1485
1556
 
1557
+ const callsByName = new Map(calls.map((call) => [call.name, call]))
1558
+ const definition = {
1559
+ styles: Object.freeze(styles),
1560
+ [ClassName.labels]: Object.freeze(
1561
+ Object.fromEntries(
1562
+ styles.map((style) => {
1563
+ let name = style.name
1564
+ let call = callsByName.get(name)
1565
+ while (!call && name.includes('-')) {
1566
+ name = name.slice(0, name.lastIndexOf('-'))
1567
+ call = callsByName.get(name)
1568
+ }
1569
+ return [
1570
+ style.name,
1571
+ {
1572
+ name: call?.cssName
1573
+ ? call.cssName + style.name.slice(call.name.length)
1574
+ : style.name,
1575
+ namespace: call?.cssNamespace,
1576
+ },
1577
+ ]
1578
+ }),
1579
+ ),
1580
+ ),
1581
+ }
1582
+ Object.defineProperty(definition, ClassName.labels, { enumerable: false })
1583
+ const selections =
1584
+ options.target === 'native' ? themes?.selectionUses : themes?.selections
1585
+
1486
1586
  return Object.freeze({
1487
1587
  namespaces: contributionData.filter(
1488
1588
  (value): value is Extract<Css.Contribution, { kind: 'namespace' }> =>
@@ -1522,7 +1622,7 @@ export function extract(options: extract.Options): extract.ReturnType {
1522
1622
  )
1523
1623
  }),
1524
1624
  ),
1525
- styles: Object.freeze({ styles: Object.freeze(styles) }),
1625
+ styles: Object.freeze(definition),
1526
1626
  ...(variables.calls.length
1527
1627
  ? { variableCalls: Object.freeze(variables.calls) }
1528
1628
  : {}),
@@ -1533,8 +1633,8 @@ export function extract(options: extract.Options): extract.ReturnType {
1533
1633
  ...(themes?.scripts.size
1534
1634
  ? { themeScripts: Object.freeze([...themes.scripts]) }
1535
1635
  : {}),
1536
- ...(themes?.selections.size
1537
- ? { themeSelections: Object.freeze([...themes.selections]) }
1636
+ ...(selections?.size
1637
+ ? { themeSelections: Object.freeze([...selections]) }
1538
1638
  : {}),
1539
1639
  themeCalls: Object.freeze(themes?.calls ?? []),
1540
1640
  ...(themes?.staticTokens.length
@@ -1552,6 +1652,9 @@ export function extract(options: extract.Options): extract.ReturnType {
1552
1652
  : {}),
1553
1653
  themeReferences: Object.freeze(themes?.references ?? []),
1554
1654
  vars: themes?.themes ?? Object.freeze({}),
1655
+ ...(themes?.varsReads.length
1656
+ ? { nativeVars: Object.freeze(themes.varsReads) }
1657
+ : {}),
1555
1658
  })
1556
1659
  }
1557
1660
 
@@ -1576,6 +1679,8 @@ export declare namespace extract {
1576
1679
 
1577
1680
  /** Ordered public compiler input and spans for later rewriting. */
1578
1681
  type ReturnType = {
1682
+ /** Readonly native variable arguments and their complete catalogs. */
1683
+ readonly nativeVars?: readonly Themes.VarsRead[] | undefined
1579
1684
  /** Module-owned namespace bindings retained when contributions are shared. */
1580
1685
  readonly namespaces?: readonly Namespace.Definition[] | undefined
1581
1686
  /** Static stylesheet effects and their source replacements. */
@@ -7,6 +7,7 @@ import * as Token from '../internal/Token.js'
7
7
  import * as Applications from './internal/Applications.js'
8
8
  import type * as Ast from '@oxc-project/types'
9
9
  import * as Css from '../web/Css.js'
10
+ import * as ClassName from '../web/internal/ClassName.js'
10
11
  import * as Expression from './internal/Expression.js'
11
12
  import MagicString from 'magic-string'
12
13
  import * as Mapping from '@jridgewell/gen-mapping'
@@ -71,11 +72,7 @@ export function compile(options: compile.Options): compile.ReturnType {
71
72
  'CSS-only named stylesheet declarations require an explicit id.',
72
73
  )
73
74
  for (const call of extracted.variableCalls ?? [])
74
- if (
75
- Object.values(call.slots).some(
76
- (slot) => !slot.name.startsWith('--z-vid-'),
77
- )
78
- )
75
+ if (!call.explicit)
79
76
  throw new Error('CSS-only output requires an explicit variable id.')
80
77
  }
81
78
 
@@ -198,7 +195,7 @@ export function compile(options: compile.Options): compile.ReturnType {
198
195
  const emitted = Css.compile({
199
196
  [ThemeRules.shared]: options[ThemeRules.shared],
200
197
  development: options.development,
201
- scope: options.moduleId,
198
+ [ClassName.labels]: extracted.styles[ClassName.labels],
202
199
  composition: options.composition,
203
200
  cssOutput: options.cssOutput,
204
201
  names: portable ? portableNames : undefined,
@@ -291,56 +288,19 @@ export function compile(options: compile.Options): compile.ReturnType {
291
288
  `${variables}.create(${JSON.stringify(call.slots.value)})`,
292
289
  )
293
290
 
294
- const first = extracted.calls[0]
295
- const scope = first ? first.name.slice(6, first.name.lastIndexOf('-')) : ''
296
291
  const identities = new Map(
297
292
  extracted.calls
298
293
  .filter((call) => call.identity)
299
294
  .map((call) => [call.name, call.identity!]),
300
295
  )
301
296
 
302
- const modes = new Map(
303
- extracted.styles.styles.map((style) => [style.name, style.cssOutput]),
304
- )
305
- const ownersByClass = new Map<string, string | false>()
306
- for (const [style, value] of Object.entries(emitted.classes))
307
- for (const name of value.split(' ').filter(Boolean))
308
- ownersByClass.set(name, ownersByClass.has(name) ? false : style)
309
-
310
- const names = new Map<string, string>()
311
-
312
- for (const classes of Object.values(emitted.classes))
313
- for (const name of classes.split(' ').filter(Boolean))
314
- names.set(
315
- name,
316
- (() => {
317
- const owner = ownersByClass.get(name)
318
- const identity = owner && identities.get(owner)
319
- if (
320
- (modes.get(owner || '') ?? options.cssOutput) === 'grouped' &&
321
- options.composition === 'independent' &&
322
- name.startsWith('g_') &&
323
- identity &&
324
- !identity.includes(' ')
325
- )
326
- return identity
327
- if (name.startsWith('g_')) return `g_${scope}_${name.slice(2)}`
328
- return name.startsWith('z_base')
329
- ? `z-${scope}-${name.slice(2)}`
330
- : name
331
- })(),
332
- )
333
-
334
297
  const classes = Object.freeze(
335
298
  Object.fromEntries(
336
299
  Object.entries(emitted.classes).map(([name, value]) => [
337
300
  name,
338
301
  [
339
302
  ...new Set([
340
- ...value
341
- .split(' ')
342
- .filter(Boolean)
343
- .map((part) => names.get(part)!),
303
+ ...value.split(' ').filter(Boolean),
344
304
  ...(identities.has(name) &&
345
305
  (!portable || portableNames[name]?.startsWith('z-compose-'))
346
306
  ? [
@@ -930,8 +890,16 @@ export function compile(options: compile.Options): compile.ReturnType {
930
890
  (scoped ? scoped.split('\n') : [])
931
891
  .map((rule, index) => {
932
892
  const line = index + 1 + (prefix ? prefix.split('\n').length : 0)
933
- const brace = rule.indexOf('{')
934
- const name = rule.slice(1, brace)
893
+ const openers = new Map<number, number>()
894
+ const conditionStarts = declarationStarts(rule, true, openers)
895
+ const selectorStart =
896
+ conditionStarts.find((start) => rule[start] === '.') ?? 0
897
+ const brace = openers.get(selectorStart) ?? rule.indexOf('{')
898
+ const name = rule
899
+ .slice(selectorStart + 1, brace)
900
+ .replace(/\\([0-9a-f]+) ?/gi, (_, code: string) =>
901
+ String.fromCodePoint(Number.parseInt(code, 16)),
902
+ )
935
903
  const linkedOwner = linkedOwners.get(name)
936
904
 
937
905
  if (linkedOwner) {
@@ -995,11 +963,11 @@ export function compile(options: compile.Options): compile.ReturnType {
995
963
  return rule
996
964
  }
997
965
 
998
- const selector = `.${names.get(name)!}`
966
+ const selector = `.${ClassName.selector(name)}`
999
967
  const call = owners.get(name)!
1000
968
 
1001
969
  Mapping.addMapping(cssMap, {
1002
- generated: { column: 0, line },
970
+ generated: { column: selectorStart, line },
1003
971
  name: call.name,
1004
972
  original: position(call.start),
1005
973
  source: options.moduleId,
@@ -1071,8 +1039,6 @@ export function compile(options: compile.Options): compile.ReturnType {
1071
1039
 
1072
1040
  const ordered = declarations(style)
1073
1041
  const authored = locations(call.body ?? definitions.get(call.start)!)
1074
- const openers = new Map<number, number>()
1075
- const conditionStarts = declarationStarts(body, true, openers)
1076
1042
  const conditions: string[] = []
1077
1043
 
1078
1044
  function collectConditions(style: Style.NamedStyle) {
@@ -1084,17 +1050,25 @@ export function compile(options: compile.Options): compile.ReturnType {
1084
1050
  }
1085
1051
 
1086
1052
  collectConditions(style)
1087
- let conditionCursor = 0
1053
+ const mappedConditions = new Set<number>()
1088
1054
 
1089
1055
  for (const start of conditionStarts) {
1090
- const condition = body.slice(start, openers.get(start))
1091
- const index = conditions.indexOf(condition, conditionCursor)
1056
+ const condition = rule.slice(start, openers.get(start))
1057
+ const index = conditions.findIndex(
1058
+ (value, index) =>
1059
+ value === condition && !mappedConditions.has(index),
1060
+ )
1092
1061
  const node = conditionNodes[index]
1093
1062
  if (!node) continue
1094
1063
 
1095
- conditionCursor = index + 1
1064
+ mappedConditions.add(index)
1096
1065
  Mapping.addMapping(cssMap, {
1097
- generated: { column: selector.length + start, line },
1066
+ generated: {
1067
+ column:
1068
+ start +
1069
+ (start > brace ? selector.length - (brace - selectorStart) : 0),
1070
+ line,
1071
+ },
1098
1072
  name: options.source.slice(node.key.start, node.key.end),
1099
1073
  original: position(node.key.start),
1100
1074
  source: options.moduleId,
@@ -1124,7 +1098,10 @@ export function compile(options: compile.Options): compile.ReturnType {
1124
1098
  used.add(propertyIndex)
1125
1099
 
1126
1100
  Mapping.addMapping(cssMap, {
1127
- generated: { column: selector.length + start, line },
1101
+ generated: {
1102
+ column: selectorStart + selector.length + start,
1103
+ line,
1104
+ },
1128
1105
  name: declaration.property,
1129
1106
  original: position(location.start),
1130
1107
  source: options.moduleId,
@@ -1132,7 +1109,7 @@ export function compile(options: compile.Options): compile.ReturnType {
1132
1109
  cursor = start + text.length
1133
1110
  }
1134
1111
 
1135
- return selector + body
1112
+ return rule.slice(0, selectorStart) + selector + body
1136
1113
  })
1137
1114
  .join('\n'),
1138
1115
  ]
@@ -1153,10 +1130,11 @@ export function compile(options: compile.Options): compile.ReturnType {
1153
1130
  Mapping.toEncodedMap(cssMap),
1154
1131
  true,
1155
1132
  )
1156
- return Object.freeze({
1133
+ const result = {
1157
1134
  ...(emitted[ThemeRules.shared]
1158
1135
  ? { [ThemeRules.shared]: emitted[ThemeRules.shared] }
1159
1136
  : {}),
1137
+ [ClassName.rules]: emitted[ClassName.rules],
1160
1138
  classes,
1161
1139
  code: portable ? options.source : module.toString(),
1162
1140
  css: namespaced.css,
@@ -1170,7 +1148,9 @@ export function compile(options: compile.Options): compile.ReturnType {
1170
1148
  version: 3 as const,
1171
1149
  },
1172
1150
  vars: emitted.vars,
1173
- })
1151
+ }
1152
+ Object.defineProperty(result, ClassName.rules, { enumerable: false })
1153
+ return Object.freeze(result)
1174
1154
  }
1175
1155
 
1176
1156
  /** Source transform contracts. */
@@ -1187,7 +1167,7 @@ export declare namespace compile {
1187
1167
  readonly composition?: Css.compile.Options['composition']
1188
1168
  /** Default CSS representation for definitions without an explicit mode. */
1189
1169
  readonly cssOutput?: Css.compile.Options['cssOutput']
1190
- /** Stable declaration names for CSS-only development updates. */
1170
+ /** Retains live definitions for development updates. */
1191
1171
  readonly development?: boolean | undefined
1192
1172
  /**
1193
1173
  * Emit the `color-scheme` selection classes beside the theme scopes.
@@ -1206,6 +1186,8 @@ export declare namespace compile {
1206
1186
  readonly classes: Readonly<Record<string, string>>
1207
1187
  /** Rewritten source with imports for surviving props callables. */
1208
1188
  readonly code: string
1189
+ /** Exact emitted rules retained for collision diagnostics. */
1190
+ readonly [ClassName.rules]: Readonly<Record<string, string>>
1209
1191
  /** Ordered, unminified stylesheet text. */
1210
1192
  readonly css: string
1211
1193
  /** Standard stylesheet map with authored selector/declaration locations. */
@@ -90,7 +90,15 @@ export function read(contract: string): readonly Catalog[] {
90
90
  return [...configurations].map(([identity, { entries, storageKey }]) => ({
91
91
  entries: [...entries].map(
92
92
  ([name, scope]) =>
93
- [name, `z_theme-${ThemeValues.encode(scope)}`] as const,
93
+ [
94
+ name,
95
+ ThemeValues.scope(
96
+ scope.startsWith(`${identity}-`)
97
+ ? scope.slice(identity.length + 1)
98
+ : scope,
99
+ identity,
100
+ ),
101
+ ] as const,
94
102
  ),
95
103
  identity,
96
104
  storageKey,
@@ -503,6 +503,13 @@ export function collect(options: collect.Options) {
503
503
  )
504
504
  : undefined
505
505
  const call: Source.Call = {
506
+ cssName: selected
507
+ .map((call) =>
508
+ [call.cssNamespace, call.cssName ?? call.identity ?? 'style']
509
+ .filter(Boolean)
510
+ .join('-'),
511
+ )
512
+ .join('-'),
506
513
  ...(portable(selected)
507
514
  ? {
508
515
  portable: portable(selected),
@@ -162,7 +162,7 @@ export function collect(options: collect.Options): Themes.Link {
162
162
 
163
163
  for (const [key, original] of Object.entries(catalog)) {
164
164
  const name = `${identity}-${key}`
165
- const definition = Token.bind(original, contract)
165
+ const definition = Token.bind(original, contract, key)
166
166
  const tokenType = type({
167
167
  ...values(original.tokens),
168
168
  ...original[Token.definition].queries,
@@ -242,6 +242,7 @@ export function collect(options: collect.Options): Themes.Link {
242
242
 
243
243
  return {}
244
244
  })(),
245
+ ...(input.id !== undefined ? { id: input.id } : {}),
245
246
  ...(input.cssOutput ? { cssOutput: input.cssOutput } : {}),
246
247
  ...(input.defaultLayer !== undefined
247
248
  ? { defaultLayer: input.defaultLayer }
@@ -251,10 +252,28 @@ export function collect(options: collect.Options): Themes.Link {
251
252
  ...(input.layers ? { layers: input.layers } : {}),
252
253
  ...(input.storageKey ? { storageKey: input.storageKey } : {}),
253
254
  }
255
+ const authoredType = type(
256
+ variableMode
257
+ ? {
258
+ ...normalized,
259
+ theme: undefined,
260
+ themes: undefined,
261
+ defaultTheme: undefined,
262
+ vars: 'themes' in normalized ? normalized.themes : normalized.theme,
263
+ ...('themes' in normalized
264
+ ? { defaultVars: normalized.defaultTheme }
265
+ : {}),
266
+ ...(authored.mappings !== undefined
267
+ ? { mappings: VariableSets.mappings(authored.mappings) }
268
+ : {}),
269
+ }
270
+ : normalized,
271
+ )
254
272
 
255
273
  return {
256
274
  binding: options.name,
257
275
  call: {
276
+ ...(options.nativeProvider ? { nativeProvider: true } : {}),
258
277
  ...(variableMode
259
278
  ? { variableConfig: true, variableMappings: authored.mappings }
260
279
  : {}),
@@ -268,9 +287,11 @@ export function collect(options: collect.Options): Themes.Link {
268
287
  options: normalized,
269
288
  start: options.expression.start,
270
289
  tokenType: selected?.call.tokenType ?? '{}',
271
- type: variableMode
272
- ? `import('zyzz').Config.VariableConfig<${type({ ...normalized, theme: undefined, themes: undefined, defaultTheme: undefined, vars: 'themes' in normalized ? normalized.themes : normalized.theme, ...('themes' in normalized ? { defaultVars: normalized.defaultTheme } : {}), ...(authored.mappings !== undefined ? { mappings: VariableSets.mappings(authored.mappings) } : {}) })}>`
273
- : `import('zyzz').Config.create.ReturnType<${type(normalized)}>`,
290
+ type: options.nativeProvider
291
+ ? `import('zyzz/react-native').defineConfig.ReturnType<${authoredType}>`
292
+ : variableMode
293
+ ? `import('zyzz').Config.VariableConfig<${authoredType}>`
294
+ : `import('zyzz').Config.create.ReturnType<${authoredType}>`,
274
295
  },
275
296
  definition,
276
297
  kind: 'config',
@@ -288,6 +309,8 @@ export declare namespace collect {
288
309
  readonly expression: Ast.CallExpression
289
310
  /** Stable module/binding identity. */
290
311
  readonly name: string
312
+ /** Native factory supplies an ordinary React Provider export. */
313
+ readonly nativeProvider?: boolean | undefined
291
314
  /** Looks up preceding immutable theme definitions. */
292
315
  readonly resolve: (node: Ast.Node) => Themes.Link | undefined
293
316
  }