@astryxdesign/cli 0.7.17 → 0.7.18-canary.g32556bb
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/README.md +1 -1
- package/api/discover/_adapter.d.mts +7 -5
- package/api/discover/_adapter.mjs +12 -11
- package/api/docs/_adapter.d.mts +19 -2
- package/api/docs/_adapter.mjs +66 -5
- package/api/doctor/_adapter.d.mts +11 -62
- package/api/doctor/_adapter.mjs +242 -472
- package/api/doctor/doctor.d.mts +1 -1
- package/api/doctor/doctor.mjs +3 -3
- package/api/doctor/theme-checks.mjs +37 -45
- package/api/error.d.mts +21 -0
- package/api/error.mjs +89 -0
- package/api/hook/list/list.d.mts +1 -1
- package/api/icon/_adapter.d.mts +8 -0
- package/api/icon/_adapter.mjs +17 -0
- package/api/icon/_authoring.mjs +6 -6
- package/api/icon/_default-look.mjs +16 -16
- package/api/icon/add/add.mjs +3 -3
- package/api/icon/exportIconIndex.doc.mjs +2 -2
- package/api/icon/icon.doc.mjs +2 -2
- package/api/icon/icon.type.d.mts +4 -0
- package/api/icon/icon.type.mjs +2 -1
- package/api/icon/search/icon-index.mjs +16 -3
- package/api/icon/search/search.d.mts +15 -5
- package/api/icon/search/search.mjs +74 -16
- package/api/icon/use/use.mjs +4 -4
- package/api/render/_adapter.mjs +233 -40
- package/api/render/render.type.d.mts +1 -1
- package/api/render/render.type.mjs +1 -1
- package/api/search/ORDERING.md +2 -2
- package/api/search/_adapter.mjs +4 -0
- package/api/search/_candidate-score.mjs +32 -8
- package/api/search/_cards.json +1 -1
- package/api/search/_compound.d.mts +0 -1
- package/api/search/_compound.mjs +93 -2
- package/api/search/_icons.d.mts +4 -2
- package/api/search/_icons.mjs +4 -2
- package/api/search/_lexical.mjs +177 -17
- package/api/search/_order.d.mts +3 -1
- package/api/search/_order.mjs +16 -5
- package/api/search/_result.d.mts +9 -0
- package/api/search/_result.mjs +10 -0
- package/api/search/_score.mjs +21 -3
- package/api/swizzle/_moduleGraph.d.mts +8 -0
- package/api/swizzle/_moduleGraph.mjs +61 -3
- package/api/template/copy/copy.mjs +5 -3
- package/api/template/template.type.d.mts +3 -3
- package/api/template/template.type.mjs +3 -3
- package/api/theme/_adapter.mjs +48 -12
- package/api/theme/build/build.d.mts +4 -0
- package/api/theme/build/build.mjs +69 -18
- package/api/theme/build/style-keys.mjs +4 -5
- package/api/theme/build/theme-object.mjs +5 -0
- package/api/theme/palette/generate/color.d.mts +47 -0
- package/api/theme/palette/generate/color.mjs +58 -1
- package/api/theme/palette/generate/derive-look.d.mts +293 -0
- package/api/theme/palette/generate/derive-look.mjs +1362 -0
- package/api/theme/palette/generate/editor-look.d.mts +62 -0
- package/api/theme/palette/generate/editor-look.mjs +550 -0
- package/api/theme/palette/generate/mapping.d.mts +94 -9
- package/api/theme/palette/generate/mapping.mjs +94 -22
- package/api/theme-edit/_adapter.mjs +13 -2
- package/api/theme-edit/_catalog.d.mts +13 -13
- package/api/theme-edit/_catalog.mjs +66 -28
- package/api/theme-edit/_check.d.mts +82 -6
- package/api/theme-edit/_check.mjs +1270 -238
- package/api/theme-edit/_color.d.mts +74 -0
- package/api/theme-edit/_color.mjs +168 -3
- package/api/theme-edit/_compiler.d.mts +3 -5
- package/api/theme-edit/_compiler.mjs +122 -23
- package/api/theme-edit/_context.d.mts +55 -12
- package/api/theme-edit/_context.mjs +114 -60
- package/api/theme-edit/_css.d.mts +11 -0
- package/api/theme-edit/_css.mjs +40 -0
- package/api/theme-edit/_edit.d.mts +15 -2
- package/api/theme-edit/_edit.mjs +1469 -133
- package/api/theme-edit/_how-commands.d.mts +116 -0
- package/api/theme-edit/_how-commands.mjs +227 -115
- package/api/theme-edit/_how-question.d.mts +74 -29
- package/api/theme-edit/_how-question.mjs +8514 -1256
- package/api/theme-edit/_how-sides.d.mts +22 -0
- package/api/theme-edit/_how-sides.mjs +173 -0
- package/api/theme-edit/_how-steps.d.mts +42 -0
- package/api/theme-edit/_how-steps.mjs +208 -0
- package/api/theme-edit/_how-values.d.mts +29 -0
- package/api/theme-edit/_how-values.mjs +111 -0
- package/api/theme-edit/_how-words.d.mts +15 -0
- package/api/theme-edit/_how-words.mjs +239 -0
- package/api/theme-edit/_how.d.mts +1 -1
- package/api/theme-edit/_how.mjs +422 -37
- package/api/theme-edit/_missed.d.mts +2 -1
- package/api/theme-edit/_missed.mjs +125 -13
- package/api/theme-edit/_normal.d.mts +5 -3
- package/api/theme-edit/_normal.mjs +54 -14
- package/api/theme-edit/_palette.d.mts +204 -4
- package/api/theme-edit/_palette.mjs +901 -25
- package/api/theme-edit/_part-pieces.d.mts +54 -0
- package/api/theme-edit/_part-pieces.mjs +179 -0
- package/api/theme-edit/_part-words.mjs +33 -5
- package/api/theme-edit/_parts.d.mts +133 -0
- package/api/theme-edit/_parts.mjs +599 -10
- package/api/theme-edit/_picture-traits.d.mts +259 -0
- package/api/theme-edit/_picture-traits.mjs +1030 -0
- package/api/theme-edit/_preview.d.mts +95 -4
- package/api/theme-edit/_preview.mjs +284 -31
- package/api/theme-edit/_project.d.mts +14 -4
- package/api/theme-edit/_project.mjs +95 -26
- package/api/theme-edit/_resolved.d.mts +46 -0
- package/api/theme-edit/_resolved.mjs +800 -0
- package/api/theme-edit/_set-line.d.mts +29 -0
- package/api/theme-edit/_set-line.mjs +100 -0
- package/api/theme-edit/_settings.d.mts +625 -28
- package/api/theme-edit/_settings.mjs +4867 -888
- package/api/theme-edit/_tables.d.mts +25 -1
- package/api/theme-edit/_tables.mjs +115 -11
- package/api/theme-edit/_text-looks.d.mts +78 -0
- package/api/theme-edit/_text-looks.mjs +376 -0
- package/api/theme-edit/_vet.d.mts +3 -26
- package/api/theme-edit/_vet.mjs +5 -89
- package/api/theme-edit/how/how.d.mts +1 -1
- package/api/theme-edit/how/how.mjs +1 -1
- package/api/theme-edit/show/show.d.mts +4 -3
- package/api/theme-edit/show/show.mjs +3 -2
- package/api/theme-edit/theme-edit.type.d.mts +117 -1
- package/api/theme-edit/theme-edit.type.mjs +46 -3
- package/api/theme-edit/themeEditHow.doc.mjs +3 -3
- package/api/theme-edit/themeEditNew.doc.mjs +4 -0
- package/api/theme-edit/themeEditSet.doc.mjs +6 -2
- package/api/theme-edit/themeEditShow.doc.mjs +22 -3
- package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
- package/assets/component-list.generated.json +1 -1
- package/assets/docs/author-a-theme.doc.mjs +7 -4
- package/assets/docs/icons.doc.mjs +7 -6
- package/assets/docs/theme.doc.dense.mjs +10 -0
- package/assets/docs/theme.doc.mjs +10 -0
- package/assets/docs/theme.doc.zh.mjs +10 -0
- package/assets/docs/tree/export-pages.doc.mjs +1 -1
- package/assets/docs/tree/icon-sets.doc.mjs +1 -1
- package/assets/docs/use-a-theme.doc.mjs +89 -17
- package/assets/docs-routes.generated.json +1 -1
- package/assets/docs.generated.json +2 -2
- package/assets/icons/definitions/article.doc.mjs +9 -0
- package/assets/icons/template-icons.json +5 -0
- package/assets/search-catalog.generated.json +2 -2
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
- package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
- package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
- package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
- package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
- package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
- package/assets/templates/blocks/components/SideNav/SideNavShowcase.tsx +9 -1
- package/assets/templates/blocks/components/SideNavCollapseButton/SideNavCollapseButtonShowcase.doc.mjs +9 -2
- package/assets/templates/blocks/components/SideNavHeading/SideNavHeadingShowcase.doc.mjs +3 -2
- package/assets/templates/blocks/components/SideNavHeading/SideNavHeadingShowcase.tsx +2 -1
- package/assets/templates/blocks/components/SideNavItem/SideNavItemShowcase.doc.mjs +3 -2
- package/assets/templates/blocks/components/SideNavSection/SideNavSectionShowcase.doc.mjs +2 -1
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/ide/page.tsx +5 -10
- package/assets/templates/pages/payment-form/page.tsx +16 -60
- package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
- package/authoring/config/parse.mjs +1 -1
- package/authoring/debug/parse.d.mts +1 -1
- package/authoring/doctypes/_schema.d.mts +13 -13
- package/authoring/doctypes/icon-definition/parse.mjs +2 -2
- package/authoring/doctypes/icon-set/parse.mjs +1 -1
- package/authoring/doctypes/template/parse.mjs +1 -4
- package/authoring/gap-report/parse.d.mts +1 -1
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/ensure-core-built.mjs +17 -10
- package/clients/cli/commands/experimental/icon.mjs +7 -7
- package/clients/cli/commands/experimental/theme.mjs +175 -13
- package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +15 -5
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/hook.mjs +7 -0
- package/clients/cli/commands/template.mjs +1 -1
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/index.mjs +6 -2
- package/clients/cli/lib/hook-format.mjs +41 -1
- package/clients/cli/lib/json-shim.mjs +34 -14
- package/clients/cli/lib/other-cli-words.mjs +7 -0
- package/clients/cli/lib/unknown-command.mjs +345 -46
- package/clients/cli/manifest.generated.json +1 -1
- package/foundation/agent-docs/agent-docs.d.mts +11 -2
- package/foundation/agent-docs/agent-docs.mjs +51 -8
- package/foundation/config/project.d.mts +11 -1
- package/foundation/config/project.mjs +11 -2
- package/foundation/discovery/component-replacement.d.mts +5 -8
- package/foundation/discovery/component-replacement.mjs +12 -14
- package/foundation/discovery/core-augmentation-points.d.mts +35 -0
- package/foundation/discovery/core-augmentation-points.mjs +410 -9
- package/foundation/discovery/core-elements.d.mts +6 -0
- package/foundation/discovery/core-elements.mjs +10 -2
- package/foundation/discovery/core-prop-types.d.mts +5 -0
- package/foundation/discovery/core-prop-types.mjs +10 -3
- package/foundation/discovery/core-props.d.mts +8 -0
- package/foundation/discovery/core-props.mjs +29 -13
- package/foundation/discovery/icon-ranking.d.mts +5 -2
- package/foundation/discovery/icon-ranking.mjs +101 -18
- package/foundation/discovery/icon-set-checks.mjs +1 -1
- package/foundation/discovery/icon-set-writer.mjs +1 -1
- package/foundation/discovery/official-list.d.mts +17 -0
- package/foundation/discovery/official-list.mjs +77 -0
- package/foundation/discovery/template-icon-notes.mjs +3 -3
- package/foundation/discovery/template-icons.mjs +2 -2
- package/foundation/discovery/template-placeholders.mjs +1 -1
- package/foundation/discovery/unknown-core-props.d.mts +130 -0
- package/foundation/discovery/unknown-core-props.mjs +601 -0
- package/foundation/discovery/written-prop-values.d.mts +35 -0
- package/foundation/discovery/written-prop-values.mjs +258 -0
- package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
- package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
- package/foundation/fs/package-name.d.mts +10 -0
- package/foundation/fs/package-name.mjs +37 -0
- package/foundation/fs/project-source-files.d.mts +27 -0
- package/foundation/fs/project-source-files.mjs +115 -0
- package/foundation/fs/project-sources.d.mts +25 -0
- package/foundation/fs/project-sources.mjs +83 -0
- package/foundation/fs/read-record.d.mts +18 -0
- package/foundation/fs/read-record.mjs +36 -2
- package/foundation/integrations/integration-warnings.d.mts +39 -7
- package/foundation/integrations/integration-warnings.mjs +141 -19
- package/foundation/integrations/missing-dependency.d.mts +11 -0
- package/foundation/integrations/missing-dependency.mjs +20 -5
- package/foundation/release/folder-lock.d.mts +5 -2
- package/foundation/release/folder-lock.mjs +9 -3
- package/foundation/release/notices.mjs +2 -8
- package/foundation/render/cut-short.d.mts +8 -2
- package/foundation/render/cut-short.mjs +50 -5
- package/foundation/render/drawn-contrast.d.mts +40 -0
- package/foundation/render/drawn-contrast.mjs +355 -0
- package/foundation/render/file-header.mjs +4 -0
- package/foundation/render/layers.d.mts +2 -1
- package/foundation/render/layers.mjs +22 -1
- package/foundation/render/package-resolve-hooks.d.mts +38 -9
- package/foundation/render/package-resolve-hooks.mjs +124 -32
- package/foundation/render/page-worker.mjs +95 -23
- package/foundation/render/part-boxes.d.mts +27 -0
- package/foundation/render/part-boxes.mjs +45 -0
- package/foundation/render/picture-chrome.mjs +36 -4
- package/foundation/render/picture-playwright.mjs +26 -2
- package/foundation/render/picture-window.d.mts +29 -2
- package/foundation/render/picture-window.mjs +99 -1
- package/foundation/render/render-page.d.mts +39 -6
- package/foundation/render/render-page.mjs +26 -10
- package/foundation/render/ts-paths.mjs +2 -1
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/error-codes.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +9 -5
- package/foundation/suggest/other-command.mjs +25 -1
- package/foundation/text/icon-set-next.d.mts +1 -1
- package/foundation/text/icon-set-next.mjs +2 -2
- package/foundation/text/written-string.d.mts +4 -1
- package/foundation/text/written-string.mjs +4 -1
- package/package.json +8 -7
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
isRecord,
|
|
30
30
|
subpathDeclaration,
|
|
31
31
|
} from '../../foundation/integrations/exports-subpaths.mjs';
|
|
32
|
+
import {reusedWhileUnchangedSync} from '../../foundation/fs/read-record.mjs';
|
|
32
33
|
|
|
33
34
|
/** The extensions an extensionless import may name, in resolution order. */
|
|
34
35
|
const CODE_FILE = /\.[cm]?[jt]sx?$/;
|
|
@@ -376,6 +377,53 @@ function publicSurfaceOf(packageDir, srcRoot, originsOf) {
|
|
|
376
377
|
return {byOrigin, byFile, exportsField};
|
|
377
378
|
}
|
|
378
379
|
|
|
380
|
+
/**
|
|
381
|
+
* Export origins by module, as {@link moduleExportOrigins} memoizes them:
|
|
382
|
+
* value and type reads apart.
|
|
383
|
+
* @typedef {{value: Map<string, any>, type: Map<string, any>}} ExportMemos
|
|
384
|
+
*/
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* The read of each package's public surface, by package and source root,
|
|
388
|
+
* with the export origins that read found. Reading one parses every module
|
|
389
|
+
* the package exports, more than the parsed-module cache keeps, so without
|
|
390
|
+
* this each copy from the same package in one process parses them all again.
|
|
391
|
+
* @type {Map<string, () => {surface: PublicSurface, memos: ExportMemos}>}
|
|
392
|
+
*/
|
|
393
|
+
const surfaceReads = new Map();
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* {@link publicSurfaceOf}, reused while every file and folder it read is
|
|
397
|
+
* unchanged, with the export origins it found. Each read caches export
|
|
398
|
+
* origins for that read only, so a read after a change sees the package as
|
|
399
|
+
* it is then.
|
|
400
|
+
* @param {string} packageDir
|
|
401
|
+
* @param {string} srcRoot
|
|
402
|
+
* @returns {{surface: PublicSurface, memos: ExportMemos}}
|
|
403
|
+
*/
|
|
404
|
+
function keptPublicSurfaceOf(packageDir, srcRoot) {
|
|
405
|
+
const key = `${packageDir}\0${srcRoot}`;
|
|
406
|
+
let read = surfaceReads.get(key);
|
|
407
|
+
if (read == null) {
|
|
408
|
+
read = reusedWhileUnchangedSync(
|
|
409
|
+
() => {
|
|
410
|
+
/** @type {ExportMemos} */
|
|
411
|
+
const memos = {value: new Map(), type: new Map()};
|
|
412
|
+
const surface = publicSurfaceOf(packageDir, srcRoot, (file, kind) =>
|
|
413
|
+
moduleExportOrigins(file, {
|
|
414
|
+
types: kind === 'type',
|
|
415
|
+
memo: memos[kind],
|
|
416
|
+
}),
|
|
417
|
+
);
|
|
418
|
+
return {surface, memos};
|
|
419
|
+
},
|
|
420
|
+
{exact: true},
|
|
421
|
+
);
|
|
422
|
+
surfaceReads.set(key, read);
|
|
423
|
+
}
|
|
424
|
+
return read();
|
|
425
|
+
}
|
|
426
|
+
|
|
379
427
|
/**
|
|
380
428
|
* A specifier that is either fixed (a public subpath) or computed from where
|
|
381
429
|
* two copied files land.
|
|
@@ -421,8 +469,9 @@ export function planCopy({
|
|
|
421
469
|
ownerPackage,
|
|
422
470
|
entries,
|
|
423
471
|
}) {
|
|
424
|
-
//
|
|
425
|
-
// package as it is then.
|
|
472
|
+
// Export reads are cached for this copy only, so a later copy sees the
|
|
473
|
+
// package as it is then. The package surface is kept across copies while
|
|
474
|
+
// what it read is unchanged.
|
|
426
475
|
const exportMemos = {value: new Map(), type: new Map()};
|
|
427
476
|
/** @type {OriginsOf} */
|
|
428
477
|
const originsOf = (file, kind) =>
|
|
@@ -472,7 +521,16 @@ export function planCopy({
|
|
|
472
521
|
* @param {{packageDir: string, srcRoot: string, ownerPackage: string}} pkg
|
|
473
522
|
*/
|
|
474
523
|
function makeContext({packageDir, srcRoot, ownerPackage}) {
|
|
475
|
-
const
|
|
524
|
+
const kept = keptPublicSurfaceOf(packageDir, srcRoot);
|
|
525
|
+
const {surface} = kept;
|
|
526
|
+
// The surface read's origins hold while the surface is kept. Copy them in
|
|
527
|
+
// so this copy reads no exported module again; what this copy adds stays
|
|
528
|
+
// in its own memo, since the surface's change check does not cover it.
|
|
529
|
+
for (const kind of /** @type {const} */ (['value', 'type'])) {
|
|
530
|
+
for (const [file, origins] of kept.memos[kind]) {
|
|
531
|
+
if (!exportMemos[kind].has(file)) exportMemos[kind].set(file, origins);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
476
534
|
/** @param {string} file */
|
|
477
535
|
const inSource = file => file.startsWith(srcRoot + path.sep);
|
|
478
536
|
/**
|
|
@@ -143,9 +143,11 @@ export function templateCopy(
|
|
|
143
143
|
`Invalid template target path "${given}": it is outside the project root (${path.resolve(cwd)}). ` +
|
|
144
144
|
(scratchPath
|
|
145
145
|
? `A scratch copy in the system temp folder takes its absolute path, ${scratchPath}.`
|
|
146
|
-
:
|
|
147
|
-
? `The template is written only inside the
|
|
148
|
-
:
|
|
146
|
+
: there
|
|
147
|
+
? `The template is written only inside the folder the command runs in${scratchFolder ? `, or as a scratch copy in the system temp folder (${scratchFolder})` : ''}. Give a path inside the project, run the command from the destination's folder, or print the source.`
|
|
148
|
+
: scratchFolder
|
|
149
|
+
? `The template is written only inside the project, or as a scratch copy in the system temp folder (${scratchFolder}). Give a path inside one, or print the source.`
|
|
150
|
+
: 'The template is written only inside the project. Give a path inside it, or print the source.'),
|
|
149
151
|
[
|
|
150
152
|
{
|
|
151
153
|
name: `${command} ${quoteCommandArgument(folder)}`,
|
|
@@ -140,7 +140,7 @@ export type TemplateIconsReport = {
|
|
|
140
140
|
*/
|
|
141
141
|
order?: string[] | undefined;
|
|
142
142
|
/**
|
|
143
|
-
* The
|
|
143
|
+
* The variant the project's icons draw, as `experimental.iconVariant` names it; present when it is set.
|
|
144
144
|
*/
|
|
145
145
|
variant?: string | undefined;
|
|
146
146
|
/**
|
|
@@ -148,7 +148,7 @@ export type TemplateIconsReport = {
|
|
|
148
148
|
*/
|
|
149
149
|
reason: string;
|
|
150
150
|
/**
|
|
151
|
-
* Icons rewritten to the first set in the project's list that has them, and the rule that chose each one: a reviewed `exact` or `strong` match, the icon the set's `map` names for the icon
|
|
151
|
+
* Icons rewritten to the first set in the project's list that has them, and the rule that chose each one: a reviewed `exact` or `strong` match, the icon the set's `map` names for the icon meaning the template declares, or `variant`, an icon the template already imports from a set in the list, moved to its export for the project's variant. `target.set` names the set used. `dropped` names the library's sizing props (`size`, `strokeWidth`, `absoluteStrokeWidth`) removed from the icon's elements: an icon set's icons take their size from CSS. `variant` is present when the variant asked for, the project's variant or else the variant the template's icon draws, is one the set's icon does not have: that variant and the set's default variant used instead.
|
|
152
152
|
*/
|
|
153
153
|
mapped: Array<{
|
|
154
154
|
source: {
|
|
@@ -170,7 +170,7 @@ export type TemplateIconsReport = {
|
|
|
170
170
|
};
|
|
171
171
|
}>;
|
|
172
172
|
/**
|
|
173
|
-
* Icons with a meaning that no set in the project's list has. The template's original import is removed. The written code declares a small placeholder component once (`target.local`, `MissingIcon` unless the file already uses that name), and each use of the icon renders it, with a comment that names the meaning. It needs no package. `fixes` are the commands that give it a real icon: map the
|
|
173
|
+
* Icons with a meaning that no set in the project's list has. The template's original import is removed. The written code declares a small placeholder component once (`target.local`, `MissingIcon` unless the file already uses that name), and each use of the icon renders it, with a comment that names the meaning. It needs no package. `fixes` are the commands that give it a real icon: map the meaning in the main set, or add a backup set that has it.
|
|
174
174
|
*/
|
|
175
175
|
placeholder: Array<{
|
|
176
176
|
source: {
|
|
@@ -105,10 +105,10 @@
|
|
|
105
105
|
* @property {'selected' | 'none' | 'ambiguous' | 'missing' | 'withdrawn'} status The project's icon-set state.
|
|
106
106
|
* @property {string | null} set The project's main icon set as `<package>/<set>`, when selected.
|
|
107
107
|
* @property {string[]} [order] The main set and each backup set as `<package>/<set>`, in the order icons are looked up; present when the project lists backups.
|
|
108
|
-
* @property {string} [variant] The
|
|
108
|
+
* @property {string} [variant] The variant the project's icons draw, as `experimental.iconVariant` names it; present when it is set.
|
|
109
109
|
* @property {string} reason Why the project has that set, or none.
|
|
110
|
-
* @property {Array<{source: {module: string, export: string}, target: {set: string, package: string, id: string, module: string, export: string}, by: 'match' | 'definition' | 'variant', dropped?: string[], variant?: {asked: string, used: string | null}}>} mapped Icons rewritten to the first set in the project's list that has them, and the rule that chose each one: a reviewed `exact` or `strong` match, the icon the set's `map` names for the icon
|
|
111
|
-
* @property {Array<{source: {module: string, export: string}, target: {local: string}, definitions: string[], fixes: string[], dropped?: string[], suggestion?: {set: string, id: string, module: string, export: string, confidence: 'likely'}}>} placeholder Icons with a meaning that no set in the project's list has. The template's original import is removed. The written code declares a small placeholder component once (`target.local`, `MissingIcon` unless the file already uses that name), and each use of the icon renders it, with a comment that names the meaning. It needs no package. `fixes` are the commands that give it a real icon: map the
|
|
110
|
+
* @property {Array<{source: {module: string, export: string}, target: {set: string, package: string, id: string, module: string, export: string}, by: 'match' | 'definition' | 'variant', dropped?: string[], variant?: {asked: string, used: string | null}}>} mapped Icons rewritten to the first set in the project's list that has them, and the rule that chose each one: a reviewed `exact` or `strong` match, the icon the set's `map` names for the icon meaning the template declares, or `variant`, an icon the template already imports from a set in the list, moved to its export for the project's variant. `target.set` names the set used. `dropped` names the library's sizing props (`size`, `strokeWidth`, `absoluteStrokeWidth`) removed from the icon's elements: an icon set's icons take their size from CSS. `variant` is present when the variant asked for, the project's variant or else the variant the template's icon draws, is one the set's icon does not have: that variant and the set's default variant used instead.
|
|
111
|
+
* @property {Array<{source: {module: string, export: string}, target: {local: string}, definitions: string[], fixes: string[], dropped?: string[], suggestion?: {set: string, id: string, module: string, export: string, confidence: 'likely'}}>} placeholder Icons with a meaning that no set in the project's list has. The template's original import is removed. The written code declares a small placeholder component once (`target.local`, `MissingIcon` unless the file already uses that name), and each use of the icon renders it, with a comment that names the meaning. It needs no package. `fixes` are the commands that give it a real icon: map the meaning in the main set, or add a backup set that has it.
|
|
112
112
|
* @property {Array<{module: string | null, export: string, reason: string, suggestion?: {set: string, id: string, module: string, export: string, confidence: 'likely'}}>} kept Icons left as the template wrote them, with why, and a `likely` reviewed match as a suggestion when the project set has one. Every declared key is mapped, a placeholder, or kept; `module` is null for a key the template does not import, and `export` is `default` for a default import and `*` for a namespace import.
|
|
113
113
|
* @property {Array<{set: string, license: string, icons: number}>} sets Each set the mapped icons come from, as `<package>/<set>`, with its license and how many icons it gave.
|
|
114
114
|
*/
|
package/api/theme/_adapter.mjs
CHANGED
|
@@ -1383,6 +1383,49 @@ async function withThemeAppLock(cwd, fn) {
|
|
|
1383
1383
|
}
|
|
1384
1384
|
}
|
|
1385
1385
|
|
|
1386
|
+
/**
|
|
1387
|
+
* The ways forward from `theme add` of a slug no theme has: a near name (a
|
|
1388
|
+
* typo) leads, as the command meant; then, unless a package was named, the
|
|
1389
|
+
* doc on where a theme you wrote must live; then the other themes, nearest
|
|
1390
|
+
* first.
|
|
1391
|
+
* @param {string} slug
|
|
1392
|
+
* @param {Array<any>} available
|
|
1393
|
+
* @param {string} cwd
|
|
1394
|
+
* @param {string | undefined} pkg
|
|
1395
|
+
*/
|
|
1396
|
+
function unknownThemeSuggestions(slug, available, cwd, pkg) {
|
|
1397
|
+
const themes = themeCommandsFor('theme add', slug, available, cwd).map(
|
|
1398
|
+
({theme, name}) => ({
|
|
1399
|
+
name,
|
|
1400
|
+
reason:
|
|
1401
|
+
theme.source === 'bundled'
|
|
1402
|
+
? 'bundled theme'
|
|
1403
|
+
: theme.source === 'local'
|
|
1404
|
+
? 'local theme'
|
|
1405
|
+
: `provided by ${theme.package}`,
|
|
1406
|
+
distance: levenshteinDistance(
|
|
1407
|
+
String(slug).toLowerCase(),
|
|
1408
|
+
theme.slug.toLowerCase(),
|
|
1409
|
+
),
|
|
1410
|
+
}),
|
|
1411
|
+
);
|
|
1412
|
+
const near = Math.min(3, Math.max(1, Math.floor(String(slug).length / 3)));
|
|
1413
|
+
const lead = themes.filter(theme => theme.distance <= near);
|
|
1414
|
+
const rest = themes.filter(theme => theme.distance > near);
|
|
1415
|
+
const docs = pkg
|
|
1416
|
+
? []
|
|
1417
|
+
: [
|
|
1418
|
+
{
|
|
1419
|
+
name: formatCliCommand(
|
|
1420
|
+
'docs author-a-theme creating-a-custom-theme',
|
|
1421
|
+
cwd,
|
|
1422
|
+
),
|
|
1423
|
+
reason: `how a theme you wrote lives in ${LOCAL_THEME_ROOT}/ so theme add finds it`,
|
|
1424
|
+
},
|
|
1425
|
+
];
|
|
1426
|
+
return [...lead, ...docs, ...rest].map(({name, reason}) => ({name, reason}));
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1386
1429
|
/**
|
|
1387
1430
|
* Add one available built theme to the app record.
|
|
1388
1431
|
* @param {string} slug
|
|
@@ -1405,19 +1448,12 @@ async function addThemeToAppLocked(slug, cwd, options) {
|
|
|
1405
1448
|
const match = await findTheme(slug, {cwd, package: options.package});
|
|
1406
1449
|
if (!match) {
|
|
1407
1450
|
const available = await listAvailableThemes(cwd);
|
|
1451
|
+
// A theme the person wrote and built elsewhere is no theme `theme add`
|
|
1452
|
+
// finds by name: the message says where one must live to be added, and
|
|
1453
|
+
// how a built theme is used without it.
|
|
1408
1454
|
throw new AstryxError(
|
|
1409
|
-
`Unknown theme "${slug}"${options.package ? ` in package "${options.package}"` : ''}
|
|
1410
|
-
|
|
1411
|
-
({theme, name}) => ({
|
|
1412
|
-
name,
|
|
1413
|
-
reason:
|
|
1414
|
-
theme.source === 'bundled'
|
|
1415
|
-
? 'bundled theme'
|
|
1416
|
-
: theme.source === 'local'
|
|
1417
|
-
? 'local theme'
|
|
1418
|
-
: `provided by ${theme.package}`,
|
|
1419
|
-
}),
|
|
1420
|
-
),
|
|
1455
|
+
`Unknown theme "${slug}"${options.package ? ` in package "${options.package}"` : ''}.${options.package ? '' : ` A theme you wrote is added by name from ${LOCAL_THEME_ROOT}/<slug>/, where a theme source sits beside a same-stem .doc.mjs descriptor; a theme you built elsewhere needs no add: import its built module and stylesheet in your app, as theme build prints with --detail full.`}`,
|
|
1456
|
+
unknownThemeSuggestions(slug, available, cwd, options.package),
|
|
1421
1457
|
ERROR_CODES.ERR_UNKNOWN_THEME,
|
|
1422
1458
|
);
|
|
1423
1459
|
}
|
|
@@ -566,8 +566,12 @@ export type ThemeBuildTrailer = {
|
|
|
566
566
|
* `ownsOutputs` says the caller made the folder the outputs go into and owns
|
|
567
567
|
* every file there named like one (the theme editor's theme folder), so a
|
|
568
568
|
* damaged or half-written output is replaced, never refused.
|
|
569
|
+
* `warnings` takes each warning message of the build, in check mode too,
|
|
570
|
+
* where the receipt carries none (the theme editor, recording a source as
|
|
571
|
+
* built without building it, keeps the warnings that build gives).
|
|
569
572
|
*/
|
|
570
573
|
export type ThemeBuildHandOff = {
|
|
574
|
+
warnings?: string[];
|
|
571
575
|
ownsOutputs?: boolean;
|
|
572
576
|
prepareFamily?: boolean;
|
|
573
577
|
familyLoader?: any;
|
|
@@ -67,6 +67,7 @@ import {createRequire, isBuiltin} from 'node:module';
|
|
|
67
67
|
import {moduleImports} from '../../../foundation/render/embedded-imports.mjs';
|
|
68
68
|
import {projectMapsImport} from '../../../foundation/render/ts-paths.mjs';
|
|
69
69
|
import {STYLESHEET_FILE} from '../../../foundation/fs/stylesheet-file.mjs';
|
|
70
|
+
import {packageNameAt} from '../../../foundation/fs/package-name.mjs';
|
|
70
71
|
import {fileURLToPath, pathToFileURL} from 'node:url';
|
|
71
72
|
import {babelParse as parse} from '../../../foundation/runtime/lazy-dependencies.mjs';
|
|
72
73
|
import {jitiCacheOptions} from '../../../foundation/fs/jiti-cache.mjs';
|
|
@@ -1487,7 +1488,10 @@ function assertThemeSourceFile(filePath, cwd, mode = {}) {
|
|
|
1487
1488
|
* `ownsOutputs` says the caller made the folder the outputs go into and owns
|
|
1488
1489
|
* every file there named like one (the theme editor's theme folder), so a
|
|
1489
1490
|
* damaged or half-written output is replaced, never refused.
|
|
1490
|
-
*
|
|
1491
|
+
* `warnings` takes each warning message of the build, in check mode too,
|
|
1492
|
+
* where the receipt carries none (the theme editor, recording a source as
|
|
1493
|
+
* built without building it, keeps the warnings that build gives).
|
|
1494
|
+
* @typedef {{warnings?: string[], ownsOutputs?: boolean, prepareFamily?: boolean, familyLoader?: any, familyInterception?: any, writeRoot?: string, claimedOutputs?: Map<string, string>, deferredWrites?: Array<Array<{dest: string, content: string}>>, commandWords?: {group: string, build: string}, colorModes?: ['light'] | ['dark'] | null, fontHelp?: FontHelp | null, loadedFonts?: ((family: string) => boolean) | null, install?: string | null}} ThemeBuildHandOff
|
|
1491
1495
|
*/
|
|
1492
1496
|
|
|
1493
1497
|
/**
|
|
@@ -1682,15 +1686,20 @@ function assertOutputsReplaceable(
|
|
|
1682
1686
|
// that source.
|
|
1683
1687
|
const owner = /** @type {{source?: string}} */ (write).source ?? filePath;
|
|
1684
1688
|
if (key === sourceKey) {
|
|
1689
|
+
// The module is named after the theme, so a .js source of that name
|
|
1690
|
+
// (brand.js for theme brand) has its built module at its own path:
|
|
1691
|
+
// only another folder takes every output.
|
|
1692
|
+
const free = freeOutPath(writes);
|
|
1685
1693
|
throw new AstryxError(
|
|
1686
|
-
`The output ${rel(write.dest)} is the theme source itself.
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
+
`The output ${rel(write.dest)} is the theme source itself, so the build does not write it. Build the outputs into another folder with --out${free ? `, such as --out ${rel(free)}` : ''}.`,
|
|
1695
|
+
free && rerun
|
|
1696
|
+
? [
|
|
1697
|
+
{
|
|
1698
|
+
name: rerun(rel(free)),
|
|
1699
|
+
reason: 'a folder where no output of this build exists yet',
|
|
1700
|
+
},
|
|
1701
|
+
]
|
|
1702
|
+
: [],
|
|
1694
1703
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
1695
1704
|
);
|
|
1696
1705
|
}
|
|
@@ -2000,14 +2009,8 @@ function resolveCoreRoot() {
|
|
|
2000
2009
|
function corePackageRoot(file) {
|
|
2001
2010
|
let dir = path.dirname(file);
|
|
2002
2011
|
for (;;) {
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
fs.readFileSync(path.join(dir, 'package.json'), 'utf-8'),
|
|
2006
|
-
);
|
|
2007
|
-
if (pkg?.name === '@astryxdesign/core') return dir;
|
|
2008
|
-
} catch {
|
|
2009
|
-
// No readable package.json here; keep walking up.
|
|
2010
|
-
}
|
|
2012
|
+
if (packageNameAt(path.join(dir, 'package.json')) === '@astryxdesign/core')
|
|
2013
|
+
return dir;
|
|
2011
2014
|
const parent = path.dirname(dir);
|
|
2012
2015
|
if (parent === dir) return null;
|
|
2013
2016
|
dir = parent;
|
|
@@ -3139,7 +3142,7 @@ async function extractThemeDefinition(filePath, interception, /** @type {any} */
|
|
|
3139
3142
|
? jitiError
|
|
3140
3143
|
: new Error(`it threw ${thrownText(jitiError)}`);
|
|
3141
3144
|
throw new Error(
|
|
3142
|
-
`Failed to load theme from ${filePath}: ${themeLoadReason(je)}`,
|
|
3145
|
+
`Failed to load theme from ${filePath}: ${themeLoadReason(je)}${await baseImportHint(filePath, je)}`,
|
|
3143
3146
|
{cause: jitiError},
|
|
3144
3147
|
);
|
|
3145
3148
|
}
|
|
@@ -3319,6 +3322,53 @@ function thrownText(value) {
|
|
|
3319
3322
|
}
|
|
3320
3323
|
}
|
|
3321
3324
|
|
|
3325
|
+
/**
|
|
3326
|
+
* The import that fixes a base Core refuses as no theme, when the theme
|
|
3327
|
+
* extends a package's default export or the package as one object: a theme
|
|
3328
|
+
* package exports its themes by name, and the hint names them.
|
|
3329
|
+
* @param {string} filePath
|
|
3330
|
+
* @param {Error} error
|
|
3331
|
+
* @returns {Promise<string>} '' when the base is no such import
|
|
3332
|
+
*/
|
|
3333
|
+
async function baseImportHint(filePath, error) {
|
|
3334
|
+
if (!/`extends` must be a theme from defineTheme\(\)/.test(error.message))
|
|
3335
|
+
return '';
|
|
3336
|
+
const binding = themeBaseBinding(filePath, 'default');
|
|
3337
|
+
const specifier = binding?.importPath;
|
|
3338
|
+
if (
|
|
3339
|
+
!specifier ||
|
|
3340
|
+
specifier.startsWith('.') ||
|
|
3341
|
+
path.isAbsolute(specifier) ||
|
|
3342
|
+
(binding.exportName !== 'default' && binding.exportName !== '*')
|
|
3343
|
+
)
|
|
3344
|
+
return '';
|
|
3345
|
+
/** @type {string[]} */
|
|
3346
|
+
let themes = [];
|
|
3347
|
+
try {
|
|
3348
|
+
const resolved = createRequire(filePath).resolve(specifier);
|
|
3349
|
+
const mod = await import(pathToFileURL(resolved).href);
|
|
3350
|
+
themes = Object.entries(mod)
|
|
3351
|
+
.filter(
|
|
3352
|
+
([name, value]) =>
|
|
3353
|
+
name !== 'default' &&
|
|
3354
|
+
value &&
|
|
3355
|
+
typeof value === 'object' &&
|
|
3356
|
+
typeof value.name === 'string' &&
|
|
3357
|
+
value.tokens &&
|
|
3358
|
+
typeof value.tokens === 'object',
|
|
3359
|
+
)
|
|
3360
|
+
.map(([name]) => name);
|
|
3361
|
+
} catch {
|
|
3362
|
+
// The package's exports are not read: the hint names the form only.
|
|
3363
|
+
}
|
|
3364
|
+
const how =
|
|
3365
|
+
binding.exportName === '*'
|
|
3366
|
+
? `all of ${specifier} as one object`
|
|
3367
|
+
: `the default export of ${specifier}`;
|
|
3368
|
+
const example = themes[0] ?? '<theme>';
|
|
3369
|
+
return `\nThe theme extends ${how}, which is not a theme: a theme package exports its theme by name${themes.length ? ` (${themes.join(', ')})` : ''}. Import it so: import {${example}} from '${specifier}', and extend ${example}.`;
|
|
3370
|
+
}
|
|
3371
|
+
|
|
3322
3372
|
/**
|
|
3323
3373
|
* Why a theme module did not load, with the step that fixes it. A module
|
|
3324
3374
|
* whose default export is null or a primitive trips the loader's interop
|
|
@@ -6233,6 +6283,7 @@ async function themeBuildInternal(
|
|
|
6233
6283
|
);
|
|
6234
6284
|
}
|
|
6235
6285
|
warnMissingDeclarations(writes, cwd);
|
|
6286
|
+
handOff.warnings?.push(...warningMessages);
|
|
6236
6287
|
return /** @type {import('../theme.type.mjs').ThemeBuildCheckResponse} */ ({
|
|
6237
6288
|
type: 'theme.build.check',
|
|
6238
6289
|
data: {
|
|
@@ -466,6 +466,10 @@ function keyProblem(key, value, kind, pseudoProblem) {
|
|
|
466
466
|
if (isBlock(value)) {
|
|
467
467
|
if (key.startsWith(':') && kind !== 'pseudo') return pseudoProblem(key);
|
|
468
468
|
if (kind === 'style' && MODE_KEYS.includes(key)) return null;
|
|
469
|
+
// Variants written as other styling libraries write them: named with
|
|
470
|
+
// the style keys that write them, by the build and the editor alike.
|
|
471
|
+
const keys = kind === 'style' ? variantMapKeys(key, value) : null;
|
|
472
|
+
if (keys) return variantMapMessage(key, keys);
|
|
469
473
|
return `${key} holds a block, but ${kind === 'pseudo' ? 'a pseudo key holds properties only' : `only a pseudo key (':hover', '::before')${kind === 'style' ? ' or @light / @dark' : ''} holds one here`}, so the build writes it as a declaration the browser drops`;
|
|
470
474
|
}
|
|
471
475
|
if (key.startsWith(':') || key.startsWith('@')) return null;
|
|
@@ -722,11 +726,6 @@ export function styleKeyProblems(theme) {
|
|
|
722
726
|
const block = (node, at, kind, depth) => {
|
|
723
727
|
if (!isBlock(node) || depth > 12) return;
|
|
724
728
|
for (const [k, v] of Object.entries(node)) {
|
|
725
|
-
const keys = kind === 'style' ? variantMapKeys(k, v) : null;
|
|
726
|
-
if (keys) {
|
|
727
|
-
out.push({path: [...at, k], why: variantMapMessage(k, keys)});
|
|
728
|
-
continue;
|
|
729
|
-
}
|
|
730
729
|
const why = keyProblem(k, v, kind, key => checked(key).problem);
|
|
731
730
|
if (why) {
|
|
732
731
|
out.push({path: [...at, k], why});
|
|
@@ -64,6 +64,11 @@ export function moduleBindings(ast) {
|
|
|
64
64
|
source: node.source.value,
|
|
65
65
|
imported: 'default',
|
|
66
66
|
});
|
|
67
|
+
else if (spec.type === 'ImportNamespaceSpecifier')
|
|
68
|
+
imports.set(spec.local.name, {
|
|
69
|
+
source: node.source.value,
|
|
70
|
+
imported: '*',
|
|
71
|
+
});
|
|
67
72
|
addDeclaration(node);
|
|
68
73
|
if (node.type === 'ExportNamedDeclaration') {
|
|
69
74
|
addDeclaration(node.declaration);
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @param {number} red
|
|
6
|
+
* @param {number} green
|
|
7
|
+
* @param {number} blue
|
|
8
|
+
* @returns {ColorTriple}
|
|
9
|
+
*/
|
|
10
|
+
export function linearRgbToOklab(red: number, green: number, blue: number): ColorTriple;
|
|
4
11
|
/**
|
|
5
12
|
* @param {number} lightness
|
|
6
13
|
* @param {number} a
|
|
@@ -40,11 +47,44 @@ export function oklchClampedHex(lightness: number, chroma: number, hue: number):
|
|
|
40
47
|
* @returns {number}
|
|
41
48
|
*/
|
|
42
49
|
export function toneToOklabLightness(tone: number): number;
|
|
50
|
+
/**
|
|
51
|
+
* A hex color's linear-light red, green and blue, each 0 to 1.
|
|
52
|
+
* @param {string} hex
|
|
53
|
+
* @returns {ColorTriple}
|
|
54
|
+
*/
|
|
55
|
+
export function hexToLinearRgb(hex: string): ColorTriple;
|
|
43
56
|
/**
|
|
44
57
|
* @param {string} hex
|
|
45
58
|
* @returns {number}
|
|
46
59
|
*/
|
|
47
60
|
export function luminance(hex: string): number;
|
|
61
|
+
/**
|
|
62
|
+
* A hex color's red, green and blue, 0 to 255.
|
|
63
|
+
* @param {string} hex
|
|
64
|
+
* @returns {ColorTriple}
|
|
65
|
+
*/
|
|
66
|
+
export function hexToRgbTriple(hex: string): ColorTriple;
|
|
67
|
+
/**
|
|
68
|
+
* Red, green and blue (0 to 255, rounded) as a lowercase hex.
|
|
69
|
+
* @param {ReadonlyArray<number>} rgb
|
|
70
|
+
* @returns {string}
|
|
71
|
+
*/
|
|
72
|
+
export function rgbTripleToHex(rgb: ReadonlyArray<number>): string;
|
|
73
|
+
/**
|
|
74
|
+
* A color drawn at `alpha` over `under`, as the opaque color the eye sees.
|
|
75
|
+
* @param {ReadonlyArray<number>} over
|
|
76
|
+
* @param {number} alpha
|
|
77
|
+
* @param {ReadonlyArray<number>} under
|
|
78
|
+
* @returns {ColorTriple}
|
|
79
|
+
*/
|
|
80
|
+
export function compositeOver(over: ReadonlyArray<number>, alpha: number, under: ReadonlyArray<number>): ColorTriple;
|
|
81
|
+
/**
|
|
82
|
+
* The WCAG contrast ratio of two opaque colors.
|
|
83
|
+
* @param {string} a
|
|
84
|
+
* @param {string} b
|
|
85
|
+
* @returns {number}
|
|
86
|
+
*/
|
|
87
|
+
export function contrastRatio(a: string, b: string): number;
|
|
48
88
|
/**
|
|
49
89
|
* @param {string} hex
|
|
50
90
|
* @returns {ColorTriple}
|
|
@@ -55,4 +95,11 @@ export function oklabCoordinates(hex: string): ColorTriple;
|
|
|
55
95
|
* @returns {string}
|
|
56
96
|
*/
|
|
57
97
|
export function oklabCoordinatesToHex(coordinates: ColorTriple): string;
|
|
98
|
+
/**
|
|
99
|
+
* A contrast ratio to two decimals, cut down and never rounded up, so a
|
|
100
|
+
* pair just under the bar never prints as meeting it.
|
|
101
|
+
* @param {number} ratio
|
|
102
|
+
* @returns {number}
|
|
103
|
+
*/
|
|
104
|
+
export function ratioDown(ratio: number): number;
|
|
58
105
|
export type ColorTriple = [number, number, number];
|
|
@@ -70,7 +70,7 @@ function rgbToHex(red, green, blue) {
|
|
|
70
70
|
* @param {number} blue
|
|
71
71
|
* @returns {ColorTriple}
|
|
72
72
|
*/
|
|
73
|
-
function linearRgbToOklab(red, green, blue) {
|
|
73
|
+
export function linearRgbToOklab(red, green, blue) {
|
|
74
74
|
const lRoot = Math.cbrt(
|
|
75
75
|
0.4122214708 * red + 0.5363325363 * green + 0.0514459929 * blue,
|
|
76
76
|
);
|
|
@@ -228,6 +228,15 @@ export function toneToOklabLightness(tone) {
|
|
|
228
228
|
const relative = tone > 8 ? Math.pow((tone + 16) / 116, 3) : tone / 903.3;
|
|
229
229
|
return Math.cbrt(relative);
|
|
230
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* A hex color's linear-light red, green and blue, each 0 to 1.
|
|
233
|
+
* @param {string} hex
|
|
234
|
+
* @returns {ColorTriple}
|
|
235
|
+
*/
|
|
236
|
+
export function hexToLinearRgb(hex) {
|
|
237
|
+
const [red, green, blue] = hexToRgb(hex).map(srgbToLinear);
|
|
238
|
+
return [red, green, blue];
|
|
239
|
+
}
|
|
231
240
|
/**
|
|
232
241
|
* @param {string} hex
|
|
233
242
|
* @returns {number}
|
|
@@ -236,6 +245,45 @@ export function luminance(hex) {
|
|
|
236
245
|
const [red, green, blue] = hexToRgb(hex).map(srgbToLinear);
|
|
237
246
|
return 0.2126 * red + 0.7152 * green + 0.0722 * blue;
|
|
238
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* A hex color's red, green and blue, 0 to 255.
|
|
250
|
+
* @param {string} hex
|
|
251
|
+
* @returns {ColorTriple}
|
|
252
|
+
*/
|
|
253
|
+
export function hexToRgbTriple(hex) {
|
|
254
|
+
return hexToRgb(hex);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Red, green and blue (0 to 255, rounded) as a lowercase hex.
|
|
258
|
+
* @param {ReadonlyArray<number>} rgb
|
|
259
|
+
* @returns {string}
|
|
260
|
+
*/
|
|
261
|
+
export function rgbTripleToHex(rgb) {
|
|
262
|
+
return rgbToHex(Math.round(rgb[0]), Math.round(rgb[1]), Math.round(rgb[2]));
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* A color drawn at `alpha` over `under`, as the opaque color the eye sees.
|
|
266
|
+
* @param {ReadonlyArray<number>} over
|
|
267
|
+
* @param {number} alpha
|
|
268
|
+
* @param {ReadonlyArray<number>} under
|
|
269
|
+
* @returns {ColorTriple}
|
|
270
|
+
*/
|
|
271
|
+
export function compositeOver(over, alpha, under) {
|
|
272
|
+
return /** @type {ColorTriple} */ (
|
|
273
|
+
over.map((x, n) => x * alpha + under[n] * (1 - alpha))
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* The WCAG contrast ratio of two opaque colors.
|
|
278
|
+
* @param {string} a
|
|
279
|
+
* @param {string} b
|
|
280
|
+
* @returns {number}
|
|
281
|
+
*/
|
|
282
|
+
export function contrastRatio(a, b) {
|
|
283
|
+
const x = luminance(a);
|
|
284
|
+
const y = luminance(b);
|
|
285
|
+
return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);
|
|
286
|
+
}
|
|
239
287
|
/**
|
|
240
288
|
* @param {string} hex
|
|
241
289
|
* @returns {ColorTriple}
|
|
@@ -255,3 +303,12 @@ export function oklabCoordinatesToHex(coordinates) {
|
|
|
255
303
|
const hue = ((Math.atan2(b, a) * 180) / Math.PI + 360) % 360;
|
|
256
304
|
return oklchClampedHex(Math.min(1, Math.max(0, lightness)), chroma, hue);
|
|
257
305
|
}
|
|
306
|
+
/**
|
|
307
|
+
* A contrast ratio to two decimals, cut down and never rounded up, so a
|
|
308
|
+
* pair just under the bar never prints as meeting it.
|
|
309
|
+
* @param {number} ratio
|
|
310
|
+
* @returns {number}
|
|
311
|
+
*/
|
|
312
|
+
export function ratioDown(ratio) {
|
|
313
|
+
return Math.floor(ratio * 100 + 1e-9) / 100;
|
|
314
|
+
}
|