@astryxdesign/cli 0.7.17 → 0.7.18-canary.g6dfc0b6

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.
Files changed (213) hide show
  1. package/README.md +1 -1
  2. package/api/discover/_adapter.d.mts +7 -5
  3. package/api/discover/_adapter.mjs +12 -11
  4. package/api/doctor/_adapter.d.mts +11 -62
  5. package/api/doctor/_adapter.mjs +242 -472
  6. package/api/doctor/doctor.d.mts +1 -1
  7. package/api/doctor/doctor.mjs +1 -1
  8. package/api/doctor/theme-checks.mjs +37 -45
  9. package/api/error.d.mts +21 -0
  10. package/api/error.mjs +89 -0
  11. package/api/hook/list/list.d.mts +1 -1
  12. package/api/icon/icon.doc.mjs +1 -1
  13. package/api/icon/icon.type.mjs +1 -1
  14. package/api/icon/search/search.d.mts +4 -1
  15. package/api/icon/search/search.mjs +41 -4
  16. package/api/render/_adapter.mjs +233 -40
  17. package/api/render/render.type.d.mts +1 -1
  18. package/api/render/render.type.mjs +1 -1
  19. package/api/search/ORDERING.md +2 -2
  20. package/api/search/_candidate-score.mjs +32 -8
  21. package/api/search/_cards.json +1 -1
  22. package/api/search/_compound.d.mts +0 -1
  23. package/api/search/_compound.mjs +93 -2
  24. package/api/search/_lexical.mjs +177 -17
  25. package/api/search/_order.d.mts +3 -1
  26. package/api/search/_order.mjs +16 -5
  27. package/api/search/_result.d.mts +9 -0
  28. package/api/search/_result.mjs +10 -0
  29. package/api/search/_score.mjs +21 -3
  30. package/api/swizzle/_moduleGraph.d.mts +8 -0
  31. package/api/swizzle/_moduleGraph.mjs +61 -3
  32. package/api/template/copy/copy.mjs +5 -3
  33. package/api/theme/_adapter.mjs +48 -12
  34. package/api/theme/build/build.d.mts +4 -0
  35. package/api/theme/build/build.mjs +69 -18
  36. package/api/theme/build/style-keys.mjs +4 -5
  37. package/api/theme/build/theme-object.mjs +5 -0
  38. package/api/theme/palette/generate/color.d.mts +47 -0
  39. package/api/theme/palette/generate/color.mjs +58 -1
  40. package/api/theme/palette/generate/derive-look.d.mts +293 -0
  41. package/api/theme/palette/generate/derive-look.mjs +1362 -0
  42. package/api/theme/palette/generate/editor-look.d.mts +62 -0
  43. package/api/theme/palette/generate/editor-look.mjs +550 -0
  44. package/api/theme/palette/generate/mapping.d.mts +94 -9
  45. package/api/theme/palette/generate/mapping.mjs +94 -22
  46. package/api/theme-edit/_adapter.mjs +10 -1
  47. package/api/theme-edit/_catalog.d.mts +13 -13
  48. package/api/theme-edit/_catalog.mjs +38 -16
  49. package/api/theme-edit/_check.d.mts +82 -6
  50. package/api/theme-edit/_check.mjs +1230 -223
  51. package/api/theme-edit/_color.d.mts +74 -0
  52. package/api/theme-edit/_color.mjs +168 -3
  53. package/api/theme-edit/_compiler.d.mts +3 -5
  54. package/api/theme-edit/_compiler.mjs +122 -23
  55. package/api/theme-edit/_context.d.mts +46 -5
  56. package/api/theme-edit/_context.mjs +97 -49
  57. package/api/theme-edit/_css.d.mts +11 -0
  58. package/api/theme-edit/_css.mjs +40 -0
  59. package/api/theme-edit/_edit.d.mts +13 -0
  60. package/api/theme-edit/_edit.mjs +1450 -128
  61. package/api/theme-edit/_how-commands.d.mts +12 -0
  62. package/api/theme-edit/_how-commands.mjs +96 -14
  63. package/api/theme-edit/_how-question.d.mts +73 -29
  64. package/api/theme-edit/_how-question.mjs +8131 -1209
  65. package/api/theme-edit/_how-sides.d.mts +22 -0
  66. package/api/theme-edit/_how-sides.mjs +173 -0
  67. package/api/theme-edit/_how-steps.d.mts +42 -0
  68. package/api/theme-edit/_how-steps.mjs +208 -0
  69. package/api/theme-edit/_how-values.d.mts +29 -0
  70. package/api/theme-edit/_how-values.mjs +111 -0
  71. package/api/theme-edit/_how-words.d.mts +15 -0
  72. package/api/theme-edit/_how-words.mjs +239 -0
  73. package/api/theme-edit/_how.d.mts +1 -1
  74. package/api/theme-edit/_how.mjs +412 -37
  75. package/api/theme-edit/_missed.d.mts +2 -1
  76. package/api/theme-edit/_missed.mjs +125 -13
  77. package/api/theme-edit/_normal.d.mts +5 -3
  78. package/api/theme-edit/_normal.mjs +54 -14
  79. package/api/theme-edit/_palette.d.mts +204 -4
  80. package/api/theme-edit/_palette.mjs +901 -25
  81. package/api/theme-edit/_part-pieces.d.mts +54 -0
  82. package/api/theme-edit/_part-pieces.mjs +179 -0
  83. package/api/theme-edit/_part-words.mjs +33 -5
  84. package/api/theme-edit/_parts.d.mts +133 -0
  85. package/api/theme-edit/_parts.mjs +599 -10
  86. package/api/theme-edit/_picture-traits.d.mts +259 -0
  87. package/api/theme-edit/_picture-traits.mjs +1030 -0
  88. package/api/theme-edit/_preview.d.mts +84 -4
  89. package/api/theme-edit/_preview.mjs +260 -24
  90. package/api/theme-edit/_project.d.mts +14 -4
  91. package/api/theme-edit/_project.mjs +95 -26
  92. package/api/theme-edit/_set-line.d.mts +29 -0
  93. package/api/theme-edit/_set-line.mjs +100 -0
  94. package/api/theme-edit/_settings.d.mts +625 -28
  95. package/api/theme-edit/_settings.mjs +4587 -880
  96. package/api/theme-edit/_tables.d.mts +25 -1
  97. package/api/theme-edit/_tables.mjs +115 -11
  98. package/api/theme-edit/_text-looks.d.mts +78 -0
  99. package/api/theme-edit/_text-looks.mjs +376 -0
  100. package/api/theme-edit/_vet.d.mts +3 -26
  101. package/api/theme-edit/_vet.mjs +5 -89
  102. package/api/theme-edit/how/how.d.mts +1 -1
  103. package/api/theme-edit/how/how.mjs +1 -1
  104. package/api/theme-edit/theme-edit.type.d.mts +54 -1
  105. package/api/theme-edit/theme-edit.type.mjs +17 -2
  106. package/api/theme-edit/themeEditHow.doc.mjs +3 -3
  107. package/api/theme-edit/themeEditNew.doc.mjs +4 -0
  108. package/api/theme-edit/themeEditSet.doc.mjs +6 -2
  109. package/api/theme-edit/themeEditShow.doc.mjs +4 -0
  110. package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
  111. package/assets/component-list.generated.json +1 -1
  112. package/assets/docs/author-a-theme.doc.mjs +7 -4
  113. package/assets/docs/tree/export-pages.doc.mjs +1 -1
  114. package/assets/docs/tree/icon-sets.doc.mjs +1 -1
  115. package/assets/docs/use-a-theme.doc.mjs +89 -17
  116. package/assets/docs-routes.generated.json +1 -1
  117. package/assets/docs.generated.json +2 -2
  118. package/assets/icons/definitions/article.doc.mjs +9 -0
  119. package/assets/icons/template-icons.json +5 -0
  120. package/assets/search-catalog.generated.json +2 -2
  121. package/assets/self-audit.generated.json +1 -1
  122. package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
  123. package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
  124. package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
  125. package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
  126. package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
  127. package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
  128. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
  129. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
  130. package/assets/templates/components.generated.json +1 -1
  131. package/assets/templates/pages/ide/page.tsx +5 -10
  132. package/assets/templates/pages/payment-form/page.tsx +16 -60
  133. package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
  134. package/authoring/debug/parse.d.mts +1 -1
  135. package/authoring/doctypes/_schema.d.mts +13 -13
  136. package/authoring/gap-report/parse.d.mts +1 -1
  137. package/clients/cli/build-id.generated.json +1 -1
  138. package/clients/cli/commands/ensure-core-built.mjs +17 -10
  139. package/clients/cli/commands/experimental/theme.mjs +46 -6
  140. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  141. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  142. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
  143. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
  144. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  145. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  146. package/clients/cli/commands/hook.mjs +7 -0
  147. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  148. package/clients/cli/index.mjs +6 -2
  149. package/clients/cli/lib/hook-format.mjs +41 -1
  150. package/clients/cli/lib/json-shim.mjs +34 -14
  151. package/clients/cli/lib/other-cli-words.mjs +7 -0
  152. package/clients/cli/lib/unknown-command.mjs +345 -46
  153. package/clients/cli/manifest.generated.json +1 -1
  154. package/foundation/agent-docs/agent-docs.d.mts +11 -2
  155. package/foundation/agent-docs/agent-docs.mjs +51 -8
  156. package/foundation/config/project.d.mts +11 -1
  157. package/foundation/config/project.mjs +11 -2
  158. package/foundation/discovery/component-replacement.d.mts +5 -8
  159. package/foundation/discovery/component-replacement.mjs +12 -14
  160. package/foundation/discovery/core-augmentation-points.d.mts +35 -0
  161. package/foundation/discovery/core-augmentation-points.mjs +410 -9
  162. package/foundation/discovery/core-elements.d.mts +6 -0
  163. package/foundation/discovery/core-elements.mjs +10 -2
  164. package/foundation/discovery/core-prop-types.d.mts +5 -0
  165. package/foundation/discovery/core-prop-types.mjs +10 -3
  166. package/foundation/discovery/core-props.d.mts +8 -0
  167. package/foundation/discovery/core-props.mjs +29 -13
  168. package/foundation/discovery/official-list.d.mts +17 -0
  169. package/foundation/discovery/official-list.mjs +77 -0
  170. package/foundation/discovery/unknown-core-props.d.mts +130 -0
  171. package/foundation/discovery/unknown-core-props.mjs +601 -0
  172. package/foundation/discovery/written-prop-values.d.mts +35 -0
  173. package/foundation/discovery/written-prop-values.mjs +258 -0
  174. package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
  175. package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
  176. package/foundation/fs/package-name.d.mts +10 -0
  177. package/foundation/fs/package-name.mjs +37 -0
  178. package/foundation/fs/project-source-files.d.mts +27 -0
  179. package/foundation/fs/project-source-files.mjs +115 -0
  180. package/foundation/fs/project-sources.d.mts +25 -0
  181. package/foundation/fs/project-sources.mjs +83 -0
  182. package/foundation/fs/read-record.d.mts +18 -0
  183. package/foundation/fs/read-record.mjs +36 -2
  184. package/foundation/integrations/integration-warnings.d.mts +39 -7
  185. package/foundation/integrations/integration-warnings.mjs +141 -19
  186. package/foundation/integrations/missing-dependency.d.mts +11 -0
  187. package/foundation/integrations/missing-dependency.mjs +20 -5
  188. package/foundation/release/folder-lock.d.mts +5 -2
  189. package/foundation/release/folder-lock.mjs +9 -3
  190. package/foundation/release/notices.mjs +2 -8
  191. package/foundation/render/cut-short.d.mts +8 -2
  192. package/foundation/render/cut-short.mjs +50 -5
  193. package/foundation/render/drawn-contrast.d.mts +38 -0
  194. package/foundation/render/drawn-contrast.mjs +237 -0
  195. package/foundation/render/file-header.mjs +4 -0
  196. package/foundation/render/layers.d.mts +2 -1
  197. package/foundation/render/layers.mjs +22 -1
  198. package/foundation/render/page-worker.mjs +83 -18
  199. package/foundation/render/part-boxes.d.mts +27 -0
  200. package/foundation/render/part-boxes.mjs +45 -0
  201. package/foundation/render/picture-chrome.mjs +36 -4
  202. package/foundation/render/picture-playwright.mjs +26 -2
  203. package/foundation/render/picture-window.d.mts +29 -2
  204. package/foundation/render/picture-window.mjs +99 -1
  205. package/foundation/render/render-page.d.mts +39 -6
  206. package/foundation/render/render-page.mjs +26 -10
  207. package/foundation/render/ts-paths.mjs +2 -1
  208. package/foundation/response/error-codes.doc.mjs +1 -1
  209. package/foundation/response/error-codes.mjs +1 -1
  210. package/foundation/response/response-types.doc.mjs +1 -1
  211. package/foundation/text/written-string.d.mts +4 -1
  212. package/foundation/text/written-string.mjs +4 -1
  213. package/package.json +8 -7
@@ -1,6 +1,17 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * The missing package, the package that needs it and the importing file,
6
+ * when that package declares the missing one: a broken install.
7
+ * @param {string} message
8
+ * @returns {{name: string, requiredBy: string, importer: string} | null}
9
+ */
10
+ export function brokenInstall(message: string): {
11
+ name: string;
12
+ requiredBy: string;
13
+ importer: string;
14
+ } | null;
4
15
  /**
5
16
  * The missing package's name when the package that imports it declares it.
6
17
  * @param {string} message
@@ -14,9 +14,12 @@
14
14
  * design, so a manifest that needs either has a packaging bug, which
15
15
  * reinstalling does not clear. A package listed both as a dependency and
16
16
  * as an optional one is optional, as npm reads it.
17
+ * `brokenInstall(message)`: the same finding with the package that needs
18
+ * it and the importing file.
17
19
  * @position Read by the project (foundation/config/project.mjs) to tell an
18
20
  * install the user can repair from a dependency's own packaging bug, which
19
- * stays out of the project's issues.
21
+ * stays out of the project's issues, and by the API's broken-install
22
+ * refusal (api/error.mjs).
20
23
  */
21
24
 
22
25
  import * as fs from 'node:fs';
@@ -73,11 +76,12 @@ function parse(message) {
73
76
  }
74
77
 
75
78
  /**
76
- * The missing package's name when the package that imports it declares it.
79
+ * The missing package, the package that needs it and the importing file,
80
+ * when that package declares the missing one: a broken install.
77
81
  * @param {string} message
78
- * @returns {string | null}
82
+ * @returns {{name: string, requiredBy: string, importer: string} | null}
79
83
  */
80
- export function missingDeclaredDependency(message) {
84
+ export function brokenInstall(message) {
81
85
  const found = parse(message);
82
86
  if (!found) return null;
83
87
  let dir = path.dirname(found.importer);
@@ -87,7 +91,9 @@ export function missingDeclaredDependency(message) {
87
91
  try {
88
92
  const pkg = JSON.parse(fs.readFileSync(file, 'utf-8'));
89
93
  if (typeof pkg?.name === 'string') {
90
- return requires(pkg, found.name) ? found.name : null;
94
+ return requires(pkg, found.name)
95
+ ? {name: found.name, requiredBy: pkg.name, importer: found.importer}
96
+ : null;
91
97
  }
92
98
  } catch {
93
99
  return null;
@@ -98,3 +104,12 @@ export function missingDeclaredDependency(message) {
98
104
  dir = parent;
99
105
  }
100
106
  }
107
+
108
+ /**
109
+ * The missing package's name when the package that imports it declares it.
110
+ * @param {string} message
111
+ * @returns {string | null}
112
+ */
113
+ export function missingDeclaredDependency(message) {
114
+ return brokenInstall(message)?.name ?? null;
115
+ }
@@ -16,11 +16,14 @@ export function stillHolds(): void;
16
16
  * @template T
17
17
  * @param {string} lockDir
18
18
  * @param {() => Promise<T>} fn
19
- * @param {{waitMs?: number, onBusy: (owner: any, heldSeconds: number | null) => never}} options
19
+ * @param {{waitMs?: number, silentMs?: number, onBusy: (owner: any, heldSeconds: number | null) => never}} options
20
+ * `silentMs`: how long a record may stand unrenewed before a holder that
21
+ * does not run here is taken over ({@link SILENT_MS})
20
22
  * @returns {Promise<T>}
21
23
  */
22
- export function withFolderLock<T>(lockDir: string, fn: () => Promise<T>, { waitMs, onBusy }: {
24
+ export function withFolderLock<T>(lockDir: string, fn: () => Promise<T>, { waitMs, silentMs, onBusy }: {
23
25
  waitMs?: number;
26
+ silentMs?: number;
24
27
  onBusy: (owner: any, heldSeconds: number | null) => never;
25
28
  }): Promise<T>;
26
29
  /** How long a held lock's record may stand unrenewed before it is taken over. */
@@ -111,10 +111,16 @@ const readOwner = file => {
111
111
  * @template T
112
112
  * @param {string} lockDir
113
113
  * @param {() => Promise<T>} fn
114
- * @param {{waitMs?: number, onBusy: (owner: any, heldSeconds: number | null) => never}} options
114
+ * @param {{waitMs?: number, silentMs?: number, onBusy: (owner: any, heldSeconds: number | null) => never}} options
115
+ * `silentMs`: how long a record may stand unrenewed before a holder that
116
+ * does not run here is taken over ({@link SILENT_MS})
115
117
  * @returns {Promise<T>}
116
118
  */
117
- export async function withFolderLock(lockDir, fn, {waitMs = 30_000, onBusy}) {
119
+ export async function withFolderLock(
120
+ lockDir,
121
+ fn,
122
+ {waitMs = 30_000, silentMs = SILENT_MS, onBusy},
123
+ ) {
118
124
  const ownerFile = path.join(lockDir, 'owner.json');
119
125
  /** @returns {number | null} seconds since the holder took the lock */
120
126
  const held = () => {
@@ -141,7 +147,7 @@ export async function withFolderLock(lockDir, fn, {waitMs = 30_000, onBusy}) {
141
147
  const judged = lockIdentity(lockDir);
142
148
  if (
143
149
  judged &&
144
- foreignLockIsSilent(lockDir, Date.now(), SILENT_MS) &&
150
+ foreignLockIsSilent(lockDir, Date.now(), silentMs) &&
145
151
  !aliveHere(readOwner(ownerFile))
146
152
  ) {
147
153
  takeOver(lockDir, judged);
@@ -75,6 +75,7 @@ import {
75
75
  readReleaseFacts,
76
76
  } from './project.mjs';
77
77
  import {samePath} from '../fs/path-compare.mjs';
78
+ import {readOfficialList} from '../discovery/official-list.mjs';
78
79
  import {updateNoticesOff} from './update-notice-env.mjs';
79
80
  import {binStartedRun} from './run-context.mjs';
80
81
  import {installGuidanceFor} from '../env/cli-command.mjs';
@@ -527,14 +528,7 @@ function officialPackages() {
527
528
  /** @type {any} */
528
529
  let list;
529
530
  try {
530
- // Built here, not at load: paths.mjs and this module load each other.
531
- const file = path.join(
532
- CLI_ROOT,
533
- 'assets',
534
- 'discover',
535
- 'official-packages.json',
536
- );
537
- list = JSON.parse(fs.readFileSync(file, 'utf8'));
531
+ list = readOfficialList();
538
532
  } catch {
539
533
  return [];
540
534
  }
@@ -15,21 +15,27 @@
15
15
  * narrower than the word) comes back too, the word as its `text`, with
16
16
  * `broken`; a word broken where it may break (at a hyphen, a slash, a soft
17
17
  * hyphen) is not counted.
18
+ * A text that runs past the side of its own box onto the text of a box
19
+ * beside it (weekday names wider than their calendar column) comes back
20
+ * too, with `overlaps`. Boxes placed out of the flow (absolute or fixed)
21
+ * are left out: they overlap on purpose.
18
22
  * Runs in the page: it uses nothing from outside its own body.
19
- * @returns {Array<{part: string | null, text: string, whole: boolean, broken?: boolean}>}
23
+ * @returns {Array<{part: string | null, text: string, whole: boolean, broken?: boolean, overlaps?: boolean}>}
20
24
  */
21
25
  export function cutShortText(): Array<{
22
26
  part: string | null;
23
27
  text: string;
24
28
  whole: boolean;
25
29
  broken?: boolean;
30
+ overlaps?: boolean;
26
31
  }>;
27
32
  /**
28
33
  * @file The text a picture's page draws cut short, measured in the page.
29
34
  * @input None: `cutShortText` runs in the page the picture is taken of.
30
35
  * @output `cutShortText`: each text the browser draws cut short (an ellipsis
31
36
  * or a line clamp, or text drawn past the side of a box that clips it),
32
- * and each word it breaks across two lines inside the word (`broken`),
37
+ * each word it breaks across two lines inside the word (`broken`), and
38
+ * each text drawn over its neighbor's text (`overlaps`),
33
39
  * with the part it sits in and whether keeping that part's width
34
40
  * (`flex-shrink: 0` on it, the line the editor offers) draws it whole;
35
41
  * `CUT_SHORT_PREFIX`, the line prefix a picture script prints it after.
@@ -5,7 +5,8 @@
5
5
  * @input None: `cutShortText` runs in the page the picture is taken of.
6
6
  * @output `cutShortText`: each text the browser draws cut short (an ellipsis
7
7
  * or a line clamp, or text drawn past the side of a box that clips it),
8
- * and each word it breaks across two lines inside the word (`broken`),
8
+ * each word it breaks across two lines inside the word (`broken`), and
9
+ * each text drawn over its neighbor's text (`overlaps`),
9
10
  * with the part it sits in and whether keeping that part's width
10
11
  * (`flex-shrink: 0` on it, the line the editor offers) draws it whole;
11
12
  * `CUT_SHORT_PREFIX`, the line prefix a picture script prints it after.
@@ -33,8 +34,12 @@ export const CUT_SHORT_PREFIX = 'astryx-cut-short:';
33
34
  * narrower than the word) comes back too, the word as its `text`, with
34
35
  * `broken`; a word broken where it may break (at a hyphen, a slash, a soft
35
36
  * hyphen) is not counted.
37
+ * A text that runs past the side of its own box onto the text of a box
38
+ * beside it (weekday names wider than their calendar column) comes back
39
+ * too, with `overlaps`. Boxes placed out of the flow (absolute or fixed)
40
+ * are left out: they overlap on purpose.
36
41
  * Runs in the page: it uses nothing from outside its own body.
37
- * @returns {Array<{part: string | null, text: string, whole: boolean, broken?: boolean}>}
42
+ * @returns {Array<{part: string | null, text: string, whole: boolean, broken?: boolean, overlaps?: boolean}>}
38
43
  */
39
44
  export function cutShortText() {
40
45
  /** @param {Element} el */
@@ -124,13 +129,48 @@ export function cutShortText() {
124
129
  }
125
130
  return out;
126
131
  };
127
- /** @type {Array<{el: HTMLElement, part: string | null, text: string, broken?: boolean}>} */
132
+ /** Whether a box sits in the flow (not absolute or fixed). @param {Element} el */
133
+ const inFlow = el =>
134
+ !/^(?:absolute|fixed)$/.test(getComputedStyle(el).position);
135
+ /** The boxes of a node's text, one for each line. @param {Node} node */
136
+ const textBoxes = node => {
137
+ const range = document.createRange();
138
+ range.selectNodeContents(node);
139
+ return [...range.getClientRects()].filter(r => r.width > 0 && r.height > 0);
140
+ };
141
+ /**
142
+ * Own text drawn past the side of its own box and over the text of a box
143
+ * beside it (a sibling in the flow).
144
+ * @param {HTMLElement} el
145
+ */
146
+ const overlapping = el => {
147
+ if (!ownText(el) || !inFlow(el) || !el.parentElement) return false;
148
+ const box = el.getBoundingClientRect();
149
+ const own = textBoxes(el);
150
+ // Any reach past the box counts: letters a fraction of a pixel into the
151
+ // next box already touch its text.
152
+ if (!own.some(t => t.left < box.left - 0.1 || t.right > box.right + 0.1))
153
+ return false;
154
+ for (const sib of el.parentElement.children) {
155
+ if (sib === el || !inFlow(sib) || !drawn(sib)) continue;
156
+ for (const s of textBoxes(sib))
157
+ for (const t of own) {
158
+ const w = Math.min(t.right, s.right) - Math.max(t.left, s.left);
159
+ const h = Math.min(t.bottom, s.bottom) - Math.max(t.top, s.top);
160
+ if (w > 0.1 && h > 1) return true;
161
+ }
162
+ }
163
+ return false;
164
+ };
165
+ /** @type {Array<{el: HTMLElement, part: string | null, text: string, broken?: boolean, overlaps?: boolean}>} */
128
166
  const found = [];
129
167
  for (const el of document.body.querySelectorAll('*')) {
130
168
  if (!(el instanceof HTMLElement)) continue;
131
169
  const text = (el.textContent ?? '').replace(/\s+/g, ' ').trim();
132
170
  if (!text || !drawn(el)) continue;
133
171
  if (cutShort(el)) found.push({el, part: partOf(el), text});
172
+ else if (overlapping(el))
173
+ found.push({el, part: partOf(el), text, overlaps: true});
134
174
  else
135
175
  for (const word of brokenWords(el))
136
176
  found.push({el, part: partOf(el), text: word, broken: true});
@@ -150,15 +190,20 @@ export function cutShortText() {
150
190
  found
151
191
  .filter(f => f.part === part)
152
192
  .every(f =>
153
- f.broken ? !brokenWords(f.el).includes(f.text) : !cutShort(f.el),
193
+ f.broken
194
+ ? !brokenWords(f.el).includes(f.text)
195
+ : f.overlaps
196
+ ? !overlapping(f.el)
197
+ : !cutShort(f.el),
154
198
  ),
155
199
  );
156
200
  keep.remove();
157
201
  }
158
- return found.map(({part, text, broken}) => ({
202
+ return found.map(({part, text, broken, overlaps}) => ({
159
203
  part,
160
204
  text,
161
205
  whole: whole.get(part) ?? false,
162
206
  ...(broken ? {broken: true} : {}),
207
+ ...(overlaps ? {overlaps: true} : {}),
163
208
  }));
164
209
  }
@@ -0,0 +1,38 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * Each text the page draws too faint to read: its own color, composited
6
+ * over what is drawn behind it (the fills of the boxes around it, from the
7
+ * page up), under 4.5:1, or 3:1 for large text (24px, or 18.66px bold).
8
+ * Text that is not drawn (no box, hidden), text in a disabled control or
9
+ * under a box drawn see-through (a disabled look), text in the theme's
10
+ * disabled or placeholder color (which needs no 4.5:1), and text over an
11
+ * image, a picture or a gradient (no one color behind it) are left out. `part` is the
12
+ * nearest Astryx part the text sits in (its `astryx-<part>` class); text in
13
+ * no part (a sheet's own labels) is left out. One entry for each part,
14
+ * text and pair of colors.
15
+ * Runs in the page: it uses nothing from outside its own body.
16
+ * @returns {Array<{part: string, text: string, ratio: number, fg: string, bg: string}>}
17
+ */
18
+ export function lowContrastText(): Array<{
19
+ part: string;
20
+ text: string;
21
+ ratio: number;
22
+ fg: string;
23
+ bg: string;
24
+ }>;
25
+ /**
26
+ * @file The text a picture's page draws too faint to read, measured in the
27
+ * page.
28
+ * @input None: `lowContrastText` runs in the page the picture is taken of.
29
+ * @output `lowContrastText`: each text the browser draws under the contrast
30
+ * text needs (4.5:1, or 3:1 when large), with the part it sits in and the
31
+ * two colors as drawn; `LOW_CONTRAST_PREFIX`, the line prefix a picture
32
+ * script prints it after.
33
+ * @position run by picture-chrome.mjs and picture-playwright.mjs once the
34
+ * page is drawn as the picture shows it; read back by `screenshot` in
35
+ * api/theme-edit/_preview.mjs from the script's stdout
36
+ */
37
+ /** The line prefix a picture script prints the measurement after. */
38
+ export const LOW_CONTRAST_PREFIX: "astryx-low-contrast:";
@@ -0,0 +1,237 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The text a picture's page draws too faint to read, measured in the
5
+ * page.
6
+ * @input None: `lowContrastText` runs in the page the picture is taken of.
7
+ * @output `lowContrastText`: each text the browser draws under the contrast
8
+ * text needs (4.5:1, or 3:1 when large), with the part it sits in and the
9
+ * two colors as drawn; `LOW_CONTRAST_PREFIX`, the line prefix a picture
10
+ * script prints it after.
11
+ * @position run by picture-chrome.mjs and picture-playwright.mjs once the
12
+ * page is drawn as the picture shows it; read back by `screenshot` in
13
+ * api/theme-edit/_preview.mjs from the script's stdout
14
+ */
15
+
16
+ /* global document, getComputedStyle -- lowContrastText runs in the page */
17
+
18
+ /** The line prefix a picture script prints the measurement after. */
19
+ export const LOW_CONTRAST_PREFIX = 'astryx-low-contrast:';
20
+
21
+ /**
22
+ * Each text the page draws too faint to read: its own color, composited
23
+ * over what is drawn behind it (the fills of the boxes around it, from the
24
+ * page up), under 4.5:1, or 3:1 for large text (24px, or 18.66px bold).
25
+ * Text that is not drawn (no box, hidden), text in a disabled control or
26
+ * under a box drawn see-through (a disabled look), text in the theme's
27
+ * disabled or placeholder color (which needs no 4.5:1), and text over an
28
+ * image, a picture or a gradient (no one color behind it) are left out. `part` is the
29
+ * nearest Astryx part the text sits in (its `astryx-<part>` class); text in
30
+ * no part (a sheet's own labels) is left out. One entry for each part,
31
+ * text and pair of colors.
32
+ * Runs in the page: it uses nothing from outside its own body.
33
+ * @returns {Array<{part: string, text: string, ratio: number, fg: string, bg: string}>}
34
+ */
35
+ export function lowContrastText() {
36
+ /** @param {string} v @returns {[number, number, number, number] | null} */
37
+ const rgba = v => {
38
+ const m =
39
+ /^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/.exec(
40
+ v.trim(),
41
+ );
42
+ const c =
43
+ /^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+%?))?\s*\)$/.exec(
44
+ v.trim(),
45
+ );
46
+ /** @param {string | undefined} a */
47
+ const alpha = a =>
48
+ a == null
49
+ ? 1
50
+ : a.endsWith('%')
51
+ ? Number(a.slice(0, -1)) / 100
52
+ : Number(a);
53
+ if (m) return [Number(m[1]), Number(m[2]), Number(m[3]), alpha(m[4])];
54
+ if (c)
55
+ return [
56
+ Number(c[1]) * 255,
57
+ Number(c[2]) * 255,
58
+ Number(c[3]) * 255,
59
+ alpha(c[4]),
60
+ ];
61
+ return null;
62
+ };
63
+ /** @param {number[]} top @param {number[]} under */
64
+ const over = (top, under) =>
65
+ [0, 1, 2].map(i => top[i] * top[3] + under[i] * (1 - top[3]));
66
+ /** @param {number[]} c */
67
+ const lum = c => {
68
+ const [r, g, b] = c.map(v => {
69
+ const s = v / 255;
70
+ return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
71
+ });
72
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
73
+ };
74
+ /** @param {number[]} a @param {number[]} b */
75
+ const ratio = (a, b) => {
76
+ const [x, y] = [lum(a), lum(b)].sort((p, q) => q - p);
77
+ return (x + 0.05) / (y + 0.05);
78
+ };
79
+ /** @param {number[]} c */
80
+ const hex = c =>
81
+ `#${c.map(v => Math.round(v).toString(16).padStart(2, '0')).join('')}`;
82
+ /** @param {Element} el */
83
+ const partOf = el => {
84
+ for (let a = /** @type {Element | null} */ (el); a; a = a.parentElement) {
85
+ const named = [...a.classList].find(
86
+ c => c.startsWith('astryx-') && !c.startsWith('astryx-theme'),
87
+ );
88
+ if (named) return named.slice('astryx-'.length);
89
+ }
90
+ return null;
91
+ };
92
+ /** Whether two rectangles overlap. @param {DOMRect} p @param {DOMRect} q */
93
+ const meet = (p, q) =>
94
+ p.left < q.right &&
95
+ q.left < p.right &&
96
+ p.top < q.bottom &&
97
+ q.top < p.bottom;
98
+ /**
99
+ * What is drawn behind an element's text, as one color, or null: a box
100
+ * around it see-through or hidden, disabled, or drawn with an image, or
101
+ * an image or picture under the text before an opaque fill.
102
+ * @param {Element} el
103
+ */
104
+ const behind = el => {
105
+ /** @type {Array<[number, number, number, number]>} */
106
+ const fills = [];
107
+ for (let a = /** @type {Element | null} */ (el); a; a = a.parentElement) {
108
+ const cs = getComputedStyle(a);
109
+ if (
110
+ Number(cs.opacity) < 1 ||
111
+ a.matches(':disabled, [aria-disabled="true"], [inert]')
112
+ )
113
+ return null;
114
+ if (cs.display === 'contents') continue;
115
+ if (a !== document.documentElement) {
116
+ const r = a.getBoundingClientRect();
117
+ if (r.width < 2 || r.height < 2 || cs.visibility !== 'visible')
118
+ return null;
119
+ }
120
+ if (cs.backgroundImage && cs.backgroundImage !== 'none') return null;
121
+ const f = rgba(cs.backgroundColor);
122
+ if (f && f[3] > 0) fills.push(f);
123
+ if (f && f[3] >= 1) break;
124
+ }
125
+ let under = [255, 255, 255];
126
+ for (const f of fills.reverse()) under = over(f, under);
127
+ return under;
128
+ };
129
+ /**
130
+ * Whether an image, a picture or a gradient is drawn under an element's
131
+ * text from a box beside it (media under an overlay's scrim): then no one
132
+ * color is behind the text.
133
+ * @param {Element} el
134
+ */
135
+ /**
136
+ * The page's images, pictures and gradients with their boxes, read once
137
+ * when first asked: a page has many texts and few of them fail.
138
+ * @type {Array<[Element, DOMRect]> | null}
139
+ */
140
+ let media = null;
141
+ /** @param {Element} el */
142
+ const overImage = el => {
143
+ media ??= [...document.querySelectorAll('body *')]
144
+ .filter(m => {
145
+ if (m.matches('img, picture, video, canvas, svg image')) return true;
146
+ const bgi = getComputedStyle(m).backgroundImage;
147
+ return Boolean(bgi) && bgi !== 'none';
148
+ })
149
+ .map(
150
+ m => /** @type {[Element, DOMRect]} */ ([m, m.getBoundingClientRect()]),
151
+ );
152
+ const box = el.getBoundingClientRect();
153
+ return media.some(
154
+ ([m, r]) => !m.contains(el) && !el.contains(m) && meet(r, box),
155
+ );
156
+ };
157
+ /**
158
+ * Whether a color is the theme's disabled or placeholder text color where
159
+ * an element sits (read from a probe there, as the page resolves it).
160
+ * @param {Element} el @param {number[]} c
161
+ */
162
+ const exempt = (el, c) => {
163
+ // (One probe for each theme scope and color: the tokens are the
164
+ // scope's.)
165
+ const scope = el.closest('[data-astryx-theme], [data-theme]');
166
+ const key = hex(c);
167
+ const known = exemptSeen.get(scope)?.get(key);
168
+ if (known != null) return known;
169
+ const said = exemptAt(el, c);
170
+ if (!exemptSeen.has(scope)) exemptSeen.set(scope, new Map());
171
+ /** @type {Map<string, boolean>} */ (exemptSeen.get(scope)).set(key, said);
172
+ return said;
173
+ };
174
+ /** @type {Map<Element | null, Map<string, boolean>>} */
175
+ const exemptSeen = new Map();
176
+ /** @param {Element} el @param {number[]} c */
177
+ const exemptAt = (el, c) => {
178
+ const probe = document.createElement('span');
179
+ el.appendChild(probe);
180
+ try {
181
+ return [
182
+ '--color-text-disabled',
183
+ '--color-icon-disabled',
184
+ '--color-text-placeholder',
185
+ ].some(t => {
186
+ // (A token the page does not set gives the fallback, never the
187
+ // color the probe would inherit.)
188
+ probe.style.color = `var(${t}, rgb(1, 2, 3))`;
189
+ const v = rgba(getComputedStyle(probe).color);
190
+ return (
191
+ v != null &&
192
+ !(v[0] === 1 && v[1] === 2 && v[2] === 3) &&
193
+ v.slice(0, 3).every((x, i) => Math.abs(x - c[i]) < 1)
194
+ );
195
+ });
196
+ } finally {
197
+ probe.remove();
198
+ }
199
+ };
200
+ /** @type {Map<string, {part: string, text: string, ratio: number, fg: string, bg: string}>} */
201
+ const found = new Map();
202
+ for (const el of document.querySelectorAll('body *')) {
203
+ const text = [...el.childNodes]
204
+ .filter(n => n.nodeType === 3)
205
+ .map(n => (n.textContent ?? '').trim())
206
+ .join(' ')
207
+ .trim();
208
+ if (!text) continue;
209
+ const part = partOf(el);
210
+ if (!part) continue;
211
+ const cs = getComputedStyle(el);
212
+ const fg = rgba(cs.color);
213
+ if (!fg || fg[3] === 0) continue;
214
+ const bg = behind(el);
215
+ if (!bg) continue;
216
+ const shown = over(fg, bg);
217
+ const r = ratio(shown, bg);
218
+ const size = parseFloat(cs.fontSize);
219
+ const large = size >= 24 || (size >= 18.66 && Number(cs.fontWeight) >= 700);
220
+ if (r >= (large ? 3 : 4.5)) continue;
221
+ // (The same text in the same colors is reported once. A copy left out,
222
+ // one over a picture or in a disabled color, says nothing of a later
223
+ // copy drawn faint on a plain ground: only a reported one is skipped.)
224
+ const key = `${part}\u0000${text}\u0000${hex(shown)}\u0000${hex(bg)}`;
225
+ if (found.has(key)) continue;
226
+ if (exempt(el, fg) || overImage(el)) continue;
227
+ found.set(key, {
228
+ part,
229
+ text: text.slice(0, 40),
230
+ ratio: Math.floor(r * 100) / 100,
231
+ fg: hex(shown),
232
+ bg: hex(bg),
233
+ });
234
+ if (found.size >= 60) break;
235
+ }
236
+ return [...found.values()];
237
+ }
@@ -91,6 +91,10 @@ export function headerNote(facts) {
91
91
  ' command with the folder it wrote:',
92
92
  ` ${run} experimental export ${shellArg(facts.restored)} --out ${file}${title}`,
93
93
  ...(facts.title !== undefined && !quotable ? [' The page was rendered with --title; step 1 prints the command with it.'] : []),
94
+ `To work offline later, install the CLI for your computer while online (${run} docs global/install-once):`,
95
+ ` npm install --global @astryxdesign/cli@${facts.cli ?? 'latest'}`,
96
+ ' Then, still online, run steps 1 and 3 once as astryx, so it keeps the Core a render needs.',
97
+ ' Offline, run the same commands as astryx: npx cannot fetch the CLI without a network.',
94
98
  `If you have the project, edit ${facts.page} there instead, and render it in the same way.`,
95
99
  "Inside a project, the project's own CLI answers these commands. A project CLI older than",
96
100
  `${facts.cli ?? 'the one that rendered this file'} writes the page without this note; to keep the note, update that CLI first:`,
@@ -14,7 +14,8 @@ export function layerDocument(): Promise<void>;
14
14
  * on each one an opened overlay holds (a submenu's row), and a typed letter
15
15
  * in each combobox field that a press leaves closed. A drawing that opened
16
16
  * nothing and holds a layer is right-clicked (a context menu). Each overlay
17
- * is kept once, as it was when it opened.
17
+ * is kept once, as it was when it opened; a control on the page that opens
18
+ * keeps the drawn part with it open, without its overlays.
18
19
  * @param {any} host the element the page was drawn in
19
20
  * @param {(fn: () => void) => void} flushSync
20
21
  * @returns {Promise<string[]>}
@@ -151,7 +151,8 @@ export {desktopMatches} from './picture-window.mjs';
151
151
  * on each one an opened overlay holds (a submenu's row), and a typed letter
152
152
  * in each combobox field that a press leaves closed. A drawing that opened
153
153
  * nothing and holds a layer is right-clicked (a context menu). Each overlay
154
- * is kept once, as it was when it opened.
154
+ * is kept once, as it was when it opened; a control on the page that opens
155
+ * keeps the drawn part with it open, without its overlays.
155
156
  * @param {any} host the element the page was drawn in
156
157
  * @param {(fn: () => void) => void} flushSync
157
158
  * @returns {Promise<string[]>}
@@ -243,6 +244,26 @@ export async function openLayerMarkup(host, flushSync) {
243
244
  }
244
245
  await tick();
245
246
  keep();
247
+ // A control the page itself draws (a top nav's menu trigger, outside
248
+ // every overlay) shows its open state only on the page: the part as
249
+ // drawn now, with that control open and without its overlays, is kept
250
+ // too.
251
+ if (
252
+ control.getAttribute('aria-expanded') === 'true' &&
253
+ !control.closest('[data-astryx-layer-root]')
254
+ ) {
255
+ const part = host.cloneNode(true);
256
+ for (const layer of part.querySelectorAll('[data-astryx-layer-root]'))
257
+ layer.remove();
258
+ const html = String(part.innerHTML).replace(
259
+ /<template><\/template>/g,
260
+ '',
261
+ );
262
+ if (html && !seen.has(html)) {
263
+ seen.add(html);
264
+ out.push(html);
265
+ }
266
+ }
246
267
  if (control.getAttribute('aria-expanded') === 'true')
247
268
  for (const layer of g.document.querySelectorAll(
248
269
  '[data-astryx-layer-root]',