@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
@@ -104,4 +104,53 @@ export type HowTheme = {
104
104
  ok: false;
105
105
  why: string;
106
106
  };
107
+ /**
108
+ * the measured check: why the built result does not do what the question asks, or null
109
+ */
110
+ measure: (steps: Step[], intent: MeasureIntent) => string | null;
111
+ };
112
+ /**
113
+ * What the measured check holds a command to.
114
+ */
115
+ export type MeasureIntent = {
116
+ /**
117
+ * the kinds of change asked for (color, radius, space, border, weight, opacity, shadow, fontsize); empty: any
118
+ */
119
+ families: string[];
120
+ /**
121
+ * the way a size moves
122
+ */
123
+ dir: "more" | "less" | null;
124
+ /**
125
+ * the way a color moves
126
+ */
127
+ lighter: boolean | null;
128
+ /**
129
+ * the way an opacity moves
130
+ */
131
+ opacityDir: "more" | "less" | null;
132
+ /**
133
+ * a removal: the changed values reach none or 0
134
+ */
135
+ zero: boolean;
136
+ /**
137
+ * the parts the question changes
138
+ */
139
+ subjects: string[];
140
+ /**
141
+ * the parts it excepts, compares against or forbids changing
142
+ */
143
+ keep: string[];
144
+ /**
145
+ * values the question gives (taken as given)
146
+ */
147
+ typed: string[];
148
+ /**
149
+ * the mode the question names
150
+ */
151
+ mode?: "light" | "dark" | null | undefined;
152
+ /**
153
+ * the question gives a bound ("smaller than 24px"): a space is checked against it too
154
+ */
155
+ bound?: boolean | undefined;
107
156
  };
@@ -20,7 +20,8 @@ import {
20
20
  readHistory,
21
21
  themeFiles,
22
22
  } from './_settings.mjs';
23
- import {LIKE, P} from './_tables.mjs';
23
+ import {FAMILIES, GROUPS, LIKE, P} from './_tables.mjs';
24
+ import {parseColor} from './_color.mjs';
24
25
  import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
25
26
 
26
27
  /** The theme name commands use when the app has no theme yet. */
@@ -54,6 +55,7 @@ export const EXAMPLE_THEME = 'my-theme';
54
55
  * @property {{light: Record<string, string>, dark: Record<string, string>}} base
55
56
  * @property {{light: Record<string, string>, dark: Record<string, string>}} [own] - The theme's own values: the base's with its settings applied.
56
57
  * @property {(steps: Step[]) => {ok: true} | {ok: false, why: string}} check
58
+ * @property {(steps: Step[], intent: MeasureIntent) => string | null} measure the measured check: why the built result does not do what the question asks, or null
57
59
  */
58
60
 
59
61
  /**
@@ -120,6 +122,9 @@ export async function howTheme(ctx, cwd, name) {
120
122
  const compiled = (/** @type {import('./_settings.mjs').ThemeData} */ d) =>
121
123
  JSON.stringify([d.mode, compileTheme(ctx, d, base)]);
122
124
  const before = compiled(theme);
125
+ /** @type {any} */
126
+ let beforeCache = null;
127
+ const beforeCompiled = () => (beforeCache ??= compileTheme(ctx, theme, base));
123
128
  // Whether a body font setting also moves the heading font: Core gives
124
129
  // headings the body family when a theme names no heading family, so it is
125
130
  // read from Core, and stays right when that changes.
@@ -184,6 +189,28 @@ export async function howTheme(ctx, cwd, name) {
184
189
  ? readHistory(themeFiles(cwd, slug).history).steps.length
185
190
  : 0,
186
191
  bodyFontReachesHeadings,
192
+ /**
193
+ * The measured check: build the theme with the steps in memory (the
194
+ * same compile `set` builds from; nothing is written), resolve every
195
+ * value the touched parts show at rest and in the named state or
196
+ * variant, in light and dark, before and after, and hold them to what
197
+ * the question asks. Returns why it does not fit, or null.
198
+ * @param {Step[]} steps
199
+ * @param {MeasureIntent} intent
200
+ * @returns {string | null}
201
+ */
202
+ measure(steps, intent) {
203
+ const d = JSON.parse(JSON.stringify(theme));
204
+ const checkCtx = /** @type {any} */ ({...ctx, base});
205
+ try {
206
+ for (const st of steps) apply(checkCtx, slug, d, st);
207
+ } catch {
208
+ return null; // check() says why
209
+ }
210
+ const was = beforeCompiled();
211
+ const now = compileTheme(ctx, d, base);
212
+ return measureFit(ctx, base, was, now, intent, steps);
213
+ },
187
214
  check(steps) {
188
215
  /** @type {import('./_settings.mjs').ThemeData} */
189
216
  const d = JSON.parse(JSON.stringify(theme));
@@ -209,6 +236,364 @@ export async function howTheme(ctx, cwd, name) {
209
236
  };
210
237
  }
211
238
 
239
+ /**
240
+ * What the measured check holds a command to.
241
+ * @typedef {object} MeasureIntent
242
+ * @property {string[]} families the kinds of change asked for (color, radius, space, border, weight, opacity, shadow, fontsize); empty: any
243
+ * @property {'more' | 'less' | null} dir the way a size moves
244
+ * @property {boolean | null} lighter the way a color moves
245
+ * @property {'more' | 'less' | null} opacityDir the way an opacity moves
246
+ * @property {boolean} zero a removal: the changed values reach none or 0
247
+ * @property {string[]} subjects the parts the question changes
248
+ * @property {string[]} keep the parts it excepts, compares against or forbids changing
249
+ * @property {string[]} typed values the question gives (taken as given)
250
+ * @property {'light' | 'dark' | null} [mode] the mode the question names
251
+ * @property {boolean} [bound] the question gives a bound ("smaller than 24px"): a space is checked against it too
252
+ */
253
+
254
+ /** A camelCase property as CSS writes it. @param {string} k */
255
+ const kebab = k => k.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
256
+
257
+ /**
258
+ * Every value of a compiled part, by `when|state|prop`.
259
+ * @param {any} comp the part's compiled styles
260
+ * @returns {Map<string, string>}
261
+ */
262
+ function partValues(comp) {
263
+ /** @type {Map<string, string>} */
264
+ const out = new Map();
265
+ for (const [when, rules] of Object.entries(comp ?? {}))
266
+ for (const [k, v] of Object.entries(/** @type {any} */ (rules) ?? {}))
267
+ if (v && typeof v === 'object')
268
+ for (const [k2, v2] of Object.entries(v))
269
+ out.set(`${when}|${k}|${kebab(k2)}`, String(v2));
270
+ else out.set(`${when}||${kebab(k)}`, String(v));
271
+ return out;
272
+ }
273
+
274
+ /**
275
+ * A value with every var() written out from a mode's tokens, and
276
+ * light-dark() taken for that mode.
277
+ * @param {string} v
278
+ * @param {Record<string, string>} map
279
+ * @param {'light' | 'dark'} mode
280
+ */
281
+ function resolveIn(v, map, mode) {
282
+ let out = String(v ?? '');
283
+ for (let i = 0; i < 8; i++) {
284
+ const next = out
285
+ .replace(/var\(\s*(--[a-z0-9-]+)\s*(?:,\s*([^()]*))?\)/gi, (_, t, fb) =>
286
+ String(map[t] ?? fb ?? ''),
287
+ )
288
+ .replace(
289
+ /light-dark\(\s*([^,()]+(?:\([^()]*\))?)\s*,\s*([^()]+(?:\([^()]*\))?)\s*\)/gi,
290
+ (_, a, b) => (mode === 'light' ? a : b),
291
+ );
292
+ if (next === out) break;
293
+ out = next;
294
+ }
295
+ return out.trim().toLowerCase();
296
+ }
297
+
298
+ /** The family of a CSS property or token, as the step check names them. @param {string} prop */
299
+ function familyOf(prop) {
300
+ if (/radius/.test(prop)) return 'radius';
301
+ if (/^--shadow-|^box-shadow$/.test(prop)) return 'shadow';
302
+ if (/^opacity$/.test(prop)) return 'opacity';
303
+ if (/weight/.test(prop)) return 'weight';
304
+ if (/^(font-size|--font-size-[a-z0-9]+|--text-[a-z0-9-]+-size)$/.test(prop))
305
+ return 'fontsize';
306
+ if (
307
+ /^(border(-[a-z]+)?-width|border(-(top|bottom|left|right|block|inline))?$|--border-width|--focus-outline-width|outline-width)$/.test(
308
+ prop,
309
+ )
310
+ )
311
+ return 'border';
312
+ if (/colou?r|^background(-image)?$|^fill$|^stroke$|^filter$/.test(prop))
313
+ return 'color';
314
+ if (
315
+ /^(padding|gap|margin|min-height|height|width|max-width|min-width|--spacing-|--size-)/.test(
316
+ prop,
317
+ )
318
+ )
319
+ return 'space';
320
+ return null;
321
+ }
322
+
323
+ /** A length as px (rem/em at 16), or a plain number, or null. @param {string} v */
324
+ function measureNumber(v) {
325
+ const m = /^(-?\d*\.?\d+)(px|rem|em)?$/.exec(
326
+ String(v).trim().split(/\s+/)[0],
327
+ );
328
+ return m ? Number(m[1]) * (m[2] === 'rem' || m[2] === 'em' ? 16 : 1) : null;
329
+ }
330
+
331
+ /**
332
+ * Whether a color is a foreground (text or a border): in dark mode "darker" asks it for more contrast, so it
333
+ * moves lighter there, and "lighter" darker; a fill moves the same way in
334
+ * both modes.
335
+ * @param {string} name a token or a property
336
+ */
337
+ const isForeground = name =>
338
+ !/background|surface|fill|accent|overlay/.test(name) &&
339
+ /text|border|outline|^color$|on-/.test(name);
340
+
341
+ /** @param {number[]} c */
342
+ const luminance = c => c[0] * 0.299 + c[1] * 0.587 + c[2] * 0.114;
343
+
344
+ /**
345
+ * Hold the after build to the intent; why it does not fit, or null.
346
+ * @param {any} ctx
347
+ * @param {any} base
348
+ * @param {any} was
349
+ * @param {any} now
350
+ * @param {MeasureIntent} intent
351
+ * @param {Step[]} steps
352
+ */
353
+ function measureFit(ctx, base, was, now, intent, steps) {
354
+ const tw = ownTokens(was, base);
355
+ const tn = ownTokens(now, base);
356
+ const C = ctx.C;
357
+ /** @param {string} part */
358
+ const members = part => FAMILIES[part] ?? [part];
359
+ // A kept part, or one state or variant of it (`part@when|state|`).
360
+ /** @type {Array<{part: string, prefix: string}>} */
361
+ const keeps = intent.keep.flatMap(k => {
362
+ const [part, prefix = ''] = k.split('@');
363
+ return members(part).map(m => ({part: m, prefix}));
364
+ });
365
+ const subjects = new Set(intent.subjects.flatMap(members));
366
+ /**
367
+ * The values a part shows, by `when|state|prop` and mode: its own
368
+ * compiled rules, then each token it reads for a property.
369
+ * @param {any} compiled
370
+ * @param {{light: Record<string, string>, dark: Record<string, string>}} toks
371
+ * @param {string} part
372
+ */
373
+ const shown = (compiled, toks, part) => {
374
+ const own = partValues({
375
+ ...(base.components?.[part] ?? {}),
376
+ ...(compiled.components?.[part] ?? {}),
377
+ });
378
+ /** @type {Map<string, string>} */
379
+ const raw = new Map(own);
380
+ // The part at rest in its main variant is its `base` too (a set with no
381
+ // --when writes base).
382
+ const mainWhen = (/** @type {string[]} */ ws) =>
383
+ ws.some(
384
+ w =>
385
+ w === '' ||
386
+ /^variant=(default|primary|accent|neutral)$|^size=md$/.test(w),
387
+ );
388
+ for (const g of Object.keys(GROUPS))
389
+ for (const r of C.partReads(part, g) ?? [])
390
+ if (mainWhen(r.when?.length ? r.when : ['']))
391
+ for (const prop of r.props ?? []) {
392
+ const key = `base||${prop}`;
393
+ if (!raw.has(key)) raw.set(key, `var(${r.token})`);
394
+ }
395
+ for (const g of Object.keys(GROUPS))
396
+ for (const r of C.partReads(part, g) ?? [])
397
+ for (const prop of r.props ?? [])
398
+ for (const w of r.when?.length ? r.when : [''])
399
+ if (!/::|:active|:hover|:focus|:checked|:disabled/.test(w)) {
400
+ const key = `${w ? w.replace('=', ':') : 'base'}||${prop}`;
401
+ // A variant with no rule of its own takes the part's own base
402
+ // rule over the token it reads.
403
+ if (!raw.has(key))
404
+ raw.set(key, own.get(`base||${prop}`) ?? `var(${r.token})`);
405
+ }
406
+ /** @type {Map<string, {light: string, dark: string, raw: string}>} */
407
+ const out = new Map();
408
+ for (const [k, v] of raw)
409
+ out.set(k, {
410
+ light: resolveIn(v, toks.light, 'light'),
411
+ dark: resolveIn(v, toks.dark, 'dark'),
412
+ raw: v,
413
+ });
414
+ return out;
415
+ };
416
+ // Parts the question keeps: every value they show is the same after.
417
+ for (const {part, prefix} of keeps) {
418
+ const a = shown(was, tw, part);
419
+ const b = shown(now, tn, part);
420
+ for (const [k, v] of b) {
421
+ // A whole kept part: its plain look (base); a state or variant: that.
422
+ if (prefix ? !k.startsWith(prefix) : !k.startsWith('base|')) continue;
423
+ const o = a.get(k);
424
+ // A value the part did not show before (a keep rule on a member that
425
+ // reads none of it) is not a change it shows; a corner longhand under
426
+ // a kept shorthand follows the shorthand.
427
+ if (!o) continue;
428
+ if (
429
+ /radius$/.test(k) &&
430
+ /-(start|end)-(start|end)-radius$/.test(k) &&
431
+ b.has('base||border-radius')
432
+ )
433
+ continue;
434
+ if (o.light !== v.light || o.dark !== v.dark)
435
+ return `it would change ${part} (${k.split('|').filter(Boolean).join(' ')}), which the question keeps as it is`;
436
+ }
437
+ }
438
+ const typed = new Set(intent.typed.map(x => x.toLowerCase()));
439
+ if (steps.some(st => typed.has(String(st.value ?? '').toLowerCase())))
440
+ return null;
441
+ // The subject's changed values: family, direction, removal.
442
+ const touched = new Set([
443
+ ...subjects,
444
+ ...steps
445
+ .map(st => st.on)
446
+ .filter(Boolean)
447
+ .flatMap(x => members(String(x))),
448
+ ]);
449
+ for (const part of touched) {
450
+ // A whole kept part is checked above, not as a subject.
451
+ if (keeps.some(k => k.part === part && !k.prefix)) continue;
452
+ const a = shown(was, tw, part);
453
+ const b = shown(now, tn, part);
454
+ for (const [k, v] of b) {
455
+ // A kept state or variant of the part is checked above.
456
+ if (
457
+ keeps.some(x => x.part === part && x.prefix && k.startsWith(x.prefix))
458
+ )
459
+ continue;
460
+ const prop = k.split('|')[2];
461
+ // A shorthand written where the part read longhands: its first side.
462
+ // (Whether the value before is the same rule's, not a stand-in.)
463
+ const exact = a.has(k);
464
+ const o =
465
+ a.get(k) ??
466
+ (prop === 'padding'
467
+ ? (a.get(`${k.split('|')[0]}||padding-top`) ??
468
+ a.get('base||padding-top'))
469
+ : prop === 'border'
470
+ ? a.get('base||border-width')
471
+ : a.get(`base||${prop}`));
472
+ if (o && o.light === v.light && o.dark === v.dark) continue;
473
+ const fam = familyOf(prop);
474
+ if (!fam) continue;
475
+ if (intent.families.length && !intent.families.includes(fam))
476
+ return `it would also change ${part}'s ${prop}, which is not what the question asks to change`;
477
+ for (const mode of /** @type {const} */ (['light', 'dark'])) {
478
+ const after = v[mode];
479
+ const before = o?.[mode] ?? null;
480
+ if (
481
+ intent.zero &&
482
+ ['radius', 'space', 'border', 'shadow'].includes(fam)
483
+ ) {
484
+ const n = measureNumber(after);
485
+ if (!/^(none|transparent|0)$/.test(after) && n !== 0)
486
+ return `${part}'s ${prop} would be ${after} in ${mode} mode, not none`;
487
+ continue;
488
+ }
489
+ if (before == null) continue;
490
+ if (fam === 'color' && intent.lighter != null) {
491
+ // A part's color, per variant: only the rule a step writes (its
492
+ // own --when, else the plain rule), in the mode the question
493
+ // names (else light), never an overlay layer over the fill.
494
+ if (intent.mode && mode !== intent.mode) continue;
495
+ const [when, state] = k.split('|');
496
+ const written = steps.some(
497
+ st =>
498
+ st.on &&
499
+ members(String(st.on)).includes(part) &&
500
+ (st.when ?? 'base') === when &&
501
+ (st.state ? `:${st.state}` : '') === state,
502
+ );
503
+ if (!written || !exact) continue;
504
+ if (
505
+ /overlay|tint/.test(String(o?.raw ?? '')) ||
506
+ /overlay|tint/.test(v.raw)
507
+ )
508
+ continue;
509
+ const x = parseColor(after);
510
+ const y = parseColor(before);
511
+ const want =
512
+ mode === 'dark' && isForeground(prop)
513
+ ? !intent.lighter
514
+ : intent.lighter;
515
+ if (x && y && Math.abs(luminance(x) - luminance(y)) >= 0.5)
516
+ if (want !== luminance(x) > luminance(y))
517
+ return `${part}'s ${prop}${when !== 'base' ? ` (${when})` : ''} would get ${want ? 'darker' : 'lighter'} in ${mode} mode (${before} to ${after})`;
518
+ continue;
519
+ }
520
+ const dir = fam === 'opacity' ? intent.opacityDir : intent.dir;
521
+ if (
522
+ !dir ||
523
+ !(
524
+ ['radius', 'border', 'weight', 'opacity', 'fontsize'].includes(
525
+ fam,
526
+ ) ||
527
+ // A space: one length written over one read (never a shorthand).
528
+ (fam === 'space' &&
529
+ (intent.bound ||
530
+ (exact &&
531
+ steps.some(st => st.thing === prop) &&
532
+ !/\s/.test(after) &&
533
+ !/\s/.test(String(before)))))
534
+ )
535
+ )
536
+ continue;
537
+ const x = measureNumber(after);
538
+ const y = measureNumber(before);
539
+ if (x != null && y != null && x !== y && (dir === 'more') !== x > y)
540
+ return `${part}'s ${prop} would move the other way in ${mode} mode (${before} to ${after})`;
541
+ }
542
+ }
543
+ }
544
+ // Tokens the steps name (a dial: its main token): the same checks.
545
+ const DIAL_TOKEN = /** @type {Record<string, string>} */ ({
546
+ accent: '--color-accent',
547
+ danger: '--color-error',
548
+ success: '--color-success',
549
+ warning: '--color-warning',
550
+ info: '--color-info',
551
+ neutral: '--color-neutral',
552
+ });
553
+ for (const st of steps) {
554
+ const tok = /^--/.test(st.thing) ? st.thing : DIAL_TOKEN[st.thing];
555
+ if (!tok || st.on) continue;
556
+ const fam = familyOf(tok);
557
+ if (!fam) continue;
558
+ if (intent.families.length && !intent.families.includes(fam))
559
+ return `${tok} is not what the question asks to change`;
560
+ for (const mode of /** @type {const} */ (['light', 'dark'])) {
561
+ const after = resolveIn(`var(${tok})`, tn[mode], mode);
562
+ const before = resolveIn(`var(${tok})`, tw[mode], mode);
563
+ if (after === before) continue;
564
+ if (
565
+ intent.zero &&
566
+ ['radius', 'space', 'border', 'shadow'].includes(fam)
567
+ ) {
568
+ const n = measureNumber(after);
569
+ if (!/^(none|transparent|0)$/.test(after) && n !== 0)
570
+ return `${tok} would be ${after} in ${mode} mode, not none`;
571
+ continue;
572
+ }
573
+ if (fam === 'color' && intent.lighter != null) {
574
+ if (intent.mode && mode !== intent.mode) continue;
575
+ const x = parseColor(after);
576
+ const y = parseColor(before);
577
+ const want =
578
+ mode === 'dark' && isForeground(tok)
579
+ ? !intent.lighter
580
+ : intent.lighter;
581
+ if (x && y && Math.abs(luminance(x) - luminance(y)) >= 0.5)
582
+ if (want !== luminance(x) > luminance(y))
583
+ return `${tok} would get ${want ? 'darker' : 'lighter'} in ${mode} mode (${before} to ${after})`;
584
+ continue;
585
+ }
586
+ const dir = fam === 'opacity' ? intent.opacityDir : intent.dir;
587
+ if (!dir) continue;
588
+ const x = measureNumber(after);
589
+ const y = measureNumber(before);
590
+ if (x != null && y != null && x !== y && (dir === 'more') !== x > y)
591
+ return `${tok} would move the other way in ${mode} mode (${before} to ${after})`;
592
+ }
593
+ }
594
+ return null;
595
+ }
596
+
212
597
  /**
213
598
  * Apply one step to theme data in memory, as `set` and `undo` do.
214
599
  * @param {import('./_settings.mjs').Ctx} ctx
@@ -1,6 +1,51 @@
1
1
  // @generated by scripts/sync-api-types.mjs from the JSDoc in api/**/*.mjs.
2
2
  // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
3
 
4
+ /**
5
+ * Warmer or cooler: mix in a warm (amber) or cool (blue) tint and keep the
6
+ * color's lightness, so the hue moves and the light/dark does not.
7
+ * @param {string} color @param {'warm' | 'cool'} way @param {number} amount 0 to 1
8
+ */
9
+ export function tempShift(color: string, way: "warm" | "cool", amount: number): string | null;
10
+ /**
11
+ * A box-shadow with each layer's blur scaled (the third length); offsets,
12
+ * spread, inset and color stay. Null when no layer has a blur to scale.
13
+ * @param {string} shadow @param {number} f
14
+ */
15
+ export function blurScaled(shadow: string, f: number): string | null;
16
+ /**
17
+ * The share a color amount gives ("30% lighter", "half as dark"): a
18
+ * number from 0 to 0.9, or the fallback.
19
+ * @param {string} text @param {number} fallback
20
+ */
21
+ export function colorAmount(text: string, fallback: number): number;
22
+ /**
23
+ * {@link shift} that keeps a see-through color see-through: its alpha
24
+ * stays, only its hue moves.
25
+ * @param {string} color @param {number} amount
26
+ */
27
+ export function shiftKeepAlpha(color: string, amount: number): string | null;
28
+ /**
29
+ * The color token a part reads at rest for a group (its fill or its text):
30
+ * the variant asked for, else its main variant (primary, accent), else any
31
+ * read at rest; never a pressed or hover overlay.
32
+ * @param {Array<{token: string, when: string[]}>} reads
33
+ * @param {string} [when] a variant asked for, `variant:primary`
34
+ * @returns {string | null}
35
+ */
36
+ export function restColorRead(reads: Array<{
37
+ token: string;
38
+ when: string[];
39
+ }>, when?: string): string | null;
40
+ /**
41
+ * A color with its hue moved toward a target hue by up to `step` degrees;
42
+ * lightness and saturation stay. Null for a color that does not read, or
43
+ * a gray (no hue to move).
44
+ * @param {string} color
45
+ * @param {number} target degrees
46
+ * @param {number} step degrees
47
+ */
48
+ export function hueToward(color: string, target: number, step: number): string | null;
4
49
  /**
5
50
  * An exact relative amount the words give ("half", "double", "twice",
6
51
  * "triple", "a third", "a quarter", "50%", "x0.8"), as a factor of the
@@ -43,6 +88,13 @@ export function draftAnswer(ctx: import("./_settings.mjs").Ctx, env: import("./_
43
88
  aspects: string[];
44
89
  drafts: Draft[];
45
90
  };
91
+ /**
92
+ * The property a question asks the value of ("how much padding …", "how
93
+ * rounded are …", "what color is …"), or null when it is not one.
94
+ * @param {string} q
95
+ * @returns {string | null}
96
+ */
97
+ export function valueAsked(q: string): string | null;
46
98
  /**
47
99
  * One clause, read.
48
100
  */
@@ -53,6 +105,7 @@ export type Clause = {
53
105
  when?: string;
54
106
  role?: string;
55
107
  level?: string;
108
+ missing?: string;
56
109
  }>;
57
110
  aspects: string[];
58
111
  neg: boolean;
@@ -87,6 +140,7 @@ export type Clause = {
87
140
  } | null;
88
141
  };
89
142
  export type Step = import("./_how-commands.mjs").Step;
143
+ export type MeasureIntent = import("./_how-commands.mjs").MeasureIntent;
90
144
  /**
91
145
  * One answer: what it does, and the ways to do it. Each option is a list of
92
146
  * steps run in order; most options are one step.
@@ -96,10 +150,12 @@ export type Draft = {
96
150
  options: Step[][];
97
151
  sequence?: boolean;
98
152
  lookup?: string;
153
+ intent?: MeasureIntent;
99
154
  };
100
155
  export type PartRef = {
101
156
  on: string;
102
157
  when?: string;
103
158
  role?: string;
104
159
  level?: string;
160
+ missing?: string;
105
161
  };