@canonical/terrazzo-plugin-css 0.0.2 → 0.2.0

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 (551) hide show
  1. package/dist/esm/artifact/makeArtifactToken.js.map +1 -1
  2. package/dist/esm/artifact/makeDerivedArtifactToken.js.map +1 -1
  3. package/dist/esm/artifact/types.js +2 -0
  4. package/dist/esm/artifact/types.js.map +1 -0
  5. package/dist/esm/build/annotation.js +70 -0
  6. package/dist/esm/build/annotation.js.map +1 -0
  7. package/dist/esm/build/buildModifiers.js +114 -0
  8. package/dist/esm/build/buildModifiers.js.map +1 -0
  9. package/dist/esm/build/buildPrimitive.js +78 -0
  10. package/dist/esm/build/buildPrimitive.js.map +1 -0
  11. package/dist/esm/build/buildStates.js +2 -0
  12. package/dist/esm/build/buildStates.js.map +1 -0
  13. package/dist/esm/build/buildTheme.js +95 -0
  14. package/dist/esm/build/buildTheme.js.map +1 -0
  15. package/dist/esm/build/buildTypography.js +78 -0
  16. package/dist/esm/build/buildTypography.js.map +1 -0
  17. package/dist/esm/build/builders/buildDescriptionLookup.js +11 -0
  18. package/dist/esm/build/builders/buildDescriptionLookup.js.map +1 -0
  19. package/dist/esm/build/builders/buildFallbackChain.js +22 -0
  20. package/dist/esm/build/builders/buildFallbackChain.js.map +1 -0
  21. package/dist/esm/build/builders/buildModifierFamily.js +41 -0
  22. package/dist/esm/build/builders/buildModifierFamily.js.map +1 -0
  23. package/dist/esm/build/builders/buildModifiers.js +2 -0
  24. package/dist/esm/build/builders/buildModifiers.js.map +1 -0
  25. package/dist/esm/build/builders/buildPrimitive.js +2 -0
  26. package/dist/esm/build/builders/buildPrimitive.js.map +1 -0
  27. package/dist/esm/build/builders/buildSetsPrimitive.js +58 -0
  28. package/dist/esm/build/builders/buildSetsPrimitive.js.map +1 -0
  29. package/dist/esm/build/builders/buildSetsSemantic.js +9 -0
  30. package/dist/esm/build/builders/buildSetsSemantic.js.map +1 -0
  31. package/dist/esm/build/builders/buildStates.js +47 -0
  32. package/dist/esm/build/builders/buildStates.js.map +1 -0
  33. package/dist/esm/build/builders/buildSurfaces.js +42 -0
  34. package/dist/esm/build/builders/buildSurfaces.js.map +1 -0
  35. package/dist/esm/build/builders/buildTheme.js +97 -0
  36. package/dist/esm/build/builders/buildTheme.js.map +1 -0
  37. package/dist/esm/build/builders/buildTypography.js +42 -0
  38. package/dist/esm/build/builders/buildTypography.js.map +1 -0
  39. package/dist/esm/build/builders/convertCssValueToString.js +12 -0
  40. package/dist/esm/build/builders/convertCssValueToString.js.map +1 -0
  41. package/dist/esm/build/builders/emitTypographyDecls.js +37 -0
  42. package/dist/esm/build/builders/emitTypographyDecls.js.map +1 -0
  43. package/dist/esm/build/builders/index.js +16 -0
  44. package/dist/esm/build/builders/index.js.map +1 -0
  45. package/dist/esm/build/classification.js +27 -0
  46. package/dist/esm/build/classification.js.map +1 -0
  47. package/dist/esm/build/computeDeltas.js +73 -0
  48. package/dist/esm/build/computeDeltas.js.map +1 -0
  49. package/dist/esm/build/constants/format.js +3 -0
  50. package/dist/esm/build/constants/format.js.map +1 -0
  51. package/dist/esm/build/constants/header.js +3 -0
  52. package/dist/esm/build/constants/header.js.map +1 -0
  53. package/dist/esm/build/constants/interactiveRoles.js +88 -0
  54. package/dist/esm/build/constants/interactiveRoles.js.map +1 -0
  55. package/dist/esm/build/constants/surfaceSelectorMap.js +7 -0
  56. package/dist/esm/build/constants/surfaceSelectorMap.js.map +1 -0
  57. package/dist/esm/build/context.js +2 -0
  58. package/dist/esm/build/context.js.map +1 -0
  59. package/dist/esm/build/deltas.js +2 -0
  60. package/dist/esm/build/deltas.js.map +1 -0
  61. package/dist/esm/build/extractOklchL.js +13 -0
  62. package/dist/esm/build/extractOklchL.js.map +1 -0
  63. package/dist/esm/build/filterExtensions.js +21 -0
  64. package/dist/esm/build/filterExtensions.js.map +1 -0
  65. package/dist/esm/build/formatDelta.js +5 -0
  66. package/dist/esm/build/formatDelta.js.map +1 -0
  67. package/dist/esm/build/index.js +17 -0
  68. package/dist/esm/build/index.js.map +1 -0
  69. package/dist/esm/build/modifierIo.js +105 -0
  70. package/dist/esm/build/modifierIo.js.map +1 -0
  71. package/dist/esm/build/recoverPrimitiveRef.js +26 -0
  72. package/dist/esm/build/recoverPrimitiveRef.js.map +1 -0
  73. package/dist/esm/build/shims.js +16 -0
  74. package/dist/esm/build/shims.js.map +1 -0
  75. package/dist/esm/build/types.js +2 -0
  76. package/dist/esm/build/types.js.map +1 -0
  77. package/dist/esm/css-ast/addDeclarationUnique.js +7 -0
  78. package/dist/esm/css-ast/addDeclarationUnique.js.map +1 -0
  79. package/dist/esm/css-ast/createDeclaration.js +4 -0
  80. package/dist/esm/css-ast/createDeclaration.js.map +1 -0
  81. package/dist/esm/css-ast/decl.js +1 -1
  82. package/dist/esm/css-ast/decl.js.map +1 -1
  83. package/dist/esm/css-ast/hasDeclaration.js +4 -0
  84. package/dist/esm/css-ast/hasDeclaration.js.map +1 -0
  85. package/dist/esm/css-ast/index.js +4 -4
  86. package/dist/esm/css-ast/index.js.map +1 -1
  87. package/dist/esm/css-ast/printRules.js +1 -0
  88. package/dist/esm/css-ast/printRules.js.map +1 -1
  89. package/dist/esm/css-ast/rule.js +1 -1
  90. package/dist/esm/css-ast/rule.js.map +1 -1
  91. package/dist/esm/css-ast/types.js +2 -0
  92. package/dist/esm/css-ast/types.js.map +1 -0
  93. package/dist/esm/index.js +4 -4
  94. package/dist/esm/index.js.map +1 -1
  95. package/dist/esm/layers/types.js +2 -0
  96. package/dist/esm/layers/types.js.map +1 -0
  97. package/dist/esm/layers/wrapInLayer.js +5 -5
  98. package/dist/esm/layers/wrapInLayer.js.map +1 -1
  99. package/dist/esm/light-dark/buildLightDarkDeclarations.js +2 -2
  100. package/dist/esm/light-dark/buildLightDarkDeclarations.js.map +1 -1
  101. package/dist/esm/light-dark/types.js +2 -0
  102. package/dist/esm/light-dark/types.js.map +1 -0
  103. package/dist/esm/modifiers/buildModifierContextCSS.js +2 -2
  104. package/dist/esm/modifiers/buildModifierContextCSS.js.map +1 -1
  105. package/dist/esm/modifiers/computeModifierContext.js +6 -6
  106. package/dist/esm/modifiers/computeModifierContext.js.map +1 -1
  107. package/dist/esm/modifiers/getAliasTarget.js +1 -7
  108. package/dist/esm/modifiers/getAliasTarget.js.map +1 -1
  109. package/dist/esm/modifiers/types.js +2 -0
  110. package/dist/esm/modifiers/types.js.map +1 -0
  111. package/dist/esm/naming.js +3 -8
  112. package/dist/esm/naming.js.map +1 -1
  113. package/dist/esm/plugin/canonicalPlugin.js +132 -0
  114. package/dist/esm/plugin/canonicalPlugin.js.map +1 -0
  115. package/dist/esm/plugin/index.js +6 -0
  116. package/dist/esm/plugin/index.js.map +1 -0
  117. package/dist/esm/plugin/src/artifact/classifyTier.js +7 -0
  118. package/dist/esm/plugin/src/artifact/classifyTier.js.map +1 -0
  119. package/dist/esm/plugin/src/artifact/index.js +5 -0
  120. package/dist/esm/plugin/src/artifact/index.js.map +1 -0
  121. package/dist/esm/plugin/src/artifact/makeArtifactToken.js +36 -0
  122. package/dist/esm/plugin/src/artifact/makeArtifactToken.js.map +1 -0
  123. package/dist/esm/plugin/src/artifact/makeDerivedArtifactToken.js +29 -0
  124. package/dist/esm/plugin/src/artifact/makeDerivedArtifactToken.js.map +1 -0
  125. package/dist/esm/plugin/src/artifact/serializeArtifact.js +4 -0
  126. package/dist/esm/plugin/src/artifact/serializeArtifact.js.map +1 -0
  127. package/dist/esm/plugin/src/artifact/types.js +2 -0
  128. package/dist/esm/plugin/src/artifact/types.js.map +1 -0
  129. package/dist/esm/plugin/src/build/annotation.js +70 -0
  130. package/dist/esm/plugin/src/build/annotation.js.map +1 -0
  131. package/dist/esm/plugin/src/build/buildModifiers.js +114 -0
  132. package/dist/esm/plugin/src/build/buildModifiers.js.map +1 -0
  133. package/dist/esm/plugin/src/build/buildPrimitive.js +78 -0
  134. package/dist/esm/plugin/src/build/buildPrimitive.js.map +1 -0
  135. package/dist/esm/plugin/src/build/buildStates.js +66 -0
  136. package/dist/esm/plugin/src/build/buildStates.js.map +1 -0
  137. package/dist/esm/plugin/src/build/buildTheme.js +95 -0
  138. package/dist/esm/plugin/src/build/buildTheme.js.map +1 -0
  139. package/dist/esm/plugin/src/build/buildTypography.js +78 -0
  140. package/dist/esm/plugin/src/build/buildTypography.js.map +1 -0
  141. package/dist/esm/plugin/src/build/builders/buildDescriptionLookup.js +11 -0
  142. package/dist/esm/plugin/src/build/builders/buildDescriptionLookup.js.map +1 -0
  143. package/dist/esm/plugin/src/build/builders/buildFallbackChain.js +22 -0
  144. package/dist/esm/plugin/src/build/builders/buildFallbackChain.js.map +1 -0
  145. package/dist/esm/plugin/src/build/builders/buildModifierFamily.js +41 -0
  146. package/dist/esm/plugin/src/build/builders/buildModifierFamily.js.map +1 -0
  147. package/dist/esm/plugin/src/build/builders/buildModifiers.js +2 -0
  148. package/dist/esm/plugin/src/build/builders/buildModifiers.js.map +1 -0
  149. package/dist/esm/plugin/src/build/builders/buildPrimitive.js +2 -0
  150. package/dist/esm/plugin/src/build/builders/buildPrimitive.js.map +1 -0
  151. package/dist/esm/plugin/src/build/builders/buildSetsPrimitive.js +58 -0
  152. package/dist/esm/plugin/src/build/builders/buildSetsPrimitive.js.map +1 -0
  153. package/dist/esm/plugin/src/build/builders/buildSetsSemantic.js +9 -0
  154. package/dist/esm/plugin/src/build/builders/buildSetsSemantic.js.map +1 -0
  155. package/dist/esm/plugin/src/build/builders/buildStates.js +47 -0
  156. package/dist/esm/plugin/src/build/builders/buildStates.js.map +1 -0
  157. package/dist/esm/plugin/src/build/builders/buildSurfaces.js +42 -0
  158. package/dist/esm/plugin/src/build/builders/buildSurfaces.js.map +1 -0
  159. package/dist/esm/plugin/src/build/builders/buildTheme.js +97 -0
  160. package/dist/esm/plugin/src/build/builders/buildTheme.js.map +1 -0
  161. package/dist/esm/plugin/src/build/builders/buildTypography.js +42 -0
  162. package/dist/esm/plugin/src/build/builders/buildTypography.js.map +1 -0
  163. package/dist/esm/plugin/src/build/builders/convertCssValueToString.js +12 -0
  164. package/dist/esm/plugin/src/build/builders/convertCssValueToString.js.map +1 -0
  165. package/dist/esm/plugin/src/build/builders/emitTypographyDecls.js +37 -0
  166. package/dist/esm/plugin/src/build/builders/emitTypographyDecls.js.map +1 -0
  167. package/dist/esm/plugin/src/build/builders/index.js +16 -0
  168. package/dist/esm/plugin/src/build/builders/index.js.map +1 -0
  169. package/dist/esm/plugin/src/build/classification.js +27 -0
  170. package/dist/esm/plugin/src/build/classification.js.map +1 -0
  171. package/dist/esm/plugin/src/build/computeDeltas.js +73 -0
  172. package/dist/esm/plugin/src/build/computeDeltas.js.map +1 -0
  173. package/dist/esm/plugin/src/build/constants/format.js +3 -0
  174. package/dist/esm/plugin/src/build/constants/format.js.map +1 -0
  175. package/dist/esm/plugin/src/build/constants/header.js +3 -0
  176. package/dist/esm/plugin/src/build/constants/header.js.map +1 -0
  177. package/dist/esm/plugin/src/build/constants/interactiveRoles.js +88 -0
  178. package/dist/esm/plugin/src/build/constants/interactiveRoles.js.map +1 -0
  179. package/dist/esm/plugin/src/build/constants/surfaceSelectorMap.js +7 -0
  180. package/dist/esm/plugin/src/build/constants/surfaceSelectorMap.js.map +1 -0
  181. package/dist/esm/plugin/src/build/context.js +2 -0
  182. package/dist/esm/plugin/src/build/context.js.map +1 -0
  183. package/dist/esm/plugin/src/build/deltas.js +178 -0
  184. package/dist/esm/plugin/src/build/deltas.js.map +1 -0
  185. package/dist/esm/plugin/src/build/extractOklchL.js +13 -0
  186. package/dist/esm/plugin/src/build/extractOklchL.js.map +1 -0
  187. package/dist/esm/plugin/src/build/formatDelta.js +5 -0
  188. package/dist/esm/plugin/src/build/formatDelta.js.map +1 -0
  189. package/dist/esm/plugin/src/build/index.js +14 -0
  190. package/dist/esm/plugin/src/build/index.js.map +1 -0
  191. package/dist/esm/plugin/src/build/interactiveRoles.js +88 -0
  192. package/dist/esm/plugin/src/build/interactiveRoles.js.map +1 -0
  193. package/dist/esm/plugin/src/build/modifierIo.js +105 -0
  194. package/dist/esm/plugin/src/build/modifierIo.js.map +1 -0
  195. package/dist/esm/plugin/src/build/recoverPrimitiveRef.js +26 -0
  196. package/dist/esm/plugin/src/build/recoverPrimitiveRef.js.map +1 -0
  197. package/dist/esm/plugin/src/build/shims.js +9 -0
  198. package/dist/esm/plugin/src/build/shims.js.map +1 -0
  199. package/dist/esm/plugin/src/build/types.js +2 -0
  200. package/dist/esm/plugin/src/build/types.js.map +1 -0
  201. package/dist/esm/plugin/src/css-ast/addDeclarationUnique.js +7 -0
  202. package/dist/esm/plugin/src/css-ast/addDeclarationUnique.js.map +1 -0
  203. package/dist/esm/plugin/src/css-ast/createDeclaration.js +4 -0
  204. package/dist/esm/plugin/src/css-ast/createDeclaration.js.map +1 -0
  205. package/dist/esm/plugin/src/css-ast/decl.js +4 -0
  206. package/dist/esm/plugin/src/css-ast/decl.js.map +1 -0
  207. package/dist/esm/plugin/src/css-ast/declaration.js +4 -0
  208. package/dist/esm/plugin/src/css-ast/declaration.js.map +1 -0
  209. package/dist/esm/plugin/src/css-ast/hasDeclaration.js +4 -0
  210. package/dist/esm/plugin/src/css-ast/hasDeclaration.js.map +1 -0
  211. package/dist/esm/plugin/src/css-ast/index.js +7 -0
  212. package/dist/esm/plugin/src/css-ast/index.js.map +1 -0
  213. package/dist/esm/plugin/src/css-ast/printNode.js +28 -0
  214. package/dist/esm/plugin/src/css-ast/printNode.js.map +1 -0
  215. package/dist/esm/plugin/src/css-ast/printRules.js +13 -0
  216. package/dist/esm/plugin/src/css-ast/printRules.js.map +1 -0
  217. package/dist/esm/plugin/src/css-ast/rule.js +4 -0
  218. package/dist/esm/plugin/src/css-ast/rule.js.map +1 -0
  219. package/dist/esm/plugin/src/css-ast/types.js +2 -0
  220. package/dist/esm/plugin/src/css-ast/types.js.map +1 -0
  221. package/dist/esm/plugin/src/index.js +14 -0
  222. package/dist/esm/plugin/src/index.js.map +1 -0
  223. package/dist/esm/plugin/src/layers/index.js +3 -0
  224. package/dist/esm/plugin/src/layers/index.js.map +1 -0
  225. package/dist/esm/plugin/src/layers/resolveLayerConfig.js +10 -0
  226. package/dist/esm/plugin/src/layers/resolveLayerConfig.js.map +1 -0
  227. package/dist/esm/plugin/src/layers/types.js +2 -0
  228. package/dist/esm/plugin/src/layers/types.js.map +1 -0
  229. package/dist/esm/plugin/src/layers/wrapInLayer.js +14 -0
  230. package/dist/esm/plugin/src/layers/wrapInLayer.js.map +1 -0
  231. package/dist/esm/plugin/src/light-dark/buildLightDarkDeclarations.js +14 -0
  232. package/dist/esm/plugin/src/light-dark/buildLightDarkDeclarations.js.map +1 -0
  233. package/dist/esm/plugin/src/light-dark/index.js +3 -0
  234. package/dist/esm/plugin/src/light-dark/index.js.map +1 -0
  235. package/dist/esm/plugin/src/light-dark/types.js +2 -0
  236. package/dist/esm/plugin/src/light-dark/types.js.map +1 -0
  237. package/dist/esm/plugin/src/light-dark/wrapLightDark.js +13 -0
  238. package/dist/esm/plugin/src/light-dark/wrapLightDark.js.map +1 -0
  239. package/dist/esm/plugin/src/modifiers/buildModifierContextCSS.js +11 -0
  240. package/dist/esm/plugin/src/modifiers/buildModifierContextCSS.js.map +1 -0
  241. package/dist/esm/plugin/src/modifiers/computeModifierContext.js +75 -0
  242. package/dist/esm/plugin/src/modifiers/computeModifierContext.js.map +1 -0
  243. package/dist/esm/plugin/src/modifiers/getAliasTarget.js +4 -0
  244. package/dist/esm/plugin/src/modifiers/getAliasTarget.js.map +1 -0
  245. package/dist/esm/plugin/src/modifiers/index.js +4 -0
  246. package/dist/esm/plugin/src/modifiers/index.js.map +1 -0
  247. package/dist/esm/plugin/src/modifiers/types.js +2 -0
  248. package/dist/esm/plugin/src/modifiers/types.js.map +1 -0
  249. package/dist/esm/plugin/src/naming.js +28 -0
  250. package/dist/esm/plugin/src/naming.js.map +1 -0
  251. package/dist/esm/plugin/src/plugin/canonicalPlugin.js +132 -0
  252. package/dist/esm/plugin/src/plugin/canonicalPlugin.js.map +1 -0
  253. package/dist/esm/plugin/src/plugin/index.js +6 -0
  254. package/dist/esm/plugin/src/plugin/index.js.map +1 -0
  255. package/dist/esm/plugin/src/plugin/types.js +2 -0
  256. package/dist/esm/plugin/src/plugin/types.js.map +1 -0
  257. package/dist/esm/plugin/src/plugin.js +134 -0
  258. package/dist/esm/plugin/src/plugin.js.map +1 -0
  259. package/dist/esm/plugin/src/types.js +8 -0
  260. package/dist/esm/plugin/src/types.js.map +1 -0
  261. package/dist/esm/plugin/types.js +2 -0
  262. package/dist/esm/plugin/types.js.map +1 -0
  263. package/dist/esm/plugin.js +4 -932
  264. package/dist/esm/plugin.js.map +1 -1
  265. package/dist/esm/types/src/artifact/types.js +34 -0
  266. package/dist/esm/types/src/artifact/types.js.map +1 -0
  267. package/dist/esm/types/src/index.js +2 -0
  268. package/dist/esm/types/src/index.js.map +1 -0
  269. package/dist/esm/types.js +0 -6
  270. package/dist/esm/types.js.map +1 -1
  271. package/dist/types/artifact/classifyTier.d.ts +1 -1
  272. package/dist/types/artifact/classifyTier.d.ts.map +1 -1
  273. package/dist/types/artifact/makeArtifactToken.d.ts +2 -15
  274. package/dist/types/artifact/makeArtifactToken.d.ts.map +1 -1
  275. package/dist/types/artifact/makeDerivedArtifactToken.d.ts +2 -13
  276. package/dist/types/artifact/makeDerivedArtifactToken.d.ts.map +1 -1
  277. package/dist/types/artifact/serializeArtifact.d.ts +1 -1
  278. package/dist/types/artifact/serializeArtifact.d.ts.map +1 -1
  279. package/dist/types/artifact/types.d.ts +28 -0
  280. package/dist/types/artifact/types.d.ts.map +1 -0
  281. package/dist/types/build/annotation.d.ts +14 -0
  282. package/dist/types/build/annotation.d.ts.map +1 -0
  283. package/dist/types/build/buildModifiers.d.ts +19 -0
  284. package/dist/types/build/buildModifiers.d.ts.map +1 -0
  285. package/dist/types/build/buildPrimitive.d.ts +15 -0
  286. package/dist/types/build/buildPrimitive.d.ts.map +1 -0
  287. package/dist/types/build/buildStates.d.ts +3 -0
  288. package/dist/types/build/buildStates.d.ts.map +1 -0
  289. package/dist/types/build/buildTheme.d.ts +4 -0
  290. package/dist/types/build/buildTheme.d.ts.map +1 -0
  291. package/dist/types/build/buildTypography.d.ts +5 -0
  292. package/dist/types/build/buildTypography.d.ts.map +1 -0
  293. package/dist/types/build/builders/buildDescriptionLookup.d.ts +3 -0
  294. package/dist/types/build/builders/buildDescriptionLookup.d.ts.map +1 -0
  295. package/dist/types/build/builders/buildFallbackChain.d.ts +8 -0
  296. package/dist/types/build/builders/buildFallbackChain.d.ts.map +1 -0
  297. package/dist/types/build/builders/buildModifierFamily.d.ts +6 -0
  298. package/dist/types/build/builders/buildModifierFamily.d.ts.map +1 -0
  299. package/dist/types/build/builders/buildModifiers.d.ts +3 -0
  300. package/dist/types/build/builders/buildModifiers.d.ts.map +1 -0
  301. package/dist/types/build/builders/buildPrimitive.d.ts +3 -0
  302. package/dist/types/build/builders/buildPrimitive.d.ts.map +1 -0
  303. package/dist/types/build/builders/buildSetsPrimitive.d.ts +6 -0
  304. package/dist/types/build/builders/buildSetsPrimitive.d.ts.map +1 -0
  305. package/dist/types/build/builders/buildSetsSemantic.d.ts +5 -0
  306. package/dist/types/build/builders/buildSetsSemantic.d.ts.map +1 -0
  307. package/dist/types/build/builders/buildStates.d.ts +6 -0
  308. package/dist/types/build/builders/buildStates.d.ts.map +1 -0
  309. package/dist/types/build/builders/buildSurfaces.d.ts +6 -0
  310. package/dist/types/build/builders/buildSurfaces.d.ts.map +1 -0
  311. package/dist/types/build/builders/buildTheme.d.ts +6 -0
  312. package/dist/types/build/builders/buildTheme.d.ts.map +1 -0
  313. package/dist/types/build/builders/buildTypography.d.ts +9 -0
  314. package/dist/types/build/builders/buildTypography.d.ts.map +1 -0
  315. package/dist/types/build/builders/convertCssValueToString.d.ts +6 -0
  316. package/dist/types/build/builders/convertCssValueToString.d.ts.map +1 -0
  317. package/dist/types/build/builders/emitTypographyDecls.d.ts +5 -0
  318. package/dist/types/build/builders/emitTypographyDecls.d.ts.map +1 -0
  319. package/dist/types/build/builders/index.d.ts +16 -0
  320. package/dist/types/build/builders/index.d.ts.map +1 -0
  321. package/dist/types/build/classification.d.ts +13 -0
  322. package/dist/types/build/classification.d.ts.map +1 -0
  323. package/dist/types/build/computeDeltas.d.ts +17 -0
  324. package/dist/types/build/computeDeltas.d.ts.map +1 -0
  325. package/dist/types/build/constants/format.d.ts +3 -0
  326. package/dist/types/build/constants/format.d.ts.map +1 -0
  327. package/dist/types/build/constants/header.d.ts +3 -0
  328. package/dist/types/build/constants/header.d.ts.map +1 -0
  329. package/dist/types/build/constants/interactiveRoles.d.ts +4 -0
  330. package/dist/types/build/constants/interactiveRoles.d.ts.map +1 -0
  331. package/dist/types/build/constants/surfaceSelectorMap.d.ts +3 -0
  332. package/dist/types/build/constants/surfaceSelectorMap.d.ts.map +1 -0
  333. package/dist/types/build/context.d.ts +29 -0
  334. package/dist/types/build/context.d.ts.map +1 -0
  335. package/dist/types/build/deltas.d.ts +3 -0
  336. package/dist/types/build/deltas.d.ts.map +1 -0
  337. package/dist/types/build/extractOklchL.d.ts +2 -0
  338. package/dist/types/build/extractOklchL.d.ts.map +1 -0
  339. package/dist/types/build/filterExtensions.d.ts +9 -0
  340. package/dist/types/build/filterExtensions.d.ts.map +1 -0
  341. package/dist/types/build/formatDelta.d.ts +2 -0
  342. package/dist/types/build/formatDelta.d.ts.map +1 -0
  343. package/dist/types/build/index.d.ts +21 -0
  344. package/dist/types/build/index.d.ts.map +1 -0
  345. package/dist/types/build/modifierIo.d.ts +40 -0
  346. package/dist/types/build/modifierIo.d.ts.map +1 -0
  347. package/dist/types/build/recoverPrimitiveRef.d.ts +17 -0
  348. package/dist/types/build/recoverPrimitiveRef.d.ts.map +1 -0
  349. package/dist/types/build/shims.d.ts +95 -0
  350. package/dist/types/build/shims.d.ts.map +1 -0
  351. package/dist/types/build/types.d.ts +51 -0
  352. package/dist/types/build/types.d.ts.map +1 -0
  353. package/dist/types/css-ast/addDeclarationUnique.d.ts +3 -0
  354. package/dist/types/css-ast/addDeclarationUnique.d.ts.map +1 -0
  355. package/dist/types/css-ast/createDeclaration.d.ts +4 -0
  356. package/dist/types/css-ast/createDeclaration.d.ts.map +1 -0
  357. package/dist/types/css-ast/decl.d.ts +1 -1
  358. package/dist/types/css-ast/decl.d.ts.map +1 -1
  359. package/dist/types/css-ast/hasDeclaration.d.ts +3 -0
  360. package/dist/types/css-ast/hasDeclaration.d.ts.map +1 -0
  361. package/dist/types/css-ast/index.d.ts +4 -4
  362. package/dist/types/css-ast/index.d.ts.map +1 -1
  363. package/dist/types/css-ast/printNode.d.ts +1 -1
  364. package/dist/types/css-ast/printNode.d.ts.map +1 -1
  365. package/dist/types/css-ast/printRules.d.ts +1 -1
  366. package/dist/types/css-ast/printRules.d.ts.map +1 -1
  367. package/dist/types/css-ast/rule.d.ts +2 -2
  368. package/dist/types/css-ast/rule.d.ts.map +1 -1
  369. package/dist/types/css-ast/types.d.ts +21 -0
  370. package/dist/types/css-ast/types.d.ts.map +1 -0
  371. package/dist/types/index.d.ts +5 -5
  372. package/dist/types/index.d.ts.map +1 -1
  373. package/dist/types/layers/resolveLayerConfig.d.ts +1 -1
  374. package/dist/types/layers/resolveLayerConfig.d.ts.map +1 -1
  375. package/dist/types/layers/types.d.ts +19 -0
  376. package/dist/types/layers/types.d.ts.map +1 -0
  377. package/dist/types/layers/wrapInLayer.d.ts +1 -1
  378. package/dist/types/layers/wrapInLayer.d.ts.map +1 -1
  379. package/dist/types/light-dark/buildLightDarkDeclarations.d.ts +2 -1
  380. package/dist/types/light-dark/buildLightDarkDeclarations.d.ts.map +1 -1
  381. package/dist/types/light-dark/types.d.ts +50 -0
  382. package/dist/types/light-dark/types.d.ts.map +1 -0
  383. package/dist/types/modifiers/buildModifierContextCSS.d.ts +2 -1
  384. package/dist/types/modifiers/buildModifierContextCSS.d.ts.map +1 -1
  385. package/dist/types/modifiers/computeModifierContext.d.ts +1 -1
  386. package/dist/types/modifiers/computeModifierContext.d.ts.map +1 -1
  387. package/dist/types/modifiers/getAliasTarget.d.ts +2 -3
  388. package/dist/types/modifiers/getAliasTarget.d.ts.map +1 -1
  389. package/dist/types/modifiers/types.d.ts +42 -0
  390. package/dist/types/modifiers/types.d.ts.map +1 -0
  391. package/dist/types/naming.d.ts +3 -8
  392. package/dist/types/naming.d.ts.map +1 -1
  393. package/dist/types/plugin/canonicalPlugin.d.ts +18 -0
  394. package/dist/types/plugin/canonicalPlugin.d.ts.map +1 -0
  395. package/dist/types/plugin/index.d.ts +7 -0
  396. package/dist/types/plugin/index.d.ts.map +1 -0
  397. package/dist/types/plugin/src/artifact/classifyTier.d.ts +10 -0
  398. package/dist/types/plugin/src/artifact/classifyTier.d.ts.map +1 -0
  399. package/dist/types/plugin/src/artifact/index.d.ts +5 -0
  400. package/dist/types/plugin/src/artifact/index.d.ts.map +1 -0
  401. package/dist/types/plugin/src/artifact/makeArtifactToken.d.ts +6 -0
  402. package/dist/types/plugin/src/artifact/makeArtifactToken.d.ts.map +1 -0
  403. package/dist/types/plugin/src/artifact/makeDerivedArtifactToken.d.ts +6 -0
  404. package/dist/types/plugin/src/artifact/makeDerivedArtifactToken.d.ts.map +1 -0
  405. package/dist/types/plugin/src/artifact/serializeArtifact.d.ts +6 -0
  406. package/dist/types/plugin/src/artifact/serializeArtifact.d.ts.map +1 -0
  407. package/dist/types/plugin/src/artifact/types.d.ts +28 -0
  408. package/dist/types/plugin/src/artifact/types.d.ts.map +1 -0
  409. package/dist/types/plugin/src/build/annotation.d.ts +14 -0
  410. package/dist/types/plugin/src/build/annotation.d.ts.map +1 -0
  411. package/dist/types/plugin/src/build/buildModifiers.d.ts +19 -0
  412. package/dist/types/plugin/src/build/buildModifiers.d.ts.map +1 -0
  413. package/dist/types/plugin/src/build/buildPrimitive.d.ts +15 -0
  414. package/dist/types/plugin/src/build/buildPrimitive.d.ts.map +1 -0
  415. package/dist/types/plugin/src/build/buildStates.d.ts +11 -0
  416. package/dist/types/plugin/src/build/buildStates.d.ts.map +1 -0
  417. package/dist/types/plugin/src/build/buildTheme.d.ts +4 -0
  418. package/dist/types/plugin/src/build/buildTheme.d.ts.map +1 -0
  419. package/dist/types/plugin/src/build/buildTypography.d.ts +5 -0
  420. package/dist/types/plugin/src/build/buildTypography.d.ts.map +1 -0
  421. package/dist/types/plugin/src/build/builders/buildDescriptionLookup.d.ts +3 -0
  422. package/dist/types/plugin/src/build/builders/buildDescriptionLookup.d.ts.map +1 -0
  423. package/dist/types/plugin/src/build/builders/buildFallbackChain.d.ts +8 -0
  424. package/dist/types/plugin/src/build/builders/buildFallbackChain.d.ts.map +1 -0
  425. package/dist/types/plugin/src/build/builders/buildModifierFamily.d.ts +6 -0
  426. package/dist/types/plugin/src/build/builders/buildModifierFamily.d.ts.map +1 -0
  427. package/dist/types/plugin/src/build/builders/buildModifiers.d.ts +3 -0
  428. package/dist/types/plugin/src/build/builders/buildModifiers.d.ts.map +1 -0
  429. package/dist/types/plugin/src/build/builders/buildPrimitive.d.ts +3 -0
  430. package/dist/types/plugin/src/build/builders/buildPrimitive.d.ts.map +1 -0
  431. package/dist/types/plugin/src/build/builders/buildSetsPrimitive.d.ts +6 -0
  432. package/dist/types/plugin/src/build/builders/buildSetsPrimitive.d.ts.map +1 -0
  433. package/dist/types/plugin/src/build/builders/buildSetsSemantic.d.ts +5 -0
  434. package/dist/types/plugin/src/build/builders/buildSetsSemantic.d.ts.map +1 -0
  435. package/dist/types/plugin/src/build/builders/buildStates.d.ts +6 -0
  436. package/dist/types/plugin/src/build/builders/buildStates.d.ts.map +1 -0
  437. package/dist/types/plugin/src/build/builders/buildSurfaces.d.ts +6 -0
  438. package/dist/types/plugin/src/build/builders/buildSurfaces.d.ts.map +1 -0
  439. package/dist/types/plugin/src/build/builders/buildTheme.d.ts +6 -0
  440. package/dist/types/plugin/src/build/builders/buildTheme.d.ts.map +1 -0
  441. package/dist/types/plugin/src/build/builders/buildTypography.d.ts +9 -0
  442. package/dist/types/plugin/src/build/builders/buildTypography.d.ts.map +1 -0
  443. package/dist/types/plugin/src/build/builders/convertCssValueToString.d.ts +6 -0
  444. package/dist/types/plugin/src/build/builders/convertCssValueToString.d.ts.map +1 -0
  445. package/dist/types/plugin/src/build/builders/emitTypographyDecls.d.ts +5 -0
  446. package/dist/types/plugin/src/build/builders/emitTypographyDecls.d.ts.map +1 -0
  447. package/dist/types/plugin/src/build/builders/index.d.ts +16 -0
  448. package/dist/types/plugin/src/build/builders/index.d.ts.map +1 -0
  449. package/dist/types/plugin/src/build/classification.d.ts +13 -0
  450. package/dist/types/plugin/src/build/classification.d.ts.map +1 -0
  451. package/dist/types/plugin/src/build/computeDeltas.d.ts +17 -0
  452. package/dist/types/plugin/src/build/computeDeltas.d.ts.map +1 -0
  453. package/dist/types/plugin/src/build/constants/format.d.ts +3 -0
  454. package/dist/types/plugin/src/build/constants/format.d.ts.map +1 -0
  455. package/dist/types/plugin/src/build/constants/header.d.ts +3 -0
  456. package/dist/types/plugin/src/build/constants/header.d.ts.map +1 -0
  457. package/dist/types/plugin/src/build/constants/interactiveRoles.d.ts +4 -0
  458. package/dist/types/plugin/src/build/constants/interactiveRoles.d.ts.map +1 -0
  459. package/dist/types/plugin/src/build/constants/surfaceSelectorMap.d.ts +3 -0
  460. package/dist/types/plugin/src/build/constants/surfaceSelectorMap.d.ts.map +1 -0
  461. package/dist/types/plugin/src/build/context.d.ts +30 -0
  462. package/dist/types/plugin/src/build/context.d.ts.map +1 -0
  463. package/dist/types/plugin/src/build/deltas.d.ts +27 -0
  464. package/dist/types/plugin/src/build/deltas.d.ts.map +1 -0
  465. package/dist/types/plugin/src/build/extractOklchL.d.ts +2 -0
  466. package/dist/types/plugin/src/build/extractOklchL.d.ts.map +1 -0
  467. package/dist/types/plugin/src/build/formatDelta.d.ts +2 -0
  468. package/dist/types/plugin/src/build/formatDelta.d.ts.map +1 -0
  469. package/dist/types/plugin/src/build/index.d.ts +17 -0
  470. package/dist/types/plugin/src/build/index.d.ts.map +1 -0
  471. package/dist/types/plugin/src/build/interactiveRoles.d.ts +4 -0
  472. package/dist/types/plugin/src/build/interactiveRoles.d.ts.map +1 -0
  473. package/dist/types/plugin/src/build/modifierIo.d.ts +40 -0
  474. package/dist/types/plugin/src/build/modifierIo.d.ts.map +1 -0
  475. package/dist/types/plugin/src/build/recoverPrimitiveRef.d.ts +17 -0
  476. package/dist/types/plugin/src/build/recoverPrimitiveRef.d.ts.map +1 -0
  477. package/dist/types/plugin/src/build/shims.d.ts +57 -0
  478. package/dist/types/plugin/src/build/shims.d.ts.map +1 -0
  479. package/dist/types/plugin/src/build/types.d.ts +51 -0
  480. package/dist/types/plugin/src/build/types.d.ts.map +1 -0
  481. package/dist/types/plugin/src/css-ast/addDeclarationUnique.d.ts +3 -0
  482. package/dist/types/plugin/src/css-ast/addDeclarationUnique.d.ts.map +1 -0
  483. package/dist/types/plugin/src/css-ast/createDeclaration.d.ts +4 -0
  484. package/dist/types/plugin/src/css-ast/createDeclaration.d.ts.map +1 -0
  485. package/dist/types/plugin/src/css-ast/decl.d.ts +4 -0
  486. package/dist/types/plugin/src/css-ast/decl.d.ts.map +1 -0
  487. package/dist/types/plugin/src/css-ast/declaration.d.ts +4 -0
  488. package/dist/types/plugin/src/css-ast/declaration.d.ts.map +1 -0
  489. package/dist/types/plugin/src/css-ast/hasDeclaration.d.ts +3 -0
  490. package/dist/types/plugin/src/css-ast/hasDeclaration.d.ts.map +1 -0
  491. package/dist/types/plugin/src/css-ast/index.d.ts +7 -0
  492. package/dist/types/plugin/src/css-ast/index.d.ts.map +1 -0
  493. package/dist/types/plugin/src/css-ast/printNode.d.ts +7 -0
  494. package/dist/types/plugin/src/css-ast/printNode.d.ts.map +1 -0
  495. package/dist/types/plugin/src/css-ast/printRules.d.ts +4 -0
  496. package/dist/types/plugin/src/css-ast/printRules.d.ts.map +1 -0
  497. package/dist/types/plugin/src/css-ast/rule.d.ts +4 -0
  498. package/dist/types/plugin/src/css-ast/rule.d.ts.map +1 -0
  499. package/dist/types/plugin/src/css-ast/types.d.ts +21 -0
  500. package/dist/types/plugin/src/css-ast/types.d.ts.map +1 -0
  501. package/dist/types/plugin/src/index.d.ts +15 -0
  502. package/dist/types/plugin/src/index.d.ts.map +1 -0
  503. package/dist/types/plugin/src/layers/index.d.ts +3 -0
  504. package/dist/types/plugin/src/layers/index.d.ts.map +1 -0
  505. package/dist/types/plugin/src/layers/resolveLayerConfig.d.ts +6 -0
  506. package/dist/types/plugin/src/layers/resolveLayerConfig.d.ts.map +1 -0
  507. package/dist/types/plugin/src/layers/types.d.ts +19 -0
  508. package/dist/types/plugin/src/layers/types.d.ts.map +1 -0
  509. package/dist/types/plugin/src/layers/wrapInLayer.d.ts +3 -0
  510. package/dist/types/plugin/src/layers/wrapInLayer.d.ts.map +1 -0
  511. package/dist/types/plugin/src/light-dark/buildLightDarkDeclarations.d.ts +3 -0
  512. package/dist/types/plugin/src/light-dark/buildLightDarkDeclarations.d.ts.map +1 -0
  513. package/dist/types/plugin/src/light-dark/index.d.ts +3 -0
  514. package/dist/types/plugin/src/light-dark/index.d.ts.map +1 -0
  515. package/dist/types/plugin/src/light-dark/types.d.ts +50 -0
  516. package/dist/types/plugin/src/light-dark/types.d.ts.map +1 -0
  517. package/dist/types/plugin/src/light-dark/wrapLightDark.d.ts +8 -0
  518. package/dist/types/plugin/src/light-dark/wrapLightDark.d.ts.map +1 -0
  519. package/dist/types/plugin/src/modifiers/buildModifierContextCSS.d.ts +3 -0
  520. package/dist/types/plugin/src/modifiers/buildModifierContextCSS.d.ts.map +1 -0
  521. package/dist/types/plugin/src/modifiers/computeModifierContext.d.ts +3 -0
  522. package/dist/types/plugin/src/modifiers/computeModifierContext.d.ts.map +1 -0
  523. package/dist/types/plugin/src/modifiers/getAliasTarget.d.ts +6 -0
  524. package/dist/types/plugin/src/modifiers/getAliasTarget.d.ts.map +1 -0
  525. package/dist/types/plugin/src/modifiers/index.d.ts +4 -0
  526. package/dist/types/plugin/src/modifiers/index.d.ts.map +1 -0
  527. package/dist/types/plugin/src/modifiers/types.d.ts +42 -0
  528. package/dist/types/plugin/src/modifiers/types.d.ts.map +1 -0
  529. package/dist/types/plugin/src/naming.d.ts +19 -0
  530. package/dist/types/plugin/src/naming.d.ts.map +1 -0
  531. package/dist/types/plugin/src/plugin/canonicalPlugin.d.ts +18 -0
  532. package/dist/types/plugin/src/plugin/canonicalPlugin.d.ts.map +1 -0
  533. package/dist/types/plugin/src/plugin/index.d.ts +7 -0
  534. package/dist/types/plugin/src/plugin/index.d.ts.map +1 -0
  535. package/dist/types/plugin/src/plugin/types.d.ts +36 -0
  536. package/dist/types/plugin/src/plugin/types.d.ts.map +1 -0
  537. package/dist/types/plugin/src/plugin.d.ts +18 -0
  538. package/dist/types/plugin/src/plugin.d.ts.map +1 -0
  539. package/dist/types/plugin/src/types.d.ts +188 -0
  540. package/dist/types/plugin/src/types.d.ts.map +1 -0
  541. package/dist/types/plugin/types.d.ts +36 -0
  542. package/dist/types/plugin/types.d.ts.map +1 -0
  543. package/dist/types/plugin.d.ts +5 -69
  544. package/dist/types/plugin.d.ts.map +1 -1
  545. package/dist/types/types/src/artifact/types.d.ts +152 -0
  546. package/dist/types/types/src/artifact/types.d.ts.map +1 -0
  547. package/dist/types/types/src/index.d.ts +3 -0
  548. package/dist/types/types/src/index.d.ts.map +1 -0
  549. package/dist/types/types.d.ts +11 -228
  550. package/dist/types/types.d.ts.map +1 -1
  551. package/package.json +32 -3
@@ -1,936 +1,8 @@
1
1
  /**
2
- * @canonical/terrazzo-plugin-css — Custom Terrazzo plugin for Canonical design tokens.
2
+ * Plugin composition-root shim.
3
3
  *
4
- * Generates CSS files from a single resolver:
5
- * sets.primitive.css — :root with primitive tokens
6
- * sets.semantic.css — :root with mode-invariant semantics (may be empty)
7
- * modifiers.theme.css — light-dark() colour tokens + delta vars
8
- * modifiers.typography.css — base + per-product typography
9
- * modifiers.{family}.css — modifier channel classes (one file per family)
10
- * modifiers.surfaces.css — surface channel classes
11
- * states.css — derived hover/active/disabled via * {}
12
- * tokens.json — LSP artifact
4
+ * Keeps the historical `plugin.ts` entry point while the implementation,
5
+ * its sidecar tests, and its option types live together under `plugin/`.
13
6
  */
14
- import { readFileSync } from "node:fs";
15
- import { transformCSSValue } from "@terrazzo/token-tools/css";
16
- import { makeArtifactToken, makeDerivedArtifactToken, serializeArtifact, } from "./artifact/index.js";
17
- import { decl, printRules, rule } from "./css-ast/index.js";
18
- import { resolveLayerConfig, wrapInLayer } from "./layers/index.js";
19
- import { buildLightDarkDeclarations } from "./light-dark/index.js";
20
- import { buildModifierContextCSS, computeModifierContext, } from "./modifiers/index.js";
21
- import { prefixVar, tokenIdToCssVar } from "./naming.js";
22
- // ---------------------------------------------------------------------------
23
- // Constants
24
- // ---------------------------------------------------------------------------
25
- const FORMAT = "canonical-css";
26
- const HEADER = "/* Generated by @canonical/terrazzo-plugin-css. DO NOT EDIT. */";
27
- // ---------------------------------------------------------------------------
28
- // Token classification helpers
29
- // ---------------------------------------------------------------------------
30
- /** Token IDs that belong to the primitive set. */
31
- function isPrimitive(id) {
32
- return (id.startsWith("color.palette.") ||
33
- id.startsWith("dimension.") ||
34
- id.startsWith("number.") ||
35
- id.startsWith("typography.fontFamily.") ||
36
- id.startsWith("typography.fontWeight.") ||
37
- id.startsWith("typography.fontStyle.") ||
38
- id.startsWith("typography.figureStyle.") ||
39
- id.startsWith("typography.textDecoration.") ||
40
- id.startsWith("typography.letterCase."));
41
- }
42
- /** Token IDs that are semantic colour tokens (from theme modifier). */
43
- function isSemanticColor(id) {
44
- return id.startsWith("color.") && !id.startsWith("color.palette.");
45
- }
46
- /** Token IDs that are semantic typography (from typography modifier). */
47
- function isSemanticTypography(id) {
48
- return id.startsWith("typography.") && !isPrimitive(id);
49
- }
50
- // ---------------------------------------------------------------------------
51
- // Transform value helper
52
- // ---------------------------------------------------------------------------
53
- /**
54
- * Coerce transformCSSValue output to a simple string (sRGB fallback for
55
- * wide-gamut, or the plain string). Returns null for multi-value
56
- * (typography composites) — those are handled separately.
57
- */
58
- function cssValueToString(val) {
59
- if (typeof val === "string")
60
- return val;
61
- if ("." in val)
62
- return val["."]; // WideGamutColorValue sRGB fallback
63
- return null; // multi-value (typography)
64
- }
65
- /**
66
- * Walk a DTCG token JSON tree and collect `$extensions.com.canonical.modifier.aliasOf`
67
- * entries and `$description` values, keyed by the dot-separated token ID path.
68
- *
69
- * @note Performs synchronous file I/O (readFileSync).
70
- */
71
- function extractModifierFileData(filePath) {
72
- const aliases = {};
73
- const descriptions = {};
74
- try {
75
- const raw = readFileSync(filePath, "utf8");
76
- const json = JSON.parse(raw);
77
- walkTokenTree(json, [], aliases, descriptions);
78
- }
79
- catch (err) {
80
- console.warn(`[canonical-css] Could not read modifier data from ${filePath}:`, err instanceof Error ? err.message : err);
81
- }
82
- return { aliases, descriptions };
83
- }
84
- /**
85
- * Recursively walk a DTCG token tree, collecting aliasOf entries and
86
- * `$description` values.
87
- *
88
- * When `$root` is encountered, the token ID is the parent path (the `$root`
89
- * marker is stripped per DTCG spec).
90
- */
91
- function walkTokenTree(node, path, aliases, descriptions) {
92
- if (typeof node !== "object" || node === null)
93
- return;
94
- const obj = node;
95
- // Check for $extensions at this level
96
- const ext = obj.$extensions;
97
- const modExt = ext?.["com.canonical.modifier"];
98
- if (modExt?.aliasOf && typeof modExt.aliasOf === "string") {
99
- const tokenId = path.join(".");
100
- aliases[tokenId] = modExt.aliasOf;
101
- }
102
- // Collect $description at this level (only for token nodes with $value)
103
- if ("$value" in obj &&
104
- "$description" in obj &&
105
- typeof obj.$description === "string") {
106
- const tokenId = path.join(".");
107
- descriptions[tokenId] = obj.$description;
108
- }
109
- // Recurse into children (skip $-prefixed keys except $root)
110
- for (const [key, value] of Object.entries(obj)) {
111
- if (key === "$root") {
112
- // $root collapses to the parent path
113
- walkTokenTree(value, path, aliases, descriptions);
114
- }
115
- else if (key.startsWith("$")) {
116
- }
117
- else {
118
- walkTokenTree(value, [...path, key], aliases, descriptions);
119
- }
120
- }
121
- }
122
- /**
123
- * Load modifier file data for a specific family context by reading the raw
124
- * token source files referenced in the resolver JSON.
125
- *
126
- * Returns both the alias map (token ID → aliasOf target) and the
127
- * description map (token ID → `$description` text).
128
- *
129
- * @note Performs synchronous file I/O (readFileSync + JSON.parse on the resolver).
130
- * @param tokensDir - Base directory for token sources (e.g. "./tokens/canonical")
131
- * @param family - Modifier family name (e.g. "anticipation")
132
- * @param context - Context name (e.g. "constructive")
133
- */
134
- function loadModifierData(tokensDir, family, context) {
135
- // Read the resolver JSON to find the $ref paths for this context
136
- const resolverPath = `${tokensDir}/canonical.resolver.json`;
137
- try {
138
- const resolverJson = JSON.parse(readFileSync(resolverPath, "utf8"));
139
- const refs = resolverJson.modifiers?.[family]?.contexts?.[context] ?? [];
140
- const aliases = {};
141
- const descriptions = {};
142
- for (const ref of refs) {
143
- if (ref.$ref) {
144
- const filePath = `${tokensDir}/${ref.$ref}`;
145
- const data = extractModifierFileData(filePath);
146
- Object.assign(aliases, data.aliases);
147
- Object.assign(descriptions, data.descriptions);
148
- }
149
- }
150
- return { aliases, descriptions };
151
- }
152
- catch (err) {
153
- console.warn(`[canonical-css] Could not load modifier data for ${family}/${context}:`, err instanceof Error ? err.message : err);
154
- return { aliases: {}, descriptions: {} };
155
- }
156
- }
157
- // ---------------------------------------------------------------------------
158
- // Public API
159
- // ---------------------------------------------------------------------------
160
- /**
161
- * Create the Canonical CSS plugin for Terrazzo.
162
- *
163
- * @example
164
- * ```ts
165
- * import { defineConfig } from "@terrazzo/cli";
166
- * import { canonicalPlugin } from "./src/plugin/plugin.js";
167
- *
168
- * export default defineConfig({
169
- * tokens: ["./tokens/canonical/canonical.resolver.json"],
170
- * plugins: [canonicalPlugin()],
171
- * });
172
- * ```
173
- */
174
- export function canonicalPlugin(options = {}) {
175
- const layers = resolveLayerConfig(options.layers);
176
- const tokensDir = options.tokensDir ?? "./tokens/canonical";
177
- const families = options.families ?? [
178
- "anticipation",
179
- "criticality",
180
- "emphasis",
181
- "importance",
182
- ];
183
- return {
184
- name: "@canonical/terrazzo-plugin-css",
185
- // ── transform() ────────────────────────────────────────────────────
186
- async transform({ tokens, setTransform, resolver, }) {
187
- // Base resolution (all defaults: light theme, global typography, small breakpoint)
188
- const baseSet = resolver.apply({});
189
- // Transform every token in the base resolution
190
- for (const [id, token] of Object.entries(baseSet)) {
191
- const cssVar = tokenIdToCssVar(id);
192
- const val = transformCSSValue(token, {
193
- tokensSet: baseSet,
194
- });
195
- const str = cssValueToString(val);
196
- if (str !== null) {
197
- setTransform(id, { format: FORMAT, localID: cssVar, value: str });
198
- }
199
- else {
200
- // Multi-value (typography composite) — emit each sub-property
201
- setTransform(id, {
202
- format: FORMAT,
203
- localID: cssVar,
204
- value: val,
205
- });
206
- }
207
- }
208
- // Dark theme — register additional transforms for colour tokens
209
- const darkSet = resolver.apply({ theme: "dark" });
210
- for (const [id, token] of Object.entries(darkSet)) {
211
- if (token.$type !== "color")
212
- continue;
213
- const cssVar = tokenIdToCssVar(id);
214
- const val = transformCSSValue(token, {
215
- tokensSet: darkSet,
216
- });
217
- const str = cssValueToString(val);
218
- if (str !== null) {
219
- setTransform(id, {
220
- format: FORMAT,
221
- localID: cssVar,
222
- value: str,
223
- input: { theme: "dark" },
224
- });
225
- }
226
- }
227
- // Typography product contexts
228
- for (const ctx of ["apps", "docs", "sites"]) {
229
- const typoSet = resolver.apply({ typography: ctx });
230
- for (const [id, token] of Object.entries(typoSet)) {
231
- if (!isSemanticTypography(id))
232
- continue;
233
- // setTransform requires the token ID to exist in the base `tokens`
234
- // map. Context-only tokens (e.g. typography.heading.display in sites)
235
- // must be skipped.
236
- if (!(id in tokens))
237
- continue;
238
- const cssVar = tokenIdToCssVar(id);
239
- const val = transformCSSValue(token, {
240
- tokensSet: typoSet,
241
- });
242
- const str = cssValueToString(val);
243
- if (str !== null) {
244
- setTransform(id, {
245
- format: FORMAT,
246
- localID: cssVar,
247
- value: str,
248
- input: { typography: ctx },
249
- });
250
- }
251
- else {
252
- setTransform(id, {
253
- format: FORMAT,
254
- localID: cssVar,
255
- value: val,
256
- input: { typography: ctx },
257
- });
258
- }
259
- }
260
- }
261
- },
262
- // ── build() ────────────────────────────────────────────────────────
263
- async build({ tokens, getTransforms, resolver, outputFile, }) {
264
- const artifact = {};
265
- // Capture CSS outputs so we can scan them for declaration positions
266
- const cssOutputs = new Map();
267
- const capturingOutputFile = (filename, contents) => {
268
- if (typeof contents === "string" && filename.endsWith(".css")) {
269
- cssOutputs.set(filename, contents);
270
- }
271
- outputFile(filename, contents);
272
- };
273
- // ── sets.primitive.css ───────────────────────────────────────────
274
- buildSetsPrimitive(getTransforms, layers, artifact, capturingOutputFile);
275
- // ── sets.semantic.css ───────────────────────────────────────────
276
- buildSetsSemantic(layers, capturingOutputFile);
277
- // ── modifiers.theme.css ─────────────────────────────────────────
278
- buildTheme(tokens, getTransforms, resolver, layers, artifact, capturingOutputFile);
279
- // ── modifiers.typography.css ────────────────────────────────────
280
- buildTypography(getTransforms, layers, artifact, capturingOutputFile);
281
- // ── modifiers.{family}.css ──────────────────────────────────────
282
- for (const family of families) {
283
- buildFamily(family, resolver, layers, artifact, capturingOutputFile, tokensDir);
284
- }
285
- // ── modifiers.surfaces.css ──────────────────────────────────────
286
- buildSurfaces(resolver, layers, artifact, capturingOutputFile, tokensDir);
287
- // ── states.css ──────────────────────────────────────────────────
288
- buildStates(tokens, resolver, layers, artifact, capturingOutputFile);
289
- // ── Annotate artifact with declaration positions ───────────────
290
- annotateDeclarations(artifact, cssOutputs);
291
- // ── tokens.json ─────────────────────────────────────────────────
292
- outputFile("tokens.json", serializeArtifact(artifact));
293
- },
294
- };
295
- }
296
- // ---------------------------------------------------------------------------
297
- // Build helpers
298
- //
299
- // @note All build* functions are impure: they mutate the `artifact` map and
300
- // call `outputFile()` to emit CSS files. They are called once per
301
- // build run from the plugin's `build()` hook.
302
- // ---------------------------------------------------------------------------
303
- /** @note Mutates `artifact`, calls `outputFile`. */
304
- function buildSetsPrimitive(getTransforms, layers, artifact, outputFile) {
305
- const transforms = getTransforms({ format: FORMAT });
306
- const nodes = [];
307
- for (const t of transforms) {
308
- if (!isPrimitive(t.id))
309
- continue;
310
- if (t.id.startsWith("number."))
311
- continue;
312
- // Skip dark / per-product permutations — only use the base
313
- if (t.input &&
314
- Object.keys(t.input).some((k) => k === "theme" && t.input[k] !== "light"))
315
- continue;
316
- if (t.input && "typography" in t.input && t.input.typography !== "global")
317
- continue;
318
- const cssVar = t.localID ?? tokenIdToCssVar(t.id);
319
- if (t.type === "SINGLE_VALUE") {
320
- nodes.push(decl(cssVar, t.value));
321
- artifact[cssVar] = makeArtifactToken({
322
- cssVar,
323
- id: t.id,
324
- type: t.token.$type ?? "unknown",
325
- tier: "primitive",
326
- cssOutputFile: "sets.primitive.css",
327
- description: t.token.$description,
328
- valueLight: t.value,
329
- valueDark: t.value,
330
- });
331
- }
332
- else {
333
- // Multi-value — emit each sub-property
334
- for (const [suffix, val] of Object.entries(t.value)) {
335
- const subVar = `${cssVar}-${suffix}`;
336
- nodes.push(decl(subVar, val));
337
- artifact[subVar] = makeArtifactToken({
338
- cssVar: subVar,
339
- id: `${t.id}.${suffix}`,
340
- type: t.token.$type ?? "unknown",
341
- tier: "primitive",
342
- cssOutputFile: "sets.primitive.css",
343
- description: t.token.$description,
344
- valueLight: val,
345
- valueDark: val,
346
- });
347
- }
348
- }
349
- }
350
- const wrapped = wrapInLayer(layers.tokens, [rule([":root"], nodes)]);
351
- outputFile("sets.primitive.css", `${HEADER}\n${printRules(wrapped)}\n`);
352
- }
353
- /** @note Calls `outputFile`. */
354
- function buildSetsSemantic(_layers, outputFile) {
355
- // In V2, most semantic tokens come via modifier contexts (theme, typography).
356
- // This file may be empty. Emit a comment-only placeholder.
357
- const comment = "/* sets.semantic.css — no mode-invariant semantic tokens in V2. */";
358
- outputFile("sets.semantic.css", `${HEADER}\n${comment}\n`);
359
- }
360
- /** @note Mutates `artifact`, calls `outputFile`. */
361
- function buildTheme(tokens, getTransforms, resolver, layers, artifact, outputFile) {
362
- // Collect base (light) and dark transforms for colour tokens
363
- const baseTransforms = getTransforms({ format: FORMAT });
364
- const darkTransforms = getTransforms({
365
- format: FORMAT,
366
- input: { theme: "dark" },
367
- });
368
- // Index dark transforms by token ID
369
- const darkById = new Map();
370
- for (const t of darkTransforms) {
371
- if (t.type !== "SINGLE_VALUE")
372
- continue;
373
- darkById.set(t.id, t.value);
374
- }
375
- // Build a reverse index: resolved literal value → primitive var name.
376
- // When a semantic token resolves to the same literal as a primitive,
377
- // we emit var(--primitive) instead of the raw oklch value. This keeps
378
- // the CSS and artifact connected to the primitive tokens rather than
379
- // resolving away the relationship.
380
- const primitiveByValue = new Map();
381
- for (const [cssVar, entry] of Object.entries(artifact)) {
382
- if (entry.tier === "primitive" &&
383
- entry.type === "color" &&
384
- entry.valueLight) {
385
- if (!primitiveByValue.has(entry.valueLight)) {
386
- primitiveByValue.set(entry.valueLight, cssVar);
387
- }
388
- }
389
- }
390
- // Build light-dark pairs for semantic colour tokens
391
- const pairs = [];
392
- const seenIds = new Set();
393
- for (const t of baseTransforms) {
394
- if (!isSemanticColor(t.id))
395
- continue;
396
- if (t.type !== "SINGLE_VALUE")
397
- continue;
398
- if (seenIds.has(t.id))
399
- continue;
400
- seenIds.add(t.id);
401
- const cssVar = t.localID ?? tokenIdToCssVar(t.id);
402
- const rawLight = t.value;
403
- const rawDark = darkById.get(t.id) ?? rawLight;
404
- // Recover var() references to primitives when the resolved literal
405
- // matches a known primitive value. Skip when the value already is a
406
- // var() reference (whole-token aliases preserved by Terrazzo).
407
- const lightVal = recoverPrimitiveRef(rawLight, cssVar, primitiveByValue);
408
- const darkVal = recoverPrimitiveRef(rawDark, cssVar, primitiveByValue);
409
- pairs.push({ property: cssVar, light: lightVal, dark: darkVal });
410
- artifact[cssVar] = makeArtifactToken({
411
- cssVar,
412
- id: t.id,
413
- type: "color",
414
- tier: "semantic",
415
- cssOutputFile: "modifiers.theme.css",
416
- description: t.token.$description,
417
- valueLight: lightVal,
418
- valueDark: darkVal,
419
- });
420
- }
421
- // Build CSS
422
- const themeDecls = buildLightDarkDeclarations(pairs);
423
- // Compute NativeState deltas (task 2.9)
424
- const { lightDeltaDecls, darkDeltaDecls } = computeDeltas(tokens, resolver, artifact);
425
- // Assemble :root block
426
- const rootNodes = [
427
- decl("color-scheme", "light dark"),
428
- ...themeDecls,
429
- ...lightDeltaDecls,
430
- ];
431
- const rootRule = rule([":root"], rootNodes);
432
- // Override selectors
433
- const lightOverride = rule([".light"], [decl("color-scheme", "light")]);
434
- const darkOverride = rule([".dark"], [decl("color-scheme", "dark"), ...darkDeltaDecls]);
435
- const mediaQuery = rule(["@media (prefers-color-scheme: dark)"], [rule([":root"], [decl("color-scheme", "dark"), ...darkDeltaDecls])]);
436
- const wrapped = wrapInLayer(layers.modifiers, [
437
- rootRule,
438
- lightOverride,
439
- darkOverride,
440
- mediaQuery,
441
- ]);
442
- outputFile("modifiers.theme.css", `${HEADER}\n${printRules(wrapped)}\n`);
443
- }
444
- /** @note Mutates `artifact`, calls `outputFile`. */
445
- function buildTypography(getTransforms, layers, artifact, outputFile) {
446
- const allNodes = [];
447
- // Base (global) typography → :root
448
- const baseTransforms = getTransforms({ format: FORMAT });
449
- const rootDecls = [];
450
- const seenIds = new Set();
451
- for (const t of baseTransforms) {
452
- if (!isSemanticTypography(t.id))
453
- continue;
454
- if (seenIds.has(t.id))
455
- continue;
456
- seenIds.add(t.id);
457
- emitTypographyDecls(t, rootDecls, artifact, "modifiers.typography.css");
458
- }
459
- allNodes.push(rule([":root"], rootDecls));
460
- // Per-product contexts → class selectors
461
- for (const ctx of ["apps", "docs", "sites"]) {
462
- const contextTransforms = getTransforms({
463
- format: FORMAT,
464
- input: { typography: ctx },
465
- });
466
- const contextDecls = [];
467
- for (const t of contextTransforms) {
468
- if (!isSemanticTypography(t.id))
469
- continue;
470
- emitTypographyDecls(t, contextDecls, artifact, "modifiers.typography.css");
471
- }
472
- if (contextDecls.length > 0) {
473
- allNodes.push(rule([`.${ctx}`], contextDecls));
474
- }
475
- }
476
- const wrapped = wrapInLayer(layers.modifiers, allNodes);
477
- outputFile("modifiers.typography.css", `${HEADER}\n${printRules(wrapped)}\n`);
478
- }
479
- function emitTypographyDecls(t, decls, artifact, outputFile) {
480
- const cssVar = t.localID ?? tokenIdToCssVar(t.id);
481
- if (t.type === "SINGLE_VALUE") {
482
- decls.push(decl(cssVar, t.value));
483
- artifact[cssVar] = makeArtifactToken({
484
- cssVar,
485
- id: t.id,
486
- type: t.token.$type ?? "unknown",
487
- tier: "semantic",
488
- cssOutputFile: outputFile,
489
- description: t.token.$description,
490
- valueLight: t.value,
491
- valueDark: t.value,
492
- });
493
- }
494
- else {
495
- // Multi-value: typography composite → individual sub-properties
496
- for (const [suffix, val] of Object.entries(t.value)) {
497
- const subVar = `${cssVar}-${suffix}`;
498
- decls.push(decl(subVar, val));
499
- artifact[subVar] = makeArtifactToken({
500
- cssVar: subVar,
501
- id: `${t.id}.${suffix}`,
502
- type: t.token.$type ?? "unknown",
503
- tier: "semantic",
504
- cssOutputFile: outputFile,
505
- description: t.token.$description,
506
- valueLight: val,
507
- valueDark: val,
508
- });
509
- }
510
- }
511
- }
512
- /** @note Mutates `artifact`, calls `outputFile` and `loadModifierData` (file I/O). */
513
- function buildFamily(family, resolver, layers, artifact, outputFile, tokensDir) {
514
- const baseTokens = resolver.apply({});
515
- const modifiers = resolver.source?.modifiers;
516
- const familyMod = modifiers?.[family];
517
- if (!familyMod?.contexts)
518
- return;
519
- const allNodes = [];
520
- for (const context of Object.keys(familyMod.contexts)) {
521
- if (context === "none")
522
- continue; // skip the empty default context
523
- const { aliases: aliasMap, descriptions } = loadModifierData(tokensDir, family, context);
524
- const overlayTokens = resolver.apply({ [family]: context });
525
- // Build channel-var → description lookup
526
- const descByChannelVar = buildDescriptionLookup(descriptions, "modifier");
527
- const ctx = computeModifierContext(family, context, baseTokens, overlayTokens, "modifier", aliasMap);
528
- const nodes = buildModifierContextCSS(ctx);
529
- allNodes.push(...nodes);
530
- // Register channel declarations in artifact
531
- for (const d of ctx.declarations) {
532
- artifact[d.property] = makeDerivedArtifactToken({
533
- cssVar: d.property,
534
- type: "color",
535
- tier: "semantic",
536
- cssOutputFile: `modifiers.${family}.css`,
537
- derivedFrom: d.value.replace(/^var\(/, "").replace(/\)$/, ""),
538
- derivation: "channel-modifier",
539
- description: descByChannelVar[d.property],
540
- });
541
- }
542
- }
543
- const wrapped = wrapInLayer(layers.modifiers, allNodes);
544
- outputFile(`modifiers.${family}.css`, `${HEADER}\n${printRules(wrapped)}\n`);
545
- }
546
- /**
547
- * Surface selector compounding: map resolver context names to compound
548
- * `.surface` descendant selectors based on depth.
549
- *
550
- * - layer1 → `.surface` (depth 1)
551
- * - layer2 → `.surface .surface` (depth 2)
552
- * - layer3 → `.surface .surface .surface` (depth 3, capped)
553
- */
554
- const SURFACE_SELECTOR_MAP = {
555
- layer1: ".surface",
556
- layer2: ".surface .surface",
557
- layer3: ".surface .surface .surface",
558
- };
559
- /** @note Mutates `artifact`, calls `outputFile` and `loadModifierData` (file I/O). */
560
- function buildSurfaces(resolver, layers, artifact, outputFile, tokensDir) {
561
- const baseTokens = resolver.apply({});
562
- const modifiers = resolver.source?.modifiers;
563
- const surfaceMod = modifiers?.surface;
564
- if (!surfaceMod?.contexts)
565
- return;
566
- const allNodes = [];
567
- for (const context of Object.keys(surfaceMod.contexts)) {
568
- if (context === "none")
569
- continue; // skip the empty default context
570
- const { aliases: aliasMap, descriptions } = loadModifierData(tokensDir, "surface", context);
571
- const overlayTokens = resolver.apply({ surface: context });
572
- // Build channel-var → description lookup
573
- const descByChannelVar = buildDescriptionLookup(descriptions, "surface");
574
- const ctx = computeModifierContext("surface", context, baseTokens, overlayTokens, "surface", aliasMap, SURFACE_SELECTOR_MAP[context]);
575
- const nodes = buildModifierContextCSS(ctx);
576
- allNodes.push(...nodes);
577
- for (const d of ctx.declarations) {
578
- artifact[d.property] = makeDerivedArtifactToken({
579
- cssVar: d.property,
580
- type: "color",
581
- tier: "semantic",
582
- cssOutputFile: "modifiers.surfaces.css",
583
- derivedFrom: d.value.replace(/^var\(/, "").replace(/\)$/, ""),
584
- derivation: "channel-surface",
585
- description: descByChannelVar[d.property],
586
- });
587
- }
588
- }
589
- const wrapped = wrapInLayer(layers.surfaces, allNodes);
590
- outputFile("modifiers.surfaces.css", `${HEADER}\n${printRules(wrapped)}\n`);
591
- }
592
- // ---------------------------------------------------------------------------
593
- // NativeState delta computation (task 2.9)
594
- // ---------------------------------------------------------------------------
595
- /** Interactive roles and their state variants. */
596
- const INTERACTIVE_ROLES = [
597
- {
598
- role: "color.foreground.primary",
599
- states: ["hover", "active", "disabled"],
600
- hasSurface: false,
601
- hasModifier: true,
602
- },
603
- {
604
- role: "color.foreground.secondary",
605
- states: ["hover", "active", "disabled"],
606
- hasSurface: false,
607
- hasModifier: true,
608
- },
609
- {
610
- role: "color.foreground.ghost",
611
- states: ["hover", "active", "disabled"],
612
- hasSurface: true,
613
- hasModifier: true,
614
- },
615
- {
616
- role: "color.foreground.input",
617
- states: ["hover", "active", "disabled"],
618
- hasSurface: true,
619
- hasModifier: true,
620
- },
621
- {
622
- role: "color.foreground.navigation.primary",
623
- states: ["hover", "active", "disabled"],
624
- hasSurface: true,
625
- hasModifier: false,
626
- },
627
- {
628
- role: "color.foreground.navigation.secondary",
629
- states: ["hover", "active", "disabled"],
630
- hasSurface: false,
631
- hasModifier: false,
632
- },
633
- {
634
- role: "color.foreground.checkbox.unselected",
635
- states: ["hover", "active", "disabled"],
636
- hasSurface: true,
637
- hasModifier: false,
638
- },
639
- {
640
- role: "color.foreground.radio.unselected",
641
- states: ["hover", "active", "disabled"],
642
- hasSurface: true,
643
- hasModifier: false,
644
- },
645
- {
646
- role: "color.foreground.checkbox.checkmark",
647
- states: ["disabled"],
648
- hasSurface: true,
649
- hasModifier: false,
650
- },
651
- {
652
- role: "color.foreground.radio.checkmark",
653
- states: ["disabled"],
654
- hasSurface: true,
655
- hasModifier: false,
656
- },
657
- {
658
- role: "color.foreground.switch.knob",
659
- states: ["disabled"],
660
- hasSurface: true,
661
- hasModifier: false,
662
- },
663
- {
664
- role: "color.border",
665
- states: ["disabled"],
666
- hasSurface: false,
667
- hasModifier: true,
668
- },
669
- {
670
- role: "color.text",
671
- states: ["disabled"],
672
- hasSurface: false,
673
- hasModifier: true,
674
- },
675
- {
676
- role: "color.icon",
677
- states: ["disabled"],
678
- hasSurface: false,
679
- hasModifier: true,
680
- },
681
- ];
682
- /**
683
- * Compute per-role lightness deltas for hover/active states.
684
- *
685
- * Deltas must be emitted as plain numbers — NOT wrapped in `light-dark()` —
686
- * because `var(--delta-*)` is consumed inside `calc()` inside `oklch(from ...)`,
687
- * and `light-dark()` inside `calc()` inside `oklch(from ...)` is broken in
688
- * Chromium (resolves to transparent). The chosen approach (per the design spec)
689
- * is: `:root` sets the light-mode delta as default, `.dark` and
690
- * `@media (prefers-color-scheme: dark)` override with dark-mode deltas.
691
- */
692
- function computeDeltas(_tokens, resolver, artifact) {
693
- const lightSet = resolver.apply({ theme: "light" });
694
- const darkSet = resolver.apply({ theme: "dark" });
695
- const lightDeltaDecls = [];
696
- const darkDeltaDecls = [];
697
- for (const { role, states } of INTERACTIVE_ROLES) {
698
- for (const state of states) {
699
- if (state === "disabled")
700
- continue; // disabled uses color-mix, no delta
701
- const stateId = `${role}.${state}`;
702
- const lightRest = lightSet[role];
703
- const lightState = lightSet[stateId];
704
- const darkRest = darkSet[role];
705
- const darkState = darkSet[stateId];
706
- if (!lightRest?.$value || !lightState?.$value)
707
- continue;
708
- if (!darkRest?.$value || !darkState?.$value)
709
- continue;
710
- const lightRestL = extractOklchL(lightRest.$value);
711
- const lightStateL = extractOklchL(lightState.$value);
712
- const darkRestL = extractOklchL(darkRest.$value);
713
- const darkStateL = extractOklchL(darkState.$value);
714
- if (lightRestL === null ||
715
- lightStateL === null ||
716
- darkRestL === null ||
717
- darkStateL === null)
718
- continue;
719
- const lightDelta = lightStateL - lightRestL;
720
- const darkDelta = darkStateL - darkRestL;
721
- const rolePath = tokenIdToCssVar(role).slice(2); // strip --
722
- const deltaVar = `--delta-${state}-${rolePath}`;
723
- // :root gets the light-mode delta (light is the default color-scheme)
724
- lightDeltaDecls.push(decl(deltaVar, formatDelta(lightDelta)));
725
- // .dark and @media override get the dark-mode delta
726
- darkDeltaDecls.push(decl(deltaVar, formatDelta(darkDelta)));
727
- artifact[deltaVar] = makeDerivedArtifactToken({
728
- cssVar: deltaVar,
729
- type: "number",
730
- tier: "derived",
731
- cssOutputFile: "modifiers.theme.css",
732
- derivedFrom: tokenIdToCssVar(role),
733
- derivation: "delta",
734
- valueLight: formatDelta(lightDelta),
735
- valueDark: formatDelta(darkDelta),
736
- });
737
- }
738
- }
739
- return { lightDeltaDecls, darkDeltaDecls };
740
- }
741
- function extractOklchL(value) {
742
- if (typeof value === "object" &&
743
- value !== null &&
744
- "colorSpace" in value &&
745
- value.colorSpace === "oklch" &&
746
- "components" in value &&
747
- Array.isArray(value.components)) {
748
- const l = value.components[0];
749
- return typeof l === "number" ? l : null;
750
- }
751
- return null;
752
- }
753
- function formatDelta(d) {
754
- // Round to 6 decimal places to avoid floating-point noise
755
- const rounded = Math.round(d * 1_000_000) / 1_000_000;
756
- return String(rounded);
757
- }
758
- // ---------------------------------------------------------------------------
759
- // states.css (task 2.10) — generated derivation layer
760
- // ---------------------------------------------------------------------------
761
- /** @note Mutates `artifact`, calls `outputFile`. */
762
- function buildStates(_tokens, _resolver, layers, artifact, outputFile) {
763
- const derivedDecls = [];
764
- for (const { role, states, hasSurface, hasModifier } of INTERACTIVE_ROLES) {
765
- const cssRole = tokenIdToCssVar(role); // e.g. --color-foreground-primary
766
- const rolePath = cssRole.slice(2); // color-foreground-primary
767
- // Build fallback chain: modifier → surface → base
768
- const restFallback = buildFallbackChain(cssRole, hasModifier, hasSurface);
769
- const bgFallback = buildFallbackChain("--color-background", false, true);
770
- for (const state of states) {
771
- const derivedVar = `--${state}--${rolePath}`;
772
- let formula;
773
- if (state === "disabled") {
774
- // color-mix(in oklch, <rest> 34%, <background>)
775
- formula = `color-mix(in oklch, ${restFallback} 34%, ${bgFallback})`;
776
- }
777
- else {
778
- // oklch(from <rest> calc(l + var(--delta-{state}-{role})) c h)
779
- const deltaVar = `--delta-${state}-${rolePath}`;
780
- formula = `oklch(from ${restFallback} calc(l + var(${deltaVar})) c h)`;
781
- }
782
- derivedDecls.push(decl(derivedVar, formula));
783
- artifact[derivedVar] = makeDerivedArtifactToken({
784
- cssVar: derivedVar,
785
- type: "color",
786
- tier: "derived",
787
- cssOutputFile: "states.css",
788
- derivedFrom: cssRole,
789
- derivation: state,
790
- });
791
- }
792
- }
793
- const starRule = rule(["*"], derivedDecls);
794
- const wrapped = wrapInLayer(layers.states, [starRule]);
795
- outputFile("states.css", `${HEADER}\n${printRules(wrapped)}\n`);
796
- }
797
- function buildFallbackChain(cssVar, hasModifier, hasSurface) {
798
- const modVar = prefixVar(cssVar, "modifier");
799
- const surfVar = prefixVar(cssVar, "surface");
800
- if (hasModifier && hasSurface) {
801
- return `var(${modVar}, var(${surfVar}, var(${cssVar})))`;
802
- }
803
- if (hasModifier) {
804
- return `var(${modVar}, var(${cssVar}))`;
805
- }
806
- if (hasSurface) {
807
- return `var(${surfVar}, var(${cssVar}))`;
808
- }
809
- return `var(${cssVar})`;
810
- }
811
- // ---------------------------------------------------------------------------
812
- // Declaration annotation
813
- // ---------------------------------------------------------------------------
814
- /**
815
- * Scan CSS output strings and annotate artifact tokens with their
816
- * declaration sites (selector, file, line).
817
- *
818
- * Parses each CSS file to find custom property declarations (`--var: ...`)
819
- * and records the enclosing selector and line number. Tokens appearing in
820
- * multiple selectors (e.g. modifier channels in `.warning`, `.error`, etc.)
821
- * accumulate all their declaration sites.
822
- */
823
- function annotateDeclarations(artifact, cssOutputs) {
824
- for (const [file, css] of cssOutputs) {
825
- const lines = css.split("\n");
826
- const selectorStack = [];
827
- const atRuleStack = [];
828
- let braceDepth = 0;
829
- // Track what was pushed at each brace depth so we can pop correctly.
830
- const depthContexts = [];
831
- for (let i = 0; i < lines.length; i++) {
832
- const line = lines[i];
833
- const trimmed = line.trim();
834
- // Track selector / at-rule entries: line ending with `{`
835
- if (trimmed.endsWith("{")) {
836
- const preceding = trimmed.slice(0, -1).trim();
837
- const atRuleMatch = preceding.match(/@(\w+)\s*(.*)/);
838
- if (atRuleMatch) {
839
- const atRule = {
840
- name: atRuleMatch[1],
841
- prelude: atRuleMatch[2]?.trim() ?? "",
842
- };
843
- atRuleStack.push(atRule);
844
- depthContexts[braceDepth] = { selector: null, atRule };
845
- }
846
- else {
847
- const selector = preceding || ":root";
848
- selectorStack.push(selector);
849
- depthContexts[braceDepth] = { selector, atRule: null };
850
- }
851
- braceDepth++;
852
- continue;
853
- }
854
- // Track block exits
855
- if (trimmed === "}") {
856
- braceDepth--;
857
- if (braceDepth >= 0) {
858
- const ctx = depthContexts[braceDepth];
859
- if (ctx?.selector)
860
- selectorStack.pop();
861
- if (ctx?.atRule)
862
- atRuleStack.pop();
863
- depthContexts[braceDepth] = { selector: null, atRule: null };
864
- }
865
- continue;
866
- }
867
- // Match custom property declarations
868
- const m = trimmed.match(/^(--[\w-]+)\s*:/);
869
- if (!m)
870
- continue;
871
- const cssVar = m[1];
872
- const entry = artifact[cssVar];
873
- if (!entry)
874
- continue;
875
- const selector = selectorStack[selectorStack.length - 1] ?? ":root";
876
- const decl = {
877
- selector,
878
- file,
879
- line: i,
880
- atRules: atRuleStack.length > 0
881
- ? atRuleStack.map((r) => ({ name: r.name, prelude: r.prelude }))
882
- : undefined,
883
- };
884
- if (entry.declarations) {
885
- entry.declarations.push(decl);
886
- }
887
- else {
888
- entry.declarations = [decl];
889
- }
890
- }
891
- }
892
- }
893
- // ---------------------------------------------------------------------------
894
- // Description lookup helper
895
- // ---------------------------------------------------------------------------
896
- /**
897
- * Build a map from channel CSS variable to description.
898
- *
899
- * Converts token IDs (e.g. `color.foreground.primary`) into their
900
- * channel CSS var form (e.g. `--modifier-color-foreground-primary`)
901
- * and maps each to its description.
902
- */
903
- function buildDescriptionLookup(descriptions, prefix) {
904
- const lookup = {};
905
- for (const [tokenId, desc] of Object.entries(descriptions)) {
906
- const channelVar = prefixVar(tokenIdToCssVar(tokenId), prefix);
907
- lookup[channelVar] = desc;
908
- }
909
- return lookup;
910
- }
911
- // ---------------------------------------------------------------------------
912
- // Primitive reference recovery
913
- // ---------------------------------------------------------------------------
914
- /**
915
- * Replace a resolved literal value with a `var()` reference to the matching
916
- * primitive token when one exists.
917
- *
918
- * Terrazzo resolves component-level `$ref` aliases to literal values during
919
- * `transformCSSValue`. This restores the semantic → primitive relationship
920
- * so the CSS output and artifact both reference the primitive custom property
921
- * instead of duplicating the raw value.
922
- *
923
- * Values that are already `var()` references (whole-token aliases preserved
924
- * by Terrazzo) are returned unchanged. Self-references are also skipped.
925
- */
926
- function recoverPrimitiveRef(value, selfCssVar, primitiveByValue) {
927
- // Already a var() reference — nothing to recover
928
- if (value.startsWith("var("))
929
- return value;
930
- const primitiveVar = primitiveByValue.get(value);
931
- if (primitiveVar && primitiveVar !== selfCssVar) {
932
- return `var(${primitiveVar})`;
933
- }
934
- return value;
935
- }
7
+ export { default } from "./plugin/index.js";
936
8
  //# sourceMappingURL=plugin.js.map