histoire 0.0.0 → 0.0.1

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 (208) hide show
  1. package/LICENSE +21 -0
  2. package/client.d.ts +2 -0
  3. package/dist/client/app/App.vue +84 -21
  4. package/dist/client/app/assets/histoire-text-dark.svg +89 -0
  5. package/dist/client/app/assets/histoire-text.svg +89 -0
  6. package/dist/client/app/assets/histoire.svg +51 -0
  7. package/dist/client/app/codegen/serialize-js.d.ts +1 -0
  8. package/dist/client/app/codegen/serialize-js.js +114 -0
  9. package/dist/client/app/codegen/serialize-js.js.map +1 -0
  10. package/dist/client/app/codegen/serialize-js.ts +119 -0
  11. package/dist/client/app/codegen/util.d.ts +10 -0
  12. package/dist/client/app/codegen/util.js +71 -0
  13. package/dist/client/app/codegen/util.js.map +1 -0
  14. package/dist/client/app/codegen/util.ts +79 -0
  15. package/dist/client/app/codegen/vue3.d.ts +2 -0
  16. package/dist/client/app/codegen/vue3.js +239 -0
  17. package/dist/client/app/codegen/vue3.js.map +1 -0
  18. package/dist/client/app/codegen/vue3.ts +240 -0
  19. package/dist/client/app/components/HomeView.vue +15 -1
  20. package/dist/client/app/components/StoryControls.vue +7 -2
  21. package/dist/client/app/components/StoryList.vue +20 -13
  22. package/dist/client/app/components/StoryListFolder.vue +80 -0
  23. package/dist/client/app/components/StoryListItem.vue +38 -12
  24. package/dist/client/app/components/StorySourceCode.vue +121 -0
  25. package/dist/client/app/components/StoryVariantGridItem.vue +32 -17
  26. package/dist/client/app/components/StoryVariantListItem.vue +46 -0
  27. package/dist/client/app/components/StoryVariantSingleView.vue +117 -15
  28. package/dist/client/app/components/StoryView.vue +88 -54
  29. package/dist/client/app/components/app/AppHeader.vue +56 -0
  30. package/dist/client/app/components/app/AppLogo.vue +24 -0
  31. package/dist/client/app/components/base/BaseEmpty.vue +1 -1
  32. package/dist/client/app/components/base/BaseListItemLink.vue +55 -0
  33. package/dist/client/app/components/base/BaseSplitPane.vue +57 -21
  34. package/dist/client/app/components/exposed/Story.vue +23 -58
  35. package/dist/client/app/components/exposed/Variant.vue +24 -47
  36. package/dist/client/app/components/misc/HatchedPattern.vue +25 -0
  37. package/dist/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  38. package/dist/client/app/components/search/SearchItem.vue +110 -0
  39. package/dist/client/app/components/search/SearchModal.vue +179 -0
  40. package/dist/client/app/composable/variant.ts +20 -0
  41. package/dist/client/app/global-components.ts +10 -0
  42. package/dist/client/app/index.d.ts +1 -0
  43. package/dist/client/app/index.js +4 -1
  44. package/dist/client/app/index.js.map +1 -1
  45. package/dist/client/app/index.ts +18 -0
  46. package/dist/client/app/router.ts +17 -0
  47. package/dist/client/app/sandbox.d.ts +1 -0
  48. package/dist/client/app/sandbox.js +54 -0
  49. package/dist/client/app/sandbox.js.map +1 -0
  50. package/dist/client/app/sandbox.ts +60 -0
  51. package/dist/client/app/stores/story.d.ts +161 -50
  52. package/dist/client/app/stores/story.js +5 -16
  53. package/dist/client/app/stores/story.js.map +1 -1
  54. package/dist/client/app/stores/story.ts +22 -0
  55. package/dist/client/app/style/main.css +16 -2
  56. package/dist/client/app/style/sandbox.css +14 -0
  57. package/dist/client/app/types.d.ts +36 -4
  58. package/dist/client/app/types.ts +45 -0
  59. package/dist/client/app/util/config.d.ts +3 -0
  60. package/dist/client/app/util/config.js +5 -0
  61. package/dist/client/app/util/config.js.map +1 -0
  62. package/dist/client/app/util/config.ts +6 -0
  63. package/dist/client/app/util/const.d.ts +1 -0
  64. package/dist/client/app/util/const.js +2 -0
  65. package/dist/client/app/util/const.js.map +1 -0
  66. package/dist/client/app/util/const.ts +1 -0
  67. package/dist/client/app/util/dark.d.ts +2 -0
  68. package/dist/client/app/util/dark.js +4 -0
  69. package/dist/client/app/util/dark.js.map +1 -0
  70. package/dist/client/app/util/dark.ts +4 -0
  71. package/dist/client/app/util/env.d.ts +1 -0
  72. package/dist/client/app/util/env.js +2 -0
  73. package/dist/client/app/util/env.js.map +1 -0
  74. package/dist/client/app/util/keyboard.d.ts +8 -0
  75. package/dist/client/app/util/keyboard.js +83 -0
  76. package/dist/client/app/util/keyboard.js.map +1 -0
  77. package/dist/client/app/util/mapping.d.ts +3 -0
  78. package/dist/client/app/util/mapping.js +37 -0
  79. package/dist/client/app/util/mapping.js.map +1 -0
  80. package/dist/client/app/util/mapping.ts +38 -0
  81. package/dist/client/app/util/tooltip.d.ts +6 -0
  82. package/dist/client/app/util/tooltip.js +12 -0
  83. package/dist/client/app/util/tooltip.js.map +1 -0
  84. package/dist/client/index.d.ts +8 -0
  85. package/dist/client/index.js +4 -0
  86. package/dist/client/index.js.map +1 -0
  87. package/dist/client/index.ts +12 -0
  88. package/dist/client/server/Story.server.vue +65 -0
  89. package/dist/client/server/Variant.server.vue +50 -0
  90. package/dist/client/server/index.d.ts +2 -0
  91. package/dist/client/server/index.js +26 -0
  92. package/dist/client/server/index.js.map +1 -0
  93. package/dist/client/server/index.ts +29 -0
  94. package/dist/client/shim.d.ts +5 -0
  95. package/dist/node/bin.js +8 -2
  96. package/dist/node/bin.js.map +1 -1
  97. package/dist/node/build.d.ts +2 -0
  98. package/dist/node/build.js +72 -0
  99. package/dist/node/build.js.map +1 -0
  100. package/dist/node/collect.d.ts +12 -0
  101. package/dist/node/collect.js +66 -0
  102. package/dist/node/collect.js.map +1 -0
  103. package/dist/node/colors.d.ts +274 -0
  104. package/dist/node/colors.js +313 -0
  105. package/dist/node/colors.js.map +1 -0
  106. package/dist/node/commands/build.d.ts +1 -0
  107. package/dist/node/commands/build.js +11 -0
  108. package/dist/node/commands/build.js.map +1 -0
  109. package/dist/node/commands/dev.d.ts +1 -1
  110. package/dist/node/commands/dev.js +6 -11
  111. package/dist/node/commands/dev.js.map +1 -1
  112. package/dist/node/config.d.ts +99 -1
  113. package/dist/node/config.js +90 -1
  114. package/dist/node/config.js.map +1 -1
  115. package/dist/node/context.d.ts +13 -0
  116. package/dist/node/context.js +12 -1
  117. package/dist/node/context.js.map +1 -1
  118. package/dist/node/dom/dom-keys.d.ts +4 -0
  119. package/dist/node/dom/dom-keys.js +224 -0
  120. package/dist/node/dom/dom-keys.js.map +1 -0
  121. package/dist/node/dom/env.d.ts +5 -0
  122. package/dist/node/dom/env.js +23 -0
  123. package/dist/node/dom/env.js.map +1 -0
  124. package/dist/node/index.d.ts +2 -0
  125. package/dist/node/index.js +2 -1
  126. package/dist/node/index.js.map +1 -1
  127. package/dist/node/plugin.d.ts +8 -2
  128. package/dist/node/plugin.js +142 -21
  129. package/dist/node/plugin.js.map +1 -1
  130. package/dist/node/server.d.ts +4 -1
  131. package/dist/node/server.js +80 -20
  132. package/dist/node/server.js.map +1 -1
  133. package/dist/node/stories.d.ts +8 -9
  134. package/dist/node/stories.js +42 -22
  135. package/dist/node/stories.js.map +1 -1
  136. package/dist/node/tree.d.ts +19 -0
  137. package/dist/node/tree.js +55 -0
  138. package/dist/node/tree.js.map +1 -0
  139. package/dist/node/types.d.ts +38 -0
  140. package/dist/node/types.js +2 -0
  141. package/dist/node/types.js.map +1 -0
  142. package/dist/style.css +558 -52
  143. package/package.json +42 -25
  144. package/scripts/copy.mjs +11 -0
  145. package/src/client/app/App.vue +84 -21
  146. package/src/client/app/assets/histoire-text-dark.svg +89 -0
  147. package/src/client/app/assets/histoire-text.svg +89 -0
  148. package/src/client/app/assets/histoire.svg +51 -0
  149. package/src/client/app/codegen/serialize-js.ts +119 -0
  150. package/src/client/app/codegen/util.ts +79 -0
  151. package/src/client/app/codegen/vue3.ts +240 -0
  152. package/src/client/app/components/HomeView.vue +15 -1
  153. package/src/client/app/components/StoryControls.vue +7 -2
  154. package/src/client/app/components/StoryList.vue +20 -13
  155. package/src/client/app/components/StoryListFolder.vue +80 -0
  156. package/src/client/app/components/StoryListItem.vue +38 -12
  157. package/src/client/app/components/StorySourceCode.vue +121 -0
  158. package/src/client/app/components/StoryVariantGridItem.vue +32 -17
  159. package/src/client/app/components/StoryVariantListItem.vue +46 -0
  160. package/src/client/app/components/StoryVariantSingleView.vue +117 -15
  161. package/src/client/app/components/StoryView.vue +88 -54
  162. package/src/client/app/components/app/AppHeader.vue +56 -0
  163. package/src/client/app/components/app/AppLogo.vue +24 -0
  164. package/src/client/app/components/base/BaseEmpty.vue +1 -1
  165. package/src/client/app/components/base/BaseListItemLink.vue +55 -0
  166. package/src/client/app/components/base/BaseSplitPane.vue +57 -21
  167. package/src/client/app/components/exposed/Story.vue +23 -58
  168. package/src/client/app/components/exposed/Variant.vue +24 -47
  169. package/src/client/app/components/misc/HatchedPattern.vue +25 -0
  170. package/src/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  171. package/src/client/app/components/search/SearchItem.vue +110 -0
  172. package/src/client/app/components/search/SearchModal.vue +179 -0
  173. package/src/client/app/index.ts +4 -1
  174. package/src/client/app/sandbox.ts +60 -0
  175. package/src/client/app/stores/story.ts +6 -18
  176. package/src/client/app/style/main.css +16 -2
  177. package/src/client/app/style/sandbox.css +14 -0
  178. package/src/client/app/types.ts +42 -4
  179. package/src/client/app/util/config.ts +6 -0
  180. package/src/client/app/util/const.ts +1 -0
  181. package/src/client/app/util/dark.ts +4 -0
  182. package/src/client/app/util/env.ts +1 -0
  183. package/src/client/app/util/keyboard.ts +99 -0
  184. package/src/client/app/util/mapping.ts +38 -0
  185. package/src/client/app/util/tooltip.ts +13 -0
  186. package/src/client/index.ts +12 -0
  187. package/src/client/server/Story.server.vue +65 -0
  188. package/src/client/server/Variant.server.vue +50 -0
  189. package/src/client/server/index.ts +29 -0
  190. package/src/node/bin.ts +9 -2
  191. package/src/node/build.ts +80 -0
  192. package/src/node/collect.ts +78 -0
  193. package/src/node/colors.ts +328 -0
  194. package/src/node/commands/build.ts +12 -0
  195. package/src/node/commands/dev.ts +6 -13
  196. package/src/node/config.ts +193 -1
  197. package/src/node/context.ts +21 -1
  198. package/src/node/dom/dom-keys.ts +227 -0
  199. package/src/node/dom/env.ts +26 -0
  200. package/src/node/index.ts +2 -0
  201. package/src/node/plugin.ts +146 -22
  202. package/src/node/server.ts +95 -20
  203. package/src/node/stories.ts +53 -31
  204. package/src/node/tree.ts +88 -0
  205. package/src/node/types.ts +40 -0
  206. package/tailwind.config.cjs +41 -1
  207. package/dist/client/app/components/StoryVariantItem.vue +0 -29
  208. package/src/client/app/components/StoryVariantItem.vue +0 -29
@@ -0,0 +1,83 @@
1
+ import { useEventListener } from '@vueuse/core';
2
+ import { isRef } from 'vue';
3
+ import { isMac } from './env.js';
4
+ export function onKeyboardShortcut(shortcut, handler, options = {}) {
5
+ useEventListener(options.event ?? 'keydown', event => {
6
+ if (isMatchingShortcut(isRef(shortcut) ? shortcut.value : shortcut)) {
7
+ handler(event);
8
+ }
9
+ });
10
+ }
11
+ const modifiers = {
12
+ ctrl: { key: 'Control', pressed: false },
13
+ alt: { key: 'Alt', pressed: false },
14
+ shift: { key: 'Shift', pressed: false },
15
+ meta: { key: 'Meta', pressed: false },
16
+ };
17
+ const pressedKeys = new Set();
18
+ window.addEventListener('keydown', event => {
19
+ for (const i in modifiers) {
20
+ const mod = modifiers[i];
21
+ if (mod.key === event.key) {
22
+ mod.pressed = true;
23
+ return;
24
+ }
25
+ }
26
+ pressedKeys.add(event.key.toLocaleLowerCase());
27
+ });
28
+ window.addEventListener('keyup', event => {
29
+ requestAnimationFrame(() => {
30
+ pressedKeys.clear();
31
+ for (const i in modifiers) {
32
+ const mod = modifiers[i];
33
+ if (mod.key === event.key) {
34
+ mod.pressed = false;
35
+ break;
36
+ }
37
+ }
38
+ });
39
+ });
40
+ window.addEventListener('blur', () => {
41
+ pressedKeys.clear();
42
+ for (const i in modifiers) {
43
+ const mod = modifiers[i];
44
+ mod.pressed = false;
45
+ }
46
+ });
47
+ function isMatchingShortcut(shortcut) {
48
+ for (const combination of shortcut) {
49
+ if (isMatchingCombination(combination.toLowerCase())) {
50
+ return true;
51
+ }
52
+ }
53
+ return false;
54
+ }
55
+ function isMatchingCombination(combination) {
56
+ const splitted = combination.split('+').map(key => key.trim());
57
+ const targetKey = splitted.pop();
58
+ for (const mod in modifiers) {
59
+ const containsMod = splitted.includes(mod);
60
+ const isPressed = modifiers[mod].pressed;
61
+ if (containsMod !== isPressed) {
62
+ return false;
63
+ }
64
+ }
65
+ return pressedKeys.has(targetKey);
66
+ }
67
+ export function formatKey(key) {
68
+ key = key.toLowerCase();
69
+ if (key === 'ctrl') {
70
+ return isMac ? '^' : 'Ctrl';
71
+ }
72
+ if (key === 'alt') {
73
+ return isMac ? '⎇' : 'Alt';
74
+ }
75
+ if (key === 'shift') {
76
+ return '⇧';
77
+ }
78
+ if (key === 'meta') {
79
+ return '⌘';
80
+ }
81
+ return key.charAt(0).toUpperCase() + key.substring(1).toLowerCase();
82
+ }
83
+ //# sourceMappingURL=keyboard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyboard.js","sourceRoot":"","sources":["../../../../src/client/app/util/keyboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,KAAK,EAAO,MAAM,KAAK,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAUhC,MAAM,UAAU,kBAAkB,CAAE,QAAkD,EAAE,OAAwB,EAAE,UAAmC,EAAE;IACrJ,gBAAgB,CAAC,OAAO,CAAC,KAAK,IAAI,SAAS,EAAE,KAAK,CAAC,EAAE;QACnD,IAAI,kBAAkB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE;YACnE,OAAO,CAAC,KAAK,CAAC,CAAA;SACf;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,SAAS,GAAuD;IACpE,IAAI,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE;IACxC,GAAG,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,OA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IACD,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;AACrE,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { StoryFile, Variant } from '../types';
2
+ export declare function mapFile(file: StoryFile, existingFile?: StoryFile): StoryFile;
3
+ export declare function mapVariant(variant: Variant): Variant;
@@ -0,0 +1,37 @@
1
+ import { markRaw } from 'vue';
2
+ export function mapFile(file, existingFile) {
3
+ const result = {
4
+ ...file,
5
+ component: markRaw(file.component),
6
+ story: {
7
+ ...file.story,
8
+ title: file.story.title,
9
+ file: markRaw(file),
10
+ variants: file.story.variants.map(v => mapVariant(v)),
11
+ },
12
+ };
13
+ if (existingFile) {
14
+ for (const index in result.story.variants) {
15
+ const variant = result.story.variants[index];
16
+ const existingVariant = existingFile.story.variants[index];
17
+ if (existingVariant) {
18
+ if (existingVariant.state)
19
+ Object.assign(variant.state, existingVariant.state);
20
+ if (existingVariant.initState)
21
+ variant.initState = existingVariant.initState;
22
+ if (existingVariant.slots)
23
+ variant.slots = existingVariant.slots;
24
+ }
25
+ }
26
+ }
27
+ return result;
28
+ }
29
+ export function mapVariant(variant) {
30
+ return {
31
+ ...variant,
32
+ state: {},
33
+ initState: null,
34
+ slots: () => ({}),
35
+ };
36
+ }
37
+ //# sourceMappingURL=mapping.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapping.js","sourceRoot":"","sources":["../../../../src/client/app/util/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,CAAA;AAG7B,MAAM,UAAU,OAAO,CAAE,IAAe,EAAE,YAAwB;IAChE,MAAM,MAAM,GAAc;QACxB,GAAG,IAAI;QACP,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;QAClC,KAAK,EAAE;YACL,GAAG,IAAI,CAAC,KAAK;YACb,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK;YACvB,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC;YACnB,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;SACtD;KACF,CAAA;IAED,IAAI,YAAY,EAAE;QAChB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE;YACzC,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;YAC5C,MAAM,eAAe,GAAG,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;YAC1D,IAAI,eAAe,EAAE;gBACnB,IAAI,eAAe,CAAC,KAAK;oBAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,eAAe,CAAC,KAAK,CAAC,CAAA;gBAC9E,IAAI,eAAe,CAAC,SAAS;oBAAE,OAAO,CAAC,SAAS,GAAG,eAAe,CAAC,SAAS,CAAA;gBAC5E,IAAI,eAAe,CAAC,KAAK;oBAAE,OAAO,CAAC,KAAK,GAAG,eAAe,CAAC,KAAK,CAAA;aACjE;SACF;KACF;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,UAAU,UAAU,CAAE,OAAgB;IAC1C,OAAO;QACL,GAAG,OAAO;QACV,KAAK,EAAE,EAAE;QACT,SAAS,EAAE,IAAI;QACf,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;KAClB,CAAA;AACH,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { markRaw } from 'vue'
2
+ import type { StoryFile, Variant } from '../types'
3
+
4
+ export function mapFile (file: StoryFile, existingFile?: StoryFile): StoryFile {
5
+ const result: StoryFile = {
6
+ ...file,
7
+ component: markRaw(file.component),
8
+ story: {
9
+ ...file.story,
10
+ title: file.story.title,
11
+ file: markRaw(file),
12
+ variants: file.story.variants.map(v => mapVariant(v)),
13
+ },
14
+ }
15
+
16
+ if (existingFile) {
17
+ for (const index in result.story.variants) {
18
+ const variant = result.story.variants[index]
19
+ const existingVariant = existingFile.story.variants[index]
20
+ if (existingVariant) {
21
+ if (existingVariant.state) Object.assign(variant.state, existingVariant.state)
22
+ if (existingVariant.initState) variant.initState = existingVariant.initState
23
+ if (existingVariant.slots) variant.slots = existingVariant.slots
24
+ }
25
+ }
26
+ }
27
+
28
+ return result
29
+ }
30
+
31
+ export function mapVariant (variant: Variant): Variant {
32
+ return {
33
+ ...variant,
34
+ state: {},
35
+ initState: null,
36
+ slots: () => ({}),
37
+ }
38
+ }
@@ -0,0 +1,6 @@
1
+ export declare function makeTooltip(descriptionHtml: string, keyboardShortcut: ({ isMac: boolean }: {
2
+ isMac: any;
3
+ }) => string): {
4
+ content: string;
5
+ html: boolean;
6
+ };
@@ -0,0 +1,12 @@
1
+ import { isMac } from './env.js';
2
+ import { formatKey } from './keyboard.js';
3
+ export function makeTooltip(descriptionHtml, keyboardShortcut) {
4
+ return {
5
+ content: `<div>${descriptionHtml}</div><div class="htw-flex htw-items-center htw-gap-1 htw-mt-2 htw-text-sm">${genKeyboardShortcutHtml(keyboardShortcut({ isMac }))}</div>`,
6
+ html: true,
7
+ };
8
+ }
9
+ function genKeyboardShortcutHtml(shortcut) {
10
+ return shortcut.split('+').map(k => k.trim()).map(key => `<span class="htw-bg-gray-500 htw-border-b-2 htw-border-gray-600 htw-px-1 htw-rounded-sm">${formatKey(key)}</span>`).join('');
11
+ }
12
+ //# sourceMappingURL=tooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tooltip.js","sourceRoot":"","sources":["../../../../src/client/app/util/tooltip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AAEzC,MAAM,UAAU,WAAW,CAAE,eAAuB,EAAE,gBAAgD;IACpG,OAAO;QACL,OAAO,EAAE,QAAQ,eAAe,+EAA+E,uBAAuB,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,QAAQ;QAC3K,IAAI,EAAE,IAAI;KACX,CAAA;AACH,CAAC;AAED,SAAS,uBAAuB,CAAE,QAAgB;IAChD,OAAO,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,4FAA4F,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACxL,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { App } from 'vue';
2
+ import type { Story, Variant } from './app/types.js';
3
+ export declare type Vue3StorySetupHandler = (payload: {
4
+ app: App;
5
+ story: Story;
6
+ variant: Variant;
7
+ }) => Promise<void> | void;
8
+ export declare function defineVue3StorySetup(handler: Vue3StorySetupHandler): Vue3StorySetupHandler;
@@ -0,0 +1,4 @@
1
+ export function defineVue3StorySetup(handler) {
2
+ return handler;
3
+ }
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AASA,MAAM,UAAU,oBAAoB,CAAE,OAA8B;IAClE,OAAO,OAAO,CAAA;AAChB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { App } from 'vue'
2
+ import type { Story, Variant } from './app/types.js'
3
+
4
+ export type Vue3StorySetupHandler = (payload: {
5
+ app: App
6
+ story: Story
7
+ variant: Variant
8
+ }) => Promise<void> | void
9
+
10
+ export function defineVue3StorySetup (handler: Vue3StorySetupHandler): Vue3StorySetupHandler {
11
+ return handler
12
+ }
@@ -0,0 +1,65 @@
1
+ <script lang="ts">
2
+ import { defineComponent, inject, PropType, provide, useAttrs } from 'vue'
3
+ import type { StoryFile, Story, Variant } from '../../node/types'
4
+
5
+ export default defineComponent({
6
+ inheritAttrs: false,
7
+
8
+ props: {
9
+ title: {
10
+ type: String,
11
+ required: true,
12
+ },
13
+
14
+ layout: {
15
+ type: Object as PropType<Story['layout']>,
16
+ default: () => ({ type: 'single' }),
17
+ },
18
+
19
+ icon: {
20
+ type: String,
21
+ default: null,
22
+ },
23
+
24
+ iconColor: {
25
+ type: String,
26
+ default: null,
27
+ },
28
+ },
29
+
30
+ setup (props) {
31
+ const attrs = useAttrs() as {
32
+ data: StoryFile
33
+ }
34
+
35
+ // Story
36
+
37
+ const story: Story = {
38
+ id: attrs.data.id,
39
+ title: props.title,
40
+ layout: props.layout,
41
+ icon: props.icon,
42
+ iconColor: props.iconColor,
43
+ variants: [],
44
+ }
45
+ const addStory = inject('addStory', null)
46
+ addStory?.(story)
47
+
48
+ // Variants
49
+
50
+ provide('story', story)
51
+
52
+ provide('addVariant', (variant: Variant) => {
53
+ story.variants.push(variant)
54
+ })
55
+
56
+ return {
57
+ story,
58
+ }
59
+ },
60
+
61
+ render () {
62
+ return this.$slots.default()
63
+ },
64
+ })
65
+ </script>
@@ -0,0 +1,50 @@
1
+ <script lang="ts">
2
+ import { defineComponent, inject } from 'vue'
3
+ import type { Story, Variant } from '../../node/types'
4
+
5
+ export default defineComponent({
6
+ props: {
7
+ title: {
8
+ type: String,
9
+ default: 'untitled',
10
+ },
11
+
12
+ id: {
13
+ type: String,
14
+ default: null,
15
+ },
16
+
17
+ icon: {
18
+ type: String,
19
+ default: null,
20
+ },
21
+
22
+ iconColor: {
23
+ type: String,
24
+ default: null,
25
+ },
26
+ },
27
+
28
+ setup (props) {
29
+ const story = inject<Story>('story')
30
+
31
+ function generateId () {
32
+ return `${story.id}-${story.variants.length}`
33
+ }
34
+
35
+ const variant: Variant = {
36
+ id: props.id ?? generateId(),
37
+ title: props.title,
38
+ icon: props.icon,
39
+ iconColor: props.iconColor,
40
+ }
41
+
42
+ const addVariant = inject('addVariant') as (variant: Variant) => void
43
+ addVariant(variant)
44
+ },
45
+
46
+ render () {
47
+ return null
48
+ },
49
+ })
50
+ </script>
@@ -0,0 +1,2 @@
1
+ import type { StoryFile } from '../../node/types';
2
+ export declare function run(file: StoryFile, storyData: any, el: any): Promise<void>;
@@ -0,0 +1,26 @@
1
+ import { createApp, h } from 'vue';
2
+ import Story from './Story.server.vue';
3
+ import Variant from './Variant.server.vue';
4
+ export async function run(file, storyData, el) {
5
+ const { default: Comp } = await import(file.moduleId);
6
+ const app = createApp({
7
+ provide: {
8
+ addStory(data) {
9
+ storyData.push(data);
10
+ },
11
+ },
12
+ render() {
13
+ return h(Comp, {
14
+ ref: 'comp',
15
+ data: file,
16
+ });
17
+ },
18
+ });
19
+ // eslint-disable-next-line vue/multi-word-component-names
20
+ app.component('Story', Story);
21
+ // eslint-disable-next-line vue/multi-word-component-names
22
+ app.component('Variant', Variant);
23
+ app.mount(el);
24
+ app.unmount();
25
+ }
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAElC,OAAO,KAAK,MAAM,oBAAoB,CAAA;AACtC,OAAO,OAAO,MAAM,sBAAsB,CAAA;AAE1C,MAAM,CAAC,KAAK,UAAU,GAAG,CAAE,IAAe,EAAE,SAAS,EAAE,EAAE;IACvD,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IACrD,MAAM,GAAG,GAAG,SAAS,CAAC;QACpB,OAAO,EAAE;YACP,QAAQ,CAAE,IAAI;gBACZ,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACtB,CAAC;SACF;QACD,MAAM;YACJ,OAAO,CAAC,CAAC,IAAI,EAAE;gBACb,GAAG,EAAE,MAAM;gBACX,IAAI,EAAE,IAAI;aACX,CAAC,CAAA;QACJ,CAAC;KACF,CAAC,CAAA;IAEF,0DAA0D;IAC1D,GAAG,CAAC,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAC7B,0DAA0D;IAC1D,GAAG,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;IAEjC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;IACb,GAAG,CAAC,OAAO,EAAE,CAAA;AACf,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { createApp, h } from 'vue'
2
+ import type { StoryFile } from '../../node/types'
3
+ import Story from './Story.server.vue'
4
+ import Variant from './Variant.server.vue'
5
+
6
+ export async function run (file: StoryFile, storyData, el) {
7
+ const { default: Comp } = await import(file.moduleId)
8
+ const app = createApp({
9
+ provide: {
10
+ addStory (data) {
11
+ storyData.push(data)
12
+ },
13
+ },
14
+ render () {
15
+ return h(Comp, {
16
+ ref: 'comp',
17
+ data: file,
18
+ })
19
+ },
20
+ })
21
+
22
+ // eslint-disable-next-line vue/multi-word-component-names
23
+ app.component('Story', Story)
24
+ // eslint-disable-next-line vue/multi-word-component-names
25
+ app.component('Variant', Variant)
26
+
27
+ app.mount(el)
28
+ app.unmount()
29
+ }
@@ -0,0 +1,5 @@
1
+ declare module '*.vue' {
2
+ import { ComponentOptions } from 'vue'
3
+ const comp: ComponentOptions
4
+ export default comp
5
+ }
package/dist/node/bin.js CHANGED
@@ -10,8 +10,14 @@ program.command('dev')
10
10
  .describe('open the stories in your browser for development')
11
11
  .option('-p, --port <port>', 'Listening port of the server')
12
12
  .action(async (options) => {
13
- const { dev } = await import('./commands/dev.js');
14
- return dev(options);
13
+ const { devCommand } = await import('./commands/dev.js');
14
+ return devCommand(options);
15
+ });
16
+ program.command('build')
17
+ .describe('build the histoire final app you can deploy')
18
+ .action(async () => {
19
+ const { buildCommand } = await import('./commands/build.js');
20
+ return buildCommand();
15
21
  });
16
22
  program.parse(process.argv);
17
23
  //# sourceMappingURL=bin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bin.js","sourceRoot":"","sources":["../../src/node/bin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AACnC,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAEzD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,oBAAoB,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;AAEjG,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,CAAA;AAChC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAExB,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;KACnB,QAAQ,CAAC,kDAAkD,CAAC;KAC5D,MAAM,CAAC,mBAAmB,EAAE,8BAA8B,CAAC;KAC3D,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAA;IACjD,OAAO,GAAG,CAAC,OAAO,CAAC,CAAA;AACrB,CAAC,CAAC,CAAA;AAEJ,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA"}
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../../src/node/bin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AACnC,OAAO,IAAI,MAAM,MAAM,CAAA;AAEvB,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAEzD,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,EAAE,oBAAoB,CAAC,EAAE,MAAM,CAAC,CAAC,CAAA;AAEjG,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,CAAA;AAChC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAExB,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC;KACnB,QAAQ,CAAC,kDAAkD,CAAC;KAC5D,MAAM,CAAC,mBAAmB,EAAE,8BAA8B,CAAC;KAC3D,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAA;IACxD,OAAO,UAAU,CAAC,OAAO,CAAC,CAAA;AAC5B,CAAC,CAAC,CAAA;AAEJ,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;KACrB,QAAQ,CAAC,6CAA6C,CAAC;KACvD,MAAM,CAAC,KAAK,IAAI,EAAE;IACjB,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,qBAAqB,CAAC,CAAA;IAC5D,OAAO,YAAY,EAAE,CAAA;AACvB,CAAC,CAAC,CAAA;AAEJ,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ import { Context } from './context.js';
2
+ export declare function build(ctx: Context): Promise<void>;
@@ -0,0 +1,72 @@
1
+ import { join } from 'pathe';
2
+ import { build as viteBuild, createServer as createViteServer, resolveConfig as resolveViteConfig } from 'vite';
3
+ import fs from 'fs-extra';
4
+ import { lookup as lookupMime } from 'mrmime';
5
+ import { APP_PATH } from './alias.js';
6
+ import { createVitePlugins } from './plugin.js';
7
+ import { findAllStories } from './stories.js';
8
+ import { useCollectStories } from './collect.js';
9
+ export async function build(ctx) {
10
+ await findAllStories(ctx);
11
+ // Collect story data
12
+ const viteConfig = await resolveViteConfig({}, ctx.mode === 'dev' ? 'serve' : 'build');
13
+ const plugins = [];
14
+ const hasVuePlugin = viteConfig.plugins.find(p => p.name === 'vite:vue');
15
+ if (!hasVuePlugin) {
16
+ plugins.push((await import('@vitejs/plugin-vue')).default());
17
+ }
18
+ const server = await createViteServer({
19
+ plugins,
20
+ });
21
+ await server.pluginContainer.buildStart({});
22
+ const { executeStoryFile, destroy: destroyCollectStories } = useCollectStories({
23
+ server,
24
+ throws: true,
25
+ }, ctx);
26
+ for (const storyFile of ctx.storyFiles) {
27
+ await executeStoryFile(storyFile);
28
+ }
29
+ await server.close();
30
+ await destroyCollectStories();
31
+ const results = await viteBuild({
32
+ plugins: await createVitePlugins(ctx),
33
+ build: {
34
+ rollupOptions: {
35
+ input: [
36
+ join(APP_PATH, 'index.ts'),
37
+ join(APP_PATH, 'sandbox.ts'),
38
+ ],
39
+ },
40
+ outDir: ctx.config.outDir,
41
+ emptyOutDir: true,
42
+ cssCodeSplit: false,
43
+ },
44
+ });
45
+ const result = Array.isArray(results) ? results[0] : results;
46
+ const styleOutput = result.output.find(o => o.name === 'style.css' && o.type === 'asset');
47
+ // Index
48
+ const indexOutput = result.output.find(o => o.name === 'index' && o.type === 'chunk');
49
+ await writeHtml(indexOutput.fileName, styleOutput.fileName, 'index.html', ctx);
50
+ // Sandbox
51
+ const sandboxOutput = result.output.find(o => o.name === 'sandbox' && o.type === 'chunk');
52
+ await writeHtml(sandboxOutput.fileName, styleOutput.fileName, '__sandbox.html', ctx);
53
+ }
54
+ async function writeHtml(jsEntryFile, cssEntryFile, htmlFileName, ctx) {
55
+ const code = `<!DOCTYPE html>
56
+ <html>
57
+ <head>
58
+ <title>${ctx.config.theme.title}</title>
59
+ <meta charset="utf-8">
60
+ <meta name="viewport" content="width=device-width,initial-scale=1">
61
+ <meta name="description" content="">
62
+ <link rel="stylesheet" href="/${cssEntryFile}">
63
+ ${ctx.config.theme?.favicon ? `<link rel="icon" type="${lookupMime(ctx.config.theme.favicon)}" href="${ctx.config.theme.favicon}"/>` : ''}
64
+ </head>
65
+ <body>
66
+ <div id="app"></div>
67
+ <script type="module" src="/${jsEntryFile}"></script>
68
+ </body>
69
+ </html>`;
70
+ await fs.writeFile(join(ctx.config.outDir, htmlFileName), code, 'utf8');
71
+ }
72
+ //# sourceMappingURL=build.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.js","sourceRoot":"","sources":["../../src/node/build.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAC5B,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,YAAY,IAAI,gBAAgB,EAAE,aAAa,IAAI,iBAAiB,EAAwB,MAAM,MAAM,CAAA;AACrI,OAAO,EAAE,MAAM,UAAU,CAAA;AACzB,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAErC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,MAAM,CAAC,KAAK,UAAU,KAAK,CAAE,GAAY;IACvC,MAAM,cAAc,CAAC,GAAG,CAAC,CAAA;IAEzB,qBAAqB;IACrB,MAAM,UAAU,GAAG,MAAM,iBAAiB,CAAC,EAAE,EAAE,GAAG,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;IACtF,MAAM,OAAO,GAAiB,EAAE,CAAA;IAChC,MA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C,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;AACzE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { ViteDevServer } from 'vite';
2
+ import type { StoryFile } from './types.js';
3
+ import type { Context } from './context.js';
4
+ export interface UseCollectStoriesOptions {
5
+ server: ViteDevServer;
6
+ throws?: boolean;
7
+ }
8
+ export declare function useCollectStories(options: UseCollectStoriesOptions, ctx: Context): {
9
+ clearCache: () => void;
10
+ executeStoryFile: (storyFile: StoryFile) => Promise<void>;
11
+ destroy: () => Promise<void>;
12
+ };
@@ -0,0 +1,66 @@
1
+ import { fileURLToPath } from 'url';
2
+ import { ViteNodeServer } from 'vite-node/server';
3
+ import { ViteNodeRunner } from 'vite-node/client';
4
+ import { dirname, resolve, relative } from 'pathe';
5
+ import pc from 'picocolors';
6
+ import { createDomEnv } from './dom/env.js';
7
+ import { createPath } from './tree.js';
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+ export function useCollectStories(options, ctx) {
10
+ const { server } = options;
11
+ const { destroy: destroyDomEnv } = createDomEnv();
12
+ const node = new ViteNodeServer(server);
13
+ const runner = new ViteNodeRunner({
14
+ root: server.config.root,
15
+ base: server.config.base,
16
+ fetchModule(id) {
17
+ // Alias
18
+ if (id.endsWith('vue.runtime.esm-bundler.js')) {
19
+ id = 'vue';
20
+ }
21
+ return node.fetchModule(id);
22
+ },
23
+ });
24
+ function clearCache() {
25
+ node.fetchCache.clear();
26
+ runner.moduleCache.clear();
27
+ }
28
+ async function executeStoryFile(storyFile) {
29
+ try {
30
+ // Mount app to collect stories/variants
31
+ const el = window.document.createElement('div');
32
+ const { run } = await runner.executeFile(resolve(__dirname, '../client/server/index.js'));
33
+ const storyData = [];
34
+ await run(storyFile, storyData, el);
35
+ if (storyData.length === 0) {
36
+ console.warn(pc.yellow(`No story found for ${storyFile.path}`));
37
+ return;
38
+ }
39
+ else if (storyData.length > 1) {
40
+ console.warn(pc.yellow(`Multiple stories not supported: ${storyFile.path}`));
41
+ }
42
+ storyFile.story = storyData[0];
43
+ const file = {
44
+ title: storyData[0].title,
45
+ path: relative(server.config.root, storyFile.path),
46
+ };
47
+ storyFile.treePath = createPath(ctx.config, file);
48
+ storyFile.story.title = storyFile.treePath[storyFile.treePath.length - 1];
49
+ }
50
+ catch (e) {
51
+ console.error(pc.red(`Error while collecting story ${storyFile.path}:\n${e.frame ? `${pc.bold(e.message)}\n${e.frame}` : e.stack}`));
52
+ if (options.throws) {
53
+ throw e;
54
+ }
55
+ }
56
+ }
57
+ async function destroy() {
58
+ destroyDomEnv();
59
+ }
60
+ return {
61
+ clearCache,
62
+ executeStoryFile,
63
+ destroy,
64
+ };
65
+ }
66
+ //# sourceMappingURL=collect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collect.js","sourceRoot":"","sources":["../../src/node/collect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAClD,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAY,MAAM,WAAW,CAAA;AAGhD,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;AAOzD,MAAM,UAAU,iBAAiB,CAAE,OAAiC,EAAE,GAAY;IAChF,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAC1B,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,YAAY,EAAE,CAAA;IAEjD,MAAM,IAAI,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,CAAA;IACvC,MAAM,MAAM,GA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