@astryxdesign/cli 0.7.18-canary.gfca8508 → 0.7.18
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/CHANGELOG.md +185 -19
- package/README.md +19 -19
- package/api/component/_adapter.d.mts +2 -1
- package/api/component/_adapter.mjs +2 -1
- package/api/docs/_adapter.d.mts +6 -5
- package/api/docs/_adapter.mjs +36 -5
- package/api/doctor/_adapter.d.mts +6 -3
- package/api/doctor/_adapter.mjs +13 -5
- package/api/doctor/doctor.mjs +2 -2
- package/api/doctor/font-packages.d.mts +36 -0
- package/api/doctor/font-packages.mjs +124 -0
- package/api/doctor/theme-checks.mjs +110 -49
- package/api/experimental.d.mts +0 -2
- package/api/experimental.mjs +0 -12
- package/api/icon/_adapter.d.mts +1 -1
- package/api/icon/_adapter.mjs +1 -0
- package/api/icon/_authoring.mjs +17 -8
- package/api/icon/_default-look.mjs +15 -15
- package/api/icon/add/add.mjs +9 -4
- package/api/icon/exportIconIndex.doc.mjs +1 -1
- package/api/icon/icon.doc.mjs +1 -1
- package/api/icon/icon.type.d.mts +33 -33
- package/api/icon/icon.type.mjs +45 -45
- package/api/icon/iconAdd.doc.mjs +1 -1
- package/api/icon/iconNewSet.doc.mjs +3 -3
- package/api/icon/iconUse.doc.mjs +5 -5
- package/api/icon/rankIconIndex.doc.mjs +1 -1
- package/api/icon/use/use.mjs +4 -4
- package/api/init/run/run.mjs +0 -1
- package/api/integration/add-helpers.mjs +1 -1
- package/api/render/_adapter.mjs +7 -1
- package/api/search/ORDERING.md +1 -1
- package/api/search/_candidate-score.mjs +20 -0
- package/api/search/_words.d.mts +8 -0
- package/api/search/_words.mjs +15 -0
- package/api/template/template.type.d.mts +2 -2
- package/api/template/template.type.mjs +2 -2
- package/api/theme/_adapter.mjs +19 -11
- package/api/theme/build/build.d.mts +19 -51
- package/api/theme/build/build.mjs +195 -189
- package/api/theme/build/font-warning.d.mts +19 -2
- package/api/theme/build/font-warning.mjs +46 -5
- package/api/theme/generateTonalPalette.doc.mjs +1 -1
- package/api/theme/palette/generate/derive-look.mjs +108 -37
- package/api/theme/palette/generate/mapping.mjs +2 -0
- package/api/theme/template/template.d.mts +0 -17
- package/api/theme/template/template.mjs +1 -42
- package/api/theme/theme.type.d.mts +5 -4
- package/api/theme/theme.type.mjs +5 -4
- package/api/theme/themePaletteGenerate.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +1 -1
- package/assets/codemods/transforms/v0.7.0/preserve-bottom-sheet-content-padding.mjs +3 -1
- package/assets/component-list.generated.json +1 -1
- package/assets/discover/official-packages.json +26 -2
- package/assets/docs/author-a-theme.doc.mjs +6 -5
- package/assets/docs/browser-support.doc.mjs +1 -0
- package/assets/docs/icons.doc.mjs +8 -7
- package/assets/docs/motion.doc.mjs +46 -0
- package/assets/docs/theme.doc.dense.mjs +6 -17
- package/assets/docs/theme.doc.mjs +6 -16
- package/assets/docs/theme.doc.zh.mjs +6 -16
- package/assets/docs/tree/ci-and-containers.doc.mjs +1 -1
- package/assets/docs/tree/font-setup.doc.mjs +30 -0
- package/assets/docs/tree/icon-sets.doc.mjs +1 -1
- package/assets/docs/tree/template-icons.doc.mjs +3 -3
- package/assets/docs/tree/tokens-color.doc.mjs +5 -0
- package/assets/docs/tree/tokens.doc.mjs +4 -3
- package/assets/docs/tree/updates.doc.mjs +1 -1
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/icons/definitions/drag.doc.mjs +1 -0
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Card/SelectableCardElevated.doc.mjs +1 -1
- package/assets/templates/blocks/components/Card/SelectableCardElevated.tsx +20 -10
- package/assets/templates/blocks/components/Card/SelectableCardShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/Card/SelectableCardShowcase.tsx +36 -16
- package/assets/templates/blocks/components/ChatComposerInput/ChatComposerInputMentionTrigger.tsx +6 -0
- package/assets/templates/blocks/components/ChatComposerInput/ChatComposerInputMultipleTriggers.tsx +6 -0
- package/assets/templates/blocks/components/Hooks/useIndicatorFocusRingHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useIndicatorFocusRingHookUsage.tsx +63 -0
- package/assets/templates/blocks/components/Hooks/useLongPressHookUsage.doc.mjs +29 -0
- package/assets/templates/blocks/components/Hooks/useLongPressHookUsage.tsx +237 -0
- package/assets/templates/blocks/components/SideNav/SideNavShowcase.tsx +10 -72
- package/assets/templates/blocks/components/SideNav/SideNavWithHeaderMenu.doc.mjs +1 -1
- package/assets/templates/blocks/components/SideNav/SideNavWithHeaderMenu.tsx +7 -7
- package/assets/templates/blocks/components/Table/TableCustomRowTable.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/TableCustomRowTable.tsx +96 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ai-chat-landing/page.tsx +4 -0
- package/assets/templates/pages/dashboard-scorecard/page.tsx +26 -7
- package/assets/templates/pages/editor/page.tsx +13 -3
- package/assets/templates/themes/butter/butterPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/butter/butterTheme.ts +12 -10
- package/assets/templates/themes/butter/icons.tsx +2 -0
- package/assets/templates/themes/chocolate/chocolateTheme.ts +1 -0
- package/assets/templates/themes/chocolate/icons.tsx +2 -0
- package/assets/templates/themes/gothic/gothicPaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/gothic/gothicTheme.ts +1 -0
- package/assets/templates/themes/gothic/icons.tsx +2 -0
- package/assets/templates/themes/matcha/icons.tsx +2 -0
- package/assets/templates/themes/matcha/matchaPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/matcha/matchaTheme.ts +1 -0
- package/assets/templates/themes/neutral/icons.tsx +2 -0
- package/assets/templates/themes/neutral/neutralPaletteRefs.generated.ts +2 -2
- package/assets/templates/themes/neutral/neutralTheme.ts +1 -0
- package/assets/templates/themes/stone/icons.tsx +2 -0
- package/assets/templates/themes/stone/stonePaletteRefs.generated.ts +1 -1
- package/assets/templates/themes/stone/stoneTheme.ts +1 -0
- package/assets/templates/themes/y2k/icons.tsx +2 -0
- package/assets/templates/themes/y2k/y2kTheme.ts +1 -0
- package/assets/theme.template.ts +9 -5
- package/authoring/config/parse.mjs +1 -1
- package/authoring/doctypes/base/type.ts +2 -3
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/icon-set/icon-names.mjs +1 -0
- package/authoring/integration/integration.doc.mjs +1 -1
- package/authoring/integration/type.ts +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/experimental/icon.mjs +7 -7
- package/clients/cli/commands/experimental/index.mjs +0 -5
- package/clients/cli/commands/experimental-icon-new-set.doc.mjs +2 -2
- package/clients/cli/commands/experimental-icon-use.doc.mjs +4 -4
- package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
- package/clients/cli/commands/experimental.doc.mjs +2 -6
- package/clients/cli/commands/template.mjs +1 -1
- package/clients/cli/commands/theme-build.doc.mjs +8 -1
- package/clients/cli/commands/theme-palette-generate.doc.mjs +1 -1
- package/clients/cli/commands/theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/theme.doc.mjs +1 -11
- package/clients/cli/commands/theme.mjs +110 -475
- package/clients/cli/commands.generated.json +1 -1
- package/clients/cli/index.mjs +4 -34
- package/clients/cli/lib/base-gate.mjs +2 -3
- package/clients/cli/lib/cli-error.mjs +8 -72
- package/clients/cli/lib/define-command.mjs +0 -19
- package/clients/cli/lib/json-shim.mjs +11 -633
- package/clients/cli/lib/manifest.mjs +0 -4
- package/clients/cli/lib/stray-option.mjs +1 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.mjs +1 -1
- package/foundation/color/css-color.mjs +2 -3
- package/foundation/discovery/app-layout.d.mts +13 -0
- package/foundation/discovery/app-layout.mjs +35 -0
- package/foundation/discovery/fixture-refs.d.mts +51 -0
- package/foundation/discovery/fixture-refs.mjs +351 -0
- package/foundation/discovery/icon-definition-discovery.mjs +1 -1
- package/foundation/discovery/icon-ranking.mjs +2 -2
- package/foundation/discovery/icon-set-checks.mjs +1 -1
- package/foundation/discovery/icon-set-discovery.mjs +1 -1
- package/foundation/discovery/icon-set-writer.d.mts +24 -7
- package/foundation/discovery/icon-set-writer.mjs +66 -22
- package/foundation/discovery/static-descriptor.d.mts +49 -0
- package/foundation/discovery/static-descriptor.mjs +548 -0
- package/foundation/discovery/template-adapter.d.mts +0 -47
- package/foundation/discovery/template-adapter.mjs +1 -333
- package/foundation/discovery/theme-discovery.d.mts +6 -47
- package/foundation/discovery/theme-discovery.mjs +15 -537
- package/foundation/doc-compiler/import.mjs +1 -1
- package/foundation/env/user-dirs.d.mts +5 -2
- package/foundation/env/user-dirs.mjs +12 -5
- package/foundation/fonts/next-font.d.mts +26 -0
- package/foundation/fonts/next-font.mjs +149 -0
- package/foundation/fs/empty-folder.mjs +2 -2
- package/foundation/fs/read-record.mjs +11 -4
- package/foundation/pictures/pictures.d.mts +1 -45
- package/foundation/pictures/pictures.mjs +8 -8
- package/foundation/release/folder-lock.mjs +3 -2
- package/foundation/render/cut-short.d.mts +2 -2
- package/foundation/render/cut-short.mjs +2 -2
- package/foundation/render/drawn-contrast.d.mts +2 -2
- package/foundation/render/drawn-contrast.mjs +2 -2
- package/foundation/render/font-probe.d.mts +2 -2
- package/foundation/render/font-probe.mjs +2 -2
- package/foundation/render/layers.mjs +1 -2
- package/foundation/render/package-resolve-hooks.d.mts +25 -5
- package/foundation/render/package-resolve-hooks.mjs +77 -14
- package/foundation/render/page-worker.mjs +24 -12
- package/foundation/render/part-boxes.d.mts +2 -3
- package/foundation/render/part-boxes.mjs +2 -3
- package/foundation/render/picture-chrome.mjs +5 -0
- package/foundation/render/render-page.d.mts +1 -1
- package/foundation/render/render-page.mjs +4 -5
- package/foundation/render/single-copy-hooks.d.mts +2 -0
- package/foundation/render/single-copy-hooks.mjs +2 -0
- package/foundation/response/error-codes.doc.mjs +14 -14
- package/foundation/response/error-codes.mjs +13 -13
- package/foundation/response/response-types.doc.mjs +7 -68
- package/foundation/runtime/css-tree.mjs +2 -2
- package/foundation/runtime/word-table.d.mts +1 -1
- package/foundation/runtime/word-table.mjs +1 -1
- package/foundation/suggest/other-command.d.mts +52 -15
- package/foundation/suggest/other-command.mjs +168 -45
- package/foundation/text/suggest-order.d.mts +7 -0
- package/foundation/text/suggest-order.mjs +1 -1
- package/package.json +7 -8
- package/api/theme-edit/_adapter.d.mts +0 -228
- package/api/theme-edit/_adapter.mjs +0 -2025
- package/api/theme-edit/_catalog.d.mts +0 -172
- package/api/theme-edit/_catalog.mjs +0 -806
- package/api/theme-edit/_check.d.mts +0 -391
- package/api/theme-edit/_check.mjs +0 -9370
- package/api/theme-edit/_color.d.mts +0 -135
- package/api/theme-edit/_color.mjs +0 -480
- package/api/theme-edit/_compiler.d.mts +0 -77
- package/api/theme-edit/_compiler.mjs +0 -1053
- package/api/theme-edit/_context.d.mts +0 -399
- package/api/theme-edit/_context.mjs +0 -1778
- package/api/theme-edit/_css.d.mts +0 -169
- package/api/theme-edit/_css.mjs +0 -1167
- package/api/theme-edit/_edit.d.mts +0 -167
- package/api/theme-edit/_edit.mjs +0 -11220
- package/api/theme-edit/_how-commands.d.mts +0 -315
- package/api/theme-edit/_how-commands.mjs +0 -1664
- package/api/theme-edit/_how-question.d.mts +0 -341
- package/api/theme-edit/_how-question.mjs +0 -33339
- package/api/theme-edit/_how-sides.d.mts +0 -22
- package/api/theme-edit/_how-sides.mjs +0 -173
- package/api/theme-edit/_how-steps.d.mts +0 -42
- package/api/theme-edit/_how-steps.mjs +0 -208
- package/api/theme-edit/_how-values.d.mts +0 -29
- package/api/theme-edit/_how-values.mjs +0 -111
- package/api/theme-edit/_how-words.d.mts +0 -15
- package/api/theme-edit/_how-words.mjs +0 -239
- package/api/theme-edit/_how.d.mts +0 -55
- package/api/theme-edit/_how.mjs +0 -2388
- package/api/theme-edit/_importers.d.mts +0 -38
- package/api/theme-edit/_importers.mjs +0 -188
- package/api/theme-edit/_marks.d.mts +0 -39
- package/api/theme-edit/_marks.mjs +0 -67
- package/api/theme-edit/_missed.d.mts +0 -56
- package/api/theme-edit/_missed.mjs +0 -1128
- package/api/theme-edit/_name-rule.d.mts +0 -11
- package/api/theme-edit/_name-rule.mjs +0 -12
- package/api/theme-edit/_normal.d.mts +0 -365
- package/api/theme-edit/_normal.mjs +0 -1978
- package/api/theme-edit/_overview.d.mts +0 -9
- package/api/theme-edit/_overview.mjs +0 -293
- package/api/theme-edit/_palette.d.mts +0 -616
- package/api/theme-edit/_palette.mjs +0 -2776
- package/api/theme-edit/_part-pieces.d.mts +0 -54
- package/api/theme-edit/_part-pieces.mjs +0 -179
- package/api/theme-edit/_part-words.d.mts +0 -39
- package/api/theme-edit/_part-words.mjs +0 -242
- package/api/theme-edit/_parts.d.mts +0 -402
- package/api/theme-edit/_parts.mjs +0 -2322
- package/api/theme-edit/_picture-traits.d.mts +0 -259
- package/api/theme-edit/_picture-traits.mjs +0 -1030
- package/api/theme-edit/_png.d.mts +0 -94
- package/api/theme-edit/_png.mjs +0 -479
- package/api/theme-edit/_preview-app.d.mts +0 -172
- package/api/theme-edit/_preview-app.mjs +0 -6430
- package/api/theme-edit/_preview.d.mts +0 -484
- package/api/theme-edit/_preview.mjs +0 -2775
- package/api/theme-edit/_project.d.mts +0 -207
- package/api/theme-edit/_project.mjs +0 -643
- package/api/theme-edit/_resolved.d.mts +0 -46
- package/api/theme-edit/_resolved.mjs +0 -800
- package/api/theme-edit/_set-line.d.mts +0 -29
- package/api/theme-edit/_set-line.mjs +0 -100
- package/api/theme-edit/_settings.d.mts +0 -2426
- package/api/theme-edit/_settings.mjs +0 -18449
- package/api/theme-edit/_tables.d.mts +0 -227
- package/api/theme-edit/_tables.mjs +0 -1128
- package/api/theme-edit/_text-looks.d.mts +0 -78
- package/api/theme-edit/_text-looks.mjs +0 -376
- package/api/theme-edit/_vet.d.mts +0 -50
- package/api/theme-edit/_vet.mjs +0 -166
- package/api/theme-edit/how/how.d.mts +0 -17
- package/api/theme-edit/how/how.mjs +0 -28
- package/api/theme-edit/new/new.d.mts +0 -11
- package/api/theme-edit/new/new.mjs +0 -22
- package/api/theme-edit/preview-add/preview-add.d.mts +0 -14
- package/api/theme-edit/preview-add/preview-add.mjs +0 -25
- package/api/theme-edit/preview-app/preview-app.d.mts +0 -13
- package/api/theme-edit/preview-app/preview-app.mjs +0 -24
- package/api/theme-edit/preview-list/preview-list.d.mts +0 -10
- package/api/theme-edit/preview-list/preview-list.mjs +0 -21
- package/api/theme-edit/preview-remove/preview-remove.d.mts +0 -12
- package/api/theme-edit/preview-remove/preview-remove.mjs +0 -23
- package/api/theme-edit/set/set.d.mts +0 -13
- package/api/theme-edit/set/set.mjs +0 -24
- package/api/theme-edit/show/show.d.mts +0 -13
- package/api/theme-edit/show/show.mjs +0 -24
- package/api/theme-edit/theme-edit.d.mts +0 -12
- package/api/theme-edit/theme-edit.mjs +0 -36
- package/api/theme-edit/theme-edit.type.d.mts +0 -730
- package/api/theme-edit/theme-edit.type.mjs +0 -342
- package/api/theme-edit/themeEditHow.doc.d.mts +0 -6
- package/api/theme-edit/themeEditHow.doc.mjs +0 -105
- package/api/theme-edit/themeEditNew.doc.d.mts +0 -5
- package/api/theme-edit/themeEditNew.doc.mjs +0 -112
- package/api/theme-edit/themeEditPreviewAdd.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +0 -121
- package/api/theme-edit/themeEditPreviewApp.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +0 -87
- package/api/theme-edit/themeEditPreviewList.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewList.doc.mjs +0 -62
- package/api/theme-edit/themeEditPreviewRemove.doc.d.mts +0 -6
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +0 -96
- package/api/theme-edit/themeEditSet.doc.d.mts +0 -6
- package/api/theme-edit/themeEditSet.doc.mjs +0 -175
- package/api/theme-edit/themeEditShow.doc.d.mts +0 -6
- package/api/theme-edit/themeEditShow.doc.mjs +0 -118
- package/api/theme-edit/themeEditUndo.doc.d.mts +0 -6
- package/api/theme-edit/themeEditUndo.doc.mjs +0 -133
- package/api/theme-edit/undo/undo.d.mts +0 -13
- package/api/theme-edit/undo/undo.mjs +0 -24
- package/assets/preview-app/README.md +0 -6
- package/assets/preview-app/css.d.ts +0 -5
- package/assets/preview-app/gitignore +0 -4
- package/assets/preview-app/next.config.mjs +0 -12
- package/assets/preview-app/package.json +0 -24
- package/assets/preview-app/src/app/globals.css +0 -6
- package/assets/preview-app/src/app/layout.tsx +0 -21
- package/assets/preview-app/src/app/page.tsx +0 -94
- package/assets/preview-app/src/app/providers.tsx +0 -16
- package/assets/preview-app/tsconfig.json +0 -27
- package/clients/cli/commands/experimental/theme.mjs +0 -2990
- package/clients/cli/commands/experimental-theme-add.doc.mjs +0 -80
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +0 -98
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +0 -196
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +0 -174
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +0 -139
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +0 -77
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +0 -105
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +0 -49
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +0 -72
- package/clients/cli/commands/experimental-theme-list.doc.mjs +0 -49
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +0 -88
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +0 -61
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +0 -48
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +0 -59
- package/clients/cli/commands/experimental-theme-preview.doc.mjs +0 -41
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +0 -57
- package/clients/cli/commands/experimental-theme-targets.doc.mjs +0 -62
- package/clients/cli/commands/experimental-theme-template.doc.mjs +0 -63
- package/clients/cli/commands/experimental-theme-use.doc.mjs +0 -57
- package/clients/cli/commands/experimental-theme.doc.mjs +0 -60
- package/foundation/fonts/fontsource-families.generated.d.mts +0 -5
- package/foundation/fonts/fontsource-families.generated.mjs +0 -2110
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
-
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A box color shorthand's colors as typed, one per side (`#ddd #ddd
|
|
6
|
-
* transparent`), each with the sides it colors; null for a property that
|
|
7
|
-
* takes one color, or for one value. `tooMany` is set when the value has
|
|
8
|
-
* more than the property takes.
|
|
9
|
-
* @param {string} prop the property, as CSS names it
|
|
10
|
-
* @param {string} value
|
|
11
|
-
* @returns {{colors: Array<{color: string, sides: string[]}>, max: number, tooMany: boolean} | null}
|
|
12
|
-
*/
|
|
13
|
-
export function colorSides(prop: string, value: string): {
|
|
14
|
-
colors: Array<{
|
|
15
|
-
color: string;
|
|
16
|
-
sides: string[];
|
|
17
|
-
}>;
|
|
18
|
-
max: number;
|
|
19
|
-
tooMany: boolean;
|
|
20
|
-
} | null;
|
|
21
|
-
/**
|
|
22
|
-
* The opacity a slash after a color gives it, as Tailwind writes it
|
|
23
|
-
* (`black/5` is black at 5%; `white/[.08]` and `white/[8%]` at 8%), read at
|
|
24
|
-
* `at` (the slash), with how many characters it takes; null when no
|
|
25
|
-
* opacity is written there. Only the share of the color is read: 0 to 100,
|
|
26
|
-
* or 0 to 1 in brackets.
|
|
27
|
-
* @param {string} text
|
|
28
|
-
* @param {number} at
|
|
29
|
-
* @returns {{alpha: number, length: number} | null}
|
|
30
|
-
*/
|
|
31
|
-
export function opacitySuffixAt(text: string, at: number): {
|
|
32
|
-
alpha: number;
|
|
33
|
-
length: number;
|
|
34
|
-
} | null;
|
|
35
|
-
/**
|
|
36
|
-
* A color at a share of its opacity, as CSS writes it: `rgb(r g b / a)`,
|
|
37
|
-
* its own alpha included (a half-clear color at 50% is a quarter); null
|
|
38
|
-
* for what is not a fixed color.
|
|
39
|
-
* @param {string} color
|
|
40
|
-
* @param {number} alpha 0 to 1
|
|
41
|
-
* @returns {string | null}
|
|
42
|
-
*/
|
|
43
|
-
export function colorAtOpacity(color: string, alpha: number): string | null;
|
|
44
|
-
/**
|
|
45
|
-
* Tailwind's color/opacity shorthand written in a value (`0 0 0 1px
|
|
46
|
-
* black/5`, `#000/10`, `white/[.08]`): each color written out (a hex or a
|
|
47
|
-
* CSS color name) with an opacity after its slash. `color` is what CSS
|
|
48
|
-
* writes for it; null for a color word this reader cannot read as one
|
|
49
|
-
* (Tailwind's own stops, `blue-500/20`), which the caller names.
|
|
50
|
-
* @param {string} value
|
|
51
|
-
* @returns {Array<{index: number, typed: string, color: string | null}>}
|
|
52
|
-
*/
|
|
53
|
-
export function colorOpacitiesIn(value: string): Array<{
|
|
54
|
-
index: number;
|
|
55
|
-
typed: string;
|
|
56
|
-
color: string | null;
|
|
57
|
-
}>;
|
|
58
|
-
/**
|
|
59
|
-
* A value with each color/opacity shorthand in it written as CSS writes it
|
|
60
|
-
* (`0 0 0 1px black/5` is `0 0 0 1px rgb(0 0 0 / 0.05)`), and the ones this
|
|
61
|
-
* reader cannot read (Tailwind's own stops); null when the value has none.
|
|
62
|
-
* @param {string} value
|
|
63
|
-
* @returns {{css: string, found: ReturnType<typeof colorOpacitiesIn>, unread: ReturnType<typeof colorOpacitiesIn>} | null}
|
|
64
|
-
*/
|
|
65
|
-
export function colorOpacitiesAsCss(value: string): {
|
|
66
|
-
css: string;
|
|
67
|
-
found: ReturnType<typeof colorOpacitiesIn>;
|
|
68
|
-
unread: ReturnType<typeof colorOpacitiesIn>;
|
|
69
|
-
} | null;
|
|
70
|
-
/** @typedef {[number, number, number]} Rgb */
|
|
71
|
-
/**
|
|
72
|
-
* A comma (legacy) rgb() or hsl() that CSS does not take as written, in the
|
|
73
|
-
* space-separated syntax CSS reads the same channels in (`hsl(0, 100, 50)`
|
|
74
|
-
* is `hsl(0 100 50)`); null for any other value.
|
|
75
|
-
* @param {unknown} value
|
|
76
|
-
* @returns {string | null}
|
|
77
|
-
*/
|
|
78
|
-
export function colorAsCssReads(value: unknown): string | null;
|
|
79
|
-
/**
|
|
80
|
-
* Why a value cannot seed a color dial, or null when it is one fixed,
|
|
81
|
-
* opaque color: `opaque` is the color without its alpha, for a suggestion.
|
|
82
|
-
* @param {unknown} value
|
|
83
|
-
* @returns {{kind: 'system' | 'space' | 'malformed' | 'unfixed' | 'translucent' | 'unknown', message: string, opaque?: string} | null}
|
|
84
|
-
*/
|
|
85
|
-
export function colorProblem(value: unknown): {
|
|
86
|
-
kind: "system" | "space" | "malformed" | "unfixed" | "translucent" | "unknown";
|
|
87
|
-
message: string;
|
|
88
|
-
opaque?: string;
|
|
89
|
-
} | null;
|
|
90
|
-
/**
|
|
91
|
-
* A contrast ratio as a result says it: cut down to two decimals, never
|
|
92
|
-
* rounded up, so a ratio just under what a check needs (4.497) never reads
|
|
93
|
-
* as meeting it ("4.5:1, needs 4.5:1").
|
|
94
|
-
* @param {number} r
|
|
95
|
-
* @returns {string}
|
|
96
|
-
*/
|
|
97
|
-
export function ratioWords(r: number): string;
|
|
98
|
-
/**
|
|
99
|
-
* The WCAG contrast ratio of two colors.
|
|
100
|
-
* @param {number[]} a
|
|
101
|
-
* @param {number[]} b
|
|
102
|
-
*/
|
|
103
|
-
export function ratio(a: number[], b: number[]): number;
|
|
104
|
-
/**
|
|
105
|
-
* A value with each CSS escape (`Gill\ Sans`, `\5FAE`) as one plain
|
|
106
|
-
* character, as CSS reads it: an escape is part of a name, never a
|
|
107
|
-
* boundary. A backslash that escapes nothing (at the end, or before a line
|
|
108
|
-
* break) could join the next declaration, so it stays.
|
|
109
|
-
* @param {string} v
|
|
110
|
-
*/
|
|
111
|
-
export function withoutCssEscapes(v: string): string;
|
|
112
|
-
/**
|
|
113
|
-
* Whether a value can sit in a CSS declaration as it is: no `<>`, control
|
|
114
|
-
* character, comment or `!important` anywhere; outside a quoted string or a
|
|
115
|
-
* `url(data:…)`, no `;{}`; brackets and quotes closed; no old browser hack's
|
|
116
|
-
* escape at its end (`8px\9`: a browser reads it as part of the last word
|
|
117
|
-
* and drops the value). So `content: "a;b"` and a base64 data URL are
|
|
118
|
-
* values, and nothing can end the declaration.
|
|
119
|
-
* @param {string} v
|
|
120
|
-
*/
|
|
121
|
-
export function isSafeValue(v: string): boolean;
|
|
122
|
-
export { splitTop };
|
|
123
|
-
/**
|
|
124
|
-
* A value that is one var() of a custom property and nothing else, with
|
|
125
|
-
* any spaces inside its brackets as CSS reads them (`var( --x )`).
|
|
126
|
-
*/
|
|
127
|
-
export const LONE_VAR: RegExp;
|
|
128
|
-
export function isColorValue(v: unknown): boolean;
|
|
129
|
-
export function isSize(v: unknown, name?: string): boolean;
|
|
130
|
-
export function isNumber(v: unknown, name?: string): boolean;
|
|
131
|
-
/** What a value isSafeValue refuses holds, for the refusal's words. */
|
|
132
|
-
export const UNSAFE_VALUE: "it has a ; { } < > or a newline, a comment, !important, an unclosed bracket or quote, or an old browser hack (\\9, \\0) at its end";
|
|
133
|
-
export type Rgb = [number, number, number];
|
|
134
|
-
import { splitTop } from './_css.mjs';
|
|
135
|
-
export { COLOR_IN_VALUE, COLOR_NAMES, alphaOf, colorsIn, compositeOver, hex, isClipped, mixSide, namedColorHex, oklabDistance, oklabOf, parseColor } from "../../foundation/color/css-color.mjs";
|
|
@@ -1,480 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @file Color checks for `astryx experimental theme`: say why a value cannot
|
|
5
|
-
* seed a color, the contrast ratio (on the palette code's luminance), and
|
|
6
|
-
* value type checks. Reading a CSS color to RGB is the shared color reader's
|
|
7
|
-
* (foundation/color/css-color.mjs). The theme's colors themselves come from
|
|
8
|
-
* the palette generator.
|
|
9
|
-
* @position api/theme-edit — pure helpers
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
MATH_FUNCTION,
|
|
14
|
-
cssNumber,
|
|
15
|
-
keywordsOf,
|
|
16
|
-
matchType,
|
|
17
|
-
splitTop,
|
|
18
|
-
} from './_css.mjs';
|
|
19
|
-
import {
|
|
20
|
-
COLOR_SPACES,
|
|
21
|
-
FIXED,
|
|
22
|
-
FUNCTIONS,
|
|
23
|
-
KEYWORDS,
|
|
24
|
-
MIX_SPACES,
|
|
25
|
-
NAMED,
|
|
26
|
-
SYSTEM,
|
|
27
|
-
alphaOf,
|
|
28
|
-
hex,
|
|
29
|
-
mixColor,
|
|
30
|
-
mixSide,
|
|
31
|
-
namedColorHex,
|
|
32
|
-
parseColor,
|
|
33
|
-
readColor,
|
|
34
|
-
} from '../../foundation/color/css-color.mjs';
|
|
35
|
-
import {contrastRatio, ratioDown} from '../theme/palette/generate/color.mjs';
|
|
36
|
-
|
|
37
|
-
export {splitTop};
|
|
38
|
-
export {
|
|
39
|
-
COLOR_IN_VALUE,
|
|
40
|
-
COLOR_NAMES,
|
|
41
|
-
alphaOf,
|
|
42
|
-
colorsIn,
|
|
43
|
-
compositeOver,
|
|
44
|
-
hex,
|
|
45
|
-
isClipped,
|
|
46
|
-
mixSide,
|
|
47
|
-
namedColorHex,
|
|
48
|
-
oklabDistance,
|
|
49
|
-
oklabOf,
|
|
50
|
-
parseColor,
|
|
51
|
-
} from '../../foundation/color/css-color.mjs';
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* The box color shorthands, which take one color per side, and how many
|
|
55
|
-
* sides each names (`border-color: top right bottom left`).
|
|
56
|
-
* @type {Record<string, number>}
|
|
57
|
-
*/
|
|
58
|
-
const COLOR_SIDE_COUNT = {
|
|
59
|
-
'border-color': 4,
|
|
60
|
-
'border-block-color': 2,
|
|
61
|
-
'border-inline-color': 2,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* The sides each count of colors names, as CSS gives them out.
|
|
66
|
-
* @type {Record<number, string[][]>}
|
|
67
|
-
*/
|
|
68
|
-
const SIDE_NAMES = {
|
|
69
|
-
4: [['top'], ['right'], ['bottom'], ['left']],
|
|
70
|
-
3: [['top'], ['right', 'left'], ['bottom']],
|
|
71
|
-
2: [
|
|
72
|
-
['top', 'bottom'],
|
|
73
|
-
['right', 'left'],
|
|
74
|
-
],
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* A box color shorthand's colors as typed, one per side (`#ddd #ddd
|
|
79
|
-
* transparent`), each with the sides it colors; null for a property that
|
|
80
|
-
* takes one color, or for one value. `tooMany` is set when the value has
|
|
81
|
-
* more than the property takes.
|
|
82
|
-
* @param {string} prop the property, as CSS names it
|
|
83
|
-
* @param {string} value
|
|
84
|
-
* @returns {{colors: Array<{color: string, sides: string[]}>, max: number, tooMany: boolean} | null}
|
|
85
|
-
*/
|
|
86
|
-
export function colorSides(prop, value) {
|
|
87
|
-
const max = COLOR_SIDE_COUNT[prop];
|
|
88
|
-
if (!max) return null;
|
|
89
|
-
const parts = splitTop(String(value).trim(), ' ')
|
|
90
|
-
.map(x => x.trim())
|
|
91
|
-
.filter(Boolean);
|
|
92
|
-
if (parts.length < 2) return null;
|
|
93
|
-
const logical = max === 2 && prop !== 'border-color';
|
|
94
|
-
/** @type {string[][]} */
|
|
95
|
-
const names = logical
|
|
96
|
-
? [['start'], ['end']]
|
|
97
|
-
: (SIDE_NAMES[parts.length] ?? []);
|
|
98
|
-
return {
|
|
99
|
-
colors: parts.map((color, i) => ({color, sides: names[i] ?? []})),
|
|
100
|
-
max,
|
|
101
|
-
tooMany: parts.length > max,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* The opacity a slash after a color gives it, as Tailwind writes it
|
|
107
|
-
* (`black/5` is black at 5%; `white/[.08]` and `white/[8%]` at 8%), read at
|
|
108
|
-
* `at` (the slash), with how many characters it takes; null when no
|
|
109
|
-
* opacity is written there. Only the share of the color is read: 0 to 100,
|
|
110
|
-
* or 0 to 1 in brackets.
|
|
111
|
-
* @param {string} text
|
|
112
|
-
* @param {number} at
|
|
113
|
-
* @returns {{alpha: number, length: number} | null}
|
|
114
|
-
*/
|
|
115
|
-
export function opacitySuffixAt(text, at) {
|
|
116
|
-
const m =
|
|
117
|
-
/^\/(?:(\d{1,3}(?:\.\d+)?)|\[\s*(\d*\.?\d+)\s*(%?)\s*\])(?![\w.%\]])/.exec(
|
|
118
|
-
text.slice(at),
|
|
119
|
-
);
|
|
120
|
-
if (!m) return null;
|
|
121
|
-
const n = m[1] != null ? Number(m[1]) / 100 : Number(m[2]) / (m[3] ? 100 : 1);
|
|
122
|
-
if (!Number.isFinite(n) || n < 0 || n > 1) return null;
|
|
123
|
-
return {alpha: n, length: m[0].length};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* A color at a share of its opacity, as CSS writes it: `rgb(r g b / a)`,
|
|
128
|
-
* its own alpha included (a half-clear color at 50% is a quarter); null
|
|
129
|
-
* for what is not a fixed color.
|
|
130
|
-
* @param {string} color
|
|
131
|
-
* @param {number} alpha 0 to 1
|
|
132
|
-
* @returns {string | null}
|
|
133
|
-
*/
|
|
134
|
-
export function colorAtOpacity(color, alpha) {
|
|
135
|
-
const rgb = parseColor(color);
|
|
136
|
-
if (!rgb) return null;
|
|
137
|
-
const a = Math.round(alphaOf(color) * alpha * 1000) / 1000;
|
|
138
|
-
return `rgb(${rgb.map(c => Math.round(c)).join(' ')} / ${a})`;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Tailwind's color/opacity shorthand written in a value (`0 0 0 1px
|
|
143
|
-
* black/5`, `#000/10`, `white/[.08]`): each color written out (a hex or a
|
|
144
|
-
* CSS color name) with an opacity after its slash. `color` is what CSS
|
|
145
|
-
* writes for it; null for a color word this reader cannot read as one
|
|
146
|
-
* (Tailwind's own stops, `blue-500/20`), which the caller names.
|
|
147
|
-
* @param {string} value
|
|
148
|
-
* @returns {Array<{index: number, typed: string, color: string | null}>}
|
|
149
|
-
*/
|
|
150
|
-
export function colorOpacitiesIn(value) {
|
|
151
|
-
const text = String(value ?? '');
|
|
152
|
-
/** @type {Array<{index: number, typed: string, color: string | null}>} */
|
|
153
|
-
const out = [];
|
|
154
|
-
// (A url() holds a path, `url(/img/white/24.png)`, never a color; so
|
|
155
|
-
// does a quoted string, an image-set() path or a bare quoted path,
|
|
156
|
-
// `"/img/red/50/a.png"`.)
|
|
157
|
-
const urls = [
|
|
158
|
-
...text.matchAll(/\burl\(\s*(?:"[^"]*"|'[^']*'|[^)]*)\)|"[^"]*"|'[^']*'/gi),
|
|
159
|
-
].map(u => [u.index ?? 0, (u.index ?? 0) + u[0].length]);
|
|
160
|
-
for (const m of text.matchAll(
|
|
161
|
-
/(?<![\w#.])(#[0-9a-f]{3,8}|[a-z]+(?:-\d{2,3})?)(?=\/)/gi,
|
|
162
|
-
)) {
|
|
163
|
-
if (urls.some(([a, b]) => (m.index ?? 0) >= a && (m.index ?? 0) < b))
|
|
164
|
-
continue;
|
|
165
|
-
const at = (m.index ?? 0) + m[0].length;
|
|
166
|
-
const op = opacitySuffixAt(text, at);
|
|
167
|
-
if (!op) continue;
|
|
168
|
-
const word = m[1].toLowerCase();
|
|
169
|
-
const stop = /-\d{2,3}$/.test(word);
|
|
170
|
-
const base = word.startsWith('#')
|
|
171
|
-
? parseColor(word)
|
|
172
|
-
? m[1]
|
|
173
|
-
: null
|
|
174
|
-
: namedColorHex(word);
|
|
175
|
-
if (!base && !stop) continue;
|
|
176
|
-
out.push({
|
|
177
|
-
index: m.index ?? 0,
|
|
178
|
-
typed: text.slice(m.index ?? 0, at + op.length),
|
|
179
|
-
color: base ? colorAtOpacity(base, op.alpha) : null,
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
return out;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* A value with each color/opacity shorthand in it written as CSS writes it
|
|
187
|
-
* (`0 0 0 1px black/5` is `0 0 0 1px rgb(0 0 0 / 0.05)`), and the ones this
|
|
188
|
-
* reader cannot read (Tailwind's own stops); null when the value has none.
|
|
189
|
-
* @param {string} value
|
|
190
|
-
* @returns {{css: string, found: ReturnType<typeof colorOpacitiesIn>, unread: ReturnType<typeof colorOpacitiesIn>} | null}
|
|
191
|
-
*/
|
|
192
|
-
export function colorOpacitiesAsCss(value) {
|
|
193
|
-
const found = colorOpacitiesIn(value);
|
|
194
|
-
if (!found.length) return null;
|
|
195
|
-
const css = found.reduceRight(
|
|
196
|
-
(v, x) =>
|
|
197
|
-
x.color == null
|
|
198
|
-
? v
|
|
199
|
-
: v.slice(0, x.index) + x.color + v.slice(x.index + x.typed.length),
|
|
200
|
-
String(value),
|
|
201
|
-
);
|
|
202
|
-
return {css, found, unread: found.filter(x => x.color == null)};
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/** @typedef {[number, number, number]} Rgb */
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* A comma (legacy) rgb() or hsl() that CSS does not take as written, in the
|
|
209
|
-
* space-separated syntax CSS reads the same channels in (`hsl(0, 100, 50)`
|
|
210
|
-
* is `hsl(0 100 50)`); null for any other value.
|
|
211
|
-
* @param {unknown} value
|
|
212
|
-
* @returns {string | null}
|
|
213
|
-
*/
|
|
214
|
-
export function colorAsCssReads(value) {
|
|
215
|
-
const s = String(value ?? '').trim();
|
|
216
|
-
const fn = /^(rgba?|hsla?)\((.*)\)$/i.exec(s);
|
|
217
|
-
if (!fn || !fn[2].includes(',') || readColor(s)) return null;
|
|
218
|
-
const parts = fn[2].split(',').map(x => x.trim());
|
|
219
|
-
if (parts.length !== 3 && parts.length !== 4) return null;
|
|
220
|
-
const name = fn[1].toLowerCase().replace(/a$/, '');
|
|
221
|
-
const modern = `${name}(${parts.slice(0, 3).join(' ')}${parts[3] ? ` / ${parts[3]}` : ''})`;
|
|
222
|
-
return readColor(modern) ? modern : null;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Why a value cannot seed a color dial, or null when it is one fixed,
|
|
227
|
-
* opaque color: `opaque` is the color without its alpha, for a suggestion.
|
|
228
|
-
* @param {unknown} value
|
|
229
|
-
* @returns {{kind: 'system' | 'space' | 'malformed' | 'unfixed' | 'translucent' | 'unknown', message: string, opaque?: string} | null}
|
|
230
|
-
*/
|
|
231
|
-
export function colorProblem(value) {
|
|
232
|
-
const s = String(value ?? '').trim();
|
|
233
|
-
const read = readColor(s);
|
|
234
|
-
if (read && read.alpha >= 1) return null;
|
|
235
|
-
if (read)
|
|
236
|
-
return {
|
|
237
|
-
kind: 'translucent',
|
|
238
|
-
message: `is ${Math.round(read.alpha * 1000) / 1000 >= 1 ? 'not fully opaque' : `see-through (opacity ${Math.round(read.alpha * 1000) / 1000})`}, and a color needs to be opaque to generate shades from`,
|
|
239
|
-
opaque: hex(read.rgb),
|
|
240
|
-
};
|
|
241
|
-
const lower = s.toLowerCase();
|
|
242
|
-
if (SYSTEM.includes(lower))
|
|
243
|
-
return {
|
|
244
|
-
kind: 'system',
|
|
245
|
-
message:
|
|
246
|
-
"is a system color: it follows the user's device, so no shades can be generated from it. Give a fixed color",
|
|
247
|
-
};
|
|
248
|
-
const fn = /^([a-z-]+)\((.*)\)$/i.exec(s);
|
|
249
|
-
if (fn && fn[1].toLowerCase() === 'color') {
|
|
250
|
-
const space = /^\s*([a-z0-9-]+)\s/i.exec(fn[2])?.[1].toLowerCase();
|
|
251
|
-
if (
|
|
252
|
-
space &&
|
|
253
|
-
!COLOR_SPACES.includes(space) &&
|
|
254
|
-
!/var\(|calc\(|\bfrom\b/i.test(fn[2])
|
|
255
|
-
)
|
|
256
|
-
return {
|
|
257
|
-
kind: 'space',
|
|
258
|
-
message: `uses the ${space} color space, and color() is read in ${COLOR_SPACES.join(', ')} only`,
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
if (fn && FIXED.test(fn[1]) && !/var\(|calc\(|env\(|\bfrom\b/i.test(fn[2]))
|
|
262
|
-
return {kind: 'malformed', message: 'is not a valid CSS color'};
|
|
263
|
-
// A mix this reader cannot work out (another space, a color with no
|
|
264
|
-
// fixed value) says so, rather than calling the mix unfixed.
|
|
265
|
-
if (
|
|
266
|
-
fn &&
|
|
267
|
-
fn[1].toLowerCase() === 'color-mix' &&
|
|
268
|
-
!/var\(|env\(/i.test(fn[2])
|
|
269
|
-
) {
|
|
270
|
-
// The shares, beside each color (a color's own percentages aside).
|
|
271
|
-
const [space, ...sides] = splitTop(fn[2], ',').map(x => x.trim());
|
|
272
|
-
const parts = sides.map(mixSide);
|
|
273
|
-
if (parts.some(x => x.pct != null && (x.pct < 0 || x.pct > 100)))
|
|
274
|
-
return {
|
|
275
|
-
kind: 'malformed',
|
|
276
|
-
message:
|
|
277
|
-
'has a color-mix() share outside 0% to 100%, which CSS does not take',
|
|
278
|
-
...(() => {
|
|
279
|
-
const near = mixColor(
|
|
280
|
-
[
|
|
281
|
-
space,
|
|
282
|
-
...parts.map(x =>
|
|
283
|
-
x.pct == null
|
|
284
|
-
? x.color
|
|
285
|
-
: `${x.color} ${Math.max(0, Math.min(100, x.pct))}%`,
|
|
286
|
-
),
|
|
287
|
-
].join(', '),
|
|
288
|
-
);
|
|
289
|
-
return near ? {opaque: hex(near.rgb)} : {};
|
|
290
|
-
})(),
|
|
291
|
-
};
|
|
292
|
-
const near = mixColor(fn[2], true);
|
|
293
|
-
return {
|
|
294
|
-
kind: 'unfixed',
|
|
295
|
-
message: `is a color-mix() this editor does not work out (it mixes in ${MIX_SPACES.join(', ')}, from colors with fixed values)${near ? `; mixed in oklab it is about ${hex(near.rgb)}` : ''}: give the mixed color itself`,
|
|
296
|
-
...(near ? {opaque: hex(near.rgb)} : {}),
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
// A relative color that changes its channels is not worked out here.
|
|
300
|
-
const rel =
|
|
301
|
-
fn && /^from\s+(.+?)\s+\S+\s+\S+\s+\S+(\s*\/.*)?$/i.exec(fn[2].trim());
|
|
302
|
-
if (rel && !/var\(|env\(/i.test(fn?.[2] ?? '')) {
|
|
303
|
-
const origin = readColor(rel[1]);
|
|
304
|
-
return {
|
|
305
|
-
kind: 'unfixed',
|
|
306
|
-
message: `is a relative color that changes its channels, which this editor does not work out${origin ? ` (it starts from ${hex(origin.rgb)})` : ''}: give the color itself`,
|
|
307
|
-
...(origin ? {opaque: hex(origin.rgb)} : {}),
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
if (isColorValue(s))
|
|
311
|
-
return {
|
|
312
|
-
kind: 'unfixed',
|
|
313
|
-
message: 'has no fixed color, so no shades can be generated from it',
|
|
314
|
-
};
|
|
315
|
-
return {kind: 'unknown', message: 'is not a CSS color'};
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* A contrast ratio as a result says it: cut down to two decimals, never
|
|
320
|
-
* rounded up, so a ratio just under what a check needs (4.497) never reads
|
|
321
|
-
* as meeting it ("4.5:1, needs 4.5:1").
|
|
322
|
-
* @param {number} r
|
|
323
|
-
* @returns {string}
|
|
324
|
-
*/
|
|
325
|
-
export function ratioWords(r) {
|
|
326
|
-
return ratioDown(r).toFixed(2);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* The WCAG contrast ratio of two colors.
|
|
331
|
-
* @param {number[]} a
|
|
332
|
-
* @param {number[]} b
|
|
333
|
-
*/
|
|
334
|
-
export function ratio(a, b) {
|
|
335
|
-
return contrastRatio(hex(a), hex(b));
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* A value that is one var() of a custom property and nothing else, with
|
|
340
|
-
* any spaces inside its brackets as CSS reads them (`var( --x )`).
|
|
341
|
-
*/
|
|
342
|
-
export const LONE_VAR = /^var\(\s*--[a-z0-9-]+\s*\)$/i;
|
|
343
|
-
|
|
344
|
-
/** A var() of a custom property with a fallback: the fallback, captured. */
|
|
345
|
-
const VAR_FALLBACK = /^var\(\s*--[a-z0-9-]+\s*,\s*(.+)\)$/i;
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Whether a value is one CSS color: a hex, a color function, a named or
|
|
349
|
-
* system color, a color keyword, or a variable. A function with plain
|
|
350
|
-
* numbers must be well formed; one with `var()`, `calc()`, `env()` or a
|
|
351
|
-
* relative color is taken as written.
|
|
352
|
-
* @param {unknown} v
|
|
353
|
-
* @returns {boolean}
|
|
354
|
-
*/
|
|
355
|
-
export const isColorValue = v => {
|
|
356
|
-
const s = String(v).trim();
|
|
357
|
-
const fn = /^([a-z-]+)\((.*)\)$/i.exec(s);
|
|
358
|
-
if (fn && FIXED.test(fn[1]) && !/var\(|calc\(|env\(|\bfrom\b/i.test(fn[2]))
|
|
359
|
-
return (
|
|
360
|
-
readColor(s) != null ||
|
|
361
|
-
(fn[1].toLowerCase() === 'color' &&
|
|
362
|
-
!COLOR_SPACES.includes(
|
|
363
|
-
/^\s*([a-z0-9-]+)\s/i.exec(fn[2])?.[1].toLowerCase() ?? '',
|
|
364
|
-
) &&
|
|
365
|
-
/^\s*[a-z0-9-]+(\s+\S+){3}(\s*\/\s*\S+)?\s*$/i.test(fn[2]))
|
|
366
|
-
);
|
|
367
|
-
return (
|
|
368
|
-
/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(s) ||
|
|
369
|
-
FUNCTIONS.test(s) ||
|
|
370
|
-
LONE_VAR.test(s) ||
|
|
371
|
-
// A variable with a color to fall back to.
|
|
372
|
-
(VAR_FALLBACK.test(s) &&
|
|
373
|
-
isColorValue(/** @type {string} */ (VAR_FALLBACK.exec(s)?.[1]))) ||
|
|
374
|
-
Object.hasOwn(NAMED, s.toLowerCase()) ||
|
|
375
|
-
KEYWORDS.includes(s.toLowerCase()) ||
|
|
376
|
-
SYSTEM.includes(s.toLowerCase())
|
|
377
|
-
);
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Whether a value reads as one CSS size for the token: a length in any CSS
|
|
382
|
-
* unit, 0, a variable, env(), or calc()/min()/max()/clamp() with a length
|
|
383
|
-
* inside; below zero only where the property takes it (an offset).
|
|
384
|
-
* @param {unknown} v
|
|
385
|
-
* @param {string} [name]
|
|
386
|
-
*/
|
|
387
|
-
export const isSize = (v, name = '') => {
|
|
388
|
-
const s = String(v).trim();
|
|
389
|
-
if (s === '0') return true;
|
|
390
|
-
// One length or percentage, read as CSS reads it (+4px, 4e+1px; never
|
|
391
|
-
// 1.px). Only a property that takes a negative length gets one: an
|
|
392
|
-
// offset, a letter spacing, an indent.
|
|
393
|
-
const n = cssNumber(s);
|
|
394
|
-
if (n && n.unit && matchType('length-percentage', s) != null)
|
|
395
|
-
return n.value >= 0 || /offset|tracking|letter-spacing|indent/.test(name);
|
|
396
|
-
if (LONE_VAR.test(s)) return true;
|
|
397
|
-
if (/^env\([a-z-]+(,.*)?\)$/i.test(s)) return true;
|
|
398
|
-
return MATH_FUNCTION.test(s) && matchType('length-percentage', s) != null;
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* Whether a value reads as a CSS number for the token: a weight is 1 to
|
|
403
|
-
* 1000 or a weight keyword; a line height is a number, length or
|
|
404
|
-
* percentage of 0 or more, or `normal`.
|
|
405
|
-
* @param {unknown} v
|
|
406
|
-
* @param {string} [name]
|
|
407
|
-
*/
|
|
408
|
-
export const isNumber = (v, name = '') => {
|
|
409
|
-
const s = String(v).trim();
|
|
410
|
-
if (LONE_VAR.test(s)) return true;
|
|
411
|
-
const n = cssNumber(s);
|
|
412
|
-
// A weight: a font-weight keyword, or a number from 1 to 1000.
|
|
413
|
-
if (/weight/.test(name))
|
|
414
|
-
return (
|
|
415
|
-
keywordsOf('font-weight').includes(s.toLowerCase()) ||
|
|
416
|
-
(n?.unit === '' && n.value >= 1 && n.value <= 1000) ||
|
|
417
|
-
(MATH_FUNCTION.test(s) && matchType('number', s) != null)
|
|
418
|
-
);
|
|
419
|
-
if (/leading|line-height/.test(name))
|
|
420
|
-
return (
|
|
421
|
-
s === 'normal' ||
|
|
422
|
-
(n != null &&
|
|
423
|
-
['', 'px', 'rem', 'em', '%'].includes(n.unit) &&
|
|
424
|
-
n.value >= 0) ||
|
|
425
|
-
(MATH_FUNCTION.test(s) && matchType('length-percentage', s) != null) ||
|
|
426
|
-
(MATH_FUNCTION.test(s) && matchType('number', s) != null)
|
|
427
|
-
);
|
|
428
|
-
return n?.unit === '';
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* A value with each CSS escape (`Gill\ Sans`, `\5FAE`) as one plain
|
|
433
|
-
* character, as CSS reads it: an escape is part of a name, never a
|
|
434
|
-
* boundary. A backslash that escapes nothing (at the end, or before a line
|
|
435
|
-
* break) could join the next declaration, so it stays.
|
|
436
|
-
* @param {string} v
|
|
437
|
-
*/
|
|
438
|
-
export function withoutCssEscapes(v) {
|
|
439
|
-
return v.replace(/\\(?:[0-9a-fA-F]{1,6}[ \t]?|[^\n\r\f0-9a-fA-F])/g, 'x');
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/** What a value isSafeValue refuses holds, for the refusal's words. */
|
|
443
|
-
export const UNSAFE_VALUE =
|
|
444
|
-
'it has a ; { } < > or a newline, a comment, !important, an unclosed bracket or quote, or an old browser hack (\\9, \\0) at its end';
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* Whether a value can sit in a CSS declaration as it is: no `<>`, control
|
|
448
|
-
* character, comment or `!important` anywhere; outside a quoted string or a
|
|
449
|
-
* `url(data:…)`, no `;{}`; brackets and quotes closed; no old browser hack's
|
|
450
|
-
* escape at its end (`8px\9`: a browser reads it as part of the last word
|
|
451
|
-
* and drops the value). So `content: "a;b"` and a base64 data URL are
|
|
452
|
-
* values, and nothing can end the declaration.
|
|
453
|
-
* @param {string} v
|
|
454
|
-
*/
|
|
455
|
-
export function isSafeValue(v) {
|
|
456
|
-
if (/\\[09]\s*$/.test(v)) return false;
|
|
457
|
-
// A shell comment ("# direct"), as a command run without a shell passes
|
|
458
|
-
// it, is a comment too.
|
|
459
|
-
// `</` (a closing tag), control characters, comments and !important are
|
|
460
|
-
// refused anywhere; < and > only outside a quoted string.
|
|
461
|
-
// A tab is white space, as CSS reads it.
|
|
462
|
-
if (
|
|
463
|
-
// eslint-disable-next-line no-control-regex
|
|
464
|
-
/<\/|[\u0000-\u0008\u000a-\u001f\u007f]|\/\*|!important|(^|\s)#(\s|$)/i.test(
|
|
465
|
-
v,
|
|
466
|
-
)
|
|
467
|
-
)
|
|
468
|
-
return false;
|
|
469
|
-
const outside = withoutCssEscapes(v)
|
|
470
|
-
.replace(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g, '""')
|
|
471
|
-
.replace(/url\(data:[^\s"'()\\]*\)/gi, 'url()');
|
|
472
|
-
if (/[;{}\\<>]/.test(outside)) return false;
|
|
473
|
-
let depth = 0;
|
|
474
|
-
for (const c of outside.replace(/""/g, '')) {
|
|
475
|
-
if (c === '"' || c === "'") return false;
|
|
476
|
-
if (c === '(') depth++;
|
|
477
|
-
if (c === ')' && --depth < 0) return false;
|
|
478
|
-
}
|
|
479
|
-
return depth === 0;
|
|
480
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
|
-
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {import('./_project.mjs').ThemeProject} project
|
|
6
|
-
* @param {PartData} parts
|
|
7
|
-
*/
|
|
8
|
-
export function makeCompiler(project: import("./_project.mjs").ThemeProject, parts: PartData): {
|
|
9
|
-
MAP: Record<string, import("./_parts.mjs").PartRecord>;
|
|
10
|
-
typeOf: (tok: string) => string;
|
|
11
|
-
isToken: (tok: string) => boolean;
|
|
12
|
-
propsReading: (tok: string) => string[];
|
|
13
|
-
feeds: (target: string, token: string) => Array<{
|
|
14
|
-
part: string;
|
|
15
|
-
prop: string;
|
|
16
|
-
when: string;
|
|
17
|
-
}>;
|
|
18
|
-
fmtFeeds: (list: ReturnType<(target: string, token: string) => Array<{
|
|
19
|
-
part: string;
|
|
20
|
-
prop: string;
|
|
21
|
-
when: string;
|
|
22
|
-
}>>, target?: string) => string;
|
|
23
|
-
showsCorners: (target: string) => boolean;
|
|
24
|
-
groupOfToken: (t: string) => string | null;
|
|
25
|
-
groupOfProp: (p: string) => string | null;
|
|
26
|
-
partReads: (target: string, group: string | null) => Read[];
|
|
27
|
-
fmtWhen: (w: string[]) => string;
|
|
28
|
-
statusNote: (target: string, tok: string) => string;
|
|
29
|
-
allReads: (target: string) => Set<string>;
|
|
30
|
-
anyReader: (tok: string) => string[];
|
|
31
|
-
checkTokenOn: (theme: string, target: string, token: string, value: string, P: string, when?: string, also?: string) => CheckFailure | null;
|
|
32
|
-
checkTokenGlobal: (token: string, _P: string) => CheckFailure | null;
|
|
33
|
-
variantValues: (target: string) => Record<string, string[]>;
|
|
34
|
-
contrast: (value: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, baseValue: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, modes: string[], { parseColor, ratio, alphaOf, compositeOver, page, drawnByRule, }: {
|
|
35
|
-
parseColor: (v: unknown) => [number, number, number] | null;
|
|
36
|
-
ratio: (a: number[], b: number[]) => number;
|
|
37
|
-
alphaOf: (v: unknown) => number;
|
|
38
|
-
compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number];
|
|
39
|
-
page: (mode: string) => string | null | undefined;
|
|
40
|
-
drawnByRule?: (pair: TextPair, side: "fg" | "bg", mode: string) => boolean;
|
|
41
|
-
}, extra?: TextPair[]) => {
|
|
42
|
-
problems: {
|
|
43
|
-
part: string;
|
|
44
|
-
mode: string;
|
|
45
|
-
ratio: number;
|
|
46
|
-
sample: string;
|
|
47
|
-
fg: string;
|
|
48
|
-
fgToken: string | null;
|
|
49
|
-
textPart: string | null;
|
|
50
|
-
when: string | null;
|
|
51
|
-
bgPart: string | null;
|
|
52
|
-
bg: string;
|
|
53
|
-
ground: [number, number, number];
|
|
54
|
-
over: string | null;
|
|
55
|
-
pair: any;
|
|
56
|
-
}[];
|
|
57
|
-
unchecked: string[];
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
/** Only these token types may differ between light and dark. */
|
|
61
|
-
export const MODAL: Set<string>;
|
|
62
|
-
export function isColorToken(name: string): boolean;
|
|
63
|
-
export type Read = {
|
|
64
|
-
token: string;
|
|
65
|
-
props: string[];
|
|
66
|
-
when: string[];
|
|
67
|
-
};
|
|
68
|
-
export type CheckFailure = {
|
|
69
|
-
message: string;
|
|
70
|
-
run: string[];
|
|
71
|
-
also: string[];
|
|
72
|
-
soft?: boolean;
|
|
73
|
-
held?: string[];
|
|
74
|
-
};
|
|
75
|
-
export type PartData = import("./_parts.mjs").PartData;
|
|
76
|
-
export type TextPair = import("./_parts.mjs").TextPair;
|
|
77
|
-
export type Compiler = ReturnType<typeof makeCompiler>;
|