@analogjs/storybook-angular 3.0.0-alpha.4 → 3.0.0-alpha.40

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@analogjs/storybook-angular",
3
- "version": "3.0.0-alpha.4",
3
+ "version": "3.0.0-alpha.40",
4
4
  "description": "Storybook Integration for Angular & Vite",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -34,20 +34,21 @@
34
34
  "default": "./src/lib/testing.js"
35
35
  }
36
36
  },
37
- "main": "src/index.js",
37
+ "main": "./src/index.js",
38
38
  "dependencies": {
39
- "@storybook/builder-vite": "^10.0.0"
39
+ "@storybook/builder-vite": "^10.3.5",
40
+ "obug": "^2.1.1"
40
41
  },
41
42
  "peerDependencies": {
42
43
  "@storybook/angular": "^10.0.0",
43
44
  "@analogjs/vite-plugin-angular": "*",
44
45
  "storybook": "^10.0.0",
45
- "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
46
+ "vite": "^6.0.0 || ^7.0.0 || ^8.0.0"
46
47
  },
47
48
  "engines": {
48
- "node": ">=20.0.0"
49
+ "node": ">=22.18.0 || >=24.3.0"
49
50
  },
50
- "builders": "src/lib/builders.json",
51
+ "builders": "./src/lib/builders.json",
51
52
  "ng-add": {
52
53
  "save": "devDependencies"
53
54
  },
@@ -65,7 +66,5 @@
65
66
  "publishConfig": {
66
67
  "access": "public",
67
68
  "provenance": true
68
- },
69
- "types": "./src/index.d.ts",
70
- "module": "./src/index.js"
71
- }
69
+ }
70
+ }
package/preset.js CHANGED
@@ -1 +1 @@
1
- export * from './src/lib/preset.js';
1
+ export * from './dist/src/lib/preset.js';
package/src/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
- export { type AngularOptions, type Parameters as AngularParameters, type AngularRenderer, type Decorator, type IStory, type Loader, type Meta, type Preview, type StoryContext, type StoryFn, type StoryObj, applicationConfig, argsToTemplate, componentWrapperDecorator, moduleMetadata, setProjectAnnotations, } from '@storybook/angular';
2
- export { type FrameworkOptions, type StorybookConfig } from './types';
1
+ export { type AngularOptions, type Parameters as AngularParameters, type AngularRenderer, type Decorator, type IStory, type Loader, type Meta, type Preview, type StoryContext, type StoryFn, type StoryObj, applicationConfig, argsToTemplate, moduleMetadata, setProjectAnnotations } from "@storybook/angular";
2
+ export { componentWrapperDecorator } from "./lib/component-wrapper-decorator";
3
+ export { type FrameworkOptions, type StorybookConfig } from "./types";
package/src/index.js CHANGED
@@ -1,2 +1,3 @@
1
- export { applicationConfig, argsToTemplate, componentWrapperDecorator, moduleMetadata, setProjectAnnotations, } from '@storybook/angular';
2
- //# sourceMappingURL=index.js.map
1
+ import { componentWrapperDecorator } from "./lib/component-wrapper-decorator.js";
2
+ import { applicationConfig, argsToTemplate, moduleMetadata, setProjectAnnotations } from "@storybook/angular";
3
+ export { applicationConfig, argsToTemplate, componentWrapperDecorator, moduleMetadata, setProjectAnnotations };
@@ -1,2 +1,2 @@
1
- import BuildStorybookBuilder from '@storybook/angular/builders/build-storybook';
1
+ import BuildStorybookBuilder from "@storybook/angular/builders/build-storybook";
2
2
  export default BuildStorybookBuilder;
@@ -1,3 +1,7 @@
1
- import BuildStorybookBuilder from '@storybook/angular/builders/build-storybook';
2
- export default BuildStorybookBuilder;
1
+ import BuildStorybookBuilder from "@storybook/angular/builders/build-storybook";
2
+ //#region packages/storybook-angular/src/lib/build-storybook/build-storybook.ts
3
+ var build_storybook_default = BuildStorybookBuilder;
4
+ //#endregion
5
+ export { build_storybook_default as default };
6
+
3
7
  //# sourceMappingURL=build-storybook.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build-storybook.js","sourceRoot":"","sources":["../../../../../../packages/storybook-angular/src/lib/build-storybook/build-storybook.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,6CAA6C,CAAC;AAEhF,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"build-storybook.js","names":[],"sources":["../../../../src/lib/build-storybook/build-storybook.ts"],"sourcesContent":["import BuildStorybookBuilder from '@storybook/angular/builders/build-storybook';\n\nexport default BuildStorybookBuilder;\n"],"mappings":";;AAEA,IAAA,0BAAe"}
@@ -0,0 +1,6 @@
1
+ import { type Type } from "@angular/core";
2
+ import { type AngularRenderer, type StoryContext } from "@storybook/angular";
3
+ import type { DecoratorFunction } from "storybook/internal/types";
4
+ type StoryProps = Record<string, unknown>;
5
+ export declare function componentWrapperDecorator<TArgs = any>(element: Type<unknown> | ((story: string) => string), props?: StoryProps | ((storyContext: StoryContext<TArgs>) => StoryProps)): DecoratorFunction<AngularRenderer, TArgs>;
6
+ export {};
@@ -0,0 +1,66 @@
1
+ import { argsToTemplate, componentWrapperDecorator } from "@storybook/angular";
2
+ import { reflectComponentType } from "@angular/core";
3
+ //#region packages/storybook-angular/src/lib/component-wrapper-decorator.ts
4
+ var VOID_ELEMENTS = new Set([
5
+ "area",
6
+ "base",
7
+ "br",
8
+ "col",
9
+ "command",
10
+ "embed",
11
+ "hr",
12
+ "img",
13
+ "input",
14
+ "keygen",
15
+ "link",
16
+ "meta",
17
+ "param",
18
+ "source",
19
+ "track",
20
+ "wbr"
21
+ ]);
22
+ function componentWrapperDecorator$1(element, props) {
23
+ const decorator = componentWrapperDecorator(element, props);
24
+ return (storyFn, storyContext) => decorator(() => ensureStoryTemplate(storyFn(), storyContext), storyContext);
25
+ }
26
+ function ensureStoryTemplate(story, storyContext) {
27
+ if (story.template || !storyContext.component) return story;
28
+ const component = reflectComponentType(storyContext.component);
29
+ if (!component) return story;
30
+ return {
31
+ ...story,
32
+ template: createTemplate(component, story.props ?? storyContext.args),
33
+ userDefinedTemplate: false
34
+ };
35
+ }
36
+ function createTemplate(component, props) {
37
+ const selector = component.selector.split(",")[0]?.trim();
38
+ if (!selector) return "<ng-container *ngComponentOutlet=\"storyComponent\"></ng-container>";
39
+ return buildTemplate(selector, argsToTemplate(filterTemplateBindings(component, props)));
40
+ }
41
+ function filterTemplateBindings(component, props) {
42
+ if (!props || typeof props !== "object") return {};
43
+ const supportedBindings = new Set([...component.inputs.map((input) => input.templateName), ...component.outputs.map((output) => output.templateName)]);
44
+ return Object.fromEntries(Object.entries(props).filter(([key, value]) => {
45
+ return value !== void 0 && supportedBindings.has(key);
46
+ }));
47
+ }
48
+ function buildTemplate(selector, attributes) {
49
+ const tagName = selector.match(/^[A-Za-z][\w-]*/)?.[0] ?? "div";
50
+ const id = selector.match(/#([\w-]+)/)?.[1];
51
+ const classes = [...selector.matchAll(/\.([\w-]+)/g)].map((match) => match[1]);
52
+ const selectorAttributes = [...selector.matchAll(/\[([^\]]+)\]/g)].map((match) => match[1].trim());
53
+ const parts = [
54
+ id ? `id="${id}"` : "",
55
+ classes.length > 0 ? `class="${classes.join(" ")}"` : "",
56
+ ...selectorAttributes,
57
+ attributes
58
+ ].filter(Boolean);
59
+ const openingTag = parts.length > 0 ? `<${tagName} ${parts.join(" ")}>` : `<${tagName}>`;
60
+ if (VOID_ELEMENTS.has(tagName)) return openingTag.replace(/>$/, " />");
61
+ return `${openingTag}</${tagName}>`;
62
+ }
63
+ //#endregion
64
+ export { componentWrapperDecorator$1 as componentWrapperDecorator };
65
+
66
+ //# sourceMappingURL=component-wrapper-decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"component-wrapper-decorator.js","names":[],"sources":["../../../src/lib/component-wrapper-decorator.ts"],"sourcesContent":["import {\n reflectComponentType,\n type ComponentMirror,\n type Type,\n} from '@angular/core';\nimport {\n argsToTemplate,\n componentWrapperDecorator as originalComponentWrapperDecorator,\n type AngularRenderer,\n type IStory,\n type StoryContext,\n} from '@storybook/angular';\nimport type { DecoratorFunction } from 'storybook/internal/types';\n\ntype StoryProps = Record<string, unknown>;\n\nconst VOID_ELEMENTS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'command',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'keygen',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n]);\n\nexport function componentWrapperDecorator<TArgs = any>(\n element: Type<unknown> | ((story: string) => string),\n props?: StoryProps | ((storyContext: StoryContext<TArgs>) => StoryProps),\n): DecoratorFunction<AngularRenderer, TArgs> {\n const decorator = originalComponentWrapperDecorator(element, props);\n\n return (storyFn, storyContext) =>\n decorator(() => ensureStoryTemplate(storyFn(), storyContext), storyContext);\n}\n\nfunction ensureStoryTemplate<TArgs>(\n story: IStory,\n storyContext: StoryContext<TArgs>,\n): IStory {\n if (story.template || !storyContext.component) {\n return story;\n }\n\n const component = reflectComponentType(\n storyContext.component as Type<unknown>,\n );\n\n if (!component) {\n return story;\n }\n\n return {\n ...story,\n template: createTemplate(component, story.props ?? storyContext.args),\n userDefinedTemplate: false,\n };\n}\n\nfunction createTemplate(\n component: ComponentMirror<unknown>,\n props: unknown,\n): string {\n const selector = component.selector.split(',')[0]?.trim();\n if (!selector) {\n return '<ng-container *ngComponentOutlet=\"storyComponent\"></ng-container>';\n }\n\n const bindings = filterTemplateBindings(component, props);\n const attributes = argsToTemplate(bindings);\n\n return buildTemplate(selector, attributes);\n}\n\nfunction filterTemplateBindings(\n component: ComponentMirror<unknown>,\n props: unknown,\n): StoryProps {\n if (!props || typeof props !== 'object') {\n return {};\n }\n\n const supportedBindings = new Set([\n ...component.inputs.map((input) => input.templateName),\n ...component.outputs.map((output) => output.templateName),\n ]);\n\n return Object.fromEntries(\n Object.entries(props).filter(([key, value]) => {\n return value !== undefined && supportedBindings.has(key);\n }),\n );\n}\n\nfunction buildTemplate(selector: string, attributes: string): string {\n const elementMatch = selector.match(/^[A-Za-z][\\w-]*/);\n const tagName = elementMatch?.[0] ?? 'div';\n const id = selector.match(/#([\\w-]+)/)?.[1];\n const classes = [...selector.matchAll(/\\.([\\w-]+)/g)].map(\n (match) => match[1],\n );\n const selectorAttributes = [...selector.matchAll(/\\[([^\\]]+)\\]/g)].map(\n (match) => match[1].trim(),\n );\n const parts = [\n id ? `id=\"${id}\"` : '',\n classes.length > 0 ? `class=\"${classes.join(' ')}\"` : '',\n ...selectorAttributes,\n attributes,\n ].filter(Boolean);\n const openingTag =\n parts.length > 0 ? `<${tagName} ${parts.join(' ')}>` : `<${tagName}>`;\n\n if (VOID_ELEMENTS.has(tagName)) {\n return openingTag.replace(/>$/, ' />');\n }\n\n return `${openingTag}</${tagName}>`;\n}\n"],"mappings":";;;AAgBA,IAAM,gBAAgB,IAAI,IAAI;CAC5B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;AAEF,SAAgB,4BACd,SACA,OAC2C;CAC3C,MAAM,YAAY,0BAAkC,SAAS,MAAM;AAEnE,SAAQ,SAAS,iBACf,gBAAgB,oBAAoB,SAAS,EAAE,aAAa,EAAE,aAAa;;AAG/E,SAAS,oBACP,OACA,cACQ;AACR,KAAI,MAAM,YAAY,CAAC,aAAa,UAClC,QAAO;CAGT,MAAM,YAAY,qBAChB,aAAa,UACd;AAED,KAAI,CAAC,UACH,QAAO;AAGT,QAAO;EACL,GAAG;EACH,UAAU,eAAe,WAAW,MAAM,SAAS,aAAa,KAAK;EACrE,qBAAqB;EACtB;;AAGH,SAAS,eACP,WACA,OACQ;CACR,MAAM,WAAW,UAAU,SAAS,MAAM,IAAI,CAAC,IAAI,MAAM;AACzD,KAAI,CAAC,SACH,QAAO;AAMT,QAAO,cAAc,UAFF,eADF,uBAAuB,WAAW,MAAM,CACd,CAED;;AAG5C,SAAS,uBACP,WACA,OACY;AACZ,KAAI,CAAC,SAAS,OAAO,UAAU,SAC7B,QAAO,EAAE;CAGX,MAAM,oBAAoB,IAAI,IAAI,CAChC,GAAG,UAAU,OAAO,KAAK,UAAU,MAAM,aAAa,EACtD,GAAG,UAAU,QAAQ,KAAK,WAAW,OAAO,aAAa,CAC1D,CAAC;AAEF,QAAO,OAAO,YACZ,OAAO,QAAQ,MAAM,CAAC,QAAQ,CAAC,KAAK,WAAW;AAC7C,SAAO,UAAU,KAAA,KAAa,kBAAkB,IAAI,IAAI;GACxD,CACH;;AAGH,SAAS,cAAc,UAAkB,YAA4B;CAEnE,MAAM,UADe,SAAS,MAAM,kBAAkB,GACvB,MAAM;CACrC,MAAM,KAAK,SAAS,MAAM,YAAY,GAAG;CACzC,MAAM,UAAU,CAAC,GAAG,SAAS,SAAS,cAAc,CAAC,CAAC,KACnD,UAAU,MAAM,GAClB;CACD,MAAM,qBAAqB,CAAC,GAAG,SAAS,SAAS,gBAAgB,CAAC,CAAC,KAChE,UAAU,MAAM,GAAG,MAAM,CAC3B;CACD,MAAM,QAAQ;EACZ,KAAK,OAAO,GAAG,KAAK;EACpB,QAAQ,SAAS,IAAI,UAAU,QAAQ,KAAK,IAAI,CAAC,KAAK;EACtD,GAAG;EACH;EACD,CAAC,OAAO,QAAQ;CACjB,MAAM,aACJ,MAAM,SAAS,IAAI,IAAI,QAAQ,GAAG,MAAM,KAAK,IAAI,CAAC,KAAK,IAAI,QAAQ;AAErE,KAAI,cAAc,IAAI,QAAQ,CAC5B,QAAO,WAAW,QAAQ,MAAM,MAAM;AAGxC,QAAO,GAAG,WAAW,IAAI,QAAQ"}
@@ -0,0 +1 @@
1
+ export declare const debugStyles: unknown;
@@ -0,0 +1,7 @@
1
+ import { createDebug } from "../../node_modules/.pnpm/obug@2.1.1/node_modules/obug/dist/browser.js";
2
+ //#region packages/storybook-angular/src/lib/debug.ts
3
+ var debugStyles = createDebug("analog-storybook:styles");
4
+ //#endregion
5
+ export { debugStyles };
6
+
7
+ //# sourceMappingURL=debug.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.js","names":[],"sources":["../../../src/lib/debug.ts"],"sourcesContent":["import { createDebug } from 'obug';\n\nexport const debugStyles = createDebug('analog-storybook:styles');\n"],"mappings":";;AAEA,IAAa,cAAc,YAAY,0BAA0B"}
@@ -1,4 +1,4 @@
1
1
  export declare const previewAnnotations: (entries: string[] | undefined, options: any) => Promise<string[]>;
2
2
  export declare const core: (config: any, options: any) => Promise<any>;
3
3
  export declare const viteFinal: (config: any, options: any) => Promise<any>;
4
- export { addons } from '@storybook/angular/preset';
4
+ export { addons } from "@storybook/angular/preset";
package/src/lib/preset.js CHANGED
@@ -1,173 +1,162 @@
1
- import { resolve } from 'node:path';
2
- import { core as PresetCore } from '@storybook/angular/preset';
3
- import { fileURLToPath } from 'node:url';
4
- export const previewAnnotations = async (entries = [], options) => {
5
- const config = fileURLToPath(import.meta.resolve('@storybook/angular/client/config'));
6
- const annotations = [...entries, config];
7
- if (options.enableProdMode) {
8
- const previewProdPath = fileURLToPath(import.meta.resolve('@storybook/angular/client/preview-prod'));
9
- annotations.unshift(previewProdPath);
10
- }
11
- const docsConfig = await options.presets.apply('docs', {}, options);
12
- const docsEnabled = Object.keys(docsConfig).length > 0;
13
- if (docsEnabled) {
14
- const docsConfigPath = fileURLToPath(import.meta.resolve('@storybook/angular/client/docs/config'));
15
- annotations.push(docsConfigPath);
16
- }
17
- return annotations;
1
+ import { debugStyles } from "./debug.js";
2
+ import { existsSync } from "node:fs";
3
+ import { resolve } from "node:path";
4
+ import { addons, core as core$1 } from "@storybook/angular/preset";
5
+ import { fileURLToPath } from "node:url";
6
+ import * as vite from "vite";
7
+ import angular from "@analogjs/vite-plugin-angular";
8
+ //#region packages/storybook-angular/src/lib/preset.ts
9
+ var previewAnnotations = async (entries = [], options) => {
10
+ const config = fileURLToPath(import.meta.resolve("@storybook/angular/client/config"));
11
+ const annotations = [...entries, config];
12
+ if (options.enableProdMode) {
13
+ const previewProdPath = fileURLToPath(import.meta.resolve("@storybook/angular/client/preview-prod"));
14
+ annotations.unshift(previewProdPath);
15
+ }
16
+ const docsConfig = await options.presets.apply("docs", {}, options);
17
+ if (Object.keys(docsConfig).length > 0) {
18
+ const docsConfigPath = fileURLToPath(import.meta.resolve("@storybook/angular/client/docs/config"));
19
+ annotations.push(docsConfigPath);
20
+ }
21
+ return annotations;
18
22
  };
19
- export const core = async (config, options) => {
20
- const presetCore = await PresetCore(config, options);
21
- return {
22
- ...presetCore,
23
- builder: {
24
- name: import.meta.resolve('@storybook/builder-vite'),
25
- options: { ...presetCore.options },
26
- },
27
- };
23
+ var core = async (config, options) => {
24
+ const presetCore = await core$1(config, options);
25
+ return {
26
+ ...presetCore,
27
+ builder: {
28
+ name: import.meta.resolve("@storybook/builder-vite"),
29
+ options: { ...presetCore.options }
30
+ }
31
+ };
28
32
  };
29
33
  async function resolveExperimentalZoneless(frameworkOptions, angularBuilderOptions) {
30
- // 1. Explicit framework option (user's .storybook/main.ts)
31
- if (typeof frameworkOptions?.experimentalZoneless === 'boolean') {
32
- return frameworkOptions.experimentalZoneless;
33
- }
34
- // 2. Angular builder options (set by start-storybook/build-storybook)
35
- if (typeof angularBuilderOptions?.experimentalZoneless === 'boolean') {
36
- return angularBuilderOptions.experimentalZoneless;
37
- }
38
- // 3. Auto-detect Angular 21+ (matches @storybook/angular builder behavior)
39
- try {
40
- const { VERSION } = await import('@angular/core');
41
- return !!(VERSION.major && Number(VERSION.major) >= 21);
42
- }
43
- catch {
44
- return false;
45
- }
34
+ if (typeof frameworkOptions?.experimentalZoneless === "boolean") return frameworkOptions.experimentalZoneless;
35
+ if (typeof angularBuilderOptions?.experimentalZoneless === "boolean") return angularBuilderOptions.experimentalZoneless;
36
+ try {
37
+ const { VERSION } = await import("@angular/core");
38
+ return !!(VERSION.major && Number(VERSION.major) >= 21);
39
+ } catch {
40
+ return false;
41
+ }
46
42
  }
47
- export const viteFinal = async (config, options) => {
48
- // Remove any loaded analogjs plugins from a vite.config.(m)ts file
49
- config.plugins = (config.plugins ?? [])
50
- .flat()
51
- .filter((plugin) => !plugin.name.includes('analogjs'));
52
- // Merge custom configuration into the default config
53
- const { mergeConfig, normalizePath } = await import('vite');
54
- const { default: angular } = await import('@analogjs/vite-plugin-angular');
55
- const framework = await options.presets.apply('framework');
56
- const experimentalZoneless = await resolveExperimentalZoneless(framework.options, options?.angularBuilderOptions);
57
- return mergeConfig(config, {
58
- // Add dependencies to pre-optimization
59
- optimizeDeps: {
60
- include: [
61
- '@storybook/angular/client',
62
- '@analogjs/storybook-angular',
63
- '@angular/compiler',
64
- '@angular/platform-browser',
65
- '@angular/platform-browser/animations',
66
- 'tslib',
67
- ...(experimentalZoneless ? [] : ['zone.js']),
68
- ],
69
- },
70
- plugins: [
71
- angular({
72
- jit: typeof framework.options?.jit !== 'undefined'
73
- ? framework.options?.jit
74
- : true,
75
- liveReload: typeof framework.options?.liveReload !== 'undefined'
76
- ? framework.options?.liveReload
77
- : false,
78
- tsconfig: typeof framework.options?.tsconfig !== 'undefined'
79
- ? framework.options?.tsconfig
80
- : (options?.tsConfig ?? './.storybook/tsconfig.json'),
81
- inlineStylesExtension: typeof framework.options?.inlineStylesExtension !== 'undefined'
82
- ? framework.options?.inlineStylesExtension
83
- : 'css',
84
- }),
85
- angularOptionsPlugin(options, { normalizePath, experimentalZoneless }),
86
- storybookEsbuildPlugin(),
87
- ],
88
- define: {
89
- STORYBOOK_ANGULAR_OPTIONS: JSON.stringify({
90
- experimentalZoneless: !!experimentalZoneless,
91
- }),
92
- },
93
- });
43
+ var viteFinal = async (config, options) => {
44
+ config.plugins = (config.plugins ?? []).flat().filter((plugin) => !plugin.name.includes("analogjs"));
45
+ const { hmr: _removedHmrOption, ...frameworkOptions } = (await options.presets.apply("framework")).options ?? {};
46
+ const experimentalZoneless = await resolveExperimentalZoneless(frameworkOptions, options?.angularBuilderOptions);
47
+ const liveReload = typeof frameworkOptions.liveReload !== "undefined" ? frameworkOptions.liveReload : false;
48
+ return vite.mergeConfig(config, {
49
+ optimizeDeps: { include: [
50
+ "@storybook/angular/client",
51
+ "@analogjs/storybook-angular",
52
+ "@angular/compiler",
53
+ "@angular/platform-browser",
54
+ "@angular/platform-browser/animations",
55
+ "tslib",
56
+ ...experimentalZoneless ? [] : ["zone.js"]
57
+ ] },
58
+ resolve: { alias: { "@storybook/globalThis": "@storybook/global" } },
59
+ plugins: [
60
+ angular({
61
+ jit: typeof frameworkOptions.jit !== "undefined" ? frameworkOptions.jit : true,
62
+ liveReload,
63
+ tsconfig: typeof frameworkOptions.tsconfig !== "undefined" ? frameworkOptions.tsconfig : options?.tsConfig ?? "./.storybook/tsconfig.json",
64
+ inlineStylesExtension: typeof frameworkOptions.inlineStylesExtension !== "undefined" ? frameworkOptions.inlineStylesExtension : "css"
65
+ }),
66
+ angularOptionsPlugin(options, {
67
+ normalizePath: vite.normalizePath,
68
+ experimentalZoneless
69
+ }),
70
+ storybookTransformConfigPlugin()
71
+ ],
72
+ define: { STORYBOOK_ANGULAR_OPTIONS: JSON.stringify({ experimentalZoneless: !!experimentalZoneless }) }
73
+ });
94
74
  };
95
- function angularOptionsPlugin(options, { normalizePath, experimentalZoneless, }) {
96
- let resolvedConfig;
97
- return {
98
- name: 'analogjs-storybook-options-plugin',
99
- config(userConfig) {
100
- resolvedConfig = userConfig;
101
- const loadPaths = options?.angularBuilderOptions?.stylePreprocessorOptions?.loadPaths;
102
- const sassOptions = options?.angularBuilderOptions?.stylePreprocessorOptions?.sass;
103
- if (Array.isArray(loadPaths)) {
104
- const workspaceRoot = options.angularBuilderContext?.workspaceRoot ??
105
- userConfig?.root ??
106
- process.cwd();
107
- return {
108
- css: {
109
- preprocessorOptions: {
110
- scss: {
111
- ...sassOptions,
112
- loadPaths: loadPaths.map((loadPath) => `${resolve(workspaceRoot, loadPath)}`),
113
- },
114
- },
115
- },
116
- };
117
- }
118
- return;
119
- },
120
- async transform(code, id) {
121
- if (normalizePath(id).endsWith(normalizePath(`${options.configDir}/preview.ts`))) {
122
- const imports = [];
123
- const styles = options?.angularBuilderOptions?.styles;
124
- if (Array.isArray(styles)) {
125
- styles.forEach((style) => {
126
- imports.push(style);
127
- });
128
- }
129
- if (!experimentalZoneless) {
130
- imports.push('zone.js');
131
- }
132
- // Use vite config root when angularBuilderContext is not available
133
- // (e.g., when running via Vitest instead of Angular builders)
134
- const projectRoot = resolvedConfig?.root ?? process.cwd();
135
- return {
136
- code: `
137
- ${imports
138
- .map((extraImport) => {
139
- if (extraImport.startsWith('.') ||
140
- extraImport.startsWith('src')) {
141
- // relative to root
142
- return `import '${resolve(projectRoot, extraImport)}';`;
143
- }
144
- // absolute import
145
- return `import '${extraImport}';`;
146
- })
147
- .join('\n')}
75
+ function angularOptionsPlugin(options, { normalizePath, experimentalZoneless }) {
76
+ let resolvedConfig;
77
+ const resolveStyleImport = (extraImport, projectRoot, workspaceRoot) => {
78
+ const resolvedProjectImport = resolve(projectRoot, extraImport);
79
+ const resolvedWorkspaceImport = resolve(workspaceRoot, extraImport);
80
+ if (extraImport.startsWith(".") || extraImport.startsWith("src") || existsSync(resolvedProjectImport)) return {
81
+ specifier: resolvedProjectImport,
82
+ source: "project"
83
+ };
84
+ if (existsSync(resolvedWorkspaceImport)) return {
85
+ specifier: resolvedWorkspaceImport,
86
+ source: "workspace"
87
+ };
88
+ return {
89
+ specifier: extraImport,
90
+ source: "bare"
91
+ };
92
+ };
93
+ return {
94
+ name: "analogjs-storybook-options-plugin",
95
+ config(userConfig) {
96
+ resolvedConfig = userConfig;
97
+ const loadPaths = options?.angularBuilderOptions?.stylePreprocessorOptions?.loadPaths;
98
+ const sassOptions = options?.angularBuilderOptions?.stylePreprocessorOptions?.sass;
99
+ if (Array.isArray(loadPaths)) {
100
+ const workspaceRoot = options.angularBuilderContext?.workspaceRoot ?? userConfig?.root ?? process.cwd();
101
+ const resolvedLoadPaths = loadPaths.map((loadPath) => `${resolve(workspaceRoot, loadPath)}`);
102
+ debugStyles("resolved SCSS load paths", {
103
+ configDir: options.configDir,
104
+ workspaceRoot,
105
+ projectRoot: userConfig?.root ?? process.cwd(),
106
+ loadPaths,
107
+ resolvedLoadPaths
108
+ });
109
+ return { css: { preprocessorOptions: { scss: {
110
+ ...sassOptions,
111
+ loadPaths: resolvedLoadPaths
112
+ } } } };
113
+ }
114
+ },
115
+ async transform(code, id) {
116
+ if (normalizePath(id).endsWith(normalizePath(`${options.configDir}/preview.ts`))) {
117
+ const imports = [];
118
+ const styles = options?.angularBuilderOptions?.styles;
119
+ const workspaceRoot = options?.angularBuilderContext?.workspaceRoot ?? process.cwd();
120
+ if (Array.isArray(styles)) {
121
+ debugStyles("injecting Storybook global styles", {
122
+ configDir: options.configDir,
123
+ workspaceRoot,
124
+ projectRoot: resolvedConfig?.root ?? process.cwd(),
125
+ styles
126
+ });
127
+ styles.forEach((style) => {
128
+ imports.push(style);
129
+ });
130
+ }
131
+ if (!experimentalZoneless) imports.push("zone.js");
132
+ const projectRoot = resolvedConfig?.root ?? process.cwd();
133
+ return { code: `
134
+ ${imports.map((extraImport) => {
135
+ const resolved = resolveStyleImport(extraImport, projectRoot, workspaceRoot);
136
+ debugStyles("resolved Storybook style import", {
137
+ input: extraImport,
138
+ source: resolved.source,
139
+ specifier: resolved.specifier
140
+ });
141
+ return `import '${resolved.specifier}';`;
142
+ }).join("\n")}
148
143
  ${code}
149
- `,
150
- };
151
- }
152
- return;
153
- },
154
- };
144
+ ` };
145
+ }
146
+ }
147
+ };
155
148
  }
156
- function storybookEsbuildPlugin() {
157
- return {
158
- name: 'analogjs-storybook-esbuild-config',
159
- apply: 'build',
160
- config() {
161
- return {
162
- esbuild: {
163
- // Don't mangle class names during the build
164
- // This fixes display of compodoc argtypes
165
- keepNames: true,
166
- },
167
- };
168
- },
169
- };
149
+ function storybookTransformConfigPlugin() {
150
+ const configKey = vite.rolldownVersion ? "oxc" : "esbuild";
151
+ return {
152
+ name: "analogjs-storybook-transform-config",
153
+ apply: "build",
154
+ config() {
155
+ return { [configKey]: { keepNames: true } };
156
+ }
157
+ };
170
158
  }
171
- export { addons } from '@storybook/angular/preset';
172
- //# sourceMappingURL=preset.js.map
159
+ //#endregion
160
+ export { addons, core, previewAnnotations, viteFinal };
161
+
173
162
  //# sourceMappingURL=preset.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"preset.js","sourceRoot":"","sources":["../../../../../packages/storybook-angular/src/lib/preset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,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","names":[],"sources":["../../../src/lib/preset.ts"],"sourcesContent":["import { existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\nimport { core as PresetCore } from '@storybook/angular/preset';\nimport { fileURLToPath } from 'node:url';\nimport * as vite from 'vite';\nimport type { Plugin, UserConfig } from 'vite';\nimport angular from '@analogjs/vite-plugin-angular';\nimport { debugStyles } from './debug';\n\nexport const previewAnnotations = async (\n entries: string[] = [],\n options: any,\n): Promise<string[]> => {\n const config = fileURLToPath(\n import.meta.resolve('@storybook/angular/client/config'),\n );\n const annotations = [...entries, config];\n\n if (options.enableProdMode) {\n const previewProdPath = fileURLToPath(\n import.meta.resolve('@storybook/angular/client/preview-prod'),\n );\n annotations.unshift(previewProdPath);\n }\n\n const docsConfig = await options.presets.apply('docs', {}, options);\n const docsEnabled = Object.keys(docsConfig).length > 0;\n if (docsEnabled) {\n const docsConfigPath = fileURLToPath(\n import.meta.resolve('@storybook/angular/client/docs/config'),\n );\n annotations.push(docsConfigPath);\n }\n return annotations;\n};\n\nexport const core = async (config: any, options: any): Promise<any> => {\n const presetCore = await PresetCore(config, options);\n return {\n ...presetCore,\n builder: {\n name: import.meta.resolve('@storybook/builder-vite'),\n options: { ...presetCore.options },\n },\n };\n};\n\nasync function resolveExperimentalZoneless(\n frameworkOptions: any,\n angularBuilderOptions: any,\n) {\n // 1. Explicit framework option (user's .storybook/main.ts)\n if (typeof frameworkOptions?.experimentalZoneless === 'boolean') {\n return frameworkOptions.experimentalZoneless;\n }\n\n // 2. Angular builder options (set by start-storybook/build-storybook)\n if (typeof angularBuilderOptions?.experimentalZoneless === 'boolean') {\n return angularBuilderOptions.experimentalZoneless;\n }\n\n // 3. Auto-detect Angular 21+ (matches @storybook/angular builder behavior)\n try {\n const { VERSION } = await import('@angular/core');\n return !!(VERSION.major && Number(VERSION.major) >= 21);\n } catch {\n return false;\n }\n}\n\nexport const viteFinal = async (config: any, options: any): Promise<any> => {\n // Remove any loaded analogjs plugins from a vite.config.(m)ts file\n config.plugins = (config.plugins ?? [])\n .flat()\n .filter((plugin: any) => !plugin.name.includes('analogjs'));\n\n // @ts-expect-error - untyped storybook presets API\n const framework = await options.presets.apply('framework');\n const { hmr: _removedHmrOption, ...frameworkOptions } =\n framework.options ?? {};\n const experimentalZoneless = await resolveExperimentalZoneless(\n frameworkOptions,\n options?.angularBuilderOptions,\n );\n const liveReload =\n typeof frameworkOptions.liveReload !== 'undefined'\n ? frameworkOptions.liveReload\n : false;\n return vite.mergeConfig(config, {\n // Add dependencies to pre-optimization\n optimizeDeps: {\n include: [\n '@storybook/angular/client',\n '@analogjs/storybook-angular',\n '@angular/compiler',\n '@angular/platform-browser',\n '@angular/platform-browser/animations',\n 'tslib',\n ...(experimentalZoneless ? [] : ['zone.js']),\n ],\n },\n resolve: {\n alias: {\n '@storybook/globalThis': '@storybook/global',\n },\n },\n plugins: [\n angular({\n jit:\n typeof frameworkOptions.jit !== 'undefined'\n ? frameworkOptions.jit\n : true,\n liveReload,\n tsconfig:\n typeof frameworkOptions.tsconfig !== 'undefined'\n ? frameworkOptions.tsconfig\n : (options?.tsConfig ?? './.storybook/tsconfig.json'),\n inlineStylesExtension:\n typeof frameworkOptions.inlineStylesExtension !== 'undefined'\n ? frameworkOptions.inlineStylesExtension\n : 'css',\n }),\n angularOptionsPlugin(options, {\n normalizePath: vite.normalizePath,\n experimentalZoneless,\n }),\n storybookTransformConfigPlugin(),\n ],\n define: {\n STORYBOOK_ANGULAR_OPTIONS: JSON.stringify({\n experimentalZoneless: !!experimentalZoneless,\n }),\n },\n });\n};\n\nfunction angularOptionsPlugin(\n options: any,\n {\n normalizePath,\n experimentalZoneless,\n }: { normalizePath: (path: string) => string; experimentalZoneless: boolean },\n): Plugin {\n let resolvedConfig: UserConfig | undefined;\n\n const resolveStyleImport = (\n extraImport: string,\n projectRoot: string,\n workspaceRoot: string,\n ) => {\n const resolvedProjectImport = resolve(projectRoot, extraImport);\n const resolvedWorkspaceImport = resolve(workspaceRoot, extraImport);\n\n if (\n extraImport.startsWith('.') ||\n extraImport.startsWith('src') ||\n existsSync(resolvedProjectImport)\n ) {\n return {\n specifier: resolvedProjectImport,\n source: 'project',\n } as const;\n }\n\n if (existsSync(resolvedWorkspaceImport)) {\n return {\n specifier: resolvedWorkspaceImport,\n source: 'workspace',\n } as const;\n }\n\n return {\n specifier: extraImport,\n source: 'bare',\n } as const;\n };\n\n return {\n name: 'analogjs-storybook-options-plugin',\n config(userConfig: UserConfig) {\n resolvedConfig = userConfig;\n const loadPaths =\n options?.angularBuilderOptions?.stylePreprocessorOptions?.loadPaths;\n const sassOptions =\n options?.angularBuilderOptions?.stylePreprocessorOptions?.sass;\n\n if (Array.isArray(loadPaths)) {\n const workspaceRoot =\n options.angularBuilderContext?.workspaceRoot ??\n userConfig?.root ??\n process.cwd();\n const resolvedLoadPaths = loadPaths.map(\n (loadPath) => `${resolve(workspaceRoot, loadPath)}`,\n );\n\n debugStyles('resolved SCSS load paths', {\n configDir: options.configDir,\n workspaceRoot,\n projectRoot: userConfig?.root ?? process.cwd(),\n loadPaths,\n resolvedLoadPaths,\n });\n\n return {\n css: {\n preprocessorOptions: {\n scss: {\n ...sassOptions,\n loadPaths: resolvedLoadPaths,\n },\n },\n },\n };\n }\n\n return;\n },\n async transform(code: string, id: string) {\n if (\n normalizePath(id).endsWith(\n normalizePath(`${options.configDir}/preview.ts`),\n )\n ) {\n const imports = [];\n const styles = options?.angularBuilderOptions?.styles;\n const workspaceRoot =\n options?.angularBuilderContext?.workspaceRoot ?? process.cwd();\n\n if (Array.isArray(styles)) {\n debugStyles('injecting Storybook global styles', {\n configDir: options.configDir,\n workspaceRoot,\n projectRoot: resolvedConfig?.root ?? process.cwd(),\n styles,\n });\n\n styles.forEach((style) => {\n imports.push(style);\n });\n }\n\n if (!experimentalZoneless) {\n imports.push('zone.js');\n }\n\n // Use vite config root when angularBuilderContext is not available\n // (e.g., when running via Vitest instead of Angular builders)\n const projectRoot = resolvedConfig?.root ?? process.cwd();\n\n return {\n code: `\n ${imports\n .map((extraImport) => {\n const resolved = resolveStyleImport(\n extraImport,\n projectRoot,\n workspaceRoot,\n );\n\n debugStyles('resolved Storybook style import', {\n input: extraImport,\n source: resolved.source,\n specifier: resolved.specifier,\n });\n\n return `import '${resolved.specifier}';`;\n })\n .join('\\n')}\n ${code}\n `,\n };\n }\n\n return;\n },\n };\n}\n\nfunction storybookTransformConfigPlugin(): Plugin {\n const configKey = vite.rolldownVersion ? 'oxc' : 'esbuild';\n\n return {\n name: 'analogjs-storybook-transform-config',\n apply: 'build',\n config() {\n return {\n [configKey]: {\n // Don't mangle class names during the build\n // This fixes display of compodoc argtypes\n keepNames: true,\n },\n };\n },\n };\n}\n\nexport { addons } from '@storybook/angular/preset';\n"],"mappings":";;;;;;;;AASA,IAAa,qBAAqB,OAChC,UAAoB,EAAE,EACtB,YACsB;CACtB,MAAM,SAAS,cACb,OAAO,KAAK,QAAQ,mCAAmC,CACxD;CACD,MAAM,cAAc,CAAC,GAAG,SAAS,OAAO;AAExC,KAAI,QAAQ,gBAAgB;EAC1B,MAAM,kBAAkB,cACtB,OAAO,KAAK,QAAQ,yCAAyC,CAC9D;AACD,cAAY,QAAQ,gBAAgB;;CAGtC,MAAM,aAAa,MAAM,QAAQ,QAAQ,MAAM,QAAQ,EAAE,EAAE,QAAQ;AAEnE,KADoB,OAAO,KAAK,WAAW,CAAC,SAAS,GACpC;EACf,MAAM,iBAAiB,cACrB,OAAO,KAAK,QAAQ,wCAAwC,CAC7D;AACD,cAAY,KAAK,eAAe;;AAElC,QAAO;;AAGT,IAAa,OAAO,OAAO,QAAa,YAA+B;CACrE,MAAM,aAAa,MAAM,OAAW,QAAQ,QAAQ;AACpD,QAAO;EACL,GAAG;EACH,SAAS;GACP,MAAM,OAAO,KAAK,QAAQ,0BAA0B;GACpD,SAAS,EAAE,GAAG,WAAW,SAAS;GACnC;EACF;;AAGH,eAAe,4BACb,kBACA,uBACA;AAEA,KAAI,OAAO,kBAAkB,yBAAyB,UACpD,QAAO,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ACH,SAAQ,KAAK,UAAU;IAKzB,MAAM,cAAc,gBAAgB,QAAQ,QAAQ,KAAK;AAEzD,WAAO,EACL,MAAM;cACF,QACC,KAAK,gBAAgB;KACpB,MAAM,WAAW,mBACf,aACA,aACA,cACD;AAED,iBAAY,mCAAmC;MAC7C,OAAO;MACP,QAAQ,SAAS;MACjB,WAAW,SAAS;MACrB,CAAC;AAEF,YAAO,WAAW,SAAS,UAAU;MACrC,CACD,KAAK,KAAK,CAAC;cACZ,KAAK;aAEV;;;EAKN;;AAGH,SAAS,iCAAyC;CAChD,MAAM,YAAY,KAAK,kBAAkB,QAAQ;AAEjD,QAAO;EACL,MAAM;EACN,OAAO;EACP,SAAS;AACP,UAAO,GACJ,YAAY,EAGX,WAAW,MACZ,EACF;;EAEJ"}
@@ -1,2 +1,2 @@
1
- import StartStorybookBuilder from '@storybook/angular/builders/start-storybook';
1
+ import StartStorybookBuilder from "@storybook/angular/builders/start-storybook";
2
2
  export default StartStorybookBuilder;
@@ -1,3 +1,7 @@
1
- import StartStorybookBuilder from '@storybook/angular/builders/start-storybook';
2
- export default StartStorybookBuilder;
1
+ import StartStorybookBuilder from "@storybook/angular/builders/start-storybook";
2
+ //#region packages/storybook-angular/src/lib/start-storybook/start-storybook.ts
3
+ var start_storybook_default = StartStorybookBuilder;
4
+ //#endregion
5
+ export { start_storybook_default as default };
6
+
3
7
  //# sourceMappingURL=start-storybook.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"start-storybook.js","sourceRoot":"","sources":["../../../../../../packages/storybook-angular/src/lib/start-storybook/start-storybook.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,6CAA6C,CAAC;AAEhF,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"start-storybook.js","names":[],"sources":["../../../../src/lib/start-storybook/start-storybook.ts"],"sourcesContent":["import StartStorybookBuilder from '@storybook/angular/builders/start-storybook';\n\nexport default StartStorybookBuilder;\n"],"mappings":";;AAEA,IAAA,0BAAe"}
@@ -1,7 +1,7 @@
1
- import '@angular/compiler';
2
- import type { AngularRenderer } from '@storybook/angular';
3
- import { NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations, RenderContext } from 'storybook/internal/types';
4
- import * as configAnnotations from '@storybook/angular/client/config';
1
+ import "@angular/compiler";
2
+ import type { AngularRenderer } from "@storybook/angular";
3
+ import { NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations, RenderContext } from "storybook/internal/types";
4
+ import * as configAnnotations from "@storybook/angular/client/config";
5
5
  export declare const render: typeof configAnnotations.render;
6
6
  export declare function renderToCanvas(context: RenderContext<AngularRenderer>, element: HTMLElement): Promise<void>;
7
7
  export declare function setProjectAnnotations(projectAnnotations: NamedOrDefaultProjectAnnotations<any> | NamedOrDefaultProjectAnnotations<any>[]): NormalizedProjectAnnotations<AngularRenderer>;
@@ -1,21 +1,20 @@
1
- import '@angular/compiler';
2
- import { setProjectAnnotations as originalSetProjectAnnotations } from '@storybook/angular/client';
3
- import * as configAnnotations from '@storybook/angular/client/config';
4
- export const render = configAnnotations.render;
5
- export async function renderToCanvas(context, element) {
6
- element.id = context.id;
7
- await configAnnotations.renderToCanvas(context, element);
1
+ import "@angular/compiler";
2
+ import { setProjectAnnotations as setProjectAnnotations$1 } from "@storybook/angular/client";
3
+ import * as configAnnotations from "@storybook/angular/client/config";
4
+ //#region packages/storybook-angular/src/lib/testing.ts
5
+ var render = configAnnotations.render;
6
+ async function renderToCanvas(context, element) {
7
+ element.id = context.id;
8
+ await configAnnotations.renderToCanvas(context, element);
8
9
  }
9
- const renderAnnotations = {
10
- render,
11
- renderToCanvas,
10
+ var renderAnnotations = {
11
+ render,
12
+ renderToCanvas
12
13
  };
13
- export function setProjectAnnotations(projectAnnotations) {
14
- return originalSetProjectAnnotations([
15
- renderAnnotations,
16
- ...(Array.isArray(projectAnnotations)
17
- ? projectAnnotations
18
- : [projectAnnotations]),
19
- ]);
14
+ function setProjectAnnotations(projectAnnotations) {
15
+ return setProjectAnnotations$1([renderAnnotations, ...Array.isArray(projectAnnotations) ? projectAnnotations : [projectAnnotations]]);
20
16
  }
17
+ //#endregion
18
+ export { render, renderToCanvas, setProjectAnnotations };
19
+
21
20
  //# sourceMappingURL=testing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.js","sourceRoot":"","sources":["../../../../../packages/storybook-angular/src/lib/testing.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,CAAC;AAE3B,OAAO,EAAE,qBAAqB,IAAI,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAMnG,OAAO,KAAK,iBAAiB,MAAM,kCAAkC,CAAC;AAEtE,MAAM,CAAC,MAAM,MAAM,GAAoC,iBAAiB,CAAC,MAAM,CAAC;AAEhF,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAuC,EACvC,OAAoB;IAEpB,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;IACxB,MAAM,iBAAiB,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,iBAAiB,GAAG;IACxB,MAAM;IACN,cAAc;CACf,CAAC;AAEF,MAAM,UAAU,qBAAqB,CACnC,kBAE2C;IAE3C,OAAO,6BAA6B,CAAC;QACnC,iBAAiB;QACjB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC;YACnC,CAAC,CAAC,kBAAkB;YACpB,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC;KAC1B,CAAkD,CAAC;AACtD,CAAC"}
1
+ {"version":3,"file":"testing.js","names":[],"sources":["../../../src/lib/testing.ts"],"sourcesContent":["import '@angular/compiler';\nimport type { AngularRenderer } from '@storybook/angular';\nimport { setProjectAnnotations as originalSetProjectAnnotations } from '@storybook/angular/client';\nimport {\n NamedOrDefaultProjectAnnotations,\n NormalizedProjectAnnotations,\n RenderContext,\n} from 'storybook/internal/types';\nimport * as configAnnotations from '@storybook/angular/client/config';\n\nexport const render: typeof configAnnotations.render = configAnnotations.render;\n\nexport async function renderToCanvas(\n context: RenderContext<AngularRenderer>,\n element: HTMLElement,\n): Promise<void> {\n element.id = context.id;\n await configAnnotations.renderToCanvas(context, element);\n}\n\nconst renderAnnotations = {\n render,\n renderToCanvas,\n};\n\nexport function setProjectAnnotations(\n projectAnnotations:\n | NamedOrDefaultProjectAnnotations<any>\n | NamedOrDefaultProjectAnnotations<any>[],\n): NormalizedProjectAnnotations<AngularRenderer> {\n return originalSetProjectAnnotations([\n renderAnnotations,\n ...(Array.isArray(projectAnnotations)\n ? projectAnnotations\n : [projectAnnotations]),\n ]) as NormalizedProjectAnnotations<AngularRenderer>;\n}\n"],"mappings":";;;;AAUA,IAAa,SAA0C,kBAAkB;AAEzE,eAAsB,eACpB,SACA,SACe;AACf,SAAQ,KAAK,QAAQ;AACrB,OAAM,kBAAkB,eAAe,SAAS,QAAQ;;AAG1D,IAAM,oBAAoB;CACxB;CACA;CACD;AAED,SAAgB,sBACd,oBAG+C;AAC/C,QAAO,wBAA8B,CACnC,mBACA,GAAI,MAAM,QAAQ,mBAAmB,GACjC,qBACA,CAAC,mBAAmB,CACzB,CAAC"}
@@ -1,9 +1,9 @@
1
- import { BuilderOptions, CLIOptions, LoadOptions } from 'storybook/internal/types';
1
+ import { BuilderOptions, CLIOptions, LoadOptions } from "storybook/internal/types";
2
2
  export type StandaloneOptions = CLIOptions & LoadOptions & BuilderOptions & {
3
- mode?: 'static' | 'dev';
4
- enableProdMode: boolean;
5
- angularBuilderOptions?: Record<string, any> & {
6
- experimentalZoneless?: boolean;
7
- };
8
- tsConfig?: string;
3
+ mode?: "static" | "dev";
4
+ enableProdMode: boolean;
5
+ angularBuilderOptions?: Record<string, any> & {
6
+ experimentalZoneless?: boolean;
7
+ };
8
+ tsConfig?: string;
9
9
  };
package/src/types.d.ts CHANGED
@@ -1,27 +1,33 @@
1
- import { CompatibleString } from 'storybook/internal/types';
2
- import { StorybookConfig as StorybookConfigBase } from '@storybook/angular';
3
- import { BuilderOptions, StorybookConfigVite } from '@storybook/builder-vite';
4
- type FrameworkName = CompatibleString<'@analogjs/storybook-angular'>;
5
- type BuilderName = CompatibleString<'@storybook/builder-vite'>;
1
+ import { CompatibleString } from "storybook/internal/types";
2
+ import { StorybookConfig as StorybookConfigBase } from "@storybook/angular";
3
+ import { BuilderOptions, StorybookConfigVite } from "@storybook/builder-vite";
4
+ type FrameworkName = CompatibleString<"@analogjs/storybook-angular">;
5
+ type BuilderName = CompatibleString<"@storybook/builder-vite">;
6
6
  export type FrameworkOptions = {
7
- builder?: BuilderOptions;
8
- jit?: boolean;
9
- liveReload?: boolean;
10
- inlineStylesExtension?: string;
11
- tsconfig?: string;
12
- experimentalZoneless?: boolean;
7
+ builder?: BuilderOptions;
8
+ jit?: boolean;
9
+ /**
10
+ * Enables Analog's Angular live-reload/HMR pipeline for Storybook.
11
+ *
12
+ * This is separate from Vite's `server.hmr` option, which configures the
13
+ * HMR client transport.
14
+ */
15
+ liveReload?: boolean;
16
+ inlineStylesExtension?: string;
17
+ tsconfig?: string;
18
+ experimentalZoneless?: boolean;
13
19
  };
14
20
  type StorybookConfigFramework = {
15
- framework: FrameworkName | {
16
- name: FrameworkName;
17
- options: FrameworkOptions;
18
- };
19
- core?: StorybookConfigBase['core'] & {
20
- builder?: BuilderName | {
21
- name: BuilderName;
22
- options: BuilderOptions;
23
- };
24
- };
21
+ framework: FrameworkName | {
22
+ name: FrameworkName;
23
+ options: FrameworkOptions;
24
+ };
25
+ core?: StorybookConfigBase["core"] & {
26
+ builder?: BuilderName | {
27
+ name: BuilderName;
28
+ options: BuilderOptions;
29
+ };
30
+ };
25
31
  };
26
32
  /** The interface for Storybook configuration in `main.ts` files. */
27
33
  export type StorybookConfig = Omit<StorybookConfigBase, keyof StorybookConfigVite | keyof StorybookConfigFramework> & StorybookConfigVite & StorybookConfigFramework;
package/README.md DELETED
@@ -1,270 +0,0 @@
1
- # @analogjs/storybook-angular
2
-
3
- Integration package for Storybook using Angular & Vite.
4
-
5
- > This is a community integration not maintained by the Storybook team. If you have issues,
6
- > file an issue in our [GitHub repo](https://github.com/analogjs/analog/issues).
7
-
8
- ## Setup
9
-
10
- If you don't have Storybook setup already, run the following command to initialize Storybook for your project:
11
-
12
- ```sh
13
- npx storybook@latest init
14
- ```
15
-
16
- Follow the provided prompts, and commit your changes.
17
-
18
- ## Installing the Storybook package
19
-
20
- Install the Storybook Plugin for Angular and Vite. Depending on your preferred package manager, run one of the following commands:
21
-
22
- ```shell
23
- npm install @analogjs/storybook-angular --save-dev
24
- ```
25
-
26
- ## Configuring Storybook
27
-
28
- Update the `.storybook/main.ts` file to use the `StorybookConfig` type. Also update the `framework` to use the `@analogjs/storybook-angular` package.
29
-
30
- ```ts
31
- import { StorybookConfig } from '@analogjs/storybook-angular';
32
-
33
- const config: StorybookConfig = {
34
- // other config, addons, etc.
35
- framework: {
36
- name: '@analogjs/storybook-angular',
37
- options: {},
38
- },
39
- };
40
-
41
- export default config;
42
- ```
43
-
44
- Remove the existing `webpackFinal` config function if present.
45
-
46
- Next, update the Storybook targets in the `angular.json` or `project.json`
47
-
48
- ```json
49
- "storybook": {
50
- "builder": "@analogjs/storybook-angular:start-storybook",
51
- },
52
- "build-storybook": {
53
- "builder": "@analogjs/storybook-angular:build-storybook"
54
- }
55
- ```
56
-
57
- Remove any `webpack` specific options and remove the `browserTarget` option.
58
-
59
- Add the `/storybook-static` folder to the `.gitignore` file.
60
-
61
- ## Setting up CSS
62
-
63
- To register global styles, add them to the `@analogjs/storybook-angular` builder options in the `angular.json` or `project.json`.
64
-
65
- ```json
66
- "storybook": {
67
- "builder": "@analogjs/storybook-angular:start-storybook",
68
- "options": {
69
- // ... other options
70
- "styles": [
71
- "src/styles.css"
72
- ],
73
- "stylePreprocessorOptions": {
74
- "loadPaths": ["libs/my-lib/styles"]
75
- }
76
- }
77
- },
78
- "build-storybook": {
79
- "builder": "@analogjs/storybook-angular:build-storybook",
80
- "options": {
81
- // ... other options
82
- "styles": [
83
- "src/styles.css"
84
- ],
85
- "stylePreprocessorOptions": {
86
- "loadPaths": ["libs/my-lib/styles"]
87
- }
88
- }
89
- }
90
- ```
91
-
92
- ## Enabling Zoneless Change Detection
93
-
94
- To use zoneless change detection for the Storybook, add the `experimentalZoneless` flag to the `@analogjs/storybook-angular` builder options in the `angular.json`.
95
-
96
- ```json
97
- "storybook": {
98
- "builder": "@analogjs/storybook-angular:start-storybook",
99
- "options": {
100
- // ... other options
101
- "experimentalZoneless": true
102
- }
103
- },
104
- "build-storybook": {
105
- "builder": "@analogjs/storybook-angular:build-storybook",
106
- "options": {
107
- // ... other options
108
- "experimentalZoneless": true
109
- }
110
- }
111
- ```
112
-
113
- For `project.json`
114
-
115
- ```json
116
- "storybook": {
117
- "executor": "@analogjs/storybook-angular:start-storybook",
118
- "options": {
119
- // ... other options
120
- "configDir": "path/to/.storybook",
121
- "experimentalZoneless": true,
122
- "compodoc": false
123
- }
124
- },
125
- "build-storybook": {
126
- "executor": "@analogjs/storybook-angular:build-storybook",
127
- "options": {
128
- // ... other options
129
- "configDir": "path/to/.storybook",
130
- "experimentalZoneless": true,
131
- "compodoc": false
132
- }
133
- }
134
- ```
135
-
136
- > Zoneless change detection is the default for new projects starting Angular v21.
137
-
138
- ## Setting up Static Assets
139
-
140
- Static assets are configured in the `.storybook/main.ts` file using the `staticDirs` array.
141
-
142
- The example below shows how to add the `public` directory from `src/public` relative to the `.storybook/main.ts` file.
143
-
144
- ```ts
145
- import { StorybookConfig } from '@analogjs/storybook-angular';
146
-
147
- const config: StorybookConfig = {
148
- // other config, addons, etc.
149
- framework: {
150
- name: '@analogjs/storybook-angular',
151
- options: {},
152
- },
153
- staticDirs: ['../public'],
154
- };
155
-
156
- export default config;
157
- ```
158
-
159
- See the [Storybook docs on images and assets](https://storybook.js.org/docs/configure/integration/images-and-assets) for more information.
160
-
161
- ## Running Storybook
162
-
163
- Run the command for starting the development server.
164
-
165
- ```sh
166
- npm run storybook
167
- ```
168
-
169
- ## Building Storybook
170
-
171
- Run the command for building the storybook.
172
-
173
- ```sh
174
- npm run build-storybook
175
- ```
176
-
177
- ## Using TypeScript Config Path Aliases
178
-
179
- If you are using `paths` in your `tsconfig.json`, support for those aliases can be added to the `vite.config.ts`.
180
-
181
- ### With Angular CLI
182
-
183
- First, install the `vite-tsconfig-paths` package.
184
-
185
- ```shell
186
- npm install vite-tsconfig-paths --save-dev
187
- ```
188
-
189
- Next, add the plugin to the `plugins` array in the `.storybook/main.ts`.
190
-
191
- ```ts
192
- import viteTsConfigPaths from 'vite-tsconfig-paths';
193
- import { UserConfig, mergeConfig } from 'vite';
194
-
195
- import type { StorybookConfig } from '@analogjs/storybook-angular';
196
-
197
- const config: StorybookConfig = {
198
- // ... other config, addons, etc.
199
- async viteFinal(config: UserConfig) {
200
- return mergeConfig(config, {
201
- plugins: [viteTsConfigPaths()],
202
- });
203
- },
204
- };
205
-
206
- export default config;
207
- ```
208
-
209
- ### With Nx
210
-
211
- For Nx workspaces, import and use the `nxViteTsPaths` plugin from the `@nx/vite` package. Add the plugin to the `plugins` array in the `.storybook/main.ts`.
212
-
213
- ```ts
214
- import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
215
- import { UserConfig, mergeConfig } from 'vite';
216
-
217
- import type { StorybookConfig } from '@analogjs/storybook-angular';
218
-
219
- const config: StorybookConfig = {
220
- // ... other config, addons, etc.
221
- async viteFinal(config: UserConfig) {
222
- return mergeConfig(config, {
223
- plugins: [nxViteTsPaths()],
224
- });
225
- },
226
- };
227
-
228
- export default config;
229
- ```
230
-
231
- ## Using File Replacements
232
-
233
- You can also use the `replaceFiles()` plugin from Nx to replace files during your build.
234
-
235
- Import the plugin and set it up:
236
-
237
- ```ts
238
- import { replaceFiles } from '@nx/vite/plugins/rollup-replace-files.plugin';
239
- import { UserConfig, mergeConfig } from 'vite';
240
-
241
- import type { StorybookConfig } from '@analogjs/storybook-angular';
242
-
243
- const config: StorybookConfig = {
244
- // ... other config, addons, etc.
245
- async viteFinal(config: UserConfig) {
246
- return mergeConfig(config, {
247
- plugins: [
248
- replaceFiles([
249
- {
250
- replace: './src/one.ts',
251
- with: './src/two.ts',
252
- },
253
- ]),
254
- ],
255
- });
256
- },
257
- };
258
-
259
- export default config;
260
- ```
261
-
262
- Adding the replacement files to `files` array in the `tsconfig.app.json` may also be necessary.
263
-
264
- ```json
265
- {
266
- "extends": "./tsconfig.json",
267
- // other config
268
- "files": ["src/main.ts", "src/main.server.ts", "src/two.ts"]
269
- }
270
- ```
package/src/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/storybook-angular/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,iBAAiB,EACjB,cAAc,EACd,yBAAyB,EACzB,cAAc,EACd,qBAAqB,GACtB,MAAM,oBAAoB,CAAC"}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=standalone-options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"standalone-options.js","sourceRoot":"","sources":["../../../../../../packages/storybook-angular/src/lib/utils/standalone-options.ts"],"names":[],"mappings":""}
package/src/types.js DELETED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=types.js.map
package/src/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../packages/storybook-angular/src/types.ts"],"names":[],"mappings":""}