histoire 0.0.0 → 0.0.3

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 (204) 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 +113 -0
  9. package/dist/client/app/codegen/serialize-js.ts +119 -0
  10. package/dist/client/app/codegen/util.d.ts +10 -0
  11. package/dist/client/app/codegen/util.js +70 -0
  12. package/dist/client/app/codegen/util.ts +79 -0
  13. package/dist/client/app/codegen/vue3.d.ts +2 -0
  14. package/dist/client/app/codegen/vue3.js +238 -0
  15. package/dist/client/app/codegen/vue3.ts +240 -0
  16. package/dist/client/app/components/HomeView.vue +15 -1
  17. package/dist/client/app/components/StoryControls.vue +7 -2
  18. package/dist/client/app/components/StoryList.vue +20 -13
  19. package/dist/client/app/components/StoryListFolder.vue +87 -0
  20. package/dist/client/app/components/StoryListItem.vue +38 -12
  21. package/dist/client/app/components/StorySourceCode.vue +121 -0
  22. package/dist/client/app/components/StoryVariantGridItem.vue +32 -17
  23. package/dist/client/app/components/StoryVariantListItem.vue +46 -0
  24. package/dist/client/app/components/StoryVariantSingleView.vue +145 -15
  25. package/dist/client/app/components/StoryView.vue +88 -54
  26. package/dist/client/app/components/app/AppHeader.vue +56 -0
  27. package/dist/client/app/components/app/AppLogo.vue +24 -0
  28. package/dist/client/app/components/base/BaseEmpty.vue +1 -1
  29. package/dist/client/app/components/base/BaseListItemLink.vue +55 -0
  30. package/dist/client/app/components/base/BaseSplitPane.vue +57 -21
  31. package/dist/client/app/components/exposed/Story.vue +23 -58
  32. package/dist/client/app/components/exposed/Variant.vue +24 -47
  33. package/dist/client/app/components/misc/HatchedPattern.vue +25 -0
  34. package/dist/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  35. package/dist/client/app/components/search/SearchItem.vue +110 -0
  36. package/dist/client/app/components/search/SearchModal.vue +179 -0
  37. package/dist/client/app/composable/variant.js +0 -1
  38. package/dist/client/app/composable/variant.ts +20 -0
  39. package/dist/client/app/global-components.js +0 -1
  40. package/dist/client/app/global-components.ts +10 -0
  41. package/dist/client/app/index.d.ts +1 -0
  42. package/dist/client/app/index.js +10 -2
  43. package/dist/client/app/index.ts +24 -0
  44. package/dist/client/app/router.js +0 -1
  45. package/dist/client/app/router.ts +17 -0
  46. package/dist/client/app/sandbox.d.ts +1 -0
  47. package/dist/client/app/sandbox.js +53 -0
  48. package/dist/client/app/sandbox.ts +60 -0
  49. package/dist/client/app/stores/story.d.ts +167 -50
  50. package/dist/client/app/stores/story.js +33 -16
  51. package/dist/client/app/stores/story.ts +58 -0
  52. package/dist/client/app/style/floating-vue.css +31 -0
  53. package/dist/client/app/style/main.css +17 -2
  54. package/dist/client/app/style/sandbox.css +14 -0
  55. package/dist/client/app/types.d.ts +36 -4
  56. package/dist/client/app/types.js +0 -1
  57. package/dist/client/app/types.ts +59 -0
  58. package/dist/client/app/util/config.d.ts +3 -0
  59. package/dist/client/app/util/config.js +4 -0
  60. package/dist/client/app/util/config.ts +6 -0
  61. package/dist/client/app/util/const.d.ts +1 -0
  62. package/dist/client/app/util/const.js +1 -0
  63. package/dist/client/app/util/const.ts +1 -0
  64. package/dist/client/app/util/dark.d.ts +2 -0
  65. package/dist/client/app/util/dark.js +3 -0
  66. package/dist/client/app/util/dark.ts +4 -0
  67. package/dist/client/app/util/env.d.ts +1 -0
  68. package/dist/client/app/util/env.js +1 -0
  69. package/dist/client/app/util/env.ts +1 -0
  70. package/dist/client/app/util/keyboard.d.ts +8 -0
  71. package/dist/client/app/util/keyboard.js +82 -0
  72. package/dist/client/app/util/keyboard.ts +99 -0
  73. package/dist/client/app/util/mapping.d.ts +3 -0
  74. package/dist/client/app/util/mapping.js +39 -0
  75. package/dist/client/app/util/mapping.ts +41 -0
  76. package/dist/client/app/util/tooltip.d.ts +6 -0
  77. package/dist/client/app/util/tooltip.js +11 -0
  78. package/dist/client/app/util/tooltip.ts +13 -0
  79. package/dist/client/index.d.ts +8 -0
  80. package/dist/client/index.js +3 -0
  81. package/dist/client/index.ts +12 -0
  82. package/dist/client/server/Story.server.vue +65 -0
  83. package/dist/client/server/Variant.server.vue +50 -0
  84. package/dist/client/server/index.d.ts +2 -0
  85. package/dist/client/server/index.js +25 -0
  86. package/dist/client/server/index.ts +29 -0
  87. package/dist/client/shim.d.ts +5 -0
  88. package/dist/node/alias.js +0 -1
  89. package/dist/node/bin.js +8 -3
  90. package/dist/node/build.d.ts +2 -0
  91. package/dist/node/build.js +71 -0
  92. package/dist/node/collect.d.ts +12 -0
  93. package/dist/node/collect.js +65 -0
  94. package/dist/node/colors.d.ts +286 -0
  95. package/dist/node/colors.js +324 -0
  96. package/dist/node/commands/build.d.ts +1 -0
  97. package/dist/node/commands/build.js +10 -0
  98. package/dist/node/commands/dev.d.ts +1 -1
  99. package/dist/node/commands/dev.js +45 -13
  100. package/dist/node/config.d.ts +112 -1
  101. package/dist/node/config.js +124 -2
  102. package/dist/node/context.d.ts +13 -0
  103. package/dist/node/context.js +12 -2
  104. package/dist/node/dom/dom-keys.d.ts +4 -0
  105. package/dist/node/dom/dom-keys.js +223 -0
  106. package/dist/node/dom/env.d.ts +5 -0
  107. package/dist/node/dom/env.js +22 -0
  108. package/dist/node/index.d.ts +2 -0
  109. package/dist/node/index.js +2 -2
  110. package/dist/node/plugin.d.ts +8 -2
  111. package/dist/node/plugin.js +150 -22
  112. package/dist/node/server.d.ts +4 -1
  113. package/dist/node/server.js +80 -21
  114. package/dist/node/stories.d.ts +8 -9
  115. package/dist/node/stories.js +42 -23
  116. package/dist/node/tree.d.ts +19 -0
  117. package/dist/node/tree.js +54 -0
  118. package/dist/node/types.d.ts +38 -0
  119. package/dist/node/types.js +1 -0
  120. package/dist/style.css +610 -53
  121. package/package.json +45 -25
  122. package/scripts/copy.mjs +11 -0
  123. package/src/client/app/App.vue +84 -21
  124. package/src/client/app/assets/histoire-text-dark.svg +89 -0
  125. package/src/client/app/assets/histoire-text.svg +89 -0
  126. package/src/client/app/assets/histoire.svg +51 -0
  127. package/src/client/app/codegen/serialize-js.ts +119 -0
  128. package/src/client/app/codegen/util.ts +79 -0
  129. package/src/client/app/codegen/vue3.ts +240 -0
  130. package/src/client/app/components/HomeView.vue +15 -1
  131. package/src/client/app/components/StoryControls.vue +7 -2
  132. package/src/client/app/components/StoryList.vue +20 -13
  133. package/src/client/app/components/StoryListFolder.vue +87 -0
  134. package/src/client/app/components/StoryListItem.vue +38 -12
  135. package/src/client/app/components/StorySourceCode.vue +121 -0
  136. package/src/client/app/components/StoryVariantGridItem.vue +32 -17
  137. package/src/client/app/components/StoryVariantListItem.vue +46 -0
  138. package/src/client/app/components/StoryVariantSingleView.vue +145 -15
  139. package/src/client/app/components/StoryView.vue +88 -54
  140. package/src/client/app/components/app/AppHeader.vue +56 -0
  141. package/src/client/app/components/app/AppLogo.vue +24 -0
  142. package/src/client/app/components/base/BaseEmpty.vue +1 -1
  143. package/src/client/app/components/base/BaseListItemLink.vue +55 -0
  144. package/src/client/app/components/base/BaseSplitPane.vue +57 -21
  145. package/src/client/app/components/exposed/Story.vue +23 -58
  146. package/src/client/app/components/exposed/Variant.vue +24 -47
  147. package/src/client/app/components/misc/HatchedPattern.vue +25 -0
  148. package/src/client/app/components/{SandboxVue.vue → sandbox/SandboxVue3.vue} +31 -12
  149. package/src/client/app/components/search/SearchItem.vue +110 -0
  150. package/src/client/app/components/search/SearchModal.vue +179 -0
  151. package/src/client/app/index.ts +10 -1
  152. package/src/client/app/sandbox.ts +60 -0
  153. package/src/client/app/stores/story.ts +39 -15
  154. package/src/client/app/style/floating-vue.css +31 -0
  155. package/src/client/app/style/main.css +17 -2
  156. package/src/client/app/style/sandbox.css +14 -0
  157. package/src/client/app/types.ts +42 -4
  158. package/src/client/app/util/config.ts +6 -0
  159. package/src/client/app/util/const.ts +1 -0
  160. package/src/client/app/util/dark.ts +4 -0
  161. package/src/client/app/util/env.ts +1 -0
  162. package/src/client/app/util/keyboard.ts +99 -0
  163. package/src/client/app/util/mapping.ts +41 -0
  164. package/src/client/app/util/tooltip.ts +13 -0
  165. package/src/client/index.ts +12 -0
  166. package/src/client/server/Story.server.vue +65 -0
  167. package/src/client/server/Variant.server.vue +50 -0
  168. package/src/client/server/index.ts +29 -0
  169. package/src/node/bin.ts +9 -2
  170. package/src/node/build.ts +80 -0
  171. package/src/node/collect.ts +78 -0
  172. package/src/node/colors.ts +340 -0
  173. package/src/node/commands/build.ts +12 -0
  174. package/src/node/commands/dev.ts +49 -12
  175. package/src/node/config.ts +240 -1
  176. package/src/node/context.ts +21 -1
  177. package/src/node/dom/dom-keys.ts +227 -0
  178. package/src/node/dom/env.ts +26 -0
  179. package/src/node/index.ts +2 -0
  180. package/src/node/plugin.ts +155 -22
  181. package/src/node/server.ts +95 -20
  182. package/src/node/stories.ts +53 -31
  183. package/src/node/tree.spec.ts +28 -0
  184. package/src/node/tree.ts +88 -0
  185. package/src/node/types.ts +40 -0
  186. package/tailwind.config.cjs +41 -1
  187. package/tsconfig.json +2 -1
  188. package/dist/client/app/components/StoryVariantItem.vue +0 -29
  189. package/dist/client/app/composable/variant.js.map +0 -1
  190. package/dist/client/app/global-components.js.map +0 -1
  191. package/dist/client/app/index.js.map +0 -1
  192. package/dist/client/app/router.js.map +0 -1
  193. package/dist/client/app/stores/story.js.map +0 -1
  194. package/dist/client/app/types.js.map +0 -1
  195. package/dist/node/alias.js.map +0 -1
  196. package/dist/node/bin.js.map +0 -1
  197. package/dist/node/commands/dev.js.map +0 -1
  198. package/dist/node/config.js.map +0 -1
  199. package/dist/node/context.js.map +0 -1
  200. package/dist/node/index.js.map +0 -1
  201. package/dist/node/plugin.js.map +0 -1
  202. package/dist/node/server.js.map +0 -1
  203. package/dist/node/stories.js.map +0 -1
  204. package/src/client/app/components/StoryVariantItem.vue +0 -29
@@ -1,21 +1,58 @@
1
- import { join } from 'pathe'
2
- import { HistoireConfig } from '../config.js'
3
- import { Context } from '../context.js'
1
+ import { resolveConfigFile } from '../config.js'
2
+ import { createContext } from '../context.js'
4
3
  import { createServer } from '../server.js'
4
+ import chokidar from 'chokidar'
5
+ import pc from 'picocolors'
5
6
 
6
7
  export interface DevOptions {
7
8
  port: number
8
9
  }
9
10
 
10
- export async function dev (options: DevOptions) {
11
- const config: HistoireConfig = {
12
- sourceDir: join(process.cwd(), 'src'),
13
- storyMatch: ['**/*.story.vue'],
11
+ export async function devCommand (options: DevOptions) {
12
+ let stop: () => Promise<void>
13
+
14
+ async function start () {
15
+ const ctx = await createContext({
16
+ mode: 'dev',
17
+ })
18
+ const { server, close } = await createServer(ctx, options.port)
19
+ server.printUrls()
20
+
21
+ // Histoire config watcher
22
+ let watcher: chokidar.FSWatcher
23
+ if (server.config.configFile) {
24
+ watcher = chokidar.watch(server.config.configFile, {
25
+ ignoreInitial: true,
26
+ })
27
+ watcher.on('change', () => {
28
+ restart('Vite')
29
+ })
30
+ }
31
+
32
+ return async () => {
33
+ await watcher?.close()
34
+ await close()
35
+ }
14
36
  }
15
- const ctx: Context = {
16
- config,
37
+
38
+ async function restart (source: string) {
39
+ if (stop) {
40
+ console.log(pc.blue(`${source} config changed, restarting...`))
41
+ stop()
42
+ stop = null // Don't call stop again until new start() is done
43
+ stop = await start()
44
+ }
45
+ }
46
+
47
+ stop = await start()
48
+
49
+ const configFile = await resolveConfigFile()
50
+ if (configFile) {
51
+ const watcher = chokidar.watch(configFile, {
52
+ ignoreInitial: true,
53
+ })
54
+ watcher.on('change', () => {
55
+ restart('Histoire')
56
+ })
17
57
  }
18
- const server = await createServer(ctx)
19
- await server.listen(options.port)
20
- server.printUrls()
21
58
  }
@@ -1,4 +1,243 @@
1
+ import path from 'pathe'
2
+ import fs from 'fs'
3
+ import defu from 'defu'
4
+ import { createServer, resolveConfig as resolveViteConfig, UserConfig as ViteConfig } from 'vite'
5
+ import { ViteNodeServer } from 'vite-node/server'
6
+ import { ViteNodeRunner } from 'vite-node/client'
7
+ import pc from 'picocolors'
8
+ import { TreeFile } from './tree.js'
9
+ import { defaultColors } from './colors.js'
10
+
11
+ type CustomizableColors = 'primary' | 'gray'
12
+ type ColorKeys = '50' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'
13
+ type GrayColorKeys = ColorKeys | '750' | '850' | '950'
14
+
15
+ interface ResponsivePreset {
16
+ label: string
17
+ width: number
18
+ }
19
+
1
20
  export interface HistoireConfig {
2
- sourceDir: string
21
+ /**
22
+ * Output directory.
23
+ */
24
+ outDir: string
25
+ /**
26
+ * Glob patterns for story files to include.
27
+ */
3
28
  storyMatch: string[]
29
+ /**
30
+ * Glob patterns to ignore files while searching for story files.
31
+ */
32
+ storyIgnored: string[]
33
+ /**
34
+ * How to generate the story tree.
35
+ */
36
+ tree: {
37
+ /**
38
+ * Use `'title'` to create the path from the title of the story, using `/` as the separator.
39
+ *
40
+ * Use `'path'` use the real folder structure on your computer.
41
+ */
42
+ file?: 'title' | 'path' | ((file: TreeFile) => string[])
43
+ order?: 'asc' | ((a: string, b: string) => number)
44
+ }
45
+ /**
46
+ * Customize the look of the histoire book.
47
+ */
48
+ theme: {
49
+ /**
50
+ * Main page title. For example: 'Acme Inc.'
51
+ */
52
+ title?: string
53
+ /**
54
+ * Custom logo files. Should be import paths (processed by Vite).
55
+ *
56
+ * Example: `'/src/assets/my-logo.svg'`
57
+ */
58
+ logo?: {
59
+ /**
60
+ * Square logo without text.
61
+ */
62
+ square?: string
63
+ /**
64
+ * Full logo for light theme.
65
+ */
66
+ light?: string
67
+ /**
68
+ * Full logo for dark theme.
69
+ */
70
+ dark?: string
71
+ }
72
+ /**
73
+ * Href to the favicon file (**not** processed by Vite). Put the file in the public directory.
74
+ *
75
+ * Example: `'/favicon.ico'`
76
+ */
77
+ favicon?: string
78
+ /**
79
+ * Customize the colors. Each color should be an object with shades as keys.
80
+ *
81
+ * Example: ```{ primary: { 50: '#eef2ff', 100: '#e0e7ff', ..., 900: '#312e81' } }```
82
+ *
83
+ * You can import `defaultColors` from `'histoire'` to use predefined colors or you can create your own colors from scratch.
84
+ */
85
+ colors?: {
86
+ [key in CustomizableColors]?: key extends 'gray' ? {
87
+ [key in GrayColorKeys]?: string
88
+ } :{
89
+ [key in ColorKeys]?: string
90
+ }
91
+ }
92
+ }
93
+ /**
94
+ * Setup file exposting a default function executed when setting up each story preview.
95
+ *
96
+ * Import custom CSS files from this file.
97
+ *
98
+ * Example: `'/src/histoire-setup.ts'`
99
+ */
100
+ setupFile?: string
101
+ /**
102
+ * Predefined responsive sizes for story playgrounds.
103
+ */
104
+ responsivePresets?: ResponsivePreset[]
105
+ /**
106
+ * Vite config override
107
+ */
108
+ vite?: ViteConfig
109
+ }
110
+
111
+ export function getDefaultConfig (): HistoireConfig {
112
+ return {
113
+ outDir: 'histoire-dist',
114
+ storyMatch: ['**/*.story.vue'],
115
+ storyIgnored: ['**/node_modules/**'],
116
+ tree: {
117
+ file: 'title',
118
+ order: 'asc',
119
+ },
120
+ theme: {
121
+ title: 'Histoire',
122
+ colors: {
123
+ primary: defaultColors.emerald,
124
+ gray: defaultColors.zinc,
125
+ },
126
+ },
127
+ responsivePresets: [
128
+ {
129
+ label: 'Mobile (Small)',
130
+ width: 320,
131
+ },
132
+ {
133
+ label: 'Mobile (Medium)',
134
+ width: 375,
135
+ },
136
+ {
137
+ label: 'Mobile (Large)',
138
+ width: 425,
139
+ },
140
+ {
141
+ label: 'Tablet',
142
+ width: 768,
143
+ },
144
+ {
145
+ label: 'Laptop (Small)',
146
+ width: 1024,
147
+ },
148
+ {
149
+ label: 'Laptop (Large)',
150
+ width: 1440,
151
+ },
152
+ {
153
+ label: 'Desktop',
154
+ width: 1920,
155
+ },
156
+ {
157
+ label: '4K',
158
+ width: 3840,
159
+ },
160
+ ],
161
+ }
162
+ }
163
+
164
+ export const configFileNames = [
165
+ 'histoire.config.ts',
166
+ 'histoire.config.js',
167
+ '.histoire.ts',
168
+ '.histoire.js',
169
+ ]
170
+
171
+ export function resolveConfigFile (cwd: string = process.cwd()): string {
172
+ let { root } = path.parse(cwd)
173
+ let dir = cwd
174
+
175
+ // Fix for windows, waiting for pathe to fix this: https://github.com/unjs/pathe/issues/5
176
+ if (root === '' && dir[1] === ':') {
177
+ root = dir.substring(0, 2)
178
+ }
179
+
180
+ while (dir !== root) {
181
+ for (const fileName of configFileNames) {
182
+ const searchPath = path.join(dir, fileName)
183
+ if (fs.existsSync(searchPath)) {
184
+ return searchPath
185
+ }
186
+ }
187
+ dir = path.dirname(dir)
188
+ }
189
+
190
+ return null
191
+ }
192
+
193
+ export async function loadConfigFile (configFile: string): Promise<Partial<HistoireConfig>> {
194
+ try {
195
+ const server = await createServer()
196
+ await server.pluginContainer.buildStart({})
197
+ const node = new ViteNodeServer(server)
198
+ const runner = new ViteNodeRunner({
199
+ root: path.dirname(configFile),
200
+ fetchModule (id) {
201
+ return node.fetchModule(id)
202
+ },
203
+ })
204
+ const result: { default: Partial<HistoireConfig> } = await runner.executeFile(configFile)
205
+ await server.close()
206
+ if (!result.default) {
207
+ throw new Error(`Expected default export in ${configFile}`)
208
+ }
209
+ return result.default
210
+ } catch (e) {
211
+ console.error(pc.red(`Error while loading ${configFile}`))
212
+ throw e
213
+ }
214
+ }
215
+
216
+ export async function resolveConfig (cwd: string = process.cwd()): Promise<HistoireConfig> {
217
+ let result: Partial<HistoireConfig>
218
+ const configFile = resolveConfigFile(cwd)
219
+ if (configFile) {
220
+ result = await loadConfigFile(configFile)
221
+ }
222
+ const viteConfig = await resolveViteConfig({}, 'serve')
223
+ const viteHistoireConfig = (viteConfig.histoire ?? {}) as HistoireConfig
224
+ return processConfig(defu(result, viteHistoireConfig, getDefaultConfig()))
225
+ }
226
+
227
+ export function processConfig (config: HistoireConfig): HistoireConfig {
228
+ config.outDir = path.resolve(process.cwd(), config.outDir)
229
+ return config
230
+ }
231
+
232
+ export function defineConfig (config: Partial<HistoireConfig>) {
233
+ return config
234
+ }
235
+
236
+ declare module 'vite' {
237
+ interface UserConfig {
238
+ /**
239
+ * Histoire configuration
240
+ */
241
+ histoire?: Partial<HistoireConfig>
242
+ }
4
243
  }
@@ -1,5 +1,25 @@
1
- import { HistoireConfig } from './config.js'
1
+ import { resolveConfig as resolveViteConfig } from 'vite'
2
+ import { resolveConfig, HistoireConfig } from './config.js'
3
+ import type { StoryFile } from './types.js'
2
4
 
3
5
  export interface Context {
6
+ root: string
4
7
  config: HistoireConfig
8
+ mode: 'dev' | 'build'
9
+ storyFiles: StoryFile[]
10
+ }
11
+
12
+ export interface CreateContextOptions {
13
+ mode: Context['mode']
14
+ }
15
+
16
+ export async function createContext (options: CreateContextOptions) {
17
+ const config = await resolveConfig()
18
+ const viteConfig = await resolveViteConfig({}, 'build')
19
+ return {
20
+ root: viteConfig.root,
21
+ config,
22
+ mode: options.mode,
23
+ storyFiles: [],
24
+ }
5
25
  }
@@ -0,0 +1,227 @@
1
+ /**
2
+ * Code from vitest https://github.com/antfu-sponsors/vitest/blob/6066fdbf3b1d17021aac20591b5ef3603056fa5f/src/integrations/dom/keys.ts by @antfu and @patak
3
+ */
4
+
5
+ // SEE https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/interfaces.js
6
+
7
+ const LIVING_KEYS = [
8
+ 'DOMException',
9
+ 'URL',
10
+ 'URLSearchParams',
11
+ 'EventTarget',
12
+ 'NamedNodeMap',
13
+ 'Node',
14
+ 'Attr',
15
+ 'Element',
16
+ 'DocumentFragment',
17
+ 'DOMImplementation',
18
+ 'Document',
19
+ 'XMLDocument',
20
+ 'CharacterData',
21
+ 'Text',
22
+ 'CDATASection',
23
+ 'ProcessingInstruction',
24
+ 'Comment',
25
+ 'DocumentType',
26
+ 'NodeList',
27
+ 'HTMLCollection',
28
+ 'HTMLOptionsCollection',
29
+ 'DOMStringMap',
30
+ 'DOMTokenList',
31
+ 'StyleSheetList',
32
+ 'HTMLElement',
33
+ 'HTMLHeadElement',
34
+ 'HTMLTitleElement',
35
+ 'HTMLBaseElement',
36
+ 'HTMLLinkElement',
37
+ 'HTMLMetaElement',
38
+ 'HTMLStyleElement',
39
+ 'HTMLBodyElement',
40
+ 'HTMLHeadingElement',
41
+ 'HTMLParagraphElement',
42
+ 'HTMLHRElement',
43
+ 'HTMLPreElement',
44
+ 'HTMLUListElement',
45
+ 'HTMLOListElement',
46
+ 'HTMLLIElement',
47
+ 'HTMLMenuElement',
48
+ 'HTMLDListElement',
49
+ 'HTMLDivElement',
50
+ 'HTMLAnchorElement',
51
+ 'HTMLAreaElement',
52
+ 'HTMLBRElement',
53
+ 'HTMLButtonElement',
54
+ 'HTMLCanvasElement',
55
+ 'HTMLDataElement',
56
+ 'HTMLDataListElement',
57
+ 'HTMLDetailsElement',
58
+ 'HTMLDialogElement',
59
+ 'HTMLDirectoryElement',
60
+ 'HTMLFieldSetElement',
61
+ 'HTMLFontElement',
62
+ 'HTMLFormElement',
63
+ 'HTMLHtmlElement',
64
+ 'HTMLImageElement',
65
+ 'HTMLInputElement',
66
+ 'HTMLLabelElement',
67
+ 'HTMLLegendElement',
68
+ 'HTMLMapElement',
69
+ 'HTMLMarqueeElement',
70
+ 'HTMLMediaElement',
71
+ 'HTMLMeterElement',
72
+ 'HTMLModElement',
73
+ 'HTMLOptGroupElement',
74
+ 'HTMLOptionElement',
75
+ 'HTMLOutputElement',
76
+ 'HTMLPictureElement',
77
+ 'HTMLProgressElement',
78
+ 'HTMLQuoteElement',
79
+ 'HTMLScriptElement',
80
+ 'HTMLSelectElement',
81
+ 'HTMLSlotElement',
82
+ 'HTMLSourceElement',
83
+ 'HTMLSpanElement',
84
+ 'HTMLTableCaptionElement',
85
+ 'HTMLTableCellElement',
86
+ 'HTMLTableColElement',
87
+ 'HTMLTableElement',
88
+ 'HTMLTimeElement',
89
+ 'HTMLTableRowElement',
90
+ 'HTMLTableSectionElement',
91
+ 'HTMLTemplateElement',
92
+ 'HTMLTextAreaElement',
93
+ 'HTMLUnknownElement',
94
+ 'HTMLFrameElement',
95
+ 'HTMLFrameSetElement',
96
+ 'HTMLIFrameElement',
97
+ 'HTMLEmbedElement',
98
+ 'HTMLObjectElement',
99
+ 'HTMLParamElement',
100
+ 'HTMLVideoElement',
101
+ 'HTMLAudioElement',
102
+ 'HTMLTrackElement',
103
+ 'SVGElement',
104
+ 'SVGGraphicsElement',
105
+ 'SVGSVGElement',
106
+ 'SVGTitleElement',
107
+ 'SVGAnimatedString',
108
+ 'SVGNumber',
109
+ 'SVGStringList',
110
+ 'Event',
111
+ 'CloseEvent',
112
+ 'CustomEvent',
113
+ 'MessageEvent',
114
+ 'ErrorEvent',
115
+ 'HashChangeEvent',
116
+ 'PopStateEvent',
117
+ 'StorageEvent',
118
+ 'ProgressEvent',
119
+ 'PageTransitionEvent',
120
+ 'UIEvent',
121
+ 'FocusEvent',
122
+ 'InputEvent',
123
+ 'MouseEvent',
124
+ 'KeyboardEvent',
125
+ 'TouchEvent',
126
+ 'CompositionEvent',
127
+ 'WheelEvent',
128
+ 'BarProp',
129
+ 'External',
130
+ 'Location',
131
+ 'History',
132
+ 'Screen',
133
+ 'Performance',
134
+ 'Navigator',
135
+ 'PluginArray',
136
+ 'MimeTypeArray',
137
+ 'Plugin',
138
+ 'MimeType',
139
+ 'FileReader',
140
+ 'Blob',
141
+ 'File',
142
+ 'FileList',
143
+ 'ValidityState',
144
+ 'DOMParser',
145
+ 'XMLSerializer',
146
+ 'FormData',
147
+ 'XMLHttpRequestEventTarget',
148
+ 'XMLHttpRequestUpload',
149
+ 'XMLHttpRequest',
150
+ 'WebSocket',
151
+ 'NodeFilter',
152
+ 'NodeIterator',
153
+ 'TreeWalker',
154
+ 'AbstractRange',
155
+ 'Range',
156
+ 'StaticRange',
157
+ 'Selection',
158
+ 'Storage',
159
+ 'CustomElementRegistry',
160
+ 'ShadowRoot',
161
+ 'MutationObserver',
162
+ 'MutationRecord',
163
+ 'Headers',
164
+ 'AbortController',
165
+ 'AbortSignal',
166
+ ]
167
+
168
+ const OTHER_KEYS = [
169
+ 'addEventListener',
170
+ 'alert',
171
+ 'atob',
172
+ 'blur',
173
+ 'btoa',
174
+ /* 'clearInterval', */
175
+ /* 'clearTimeout', */
176
+ 'close',
177
+ 'confirm',
178
+ /* 'console', */
179
+ 'createPopup',
180
+ 'dispatchEvent',
181
+ 'document',
182
+ 'focus',
183
+ 'frames',
184
+ 'getComputedStyle',
185
+ 'history',
186
+ 'innerHeight',
187
+ 'innerWidth',
188
+ 'length',
189
+ 'location',
190
+ 'moveBy',
191
+ 'moveTo',
192
+ 'name',
193
+ 'navigator',
194
+ 'open',
195
+ 'outerHeight',
196
+ 'outerWidth',
197
+ 'pageXOffset',
198
+ 'pageYOffset',
199
+ 'parent',
200
+ 'postMessage',
201
+ 'print',
202
+ 'prompt',
203
+ 'removeEventListener',
204
+ 'resizeBy',
205
+ 'resizeTo',
206
+ 'screen',
207
+ 'screenLeft',
208
+ 'screenTop',
209
+ 'screenX',
210
+ 'screenY',
211
+ 'scroll',
212
+ 'scrollBy',
213
+ 'scrollLeft',
214
+ 'scrollTo',
215
+ 'scrollTop',
216
+ 'scrollX',
217
+ 'scrollY',
218
+ 'self',
219
+ /* 'setInterval', */
220
+ /* 'setTimeout', */
221
+ 'stop',
222
+ /* 'toString', */
223
+ 'top',
224
+ 'window',
225
+ ]
226
+
227
+ export const KEYS = LIVING_KEYS.concat(OTHER_KEYS)
@@ -0,0 +1,26 @@
1
+ import { Window } from 'happy-dom'
2
+ import { KEYS } from './dom-keys.js'
3
+
4
+ export function createDomEnv () {
5
+ // @ts-ignore
6
+ const window = global.window = new Window()
7
+ const globalKeys = KEYS.concat(Object.getOwnPropertyNames(window))
8
+ .filter(k => !k.startsWith('_'))
9
+ .filter(k => !(k in global))
10
+
11
+ for (const key of globalKeys) {
12
+ global[key] = window[key]
13
+ }
14
+
15
+ function destroy () {
16
+ globalKeys.forEach(key => delete global[key])
17
+ globalKeys.length = 0
18
+ window.happyDOM.cancelAsync()
19
+ delete global.window
20
+ }
21
+
22
+ return {
23
+ window,
24
+ destroy,
25
+ }
26
+ }
package/src/node/index.ts CHANGED
@@ -0,0 +1,2 @@
1
+ export * from './config.js'
2
+ export { defaultColors } from './colors.js'