@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
|
@@ -25,6 +25,11 @@ import {AstryxError} from '../error.mjs';
|
|
|
25
25
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
26
26
|
import {importPathOf, installLine, literals} from './_project.mjs';
|
|
27
27
|
import {removeEmptyFolder} from '../../foundation/fs/empty-folder.mjs';
|
|
28
|
+
import {sidesOf} from './_css.mjs';
|
|
29
|
+
|
|
30
|
+
/** Text properties CSS inherits, which a part passes to the text inside it. */
|
|
31
|
+
export const INHERITED_TEXT =
|
|
32
|
+
/^(font-(size|weight|style|family|variant)|text-(transform|align)|letter-spacing|line-height|white-space|word-spacing)$/;
|
|
28
33
|
import {VOID} from '../../foundation/render/html-reader.mjs';
|
|
29
34
|
import {
|
|
30
35
|
RENDER_TIMEOUT_MS,
|
|
@@ -95,9 +100,12 @@ const LIFECYCLE_FLAGS = new Set([
|
|
|
95
100
|
* @property {Record<string, {tokens: Record<string, string[]>, values: string[]}>} own - property -> tokens (with conditions) and raw values
|
|
96
101
|
* @property {Record<string, Record<string, string>>} [at] - property -> the value under each condition, private variables resolved
|
|
97
102
|
* @property {Record<string, string[]>} inside - tokens read by unnamed elements inside the part -> properties
|
|
103
|
+
* @property {Record<string, string[]>} [innerSets] - inherited text properties a visible unnamed element inside the part that holds text sets to values of its own -> those values (a code block's lines: white-space pre or pre-wrap)
|
|
98
104
|
* @property {Record<string, string[]>} attrs - data attributes seen on the part
|
|
99
105
|
* @property {string[]} contains - parts rendered inside it
|
|
106
|
+
* @property {string[]} [drawnAs] - the other parts drawn on the same element (a select's option is drawn as an Item)
|
|
100
107
|
* @property {string[]} [repeats] - parts it holds more than one of side by side, as the nearest part around them (a shortcut's keys, a button group's buttons)
|
|
108
|
+
* @property {string[]} [listed] - the parts inside it drawn more than once in one of its elements (a menu's items), unlike a part drawn there once (a header's nav)
|
|
101
109
|
* @property {Record<string, string[]>} [holdsVariants] - for a part rendered inside it, the variants it is drawn in there (a toast's close button: ghost)
|
|
102
110
|
* @property {string[]} [tags] - the elements it is rendered as (`tr` for a table row)
|
|
103
111
|
* @property {string} [underInput] - drawn under an invisible native input
|
|
@@ -762,12 +770,92 @@ function deepFreeze(value) {
|
|
|
762
770
|
return value;
|
|
763
771
|
}
|
|
764
772
|
|
|
773
|
+
/**
|
|
774
|
+
* The runtime states the census finds a part's own element marked with
|
|
775
|
+
* that its doc does not list (a list item rides an Item, whose
|
|
776
|
+
* `data-selected` marks it selected): each `name=name` condition the part
|
|
777
|
+
* reads under, less its visual props. Added to the part's states, so set
|
|
778
|
+
* names them and the build writes them as the data attribute Core marks.
|
|
779
|
+
* @param {{target: Map<string, {props: string[], states: string[]}>}} project
|
|
780
|
+
* @param {PartData} parts
|
|
781
|
+
*/
|
|
782
|
+
export function addCensusStates(project, parts) {
|
|
783
|
+
const named = censusStateNames(parts);
|
|
784
|
+
for (const [part, names] of named) {
|
|
785
|
+
const t = project.target.get(part);
|
|
786
|
+
if (!t) continue;
|
|
787
|
+
const props = new Set(t.props);
|
|
788
|
+
for (const name of names)
|
|
789
|
+
if (!props.has(name) && !t.states.includes(name)) {
|
|
790
|
+
t.states.push(name);
|
|
791
|
+
let seen = CENSUS_STATES.get(t);
|
|
792
|
+
if (!seen) CENSUS_STATES.set(t, (seen = new Set()));
|
|
793
|
+
seen.add(name);
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
/**
|
|
799
|
+
* The states each part target took from the census alone (addCensusStates):
|
|
800
|
+
* Core's theme takes no style key for them on that part.
|
|
801
|
+
* @type {WeakMap<object, Set<string>>}
|
|
802
|
+
*/
|
|
803
|
+
const CENSUS_STATES = new WeakMap();
|
|
804
|
+
|
|
805
|
+
/**
|
|
806
|
+
* A part's states that came from the census alone, not its doc: states
|
|
807
|
+
* Core's theme takes no style key for on that part (a list item rides an
|
|
808
|
+
* Item, whose own `selected` it shows), which the build writes as the
|
|
809
|
+
* attribute Core marks.
|
|
810
|
+
* @param {{target: Map<string, any>}} project
|
|
811
|
+
* @param {string} part
|
|
812
|
+
* @returns {string[]}
|
|
813
|
+
*/
|
|
814
|
+
export function censusStatesOf(project, part) {
|
|
815
|
+
const t = project.target.get(part);
|
|
816
|
+
return t ? [...(CENSUS_STATES.get(t) ?? [])] : [];
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* The names each part's rules write as a state (`selected=selected`), read
|
|
821
|
+
* from the part data: partData hands out the same frozen data while its
|
|
822
|
+
* file is unchanged, so they are read once for each.
|
|
823
|
+
* @param {PartData} parts
|
|
824
|
+
* @returns {Map<string, Set<string>>}
|
|
825
|
+
*/
|
|
826
|
+
function censusStateNames(parts) {
|
|
827
|
+
const kept = STATE_NAMES.get(parts.map);
|
|
828
|
+
if (kept) return kept;
|
|
829
|
+
/** @type {Map<string, Set<string>>} */
|
|
830
|
+
const out = new Map();
|
|
831
|
+
for (const [part, rec] of Object.entries(parts.map)) {
|
|
832
|
+
/** @type {Set<string>} */
|
|
833
|
+
const found = new Set();
|
|
834
|
+
for (const byCond of Object.values(rec.at ?? {}))
|
|
835
|
+
for (const cond of Object.keys(byCond ?? {}))
|
|
836
|
+
for (const pair of cond.split(/\s/)[0].split(','))
|
|
837
|
+
if (
|
|
838
|
+
/^([a-z][\w-]*)=\1$/.test(pair) &&
|
|
839
|
+
// (A state of a part drawn on this part's element is that
|
|
840
|
+
// part's: only the part's own marks count, see walkMarkup.)
|
|
841
|
+
Object.hasOwn(rec.attrs ?? {}, pair.slice(0, pair.indexOf('=')))
|
|
842
|
+
)
|
|
843
|
+
found.add(pair.slice(0, pair.indexOf('=')));
|
|
844
|
+
if (found.size) out.set(part, found);
|
|
845
|
+
}
|
|
846
|
+
STATE_NAMES.set(parts.map, out);
|
|
847
|
+
return out;
|
|
848
|
+
}
|
|
849
|
+
/** @type {WeakMap<object, Map<string, Set<string>>>} */
|
|
850
|
+
const STATE_NAMES = new WeakMap();
|
|
851
|
+
|
|
765
852
|
/**
|
|
766
853
|
* The part data for the installed Core, from the cache or built now.
|
|
767
854
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
768
855
|
* @returns {Promise<PartData>}
|
|
769
856
|
*/
|
|
770
857
|
export async function partData(project) {
|
|
858
|
+
if (!project.cacheDir) return buildPartData(project);
|
|
771
859
|
const file = path.join(project.cacheDir, 'parts.json');
|
|
772
860
|
try {
|
|
773
861
|
// The file is read again only when it changed: every command reads it,
|
|
@@ -987,6 +1075,19 @@ async function buildPartData(project) {
|
|
|
987
1075
|
const layers = walkMarkup(markup.slice(at), decls, tokens, project.target);
|
|
988
1076
|
const added = Object.keys(layers.map).filter(k => !(k in result.map));
|
|
989
1077
|
for (const k of added) result.map[k] = layers.map[k];
|
|
1078
|
+
// A part the page draws too keeps its page record, and takes from the
|
|
1079
|
+
// opened overlays only the open state the page never shows (a menu's
|
|
1080
|
+
// submenu row, open while its flyout is): its conditions under the open
|
|
1081
|
+
// attribute.
|
|
1082
|
+
for (const [k, rec] of Object.entries(layers.map)) {
|
|
1083
|
+
if (added.includes(k)) continue;
|
|
1084
|
+
const page = result.map[k];
|
|
1085
|
+
if (!page) continue;
|
|
1086
|
+
for (const [prop, byCond] of Object.entries(rec.at ?? {}))
|
|
1087
|
+
for (const [cond, v] of Object.entries(byCond ?? {}))
|
|
1088
|
+
if (/(?:^|,)aria-expanded=true\b/.test(cond.split(' ')[0]))
|
|
1089
|
+
((page.at ??= {})[prop] ??= {})[cond] ??= v;
|
|
1090
|
+
}
|
|
990
1091
|
const seen = new Set(result.pairs.map(x => JSON.stringify(x)));
|
|
991
1092
|
for (const x of layers.pairs)
|
|
992
1093
|
if (
|
|
@@ -1302,9 +1403,9 @@ function resolvePrivate(v, env, tokens, depth = 0) {
|
|
|
1302
1403
|
* @returns {{map: Record<string, PartRecord>, pairs: TextPair[]}}
|
|
1303
1404
|
*/
|
|
1304
1405
|
export function walkMarkup(html, decls, tokens, targets = new Map()) {
|
|
1305
|
-
/** @type {Record<string, {own: Record<string, {tokens: Record<string, Set<string>>, values: Set<string>}>, at: Record<string, Record<string, string>>, inside: Record<string, Set<string>>, attrs: Record<string, Set<string>>, contains: Set<string>, repeats: Set<string>, holdsVariants?: Record<string, Set<string>>, tags: Set<string>, innerCorners: Set<string>, media: boolean, mediaSides?: Set<string>, line?: Set<string>, lineAdded?: Array<[string, string, Set<string>, boolean?]>, held?: Record<string, Set<string>>, underInput?: string}>} */
|
|
1406
|
+
/** @type {Record<string, {own: Record<string, {tokens: Record<string, Set<string>>, values: Set<string>}>, at: Record<string, Record<string, string>>, inside: Record<string, Set<string>>, attrs: Record<string, Set<string>>, contains: Set<string>, repeats: Set<string>, holdsVariants?: Record<string, Set<string>>, tags: Set<string>, innerCorners: Set<string>, media: boolean, mediaSides?: Set<string>, line?: Set<string>, lineAdded?: Array<[string, string, Set<string>, boolean?]>, held?: Record<string, Set<string>>, alone?: boolean, borrowed?: Record<string, Set<string>>, listed?: Set<string>, drawnAs?: Set<string>, innerSets?: Record<string, Set<string>>, underInput?: string}>} */
|
|
1306
1407
|
const map = {};
|
|
1307
|
-
/** @type {Array<{env: Record<string, string>, target: string | null, all?: string[], fg: PaintSide | null, bg: PaintSide | null, cond: string, kids?: string[], input?: boolean, owns?: boolean, seenParts?: Record<string, number>}>} */
|
|
1408
|
+
/** @type {Array<{env: Record<string, string>, target: string | null, all?: string[], fg: PaintSide | null, bg: PaintSide | null, cond: string, kids?: string[], input?: boolean, owns?: boolean, seenParts?: Record<string, number>, seen?: Map<string, number>}>} */
|
|
1308
1409
|
const stack = [{env: {}, target: null, fg: null, bg: null, cond: ''}];
|
|
1309
1410
|
/** @type {Map<string, TextPair>} */
|
|
1310
1411
|
const pairs = new Map();
|
|
@@ -1382,11 +1483,19 @@ export function walkMarkup(html, decls, tokens, targets = new Map()) {
|
|
|
1382
1483
|
// that marks the place with a runtime state of its own (a selected tab)
|
|
1383
1484
|
// is conditioned by that state already.
|
|
1384
1485
|
const ownState = Object.keys(dataAttrs).some(k => states.has(k));
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1486
|
+
// (Open is the part's own state, never a place another component puts
|
|
1487
|
+
// it: a submenu's row is highlighted while its flyout is open, and open
|
|
1488
|
+
// too.)
|
|
1489
|
+
const context = [
|
|
1490
|
+
...attrs.matchAll(
|
|
1491
|
+
ownState
|
|
1492
|
+
? /\b(aria-expanded)="([^"]*)"/g
|
|
1493
|
+
: /\b(aria-(?:current|pressed|expanded))="([^"]*)"/g,
|
|
1494
|
+
),
|
|
1495
|
+
]
|
|
1496
|
+
.filter(x => x[2] !== 'false')
|
|
1497
|
+
.map(x => `${x[1]}=${x[2]}`);
|
|
1498
|
+
const open = context.includes('aria-expanded=true');
|
|
1390
1499
|
const env = {...parent.env};
|
|
1391
1500
|
const own = cls.flatMap(c => decls.get(c) ?? []);
|
|
1392
1501
|
for (const d of own)
|
|
@@ -1404,6 +1513,17 @@ export function walkMarkup(html, decls, tokens, targets = new Map()) {
|
|
|
1404
1513
|
Boolean(selfClose) ||
|
|
1405
1514
|
VOID.has(tag.toLowerCase()) ||
|
|
1406
1515
|
html.startsWith(`</${tag}>`, (m.index ?? 0) + m[0].length);
|
|
1516
|
+
// (An element that holds text a reader sees: never an empty one, an
|
|
1517
|
+
// icon's box, or text hidden for screen readers alone.)
|
|
1518
|
+
const after = html.slice((m.index ?? 0) + m[0].length);
|
|
1519
|
+
const holdsText =
|
|
1520
|
+
!empty &&
|
|
1521
|
+
!/^\s*<svg\b/i.test(after) &&
|
|
1522
|
+
!own.some(
|
|
1523
|
+
d =>
|
|
1524
|
+
(d.prop === 'clip' && d.value !== 'auto') ||
|
|
1525
|
+
(d.prop === 'clip-path' && /inset\(\s*50%/.test(d.value)),
|
|
1526
|
+
);
|
|
1407
1527
|
const paints = (
|
|
1408
1528
|
/** @type {{prop: string, value: string, cond: string}} */ d,
|
|
1409
1529
|
) =>
|
|
@@ -1444,9 +1564,22 @@ export function walkMarkup(html, decls, tokens, targets = new Map()) {
|
|
|
1444
1564
|
innerCorners: new Set(),
|
|
1445
1565
|
media: false,
|
|
1446
1566
|
});
|
|
1447
|
-
|
|
1567
|
+
// A data attribute another target on the element declares is this
|
|
1568
|
+
// part's only when the part rides on that one: a part always drawn
|
|
1569
|
+
// together with another (a list item on its Item) takes that one's
|
|
1570
|
+
// states; a part also drawn on its own (a Button) never takes the
|
|
1571
|
+
// states of a part drawn on it (a pagination cell's selected). Which
|
|
1572
|
+
// is which is known once the whole census is read.
|
|
1573
|
+
if (ownsTarget) {
|
|
1574
|
+
const mine = targets.get(t);
|
|
1575
|
+
if (named.length === 1) T.alone = true;
|
|
1576
|
+
for (const o of named)
|
|
1577
|
+
if (o.slice(7) !== t) (T.drawnAs ??= new Set()).add(o.slice(7));
|
|
1448
1578
|
for (const [k, v] of Object.entries(dataAttrs))
|
|
1449
|
-
(
|
|
1579
|
+
if (!mine || mine.props.includes(k) || mine.states.includes(k))
|
|
1580
|
+
(T.attrs[k] ??= new Set()).add(v);
|
|
1581
|
+
else ((T.borrowed ??= {})[k] ??= new Set()).add(v);
|
|
1582
|
+
}
|
|
1450
1583
|
// Core's media surface inside the part (a toast's inverted surface):
|
|
1451
1584
|
// it sets the text tokens of what it holds from the on-dark color
|
|
1452
1585
|
// where it is dark and the on-light color where it is light (Core's
|
|
@@ -1466,6 +1599,10 @@ export function walkMarkup(html, decls, tokens, targets = new Map()) {
|
|
|
1466
1599
|
: parent.cond;
|
|
1467
1600
|
for (const d of own) {
|
|
1468
1601
|
if (d.prop.startsWith('--')) continue;
|
|
1602
|
+
// (An element drawn open is never disabled: what opens it is
|
|
1603
|
+
// enabled. Its disabled rules are recorded where Core draws it
|
|
1604
|
+
// closed, never as open and disabled at once.)
|
|
1605
|
+
if (open && d.cond && /disabled/.test(d.cond)) continue;
|
|
1469
1606
|
// (An inherited background paints nothing of its own: it reads no
|
|
1470
1607
|
// token, and what shows is its parent's.)
|
|
1471
1608
|
const toks = expand(d.value, env, tokens);
|
|
@@ -1480,6 +1617,19 @@ export function walkMarkup(html, decls, tokens, targets = new Map()) {
|
|
|
1480
1617
|
toks.has('--border-width')));
|
|
1481
1618
|
if (!ownsTarget)
|
|
1482
1619
|
for (const k of toks) (T.inside[k] ??= new Set()).add(d.prop);
|
|
1620
|
+
// (An element inside the part that sets an inherited text property
|
|
1621
|
+
// to a value of its own, a code block's lines keeping white-space
|
|
1622
|
+
// pre: that property set on the part never reaches its text.)
|
|
1623
|
+
if (
|
|
1624
|
+
!ownsTarget &&
|
|
1625
|
+
!toks.size &&
|
|
1626
|
+
INHERITED_TEXT.test(d.prop) &&
|
|
1627
|
+
!/^(inherit|unset|initial|revert)$/.test(String(d.value).trim()) &&
|
|
1628
|
+
holdsText
|
|
1629
|
+
)
|
|
1630
|
+
((T.innerSets ??= {})[d.prop] ??= new Set()).add(
|
|
1631
|
+
String(d.value).trim(),
|
|
1632
|
+
);
|
|
1483
1633
|
if (asOwn && (ownsTarget || lineProp)) {
|
|
1484
1634
|
// (Drawn by the line inside the part, not the part's own element:
|
|
1485
1635
|
// a setting on the part does not reach it.)
|
|
@@ -1574,6 +1724,12 @@ export function walkMarkup(html, decls, tokens, targets = new Map()) {
|
|
|
1574
1724
|
for (const at of anc.all ?? (anc.target ? [anc.target] : []))
|
|
1575
1725
|
if (at !== t) {
|
|
1576
1726
|
map[at].contains.add(t);
|
|
1727
|
+
// (A part drawn a second time inside the same element is listed
|
|
1728
|
+
// there: a menu's items, never a header's one nav.)
|
|
1729
|
+
const seen = (anc.seen ??= new Map());
|
|
1730
|
+
seen.set(`${at}\0${t}`, (seen.get(`${at}\0${t}`) ?? 0) + 1);
|
|
1731
|
+
if (seen.get(`${at}\0${t}`) === 2)
|
|
1732
|
+
(map[at].listed ??= new Set()).add(t);
|
|
1577
1733
|
// (The variant each holds there: a toast's close button is a
|
|
1578
1734
|
// ghost button.)
|
|
1579
1735
|
if (dataAttrs.variant)
|
|
@@ -1674,11 +1830,32 @@ export function walkMarkup(html, decls, tokens, targets = new Map()) {
|
|
|
1674
1830
|
inside: Object.fromEntries(
|
|
1675
1831
|
Object.entries(v.inside).map(([k, s]) => [k, [...s]]),
|
|
1676
1832
|
),
|
|
1833
|
+
...(v.innerSets
|
|
1834
|
+
? {
|
|
1835
|
+
innerSets: Object.fromEntries(
|
|
1836
|
+
Object.entries(v.innerSets).map(([k, s]) => [k, [...s]]),
|
|
1837
|
+
),
|
|
1838
|
+
}
|
|
1839
|
+
: {}),
|
|
1677
1840
|
attrs: Object.fromEntries(
|
|
1678
|
-
Object.entries(
|
|
1841
|
+
Object.entries(
|
|
1842
|
+
v.alone
|
|
1843
|
+
? v.attrs
|
|
1844
|
+
: {
|
|
1845
|
+
...Object.fromEntries(
|
|
1846
|
+
Object.entries(v.borrowed ?? {}).map(([k, s]) => [
|
|
1847
|
+
k,
|
|
1848
|
+
new Set([...s, ...(v.attrs[k] ?? [])]),
|
|
1849
|
+
]),
|
|
1850
|
+
),
|
|
1851
|
+
...v.attrs,
|
|
1852
|
+
},
|
|
1853
|
+
).map(([k, s]) => [k, [...s]]),
|
|
1679
1854
|
),
|
|
1680
1855
|
contains: [...v.contains],
|
|
1681
1856
|
...(v.repeats?.size ? {repeats: [...v.repeats]} : {}),
|
|
1857
|
+
...(v.listed?.size ? {listed: [...v.listed]} : {}),
|
|
1858
|
+
...(v.drawnAs?.size ? {drawnAs: [...v.drawnAs]} : {}),
|
|
1682
1859
|
...(v.holdsVariants
|
|
1683
1860
|
? {
|
|
1684
1861
|
holdsVariants: Object.fromEntries(
|
|
@@ -1703,3 +1880,415 @@ export function walkMarkup(html, decls, tokens, targets = new Map()) {
|
|
|
1703
1880
|
}
|
|
1704
1881
|
return {map: out, pairs: [...pairs.values()]};
|
|
1705
1882
|
}
|
|
1883
|
+
|
|
1884
|
+
/**
|
|
1885
|
+
* The family roles the census shows, each read from the parts' own
|
|
1886
|
+
* structure (their tags, states, resting fills, press overlays and their
|
|
1887
|
+
* component's doc category), never from their names: a look set on one
|
|
1888
|
+
* member of a role reaches the others.
|
|
1889
|
+
* - `button-like`: drawn as a <button> with a press overlay and a box of
|
|
1890
|
+
* its own (a fill at rest in some variant, or a pressed state), never a
|
|
1891
|
+
* selectable item;
|
|
1892
|
+
* - `overlays`: an Overlay component's own surface, filled with the
|
|
1893
|
+
* surface or popover color;
|
|
1894
|
+
* - `option-rows`: a row (a <div> or <li>) clear at rest that is
|
|
1895
|
+
* highlighted as you move through a list, or pressed without being
|
|
1896
|
+
* selectable;
|
|
1897
|
+
* - `selected-items`: a part with a selected (or active) state whose
|
|
1898
|
+
* selected look fills it;
|
|
1899
|
+
* - `accent-fills`: a part filled with the accent at rest;
|
|
1900
|
+
* - `inset-fields`: the inputs and the parts filled with the track color;
|
|
1901
|
+
* - `status-surfaces`: a part holding a message with a control of its own
|
|
1902
|
+
* whose fill follows a prop whose values name the theme's status roles
|
|
1903
|
+
* (info, success, warning, error);
|
|
1904
|
+
* - `overlay-headers`: an Overlay component's part, not its surface, that
|
|
1905
|
+
* holds a heading and a control (its title and its close button);
|
|
1906
|
+
* - `controls`: the parts that take their height from the control size
|
|
1907
|
+
* tokens (`--size-element-sm`, `-md`, `-lg`) and are a button, an input,
|
|
1908
|
+
* or a form control's own part (an input group): at each size they share
|
|
1909
|
+
* one height.
|
|
1910
|
+
* @param {{MAP: Record<string, any>}} C
|
|
1911
|
+
* @param {{target: Map<string, any>, components: Record<string, any>}} project
|
|
1912
|
+
* @param {string[]} inputs the inputs group's members
|
|
1913
|
+
* @param {string[]} statusWords the theme's status role words
|
|
1914
|
+
* @returns {Record<'button-like' | 'overlays' | 'option-rows' | 'selected-items' | 'accent-fills' | 'inset-fields' | 'status-surfaces' | 'overlay-headers' | 'controls', string[]>}
|
|
1915
|
+
*/
|
|
1916
|
+
export function familyRoles(
|
|
1917
|
+
C,
|
|
1918
|
+
project,
|
|
1919
|
+
inputs = [],
|
|
1920
|
+
statusWords = ['info', 'success', 'warning', 'error'],
|
|
1921
|
+
) {
|
|
1922
|
+
/** @type {Record<string, string[]>} */
|
|
1923
|
+
const out = {
|
|
1924
|
+
'button-like': [],
|
|
1925
|
+
overlays: [],
|
|
1926
|
+
'option-rows': [],
|
|
1927
|
+
'selected-items': [],
|
|
1928
|
+
'accent-fills': [],
|
|
1929
|
+
'inset-fields': [],
|
|
1930
|
+
'status-surfaces': [],
|
|
1931
|
+
'overlay-headers': [],
|
|
1932
|
+
controls: [],
|
|
1933
|
+
};
|
|
1934
|
+
/** @param {string} key @param {string} prop @param {(cond: string) => boolean} keep */
|
|
1935
|
+
const values = (key, prop, keep) =>
|
|
1936
|
+
Object.entries(C.MAP?.[key]?.at?.[prop] ?? {})
|
|
1937
|
+
.filter(([cond]) => keep(cond))
|
|
1938
|
+
.map(([, v]) => String(v).trim());
|
|
1939
|
+
const CLEAR = /^(?:transparent|none|rgba\(0, ?0, ?0, ?0\))$/;
|
|
1940
|
+
for (const [key, tg] of project.target) {
|
|
1941
|
+
const rec = C.MAP?.[key];
|
|
1942
|
+
if (!rec) continue;
|
|
1943
|
+
const tags = [...(rec.tags ?? [])];
|
|
1944
|
+
const states = [...(tg.states ?? []), ...Object.keys(rec.attrs ?? {})].map(
|
|
1945
|
+
String,
|
|
1946
|
+
);
|
|
1947
|
+
const selectable = states.some(st => /^(?:selected|active)$/.test(st));
|
|
1948
|
+
const highlighted = states.includes('highlighted');
|
|
1949
|
+
const pressed = JSON.stringify(rec.at ?? {}).includes('data-astryx-press');
|
|
1950
|
+
// (At rest: a condition of visual props only, no state (a state the
|
|
1951
|
+
// docs name, an ARIA state, or a boolean attribute Core writes as its
|
|
1952
|
+
// own name, selected="selected"), pseudo-class or inner element.)
|
|
1953
|
+
const docStates = new Set((tg.states ?? []).map(String));
|
|
1954
|
+
const rest = values(
|
|
1955
|
+
key,
|
|
1956
|
+
'background-color',
|
|
1957
|
+
cond =>
|
|
1958
|
+
!/[\s:[]/.test(cond) &&
|
|
1959
|
+
(cond === 'always' ||
|
|
1960
|
+
cond.split(',').every(kv => {
|
|
1961
|
+
const [k, v] = kv.split('=');
|
|
1962
|
+
return k !== v && !docStates.has(k) && !k.startsWith('aria-');
|
|
1963
|
+
})),
|
|
1964
|
+
);
|
|
1965
|
+
const comp = project.components?.[tg.component];
|
|
1966
|
+
const own = comp?.targets?.[0]?.className === `astryx-${key}`;
|
|
1967
|
+
if (
|
|
1968
|
+
tags.length &&
|
|
1969
|
+
tags.every(t => t === 'button') &&
|
|
1970
|
+
pressed &&
|
|
1971
|
+
!selectable &&
|
|
1972
|
+
!highlighted &&
|
|
1973
|
+
(rest.some(v => !CLEAR.test(v)) || states.some(st => /pressed/i.test(st)))
|
|
1974
|
+
)
|
|
1975
|
+
out['button-like'].push(key);
|
|
1976
|
+
if (
|
|
1977
|
+
comp?.category === 'Overlay' &&
|
|
1978
|
+
own &&
|
|
1979
|
+
values(key, 'background-color', cond => !/[\s:[]/.test(cond)).some(v =>
|
|
1980
|
+
/--color-background-(?:surface|popover)\b/.test(v),
|
|
1981
|
+
)
|
|
1982
|
+
)
|
|
1983
|
+
out.overlays.push(key);
|
|
1984
|
+
if (
|
|
1985
|
+
tags.length &&
|
|
1986
|
+
tags.every(t => t === 'div' || t === 'li') &&
|
|
1987
|
+
rest.length > 0 &&
|
|
1988
|
+
rest.every(v => CLEAR.test(v)) &&
|
|
1989
|
+
(highlighted || (pressed && !selectable))
|
|
1990
|
+
)
|
|
1991
|
+
out['option-rows'].push(key);
|
|
1992
|
+
if (
|
|
1993
|
+
selectable &&
|
|
1994
|
+
values(
|
|
1995
|
+
key,
|
|
1996
|
+
'background-color',
|
|
1997
|
+
cond =>
|
|
1998
|
+
/(?:^|,)(?:selected=selected|active=active)(?:,|$)/.test(cond) &&
|
|
1999
|
+
!/[\s:[]/.test(cond),
|
|
2000
|
+
).some(v => !CLEAR.test(v))
|
|
2001
|
+
)
|
|
2002
|
+
out['selected-items'].push(key);
|
|
2003
|
+
if (rest.some(v => /^var\(--color-accent\)$/.test(v)))
|
|
2004
|
+
out['accent-fills'].push(key);
|
|
2005
|
+
if (
|
|
2006
|
+
inputs.includes(key) ||
|
|
2007
|
+
rest.some(v => /^var\(--color-track\)$/.test(v))
|
|
2008
|
+
)
|
|
2009
|
+
out['inset-fields'].push(key);
|
|
2010
|
+
// (A status prop: one whose values are the theme's status words; the
|
|
2011
|
+
// fill follows it when it differs between them or reads a status
|
|
2012
|
+
// token.)
|
|
2013
|
+
const statusProps = Object.entries(rec.attrs ?? {})
|
|
2014
|
+
.filter(
|
|
2015
|
+
([, vals]) =>
|
|
2016
|
+
Array.isArray(vals) &&
|
|
2017
|
+
vals.some(v => statusWords.includes(String(v))),
|
|
2018
|
+
)
|
|
2019
|
+
.map(([k]) => k);
|
|
2020
|
+
if (statusProps.length) {
|
|
2021
|
+
const fills = Object.entries(rec.at?.['background-color'] ?? {}).filter(
|
|
2022
|
+
([cond]) => !/[\s:[]/.test(cond),
|
|
2023
|
+
);
|
|
2024
|
+
const statusFill = new RegExp(
|
|
2025
|
+
`--color-(?:background-)?(?:${statusWords.join('|')})\\b`,
|
|
2026
|
+
);
|
|
2027
|
+
const byStatus = fills.filter(([cond]) =>
|
|
2028
|
+
statusProps.some(k => new RegExp(`(?:^|,)${k}=`).test(cond)),
|
|
2029
|
+
);
|
|
2030
|
+
// (A surface: it holds a message with a control of its own, a dismiss
|
|
2031
|
+
// or an action; a badge or a dot is a mark, not a surface.)
|
|
2032
|
+
if (
|
|
2033
|
+
(rec.contains ?? []).includes('button') &&
|
|
2034
|
+
(byStatus.some(([, v]) => statusFill.test(String(v))) ||
|
|
2035
|
+
new Set(fills.map(([, v]) => String(v))).size > 1)
|
|
2036
|
+
)
|
|
2037
|
+
out['status-surfaces'].push(key);
|
|
2038
|
+
}
|
|
2039
|
+
if (
|
|
2040
|
+
comp?.category === 'Overlay' &&
|
|
2041
|
+
!own &&
|
|
2042
|
+
(rec.contains ?? []).includes('heading') &&
|
|
2043
|
+
(rec.contains ?? []).includes('button')
|
|
2044
|
+
)
|
|
2045
|
+
out['overlay-headers'].push(key);
|
|
2046
|
+
/** Whether a part's own height reads a control size token. @param {string} part */
|
|
2047
|
+
const sizedOwn = part =>
|
|
2048
|
+
Object.entries(C.MAP?.[part]?.own ?? {}).some(
|
|
2049
|
+
([prop, v]) =>
|
|
2050
|
+
CONTROL_HEIGHT_PROPS.test(prop) &&
|
|
2051
|
+
Object.keys(/** @type {any} */ (v)?.tokens ?? {}).some(t =>
|
|
2052
|
+
CONTROL_SIZE_TOKEN.test(t),
|
|
2053
|
+
),
|
|
2054
|
+
);
|
|
2055
|
+
// (A field whose boxes are its parts, a date and time input's two
|
|
2056
|
+
// segments, is sized through them: the token set on the field reaches
|
|
2057
|
+
// them.)
|
|
2058
|
+
const sizedByControlSize =
|
|
2059
|
+
sizedOwn(key) ||
|
|
2060
|
+
(own &&
|
|
2061
|
+
inputs.includes(key) &&
|
|
2062
|
+
[...project.target].some(
|
|
2063
|
+
([k, t]) => k !== key && t.component === tg.component && sizedOwn(k),
|
|
2064
|
+
));
|
|
2065
|
+
if (
|
|
2066
|
+
sizedByControlSize &&
|
|
2067
|
+
(inputs.includes(key) ||
|
|
2068
|
+
out['button-like'].includes(key) ||
|
|
2069
|
+
(comp?.category === 'Form Controls' && own))
|
|
2070
|
+
)
|
|
2071
|
+
out.controls.push(key);
|
|
2072
|
+
}
|
|
2073
|
+
return /** @type {any} */ (out);
|
|
2074
|
+
}
|
|
2075
|
+
|
|
2076
|
+
/** The properties a control's height is set by. */
|
|
2077
|
+
export const CONTROL_HEIGHT_PROPS = /^(height|min-height|block-size)$/;
|
|
2078
|
+
|
|
2079
|
+
/** The tokens that hold a control's height at each size. */
|
|
2080
|
+
export const CONTROL_SIZE_TOKEN = /^--size-element-(sm|md|lg)$/;
|
|
2081
|
+
|
|
2082
|
+
/**
|
|
2083
|
+
* The properties that size a part in the block direction: a part that sets
|
|
2084
|
+
* none of them (a layout region, which may draw a divider line) is a frame
|
|
2085
|
+
* a bar's height passes through.
|
|
2086
|
+
*/
|
|
2087
|
+
const BLOCK_BOX =
|
|
2088
|
+
/^(height|min-height|max-height|(min-|max-)?block-size|padding(-(top|bottom|block(-start|-end)?))?|margin-(top|bottom|block(-start|-end)?))$/;
|
|
2089
|
+
|
|
2090
|
+
/** The elements a control is drawn as: never a bar, nor a bar's row. */
|
|
2091
|
+
const CONTROL_TAGS = new Set([
|
|
2092
|
+
'button',
|
|
2093
|
+
'a',
|
|
2094
|
+
'input',
|
|
2095
|
+
'select',
|
|
2096
|
+
'textarea',
|
|
2097
|
+
'label',
|
|
2098
|
+
]);
|
|
2099
|
+
|
|
2100
|
+
/**
|
|
2101
|
+
* The value a part draws a property with as the census saw it: the one it
|
|
2102
|
+
* always has, else the one every condition it was drawn in agrees on; null
|
|
2103
|
+
* when it sets none (or conditions differ).
|
|
2104
|
+
* @param {PartRecord | undefined} rec
|
|
2105
|
+
* @param {string} prop
|
|
2106
|
+
* @returns {string | null}
|
|
2107
|
+
*/
|
|
2108
|
+
export function drawnValue(rec, prop) {
|
|
2109
|
+
const at = rec?.at?.[prop];
|
|
2110
|
+
if (!at) return null;
|
|
2111
|
+
if (at.always != null) return at.always;
|
|
2112
|
+
const values = [...new Set(Object.values(at))];
|
|
2113
|
+
return values.length === 1 ? values[0] : null;
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
/**
|
|
2117
|
+
* The bar rows a part holds, from the part map's `contains` relation: the
|
|
2118
|
+
* parts drawn inside it that lay their own children out in one row,
|
|
2119
|
+
* centered across its whole width (display flex, align-items center, width
|
|
2120
|
+
* 100%: the top nav in the app's header) and holding items of more than
|
|
2121
|
+
* one kind, drawn there once (a part listed inside it is a list's item,
|
|
2122
|
+
* never its bar's row: a menu's items, a side nav's items), neither of them
|
|
2123
|
+
* drawn as a control (a collapsible's trigger, an avatar's button), reached
|
|
2124
|
+
* through frames that draw no box of their own (a layout region). A part
|
|
2125
|
+
* holding such a row is laid out as a bar:
|
|
2126
|
+
* a height or a vertical padding set on it makes the bar that row fills.
|
|
2127
|
+
* @param {Record<string, PartRecord>} map
|
|
2128
|
+
* @param {string} holder
|
|
2129
|
+
* @returns {string[]}
|
|
2130
|
+
*/
|
|
2131
|
+
export function barRows(map, holder) {
|
|
2132
|
+
const inside = map[holder]?.contains ?? [];
|
|
2133
|
+
/** @param {string} p */
|
|
2134
|
+
const frame = p =>
|
|
2135
|
+
!Object.keys(map[p]?.at ?? {}).some(k => BLOCK_BOX.test(k));
|
|
2136
|
+
/** A part drawn as a control (a button, a link, a field). @param {string} p */
|
|
2137
|
+
const control = p =>
|
|
2138
|
+
(map[p]?.tags ?? []).some(t => CONTROL_TAGS.has(t.toLowerCase()));
|
|
2139
|
+
if (control(holder)) return [];
|
|
2140
|
+
const listed = new Set(map[holder]?.listed ?? []);
|
|
2141
|
+
return inside.filter(r => {
|
|
2142
|
+
const rec = map[r];
|
|
2143
|
+
if (listed.has(r) || control(r)) return false;
|
|
2144
|
+
// (A bar's row lays out items: more than one kind of part inside it,
|
|
2145
|
+
// where a menu's divider or a typeahead option's icon is one or none.)
|
|
2146
|
+
if ((rec?.contains ?? []).length < 2) return false;
|
|
2147
|
+
if (
|
|
2148
|
+
!/^(inline-)?flex$/.test(drawnValue(rec, 'display') ?? '') ||
|
|
2149
|
+
/^column/.test(drawnValue(rec, 'flex-direction') ?? '') ||
|
|
2150
|
+
drawnValue(rec, 'align-items') !== 'center' ||
|
|
2151
|
+
drawnValue(rec, 'width') !== '100%'
|
|
2152
|
+
)
|
|
2153
|
+
return false;
|
|
2154
|
+
return inside
|
|
2155
|
+
.filter(p => p !== r && (map[p]?.contains ?? []).includes(r))
|
|
2156
|
+
.every(frame);
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
2159
|
+
|
|
2160
|
+
/**
|
|
2161
|
+
* A pair of block-direction sides (top and bottom) one family of
|
|
2162
|
+
* properties gives, read from `get(prop)`: the longhands win over
|
|
2163
|
+
* `<family>-block`, which wins over the shorthand. Null sides are unset.
|
|
2164
|
+
* @param {(prop: string) => string | null} get
|
|
2165
|
+
* @param {'padding' | 'border-width'} family
|
|
2166
|
+
* @returns {[string | null, string | null]}
|
|
2167
|
+
*/
|
|
2168
|
+
export function blockSides(get, family) {
|
|
2169
|
+
const [head, tail] =
|
|
2170
|
+
family === 'padding' ? ['padding', ''] : ['border', '-width'];
|
|
2171
|
+
/** @param {string} side */
|
|
2172
|
+
const name = side => `${head}-${side}${tail}`;
|
|
2173
|
+
const whole = get(family);
|
|
2174
|
+
const all = whole ? sidesOf(family, whole) : null;
|
|
2175
|
+
const block = get(name('block'));
|
|
2176
|
+
const ends = block ? sidesOf(name('block'), block) : null;
|
|
2177
|
+
return [
|
|
2178
|
+
get(name('top')) ??
|
|
2179
|
+
get(name('block-start')) ??
|
|
2180
|
+
ends?.[name('block-start')] ??
|
|
2181
|
+
all?.[name('top')] ??
|
|
2182
|
+
null,
|
|
2183
|
+
get(name('bottom')) ??
|
|
2184
|
+
get(name('block-end')) ??
|
|
2185
|
+
ends?.[name('block-end')] ??
|
|
2186
|
+
all?.[name('bottom')] ??
|
|
2187
|
+
null,
|
|
2188
|
+
];
|
|
2189
|
+
}
|
|
2190
|
+
|
|
2191
|
+
/**
|
|
2192
|
+
* A part's measured height as it is drawn, in px: its own height or
|
|
2193
|
+
* min-height when it gives one in px, else its vertical padding and
|
|
2194
|
+
* borders around one line of its text (its line height: a length, or a
|
|
2195
|
+
* number times its font size). The theme's own values (`own(prop)`) win
|
|
2196
|
+
* over the ones Core draws it with (the part map's); `px(value)` reads a
|
|
2197
|
+
* length, tokens resolved (null when the value is no length). Null when
|
|
2198
|
+
* neither a height nor a line height reads.
|
|
2199
|
+
* @param {Record<string, PartRecord>} map
|
|
2200
|
+
* @param {string} part
|
|
2201
|
+
* @param {(prop: string) => string | null} own
|
|
2202
|
+
* @param {Record<string, unknown>} tokens the token values a var() reads
|
|
2203
|
+
* @param {(value: string) => number | null} pxOf
|
|
2204
|
+
* @returns {number | null}
|
|
2205
|
+
*/
|
|
2206
|
+
export function partHeightPx(map, part, own, tokens, pxOf) {
|
|
2207
|
+
/** A value with the tokens it reads put in. @param {string} v */
|
|
2208
|
+
const resolve = v => {
|
|
2209
|
+
let out = String(v);
|
|
2210
|
+
for (let i = 0; i < 6 && /var\(/.test(out); i++)
|
|
2211
|
+
out = out.replace(
|
|
2212
|
+
/var\(\s*(--[\w-]+)\s*(?:,\s*([^()]*))?\)/g,
|
|
2213
|
+
(_, name, fallback) => {
|
|
2214
|
+
const t = tokens[name];
|
|
2215
|
+
const one = Array.isArray(t) ? t[0] : t;
|
|
2216
|
+
return one != null ? String(one) : (fallback ?? '');
|
|
2217
|
+
},
|
|
2218
|
+
);
|
|
2219
|
+
return out.trim();
|
|
2220
|
+
};
|
|
2221
|
+
/** @param {string} v */
|
|
2222
|
+
const px = v => pxOf(resolve(v));
|
|
2223
|
+
/**
|
|
2224
|
+
* The value in effect: a property family the theme sets is all the
|
|
2225
|
+
* theme's (its shorthand covers Core's longhands), else Core's.
|
|
2226
|
+
* @param {RegExp} family
|
|
2227
|
+
*/
|
|
2228
|
+
const reader = family => {
|
|
2229
|
+
const ownsFamily = [...Object.keys(map[part]?.at ?? {}), ...FAMILY_PROPS]
|
|
2230
|
+
.filter(k => family.test(k))
|
|
2231
|
+
.some(k => own(k) != null);
|
|
2232
|
+
return (/** @type {string} */ prop) =>
|
|
2233
|
+
ownsFamily ? own(prop) : drawnValue(map[part], prop);
|
|
2234
|
+
};
|
|
2235
|
+
/** @param {string | null} v */
|
|
2236
|
+
const len = v => (v == null ? 0 : (px(v) ?? 0));
|
|
2237
|
+
const pad = blockSides(reader(/^padding/), 'padding');
|
|
2238
|
+
const border = blockSides(reader(/^border/), 'border-width');
|
|
2239
|
+
const sizes = reader(/^(min-)?height$|block-size$/);
|
|
2240
|
+
const explicit = [sizes('height'), sizes('min-height'), sizes('block-size')]
|
|
2241
|
+
.map(v => (v == null ? null : px(v)))
|
|
2242
|
+
.filter(n => n != null);
|
|
2243
|
+
const text = reader(/^(font-size|line-height)$/);
|
|
2244
|
+
/** One line of text: a length, or a number times the font size. @param {string | null} size @param {string | null} leading */
|
|
2245
|
+
const lineOf = (size, leading) => {
|
|
2246
|
+
const fontPx = px(size ?? 'var(--text-body-size, 16px)') ?? 16;
|
|
2247
|
+
const lh = resolve(leading ?? 'var(--text-body-leading)');
|
|
2248
|
+
return /^[\d.]+$/.test(lh)
|
|
2249
|
+
? Number(lh) * fontPx
|
|
2250
|
+
: lh === 'normal' || lh === ''
|
|
2251
|
+
? null
|
|
2252
|
+
: px(lh);
|
|
2253
|
+
};
|
|
2254
|
+
// Text the part's own unnamed elements draw with a type of their own (a
|
|
2255
|
+
// nav heading's title) is the line it holds; else its own text, or the
|
|
2256
|
+
// body text it inherits.
|
|
2257
|
+
const inner = Object.entries(map[part]?.inside ?? {})
|
|
2258
|
+
.filter(
|
|
2259
|
+
([tok, props]) => props.includes('line-height') && /-leading$/.test(tok),
|
|
2260
|
+
)
|
|
2261
|
+
.map(([tok]) =>
|
|
2262
|
+
lineOf(`var(${tok.replace(/-leading$/, '-size')})`, `var(${tok})`),
|
|
2263
|
+
)
|
|
2264
|
+
.filter(n => n != null);
|
|
2265
|
+
const line =
|
|
2266
|
+
text('line-height') == null && inner.length
|
|
2267
|
+
? Math.max(...inner)
|
|
2268
|
+
: lineOf(text('font-size'), text('line-height'));
|
|
2269
|
+
const box =
|
|
2270
|
+
line == null
|
|
2271
|
+
? null
|
|
2272
|
+
: len(pad[0]) + len(pad[1]) + len(border[0]) + len(border[1]) + line;
|
|
2273
|
+
const all = [...explicit, ...(box == null ? [] : [box])];
|
|
2274
|
+
return all.length ? Math.max(...all) : null;
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
/** The block-direction properties a theme may set on a part. */
|
|
2278
|
+
const FAMILY_PROPS = [
|
|
2279
|
+
'padding',
|
|
2280
|
+
'padding-block',
|
|
2281
|
+
'padding-top',
|
|
2282
|
+
'padding-bottom',
|
|
2283
|
+
'padding-block-start',
|
|
2284
|
+
'padding-block-end',
|
|
2285
|
+
'border-width',
|
|
2286
|
+
'border-block-width',
|
|
2287
|
+
'border-top-width',
|
|
2288
|
+
'border-bottom-width',
|
|
2289
|
+
'height',
|
|
2290
|
+
'min-height',
|
|
2291
|
+
'block-size',
|
|
2292
|
+
'font-size',
|
|
2293
|
+
'line-height',
|
|
2294
|
+
];
|