@aurelia/storybook 0.1.1 → 1.0.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 (73) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +31 -3
  3. package/__tests__/preset.test.ts +49 -0
  4. package/__tests__/preview.test.ts +139 -0
  5. package/__tests__/render.test.ts +0 -1
  6. package/__tests__/webpack.test.ts +21 -0
  7. package/apps/hello-world/.storybook/main.ts +30 -0
  8. package/apps/hello-world/.storybook/preview.ts +1 -0
  9. package/apps/hello-world/.stylelintrc.json +5 -0
  10. package/apps/hello-world/.yarnrc.yml +2 -0
  11. package/apps/hello-world/README.md +28 -0
  12. package/apps/hello-world/eslint.config.mjs +25 -0
  13. package/apps/hello-world/favicon.ico +0 -0
  14. package/apps/hello-world/index.html +17 -0
  15. package/apps/hello-world/package.json +65 -0
  16. package/apps/hello-world/src/hello-world.html +6 -0
  17. package/apps/hello-world/src/hello-world.ts +17 -0
  18. package/apps/hello-world/src/main.ts +6 -0
  19. package/apps/hello-world/src/my-app.html +1 -0
  20. package/apps/hello-world/src/my-app.ts +3 -0
  21. package/apps/hello-world/src/resource.d.ts +15 -0
  22. package/apps/hello-world/src/stories/hello-world.stories.ts +53 -0
  23. package/apps/hello-world/test/my-app.spec.ts +15 -0
  24. package/apps/hello-world/test/setup.ts +29 -0
  25. package/apps/hello-world/tsconfig.json +18 -0
  26. package/apps/hello-world/tsconfig.vitest.json +11 -0
  27. package/apps/hello-world/vite.config.ts +19 -0
  28. package/apps/hello-world/vitest.config.ts +15 -0
  29. package/apps/hello-world-webpack/.env.development +0 -0
  30. package/apps/hello-world-webpack/.storybook/main.ts +18 -0
  31. package/apps/hello-world-webpack/.storybook/preview.ts +3 -0
  32. package/apps/hello-world-webpack/.stylelintrc.json +5 -0
  33. package/apps/hello-world-webpack/.yarnrc.yml +2 -0
  34. package/apps/hello-world-webpack/README.md +29 -0
  35. package/apps/hello-world-webpack/eslint.config.mjs +25 -0
  36. package/apps/hello-world-webpack/favicon.ico +0 -0
  37. package/apps/hello-world-webpack/index.html +15 -0
  38. package/apps/hello-world-webpack/package-lock.json +10178 -0
  39. package/apps/hello-world-webpack/package.json +55 -0
  40. package/apps/hello-world-webpack/src/main.ts +6 -0
  41. package/apps/hello-world-webpack/src/my-app.css +3 -0
  42. package/apps/hello-world-webpack/src/my-app.html +1 -0
  43. package/apps/hello-world-webpack/src/my-app.stories.ts +12 -0
  44. package/apps/hello-world-webpack/src/my-app.ts +3 -0
  45. package/apps/hello-world-webpack/src/resource.d.ts +13 -0
  46. package/apps/hello-world-webpack/tsconfig.json +18 -0
  47. package/apps/hello-world-webpack/webpack.config.js +111 -0
  48. package/dist/index.js.map +1 -1
  49. package/dist/index.mjs.map +1 -1
  50. package/dist/preset.js +35 -1
  51. package/dist/preset.js.map +1 -1
  52. package/dist/preset.mjs +34 -2
  53. package/dist/preset.mjs.map +1 -1
  54. package/dist/preview/render.js.map +1 -1
  55. package/dist/preview/render.mjs.map +1 -1
  56. package/dist/preview.js +75 -0
  57. package/dist/preview.js.map +1 -0
  58. package/dist/preview.mjs +73 -0
  59. package/dist/preview.mjs.map +1 -0
  60. package/dist/webpack.js +23 -0
  61. package/dist/webpack.js.map +1 -0
  62. package/dist/webpack.mjs +21 -0
  63. package/dist/webpack.mjs.map +1 -0
  64. package/jest.config.js +1 -1
  65. package/package.json +26 -23
  66. package/src/preset.ts +22 -5
  67. package/src/preview.ts +50 -0
  68. package/src/webpack.ts +21 -0
  69. package/__tests__/render.test.d.ts +0 -1
  70. package/dist/index.d.ts +0 -3
  71. package/dist/preset.d.ts +0 -8
  72. package/dist/preview/render.d.ts +0 -17
  73. package/dist/preview/types.d.ts +0 -5
@@ -0,0 +1,73 @@
1
+ import '@storybook/core-events';
2
+ import Aurelia, { CustomElement } from 'aurelia';
3
+
4
+ function bootstrapAureliaApp(story, args, domElement, component) {
5
+ const aurelia = new Aurelia(story.container);
6
+ if (story.items?.length) {
7
+ aurelia.register(...story.items);
8
+ }
9
+ if (story.components?.length) {
10
+ aurelia.register(...story.components);
11
+ }
12
+ let { template } = story;
13
+ if (component) {
14
+ template = template ?? createComponentTemplate(component, story.innerHtml);
15
+ aurelia.register(component);
16
+ }
17
+ const App = CustomElement.define({
18
+ name: 'au-storybook',
19
+ template,
20
+ containerless: true,
21
+ }, class {
22
+ });
23
+ const app = Object.assign(new App(), args);
24
+ return aurelia.app({
25
+ host: domElement,
26
+ component: app,
27
+ });
28
+ }
29
+ function createComponentTemplate(component, innerHtml) {
30
+ const def = CustomElement.getDefinition(component);
31
+ return `<${def.name} ${Object.values(def.bindables)
32
+ .map((bindable) => `${bindable.attribute}.bind="${bindable.name}"`)
33
+ .join(' ')}>${innerHtml ?? ''}</${def.name}>`;
34
+ }
35
+
36
+ // Track the current story's cleanup function
37
+ let currentCleanup = null;
38
+ const render = (args, context) => {
39
+ // Clean up previous story if exists
40
+ if (currentCleanup) {
41
+ currentCleanup();
42
+ currentCleanup = null;
43
+ }
44
+ // Create a container element
45
+ const container = document.createElement('div');
46
+ // Get the story function result
47
+ const story = context.storyFn();
48
+ // Bootstrap Aurelia app immediately
49
+ if (story && (story.Component || story.template)) {
50
+ const app = bootstrapAureliaApp(story, args, container, story.Component || context.component);
51
+ // Start the app asynchronously
52
+ const startPromise = app.start();
53
+ if (startPromise && typeof startPromise.catch === 'function') {
54
+ startPromise.catch((error) => {
55
+ console.error('Failed to start Aurelia app:', error);
56
+ });
57
+ }
58
+ // Set cleanup function
59
+ currentCleanup = () => {
60
+ const stopPromise = app.stop();
61
+ if (stopPromise && typeof stopPromise.catch === 'function') {
62
+ stopPromise.catch((error) => {
63
+ console.error('Failed to stop Aurelia app:', error);
64
+ });
65
+ }
66
+ };
67
+ }
68
+ // Return the container element immediately
69
+ return container;
70
+ };
71
+
72
+ export { render };
73
+ //# sourceMappingURL=preview.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preview.mjs","sources":["../src/preview/render.ts","../src/preview.ts"],"sourcesContent":["import { STORY_CHANGED } from '@storybook/core-events';\nimport type { RenderContext, ArgsStoryFn } from '@storybook/types';\nimport type { AureliaRenderer } from './types';\nimport Aurelia, { Constructable, CustomElement } from 'aurelia';\n\ninterface AureliaStoryResult {\n template: string;\n components?: unknown[];\n Component?: unknown;\n container?: any;\n items?: unknown[];\n innerHtml?: string;\n props?: Record<string, any>;\n}\n\n/**\n * Merges multiple sources into a single object.\n * Sources can be story parameters, args, or story.props.\n */\nfunction mergeStoryProps(\n ...sources: Array<Record<string, any> | undefined>\n): Record<string, any> {\n return Object.assign({}, ...sources);\n}\n\n// Track Aurelia apps for cleanup\nconst appMap = new Map<HTMLElement, Aurelia>();\n\nasync function teardown(element: HTMLElement) {\n if (appMap.has(element)) {\n const app = appMap.get(element);\n if (app) {\n await app.stop();\n appMap.delete(element);\n }\n }\n}\n\nexport const render: ArgsStoryFn<AureliaRenderer> = (args, { id, component: Component }) => {\n if (!Component) {\n throw new Error(\n `Unable to render story ${id} as the component annotation is missing from the default export`\n );\n }\n return { Component, props: args, template: '' };\n};\n\nexport async function renderToCanvas(\n {\n storyFn,\n title,\n name,\n showMain,\n showError,\n storyContext,\n forceRemount,\n }: RenderContext<AureliaRenderer>,\n canvasElement: HTMLElement,\n bootstrapAppFn?: typeof bootstrapAureliaApp\n) {\n const appBootstrapFn = bootstrapAppFn || bootstrapAureliaApp;\n\n const { parameters, component, args } = storyContext;\n let app = appMap.get(canvasElement);\n\n const story = storyFn() as AureliaStoryResult;\n\n if (!story) {\n showError({\n title: `Expecting an Aurelia component from the story: \"${name}\" of \"${title}\".`,\n description: `\n Did you forget to return the Aurelia component from the story?\n Use \"() => ({ template: '<custom-component></custom-component>' })\" when defining the story.\n `,\n });\n return () => {};\n }\n\n showMain();\n\n let mergedProps;\n // Use full merge (including story.props) when bootstrapping a new app or force remounting.\n if (!app || forceRemount) {\n mergedProps = mergeStoryProps(parameters?.args, args, story.props);\n if (app) {\n await teardown(canvasElement);\n }\n app = appBootstrapFn(\n story,\n mergedProps,\n canvasElement,\n component as Constructable\n ) as Aurelia;\n await app.start();\n appMap.set(canvasElement, app);\n } else {\n // Update the existing app viewModel only with parameters and args (exclude story.props).\n mergedProps = mergeStoryProps(parameters?.args, args);\n if (app.root?.controller?.viewModel) {\n Object.assign(app.root.controller.viewModel, mergedProps);\n }\n }\n\n // Set up story change listener for cleanup\n const channel = storyContext.viewMode === 'story' ? storyContext.channel : null;\n let onStoryChange: () => void;\n if (channel) {\n onStoryChange = () => {\n // When the story changes, clean up the Aurelia app\n teardown(canvasElement);\n };\n channel.on(STORY_CHANGED, onStoryChange);\n }\n\n // Return teardown function that also unsubscribes from STORY_CHANGED\n return async () => {\n if (channel && onStoryChange) {\n channel.off(STORY_CHANGED, onStoryChange);\n }\n await teardown(canvasElement);\n };\n}\n\nexport function bootstrapAureliaApp(\n story: AureliaStoryResult,\n args: Record<string, any>,\n domElement: HTMLElement,\n component?: Constructable\n) {\n const aurelia = new Aurelia(story.container);\n\n if (story.items?.length) {\n aurelia.register(...story.items);\n }\n\n if (story.components?.length) {\n aurelia.register(...story.components);\n }\n\n let { template } = story;\n\n if (component) {\n template = template ?? createComponentTemplate(component, story.innerHtml);\n aurelia.register(component);\n }\n\n const App = CustomElement.define(\n {\n name: 'au-storybook',\n template,\n containerless: true,\n },\n class {}\n );\n\n const app = Object.assign(new App(), args);\n\n return aurelia.app({\n host: domElement,\n component: app,\n });\n}\n\nexport function createComponentTemplate(\n component: Constructable,\n innerHtml?: string\n): string {\n const def = CustomElement.getDefinition(component);\n\n return `<${def.name} ${Object.values(def.bindables)\n .map((bindable) => `${bindable.attribute}.bind=\"${bindable.name}\"`)\n .join(' ')}>${innerHtml ?? ''}</${def.name}>`;\n}","import { renderToCanvas, bootstrapAureliaApp } from './preview/render';\nimport Aurelia from 'aurelia';\n\n// Track the current story's cleanup function\nlet currentCleanup: (() => void) | null = null;\n\nexport const render = (args: any, context: any) => {\n // Clean up previous story if exists\n if (currentCleanup) {\n currentCleanup();\n currentCleanup = null;\n }\n\n // Create a container element\n const container = document.createElement('div');\n \n // Get the story function result\n const story = context.storyFn();\n \n // Bootstrap Aurelia app immediately\n if (story && (story.Component || story.template)) {\n const app = bootstrapAureliaApp(\n story,\n args,\n container,\n story.Component || context.component\n ) as Aurelia;\n \n // Start the app asynchronously\n const startPromise = app.start();\n if (startPromise && typeof startPromise.catch === 'function') {\n startPromise.catch((error: any) => {\n console.error('Failed to start Aurelia app:', error);\n });\n }\n \n // Set cleanup function\n currentCleanup = () => {\n const stopPromise = app.stop();\n if (stopPromise && typeof stopPromise.catch === 'function') {\n stopPromise.catch((error: any) => {\n console.error('Failed to stop Aurelia app:', error);\n });\n }\n };\n }\n \n // Return the container element immediately\n return container;\n}; "],"names":[],"mappings":"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"}
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * A set of rules to be added to the webpack configuration.
5
+ * @returns
6
+ */
7
+ function getRules() {
8
+ return [
9
+ {
10
+ test: /\.ts$/i,
11
+ use: ['ts-loader', '@aurelia/webpack-loader'],
12
+ exclude: /node_modules/,
13
+ },
14
+ {
15
+ test: /\.html$/i,
16
+ use: '@aurelia/webpack-loader',
17
+ exclude: /node_modules/,
18
+ },
19
+ ];
20
+ }
21
+
22
+ exports.getRules = getRules;
23
+ //# sourceMappingURL=webpack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.js","sources":["../src/webpack.ts"],"sourcesContent":["// src/webpack.ts\nimport type { RuleSetRule } from 'webpack';\n\n/**\n * A set of rules to be added to the webpack configuration.\n * @returns\n */\nexport function getRules(): RuleSetRule[] {\n return [\n {\n test: /\\.ts$/i,\n use: ['ts-loader', '@aurelia/webpack-loader'],\n exclude: /node_modules/,\n },\n {\n test: /\\.html$/i,\n use: '@aurelia/webpack-loader',\n exclude: /node_modules/,\n },\n ];\n}\n"],"names":[],"mappings":";;AAGA;;;AAGG;SACa,QAAQ,GAAA;IACtB,OAAO;AACL,QAAA;AACE,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,GAAG,EAAE,CAAC,WAAW,EAAE,yBAAyB,CAAC;AAC7C,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;AACD,QAAA;AACE,YAAA,IAAI,EAAE,UAAU;AAChB,YAAA,GAAG,EAAE,yBAAyB;AAC9B,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;KACF;AACH;;;;"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * A set of rules to be added to the webpack configuration.
3
+ * @returns
4
+ */
5
+ function getRules() {
6
+ return [
7
+ {
8
+ test: /\.ts$/i,
9
+ use: ['ts-loader', '@aurelia/webpack-loader'],
10
+ exclude: /node_modules/,
11
+ },
12
+ {
13
+ test: /\.html$/i,
14
+ use: '@aurelia/webpack-loader',
15
+ exclude: /node_modules/,
16
+ },
17
+ ];
18
+ }
19
+
20
+ export { getRules };
21
+ //# sourceMappingURL=webpack.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.mjs","sources":["../src/webpack.ts"],"sourcesContent":["// src/webpack.ts\nimport type { RuleSetRule } from 'webpack';\n\n/**\n * A set of rules to be added to the webpack configuration.\n * @returns\n */\nexport function getRules(): RuleSetRule[] {\n return [\n {\n test: /\\.ts$/i,\n use: ['ts-loader', '@aurelia/webpack-loader'],\n exclude: /node_modules/,\n },\n {\n test: /\\.html$/i,\n use: '@aurelia/webpack-loader',\n exclude: /node_modules/,\n },\n ];\n}\n"],"names":[],"mappings":"AAGA;;;AAGG;SACa,QAAQ,GAAA;IACtB,OAAO;AACL,QAAA;AACE,YAAA,IAAI,EAAE,QAAQ;AACd,YAAA,GAAG,EAAE,CAAC,WAAW,EAAE,yBAAyB,CAAC;AAC7C,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;AACD,QAAA;AACE,YAAA,IAAI,EAAE,UAAU;AAChB,YAAA,GAAG,EAAE,yBAAyB;AAC9B,YAAA,OAAO,EAAE,cAAc;AACxB,SAAA;KACF;AACH;;;;"}
package/jest.config.js CHANGED
@@ -5,5 +5,5 @@ module.exports = {
5
5
  transform: {
6
6
  "^.+\\.tsx?$": ["ts-jest"],
7
7
  },
8
- testMatch: ["**/?(*.)+(spec|test).ts?(x)"]
8
+ testMatch: ["**/__tests__/**/*.test.ts?(x)"]
9
9
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aurelia/storybook",
3
- "version": "0.1.1",
4
- "description": "A Storybook plugin to render Aurelia 2 components using Vite",
3
+ "version": "1.0.0",
4
+ "description": "A Storybook plugin to render Aurelia 2 components using Vite or Webpack",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "module": "dist/index.mjs",
@@ -12,32 +12,35 @@
12
12
  "build": "rollup -c",
13
13
  "build:types": "tsc --project tsconfig.build.json --emitDeclarationOnly",
14
14
  "watch": "rollup -c -w",
15
- "test": "jest"
15
+ "test": "NODE_OPTIONS=--no-deprecation jest"
16
16
  },
17
17
  "peerDependencies": {
18
- "@aurelia/runtime-html": "^2.0.0-beta.23",
19
- "@aurelia/vite-plugin": "^2.0.0-beta.23",
18
+ "@aurelia/runtime-html": "^2.0.0-beta.24",
19
+ "@aurelia/vite-plugin": "^2.0.0-beta.24",
20
20
  "@storybook/addons": "^7.6.17",
21
- "@storybook/builder-vite": "^8.5.3",
22
- "@storybook/core-common": "^8.5.3",
23
- "@storybook/core-events": "^8.5.3",
24
- "aurelia": "^2.0.0-beta.23"
21
+ "@storybook/builder-vite": "^9.0.12",
22
+ "@storybook/builder-webpack5": "^9.0.12",
23
+ "@storybook/core-common": "^8.6.14",
24
+ "@storybook/core-events": "^8.6.14",
25
+ "aurelia": "^2.0.0-beta.24"
25
26
  },
26
27
  "devDependencies": {
27
- "@rollup/plugin-commonjs": "^28.0.2",
28
- "@rollup/plugin-node-resolve": "^16.0.0",
29
- "@rollup/plugin-typescript": "^12.1.2",
30
- "@storybook/builder-vite": "^8.5.3",
31
- "@storybook/core-common": "^8.5.3",
32
- "@storybook/preview-api": "^8.5.3",
33
- "@storybook/types": "^8.5.3",
34
- "@types/jest": "^29.5.14",
35
- "glob": "^11.0.1",
36
- "jest": "^29.7.0",
37
- "jest-environment-jsdom": "^29.7.0",
38
- "rollup": "^4.34.2",
39
- "ts-jest": "^29.2.5",
40
- "typescript": "^5.7.3"
28
+ "@aurelia/webpack-loader": "^2.0.0-beta.24",
29
+ "@rollup/plugin-commonjs": "^28.0.6",
30
+ "@rollup/plugin-node-resolve": "^16.0.1",
31
+ "@rollup/plugin-typescript": "^12.1.3",
32
+ "@storybook/builder-vite": "^9.0.12",
33
+ "@storybook/core-common": "^8.6.14",
34
+ "@storybook/preview-api": "^8.6.14",
35
+ "@storybook/types": "^8.6.14",
36
+ "@types/jest": "^30.0.0",
37
+ "glob": "^11.0.3",
38
+ "jest": "^30.0.2",
39
+ "jest-environment-jsdom": "^30.0.2",
40
+ "rollup": "^4.44.0",
41
+ "ts-jest": "^29.4.0",
42
+ "ts-loader": "^9.5.2",
43
+ "typescript": "^5.8.3"
41
44
  },
42
45
  "exports": {
43
46
  ".": {
package/src/preset.ts CHANGED
@@ -1,14 +1,31 @@
1
1
  // src/preset.ts
2
2
  // Minimal preset for Storybook-Aurelia2
3
3
 
4
+ import { getRules } from './webpack';
5
+
4
6
  /**
5
7
  * Optionally adjust the Vite configuration.
6
8
  */
7
9
  export async function viteFinal(config: any): Promise<any> {
8
10
  // For now, return the config unchanged.
9
11
  return config;
10
- }
11
-
12
- // Export a default for compatibility.
13
- export default { viteFinal };
14
-
12
+ }
13
+
14
+ /**
15
+ * A function to configure webpack.
16
+ * @param config
17
+ * @returns
18
+ */
19
+ export async function webpackFinal(config: any): Promise<any> {
20
+ const rules = config.module?.rules;
21
+ if (rules) {
22
+ rules.push(...getRules());
23
+ }
24
+
25
+ return config;
26
+ }
27
+
28
+ // Export a default for compatibility.
29
+ export default { viteFinal, webpackFinal };
30
+
31
+ export const previewAnnotations = [require.resolve('./preview')];
package/src/preview.ts ADDED
@@ -0,0 +1,50 @@
1
+ import { renderToCanvas, bootstrapAureliaApp } from './preview/render';
2
+ import Aurelia from 'aurelia';
3
+
4
+ // Track the current story's cleanup function
5
+ let currentCleanup: (() => void) | null = null;
6
+
7
+ export const render = (args: any, context: any) => {
8
+ // Clean up previous story if exists
9
+ if (currentCleanup) {
10
+ currentCleanup();
11
+ currentCleanup = null;
12
+ }
13
+
14
+ // Create a container element
15
+ const container = document.createElement('div');
16
+
17
+ // Get the story function result
18
+ const story = context.storyFn();
19
+
20
+ // Bootstrap Aurelia app immediately
21
+ if (story && (story.Component || story.template)) {
22
+ const app = bootstrapAureliaApp(
23
+ story,
24
+ args,
25
+ container,
26
+ story.Component || context.component
27
+ ) as Aurelia;
28
+
29
+ // Start the app asynchronously
30
+ const startPromise = app.start();
31
+ if (startPromise && typeof startPromise.catch === 'function') {
32
+ startPromise.catch((error: any) => {
33
+ console.error('Failed to start Aurelia app:', error);
34
+ });
35
+ }
36
+
37
+ // Set cleanup function
38
+ currentCleanup = () => {
39
+ const stopPromise = app.stop();
40
+ if (stopPromise && typeof stopPromise.catch === 'function') {
41
+ stopPromise.catch((error: any) => {
42
+ console.error('Failed to stop Aurelia app:', error);
43
+ });
44
+ }
45
+ };
46
+ }
47
+
48
+ // Return the container element immediately
49
+ return container;
50
+ };
package/src/webpack.ts ADDED
@@ -0,0 +1,21 @@
1
+ // src/webpack.ts
2
+ import type { RuleSetRule } from 'webpack';
3
+
4
+ /**
5
+ * A set of rules to be added to the webpack configuration.
6
+ * @returns
7
+ */
8
+ export function getRules(): RuleSetRule[] {
9
+ return [
10
+ {
11
+ test: /\.ts$/i,
12
+ use: ['ts-loader', '@aurelia/webpack-loader'],
13
+ exclude: /node_modules/,
14
+ },
15
+ {
16
+ test: /\.html$/i,
17
+ use: '@aurelia/webpack-loader',
18
+ exclude: /node_modules/,
19
+ },
20
+ ];
21
+ }
@@ -1 +0,0 @@
1
- export {};
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { renderToCanvas } from './preview/render';
2
- export { renderToCanvas };
3
- export declare const render: typeof renderToCanvas;
package/dist/preset.d.ts DELETED
@@ -1,8 +0,0 @@
1
- /**
2
- * Optionally adjust the Vite configuration.
3
- */
4
- export declare function viteFinal(config: any): Promise<any>;
5
- declare const _default: {
6
- viteFinal: typeof viteFinal;
7
- };
8
- export default _default;
@@ -1,17 +0,0 @@
1
- import type { RenderContext, ArgsStoryFn } from '@storybook/types';
2
- import type { AureliaRenderer } from './types';
3
- import Aurelia, { Constructable } from 'aurelia';
4
- interface AureliaStoryResult {
5
- template: string;
6
- components?: unknown[];
7
- Component?: unknown;
8
- container?: any;
9
- items?: unknown[];
10
- innerHtml?: string;
11
- props?: Record<string, any>;
12
- }
13
- export declare const render: ArgsStoryFn<AureliaRenderer>;
14
- export declare function renderToCanvas({ storyFn, title, name, showMain, showError, storyContext, forceRemount, }: RenderContext<AureliaRenderer>, canvasElement: HTMLElement, bootstrapAppFn?: typeof bootstrapAureliaApp): Promise<() => void>;
15
- export declare function bootstrapAureliaApp(story: AureliaStoryResult, args: Record<string, any>, domElement: HTMLElement, component?: Constructable): Omit<Aurelia, "enhance" | "register" | "app">;
16
- export declare function createComponentTemplate(component: Constructable, innerHtml?: string): string;
17
- export {};
@@ -1,5 +0,0 @@
1
- import type { Renderer } from '@storybook/types';
2
- export interface AureliaRenderer extends Renderer {
3
- /** The DOM element in which the story is rendered */
4
- canvasElement: HTMLElement;
5
- }