@astryxdesign/cli 0.7.17 → 0.7.18-canary.g32556bb

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/README.md +1 -1
  2. package/api/discover/_adapter.d.mts +7 -5
  3. package/api/discover/_adapter.mjs +12 -11
  4. package/api/docs/_adapter.d.mts +19 -2
  5. package/api/docs/_adapter.mjs +66 -5
  6. package/api/doctor/_adapter.d.mts +11 -62
  7. package/api/doctor/_adapter.mjs +242 -472
  8. package/api/doctor/doctor.d.mts +1 -1
  9. package/api/doctor/doctor.mjs +3 -3
  10. package/api/doctor/theme-checks.mjs +37 -45
  11. package/api/error.d.mts +21 -0
  12. package/api/error.mjs +89 -0
  13. package/api/hook/list/list.d.mts +1 -1
  14. package/api/icon/_adapter.d.mts +8 -0
  15. package/api/icon/_adapter.mjs +17 -0
  16. package/api/icon/_authoring.mjs +6 -6
  17. package/api/icon/_default-look.mjs +16 -16
  18. package/api/icon/add/add.mjs +3 -3
  19. package/api/icon/exportIconIndex.doc.mjs +2 -2
  20. package/api/icon/icon.doc.mjs +2 -2
  21. package/api/icon/icon.type.d.mts +4 -0
  22. package/api/icon/icon.type.mjs +2 -1
  23. package/api/icon/search/icon-index.mjs +16 -3
  24. package/api/icon/search/search.d.mts +15 -5
  25. package/api/icon/search/search.mjs +74 -16
  26. package/api/icon/use/use.mjs +4 -4
  27. package/api/render/_adapter.mjs +233 -40
  28. package/api/render/render.type.d.mts +1 -1
  29. package/api/render/render.type.mjs +1 -1
  30. package/api/search/ORDERING.md +2 -2
  31. package/api/search/_adapter.mjs +4 -0
  32. package/api/search/_candidate-score.mjs +32 -8
  33. package/api/search/_cards.json +1 -1
  34. package/api/search/_compound.d.mts +0 -1
  35. package/api/search/_compound.mjs +93 -2
  36. package/api/search/_icons.d.mts +4 -2
  37. package/api/search/_icons.mjs +4 -2
  38. package/api/search/_lexical.mjs +177 -17
  39. package/api/search/_order.d.mts +3 -1
  40. package/api/search/_order.mjs +16 -5
  41. package/api/search/_result.d.mts +9 -0
  42. package/api/search/_result.mjs +10 -0
  43. package/api/search/_score.mjs +21 -3
  44. package/api/swizzle/_moduleGraph.d.mts +8 -0
  45. package/api/swizzle/_moduleGraph.mjs +61 -3
  46. package/api/template/copy/copy.mjs +5 -3
  47. package/api/template/template.type.d.mts +3 -3
  48. package/api/template/template.type.mjs +3 -3
  49. package/api/theme/_adapter.mjs +48 -12
  50. package/api/theme/build/build.d.mts +4 -0
  51. package/api/theme/build/build.mjs +69 -18
  52. package/api/theme/build/style-keys.mjs +4 -5
  53. package/api/theme/build/theme-object.mjs +5 -0
  54. package/api/theme/palette/generate/color.d.mts +47 -0
  55. package/api/theme/palette/generate/color.mjs +58 -1
  56. package/api/theme/palette/generate/derive-look.d.mts +293 -0
  57. package/api/theme/palette/generate/derive-look.mjs +1362 -0
  58. package/api/theme/palette/generate/editor-look.d.mts +62 -0
  59. package/api/theme/palette/generate/editor-look.mjs +550 -0
  60. package/api/theme/palette/generate/mapping.d.mts +94 -9
  61. package/api/theme/palette/generate/mapping.mjs +94 -22
  62. package/api/theme-edit/_adapter.mjs +13 -2
  63. package/api/theme-edit/_catalog.d.mts +13 -13
  64. package/api/theme-edit/_catalog.mjs +66 -28
  65. package/api/theme-edit/_check.d.mts +82 -6
  66. package/api/theme-edit/_check.mjs +1270 -238
  67. package/api/theme-edit/_color.d.mts +74 -0
  68. package/api/theme-edit/_color.mjs +168 -3
  69. package/api/theme-edit/_compiler.d.mts +3 -5
  70. package/api/theme-edit/_compiler.mjs +122 -23
  71. package/api/theme-edit/_context.d.mts +55 -12
  72. package/api/theme-edit/_context.mjs +114 -60
  73. package/api/theme-edit/_css.d.mts +11 -0
  74. package/api/theme-edit/_css.mjs +40 -0
  75. package/api/theme-edit/_edit.d.mts +15 -2
  76. package/api/theme-edit/_edit.mjs +1469 -133
  77. package/api/theme-edit/_how-commands.d.mts +116 -0
  78. package/api/theme-edit/_how-commands.mjs +227 -115
  79. package/api/theme-edit/_how-question.d.mts +74 -29
  80. package/api/theme-edit/_how-question.mjs +8514 -1256
  81. package/api/theme-edit/_how-sides.d.mts +22 -0
  82. package/api/theme-edit/_how-sides.mjs +173 -0
  83. package/api/theme-edit/_how-steps.d.mts +42 -0
  84. package/api/theme-edit/_how-steps.mjs +208 -0
  85. package/api/theme-edit/_how-values.d.mts +29 -0
  86. package/api/theme-edit/_how-values.mjs +111 -0
  87. package/api/theme-edit/_how-words.d.mts +15 -0
  88. package/api/theme-edit/_how-words.mjs +239 -0
  89. package/api/theme-edit/_how.d.mts +1 -1
  90. package/api/theme-edit/_how.mjs +422 -37
  91. package/api/theme-edit/_missed.d.mts +2 -1
  92. package/api/theme-edit/_missed.mjs +125 -13
  93. package/api/theme-edit/_normal.d.mts +5 -3
  94. package/api/theme-edit/_normal.mjs +54 -14
  95. package/api/theme-edit/_palette.d.mts +204 -4
  96. package/api/theme-edit/_palette.mjs +901 -25
  97. package/api/theme-edit/_part-pieces.d.mts +54 -0
  98. package/api/theme-edit/_part-pieces.mjs +179 -0
  99. package/api/theme-edit/_part-words.mjs +33 -5
  100. package/api/theme-edit/_parts.d.mts +133 -0
  101. package/api/theme-edit/_parts.mjs +599 -10
  102. package/api/theme-edit/_picture-traits.d.mts +259 -0
  103. package/api/theme-edit/_picture-traits.mjs +1030 -0
  104. package/api/theme-edit/_preview.d.mts +95 -4
  105. package/api/theme-edit/_preview.mjs +284 -31
  106. package/api/theme-edit/_project.d.mts +14 -4
  107. package/api/theme-edit/_project.mjs +95 -26
  108. package/api/theme-edit/_resolved.d.mts +46 -0
  109. package/api/theme-edit/_resolved.mjs +800 -0
  110. package/api/theme-edit/_set-line.d.mts +29 -0
  111. package/api/theme-edit/_set-line.mjs +100 -0
  112. package/api/theme-edit/_settings.d.mts +625 -28
  113. package/api/theme-edit/_settings.mjs +4867 -888
  114. package/api/theme-edit/_tables.d.mts +25 -1
  115. package/api/theme-edit/_tables.mjs +115 -11
  116. package/api/theme-edit/_text-looks.d.mts +78 -0
  117. package/api/theme-edit/_text-looks.mjs +376 -0
  118. package/api/theme-edit/_vet.d.mts +3 -26
  119. package/api/theme-edit/_vet.mjs +5 -89
  120. package/api/theme-edit/how/how.d.mts +1 -1
  121. package/api/theme-edit/how/how.mjs +1 -1
  122. package/api/theme-edit/show/show.d.mts +4 -3
  123. package/api/theme-edit/show/show.mjs +3 -2
  124. package/api/theme-edit/theme-edit.type.d.mts +117 -1
  125. package/api/theme-edit/theme-edit.type.mjs +46 -3
  126. package/api/theme-edit/themeEditHow.doc.mjs +3 -3
  127. package/api/theme-edit/themeEditNew.doc.mjs +4 -0
  128. package/api/theme-edit/themeEditSet.doc.mjs +6 -2
  129. package/api/theme-edit/themeEditShow.doc.mjs +22 -3
  130. package/api/theme-edit/themeEditUndo.doc.mjs +4 -0
  131. package/assets/component-list.generated.json +1 -1
  132. package/assets/docs/author-a-theme.doc.mjs +7 -4
  133. package/assets/docs/icons.doc.mjs +7 -6
  134. package/assets/docs/theme.doc.dense.mjs +10 -0
  135. package/assets/docs/theme.doc.mjs +10 -0
  136. package/assets/docs/theme.doc.zh.mjs +10 -0
  137. package/assets/docs/tree/export-pages.doc.mjs +1 -1
  138. package/assets/docs/tree/icon-sets.doc.mjs +1 -1
  139. package/assets/docs/use-a-theme.doc.mjs +89 -17
  140. package/assets/docs-routes.generated.json +1 -1
  141. package/assets/docs.generated.json +2 -2
  142. package/assets/icons/definitions/article.doc.mjs +9 -0
  143. package/assets/icons/template-icons.json +5 -0
  144. package/assets/search-catalog.generated.json +2 -2
  145. package/assets/self-audit.generated.json +1 -1
  146. package/assets/templates/blocks/components/Citation/CitationInlineText.doc.mjs +1 -1
  147. package/assets/templates/blocks/components/Citation/CitationInlineText.tsx +3 -1
  148. package/assets/templates/blocks/components/Citation/CitationShowcase.doc.mjs +1 -1
  149. package/assets/templates/blocks/components/Citation/CitationShowcase.tsx +3 -1
  150. package/assets/templates/blocks/components/Citation/CitationSourceList.doc.mjs +1 -1
  151. package/assets/templates/blocks/components/Citation/CitationSourceList.tsx +7 -3
  152. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.doc.mjs +1 -1
  153. package/assets/templates/blocks/components/Markdown/MarkdownCitedContent.tsx +5 -2
  154. package/assets/templates/blocks/components/SideNav/SideNavShowcase.tsx +9 -1
  155. package/assets/templates/blocks/components/SideNavCollapseButton/SideNavCollapseButtonShowcase.doc.mjs +9 -2
  156. package/assets/templates/blocks/components/SideNavHeading/SideNavHeadingShowcase.doc.mjs +3 -2
  157. package/assets/templates/blocks/components/SideNavHeading/SideNavHeadingShowcase.tsx +2 -1
  158. package/assets/templates/blocks/components/SideNavItem/SideNavItemShowcase.doc.mjs +3 -2
  159. package/assets/templates/blocks/components/SideNavSection/SideNavSectionShowcase.doc.mjs +2 -1
  160. package/assets/templates/components.generated.json +1 -1
  161. package/assets/templates/pages/ide/page.tsx +5 -10
  162. package/assets/templates/pages/payment-form/page.tsx +16 -60
  163. package/assets/templates/themes/neutral/neutralTheme.ts +4 -3
  164. package/authoring/config/parse.mjs +1 -1
  165. package/authoring/debug/parse.d.mts +1 -1
  166. package/authoring/doctypes/_schema.d.mts +13 -13
  167. package/authoring/doctypes/icon-definition/parse.mjs +2 -2
  168. package/authoring/doctypes/icon-set/parse.mjs +1 -1
  169. package/authoring/doctypes/template/parse.mjs +1 -4
  170. package/authoring/gap-report/parse.d.mts +1 -1
  171. package/clients/cli/build-id.generated.json +1 -1
  172. package/clients/cli/commands/ensure-core-built.mjs +17 -10
  173. package/clients/cli/commands/experimental/icon.mjs +7 -7
  174. package/clients/cli/commands/experimental/theme.mjs +175 -13
  175. package/clients/cli/commands/experimental-icon.doc.mjs +1 -1
  176. package/clients/cli/commands/experimental-theme-compile.doc.mjs +1 -1
  177. package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +11 -3
  178. package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +3 -3
  179. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +15 -5
  180. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  181. package/clients/cli/commands/hook.mjs +7 -0
  182. package/clients/cli/commands/template.mjs +1 -1
  183. package/clients/cli/commands/theme-build.doc.mjs +1 -1
  184. package/clients/cli/index.mjs +6 -2
  185. package/clients/cli/lib/hook-format.mjs +41 -1
  186. package/clients/cli/lib/json-shim.mjs +34 -14
  187. package/clients/cli/lib/other-cli-words.mjs +7 -0
  188. package/clients/cli/lib/unknown-command.mjs +345 -46
  189. package/clients/cli/manifest.generated.json +1 -1
  190. package/foundation/agent-docs/agent-docs.d.mts +11 -2
  191. package/foundation/agent-docs/agent-docs.mjs +51 -8
  192. package/foundation/config/project.d.mts +11 -1
  193. package/foundation/config/project.mjs +11 -2
  194. package/foundation/discovery/component-replacement.d.mts +5 -8
  195. package/foundation/discovery/component-replacement.mjs +12 -14
  196. package/foundation/discovery/core-augmentation-points.d.mts +35 -0
  197. package/foundation/discovery/core-augmentation-points.mjs +410 -9
  198. package/foundation/discovery/core-elements.d.mts +6 -0
  199. package/foundation/discovery/core-elements.mjs +10 -2
  200. package/foundation/discovery/core-prop-types.d.mts +5 -0
  201. package/foundation/discovery/core-prop-types.mjs +10 -3
  202. package/foundation/discovery/core-props.d.mts +8 -0
  203. package/foundation/discovery/core-props.mjs +29 -13
  204. package/foundation/discovery/icon-ranking.d.mts +5 -2
  205. package/foundation/discovery/icon-ranking.mjs +101 -18
  206. package/foundation/discovery/icon-set-checks.mjs +1 -1
  207. package/foundation/discovery/icon-set-writer.mjs +1 -1
  208. package/foundation/discovery/official-list.d.mts +17 -0
  209. package/foundation/discovery/official-list.mjs +77 -0
  210. package/foundation/discovery/template-icon-notes.mjs +3 -3
  211. package/foundation/discovery/template-icons.mjs +2 -2
  212. package/foundation/discovery/template-placeholders.mjs +1 -1
  213. package/foundation/discovery/unknown-core-props.d.mts +130 -0
  214. package/foundation/discovery/unknown-core-props.mjs +601 -0
  215. package/foundation/discovery/written-prop-values.d.mts +35 -0
  216. package/foundation/discovery/written-prop-values.mjs +258 -0
  217. package/foundation/fonts/fontsource-families.generated.d.mts +5 -0
  218. package/foundation/fonts/fontsource-families.generated.mjs +2110 -0
  219. package/foundation/fs/package-name.d.mts +10 -0
  220. package/foundation/fs/package-name.mjs +37 -0
  221. package/foundation/fs/project-source-files.d.mts +27 -0
  222. package/foundation/fs/project-source-files.mjs +115 -0
  223. package/foundation/fs/project-sources.d.mts +25 -0
  224. package/foundation/fs/project-sources.mjs +83 -0
  225. package/foundation/fs/read-record.d.mts +18 -0
  226. package/foundation/fs/read-record.mjs +36 -2
  227. package/foundation/integrations/integration-warnings.d.mts +39 -7
  228. package/foundation/integrations/integration-warnings.mjs +141 -19
  229. package/foundation/integrations/missing-dependency.d.mts +11 -0
  230. package/foundation/integrations/missing-dependency.mjs +20 -5
  231. package/foundation/release/folder-lock.d.mts +5 -2
  232. package/foundation/release/folder-lock.mjs +9 -3
  233. package/foundation/release/notices.mjs +2 -8
  234. package/foundation/render/cut-short.d.mts +8 -2
  235. package/foundation/render/cut-short.mjs +50 -5
  236. package/foundation/render/drawn-contrast.d.mts +40 -0
  237. package/foundation/render/drawn-contrast.mjs +355 -0
  238. package/foundation/render/file-header.mjs +4 -0
  239. package/foundation/render/layers.d.mts +2 -1
  240. package/foundation/render/layers.mjs +22 -1
  241. package/foundation/render/package-resolve-hooks.d.mts +38 -9
  242. package/foundation/render/package-resolve-hooks.mjs +124 -32
  243. package/foundation/render/page-worker.mjs +95 -23
  244. package/foundation/render/part-boxes.d.mts +27 -0
  245. package/foundation/render/part-boxes.mjs +45 -0
  246. package/foundation/render/picture-chrome.mjs +36 -4
  247. package/foundation/render/picture-playwright.mjs +26 -2
  248. package/foundation/render/picture-window.d.mts +29 -2
  249. package/foundation/render/picture-window.mjs +99 -1
  250. package/foundation/render/render-page.d.mts +39 -6
  251. package/foundation/render/render-page.mjs +26 -10
  252. package/foundation/render/ts-paths.mjs +2 -1
  253. package/foundation/response/error-codes.doc.mjs +1 -1
  254. package/foundation/response/error-codes.mjs +1 -1
  255. package/foundation/response/response-types.doc.mjs +9 -5
  256. package/foundation/suggest/other-command.mjs +25 -1
  257. package/foundation/text/icon-set-next.d.mts +1 -1
  258. package/foundation/text/icon-set-next.mjs +2 -2
  259. package/foundation/text/written-string.d.mts +4 -1
  260. package/foundation/text/written-string.mjs +4 -1
  261. package/package.json +8 -7
@@ -14,7 +14,8 @@ export function layerDocument(): Promise<void>;
14
14
  * on each one an opened overlay holds (a submenu's row), and a typed letter
15
15
  * in each combobox field that a press leaves closed. A drawing that opened
16
16
  * nothing and holds a layer is right-clicked (a context menu). Each overlay
17
- * is kept once, as it was when it opened.
17
+ * is kept once, as it was when it opened; a control on the page that opens
18
+ * keeps the drawn part with it open, without its overlays.
18
19
  * @param {any} host the element the page was drawn in
19
20
  * @param {(fn: () => void) => void} flushSync
20
21
  * @returns {Promise<string[]>}
@@ -151,7 +151,8 @@ export {desktopMatches} from './picture-window.mjs';
151
151
  * on each one an opened overlay holds (a submenu's row), and a typed letter
152
152
  * in each combobox field that a press leaves closed. A drawing that opened
153
153
  * nothing and holds a layer is right-clicked (a context menu). Each overlay
154
- * is kept once, as it was when it opened.
154
+ * is kept once, as it was when it opened; a control on the page that opens
155
+ * keeps the drawn part with it open, without its overlays.
155
156
  * @param {any} host the element the page was drawn in
156
157
  * @param {(fn: () => void) => void} flushSync
157
158
  * @returns {Promise<string[]>}
@@ -243,6 +244,26 @@ export async function openLayerMarkup(host, flushSync) {
243
244
  }
244
245
  await tick();
245
246
  keep();
247
+ // A control the page itself draws (a top nav's menu trigger, outside
248
+ // every overlay) shows its open state only on the page: the part as
249
+ // drawn now, with that control open and without its overlays, is kept
250
+ // too.
251
+ if (
252
+ control.getAttribute('aria-expanded') === 'true' &&
253
+ !control.closest('[data-astryx-layer-root]')
254
+ ) {
255
+ const part = host.cloneNode(true);
256
+ for (const layer of part.querySelectorAll('[data-astryx-layer-root]'))
257
+ layer.remove();
258
+ const html = String(part.innerHTML).replace(
259
+ /<template><\/template>/g,
260
+ '',
261
+ );
262
+ if (html && !seen.has(html)) {
263
+ seen.add(html);
264
+ out.push(html);
265
+ }
266
+ }
246
267
  if (control.getAttribute('aria-expanded') === 'true')
247
268
  for (const layer of g.document.querySelectorAll(
248
269
  '[data-astryx-layer-root]',
@@ -10,12 +10,27 @@
10
10
  */
11
11
  export function installedPackageOf(file: string): string | null;
12
12
  /**
13
- * Lookups that one set of hooks keeps: each folder's package.json `type`
14
- * (null for a folder with none, undefined for one that cannot be read).
15
- * @typedef {{types: Map<string, string | null | undefined>}} PackageLookups
13
+ * What a folder's package.json says: its `name` and its module `type`
14
+ * ('commonjs' when it names none); null for a folder with no package.json,
15
+ * undefined for one that cannot be read.
16
+ * @typedef {{name: unknown, type: string} | null | undefined} FolderManifest
17
+ */
18
+ /**
19
+ * Lookups that one set of hooks keeps: each folder's package.json, read once,
20
+ * and the folders of the linked packages bare imports reached.
21
+ * @typedef {{manifests: Map<string, FolderManifest>, linked: Set<string>}} PackageLookups
16
22
  */
17
23
  /** @returns {PackageLookups} */
18
24
  export function packageLookups(): PackageLookups;
25
+ /**
26
+ * The folder of the linked package that holds `file`: the nearest folder
27
+ * above it that a bare import was found to reach (see noteLinkedPackage),
28
+ * with no node_modules folder between them; else null.
29
+ * @param {string} file
30
+ * @param {PackageLookups} lookups
31
+ * @returns {string | null}
32
+ */
33
+ export function linkedPackageOf(file: string, lookups: PackageLookups): string | null;
19
34
  /**
20
35
  * The URL of the ES module that `specifier` names from `parent`, when both
21
36
  * are files of one installed package and Node would load it as an ES module;
@@ -31,11 +46,15 @@ export function packageLookups(): PackageLookups;
31
46
  */
32
47
  export function packageModuleUrl(specifier: string, parent: string | undefined, lookups: PackageLookups): string | null;
33
48
  /**
34
- * Module hooks that resolve imports between the files of an installed
35
- * package by path.
49
+ * Module hooks that resolve imports between the files of an installed or a
50
+ * linked package by path.
36
51
  * @param {PackageLookups} [lookups]
52
+ * @param {{skip?: (folder: string) => boolean}} [options] - `skip`: a folder
53
+ * never taken as a linked package's (the page's own folders)
37
54
  */
38
- export function packageResolveHooks(lookups?: PackageLookups): {
55
+ export function packageResolveHooks(lookups?: PackageLookups, { skip }?: {
56
+ skip?: (folder: string) => boolean;
57
+ }): {
39
58
  /**
40
59
  * @param {string} specifier
41
60
  * @param {{parentURL?: string}} context
@@ -46,9 +65,19 @@ export function packageResolveHooks(lookups?: PackageLookups): {
46
65
  }, nextResolve: (specifier: string, context: any) => any): any;
47
66
  };
48
67
  /**
49
- * Lookups that one set of hooks keeps: each folder's package.json `type`
50
- * (null for a folder with none, undefined for one that cannot be read).
68
+ * What a folder's package.json says: its `name` and its module `type`
69
+ * ('commonjs' when it names none); null for a folder with no package.json,
70
+ * undefined for one that cannot be read.
71
+ */
72
+ export type FolderManifest = {
73
+ name: unknown;
74
+ type: string;
75
+ } | null | undefined;
76
+ /**
77
+ * Lookups that one set of hooks keeps: each folder's package.json, read once,
78
+ * and the folders of the linked packages bare imports reached.
51
79
  */
52
80
  export type PackageLookups = {
53
- types: Map<string, string | null | undefined>;
81
+ manifests: Map<string, FolderManifest>;
82
+ linked: Set<string>;
54
83
  };
@@ -1,13 +1,15 @@
1
1
  // Copyright (c) Meta Platforms, Inc. and affiliates.
2
2
 
3
3
  /**
4
- * @file The export worker's imports between the files of an installed
5
- * package, resolved by their path in the package.
4
+ * @file The export worker's imports between the files of an installed or a
5
+ * linked package, resolved by their path in the package.
6
6
  *
7
7
  * @input `packageResolveHooks()`, registered by page-worker.mjs.
8
8
  * @output Module hooks whose resolve step answers a relative, fully
9
- * specified ES module import between two files of one installed package
10
- * with the file's URL; every other import goes on to the next resolver.
9
+ * specified ES module import between two files of one installed package,
10
+ * or of one linked package (one a bare import reached outside
11
+ * node_modules), with the file's URL; every other import goes on to the
12
+ * next resolver, and its answer is returned as it is.
11
13
  * @position foundation/render. Node reads the nearest package.json of each
12
14
  * module it resolves and loads, and it reads a package's whole manifest
13
15
  * again for each module, so a package of hundreds of modules (Core) reads
@@ -18,6 +20,7 @@
18
20
  import * as fs from 'node:fs';
19
21
  import * as path from 'node:path';
20
22
  import {fileURLToPath, pathToFileURL} from 'node:url';
23
+ import {packageOf} from './served-packages.mjs';
21
24
 
22
25
  const NODE_MODULES = `${path.sep}node_modules${path.sep}`;
23
26
 
@@ -41,16 +44,111 @@ export function installedPackageOf(file) {
41
44
  }
42
45
 
43
46
  /**
44
- * Lookups that one set of hooks keeps: each folder's package.json `type`
45
- * (null for a folder with none, undefined for one that cannot be read).
46
- * @typedef {{types: Map<string, string | null | undefined>}} PackageLookups
47
+ * What a folder's package.json says: its `name` and its module `type`
48
+ * ('commonjs' when it names none); null for a folder with no package.json,
49
+ * undefined for one that cannot be read.
50
+ * @typedef {{name: unknown, type: string} | null | undefined} FolderManifest
51
+ */
52
+
53
+ /**
54
+ * Lookups that one set of hooks keeps: each folder's package.json, read once,
55
+ * and the folders of the linked packages bare imports reached.
56
+ * @typedef {{manifests: Map<string, FolderManifest>, linked: Set<string>}} PackageLookups
47
57
  */
48
58
 
49
59
  /** @returns {PackageLookups} */
50
60
  export function packageLookups() {
51
- return {types: new Map()};
61
+ return {manifests: new Map(), linked: new Set()};
62
+ }
63
+
64
+ /**
65
+ * The package.json of folder `d`, read once for each folder.
66
+ * @param {string} d
67
+ * @param {PackageLookups} lookups
68
+ * @returns {FolderManifest}
69
+ */
70
+ function manifestAt(d, lookups) {
71
+ if (!lookups.manifests.has(d)) {
72
+ /** @type {FolderManifest} */
73
+ let found = null;
74
+ const file = path.join(d, 'package.json');
75
+ if (fs.existsSync(file)) {
76
+ try {
77
+ const manifest = JSON.parse(fs.readFileSync(file, 'utf8'));
78
+ found = {
79
+ name: manifest?.name,
80
+ type: typeof manifest?.type === 'string' ? manifest.type : 'commonjs',
81
+ };
82
+ } catch {
83
+ found = undefined;
84
+ }
85
+ }
86
+ lookups.manifests.set(d, found);
87
+ }
88
+ return lookups.manifests.get(d);
89
+ }
90
+
91
+ /**
92
+ * The folder of the linked package that holds `file`: the nearest folder
93
+ * above it that a bare import was found to reach (see noteLinkedPackage),
94
+ * with no node_modules folder between them; else null.
95
+ * @param {string} file
96
+ * @param {PackageLookups} lookups
97
+ * @returns {string | null}
98
+ */
99
+ export function linkedPackageOf(file, lookups) {
100
+ if (lookups.linked.size === 0) return null;
101
+ for (let d = path.dirname(file); ; d = path.dirname(d)) {
102
+ if (path.basename(d) === 'node_modules') return null;
103
+ if (lookups.linked.has(d)) return d;
104
+ if (path.dirname(d) === d) return null;
105
+ }
52
106
  }
53
107
 
108
+ /**
109
+ * The `name` in the package.json of the folder nearest `dir` that has one,
110
+ * with that folder; null when no folder up to the file system's root has one.
111
+ * A package.json that cannot be read still counts, with no name.
112
+ * @param {string} dir
113
+ * @param {PackageLookups} lookups
114
+ * @returns {{dir: string, name: unknown} | null}
115
+ */
116
+ function nearestManifest(dir, lookups) {
117
+ for (let d = dir; ; d = path.dirname(d)) {
118
+ const manifest = manifestAt(d, lookups);
119
+ if (manifest !== null) return {dir: d, name: manifest?.name};
120
+ if (path.dirname(d) === d) return null;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Notes the folder of a linked package: a bare import that resolved to a
126
+ * file outside node_modules reached the package whose folder holds that
127
+ * file's nearest package.json, when that package.json names the package the
128
+ * import names. A folder `skip` refuses is not noted.
129
+ * @param {string} specifier
130
+ * @param {unknown} url - the resolved URL
131
+ * @param {PackageLookups} lookups
132
+ * @param {(folder: string) => boolean} skip - takes the folder with a
133
+ * trailing separator
134
+ */
135
+ function noteLinkedPackage(specifier, url, lookups, skip) {
136
+ if (typeof url !== 'string' || !url.startsWith('file:')) return;
137
+ const file = fileURLToPath(url);
138
+ if (file.includes(NODE_MODULES)) return;
139
+ const found = nearestManifest(path.dirname(file), lookups);
140
+ if (
141
+ found &&
142
+ found.name === packageOf(specifier) &&
143
+ !skip(found.dir + path.sep)
144
+ )
145
+ lookups.linked.add(found.dir);
146
+ }
147
+
148
+ /** Whether a specifier names a package (not a path, a URL or an import map entry). @param {string} specifier */
149
+ const isBare = specifier =>
150
+ !/^[./#]/.test(specifier) && !/^[a-z][a-z0-9+.-]*:/i.test(specifier);
151
+
54
152
  /**
55
153
  * The `type` of the package.json nearest `dir`, searched up to `root`
56
154
  * included: a string, null when the folders hold none, or undefined when one
@@ -62,22 +160,8 @@ export function packageLookups() {
62
160
  */
63
161
  function packageTypeAt(dir, root, lookups) {
64
162
  for (let d = dir; ; d = path.dirname(d)) {
65
- let type = lookups.types.get(d);
66
- if (!lookups.types.has(d)) {
67
- type = null;
68
- const file = path.join(d, 'package.json');
69
- if (fs.existsSync(file)) {
70
- try {
71
- const manifest = JSON.parse(fs.readFileSync(file, 'utf8'));
72
- type =
73
- typeof manifest?.type === 'string' ? manifest.type : 'commonjs';
74
- } catch {
75
- type = undefined;
76
- }
77
- }
78
- lookups.types.set(d, type);
79
- }
80
- if (type !== null) return type;
163
+ const manifest = manifestAt(d, lookups);
164
+ if (manifest !== null) return manifest?.type;
81
165
  if (d === root || path.dirname(d) === d) return null;
82
166
  }
83
167
  }
@@ -100,12 +184,13 @@ export function packageModuleUrl(specifier, parent, lookups) {
100
184
  if (!specifier.startsWith('./') && !specifier.startsWith('../')) return null;
101
185
  if (/[%?#\\]/.test(specifier) || !/\.m?js$/.test(specifier)) return null;
102
186
  const from = fileURLToPath(parent);
103
- const root = installedPackageOf(from);
187
+ const root = installedPackageOf(from) ?? linkedPackageOf(from, lookups);
104
188
  if (root === null) return null;
105
189
  const file = path.resolve(path.dirname(from), specifier);
106
190
  // A file in a node_modules folder inside the package belongs to another
107
191
  // package, whose scope Node reads apart from this one.
108
- if (installedPackageOf(file) !== root) return null;
192
+ if ((installedPackageOf(file) ?? linkedPackageOf(file, lookups)) !== root)
193
+ return null;
109
194
  const stat = fs.statSync(file, {throwIfNoEntry: false});
110
195
  if (!stat?.isFile()) return null;
111
196
  try {
@@ -123,11 +208,16 @@ export function packageModuleUrl(specifier, parent, lookups) {
123
208
  }
124
209
 
125
210
  /**
126
- * Module hooks that resolve imports between the files of an installed
127
- * package by path.
211
+ * Module hooks that resolve imports between the files of an installed or a
212
+ * linked package by path.
128
213
  * @param {PackageLookups} [lookups]
214
+ * @param {{skip?: (folder: string) => boolean}} [options] - `skip`: a folder
215
+ * never taken as a linked package's (the page's own folders)
129
216
  */
130
- export function packageResolveHooks(lookups = packageLookups()) {
217
+ export function packageResolveHooks(
218
+ lookups = packageLookups(),
219
+ {skip = () => false} = {},
220
+ ) {
131
221
  return {
132
222
  /**
133
223
  * @param {string} specifier
@@ -136,9 +226,11 @@ export function packageResolveHooks(lookups = packageLookups()) {
136
226
  */
137
227
  resolve(specifier, context, nextResolve) {
138
228
  const url = packageModuleUrl(specifier, context.parentURL, lookups);
139
- return url === null
140
- ? nextResolve(specifier, context)
141
- : {url, format: 'module', shortCircuit: true};
229
+ if (url !== null) return {url, format: 'module', shortCircuit: true};
230
+ const resolved = nextResolve(specifier, context);
231
+ if (isBare(specifier))
232
+ noteLinkedPackage(specifier, resolved?.url, lookups, skip);
233
+ return resolved;
142
234
  },
143
235
  };
144
236
  }
@@ -55,7 +55,9 @@ import {importSpecifiers, moduleImports} from './embedded-imports.mjs';
55
55
  import {sha256} from './source-block.mjs';
56
56
  import {BundleError, CARRIED_MODULE, bundleForBrowser} from './client-bundle.mjs';
57
57
  import {droppedImports, importUses} from './value-uses.mjs';
58
- import {coreComponentOf} from '../discovery/core-elements.mjs';
58
+ import {OTHER_JSX_RUNTIME, coreComponentOf} from '../discovery/core-elements.mjs';
59
+ import {corePropUsesOf} from '../discovery/core-props.mjs';
60
+ import {writtenValue} from '../discovery/written-prop-values.mjs';
59
61
  import {CHART_GLOBAL, CHART_ROOTS, FOLLOWS_WIDTH, boxHeights, chartDocument, chartDrawings, foldLegends, roundCoordinates, separateIds} from './charts.mjs';
60
62
  import {LAYER_GLOBAL, LAYER_PLACEHOLDER, countQueuedImmediates, layerDocument, layerPlaceholder, openLayerMarkup, settled} from './layers.mjs';
61
63
 
@@ -183,11 +185,20 @@ const texts = [];
183
185
  /** @type {Record<string, string[]>} */
184
186
  const fnTexts = {};
185
187
  /**
186
- * Each string a page's own file gives a Core component's prop
187
- * (`<Button variant="danger">`), for the unknown-prop-value warning.
188
- * @type {{component: string, prop: string, value: string, file: string, line: number}[]}
188
+ * What a page's own file certainly gives a Core component's prop
189
+ * (`<Button variant="danger">`, each branch of
190
+ * `variant={busy ? 'ghost' : 'danger'}`, `status="error"`), for the
191
+ * unknown-prop-value warning.
192
+ * @type {(import('../discovery/written-prop-values.mjs').WrittenValue & {component: string, prop: string, file: string, line: number})[]}
189
193
  */
190
194
  const propValues = [];
195
+ /**
196
+ * Each prop a page's own file gives a Core component by name, for the
197
+ * unknown-prop warning; a file that compiles its JSX with another runtime
198
+ * gives none.
199
+ * @type {(import('../discovery/core-props.mjs').CorePropUse & {file: string, element: {line: number, column: number}})[]}
200
+ */
201
+ const propNames = [];
191
202
  /** Each media query the page's own code asks in JavaScript, for the screen-query warning. */
192
203
  /** @type {{call: string, file: string, line: number}[]} */
193
204
  const screenQueries = [];
@@ -621,6 +632,49 @@ async function drawCharts(markup, Page) {
621
632
  };
622
633
  }
623
634
 
635
+ /**
636
+ * The markup of a part's open layers. A layer opened from inside another
637
+ * (its opener, the control naming it in aria-controls, sits in that layer:
638
+ * a submenu's flyout) is drawn once, beside the layer it opens from, in a
639
+ * row with it, as a browser places it; never again inside that layer, where
640
+ * the document holds it too.
641
+ * @param {any[]} open the open layers, in the order they opened
642
+ * @returns {string}
643
+ */
644
+ function nestedLayers(open) {
645
+ /** @param {any} layer */
646
+ const parentOf = layer => {
647
+ const ids = new Set(
648
+ [layer, ...layer.querySelectorAll('[id]')].map(e => e.id).filter(Boolean),
649
+ );
650
+ return (
651
+ open.find(
652
+ other =>
653
+ other !== layer &&
654
+ !layer.contains(other) &&
655
+ [...other.querySelectorAll('[aria-controls]')].some(c =>
656
+ ids.has(c.getAttribute('aria-controls')),
657
+ ),
658
+ ) ?? null
659
+ );
660
+ };
661
+ const parents = new Map(open.map(layer => [layer, parentOf(layer)]));
662
+ /** @param {any} layer @returns {string} */
663
+ const draw = layer => {
664
+ const kids = open.filter(o => parents.get(o) === layer);
665
+ if (!kids.length) return layer.outerHTML;
666
+ const own = layer.cloneNode(true);
667
+ for (const inner of own.querySelectorAll('[data-astryx-layer-root]'))
668
+ inner.remove();
669
+ return `<div data-astryx-layer-nest="">${own.outerHTML}${kids.map(draw).join('')}</div>`;
670
+ };
671
+ return open
672
+ .filter(layer => !parents.get(layer))
673
+ .map(draw)
674
+ .join('');
675
+ }
676
+
677
+
624
678
  /**
625
679
  * Parts the page asked to be drawn, in the order asked: open (`ifOpen`: drawn
626
680
  * as nothing when nothing opens), or `mounted`, as the browser shows the part
@@ -725,10 +779,12 @@ async function drawLayers(markup, server) {
725
779
  );
726
780
  if (open.length) {
727
781
  // The part as drawn, then each overlay open now, after it; never a
728
- // closed one, nor the markers that place them.
782
+ // closed one, nor the markers that place them. A layer opened from
783
+ // inside another (a submenu's flyout) is drawn beside the layer it
784
+ // opens from, as a browser places it.
729
785
  const part = host.cloneNode(true);
730
786
  for (const layer of part.querySelectorAll('[data-astryx-layer-root]')) layer.remove();
731
- out = part.innerHTML.replace(/<template><\/template>/g, '') + open.map(layer => layer.outerHTML).join('');
787
+ out = part.innerHTML.replace(/<template><\/template>/g, '') + nestedLayers(open);
732
788
  }
733
789
  }
734
790
  } catch {
@@ -798,7 +854,11 @@ async function drawOpenLayers(elements, React) {
798
854
  flushSync(() => root.render(createElement(Alone, null, element)));
799
855
  // (A part that opens nothing on a press and holds a layer, a context
800
856
  // menu's area, is right-clicked, as one drawn in its own place is.)
801
- layers.push(...(await openLayerMarkup(host, flushSync)));
857
+ // A layer opened from inside another is drawn beside it (nestedLayers).
858
+ const box = g.document.createElement('div');
859
+ box.innerHTML = (await openLayerMarkup(host, flushSync)).join('');
860
+ const drawn = nestedLayers([...box.children]);
861
+ if (drawn) layers.push(drawn);
802
862
  } catch {
803
863
  // A part that cannot be drawn there adds no overlays.
804
864
  }
@@ -1126,8 +1186,11 @@ function carriedName(p, t) {
1126
1186
  * recorded it already.
1127
1187
  * @param {string} filename
1128
1188
  * @param {boolean} [browser]
1189
+ * @param {boolean} [reactJsx] whether the module compiles its JSX with
1190
+ * React's runtime, so its Core props are recorded for the unknown-prop
1191
+ * warning
1129
1192
  */
1130
- function pagePlugin(filename, browser = false) {
1193
+ function pagePlugin(filename, browser = false, reactJsx = true) {
1131
1194
  const dir = path.dirname(filename);
1132
1195
  /**
1133
1196
  * Record an https image address the page builds in code (a template with
@@ -1319,16 +1382,17 @@ function pagePlugin(filename, browser = false) {
1319
1382
  if (browser) return;
1320
1383
  const component = coreComponentOf(p.node.name, p.scope);
1321
1384
  if (!component) return;
1322
- for (const attr of p.node.attributes) {
1385
+ const attrs = p.node.attributes;
1386
+ // A spread after an attribute can replace its value.
1387
+ const lastSpread = attrs.findLastIndex((/** @type {any} */ a) => a.type === 'JSXSpreadAttribute');
1388
+ for (const attr of attrs.slice(lastSpread + 1)) {
1323
1389
  if (attr.type !== 'JSXAttribute' || attr.name.type !== 'JSXIdentifier') continue;
1324
- const value =
1325
- attr.value?.type === 'StringLiteral'
1326
- ? attr.value.value
1327
- : attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type === 'StringLiteral'
1328
- ? attr.value.expression.value
1329
- : null;
1330
- if (value === null) continue;
1331
- propValues.push({component, prop: attr.name.name, value, file: filename, line: attr.loc?.start.line ?? 0});
1390
+ const written = writtenValue(attr, p.scope);
1391
+ if (written) propValues.push({component, prop: attr.name.name, ...written, file: filename, line: attr.loc?.start.line ?? 0});
1392
+ }
1393
+ if (reactJsx) {
1394
+ const element = {line: p.node.loc?.start.line ?? 0, column: (p.node.loc?.start.column ?? 0) + 1};
1395
+ for (const use of corePropUsesOf(p)) propNames.push({...use, file: filename, element});
1332
1396
  }
1333
1397
  },
1334
1398
  JSXText(/** @type {any} */ p) {
@@ -1580,12 +1644,19 @@ if (servedParent && Object.keys(SINGLE_COPY_ALIASES).length > 0) {
1580
1644
  data: {parent: pathToFileURL(servedParent.filename).href, names: Object.keys(SINGLE_COPY_ALIASES)},
1581
1645
  });
1582
1646
  }
1583
- // Imports between the files of an installed package resolve by path (a
1584
- // Node without in-thread hooks resolves them itself). The hook answers only
1585
- // relative imports inside a package, and single-copy-hooks.mjs answers only
1586
- // package names, so neither changes what the other resolves.
1647
+ // Imports between the files of an installed or a linked package resolve by
1648
+ // path (a Node without in-thread hooks resolves them itself). The hook
1649
+ // answers only relative imports inside a package, and single-copy-hooks.mjs
1650
+ // answers only package names, so neither changes what the other resolves.
1651
+ // The page's own folders, and a folder that holds the page, are never a
1652
+ // linked package's: the page's modules compile as its own.
1587
1653
  const registerHooks = /** @type {any} */ (Module).registerHooks;
1588
- if (typeof registerHooks === 'function') registerHooks(packageResolveHooks());
1654
+ if (typeof registerHooks === 'function')
1655
+ registerHooks(
1656
+ packageResolveHooks(undefined, {
1657
+ skip: folder => isLocal(folder) || entry.startsWith(folder),
1658
+ }),
1659
+ );
1589
1660
 
1590
1661
  /** What the StyleX compiler reads as a theme or constants file, by name. */
1591
1662
  const STYLEX_THEME_FILE = /\.(?:stylex(?:\.const)?|transformed)(?:\.(?:js|ts|tsx|jsx|mjs|cjs))?$/;
@@ -1754,7 +1825,7 @@ function compilePageModule(source, filename, browser = false) {
1754
1825
  compact: false,
1755
1826
  plugins: [
1756
1827
  aliasPlugin(),
1757
- pagePlugin(filename, browser),
1828
+ pagePlugin(filename, browser, !OTHER_JSX_RUNTIME.test(source)),
1758
1829
  ...(source.includes('stylex') ? [stylexPluginFor(source, filename)] : []),
1759
1830
  ],
1760
1831
  });
@@ -2585,6 +2656,7 @@ try {
2585
2656
  remoteNamedOnly: [...namedOnlyLiterals].filter(url => !placedLiterals.has(url)),
2586
2657
  builtRemote,
2587
2658
  propValues: propValues.map(v => ({...v, file: path.relative(path.dirname(entry), v.file).split(path.sep).join('/')})),
2659
+ propNames,
2588
2660
  logs,
2589
2661
  script: script?.code ?? null,
2590
2662
  scriptModules: script?.modules ?? 0,
@@ -0,0 +1,27 @@
1
+ // @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
2
+ // DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
3
+
4
+ /**
5
+ * The width and height of every drawn element of each part named, in page
6
+ * order, to a hundredth of a pixel. An element that is not drawn (no box,
7
+ * hidden, `display: contents`) is left out.
8
+ * Runs in the page: it uses nothing from outside its own body.
9
+ * @param {string[]} parts
10
+ * @returns {Record<string, Array<[number, number]>>}
11
+ */
12
+ export function partBoxes(parts: string[]): Record<string, Array<[number, number]>>;
13
+ /**
14
+ * @file The size of each drawn Astryx part on a picture's page, measured in
15
+ * the page.
16
+ * @input None: `partBoxes` runs in the page the picture is taken of.
17
+ * @output `partBoxes`: for each part named, the width and height of every
18
+ * element drawn with its `astryx-<part>` class, in page order;
19
+ * `PART_BOXES_PREFIX`, the line prefix a picture script prints it after.
20
+ * @position run by picture-chrome.mjs and picture-playwright.mjs for a job
21
+ * that names parts to measure, once the page is drawn as the picture shows
22
+ * it; read back by `screenshots` in api/theme-edit/_preview.mjs from the
23
+ * script's stdout. The theme editor compares two pictures' boxes to name
24
+ * what a change of size moves on the page.
25
+ */
26
+ /** The line prefix a picture script prints the measurement after. */
27
+ export const PART_BOXES_PREFIX: "astryx-part-boxes:";
@@ -0,0 +1,45 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file The size of each drawn Astryx part on a picture's page, measured in
5
+ * the page.
6
+ * @input None: `partBoxes` runs in the page the picture is taken of.
7
+ * @output `partBoxes`: for each part named, the width and height of every
8
+ * element drawn with its `astryx-<part>` class, in page order;
9
+ * `PART_BOXES_PREFIX`, the line prefix a picture script prints it after.
10
+ * @position run by picture-chrome.mjs and picture-playwright.mjs for a job
11
+ * that names parts to measure, once the page is drawn as the picture shows
12
+ * it; read back by `screenshots` in api/theme-edit/_preview.mjs from the
13
+ * script's stdout. The theme editor compares two pictures' boxes to name
14
+ * what a change of size moves on the page.
15
+ */
16
+
17
+ /* global document, getComputedStyle -- partBoxes runs in the page */
18
+
19
+ /** The line prefix a picture script prints the measurement after. */
20
+ export const PART_BOXES_PREFIX = 'astryx-part-boxes:';
21
+
22
+ /**
23
+ * The width and height of every drawn element of each part named, in page
24
+ * order, to a hundredth of a pixel. An element that is not drawn (no box,
25
+ * hidden, `display: contents`) is left out.
26
+ * Runs in the page: it uses nothing from outside its own body.
27
+ * @param {string[]} parts
28
+ * @returns {Record<string, Array<[number, number]>>}
29
+ */
30
+ export function partBoxes(parts) {
31
+ /** @type {Record<string, Array<[number, number]>>} */
32
+ const out = {};
33
+ const round = (/** @type {number} */ n) => Math.round(n * 100) / 100;
34
+ for (const part of parts) {
35
+ out[part] = [];
36
+ for (const el of document.querySelectorAll(`.astryx-${part}`)) {
37
+ const cs = getComputedStyle(el);
38
+ if (cs.display === 'contents' || cs.visibility !== 'visible') continue;
39
+ const r = el.getBoundingClientRect();
40
+ if (!r.width && !r.height) continue;
41
+ out[part].push([round(r.width), round(r.height)]);
42
+ }
43
+ }
44
+ return out;
45
+ }