@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,441 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import postcss from 'postcss'
|
|
5
|
+
import valueParser from 'postcss-value-parser'
|
|
6
|
+
import { glob } from 'tinyglobby'
|
|
7
|
+
|
|
8
|
+
import { colorToRgb, loadTokenConfig, readTokenRecords } from './pipeline.mjs'
|
|
9
|
+
|
|
10
|
+
const MULTI_PREFIXES = [
|
|
11
|
+
'font-size',
|
|
12
|
+
'font-weight',
|
|
13
|
+
'font-family',
|
|
14
|
+
'line-height',
|
|
15
|
+
'letter-spacing',
|
|
16
|
+
'border-width',
|
|
17
|
+
'border-radius',
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
const toPosix = (file) => file.split(sep).join('/')
|
|
21
|
+
|
|
22
|
+
const titleize = (slug) =>
|
|
23
|
+
slug
|
|
24
|
+
.replace(/[-_]+/g, ' ')
|
|
25
|
+
.replace(/^\w/, (char) => char.toUpperCase())
|
|
26
|
+
|
|
27
|
+
function cssNameToPath(cssName) {
|
|
28
|
+
const raw = cssName.replace(/^--/, '')
|
|
29
|
+
for (const prefix of MULTI_PREFIXES) {
|
|
30
|
+
if (raw.startsWith(`${prefix}-`)) {
|
|
31
|
+
return [prefix, raw.slice(prefix.length + 1)]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const dash = raw.indexOf('-')
|
|
35
|
+
if (dash > 0) {
|
|
36
|
+
return [raw.slice(0, dash), raw.slice(dash + 1)]
|
|
37
|
+
}
|
|
38
|
+
return [raw]
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Top-level parts of a value, split on commas and spaces outside parentheses.
|
|
42
|
+
const topLevelParts = (value) => {
|
|
43
|
+
const parsed = valueParser(value)
|
|
44
|
+
return parsed.nodes.filter((node) => node.type !== 'space' && node.type !== 'comment' && node.type !== 'div')
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// A box-shadow value: lengths plus a color (`0 1px 2px rgba(0,0,0,.1), …`), or `none`.
|
|
48
|
+
function isShadowValue(value) {
|
|
49
|
+
const parts = topLevelParts(value)
|
|
50
|
+
if (parts.length < 2) return false
|
|
51
|
+
const lengths = parts.filter((node) => node.type === 'word' && /^-?\d*\.?\d+(?:px|rem|em)?$/.test(node.value)).length
|
|
52
|
+
const colors = parts.filter(
|
|
53
|
+
(node) =>
|
|
54
|
+
(node.type === 'function' && /^(?:rgba?|hsla?|oklch|oklab|lab|lch|color|color-mix|var)$/i.test(node.value)) ||
|
|
55
|
+
(node.type === 'word' && (colorToRgb(node.value) || /^(?:transparent|currentcolor|black|white)$/i.test(node.value))),
|
|
56
|
+
).length
|
|
57
|
+
return lengths >= 2 && colors >= 1
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function inferTypeAndValue(value) {
|
|
61
|
+
const trimmed = value.trim()
|
|
62
|
+
if (/^-?\d+(?:\.\d+)?(px|rem|em|%)$/.test(trimmed)) {
|
|
63
|
+
const match = /^(-?\d+(?:\.\d+)?)(px|rem|em|%)$/.exec(trimmed)
|
|
64
|
+
return {
|
|
65
|
+
dtcgType: 'dimension',
|
|
66
|
+
uiType: 'length',
|
|
67
|
+
value: { value: Number(match[1]), unit: match[2] },
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Typed by the whole value: a shadow that contains a color is a shadow, not a color.
|
|
71
|
+
if (isShadowValue(trimmed)) {
|
|
72
|
+
return { dtcgType: 'shadow', uiType: 'text', value: trimmed }
|
|
73
|
+
}
|
|
74
|
+
const single = topLevelParts(trimmed).length === 1
|
|
75
|
+
if (
|
|
76
|
+
single &&
|
|
77
|
+
(colorToRgb(trimmed) || /^(?:color-mix|rgba?|hsla?|oklch|oklab|lab|lch|color)\(/i.test(trimmed))
|
|
78
|
+
) {
|
|
79
|
+
return {
|
|
80
|
+
dtcgType: 'color',
|
|
81
|
+
uiType: 'color',
|
|
82
|
+
value: trimmed,
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
dtcgType: 'string',
|
|
87
|
+
uiType: 'text',
|
|
88
|
+
value: trimmed,
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Which theme a rule's variables belong to: `default` (:root, :host, html, @theme, light), `dark`
|
|
93
|
+
// (a .dark / [data-theme=dark] selector or a prefers-color-scheme: dark media query), or null
|
|
94
|
+
// (component-scoped variables, not tokens).
|
|
95
|
+
function themeOf(node) {
|
|
96
|
+
let media = ''
|
|
97
|
+
for (let parent = node.parent; parent; parent = parent.parent) {
|
|
98
|
+
if (parent.type === 'atrule' && parent.name.toLowerCase() === 'media') media += ` ${parent.params}`
|
|
99
|
+
}
|
|
100
|
+
const darkMedia = /prefers-color-scheme\s*:\s*dark/i.test(media)
|
|
101
|
+
if (node.type === 'atrule') return darkMedia ? 'dark' : 'default'
|
|
102
|
+
const selectors = node.selectors ?? [node.selector]
|
|
103
|
+
if (selectors.some((selector) => /dark/i.test(selector))) return 'dark'
|
|
104
|
+
const rootLike = selectors.every((selector) =>
|
|
105
|
+
/^(?::root|:host|html)(?:\.light|\[data-theme=["']?light["']?\]|:not\([^)]*\))*$/i.test(selector.trim()),
|
|
106
|
+
)
|
|
107
|
+
if (!rootLike) return null
|
|
108
|
+
return darkMedia ? 'dark' : 'default'
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function extractCssCustomProperties(cssText, file) {
|
|
112
|
+
const rootAst = postcss.parse(cssText, { from: file })
|
|
113
|
+
const entries = []
|
|
114
|
+
const collectFromContainer = (container, theme) => {
|
|
115
|
+
container.walkDecls((decl) => {
|
|
116
|
+
if (decl.parent !== container) return
|
|
117
|
+
if (!decl.prop.startsWith('--')) return
|
|
118
|
+
const value = decl.value.trim()
|
|
119
|
+
if (!value) return
|
|
120
|
+
entries.push({ cssName: decl.prop, value, theme, file })
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
rootAst.walk((node) => {
|
|
124
|
+
if (node.type === 'atrule' && node.name.toLowerCase() === 'theme') {
|
|
125
|
+
// `@theme inline` maps Tailwind names onto the app's own variables (shadcn); it stays in
|
|
126
|
+
// the app's CSS, where its dark-mode behaviour is defined. Its targets become tokens.
|
|
127
|
+
if (/\binline\b/.test(node.params)) return
|
|
128
|
+
collectFromContainer(node, themeOf(node))
|
|
129
|
+
} else if (node.type === 'rule') {
|
|
130
|
+
const theme = themeOf(node)
|
|
131
|
+
if (theme) collectFromContainer(node, theme)
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
return entries
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function extractSingleVarAlias(value) {
|
|
138
|
+
const parsed = valueParser(value)
|
|
139
|
+
const meaningful = parsed.nodes.filter(
|
|
140
|
+
(node) => node.type !== 'space' && node.type !== 'comment',
|
|
141
|
+
)
|
|
142
|
+
if (meaningful.length !== 1) return null
|
|
143
|
+
const node = meaningful[0]
|
|
144
|
+
if (node.type !== 'function' || node.value.toLowerCase() !== 'var') return null
|
|
145
|
+
const arg = (node.nodes ?? []).find(
|
|
146
|
+
(child) => child.type === 'word' && child.value.startsWith('--'),
|
|
147
|
+
)
|
|
148
|
+
return arg ? arg.value : null
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const cssNameOfPath = (tokenPath) => `--${tokenPath.join('-')}`
|
|
152
|
+
const withCssName = (leaf, cssName) => ({
|
|
153
|
+
...leaf,
|
|
154
|
+
$extensions: { 'design-surface': { ...leaf.$extensions['design-surface'], cssName } },
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
function readJsonOrEmpty(file) {
|
|
158
|
+
if (!existsSync(file)) return {}
|
|
159
|
+
try {
|
|
160
|
+
return JSON.parse(readFileSync(file, 'utf8'))
|
|
161
|
+
} catch {
|
|
162
|
+
return {}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function insertToken(rootObj, tokenPath, leaf, tier, groupName) {
|
|
167
|
+
if (tokenPath.length === 1) {
|
|
168
|
+
const [key] = tokenPath
|
|
169
|
+
if (key in rootObj) return false
|
|
170
|
+
rootObj[key] = {
|
|
171
|
+
...leaf,
|
|
172
|
+
$extensions: {
|
|
173
|
+
'design-surface': {
|
|
174
|
+
tier,
|
|
175
|
+
group: groupName,
|
|
176
|
+
...leaf.$extensions['design-surface'],
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
}
|
|
180
|
+
return true
|
|
181
|
+
}
|
|
182
|
+
const [head, ...rest] = tokenPath
|
|
183
|
+
if (!(head in rootObj)) {
|
|
184
|
+
rootObj[head] = {
|
|
185
|
+
$extensions: {
|
|
186
|
+
'design-surface': {
|
|
187
|
+
tier,
|
|
188
|
+
group: groupName,
|
|
189
|
+
label: titleize(head),
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
let cursor = rootObj[head]
|
|
195
|
+
if (!cursor || typeof cursor !== 'object' || Array.isArray(cursor) || '$value' in cursor) {
|
|
196
|
+
return false
|
|
197
|
+
}
|
|
198
|
+
for (let i = 0; i < rest.length - 1; i += 1) {
|
|
199
|
+
const segment = rest[i]
|
|
200
|
+
if (!(segment in cursor)) cursor[segment] = {}
|
|
201
|
+
cursor = cursor[segment]
|
|
202
|
+
if (!cursor || typeof cursor !== 'object' || Array.isArray(cursor) || '$value' in cursor) {
|
|
203
|
+
return false
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const leafKey = rest[rest.length - 1]
|
|
207
|
+
if (leafKey in cursor) return false
|
|
208
|
+
cursor[leafKey] = leaf
|
|
209
|
+
return true
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* How many CSS custom properties the given (absolute or root-relative) stylesheets declare at
|
|
214
|
+
* the top level of a rule, the ones `extractTokensFromCss` turns into tokens. Unreadable or
|
|
215
|
+
* unparsable files count 0. Setup uses it to skip the starter tokens for an app that has its own.
|
|
216
|
+
*/
|
|
217
|
+
export function cssCustomPropertyCount(root, files) {
|
|
218
|
+
let count = 0
|
|
219
|
+
for (const entry of files ?? []) {
|
|
220
|
+
try {
|
|
221
|
+
const file = resolve(root, entry)
|
|
222
|
+
count += extractCssCustomProperties(readFileSync(file, 'utf8'), file).length
|
|
223
|
+
} catch {
|
|
224
|
+
// not a stylesheet we can read
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return count
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export async function extractTokensFromCss({ root = process.cwd(), files = [], dryRun = false } = {}) {
|
|
231
|
+
const config = loadTokenConfig(root)
|
|
232
|
+
const generatedCssAbs = config.cssOutPath
|
|
233
|
+
let targetFiles = []
|
|
234
|
+
|
|
235
|
+
if (files.length === 0) {
|
|
236
|
+
targetFiles = await glob(['src/**/*.css'], {
|
|
237
|
+
cwd: root,
|
|
238
|
+
absolute: true,
|
|
239
|
+
onlyFiles: true,
|
|
240
|
+
ignore: ['**/node_modules/**', '**/dist/**', '**/tokens.generated.css'],
|
|
241
|
+
})
|
|
242
|
+
} else {
|
|
243
|
+
for (const entry of files) {
|
|
244
|
+
if (/[*?[\]{}]/.test(entry)) {
|
|
245
|
+
const matched = await glob([entry], {
|
|
246
|
+
cwd: root,
|
|
247
|
+
absolute: true,
|
|
248
|
+
onlyFiles: true,
|
|
249
|
+
ignore: ['**/node_modules/**', '**/dist/**', '**/tokens.generated.css'],
|
|
250
|
+
})
|
|
251
|
+
targetFiles.push(...matched)
|
|
252
|
+
} else {
|
|
253
|
+
const abs = resolve(root, entry)
|
|
254
|
+
if (!existsSync(abs)) throw new Error(`CSS file not found: ${entry}`)
|
|
255
|
+
targetFiles.push(abs)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
targetFiles = [...new Set(targetFiles)]
|
|
261
|
+
.filter((file) => file !== generatedCssAbs)
|
|
262
|
+
.sort()
|
|
263
|
+
|
|
264
|
+
// Light / default values are the token values (a later default declaration overrides an
|
|
265
|
+
// earlier one, like the cascade); dark values are recorded on the token, never its value.
|
|
266
|
+
const declared = new Map()
|
|
267
|
+
const darkValues = new Map()
|
|
268
|
+
for (const file of targetFiles) {
|
|
269
|
+
const text = readFileSync(file, 'utf8')
|
|
270
|
+
for (const item of extractCssCustomProperties(text, file)) {
|
|
271
|
+
if (item.theme === 'dark') darkValues.set(item.cssName, item.value)
|
|
272
|
+
else declared.set(item.cssName, item.value)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// Only-dark variables still need a default: the dark value is the only one there is.
|
|
276
|
+
for (const [cssName, value] of darkValues) if (!declared.has(cssName)) declared.set(cssName, value)
|
|
277
|
+
|
|
278
|
+
let existingRecords = []
|
|
279
|
+
try {
|
|
280
|
+
existingRecords = readTokenRecords(root, config.tokenDir).records
|
|
281
|
+
} catch {
|
|
282
|
+
existingRecords = []
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const existingCss = new Set(existingRecords.map((record) => record.cssName))
|
|
286
|
+
const existingPaths = new Set(existingRecords.map((record) => record.path.join('.')))
|
|
287
|
+
const cssToPath = new Map(existingRecords.map((record) => [record.cssName, record.path.join('.')]))
|
|
288
|
+
const pathToType = new Map(existingRecords.map((record) => [record.path.join('.'), record.dtcgType]))
|
|
289
|
+
|
|
290
|
+
const pendingPrimitives = []
|
|
291
|
+
const pendingSemantics = []
|
|
292
|
+
const skippedExisting = []
|
|
293
|
+
|
|
294
|
+
// Shorter names first, so `--card` becomes the token `card` and `--card-foreground` (which
|
|
295
|
+
// cannot nest under a token) the renamed path `card-foreground`, not the other way round.
|
|
296
|
+
const ordered = [...declared].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
297
|
+
for (const [cssName, value] of ordered) {
|
|
298
|
+
const tokenPath = cssNameToPath(cssName)
|
|
299
|
+
const pathStr = tokenPath.join('.')
|
|
300
|
+
if (existingCss.has(cssName) || existingPaths.has(pathStr)) {
|
|
301
|
+
skippedExisting.push(cssName)
|
|
302
|
+
continue
|
|
303
|
+
}
|
|
304
|
+
const targetCss = extractSingleVarAlias(value.trim())
|
|
305
|
+
if (targetCss) {
|
|
306
|
+
pendingSemantics.push({ cssName, tokenPath, pathStr, rawValue: value.trim(), targetCss })
|
|
307
|
+
} else {
|
|
308
|
+
const inferred = inferTypeAndValue(value)
|
|
309
|
+
pendingPrimitives.push({ cssName, tokenPath, pathStr, ...inferred })
|
|
310
|
+
cssToPath.set(cssName, pathStr)
|
|
311
|
+
pathToType.set(pathStr, inferred.dtcgType)
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
for (const item of pendingSemantics) {
|
|
316
|
+
cssToPath.set(item.cssName, item.pathStr)
|
|
317
|
+
}
|
|
318
|
+
const semanticByCss = new Map(pendingSemantics.map((item) => [item.cssName, item]))
|
|
319
|
+
const resolveAliasType = (cssName, visited = new Set()) => {
|
|
320
|
+
if (visited.has(cssName)) return 'string'
|
|
321
|
+
visited.add(cssName)
|
|
322
|
+
const mappedPath = cssToPath.get(cssName)
|
|
323
|
+
if (mappedPath && pathToType.has(mappedPath)) {
|
|
324
|
+
return pathToType.get(mappedPath)
|
|
325
|
+
}
|
|
326
|
+
const nextSemantic = semanticByCss.get(cssName)
|
|
327
|
+
if (nextSemantic) {
|
|
328
|
+
const resolved = resolveAliasType(nextSemantic.targetCss, visited)
|
|
329
|
+
pathToType.set(nextSemantic.pathStr, resolved)
|
|
330
|
+
return resolved
|
|
331
|
+
}
|
|
332
|
+
return 'string'
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
const tokenRoot = resolve(root, config.tokenDir)
|
|
336
|
+
const primitiveFile = join(tokenRoot, 'primitive.tokens.json')
|
|
337
|
+
const semanticFile = join(tokenRoot, 'semantic.tokens.json')
|
|
338
|
+
const primitiveJson = readJsonOrEmpty(primitiveFile)
|
|
339
|
+
const semanticJson = readJsonOrEmpty(semanticFile)
|
|
340
|
+
|
|
341
|
+
// A token path that collides with another token (a token cannot also be a group) is renamed:
|
|
342
|
+
// the dashed name as one segment, else a numbered key. The CSS name never changes
|
|
343
|
+
// ($extensions["design-surface"].cssName keeps it), and every rename is reported.
|
|
344
|
+
const renamed = []
|
|
345
|
+
const recordedDark = []
|
|
346
|
+
const place = (json, item, leaf, tier) => {
|
|
347
|
+
const dark = darkValues.get(item.cssName)
|
|
348
|
+
if (dark !== undefined && dark !== declared.get(item.cssName)) {
|
|
349
|
+
leaf.$extensions['design-surface'].modes = { dark }
|
|
350
|
+
recordedDark.push(item.cssName)
|
|
351
|
+
}
|
|
352
|
+
const group = item.tokenPath[0]
|
|
353
|
+
const raw = item.cssName.replace(/^--/, '')
|
|
354
|
+
const candidates = [item.tokenPath, [raw]]
|
|
355
|
+
for (let n = 2; n < 10; n += 1) candidates.push([...item.tokenPath.slice(0, -1), `${item.tokenPath[item.tokenPath.length - 1]}-${n}`])
|
|
356
|
+
for (const candidate of candidates) {
|
|
357
|
+
const pathStr = candidate.join('.')
|
|
358
|
+
if (existingPaths.has(pathStr)) continue
|
|
359
|
+
const own = cssNameOfPath(candidate) === item.cssName ? leaf : withCssName(leaf, item.cssName)
|
|
360
|
+
if (insertToken(json, candidate, own, tier, group)) {
|
|
361
|
+
existingPaths.add(pathStr)
|
|
362
|
+
cssToPath.set(item.cssName, pathStr)
|
|
363
|
+
pathToType.set(pathStr, leaf.$type)
|
|
364
|
+
if (candidate !== item.tokenPath) renamed.push({ cssName: item.cssName, from: item.pathStr, to: pathStr })
|
|
365
|
+
return pathStr
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
skippedExisting.push(item.cssName)
|
|
369
|
+
return null
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const addedPrimitives = []
|
|
373
|
+
for (const item of pendingPrimitives) {
|
|
374
|
+
const leaf = {
|
|
375
|
+
$type: item.dtcgType,
|
|
376
|
+
$value: item.value,
|
|
377
|
+
$extensions: {
|
|
378
|
+
'design-surface': {
|
|
379
|
+
label: titleize(item.tokenPath[item.tokenPath.length - 1]),
|
|
380
|
+
uiType: item.uiType,
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
}
|
|
384
|
+
const placed = place(primitiveJson, item, leaf, 'primitive')
|
|
385
|
+
if (placed) addedPrimitives.push({ cssName: item.cssName, path: placed, value: item.value, type: item.dtcgType })
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const addedSemantics = []
|
|
389
|
+
for (const item of pendingSemantics) {
|
|
390
|
+
const targetPath = cssToPath.get(item.targetCss)
|
|
391
|
+
const dtcgType = targetPath
|
|
392
|
+
? resolveAliasType(item.targetCss, new Set([item.cssName]))
|
|
393
|
+
: 'string'
|
|
394
|
+
pathToType.set(item.pathStr, dtcgType)
|
|
395
|
+
const uiType = dtcgType === 'color' ? 'color' : dtcgType === 'dimension' ? 'length' : 'text'
|
|
396
|
+
const tokenValue = targetPath ? `{${targetPath}}` : item.rawValue
|
|
397
|
+
const leaf = {
|
|
398
|
+
$type: dtcgType,
|
|
399
|
+
$value: tokenValue,
|
|
400
|
+
$extensions: {
|
|
401
|
+
'design-surface': {
|
|
402
|
+
label: titleize(item.tokenPath[item.tokenPath.length - 1]),
|
|
403
|
+
uiType,
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
}
|
|
407
|
+
const placed = place(semanticJson, item, leaf, 'semantic')
|
|
408
|
+
if (placed) {
|
|
409
|
+
addedSemantics.push({
|
|
410
|
+
cssName: item.cssName,
|
|
411
|
+
path: placed,
|
|
412
|
+
value: tokenValue,
|
|
413
|
+
type: dtcgType,
|
|
414
|
+
})
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (!dryRun) {
|
|
419
|
+
mkdirSync(tokenRoot, { recursive: true })
|
|
420
|
+
if (addedPrimitives.length) {
|
|
421
|
+
mkdirSync(dirname(primitiveFile), { recursive: true })
|
|
422
|
+
writeFileSync(primitiveFile, `${JSON.stringify(primitiveJson, null, 2)}\n`)
|
|
423
|
+
}
|
|
424
|
+
if (addedSemantics.length) {
|
|
425
|
+
mkdirSync(dirname(semanticFile), { recursive: true })
|
|
426
|
+
writeFileSync(semanticFile, `${JSON.stringify(semanticJson, null, 2)}\n`)
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
return {
|
|
431
|
+
dryRun,
|
|
432
|
+
scannedFiles: targetFiles.map((file) => toPosix(relative(root, file))),
|
|
433
|
+
primitiveFile: toPosix(relative(root, primitiveFile)),
|
|
434
|
+
semanticFile: toPosix(relative(root, semanticFile)),
|
|
435
|
+
addedPrimitives,
|
|
436
|
+
addedSemantics,
|
|
437
|
+
skippedExisting,
|
|
438
|
+
renamed,
|
|
439
|
+
dark: recordedDark,
|
|
440
|
+
}
|
|
441
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TokenGroup, TokenHealth } from '../shared/tokens'
|
|
2
|
+
|
|
3
|
+
export type TokenModuleData = {
|
|
4
|
+
tokenSourceHash: string
|
|
5
|
+
tokenGroups: TokenGroup[]
|
|
6
|
+
tokenValues: Record<string, string>
|
|
7
|
+
tokenSources: Record<string, string>
|
|
8
|
+
tokenAliases: Record<string, string>
|
|
9
|
+
tokenHealth: TokenHealth
|
|
10
|
+
}
|
|
11
|
+
export declare const TOKENS_DATA_EVENT: 'design-surface:tokens-data'
|
|
12
|
+
export declare function tokenModuleData(options: { root: string }): Promise<TokenModuleData>
|
|
13
|
+
export declare function isTokenDataFile(root: string, file: string): boolean
|
|
14
|
+
export declare function loadTokenConfig(root: string): { tokenDir: string; cssOut: string; tsOut: string }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// Token data for the editor without re-importing a module. After a token build (an in-process
|
|
2
|
+
// token operation or a CLI `tokens build` in another process), the dev server sees the generated
|
|
3
|
+
// CSS (or a token JSON file) change and sends the `design-surface:tokens-data` HMR event; the
|
|
4
|
+
// editor then GETs /__seji/api/tokens, which answers with tokenModuleData: the same exports as
|
|
5
|
+
// virtual:design/tokens. The generated TS stays unwatched (re-importing it stalled the editor).
|
|
6
|
+
import { relative, resolve, sep } from 'node:path'
|
|
7
|
+
|
|
8
|
+
import { analyzeTokens, cssOutFile, loadTokenConfig } from './pipeline.mjs'
|
|
9
|
+
|
|
10
|
+
export { loadTokenConfig }
|
|
11
|
+
|
|
12
|
+
export const TOKENS_DATA_EVENT = 'design-surface:tokens-data'
|
|
13
|
+
|
|
14
|
+
/** `{ tokenSourceHash, tokenGroups, tokenValues, tokenSources, tokenAliases, tokenHealth }`. */
|
|
15
|
+
export async function tokenModuleData({ root }) {
|
|
16
|
+
return (await analyzeTokens({ root })).outputs.data
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** True for the generated token CSS and for `<tokenDir>/*.tokens.json`. */
|
|
20
|
+
export function isTokenDataFile(root, file) {
|
|
21
|
+
let config
|
|
22
|
+
try {
|
|
23
|
+
config = loadTokenConfig(root)
|
|
24
|
+
} catch {
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
const target = resolve(file)
|
|
28
|
+
// The same resolved path the token build writes (a root design/ writes into the app).
|
|
29
|
+
if (target === resolve(cssOutFile(root, config))) return true
|
|
30
|
+
const rel = relative(resolve(root, config.tokenDir), target)
|
|
31
|
+
return Boolean(rel) && !rel.startsWith('..') && !rel.includes(sep) && rel.endsWith('.tokens.json')
|
|
32
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// One token operation at a time per project, across processes (CLI and the Vite dev
|
|
2
|
+
// server share it). The lock is a directory in the OS temp dir keyed by the project root;
|
|
3
|
+
// the holder refreshes its mtime while it runs, so a crashed holder goes stale quickly.
|
|
4
|
+
// Waiting is asynchronous (never blocks the dev server's event loop).
|
|
5
|
+
import { createHash } from 'node:crypto'
|
|
6
|
+
import { mkdirSync, readFileSync, realpathSync, rmSync, statSync, utimesSync, writeFileSync } from 'node:fs'
|
|
7
|
+
import { hostname, tmpdir } from 'node:os'
|
|
8
|
+
import { join, resolve } from 'node:path'
|
|
9
|
+
import { setTimeout as delay } from 'node:timers/promises'
|
|
10
|
+
|
|
11
|
+
const HEARTBEAT_MS = 1_000
|
|
12
|
+
const STALE_MS = 15_000
|
|
13
|
+
const POLL_MS = 25
|
|
14
|
+
|
|
15
|
+
export class TokenLockTimeoutError extends Error {
|
|
16
|
+
constructor(message, owner) {
|
|
17
|
+
super(message)
|
|
18
|
+
this.name = 'TokenLockTimeoutError'
|
|
19
|
+
if (owner) this.owner = owner
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function lockDirFor(root) {
|
|
24
|
+
let base = resolve(root)
|
|
25
|
+
try {
|
|
26
|
+
base = realpathSync(base)
|
|
27
|
+
} catch {
|
|
28
|
+
// a missing root still gets a stable key
|
|
29
|
+
}
|
|
30
|
+
const key = createHash('sha1').update(base).digest('hex').slice(0, 20)
|
|
31
|
+
return join(tmpdir(), 'seji-locks', `${key}.token-ops.lock`)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readOwner(lock) {
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(readFileSync(join(lock, 'owner.json'), 'utf8'))
|
|
37
|
+
} catch {
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const alive = (pid) => {
|
|
43
|
+
try {
|
|
44
|
+
process.kill(pid, 0)
|
|
45
|
+
return true
|
|
46
|
+
} catch (error) {
|
|
47
|
+
return error?.code === 'EPERM'
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isStale(lock) {
|
|
52
|
+
let mtime
|
|
53
|
+
try {
|
|
54
|
+
mtime = statSync(lock).mtimeMs
|
|
55
|
+
} catch {
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
if (Date.now() - mtime > STALE_MS) return true
|
|
59
|
+
const owner = readOwner(lock)
|
|
60
|
+
return Boolean(owner && owner.host === hostname() && typeof owner.pid === 'number' && owner.pid !== process.pid && !alive(owner.pid))
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Run async `fn` while holding the project's token-operation lock. */
|
|
64
|
+
export async function withTokenOpLock(root, fn, { timeoutMs = 120_000 } = {}) {
|
|
65
|
+
const lock = lockDirFor(root)
|
|
66
|
+
mkdirSync(join(lock, '..'), { recursive: true })
|
|
67
|
+
const started = Date.now()
|
|
68
|
+
for (;;) {
|
|
69
|
+
try {
|
|
70
|
+
mkdirSync(lock)
|
|
71
|
+
break
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (error?.code !== 'EEXIST') throw error
|
|
74
|
+
if (isStale(lock)) {
|
|
75
|
+
rmSync(lock, { recursive: true, force: true })
|
|
76
|
+
continue
|
|
77
|
+
}
|
|
78
|
+
if (Date.now() - started > timeoutMs) {
|
|
79
|
+
const owner = readOwner(lock)
|
|
80
|
+
throw new TokenLockTimeoutError(
|
|
81
|
+
`another token operation is still running${owner?.pid ? ` (pid ${owner.pid}${owner.op ? `, ${owner.op}` : ''})` : ''}; retry when it finishes`,
|
|
82
|
+
owner,
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
await delay(POLL_MS)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
writeFileSync(join(lock, 'owner.json'), JSON.stringify({ pid: process.pid, host: hostname(), at: new Date().toISOString() }))
|
|
90
|
+
} catch {
|
|
91
|
+
// owner info is advisory
|
|
92
|
+
}
|
|
93
|
+
const heartbeat = setInterval(() => {
|
|
94
|
+
try {
|
|
95
|
+
const now = new Date()
|
|
96
|
+
utimesSync(lock, now, now)
|
|
97
|
+
} catch {
|
|
98
|
+
// lock dir removed underneath us; nothing to refresh
|
|
99
|
+
}
|
|
100
|
+
}, HEARTBEAT_MS)
|
|
101
|
+
heartbeat.unref?.()
|
|
102
|
+
try {
|
|
103
|
+
return await fn()
|
|
104
|
+
} finally {
|
|
105
|
+
clearInterval(heartbeat)
|
|
106
|
+
rmSync(lock, { recursive: true, force: true })
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export type TokenOpName =
|
|
2
|
+
| 'rename'
|
|
3
|
+
| 'merge'
|
|
4
|
+
| 'deprecate'
|
|
5
|
+
| 'delete'
|
|
6
|
+
| 'describe'
|
|
7
|
+
| 'set'
|
|
8
|
+
| 'create'
|
|
9
|
+
| 'replace-literal'
|
|
10
|
+
| 'revert'
|
|
11
|
+
|
|
12
|
+
export declare const TOKEN_OPS: TokenOpName[]
|
|
13
|
+
export declare const TOKEN_TIERS: Array<'primitive' | 'semantic' | 'component'>
|
|
14
|
+
|
|
15
|
+
export declare class TokenOpError extends Error {
|
|
16
|
+
details?: Record<string, unknown>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type TokenOpArgs = {
|
|
20
|
+
design?: string
|
|
21
|
+
dryRun?: boolean
|
|
22
|
+
token?: string
|
|
23
|
+
to?: string
|
|
24
|
+
into?: string
|
|
25
|
+
keep?: 'target' | 'source'
|
|
26
|
+
/** false = do not keep the old name as a deprecated alias (rename / merge). */
|
|
27
|
+
alias?: boolean
|
|
28
|
+
reason?: string
|
|
29
|
+
replacement?: string
|
|
30
|
+
noReplacement?: boolean
|
|
31
|
+
mode?: 'mark-only' | 'replace-all'
|
|
32
|
+
description?: string
|
|
33
|
+
value?: string
|
|
34
|
+
/** create: explicit tier (no default) and DTCG $type (inferred from the value when omitted). */
|
|
35
|
+
tier?: 'primitive' | 'semantic' | 'component' | string
|
|
36
|
+
type?: string
|
|
37
|
+
literal?: string
|
|
38
|
+
scope?: string
|
|
39
|
+
property?: string
|
|
40
|
+
batch?: string
|
|
41
|
+
force?: boolean
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export declare function resolveDesign(root: string, design?: string | null): string
|
|
45
|
+
export declare function revertBatch(options: {
|
|
46
|
+
root?: string
|
|
47
|
+
batch: string
|
|
48
|
+
design?: string
|
|
49
|
+
force?: boolean
|
|
50
|
+
dryRun?: boolean
|
|
51
|
+
}): Promise<Record<string, unknown>>
|
|
52
|
+
export declare function runTokenOp(options: {
|
|
53
|
+
root?: string
|
|
54
|
+
op: string
|
|
55
|
+
args?: TokenOpArgs
|
|
56
|
+
/**
|
|
57
|
+
* `beforeWrite` gets the review item the operation will record, right before the first write;
|
|
58
|
+
* the fields it returns (e.g. `{ snapshots }`) are stored on that item. The rest are test
|
|
59
|
+
* seams for failure injection.
|
|
60
|
+
*/
|
|
61
|
+
hooks?: TokenOpHooks
|
|
62
|
+
}): Promise<Record<string, unknown>>
|
|
63
|
+
/** Throws a TokenOpError (`details.code: 'invalid-args'`) on unknown or mistyped arguments. */
|
|
64
|
+
export declare function validateTokenOpArgs(args: unknown): TokenOpArgs
|
|
65
|
+
|
|
66
|
+
export type TokenOpHooks = {
|
|
67
|
+
beforeWrite?: (item: import('../shared/types').ReviewItem) => Promise<Record<string, unknown> | undefined> | Record<string, unknown> | undefined
|
|
68
|
+
afterPlan?: (info: { attempt: number }) => void | Promise<void>
|
|
69
|
+
afterWrite?: (entry: { file: string }) => void
|
|
70
|
+
beforeRecord?: () => void
|
|
71
|
+
}
|