@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,479 @@
|
|
|
1
|
+
// Value normalization for consolidation: every literal and token value of a category is turned
|
|
2
|
+
// into one canonical form so equal values written differently (`#FFF`, `white`,
|
|
3
|
+
// `rgb(255 255 255)`; `0.75rem`, `12px`) compare equal, and near values get a distance:
|
|
4
|
+
// colors in OKLab (ΔE × 100, the scale where ~2 is a just-noticeable difference), dimensions
|
|
5
|
+
// in px. Parsing goes through postcss-value-parser nodes, never through file text.
|
|
6
|
+
import valueParser from 'postcss-value-parser'
|
|
7
|
+
|
|
8
|
+
import { CATEGORIES, DEFAULT_CATEGORIES } from '../../shared/consolidateCategories.mjs'
|
|
9
|
+
import { deltaE, rgbToOklab, sameHue } from '../../shared/oklab.mjs'
|
|
10
|
+
|
|
11
|
+
export { CATEGORIES, DEFAULT_CATEGORIES }
|
|
12
|
+
|
|
13
|
+
/** Default clustering tolerance per category: ΔE(OKLab×100) for colors, px for dimensions. */
|
|
14
|
+
export const DEFAULT_TOLERANCE = {
|
|
15
|
+
color: 2,
|
|
16
|
+
spacing: 1,
|
|
17
|
+
radius: 1,
|
|
18
|
+
'font-size': 1,
|
|
19
|
+
'border-width': 0,
|
|
20
|
+
size: 1,
|
|
21
|
+
'font-weight': 0,
|
|
22
|
+
'line-height': 0,
|
|
23
|
+
shadow: 0,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const SIDES = ['top', 'right', 'bottom', 'left', 'block', 'inline', 'block-start', 'block-end', 'inline-start', 'inline-end']
|
|
27
|
+
|
|
28
|
+
const CATEGORY_PROPERTIES = {
|
|
29
|
+
color: [
|
|
30
|
+
'color',
|
|
31
|
+
'background-color',
|
|
32
|
+
'border-color',
|
|
33
|
+
...SIDES.map((side) => `border-${side}-color`),
|
|
34
|
+
'outline-color',
|
|
35
|
+
'text-decoration-color',
|
|
36
|
+
'column-rule-color',
|
|
37
|
+
'caret-color',
|
|
38
|
+
'accent-color',
|
|
39
|
+
'fill',
|
|
40
|
+
'stroke',
|
|
41
|
+
'stop-color',
|
|
42
|
+
'flood-color',
|
|
43
|
+
'lighting-color',
|
|
44
|
+
'background',
|
|
45
|
+
],
|
|
46
|
+
spacing: [
|
|
47
|
+
'padding',
|
|
48
|
+
...SIDES.map((side) => `padding-${side}`),
|
|
49
|
+
'margin',
|
|
50
|
+
...SIDES.map((side) => `margin-${side}`),
|
|
51
|
+
'gap',
|
|
52
|
+
'row-gap',
|
|
53
|
+
'column-gap',
|
|
54
|
+
'grid-gap',
|
|
55
|
+
'scroll-margin',
|
|
56
|
+
'scroll-padding',
|
|
57
|
+
],
|
|
58
|
+
radius: [
|
|
59
|
+
'border-radius',
|
|
60
|
+
...['top-left', 'top-right', 'bottom-right', 'bottom-left', 'start-start', 'start-end', 'end-start', 'end-end'].map(
|
|
61
|
+
(corner) => `border-${corner}-radius`,
|
|
62
|
+
),
|
|
63
|
+
],
|
|
64
|
+
'font-size': ['font-size'],
|
|
65
|
+
'font-weight': ['font-weight'],
|
|
66
|
+
'line-height': ['line-height'],
|
|
67
|
+
'border-width': ['border-width', ...SIDES.map((side) => `border-${side}-width`), 'outline-width'],
|
|
68
|
+
shadow: ['box-shadow', 'text-shadow'],
|
|
69
|
+
size: ['width', 'height', 'min-width', 'min-height', 'max-width', 'max-height', 'inline-size', 'block-size', 'flex-basis'],
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Shorthands that can hold a value of the category among other values (always leftovers). */
|
|
73
|
+
const CATEGORY_SHORTHANDS = {
|
|
74
|
+
color: ['border', ...SIDES.map((side) => `border-${side}`), 'outline', 'text-decoration', 'column-rule', 'background-image'],
|
|
75
|
+
'font-size': ['font'],
|
|
76
|
+
'font-weight': ['font'],
|
|
77
|
+
'line-height': ['font'],
|
|
78
|
+
'border-width': ['border', ...SIDES.map((side) => `border-${side}`), 'outline'],
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const PROPERTY_CATEGORY = new Map()
|
|
82
|
+
for (const [category, properties] of Object.entries(CATEGORY_PROPERTIES)) {
|
|
83
|
+
for (const property of properties) PROPERTY_CATEGORY.set(property, category)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The category whose single-value properties include `property` (lower-case CSS name). */
|
|
87
|
+
export const categoryOfProperty = (property) => PROPERTY_CATEGORY.get(String(property ?? '').toLowerCase()) ?? null
|
|
88
|
+
|
|
89
|
+
/** Properties of `category` where a whole-value literal can be replaced by the tool. */
|
|
90
|
+
export const propertiesOf = (category) => CATEGORY_PROPERTIES[category] ?? []
|
|
91
|
+
|
|
92
|
+
/** Categories a shorthand property can carry inside a larger value. */
|
|
93
|
+
export const shorthandCategories = (property) =>
|
|
94
|
+
Object.entries(CATEGORY_SHORTHANDS)
|
|
95
|
+
.filter(([, list]) => list.includes(String(property ?? '').toLowerCase()))
|
|
96
|
+
.map(([category]) => category)
|
|
97
|
+
|
|
98
|
+
const SPACING_TW = ['p', 'px', 'py', 'pt', 'pr', 'pb', 'pl', 'ps', 'pe', 'm', 'mx', 'my', 'mt', 'mr', 'mb', 'ml', 'ms', 'me', 'gap', 'gap-x', 'gap-y', 'space-x', 'space-y', 'scroll-m', 'scroll-p']
|
|
99
|
+
const TW_SIDES = ['', '-x', '-y', '-t', '-r', '-b', '-l', '-s', '-e']
|
|
100
|
+
const TW_CORNERS = ['', '-t', '-r', '-b', '-l', '-s', '-e', '-tl', '-tr', '-br', '-bl', '-ss', '-se', '-ee', '-es']
|
|
101
|
+
|
|
102
|
+
/** Tailwind utilities whose arbitrary value (`p-[13px]`) belongs to each category. */
|
|
103
|
+
const CATEGORY_UTILITIES = {
|
|
104
|
+
color: ['bg', 'text', ...TW_SIDES.map((side) => `border${side}`), 'outline', 'ring', 'ring-offset', 'divide', 'accent', 'caret', 'fill', 'stroke', 'decoration', 'from', 'via', 'to', 'placeholder', 'shadow', 'inset-shadow', 'drop-shadow'],
|
|
105
|
+
spacing: SPACING_TW,
|
|
106
|
+
radius: TW_CORNERS.map((corner) => `rounded${corner}`),
|
|
107
|
+
'font-size': ['text'],
|
|
108
|
+
'font-weight': ['font'],
|
|
109
|
+
'line-height': ['leading'],
|
|
110
|
+
'border-width': [...TW_SIDES.map((side) => `border${side}`), 'outline', 'ring', 'divide-x', 'divide-y'],
|
|
111
|
+
// `drop-shadow-[…]` is a filter, not a box-shadow value: not clustered with shadow tokens.
|
|
112
|
+
shadow: ['shadow', 'inset-shadow'],
|
|
113
|
+
size: ['w', 'h', 'size', 'min-w', 'min-h', 'max-w', 'max-h', 'basis'],
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Tailwind namespace hint for `utility-(hint:--token)` when the token is outside the theme. */
|
|
117
|
+
export const NAMESPACE_HINT = {
|
|
118
|
+
color: 'color',
|
|
119
|
+
spacing: 'spacing',
|
|
120
|
+
radius: 'radius',
|
|
121
|
+
'font-size': 'text',
|
|
122
|
+
'font-weight': 'font-weight',
|
|
123
|
+
'line-height': 'leading',
|
|
124
|
+
// `border-(length:--w)` / `outline-(length:--w)` / `divide-x-(length:--w)`; `ring-(--w)` is the
|
|
125
|
+
// ring width already (Tailwind v4 docs: border-width, outline-width, box-shadow).
|
|
126
|
+
'border-width': 'border-width',
|
|
127
|
+
shadow: 'shadow',
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const utilitiesOf = (category) => CATEGORY_UTILITIES[category] ?? []
|
|
131
|
+
|
|
132
|
+
// ---------------------------------------------------------------------------------------
|
|
133
|
+
// Colors
|
|
134
|
+
|
|
135
|
+
/** The 148 CSS named colors (CSS Color 4). */
|
|
136
|
+
const NAMED_COLORS = {
|
|
137
|
+
aliceblue: '#f0f8ff', antiquewhite: '#faebd7', aqua: '#00ffff', aquamarine: '#7fffd4', azure: '#f0ffff',
|
|
138
|
+
beige: '#f5f5dc', bisque: '#ffe4c4', black: '#000000', blanchedalmond: '#ffebcd', blue: '#0000ff',
|
|
139
|
+
blueviolet: '#8a2be2', brown: '#a52a2a', burlywood: '#deb887', cadetblue: '#5f9ea0', chartreuse: '#7fff00',
|
|
140
|
+
chocolate: '#d2691e', coral: '#ff7f50', cornflowerblue: '#6495ed', cornsilk: '#fff8dc', crimson: '#dc143c',
|
|
141
|
+
cyan: '#00ffff', darkblue: '#00008b', darkcyan: '#008b8b', darkgoldenrod: '#b8860b', darkgray: '#a9a9a9',
|
|
142
|
+
darkgreen: '#006400', darkgrey: '#a9a9a9', darkkhaki: '#bdb76b', darkmagenta: '#8b008b',
|
|
143
|
+
darkolivegreen: '#556b2f', darkorange: '#ff8c00', darkorchid: '#9932cc', darkred: '#8b0000',
|
|
144
|
+
darksalmon: '#e9967a', darkseagreen: '#8fbc8f', darkslateblue: '#483d8b', darkslategray: '#2f4f4f',
|
|
145
|
+
darkslategrey: '#2f4f4f', darkturquoise: '#00ced1', darkviolet: '#9400d3', deeppink: '#ff1493',
|
|
146
|
+
deepskyblue: '#00bfff', dimgray: '#696969', dimgrey: '#696969', dodgerblue: '#1e90ff',
|
|
147
|
+
firebrick: '#b22222', floralwhite: '#fffaf0', forestgreen: '#228b22', fuchsia: '#ff00ff',
|
|
148
|
+
gainsboro: '#dcdcdc', ghostwhite: '#f8f8ff', gold: '#ffd700', goldenrod: '#daa520', gray: '#808080',
|
|
149
|
+
green: '#008000', greenyellow: '#adff2f', grey: '#808080', honeydew: '#f0fff0', hotpink: '#ff69b4',
|
|
150
|
+
indianred: '#cd5c5c', indigo: '#4b0082', ivory: '#fffff0', khaki: '#f0e68c', lavender: '#e6e6fa',
|
|
151
|
+
lavenderblush: '#fff0f5', lawngreen: '#7cfc00', lemonchiffon: '#fffacd', lightblue: '#add8e6',
|
|
152
|
+
lightcoral: '#f08080', lightcyan: '#e0ffff', lightgoldenrodyellow: '#fafad2', lightgray: '#d3d3d3',
|
|
153
|
+
lightgreen: '#90ee90', lightgrey: '#d3d3d3', lightpink: '#ffb6c1', lightsalmon: '#ffa07a',
|
|
154
|
+
lightseagreen: '#20b2aa', lightskyblue: '#87cefa', lightslategray: '#778899', lightslategrey: '#778899',
|
|
155
|
+
lightsteelblue: '#b0c4de', lightyellow: '#ffffe0', lime: '#00ff00', limegreen: '#32cd32', linen: '#faf0e6',
|
|
156
|
+
magenta: '#ff00ff', maroon: '#800000', mediumaquamarine: '#66cdaa', mediumblue: '#0000cd',
|
|
157
|
+
mediumorchid: '#ba55d3', mediumpurple: '#9370db', mediumseagreen: '#3cb371', mediumslateblue: '#7b68ee',
|
|
158
|
+
mediumspringgreen: '#00fa9a', mediumturquoise: '#48d1cc', mediumvioletred: '#c71585',
|
|
159
|
+
midnightblue: '#191970', mintcream: '#f5fffa', mistyrose: '#ffe4e1', moccasin: '#ffe4b5',
|
|
160
|
+
navajowhite: '#ffdead', navy: '#000080', oldlace: '#fdf5e6', olive: '#808000', olivedrab: '#6b8e23',
|
|
161
|
+
orange: '#ffa500', orangered: '#ff4500', orchid: '#da70d6', palegoldenrod: '#eee8aa', palegreen: '#98fb98',
|
|
162
|
+
paleturquoise: '#afeeee', palevioletred: '#db7093', papayawhip: '#ffefd5', peachpuff: '#ffdab9',
|
|
163
|
+
peru: '#cd853f', pink: '#ffc0cb', plum: '#dda0dd', powderblue: '#b0e0e6', purple: '#800080',
|
|
164
|
+
rebeccapurple: '#663399', red: '#ff0000', rosybrown: '#bc8f8f', royalblue: '#4169e1',
|
|
165
|
+
saddlebrown: '#8b4513', salmon: '#fa8072', sandybrown: '#f4a460', seagreen: '#2e8b57', seashell: '#fff5ee',
|
|
166
|
+
sienna: '#a0522d', silver: '#c0c0c0', skyblue: '#87ceeb', slateblue: '#6a5acd', slategray: '#708090',
|
|
167
|
+
slategrey: '#708090', snow: '#fffafa', springgreen: '#00ff7f', steelblue: '#4682b4', tan: '#d2b48c',
|
|
168
|
+
teal: '#008080', thistle: '#d8bfd8', tomato: '#ff6347', turquoise: '#40e0d0', violet: '#ee82ee',
|
|
169
|
+
wheat: '#f5deb3', white: '#ffffff', whitesmoke: '#f5f5f5', yellow: '#ffff00', yellowgreen: '#9acd32',
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Keywords that are colors but never consolidated into tokens. */
|
|
173
|
+
const COLOR_KEYWORDS = new Set(['transparent', 'currentcolor', 'inherit', 'initial', 'unset', 'revert', 'none'])
|
|
174
|
+
|
|
175
|
+
const clamp01 = (value) => Math.min(1, Math.max(0, value))
|
|
176
|
+
const hex2 = (value) => Math.round(clamp01(value) * 255).toString(16).padStart(2, '0')
|
|
177
|
+
|
|
178
|
+
function parseNumber(node, { percentScale = 1, angle = false } = {}) {
|
|
179
|
+
if (!node || node.type !== 'word') return null
|
|
180
|
+
const unit = valueParser.unit(node.value)
|
|
181
|
+
if (!unit) {
|
|
182
|
+
if (node.value.toLowerCase() === 'none') return 0
|
|
183
|
+
return null
|
|
184
|
+
}
|
|
185
|
+
const number = Number(unit.number)
|
|
186
|
+
if (!Number.isFinite(number)) return null
|
|
187
|
+
const suffix = unit.unit.toLowerCase()
|
|
188
|
+
if (suffix === '%') return (number / 100) * percentScale
|
|
189
|
+
if (angle) {
|
|
190
|
+
if (suffix === '' || suffix === 'deg') return number
|
|
191
|
+
if (suffix === 'turn') return number * 360
|
|
192
|
+
if (suffix === 'rad') return (number * 180) / Math.PI
|
|
193
|
+
if (suffix === 'grad') return number * 0.9
|
|
194
|
+
return null
|
|
195
|
+
}
|
|
196
|
+
return suffix === '' ? number : null
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Function arguments split into [channels, alpha] (comma syntax or `a b c / alpha`). */
|
|
200
|
+
function functionArgs(node) {
|
|
201
|
+
const parts = []
|
|
202
|
+
let alpha = null
|
|
203
|
+
let slash = false
|
|
204
|
+
for (const child of node.nodes ?? []) {
|
|
205
|
+
if (child.type === 'space' || child.type === 'comment') continue
|
|
206
|
+
if (child.type === 'div') {
|
|
207
|
+
if (child.value === '/') slash = true
|
|
208
|
+
continue
|
|
209
|
+
}
|
|
210
|
+
if (slash) alpha = child
|
|
211
|
+
else parts.push(child)
|
|
212
|
+
}
|
|
213
|
+
if (alpha === null && parts.length === 4) alpha = parts.pop()
|
|
214
|
+
return { parts, alpha }
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const linearToSrgb = (c) => (c <= 0.0031308 ? 12.92 * c : 1.055 * c ** (1 / 2.4) - 0.055)
|
|
218
|
+
|
|
219
|
+
export { rgbToOklab }
|
|
220
|
+
|
|
221
|
+
/** OKLab → sRGB (0..1, unclamped; `inGamut` false when clamping was needed). */
|
|
222
|
+
export function oklabToRgb([L, a, b]) {
|
|
223
|
+
const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3
|
|
224
|
+
const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3
|
|
225
|
+
const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3
|
|
226
|
+
const rgb = [
|
|
227
|
+
linearToSrgb(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s),
|
|
228
|
+
linearToSrgb(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s),
|
|
229
|
+
linearToSrgb(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s),
|
|
230
|
+
]
|
|
231
|
+
return rgb
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function hslToRgb(h, s, l) {
|
|
235
|
+
const hue = (((h % 360) + 360) % 360) / 360
|
|
236
|
+
if (s === 0) return [l, l, l]
|
|
237
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s
|
|
238
|
+
const p = 2 * l - q
|
|
239
|
+
const channel = (t) => {
|
|
240
|
+
let x = t
|
|
241
|
+
if (x < 0) x += 1
|
|
242
|
+
if (x > 1) x -= 1
|
|
243
|
+
if (x < 1 / 6) return p + (q - p) * 6 * x
|
|
244
|
+
if (x < 1 / 2) return q
|
|
245
|
+
if (x < 2 / 3) return p + (q - p) * (2 / 3 - x) * 6
|
|
246
|
+
return p
|
|
247
|
+
}
|
|
248
|
+
return [channel(hue + 1 / 3), channel(hue), channel(hue - 1 / 3)]
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function colorFromNode(node) {
|
|
252
|
+
if (node.type === 'word') {
|
|
253
|
+
const value = node.value.toLowerCase()
|
|
254
|
+
const hex = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/.exec(value)?.[1]
|
|
255
|
+
if (hex) {
|
|
256
|
+
const full = hex.length <= 4 ? [...hex].map((ch) => ch + ch).join('') : hex
|
|
257
|
+
const channels = [0, 2, 4, 6].map((i) => (full.length > i ? parseInt(full.slice(i, i + 2), 16) / 255 : 1))
|
|
258
|
+
return { rgb: channels.slice(0, 3), alpha: channels[3] }
|
|
259
|
+
}
|
|
260
|
+
if (NAMED_COLORS[value]) return colorFromNode({ type: 'word', value: NAMED_COLORS[value] })
|
|
261
|
+
return null
|
|
262
|
+
}
|
|
263
|
+
if (node.type !== 'function') return null
|
|
264
|
+
const name = node.value.toLowerCase()
|
|
265
|
+
const { parts, alpha: alphaNode } = functionArgs(node)
|
|
266
|
+
if (parts.length !== 3) return null
|
|
267
|
+
const alpha = alphaNode ? parseNumber(alphaNode) : 1
|
|
268
|
+
if (alpha === null) return null
|
|
269
|
+
if (name === 'rgb' || name === 'rgba') {
|
|
270
|
+
const channels = parts.map((part) => parseNumber(part, { percentScale: 255 }))
|
|
271
|
+
if (channels.some((value) => value === null)) return null
|
|
272
|
+
return { rgb: channels.map((value) => value / 255), alpha }
|
|
273
|
+
}
|
|
274
|
+
if (name === 'hsl' || name === 'hsla') {
|
|
275
|
+
const h = parseNumber(parts[0], { angle: true })
|
|
276
|
+
const s = parseNumber(parts[1])
|
|
277
|
+
const l = parseNumber(parts[2])
|
|
278
|
+
if (h === null || s === null || l === null) return null
|
|
279
|
+
// `hsl(0 50 50)` (modern, no %) means 50%.
|
|
280
|
+
const pct = (value, part) => (valueParser.unit(part.value)?.unit === '%' ? value : value / 100)
|
|
281
|
+
return { rgb: hslToRgb(h, pct(s, parts[1]), pct(l, parts[2])), alpha }
|
|
282
|
+
}
|
|
283
|
+
if (name === 'oklch' || name === 'oklab') {
|
|
284
|
+
const L = parseNumber(parts[0])
|
|
285
|
+
if (L === null) return null
|
|
286
|
+
const lightness = L
|
|
287
|
+
if (name === 'oklch') {
|
|
288
|
+
const C = parseNumber(parts[1], { percentScale: 0.4 })
|
|
289
|
+
const H = parseNumber(parts[2], { angle: true })
|
|
290
|
+
if (C === null || H === null) return null
|
|
291
|
+
const rad = (H * Math.PI) / 180
|
|
292
|
+
return { rgb: oklabToRgb([lightness, C * Math.cos(rad), C * Math.sin(rad)]), alpha }
|
|
293
|
+
}
|
|
294
|
+
const A = parseNumber(parts[1], { percentScale: 0.4 })
|
|
295
|
+
const B = parseNumber(parts[2], { percentScale: 0.4 })
|
|
296
|
+
if (A === null || B === null) return null
|
|
297
|
+
return { rgb: oklabToRgb([lightness, A, B]), alpha }
|
|
298
|
+
}
|
|
299
|
+
return null
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Parse one CSS color value. Returns `{ canonical, rgb, alpha, lab, approximate }` with
|
|
304
|
+
* `canonical` the lower-case `#rrggbb` (or `#rrggbbaa` when translucent), or null when the
|
|
305
|
+
* value is not a single static color (keywords, `color-mix()`, `var()`…).
|
|
306
|
+
*/
|
|
307
|
+
export function parseColor(value) {
|
|
308
|
+
let parsed
|
|
309
|
+
try {
|
|
310
|
+
parsed = valueParser(String(value ?? '').trim())
|
|
311
|
+
} catch {
|
|
312
|
+
return null
|
|
313
|
+
}
|
|
314
|
+
const nodes = parsed.nodes.filter((node) => node.type !== 'space' && node.type !== 'comment')
|
|
315
|
+
if (nodes.length !== 1) return null
|
|
316
|
+
return colorOfNode(nodes[0])
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** Like `parseColor` for an already parsed postcss-value-parser node. */
|
|
320
|
+
export function colorOfNode(node) {
|
|
321
|
+
if (node.type === 'word' && COLOR_KEYWORDS.has(node.value.toLowerCase())) return null
|
|
322
|
+
const color = colorFromNode(node)
|
|
323
|
+
if (!color) return null
|
|
324
|
+
const approximate = color.rgb.some((channel) => channel < -0.0005 || channel > 1.0005)
|
|
325
|
+
const rgb = color.rgb.map(clamp01)
|
|
326
|
+
const alpha = clamp01(color.alpha)
|
|
327
|
+
// A color outside sRGB is not its clipped hex: it keeps its own (lower-case) spelling as the
|
|
328
|
+
// canonical, so it never compares equal to the hex, and is flagged `approximate`.
|
|
329
|
+
const canonical = approximate
|
|
330
|
+
? valueParser.stringify(node).trim().toLowerCase().replace(/\s+/g, ' ')
|
|
331
|
+
: `#${rgb.map(hex2).join('')}${alpha < 1 ? hex2(alpha) : ''}`
|
|
332
|
+
// Distances use the 8-bit canonical value so equal canonicals are exactly 0 apart.
|
|
333
|
+
const quantized = rgb.map((channel) => Math.round(channel * 255) / 255)
|
|
334
|
+
return { canonical, rgb: quantized, alpha: Math.round(alpha * 255) / 255, lab: rgbToOklab(quantized), ...(approximate ? { approximate: true } : {}) }
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** Is this node a color literal (anything `colorOfNode` understands)? */
|
|
338
|
+
export const isColorNode = (node) => colorOfNode(node) !== null
|
|
339
|
+
|
|
340
|
+
/** Perceptual distance: Euclidean OKLab × 100, with alpha difference × 100 in quadrature. */
|
|
341
|
+
export function colorDistance(a, b) {
|
|
342
|
+
return deltaE(a.lab, b.lab, a.alpha, b.alpha)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* How close two colors are for clustering and reuse suggestions: their ΔE, or Infinity when
|
|
347
|
+
* their hues differ (shared/oklab.mjs `sameHue`: a tint is never close to a gray, a red tint
|
|
348
|
+
* never close to a violet one), however small the ΔE.
|
|
349
|
+
*/
|
|
350
|
+
export function colorCloseness(a, b) {
|
|
351
|
+
return sameHue(a.lab, b.lab) ? colorDistance(a, b) : Infinity
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// ---------------------------------------------------------------------------------------
|
|
355
|
+
// Dimensions, numbers, shadows
|
|
356
|
+
|
|
357
|
+
const LENGTH_UNITS = new Set(['px', 'rem', 'em', '%', 'ch', 'ex', 'vw', 'vh', 'vmin', 'vmax', 'pt', 'cap', 'lh', 'rlh', 'svh', 'dvh', 'lvh'])
|
|
358
|
+
const DIMENSION_KEYWORDS = new Set(['auto', 'inherit', 'initial', 'unset', 'revert', 'none', 'normal'])
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Parse a length (`12px`, `0.75rem`; `rem` counts as `rootPx` px). Returns
|
|
362
|
+
* `{ canonical, number, unit, px? }` (`unit` is the comparison family: px for px/rem/pt,
|
|
363
|
+
* else the unit itself), or null. Zero is not consolidated.
|
|
364
|
+
*/
|
|
365
|
+
export function parseDimension(value, { rootPx = 16, unitless = false } = {}) {
|
|
366
|
+
const unit = valueParser.unit(String(value ?? '').trim())
|
|
367
|
+
if (!unit) return null
|
|
368
|
+
const number = Number(unit.number)
|
|
369
|
+
if (!Number.isFinite(number)) return null
|
|
370
|
+
const suffix = unit.unit.toLowerCase()
|
|
371
|
+
if (number === 0) return null
|
|
372
|
+
if (suffix === '') return unitless ? { canonical: String(round(number)), number, unit: '' } : null
|
|
373
|
+
if (!LENGTH_UNITS.has(suffix)) return null
|
|
374
|
+
if (suffix === 'px' || suffix === 'rem' || suffix === 'pt') {
|
|
375
|
+
const px = suffix === 'px' ? number : suffix === 'rem' ? number * rootPx : (number * 4) / 3
|
|
376
|
+
return { canonical: `${round(px)}px`, number, unit: 'px', px: round(px), ...(suffix !== 'px' ? { converted: suffix } : {}) }
|
|
377
|
+
}
|
|
378
|
+
return { canonical: `${round(number)}${suffix}`, number, unit: suffix }
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
const round = (value) => Math.round(value * 1000) / 1000
|
|
382
|
+
|
|
383
|
+
const FONT_WEIGHTS = { normal: 400, bold: 700 }
|
|
384
|
+
|
|
385
|
+
export function parseFontWeight(value) {
|
|
386
|
+
const text = String(value ?? '').trim().toLowerCase()
|
|
387
|
+
if (FONT_WEIGHTS[text]) return { canonical: String(FONT_WEIGHTS[text]), number: FONT_WEIGHTS[text], unit: '' }
|
|
388
|
+
if (!/^\d{1,4}$/.test(text)) return null
|
|
389
|
+
const number = Number(text)
|
|
390
|
+
return number >= 1 && number <= 1000 ? { canonical: String(number), number, unit: '' } : null
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/** Shadows are compared exactly after normalizing whitespace, zero units and colors. */
|
|
394
|
+
export function parseShadow(value) {
|
|
395
|
+
let parsed
|
|
396
|
+
try {
|
|
397
|
+
parsed = valueParser(String(value ?? '').trim())
|
|
398
|
+
} catch {
|
|
399
|
+
return null
|
|
400
|
+
}
|
|
401
|
+
let dynamic = false
|
|
402
|
+
valueParser.walk(parsed.nodes, (node) => {
|
|
403
|
+
if (node.type === 'function' && ['var', 'env', 'calc', 'color-mix'].includes(node.value.toLowerCase())) dynamic = true
|
|
404
|
+
})
|
|
405
|
+
if (dynamic) return null
|
|
406
|
+
const text = valueParser.stringify(parsed.nodes).trim().toLowerCase()
|
|
407
|
+
if (!text || DIMENSION_KEYWORDS.has(text)) return null
|
|
408
|
+
const out = []
|
|
409
|
+
const visit = (nodes) => {
|
|
410
|
+
for (const node of nodes) {
|
|
411
|
+
if (node.type === 'space' || node.type === 'comment') continue
|
|
412
|
+
if (node.type === 'div') {
|
|
413
|
+
out.push(node.value === ',' ? ',' : node.value)
|
|
414
|
+
continue
|
|
415
|
+
}
|
|
416
|
+
const color = colorOfNode(node)
|
|
417
|
+
if (color) {
|
|
418
|
+
out.push(color.canonical)
|
|
419
|
+
continue
|
|
420
|
+
}
|
|
421
|
+
if (node.type === 'word') {
|
|
422
|
+
const unit = valueParser.unit(node.value)
|
|
423
|
+
out.push(unit && Number(unit.number) === 0 ? '0' : node.value.toLowerCase())
|
|
424
|
+
continue
|
|
425
|
+
}
|
|
426
|
+
out.push(valueParser.stringify(node).toLowerCase().replace(/\s+/g, ' '))
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
visit(parsed.nodes)
|
|
430
|
+
return { canonical: out.join(' ').replace(/ , /g, ', ') }
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Normalize a value of `category`. Returns `{ canonical, … }` or null when the value cannot
|
|
435
|
+
* take part (keywords, zero, var()/calc(), composite formulas).
|
|
436
|
+
*/
|
|
437
|
+
export function normalizeValue(category, value, options = {}) {
|
|
438
|
+
if (category === 'color') return parseColor(value)
|
|
439
|
+
if (category === 'shadow') return parseShadow(value)
|
|
440
|
+
if (category === 'font-weight') return parseFontWeight(value)
|
|
441
|
+
if (category === 'line-height') return parseDimension(value, { ...options, unitless: true })
|
|
442
|
+
return parseDimension(value, options)
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** Distance between two normalized values of a category (Infinity when not comparable). */
|
|
446
|
+
export function valueDistance(category, a, b) {
|
|
447
|
+
if (!a || !b) return Infinity
|
|
448
|
+
if (a.canonical === b.canonical) return 0
|
|
449
|
+
if (category === 'color') return colorCloseness(a, b)
|
|
450
|
+
if (category === 'shadow') return Infinity
|
|
451
|
+
if (a.unit !== b.unit) return Infinity
|
|
452
|
+
return Math.abs((a.px ?? a.number) - (b.px ?? b.number))
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** Categories whose values are lengths: the written unit matters (rem follows the root font size). */
|
|
456
|
+
export const LENGTH_CATEGORIES = new Set(['spacing', 'radius', 'font-size', 'border-width', 'size', 'line-height'])
|
|
457
|
+
|
|
458
|
+
/** The written unit of a length value (`rem`, `px`, `''` for unitless), else ''. */
|
|
459
|
+
export function unitKind(category, text) {
|
|
460
|
+
if (!LENGTH_CATEGORIES.has(category)) return ''
|
|
461
|
+
const unit = valueParser.unit(String(text ?? '').trim())
|
|
462
|
+
return unit ? unit.unit.toLowerCase() : ''
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/** Delta record for a visible change (`from` → `to`). */
|
|
466
|
+
export function deltaOf(category, from, to) {
|
|
467
|
+
const distance = valueDistance(category, from, to)
|
|
468
|
+
if (category === 'color') {
|
|
469
|
+
// The delta is the plain ΔE even across hues (a human may still pick such a token).
|
|
470
|
+
return {
|
|
471
|
+
deltaE: from?.lab && to?.lab ? Math.round(colorDistance(from, to) * 100) / 100 : Math.round(distance * 100) / 100,
|
|
472
|
+
...(from?.lab && to?.lab && !sameHue(from.lab, to.lab) ? { hue: 'different' } : {}),
|
|
473
|
+
...(from?.approximate || to?.approximate ? { gamut: 'outside sRGB: compared after clipping; the rendered color changes' } : {}),
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
if (category === 'shadow') return { different: true }
|
|
477
|
+
if (Number.isFinite(distance)) return { [from.unit || 'value']: round(((to.px ?? to.number) - (from.px ?? from.number))) }
|
|
478
|
+
return { different: true }
|
|
479
|
+
}
|