@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
@@ -16,7 +16,7 @@ export const doc = {
16
16
  summary:
17
17
  'Render a page to one self-contained HTML file, or turn a rendered file back into a page.',
18
18
  description:
19
- "Renders the page module's default export on the server with the project's own React and Astryx components (outside a project, with the Astryx, React and StyleX the CLI runs with), and writes ONE static HTML file that needs nothing beside it: the page's own StyleX styles are compiled, Core's stylesheets are cut to the rules the markup uses (layer order, custom properties and keyframes kept), local images become data: URIs, and the page's source is embedded so it can be given back exactly. The file runs no script and loads nothing from the network, so it works inside a sandboxed frame with a strict content security policy, and its colors follow the viewer's light or dark scheme. Warnings name anything that may differ from what the author meant, such as a component that did not render the text it was given. With `reverse`, it writes the embedded source back byte for byte, and only the files a render embeds: the page and the local modules, stylesheets, JSON files and images it imports, into a new folder; a file with Astryx markup but no embedded source is rebuilt from its component class names and data attributes (text and layout only); any other file is refused. Experimental: it may change or be removed in a patch release.",
19
+ "Renders the page module's default export on the server with the project's own React and Astryx components (outside a project, with the Astryx, React and StyleX the CLI runs with), and writes ONE static HTML file that needs nothing beside it: the page's own StyleX styles are compiled, Core's stylesheets are cut to the rules the markup uses (layer order, custom properties and keyframes kept), local images become data: URIs, and the page's source is embedded so it can be given back exactly. The file runs no script and loads nothing from the network, so it works inside a sandboxed frame with a strict content security policy, and its colors follow the viewer's light or dark scheme. Warnings name anything that may differ from what the author meant, such as a component that did not render the text it was given. The file opens with a plain note for its next reader, a person or an agent: the CLI version and render format that made it, the page's path, the files it carries, the packages and versions it rendered with, and the exact commands that give the page back and render it again; the embedded source records the same facts and the markup as rendered. With `reverse` (the way back, or unrender), it writes the embedded source back byte for byte, and only the files a render embeds: the page and the local modules, stylesheets, JSON files and images it imports, into a new folder; it also reports the render format, the CLI version and packages that rendered the file, and whether someone changed the markup after the render, naming each run of text that changed and where the old text sits in the restored source (the restored files stay the page as rendered); a file with Astryx markup but no embedded source is rebuilt from its component class names and data attributes (text and layout only); any other file is refused. Experimental: it may change or be removed in a patch release.",
20
20
  importPath: '@astryxdesign/cli/api/experimental',
21
21
  signature:
22
22
  'render(file: string, options?: RenderOptions): Promise<RenderPageResponse | RenderReverseResponse>',
@@ -29,6 +29,9 @@ export const doc = {
29
29
  'snapshot',
30
30
  'self-contained',
31
31
  'reverse',
32
+ 'unrender',
33
+ 'restore',
34
+ 'round trip',
32
35
  ],
33
36
  params: [
34
37
  {
@@ -77,7 +80,7 @@ export const doc = {
77
80
  {
78
81
  type: 'render.reverse',
79
82
  description:
80
- "How the page came back (`embedded`, exact; or `rebuilt`, text and layout only), the files written, and for a rebuilt page the components it uses and what could not be rebuilt.",
83
+ "How the page came back (`embedded`, exact; or `rebuilt`, text and layout only), the files written; for an embedded page the render format, the CLI version and packages that rendered it, and whether its markup changed after the render, with each text change; for a rebuilt page the components it uses and what could not be rebuilt.",
81
84
  },
82
85
  ],
83
86
  throws: [
@@ -101,7 +104,11 @@ export const doc = {
101
104
  code: 'ERR_RENDER_NOT_ASTRYX',
102
105
  when: 'reversing a file a render did not write, with no embedded source and no Astryx markup; the suggestion is `astryx build "<what the page is>"`',
103
106
  },
104
- {code: 'ERR_RENDER_SOURCE_DAMAGED', when: 'reversing a file a render wrote whose embedded source was removed (and that has no Astryx components to rebuild from), a file whose embedded source is damaged, lists a path twice, carries a module, stylesheet or JSON file the page does not reach through its imports, or an image, font or media file whose bytes are not one, or carries a file a render never embeds (a dotfile or dot-folder, `node_modules`, a package manifest, lockfile or tool configuration, or any kind but a page module, stylesheet, JSON or image)'},
107
+ {code: 'ERR_RENDER_SOURCE_DAMAGED', when: 'reversing a file a render wrote whose embedded source was removed (and that has no Astryx components to rebuild from), a file a render wrote that ends before its embedded source, a file that holds merge conflict markers, a file whose embedded source is cut short or damaged (or names a CLI version that is not a release version), lists a path twice, carries a module, stylesheet or JSON file the page does not reach through its imports, or an image, font or media file whose bytes are not one, or carries a file a render never embeds (a dotfile or dot-folder, `node_modules`, a package manifest, lockfile or tool configuration, or any kind but a page module, stylesheet, JSON or image)'},
108
+ {
109
+ code: 'ERR_RENDER_NEWER_FORMAT',
110
+ when: 'reversing a file in a newer render format than this CLI reads; the message and the suggestion name the CLI version that wrote it',
111
+ },
105
112
  {code: 'ERR_PATH_TRAVERSAL', when: 'a file would be written outside the current folder (symlinks followed), or through a symbolic link: `out`, or with `reverse` the page or an embedded file; or, with `reverse`, a file other than the page would go into a folder that already exists'},
106
113
  ],
107
114
  examples: [
@@ -37,6 +37,28 @@ export type RenderWarning = {
37
37
  */
38
38
  message: string;
39
39
  };
40
+ /**
41
+ * A run of text in a rendered file that differs from the text the render
42
+ * wrote: someone edited the HTML after the render.
43
+ */
44
+ export type RenderEdit = {
45
+ /**
46
+ * - The text as rendered; null for text added after the render.
47
+ */
48
+ was: string | null;
49
+ /**
50
+ * - The text the file holds now; null for text removed after the render.
51
+ */
52
+ now: string | null;
53
+ /**
54
+ * - The restored module that holds the text as rendered, when it appears there exactly once.
55
+ */
56
+ file?: string | undefined;
57
+ /**
58
+ * - The line of `file` where that text starts.
59
+ */
60
+ line?: number | undefined;
61
+ };
40
62
  /**
41
63
  * `astryx --json experimental render <page>`.
42
64
  */
@@ -70,5 +92,13 @@ export type RenderReverseResponse = {
70
92
  elements?: number | undefined;
71
93
  unknown?: string[] | undefined;
72
94
  omitted?: string[] | undefined;
95
+ format?: number | undefined;
96
+ renderedBy?: string | undefined;
97
+ packages?: string[] | undefined;
98
+ title?: string | undefined;
99
+ edited?: boolean | undefined;
100
+ stylesEdited?: boolean | undefined;
101
+ edits?: RenderEdit[] | undefined;
102
+ moreEdits?: number | undefined;
73
103
  };
74
104
  };
@@ -26,6 +26,17 @@
26
26
  * @property {string} message - What happened and what to do, in one sentence.
27
27
  */
28
28
 
29
+ /**
30
+ * A run of text in a rendered file that differs from the text the render
31
+ * wrote: someone edited the HTML after the render.
32
+ * @experimental May change or be removed in a patch release.
33
+ * @typedef {object} RenderEdit
34
+ * @property {string | null} was - The text as rendered; null for text added after the render.
35
+ * @property {string | null} now - The text the file holds now; null for text removed after the render.
36
+ * @property {string} [file] - The restored module that holds the text as rendered, when it appears there exactly once.
37
+ * @property {number} [line] - The line of `file` where that text starts.
38
+ */
39
+
29
40
  /**
30
41
  * `astryx --json experimental render <page>`.
31
42
  * @experimental May change or be removed in a patch release.
@@ -59,6 +70,14 @@
59
70
  * @property {number} [data.elements] - Rebuilt only: how many component elements were rebuilt.
60
71
  * @property {string[]} [data.unknown] - Rebuilt only: Astryx class names no installed component claims; their content is kept as plain elements.
61
72
  * @property {string[]} [data.omitted] - Rebuilt only: component kinds left out because the markup cannot give them back (such as icons).
73
+ * @property {number} [data.format] - Embedded only: the render format of the file's embedded source.
74
+ * @property {string} [data.renderedBy] - Embedded only: the version of the CLI that rendered the file, when the file names it.
75
+ * @property {string[]} [data.packages] - Embedded only, when the file records them: the packages the page rendered with, as `name@version`.
76
+ * @property {string} [data.title] - Embedded only: the title given with --title when the page was rendered, which a render again needs too.
77
+ * @property {boolean} [data.edited] - Embedded only, when the file records the page as rendered: whether someone changed its markup, title or styles after the render. The restored files are always the page as rendered, without those changes.
78
+ * @property {boolean} [data.stylesEdited] - With `edited`: whether the styles (the <style> element) changed after the render.
79
+ * @property {RenderEdit[]} [data.edits] - When `edited`: each run of text that changed after the render (at most 50, the title first), so the change can be made in the source. Empty when only styles, attributes, elements or formatting changed.
80
+ * @property {number} [data.moreEdits] - When `edits` stops at 50: how many more changes there are.
62
81
  */
63
82
 
64
83
  export {};
@@ -6,7 +6,7 @@
6
6
 
7
7
  `spec:AST-083` owns search's result order; this file describes the data that implements it. Inside one score band, a searcher's static weights decide the order. Matches with the same score move together as one block, placed by the learned position of the block's first match: moving each one on its own breaks search's existing rules for tied matches. Inside a block, the lexical ranker's order holds, except below the first result: there a block of one domain puts a part of the first result first (its name words start with the first result's; at most two parts lead across an answer), then the match whose matched words are rarer in the catalog. Matches never cross bands or kinds. There is no model runtime: every number is a plain static value read at load time.
8
8
 
9
- After that order, one fit pass reads the first ten results (`_fit-order.mjs`). The first result stays. The others split into runs of one band and kind. Inside a run, each match gets a fit to the whole query from build's block-picker match (`../build/blocks/blocks.mjs` with `blocks.weights.json`) over the match's own docs: its name words, display name or title, description, and keywords. A match whose fit is under 1.7 times the run's median fit moves, in order, after the others in its run, unless its name spells two or more of the query's words. Such a match never moves down; it can still move up when others move after it. A run whose median fit is zero or less keeps its order. A query that is an entry's whole name skips the pass, as it skips the learned order. The pass always reads ten places before the limit cuts the answer. At the default limit, and at any limit of 10 or more, the set of results stays the same. A smaller limit shows the top of the new order, so it can show a different result. Build's loader (`loadBlockPicker` in `../build/_adapter.mjs`) reads and checks the block-picker weights for both commands. When the file is missing, unreadable, or not the picker's shape, the loader returns null and the pass keeps the order. The pass reads the weights only when a run holds two or more matches, and it decodes only the matrix rows that the query's words and those matches' docs use, so a search does not pay for the whole catalog.
9
+ After that order, one fit pass reads the first ten results (`_fit-order.mjs`). The first result stays. The others split into runs of one band and kind. Inside a run, each match gets a fit to the whole query from the block picker's `matchOf` (`../build/blocks/blocks.mjs` with `blocks.weights.json`, over the weights' vocabulary) over the match's own docs: its name words, display name or title, description, and keywords. A match whose fit is under 1.7 times the run's median fit moves, in order, after the others in its run, unless its name spells two or more of the query's words. Such a match never moves down; it can still move up when others move after it. A run whose median fit is zero or less keeps its order. A query that is an entry's whole name skips the pass, as it skips the learned order. The pass always reads ten places before the limit cuts the answer. At the default limit, and at any limit of 10 or more, the set of results stays the same. A smaller limit shows the top of the new order, so it can show a different result. Build's loader (`loadBlockPicker` in `../build/_adapter.mjs`) reads and checks the block-picker weights for both commands. When the file is missing, unreadable, or not the picker's shape, the loader returns null and the pass keeps the order. The pass reads the weights only when a run holds two or more matches, and it decodes only the matrix rows that the query's words and those matches' docs use, so a search does not pay for the whole catalog.
10
10
 
11
11
  ## Files
12
12
 
@@ -130,25 +130,50 @@ function mentionPattern(term, t) {
130
130
  }
131
131
 
132
132
  /**
133
- * Each prose text lowercased once per process: a search reads every
134
- * candidate's description for every term.
135
- * @type {Map<string, string>}
133
+ * Each candidate's names and keywords lowercased once, and its description,
134
+ * prose and guidance lowercased on first use: a search scores every candidate
135
+ * for every term and synonym. Keyed by the candidate object, so it goes when
136
+ * the catalog does. A candidate's name, aliases, keywords, description, prose
137
+ * and guidance must not change after its first score, as no catalog changes
138
+ * them: an edited candidate, including one in a stored index passed to
139
+ * `rankSearchIndex()` again, would still be scored on its first text.
140
+ * @type {WeakMap<object, {names: {name: string, lower: string, leaf: string}[], keywords: {kw: string, text: string, lower: string}[], description?: string, prose: (string | undefined)[], guidance: (string | undefined)[]}>}
136
141
  */
137
- const lowered = new Map();
142
+ const prepared = new WeakMap();
138
143
 
139
- /** How many texts are kept lowercased before the cache starts over. */
140
- const CACHE_LIMIT = 100_000;
144
+ /** @param {any} candidate */
145
+ function prepare(candidate) {
146
+ let p = prepared.get(candidate);
147
+ if (p === undefined) {
148
+ const {name, aliases = [], keywords = []} = candidate;
149
+ p = {
150
+ names: [name, ...aliases.filter(Boolean)].map(n => {
151
+ const l = n.toLowerCase();
152
+ return {name: n, lower: l, leaf: l.slice(l.lastIndexOf('/') + 1)};
153
+ }),
154
+ keywords: keywords.map((/** @type {string} */ kw) => {
155
+ const text = String(kw);
156
+ return {kw, text, lower: text.toLowerCase()};
157
+ }),
158
+ description: undefined,
159
+ prose: [],
160
+ guidance: [],
161
+ };
162
+ prepared.set(candidate, p);
163
+ }
164
+ return p;
165
+ }
141
166
 
142
167
  /**
143
- * @param {string} text
144
- * @returns {string}
168
+ * @param {(string | undefined)[]} memo
169
+ * @param {unknown[]} blobs
170
+ * @param {number} i
145
171
  */
146
- function lower(text) {
147
- let out = lowered.get(text);
172
+ function loweredAt(memo, blobs, i) {
173
+ let out = memo[i];
148
174
  if (out === undefined) {
149
- if (lowered.size >= CACHE_LIMIT) lowered.clear();
150
- out = text.toLowerCase();
151
- lowered.set(text, out);
175
+ out = String(blobs[i]).toLowerCase();
176
+ memo[i] = out;
152
177
  }
153
178
  return out;
154
179
  }
@@ -196,10 +221,7 @@ export function scoreCandidate(
196
221
  {fuzzy = true, joins = true, part = false, synonym = false} = {},
197
222
  ) {
198
223
  const {
199
- name,
200
- aliases = [],
201
224
  domain,
202
- keywords = [],
203
225
  description = '',
204
226
  prose = [],
205
227
  guidance = [],
@@ -208,6 +230,7 @@ export function scoreCandidate(
208
230
  } = candidate;
209
231
  // The term's forms, worked out once for every word below.
210
232
  const t = termWords(term);
233
+ const p = prepare(candidate);
211
234
  let best = 0;
212
235
  let reason = '';
213
236
  /** @type {'partial' | 'keyword' | false} */
@@ -229,11 +252,13 @@ export function scoreCandidate(
229
252
  // ── Name signals ────────────────────────────────────────────────
230
253
  // An alias is a name too: a theme answers to its display name as well as
231
254
  // its slug.
232
- for (const candidateName of [name, ...aliases.filter(Boolean)]) {
233
- const nameLower = candidateName.toLowerCase();
255
+ for (const {
256
+ name: candidateName,
257
+ lower: nameLower,
258
+ leaf: leafLower,
259
+ } of p.names) {
234
260
  // A placed guide's name is its route, and the route's last segment is its
235
261
  // name too, as a flat topic's is: `codemods` is authoring/building-blocks/codemods.
236
- const leafLower = nameLower.slice(nameLower.lastIndexOf('/') + 1);
237
262
 
238
263
  // A plural of the name is the name: `integration` is the `integrations`
239
264
  // guides, `tab` the `tabs` doc.
@@ -315,8 +340,7 @@ export function scoreCandidate(
315
340
 
316
341
  // ── Keyword signals ─────────────────────────────────────────────
317
342
  const termJoined = joined(term);
318
- for (const kw of keywords) {
319
- const kwLower = String(kw).toLowerCase();
343
+ for (const {kw, text: kwText, lower: kwLower} of p.keywords) {
320
344
  // A one-word keyword typed as separate words is the keyword: `number
321
345
  // field` is `numberfield`. Only a
322
346
  // lowercase keyword, one an author declares for a reader to type: a
@@ -326,12 +350,7 @@ export function scoreCandidate(
326
350
  consider(90, `keyword "${kw}"`);
327
351
  continue;
328
352
  }
329
- if (
330
- joins &&
331
- domain !== 'doc' &&
332
- /\s/.test(term) &&
333
- String(kw) === termJoined
334
- ) {
353
+ if (joins && domain !== 'doc' && /\s/.test(term) && kwText === termJoined) {
335
354
  consider(90, `keyword "${kw}"`, 'keyword');
336
355
  continue;
337
356
  }
@@ -368,12 +387,12 @@ export function scoreCandidate(
368
387
  // so "chart" matches "charts" and "filter" matches "filtering".
369
388
  if (term.length >= 3) {
370
389
  const re = mentionPattern(term, t);
371
- if (description && re.test(lower(description))) {
390
+ if (description && re.test((p.description ??= description.toLowerCase()))) {
372
391
  consider(50, `description mentions "${term}"`);
373
392
  } else {
374
393
  let matchedProse = false;
375
- for (const blob of prose) {
376
- if (blob && re.test(lower(String(blob)))) {
394
+ for (let i = 0; i < prose.length; i++) {
395
+ if (prose[i] && re.test(loweredAt(p.prose, prose, i))) {
377
396
  consider(50, `docs mention "${term}"`);
378
397
  matchedProse = true;
379
398
  break;
@@ -383,8 +402,8 @@ export function scoreCandidate(
383
402
  // so the term appearing there is weaker evidence than the component's own
384
403
  // summary. Only consulted when nothing stronger matched.
385
404
  if (!matchedProse) {
386
- for (const blob of guidance) {
387
- if (blob && re.test(lower(String(blob)))) {
405
+ for (let i = 0; i < guidance.length; i++) {
406
+ if (guidance[i] && re.test(loweredAt(p.guidance, guidance, i))) {
388
407
  consider(45, `guidance mentions "${term}"`);
389
408
  break;
390
409
  }
@@ -8,9 +8,9 @@
8
8
  * @output the same response with the same results, maybe in a new order
9
9
  * @position api/search; rankWith (_main-searcher.mjs) runs it after
10
10
  * orderMatches, with the weights the adapter loads (loadSearchData) through
11
- * build's own loader. The fit is build's block-picker match
12
- * (build/blocks/blocks.mjs) with its shipped weights, so an entry the weights
13
- * never saw is scored from its own docs the same way. Without readable
11
+ * build's own loader. The fit is the block picker's `matchOf`
12
+ * (build/blocks/blocks.mjs) over the shipped weights' vocabulary, so an entry
13
+ * the weights never saw is scored from its own docs the same way. Without readable
14
14
  * weights the order stays.
15
15
  */
16
16
 
@@ -17,7 +17,7 @@
17
17
  * (spec AST-081 FR3).
18
18
  */
19
19
  export function toResult(c: Candidate, score: number, reason: string, matchedTerms: number, queryTerms: number, outside?: boolean): {
20
- domain: "template" | "component" | "doc" | "theme" | "hook";
20
+ domain: "component" | "template" | "doc" | "theme" | "hook";
21
21
  name: string;
22
22
  package: string | undefined;
23
23
  score: number;
@@ -27,7 +27,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
27
27
  deprecated?: import("../../authoring/index.js").ComponentDeprecation | undefined;
28
28
  import: string | undefined;
29
29
  command: string;
30
- domain: "template" | "component" | "doc" | "theme" | "hook";
30
+ domain: "component" | "template" | "doc" | "theme" | "hook";
31
31
  name: string;
32
32
  package: string | undefined;
33
33
  score: number;
@@ -39,7 +39,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
39
39
  command: string;
40
40
  section?: string | undefined;
41
41
  name: string;
42
- domain: "template" | "component" | "doc" | "theme" | "hook";
42
+ domain: "component" | "template" | "doc" | "theme" | "hook";
43
43
  package: string | undefined;
44
44
  score: number;
45
45
  reason: string;
@@ -48,7 +48,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
48
48
  displayName: string | undefined;
49
49
  kind: "page" | "block" | undefined;
50
50
  command: string;
51
- domain: "template" | "component" | "doc" | "theme" | "hook";
51
+ domain: "component" | "template" | "doc" | "theme" | "hook";
52
52
  name: string;
53
53
  package: string | undefined;
54
54
  score: number;
@@ -57,7 +57,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
57
57
  } | {
58
58
  displayName: string | undefined;
59
59
  command: string;
60
- domain: "template" | "component" | "doc" | "theme" | "hook";
60
+ domain: "component" | "template" | "doc" | "theme" | "hook";
61
61
  name: string;
62
62
  package: string | undefined;
63
63
  score: number;
@@ -7,12 +7,17 @@
7
7
  * @param {string} tok
8
8
  * @param {Candidate} candidate
9
9
  * @param {{fuzzy?: boolean, part?: boolean}} [opts] - see scoreCandidate
10
+ * @param {{score: number, reason: string} | null} [direct] - scoreCandidate(tok,
11
+ * candidate, opts), when the caller already holds it
10
12
  * @returns {{score: number, reason: string} | null}
11
13
  */
12
14
  export function bestForToken(tok: string, candidate: Candidate, opts?: {
13
15
  fuzzy?: boolean;
14
16
  part?: boolean;
15
- }): {
17
+ }, direct?: {
18
+ score: number;
19
+ reason: string;
20
+ } | null): {
16
21
  score: number;
17
22
  reason: string;
18
23
  } | null;
@@ -40,10 +40,13 @@ const MIN_TOKEN_SCORE = 50;
40
40
  * @param {string} tok
41
41
  * @param {Candidate} candidate
42
42
  * @param {{fuzzy?: boolean, part?: boolean}} [opts] - see scoreCandidate
43
+ * @param {{score: number, reason: string} | null} [direct] - scoreCandidate(tok,
44
+ * candidate, opts), when the caller already holds it
43
45
  * @returns {{score: number, reason: string} | null}
44
46
  */
45
- export function bestForToken(tok, candidate, opts = {}) {
46
- let best = scoreCandidate(tok, candidate, opts);
47
+ export function bestForToken(tok, candidate, opts = {}, direct = undefined) {
48
+ let best =
49
+ direct !== undefined ? direct : scoreCandidate(tok, candidate, opts);
47
50
  const syns = SYNONYM_INDEX.get(tok);
48
51
  if (syns) {
49
52
  for (const s of syns) {
@@ -131,8 +134,17 @@ export function scoreQuery(
131
134
  * single words), but if stopwords left exactly one DIFFERENT token (e.g.
132
135
  * "pricing page" → "pricing"), score that token too and take the stronger. */
133
136
  const fewTokens = () => {
137
+ // A one-word query whose token is the query itself scores exactly as
138
+ // `full` did: `joins` only matters for a term with a space in it.
134
139
  const single =
135
- tokens.length === 1 ? bestForToken(tokens[0], candidate, {fuzzy}) : null;
140
+ tokens.length === 1
141
+ ? bestForToken(
142
+ tokens[0],
143
+ candidate,
144
+ {fuzzy},
145
+ tokens[0] === term && !/\s/.test(term) ? full : undefined,
146
+ )
147
+ : null;
136
148
  if (full && (!single || full.score >= single.score)) return asFull(full);
137
149
  return single ? asFull(single) : null;
138
150
  };
@@ -13,7 +13,7 @@
13
13
  */
14
14
  export function search(query: string, options?: {
15
15
  cwd?: string | undefined;
16
- type?: "template" | "component" | "doc" | "theme" | "hook" | undefined;
16
+ type?: "component" | "template" | "doc" | "theme" | "hook" | undefined;
17
17
  limit?: number | undefined;
18
18
  }): Promise<import("./search.type.mjs").SearchResponse>;
19
19
  /**
@@ -1186,6 +1186,7 @@ async function writeThemeApp(
1186
1186
  stylesheet: theme.stylesheet,
1187
1187
  ...(theme.fontStylesheet ? {fontStylesheet: theme.fontStylesheet} : {}),
1188
1188
  source: theme.source,
1189
+ ...(theme.mode ? {mode: theme.mode} : {}),
1189
1190
  })),
1190
1191
  default: defaultSlug,
1191
1192
  modulePath: prepared.module.path,
@@ -1194,6 +1195,15 @@ async function writeThemeApp(
1194
1195
  slug,
1195
1196
  changed,
1196
1197
  firstAdd: action === 'add' && !state.configured,
1198
+ // The module lists one-mode themes' modes for the first time, after
1199
+ // the app was wired without them: the wiring takes the mode now.
1200
+ ...(state.configured &&
1201
+ /\bexport const themeModes\b/.test(prepared.moduleContents) &&
1202
+ !/\bexport const themeModes\b/.test(
1203
+ String(prepared.module.expectedOriginal ?? ''),
1204
+ )
1205
+ ? {wireModes: true}
1206
+ : {}),
1197
1207
  },
1198
1208
  ...(notes.length > 0 ? {notes} : {}),
1199
1209
  },
@@ -57,6 +57,34 @@ export function normalizeThemeBuildForCompare(content: string): string;
57
57
  * @returns {boolean}
58
58
  */
59
59
  export function isPrivateVarRefusal(error: unknown): boolean;
60
+ /**
61
+ * The marks a file's leading comment carries (see `generatedMark`): a theme
62
+ * build's output, or a file the theme editor writes, with the command it
63
+ * names. The one reader build and doctor share.
64
+ * @param {string} source the start of the file
65
+ * @param {string} [file] its path, for a mark that names no exact command
66
+ */
67
+ export function fileMark(source: string, file?: string): {
68
+ kind: "build" | "editor";
69
+ command: string;
70
+ } | null;
71
+ /**
72
+ * The command a file's leading comment says writes it, when another CLI
73
+ * command generates it (the theme editor's settings module or app copy):
74
+ * the exact command its mark names. Null for a theme build's own output and
75
+ * a file without a mark, such as a theme source of one's own.
76
+ * @param {string} file
77
+ * @returns {string | null}
78
+ */
79
+ export function generatedFileCommand(file: string): string | null;
80
+ /**
81
+ * The command that writes `file`: from its own mark, or, when it is
82
+ * missing, from the files beside it (see `missingGeneratedCommand`); null
83
+ * otherwise.
84
+ * @param {string} file
85
+ * @returns {string | null}
86
+ */
87
+ export function generatedSourceCommand(file: string): string | null;
60
88
  /**
61
89
  * The files a theme source is made of: the source and every local file it
62
90
  * imports, directly or through other local files, read from their import
@@ -129,6 +157,13 @@ export function writeDeferredBuildOutputs(deferred: Array<Array<{
129
157
  * @returns {string}
130
158
  */
131
159
  export function importSpecifier(relDir: string, base: string): string;
160
+ /**
161
+ * A one-mode `colorModes` value (`['light']` or `['dark']`), or null for
162
+ * anything else: a theme with both modes needs no export.
163
+ * @param {unknown} value
164
+ * @returns {['light'] | ['dark'] | null}
165
+ */
166
+ export function oneColorMode(value: unknown): ["light"] | ["dark"] | null;
132
167
  /**
133
168
  * The package a theme load failed on because it is not installed.
134
169
  * @param {unknown} error
@@ -359,6 +394,8 @@ export type ThemeBuildTrailer = {
359
394
  * output must stay inside, for a scratch build; `commandWords` names the
360
395
  * command in the rebuild hint; `prepareFamily`, `familyLoader`, and
361
396
  * `familyInterception` make the build a family member's plan.
397
+ * `colorModes` is the one color mode a calling command knows the theme has
398
+ * (the theme editor, from its settings), written into the built module.
362
399
  */
363
400
  export type ThemeBuildHandOff = {
364
401
  prepareFamily?: boolean;
@@ -374,4 +411,5 @@ export type ThemeBuildHandOff = {
374
411
  group: string;
375
412
  build: string;
376
413
  };
414
+ colorModes?: ["light"] | ["dark"] | null;
377
415
  };