@rien7/seji 0.0.0 → 0.6.1
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 +585 -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 +339 -0
- package/dist/cli/doctor.mjs +311 -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 +360 -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 +2834 -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/legacyPaths.d.mts +1 -0
- package/dist/shared/legacyPaths.mjs +9 -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 +25 -0
- package/dist/shared/prompt.mjs +217 -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 +1264 -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 +106 -1
- package/skills/seji/SKILL.md +400 -0
- package/skills/seji-authoring/SKILL.md +397 -0
- package/skills/seji-tokens/SKILL.md +432 -0
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
// Token usage index: for every token, which tokens reference it, which components and
|
|
2
|
+
// screens use it, and how many code references it has. Everything "who uses this" /
|
|
3
|
+
// "what does this change affect" reads from here, headless (CLI, HTTP, editor).
|
|
4
|
+
//
|
|
5
|
+
// Static analysis, so attribution is best-effort and every hit says how it was found:
|
|
6
|
+
// - code: `var(--token)` / Tailwind `(--token)` references found by the token adapters.
|
|
7
|
+
// - components: exported components of a file that references the token directly, or of a
|
|
8
|
+
// TSX/JSX file that uses every class of a CSS rule that references it.
|
|
9
|
+
// - screens: designs (design/<id>/design.tsx and its relative imports) that reference the
|
|
10
|
+
// token, use such a class, or render such a component; plus component pages registered
|
|
11
|
+
// in design/components.ts for those components.
|
|
12
|
+
// Components, imports and renders come from the syntax tree (src/components/astIndex.mjs):
|
|
13
|
+
// aliased / namespace / default imports, re-exports, `as={X}` and `createElement(X)` all
|
|
14
|
+
// resolve to the component's declaration; nothing is matched in file text.
|
|
15
|
+
// Usage through tokens that alias the token (directly or via var() in their value), and
|
|
16
|
+
// through local CSS aliases (`:root { --accent: var(--chrome-accent) }`), counts toward its
|
|
17
|
+
// impact; each hit lists the name(s) it came through in `via`.
|
|
18
|
+
import { existsSync, readFileSync, readdirSync, realpathSync, statSync } from 'node:fs'
|
|
19
|
+
import { dirname, join, relative, resolve, sep } from 'node:path'
|
|
20
|
+
|
|
21
|
+
import { buildComponentIndex } from '../components/astIndex.mjs'
|
|
22
|
+
import { parseSourceAst, propertyKeyName, staticStringOf, walkAst } from './adapters/oxcShared.mjs'
|
|
23
|
+
import { analyzeTokens, colorToRgb, scanFiles } from './pipeline.mjs'
|
|
24
|
+
|
|
25
|
+
const DESIGN_DIR = 'design'
|
|
26
|
+
const CODE_EXT = /\.(tsx|jsx|ts|js|mts|mjs|cts|cjs)$/i
|
|
27
|
+
const VITE_CONFIGS = ['vite.config.ts', 'vite.config.mts', 'vite.config.js', 'vite.config.mjs']
|
|
28
|
+
const RESOLVE_EXT = ['', '.tsx', '.ts', '.jsx', '.js', '.mts', '.mjs', '/index.tsx', '/index.ts', '/index.jsx', '/index.js']
|
|
29
|
+
const STATE_CLASS = /^(is|has)-/
|
|
30
|
+
|
|
31
|
+
const toPosix = (file) => file.split(sep).join('/')
|
|
32
|
+
const realOf = (file) => {
|
|
33
|
+
try {
|
|
34
|
+
return realpathSync(file)
|
|
35
|
+
} catch {
|
|
36
|
+
return file
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const sortUnique = (values) => [...new Set(values)].sort()
|
|
40
|
+
|
|
41
|
+
/** Classes of the subject (rightmost compound) of each selector in a rule, minus state classes. */
|
|
42
|
+
function subjectClasses(selector) {
|
|
43
|
+
const result = []
|
|
44
|
+
for (const part of String(selector).split(',')) {
|
|
45
|
+
const subject = part.trim().split(/[\s>+~]+/).pop() ?? ''
|
|
46
|
+
const classes = [...subject.matchAll(/\.(-?[_a-zA-Z][\w-]*)/g)]
|
|
47
|
+
.map((match) => match[1])
|
|
48
|
+
.filter((name) => !STATE_CLASS.test(name))
|
|
49
|
+
if (classes.length) result.push(classes)
|
|
50
|
+
}
|
|
51
|
+
return result
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function resolveImport(root, fromFile, spec) {
|
|
55
|
+
if (!spec.startsWith('.') && !spec.startsWith('/')) return null
|
|
56
|
+
const base = spec.startsWith('/') ? join(root, spec) : resolve(dirname(fromFile), spec)
|
|
57
|
+
for (const ext of RESOLVE_EXT) {
|
|
58
|
+
const candidate = `${base}${ext}`
|
|
59
|
+
if (existsSync(candidate) && statSync(candidate).isFile()) return candidate
|
|
60
|
+
}
|
|
61
|
+
return null
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function listDesigns(root) {
|
|
65
|
+
const base = join(root, DESIGN_DIR)
|
|
66
|
+
if (!existsSync(base)) return []
|
|
67
|
+
return readdirSync(base, { withFileTypes: true })
|
|
68
|
+
.filter((entry) => entry.isDirectory() && existsSync(join(base, entry.name, 'design.tsx')))
|
|
69
|
+
.map((entry) => ({ id: entry.name, file: join(base, entry.name, 'design.tsx') }))
|
|
70
|
+
.sort((a, b) => a.id.localeCompare(b.id))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* All files reachable from a design entry through relative / root-relative imports (module
|
|
75
|
+
* specifiers read from the syntax tree; stylesheets they import are included).
|
|
76
|
+
*/
|
|
77
|
+
function designGraph(root, entry, moduleRefsOf) {
|
|
78
|
+
const seen = new Set()
|
|
79
|
+
const stack = [entry]
|
|
80
|
+
while (stack.length) {
|
|
81
|
+
const file = stack.pop()
|
|
82
|
+
if (seen.has(file)) continue
|
|
83
|
+
seen.add(file)
|
|
84
|
+
if (!CODE_EXT.test(file)) continue
|
|
85
|
+
for (const spec of moduleRefsOf(file)) {
|
|
86
|
+
const next = resolveImport(root, file, spec)
|
|
87
|
+
if (next && !seen.has(next) && !next.includes(`${sep}node_modules${sep}`)) stack.push(next)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return [...seen]
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* When a token may be deleted: nothing references it — no token aliases it or uses it in its
|
|
95
|
+
* value, no local CSS alias points at it, no code references it, no component uses it. The one
|
|
96
|
+
* rule shared by the usage report (`deletable`, `blockedBy`), `tokens delete` and the editor.
|
|
97
|
+
*/
|
|
98
|
+
export function deleteBlockers({ tokens = [], localAliases = [], codeRefs = 0, components = 0 } = {}) {
|
|
99
|
+
const blockedBy = { tokens: [...tokens], localAliases: [...localAliases], codeRefs, components }
|
|
100
|
+
return {
|
|
101
|
+
deletable: !blockedBy.tokens.length && !blockedBy.localAliases.length && !codeRefs && !components,
|
|
102
|
+
blockedBy,
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The tier rule, one owner for the component page and the token page: components style with
|
|
108
|
+
* semantic (or component) tokens; a primitive (base-layer) token used directly by a component
|
|
109
|
+
* is a problem. The component page flags each such token row of a component; the token page
|
|
110
|
+
* flags the primitive with how many components use it directly. Returns the warning code or null.
|
|
111
|
+
*/
|
|
112
|
+
export function tierWarning(tier, directComponents = 1) {
|
|
113
|
+
return tier === 'primitive' && directComponents > 0 ? 'primitive' : null
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The project's `design/components.ts` (or .tsx / .js), or null. */
|
|
117
|
+
export function componentPagesFile(root) {
|
|
118
|
+
return (
|
|
119
|
+
['components.ts', 'components.tsx', 'components.js']
|
|
120
|
+
.map((name) => join(root, DESIGN_DIR, name))
|
|
121
|
+
.find((candidate) => existsSync(candidate)) ?? null
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* `design/components.ts` registrations, read from its syntax tree: every
|
|
127
|
+
* `Name: { design: '…', page: '…' }` property. Returns name → { design, page, key } where
|
|
128
|
+
* `key` is the property key's source range (the component rename rewrites it).
|
|
129
|
+
*/
|
|
130
|
+
export function readComponentRegistrations(root) {
|
|
131
|
+
const file = componentPagesFile(root)
|
|
132
|
+
const pages = new Map()
|
|
133
|
+
if (!file) return { file: null, pages }
|
|
134
|
+
const content = readFileSync(file, 'utf8')
|
|
135
|
+
const { program } = parseSourceAst(file, content, null)
|
|
136
|
+
walkAst(program, (node) => {
|
|
137
|
+
if (node.type !== 'Property' && node.type !== 'ObjectProperty') return
|
|
138
|
+
if (node.computed || node.value?.type !== 'ObjectExpression') return
|
|
139
|
+
const name = propertyKeyName(node.key)
|
|
140
|
+
if (!name || !/^[A-Z]/.test(name)) return
|
|
141
|
+
const fields = {}
|
|
142
|
+
for (const property of node.value.properties ?? []) {
|
|
143
|
+
if ((property.type !== 'Property' && property.type !== 'ObjectProperty') || property.computed) continue
|
|
144
|
+
const key = propertyKeyName(property.key)
|
|
145
|
+
const value = staticStringOf(property.value)
|
|
146
|
+
if ((key === 'design' || key === 'page') && value !== null) fields[key] = value
|
|
147
|
+
}
|
|
148
|
+
if (fields.design && fields.page && !pages.has(name)) {
|
|
149
|
+
pages.set(name, {
|
|
150
|
+
design: fields.design,
|
|
151
|
+
page: fields.page,
|
|
152
|
+
key: { start: node.key.start, end: node.key.end, quoted: node.key.type !== 'Identifier' },
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
return { file, content, pages }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** `design/components.ts` registrations: component name → its page. */
|
|
160
|
+
export function readComponentPages(root) {
|
|
161
|
+
const { pages } = readComponentRegistrations(root)
|
|
162
|
+
return new Map([...pages].map(([name, entry]) => [name, { design: entry.design, page: entry.page }]))
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function sameValue(a, b) {
|
|
166
|
+
const left = String(a ?? '').trim().toLowerCase()
|
|
167
|
+
const right = String(b ?? '').trim().toLowerCase()
|
|
168
|
+
if (!left || !right) return false
|
|
169
|
+
if (left === right) return true
|
|
170
|
+
if (!/^#[0-9a-f]{3}$|^#[0-9a-f]{6}$/.test(left) || !/^#[0-9a-f]{3}$|^#[0-9a-f]{6}$/.test(right)) return false
|
|
171
|
+
return colorToRgb(left)?.join() === colorToRgb(right)?.join()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Build the usage index. Pass an existing `analyzeTokens()` result to avoid a second scan.
|
|
176
|
+
*/
|
|
177
|
+
export async function buildUsageIndex({ root = process.cwd(), analysis, extraFiles = [] } = {}) {
|
|
178
|
+
const { records, usage, config } = analysis ?? (await analyzeTokens({ root }))
|
|
179
|
+
const byPath = new Map(records.map((record) => [record.path.join('.'), record]))
|
|
180
|
+
const byCss = new Map(records.map((record) => [record.cssName, record]))
|
|
181
|
+
|
|
182
|
+
// token → tokens it references (DTCG alias and var() inside composite values)
|
|
183
|
+
const references = new Map(records.map((record) => [record.cssName, new Set()]))
|
|
184
|
+
for (const record of records) {
|
|
185
|
+
const out = references.get(record.cssName)
|
|
186
|
+
if (record.alias && byPath.has(record.alias)) out.add(byPath.get(record.alias).cssName)
|
|
187
|
+
if (typeof record.raw === 'string') {
|
|
188
|
+
for (const match of record.raw.matchAll(/var\(\s*(--[a-zA-Z0-9_-]+)/g)) {
|
|
189
|
+
if (byCss.has(match[1]) && match[1] !== record.cssName) out.add(match[1])
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const referencedBy = new Map(records.map((record) => [record.cssName, new Set()]))
|
|
194
|
+
for (const [name, targets] of references) {
|
|
195
|
+
for (const target of targets) referencedBy.get(target).add(name)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Local CSS aliases (`:root { --accent: var(--chrome-accent) }`): uses of the local name
|
|
199
|
+
// are uses of the token, so they join the token's alias closure.
|
|
200
|
+
const localAliases = new Map()
|
|
201
|
+
for (const diag of usage.diagnostics) {
|
|
202
|
+
if (
|
|
203
|
+
diag.kind === 'token-ref' &&
|
|
204
|
+
byCss.has(diag.token) &&
|
|
205
|
+
diag.property?.startsWith('--') &&
|
|
206
|
+
!byCss.has(diag.property) &&
|
|
207
|
+
/:root\b/.test(diag.selector ?? '')
|
|
208
|
+
) {
|
|
209
|
+
localAliases.set(diag.property, diag.token)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
for (const [local, target] of localAliases) {
|
|
213
|
+
references.set(local, new Set([target]))
|
|
214
|
+
referencedBy.set(local, referencedBy.get(local) ?? new Set())
|
|
215
|
+
referencedBy.get(target).add(local)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// direct code references
|
|
219
|
+
const refsByToken = new Map([...references.keys()].map((name) => [name, []]))
|
|
220
|
+
const literals = []
|
|
221
|
+
for (const diag of usage.diagnostics) {
|
|
222
|
+
if (diag.kind === 'token-ref' && refsByToken.has(diag.token)) refsByToken.get(diag.token).push(diag)
|
|
223
|
+
else if (diag.kind === 'literal') literals.push(diag)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Code files (scanned + design/ + extra files such as the component catalog), indexed from
|
|
227
|
+
// their syntax trees: component declarations, imports, renders, class words.
|
|
228
|
+
const scanned = scanFiles(root, config).map((file) => ({
|
|
229
|
+
abs: file,
|
|
230
|
+
file: toPosix(relative(root, file)),
|
|
231
|
+
}))
|
|
232
|
+
const designRoot = resolve(root, DESIGN_DIR)
|
|
233
|
+
const indexFiles = new Map()
|
|
234
|
+
const addIndexFile = (abs) => {
|
|
235
|
+
if (!CODE_EXT.test(abs) || /\.d\.[cm]?ts$/i.test(abs) || indexFiles.has(abs)) return
|
|
236
|
+
indexFiles.set(abs, { abs, file: toPosix(relative(root, abs)) })
|
|
237
|
+
}
|
|
238
|
+
for (const entry of scanned) addIndexFile(entry.abs)
|
|
239
|
+
const walkCode = (dir) => {
|
|
240
|
+
if (!existsSync(dir)) return
|
|
241
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
242
|
+
if (entry.name === 'node_modules' || entry.name.startsWith('.')) continue
|
|
243
|
+
const abs = join(dir, entry.name)
|
|
244
|
+
if (entry.isDirectory()) walkCode(abs)
|
|
245
|
+
else addIndexFile(abs)
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
walkCode(designRoot)
|
|
249
|
+
for (const name of VITE_CONFIGS) if (existsSync(join(root, name))) addIndexFile(join(root, name))
|
|
250
|
+
for (const abs of extraFiles) addIndexFile(resolve(root, abs))
|
|
251
|
+
const index = buildComponentIndex({ root, files: [...indexFiles.values()], designDir: designRoot })
|
|
252
|
+
const infoOf = (abs) => index.infos.get(abs) ?? index.infos.get(realOf(abs)) ?? null
|
|
253
|
+
const moduleRefsOf = (abs) => (infoOf(abs)?.moduleRefs ?? []).map((entry) => entry.source)
|
|
254
|
+
|
|
255
|
+
// Exported components per root-relative file (outside design/), from the syntax tree.
|
|
256
|
+
const componentDefs = index.definitions.filter((definition) => !definition.design)
|
|
257
|
+
const componentsByFile = new Map()
|
|
258
|
+
for (const definition of componentDefs) {
|
|
259
|
+
const list = componentsByFile.get(definition.file) ?? []
|
|
260
|
+
list.push({ name: definition.name, exportName: definition.exportName, file: definition.file, line: definition.line })
|
|
261
|
+
componentsByFile.set(definition.file, list)
|
|
262
|
+
}
|
|
263
|
+
const componentFiles = [...new Set(componentDefs.map((definition) => definition.file))].map((file) => ({
|
|
264
|
+
file,
|
|
265
|
+
abs: componentDefs.find((definition) => definition.file === file).abs,
|
|
266
|
+
}))
|
|
267
|
+
const classesOf = (entry) => infoOf(entry.abs)?.classWords ?? new Set()
|
|
268
|
+
const filesWithClasses = (classes, candidates) =>
|
|
269
|
+
candidates.filter((entry) => classes.every((name) => classesOf(entry).has(name)))
|
|
270
|
+
|
|
271
|
+
const designs = listDesigns(root).map((design) => {
|
|
272
|
+
const files = designGraph(root, design.file, moduleRefsOf).map((abs) => ({ abs, file: toPosix(relative(root, abs)) }))
|
|
273
|
+
return { ...design, files, fileSet: new Set(files.map((entry) => entry.file)) }
|
|
274
|
+
})
|
|
275
|
+
const designsOfFile = new Map()
|
|
276
|
+
for (const design of designs) {
|
|
277
|
+
for (const entry of design.files) {
|
|
278
|
+
for (const key of [entry.file, toPosix(relative(root, realOf(entry.abs)))]) {
|
|
279
|
+
const list = designsOfFile.get(key) ?? []
|
|
280
|
+
if (!list.includes(design.id)) list.push(design.id)
|
|
281
|
+
designsOfFile.set(key, list)
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
const componentPages = readComponentPages(root)
|
|
286
|
+
const definitionOf = (name) => index.definitionsNamed(name).find((definition) => !definition.design) ?? null
|
|
287
|
+
/** Designs whose screens render a component (any use in a file of the design's graph). */
|
|
288
|
+
const renderingCache = new Map()
|
|
289
|
+
const designsRendering = (definition) => {
|
|
290
|
+
const key = `${definition.abs}#${definition.local ?? 'default'}`
|
|
291
|
+
if (renderingCache.has(key)) return renderingCache.get(key)
|
|
292
|
+
const ids = new Set()
|
|
293
|
+
for (const use of index.usesOf(definition)) for (const id of designsOfFile.get(use.file) ?? []) ids.add(id)
|
|
294
|
+
const result = [...ids].sort()
|
|
295
|
+
renderingCache.set(key, result)
|
|
296
|
+
return result
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Direct usage of one token (not counting tokens that alias it). */
|
|
300
|
+
const directUsage = (name) => {
|
|
301
|
+
const refs = refsByToken.get(name) ?? []
|
|
302
|
+
const components = new Map()
|
|
303
|
+
const addComponent = (item, match) => {
|
|
304
|
+
const key = `${item.name}\0${item.file}`
|
|
305
|
+
const existing = components.get(key) ?? { name: item.name, file: item.file, match: [] }
|
|
306
|
+
if (!existing.match.includes(match)) existing.match.push(match)
|
|
307
|
+
components.set(key, existing)
|
|
308
|
+
}
|
|
309
|
+
const classSets = []
|
|
310
|
+
for (const ref of refs) {
|
|
311
|
+
for (const item of componentsByFile.get(ref.file) ?? []) addComponent(item, `references in ${ref.file}`)
|
|
312
|
+
if (ref.selector) classSets.push(...subjectClasses(ref.selector))
|
|
313
|
+
}
|
|
314
|
+
const uniqueClassSets = [...new Map(classSets.map((set) => [set.join('.'), set])).values()]
|
|
315
|
+
for (const classes of uniqueClassSets) {
|
|
316
|
+
for (const entry of filesWithClasses(classes, componentFiles)) {
|
|
317
|
+
for (const item of componentsByFile.get(entry.file) ?? []) addComponent(item, `class .${classes.join('.')}`)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const screens = new Map()
|
|
322
|
+
const addScreen = (screen, match) => {
|
|
323
|
+
const key = `${screen.design}\0${screen.page ?? ''}`
|
|
324
|
+
const existing = screens.get(key) ?? { ...screen, match: [] }
|
|
325
|
+
if (!existing.match.includes(match)) existing.match.push(match)
|
|
326
|
+
screens.set(key, existing)
|
|
327
|
+
}
|
|
328
|
+
const componentList = [...components.values()]
|
|
329
|
+
for (const design of designs) {
|
|
330
|
+
for (const ref of refs) {
|
|
331
|
+
if (design.fileSet.has(ref.file)) addScreen({ design: design.id }, `references in ${ref.file}`)
|
|
332
|
+
}
|
|
333
|
+
for (const classes of uniqueClassSets) {
|
|
334
|
+
if (filesWithClasses(classes, design.files).length) addScreen({ design: design.id }, `class .${classes.join('.')}`)
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
for (const component of componentList) {
|
|
338
|
+
const definition = index.definitionsNamed(component.name).find((item) => item.file === component.file)
|
|
339
|
+
for (const id of definition ? designsRendering(definition) : []) {
|
|
340
|
+
addScreen({ design: id }, `renders <${component.name}>`)
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
for (const component of componentList) {
|
|
344
|
+
const page = componentPages.get(component.name)
|
|
345
|
+
if (page) addScreen(page, `component page of ${component.name}`)
|
|
346
|
+
}
|
|
347
|
+
return { refs, components: componentList, screens: [...screens.values()] }
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const directCache = new Map()
|
|
351
|
+
const direct = (name) => {
|
|
352
|
+
if (!directCache.has(name)) directCache.set(name, directUsage(name))
|
|
353
|
+
return directCache.get(name)
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
const closure = (name) => {
|
|
357
|
+
const seen = new Set()
|
|
358
|
+
const stack = [...(referencedBy.get(name) ?? [])]
|
|
359
|
+
while (stack.length) {
|
|
360
|
+
const next = stack.pop()
|
|
361
|
+
if (seen.has(next) || next === name) continue
|
|
362
|
+
seen.add(next)
|
|
363
|
+
stack.push(...(referencedBy.get(next) ?? []))
|
|
364
|
+
}
|
|
365
|
+
return [...seen].sort()
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
const summarizeRefs = (refs) => {
|
|
369
|
+
const byFile = new Map()
|
|
370
|
+
for (const ref of refs) {
|
|
371
|
+
const entry = byFile.get(ref.file) ?? { file: ref.file, count: 0, lines: [] }
|
|
372
|
+
entry.count += 1
|
|
373
|
+
if (typeof ref.line === 'number' && !entry.lines.includes(ref.line)) entry.lines.push(ref.line)
|
|
374
|
+
byFile.set(ref.file, entry)
|
|
375
|
+
}
|
|
376
|
+
return [...byFile.values()]
|
|
377
|
+
.map((entry) => ({ ...entry, lines: entry.lines.sort((a, b) => a - b) }))
|
|
378
|
+
.sort((a, b) => b.count - a.count || a.file.localeCompare(b.file))
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const resolveName = (token) => {
|
|
382
|
+
if (byCss.has(token)) return token
|
|
383
|
+
if (byPath.has(token)) return byPath.get(token).cssName
|
|
384
|
+
if (localAliases.has(token)) return localAliases.get(token)
|
|
385
|
+
const css = token.startsWith('--') ? token : `--${token}`
|
|
386
|
+
return byCss.has(css) ? css : null
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/** Full usage of one token: its own references plus everything that comes through aliases. */
|
|
390
|
+
const tokenUsage = (token) => {
|
|
391
|
+
const name = resolveName(token)
|
|
392
|
+
if (!name) return null
|
|
393
|
+
const record = byCss.get(name)
|
|
394
|
+
const via = [name, ...closure(name)]
|
|
395
|
+
const components = new Map()
|
|
396
|
+
const screens = new Map()
|
|
397
|
+
let impactRefs = 0
|
|
398
|
+
for (const source of via) {
|
|
399
|
+
const usageOf = direct(source)
|
|
400
|
+
impactRefs += usageOf.refs.length
|
|
401
|
+
for (const component of usageOf.components) {
|
|
402
|
+
const key = `${component.name}\0${component.file}`
|
|
403
|
+
const existing = components.get(key) ?? { ...component, match: [...component.match], via: [] }
|
|
404
|
+
existing.via.push(source)
|
|
405
|
+
for (const match of component.match) if (!existing.match.includes(match)) existing.match.push(match)
|
|
406
|
+
components.set(key, existing)
|
|
407
|
+
}
|
|
408
|
+
for (const screen of usageOf.screens) {
|
|
409
|
+
const key = `${screen.design}\0${screen.page ?? ''}`
|
|
410
|
+
const existing = screens.get(key) ?? { ...screen, match: [...screen.match], via: [] }
|
|
411
|
+
existing.via.push(source)
|
|
412
|
+
for (const match of screen.match) if (!existing.match.includes(match)) existing.match.push(match)
|
|
413
|
+
screens.set(key, existing)
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const own = direct(name)
|
|
417
|
+
const sortByName = (a, b) => a.name.localeCompare(b.name) || a.file.localeCompare(b.file)
|
|
418
|
+
const sortScreens = (a, b) => a.design.localeCompare(b.design) || String(a.page ?? '').localeCompare(String(b.page ?? ''))
|
|
419
|
+
const isToken = (entry) => byCss.has(entry)
|
|
420
|
+
const referencedByDirect = sortUnique([...(referencedBy.get(name) ?? [])].filter(isToken))
|
|
421
|
+
const referencedByAll = via.slice(1).filter(isToken)
|
|
422
|
+
const local = via.slice(1).filter((entry) => !isToken(entry))
|
|
423
|
+
return {
|
|
424
|
+
token: name,
|
|
425
|
+
path: record.path.join('.'),
|
|
426
|
+
tier: record.tier,
|
|
427
|
+
type: record.dtcgType,
|
|
428
|
+
value: record.value,
|
|
429
|
+
...(record.alias ? { alias: record.alias } : {}),
|
|
430
|
+
...(record.description ? { description: record.description } : {}),
|
|
431
|
+
...(record.deprecated !== undefined ? { deprecated: record.deprecated } : {}),
|
|
432
|
+
source: record.source,
|
|
433
|
+
references: sortUnique(references.get(name) ?? []),
|
|
434
|
+
referencedBy: { direct: referencedByDirect, transitive: referencedByAll, localAliases: local },
|
|
435
|
+
code: { count: own.refs.length, files: summarizeRefs(own.refs) },
|
|
436
|
+
components: [...components.values()].map((item) => ({ ...item, via: sortUnique(item.via) })).sort(sortByName),
|
|
437
|
+
screens: [...screens.values()].map((item) => ({ ...item, via: sortUnique(item.via) })).sort(sortScreens),
|
|
438
|
+
summary: {
|
|
439
|
+
tokens: referencedByAll.length,
|
|
440
|
+
components: components.size,
|
|
441
|
+
// Components that use this token itself, not through an alias (the tier rule's count).
|
|
442
|
+
directComponents: own.components.length,
|
|
443
|
+
screens: screens.size,
|
|
444
|
+
codeRefs: own.refs.length,
|
|
445
|
+
impactCodeRefs: impactRefs,
|
|
446
|
+
},
|
|
447
|
+
...(tierWarning(record.tier, own.components.length) ? { warning: tierWarning(record.tier, own.components.length) } : {}),
|
|
448
|
+
...deleteBlockers({
|
|
449
|
+
tokens: referencedByDirect,
|
|
450
|
+
localAliases: local,
|
|
451
|
+
codeRefs: own.refs.length,
|
|
452
|
+
components: components.size,
|
|
453
|
+
}),
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const allTokens = () =>
|
|
458
|
+
records
|
|
459
|
+
.map((record) => tokenUsage(record.cssName))
|
|
460
|
+
.map((entry) => ({
|
|
461
|
+
token: entry.token,
|
|
462
|
+
path: entry.path,
|
|
463
|
+
tier: entry.tier,
|
|
464
|
+
...entry.summary,
|
|
465
|
+
...(entry.warning ? { warning: entry.warning } : {}),
|
|
466
|
+
deletable: entry.deletable,
|
|
467
|
+
}))
|
|
468
|
+
.sort((a, b) => a.path.localeCompare(b.path))
|
|
469
|
+
|
|
470
|
+
/** Hard-coded color literals under a file/dir prefix (or everywhere), with exact-value token matches. */
|
|
471
|
+
const componentFile = (name) =>
|
|
472
|
+
[...componentsByFile.values()].flat().find((item) => item.name === name)?.file
|
|
473
|
+
const hardcoded = (scope) => {
|
|
474
|
+
// Scope: a root-relative file or directory, or an exported component name.
|
|
475
|
+
const target = scope && /^[A-Z]\w*$/.test(scope) ? componentFile(scope) ?? scope : scope
|
|
476
|
+
const prefix = target ? toPosix(target).replace(/^\.\//, '').replace(/\/$/, '') : ''
|
|
477
|
+
const inScope = (file) => !prefix || file === prefix || file.startsWith(`${prefix}/`)
|
|
478
|
+
const byFile = new Map()
|
|
479
|
+
for (const diag of literals) {
|
|
480
|
+
if (!inScope(diag.file)) continue
|
|
481
|
+
const fileEntry = byFile.get(diag.file) ?? { file: diag.file, count: 0, values: new Map() }
|
|
482
|
+
fileEntry.count += 1
|
|
483
|
+
const value = fileEntry.values.get(diag.value) ?? { value: diag.value, count: 0, lines: [], properties: [] }
|
|
484
|
+
value.count += 1
|
|
485
|
+
if (typeof diag.line === 'number' && !value.lines.includes(diag.line)) value.lines.push(diag.line)
|
|
486
|
+
if (diag.property && !value.properties.includes(diag.property)) value.properties.push(diag.property)
|
|
487
|
+
fileEntry.values.set(diag.value, value)
|
|
488
|
+
byFile.set(diag.file, fileEntry)
|
|
489
|
+
}
|
|
490
|
+
const files = [...byFile.values()]
|
|
491
|
+
.map((entry) => ({
|
|
492
|
+
file: entry.file,
|
|
493
|
+
count: entry.count,
|
|
494
|
+
values: [...entry.values.values()]
|
|
495
|
+
.map((value) => ({
|
|
496
|
+
...value,
|
|
497
|
+
lines: value.lines.sort((a, b) => a - b),
|
|
498
|
+
properties: value.properties.sort(),
|
|
499
|
+
matches: records
|
|
500
|
+
.filter((record) => sameValue(record.value, value.value))
|
|
501
|
+
.map((record) => record.cssName)
|
|
502
|
+
.sort(),
|
|
503
|
+
}))
|
|
504
|
+
.sort((a, b) => b.count - a.count || a.value.localeCompare(b.value)),
|
|
505
|
+
}))
|
|
506
|
+
.sort((a, b) => b.count - a.count || a.file.localeCompare(b.file))
|
|
507
|
+
return {
|
|
508
|
+
scope: scope || '.',
|
|
509
|
+
...(target && target !== scope ? { file: target } : {}),
|
|
510
|
+
kinds: ['color'],
|
|
511
|
+
count: files.reduce((sum, entry) => sum + entry.count, 0),
|
|
512
|
+
files,
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// ---------------------------------------------------------------------------------------
|
|
517
|
+
// Component-centric view: which tokens / literals a component's styles use. Styles are
|
|
518
|
+
// attributed the same way as above (its own file, CSS rules whose subject classes it
|
|
519
|
+
// applies), plus rules for classes callers pass it (`<Button className="primary-button">`),
|
|
520
|
+
// since shared components are often styled at the call site. Call sites come from the AST
|
|
521
|
+
// index: every reference that resolves to the declaration.
|
|
522
|
+
// ---------------------------------------------------------------------------------------
|
|
523
|
+
const componentEntry = (name) => {
|
|
524
|
+
const definition = definitionOf(name)
|
|
525
|
+
return definition
|
|
526
|
+
? { name: definition.name, exportName: definition.exportName, file: definition.file, line: definition.line }
|
|
527
|
+
: null
|
|
528
|
+
}
|
|
529
|
+
// A component page's own renderers follow `<Name><Suffix>` (ButtonState, buttonFrames…);
|
|
530
|
+
// the name is the top-level declaration that contains the use, read from the syntax tree.
|
|
531
|
+
const PAGE_SUFFIX = /^(?:State|States|Page|Frame|Frames|Demo|Demos|Example|Examples|Story|Stories|Board|Preview|Previews)?$/
|
|
532
|
+
const ownerOfDeclaration = (declaration) => {
|
|
533
|
+
if (!declaration) return null
|
|
534
|
+
const upper = declaration[0].toUpperCase() + declaration.slice(1)
|
|
535
|
+
let best = null
|
|
536
|
+
for (const name of componentPages.keys()) {
|
|
537
|
+
if (upper.startsWith(name) && PAGE_SUFFIX.test(upper.slice(name.length))) {
|
|
538
|
+
if (!best || name.length > best.length) best = name
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
return best
|
|
542
|
+
}
|
|
543
|
+
const ruleDiags = usage.diagnostics.filter((diag) => diag.selector && (diag.kind === 'token-ref' || diag.kind === 'literal'))
|
|
544
|
+
const stateOf = (selector) => /:(hover|active|focus-visible|focus-within|focus|disabled)\b/.exec(String(selector ?? ''))?.[1]
|
|
545
|
+
|
|
546
|
+
/** Semantic tokens to use instead of a primitive one: those aliasing it, then equal values. */
|
|
547
|
+
const semanticFor = (token) => {
|
|
548
|
+
const record = byCss.get(token)
|
|
549
|
+
if (!record) return []
|
|
550
|
+
const aliasing = closure(token).filter((name) => byCss.get(name)?.tier === 'semantic')
|
|
551
|
+
const sameValued = records
|
|
552
|
+
.filter((other) => other.tier === 'semantic' && other.cssName !== token && sameValue(other.value, record.value))
|
|
553
|
+
.map((other) => other.cssName)
|
|
554
|
+
return [...new Set([...aliasing, ...sameValued])]
|
|
555
|
+
.slice(0, 4)
|
|
556
|
+
.map((name) => ({ token: name, path: byCss.get(name).path.join('.'), via: aliasing.includes(name) ? 'alias' : 'value' }))
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
const componentUsage = (name) => {
|
|
560
|
+
const definition = definitionOf(name)
|
|
561
|
+
if (!definition) return null
|
|
562
|
+
const file = definition.file
|
|
563
|
+
|
|
564
|
+
// Classes its callers pass it: rules for them style it too.
|
|
565
|
+
const callerClasses = new Set()
|
|
566
|
+
for (const use of index.usesOf(definition)) for (const word of use.classNames) callerClasses.add(word)
|
|
567
|
+
|
|
568
|
+
// --- what its styles use -------------------------------------------------------------
|
|
569
|
+
const ownClasses = classesOf({ file, abs: definition.abs })
|
|
570
|
+
const matchesRule = (selector, classes) =>
|
|
571
|
+
subjectClasses(selector).some((set) => set.every((item) => classes.has(item)))
|
|
572
|
+
const tokenRows = new Map()
|
|
573
|
+
const literalRows = new Map()
|
|
574
|
+
const addDiag = (diag, match) => {
|
|
575
|
+
const state = stateOf(diag.selector)
|
|
576
|
+
const property = diag.property ?? ''
|
|
577
|
+
if (diag.kind === 'token-ref') {
|
|
578
|
+
const token = resolveName(diag.token)
|
|
579
|
+
if (!token) return
|
|
580
|
+
const record = byCss.get(token)
|
|
581
|
+
const row = tokenRows.get(token) ?? {
|
|
582
|
+
token,
|
|
583
|
+
...(record ? { path: record.path.join('.'), tier: record.tier } : {}),
|
|
584
|
+
count: 0,
|
|
585
|
+
properties: new Map(),
|
|
586
|
+
file: diag.file,
|
|
587
|
+
...(typeof diag.line === 'number' ? { line: diag.line } : {}),
|
|
588
|
+
match,
|
|
589
|
+
}
|
|
590
|
+
row.count += 1
|
|
591
|
+
const propertyKey = `${property}\0${state ?? ''}`
|
|
592
|
+
const use = row.properties.get(propertyKey) ?? {
|
|
593
|
+
property,
|
|
594
|
+
...(state ? { state } : {}),
|
|
595
|
+
count: 0,
|
|
596
|
+
file: diag.file,
|
|
597
|
+
...(typeof diag.line === 'number' ? { line: diag.line } : {}),
|
|
598
|
+
match,
|
|
599
|
+
}
|
|
600
|
+
use.count += 1
|
|
601
|
+
row.properties.set(propertyKey, use)
|
|
602
|
+
tokenRows.set(token, row)
|
|
603
|
+
return
|
|
604
|
+
}
|
|
605
|
+
const key = `${property}\0${state ?? ''}\0${diag.value}`
|
|
606
|
+
const row = literalRows.get(key)
|
|
607
|
+
if (row) {
|
|
608
|
+
row.count += 1
|
|
609
|
+
return
|
|
610
|
+
}
|
|
611
|
+
literalRows.set(key, {
|
|
612
|
+
property,
|
|
613
|
+
...(state ? { state } : {}),
|
|
614
|
+
value: diag.value,
|
|
615
|
+
count: 1,
|
|
616
|
+
file: diag.file,
|
|
617
|
+
...(typeof diag.line === 'number' ? { line: diag.line } : {}),
|
|
618
|
+
match,
|
|
619
|
+
matches: records.filter((record) => sameValue(record.value, diag.value)).map((record) => record.cssName).sort(),
|
|
620
|
+
})
|
|
621
|
+
}
|
|
622
|
+
for (const diag of usage.diagnostics) {
|
|
623
|
+
if (diag.file === file && (diag.kind === 'token-ref' || diag.kind === 'literal')) addDiag(diag, `references in ${file}`)
|
|
624
|
+
}
|
|
625
|
+
for (const diag of ruleDiags) {
|
|
626
|
+
if (diag.file === file) continue
|
|
627
|
+
if (matchesRule(diag.selector, ownClasses)) addDiag(diag, `class rule ${diag.selector}`)
|
|
628
|
+
else if (matchesRule(diag.selector, callerClasses)) addDiag(diag, `caller className rule ${diag.selector}`)
|
|
629
|
+
}
|
|
630
|
+
const byState = (a, b) =>
|
|
631
|
+
String(a.state ?? '').localeCompare(String(b.state ?? '')) || a.property.localeCompare(b.property)
|
|
632
|
+
// One row per token, listing the properties (and states) it styles. A primitive-tier
|
|
633
|
+
// token used directly by a component is flagged with the semantic tokens to use instead.
|
|
634
|
+
const rows = [...tokenRows.values()]
|
|
635
|
+
.map((row) => {
|
|
636
|
+
const warning = tierWarning(row.tier)
|
|
637
|
+
return {
|
|
638
|
+
...row,
|
|
639
|
+
properties: [...row.properties.values()].sort(byState),
|
|
640
|
+
...(warning ? { warning, suggestions: semanticFor(row.token) } : {}),
|
|
641
|
+
}
|
|
642
|
+
})
|
|
643
|
+
.sort(
|
|
644
|
+
(a, b) =>
|
|
645
|
+
Number(Boolean(b.warning)) - Number(Boolean(a.warning)) ||
|
|
646
|
+
String(a.path ?? a.token).localeCompare(String(b.path ?? b.token)),
|
|
647
|
+
)
|
|
648
|
+
|
|
649
|
+
const literalCount = [...literalRows.values()].reduce((sum, row) => sum + row.count, 0)
|
|
650
|
+
return {
|
|
651
|
+
name,
|
|
652
|
+
file,
|
|
653
|
+
...(typeof definition.line === 'number' ? { line: definition.line } : {}),
|
|
654
|
+
page: componentPages.get(name) ?? null,
|
|
655
|
+
tokenRows: rows,
|
|
656
|
+
literals: [...literalRows.values()].sort(byState),
|
|
657
|
+
summary: {
|
|
658
|
+
tokens: rows.length,
|
|
659
|
+
primitive: rows.filter((row) => row.warning === 'primitive').length,
|
|
660
|
+
hardcoded: literalCount,
|
|
661
|
+
},
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
const componentNames = () => sortUnique(componentDefs.map((item) => item.name))
|
|
665
|
+
|
|
666
|
+
return {
|
|
667
|
+
tokenUsage,
|
|
668
|
+
allTokens,
|
|
669
|
+
hardcoded,
|
|
670
|
+
resolveName,
|
|
671
|
+
componentUsage,
|
|
672
|
+
componentNames,
|
|
673
|
+
componentEntry,
|
|
674
|
+
componentIndex: index,
|
|
675
|
+
componentDefinition: definitionOf,
|
|
676
|
+
componentPages,
|
|
677
|
+
/** The component whose page a design-file declaration renders (`ButtonState` → Button), or null. */
|
|
678
|
+
componentPageOwner: ownerOfDeclaration,
|
|
679
|
+
}
|
|
680
|
+
}
|