@thanhnguyxn/pixelcraft 0.1.0 → 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.
- package/.agents/plugins/marketplace.json +1 -1
- package/.antigravity-plugin/plugin.json +32 -0
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +15 -4
- package/.codex-plugin/plugin.json +45 -0
- package/.cursor-plugin/marketplace.json +17 -0
- package/.cursor-plugin/plugin.json +27 -0
- package/.devin-plugin/plugin.json +21 -0
- package/.github/plugin/marketplace.json +34 -0
- package/CHANGELOG.md +159 -0
- package/GEMINI.md +1 -0
- package/README.md +185 -328
- package/SECURITY.md +28 -0
- package/assets/pixelcraft-logo-128.png +0 -0
- package/assets/pixelcraft-logo-256.png +0 -0
- package/bin/pixelcraft.mjs +431 -23
- package/docs/ARCHITECTURE.md +40 -37
- package/docs/DESIGN-RATIONALE.md +51 -3
- package/docs/INSTALL.md +221 -0
- package/evals/README.md +16 -6
- package/evals/fixtures/3d-web-engineering.json +69 -0
- package/evals/fixtures/acceptance-checklist-rule03-gate.json +43 -0
- package/evals/fixtures/ai-ui-libraries.json +53 -0
- package/evals/fixtures/audio-visual-accessibility.json +69 -0
- package/evals/fixtures/auth-and-checkout-ui.json +53 -0
- package/evals/fixtures/brandkit-identity-governance.json +48 -0
- package/evals/fixtures/build-and-architecture.json +53 -0
- package/evals/fixtures/canvas-and-node-editors.json +53 -0
- package/evals/fixtures/chat-ai-exfiltration-ime-hitl-gate.json +43 -0
- package/evals/fixtures/completion-gate-scan-until-clean.json +44 -0
- package/evals/fixtures/component-systems.json +53 -0
- package/evals/fixtures/component-testing.json +53 -0
- package/evals/fixtures/constrained-voice-and-tv.json +43 -0
- package/evals/fixtures/creative-code-rendering.json +69 -0
- package/evals/fixtures/creative-reference-evidence.json +67 -0
- package/evals/fixtures/data-app-python-marimo.json +49 -0
- package/evals/fixtures/desktop-cpp-juce-audio.json +49 -0
- package/evals/fixtures/desktop-csharp-avalonia.json +49 -0
- package/evals/fixtures/desktop-native-workspace.json +48 -0
- package/evals/fixtures/desktop-python-anti-tkinter.json +49 -0
- package/evals/fixtures/document-prepress-pdfx4-tounicode.json +43 -0
- package/evals/fixtures/document-rust-typst-invoice.json +49 -0
- package/evals/fixtures/document-typst-and-print-css.json +43 -0
- package/evals/fixtures/email-mjml-dark-mode.json +49 -0
- package/evals/fixtures/email-outlook-and-plaintext.json +43 -0
- package/evals/fixtures/enterprise-data-ui.json +53 -0
- package/evals/fixtures/extended-tui-toolkits.json +53 -0
- package/evals/fixtures/extensions-mv3-and-vscode.json +43 -0
- package/evals/fixtures/file-upload-media-ui.json +53 -0
- package/evals/fixtures/forms-validation.json +53 -0
- package/evals/fixtures/game-go-ebitengine.json +49 -0
- package/evals/fixtures/game-godot-gdscript.json +49 -0
- package/evals/fixtures/game-ui-hud-and-engines.json +43 -0
- package/evals/fixtures/i18n-engineering.json +53 -0
- package/evals/fixtures/local-first-sync.json +53 -0
- package/evals/fixtures/lynxjs.json +53 -0
- package/evals/fixtures/maizzle-email.json +53 -0
- package/evals/fixtures/maps-geospatial.json +53 -0
- package/evals/fixtures/media-og-and-video-export.json +43 -0
- package/evals/fixtures/media-players.json +53 -0
- package/evals/fixtures/mobile-compose-16kb-foldable-store-gate.json +44 -0
- package/evals/fixtures/mobile-elixir-liveview-native.json +49 -0
- package/evals/fixtures/mobile-flutter-dynamic-type.json +49 -0
- package/evals/fixtures/mobile-harmonyos-arkui.json +49 -0
- package/evals/fixtures/mobile-jetpack-compose.json +49 -0
- package/evals/fixtures/mobile-swiftui-ios.json +49 -0
- package/evals/fixtures/motion-engineering.json +69 -0
- package/evals/fixtures/pdfjs-and-pptx.json +53 -0
- package/evals/fixtures/plan-discovery-interview.json +31 -0
- package/evals/fixtures/plan-grill-me-brainstorm-gate.json +49 -0
- package/evals/fixtures/reactive-data-apps.json +53 -0
- package/evals/fixtures/review-evidence-audit.json +43 -0
- package/evals/fixtures/rich-text-and-code-editors.json +53 -0
- package/evals/fixtures/scrollytelling-resilience.json +70 -0
- package/evals/fixtures/spatial-xr-comfort-and-platforms.json +43 -0
- package/evals/fixtures/state-architecture.json +53 -0
- package/evals/fixtures/styling-ecosystem.json +53 -0
- package/evals/fixtures/token-tooling.json +53 -0
- package/evals/fixtures/tui-go-bubbletea.json +49 -0
- package/evals/fixtures/tui-rust-ratatui-grapheme-paste-teardown.json +44 -0
- package/evals/fixtures/tui-rust-ratatui.json +49 -0
- package/evals/fixtures/ux-state-matrix-and-i18n.json +43 -0
- package/evals/fixtures/web-3d-engines.json +53 -0
- package/evals/fixtures/web-php-laravel-filament.json +49 -0
- package/evals/fixtures/web-ruby-viewcomponent-phlex.json +49 -0
- package/evals/pixelcraft-accessibility.md +17 -0
- package/evals/pixelcraft-craft.md +16 -0
- package/evals/pixelcraft-dataviz.md +3 -3
- package/evals/pixelcraft-direction.md +17 -0
- package/evals/pixelcraft-game-ui.md +3 -3
- package/evals/pixelcraft-mobile.md +3 -3
- package/evals/pixelcraft-patterns.md +16 -0
- package/evals/pixelcraft-plan.md +65 -3
- package/evals/pixelcraft-review.md +3 -3
- package/evals/pixelcraft-visual-qa.md +11 -5
- package/evals/pixelcraft-web.md +21 -3
- package/evals/pixelcraft.md +4 -4
- package/gemini-extension.json +3 -2
- package/install.ps1 +57 -11
- package/install.sh +82 -7
- package/package.json +32 -4
- package/plugin.json +6 -1
- package/scripts/build-adapters.mjs +11 -13
- package/scripts/run-evals.mjs +397 -0
- package/scripts/sync-docs.mjs +381 -0
- package/scripts/test-build-adapters.mjs +14 -1
- package/scripts/test-cross-platform-qa.mjs +359 -0
- package/scripts/test-distribution.mjs +86 -7
- package/scripts/test-export-tokens.mjs +259 -3
- package/scripts/test-finish-gate.mjs +133 -10
- package/scripts/test-installers.mjs +155 -6
- package/scripts/test-shoot.mjs +23 -1
- package/scripts/test-slop-scan.mjs +390 -3
- package/scripts/test-style-inventory.mjs +23 -0
- package/scripts/test-sync-docs.mjs +140 -0
- package/scripts/test-validate-skills.mjs +82 -4
- package/scripts/validate-skills.mjs +149 -3
- package/skills/pixelcraft/SKILL.md +67 -47
- package/skills/pixelcraft/references/design-brief.md +2 -2
- package/skills/pixelcraft/references/floor.md +36 -19
- package/skills/pixelcraft/references/report-template.md +25 -11
- package/skills/pixelcraft/references/stack-detection.md +138 -67
- package/skills/pixelcraft/references/surface-acceptance.md +33 -21
- package/skills/pixelcraft/references/workflow-checkpoints.md +49 -7
- package/skills/pixelcraft-accessibility/SKILL.md +34 -13
- package/skills/pixelcraft-accessibility/references/apg-patterns.md +13 -0
- package/skills/pixelcraft-accessibility/references/motion-canvas.md +57 -0
- package/skills/pixelcraft-accessibility/references/platforms.md +34 -6
- package/skills/pixelcraft-accessibility/references/verification.md +15 -10
- package/skills/pixelcraft-accessibility/references/wcag22-checks.md +38 -5
- package/skills/pixelcraft-brandkit/SKILL.md +42 -30
- package/skills/pixelcraft-brandkit/references/asset-pipeline.md +90 -50
- package/skills/pixelcraft-brandkit/references/brand-governance.md +29 -27
- package/skills/pixelcraft-brandkit/references/logo-methods.md +33 -34
- package/skills/pixelcraft-brandkit/references/prompt-template.md +53 -51
- package/skills/pixelcraft-brandkit/references/qa-checklist.md +7 -2
- package/skills/pixelcraft-brandkit/references/visual-modes.md +16 -16
- package/skills/pixelcraft-chat-ui/SKILL.md +31 -27
- package/skills/pixelcraft-chat-ui/references/agentic-workspace.md +66 -0
- package/skills/pixelcraft-chat-ui/references/ai-ui-libraries.md +259 -0
- package/skills/pixelcraft-chat-ui/references/conversation-design.md +12 -6
- package/skills/pixelcraft-chat-ui/references/mobile-business-platforms.md +58 -68
- package/skills/pixelcraft-chat-ui/references/slack-discord.md +60 -76
- package/skills/pixelcraft-constrained/SKILL.md +21 -20
- package/skills/pixelcraft-constrained/references/specialized-hardware.md +69 -45
- package/skills/pixelcraft-constrained/references/tv-wearables.md +123 -73
- package/skills/pixelcraft-constrained/references/voice-ui.md +86 -45
- package/skills/pixelcraft-craft/SKILL.md +29 -15
- package/skills/pixelcraft-craft/references/color.md +62 -6
- package/skills/pixelcraft-craft/references/layout.md +32 -0
- package/skills/pixelcraft-craft/references/motion.md +99 -12
- package/skills/pixelcraft-craft/references/typography.md +48 -9
- package/skills/pixelcraft-data-apps/SKILL.md +50 -31
- package/skills/pixelcraft-data-apps/references/ai-and-internal-data-apps.md +147 -0
- package/skills/pixelcraft-data-apps/references/dash.md +87 -31
- package/skills/pixelcraft-data-apps/references/evidence.md +41 -26
- package/skills/pixelcraft-data-apps/references/gradio.md +65 -27
- package/skills/pixelcraft-data-apps/references/julia-genie.md +64 -29
- package/skills/pixelcraft-data-apps/references/jupyter-widgets.md +65 -27
- package/skills/pixelcraft-data-apps/references/nicegui.md +73 -34
- package/skills/pixelcraft-data-apps/references/observable-framework.md +65 -27
- package/skills/pixelcraft-data-apps/references/panel.md +69 -23
- package/skills/pixelcraft-data-apps/references/r-shiny.md +104 -34
- package/skills/pixelcraft-data-apps/references/reactive-data-apps.md +186 -0
- package/skills/pixelcraft-data-apps/references/reflex.md +85 -31
- package/skills/pixelcraft-data-apps/references/shiny.md +84 -27
- package/skills/pixelcraft-data-apps/references/streamlit.md +73 -25
- package/skills/pixelcraft-dataviz/SKILL.md +21 -24
- package/skills/pixelcraft-dataviz/references/color-accessibility.md +2 -2
- package/skills/pixelcraft-dataviz/references/encoding-tables-dashboards.md +35 -25
- package/skills/pixelcraft-dataviz/references/libraries.md +165 -46
- package/skills/pixelcraft-dataviz/references/maps-geospatial.md +159 -0
- package/skills/pixelcraft-dataviz/references/realtime-graphs-maps-scale.md +58 -65
- package/skills/pixelcraft-desktop/SKILL.md +61 -39
- package/skills/pixelcraft-desktop/references/appkit.md +60 -26
- package/skills/pixelcraft-desktop/references/avalonia.md +65 -29
- package/skills/pixelcraft-desktop/references/cpp-gui.md +104 -27
- package/skills/pixelcraft-desktop/references/electron.md +68 -26
- package/skills/pixelcraft-desktop/references/go-gui.md +59 -30
- package/skills/pixelcraft-desktop/references/gtk.md +74 -31
- package/skills/pixelcraft-desktop/references/javafx-swing.md +54 -25
- package/skills/pixelcraft-desktop/references/qt-pyside-qml.md +57 -30
- package/skills/pixelcraft-desktop/references/rust-gui.md +59 -41
- package/skills/pixelcraft-desktop/references/tauri.md +80 -24
- package/skills/pixelcraft-desktop/references/uno-platform.md +42 -23
- package/skills/pixelcraft-desktop/references/winui-wpf.md +66 -26
- package/skills/pixelcraft-desktop/references/working-context.md +82 -3
- package/skills/pixelcraft-direction/SKILL.md +48 -82
- package/skills/pixelcraft-direction/references/creative-brainstorming.md +72 -0
- package/skills/pixelcraft-direction/references/direction-card.md +11 -1
- package/skills/pixelcraft-direction/references/direction-scoring.md +5 -1
- package/skills/pixelcraft-direction/references/motion-identity.md +67 -0
- package/skills/pixelcraft-direction/references/movements.md +3 -0
- package/skills/pixelcraft-direction/references/reference-analysis.md +37 -0
- package/skills/pixelcraft-direction/references/slop-fingerprints.md +32 -7
- package/skills/pixelcraft-document/SKILL.md +27 -23
- package/skills/pixelcraft-document/references/archetypes.md +27 -4
- package/skills/pixelcraft-document/references/pdf-tools.md +241 -81
- package/skills/pixelcraft-document/references/pdfjs-and-pptx.md +114 -0
- package/skills/pixelcraft-document/references/print-css.md +96 -43
- package/skills/pixelcraft-document/references/slides.md +123 -27
- package/skills/pixelcraft-email/SKILL.md +42 -20
- package/skills/pixelcraft-email/references/client-quirks.md +101 -33
- package/skills/pixelcraft-email/references/html-tables.md +83 -22
- package/skills/pixelcraft-email/references/maizzle.md +54 -0
- package/skills/pixelcraft-email/references/mjml.md +13 -11
- package/skills/pixelcraft-email/references/react-email.md +76 -34
- package/skills/pixelcraft-extensions/SKILL.md +32 -27
- package/skills/pixelcraft-extensions/references/browser-extensions.md +91 -17
- package/skills/pixelcraft-extensions/references/figma-office.md +97 -14
- package/skills/pixelcraft-extensions/references/ide-and-saas-plugins.md +125 -0
- package/skills/pixelcraft-extensions/references/raycast.md +90 -11
- package/skills/pixelcraft-extensions/references/vscode-webviews.md +91 -17
- package/skills/pixelcraft-game-ui/SKILL.md +45 -26
- package/skills/pixelcraft-game-ui/references/bevy.md +69 -31
- package/skills/pixelcraft-game-ui/references/godot.md +100 -27
- package/skills/pixelcraft-game-ui/references/hud-principles.md +50 -21
- package/skills/pixelcraft-game-ui/references/love2d.md +53 -27
- package/skills/pixelcraft-game-ui/references/monogame.md +45 -29
- package/skills/pixelcraft-game-ui/references/unity-ugui.md +109 -0
- package/skills/pixelcraft-game-ui/references/unity-ui-toolkit.md +69 -27
- package/skills/pixelcraft-game-ui/references/unreal-umg.md +53 -26
- package/skills/pixelcraft-game-ui/references/web-and-middleware-game-ui.md +122 -0
- package/skills/pixelcraft-handoff/SKILL.md +14 -13
- package/skills/pixelcraft-handoff/references/design-translation.md +40 -10
- package/skills/pixelcraft-handoff/references/motion-handoff.md +54 -0
- package/skills/pixelcraft-media/SKILL.md +20 -23
- package/skills/pixelcraft-media/references/banners-video.md +83 -65
- package/skills/pixelcraft-media/references/og-generation.md +110 -63
- package/skills/pixelcraft-media/references/social-cards.md +57 -58
- package/skills/pixelcraft-mobile/SKILL.md +53 -36
- package/skills/pixelcraft-mobile/references/dotnet-maui.md +62 -34
- package/skills/pixelcraft-mobile/references/flet.md +53 -26
- package/skills/pixelcraft-mobile/references/flutter.md +76 -32
- package/skills/pixelcraft-mobile/references/harmonyos-and-emerging-mobile.md +121 -0
- package/skills/pixelcraft-mobile/references/ionic-capacitor.md +48 -26
- package/skills/pixelcraft-mobile/references/jetpack-compose.md +92 -24
- package/skills/pixelcraft-mobile/references/kivy.md +54 -31
- package/skills/pixelcraft-mobile/references/kotlin-multiplatform.md +53 -27
- package/skills/pixelcraft-mobile/references/lynxjs.md +110 -0
- package/skills/pixelcraft-mobile/references/nativescript-and-skip.md +91 -0
- package/skills/pixelcraft-mobile/references/react-native-expo.md +66 -31
- package/skills/pixelcraft-mobile/references/swiftui.md +158 -28
- package/skills/pixelcraft-mobile/references/tactile-interactions.md +55 -0
- package/skills/pixelcraft-mobile/references/task-state-composition.md +82 -2
- package/skills/pixelcraft-mobile/references/uikit.md +57 -23
- package/skills/pixelcraft-patterns/SKILL.md +30 -13
- package/skills/pixelcraft-patterns/references/accessibility-resilience.md +29 -0
- package/skills/pixelcraft-patterns/references/ai-and-offline-patterns.md +54 -0
- package/skills/pixelcraft-patterns/references/auth-onboarding.md +32 -13
- package/skills/pixelcraft-patterns/references/billing-paywalls.md +40 -0
- package/skills/pixelcraft-patterns/references/command-workspace.md +56 -0
- package/skills/pixelcraft-patterns/references/commerce.md +35 -16
- package/skills/pixelcraft-patterns/references/communication.md +34 -15
- package/skills/pixelcraft-patterns/references/creative-tools.md +30 -17
- package/skills/pixelcraft-patterns/references/creative-web-composition.md +38 -0
- package/skills/pixelcraft-patterns/references/dashboard-admin.md +22 -18
- package/skills/pixelcraft-patterns/references/history-diff-undo.md +50 -0
- package/skills/pixelcraft-patterns/references/marketing.md +31 -19
- package/skills/pixelcraft-patterns/references/multi-tenant-rbac.md +47 -0
- package/skills/pixelcraft-patterns/references/narrative-systems.md +42 -0
- package/skills/pixelcraft-patterns/references/notifications-activity.md +57 -0
- package/skills/pixelcraft-patterns/references/pattern-selection.md +8 -2
- package/skills/pixelcraft-patterns/references/scheduling-kanban.md +47 -0
- package/skills/pixelcraft-patterns/references/scroll-implementation.md +37 -0
- package/skills/pixelcraft-patterns/references/settings.md +40 -12
- package/skills/pixelcraft-plan/SKILL.md +54 -18
- package/skills/pixelcraft-plan/references/discovery-interview.md +110 -0
- package/skills/pixelcraft-plan/references/grill-me-protocol.md +63 -0
- package/skills/pixelcraft-plan/references/plan-template.md +44 -9
- package/skills/pixelcraft-plan/references/repo-discovery.md +16 -9
- package/skills/pixelcraft-plan/references/stack-freshness.md +22 -5
- package/skills/pixelcraft-plan/references/stack-selection.md +65 -9
- package/skills/pixelcraft-review/SKILL.md +41 -19
- package/skills/pixelcraft-review/references/audit-report.md +20 -1
- package/skills/pixelcraft-review/references/heuristics.md +63 -18
- package/skills/pixelcraft-review/references/personas.md +41 -14
- package/skills/pixelcraft-review/references/polish.md +66 -26
- package/skills/pixelcraft-review/scripts/check-acceptance.mjs +619 -0
- package/skills/pixelcraft-review/scripts/fixtures/focus-longhand-removal.css +34 -0
- package/skills/pixelcraft-review/scripts/slop-scan.mjs +679 -32
- package/skills/pixelcraft-spatial/SKILL.md +16 -17
- package/skills/pixelcraft-spatial/references/comfort-accessibility.md +25 -84
- package/skills/pixelcraft-spatial/references/platforms.md +123 -53
- package/skills/pixelcraft-tokens/SKILL.md +18 -14
- package/skills/pixelcraft-tokens/assets/tokens.example.json +1 -1
- package/skills/pixelcraft-tokens/assets/tokens.modes.example.json +1 -1
- package/skills/pixelcraft-tokens/references/format.md +39 -9
- package/skills/pixelcraft-tokens/references/governance.md +1 -1
- package/skills/pixelcraft-tokens/references/theme-presets.md +36 -8
- package/skills/pixelcraft-tokens/references/token-tooling.md +119 -0
- package/skills/pixelcraft-tokens/scripts/export-tokens.mjs +637 -75
- package/skills/pixelcraft-tui/SKILL.md +41 -25
- package/skills/pixelcraft-tui/references/bubbletea-lipgloss.md +49 -30
- package/skills/pixelcraft-tui/references/extended-tui-toolkits.md +127 -0
- package/skills/pixelcraft-tui/references/ink.md +77 -28
- package/skills/pixelcraft-tui/references/ratatui.md +70 -30
- package/skills/pixelcraft-tui/references/rich.md +53 -33
- package/skills/pixelcraft-tui/references/terminal-protocols.md +80 -0
- package/skills/pixelcraft-tui/references/textual.md +75 -34
- package/skills/pixelcraft-ux/SKILL.md +22 -12
- package/skills/pixelcraft-ux/references/feedback-performance.md +39 -19
- package/skills/pixelcraft-ux/references/forms.md +57 -3
- package/skills/pixelcraft-ux/references/i18n.md +50 -12
- package/skills/pixelcraft-ux/references/laws.md +35 -14
- package/skills/pixelcraft-ux/references/state-matrix.md +15 -1
- package/skills/pixelcraft-ux/references/ux-writing.md +1 -0
- package/skills/pixelcraft-visual-qa/SKILL.md +21 -7
- package/skills/pixelcraft-visual-qa/references/capture-desktop-game.md +28 -7
- package/skills/pixelcraft-visual-qa/references/capture-document.md +70 -0
- package/skills/pixelcraft-visual-qa/references/capture-email.md +13 -9
- package/skills/pixelcraft-visual-qa/references/capture-mobile.md +20 -5
- package/skills/pixelcraft-visual-qa/references/capture-terminal.md +6 -2
- package/skills/pixelcraft-visual-qa/references/motion-capture.md +63 -0
- package/skills/pixelcraft-visual-qa/references/performance-budgets.md +25 -12
- package/skills/pixelcraft-visual-qa/references/realtime-graphics.md +55 -0
- package/skills/pixelcraft-visual-qa/scripts/check-contrast.mjs +442 -0
- package/skills/pixelcraft-visual-qa/scripts/check-email.mjs +397 -0
- package/skills/pixelcraft-visual-qa/scripts/check-pdf.mjs +189 -0
- package/skills/pixelcraft-visual-qa/scripts/check-tui.mjs +321 -0
- package/skills/pixelcraft-visual-qa/scripts/finish-gate.mjs +50 -11
- package/skills/pixelcraft-visual-qa/scripts/shoot.mjs +214 -59
- package/skills/pixelcraft-visual-qa/scripts/style-inventory.mjs +121 -49
- package/skills/pixelcraft-web/SKILL.md +105 -49
- package/skills/pixelcraft-web/references/accessibility-performance.md +42 -0
- package/skills/pixelcraft-web/references/adaptive-layout.md +52 -8
- package/skills/pixelcraft-web/references/angular.md +63 -16
- package/skills/pixelcraft-web/references/assets-pipeline.md +67 -0
- package/skills/pixelcraft-web/references/astro.md +64 -13
- package/skills/pixelcraft-web/references/audio-reactive.md +61 -0
- package/skills/pixelcraft-web/references/auth-and-checkout-ui.md +115 -0
- package/skills/pixelcraft-web/references/build-and-architecture.md +215 -0
- package/skills/pixelcraft-web/references/canvas-and-node-editors.md +157 -0
- package/skills/pixelcraft-web/references/clojurescript.md +52 -17
- package/skills/pixelcraft-web/references/component-systems.md +102 -0
- package/skills/pixelcraft-web/references/component-testing.md +170 -0
- package/skills/pixelcraft-web/references/creative-effects.md +59 -0
- package/skills/pixelcraft-web/references/creative-runtime.md +34 -0
- package/skills/pixelcraft-web/references/enterprise-data-ui.md +138 -0
- package/skills/pixelcraft-web/references/file-upload-media-ui.md +82 -0
- package/skills/pixelcraft-web/references/forms-validation.md +123 -0
- package/skills/pixelcraft-web/references/fsharp-fable.md +3 -2
- package/skills/pixelcraft-web/references/gsap.md +102 -0
- package/skills/pixelcraft-web/references/html-css.md +144 -12
- package/skills/pixelcraft-web/references/htmx-alpine.md +68 -18
- package/skills/pixelcraft-web/references/i18n-engineering.md +106 -0
- package/skills/pixelcraft-web/references/interaction-and-search-primitives.md +196 -0
- package/skills/pixelcraft-web/references/java-web.md +27 -18
- package/skills/pixelcraft-web/references/kotlin-web.md +6 -2
- package/skills/pixelcraft-web/references/leptos-yew.md +62 -19
- package/skills/pixelcraft-web/references/lit-web-components.md +4 -2
- package/skills/pixelcraft-web/references/local-first-sync.md +105 -0
- package/skills/pixelcraft-web/references/media-players.md +104 -0
- package/skills/pixelcraft-web/references/motion-react.md +96 -0
- package/skills/pixelcraft-web/references/motion-recipes.md +82 -0
- package/skills/pixelcraft-web/references/preact-fresh-hono.md +111 -0
- package/skills/pixelcraft-web/references/pwa.md +6 -1
- package/skills/pixelcraft-web/references/qwik.md +51 -11
- package/skills/pixelcraft-web/references/r3f-integration.md +69 -0
- package/skills/pixelcraft-web/references/react-next.md +112 -13
- package/skills/pixelcraft-web/references/rendering-choice.md +63 -0
- package/skills/pixelcraft-web/references/rendering-performance.md +80 -0
- package/skills/pixelcraft-web/references/rich-text-and-code-editors.md +220 -0
- package/skills/pixelcraft-web/references/rive-lottie.md +73 -0
- package/skills/pixelcraft-web/references/scene-architecture.md +132 -0
- package/skills/pixelcraft-web/references/server-rendered.md +106 -63
- package/skills/pixelcraft-web/references/shader-workflow.md +77 -0
- package/skills/pixelcraft-web/references/smooth-scroll.md +58 -0
- package/skills/pixelcraft-web/references/solid.md +67 -16
- package/skills/pixelcraft-web/references/state-architecture.md +107 -0
- package/skills/pixelcraft-web/references/styling-ecosystem.md +273 -0
- package/skills/pixelcraft-web/references/svelte.md +61 -11
- package/skills/pixelcraft-web/references/tailwind.md +40 -14
- package/skills/pixelcraft-web/references/video-media.md +69 -0
- package/skills/pixelcraft-web/references/vue-nuxt.md +37 -13
- package/skills/pixelcraft-web/references/web-3d-engines.md +97 -0
|
@@ -2,15 +2,61 @@
|
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
|
|
5
|
-
const formats = [
|
|
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
|
+
]);
|
|
6
43
|
|
|
7
44
|
function help() {
|
|
8
|
-
return `Usage: node export-tokens.mjs <tokens.json> --format <${formats.join('|')}|all> [--mode NAME] [--out-dir DIR]
|
|
45
|
+
return `Usage: node export-tokens.mjs <tokens.json> --format <${formats.join('|')}|all> [--mode NAME] [--selector SEL] [--preserve-references] [--out-dir DIR]
|
|
9
46
|
|
|
10
|
-
Zero-dependency exporter for the common DTCG 2025.10 subset used by Pixelcraft
|
|
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).
|
|
11
49
|
Without --out-dir, generated text is written to stdout. Advanced DTCG features
|
|
12
50
|
such as advanced tool-specific extensions should be handled by a dedicated compiler.
|
|
13
|
-
Pixelcraft token-level mode overrides use $extensions.pixelcraft.modes
|
|
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`;
|
|
14
60
|
}
|
|
15
61
|
|
|
16
62
|
function camel(parts) {
|
|
@@ -20,14 +66,35 @@ function camel(parts) {
|
|
|
20
66
|
}).join('');
|
|
21
67
|
}
|
|
22
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, '&')
|
|
77
|
+
.replace(/</g, '<')
|
|
78
|
+
.replace(/>/g, '>')
|
|
79
|
+
.replace(/"/g, '"');
|
|
23
80
|
|
|
24
|
-
function flatten(node, parts = [], inheritedType = '', out = []) {
|
|
81
|
+
function flatten(node, parts = [], inheritedType = '', out = [], inheritedDeprecated = false) {
|
|
25
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
|
+
}
|
|
26
89
|
for (const [key, value] of Object.entries(node)) {
|
|
27
90
|
if (key.startsWith('$') || typeof value !== 'object' || value === null || Array.isArray(value)) continue;
|
|
28
91
|
const next = [...parts, key];
|
|
29
|
-
if (Object.hasOwn(value, '$value'))
|
|
30
|
-
|
|
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
|
+
}
|
|
31
98
|
}
|
|
32
99
|
return out;
|
|
33
100
|
}
|
|
@@ -35,17 +102,50 @@ function flatten(node, parts = [], inheritedType = '', out = []) {
|
|
|
35
102
|
function gamma(v) {
|
|
36
103
|
return v <= 0.0031308 ? 12.92 * v : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
|
|
37
104
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
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) {
|
|
40
109
|
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
|
|
41
110
|
const m = (L - 0.1055613458 * a - 0.0638541729 * b) ** 3;
|
|
42
111
|
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
|
|
43
112
|
return [
|
|
44
113
|
gamma(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),
|
|
45
114
|
gamma(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),
|
|
46
|
-
gamma(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s)
|
|
115
|
+
gamma(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s),
|
|
47
116
|
].map((v) => Math.max(0, Math.min(1, v)));
|
|
48
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
|
+
}
|
|
49
149
|
function rgbHex(rgb, alpha = 1) {
|
|
50
150
|
const vals = [...rgb, alpha].map((v) => Math.round(Math.max(0, Math.min(1, v)) * 255).toString(16).padStart(2, '0'));
|
|
51
151
|
return `#${vals.slice(0, 3).join('')}${alpha < 1 ? vals[3] : ''}`;
|
|
@@ -69,7 +169,7 @@ function parseHexString(str) {
|
|
|
69
169
|
function requireTypedColor(token, format) {
|
|
70
170
|
if (!token.value.rgb) {
|
|
71
171
|
throw new Error(
|
|
72
|
-
`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
|
|
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`
|
|
73
173
|
);
|
|
74
174
|
}
|
|
75
175
|
return token.value;
|
|
@@ -80,12 +180,30 @@ function argbHex(color) {
|
|
|
80
180
|
function fmtNumber(value) {
|
|
81
181
|
return Number.isInteger(value) ? String(value) : String(Number(value.toFixed(6)));
|
|
82
182
|
}
|
|
183
|
+
function fmtFloat(value) {
|
|
184
|
+
const formatted = fmtNumber(value);
|
|
185
|
+
return formatted.includes('.') ? formatted : `${formatted}.0`;
|
|
186
|
+
}
|
|
83
187
|
function durationMs(value) {
|
|
84
188
|
const amount = Number(value.value);
|
|
85
189
|
if (value.unit === 'ms') return amount;
|
|
86
190
|
if (value.unit === 's') return amount * 1000;
|
|
87
191
|
throw new Error(`unsupported duration unit '${value.unit}'`);
|
|
88
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
|
+
}
|
|
89
207
|
|
|
90
208
|
function colorParts(value) {
|
|
91
209
|
if (typeof value === 'string') {
|
|
@@ -95,26 +213,128 @@ function colorParts(value) {
|
|
|
95
213
|
}
|
|
96
214
|
const space = value.colorSpace;
|
|
97
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
|
+
};
|
|
98
226
|
if (space === 'srgb') {
|
|
99
|
-
const rgb = value.components.map(
|
|
100
|
-
|
|
227
|
+
const rgb = value.components.map(componentNumber);
|
|
228
|
+
const out = resolveRgb(rgb);
|
|
229
|
+
return { ...out, alpha, css: out.hex };
|
|
101
230
|
}
|
|
102
231
|
if (space === 'oklch') {
|
|
103
|
-
const [L, C] = value.components.map(
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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}` : ''})` };
|
|
108
250
|
}
|
|
109
251
|
throw new Error(`unsupported colorSpace '${space}'`);
|
|
110
252
|
}
|
|
111
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
|
+
|
|
112
328
|
function scalar(token, type) {
|
|
113
329
|
const v = token.$value;
|
|
114
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;
|
|
115
335
|
if (typeof v === 'object' && v !== null && 'value' in v && 'unit' in v) return `${v.value}${v.unit}`;
|
|
116
336
|
if (Array.isArray(v)) return v.join(', ');
|
|
117
|
-
if (typeof v === 'object') return JSON.stringify(v);
|
|
337
|
+
if (typeof v === 'object' && v !== null) return JSON.stringify(v);
|
|
118
338
|
return String(v);
|
|
119
339
|
}
|
|
120
340
|
|
|
@@ -127,20 +347,48 @@ function applyMode(token, mode) {
|
|
|
127
347
|
}
|
|
128
348
|
|
|
129
349
|
function createResolver(tokens) {
|
|
130
|
-
const byPath = new Map(
|
|
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
|
+
}
|
|
131
356
|
const resolving = new Set();
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
if (typeof
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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;
|
|
144
392
|
}
|
|
145
393
|
|
|
146
394
|
function collect(file, mode) {
|
|
@@ -161,26 +409,100 @@ function collect(file, mode) {
|
|
|
161
409
|
return tokens.map((token) => resolveTokens(token));
|
|
162
410
|
}
|
|
163
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
|
+
|
|
164
446
|
function entries(tokens) {
|
|
165
|
-
const list = tokens.map((t) => ({
|
|
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
|
+
}));
|
|
166
454
|
const seen = new Map();
|
|
167
455
|
for (const t of list) {
|
|
168
456
|
for (const [kind, identifier] of [['identifier', t.name], ['variable', t.varName]]) {
|
|
169
457
|
const key = `${kind}:${identifier}`;
|
|
170
458
|
const previous = seen.get(key);
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
seen.set(key, current);
|
|
459
|
+
if (previous) throw new Error(`token collision: '${previous}' and '${t.pathKey}' both map to ${kind} '${identifier}'`);
|
|
460
|
+
seen.set(key, t.pathKey);
|
|
174
461
|
}
|
|
175
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
|
+
}
|
|
176
470
|
return list;
|
|
177
471
|
}
|
|
178
472
|
|
|
179
|
-
function render(format, list) {
|
|
180
|
-
const
|
|
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
|
+
|
|
181
482
|
if (format === 'css' || format === 'tailwind') {
|
|
182
|
-
const body = list.map((t) =>
|
|
183
|
-
|
|
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`;
|
|
184
506
|
}
|
|
185
507
|
if (format === 'swift') {
|
|
186
508
|
const lines = list.map((t) => {
|
|
@@ -193,7 +515,10 @@ function render(format, list) {
|
|
|
193
515
|
const ms = durationMs(t.token.$value);
|
|
194
516
|
return ` public static let ${t.name}: TimeInterval = ${fmtNumber(ms / 1000)} // seconds`;
|
|
195
517
|
}
|
|
196
|
-
if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {}))
|
|
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
|
+
}
|
|
197
522
|
return ` public static let ${t.name} = ${JSON.stringify(String(t.value))}`;
|
|
198
523
|
});
|
|
199
524
|
return `import Foundation\nimport SwiftUI\n\npublic enum PixelcraftTokens {\n${lines.join('\n')}\n}\n`;
|
|
@@ -206,8 +531,9 @@ function render(format, list) {
|
|
|
206
531
|
return `val ${t.name} = ${fmtNumber(durationMs(t.token.$value))}.milliseconds`;
|
|
207
532
|
}
|
|
208
533
|
if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {})) {
|
|
209
|
-
const unit = t.path
|
|
210
|
-
|
|
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}` : ''}`;
|
|
211
537
|
}
|
|
212
538
|
return `val ${t.name} = ${JSON.stringify(String(t.value))}`;
|
|
213
539
|
});
|
|
@@ -222,7 +548,10 @@ function render(format, list) {
|
|
|
222
548
|
const constructor = Number.isInteger(ms) ? `Duration(milliseconds: ${fmtNumber(ms)})` : `Duration(microseconds: ${Math.round(ms * 1000)})`;
|
|
223
549
|
return `static const Duration ${t.name} = ${constructor};`;
|
|
224
550
|
}
|
|
225
|
-
if (typeof t.token.$value === 'object' && 'value' in (t.token.$value || {}))
|
|
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
|
+
}
|
|
226
555
|
return `static const String ${t.name} = ${JSON.stringify(String(t.value))};`;
|
|
227
556
|
});
|
|
228
557
|
return `import 'dart:ui';\n\nclass PixelcraftTokens {\n ${lines.join('\n ')}\n}\n`;
|
|
@@ -237,47 +566,280 @@ function render(format, list) {
|
|
|
237
566
|
return `/* QSS has no runtime variables. Treat this file as preprocessor input. */\n${lines.join('\n')}\n`;
|
|
238
567
|
}
|
|
239
568
|
if (format === 'textual') {
|
|
240
|
-
return list.map((t) => `$${t.varName}: ${t.type === 'color' ? t.value.hex : t.value};`).join('\n')
|
|
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`;
|
|
241
753
|
}
|
|
242
754
|
throw new Error(`unknown format ${format}`);
|
|
243
755
|
}
|
|
244
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
|
+
|
|
245
817
|
try {
|
|
246
|
-
const
|
|
247
|
-
if (
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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}`);
|
|
257
831
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const specified = args.includes(name) || args.some((a) => a.startsWith(`${name}=`));
|
|
263
|
-
if (specified && !getOpt(name)) throw new Error(`${name} requires a value`);
|
|
264
|
-
}
|
|
265
|
-
const format = getOpt('--format') || 'all';
|
|
266
|
-
if (![...formats, 'all'].includes(format)) throw new Error(`unknown --format ${format}`);
|
|
267
|
-
const selected = format === 'all' ? formats : [format];
|
|
268
|
-
const mode = getOpt('--mode');
|
|
269
|
-
const list = entries(collect(input, mode));
|
|
270
|
-
const outDir = getOpt('--out-dir');
|
|
271
|
-
if (outDir) {
|
|
272
|
-
fs.mkdirSync(outDir, { recursive: true });
|
|
832
|
+
}
|
|
833
|
+
const renderOpts = { selector: cli.selector, preserveReferences: cli.preserveReferences };
|
|
834
|
+
if (cli.outDir) {
|
|
835
|
+
fs.mkdirSync(cli.outDir, { recursive: true });
|
|
273
836
|
for (const f of selected) {
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
fs.writeFileSync(file, render(f, list));
|
|
837
|
+
const file = path.join(cli.outDir, outputFileName(f, cli.mode));
|
|
838
|
+
fs.writeFileSync(file, render(f, list, renderOpts));
|
|
277
839
|
console.log(`wrote ${file}`);
|
|
278
840
|
}
|
|
279
841
|
} else {
|
|
280
|
-
for (const f of selected) console.log(`/* ${f}${mode ? ` mode=${mode}` : ''} */\n${render(f, list)}`);
|
|
842
|
+
for (const f of selected) console.log(`/* ${f}${cli.mode ? ` mode=${cli.mode}` : ''} */\n${render(f, list, renderOpts)}`);
|
|
281
843
|
}
|
|
282
844
|
} catch (error) {
|
|
283
845
|
console.error(`export-tokens: ${error.message}`);
|