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