poveste 0.1.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 (251) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +11 -0
  3. package/bin.mjs +4 -0
  4. package/client.d.ts +19 -0
  5. package/client.js +15 -0
  6. package/dist/controls.d.ts +2 -0
  7. package/dist/controls.d.ts.map +1 -0
  8. package/dist/controls.js +1 -0
  9. package/dist/node/alias.d.ts +3 -0
  10. package/dist/node/alias.d.ts.map +1 -0
  11. package/dist/node/alias.js +5 -0
  12. package/dist/node/bin.d.ts +2 -0
  13. package/dist/node/bin.d.ts.map +1 -0
  14. package/dist/node/bin.js +35 -0
  15. package/dist/node/build-serialize.d.ts +22 -0
  16. package/dist/node/build-serialize.d.ts.map +1 -0
  17. package/dist/node/build-serialize.js +36 -0
  18. package/dist/node/build.d.ts +3 -0
  19. package/dist/node/build.d.ts.map +1 -0
  20. package/dist/node/build.js +228 -0
  21. package/dist/node/builtin-plugins/pinceau-tokens.d.ts +7 -0
  22. package/dist/node/builtin-plugins/pinceau-tokens.d.ts.map +1 -0
  23. package/dist/node/builtin-plugins/pinceau-tokens.js +505 -0
  24. package/dist/node/builtin-plugins/tailwind-tokens.d.ts +6 -0
  25. package/dist/node/builtin-plugins/tailwind-tokens.d.ts.map +1 -0
  26. package/dist/node/builtin-plugins/tailwind-tokens.js +523 -0
  27. package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts +15 -0
  28. package/dist/node/builtin-plugins/vanilla-support/MountStory.d.ts.map +1 -0
  29. package/dist/node/builtin-plugins/vanilla-support/MountStory.js +39 -0
  30. package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts +39 -0
  31. package/dist/node/builtin-plugins/vanilla-support/RenderStory.d.ts.map +1 -0
  32. package/dist/node/builtin-plugins/vanilla-support/RenderStory.js +129 -0
  33. package/dist/node/builtin-plugins/vanilla-support/client.d.ts +4 -0
  34. package/dist/node/builtin-plugins/vanilla-support/client.d.ts.map +1 -0
  35. package/dist/node/builtin-plugins/vanilla-support/client.js +5 -0
  36. package/dist/node/builtin-plugins/vanilla-support/collect.d.ts +3 -0
  37. package/dist/node/builtin-plugins/vanilla-support/collect.d.ts.map +1 -0
  38. package/dist/node/builtin-plugins/vanilla-support/collect.js +33 -0
  39. package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts +3 -0
  40. package/dist/node/builtin-plugins/vanilla-support/plugin.d.ts.map +1 -0
  41. package/dist/node/builtin-plugins/vanilla-support/plugin.js +29 -0
  42. package/dist/node/builtin-plugins/vanilla-support/types.d.ts +36 -0
  43. package/dist/node/builtin-plugins/vanilla-support/types.d.ts.map +1 -0
  44. package/dist/node/builtin-plugins/vanilla-support/types.js +3 -0
  45. package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts +4 -0
  46. package/dist/node/builtin-plugins/vanilla-support/vanilla.story.d.ts.map +1 -0
  47. package/dist/node/builtin-plugins/vanilla-support/vanilla.story.js +55 -0
  48. package/dist/node/collect/index.d.ts +14 -0
  49. package/dist/node/collect/index.d.ts.map +1 -0
  50. package/dist/node/collect/index.js +129 -0
  51. package/dist/node/collect/run.d.ts +3 -0
  52. package/dist/node/collect/run.d.ts.map +1 -0
  53. package/dist/node/collect/run.js +7 -0
  54. package/dist/node/collect/worker.d.ts +14 -0
  55. package/dist/node/collect/worker.d.ts.map +1 -0
  56. package/dist/node/collect/worker.js +64 -0
  57. package/dist/node/colors.d.ts +287 -0
  58. package/dist/node/colors.d.ts.map +1 -0
  59. package/dist/node/colors.js +324 -0
  60. package/dist/node/commands/build.d.ts +5 -0
  61. package/dist/node/commands/build.d.ts.map +1 -0
  62. package/dist/node/commands/build.js +9 -0
  63. package/dist/node/commands/dev.d.ts +8 -0
  64. package/dist/node/commands/dev.d.ts.map +1 -0
  65. package/dist/node/commands/dev.js +52 -0
  66. package/dist/node/commands/preview.d.ts +5 -0
  67. package/dist/node/commands/preview.d.ts.map +1 -0
  68. package/dist/node/commands/preview.js +15 -0
  69. package/dist/node/config.d.ts +40 -0
  70. package/dist/node/config.d.ts.map +1 -0
  71. package/dist/node/config.js +330 -0
  72. package/dist/node/context.d.ts +18 -0
  73. package/dist/node/context.d.ts.map +1 -0
  74. package/dist/node/context.js +28 -0
  75. package/dist/node/dom/dom-keys.d.ts +5 -0
  76. package/dist/node/dom/dom-keys.d.ts.map +1 -0
  77. package/dist/node/dom/dom-keys.js +233 -0
  78. package/dist/node/dom/env.d.ts +5 -0
  79. package/dist/node/dom/env.d.ts.map +1 -0
  80. package/dist/node/dom/env.js +47 -0
  81. package/dist/node/dom/util.d.ts +11 -0
  82. package/dist/node/dom/util.d.ts.map +1 -0
  83. package/dist/node/dom/util.js +65 -0
  84. package/dist/node/index.d.ts +12 -0
  85. package/dist/node/index.d.ts.map +1 -0
  86. package/dist/node/index.js +4 -0
  87. package/dist/node/load.d.ts +9 -0
  88. package/dist/node/load.d.ts.map +1 -0
  89. package/dist/node/load.js +42 -0
  90. package/dist/node/markdown.d.ts +11 -0
  91. package/dist/node/markdown.d.ts.map +1 -0
  92. package/dist/node/markdown.js +228 -0
  93. package/dist/node/plugin.d.ts +42 -0
  94. package/dist/node/plugin.d.ts.map +1 -0
  95. package/dist/node/plugin.js +67 -0
  96. package/dist/node/preview.d.ts +8 -0
  97. package/dist/node/preview.d.ts.map +1 -0
  98. package/dist/node/preview.js +41 -0
  99. package/dist/node/search.d.ts +17 -0
  100. package/dist/node/search.d.ts.map +1 -0
  101. package/dist/node/search.js +72 -0
  102. package/dist/node/server.d.ts +12 -0
  103. package/dist/node/server.d.ts.map +1 -0
  104. package/dist/node/server.js +189 -0
  105. package/dist/node/stories.d.ts +22 -0
  106. package/dist/node/stories.d.ts.map +1 -0
  107. package/dist/node/stories.js +125 -0
  108. package/dist/node/tree.d.ts +4 -0
  109. package/dist/node/tree.d.ts.map +1 -0
  110. package/dist/node/tree.js +117 -0
  111. package/dist/node/util/find-up.d.ts +2 -0
  112. package/dist/node/util/find-up.d.ts.map +1 -0
  113. package/dist/node/util/find-up.js +20 -0
  114. package/dist/node/util/fs.d.ts +2 -0
  115. package/dist/node/util/fs.d.ts.map +1 -0
  116. package/dist/node/util/fs.js +1 -0
  117. package/dist/node/util/log.d.ts +2 -0
  118. package/dist/node/util/log.d.ts.map +1 -0
  119. package/dist/node/util/log.js +9 -0
  120. package/dist/node/util/slugify.d.ts +2 -0
  121. package/dist/node/util/slugify.d.ts.map +1 -0
  122. package/dist/node/util/slugify.js +22 -0
  123. package/dist/node/util/vendors.d.ts +3 -0
  124. package/dist/node/util/vendors.d.ts.map +1 -0
  125. package/dist/node/util/vendors.js +22 -0
  126. package/dist/node/vendors/controls.d.ts +2 -0
  127. package/dist/node/vendors/controls.d.ts.map +1 -0
  128. package/dist/node/vendors/controls.js +1 -0
  129. package/dist/node/vendors/vue.d.ts +2 -0
  130. package/dist/node/vendors/vue.d.ts.map +1 -0
  131. package/dist/node/vendors/vue.js +1 -0
  132. package/dist/node/virtual/index.d.ts +38 -0
  133. package/dist/node/virtual/index.d.ts.map +1 -0
  134. package/dist/node/virtual/index.js +49 -0
  135. package/dist/node/virtual/markdown.d.ts +3 -0
  136. package/dist/node/virtual/markdown.d.ts.map +1 -0
  137. package/dist/node/virtual/markdown.js +19 -0
  138. package/dist/node/virtual/noop.d.ts +2 -0
  139. package/dist/node/virtual/noop.d.ts.map +1 -0
  140. package/dist/node/virtual/noop.js +1 -0
  141. package/dist/node/virtual/resolved-commands.d.ts +3 -0
  142. package/dist/node/virtual/resolved-commands.d.ts.map +1 -0
  143. package/dist/node/virtual/resolved-commands.js +32 -0
  144. package/dist/node/virtual/resolved-config.d.ts +3 -0
  145. package/dist/node/virtual/resolved-config.d.ts.map +1 -0
  146. package/dist/node/virtual/resolved-config.js +10 -0
  147. package/dist/node/virtual/resolved-generated-global-setup.d.ts +3 -0
  148. package/dist/node/virtual/resolved-generated-global-setup.d.ts.map +1 -0
  149. package/dist/node/virtual/resolved-generated-global-setup.js +23 -0
  150. package/dist/node/virtual/resolved-generated-setup-code.d.ts +3 -0
  151. package/dist/node/virtual/resolved-generated-setup-code.d.ts.map +1 -0
  152. package/dist/node/virtual/resolved-generated-setup-code.js +5 -0
  153. package/dist/node/virtual/resolved-markdown-files.d.ts +3 -0
  154. package/dist/node/virtual/resolved-markdown-files.d.ts.map +1 -0
  155. package/dist/node/virtual/resolved-markdown-files.js +17 -0
  156. package/dist/node/virtual/resolved-stories.d.ts +3 -0
  157. package/dist/node/virtual/resolved-stories.d.ts.map +1 -0
  158. package/dist/node/virtual/resolved-stories.js +42 -0
  159. package/dist/node/virtual/resolved-support-plugins-client.d.ts +3 -0
  160. package/dist/node/virtual/resolved-support-plugins-client.d.ts.map +1 -0
  161. package/dist/node/virtual/resolved-support-plugins-client.js +11 -0
  162. package/dist/node/virtual/resolved-support-plugins-collect.d.ts +3 -0
  163. package/dist/node/virtual/resolved-support-plugins-collect.d.ts.map +1 -0
  164. package/dist/node/virtual/resolved-support-plugins-collect.js +11 -0
  165. package/dist/node/virtual/resolved-theme.d.ts +3 -0
  166. package/dist/node/virtual/resolved-theme.d.ts.map +1 -0
  167. package/dist/node/virtual/resolved-theme.js +12 -0
  168. package/dist/node/virtual/story-source.d.ts +3 -0
  169. package/dist/node/virtual/story-source.d.ts.map +1 -0
  170. package/dist/node/virtual/story-source.js +16 -0
  171. package/dist/node/virtual/story.d.ts +3 -0
  172. package/dist/node/virtual/story.d.ts.map +1 -0
  173. package/dist/node/virtual/story.js +7 -0
  174. package/dist/node/virtual/util.d.ts +3 -0
  175. package/dist/node/virtual/util.d.ts.map +1 -0
  176. package/dist/node/virtual/util.js +4 -0
  177. package/dist/node/virtual/vite-plugin.d.ts +4 -0
  178. package/dist/node/virtual/vite-plugin.d.ts.map +1 -0
  179. package/dist/node/virtual/vite-plugin.js +126 -0
  180. package/dist/node/vite.d.ts +9 -0
  181. package/dist/node/vite.d.ts.map +1 -0
  182. package/dist/node/vite.js +337 -0
  183. package/index.d.ts +1 -0
  184. package/package.json +89 -0
  185. package/plugin.d.ts +3 -0
  186. package/plugin.js +11 -0
  187. package/src/controls.ts +1 -0
  188. package/src/node/__tests__/markdown/test1.story.md +7 -0
  189. package/src/node/__tests__/markdown/test2.story.md +5 -0
  190. package/src/node/__tests__/markdown.spec.ts +61 -0
  191. package/src/node/__tests__/tree.spec.ts +109 -0
  192. package/src/node/alias.ts +8 -0
  193. package/src/node/bin.ts +43 -0
  194. package/src/node/build-serialize.ts +62 -0
  195. package/src/node/build.ts +283 -0
  196. package/src/node/builtin-plugins/pinceau-tokens.ts +521 -0
  197. package/src/node/builtin-plugins/tailwind-tokens.ts +536 -0
  198. package/src/node/builtin-plugins/vanilla-support/MountStory.ts +49 -0
  199. package/src/node/builtin-plugins/vanilla-support/RenderStory.ts +164 -0
  200. package/src/node/builtin-plugins/vanilla-support/client.ts +6 -0
  201. package/src/node/builtin-plugins/vanilla-support/collect.ts +43 -0
  202. package/src/node/builtin-plugins/vanilla-support/plugin.ts +35 -0
  203. package/src/node/builtin-plugins/vanilla-support/types.ts +40 -0
  204. package/src/node/builtin-plugins/vanilla-support/vanilla.story.ts +63 -0
  205. package/src/node/collect/index.ts +160 -0
  206. package/src/node/collect/run.ts +9 -0
  207. package/src/node/collect/worker.ts +97 -0
  208. package/src/node/colors.ts +340 -0
  209. package/src/node/commands/build.ts +14 -0
  210. package/src/node/commands/dev.ts +67 -0
  211. package/src/node/commands/preview.ts +22 -0
  212. package/src/node/config.ts +385 -0
  213. package/src/node/context.ts +60 -0
  214. package/src/node/dom/dom-keys.ts +238 -0
  215. package/src/node/dom/env.ts +60 -0
  216. package/src/node/dom/util.ts +83 -0
  217. package/src/node/index.ts +12 -0
  218. package/src/node/load.ts +59 -0
  219. package/src/node/markdown.ts +267 -0
  220. package/src/node/plugin.ts +95 -0
  221. package/src/node/preview.ts +57 -0
  222. package/src/node/search.ts +84 -0
  223. package/src/node/server.ts +235 -0
  224. package/src/node/stories.ts +154 -0
  225. package/src/node/tree.ts +158 -0
  226. package/src/node/util/find-up.ts +24 -0
  227. package/src/node/util/fs.ts +1 -0
  228. package/src/node/util/log.ts +10 -0
  229. package/src/node/util/slugify.ts +26 -0
  230. package/src/node/util/vendors.ts +27 -0
  231. package/src/node/vendors/controls.ts +1 -0
  232. package/src/node/vendors/vue.ts +1 -0
  233. package/src/node/virtual/index.ts +50 -0
  234. package/src/node/virtual/markdown.ts +21 -0
  235. package/src/node/virtual/noop.ts +1 -0
  236. package/src/node/virtual/resolved-commands.ts +42 -0
  237. package/src/node/virtual/resolved-config.ts +12 -0
  238. package/src/node/virtual/resolved-generated-global-setup.ts +25 -0
  239. package/src/node/virtual/resolved-generated-setup-code.ts +7 -0
  240. package/src/node/virtual/resolved-markdown-files.ts +19 -0
  241. package/src/node/virtual/resolved-stories.ts +44 -0
  242. package/src/node/virtual/resolved-support-plugins-client.ts +14 -0
  243. package/src/node/virtual/resolved-support-plugins-collect.ts +14 -0
  244. package/src/node/virtual/resolved-theme.ts +14 -0
  245. package/src/node/virtual/story-source.ts +18 -0
  246. package/src/node/virtual/story.ts +9 -0
  247. package/src/node/virtual/util.ts +5 -0
  248. package/src/node/virtual/vite-plugin.ts +146 -0
  249. package/src/node/vite.ts +379 -0
  250. package/tsconfig.json +44 -0
  251. package/vitest.config.ts +10 -0
@@ -0,0 +1,129 @@
1
+ import { defineComponent as _defineComponent, h as _h, onBeforeUnmount as _onBeforeUnmount, onMounted as _onMounted, ref as _ref, watch as _watch, } from '@poveste/vendors/vue';
2
+ // @ts-expect-error virtual module id
3
+ import * as generatedSetup from 'virtual:$histoire-generated-global-setup';
4
+ // @ts-expect-error virtual module id
5
+ import * as setup from 'virtual:$histoire-setup';
6
+ export default _defineComponent({
7
+ name: 'RenderStory',
8
+ props: {
9
+ variant: {
10
+ type: Object,
11
+ required: true,
12
+ },
13
+ story: {
14
+ type: Object,
15
+ required: true,
16
+ },
17
+ slotName: {
18
+ type: String,
19
+ default: 'default',
20
+ },
21
+ },
22
+ emits: {
23
+ ready: () => true,
24
+ },
25
+ setup(props, { emit }) {
26
+ const sandbox = _ref();
27
+ let mounting = false;
28
+ let app;
29
+ let appHooks;
30
+ async function unmountVariant() {
31
+ if (app) {
32
+ await app.onUnmount?.();
33
+ if (appHooks) {
34
+ for (const hook of appHooks.onUnmount) {
35
+ await hook();
36
+ }
37
+ }
38
+ app.el.parentNode.removeChild(app.el);
39
+ app = null;
40
+ }
41
+ }
42
+ async function mountVariant() {
43
+ if (mounting)
44
+ return;
45
+ mounting = true;
46
+ await unmountVariant();
47
+ app = {
48
+ el: document.createElement('div'),
49
+ };
50
+ if (typeof generatedSetup?.setupVanilla === 'function') {
51
+ await generatedSetup.setupVanilla({
52
+ app,
53
+ story: props.story,
54
+ variant: props.variant,
55
+ });
56
+ }
57
+ if (typeof setup?.setupVanilla === 'function') {
58
+ await setup.setupVanilla({
59
+ app,
60
+ story: props.story,
61
+ variant: props.variant,
62
+ });
63
+ }
64
+ if (typeof props.variant.setupApp === 'function') {
65
+ await props.variant.setupApp({
66
+ app,
67
+ story: props.story,
68
+ variant: props.variant,
69
+ });
70
+ }
71
+ await app.onMount?.();
72
+ appHooks = {
73
+ onUpdate: [],
74
+ onUnmount: [],
75
+ };
76
+ const api = {
77
+ el: app.el,
78
+ state: props.variant.state,
79
+ onUpdate: (cb) => {
80
+ appHooks.onUpdate.push(cb);
81
+ },
82
+ onUnmount: (cb) => {
83
+ appHooks.onUnmount.push(cb);
84
+ },
85
+ };
86
+ const onMount = props.variant.slots()[props.slotName];
87
+ await onMount(api);
88
+ sandbox.value.appendChild(app.el);
89
+ emit('ready');
90
+ }
91
+ _onMounted(async () => {
92
+ if (props.variant.configReady) {
93
+ await mountVariant();
94
+ }
95
+ });
96
+ _watch(() => props.variant, async (value) => {
97
+ if (value.configReady && !mounting) {
98
+ if (!app) {
99
+ await mountVariant();
100
+ }
101
+ else {
102
+ // @TODO check if need to refresh here
103
+ }
104
+ }
105
+ }, {
106
+ deep: true,
107
+ });
108
+ _watch(() => props.variant.state, async () => {
109
+ if (appHooks) {
110
+ for (const hook of appHooks.onUpdate) {
111
+ await hook();
112
+ }
113
+ }
114
+ }, {
115
+ deep: true,
116
+ });
117
+ _onBeforeUnmount(() => {
118
+ unmountVariant();
119
+ });
120
+ return {
121
+ sandbox,
122
+ };
123
+ },
124
+ render() {
125
+ return _h('div', {
126
+ ref: 'sandbox',
127
+ });
128
+ },
129
+ });
@@ -0,0 +1,4 @@
1
+ export { default as MountStory } from './MountStory';
2
+ export { default as RenderStory } from './RenderStory';
3
+ export declare function generateSourceCode(): void;
4
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/node/builtin-plugins/vanilla-support/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAA;AAEtD,wBAAgB,kBAAkB,SAEjC"}
@@ -0,0 +1,5 @@
1
+ export { default as MountStory } from './MountStory';
2
+ export { default as RenderStory } from './RenderStory';
3
+ export function generateSourceCode() {
4
+ // noop
5
+ }
@@ -0,0 +1,3 @@
1
+ import type { ServerRunPayload } from '@poveste/shared';
2
+ export declare function run({ file, storyData }: ServerRunPayload): Promise<void>;
3
+ //# sourceMappingURL=collect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collect.d.ts","sourceRoot":"","sources":["../../../../src/node/builtin-plugins/vanilla-support/collect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAA8B,MAAM,iBAAiB,CAAA;AAGnF,wBAAsB,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,gBAAgB,iBAuC9D"}
@@ -0,0 +1,33 @@
1
+ export async function run({ file, storyData }) {
2
+ const { default: Comp } = await import(/* @vite-ignore */ file.moduleId);
3
+ const options = Comp;
4
+ let rawVariants = [];
5
+ if (options.onMount) {
6
+ // Implicit variant
7
+ rawVariants = [{
8
+ id: '_default',
9
+ title: 'default',
10
+ }];
11
+ }
12
+ else {
13
+ rawVariants = options.variants;
14
+ }
15
+ const story = {
16
+ id: options.id ?? file.id,
17
+ title: options.title ?? file.fileName,
18
+ group: options.group,
19
+ layout: options.layout ?? { type: 'single', iframe: true },
20
+ icon: options.icon,
21
+ iconColor: options.iconColor,
22
+ docsOnly: options.docsOnly ?? false,
23
+ variants: null,
24
+ };
25
+ const variants = rawVariants.map((v, index) => ({
26
+ id: v.id ?? `${story.id}-${index}`,
27
+ title: v.title ?? 'untitled',
28
+ icon: v.icon ?? options.icon,
29
+ iconColor: v.iconColor ?? options.iconColor,
30
+ }));
31
+ story.variants = variants;
32
+ storyData.push(story);
33
+ }
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '@poveste/shared';
2
+ export declare function vanillaSupport(): Plugin;
3
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../src/node/builtin-plugins/vanilla-support/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAM7C,wBAAgB,cAAc,IAAI,MAAM,CA4BvC"}
@@ -0,0 +1,29 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { dirname } from 'pathe';
3
+ const __dirname = dirname(fileURLToPath(import.meta.url));
4
+ export function vanillaSupport() {
5
+ return {
6
+ name: 'builtin:vanilla-support',
7
+ defaultConfig() {
8
+ return {
9
+ supportMatch: [
10
+ {
11
+ id: 'vanilla',
12
+ patterns: ['**/*.js'],
13
+ pluginIds: ['vanilla'],
14
+ },
15
+ ],
16
+ };
17
+ },
18
+ supportPlugin: {
19
+ id: 'vanilla',
20
+ moduleName: __dirname,
21
+ setupFn: 'setupVanilla',
22
+ importStoryComponent: (file, index) => `import Comp${index} from ${JSON.stringify(file.moduleId)}`, // @TODO code-splitting
23
+ },
24
+ // onDev (api) {
25
+ // // Test vanilla story
26
+ // api.addStoryFile(resolve(__dirname, './vanilla.story.js'))
27
+ // },
28
+ };
29
+ }
@@ -0,0 +1,36 @@
1
+ import type { Awaitable, Story, StoryProps, Variant, VariantProps } from '@poveste/shared';
2
+ export interface App {
3
+ el: HTMLElement;
4
+ onMount?: () => void;
5
+ onUpdate?: () => void;
6
+ onUnmount?: () => void;
7
+ }
8
+ export interface MountApi {
9
+ el: HTMLElement;
10
+ state: Record<string, any>;
11
+ onUpdate: (cb: () => unknown) => Awaitable<void>;
12
+ onUnmount: (cb: () => unknown) => Awaitable<void>;
13
+ }
14
+ export interface VanillaApi {
15
+ onMount?: (api: MountApi) => Awaitable<void>;
16
+ onMountControls?: (api: MountApi) => Awaitable<void>;
17
+ }
18
+ interface CommonProps {
19
+ setupApp?: (payload: {
20
+ app: App;
21
+ story: Story;
22
+ variant: Variant;
23
+ }) => unknown;
24
+ }
25
+ export type StoryOptions = Omit<StoryProps, 'setupApp'> & CommonProps & ((VanillaApi & {
26
+ variants?: never;
27
+ }) | {
28
+ variants?: VariantOptions[];
29
+ onMount?: never;
30
+ onMountControls?: never;
31
+ });
32
+ export interface VariantOptions extends Omit<VariantProps, 'setupApp'>, CommonProps, VanillaApi {
33
+ }
34
+ export declare function defineStory(story: StoryOptions): StoryOptions;
35
+ export {};
36
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/node/builtin-plugins/vanilla-support/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE1F,MAAM,WAAW,GAAG;IAClB,EAAE,EAAE,WAAW,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;CACvB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,WAAW,CAAA;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC1B,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,OAAO,KAAK,SAAS,CAAC,IAAI,CAAC,CAAA;IAChD,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,OAAO,KAAK,SAAS,CAAC,IAAI,CAAC,CAAA;CAClD;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,SAAS,CAAC,IAAI,CAAC,CAAA;IAC5C,eAAe,CAAC,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,SAAS,CAAC,IAAI,CAAC,CAAA;CACrD;AAED,UAAU,WAAW;IACnB,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,GAAG,EAAE,GAAG,CAAC;QAAC,KAAK,EAAE,KAAK,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,KAAK,OAAO,CAAA;CAC9E;AAED,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,WAAW,GAAG,CAAC,CAAC,UAAU,GAAG;IACrF,QAAQ,CAAC,EAAE,KAAK,CAAA;CACjB,CAAC,GAAG;IACH,QAAQ,CAAC,EAAE,cAAc,EAAE,CAAA;IAC3B,OAAO,CAAC,EAAE,KAAK,CAAA;IACf,eAAe,CAAC,EAAE,KAAK,CAAA;CACxB,CAAC,CAAA;AAEF,MAAM,WAAW,cAAe,SAAQ,IAAI,CAAC,YAAY,EAAE,UAAU,CAAC,EAAE,WAAW,EAAE,UAAU;CAE9F;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,gBAE9C"}
@@ -0,0 +1,3 @@
1
+ export function defineStory(story) {
2
+ return story;
3
+ }
@@ -0,0 +1,4 @@
1
+ import type { StoryOptions } from './types';
2
+ declare const _default: StoryOptions;
3
+ export default _default;
4
+ //# sourceMappingURL=vanilla.story.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vanilla.story.d.ts","sourceRoot":"","sources":["../../../../src/node/builtin-plugins/vanilla-support/vanilla.story.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;wBA8DtC,YAAY;AA5DjB,wBA4DiB"}
@@ -0,0 +1,55 @@
1
+ export default {
2
+ title: 'Vanilla story',
3
+ icon: 'ion:logo-nodejs',
4
+ variants: [
5
+ {
6
+ title: 'Hello',
7
+ onMount: ({ el, state, onUpdate }) => {
8
+ state.count = 0;
9
+ const div = document.createElement('div');
10
+ div.innerHTML = '<h1>Hello World</h1>';
11
+ el.appendChild(div);
12
+ const counter = document.createElement('pre');
13
+ counter.innerHTML = `Counter: ${state.counter}`;
14
+ div.appendChild(counter);
15
+ onUpdate(() => {
16
+ counter.innerHTML = `Counter: ${state.count}`;
17
+ });
18
+ },
19
+ onMountControls: ({ el, state, onUnmount }) => {
20
+ const add = () => {
21
+ state.count++;
22
+ };
23
+ Object.assign(el.style, {
24
+ padding: '8px',
25
+ });
26
+ const btn = document.createElement('button');
27
+ btn.innerHTML = '+1';
28
+ Object.assign(btn.style, {
29
+ padding: '6px',
30
+ borderRadius: '3px',
31
+ backgroundColor: '#a7f3d0',
32
+ });
33
+ btn.addEventListener('click', add);
34
+ el.appendChild(btn);
35
+ onUnmount(() => {
36
+ btn.removeEventListener('click', add);
37
+ });
38
+ },
39
+ },
40
+ {
41
+ title: 'Meow',
42
+ onMount: ({ el, onUpdate, onUnmount }) => {
43
+ const div = document.createElement('div');
44
+ div.innerHTML = '<h1>Meow</h1>';
45
+ el.appendChild(div);
46
+ onUpdate(() => {
47
+ console.log('update');
48
+ });
49
+ onUnmount(() => {
50
+ el.removeChild(div);
51
+ });
52
+ },
53
+ },
54
+ ],
55
+ };
@@ -0,0 +1,14 @@
1
+ import type { ServerStoryFile } from '@poveste/shared';
2
+ import type { ViteDevServer } from 'vite';
3
+ import type { Context } from '../context.js';
4
+ export interface UseCollectStoriesOptions {
5
+ server: ViteDevServer;
6
+ mainServer?: ViteDevServer;
7
+ throws?: boolean;
8
+ }
9
+ export declare function useCollectStories(options: UseCollectStoriesOptions, ctx: Context): {
10
+ clearCache: () => void;
11
+ executeStoryFile: (storyFile: ServerStoryFile) => Promise<void>;
12
+ destroy: () => Promise<void>;
13
+ };
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/node/collect/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAEzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAa5C,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,aAAa,CAAA;IACrB,UAAU,CAAC,EAAE,aAAa,CAAA;IAC1B,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,EAAE,GAAG,EAAE,OAAO;;kCA0EpC,eAAe;;EA+D3D"}
@@ -0,0 +1,129 @@
1
+ import { cpus } from 'node:os';
2
+ import { MessageChannel } from 'node:worker_threads';
3
+ import Tinypool from '@akryum/tinypool';
4
+ import { createBirpc } from 'birpc';
5
+ import path, { relative } from 'pathe';
6
+ import pc from 'picocolors';
7
+ import { ViteNodeServer } from 'vite-node/server';
8
+ import { TEMP_PATH } from '../alias.js';
9
+ import { createPath } from '../tree.js';
10
+ import { slash } from '../util/fs.js';
11
+ export function useCollectStories(options, ctx) {
12
+ const { server, mainServer } = options;
13
+ const node = new ViteNodeServer(server, {
14
+ deps: {
15
+ inline: [
16
+ /histoire\/dist/,
17
+ /histoire\/client/,
18
+ /@histoire\/[\w-]+\/dist/,
19
+ /histoire-[\w-]+\/dist/,
20
+ /@vue\/devtools-api/,
21
+ /vuetify/,
22
+ // @TODO temporary fix for https://github.com/histoire-dev/histoire/issues/409
23
+ /vite\w*\/dist\/client\/(client|env).mjs/,
24
+ ...ctx.config.viteNodeInlineDeps ?? [],
25
+ new RegExp(path.resolve(TEMP_PATH, 'plugins')),
26
+ ],
27
+ fallbackCJS: true,
28
+ },
29
+ transformMode: ctx.config.viteNodeTransformMode,
30
+ });
31
+ const maxThreads = ctx.config.collectMaxThreads ?? cpus().length;
32
+ const threadsCount = ctx.mode === 'dev'
33
+ ? Math.max(Math.min(maxThreads, Math.floor(cpus().length / 2)), 1)
34
+ : Math.max(Math.min(maxThreads, cpus().length - 1), 1);
35
+ console.log(pc.blue(`Using ${threadsCount} thread${threadsCount === 1 ? '' : 's'} for story collection`));
36
+ const threadPool = new Tinypool({
37
+ filename: new URL('./worker.js', import.meta.url).href,
38
+ // WebContainer compatibility (Stackblitz)
39
+ useAtomics: typeof process.versions.webcontainer !== 'string',
40
+ minThreads: threadsCount,
41
+ maxThreads: threadsCount,
42
+ });
43
+ function clearCache() {
44
+ server.moduleGraph.invalidateAll();
45
+ node.fetchCache.clear();
46
+ }
47
+ function createChannel() {
48
+ const channel = new MessageChannel();
49
+ const port = channel.port2;
50
+ const workerPort = channel.port1;
51
+ createBirpc({
52
+ fetchModule: id => node.fetchModule(id),
53
+ resolveId: (id, importer) => node.resolveId(id, importer),
54
+ }, {
55
+ post: data => port.postMessage(data),
56
+ on: data => port.on('message', data),
57
+ });
58
+ return {
59
+ port,
60
+ workerPort,
61
+ };
62
+ }
63
+ if (mainServer) {
64
+ mainServer.watcher.on('change', (file) => {
65
+ file = slash(file);
66
+ threadPool.broadcastMessage({
67
+ kind: 'hst:invalidate',
68
+ file,
69
+ });
70
+ });
71
+ }
72
+ async function executeStoryFile(storyFile) {
73
+ try {
74
+ const { workerPort } = createChannel();
75
+ const payload = {
76
+ root: server.config.root,
77
+ base: server.config.base,
78
+ storyFile,
79
+ port: workerPort,
80
+ };
81
+ const { storyData } = await threadPool.run(payload, {
82
+ transferList: [
83
+ workerPort,
84
+ ],
85
+ });
86
+ if (storyData.length === 0) {
87
+ console.warn(pc.yellow(`⚠️ No story found for ${storyFile.path}`));
88
+ return;
89
+ }
90
+ else if (storyData.length > 1) {
91
+ console.warn(pc.yellow(`⚠️ Multiple stories not supported: ${storyFile.path}`));
92
+ }
93
+ const finalData = storyData[0];
94
+ // Default props
95
+ if (ctx.config.defaultStoryProps) {
96
+ for (const key in ctx.config.defaultStoryProps) {
97
+ if (finalData[key] == null) {
98
+ finalData[key] = ctx.config.defaultStoryProps[key];
99
+ }
100
+ }
101
+ }
102
+ if (!finalData.layout) {
103
+ finalData.layout = { type: 'single', iframe: true };
104
+ }
105
+ storyFile.id = finalData.id;
106
+ storyFile.story = finalData;
107
+ storyFile.treeFile = {
108
+ title: finalData.title,
109
+ path: relative(server.config.root, storyFile.path),
110
+ };
111
+ storyFile.treePath = createPath(ctx.config, storyFile.treeFile);
112
+ storyFile.story.title = storyFile.treePath[storyFile.treePath.length - 1];
113
+ }
114
+ catch (e) {
115
+ console.error(pc.red(`Error while collecting story ${storyFile.path}:\n${e.frame ? `${pc.bold(e.message)}\n${e.frame}` : e.stack}`));
116
+ if (options.throws) {
117
+ throw e;
118
+ }
119
+ }
120
+ }
121
+ async function destroy() {
122
+ await threadPool.destroy();
123
+ }
124
+ return {
125
+ clearCache,
126
+ executeStoryFile,
127
+ destroy,
128
+ };
129
+ }
@@ -0,0 +1,3 @@
1
+ import type { ServerRunPayload } from '@poveste/shared';
2
+ export declare function run(payload: ServerRunPayload): Promise<any>;
3
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../../src/node/collect/run.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIvD,wBAAsB,GAAG,CAAC,OAAO,EAAE,gBAAgB,gBAIlD"}
@@ -0,0 +1,7 @@
1
+ // @ts-expect-error virtual module
2
+ import { collectSupportPlugins } from 'virtual:$histoire-support-plugins-collect';
3
+ export async function run(payload) {
4
+ const { run } = await collectSupportPlugins[payload.file.supportPluginId]();
5
+ const result = await run(payload);
6
+ return result;
7
+ }
@@ -0,0 +1,14 @@
1
+ import type { ServerStory, ServerStoryFile } from '@poveste/shared';
2
+ import type { MessagePort } from 'node:worker_threads';
3
+ export interface Payload {
4
+ root: string;
5
+ base: string;
6
+ port: MessagePort;
7
+ storyFile: ServerStoryFile;
8
+ }
9
+ export interface ReturnData {
10
+ storyData: ServerStory[];
11
+ }
12
+ declare const _default: (payload: Payload) => Promise<ReturnData>;
13
+ export default _default;
14
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/node/collect/worker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAoB,WAAW,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACrF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAatD,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,CAAA;IACjB,SAAS,EAAE,eAAe,CAAA;CAC3B;AAED,MAAM,WAAW,UAAU;IACzB,SAAS,EAAE,WAAW,EAAE,CAAA;CACzB;kCAgB8B,OAAO,KAAG,OAAO,CAAC,UAAU,CAAC;AAA5D,wBAyDC"}
@@ -0,0 +1,64 @@
1
+ import { performance } from 'node:perf_hooks';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { parentPort } from 'node:worker_threads';
4
+ import { createBirpc } from 'birpc';
5
+ import { dirname, resolve } from 'pathe';
6
+ import pc from 'picocolors';
7
+ import { ModuleCacheMap, ViteNodeRunner } from 'vite-node/client';
8
+ import { createDomEnv } from '../dom/env.js';
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
10
+ const _moduleCache = new ModuleCacheMap();
11
+ let _runner;
12
+ let _rpc;
13
+ // Cleanup module cache
14
+ parentPort.on('message', (message) => {
15
+ if (message?.kind === 'hst:invalidate') {
16
+ _moduleCache.delete(message.file);
17
+ }
18
+ });
19
+ export default async (payload) => {
20
+ const startTime = performance.now();
21
+ process.env.HST_COLLECT = 'true';
22
+ _rpc = createBirpc({}, {
23
+ post: data => payload.port.postMessage(data),
24
+ on: data => payload.port.on('message', data),
25
+ });
26
+ const runner = _runner ?? (_runner = new ViteNodeRunner({
27
+ root: payload.root,
28
+ base: payload.base,
29
+ moduleCache: _moduleCache,
30
+ fetchModule(id) {
31
+ return _rpc.fetchModule(id);
32
+ },
33
+ resolveId(id, importer) {
34
+ return _rpc.resolveId(id, importer);
35
+ },
36
+ }));
37
+ const { destroy: destroyDomEnv } = createDomEnv();
38
+ const el = window.document.createElement('div');
39
+ const beforeExecuteTime = performance.now();
40
+ // Mount app to collect stories/variants
41
+ const { run } = (await runner.executeFile(resolve(__dirname, './run.js')));
42
+ const afterExecuteTime = performance.now();
43
+ const storyData = [];
44
+ await run({
45
+ file: payload.storyFile,
46
+ storyData,
47
+ el,
48
+ });
49
+ const afterRunTime = performance.now();
50
+ if (payload.storyFile.markdownFile) {
51
+ const el = document.createElement('div');
52
+ el.innerHTML = payload.storyFile.markdownFile.html;
53
+ const text = el.textContent;
54
+ storyData.forEach((s) => {
55
+ s.docsText = text;
56
+ });
57
+ }
58
+ destroyDomEnv();
59
+ const endTime = performance.now();
60
+ console.log(pc.dim(`${payload.storyFile.relativePath} ${Math.round(endTime - startTime)}ms (setup:${Math.round(beforeExecuteTime - startTime)}ms, execute:${Math.round(afterExecuteTime - beforeExecuteTime)}ms, run:${Math.round(afterRunTime - afterExecuteTime)}ms)`));
61
+ return {
62
+ storyData,
63
+ };
64
+ };