@thanhnguyxn/pixelcraft 0.0.0-stage → 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 (455) hide show
  1. package/.agents/plugins/marketplace.json +20 -0
  2. package/.antigravity-plugin/plugin.json +32 -0
  3. package/.claude-plugin/marketplace.json +20 -0
  4. package/.claude-plugin/plugin.json +22 -0
  5. package/.codex-plugin/plugin.json +45 -0
  6. package/.cursor-plugin/marketplace.json +17 -0
  7. package/.cursor-plugin/plugin.json +27 -0
  8. package/.devin-plugin/plugin.json +21 -0
  9. package/.github/plugin/marketplace.json +34 -0
  10. package/CHANGELOG.md +159 -0
  11. package/GEMINI.md +1 -0
  12. package/LICENSE +21 -0
  13. package/README.md +264 -2
  14. package/SECURITY.md +28 -0
  15. package/assets/README.md +28 -0
  16. package/assets/pixelcraft-logo-128.png +0 -0
  17. package/assets/pixelcraft-logo-256.png +0 -0
  18. package/assets/pixelcraft-logo-512.png +0 -0
  19. package/bin/pixelcraft.mjs +852 -0
  20. package/docs/ARCHITECTURE.md +105 -0
  21. package/docs/DESIGN-RATIONALE.md +191 -0
  22. package/docs/INSTALL.md +221 -0
  23. package/evals/README.md +37 -0
  24. package/evals/fixtures/3d-web-engineering.json +69 -0
  25. package/evals/fixtures/README.md +36 -0
  26. package/evals/fixtures/acceptance-checklist-rule03-gate.json +43 -0
  27. package/evals/fixtures/ai-ui-libraries.json +53 -0
  28. package/evals/fixtures/audio-visual-accessibility.json +69 -0
  29. package/evals/fixtures/auth-and-checkout-ui.json +53 -0
  30. package/evals/fixtures/brandkit-identity-governance.json +48 -0
  31. package/evals/fixtures/build-and-architecture.json +53 -0
  32. package/evals/fixtures/canvas-and-node-editors.json +53 -0
  33. package/evals/fixtures/chat-ai-exfiltration-ime-hitl-gate.json +43 -0
  34. package/evals/fixtures/completion-gate-scan-until-clean.json +44 -0
  35. package/evals/fixtures/component-systems.json +53 -0
  36. package/evals/fixtures/component-testing.json +53 -0
  37. package/evals/fixtures/constrained-voice-and-tv.json +43 -0
  38. package/evals/fixtures/creative-code-rendering.json +69 -0
  39. package/evals/fixtures/creative-reference-evidence.json +67 -0
  40. package/evals/fixtures/data-app-python-marimo.json +49 -0
  41. package/evals/fixtures/desktop-cpp-juce-audio.json +49 -0
  42. package/evals/fixtures/desktop-csharp-avalonia.json +49 -0
  43. package/evals/fixtures/desktop-native-workspace.json +48 -0
  44. package/evals/fixtures/desktop-python-anti-tkinter.json +49 -0
  45. package/evals/fixtures/direction-prototype-complexity.json +29 -0
  46. package/evals/fixtures/document-prepress-pdfx4-tounicode.json +43 -0
  47. package/evals/fixtures/document-rust-typst-invoice.json +49 -0
  48. package/evals/fixtures/document-typst-and-print-css.json +43 -0
  49. package/evals/fixtures/email-mjml-dark-mode.json +49 -0
  50. package/evals/fixtures/email-outlook-and-plaintext.json +43 -0
  51. package/evals/fixtures/enterprise-data-ui.json +53 -0
  52. package/evals/fixtures/extended-tui-toolkits.json +53 -0
  53. package/evals/fixtures/extensions-mv3-and-vscode.json +43 -0
  54. package/evals/fixtures/file-upload-media-ui.json +53 -0
  55. package/evals/fixtures/finish-gate-anti-slop.json +30 -0
  56. package/evals/fixtures/forms-accessibility-negative.json +29 -0
  57. package/evals/fixtures/forms-validation.json +53 -0
  58. package/evals/fixtures/game-go-ebitengine.json +49 -0
  59. package/evals/fixtures/game-godot-gdscript.json +49 -0
  60. package/evals/fixtures/game-ui-hud-and-engines.json +43 -0
  61. package/evals/fixtures/handoff-fidelity-tolerance.json +29 -0
  62. package/evals/fixtures/i18n-engineering.json +53 -0
  63. package/evals/fixtures/local-first-sync.json +53 -0
  64. package/evals/fixtures/lynxjs.json +53 -0
  65. package/evals/fixtures/maizzle-email.json +53 -0
  66. package/evals/fixtures/maps-geospatial.json +53 -0
  67. package/evals/fixtures/media-og-and-video-export.json +43 -0
  68. package/evals/fixtures/media-players.json +53 -0
  69. package/evals/fixtures/mobile-compose-16kb-foldable-store-gate.json +44 -0
  70. package/evals/fixtures/mobile-elixir-liveview-native.json +49 -0
  71. package/evals/fixtures/mobile-flutter-dynamic-type.json +49 -0
  72. package/evals/fixtures/mobile-harmonyos-arkui.json +49 -0
  73. package/evals/fixtures/mobile-jetpack-compose.json +49 -0
  74. package/evals/fixtures/mobile-swiftui-ios.json +49 -0
  75. package/evals/fixtures/motion-engineering.json +69 -0
  76. package/evals/fixtures/pdfjs-and-pptx.json +53 -0
  77. package/evals/fixtures/plan-brownfield-evidence.json +28 -0
  78. package/evals/fixtures/plan-discovery-interview.json +31 -0
  79. package/evals/fixtures/plan-grill-me-brainstorm-gate.json +49 -0
  80. package/evals/fixtures/reactive-data-apps.json +53 -0
  81. package/evals/fixtures/review-evidence-audit.json +43 -0
  82. package/evals/fixtures/rich-text-and-code-editors.json +53 -0
  83. package/evals/fixtures/scrollytelling-resilience.json +70 -0
  84. package/evals/fixtures/spatial-xr-comfort-and-platforms.json +43 -0
  85. package/evals/fixtures/state-architecture.json +53 -0
  86. package/evals/fixtures/styling-ecosystem.json +53 -0
  87. package/evals/fixtures/token-tooling.json +53 -0
  88. package/evals/fixtures/tui-go-bubbletea.json +49 -0
  89. package/evals/fixtures/tui-rust-ratatui-grapheme-paste-teardown.json +44 -0
  90. package/evals/fixtures/tui-rust-ratatui.json +49 -0
  91. package/evals/fixtures/ux-state-matrix-and-i18n.json +43 -0
  92. package/evals/fixtures/visual-qa-task-evidence.json +29 -0
  93. package/evals/fixtures/web-3d-engines.json +53 -0
  94. package/evals/fixtures/web-php-laravel-filament.json +49 -0
  95. package/evals/fixtures/web-ruby-viewcomponent-phlex.json +49 -0
  96. package/evals/fixtures/workflow-checkpoints.json +30 -0
  97. package/evals/pixelcraft-accessibility.md +74 -0
  98. package/evals/pixelcraft-brandkit.md +58 -0
  99. package/evals/pixelcraft-chat-ui.md +55 -0
  100. package/evals/pixelcraft-constrained.md +55 -0
  101. package/evals/pixelcraft-craft.md +76 -0
  102. package/evals/pixelcraft-data-apps.md +55 -0
  103. package/evals/pixelcraft-dataviz.md +59 -0
  104. package/evals/pixelcraft-desktop.md +55 -0
  105. package/evals/pixelcraft-direction.md +77 -0
  106. package/evals/pixelcraft-document.md +55 -0
  107. package/evals/pixelcraft-email.md +55 -0
  108. package/evals/pixelcraft-extensions.md +55 -0
  109. package/evals/pixelcraft-game-ui.md +59 -0
  110. package/evals/pixelcraft-handoff.md +57 -0
  111. package/evals/pixelcraft-media.md +55 -0
  112. package/evals/pixelcraft-mobile.md +59 -0
  113. package/evals/pixelcraft-patterns.md +73 -0
  114. package/evals/pixelcraft-plan.md +127 -0
  115. package/evals/pixelcraft-review.md +63 -0
  116. package/evals/pixelcraft-spatial.md +55 -0
  117. package/evals/pixelcraft-tokens.md +57 -0
  118. package/evals/pixelcraft-tui.md +55 -0
  119. package/evals/pixelcraft-ux.md +59 -0
  120. package/evals/pixelcraft-visual-qa.md +86 -0
  121. package/evals/pixelcraft-web.md +89 -0
  122. package/evals/pixelcraft.md +70 -0
  123. package/gemini-extension.json +6 -0
  124. package/install.ps1 +341 -0
  125. package/install.sh +512 -0
  126. package/package.json +91 -4
  127. package/plugin.json +29 -0
  128. package/scripts/build-adapters.mjs +288 -0
  129. package/scripts/build-release-archives.mjs +61 -0
  130. package/scripts/build-skill-zips.mjs +94 -0
  131. package/scripts/run-evals.mjs +397 -0
  132. package/scripts/sync-docs.mjs +381 -0
  133. package/scripts/test-build-adapters.mjs +61 -0
  134. package/scripts/test-cross-platform-qa.mjs +359 -0
  135. package/scripts/test-distribution.mjs +203 -0
  136. package/scripts/test-export-tokens.mjs +361 -0
  137. package/scripts/test-finish-gate.mjs +271 -0
  138. package/scripts/test-installers.mjs +216 -0
  139. package/scripts/test-release-archives.mjs +42 -0
  140. package/scripts/test-shoot.mjs +87 -0
  141. package/scripts/test-slop-scan.mjs +416 -0
  142. package/scripts/test-style-inventory.mjs +234 -0
  143. package/scripts/test-sync-docs.mjs +140 -0
  144. package/scripts/test-validate-skills.mjs +195 -0
  145. package/scripts/validate-skills.mjs +658 -0
  146. package/skills/pixelcraft/SKILL.md +155 -0
  147. package/skills/pixelcraft/references/design-brief.md +75 -0
  148. package/skills/pixelcraft/references/floor.md +90 -0
  149. package/skills/pixelcraft/references/report-template.md +49 -0
  150. package/skills/pixelcraft/references/stack-detection.md +226 -0
  151. package/skills/pixelcraft/references/surface-acceptance.md +52 -0
  152. package/skills/pixelcraft/references/workflow-checkpoints.md +71 -0
  153. package/skills/pixelcraft-accessibility/SKILL.md +54 -0
  154. package/skills/pixelcraft-accessibility/references/apg-patterns.md +64 -0
  155. package/skills/pixelcraft-accessibility/references/motion-canvas.md +57 -0
  156. package/skills/pixelcraft-accessibility/references/platforms.md +86 -0
  157. package/skills/pixelcraft-accessibility/references/verification.md +64 -0
  158. package/skills/pixelcraft-accessibility/references/wcag22-checks.md +99 -0
  159. package/skills/pixelcraft-brandkit/SKILL.md +127 -0
  160. package/skills/pixelcraft-brandkit/references/asset-pipeline.md +165 -0
  161. package/skills/pixelcraft-brandkit/references/brand-governance.md +82 -0
  162. package/skills/pixelcraft-brandkit/references/layouts.md +88 -0
  163. package/skills/pixelcraft-brandkit/references/logo-concepting.md +83 -0
  164. package/skills/pixelcraft-brandkit/references/logo-methods.md +97 -0
  165. package/skills/pixelcraft-brandkit/references/pixel-art-logos.md +82 -0
  166. package/skills/pixelcraft-brandkit/references/prompt-template.md +87 -0
  167. package/skills/pixelcraft-brandkit/references/qa-checklist.md +93 -0
  168. package/skills/pixelcraft-brandkit/references/visual-modes.md +123 -0
  169. package/skills/pixelcraft-chat-ui/SKILL.md +57 -0
  170. package/skills/pixelcraft-chat-ui/references/agentic-workspace.md +66 -0
  171. package/skills/pixelcraft-chat-ui/references/ai-ui-libraries.md +259 -0
  172. package/skills/pixelcraft-chat-ui/references/conversation-design.md +84 -0
  173. package/skills/pixelcraft-chat-ui/references/mobile-business-platforms.md +77 -0
  174. package/skills/pixelcraft-chat-ui/references/slack-discord.md +80 -0
  175. package/skills/pixelcraft-constrained/SKILL.md +52 -0
  176. package/skills/pixelcraft-constrained/references/specialized-hardware.md +90 -0
  177. package/skills/pixelcraft-constrained/references/tv-wearables.md +134 -0
  178. package/skills/pixelcraft-constrained/references/voice-ui.md +104 -0
  179. package/skills/pixelcraft-craft/SKILL.md +58 -0
  180. package/skills/pixelcraft-craft/references/color.md +125 -0
  181. package/skills/pixelcraft-craft/references/imagery-icons.md +37 -0
  182. package/skills/pixelcraft-craft/references/layout-quality.md +65 -0
  183. package/skills/pixelcraft-craft/references/layout.md +73 -0
  184. package/skills/pixelcraft-craft/references/motion.md +163 -0
  185. package/skills/pixelcraft-craft/references/typography.md +110 -0
  186. package/skills/pixelcraft-data-apps/SKILL.md +86 -0
  187. package/skills/pixelcraft-data-apps/references/ai-and-internal-data-apps.md +147 -0
  188. package/skills/pixelcraft-data-apps/references/dash.md +109 -0
  189. package/skills/pixelcraft-data-apps/references/evidence.md +90 -0
  190. package/skills/pixelcraft-data-apps/references/gradio.md +103 -0
  191. package/skills/pixelcraft-data-apps/references/julia-genie.md +89 -0
  192. package/skills/pixelcraft-data-apps/references/jupyter-widgets.md +91 -0
  193. package/skills/pixelcraft-data-apps/references/nicegui.md +102 -0
  194. package/skills/pixelcraft-data-apps/references/observable-framework.md +105 -0
  195. package/skills/pixelcraft-data-apps/references/panel.md +99 -0
  196. package/skills/pixelcraft-data-apps/references/r-shiny.md +124 -0
  197. package/skills/pixelcraft-data-apps/references/reactive-data-apps.md +186 -0
  198. package/skills/pixelcraft-data-apps/references/reflex.md +116 -0
  199. package/skills/pixelcraft-data-apps/references/shiny.md +110 -0
  200. package/skills/pixelcraft-data-apps/references/streamlit.md +113 -0
  201. package/skills/pixelcraft-dataviz/SKILL.md +60 -0
  202. package/skills/pixelcraft-dataviz/references/chart-choice.md +55 -0
  203. package/skills/pixelcraft-dataviz/references/color-accessibility.md +112 -0
  204. package/skills/pixelcraft-dataviz/references/encoding-tables-dashboards.md +107 -0
  205. package/skills/pixelcraft-dataviz/references/libraries.md +176 -0
  206. package/skills/pixelcraft-dataviz/references/maps-geospatial.md +159 -0
  207. package/skills/pixelcraft-dataviz/references/realtime-graphs-maps-scale.md +92 -0
  208. package/skills/pixelcraft-desktop/SKILL.md +93 -0
  209. package/skills/pixelcraft-desktop/references/appkit.md +92 -0
  210. package/skills/pixelcraft-desktop/references/avalonia.md +95 -0
  211. package/skills/pixelcraft-desktop/references/cpp-gui.md +129 -0
  212. package/skills/pixelcraft-desktop/references/electron.md +96 -0
  213. package/skills/pixelcraft-desktop/references/go-gui.md +83 -0
  214. package/skills/pixelcraft-desktop/references/gtk.md +97 -0
  215. package/skills/pixelcraft-desktop/references/javafx-swing.md +81 -0
  216. package/skills/pixelcraft-desktop/references/qt-pyside-qml.md +88 -0
  217. package/skills/pixelcraft-desktop/references/rust-gui.md +83 -0
  218. package/skills/pixelcraft-desktop/references/tauri.md +110 -0
  219. package/skills/pixelcraft-desktop/references/uno-platform.md +71 -0
  220. package/skills/pixelcraft-desktop/references/winui-wpf.md +98 -0
  221. package/skills/pixelcraft-desktop/references/working-context.md +84 -0
  222. package/skills/pixelcraft-direction/SKILL.md +120 -0
  223. package/skills/pixelcraft-direction/references/composition-library.md +84 -0
  224. package/skills/pixelcraft-direction/references/creative-brainstorming.md +72 -0
  225. package/skills/pixelcraft-direction/references/direction-card.md +64 -0
  226. package/skills/pixelcraft-direction/references/direction-scoring.md +76 -0
  227. package/skills/pixelcraft-direction/references/motion-identity.md +67 -0
  228. package/skills/pixelcraft-direction/references/movements.md +71 -0
  229. package/skills/pixelcraft-direction/references/reference-analysis.md +37 -0
  230. package/skills/pixelcraft-direction/references/repetition-history.md +75 -0
  231. package/skills/pixelcraft-direction/references/slop-fingerprints.md +83 -0
  232. package/skills/pixelcraft-direction/references/wildcards.md +47 -0
  233. package/skills/pixelcraft-document/SKILL.md +58 -0
  234. package/skills/pixelcraft-document/references/archetypes.md +106 -0
  235. package/skills/pixelcraft-document/references/pdf-tools.md +314 -0
  236. package/skills/pixelcraft-document/references/pdfjs-and-pptx.md +114 -0
  237. package/skills/pixelcraft-document/references/print-css.md +187 -0
  238. package/skills/pixelcraft-document/references/slides.md +198 -0
  239. package/skills/pixelcraft-email/SKILL.md +80 -0
  240. package/skills/pixelcraft-email/references/client-quirks.md +113 -0
  241. package/skills/pixelcraft-email/references/html-tables.md +114 -0
  242. package/skills/pixelcraft-email/references/maizzle.md +54 -0
  243. package/skills/pixelcraft-email/references/mjml.md +54 -0
  244. package/skills/pixelcraft-email/references/react-email.md +95 -0
  245. package/skills/pixelcraft-extensions/SKILL.md +56 -0
  246. package/skills/pixelcraft-extensions/references/browser-extensions.md +105 -0
  247. package/skills/pixelcraft-extensions/references/figma-office.md +106 -0
  248. package/skills/pixelcraft-extensions/references/ide-and-saas-plugins.md +125 -0
  249. package/skills/pixelcraft-extensions/references/raycast.md +98 -0
  250. package/skills/pixelcraft-extensions/references/vscode-webviews.md +100 -0
  251. package/skills/pixelcraft-game-ui/SKILL.md +80 -0
  252. package/skills/pixelcraft-game-ui/references/bevy.md +90 -0
  253. package/skills/pixelcraft-game-ui/references/godot.md +130 -0
  254. package/skills/pixelcraft-game-ui/references/hud-principles.md +67 -0
  255. package/skills/pixelcraft-game-ui/references/love2d.md +77 -0
  256. package/skills/pixelcraft-game-ui/references/monogame.md +68 -0
  257. package/skills/pixelcraft-game-ui/references/unity-ugui.md +109 -0
  258. package/skills/pixelcraft-game-ui/references/unity-ui-toolkit.md +107 -0
  259. package/skills/pixelcraft-game-ui/references/unreal-umg.md +80 -0
  260. package/skills/pixelcraft-game-ui/references/web-and-middleware-game-ui.md +122 -0
  261. package/skills/pixelcraft-handoff/SKILL.md +50 -0
  262. package/skills/pixelcraft-handoff/references/design-translation.md +134 -0
  263. package/skills/pixelcraft-handoff/references/fidelity-tolerance.md +78 -0
  264. package/skills/pixelcraft-handoff/references/motion-handoff.md +54 -0
  265. package/skills/pixelcraft-media/SKILL.md +49 -0
  266. package/skills/pixelcraft-media/references/banners-video.md +130 -0
  267. package/skills/pixelcraft-media/references/og-generation.md +154 -0
  268. package/skills/pixelcraft-media/references/social-cards.md +71 -0
  269. package/skills/pixelcraft-mobile/SKILL.md +86 -0
  270. package/skills/pixelcraft-mobile/references/dotnet-maui.md +91 -0
  271. package/skills/pixelcraft-mobile/references/flet.md +80 -0
  272. package/skills/pixelcraft-mobile/references/flutter.md +113 -0
  273. package/skills/pixelcraft-mobile/references/harmonyos-and-emerging-mobile.md +121 -0
  274. package/skills/pixelcraft-mobile/references/ionic-capacitor.md +87 -0
  275. package/skills/pixelcraft-mobile/references/jetpack-compose.md +129 -0
  276. package/skills/pixelcraft-mobile/references/kivy.md +82 -0
  277. package/skills/pixelcraft-mobile/references/kotlin-multiplatform.md +86 -0
  278. package/skills/pixelcraft-mobile/references/lynxjs.md +110 -0
  279. package/skills/pixelcraft-mobile/references/nativescript-and-skip.md +91 -0
  280. package/skills/pixelcraft-mobile/references/react-native-expo.md +106 -0
  281. package/skills/pixelcraft-mobile/references/swiftui.md +200 -0
  282. package/skills/pixelcraft-mobile/references/tactile-interactions.md +55 -0
  283. package/skills/pixelcraft-mobile/references/task-state-composition.md +85 -0
  284. package/skills/pixelcraft-mobile/references/uikit.md +92 -0
  285. package/skills/pixelcraft-patterns/SKILL.md +75 -0
  286. package/skills/pixelcraft-patterns/references/accessibility-resilience.md +29 -0
  287. package/skills/pixelcraft-patterns/references/ai-and-offline-patterns.md +54 -0
  288. package/skills/pixelcraft-patterns/references/auth-onboarding.md +44 -0
  289. package/skills/pixelcraft-patterns/references/billing-paywalls.md +40 -0
  290. package/skills/pixelcraft-patterns/references/command-workspace.md +56 -0
  291. package/skills/pixelcraft-patterns/references/commerce.md +47 -0
  292. package/skills/pixelcraft-patterns/references/communication.md +45 -0
  293. package/skills/pixelcraft-patterns/references/creative-tools.md +42 -0
  294. package/skills/pixelcraft-patterns/references/creative-web-composition.md +38 -0
  295. package/skills/pixelcraft-patterns/references/dashboard-admin.md +35 -0
  296. package/skills/pixelcraft-patterns/references/history-diff-undo.md +50 -0
  297. package/skills/pixelcraft-patterns/references/marketing.md +44 -0
  298. package/skills/pixelcraft-patterns/references/multi-tenant-rbac.md +47 -0
  299. package/skills/pixelcraft-patterns/references/narrative-systems.md +42 -0
  300. package/skills/pixelcraft-patterns/references/notifications-activity.md +57 -0
  301. package/skills/pixelcraft-patterns/references/pattern-selection.md +80 -0
  302. package/skills/pixelcraft-patterns/references/scheduling-kanban.md +47 -0
  303. package/skills/pixelcraft-patterns/references/scroll-implementation.md +37 -0
  304. package/skills/pixelcraft-patterns/references/search-filtering.md +42 -0
  305. package/skills/pixelcraft-patterns/references/settings.md +51 -0
  306. package/skills/pixelcraft-patterns/references/tables-crud.md +43 -0
  307. package/skills/pixelcraft-plan/SKILL.md +103 -0
  308. package/skills/pixelcraft-plan/references/design-input.md +69 -0
  309. package/skills/pixelcraft-plan/references/discovery-interview.md +110 -0
  310. package/skills/pixelcraft-plan/references/grill-me-protocol.md +63 -0
  311. package/skills/pixelcraft-plan/references/plan-template.md +134 -0
  312. package/skills/pixelcraft-plan/references/repo-discovery.md +49 -0
  313. package/skills/pixelcraft-plan/references/stack-freshness.md +67 -0
  314. package/skills/pixelcraft-plan/references/stack-selection.md +98 -0
  315. package/skills/pixelcraft-review/SKILL.md +86 -0
  316. package/skills/pixelcraft-review/references/audit-report.md +69 -0
  317. package/skills/pixelcraft-review/references/critique-protocol.md +89 -0
  318. package/skills/pixelcraft-review/references/heuristics.md +63 -0
  319. package/skills/pixelcraft-review/references/personas.md +53 -0
  320. package/skills/pixelcraft-review/references/polish.md +78 -0
  321. package/skills/pixelcraft-review/scripts/check-acceptance.mjs +619 -0
  322. package/skills/pixelcraft-review/scripts/fixtures/brand-critique-waivers.json +14 -0
  323. package/skills/pixelcraft-review/scripts/fixtures/brand-critique.css +18 -0
  324. package/skills/pixelcraft-review/scripts/fixtures/clean.html +43 -0
  325. package/skills/pixelcraft-review/scripts/fixtures/focus-after-block.css +4 -0
  326. package/skills/pixelcraft-review/scripts/fixtures/focus-at-rules.css +17 -0
  327. package/skills/pixelcraft-review/scripts/fixtures/focus-comments.css +10 -0
  328. package/skills/pixelcraft-review/scripts/fixtures/focus-html-quote-leak.html +12 -0
  329. package/skills/pixelcraft-review/scripts/fixtures/focus-invalid-replacements.css +27 -0
  330. package/skills/pixelcraft-review/scripts/fixtures/focus-longhand-removal.css +34 -0
  331. package/skills/pixelcraft-review/scripts/fixtures/focus-nested-rules.css +19 -0
  332. package/skills/pixelcraft-review/scripts/fixtures/focus-not-visible-skip.css +8 -0
  333. package/skills/pixelcraft-review/scripts/fixtures/focus-outline-shorthands.css +11 -0
  334. package/skills/pixelcraft-review/scripts/fixtures/focus-unknown-and-border.css +15 -0
  335. package/skills/pixelcraft-review/scripts/fixtures/focus-unknown-last-wins.css +19 -0
  336. package/skills/pixelcraft-review/scripts/fixtures/focus-valid-replacements-extended.css +29 -0
  337. package/skills/pixelcraft-review/scripts/fixtures/focus-visible-no-replacement.css +3 -0
  338. package/skills/pixelcraft-review/scripts/fixtures/focus-visible-valid-replacements.css +9 -0
  339. package/skills/pixelcraft-review/scripts/fixtures/slop.html +28 -0
  340. package/skills/pixelcraft-review/scripts/slop-scan.mjs +1233 -0
  341. package/skills/pixelcraft-spatial/SKILL.md +51 -0
  342. package/skills/pixelcraft-spatial/references/comfort-accessibility.md +39 -0
  343. package/skills/pixelcraft-spatial/references/platforms.md +147 -0
  344. package/skills/pixelcraft-tokens/SKILL.md +60 -0
  345. package/skills/pixelcraft-tokens/assets/tokens.example.json +71 -0
  346. package/skills/pixelcraft-tokens/assets/tokens.modes.example.json +47 -0
  347. package/skills/pixelcraft-tokens/references/adoption.md +55 -0
  348. package/skills/pixelcraft-tokens/references/format.md +84 -0
  349. package/skills/pixelcraft-tokens/references/governance.md +80 -0
  350. package/skills/pixelcraft-tokens/references/state-tokens.md +62 -0
  351. package/skills/pixelcraft-tokens/references/theme-presets.md +122 -0
  352. package/skills/pixelcraft-tokens/references/token-tooling.md +119 -0
  353. package/skills/pixelcraft-tokens/scripts/export-tokens.mjs +847 -0
  354. package/skills/pixelcraft-tui/SKILL.md +76 -0
  355. package/skills/pixelcraft-tui/references/bubbletea-lipgloss.md +79 -0
  356. package/skills/pixelcraft-tui/references/extended-tui-toolkits.md +127 -0
  357. package/skills/pixelcraft-tui/references/ink.md +109 -0
  358. package/skills/pixelcraft-tui/references/ratatui.md +102 -0
  359. package/skills/pixelcraft-tui/references/rich.md +82 -0
  360. package/skills/pixelcraft-tui/references/terminal-protocols.md +80 -0
  361. package/skills/pixelcraft-tui/references/textual.md +108 -0
  362. package/skills/pixelcraft-ux/SKILL.md +56 -0
  363. package/skills/pixelcraft-ux/references/cognitive-walkthrough.md +70 -0
  364. package/skills/pixelcraft-ux/references/feedback-performance.md +50 -0
  365. package/skills/pixelcraft-ux/references/flows-ia.md +44 -0
  366. package/skills/pixelcraft-ux/references/forms.md +151 -0
  367. package/skills/pixelcraft-ux/references/i18n.md +221 -0
  368. package/skills/pixelcraft-ux/references/laws.md +39 -0
  369. package/skills/pixelcraft-ux/references/locale-test-matrix.md +60 -0
  370. package/skills/pixelcraft-ux/references/state-matrix.md +53 -0
  371. package/skills/pixelcraft-ux/references/usability-testing.md +84 -0
  372. package/skills/pixelcraft-ux/references/ux-writing.md +44 -0
  373. package/skills/pixelcraft-visual-qa/SKILL.md +96 -0
  374. package/skills/pixelcraft-visual-qa/references/baseline-governance.md +70 -0
  375. package/skills/pixelcraft-visual-qa/references/capture-desktop-game.md +59 -0
  376. package/skills/pixelcraft-visual-qa/references/capture-document.md +70 -0
  377. package/skills/pixelcraft-visual-qa/references/capture-email.md +38 -0
  378. package/skills/pixelcraft-visual-qa/references/capture-mobile.md +50 -0
  379. package/skills/pixelcraft-visual-qa/references/capture-terminal.md +35 -0
  380. package/skills/pixelcraft-visual-qa/references/critique-rubric.md +71 -0
  381. package/skills/pixelcraft-visual-qa/references/finish-gate.md +35 -0
  382. package/skills/pixelcraft-visual-qa/references/measured-craft.md +30 -0
  383. package/skills/pixelcraft-visual-qa/references/motion-capture.md +63 -0
  384. package/skills/pixelcraft-visual-qa/references/performance-budgets.md +78 -0
  385. package/skills/pixelcraft-visual-qa/references/realtime-graphics.md +55 -0
  386. package/skills/pixelcraft-visual-qa/references/task-verification.md +81 -0
  387. package/skills/pixelcraft-visual-qa/scripts/check-contrast.mjs +442 -0
  388. package/skills/pixelcraft-visual-qa/scripts/check-email.mjs +397 -0
  389. package/skills/pixelcraft-visual-qa/scripts/check-pdf.mjs +189 -0
  390. package/skills/pixelcraft-visual-qa/scripts/check-tui.mjs +321 -0
  391. package/skills/pixelcraft-visual-qa/scripts/finish-gate.mjs +174 -0
  392. package/skills/pixelcraft-visual-qa/scripts/fixtures/shoot-aria-modal.html +19 -0
  393. package/skills/pixelcraft-visual-qa/scripts/fixtures/shoot-audit.html +34 -0
  394. package/skills/pixelcraft-visual-qa/scripts/fixtures/shoot-modal.html +17 -0
  395. package/skills/pixelcraft-visual-qa/scripts/fixtures/style-inventory-deferred.js +1 -0
  396. package/skills/pixelcraft-visual-qa/scripts/fixtures/style-inventory-edge.html +52 -0
  397. package/skills/pixelcraft-visual-qa/scripts/fixtures/style-inventory.html +80 -0
  398. package/skills/pixelcraft-visual-qa/scripts/fixtures/style-inventory.js +8 -0
  399. package/skills/pixelcraft-visual-qa/scripts/shoot.mjs +668 -0
  400. package/skills/pixelcraft-visual-qa/scripts/style-inventory.mjs +1226 -0
  401. package/skills/pixelcraft-web/SKILL.md +132 -0
  402. package/skills/pixelcraft-web/references/accessibility-performance.md +42 -0
  403. package/skills/pixelcraft-web/references/adaptive-layout.md +69 -0
  404. package/skills/pixelcraft-web/references/angular.md +108 -0
  405. package/skills/pixelcraft-web/references/assets-pipeline.md +67 -0
  406. package/skills/pixelcraft-web/references/astro.md +113 -0
  407. package/skills/pixelcraft-web/references/audio-reactive.md +61 -0
  408. package/skills/pixelcraft-web/references/auth-and-checkout-ui.md +115 -0
  409. package/skills/pixelcraft-web/references/build-and-architecture.md +215 -0
  410. package/skills/pixelcraft-web/references/canvas-and-node-editors.md +157 -0
  411. package/skills/pixelcraft-web/references/clojurescript.md +88 -0
  412. package/skills/pixelcraft-web/references/component-systems.md +102 -0
  413. package/skills/pixelcraft-web/references/component-testing.md +170 -0
  414. package/skills/pixelcraft-web/references/creative-effects.md +59 -0
  415. package/skills/pixelcraft-web/references/creative-runtime.md +34 -0
  416. package/skills/pixelcraft-web/references/elm.md +53 -0
  417. package/skills/pixelcraft-web/references/enterprise-data-ui.md +138 -0
  418. package/skills/pixelcraft-web/references/file-upload-media-ui.md +82 -0
  419. package/skills/pixelcraft-web/references/forms-validation.md +123 -0
  420. package/skills/pixelcraft-web/references/fsharp-fable.md +54 -0
  421. package/skills/pixelcraft-web/references/gsap.md +102 -0
  422. package/skills/pixelcraft-web/references/html-css.md +220 -0
  423. package/skills/pixelcraft-web/references/htmx-alpine.md +103 -0
  424. package/skills/pixelcraft-web/references/i18n-engineering.md +106 -0
  425. package/skills/pixelcraft-web/references/interaction-and-search-primitives.md +196 -0
  426. package/skills/pixelcraft-web/references/java-web.md +61 -0
  427. package/skills/pixelcraft-web/references/kotlin-web.md +57 -0
  428. package/skills/pixelcraft-web/references/leptos-yew.md +97 -0
  429. package/skills/pixelcraft-web/references/lit-web-components.md +63 -0
  430. package/skills/pixelcraft-web/references/local-first-sync.md +105 -0
  431. package/skills/pixelcraft-web/references/media-players.md +104 -0
  432. package/skills/pixelcraft-web/references/motion-react.md +96 -0
  433. package/skills/pixelcraft-web/references/motion-recipes.md +82 -0
  434. package/skills/pixelcraft-web/references/preact-fresh-hono.md +111 -0
  435. package/skills/pixelcraft-web/references/pwa.md +230 -0
  436. package/skills/pixelcraft-web/references/qwik.md +94 -0
  437. package/skills/pixelcraft-web/references/r3f-integration.md +69 -0
  438. package/skills/pixelcraft-web/references/react-next.md +168 -0
  439. package/skills/pixelcraft-web/references/rendering-choice.md +63 -0
  440. package/skills/pixelcraft-web/references/rendering-performance.md +80 -0
  441. package/skills/pixelcraft-web/references/rich-text-and-code-editors.md +220 -0
  442. package/skills/pixelcraft-web/references/rive-lottie.md +73 -0
  443. package/skills/pixelcraft-web/references/scala-laminar.md +53 -0
  444. package/skills/pixelcraft-web/references/scene-architecture.md +132 -0
  445. package/skills/pixelcraft-web/references/server-rendered.md +114 -0
  446. package/skills/pixelcraft-web/references/shader-workflow.md +77 -0
  447. package/skills/pixelcraft-web/references/smooth-scroll.md +58 -0
  448. package/skills/pixelcraft-web/references/solid.md +111 -0
  449. package/skills/pixelcraft-web/references/state-architecture.md +107 -0
  450. package/skills/pixelcraft-web/references/styling-ecosystem.md +273 -0
  451. package/skills/pixelcraft-web/references/svelte.md +111 -0
  452. package/skills/pixelcraft-web/references/tailwind.md +99 -0
  453. package/skills/pixelcraft-web/references/video-media.md +69 -0
  454. package/skills/pixelcraft-web/references/vue-nuxt.md +86 -0
  455. package/skills/pixelcraft-web/references/web-3d-engines.md +97 -0
@@ -0,0 +1,847 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+
5
+ const formats = [
6
+ 'css', 'tailwind', 'swift', 'kotlin', 'dart', 'python', 'qt', 'textual',
7
+ 'ts', 'scss', 'xaml', 'android-xml', 'rust',
8
+ 'go-lipgloss', 'godot', 'unity-uss', 'slint', 'gtk4', 'typst',
9
+ ];
10
+
11
+ const extensions = {
12
+ css: 'css',
13
+ tailwind: 'tailwind.css',
14
+ swift: 'swift',
15
+ kotlin: 'kt',
16
+ dart: 'dart',
17
+ python: 'py',
18
+ qt: 'qt',
19
+ textual: 'textual',
20
+ ts: 'ts',
21
+ scss: 'scss',
22
+ xaml: 'xaml',
23
+ 'android-xml': 'xml',
24
+ rust: 'rs',
25
+ 'go-lipgloss': 'go',
26
+ godot: 'gd',
27
+ 'unity-uss': 'uss',
28
+ slint: 'slint',
29
+ gtk4: 'css',
30
+ typst: 'typ',
31
+ };
32
+
33
+ function outputFileName(format, mode) {
34
+ const modePart = mode ? `.${mode}` : '';
35
+ if (format === 'gtk4') return `tokens${modePart}-gtk4.css`;
36
+ return `tokens${modePart}.${extensions[format]}`;
37
+ }
38
+
39
+ const genericFontFamilies = new Set([
40
+ 'serif', 'sans-serif', 'monospace', 'cursive', 'fantasy', 'system-ui',
41
+ 'ui-serif', 'ui-sans-serif', 'ui-monospace', 'ui-rounded', 'emoji', 'math', 'fangsong',
42
+ ]);
43
+
44
+ function help() {
45
+ return `Usage: node export-tokens.mjs <tokens.json> --format <${formats.join('|')}|all> [--mode NAME] [--selector SEL] [--preserve-references] [--out-dir DIR]
46
+
47
+ Zero-dependency exporter for the common DTCG 2025.10 subset used by Pixelcraft
48
+ (including $root group base tokens and non-fatal $deprecated warnings to stderr).
49
+ Without --out-dir, generated text is written to stdout. Advanced DTCG features
50
+ such as advanced tool-specific extensions should be handled by a dedicated compiler.
51
+ Pixelcraft token-level mode overrides use $extensions.pixelcraft.modes.
52
+
53
+ Options:
54
+ --format NAME Output format (${formats.join(', ')}, or all; default: all)
55
+ --mode NAME Apply mode overrides from $extensions.pixelcraft.modes
56
+ --selector SEL CSS selector wrapper for --format css (default: :root)
57
+ --preserve-references Emit var(--...) / $... aliases for direct token references in CSS/Tailwind/SCSS/USS
58
+ --out-dir DIR Write generated files to DIR instead of stdout
59
+ --help Show this help`;
60
+ }
61
+
62
+ function camel(parts) {
63
+ return parts.map((p, i) => {
64
+ const clean = p.replace(/[^a-zA-Z0-9]+(.)/g, (_, c) => c.toUpperCase()).replace(/[^a-zA-Z0-9]/g, '');
65
+ return i === 0 ? clean : clean.charAt(0).toUpperCase() + clean.slice(1);
66
+ }).join('');
67
+ }
68
+ const kebab = (parts) => parts.join('-').replace(/[^a-zA-Z0-9-]/g, '-').toLowerCase();
69
+ const pascal = (name) => name.charAt(0).toUpperCase() + name.slice(1);
70
+ const snake = (varName) => varName.replace(/-/g, '_');
71
+ const rustConst = (varName) => {
72
+ const upper = varName.replace(/-/g, '_').toUpperCase();
73
+ return /^\d/.test(upper) ? `_${upper}` : upper;
74
+ };
75
+ const xmlEscape = (text) => String(text)
76
+ .replace(/&/g, '&amp;')
77
+ .replace(/</g, '&lt;')
78
+ .replace(/>/g, '&gt;')
79
+ .replace(/"/g, '&quot;');
80
+
81
+ function flatten(node, parts = [], inheritedType = '', out = [], inheritedDeprecated = false) {
82
+ const type = node.$type || inheritedType;
83
+ const groupDeprecated = node.$deprecated !== undefined ? node.$deprecated : inheritedDeprecated;
84
+ if (parts.length > 0 && Object.hasOwn(node, '$root') && typeof node.$root === 'object' && node.$root !== null
85
+ && !Array.isArray(node.$root) && Object.hasOwn(node.$root, '$value')) {
86
+ const rootDeprecated = node.$root.$deprecated !== undefined ? node.$root.$deprecated : groupDeprecated;
87
+ out.push({ path: parts, type: node.$root.$type || type, token: node.$root, isRoot: true, deprecated: rootDeprecated });
88
+ }
89
+ for (const [key, value] of Object.entries(node)) {
90
+ if (key.startsWith('$') || typeof value !== 'object' || value === null || Array.isArray(value)) continue;
91
+ const next = [...parts, key];
92
+ if (Object.hasOwn(value, '$value')) {
93
+ const tokDeprecated = value.$deprecated !== undefined ? value.$deprecated : groupDeprecated;
94
+ out.push({ path: next, type: value.$type || type, token: value, deprecated: tokDeprecated });
95
+ } else {
96
+ flatten(value, next, type, out, groupDeprecated);
97
+ }
98
+ }
99
+ return out;
100
+ }
101
+
102
+ function gamma(v) {
103
+ return v <= 0.0031308 ? 12.92 * v : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
104
+ }
105
+ function linearize(c) {
106
+ return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
107
+ }
108
+ function oklabToRgb(L, a, b) {
109
+ const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
110
+ const m = (L - 0.1055613458 * a - 0.0638541729 * b) ** 3;
111
+ const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
112
+ return [
113
+ gamma(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),
114
+ gamma(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),
115
+ gamma(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s),
116
+ ].map((v) => Math.max(0, Math.min(1, v)));
117
+ }
118
+ function oklchToRgb(L, C, H) {
119
+ const a = C * Math.cos(H * Math.PI / 180);
120
+ const b = C * Math.sin(H * Math.PI / 180);
121
+ return oklabToRgb(L, a, b);
122
+ }
123
+ function displayP3ToRgb(r, g, b) {
124
+ const lr = linearize(r);
125
+ const lg = linearize(g);
126
+ const lb = linearize(b);
127
+ return [
128
+ gamma(1.2249401763 * lr - 0.2249401763 * lg),
129
+ gamma(-0.0420569547 * lr + 1.0420569547 * lg),
130
+ gamma(-0.0196375546 * lr - 0.0786360456 * lg + 1.0982736002 * lb),
131
+ ].map((v) => Math.max(0, Math.min(1, v)));
132
+ }
133
+ function hslToRgb(H, S, L) {
134
+ const h = ((H % 360) + 360) % 360;
135
+ const s = Math.max(0, Math.min(100, S)) / 100;
136
+ const l = Math.max(0, Math.min(100, L)) / 100;
137
+ const c = (1 - Math.abs(2 * l - 1)) * s;
138
+ const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
139
+ const m = l - c / 2;
140
+ let r = 0, g = 0, b = 0;
141
+ if (h < 60) [r, g, b] = [c, x, 0];
142
+ else if (h < 120) [r, g, b] = [x, c, 0];
143
+ else if (h < 180) [r, g, b] = [0, c, x];
144
+ else if (h < 240) [r, g, b] = [0, x, c];
145
+ else if (h < 300) [r, g, b] = [x, 0, c];
146
+ else [r, g, b] = [c, 0, x];
147
+ return [r + m, g + m, b + m].map((v) => Math.max(0, Math.min(1, v)));
148
+ }
149
+ function rgbHex(rgb, alpha = 1) {
150
+ const vals = [...rgb, alpha].map((v) => Math.round(Math.max(0, Math.min(1, v)) * 255).toString(16).padStart(2, '0'));
151
+ return `#${vals.slice(0, 3).join('')}${alpha < 1 ? vals[3] : ''}`;
152
+ }
153
+ function alphaByte(alpha) {
154
+ return Math.round(Math.max(0, Math.min(1, alpha)) * 255).toString(16).padStart(2, '0');
155
+ }
156
+ function parseHexString(str) {
157
+ const m = /^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(str.trim());
158
+ if (!m) return null;
159
+ let hex = m[1].toLowerCase();
160
+ if (hex.length === 3 || hex.length === 4) {
161
+ hex = hex.split('').map((ch) => ch + ch).join('');
162
+ }
163
+ const r = parseInt(hex.slice(0, 2), 16) / 255;
164
+ const g = parseInt(hex.slice(2, 4), 16) / 255;
165
+ const b = parseInt(hex.slice(4, 6), 16) / 255;
166
+ const alpha = hex.length === 8 ? parseInt(hex.slice(6, 8), 16) / 255 : 1;
167
+ return { rgb: [r, g, b], alpha, hex: `#${hex.slice(0, 6)}${hex.length === 8 ? hex.slice(6, 8) : ''}`, css: str.trim() };
168
+ }
169
+ function requireTypedColor(token, format) {
170
+ if (!token.value.rgb) {
171
+ throw new Error(
172
+ `color token '${token.path.join('.')}' uses non-hex string '${token.value.css}' which cannot be exported to ${format}; use #rrggbb/#rrggbbaa hex or a DTCG color object`
173
+ );
174
+ }
175
+ return token.value;
176
+ }
177
+ function argbHex(color) {
178
+ return `${alphaByte(color.alpha ?? 1)}${color.hex.slice(1, 7)}`;
179
+ }
180
+ function fmtNumber(value) {
181
+ return Number.isInteger(value) ? String(value) : String(Number(value.toFixed(6)));
182
+ }
183
+ function fmtFloat(value) {
184
+ const formatted = fmtNumber(value);
185
+ return formatted.includes('.') ? formatted : `${formatted}.0`;
186
+ }
187
+ function durationMs(value) {
188
+ const amount = Number(value.value);
189
+ if (value.unit === 'ms') return amount;
190
+ if (value.unit === 's') return amount * 1000;
191
+ throw new Error(`unsupported duration unit '${value.unit}'`);
192
+ }
193
+ function isFontSizePath(parts) {
194
+ return /(?:^|\.)(?:font\.size|text\.size|typography)(?:\.|$)/i.test(parts.join('.'));
195
+ }
196
+ function nativeDimension(dim) {
197
+ const amount = Number(dim.value);
198
+ if (dim.unit === 'rem') {
199
+ return { value: amount * 16, comment: `${amount}rem @ 16px base`, converted: true };
200
+ }
201
+ return { value: amount, comment: dim.unit, converted: false };
202
+ }
203
+
204
+ function componentNumber(value) {
205
+ return value === 'none' ? 0 : Number(value);
206
+ }
207
+
208
+ function colorParts(value) {
209
+ if (typeof value === 'string') {
210
+ const parsed = parseHexString(value);
211
+ if (parsed) return parsed;
212
+ return { hex: value, css: value, rgb: null, alpha: 1 };
213
+ }
214
+ const space = value.colorSpace;
215
+ const alpha = value.alpha ?? 1;
216
+ const explicitFallback = typeof value.hex === 'string' ? parseHexString(value.hex) : null;
217
+ const resolveRgb = (computed) => {
218
+ if (explicitFallback) {
219
+ return {
220
+ rgb: explicitFallback.rgb,
221
+ hex: rgbHex(explicitFallback.rgb, value.alpha !== undefined ? alpha : explicitFallback.alpha),
222
+ };
223
+ }
224
+ return { rgb: computed, hex: rgbHex(computed, alpha) };
225
+ };
226
+ if (space === 'srgb') {
227
+ const rgb = value.components.map(componentNumber);
228
+ const out = resolveRgb(rgb);
229
+ return { ...out, alpha, css: out.hex };
230
+ }
231
+ if (space === 'oklch') {
232
+ const [L, C, H] = value.components.map(componentNumber);
233
+ const out = resolveRgb(oklchToRgb(L, C, H));
234
+ return { ...out, alpha, css: `oklch(${L} ${C} ${H}${alpha < 1 ? ` / ${alpha}` : ''})` };
235
+ }
236
+ if (space === 'oklab') {
237
+ const [L, a, b] = value.components.map(componentNumber);
238
+ const out = resolveRgb(oklabToRgb(L, a, b));
239
+ return { ...out, alpha, css: `oklab(${L} ${a} ${b}${alpha < 1 ? ` / ${alpha}` : ''})` };
240
+ }
241
+ if (space === 'display-p3') {
242
+ const [r, g, b] = value.components.map(componentNumber);
243
+ const out = resolveRgb(displayP3ToRgb(r, g, b));
244
+ return { ...out, alpha, css: `color(display-p3 ${r} ${g} ${b}${alpha < 1 ? ` / ${alpha}` : ''})` };
245
+ }
246
+ if (space === 'hsl') {
247
+ const [H, S, L] = value.components.map(componentNumber);
248
+ const out = resolveRgb(hslToRgb(H, S, L));
249
+ return { ...out, alpha, css: `hsl(${H} ${S}% ${L}%${alpha < 1 ? ` / ${alpha}` : ''})` };
250
+ }
251
+ throw new Error(`unsupported colorSpace '${space}'`);
252
+ }
253
+
254
+ function formatFontFamilyItem(item) {
255
+ const trimmed = String(item).trim().replace(/^['"]|['"]$/g, '').trim();
256
+ if (!trimmed) return '';
257
+ if (genericFontFamilies.has(trimmed.toLowerCase()) || /^[a-zA-Z_-][a-zA-Z0-9_-]*$/.test(trimmed)) {
258
+ return trimmed;
259
+ }
260
+ return `"${trimmed.replace(/"/g, '\\"')}"`;
261
+ }
262
+
263
+ function formatFontFamily(v) {
264
+ const list = Array.isArray(v) ? v : [v];
265
+ return list.map(formatFontFamilyItem).filter(Boolean).join(', ');
266
+ }
267
+
268
+ function formatDimOrScalar(v) {
269
+ if (v === undefined || v === null) return '';
270
+ if (typeof v === 'object' && 'value' in v && 'unit' in v) return `${v.value}${v.unit}`;
271
+ return String(v);
272
+ }
273
+
274
+ function formatShadowLayer(layer) {
275
+ const parts = [];
276
+ if (layer.inset) parts.push('inset');
277
+ parts.push(formatDimOrScalar(layer.offsetX ?? { value: 0, unit: 'px' }));
278
+ parts.push(formatDimOrScalar(layer.offsetY ?? { value: 0, unit: 'px' }));
279
+ if (layer.blur !== undefined) parts.push(formatDimOrScalar(layer.blur));
280
+ if (layer.spread !== undefined) parts.push(formatDimOrScalar(layer.spread));
281
+ if (layer.color !== undefined) parts.push(colorParts(layer.color).css);
282
+ return parts.join(' ');
283
+ }
284
+
285
+ function formatCubicBezier(v) {
286
+ return Array.isArray(v) && v.length === 4 ? `cubic-bezier(${v.join(', ')})` : String(v);
287
+ }
288
+
289
+ function formatComposite(type, v) {
290
+ if (type === 'shadow') {
291
+ const layers = Array.isArray(v) ? v : [v];
292
+ return layers.map(formatShadowLayer).join(', ');
293
+ }
294
+ if (type === 'border') {
295
+ const width = formatDimOrScalar(v.width ?? { value: 1, unit: 'px' });
296
+ const style = typeof v.style === 'string' ? v.style : (v.style?.dashArray ? 'dashed' : 'solid');
297
+ const color = v.color !== undefined ? colorParts(v.color).css : 'currentColor';
298
+ return `${width} ${style} ${color}`;
299
+ }
300
+ if (type === 'transition') {
301
+ const parts = [];
302
+ if (v.duration !== undefined) parts.push(formatDimOrScalar(v.duration));
303
+ if (v.timingFunction !== undefined) parts.push(formatCubicBezier(v.timingFunction));
304
+ if (v.delay !== undefined) parts.push(formatDimOrScalar(v.delay));
305
+ return parts.join(' ');
306
+ }
307
+ if (type === 'gradient' && Array.isArray(v)) {
308
+ const stops = v.map((stop) => {
309
+ const col = colorParts(stop.color).css;
310
+ const pct = stop.position !== undefined ? ` ${fmtNumber(Number(stop.position) * 100)}%` : '';
311
+ return `${col}${pct}`;
312
+ });
313
+ return `linear-gradient(${stops.join(', ')})`;
314
+ }
315
+ if (type === 'typography') {
316
+ const parts = [];
317
+ if (v.fontStyle) parts.push(String(v.fontStyle));
318
+ if (v.fontWeight !== undefined) parts.push(String(v.fontWeight));
319
+ const size = formatDimOrScalar(v.fontSize);
320
+ const lh = v.lineHeight !== undefined ? `/${formatDimOrScalar(v.lineHeight)}` : '';
321
+ if (size) parts.push(`${size}${lh}`);
322
+ if (v.fontFamily !== undefined) parts.push(formatFontFamily(v.fontFamily));
323
+ return parts.join(' ');
324
+ }
325
+ return null;
326
+ }
327
+
328
+ function scalar(token, type) {
329
+ const v = token.$value;
330
+ if (type === 'color') return colorParts(v);
331
+ if (type === 'cubicBezier') return formatCubicBezier(v);
332
+ if (type === 'fontFamily') return formatFontFamily(v);
333
+ const composite = typeof v === 'object' && v !== null ? formatComposite(type, v) : null;
334
+ if (composite !== null) return composite;
335
+ if (typeof v === 'object' && v !== null && 'value' in v && 'unit' in v) return `${v.value}${v.unit}`;
336
+ if (Array.isArray(v)) return v.join(', ');
337
+ if (typeof v === 'object' && v !== null) return JSON.stringify(v);
338
+ return String(v);
339
+ }
340
+
341
+ function applyMode(token, mode) {
342
+ if (!mode) return token;
343
+ const replacement = token.token.$extensions?.pixelcraft?.modes?.[mode];
344
+ if (replacement === undefined) return token;
345
+ const value = replacement && typeof replacement === 'object' && Object.hasOwn(replacement, '$value') ? replacement.$value : replacement;
346
+ return { ...token, token: { ...token.token, $value: value } };
347
+ }
348
+
349
+ function createResolver(tokens) {
350
+ const byPath = new Map();
351
+ for (const t of tokens) {
352
+ const key = t.path.join('.');
353
+ byPath.set(key, t);
354
+ if (t.isRoot) byPath.set(`${key}.$root`, t);
355
+ }
356
+ const resolving = new Set();
357
+
358
+ function resolveValue(val) {
359
+ if (typeof val === 'string' && /^\{[^}]+\}$/.test(val)) {
360
+ const key = val.slice(1, -1);
361
+ if (resolving.has(key)) throw new Error(`reference cycle at ${key}`);
362
+ const target = byPath.get(key);
363
+ if (!target) throw new Error(`unresolved token reference {${key}}`);
364
+ resolving.add(key);
365
+ const resolved = resolve(target);
366
+ resolving.delete(key);
367
+ return { value: resolved.token.$value, type: resolved.type };
368
+ }
369
+ if (Array.isArray(val)) {
370
+ return { value: val.map((item) => resolveValue(item).value), type: '' };
371
+ }
372
+ if (val && typeof val === 'object') {
373
+ const next = {};
374
+ for (const [k, v] of Object.entries(val)) next[k] = resolveValue(v).value;
375
+ return { value: next, type: '' };
376
+ }
377
+ return { value: val, type: '' };
378
+ }
379
+
380
+ function resolve(t) {
381
+ const raw = t.token.$value;
382
+ const directRef = typeof raw === 'string' && /^\{[^}]+\}$/.test(raw) ? raw.slice(1, -1) : null;
383
+ const resolved = resolveValue(raw);
384
+ return {
385
+ ...t,
386
+ type: t.type || resolved.type,
387
+ refKey: directRef,
388
+ token: { ...t.token, $value: resolved.value },
389
+ };
390
+ }
391
+ return resolve;
392
+ }
393
+
394
+ function collect(file, mode) {
395
+ const data = JSON.parse(fs.readFileSync(file, 'utf8'));
396
+ const flattened = flatten(data);
397
+ const modes = new Set();
398
+ for (const token of flattened) {
399
+ for (const name of Object.keys(token.token.$extensions?.pixelcraft?.modes || {})) modes.add(name);
400
+ }
401
+ if (mode && !modes.has(mode)) throw new Error(`unknown --mode ${mode}`);
402
+ const resolveBase = createResolver(flattened);
403
+ const baseTokens = flattened.map((token) => resolveBase(token));
404
+ const tokens = flattened.map((token, index) => {
405
+ const typed = token.type ? token : { ...token, type: baseTokens[index].type };
406
+ return applyMode(typed, mode);
407
+ });
408
+ const resolveTokens = createResolver(tokens);
409
+ return tokens.map((token) => resolveTokens(token));
410
+ }
411
+
412
+ function tailwindNamespaceName(token) {
413
+ const name = token.varName;
414
+ if (token.type === 'color') {
415
+ if (name.startsWith('color-')) return name;
416
+ return `color-${name.replace(/(^|-)color-/, '$1')}`;
417
+ }
418
+ if (token.type === 'fontFamily') {
419
+ if (name.startsWith('font-family-')) return `font-${name.slice('font-family-'.length)}`;
420
+ if (name.startsWith('font-')) return name;
421
+ return `font-${name}`;
422
+ }
423
+ if (token.type === 'cubicBezier') {
424
+ if (name.startsWith('ease-')) return name;
425
+ return `ease-${name.replace(/^(?:motion-)?(?:easing|ease)-/, '')}`;
426
+ }
427
+ if (token.type === 'shadow') {
428
+ if (name.startsWith('shadow-')) return name;
429
+ return `shadow-${name}`;
430
+ }
431
+ if (token.type === 'dimension') {
432
+ if (name.startsWith('spacing-')) return name;
433
+ if (name.startsWith('space-')) return `spacing-${name.slice('space-'.length)}`;
434
+ if (/(^|-)space-/.test(name)) return `spacing-${name.replace(/(^|-)space-/, '$1')}`;
435
+ if (name.startsWith('radius-')) return name;
436
+ if (/(^|-)radius(?:-|$)/.test(name)) {
437
+ const stripped = name.replace(/(^|-)radius(?:-|$)/, '$1').replace(/-$/, '');
438
+ return stripped ? `radius-${stripped}` : name;
439
+ }
440
+ if (name.startsWith('font-size-')) return `text-${name.slice('font-size-'.length)}`;
441
+ if (name.startsWith('text-')) return name;
442
+ }
443
+ return name;
444
+ }
445
+
446
+ function entries(tokens) {
447
+ const list = tokens.map((t) => ({
448
+ ...t,
449
+ pathKey: t.path.join('.'),
450
+ name: camel(t.path),
451
+ varName: kebab(t.path),
452
+ value: scalar(t.token, t.type),
453
+ }));
454
+ const seen = new Map();
455
+ for (const t of list) {
456
+ for (const [kind, identifier] of [['identifier', t.name], ['variable', t.varName]]) {
457
+ const key = `${kind}:${identifier}`;
458
+ const previous = seen.get(key);
459
+ if (previous) throw new Error(`token collision: '${previous}' and '${t.pathKey}' both map to ${kind} '${identifier}'`);
460
+ seen.set(key, t.pathKey);
461
+ }
462
+ }
463
+ const twUsed = new Set();
464
+ for (const t of list) {
465
+ let candidate = tailwindNamespaceName(t);
466
+ if (twUsed.has(candidate)) candidate = t.varName;
467
+ twUsed.add(candidate);
468
+ t.twVarName = candidate;
469
+ }
470
+ return list;
471
+ }
472
+
473
+ function render(format, list, options = {}) {
474
+ const selector = options.selector || ':root';
475
+ const preserveReferences = Boolean(options.preserveReferences);
476
+ const byPathKey = new Map(list.map((t) => [t.pathKey, t]));
477
+ const lookupRef = (refKey) => {
478
+ if (!preserveReferences || !refKey) return null;
479
+ return byPathKey.get(refKey) || byPathKey.get(refKey.replace(/\.\$root$/, '')) || null;
480
+ };
481
+
482
+ if (format === 'css' || format === 'tailwind') {
483
+ const body = list.map((t) => {
484
+ const target = lookupRef(t.refKey);
485
+ const varName = format === 'tailwind' ? t.twVarName : t.varName;
486
+ const val = target
487
+ ? `var(--${format === 'tailwind' ? target.twVarName : target.varName})`
488
+ : (typeof t.value === 'object' ? t.value.css : t.value);
489
+ return ` --${varName}: ${val};`;
490
+ }).join('\n');
491
+ return format === 'css' ? `${selector} {\n${body}\n}\n` : `@theme {\n${body}\n}\n`;
492
+ }
493
+ if (format === 'scss') {
494
+ return `${list.map((t) => {
495
+ const target = lookupRef(t.refKey);
496
+ const val = target ? `$${target.varName}` : (typeof t.value === 'object' ? t.value.css : t.value);
497
+ return `$${t.varName}: ${val};`;
498
+ }).join('\n')}\n`;
499
+ }
500
+ if (format === 'ts') {
501
+ const lines = list.map((t) => {
502
+ const val = typeof t.value === 'object' ? t.value.css : String(t.value);
503
+ return ` ${t.name}: ${JSON.stringify(val)},`;
504
+ });
505
+ return `export const pixelcraftTokens = {\n${lines.join('\n')}\n} as const;\n\nexport type PixelcraftTokenName = keyof typeof pixelcraftTokens;\nexport type PixelcraftTokenValue = (typeof pixelcraftTokens)[PixelcraftTokenName];\n`;
506
+ }
507
+ if (format === 'swift') {
508
+ const lines = list.map((t) => {
509
+ if (t.type === 'color') {
510
+ const col = requireTypedColor(t, 'swift');
511
+ const [r, g, b] = col.rgb;
512
+ return ` public static let ${t.name} = Color(red: ${r.toFixed(4)}, green: ${g.toFixed(4)}, blue: ${b.toFixed(4)}, opacity: ${fmtNumber(col.alpha ?? 1)})`;
513
+ }
514
+ if (t.type === 'duration' && typeof t.token.$value === 'object') {
515
+ const ms = durationMs(t.token.$value);
516
+ return ` public static let ${t.name}: TimeInterval = ${fmtNumber(ms / 1000)} // seconds`;
517
+ }
518
+ if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {})) {
519
+ const dim = nativeDimension(t.token.$value);
520
+ return ` public static let ${t.name}: CGFloat = ${fmtNumber(dim.value)} // ${dim.comment}`;
521
+ }
522
+ return ` public static let ${t.name} = ${JSON.stringify(String(t.value))}`;
523
+ });
524
+ return `import Foundation\nimport SwiftUI\n\npublic enum PixelcraftTokens {\n${lines.join('\n')}\n}\n`;
525
+ }
526
+ if (format === 'kotlin') {
527
+ const hasDuration = list.some((t) => t.type === 'duration');
528
+ const lines = list.map((t) => {
529
+ if (t.type === 'color') return `val ${t.name} = Color(0x${argbHex(requireTypedColor(t, 'kotlin'))})`;
530
+ if (t.type === 'duration' && typeof t.token.$value === 'object') {
531
+ return `val ${t.name} = ${fmtNumber(durationMs(t.token.$value))}.milliseconds`;
532
+ }
533
+ if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {})) {
534
+ const unit = isFontSizePath(t.path) ? 'sp' : 'dp';
535
+ const dim = nativeDimension(t.token.$value);
536
+ return `val ${t.name} = ${fmtNumber(dim.value)}.${unit}${dim.converted ? ` // ${dim.comment}` : ''}`;
537
+ }
538
+ return `val ${t.name} = ${JSON.stringify(String(t.value))}`;
539
+ });
540
+ const durationImport = hasDuration ? 'import kotlin.time.Duration.Companion.milliseconds\n' : '';
541
+ return `import androidx.compose.ui.graphics.Color\nimport androidx.compose.ui.unit.dp\nimport androidx.compose.ui.unit.sp\n${durationImport}\n${lines.join('\n')}\n`;
542
+ }
543
+ if (format === 'dart') {
544
+ const lines = list.map((t) => {
545
+ if (t.type === 'color') return `static const Color ${t.name} = Color(0x${argbHex(requireTypedColor(t, 'dart'))});`;
546
+ if (t.type === 'duration' && typeof t.token.$value === 'object') {
547
+ const ms = durationMs(t.token.$value);
548
+ const constructor = Number.isInteger(ms) ? `Duration(milliseconds: ${fmtNumber(ms)})` : `Duration(microseconds: ${Math.round(ms * 1000)})`;
549
+ return `static const Duration ${t.name} = ${constructor};`;
550
+ }
551
+ if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {})) {
552
+ const dim = nativeDimension(t.token.$value);
553
+ return `static const double ${t.name} = ${fmtNumber(dim.value)}; // ${dim.comment}`;
554
+ }
555
+ return `static const String ${t.name} = ${JSON.stringify(String(t.value))};`;
556
+ });
557
+ return `import 'dart:ui';\n\nclass PixelcraftTokens {\n ${lines.join('\n ')}\n}\n`;
558
+ }
559
+ if (format === 'python') {
560
+ const obj = {};
561
+ for (const t of list) obj[t.varName] = t.type === 'color' ? t.value.hex : String(t.value);
562
+ return `PIXELCRAFT_TOKENS = ${JSON.stringify(obj, null, 2)}\n`;
563
+ }
564
+ if (format === 'qt') {
565
+ const lines = list.map((t) => `@${t.varName}: ${t.type === 'color' ? t.value.hex : t.value};`);
566
+ return `/* QSS has no runtime variables. Treat this file as preprocessor input. */\n${lines.join('\n')}\n`;
567
+ }
568
+ if (format === 'textual') {
569
+ return `${list.map((t) => `$${t.varName}: ${t.type === 'color' ? t.value.hex : t.value};`).join('\n')}\n`;
570
+ }
571
+ if (format === 'xaml') {
572
+ const lines = list.map((t) => {
573
+ const key = xmlEscape(pascal(t.name));
574
+ if (t.type === 'color') {
575
+ const col = requireTypedColor(t, 'xaml');
576
+ return ` <Color x:Key="${key}">#${argbHex(col).toUpperCase()}</Color>`;
577
+ }
578
+ if (t.type === 'duration' && typeof t.token.$value === 'object') {
579
+ return ` <x:Int32 x:Key="${key}">${Math.round(durationMs(t.token.$value))}</x:Int32><!-- ms -->`;
580
+ }
581
+ if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {})) {
582
+ const dim = nativeDimension(t.token.$value);
583
+ return ` <x:Double x:Key="${key}">${fmtNumber(dim.value)}</x:Double><!-- ${xmlEscape(dim.comment)} -->`;
584
+ }
585
+ return ` <x:String x:Key="${key}">${xmlEscape(String(t.value))}</x:String>`;
586
+ });
587
+ return `<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"\n xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">\n${lines.join('\n')}\n</ResourceDictionary>\n`;
588
+ }
589
+ if (format === 'android-xml') {
590
+ const lines = list.map((t) => {
591
+ const key = xmlEscape(snake(t.varName));
592
+ if (t.type === 'color') {
593
+ const col = requireTypedColor(t, 'android-xml');
594
+ return ` <color name="${key}">#${argbHex(col).toUpperCase()}</color>`;
595
+ }
596
+ if (t.type === 'duration' && typeof t.token.$value === 'object') {
597
+ return ` <integer name="${key}">${Math.round(durationMs(t.token.$value))}</integer>`;
598
+ }
599
+ if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {})) {
600
+ const unit = isFontSizePath(t.path) ? 'sp' : 'dp';
601
+ const dim = nativeDimension(t.token.$value);
602
+ const note = dim.converted ? ` <!-- ${xmlEscape(dim.comment)} -->` : '';
603
+ return ` <dimen name="${key}">${fmtNumber(dim.value)}${unit}</dimen>${note}`;
604
+ }
605
+ return ` <string name="${key}">${xmlEscape(String(t.value))}</string>`;
606
+ });
607
+ return `<?xml version="1.0" encoding="utf-8"?>\n<resources>\n${lines.join('\n')}\n</resources>\n`;
608
+ }
609
+ if (format === 'rust') {
610
+ const lines = list.map((t) => {
611
+ const id = rustConst(t.varName);
612
+ if (t.type === 'color') {
613
+ const col = requireTypedColor(t, 'rust');
614
+ const [r, g, b] = col.rgb.map((v) => Math.round(Math.max(0, Math.min(1, v)) * 255));
615
+ const a = Math.round(Math.max(0, Math.min(1, col.alpha ?? 1)) * 255);
616
+ return `pub const ${id}: [u8; 4] = [${r}, ${g}, ${b}, ${a}]; // ${col.hex}`;
617
+ }
618
+ if (t.type === 'duration' && typeof t.token.$value === 'object') {
619
+ return `pub const ${id}: u64 = ${Math.round(durationMs(t.token.$value))}; // ms`;
620
+ }
621
+ if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {})) {
622
+ const dim = nativeDimension(t.token.$value);
623
+ return `pub const ${id}: f32 = ${fmtFloat(dim.value)}; // ${dim.comment}`;
624
+ }
625
+ return `pub const ${id}: &str = ${JSON.stringify(String(t.value))};`;
626
+ });
627
+ return `// Generated by Pixelcraft export-tokens.mjs\n${lines.join('\n')}\n`;
628
+ }
629
+ if (format === 'go-lipgloss') {
630
+ const hasColors = list.some((t) => t.type === 'color');
631
+ const lines = list.map((t) => {
632
+ const base = pascal(t.name);
633
+ const id = /^\d/.test(base) ? `Token${base}` : base;
634
+ if (t.type === 'color') {
635
+ const col = requireTypedColor(t, 'go-lipgloss');
636
+ return `\t${id} = lipgloss.Color(${JSON.stringify(col.hex)})`;
637
+ }
638
+ if (t.type === 'duration' && typeof t.token.$value === 'object') {
639
+ return `\t${id} = ${Math.round(durationMs(t.token.$value))} // ms`;
640
+ }
641
+ if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {})) {
642
+ const dim = nativeDimension(t.token.$value);
643
+ return `\t${id} = ${fmtNumber(dim.value)} // ${dim.comment}`;
644
+ }
645
+ return `\t${id} = ${JSON.stringify(String(t.value))}`;
646
+ });
647
+ const imp = hasColors ? '\nimport "github.com/charmbracelet/lipgloss"\n' : '';
648
+ return `// Code generated by Pixelcraft export-tokens.mjs. DO NOT EDIT.\npackage tokens\n${imp}\nconst (\n${lines.join('\n')}\n)\n`;
649
+ }
650
+ if (format === 'godot') {
651
+ const lines = list.map((t) => {
652
+ const id = rustConst(t.varName);
653
+ if (t.type === 'color') {
654
+ const col = requireTypedColor(t, 'godot');
655
+ return `const ${id}: Color = Color.html(${JSON.stringify(col.hex)})`;
656
+ }
657
+ if (t.type === 'duration' && typeof t.token.$value === 'object') {
658
+ return `const ${id}: float = ${fmtFloat(durationMs(t.token.$value) / 1000)} # seconds`;
659
+ }
660
+ if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {})) {
661
+ const dim = nativeDimension(t.token.$value);
662
+ return `const ${id}: float = ${fmtFloat(dim.value)} # ${dim.comment}`;
663
+ }
664
+ if (typeof t.token.$value === 'number') {
665
+ return `const ${id}: float = ${fmtFloat(t.token.$value)}`;
666
+ }
667
+ return `const ${id}: String = ${JSON.stringify(String(t.value))}`;
668
+ });
669
+ return `# Generated by Pixelcraft export-tokens.mjs\nclass_name DesignTokens\n\n${lines.join('\n')}\n`;
670
+ }
671
+ if (format === 'unity-uss') {
672
+ const body = list.map((t) => {
673
+ const target = lookupRef(t.refKey);
674
+ if (target) return ` --${t.varName}: var(--${target.varName});`;
675
+ if (t.type === 'color') {
676
+ const col = requireTypedColor(t, 'unity-uss');
677
+ return ` --${t.varName}: ${col.hex};`;
678
+ }
679
+ if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {}) && t.token.$value.unit === 'rem') {
680
+ const dim = nativeDimension(t.token.$value);
681
+ return ` --${t.varName}: ${fmtNumber(dim.value)}px; /* ${dim.comment} */`;
682
+ }
683
+ return ` --${t.varName}: ${typeof t.value === 'object' ? t.value.css : t.value};`;
684
+ }).join('\n');
685
+ return `/* Generated by Pixelcraft export-tokens.mjs (Unity UI Toolkit USS) */\n:root {\n${body}\n}\n`;
686
+ }
687
+ if (format === 'slint') {
688
+ const lines = list.map((t) => {
689
+ const id = /^\d/.test(t.varName) ? `_${t.varName}` : t.varName;
690
+ if (t.type === 'color') {
691
+ const col = requireTypedColor(t, 'slint');
692
+ return ` out property <color> ${id}: ${col.hex};`;
693
+ }
694
+ if (t.type === 'duration' && typeof t.token.$value === 'object') {
695
+ return ` out property <duration> ${id}: ${Math.round(durationMs(t.token.$value))}ms;`;
696
+ }
697
+ if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {})) {
698
+ const dim = nativeDimension(t.token.$value);
699
+ return ` out property <length> ${id}: ${fmtNumber(dim.value)}px;${dim.converted ? ` // ${dim.comment}` : ''}`;
700
+ }
701
+ if (typeof t.token.$value === 'number') {
702
+ return ` out property <float> ${id}: ${fmtNumber(t.token.$value)};`;
703
+ }
704
+ return ` out property <string> ${id}: ${JSON.stringify(String(t.value))};`;
705
+ });
706
+ return `// Generated by Pixelcraft export-tokens.mjs\nexport global DesignTokens {\n${lines.join('\n')}\n}\n`;
707
+ }
708
+ if (format === 'gtk4') {
709
+ const colorLines = [];
710
+ const propLines = [];
711
+ for (const t of list) {
712
+ if (t.type === 'color') {
713
+ const col = requireTypedColor(t, 'gtk4');
714
+ const key = snake(t.varName);
715
+ if ((col.alpha ?? 1) < 1) {
716
+ const [r, g, b] = col.rgb.map((v) => Math.round(Math.max(0, Math.min(1, v)) * 255));
717
+ colorLines.push(`@define-color ${key} rgba(${r}, ${g}, ${b}, ${fmtNumber(col.alpha)});`);
718
+ } else {
719
+ colorLines.push(`@define-color ${key} ${col.hex};`);
720
+ }
721
+ } else {
722
+ propLines.push(` --${t.varName}: ${t.value};`);
723
+ }
724
+ }
725
+ const sections = ['/* Generated by Pixelcraft export-tokens.mjs (GTK4 CSS) */'];
726
+ if (colorLines.length) sections.push(colorLines.join('\n'));
727
+ if (propLines.length) sections.push(`:root {\n${propLines.join('\n')}\n}`);
728
+ return `${sections.join('\n\n')}\n`;
729
+ }
730
+ if (format === 'typst') {
731
+ const typstUnits = new Set(['pt', 'mm', 'cm', 'in', 'em']);
732
+ const lines = list.map((t) => {
733
+ const key = /^[a-zA-Z_][a-zA-Z0-9_-]*$/.test(t.varName) ? t.varName : JSON.stringify(t.varName);
734
+ if (t.type === 'color') {
735
+ const col = requireTypedColor(t, 'typst');
736
+ return ` ${key}: rgb(${JSON.stringify(col.hex)}),`;
737
+ }
738
+ if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {}) && t.type !== 'duration') {
739
+ const amount = Number(t.token.$value.value);
740
+ const unit = t.token.$value.unit;
741
+ if (typstUnits.has(unit)) return ` ${key}: ${fmtNumber(amount)}${unit},`;
742
+ if (unit === 'rem') return ` ${key}: ${fmtNumber(amount)}em, // ${amount}rem`;
743
+ if (unit === 'px') return ` ${key}: ${fmtNumber(amount * 0.75)}pt, // ${amount}px @ 96dpi`;
744
+ const dim = nativeDimension(t.token.$value);
745
+ return ` ${key}: ${fmtNumber(dim.value)}pt, // ${dim.comment}`;
746
+ }
747
+ if (typeof t.token.$value === 'number') {
748
+ return ` ${key}: ${fmtNumber(t.token.$value)},`;
749
+ }
750
+ return ` ${key}: ${JSON.stringify(String(t.value))},`;
751
+ });
752
+ return `// Generated by Pixelcraft export-tokens.mjs\n#let tokens = (\n${lines.join('\n')}\n)\n`;
753
+ }
754
+ throw new Error(`unknown format ${format}`);
755
+ }
756
+
757
+ function parseCli(args) {
758
+ const valueOptions = new Set(['--format', '--mode', '--out-dir', '--selector']);
759
+ const flagOptions = new Set(['--help', '-h', '--preserve-references']);
760
+ const isKnownOption = (token) => valueOptions.has(token) || flagOptions.has(token)
761
+ || [...valueOptions].some((opt) => token.startsWith(`${opt}=`));
762
+
763
+ const parsed = {
764
+ help: false,
765
+ input: null,
766
+ format: 'all',
767
+ mode: '',
768
+ outDir: '',
769
+ selector: ':root',
770
+ preserveReferences: false,
771
+ };
772
+
773
+ for (let i = 0; i < args.length; i += 1) {
774
+ const arg = args[i];
775
+ if (arg === '--help' || arg === '-h') {
776
+ parsed.help = true;
777
+ continue;
778
+ }
779
+ if (arg === '--preserve-references') {
780
+ parsed.preserveReferences = true;
781
+ continue;
782
+ }
783
+ let matchedOpt = null;
784
+ let value = null;
785
+ if (valueOptions.has(arg)) {
786
+ matchedOpt = arg;
787
+ const next = args[i + 1];
788
+ if (next === undefined || next === '' || isKnownOption(next)) {
789
+ throw new Error(`${arg} requires a value`);
790
+ }
791
+ value = next;
792
+ i += 1;
793
+ } else {
794
+ for (const opt of valueOptions) {
795
+ if (arg.startsWith(`${opt}=`)) {
796
+ matchedOpt = opt;
797
+ value = arg.slice(opt.length + 1);
798
+ if (!value) throw new Error(`${opt} requires a value`);
799
+ break;
800
+ }
801
+ }
802
+ }
803
+ if (matchedOpt) {
804
+ if (matchedOpt === '--format') parsed.format = value;
805
+ else if (matchedOpt === '--mode') parsed.mode = value;
806
+ else if (matchedOpt === '--out-dir') parsed.outDir = value;
807
+ else if (matchedOpt === '--selector') parsed.selector = value;
808
+ continue;
809
+ }
810
+ if (arg.startsWith('-')) throw new Error(`unknown option: ${arg}`);
811
+ if (parsed.input) throw new Error(`unexpected extra argument: ${arg}`);
812
+ parsed.input = arg;
813
+ }
814
+ return parsed;
815
+ }
816
+
817
+ try {
818
+ const cli = parseCli(process.argv.slice(2));
819
+ if (cli.help) {
820
+ console.log(help());
821
+ process.exit(0);
822
+ }
823
+ if (!cli.input) throw new Error('missing tokens.json input');
824
+ if (![...formats, 'all'].includes(cli.format)) throw new Error(`unknown --format ${cli.format}`);
825
+ const selected = cli.format === 'all' ? formats : [cli.format];
826
+ const list = entries(collect(cli.input, cli.mode));
827
+ for (const t of list) {
828
+ if (t.deprecated) {
829
+ const detail = typeof t.deprecated === 'string' && t.deprecated.trim() ? ` (${t.deprecated.trim()})` : '';
830
+ console.error(`export-tokens: warning: deprecated token '${t.pathKey}'${detail}`);
831
+ }
832
+ }
833
+ const renderOpts = { selector: cli.selector, preserveReferences: cli.preserveReferences };
834
+ if (cli.outDir) {
835
+ fs.mkdirSync(cli.outDir, { recursive: true });
836
+ for (const f of selected) {
837
+ const file = path.join(cli.outDir, outputFileName(f, cli.mode));
838
+ fs.writeFileSync(file, render(f, list, renderOpts));
839
+ console.log(`wrote ${file}`);
840
+ }
841
+ } else {
842
+ for (const f of selected) console.log(`/* ${f}${cli.mode ? ` mode=${cli.mode}` : ''} */\n${render(f, list, renderOpts)}`);
843
+ }
844
+ } catch (error) {
845
+ console.error(`export-tokens: ${error.message}`);
846
+ process.exit(1);
847
+ }