@astryxdesign/cli 0.7.16 → 0.7.17-canary.g9a957aa

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 (229) hide show
  1. package/README.md +12 -23
  2. package/api/build/_adapter.d.mts +5 -0
  3. package/api/build/_adapter.mjs +49 -34
  4. package/api/build/blocks/blocks.d.mts +7 -5
  5. package/api/build/blocks/blocks.mjs +113 -26
  6. package/api/build/build.doc.mjs +2 -1
  7. package/api/build/kit/rank.mjs +47 -9
  8. package/api/build/kit/weights.d.mts +16 -3
  9. package/api/build/kit/weights.json +1 -1
  10. package/api/build/kit/weights.mjs +238 -31
  11. package/api/build/kit/word-model.d.mts +23 -0
  12. package/api/build/kit/word-model.mjs +46 -0
  13. package/api/build/kit/words.d.mts +32 -0
  14. package/api/build/kit/words.mjs +49 -1
  15. package/api/component/__fixtures__/resolutions/modules.txt +4 -5
  16. package/api/component/list/list.d.mts +1 -1
  17. package/api/component/list/list.mjs +48 -5
  18. package/api/discover/_adapter.d.mts +1 -1
  19. package/api/docs/_adapter.d.mts +26 -2
  20. package/api/docs/_adapter.mjs +217 -5
  21. package/api/docs/docs.d.mts +3 -0
  22. package/api/docs/docs.doc.mjs +7 -1
  23. package/api/docs/docs.mjs +12 -0
  24. package/api/docs/docs.type.d.mts +5 -0
  25. package/api/docs/docs.type.mjs +2 -0
  26. package/api/docs/node/node.mjs +1 -1
  27. package/api/doctor/_adapter.d.mts +27 -5
  28. package/api/doctor/_adapter.mjs +77 -6
  29. package/api/doctor/built-checks.mjs +38 -13
  30. package/api/doctor/doctor.d.mts +4 -3
  31. package/api/doctor/doctor.mjs +14 -7
  32. package/api/doctor/theme-checks.mjs +121 -17
  33. package/api/render/_adapter.mjs +491 -186
  34. package/api/render/render.doc.mjs +10 -3
  35. package/api/render/render.type.d.mts +30 -0
  36. package/api/render/render.type.mjs +19 -0
  37. package/api/search/ORDERING.md +1 -1
  38. package/api/search/_candidate-score.mjs +51 -32
  39. package/api/search/_fit-order.mjs +3 -3
  40. package/api/search/_result.d.mts +5 -5
  41. package/api/search/_score.d.mts +6 -1
  42. package/api/search/_score.mjs +15 -3
  43. package/api/search/search.d.mts +1 -1
  44. package/api/theme/_adapter.mjs +10 -0
  45. package/api/theme/build/build.d.mts +38 -0
  46. package/api/theme/build/build.mjs +144 -24
  47. package/api/theme/theme.type.d.mts +10 -0
  48. package/api/theme/theme.type.mjs +7 -1
  49. package/api/theme-edit/_adapter.d.mts +35 -0
  50. package/api/theme-edit/_adapter.mjs +477 -41
  51. package/api/theme-edit/_check.d.mts +28 -22
  52. package/api/theme-edit/_check.mjs +1077 -200
  53. package/api/theme-edit/_compiler.mjs +9 -0
  54. package/api/theme-edit/_context.mjs +60 -3
  55. package/api/theme-edit/_css.mjs +21 -1
  56. package/api/theme-edit/_edit.d.mts +22 -0
  57. package/api/theme-edit/_edit.mjs +932 -82
  58. package/api/theme-edit/_how-commands.d.mts +49 -0
  59. package/api/theme-edit/_how-commands.mjs +386 -1
  60. package/api/theme-edit/_how-question.d.mts +56 -0
  61. package/api/theme-edit/_how-question.mjs +3509 -168
  62. package/api/theme-edit/_how.mjs +104 -4
  63. package/api/theme-edit/_marks.d.mts +31 -5
  64. package/api/theme-edit/_marks.mjs +57 -5
  65. package/api/theme-edit/_normal.d.mts +137 -0
  66. package/api/theme-edit/_normal.mjs +612 -0
  67. package/api/theme-edit/_palette.mjs +10 -4
  68. package/api/theme-edit/_parts.d.mts +4 -0
  69. package/api/theme-edit/_parts.mjs +28 -2
  70. package/api/theme-edit/_preview-app.d.mts +7 -1
  71. package/api/theme-edit/_preview-app.mjs +191 -15
  72. package/api/theme-edit/_preview.d.mts +64 -8
  73. package/api/theme-edit/_preview.mjs +401 -83
  74. package/api/theme-edit/_settings.d.mts +139 -5
  75. package/api/theme-edit/_settings.mjs +1659 -112
  76. package/api/theme-edit/_tables.mjs +17 -1
  77. package/api/theme-edit/theme-edit.type.d.mts +10 -1
  78. package/api/theme-edit/theme-edit.type.mjs +4 -1
  79. package/api/theme-edit/themeEditPreviewApp.doc.mjs +2 -2
  80. package/assets/codemods/run-codemod.mjs +73 -6
  81. package/assets/codemods/transforms/next/index.mjs +11 -1
  82. package/assets/codemods/transforms/next/migrate-item-swipe-actions-to-swipe.mjs +394 -0
  83. package/assets/docs/author-a-theme.doc.mjs +1 -0
  84. package/assets/docs/theme.doc.dense.mjs +2 -2
  85. package/assets/docs/theme.doc.mjs +1 -1
  86. package/assets/docs/tree/check-your-docs.doc.mjs +1 -1
  87. package/assets/docs/tree/cli-command.doc.mjs +2 -3
  88. package/assets/docs/tree/render-pages.doc.mjs +43 -2
  89. package/assets/docs/tree/template-doc-overview.doc.mjs +1 -1
  90. package/assets/docs/tree/test-in-an-app.doc.mjs +1 -1
  91. package/assets/docs/use-a-theme.doc.mjs +1 -1
  92. package/assets/docs.generated.json +2 -2
  93. package/assets/self-audit.generated.json +1 -1
  94. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.doc.mjs +14 -0
  95. package/assets/templates/blocks/components/ChatComposerInput/useChatDictationHookUsage.tsx +38 -0
  96. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.doc.mjs +14 -0
  97. package/assets/templates/blocks/components/SyntaxTheme/useSyntaxThemeHookUsage.tsx +36 -0
  98. package/assets/templates/components.generated.json +1 -1
  99. package/assets/templates/pages/ai-chat/template.doc.mjs +8 -4
  100. package/assets/templates/pages/ai-chat-landing/template.doc.mjs +2 -1
  101. package/assets/templates/pages/blank/template.doc.mjs +1 -1
  102. package/assets/templates/pages/canvas-editor/template.doc.mjs +4 -2
  103. package/assets/templates/pages/centered-hero/template.doc.mjs +9 -1
  104. package/assets/templates/pages/classic-gallery/template.doc.mjs +1 -1
  105. package/assets/templates/pages/contact-form/template.doc.mjs +2 -1
  106. package/assets/templates/pages/dashboard/template.doc.mjs +3 -2
  107. package/assets/templates/pages/dashboard-alert-rail/template.doc.mjs +2 -1
  108. package/assets/templates/pages/dashboard-cohort-funnel/template.doc.mjs +2 -1
  109. package/assets/templates/pages/dashboard-composition/template.doc.mjs +2 -1
  110. package/assets/templates/pages/dashboard-progress/template.doc.mjs +6 -3
  111. package/assets/templates/pages/detail-page/template.doc.mjs +10 -3
  112. package/assets/templates/pages/documentation/template.doc.mjs +4 -1
  113. package/assets/templates/pages/documentation-design/template.doc.mjs +7 -1
  114. package/assets/templates/pages/documentation-technical/template.doc.mjs +7 -1
  115. package/assets/templates/pages/editor/template.doc.mjs +1 -7
  116. package/assets/templates/pages/file-explorer/template.doc.mjs +1 -1
  117. package/assets/templates/pages/form-two-column/template.doc.mjs +4 -3
  118. package/assets/templates/pages/form-wizard/template.doc.mjs +5 -3
  119. package/assets/templates/pages/gallery-hero/template.doc.mjs +4 -2
  120. package/assets/templates/pages/ide/page.tsx +24 -2
  121. package/assets/templates/pages/library/template.doc.mjs +4 -1
  122. package/assets/templates/pages/login/template.doc.mjs +2 -1
  123. package/assets/templates/pages/login-card/template.doc.mjs +2 -1
  124. package/assets/templates/pages/login-split/template.doc.mjs +2 -1
  125. package/assets/templates/pages/login-sso/template.doc.mjs +4 -2
  126. package/assets/templates/pages/mixed-gallery/template.doc.mjs +2 -1
  127. package/assets/templates/pages/product-detail/template.doc.mjs +4 -2
  128. package/assets/templates/pages/product-gallery/template.doc.mjs +2 -1
  129. package/assets/templates/pages/settings-dialog/template.doc.mjs +2 -1
  130. package/assets/templates/pages/settings-sidebar/template.doc.mjs +2 -1
  131. package/assets/templates/pages/shell-nav/template.doc.mjs +4 -2
  132. package/assets/templates/pages/shell-side-nav/template.doc.mjs +5 -3
  133. package/assets/templates/pages/shell-top-nav/template.doc.mjs +2 -1
  134. package/assets/templates/pages/side-gallery/template.doc.mjs +9 -1
  135. package/assets/templates/pages/table-filter/template.doc.mjs +9 -8
  136. package/assets/templates/pages/table-grouped/template.doc.mjs +4 -2
  137. package/assets/templates/pages/table-page/template.doc.mjs +5 -4
  138. package/assets/templates/pages/table-tree/template.doc.mjs +6 -3
  139. package/assets/templates/pages/theme-showcase/template.doc.mjs +2 -1
  140. package/assets/templates/pages/work-item-detail/template.doc.mjs +1 -0
  141. package/authoring/debug/parse.d.mts +3 -3
  142. package/authoring/doctypes/_schema.d.mts +3 -3
  143. package/authoring/doctypes/command/command.doc.mjs +1 -1
  144. package/authoring/doctypes/template/template.doc.mjs +1 -1
  145. package/authoring/doctypes/template/type.ts +9 -0
  146. package/clients/cli/bin/astryx.mjs +6 -9
  147. package/clients/cli/build-id.generated.json +1 -1
  148. package/clients/cli/commands/component.doc.mjs +1 -1
  149. package/clients/cli/commands/component.mjs +20 -2
  150. package/clients/cli/commands/docs.doc.mjs +7 -1
  151. package/clients/cli/commands/docs.mjs +3 -1
  152. package/clients/cli/commands/doctor.mjs +22 -14
  153. package/clients/cli/commands/experimental/render.mjs +32 -1
  154. package/clients/cli/commands/experimental/theme.mjs +27 -2
  155. package/clients/cli/commands/experimental-render.doc.mjs +2 -2
  156. package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
  157. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
  158. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  159. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  160. package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
  161. package/clients/cli/commands/search.doc.mjs +2 -1
  162. package/clients/cli/commands/search.mjs +6 -1
  163. package/clients/cli/commands/template.mjs +4 -2
  164. package/clients/cli/commands/theme-build.doc.mjs +5 -1
  165. package/clients/cli/commands/theme.doc.mjs +1 -1
  166. package/clients/cli/commands/theme.mjs +138 -3
  167. package/clients/cli/commands/upgrade.mjs +42 -7
  168. package/clients/cli/index.mjs +1 -1
  169. package/clients/cli/lib/component-format.mjs +205 -98
  170. package/clients/cli/lib/hook-format.mjs +9 -19
  171. package/clients/cli/manifest.generated.json +1 -1
  172. package/foundation/agent-docs/agent-docs.mjs +1 -1
  173. package/foundation/config/theme-state.d.mts +13 -1
  174. package/foundation/config/theme-state.mjs +47 -7
  175. package/foundation/discovery/component-discovery.d.mts +11 -0
  176. package/foundation/discovery/component-discovery.mjs +27 -2
  177. package/foundation/discovery/component-replacement.mjs +130 -1
  178. package/foundation/discovery/entry-name-files.d.mts +43 -0
  179. package/foundation/discovery/entry-name-files.mjs +264 -0
  180. package/foundation/discovery/hook-discovery.d.mts +8 -2
  181. package/foundation/discovery/hook-discovery.mjs +20 -7
  182. package/foundation/discovery/runner-allowlist.d.mts +1 -0
  183. package/foundation/discovery/runner-allowlist.mjs +2 -0
  184. package/foundation/discovery/template-adapter.d.mts +52 -0
  185. package/foundation/discovery/template-adapter.mjs +169 -0
  186. package/foundation/discovery/theme-imports.d.mts +14 -0
  187. package/foundation/discovery/theme-imports.mjs +43 -1
  188. package/foundation/doc-compiler/import.mjs +7 -1
  189. package/foundation/doc-compiler/parse-readable.mjs +4 -1
  190. package/foundation/doc-compiler/stored-docs.d.mts +22 -0
  191. package/foundation/doc-compiler/stored-docs.mjs +49 -0
  192. package/foundation/fs/cache-eviction.d.mts +21 -0
  193. package/foundation/fs/cache-eviction.mjs +73 -0
  194. package/foundation/fs/gather-cache.d.mts +25 -4
  195. package/foundation/fs/gather-cache.mjs +138 -52
  196. package/foundation/fs/jiti-cache.d.mts +19 -1
  197. package/foundation/fs/jiti-cache.mjs +130 -6
  198. package/foundation/fs/kept-tree.d.mts +60 -0
  199. package/foundation/fs/kept-tree.mjs +154 -0
  200. package/foundation/fs/module-loader.d.mts +18 -2
  201. package/foundation/fs/module-loader.mjs +92 -20
  202. package/foundation/identity/provider-identity.d.mts +6 -0
  203. package/foundation/identity/provider-identity.mjs +10 -1
  204. package/foundation/render/file-header.d.mts +66 -0
  205. package/foundation/render/file-header.mjs +118 -0
  206. package/foundation/render/host-answer.d.mts +18 -0
  207. package/foundation/render/host-answer.mjs +46 -0
  208. package/foundation/render/host-exit.d.mts +1 -0
  209. package/foundation/render/host-exit.mjs +6 -1
  210. package/foundation/render/html-reader.d.mts +55 -2
  211. package/foundation/render/html-reader.mjs +145 -26
  212. package/foundation/render/markup-edits.d.mts +57 -0
  213. package/foundation/render/markup-edits.mjs +182 -0
  214. package/foundation/render/page-host.mjs +29 -12
  215. package/foundation/render/page-worker.mjs +79 -10
  216. package/foundation/render/render-page.d.mts +34 -2
  217. package/foundation/render/render-page.mjs +210 -29
  218. package/foundation/render/source-block.d.mts +73 -6
  219. package/foundation/render/source-block.mjs +170 -19
  220. package/foundation/render/ts-paths.d.mts +4 -1
  221. package/foundation/render/ts-paths.mjs +7 -3
  222. package/foundation/response/error-codes.d.mts +2 -1
  223. package/foundation/response/error-codes.doc.mjs +7 -1
  224. package/foundation/response/error-codes.mjs +7 -0
  225. package/foundation/text/string-utils.d.mts +3 -2
  226. package/foundation/text/string-utils.mjs +16 -3
  227. package/foundation/text/suggest-order.d.mts +9 -0
  228. package/foundation/text/suggest-order.mjs +13 -0
  229. package/package.json +6 -6
@@ -0,0 +1,612 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The theme editor's input normaliser: how a typed or saved thing and
5
+ * value are read before any check (Unicode spaces, delimiting quotes, a
6
+ * pasted declaration, JSON and copy debris, a font stack's families). Typed
7
+ * input (`set`, `undo`) and saved settings (`loadTheme`, the stored checks)
8
+ * both read through it.
9
+ * @position packages/cli/api/theme-edit — pure helpers, no environment access
10
+ */
11
+
12
+ import {DIALS} from './_tables.mjs';
13
+
14
+ /**
15
+ * A value as CSS reads it, for every value type: every Unicode space
16
+ * (no-break, thin, ideographic…) a plain space and zero-width and format
17
+ * characters dropped, and quotes that delimit a value (curly ones, «», ‹›,
18
+ * full-width, backticks) straight. A straight-quoted CSS string keeps what
19
+ * it holds as written (`content: "it’s"`). Curly quotes pair by kind
20
+ * (double with double, single with single, in any of their shapes: „Inter“,
21
+ * ‚Inter‘); one left unpaired is read as the straight quote it stands for.
22
+ * @param {string} v
23
+ * @returns {string}
24
+ */
25
+ export function normalValueText(v) {
26
+ let out = '';
27
+ let plain = '';
28
+ const flush = () => {
29
+ out += plain
30
+ .replace(/[\u200B-\u200D\u2060\uFEFF]/g, '')
31
+ .replace(/[\u00A0\u1680\u2000-\u200A\u202F\u205F\u3000]/g, ' ');
32
+ plain = '';
33
+ };
34
+ for (let i = 0; i < v.length;) {
35
+ const c = v[i];
36
+ // A straight-quoted CSS string keeps everything inside it.
37
+ if (c === '"' || c === "'") {
38
+ let j = i + 1;
39
+ while (j < v.length && v[j] !== c) j += v[j] === '\\' ? 2 : 1;
40
+ if (j < v.length) {
41
+ flush();
42
+ out += v.slice(i, j + 1);
43
+ i = j + 1;
44
+ continue;
45
+ }
46
+ }
47
+ const kind = CURLY_DOUBLE.has(c)
48
+ ? CURLY_DOUBLE
49
+ : CURLY_SINGLE.has(c)
50
+ ? CURLY_SINGLE
51
+ : null;
52
+ /** @type {number} */
53
+ let j = -1;
54
+ if (kind) {
55
+ for (let k = i + 1; k < v.length; k++)
56
+ if (kind.has(v[k])) {
57
+ j = k;
58
+ break;
59
+ }
60
+ } else if (QUOTE_PAIRS[c]) j = v.indexOf(QUOTE_PAIRS[c], i + 1);
61
+ if (j > i) {
62
+ flush();
63
+ // What the quotes hold, as typed (`“ / ”` is a slash between
64
+ // spaces); a font family trims it (normalizeEntry).
65
+ const inner = v.slice(i + 1, j);
66
+ const single = kind === CURLY_SINGLE || c === '\uFF07';
67
+ const mark = single
68
+ ? inner.includes("'")
69
+ ? '"'
70
+ : "'"
71
+ : inner.includes('"')
72
+ ? "'"
73
+ : '"';
74
+ out += `${mark}${inner}${mark}`;
75
+ i = j + 1;
76
+ continue;
77
+ }
78
+ // An unpaired curly quote is the straight one it stands for.
79
+ plain += kind === CURLY_DOUBLE ? '"' : kind === CURLY_SINGLE ? "'" : c;
80
+ i += 1;
81
+ }
82
+ flush();
83
+ return out;
84
+ }
85
+
86
+ /** Curly double quotes, in every shape; any one closes any other. */
87
+ const CURLY_DOUBLE = new Set(['\u201C', '\u201D', '\u201E', '\u201F']);
88
+ /** Curly single quotes, in every shape. */
89
+ const CURLY_SINGLE = new Set(['\u2018', '\u2019', '\u201A', '\u201B']);
90
+ /** The other delimiting quotes and the one that closes each. */
91
+ /** @type {Record<string, string>} */
92
+ const QUOTE_PAIRS = {
93
+ '\u300C': '\u300D',
94
+ '\u300E': '\u300F',
95
+ '\u00AB': '\u00BB',
96
+ '\u00BB': '\u00AB',
97
+ '\u2039': '\u203A',
98
+ '\u203A': '\u2039',
99
+ '\uFF02': '\uFF02',
100
+ '\uFF07': '\uFF07',
101
+ '`': '`',
102
+ };
103
+
104
+ /** CSS functions whose names a value may write in any case. */
105
+ const CSS_FUNCTIONS =
106
+ /\b(light-dark|rgba?|hsla?|hwb|lab|lch|oklab|oklch|color|color-mix|calc|min|max|clamp|var)\(/gi;
107
+
108
+ /**
109
+ * A value as meant when typed with escapes or in another notation: CSS
110
+ * function names in lower case (`LIGHT-DARK(` is `light-dark(`, as CSS reads
111
+ * it); a shell or JSON backslash before `#`, a quote or a space taken off;
112
+ * a JavaScript escape in a `content` string written as CSS writes it
113
+ * (`\u2022` is `\2022 `, `\n` a line break, `\t` a tab); and the JSON
114
+ * shapes a design-tokens file or an array writes (`{"$value": "#e11d48"}`,
115
+ * `{"value": 18, "unit": "px"}`, `["#e11d48"]`, `["Inter", "sans-serif"]`).
116
+ * @param {string} thing
117
+ * @param {string} value
118
+ * @returns {string}
119
+ */
120
+ export function escapesMeant(thing, value) {
121
+ let v = value;
122
+ const content = /^content$/i.test(thing);
123
+ if (content)
124
+ return (
125
+ v
126
+ .replace(
127
+ /\\u\{?([0-9a-f]{2,6})\}?/gi,
128
+ (_, h) => `\\${h.toUpperCase()} `,
129
+ )
130
+ // `\x` with four hex digits is written for the code point (as
131
+ // `\u`), with two for that character.
132
+ .replace(
133
+ /\\x([0-9a-f]{4}|[0-9a-f]{2})/gi,
134
+ (_, h) => `\\${h.toUpperCase()} `,
135
+ )
136
+ .replace(/\\n/g, '\\A ')
137
+ .replace(/\\t/g, '\\9 ')
138
+ .replace(/\\r/g, '\\D ')
139
+ );
140
+ v = v.replace(CSS_FUNCTIONS, f => f.toLowerCase());
141
+ // A JS escape of a printable character in a font family (`Inter\u0020
142
+ // Tight`) is that character, as CSS would read its own escape.
143
+ if (/font/i.test(thing))
144
+ v = v.replace(
145
+ /\\(?:u\{?([0-9a-f]{4,6})\}?|x([0-9a-f]{2}))/gi,
146
+ (m, u, x) => {
147
+ const c = String.fromCodePoint(parseInt(u ?? x, 16));
148
+ return /^[\p{L}\p{N} _-]$/u.test(c) ? c : m;
149
+ },
150
+ );
151
+ // (A JSON string holding escaped quotes is unwrapped whole later.)
152
+ if (!/^\s*"(?:[^"\\]|\\.)*"\s*$/.test(v)) v = v.replace(/\\([#"' ])/g, '$1');
153
+ else v = v.replace(/\\([# ])/g, '$1');
154
+ const t = v.trim();
155
+ if (/^[[{]/.test(t)) {
156
+ /** @type {any} */
157
+ let j;
158
+ try {
159
+ j = JSON.parse(t);
160
+ } catch {
161
+ return v;
162
+ }
163
+ /** @param {any} x */
164
+ const text = x =>
165
+ typeof x === 'string' || typeof x === 'number' ? String(x) : null;
166
+ if (Array.isArray(j) && j.length && j.every(x => text(x) != null)) {
167
+ if (j.length === 1) return String(j[0]);
168
+ if (/font/i.test(thing))
169
+ return j
170
+ .map(x =>
171
+ /\s/.test(String(x)) && !/^["']/.test(String(x))
172
+ ? `"${x}"`
173
+ : String(x),
174
+ )
175
+ .join(', ');
176
+ return v;
177
+ }
178
+ if (j && typeof j === 'object' && !Array.isArray(j)) {
179
+ const inner =
180
+ '$value' in j ? j.$value : 'value' in j ? j.value : undefined;
181
+ if (text(inner) != null)
182
+ return `${inner}${typeof j.unit === 'string' ? j.unit : ''}`;
183
+ // One labeled entry (`{"color": "#e11d48"}`) is read as the same
184
+ // label in its CSS form (`color: #e11d48`): one reader for both.
185
+ const keys = Object.keys(j);
186
+ if (
187
+ keys.length === 1 &&
188
+ /^(--)?[a-z][a-z0-9-]*$/i.test(keys[0]) &&
189
+ text(j[keys[0]]) != null
190
+ )
191
+ return `${keys[0]}: ${j[keys[0]]}`;
192
+ }
193
+ }
194
+ return v;
195
+ }
196
+
197
+ /**
198
+ * The thing and value a setting was typed as, put right before any check: a
199
+ * declaration pasted whole or split (`accent: #e11d48`, `--color-accent=red`,
200
+ * `font:inter`, `accent:` with the value next), a token typed with an em or
201
+ * en dash (`—color-accent`) or as `var(--color-accent)`, and the value's
202
+ * Unicode spaces. A thing it cannot read is left as typed.
203
+ * @param {string} thing
204
+ * @param {string | undefined} value
205
+ * @returns {{thing: string, value: string | undefined, dropped?: string}} `dropped`: a second declaration pasted after the first, which is not set
206
+ */
207
+ export function normalizeEntry(thing, value) {
208
+ let t = normalValueText(String(thing ?? '')).trim();
209
+ let v = value == null ? value : normalValueText(String(value));
210
+ // A pasted declaration (the whole of it in the thing, or the thing with
211
+ // its colon and the value next): its `;` and `!important` go with it.
212
+ let pasted = false;
213
+ // A JSON object around one entry (`{"accent": "#e11d48"}`), whole or
214
+ // split at its colon.
215
+ if ((v == null || v.trim() === '') && /^\{[\s\S]*\}$/.test(t))
216
+ t = t.slice(1, -1).trim().replace(/,\s*$/, '');
217
+ else if (t.startsWith('{') && typeof v === 'string' && /\}\s*$/.test(v)) {
218
+ t = t.slice(1).trim();
219
+ v = v.replace(/\s*\}\s*$/, '');
220
+ }
221
+ if (v == null || v.trim() === '') {
222
+ const m = /^(\S+?)\s*[:=]\s*(.+?)\s*;?\s*$/.exec(t);
223
+ if (m && !/^https?$/i.test(m[1])) {
224
+ t = m[1];
225
+ v = m[2];
226
+ pasted = true;
227
+ }
228
+ }
229
+ // A thing ending in its colon or equals sign, the value given next.
230
+ if (/\s*[:=]+$/.test(t)) {
231
+ t = t.replace(/\s*[:=]+$/, '');
232
+ pasted = true;
233
+ }
234
+ // A thing in quotes, as a JSON or design-tokens file writes it
235
+ // (`"accent": "#e11d48"`).
236
+ const quotedThing = /^(["'])(.+)\1$/.exec(t);
237
+ if (quotedThing) {
238
+ t = quotedThing[2].trim();
239
+ pasted = true;
240
+ // Its value in JSON's double quotes is the value (`"#e11d48"`); a font
241
+ // list keeps its own quotes.
242
+ if (typeof v === 'string' && !/font/i.test(t)) {
243
+ const jv = /^\s*"([^"]*)"\s*,?\s*$/.exec(v);
244
+ if (jv) v = jv[1];
245
+ }
246
+ }
247
+ // Dash-like characters where a token's two dashes go (an em or en dash,
248
+ // a non-breaking hyphen, a minus sign, a full-width hyphen, alone or
249
+ // mixed with hyphens): `--`.
250
+ t = t.replace(/^[-\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]+/, run =>
251
+ /[^-]/.test(run) ? '--' : run,
252
+ );
253
+ // A dash-like character inside a token's name is its hyphen.
254
+ if (t.startsWith('--'))
255
+ t = `--${t.slice(2).replace(/[\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]/g, '-')}`;
256
+ // A token typed as a var() reference.
257
+ const ref = /^var\(\s*(--[a-z0-9-]+)\s*\)$/i.exec(t);
258
+ if (ref) t = ref[1];
259
+ // A dial name written in another style (textSize, text_size, a dash-like
260
+ // character for its hyphen) is the dial.
261
+ if (
262
+ !t.startsWith('-') &&
263
+ /[_\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]|[a-z][A-Z]/.test(t)
264
+ ) {
265
+ const dial = t
266
+ .replace(/[_\u2010-\u2015\u2212\uFE58\uFE63\uFF0D]/g, '-')
267
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
268
+ .toLowerCase();
269
+ if (DIALS[dial]) t = dial;
270
+ }
271
+ if (typeof v === 'string') v = escapesMeant(t, v);
272
+ // A second declaration pasted after the first (`accent: red; text-size:
273
+ // 18`): the first is this setting.
274
+ /** A second declaration pasted after the first, which this does not set. @type {string | null} */
275
+ let dropped = null;
276
+ if (typeof v === 'string') {
277
+ const cut = withoutSecondDeclaration(v);
278
+ if (cut !== v)
279
+ dropped = v
280
+ .slice(cut.length)
281
+ .replace(/^\s*;\s*/, '')
282
+ .trim();
283
+ v = cut;
284
+ }
285
+ if (pasted && typeof v === 'string') {
286
+ v = v.replace(/\s*!\s*important\s*;?\s*$/i, '').replace(/;+\s*$/, '');
287
+ }
288
+ if (typeof v === 'string') v = withoutDebris(v);
289
+ // A font stack written as a JSON string (`"\\"Open Sans\\", serif"`): the
290
+ // stack it holds.
291
+ if (
292
+ typeof v === 'string' &&
293
+ /font/i.test(t) &&
294
+ /^"(?:[^"\\]|\\.)*"$/.test(v.trim()) &&
295
+ v.includes('\\"')
296
+ ) {
297
+ try {
298
+ const inner = JSON.parse(v.trim());
299
+ if (typeof inner === 'string') v = inner;
300
+ } catch {
301
+ // Not a JSON string.
302
+ }
303
+ }
304
+ // A font stack with its quotes escaped, as it sits inside a JSON or JS
305
+ // string (`\"Inter\", sans-serif`): the stack.
306
+ if (typeof v === 'string' && /font/i.test(t) && /\\["']/.test(v))
307
+ v = v.replace(/\\(["'])/g, '$1');
308
+ // A font family's name never starts or ends with a space: French quotes
309
+ // (« Inter », with a no-break or narrow no-break space) hold the name.
310
+ if (typeof v === 'string' && /font/i.test(t)) v = trimInsideQuotes(v);
311
+ return {thing: t, value: v, ...(dropped ? {dropped} : {})};
312
+ }
313
+
314
+ /**
315
+ * A font stack's pieces, split on the commas outside quotes, with each
316
+ * piece's name and whether it was quoted; null when a quote is left open.
317
+ * @param {string} v
318
+ * @returns {Array<{name: string, quoted: boolean}> | null}
319
+ */
320
+ export function familyPieces(v) {
321
+ /** @type {Array<{name: string, quoted: boolean}>} */
322
+ const out = [];
323
+ let cur = '';
324
+ let quoted = false;
325
+ /** @type {string | null} */
326
+ let q = null;
327
+ let closed = false;
328
+ for (const c of String(v)) {
329
+ if (q) {
330
+ if (c === q) {
331
+ q = null;
332
+ closed = true;
333
+ } else cur += c;
334
+ continue;
335
+ }
336
+ if (c === '"' || c === "'") {
337
+ // A quote opening after text, or a second quoted name before a
338
+ // comma: not a stack of whole pieces.
339
+ if (cur.trim() || closed) return null;
340
+ q = c;
341
+ quoted = true;
342
+ continue;
343
+ }
344
+ // Text after a quoted name before its comma (`"Open Sans" serif`).
345
+ if (closed && c !== ',' && c.trim()) return null;
346
+ if (c === ',') {
347
+ out.push({name: cur.trim(), quoted});
348
+ cur = '';
349
+ quoted = false;
350
+ closed = false;
351
+ continue;
352
+ }
353
+ cur += c;
354
+ }
355
+ if (q) return null;
356
+ out.push({name: cur.trim(), quoted});
357
+ return out;
358
+ }
359
+
360
+ /**
361
+ * The families a typed font stack names: a trailing comma and empty pieces
362
+ * dropped, and a stack wrapped in one more pair of the quotes it uses
363
+ * inside (`""SF Mono", Monaco, monospace"`, as a JSON string) unwrapped.
364
+ * Null when the stack does not read.
365
+ * @param {string} v
366
+ * @returns {string[] | null}
367
+ */
368
+ export function familiesOf(v) {
369
+ let s = String(v)
370
+ .trim()
371
+ .replace(/,+\s*$/, '');
372
+ const w = /^(["'])([\s\S]*)\1$/.exec(s);
373
+ if (w && w[2].includes(w[1])) s = w[2].trim().replace(/,+\s*$/, '');
374
+ const pieces = familyPieces(s);
375
+ if (!pieces) return null;
376
+ return pieces.map(f => f.name).filter(Boolean);
377
+ }
378
+
379
+ /**
380
+ * A value with the debris of a bad copy taken off: a leading `=` or `:`, a
381
+ * trailing comma (a JSON or CSS list), and a quote or a closing bracket left
382
+ * over at either end. A value without any is returned as it was.
383
+ * @param {string} v
384
+ * @returns {string}
385
+ */
386
+ export function withoutDebris(v) {
387
+ let s = v.replace(/^\s*[=:]\s*/, '').replace(/\s*,+\s*$/, '');
388
+ // Quotes and brackets counted as CSS reads them: an escaped quote (\")
389
+ // is no quote, and a bracket inside a string is the string's.
390
+ const scan = (/** @type {string} */ t) => {
391
+ /** @type {Record<string, number>} */
392
+ const quotes = {'"': 0, "'": 0};
393
+ let open = 0;
394
+ let close = 0;
395
+ /** @type {string | null} */
396
+ let q = null;
397
+ for (let i = 0; i < t.length; i++) {
398
+ const c = t[i];
399
+ if (c === '\\') {
400
+ i++;
401
+ continue;
402
+ }
403
+ if (q) {
404
+ if (c === q) {
405
+ q = null;
406
+ quotes[c]++;
407
+ }
408
+ continue;
409
+ }
410
+ if (c === '"' || c === "'") {
411
+ q = c;
412
+ quotes[c]++;
413
+ } else if (c === '(') open++;
414
+ else if (c === ')') close++;
415
+ }
416
+ return {quotes, open, close};
417
+ };
418
+ for (const mark of /** @type {const} */ (['"', "'"])) {
419
+ if (scan(s).quotes[mark] % 2 === 1) {
420
+ if (s.endsWith(mark) && !s.endsWith(`\\${mark}`)) s = s.slice(0, -1);
421
+ else if (s.startsWith(mark)) s = s.slice(1);
422
+ }
423
+ }
424
+ const {open, close} = scan(s);
425
+ if (close > open && s.endsWith(')')) s = s.slice(0, -1);
426
+ return s === v.trim() ? v : s.trim();
427
+ }
428
+
429
+ /**
430
+ * A value without a second declaration pasted after it (`#e11d48;
431
+ * text-size: 18`): cut at the first `;` outside quotes that a `name:`
432
+ * follows. A `;` inside a quoted string (`"Tip; note: x"`) is the string's.
433
+ * @param {string} v
434
+ * @returns {string}
435
+ */
436
+ export function withoutSecondDeclaration(v) {
437
+ /** @type {string | null} */
438
+ let q = null;
439
+ for (let i = 0; i < v.length; i++) {
440
+ const c = v[i];
441
+ if (q) {
442
+ if (c === '\\') i++;
443
+ else if (c === q) q = null;
444
+ continue;
445
+ }
446
+ if (c === '"' || c === "'") q = c;
447
+ else if (
448
+ c === ';' &&
449
+ /^\s*[a-z-]+\s*:/i.test(v.slice(i + 1)) &&
450
+ // `light: red; dark: blue` is one value for two modes.
451
+ !/^\s*(?:light|dark)\s*:/i.test(v.slice(i + 1))
452
+ )
453
+ return v.slice(0, i);
454
+ }
455
+ return v;
456
+ }
457
+
458
+ /**
459
+ * A saved dial value read as typed input is (invisible or stray spaces,
460
+ * quotes around it, a pasted `corners: pill`, a trailing `;`, other
461
+ * letters): the value the dial may have meant.
462
+ * @param {string} dial
463
+ * @param {string} value
464
+ * @returns {string}
465
+ */
466
+ export function cleanDialValue(dial, value) {
467
+ const read = normalizeEntry(dial, value).value ?? '';
468
+ return read
469
+ .trim()
470
+ .replace(new RegExp(`^${dial.replace(/-/g, '\\-')}\\s*[:=]\\s*`, 'i'), '')
471
+ .replace(/\s*!\s*important\s*$/i, '')
472
+ .replace(/;+\s*$/, '')
473
+ .replace(/^(["'])(.*)\1$/, '$2')
474
+ .trim()
475
+ .toLowerCase();
476
+ }
477
+
478
+ /**
479
+ * A value with the spaces just inside each straight-quoted string taken off
480
+ * (`" Inter "` is "Inter"), for a font family, whose name holds none there.
481
+ * @param {string} v
482
+ * @returns {string}
483
+ */
484
+ export function trimInsideQuotes(v) {
485
+ const SP = '[\\s\\u00A0\\u202F\\u2000-\\u200A\\u3000]*';
486
+ return v.replace(
487
+ new RegExp(`(["'])${SP}((?:(?!\\1)[^\\\\]|\\\\.)*?)${SP}\\1`, 'g'),
488
+ '$1$2$1',
489
+ );
490
+ }
491
+
492
+ /**
493
+ * The other setting a dial's value is labeled with, when pasted with a
494
+ * label that names a different dial or a token (`neutral: #64748b` given
495
+ * to accent): that label and the value after it, else null. A label that
496
+ * names this dial, or a CSS property (`color: #e11d48`), is no other
497
+ * setting.
498
+ * @param {string} dial
499
+ * @param {string} value
500
+ * @returns {{thing: string, value: string} | null}
501
+ */
502
+ export function otherSettingLabel(dial, value) {
503
+ const m =
504
+ /^\s*["']?([a-z][a-z0-9_-]*|--[a-z0-9-]+)["']?\s*[:=]\s*["']?(.+?)["']?\s*;?\s*$/i.exec(
505
+ String(value),
506
+ );
507
+ if (!m) return null;
508
+ // A label in camelCase or snake_case (textSize, text_size) is the dial.
509
+ const label = m[1]
510
+ .replace(/([a-z0-9])([A-Z])/g, '$1-$2')
511
+ .replace(/_/g, '-')
512
+ .toLowerCase();
513
+ if (label === dial) return null;
514
+ if (!DIALS[label] && !label.startsWith('--')) return null;
515
+ return {thing: label, value: m[2]};
516
+ }
517
+
518
+ /**
519
+ * A light and a dark color typed as a pair: labeled (`light: red; dark:
520
+ * blue`), a JSON object (`{"light": "red", "dark": "blue"}`), or two colors
521
+ * with a slash or a comma between (`red / blue`, `red, blue`). Null when the
522
+ * value is no such pair; the caller checks that both are colors.
523
+ * @param {string} value
524
+ * @returns {{light: string, dark: string} | null}
525
+ */
526
+ export function colorPair(value) {
527
+ const v = String(value).trim();
528
+ const unq = (/** @type {string} */ x) =>
529
+ x
530
+ .trim()
531
+ .replace(/^(["'])(.*)\1$/, '$2')
532
+ .trim();
533
+ const labeled =
534
+ /^\{?\s*["']?(light|dark)["']?\s*[:=]\s*(.+?)\s*[;,]\s*["']?(light|dark)["']?\s*[:=]\s*(.+?)\s*;?\s*\}?$/i.exec(
535
+ v,
536
+ );
537
+ if (labeled && labeled[1].toLowerCase() !== labeled[3].toLowerCase()) {
538
+ const a = unq(labeled[2]);
539
+ const b = unq(labeled[4]);
540
+ return labeled[1].toLowerCase() === 'light'
541
+ ? {light: a, dark: b}
542
+ : {light: b, dark: a};
543
+ }
544
+ const two = /^([^\s,/()]+)\s*(?:\s\/\s|,)\s*([^\s,/()]+)$/.exec(v);
545
+ if (two) return {light: unq(two[1]), dark: unq(two[2])};
546
+ return null;
547
+ }
548
+
549
+ /**
550
+ * The stock values a repair would put in when it could read nothing from
551
+ * the input: the example of each value type, and the dials' defaults. A
552
+ * line with one of these is offered only when the input held it.
553
+ */
554
+ export const STOCK_VALUES = new Set([
555
+ '#1f2937',
556
+ '#7c3aed',
557
+ '#ffffff',
558
+ 'inter',
559
+ 'inter, sans-serif',
560
+ 'system',
561
+ '1px',
562
+ '6px',
563
+ '12px',
564
+ '16',
565
+ '600',
566
+ '1.4',
567
+ '150ms',
568
+ 'solid',
569
+ // The dials' fallback words and the size tokens' Core defaults, offered
570
+ // when nothing could be read.
571
+ 'medium',
572
+ 'roomy',
573
+ 'compact',
574
+ 'round',
575
+ 'light-dark(#1f2937, #f9fafb)',
576
+ ]);
577
+
578
+ /**
579
+ * Whether a suggested value carries what was typed: each of its words and
580
+ * numbers is in the typed text (cleaned: case, quotes, escapes), apart from
581
+ * a unit added to a bare number and the words of the CSS form it is written
582
+ * in (`light-dark()`, `var()`, `calc()`, a generic family). A stock value
583
+ * the input never held (a gray, a violet, `system`, `small`) does not.
584
+ * @param {string} offered
585
+ * @param {string} typed
586
+ */
587
+ export function carriesTyped(offered, typed) {
588
+ const flat = String(typed)
589
+ .toLowerCase()
590
+ .replace(/\\(?=[#"' ])/g, '')
591
+ .replace(/[\s"'\u201C\u201D\u2018\u2019\u300C\u300D]/g, '');
592
+ const FORM = new Set(['light', 'dark', 'var', 'calc', 'px', 'rem', 'em']);
593
+ return (
594
+ String(offered)
595
+ .toLowerCase()
596
+ .match(/[a-z0-9.]+/g) ?? []
597
+ )
598
+ .map(w => w.replace(/^([0-9.]+)(px|rem|em)$/, '$1'))
599
+ .filter(w => !FORM.has(w))
600
+ .every(w => flat.includes(w));
601
+ }
602
+
603
+ /**
604
+ * Whether a repair may offer `offered` for `typed`: a stock value only when
605
+ * the input held it; any other value (one read from the input, or mapped
606
+ * from it by a documented rule) may be.
607
+ * @param {string} offered
608
+ * @param {string} typed
609
+ */
610
+ export const offersTyped = (offered, typed) =>
611
+ !STOCK_VALUES.has(String(offered).toLowerCase()) ||
612
+ carriesTyped(offered, typed);
@@ -156,7 +156,11 @@ function sweepTemps(dir) {
156
156
  }
157
157
  continue;
158
158
  }
159
- const m = /^\..+\.astryx-(\d+)-[a-z0-9]+\.tmp$/.exec(n);
159
+ // A picture taken under its own name (`.<picture>.part-<pid>.png`) by a
160
+ // run stopped while the browser ran.
161
+ const m =
162
+ /^\..+\.astryx-(\d+)-[a-z0-9]+\.tmp$/.exec(n) ??
163
+ /^\.[\w-]+\.part-(\d+)\.png$/.exec(n);
160
164
  if (!m) continue;
161
165
  const p = path.join(dir, n);
162
166
  try {
@@ -203,12 +207,14 @@ export function removeEmptyFolder(dir, opts = {}) {
203
207
 
204
208
  /**
205
209
  * Whether a file name is one of the editor's own temp files: a whole-file
206
- * write's `.<name>.astryx-<pid>-<random>.tmp`, or a build's
207
- * `.<name>.tmp-<id>`. A command stopped part way can leave one behind.
210
+ * write's `.<name>.astryx-<pid>-<random>.tmp`, a build's `.<name>.tmp-<id>`,
211
+ * or a picture's `.<picture>.part-<pid>.png`. A command stopped part way can
212
+ * leave one behind.
208
213
  * @param {string} name
209
214
  */
210
215
  export const isEditorTemp = name =>
211
- /^\..+\.(astryx-\d+-[a-z0-9]+\.tmp|tmp-[\w-]+)$/.test(name);
216
+ /^\..+\.(astryx-\d+-[a-z0-9]+\.tmp|tmp-[\w-]+)$/.test(name) ||
217
+ /^\.[\w-]+\.part-\d+\.png$/.test(name);
212
218
 
213
219
  /**
214
220
  * A temp file beside `file` for a whole write, named so only the editor
@@ -142,6 +142,10 @@ export type PartRecord = {
142
142
  tokens: Record<string, string[]>;
143
143
  values: string[];
144
144
  }>;
145
+ /**
146
+ * - property -> the value under each condition, private variables resolved
147
+ */
148
+ at?: Record<string, Record<string, string>> | undefined;
145
149
  /**
146
150
  * - tokens read by unnamed elements inside the part -> properties
147
151
  */