@scaffold-ui-kit/preview 0.0.0-stage → 2.3.0

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 (350) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1868 -2
  3. package/application/host/bootstrap.ts +43 -0
  4. package/application/host/main.ts +31 -0
  5. package/application/host/shell-host.ts +47 -0
  6. package/application/index.html +12 -0
  7. package/application/lib/base-url.ts +15 -0
  8. package/application/lib/no-code-block.ts +7 -0
  9. package/application/lib/no-setup.ts +3 -0
  10. package/application/lib/no-views.ts +6 -0
  11. package/application/preview/code/code.html +12 -0
  12. package/application/preview/code/main.ts +89 -0
  13. package/application/preview/globals.ts +254 -0
  14. package/application/preview/html/main.ts +93 -0
  15. package/application/preview/html/preview.html +12 -0
  16. package/application/preview/react/main.tsx +146 -0
  17. package/application/preview/react/preview.html +12 -0
  18. package/application/preview/svelte/Preview.svelte +104 -0
  19. package/application/preview/svelte/main.ts +13 -0
  20. package/application/preview/svelte/preview.html +12 -0
  21. package/application/preview/svelte/story-props.ts +172 -0
  22. package/application/preview/view/main.ts +124 -0
  23. package/application/preview/view/view.html +12 -0
  24. package/application/preview/vue/main.ts +145 -0
  25. package/application/preview/vue/preview.html +12 -0
  26. package/application/shells/charcell/components/Application/index.css +37 -0
  27. package/application/shells/charcell/components/Application/index.tsx +65 -0
  28. package/application/shells/charcell/components/Bar/index.css +68 -0
  29. package/application/shells/charcell/components/Bar/index.tsx +60 -0
  30. package/application/shells/charcell/components/CodePane/index.css +60 -0
  31. package/application/shells/charcell/components/CodePane/index.tsx +113 -0
  32. package/application/shells/charcell/components/ComponentStage/index.css +26 -0
  33. package/application/shells/charcell/components/ComponentStage/index.tsx +110 -0
  34. package/application/shells/charcell/components/Control/index.css +20 -0
  35. package/application/shells/charcell/components/Control/index.tsx +118 -0
  36. package/application/shells/charcell/components/CopyLink/index.tsx +35 -0
  37. package/application/shells/charcell/components/Description/index.css +6 -0
  38. package/application/shells/charcell/components/Description/index.tsx +24 -0
  39. package/application/shells/charcell/components/EditorAddDialog/index.css +9 -0
  40. package/application/shells/charcell/components/EditorAddDialog/index.tsx +158 -0
  41. package/application/shells/charcell/components/EditorPanel/index.css +48 -0
  42. package/application/shells/charcell/components/EditorPanel/index.tsx +496 -0
  43. package/application/shells/charcell/components/EventsRow/index.css +42 -0
  44. package/application/shells/charcell/components/EventsRow/index.tsx +68 -0
  45. package/application/shells/charcell/components/HeadingRow/index.css +11 -0
  46. package/application/shells/charcell/components/HeadingRow/index.tsx +16 -0
  47. package/application/shells/charcell/components/Hint/index.css +16 -0
  48. package/application/shells/charcell/components/Hint/index.tsx +81 -0
  49. package/application/shells/charcell/components/HtmlWarnings/index.tsx +45 -0
  50. package/application/shells/charcell/components/KeyHints/index.css +27 -0
  51. package/application/shells/charcell/components/KeyHints/index.tsx +106 -0
  52. package/application/shells/charcell/components/KitCodeBlock/index.css +55 -0
  53. package/application/shells/charcell/components/KitCodeBlock/index.tsx +18 -0
  54. package/application/shells/charcell/components/Markdown/index.tsx +16 -0
  55. package/application/shells/charcell/components/Navigation/index.css +13 -0
  56. package/application/shells/charcell/components/Navigation/index.tsx +98 -0
  57. package/application/shells/charcell/components/NavigationSplit/index.css +16 -0
  58. package/application/shells/charcell/components/NavigationSplit/index.tsx +82 -0
  59. package/application/shells/charcell/components/OptionControls/index.tsx +93 -0
  60. package/application/shells/charcell/components/PaneStatus/index.css +7 -0
  61. package/application/shells/charcell/components/PaneStatus/index.tsx +47 -0
  62. package/application/shells/charcell/components/PaneWidth/index.tsx +45 -0
  63. package/application/shells/charcell/components/PreviewGrid/index.css +39 -0
  64. package/application/shells/charcell/components/PreviewGrid/index.tsx +344 -0
  65. package/application/shells/charcell/components/PreviewPane/index.css +127 -0
  66. package/application/shells/charcell/components/PreviewPane/index.tsx +182 -0
  67. package/application/shells/charcell/components/PromptBar/index.tsx +133 -0
  68. package/application/shells/charcell/components/ScenarioRow/index.css +36 -0
  69. package/application/shells/charcell/components/ScenarioRow/index.tsx +71 -0
  70. package/application/shells/charcell/components/Select/index.tsx +48 -0
  71. package/application/shells/charcell/components/SlotOutlet/index.css +7 -0
  72. package/application/shells/charcell/components/SlotOutlet/index.tsx +25 -0
  73. package/application/shells/charcell/components/StageBar/index.css +7 -0
  74. package/application/shells/charcell/components/StageBar/index.tsx +109 -0
  75. package/application/shells/charcell/components/StageSplit/index.css +11 -0
  76. package/application/shells/charcell/components/StageSplit/index.tsx +99 -0
  77. package/application/shells/charcell/components/StatusBar/index.tsx +30 -0
  78. package/application/shells/charcell/components/ViewControls/index.css +15 -0
  79. package/application/shells/charcell/components/ViewControls/index.tsx +58 -0
  80. package/application/shells/charcell/components/ViewHeading/index.css +13 -0
  81. package/application/shells/charcell/components/ViewHeading/index.tsx +8 -0
  82. package/application/shells/charcell/components/ViewStage/index.css +9 -0
  83. package/application/shells/charcell/components/ViewStage/index.tsx +25 -0
  84. package/application/shells/charcell/components/WrapToggle/index.tsx +27 -0
  85. package/application/shells/charcell/configuration.ts +45 -0
  86. package/application/shells/charcell/controller-context.ts +27 -0
  87. package/application/shells/charcell/fit-labels.ts +42 -0
  88. package/application/shells/charcell/html-warnings.ts +18 -0
  89. package/application/shells/charcell/index.tsx +82 -0
  90. package/application/shells/charcell/page-loading.html +57 -0
  91. package/application/shells/charcell/placement.ts +24 -0
  92. package/application/shells/charcell/shell-options.ts +23 -0
  93. package/application/shells/charcell/shell.css +37 -0
  94. package/application/shells/charcell/shell.tsx +25 -0
  95. package/application/shells/charcell/split-reset.ts +47 -0
  96. package/application/shells/charcell/stacked-rows.ts +117 -0
  97. package/application/shells/charcell/stage-toggles.ts +93 -0
  98. package/application/types/manifest.d.ts +6 -0
  99. package/application/types/preview-configuration.d.ts +10 -0
  100. package/application/types/preview-shell.d.ts +7 -0
  101. package/application/types/react-registry.d.ts +15 -0
  102. package/application/types/vue-registry.d.ts +6 -0
  103. package/dist/build.d.ts +24 -0
  104. package/dist/build.js +34 -0
  105. package/dist/check.d.ts +48 -0
  106. package/dist/check.js +781 -0
  107. package/dist/cli.d.ts +2 -0
  108. package/dist/cli.js +88 -0
  109. package/dist/context.d.ts +179 -0
  110. package/dist/context.js +783 -0
  111. package/dist/controller/catalog.d.ts +339 -0
  112. package/dist/controller/catalog.js +367 -0
  113. package/dist/controller/create-preview-controller.d.ts +532 -0
  114. package/dist/controller/create-preview-controller.js +1707 -0
  115. package/dist/controller/editor-tree.d.ts +161 -0
  116. package/dist/controller/editor-tree.js +373 -0
  117. package/dist/controller/html-source.d.ts +62 -0
  118. package/dist/controller/html-source.js +61 -0
  119. package/dist/controller/index.d.ts +9 -0
  120. package/dist/controller/index.js +12 -0
  121. package/dist/controller/persistence.d.ts +191 -0
  122. package/dist/controller/persistence.js +315 -0
  123. package/dist/controller/regeneration.d.ts +30 -0
  124. package/dist/controller/regeneration.js +27 -0
  125. package/dist/controller/source.d.ts +80 -0
  126. package/dist/controller/source.js +236 -0
  127. package/dist/controller/store.d.ts +27 -0
  128. package/dist/controller/store.js +40 -0
  129. package/dist/declarations/application/shells/charcell/components/Application/index.d.ts +2 -0
  130. package/dist/declarations/application/shells/charcell/components/Bar/index.d.ts +11 -0
  131. package/dist/declarations/application/shells/charcell/components/CodePane/index.d.ts +5 -0
  132. package/dist/declarations/application/shells/charcell/components/ComponentStage/index.d.ts +2 -0
  133. package/dist/declarations/application/shells/charcell/components/Control/index.d.ts +9 -0
  134. package/dist/declarations/application/shells/charcell/components/CopyLink/index.d.ts +1 -0
  135. package/dist/declarations/application/shells/charcell/components/Description/index.d.ts +5 -0
  136. package/dist/declarations/application/shells/charcell/components/EditorAddDialog/index.d.ts +6 -0
  137. package/dist/declarations/application/shells/charcell/components/EditorPanel/index.d.ts +2 -0
  138. package/dist/declarations/application/shells/charcell/components/EventsRow/index.d.ts +4 -0
  139. package/dist/declarations/application/shells/charcell/components/HeadingRow/index.d.ts +6 -0
  140. package/dist/declarations/application/shells/charcell/components/Hint/index.d.ts +11 -0
  141. package/dist/declarations/application/shells/charcell/components/HtmlWarnings/index.d.ts +5 -0
  142. package/dist/declarations/application/shells/charcell/components/KeyHints/index.d.ts +2 -0
  143. package/dist/declarations/application/shells/charcell/components/KitCodeBlock/index.d.ts +5 -0
  144. package/dist/declarations/application/shells/charcell/components/Markdown/index.d.ts +3 -0
  145. package/dist/declarations/application/shells/charcell/components/Navigation/index.d.ts +8 -0
  146. package/dist/declarations/application/shells/charcell/components/NavigationSplit/index.d.ts +7 -0
  147. package/dist/declarations/application/shells/charcell/components/OptionControls/index.d.ts +7 -0
  148. package/dist/declarations/application/shells/charcell/components/PaneStatus/index.d.ts +2 -0
  149. package/dist/declarations/application/shells/charcell/components/PaneWidth/index.d.ts +4 -0
  150. package/dist/declarations/application/shells/charcell/components/PreviewGrid/index.d.ts +7 -0
  151. package/dist/declarations/application/shells/charcell/components/PreviewPane/index.d.ts +9 -0
  152. package/dist/declarations/application/shells/charcell/components/PromptBar/index.d.ts +1 -0
  153. package/dist/declarations/application/shells/charcell/components/ScenarioRow/index.d.ts +2 -0
  154. package/dist/declarations/application/shells/charcell/components/Select/index.d.ts +16 -0
  155. package/dist/declarations/application/shells/charcell/components/SlotOutlet/index.d.ts +5 -0
  156. package/dist/declarations/application/shells/charcell/components/StageBar/index.d.ts +2 -0
  157. package/dist/declarations/application/shells/charcell/components/StageSplit/index.d.ts +17 -0
  158. package/dist/declarations/application/shells/charcell/components/StatusBar/index.d.ts +1 -0
  159. package/dist/declarations/application/shells/charcell/components/ViewControls/index.d.ts +9 -0
  160. package/dist/declarations/application/shells/charcell/components/ViewHeading/index.d.ts +4 -0
  161. package/dist/declarations/application/shells/charcell/components/ViewStage/index.d.ts +4 -0
  162. package/dist/declarations/application/shells/charcell/components/WrapToggle/index.d.ts +1 -0
  163. package/dist/declarations/application/shells/charcell/configuration.d.ts +31 -0
  164. package/dist/declarations/application/shells/charcell/controller-context.d.ts +9 -0
  165. package/dist/declarations/application/shells/charcell/fit-labels.d.ts +18 -0
  166. package/dist/declarations/application/shells/charcell/html-warnings.d.ts +5 -0
  167. package/dist/declarations/application/shells/charcell/index.d.ts +39 -0
  168. package/dist/declarations/application/shells/charcell/placement.d.ts +7 -0
  169. package/dist/declarations/application/shells/charcell/shell-options.d.ts +15 -0
  170. package/dist/declarations/application/shells/charcell/shell.d.ts +9 -0
  171. package/dist/declarations/application/shells/charcell/split-reset.d.ts +30 -0
  172. package/dist/declarations/application/shells/charcell/stacked-rows.d.ts +58 -0
  173. package/dist/declarations/application/shells/charcell/stage-toggles.d.ts +28 -0
  174. package/dist/declarations/src/controller/catalog.d.ts +339 -0
  175. package/dist/declarations/src/controller/create-preview-controller.d.ts +532 -0
  176. package/dist/declarations/src/controller/editor-tree.d.ts +161 -0
  177. package/dist/declarations/src/controller/html-source.d.ts +62 -0
  178. package/dist/declarations/src/controller/index.d.ts +9 -0
  179. package/dist/declarations/src/controller/persistence.d.ts +191 -0
  180. package/dist/declarations/src/controller/regeneration.d.ts +30 -0
  181. package/dist/declarations/src/controller/source.d.ts +80 -0
  182. package/dist/declarations/src/controller/store.d.ts +27 -0
  183. package/dist/declarations/src/emit/common.d.ts +103 -0
  184. package/dist/declarations/src/emit/manifest.d.ts +138 -0
  185. package/dist/declarations/src/emit/source.d.ts +87 -0
  186. package/dist/declarations/src/lib/jsx-roots.d.ts +22 -0
  187. package/dist/declarations/src/lib/module-of-source.d.ts +18 -0
  188. package/dist/declarations/src/lib/naming.d.ts +29 -0
  189. package/dist/declarations/src/lib/react-spelling.d.ts +68 -0
  190. package/dist/declarations/src/lib/scenario-story.d.ts +41 -0
  191. package/dist/declarations/src/lib/slot-fill.d.ts +15 -0
  192. package/dist/declarations/src/lib/types.d.ts +741 -0
  193. package/dist/declarations/src/options.d.ts +224 -0
  194. package/dist/declarations/src/protocol.d.ts +541 -0
  195. package/dist/declarations/src/react-view.d.ts +22 -0
  196. package/dist/declarations/src/react.d.ts +17 -0
  197. package/dist/declarations/src/shell.d.ts +99 -0
  198. package/dist/declarations/src/views.d.ts +152 -0
  199. package/dist/development-server.d.ts +121 -0
  200. package/dist/development-server.js +331 -0
  201. package/dist/emit/common.d.ts +103 -0
  202. package/dist/emit/common.js +170 -0
  203. package/dist/emit/html-source.d.ts +46 -0
  204. package/dist/emit/html-source.js +322 -0
  205. package/dist/emit/manifest.d.ts +138 -0
  206. package/dist/emit/manifest.js +74 -0
  207. package/dist/emit/react.d.ts +16 -0
  208. package/dist/emit/react.js +210 -0
  209. package/dist/emit/scratch.d.ts +40 -0
  210. package/dist/emit/scratch.js +116 -0
  211. package/dist/emit/source.d.ts +87 -0
  212. package/dist/emit/source.js +789 -0
  213. package/dist/emit/svelte.d.ts +9 -0
  214. package/dist/emit/svelte.js +177 -0
  215. package/dist/emit/vue.d.ts +2 -0
  216. package/dist/emit/vue.js +152 -0
  217. package/dist/enumerate.d.ts +2 -0
  218. package/dist/enumerate.js +162 -0
  219. package/dist/generate.d.ts +43 -0
  220. package/dist/generate.js +302 -0
  221. package/dist/html-stylesheet.d.ts +43 -0
  222. package/dist/html-stylesheet.js +145 -0
  223. package/dist/index.d.ts +18 -0
  224. package/dist/index.js +21 -0
  225. package/dist/landing.d.ts +16 -0
  226. package/dist/landing.js +45 -0
  227. package/dist/lib/exported-types.d.ts +42 -0
  228. package/dist/lib/exported-types.js +86 -0
  229. package/dist/lib/html-attributes.d.ts +2 -0
  230. package/dist/lib/html-attributes.js +111 -0
  231. package/dist/lib/html-warnings.d.ts +19 -0
  232. package/dist/lib/html-warnings.js +79 -0
  233. package/dist/lib/jsx-roots.d.ts +22 -0
  234. package/dist/lib/jsx-roots.js +243 -0
  235. package/dist/lib/module-of-source.d.ts +18 -0
  236. package/dist/lib/module-of-source.js +24 -0
  237. package/dist/lib/naming.d.ts +29 -0
  238. package/dist/lib/naming.js +56 -0
  239. package/dist/lib/parse-type.d.ts +32 -0
  240. package/dist/lib/parse-type.js +103 -0
  241. package/dist/lib/react-spelling.d.ts +68 -0
  242. package/dist/lib/react-spelling.js +197 -0
  243. package/dist/lib/scenario-story.d.ts +41 -0
  244. package/dist/lib/scenario-story.js +84 -0
  245. package/dist/lib/slot-fill.d.ts +15 -0
  246. package/dist/lib/slot-fill.js +92 -0
  247. package/dist/lib/template-files.d.ts +14 -0
  248. package/dist/lib/template-files.js +25 -0
  249. package/dist/lib/types.d.ts +741 -0
  250. package/dist/lib/types.js +13 -0
  251. package/dist/lib/void-elements.d.ts +7 -0
  252. package/dist/lib/void-elements.js +13 -0
  253. package/dist/load.d.ts +37 -0
  254. package/dist/load.js +82 -0
  255. package/dist/model.d.ts +44 -0
  256. package/dist/model.js +464 -0
  257. package/dist/options.d.ts +224 -0
  258. package/dist/options.js +223 -0
  259. package/dist/prop-types.d.ts +26 -0
  260. package/dist/prop-types.js +102 -0
  261. package/dist/props-from.d.ts +84 -0
  262. package/dist/props-from.js +510 -0
  263. package/dist/protocol.d.ts +541 -0
  264. package/dist/protocol.js +819 -0
  265. package/dist/react-view.d.ts +22 -0
  266. package/dist/react-view.js +36 -0
  267. package/dist/react.d.ts +17 -0
  268. package/dist/react.js +23 -0
  269. package/dist/sass-importers.d.ts +26 -0
  270. package/dist/sass-importers.js +32 -0
  271. package/dist/shell-acceptance.d.ts +21 -0
  272. package/dist/shell-acceptance.js +37 -0
  273. package/dist/shell-page.d.ts +36 -0
  274. package/dist/shell-page.js +90 -0
  275. package/dist/shell-peers.d.ts +38 -0
  276. package/dist/shell-peers.js +61 -0
  277. package/dist/shell.d.ts +99 -0
  278. package/dist/shell.js +52 -0
  279. package/dist/shells/charcell/page.d.ts +8 -0
  280. package/dist/shells/charcell/page.js +69 -0
  281. package/dist/story-source.d.ts +113 -0
  282. package/dist/story-source.js +271 -0
  283. package/dist/story.d.ts +5 -0
  284. package/dist/story.js +28 -0
  285. package/dist/testing.d.ts +218 -0
  286. package/dist/testing.js +284 -0
  287. package/dist/views.d.ts +152 -0
  288. package/dist/views.js +7 -0
  289. package/dist/vite-configuration.d.ts +114 -0
  290. package/dist/vite-configuration.js +578 -0
  291. package/package.json +123 -3
  292. package/src/build.ts +51 -0
  293. package/src/check.ts +1062 -0
  294. package/src/cli.ts +123 -0
  295. package/src/context.ts +1168 -0
  296. package/src/controller/catalog.ts +719 -0
  297. package/src/controller/create-preview-controller.ts +2683 -0
  298. package/src/controller/editor-tree.ts +530 -0
  299. package/src/controller/html-source.ts +114 -0
  300. package/src/controller/index.ts +105 -0
  301. package/src/controller/persistence.ts +403 -0
  302. package/src/controller/regeneration.ts +55 -0
  303. package/src/controller/source.ts +333 -0
  304. package/src/controller/store.ts +55 -0
  305. package/src/development-server.ts +442 -0
  306. package/src/emit/common.ts +201 -0
  307. package/src/emit/html-source.ts +402 -0
  308. package/src/emit/manifest.ts +241 -0
  309. package/src/emit/react.ts +263 -0
  310. package/src/emit/scratch.ts +175 -0
  311. package/src/emit/source.ts +1094 -0
  312. package/src/emit/svelte.ts +230 -0
  313. package/src/emit/vue.ts +194 -0
  314. package/src/enumerate.ts +220 -0
  315. package/src/generate.ts +443 -0
  316. package/src/html-stylesheet.ts +173 -0
  317. package/src/index.ts +60 -0
  318. package/src/landing.ts +58 -0
  319. package/src/lib/exported-types.ts +114 -0
  320. package/src/lib/html-attributes.ts +113 -0
  321. package/src/lib/html-warnings.ts +81 -0
  322. package/src/lib/jsx-roots.ts +238 -0
  323. package/src/lib/module-of-source.ts +26 -0
  324. package/src/lib/naming.ts +65 -0
  325. package/src/lib/parse-type.ts +143 -0
  326. package/src/lib/react-spelling.ts +235 -0
  327. package/src/lib/scenario-story.ts +97 -0
  328. package/src/lib/slot-fill.ts +102 -0
  329. package/src/lib/template-files.ts +31 -0
  330. package/src/lib/types.ts +778 -0
  331. package/src/lib/void-elements.ts +15 -0
  332. package/src/load.ts +144 -0
  333. package/src/model.ts +568 -0
  334. package/src/options.ts +435 -0
  335. package/src/prop-types.ts +133 -0
  336. package/src/props-from.ts +678 -0
  337. package/src/protocol.ts +1135 -0
  338. package/src/react-view.ts +45 -0
  339. package/src/react.ts +34 -0
  340. package/src/sass-importers.ts +45 -0
  341. package/src/shell-acceptance.ts +45 -0
  342. package/src/shell-page.ts +133 -0
  343. package/src/shell-peers.ts +70 -0
  344. package/src/shell.ts +194 -0
  345. package/src/shells/charcell/page.ts +82 -0
  346. package/src/story-source.ts +391 -0
  347. package/src/story.ts +42 -0
  348. package/src/testing.ts +497 -0
  349. package/src/views.ts +183 -0
  350. package/src/vite-configuration.ts +675 -0
@@ -0,0 +1,443 @@
1
+ // The preview generator: enumerate every source's component templates → build
2
+ // one target-agnostic model per component → emit a per-target
3
+ // render-registry + the host manifest into `<kitRoot>/.preview-generated/`. Pure
4
+ // function of the preview context - no kit names or paths are baked in; the
5
+ // kit supplies everything through its `preview` block (see context.ts).
6
+ //
7
+ // Every output is rendered before anything is written, so a kit module that
8
+ // fails to load leaves the previous output in place. A file is written only
9
+ // when its content differs from what is on disk, so a development server
10
+ // serving the tree reloads only for what changed.
11
+
12
+ import {
13
+ existsSync,
14
+ mkdirSync,
15
+ readdirSync,
16
+ readFileSync,
17
+ rmSync,
18
+ statSync,
19
+ writeFileSync,
20
+ } from 'node:fs';
21
+ import { basename, dirname, join, relative, resolve } from 'node:path';
22
+ import { kitPaneWidths, loadKit } from './load.js';
23
+ import { landingProblems } from './landing.js';
24
+ import { scenarioStories, storyOnScenario } from './lib/scenario-story.js';
25
+ import { resolveStory } from './model.js';
26
+ import { REACT_ATTRIBUTE_NAMES } from '@js-template-engine/extension-react';
27
+ import { declaredAttributes } from './lib/react-spelling.js';
28
+ import { emitReactRegistry } from './emit/react.js';
29
+ import { emitVueRegistry } from './emit/vue.js';
30
+ import { emitSvelteRegistry, emitSvelteWrapper } from './emit/svelte.js';
31
+ import { buildManifest, type ManifestImport } from './emit/manifest.js';
32
+ import { writeScratchStubs, type ScratchModules } from './emit/scratch.js';
33
+ import { optionProblems } from './options.js';
34
+ import {
35
+ htmlWarningLine,
36
+ printHtmlSource,
37
+ sourceStoryOf,
38
+ } from './story-source.js';
39
+ import { htmlSourceResponse } from './html-stylesheet.js';
40
+ import {
41
+ HTML_SOURCE_DIRECTORY,
42
+ type HtmlSourceResponse,
43
+ } from './controller/html-source.js';
44
+ import { exportedTypesOf } from './lib/exported-types.js';
45
+ import { sanitize } from './lib/naming.js';
46
+ import { moduleOfSource } from './lib/module-of-source.js';
47
+ import type { PreviewContext } from './context.js';
48
+ import type { ResolvedStory, Scenario, Target } from './lib/types.js';
49
+
50
+ const targets = ['react', 'vue', 'svelte'] as const;
51
+
52
+ /** How `generatePreview` treats the generated tree already on disk. */
53
+ export interface GeneratePreviewOptions {
54
+ /**
55
+ * Whether the generated tree is emptied before writing (the default). With
56
+ * `false`, as a running development server regenerates, the tree is kept:
57
+ * Vite's dependency cache and the scenario editor's story stay, a file is
58
+ * written only when its content changed, and a registry file no component
59
+ * produces any more is removed.
60
+ */
61
+ clean?: boolean;
62
+ /**
63
+ * Whether to print the html source of every story's scenarios into the
64
+ * served tree, one `html-source/<component id>.json` per component, as the
65
+ * static build reads it. Off by default: the development server prints
66
+ * html on request.
67
+ */
68
+ htmlSources?: boolean;
69
+ }
70
+
71
+ /** What `generatePreview` changed on disk. */
72
+ export interface GeneratePreviewResult {
73
+ /** The absolute paths written, because they were new or their content changed. */
74
+ written: string[];
75
+ /** The absolute paths of registry files removed because nothing produces them. */
76
+ removed: string[];
77
+ /** The absolute paths of the kit's theme sources the generation copied:
78
+ * each theme's stylesheet and its assets file or directory. */
79
+ themeSources: string[];
80
+ }
81
+
82
+ /** Every file under `directory`, as absolute paths. */
83
+ function filesUnder(directory: string): string[] {
84
+ return readdirSync(directory, { withFileTypes: true }).flatMap((entry) => {
85
+ const path = join(directory, entry.name);
86
+ return entry.isDirectory() ? filesUnder(path) : [path];
87
+ });
88
+ }
89
+
90
+ /** Writes `content` to `path` unless the file already holds exactly that. */
91
+ function writeIfChanged(path: string, content: string | Buffer): boolean {
92
+ const bytes = typeof content === 'string' ? Buffer.from(content) : content;
93
+ if (existsSync(path) && readFileSync(path).equals(bytes)) return false;
94
+ mkdirSync(dirname(path), { recursive: true });
95
+ writeFileSync(path, bytes);
96
+ return true;
97
+ }
98
+
99
+ /**
100
+ * Generates the preview into `<kitRoot>/.preview-generated/`: a render
101
+ * registry per target, the Svelte wrappers, the module-resolution data the
102
+ * scenario editor reads, the host manifest, and the themes' stylesheets.
103
+ *
104
+ * @param context - The kit's preview context.
105
+ * @param options - Whether the generated tree is emptied first.
106
+ * @returns The files written and removed.
107
+ * @example
108
+ * ```ts
109
+ * await generatePreview(loadPreviewContext(kitRoot));
110
+ * ```
111
+ */
112
+ export async function generatePreview(
113
+ context: PreviewContext,
114
+ options: GeneratePreviewOptions = {}
115
+ ): Promise<GeneratePreviewResult> {
116
+ const { clean = true, htmlSources = false } = options;
117
+ const { generatedRoot, sources } = context;
118
+ const directory: Record<string, string> = {};
119
+ for (const target of targets) {
120
+ directory[target] = resolve(generatedRoot, target);
121
+ }
122
+
123
+ const { components } = await loadKit(context);
124
+ const hints = context.configuration.controlHints ?? {};
125
+ const problems = optionProblems(context.configuration.options);
126
+ if (problems.length > 0) {
127
+ throw new Error(
128
+ `[preview] ${context.configurationPath} gives unsound preview.options:\n ${problems.join('\n ')}`
129
+ );
130
+ }
131
+ const paneWidths = kitPaneWidths(context);
132
+ if (paneWidths.errors.length > 0)
133
+ throw new Error(`[preview] ${paneWidths.errors.join('\n[preview] ')}`);
134
+ // Each output, in the order it is written: a registry after the wrappers it
135
+ // imports, and the manifest, which names every story, last.
136
+ const outputs: Array<[path: string, content: string | Buffer]> = [];
137
+ const themeSources: string[] = [];
138
+
139
+ // `moduleByName` remembers which module each component imports from, so the
140
+ // emitters group imports per source.
141
+ const moduleByName = new Map<string, string>();
142
+ const importOverrideByName = new Map<
143
+ string,
144
+ Partial<Record<Target, string>>
145
+ >();
146
+ const exportByName = new Map<string, string>();
147
+ for (const { component, source } of components) {
148
+ moduleByName.set(component.name, source.moduleBase);
149
+ if (component.importModule)
150
+ importOverrideByName.set(component.name, component.importModule);
151
+ if (component.exportName && component.exportName !== component.name) {
152
+ exportByName.set(component.name, component.exportName);
153
+ }
154
+ }
155
+ const built: ResolvedStory[] = components.map(
156
+ ({ component, story, source }) => ({
157
+ ...resolveStory(
158
+ component,
159
+ story,
160
+ hints,
161
+ context.configuration.labels,
162
+ context.omitPattern,
163
+ context.targets
164
+ ),
165
+ source: source.id,
166
+ })
167
+ );
168
+
169
+ // A component's per-target import module: a per-component override (a
170
+ // playground fixture outside its source's published barrel) wins; otherwise
171
+ // the source's module for the target (`moduleOfSource`), defaulting slot children that belong to
172
+ // no registered source to the kit's own (first) source.
173
+ const defaultModule = sources[0].moduleBase;
174
+ const moduleFor = (name: string, target: Target): string =>
175
+ importOverrideByName.get(name)?.[target] ??
176
+ moduleOfSource(moduleByName.get(name) ?? defaultModule, target);
177
+ const exportFor = (name: string): string => exportByName.get(name) ?? name;
178
+ // The names each component declares that React would otherwise respell
179
+ // (`class`, `style`, an attribute React renames): it takes them as they
180
+ // are, and every other attribute a story gives it as React spells it.
181
+ const declaredAttributesByName = new Map(
182
+ components.map(({ component }) => [
183
+ component.name,
184
+ declaredAttributes(Object.keys(component.props), REACT_ATTRIBUTE_NAMES),
185
+ ])
186
+ );
187
+ const declaredAttributesOf = (name: string): string[] =>
188
+ declaredAttributesByName.get(name) ?? [];
189
+ const declaredAttributesRecord = Object.fromEntries(
190
+ [...declaredAttributesByName].filter(([, names]) => names.length > 0)
191
+ );
192
+
193
+ // Browseable stories get registries + a nav entry; components that are not
194
+ // standalone (compound parts, shared blocks) are editor-only; omitted parts
195
+ // drop out entirely.
196
+ const stories: ResolvedStory[] = [];
197
+ const editorOnly: ResolvedStory[] = [];
198
+ const omitted: string[] = [];
199
+ for (const model of built) {
200
+ if (model.omit) {
201
+ omitted.push(model.name);
202
+ continue;
203
+ }
204
+ (model.standalone ? stories : editorOnly).push(model);
205
+ }
206
+ const landing = landingProblems(context.configuration.landing, stories);
207
+ if (landing.length > 0)
208
+ throw new Error(`[preview] ${landing.join('\n[preview] ')}`);
209
+
210
+ // Per-target registries (id → render unit) across ALL sources. A component
211
+ // renders only into the targets it declares within the kit's, so each
212
+ // target's registry sees only its own stories; a target the kit does not
213
+ // build gets an empty registry, so its iframe entry still builds.
214
+ // A scenario with slot content of its own is a story beside its
215
+ // component's, so its content renders as the component's does.
216
+ const forTarget = (target: Target): ResolvedStory[] =>
217
+ stories
218
+ .filter((model) => model.targets.includes(target))
219
+ .flatMap((model) => [model, ...scenarioStories(model)]);
220
+ for (const model of forTarget('svelte')) {
221
+ const wrapper = emitSvelteWrapper(model, moduleFor, exportFor);
222
+ outputs.push([resolve(directory.svelte, wrapper.fileName), wrapper.source]);
223
+ }
224
+ outputs.push(
225
+ [
226
+ resolve(directory.react, 'registry.tsx'),
227
+ emitReactRegistry(
228
+ forTarget('react'),
229
+ moduleFor,
230
+ exportFor,
231
+ declaredAttributesOf
232
+ ),
233
+ ],
234
+ [
235
+ resolve(directory.vue, 'registry.ts'),
236
+ emitVueRegistry(forTarget('vue'), moduleFor, exportFor),
237
+ ],
238
+ [
239
+ resolve(directory.svelte, 'registry.ts'),
240
+ emitSvelteRegistry(forTarget('svelte')),
241
+ ]
242
+ );
243
+
244
+ // The module-resolution data the scratch regeneration endpoint reads (it runs in the
245
+ // Vite dev middleware with no kit imports of its own).
246
+ const scratchModules: ScratchModules = {
247
+ defaultModule,
248
+ moduleByName: Object.fromEntries(moduleByName),
249
+ importOverrideByName: Object.fromEntries(importOverrideByName),
250
+ exportByName: Object.fromEntries(exportByName),
251
+ targets: context.targets,
252
+ ...(Object.keys(declaredAttributesRecord).length > 0
253
+ ? { declaredAttributes: declaredAttributesRecord }
254
+ : {}),
255
+ };
256
+ outputs.push([
257
+ resolve(generatedRoot, 'modules.json'),
258
+ JSON.stringify(scratchModules, null, 2) + '\n',
259
+ ]);
260
+
261
+ // Framework-neutral host manifest (nav, controls, color tokens) - stories
262
+ // plus the editor-only components (the editor reads both; the nav leaves
263
+ // those out).
264
+ const sourceMeta = sources.map((source) => ({
265
+ id: source.id,
266
+ label: source.label,
267
+ order: source.order,
268
+ moduleBase: source.moduleBase,
269
+ }));
270
+ // How a consumer imports each component, omitted ones included: a story's
271
+ // source in the browser names what its slot content holds.
272
+ const imports: Record<string, ManifestImport> = {};
273
+ for (const { component } of components) {
274
+ const types = exportedTypesOf(component, context.targets);
275
+ imports[component.name] = {
276
+ exportName: exportFor(component.name),
277
+ ...(declaredAttributesOf(component.name).length > 0
278
+ ? { declaredAttributes: declaredAttributesOf(component.name) }
279
+ : {}),
280
+ modules: Object.fromEntries(
281
+ context.targets.map((target) => [
282
+ target,
283
+ moduleFor(component.name, target),
284
+ ])
285
+ ),
286
+ ...(types ? { types } : {}),
287
+ };
288
+ }
289
+ const manifest: [string, string] = [
290
+ resolve(generatedRoot, 'manifest.json'),
291
+ JSON.stringify(
292
+ buildManifest(
293
+ [...stories, ...editorOnly],
294
+ sourceMeta,
295
+ hints.colorTokens ?? [],
296
+ context.kitName,
297
+ context.configuration.labels,
298
+ context.kitVersion,
299
+ context.configuration.persistence,
300
+ context.buildsHtml ? [...context.targets, 'html'] : context.targets,
301
+ imports,
302
+ context.configuration.codeBlock
303
+ ? { framework: context.configuration.codeBlock.framework ?? 'dom' }
304
+ : undefined,
305
+ paneWidths.paneWidths,
306
+ context.targets.includes('svelte') ? context.svelteMode : undefined,
307
+ context.targets.includes('react') ? REACT_ATTRIBUTE_NAMES : undefined,
308
+ context.configuration.landing
309
+ ),
310
+ null,
311
+ 2
312
+ ) + '\n',
313
+ ];
314
+
315
+ // Themes: copy each theme's compiled stylesheet (+ optional asset dir) into
316
+ // the served tree - `<generatedRoot>/public` is the Vite publicDir, so the iframes
317
+ // link `themes/<id>/theme.css` (under the URL the preview is served from) by convention in dev and static build alike.
318
+ for (const theme of context.configuration.themes) {
319
+ const themeDirectory = resolve(generatedRoot, 'public/themes', theme.id);
320
+ const cssSource = resolve(context.kitRoot, theme.css);
321
+ if (!existsSync(cssSource)) {
322
+ throw new Error(
323
+ `[preview] theme '${theme.id}' stylesheet not found: ${cssSource}`
324
+ );
325
+ }
326
+ themeSources.push(cssSource);
327
+ outputs.push([
328
+ resolve(themeDirectory, 'theme.css'),
329
+ readFileSync(cssSource),
330
+ ]);
331
+ if (theme.assets) {
332
+ const assetsSource = resolve(context.kitRoot, theme.assets);
333
+ themeSources.push(assetsSource);
334
+ if (existsSync(assetsSource)) {
335
+ const assetsDestination = resolve(
336
+ themeDirectory,
337
+ basename(assetsSource)
338
+ );
339
+ const files = statSync(assetsSource).isDirectory()
340
+ ? filesUnder(assetsSource)
341
+ : [assetsSource];
342
+ for (const file of files) {
343
+ outputs.push([
344
+ resolve(assetsDestination, relative(assetsSource, file)),
345
+ readFileSync(file),
346
+ ]);
347
+ }
348
+ }
349
+ }
350
+ }
351
+ // The html of each story's scenarios, which the static build cannot print
352
+ // on request: one file per component, by scenario id, the anonymous
353
+ // default under ''.
354
+ if (htmlSources) {
355
+ const enumerated = components.map((entry) => entry.component);
356
+ for (const [index, model] of built.entries()) {
357
+ if (model.omit || !model.standalone) continue;
358
+ const { component, story } = components[index];
359
+ const byScenario: Record<string, HtmlSourceResponse> = {};
360
+ // What the html leaves out, once per story however many of its
361
+ // scenarios do.
362
+ const warnings = new Set<string>();
363
+ const anonymous: Scenario = { id: '', props: {} };
364
+ for (const scenario of [anonymous, ...model.scenarios]) {
365
+ const result = await printHtmlSource(context, enumerated, {
366
+ component,
367
+ // The html the panes render, the unfilled default slot's
368
+ // placeholder included, as the scripted panes show it, and the
369
+ // scenario's own slot content where it has any.
370
+ ...sourceStoryOf(
371
+ component,
372
+ story,
373
+ storyOnScenario(model, scenario),
374
+ scenario.props ?? {},
375
+ { placeholder: true }
376
+ ),
377
+ });
378
+ if (result.markup !== undefined)
379
+ for (const warning of result.warnings) warnings.add(warning);
380
+ byScenario[scenario.id] = htmlSourceResponse(
381
+ context,
382
+ enumerated,
383
+ result
384
+ );
385
+ }
386
+ if (warnings.size > 0)
387
+ console.warn(
388
+ `[preview:generate] ${htmlWarningLine(model.name, [...warnings])}`
389
+ );
390
+ outputs.push([
391
+ resolve(
392
+ generatedRoot,
393
+ 'public',
394
+ HTML_SOURCE_DIRECTORY,
395
+ `${sanitize(model.title)}.json`
396
+ ),
397
+ JSON.stringify(byScenario) + '\n',
398
+ ]);
399
+ }
400
+ }
401
+ outputs.push(manifest);
402
+
403
+ // Everything rendered: only now is the tree touched.
404
+ if (clean) rmSync(generatedRoot, { recursive: true, force: true });
405
+ for (const target of targets) {
406
+ mkdirSync(directory[target], { recursive: true });
407
+ }
408
+ // Empty scratch registries so the previews' static scratch imports resolve;
409
+ // the scenario editor overwrites these on each edit (see emit/scratch.ts),
410
+ // so a kept tree keeps the story it holds.
411
+ if (clean || !existsSync(resolve(generatedRoot, 'scratch'))) {
412
+ writeScratchStubs(generatedRoot);
413
+ }
414
+ const written = outputs
415
+ .filter(([path, content]) => writeIfChanged(path, content))
416
+ .map(([path]) => path);
417
+ const produced = new Set(outputs.map(([path]) => path));
418
+ const removed = targets
419
+ .flatMap((target) => filesUnder(directory[target]))
420
+ .filter((path) => !produced.has(path));
421
+ for (const path of removed) rmSync(path, { force: true });
422
+
423
+ const sourceSummary = sources
424
+ .map((source) => `${source.id}=${source.moduleBase}`)
425
+ .join(', ');
426
+ console.log(
427
+ `[preview:generate] ${stories.length} components × ${context.targets.length} targets → .preview-generated/ (sources: ${sourceSummary})`
428
+ );
429
+ if (editorOnly.length > 0)
430
+ console.log(
431
+ `[preview:generate] ${editorOnly.length} not standalone (editor-only): ${editorOnly.map((model) => model.name).join(', ')}`
432
+ );
433
+ const unlisted = stories.filter((model) => model.unlisted);
434
+ if (unlisted.length > 0)
435
+ console.log(
436
+ `[preview:generate] unlisted ${unlisted.length} (reachable at their address): ${unlisted.map((model) => model.name).join(', ')}`
437
+ );
438
+ if (omitted.length > 0)
439
+ console.log(
440
+ `[preview:generate] omitted ${omitted.length} (by omit or omitPattern): ${omitted.join(', ')}`
441
+ );
442
+ return { written, removed, themeSources };
443
+ }
@@ -0,0 +1,173 @@
1
+ // The component styles the html pane shows its markup under: what the kit's
2
+ // build wrote for the html target, read from `dist/html` for the components a
3
+ // story renders. Under `in-file` each page carries its styles in `<style>`
4
+ // blocks; under `separate-file` each component has a stylesheet of its own,
5
+ // compiled when it is SCSS with the kit's own Sass and load paths. The markup
6
+ // is printed from the templates on request, so a component changed since the
7
+ // last build shows its last built styles until the kit builds again.
8
+
9
+ import { existsSync, readFileSync, statSync } from 'node:fs';
10
+ import { createRequire } from 'node:module';
11
+ import { dirname, resolve } from 'node:path';
12
+ import type { PreviewContext } from './context.js';
13
+ import type { HtmlSourceResponse } from './controller/html-source.js';
14
+ import type { HtmlSourceResult } from './emit/html-source.js';
15
+ import { summarizeHtmlWarnings } from './lib/html-warnings.js';
16
+ import { kitImporters, kitPackageDirectories } from './sass-importers.js';
17
+ import type { EnumeratedComponent } from './lib/types.js';
18
+
19
+ /** Where the kit's build writes the html target, relative to the kit root. */
20
+ export const HTML_DISTRIBUTION_DIRECTORY = 'dist/html';
21
+
22
+ const STYLE_BLOCK = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
23
+
24
+ /**
25
+ * The `<style>` blocks of a page, joined in document order.
26
+ *
27
+ * @param page - A page's markup.
28
+ * @returns The CSS its style blocks hold, or `''` when it has none.
29
+ * @example
30
+ * ```ts
31
+ * styleBlocksOf('<style>.a { color: red; }</style><p class="a"></p>');
32
+ * // '.a { color: red; }'
33
+ * ```
34
+ */
35
+ export function styleBlocksOf(page: string): string {
36
+ return [...page.matchAll(STYLE_BLOCK)]
37
+ .map((match) => match[1].trim())
38
+ .filter((css) => css !== '')
39
+ .join('\n');
40
+ }
41
+
42
+ /** A component name a built file can carry: an identifier, so it names a
43
+ * file in the html directory and nothing outside it. */
44
+ const BUILT_NAME = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
45
+
46
+ /** Each compiled SCSS sheet, by path, with the modification time it was
47
+ * compiled at. */
48
+ const compiledSheets = new Map<string, { modified: number; css: string }>();
49
+
50
+ /** The sheets already reported as left out, each reported once. */
51
+ const reportedSheets = new Set<string>();
52
+
53
+ /** Compiles an SCSS file with the kit's own Sass, or says why it cannot.
54
+ * A sheet unchanged since it last compiled is not compiled again. */
55
+ function compileScss(
56
+ path: string,
57
+ context: PreviewContext
58
+ ): { css: string } | { problem: string } {
59
+ const modified = statSync(path).mtimeMs;
60
+ const cached = compiledSheets.get(path);
61
+ if (cached && cached.modified === modified) return { css: cached.css };
62
+ let sass: {
63
+ compile: (
64
+ path: string,
65
+ options: { loadPaths: string[]; importers: unknown[] }
66
+ ) => { css: string };
67
+ NodePackageImporter?: new (entryPointDirectory?: string) => unknown;
68
+ };
69
+ try {
70
+ const kitRequire = createRequire(resolve(context.kitRoot, 'package.json'));
71
+ sass = kitRequire('sass') as typeof sass;
72
+ } catch {
73
+ return { problem: 'the kit has no sass installed to compile it' };
74
+ }
75
+ try {
76
+ const loadPaths = [
77
+ dirname(path),
78
+ ...context.sassLoadPathsAbsolute,
79
+ ...(context.configuration.scssLoadPaths ?? []).map((loadPath) =>
80
+ resolve(context.kitRoot, loadPath)
81
+ ),
82
+ ];
83
+ // The kit's own `pkg:` URLs resolve through its package.json exports,
84
+ // as its build resolves them, and any other through Sass's own importer.
85
+ const importers: unknown[] = [
86
+ ...kitImporters(context.kitRoot, kitPackageDirectories(context)),
87
+ ...(sass.NodePackageImporter
88
+ ? [new sass.NodePackageImporter(context.kitRoot)]
89
+ : []),
90
+ ];
91
+ const css = sass.compile(path, { loadPaths, importers }).css;
92
+ compiledSheets.set(path, { modified, css });
93
+ return { css };
94
+ } catch (error) {
95
+ return { problem: error instanceof Error ? error.message : String(error) };
96
+ }
97
+ }
98
+
99
+ /**
100
+ * The CSS the kit's build wrote for the html target of each named
101
+ * component, in the order given: the `<style>` blocks of its page and its
102
+ * own stylesheet, when it has one. A component with no built output adds
103
+ * nothing.
104
+ *
105
+ * @param context - The kit's preview context.
106
+ * @param components - Every component of the kit.
107
+ * @param names - The components whose styles to read, by name.
108
+ * @returns The CSS, one comment-headed section per component, or `''`.
109
+ */
110
+ export function htmlComponentStylesheet(
111
+ context: PreviewContext,
112
+ components: readonly EnumeratedComponent[],
113
+ names: readonly string[]
114
+ ): string {
115
+ const directory = resolve(context.kitRoot, HTML_DISTRIBUTION_DIRECTORY);
116
+ if (!existsSync(directory)) return '';
117
+ const sections: string[] = [];
118
+ for (const name of names) {
119
+ if (!components.some((candidate) => candidate.name === name)) continue;
120
+ if (!BUILT_NAME.test(name)) continue;
121
+ const parts: string[] = [];
122
+ const page = resolve(directory, `${name}.html`);
123
+ if (existsSync(page)) parts.push(styleBlocksOf(readFileSync(page, 'utf8')));
124
+ const css = resolve(directory, `${name}.css`);
125
+ if (existsSync(css)) parts.push(readFileSync(css, 'utf8').trim());
126
+ const scss = resolve(directory, `${name}.scss`);
127
+ if (existsSync(scss)) {
128
+ const compiled = compileScss(scss, context);
129
+ if ('css' in compiled) parts.push(compiled.css.trim());
130
+ else if (!reportedSheets.has(scss)) {
131
+ reportedSheets.add(scss);
132
+ console.warn(
133
+ `[preview] ${name}: the html pane leaves out ${name}.scss, as ${compiled.problem}`
134
+ );
135
+ }
136
+ }
137
+ const styles = parts.filter((part) => part !== '').join('\n');
138
+ if (styles !== '') sections.push(`/* ${name} */\n${styles}`);
139
+ }
140
+ return sections.join('\n\n');
141
+ }
142
+
143
+ /**
144
+ * A printed story as the html pane receives it: its markup with the styles
145
+ * of the components it renders and the warnings for what it leaves out,
146
+ * those one component gives for one reason counted on a single line, or
147
+ * what keeps it from having markup.
148
+ *
149
+ * @param context - The kit's preview context.
150
+ * @param components - Every component of the kit.
151
+ * @param result - The printed story.
152
+ * @returns The response the development server answers and the static
153
+ * build stores.
154
+ */
155
+ export function htmlSourceResponse(
156
+ context: PreviewContext,
157
+ components: readonly EnumeratedComponent[],
158
+ result: HtmlSourceResult
159
+ ): HtmlSourceResponse {
160
+ if (result.markup === undefined) return { missing: result.missing };
161
+ const stylesheet = htmlComponentStylesheet(
162
+ context,
163
+ components,
164
+ result.components
165
+ );
166
+ return {
167
+ markup: result.markup,
168
+ ...(stylesheet === '' ? {} : { stylesheet }),
169
+ ...(result.warnings.length === 0
170
+ ? {}
171
+ : { warnings: summarizeHtmlWarnings(result.warnings) }),
172
+ };
173
+ }
package/src/index.ts ADDED
@@ -0,0 +1,60 @@
1
+ // Programmatic surface: everything a consumer's own scripts (or tests) need -
2
+ // the context loader, the generator, the Vite configuration factory, and the model /
3
+ // emit layer the registries are built from.
4
+
5
+ export {
6
+ jsonProblems,
7
+ loadPreviewContext,
8
+ type PreviewContext,
9
+ type ResolvedSource,
10
+ } from './context.js';
11
+ export { generatePreview } from './generate.js';
12
+ export {
13
+ checkPreview,
14
+ type PreviewCheckOptions,
15
+ type PreviewCheckReport,
16
+ } from './check.js';
17
+ export {
18
+ storySource,
19
+ type SourceTarget,
20
+ type StorySource,
21
+ type StorySourceOptions,
22
+ } from './story-source.js';
23
+ export {
24
+ loadKit,
25
+ kitPaneWidths,
26
+ type KitPaneWidths,
27
+ type LoadedComponent,
28
+ type LoadedKit,
29
+ } from './load.js';
30
+ export {
31
+ readPropsFrom,
32
+ resolveManualComponent,
33
+ type PropsFromResult,
34
+ } from './props-from.js';
35
+ export {
36
+ applicationRoot,
37
+ buildViteConfiguration,
38
+ type DevelopmentServerOverrides,
39
+ } from './vite-configuration.js';
40
+ export { enumerateComponents } from './enumerate.js';
41
+ export { resolveStory } from './model.js';
42
+ export { propTypeForProp, defaultPropForProp } from './prop-types.js';
43
+ export { loadStory, isStructurallyOmitted } from './story.js';
44
+ export { emitReactRegistry } from './emit/react.js';
45
+ export { emitVueRegistry } from './emit/vue.js';
46
+ export { emitSvelteRegistry, emitSvelteWrapper } from './emit/svelte.js';
47
+ export {
48
+ buildManifest,
49
+ type Manifest,
50
+ type ManifestComponent,
51
+ type ManifestSource,
52
+ } from './emit/manifest.js';
53
+ export {
54
+ writeScratch,
55
+ writeScratchStubs,
56
+ SCRATCH_ID,
57
+ type ScratchPayload,
58
+ } from './emit/scratch.js';
59
+ export * from './lib/types.js';
60
+ export * from './options.js';