@rien7/seji 0.0.0-stage → 0.6.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/bin/design-surface.mjs +6 -0
- package/bin/postinstall.mjs +19 -0
- package/bin/seji.mjs +573 -0
- package/dist/agent/host.d.mts +34 -0
- package/dist/agent/host.mjs +387 -0
- package/dist/agent/messages.d.mts +9 -0
- package/dist/agent/messages.mjs +70 -0
- package/dist/agent/runtimes.mjs +157 -0
- package/dist/cli/app.mjs +321 -0
- package/dist/cli/appScan.mjs +284 -0
- package/dist/cli/catalog.mjs +78 -0
- package/dist/cli/component.mjs +165 -0
- package/dist/cli/consolidate.mjs +159 -0
- package/dist/cli/cssImport.mjs +68 -0
- package/dist/cli/dev.mjs +335 -0
- package/dist/cli/doctor.mjs +306 -0
- package/dist/cli/init.mjs +338 -0
- package/dist/cli/legacyNames.mjs +266 -0
- package/dist/cli/migrate.mjs +163 -0
- package/dist/cli/prompt.mjs +34 -0
- package/dist/cli/propose.mjs +208 -0
- package/dist/cli/providers.mjs +344 -0
- package/dist/cli/reviewOps.mjs +110 -0
- package/dist/cli/semver.mjs +45 -0
- package/dist/cli/setup.mjs +357 -0
- package/dist/cli/sketches.mjs +47 -0
- package/dist/cli/skills.mjs +150 -0
- package/dist/cli/snapshot.mjs +107 -0
- package/dist/cli/tokenOps.mjs +120 -0
- package/dist/cli/types.mjs +191 -0
- package/dist/cli/updater.mjs +274 -0
- package/dist/components/astIndex.mjs +992 -0
- package/dist/components/ops.mjs +1069 -0
- package/dist/editor/AgentProposalCard.d.ts +10 -0
- package/dist/editor/AgentProposalCard.d.ts.map +1 -0
- package/dist/editor/AgentProposalCard.js +31 -0
- package/dist/editor/AgentProposalCard.js.map +1 -0
- package/dist/editor/App.d.ts +2 -0
- package/dist/editor/App.d.ts.map +1 -0
- package/dist/editor/App.js +2832 -0
- package/dist/editor/App.js.map +1 -0
- package/dist/editor/CanvasHud.d.ts +12 -0
- package/dist/editor/CanvasHud.d.ts.map +1 -0
- package/dist/editor/CanvasHud.js +13 -0
- package/dist/editor/CanvasHud.js.map +1 -0
- package/dist/editor/CanvasSurface.d.ts +31 -0
- package/dist/editor/CanvasSurface.d.ts.map +1 -0
- package/dist/editor/CanvasSurface.js +270 -0
- package/dist/editor/CanvasSurface.js.map +1 -0
- package/dist/editor/CommentPopover.d.ts +17 -0
- package/dist/editor/CommentPopover.d.ts.map +1 -0
- package/dist/editor/CommentPopover.js +62 -0
- package/dist/editor/CommentPopover.js.map +1 -0
- package/dist/editor/Comments.d.ts +13 -0
- package/dist/editor/Comments.d.ts.map +1 -0
- package/dist/editor/Comments.js +41 -0
- package/dist/editor/Comments.js.map +1 -0
- package/dist/editor/ComponentPage.d.ts +28 -0
- package/dist/editor/ComponentPage.d.ts.map +1 -0
- package/dist/editor/ComponentPage.js +55 -0
- package/dist/editor/ComponentPage.js.map +1 -0
- package/dist/editor/ComponentPanel.d.ts +38 -0
- package/dist/editor/ComponentPanel.d.ts.map +1 -0
- package/dist/editor/ComponentPanel.js +275 -0
- package/dist/editor/ComponentPanel.js.map +1 -0
- package/dist/editor/Glyph.d.ts +51 -0
- package/dist/editor/Glyph.d.ts.map +1 -0
- package/dist/editor/Glyph.js +50 -0
- package/dist/editor/Glyph.js.map +1 -0
- package/dist/editor/History.d.ts +7 -0
- package/dist/editor/History.d.ts.map +1 -0
- package/dist/editor/History.js +51 -0
- package/dist/editor/History.js.map +1 -0
- package/dist/editor/Inspector.d.ts +56 -0
- package/dist/editor/Inspector.d.ts.map +1 -0
- package/dist/editor/Inspector.js +510 -0
- package/dist/editor/Inspector.js.map +1 -0
- package/dist/editor/LazyMount.d.ts +10 -0
- package/dist/editor/LazyMount.d.ts.map +1 -0
- package/dist/editor/LazyMount.js +29 -0
- package/dist/editor/LazyMount.js.map +1 -0
- package/dist/editor/LocaleSwitch.d.ts +3 -0
- package/dist/editor/LocaleSwitch.d.ts.map +1 -0
- package/dist/editor/LocaleSwitch.js +9 -0
- package/dist/editor/LocaleSwitch.js.map +1 -0
- package/dist/editor/PreviewFrame.d.ts +10 -0
- package/dist/editor/PreviewFrame.d.ts.map +1 -0
- package/dist/editor/PreviewFrame.js +22 -0
- package/dist/editor/PreviewFrame.js.map +1 -0
- package/dist/editor/ProjectIndex.d.ts +12 -0
- package/dist/editor/ProjectIndex.d.ts.map +1 -0
- package/dist/editor/ProjectIndex.js +43 -0
- package/dist/editor/ProjectIndex.js.map +1 -0
- package/dist/editor/PromoteComponent.d.ts +28 -0
- package/dist/editor/PromoteComponent.d.ts.map +1 -0
- package/dist/editor/PromoteComponent.js +33 -0
- package/dist/editor/PromoteComponent.js.map +1 -0
- package/dist/editor/PromoteForm.d.ts +18 -0
- package/dist/editor/PromoteForm.d.ts.map +1 -0
- package/dist/editor/PromoteForm.js +35 -0
- package/dist/editor/PromoteForm.js.map +1 -0
- package/dist/editor/PromoteToken.d.ts +31 -0
- package/dist/editor/PromoteToken.d.ts.map +1 -0
- package/dist/editor/PromoteToken.js +94 -0
- package/dist/editor/PromoteToken.js.map +1 -0
- package/dist/editor/StatePreviews.d.ts +28 -0
- package/dist/editor/StatePreviews.d.ts.map +1 -0
- package/dist/editor/StatePreviews.js +113 -0
- package/dist/editor/StatePreviews.js.map +1 -0
- package/dist/editor/ValueCombo.d.ts +51 -0
- package/dist/editor/ValueCombo.d.ts.map +1 -0
- package/dist/editor/ValueCombo.js +260 -0
- package/dist/editor/ValueCombo.js.map +1 -0
- package/dist/editor/agent/AgentPanel.d.ts +19 -0
- package/dist/editor/agent/AgentPanel.d.ts.map +1 -0
- package/dist/editor/agent/AgentPanel.js +271 -0
- package/dist/editor/agent/AgentPanel.js.map +1 -0
- package/dist/editor/agent/Markdown.d.ts +5 -0
- package/dist/editor/agent/Markdown.d.ts.map +1 -0
- package/dist/editor/agent/Markdown.js +28 -0
- package/dist/editor/agent/Markdown.js.map +1 -0
- package/dist/editor/agent/agentApi.d.ts +106 -0
- package/dist/editor/agent/agentApi.d.ts.map +1 -0
- package/dist/editor/agent/agentApi.js +66 -0
- package/dist/editor/agent/agentApi.js.map +1 -0
- package/dist/editor/agent/toolLines.d.ts +38 -0
- package/dist/editor/agent/toolLines.d.ts.map +1 -0
- package/dist/editor/agent/toolLines.js +159 -0
- package/dist/editor/agent/toolLines.js.map +1 -0
- package/dist/editor/agent/useAgent.d.ts +15 -0
- package/dist/editor/agent/useAgent.d.ts.map +1 -0
- package/dist/editor/agent/useAgent.js +65 -0
- package/dist/editor/agent/useAgent.js.map +1 -0
- package/dist/editor/api.d.ts +378 -0
- package/dist/editor/api.d.ts.map +1 -0
- package/dist/editor/api.js +247 -0
- package/dist/editor/api.js.map +1 -0
- package/dist/editor/camera.d.ts +18 -0
- package/dist/editor/camera.d.ts.map +1 -0
- package/dist/editor/camera.js +40 -0
- package/dist/editor/camera.js.map +1 -0
- package/dist/editor/canvas.d.ts +25 -0
- package/dist/editor/canvas.d.ts.map +1 -0
- package/dist/editor/canvas.js +35 -0
- package/dist/editor/canvas.js.map +1 -0
- package/dist/editor/changes/ChangesPage.d.ts +25 -0
- package/dist/editor/changes/ChangesPage.d.ts.map +1 -0
- package/dist/editor/changes/ChangesPage.js +132 -0
- package/dist/editor/changes/ChangesPage.js.map +1 -0
- package/dist/editor/changes/changeModel.d.ts +25 -0
- package/dist/editor/changes/changeModel.d.ts.map +1 -0
- package/dist/editor/changes/changeModel.js +81 -0
- package/dist/editor/changes/changeModel.js.map +1 -0
- package/dist/editor/changes/changeState.d.mts +29 -0
- package/dist/editor/changes/changeState.mjs +187 -0
- package/dist/editor/chrome/EditorChrome.d.ts +49 -0
- package/dist/editor/chrome/EditorChrome.d.ts.map +1 -0
- package/dist/editor/chrome/EditorChrome.js +21 -0
- package/dist/editor/chrome/EditorChrome.js.map +1 -0
- package/dist/editor/drafts.d.ts +46 -0
- package/dist/editor/drafts.d.ts.map +1 -0
- package/dist/editor/drafts.js +38 -0
- package/dist/editor/drafts.js.map +1 -0
- package/dist/editor/i18n.d.ts +29 -0
- package/dist/editor/i18n.d.ts.map +1 -0
- package/dist/editor/i18n.js +2320 -0
- package/dist/editor/i18n.js.map +1 -0
- package/dist/editor/iconStroke.d.ts +6 -0
- package/dist/editor/iconStroke.d.ts.map +1 -0
- package/dist/editor/iconStroke.js +6 -0
- package/dist/editor/iconStroke.js.map +1 -0
- package/dist/editor/main.d.ts +2 -0
- package/dist/editor/main.d.ts.map +1 -0
- package/dist/editor/main.js +14 -0
- package/dist/editor/main.js.map +1 -0
- package/dist/editor/model.d.ts +16 -0
- package/dist/editor/model.d.ts.map +1 -0
- package/dist/editor/model.js +11 -0
- package/dist/editor/model.js.map +1 -0
- package/dist/editor/reasons.d.ts +44 -0
- package/dist/editor/reasons.d.ts.map +1 -0
- package/dist/editor/reasons.js +131 -0
- package/dist/editor/reasons.js.map +1 -0
- package/dist/editor/reviewLifecycle.d.ts +8 -0
- package/dist/editor/reviewLifecycle.d.ts.map +1 -0
- package/dist/editor/reviewLifecycle.js +21 -0
- package/dist/editor/reviewLifecycle.js.map +1 -0
- package/dist/editor/styles.css +8737 -0
- package/dist/editor/tokenMatch.d.ts +59 -0
- package/dist/editor/tokenMatch.d.ts.map +1 -0
- package/dist/editor/tokenMatch.js +198 -0
- package/dist/editor/tokenMatch.js.map +1 -0
- package/dist/editor/tokens/ConsolidatePage.d.ts +16 -0
- package/dist/editor/tokens/ConsolidatePage.d.ts.map +1 -0
- package/dist/editor/tokens/ConsolidatePage.js +244 -0
- package/dist/editor/tokens/ConsolidatePage.js.map +1 -0
- package/dist/editor/tokens/TokenActivity.d.ts +18 -0
- package/dist/editor/tokens/TokenActivity.d.ts.map +1 -0
- package/dist/editor/tokens/TokenActivity.js +18 -0
- package/dist/editor/tokens/TokenActivity.js.map +1 -0
- package/dist/editor/tokens/TokenDialogs.d.ts +26 -0
- package/dist/editor/tokens/TokenDialogs.d.ts.map +1 -0
- package/dist/editor/tokens/TokenDialogs.js +119 -0
- package/dist/editor/tokens/TokenDialogs.js.map +1 -0
- package/dist/editor/tokens/TokenList.d.ts +21 -0
- package/dist/editor/tokens/TokenList.d.ts.map +1 -0
- package/dist/editor/tokens/TokenList.js +98 -0
- package/dist/editor/tokens/TokenList.js.map +1 -0
- package/dist/editor/tokens/TokenPage.d.ts +25 -0
- package/dist/editor/tokens/TokenPage.d.ts.map +1 -0
- package/dist/editor/tokens/TokenPage.js +108 -0
- package/dist/editor/tokens/TokenPage.js.map +1 -0
- package/dist/editor/tokens/tokenModel.d.ts +35 -0
- package/dist/editor/tokens/tokenModel.d.ts.map +1 -0
- package/dist/editor/tokens/tokenModel.js +72 -0
- package/dist/editor/tokens/tokenModel.js.map +1 -0
- package/dist/editor/ui/Button.d.ts +3 -0
- package/dist/editor/ui/Button.d.ts.map +1 -0
- package/dist/editor/ui/Button.js +6 -0
- package/dist/editor/ui/Button.js.map +1 -0
- package/dist/editor/ui/CommentBox.d.ts +23 -0
- package/dist/editor/ui/CommentBox.d.ts.map +1 -0
- package/dist/editor/ui/CommentBox.js +41 -0
- package/dist/editor/ui/CommentBox.js.map +1 -0
- package/dist/editor/ui/Icon.d.ts +8 -0
- package/dist/editor/ui/Icon.d.ts.map +1 -0
- package/dist/editor/ui/Icon.js +6 -0
- package/dist/editor/ui/Icon.js.map +1 -0
- package/dist/editor/ui/IconButton.d.ts +11 -0
- package/dist/editor/ui/IconButton.d.ts.map +1 -0
- package/dist/editor/ui/IconButton.js +6 -0
- package/dist/editor/ui/IconButton.js.map +1 -0
- package/dist/editor/ui/NumberInput.d.ts +14 -0
- package/dist/editor/ui/NumberInput.d.ts.map +1 -0
- package/dist/editor/ui/NumberInput.js +6 -0
- package/dist/editor/ui/NumberInput.js.map +1 -0
- package/dist/editor/ui/PageLine.d.ts +14 -0
- package/dist/editor/ui/PageLine.d.ts.map +1 -0
- package/dist/editor/ui/PageLine.js +7 -0
- package/dist/editor/ui/PageLine.js.map +1 -0
- package/dist/editor/ui/SearchPicker.d.ts +41 -0
- package/dist/editor/ui/SearchPicker.d.ts.map +1 -0
- package/dist/editor/ui/SearchPicker.js +82 -0
- package/dist/editor/ui/SearchPicker.js.map +1 -0
- package/dist/editor/ui/Select.d.ts +19 -0
- package/dist/editor/ui/Select.d.ts.map +1 -0
- package/dist/editor/ui/Select.js +12 -0
- package/dist/editor/ui/Select.js.map +1 -0
- package/dist/editor/ui/TokenField.d.ts +14 -0
- package/dist/editor/ui/TokenField.d.ts.map +1 -0
- package/dist/editor/ui/TokenField.js +41 -0
- package/dist/editor/ui/TokenField.js.map +1 -0
- package/dist/editor/ui/TokenPicker.d.ts +31 -0
- package/dist/editor/ui/TokenPicker.d.ts.map +1 -0
- package/dist/editor/ui/TokenPicker.js +26 -0
- package/dist/editor/ui/TokenPicker.js.map +1 -0
- package/dist/editor/useBuildError.d.ts +7 -0
- package/dist/editor/useBuildError.d.ts.map +1 -0
- package/dist/editor/useBuildError.js +30 -0
- package/dist/editor/useBuildError.js.map +1 -0
- package/dist/editor/useLatestRequest.d.ts +22 -0
- package/dist/editor/useLatestRequest.d.ts.map +1 -0
- package/dist/editor/useLatestRequest.js +49 -0
- package/dist/editor/useLatestRequest.js.map +1 -0
- package/dist/editor-bundle/editor.css +2 -0
- package/dist/editor-bundle/editor.js +83 -0
- package/dist/editor-ui.d.ts +15 -0
- package/dist/editor-ui.d.ts.map +1 -0
- package/dist/editor-ui.js +14 -0
- package/dist/editor-ui.js.map +1 -0
- package/dist/inspector/runtime.d.ts +18 -0
- package/dist/inspector/runtime.d.ts.map +1 -0
- package/dist/inspector/runtime.js +1280 -0
- package/dist/inspector/runtime.js.map +1 -0
- package/dist/preview/main.d.ts +3 -0
- package/dist/preview/main.d.ts.map +1 -0
- package/dist/preview/main.js +320 -0
- package/dist/preview/main.js.map +1 -0
- package/dist/preview/preview.css +40 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/shared/buildError.d.mts +27 -0
- package/dist/shared/buildError.mjs +141 -0
- package/dist/shared/cameraFit.d.mts +16 -0
- package/dist/shared/cameraFit.mjs +47 -0
- package/dist/shared/canvasLayout.d.mts +13 -0
- package/dist/shared/canvasLayout.mjs +171 -0
- package/dist/shared/commentShots.d.mts +12 -0
- package/dist/shared/commentShots.mjs +53 -0
- package/dist/shared/componentExtract.d.mts +43 -0
- package/dist/shared/componentExtract.mjs +136 -0
- package/dist/shared/componentMeta.d.mts +26 -0
- package/dist/shared/componentMeta.mjs +87 -0
- package/dist/shared/componentOps.d.mts +70 -0
- package/dist/shared/componentOps.mjs +407 -0
- package/dist/shared/componentTarget.d.mts +15 -0
- package/dist/shared/componentTarget.mjs +58 -0
- package/dist/shared/components.d.mts +30 -0
- package/dist/shared/components.mjs +106 -0
- package/dist/shared/consolidateCategories.d.mts +2 -0
- package/dist/shared/consolidateCategories.mjs +6 -0
- package/dist/shared/env.d.mts +4 -0
- package/dist/shared/env.mjs +18 -0
- package/dist/shared/gitChanges.d.mts +2 -0
- package/dist/shared/gitChanges.mjs +30 -0
- package/dist/shared/oklab.d.mts +6 -0
- package/dist/shared/oklab.mjs +56 -0
- package/dist/shared/optimizeEntries.d.mts +5 -0
- package/dist/shared/optimizeEntries.mjs +24 -0
- package/dist/shared/packages.d.mts +11 -0
- package/dist/shared/packages.mjs +96 -0
- package/dist/shared/projectFiles.d.mts +23 -0
- package/dist/shared/projectFiles.mjs +72 -0
- package/dist/shared/prompt.d.mts +20 -0
- package/dist/shared/prompt.mjs +201 -0
- package/dist/shared/proposals.d.mts +11 -0
- package/dist/shared/proposals.mjs +42 -0
- package/dist/shared/protocol.d.ts +122 -0
- package/dist/shared/protocol.d.ts.map +1 -0
- package/dist/shared/protocol.js +7 -0
- package/dist/shared/protocol.js.map +1 -0
- package/dist/shared/reviewArchive.d.mts +4 -0
- package/dist/shared/reviewArchive.mjs +19 -0
- package/dist/shared/reviewStore.d.mts +30 -0
- package/dist/shared/reviewStore.mjs +218 -0
- package/dist/shared/reviewVerify.d.mts +21 -0
- package/dist/shared/reviewVerify.mjs +158 -0
- package/dist/shared/sizeModes.d.mts +15 -0
- package/dist/shared/sizeModes.mjs +53 -0
- package/dist/shared/sketches.d.mts +10 -0
- package/dist/shared/sketches.mjs +64 -0
- package/dist/shared/snapshotCheck.d.mts +13 -0
- package/dist/shared/snapshotCheck.mjs +81 -0
- package/dist/shared/timeout.d.mts +1 -0
- package/dist/shared/timeout.mjs +15 -0
- package/dist/shared/tokens.d.ts +2 -0
- package/dist/shared/tokens.d.ts.map +1 -0
- package/dist/shared/tokens.js +2 -0
- package/dist/shared/tokens.js.map +1 -0
- package/dist/shared/types.d.ts +689 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +13 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/shared/wheelRouting.d.mts +9 -0
- package/dist/shared/wheelRouting.mjs +31 -0
- package/dist/shared/writeScope.mjs +96 -0
- package/dist/snapshots/diff.d.mts +28 -0
- package/dist/snapshots/diff.mjs +263 -0
- package/dist/snapshots/index.d.mts +110 -0
- package/dist/snapshots/index.mjs +638 -0
- package/dist/snapshots/render.d.mts +24 -0
- package/dist/snapshots/render.mjs +250 -0
- package/dist/snapshots/toolOps.d.mts +25 -0
- package/dist/snapshots/toolOps.mjs +69 -0
- package/dist/tokens/adapters/css.mjs +51 -0
- package/dist/tokens/adapters/cssInCode.mjs +314 -0
- package/dist/tokens/adapters/oxcShared.mjs +80 -0
- package/dist/tokens/adapters/preprocessor.mjs +63 -0
- package/dist/tokens/adapters/registry.mjs +53 -0
- package/dist/tokens/adapters/tailwindcss.mjs +424 -0
- package/dist/tokens/adapters/types.mjs +117 -0
- package/dist/tokens/consolidate/index.d.mts +42 -0
- package/dist/tokens/consolidate/index.mjs +111 -0
- package/dist/tokens/consolidate/normalize.mjs +479 -0
- package/dist/tokens/consolidate/plan.mjs +726 -0
- package/dist/tokens/consolidate/scan.mjs +928 -0
- package/dist/tokens/extract.mjs +441 -0
- package/dist/tokens/moduleData.d.mts +14 -0
- package/dist/tokens/moduleData.mjs +32 -0
- package/dist/tokens/opLock.d.mts +4 -0
- package/dist/tokens/opLock.mjs +108 -0
- package/dist/tokens/ops.d.mts +71 -0
- package/dist/tokens/ops.mjs +1511 -0
- package/dist/tokens/pipeline.mjs +813 -0
- package/dist/tokens/report.d.mts +47 -0
- package/dist/tokens/report.mjs +257 -0
- package/dist/tokens/rewrite/code.mjs +172 -0
- package/dist/tokens/rewrite/css.mjs +154 -0
- package/dist/tokens/rewrite/index.mjs +244 -0
- package/dist/tokens/rewrite/tailwind.mjs +288 -0
- package/dist/tokens/rewrite/text.mjs +116 -0
- package/dist/tokens/rewrite/value.mjs +115 -0
- package/dist/tokens/usage.d.mts +97 -0
- package/dist/tokens/usage.mjs +680 -0
- package/dist/vite/agent.d.ts +21 -0
- package/dist/vite/agent.d.ts.map +1 -0
- package/dist/vite/agent.js +165 -0
- package/dist/vite/agent.js.map +1 -0
- package/dist/vite/events.d.ts +27 -0
- package/dist/vite/events.d.ts.map +1 -0
- package/dist/vite/events.js +156 -0
- package/dist/vite/events.js.map +1 -0
- package/dist/vite/layout.d.ts +2 -0
- package/dist/vite/layout.d.ts.map +1 -0
- package/dist/vite/layout.js +4 -0
- package/dist/vite/layout.js.map +1 -0
- package/dist/vite/plugin.d.ts +40 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/dist/vite/plugin.js +1255 -0
- package/dist/vite/plugin.js.map +1 -0
- package/dist/vite/requestGuard.d.mts +3 -0
- package/dist/vite/requestGuard.mjs +43 -0
- package/dist/vite/review.d.ts +11 -0
- package/dist/vite/review.d.ts.map +1 -0
- package/dist/vite/review.js +283 -0
- package/dist/vite/review.js.map +1 -0
- package/package.json +104 -4
- package/skills/seji/SKILL.md +395 -0
- package/skills/seji-authoring/SKILL.md +397 -0
- package/skills/seji-tokens/SKILL.md +432 -0
- package/README.md +0 -3
|
@@ -0,0 +1,813 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { generatedCssPath } from '../cli/app.mjs'
|
|
6
|
+
import { analyzeFilesWithAdapters } from './adapters/registry.mjs'
|
|
7
|
+
|
|
8
|
+
const TIERS = ['primitive', 'semantic', 'component']
|
|
9
|
+
const TIER_ORDER = Object.fromEntries(TIERS.map((tier, index) => [tier, index]))
|
|
10
|
+
|
|
11
|
+
export const DEFAULT_TOKEN_CONFIG = {
|
|
12
|
+
tokenDir: 'design/tokens',
|
|
13
|
+
cssOut: 'src/tokens.generated.css',
|
|
14
|
+
tsOut: 'design/.seji/tokens.generated.ts',
|
|
15
|
+
manifestOut: 'design/.seji/tokens.manifest.json',
|
|
16
|
+
scanDirs: ['src', 'design'],
|
|
17
|
+
// Directories outside the project root the tools may rewrite (shared/writeScope.mjs).
|
|
18
|
+
// Empty: token and component operations never write outside the root.
|
|
19
|
+
writableDirs: [],
|
|
20
|
+
cssFormat: 'theme',
|
|
21
|
+
contrastPairs: [],
|
|
22
|
+
localAliases: [],
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const readJson = (file) => JSON.parse(readFileSync(file, 'utf8'))
|
|
26
|
+
const sha256 = (value) => createHash('sha256').update(value).digest('hex')
|
|
27
|
+
const toPosix = (file) => file.split(sep).join('/')
|
|
28
|
+
|
|
29
|
+
export const cssNameOf = (tokenPath) => `--${tokenPath.join('-')}`
|
|
30
|
+
|
|
31
|
+
export const aliasPath = (value) => {
|
|
32
|
+
if (typeof value !== 'string') return null
|
|
33
|
+
const match = /^\{([^}]+)\}$/.exec(value)
|
|
34
|
+
return match ? match[1] : null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// A token's tier must be explicit: either `$extensions["design-surface"].tier` on the token or
|
|
38
|
+
// one of its groups, or a `<tier>.tokens.json` source file name. There is no silent default.
|
|
39
|
+
const tierOf = (meta, file, tokenPath) => {
|
|
40
|
+
const fromFile = /^(primitive|semantic|component)\.tokens\.json$/.exec(basename(file))?.[1]
|
|
41
|
+
const tier = meta.tier ?? fromFile
|
|
42
|
+
if (!tier) {
|
|
43
|
+
throw new Error(
|
|
44
|
+
`${file}: ${tokenPath.join('.')} has no tier. Set $extensions["design-surface"].tier (primitive | semantic | component) on the token or its group, or name the file <tier>.tokens.json.`,
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
if (!TIERS.includes(tier)) {
|
|
48
|
+
throw new Error(`${file}: ${tokenPath.join('.')} has invalid tier "${tier}". Expected one of: ${TIERS.join(', ')}`)
|
|
49
|
+
}
|
|
50
|
+
return tier
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function mergeMeta(base, next) {
|
|
54
|
+
return { ...base, ...(next ?? {}) }
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function loadTokenConfig(root, overrides = {}) {
|
|
58
|
+
const configPath = join(root, 'design/tokens.config.json')
|
|
59
|
+
const fileConfig = existsSync(configPath) ? readJson(configPath) : {}
|
|
60
|
+
const merged = {
|
|
61
|
+
...DEFAULT_TOKEN_CONFIG,
|
|
62
|
+
...fileConfig,
|
|
63
|
+
...overrides,
|
|
64
|
+
}
|
|
65
|
+
if (merged.cssFormat !== 'theme' && merged.cssFormat !== 'root') {
|
|
66
|
+
throw new Error(`Invalid cssFormat "${merged.cssFormat}". Expected "theme" or "root".`)
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
tokenDir: String(merged.tokenDir),
|
|
70
|
+
cssOut: String(merged.cssOut),
|
|
71
|
+
// Absolute: cssOut against the app (not the design home of a root design/).
|
|
72
|
+
cssOutPath: generatedCssPath(root, String(merged.cssOut)),
|
|
73
|
+
tsOut: String(merged.tsOut),
|
|
74
|
+
manifestOut: String(merged.manifestOut),
|
|
75
|
+
scanDirs: Array.isArray(merged.scanDirs) ? merged.scanDirs.map(String) : DEFAULT_TOKEN_CONFIG.scanDirs,
|
|
76
|
+
writableDirs: Array.isArray(merged.writableDirs) ? merged.writableDirs.map(String) : [],
|
|
77
|
+
cssFormat: merged.cssFormat,
|
|
78
|
+
contrastPairs: Array.isArray(merged.contrastPairs) ? merged.contrastPairs : [],
|
|
79
|
+
localAliases: Array.isArray(merged.localAliases) ? merged.localAliases.map(String) : [],
|
|
80
|
+
adapters: Array.isArray(merged.adapters) ? merged.adapters.map(String) : undefined,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function walkTokens(node, tokenPath, inheritedMeta, inheritedType, file, root, records) {
|
|
85
|
+
if (!node || typeof node !== 'object' || Array.isArray(node)) return
|
|
86
|
+
if ('$value' in node) {
|
|
87
|
+
const own = node.$extensions?.['design-surface'] ?? {}
|
|
88
|
+
const meta = mergeMeta(inheritedMeta, own)
|
|
89
|
+
const type = node.$type ?? inheritedType
|
|
90
|
+
if (!type) throw new Error(`${file}: ${tokenPath.join('.')} has no $type`)
|
|
91
|
+
const cssName = meta.cssName ?? cssNameOf(tokenPath)
|
|
92
|
+
records.push({
|
|
93
|
+
path: tokenPath,
|
|
94
|
+
cssName,
|
|
95
|
+
raw: node.$value,
|
|
96
|
+
alias: aliasPath(node.$value),
|
|
97
|
+
dtcgType: type,
|
|
98
|
+
type: meta.uiType ?? (type === 'color' ? 'color' : type === 'dimension' ? 'length' : 'text'),
|
|
99
|
+
tier: tierOf(meta, file, tokenPath),
|
|
100
|
+
group: meta.group ?? tokenPath[0],
|
|
101
|
+
label: meta.label ?? tokenPath[tokenPath.length - 1],
|
|
102
|
+
labelZh: meta.labelZh,
|
|
103
|
+
description: node.$description,
|
|
104
|
+
// DTCG `$deprecated`: true or a reason string (the tool writes the reason).
|
|
105
|
+
deprecated: node.$deprecated === undefined || node.$deprecated === false ? undefined : node.$deprecated,
|
|
106
|
+
groupLabel: inheritedMeta.label,
|
|
107
|
+
groupLabelZh: inheritedMeta.labelZh,
|
|
108
|
+
min: typeof meta.min === 'number' ? meta.min : undefined,
|
|
109
|
+
max: typeof meta.max === 'number' ? meta.max : undefined,
|
|
110
|
+
step: typeof meta.step === 'number' ? meta.step : undefined,
|
|
111
|
+
source: toPosix(relative(root, file)),
|
|
112
|
+
})
|
|
113
|
+
return
|
|
114
|
+
}
|
|
115
|
+
const own = node.$extensions?.['design-surface'] ?? {}
|
|
116
|
+
const meta = mergeMeta(inheritedMeta, own)
|
|
117
|
+
const type = node.$type ?? inheritedType
|
|
118
|
+
for (const [key, value] of Object.entries(node)) {
|
|
119
|
+
if (key.startsWith('$')) continue
|
|
120
|
+
walkTokens(value, [...tokenPath, key], meta, type, file, root, records)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function readTokenRecords(root, tokenDir) {
|
|
125
|
+
const tokenRoot = resolve(root, tokenDir)
|
|
126
|
+
if (!existsSync(tokenRoot)) {
|
|
127
|
+
throw new Error(`Missing token source directory: ${tokenRoot}`)
|
|
128
|
+
}
|
|
129
|
+
const files = readdirSync(tokenRoot)
|
|
130
|
+
.filter((file) => file.endsWith('.tokens.json'))
|
|
131
|
+
.sort()
|
|
132
|
+
.map((file) => join(tokenRoot, file))
|
|
133
|
+
if (!files.length) throw new Error(`No *.tokens.json files found in ${tokenRoot}`)
|
|
134
|
+
const records = []
|
|
135
|
+
for (const file of files) {
|
|
136
|
+
const json = readJson(file)
|
|
137
|
+
walkTokens(json, [], {}, undefined, file, root, records)
|
|
138
|
+
}
|
|
139
|
+
return { files, records }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function resolveRecords(records) {
|
|
143
|
+
const byPath = new Map(records.map((record) => [record.path.join('.'), record]))
|
|
144
|
+
const byCss = new Map(records.map((record) => [record.cssName, record]))
|
|
145
|
+
const seen = new Map()
|
|
146
|
+
|
|
147
|
+
const resolveToken = (record, stack = []) => {
|
|
148
|
+
const key = record.path.join('.')
|
|
149
|
+
if (seen.has(key)) return seen.get(key)
|
|
150
|
+
if (stack.includes(key)) {
|
|
151
|
+
throw new Error(`Circular token alias: ${[...stack, key].join(' -> ')}`)
|
|
152
|
+
}
|
|
153
|
+
let value
|
|
154
|
+
if (record.alias) {
|
|
155
|
+
const target = byPath.get(record.alias)
|
|
156
|
+
if (!target) throw new Error(`${key} references missing token ${record.alias}`)
|
|
157
|
+
value = resolveToken(target, [...stack, key])
|
|
158
|
+
} else if (record.raw && typeof record.raw === 'object' && !Array.isArray(record.raw)) {
|
|
159
|
+
if ('value' in record.raw && 'unit' in record.raw) {
|
|
160
|
+
value = `${record.raw.value}${record.raw.unit}`
|
|
161
|
+
} else {
|
|
162
|
+
throw new Error(`${key} has an unsupported composite value`)
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
value = String(record.raw).replace(/var\((--[a-zA-Z0-9_-]+)\)/g, (match, name) => {
|
|
166
|
+
const target = byCss.get(name)
|
|
167
|
+
return target ? resolveToken(target, stack) : match
|
|
168
|
+
})
|
|
169
|
+
}
|
|
170
|
+
seen.set(key, value)
|
|
171
|
+
return value
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
for (const record of records) {
|
|
175
|
+
record.value = resolveToken(record)
|
|
176
|
+
if (record.alias) {
|
|
177
|
+
const target = byPath.get(record.alias)
|
|
178
|
+
if (target && record.dtcgType !== target.dtcgType) {
|
|
179
|
+
// DTCG aliases inherit the target type; a mismatched explicit type is a bug.
|
|
180
|
+
throw new Error(
|
|
181
|
+
`${record.path.join('.')} type ${record.dtcgType} does not match alias ${record.alias} type ${target.dtcgType}`,
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const seenCss = new Map()
|
|
188
|
+
for (const record of records) {
|
|
189
|
+
if (seenCss.has(record.cssName)) {
|
|
190
|
+
throw new Error(
|
|
191
|
+
`Duplicate CSS variable ${record.cssName}: ${seenCss.get(record.cssName)} and ${record.path.join('.')}`,
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
seenCss.set(record.cssName, record.path.join('.'))
|
|
195
|
+
if (!/^--[a-zA-Z0-9_-]+$/.test(record.cssName)) {
|
|
196
|
+
throw new Error(`Invalid CSS variable ${record.cssName}`)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return { byPath, byCss: new Map(records.map((record) => [record.cssName, record])) }
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function cssValue(record, byPath) {
|
|
203
|
+
if (record.alias) {
|
|
204
|
+
const target = byPath.get(record.alias)
|
|
205
|
+
if (!target) throw new Error(`Missing alias target ${record.alias}`)
|
|
206
|
+
return `var(${target.cssName})`
|
|
207
|
+
}
|
|
208
|
+
if (record.raw && typeof record.raw === 'object' && 'value' in record.raw && 'unit' in record.raw) {
|
|
209
|
+
return `${record.raw.value}${record.raw.unit}`
|
|
210
|
+
}
|
|
211
|
+
return String(record.raw)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** The generated CSS file of `config` (see generatedCssPath). */
|
|
215
|
+
export const cssOutFile = (root, config) => config.cssOutPath ?? generatedCssPath(root, config.cssOut)
|
|
216
|
+
|
|
217
|
+
export function scanFiles(root, config) {
|
|
218
|
+
const roots = config.scanDirs.map((dir) => resolve(root, dir))
|
|
219
|
+
const ignoredFiles = new Set([
|
|
220
|
+
cssOutFile(root, config),
|
|
221
|
+
resolve(root, config.tsOut),
|
|
222
|
+
resolve(root, config.manifestOut),
|
|
223
|
+
])
|
|
224
|
+
const files = []
|
|
225
|
+
const visit = (dir) => {
|
|
226
|
+
if (!existsSync(dir)) return
|
|
227
|
+
for (const entry of readdirSync(dir)) {
|
|
228
|
+
if (
|
|
229
|
+
entry === 'node_modules' ||
|
|
230
|
+
entry === 'dist' ||
|
|
231
|
+
entry === '.git' ||
|
|
232
|
+
entry === '.seji' ||
|
|
233
|
+
entry === 'tokens.generated.css' ||
|
|
234
|
+
entry === 'tokens.generated.ts'
|
|
235
|
+
) {
|
|
236
|
+
continue
|
|
237
|
+
}
|
|
238
|
+
const file = join(dir, entry)
|
|
239
|
+
if (ignoredFiles.has(file)) continue
|
|
240
|
+
const stat = statSync(file)
|
|
241
|
+
if (stat.isDirectory()) {
|
|
242
|
+
visit(file)
|
|
243
|
+
} else if (
|
|
244
|
+
/\.(css|scss|sass|less|tsx|ts|jsx|js|mts|cts|mjs|cjs)$/i.test(entry) &&
|
|
245
|
+
!file.endsWith('tokens.manifest.json')
|
|
246
|
+
) {
|
|
247
|
+
files.push(file)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
roots.forEach(visit)
|
|
252
|
+
return files
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function collectProposedTokenRefs(root) {
|
|
256
|
+
const designRoot = join(root, 'design')
|
|
257
|
+
const proposed = new Set()
|
|
258
|
+
if (!existsSync(designRoot)) return proposed
|
|
259
|
+
for (const entry of readdirSync(designRoot, { withFileTypes: true })) {
|
|
260
|
+
if (!entry.isDirectory()) continue
|
|
261
|
+
const reviewFile = join(designRoot, entry.name, 'review.json')
|
|
262
|
+
if (!existsSync(reviewFile)) continue
|
|
263
|
+
try {
|
|
264
|
+
const review = readJson(reviewFile)
|
|
265
|
+
for (const item of review?.items ?? []) {
|
|
266
|
+
if (
|
|
267
|
+
item?.kind === 'token' &&
|
|
268
|
+
item?.author === 'agent' &&
|
|
269
|
+
item?.status !== 'archived' &&
|
|
270
|
+
item?.proposalDecision !== 'rejected' &&
|
|
271
|
+
item?.target?.type === 'token' &&
|
|
272
|
+
typeof item.target.token === 'string' &&
|
|
273
|
+
item.target.token.startsWith('--')
|
|
274
|
+
) {
|
|
275
|
+
proposed.add(item.target.token)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
} catch {
|
|
279
|
+
// ignore malformed review ledgers during token scan
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return proposed
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async function scanUsage(root, records, config) {
|
|
286
|
+
const files = scanFiles(root, config)
|
|
287
|
+
const diagnostics = await analyzeFilesWithAdapters({
|
|
288
|
+
root,
|
|
289
|
+
files,
|
|
290
|
+
adapters: config.adapters,
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
const tokenNames = new Set(records.map((record) => record.cssName))
|
|
294
|
+
const usedIn = new Map(records.map((record) => [record.cssName, []]))
|
|
295
|
+
const defined = new Set(records.map((record) => record.cssName))
|
|
296
|
+
const localAliases = new Set(config.localAliases)
|
|
297
|
+
const proposedTokens = collectProposedTokenRefs(root)
|
|
298
|
+
const usedProposedTokens = new Map()
|
|
299
|
+
const unknown = new Set()
|
|
300
|
+
|
|
301
|
+
const hardcodedByFile = new Map()
|
|
302
|
+
const clusterMap = new Map()
|
|
303
|
+
const unsupportedMap = new Map()
|
|
304
|
+
|
|
305
|
+
for (const diag of diagnostics) {
|
|
306
|
+
if (diag.kind === 'token-ref' && diag.token) {
|
|
307
|
+
const name = diag.token
|
|
308
|
+
if (
|
|
309
|
+
name.startsWith('--tw-') ||
|
|
310
|
+
name.startsWith('--anchor-') ||
|
|
311
|
+
name.startsWith('--available-') ||
|
|
312
|
+
name.startsWith('--transform-')
|
|
313
|
+
) {
|
|
314
|
+
continue
|
|
315
|
+
}
|
|
316
|
+
if (tokenNames.has(name)) {
|
|
317
|
+
usedIn.get(name).push(diag.file)
|
|
318
|
+
} else if (proposedTokens.has(name)) {
|
|
319
|
+
let filesForProposed = usedProposedTokens.get(name)
|
|
320
|
+
if (!filesForProposed) {
|
|
321
|
+
filesForProposed = new Set()
|
|
322
|
+
usedProposedTokens.set(name, filesForProposed)
|
|
323
|
+
}
|
|
324
|
+
filesForProposed.add(diag.file)
|
|
325
|
+
} else if (!localAliases.has(name) && !defined.has(name)) {
|
|
326
|
+
unknown.add(`${name} (${diag.file})`)
|
|
327
|
+
}
|
|
328
|
+
continue
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (diag.kind === 'literal') {
|
|
332
|
+
let fileMap = hardcodedByFile.get(diag.file)
|
|
333
|
+
if (!fileMap) {
|
|
334
|
+
fileMap = new Map()
|
|
335
|
+
hardcodedByFile.set(diag.file, fileMap)
|
|
336
|
+
}
|
|
337
|
+
fileMap.set(diag.value, (fileMap.get(diag.value) ?? 0) + 1)
|
|
338
|
+
|
|
339
|
+
let cluster = clusterMap.get(diag.value)
|
|
340
|
+
if (!cluster) {
|
|
341
|
+
cluster = { value: diag.value, count: 0, files: new Set(), adapters: new Set() }
|
|
342
|
+
clusterMap.set(diag.value, cluster)
|
|
343
|
+
}
|
|
344
|
+
cluster.count += 1
|
|
345
|
+
cluster.files.add(diag.file)
|
|
346
|
+
cluster.adapters.add(diag.adapter)
|
|
347
|
+
continue
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (diag.kind === 'unsupported') {
|
|
351
|
+
const reason = diag.reason ?? 'unsupported'
|
|
352
|
+
const key = `${diag.file}\0${diag.adapter}\0${reason}`
|
|
353
|
+
const existing = unsupportedMap.get(key)
|
|
354
|
+
if (existing) {
|
|
355
|
+
existing.count += 1
|
|
356
|
+
} else {
|
|
357
|
+
unsupportedMap.set(key, {
|
|
358
|
+
file: diag.file,
|
|
359
|
+
adapter: diag.adapter,
|
|
360
|
+
reason,
|
|
361
|
+
count: 1,
|
|
362
|
+
...(typeof diag.line === 'number' ? { line: diag.line } : {}),
|
|
363
|
+
})
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
for (const [name, filesUsed] of usedIn) {
|
|
369
|
+
usedIn.set(name, [...new Set(filesUsed)].sort())
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const hardcoded = [...hardcodedByFile.entries()]
|
|
373
|
+
.map(([file, valueCounts]) => {
|
|
374
|
+
const values = [...valueCounts.entries()]
|
|
375
|
+
.map(([value, count]) => ({ value, count }))
|
|
376
|
+
.sort((a, b) => b.count - a.count || a.value.localeCompare(b.value))
|
|
377
|
+
const count = values.reduce((sum, entry) => sum + entry.count, 0)
|
|
378
|
+
return { file, count, values }
|
|
379
|
+
})
|
|
380
|
+
.sort((a, b) => b.count - a.count || a.file.localeCompare(b.file))
|
|
381
|
+
|
|
382
|
+
const clusters = [...clusterMap.values()]
|
|
383
|
+
.map((cluster) => ({
|
|
384
|
+
value: cluster.value,
|
|
385
|
+
count: cluster.count,
|
|
386
|
+
files: [...cluster.files].sort(),
|
|
387
|
+
adapters: [...cluster.adapters].sort(),
|
|
388
|
+
}))
|
|
389
|
+
.sort((a, b) => b.count - a.count || a.value.localeCompare(b.value))
|
|
390
|
+
|
|
391
|
+
const unsupported = [...unsupportedMap.values()].sort(
|
|
392
|
+
(a, b) => b.count - a.count || a.file.localeCompare(b.file),
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
const proposedRefs = [...usedProposedTokens.entries()]
|
|
396
|
+
.map(([token, filesSet]) => ({ token, files: [...filesSet].sort() }))
|
|
397
|
+
.sort((a, b) => a.token.localeCompare(b.token))
|
|
398
|
+
|
|
399
|
+
return {
|
|
400
|
+
usedIn,
|
|
401
|
+
unknown: [...unknown].sort(),
|
|
402
|
+
hardcoded,
|
|
403
|
+
clusters,
|
|
404
|
+
unsupported,
|
|
405
|
+
proposedRefs,
|
|
406
|
+
diagnostics,
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
export function colorToRgb(value) {
|
|
411
|
+
if (typeof value !== 'string') return null
|
|
412
|
+
const hex = value.trim().match(/^#([0-9a-f]{3,8})$/i)
|
|
413
|
+
if (hex) {
|
|
414
|
+
const raw = hex[1]
|
|
415
|
+
if (raw.length === 3) {
|
|
416
|
+
return [0, 1, 2].map((i) => parseInt(raw[i] + raw[i], 16))
|
|
417
|
+
}
|
|
418
|
+
if (raw.length === 6 || raw.length === 8) {
|
|
419
|
+
return [0, 2, 4].map((i) => parseInt(raw.slice(i, i + 2), 16))
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const rgb = value.trim().match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i)
|
|
423
|
+
if (rgb) return [Number(rgb[1]), Number(rgb[2]), Number(rgb[3])]
|
|
424
|
+
return null
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function luminance(rgb) {
|
|
428
|
+
const channels = rgb.map((channel) => {
|
|
429
|
+
const value = channel / 255
|
|
430
|
+
return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4
|
|
431
|
+
})
|
|
432
|
+
return 0.2126 * channels[0] + 0.7152 * channels[1] + 0.0722 * channels[2]
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function contrast(fg, bg) {
|
|
436
|
+
const a = luminance(fg)
|
|
437
|
+
const b = luminance(bg)
|
|
438
|
+
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05)
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function checkContrast(byPath, contrastPairs) {
|
|
442
|
+
const results = []
|
|
443
|
+
for (const pair of contrastPairs) {
|
|
444
|
+
if (!Array.isArray(pair) || pair.length < 2) continue
|
|
445
|
+
const [fgPath, bgPath] = pair
|
|
446
|
+
const fgToken = byPath.get(fgPath)
|
|
447
|
+
const bgToken = byPath.get(bgPath)
|
|
448
|
+
if (!fgToken || !bgToken) continue
|
|
449
|
+
const fg = colorToRgb(fgToken.value)
|
|
450
|
+
const bg = colorToRgb(bgToken.value)
|
|
451
|
+
if (!fg || !bg) continue
|
|
452
|
+
const ratio = contrast(fg, bg)
|
|
453
|
+
results.push({ fg: fgPath, bg: bgPath, ratio: Math.round(ratio * 100) / 100, pass: ratio >= 4.5 })
|
|
454
|
+
}
|
|
455
|
+
return results
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function resolveRuntimeImport(root) {
|
|
459
|
+
const pkgPath = resolve(root, 'package.json')
|
|
460
|
+
if (!existsSync(pkgPath)) return '@rien7/design-surface-runtime'
|
|
461
|
+
try {
|
|
462
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'))
|
|
463
|
+
const deps = {
|
|
464
|
+
...(pkg.dependencies ?? {}),
|
|
465
|
+
...(pkg.devDependencies ?? {}),
|
|
466
|
+
...(pkg.peerDependencies ?? {}),
|
|
467
|
+
}
|
|
468
|
+
if (!('@rien7/design-surface-runtime' in deps) && '@rien7/seji' in deps) {
|
|
469
|
+
return '@rien7/seji/runtime'
|
|
470
|
+
}
|
|
471
|
+
} catch {
|
|
472
|
+
// ignore malformed package.json
|
|
473
|
+
}
|
|
474
|
+
return '@rien7/design-surface-runtime'
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function buildOutputs(root, records, files, usage, config) {
|
|
478
|
+
const byPath = new Map(records.map((record) => [record.path.join('.'), record]))
|
|
479
|
+
const sourceHash = sha256(files.map((file) => readFileSync(file, 'utf8')).join('\n'))
|
|
480
|
+
const sorted = [...records].sort((a, b) => {
|
|
481
|
+
const tier = (TIER_ORDER[a.tier] ?? 99) - (TIER_ORDER[b.tier] ?? 99)
|
|
482
|
+
if (tier) return tier
|
|
483
|
+
if (a.group !== b.group) return a.group.localeCompare(b.group)
|
|
484
|
+
return a.path.join('.').localeCompare(b.path.join('.'))
|
|
485
|
+
})
|
|
486
|
+
|
|
487
|
+
const groups = new Map()
|
|
488
|
+
for (const record of sorted) {
|
|
489
|
+
const key = `${record.tier}:${record.group}`
|
|
490
|
+
if (!groups.has(key)) {
|
|
491
|
+
groups.set(key, {
|
|
492
|
+
id: key,
|
|
493
|
+
tier: record.tier,
|
|
494
|
+
tokens: [],
|
|
495
|
+
})
|
|
496
|
+
}
|
|
497
|
+
groups.get(key).tokens.push(record)
|
|
498
|
+
}
|
|
499
|
+
// Group labels come from the group metadata, captured on each token's walk.
|
|
500
|
+
// The group label is stable even when a token has its own label.
|
|
501
|
+
for (const record of records) {
|
|
502
|
+
const key = `${record.tier}:${record.group}`
|
|
503
|
+
const group = groups.get(key)
|
|
504
|
+
if (!group) continue
|
|
505
|
+
if (!group.label) {
|
|
506
|
+
group.label = record.groupLabel ?? record.group
|
|
507
|
+
group.labelZh = record.groupLabelZh
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
const cssBlock = config.cssFormat === 'root' ? ':root {' : '@theme {'
|
|
512
|
+
const tailwindExcludes =
|
|
513
|
+
config.cssFormat === 'theme'
|
|
514
|
+
? [
|
|
515
|
+
`@source not "${toPosix(relative(dirname(cssOutFile(root, config)), resolve(root, 'design')))}/**/canvas.json";`,
|
|
516
|
+
`@source not "${toPosix(relative(dirname(cssOutFile(root, config)), resolve(root, 'design')))}/**/review.json";`,
|
|
517
|
+
`@source not "${toPosix(relative(dirname(cssOutFile(root, config)), resolve(root, 'design')))}/.seji/**";`,
|
|
518
|
+
'',
|
|
519
|
+
]
|
|
520
|
+
: []
|
|
521
|
+
const css = [
|
|
522
|
+
`/* Generated from ${config.tokenDir}/*.tokens.json. Do not edit by hand. */`,
|
|
523
|
+
`/* sourceHash: ${sourceHash} */`,
|
|
524
|
+
...tailwindExcludes,
|
|
525
|
+
cssBlock,
|
|
526
|
+
...sorted.map((record) => ` ${record.cssName}: ${cssValue(record, byPath)};`),
|
|
527
|
+
'}',
|
|
528
|
+
'',
|
|
529
|
+
].join('\n')
|
|
530
|
+
|
|
531
|
+
const aliasedBy = new Map(records.map((record) => [record.path.join('.'), []]))
|
|
532
|
+
for (const record of records) {
|
|
533
|
+
if (record.alias) aliasedBy.get(record.alias)?.push(record.path.join('.'))
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const tokenDefs = sorted.map((record) => ({
|
|
537
|
+
name: record.cssName,
|
|
538
|
+
path: record.path.join('.'),
|
|
539
|
+
label: record.label,
|
|
540
|
+
...(record.labelZh ? { labelZh: record.labelZh } : {}),
|
|
541
|
+
type: record.type,
|
|
542
|
+
...(record.description ? { description: record.description } : {}),
|
|
543
|
+
...(record.deprecated !== undefined ? { deprecated: record.deprecated } : {}),
|
|
544
|
+
...(record.min !== undefined ? { min: record.min } : {}),
|
|
545
|
+
...(record.max !== undefined ? { max: record.max } : {}),
|
|
546
|
+
...(record.step !== undefined ? { step: record.step } : {}),
|
|
547
|
+
tier: record.tier,
|
|
548
|
+
...(record.alias ? { alias: record.alias } : {}),
|
|
549
|
+
source: record.source,
|
|
550
|
+
value: record.value,
|
|
551
|
+
...(usage.usedIn.get(record.cssName)?.length ? { usedIn: usage.usedIn.get(record.cssName) } : {}),
|
|
552
|
+
...(aliasedBy.get(record.path.join('.'))?.length
|
|
553
|
+
? { aliasedBy: [...new Set(aliasedBy.get(record.path.join('.')))].sort() }
|
|
554
|
+
: {}),
|
|
555
|
+
}))
|
|
556
|
+
|
|
557
|
+
const groupList = [...groups.values()].map((group) => ({
|
|
558
|
+
id: group.id,
|
|
559
|
+
label: group.label ?? group.id,
|
|
560
|
+
...(group.labelZh ? { labelZh: group.labelZh } : {}),
|
|
561
|
+
tier: group.tier,
|
|
562
|
+
tokens: group.tokens.map((record) => tokenDefs.find((token) => token.name === record.cssName)),
|
|
563
|
+
}))
|
|
564
|
+
|
|
565
|
+
const values = Object.fromEntries(sorted.map((record) => [record.cssName, record.value]))
|
|
566
|
+
const sources = Object.fromEntries(sorted.map((record) => [record.cssName, record.source]))
|
|
567
|
+
const aliases = Object.fromEntries(
|
|
568
|
+
sorted.filter((record) => record.alias).map((record) => [record.cssName, record.alias]),
|
|
569
|
+
)
|
|
570
|
+
|
|
571
|
+
const byPathAll = new Map(records.map((record) => [record.path.join('.'), record]))
|
|
572
|
+
const duplicateGroups = new Map()
|
|
573
|
+
for (const record of records) {
|
|
574
|
+
if (record.alias) continue
|
|
575
|
+
const key = `${record.group}:${record.value}`
|
|
576
|
+
const list = duplicateGroups.get(key) ?? []
|
|
577
|
+
list.push(record)
|
|
578
|
+
duplicateGroups.set(key, list)
|
|
579
|
+
}
|
|
580
|
+
const duplicates = [...duplicateGroups.values()]
|
|
581
|
+
.filter((list) => list.length > 1)
|
|
582
|
+
.map((list) => ({
|
|
583
|
+
group: list[0].group,
|
|
584
|
+
value: list[0].value,
|
|
585
|
+
tokens: list.map((record) => record.path.join('.')),
|
|
586
|
+
}))
|
|
587
|
+
const orphans = sorted
|
|
588
|
+
.filter(
|
|
589
|
+
(record) =>
|
|
590
|
+
!(usage.usedIn.get(record.cssName)?.length) &&
|
|
591
|
+
!(aliasedBy.get(record.path.join('.'))?.length),
|
|
592
|
+
)
|
|
593
|
+
.map((record) => record.path.join('.'))
|
|
594
|
+
const semanticLiterals = sorted
|
|
595
|
+
.filter((record) => record.tier === 'semantic' && !record.alias)
|
|
596
|
+
.map((record) => record.path.join('.'))
|
|
597
|
+
const componentPrimitive = sorted
|
|
598
|
+
.filter(
|
|
599
|
+
(record) =>
|
|
600
|
+
record.tier === 'component' &&
|
|
601
|
+
record.alias &&
|
|
602
|
+
byPathAll.get(record.alias)?.tier === 'primitive',
|
|
603
|
+
)
|
|
604
|
+
.map((record) => ({ token: record.path.join('.'), alias: record.alias }))
|
|
605
|
+
const health = {
|
|
606
|
+
duplicates,
|
|
607
|
+
orphans,
|
|
608
|
+
semanticLiterals,
|
|
609
|
+
componentPrimitive,
|
|
610
|
+
hardcoded: usage.hardcoded,
|
|
611
|
+
clusters: usage.clusters,
|
|
612
|
+
unsupported: usage.unsupported,
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const runtimeImport = resolveRuntimeImport(root)
|
|
616
|
+
|
|
617
|
+
const ts = [
|
|
618
|
+
`// Generated from ${config.tokenDir}/*.tokens.json. Do not edit by hand.`,
|
|
619
|
+
`// sourceHash: ${sourceHash}`,
|
|
620
|
+
`import type { TokenGroup } from '${runtimeImport}'`,
|
|
621
|
+
'',
|
|
622
|
+
`export const tokenSourceHash = ${JSON.stringify(sourceHash)}`,
|
|
623
|
+
`export const tokenGroups: TokenGroup[] = ${JSON.stringify(groupList, null, 2)}`,
|
|
624
|
+
'',
|
|
625
|
+
`export const tokenValues: Record<string, string> = ${JSON.stringify(values, null, 2)}`,
|
|
626
|
+
'',
|
|
627
|
+
`export const tokenSources: Record<string, string> = ${JSON.stringify(sources, null, 2)}`,
|
|
628
|
+
'',
|
|
629
|
+
`export const tokenAliases: Record<string, string> = ${JSON.stringify(aliases, null, 2)}`,
|
|
630
|
+
'',
|
|
631
|
+
`export const tokenHealth = ${JSON.stringify(health, null, 2)}`,
|
|
632
|
+
'',
|
|
633
|
+
].join('\n')
|
|
634
|
+
|
|
635
|
+
const manifest = {
|
|
636
|
+
version: 1,
|
|
637
|
+
sourceHash,
|
|
638
|
+
generatedAt: 'generated',
|
|
639
|
+
counts: {
|
|
640
|
+
total: sorted.length,
|
|
641
|
+
byTier: Object.fromEntries(
|
|
642
|
+
TIERS.map((tier) => [tier, sorted.filter((record) => record.tier === tier).length]),
|
|
643
|
+
),
|
|
644
|
+
},
|
|
645
|
+
tokens: sorted.map((record) => ({
|
|
646
|
+
path: record.path.join('.'),
|
|
647
|
+
cssName: record.cssName,
|
|
648
|
+
type: record.dtcgType,
|
|
649
|
+
tier: record.tier,
|
|
650
|
+
group: record.group,
|
|
651
|
+
value: record.value,
|
|
652
|
+
alias: record.alias,
|
|
653
|
+
source: record.source,
|
|
654
|
+
description: record.description,
|
|
655
|
+
...(record.deprecated !== undefined ? { deprecated: record.deprecated } : {}),
|
|
656
|
+
usedIn: usage.usedIn.get(record.cssName) ?? [],
|
|
657
|
+
aliasedBy: [...new Set(aliasedBy.get(record.path.join('.')) ?? [])].sort(),
|
|
658
|
+
})),
|
|
659
|
+
contrast: checkContrast(byPath, config.contrastPairs),
|
|
660
|
+
unknownVars: usage.unknown,
|
|
661
|
+
hardcoded: usage.hardcoded,
|
|
662
|
+
clusters: usage.clusters,
|
|
663
|
+
unsupported: usage.unsupported,
|
|
664
|
+
health,
|
|
665
|
+
}
|
|
666
|
+
// The same values the generated TS module exports (virtual:design/tokens), as plain data
|
|
667
|
+
// for GET /__seji/api/tokens.
|
|
668
|
+
const data = {
|
|
669
|
+
tokenSourceHash: sourceHash,
|
|
670
|
+
tokenGroups: groupList,
|
|
671
|
+
tokenValues: values,
|
|
672
|
+
tokenSources: sources,
|
|
673
|
+
tokenAliases: aliases,
|
|
674
|
+
tokenHealth: health,
|
|
675
|
+
}
|
|
676
|
+
return { css, ts, manifest, sorted, groupList, health, data }
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function validate(records, usage, outputs) {
|
|
680
|
+
const errors = []
|
|
681
|
+
const warnings = []
|
|
682
|
+
for (const record of records) {
|
|
683
|
+
if (
|
|
684
|
+
record.dtcgType === 'dimension' &&
|
|
685
|
+
!record.alias &&
|
|
686
|
+
!/^-?\d+(\.\d+)?(px|rem|em|%)$/.test(record.value)
|
|
687
|
+
) {
|
|
688
|
+
errors.push(`${record.path.join('.')} is not a valid dimension: ${record.value}`)
|
|
689
|
+
}
|
|
690
|
+
if (
|
|
691
|
+
record.dtcgType === 'color' &&
|
|
692
|
+
!record.alias &&
|
|
693
|
+
!colorToRgb(record.value) &&
|
|
694
|
+
!/^(color-mix|rgb|hsl|oklch|var\()/i.test(record.value)
|
|
695
|
+
) {
|
|
696
|
+
errors.push(`${record.path.join('.')} is not a valid color: ${record.value}`)
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
for (const item of outputs.manifest.contrast) {
|
|
700
|
+
if (!item.pass) errors.push(`Contrast ${item.fg} on ${item.bg} is ${item.ratio}:1, needs 4.5:1`)
|
|
701
|
+
}
|
|
702
|
+
// Variables the code reads that are not tokens: reported (all of them, in the manifest's
|
|
703
|
+
// unknownVars and the build result), never fatal. `tokens extract` turns them into tokens.
|
|
704
|
+
if (usage.unknown.length) {
|
|
705
|
+
warnings.push(
|
|
706
|
+
`${usage.unknown.length} CSS variable(s) used but not defined as tokens (run seji tokens extract, or list them in localAliases): ${usage.unknown.join(', ')}`,
|
|
707
|
+
)
|
|
708
|
+
}
|
|
709
|
+
if (usage.proposedRefs?.length) {
|
|
710
|
+
warnings.push(
|
|
711
|
+
`${usage.proposedRefs.length} unrejected agent proposal token(s) referenced (${usage.proposedRefs.map((entry) => entry.token).join(', ')}); report-only until approved and built`,
|
|
712
|
+
)
|
|
713
|
+
}
|
|
714
|
+
if (usage.hardcoded.length) {
|
|
715
|
+
const total = usage.hardcoded.reduce((sum, item) => sum + item.count, 0)
|
|
716
|
+
warnings.push(
|
|
717
|
+
`${total} hardcoded color literal(s) in ${usage.hardcoded.length} file(s); report-only for now`,
|
|
718
|
+
)
|
|
719
|
+
}
|
|
720
|
+
if (usage.unsupported.length) {
|
|
721
|
+
const total = usage.unsupported.reduce((sum, item) => sum + item.count, 0)
|
|
722
|
+
warnings.push(
|
|
723
|
+
`${total} unsupported style expression(s) across ${usage.unsupported.length} entry/entries; report-only`,
|
|
724
|
+
)
|
|
725
|
+
}
|
|
726
|
+
return { errors, warnings }
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
// Files in the tool cache (design/.seji/) are never committed, so `check` regenerates
|
|
730
|
+
// them instead of calling them stale; only the app-owned CSS output is held to `check`.
|
|
731
|
+
const inToolCache = (root, file) => {
|
|
732
|
+
const rel = toPosix(relative(resolve(root, 'design', '.seji'), file))
|
|
733
|
+
return rel !== '' && !rel.startsWith('..') && !rel.startsWith('/')
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
function compareOrWrite(root, file, content, check) {
|
|
737
|
+
const existing = existsSync(file) ? readFileSync(file, 'utf8') : ''
|
|
738
|
+
if (existing === content) return
|
|
739
|
+
if (check && !inToolCache(root, file)) {
|
|
740
|
+
if (existing !== content) {
|
|
741
|
+
throw new Error(`${toPosix(relative(root, file))} is stale. Run tokens build.`)
|
|
742
|
+
}
|
|
743
|
+
return
|
|
744
|
+
}
|
|
745
|
+
mkdirSync(dirname(file), { recursive: true })
|
|
746
|
+
writeFileSync(file, content)
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
/** Generated files (css / ts / manifest) that differ from what a build would write now. */
|
|
750
|
+
export function staleOutputs(root, config, outputs) {
|
|
751
|
+
const expected = [
|
|
752
|
+
[config.cssOut, outputs.css, cssOutFile(root, config)],
|
|
753
|
+
[config.tsOut, outputs.ts],
|
|
754
|
+
[config.manifestOut, `${JSON.stringify(outputs.manifest, null, 2)}\n`],
|
|
755
|
+
]
|
|
756
|
+
return expected
|
|
757
|
+
.filter(([file, content, path]) => {
|
|
758
|
+
const abs = path ?? resolve(root, file)
|
|
759
|
+
return !existsSync(abs) || readFileSync(abs, 'utf8') !== content
|
|
760
|
+
})
|
|
761
|
+
.map(([file]) => file)
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* Read, resolve, scan, and validate tokens without writing anything. Shared by
|
|
766
|
+
* `tokens build|check`, `health`, and the usage index so headless commands see
|
|
767
|
+
* exactly what the build sees.
|
|
768
|
+
*/
|
|
769
|
+
export async function analyzeTokens({ root = process.cwd(), config: overrides = {} } = {}) {
|
|
770
|
+
const config = loadTokenConfig(root, overrides)
|
|
771
|
+
const { files, records } = readTokenRecords(root, config.tokenDir)
|
|
772
|
+
resolveRecords(records)
|
|
773
|
+
const usage = await scanUsage(root, records, config)
|
|
774
|
+
const outputs = buildOutputs(root, records, files, usage, config)
|
|
775
|
+
const { errors, warnings } = validate(records, usage, outputs)
|
|
776
|
+
return { config, files, records, usage, outputs, errors, warnings }
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
export async function runTokenPipeline({ root = process.cwd(), check = false, config: overrides = {} } = {}) {
|
|
780
|
+
const { config, usage, outputs, errors, warnings } = await analyzeTokens({ root, config: overrides })
|
|
781
|
+
|
|
782
|
+
const validationError = () => {
|
|
783
|
+
const error = new Error(`Token validation failed (${errors.length}):\n${errors.map((e) => ` - ${e}`).join('\n')}`)
|
|
784
|
+
error.validationErrors = errors
|
|
785
|
+
error.warnings = warnings
|
|
786
|
+
error.counts = outputs.manifest.counts
|
|
787
|
+
return error
|
|
788
|
+
}
|
|
789
|
+
if (check && errors.length) throw validationError()
|
|
790
|
+
|
|
791
|
+
// A build always writes its outputs, so the editor and the app see the current tokens even
|
|
792
|
+
// while a validation problem (an invalid value, a failing contrast pair) is being fixed; the
|
|
793
|
+
// problem is still the command's error.
|
|
794
|
+
compareOrWrite(root, cssOutFile(root, config), outputs.css, check)
|
|
795
|
+
compareOrWrite(root, resolve(root, config.tsOut), outputs.ts, check)
|
|
796
|
+
compareOrWrite(
|
|
797
|
+
root,
|
|
798
|
+
resolve(root, config.manifestOut),
|
|
799
|
+
`${JSON.stringify(outputs.manifest, null, 2)}\n`,
|
|
800
|
+
check,
|
|
801
|
+
)
|
|
802
|
+
if (errors.length) throw validationError()
|
|
803
|
+
|
|
804
|
+
return {
|
|
805
|
+
check,
|
|
806
|
+
config,
|
|
807
|
+
counts: outputs.manifest.counts,
|
|
808
|
+
contrast: outputs.manifest.contrast,
|
|
809
|
+
unsupported: usage.unsupported,
|
|
810
|
+
unknown: usage.unknown,
|
|
811
|
+
warnings,
|
|
812
|
+
}
|
|
813
|
+
}
|