@storybook/angular-vite 10.6.0-alpha.5 → 10.6.0-alpha.6

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/dist/index.js CHANGED
@@ -5,10 +5,10 @@ import {
5
5
  componentWrapperDecorator,
6
6
  moduleMetadata,
7
7
  setProjectAnnotations
8
- } from "./_browser-chunks/chunk-GVH2OCSY.js";
9
- import "./_browser-chunks/chunk-XXAOQLNU.js";
10
- import "./_browser-chunks/chunk-THKACJYB.js";
11
- import "./_browser-chunks/chunk-6DVGZIOB.js";
8
+ } from "./_browser-chunks/chunk-HBLYOJ22.js";
9
+ import "./_browser-chunks/chunk-CHMLOECK.js";
10
+ import "./_browser-chunks/chunk-BUNW7ROM.js";
11
+ import "./_browser-chunks/chunk-ECGMCGUZ.js";
12
12
  export {
13
13
  __definePreview,
14
14
  applicationConfig,
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_1pj9uj7yzpf from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_1pj9uj7yzpf from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_1pj9uj7yzpf from "node:module";
1
+ import CJS_COMPAT_NODE_URL_ze1vib595n from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_ze1vib595n from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_ze1vib595n from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_1pj9uj7yzpf.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_1pj9uj7yzpf.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_1pj9uj7yzpf.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_ze1vib595n.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_ze1vib595n.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_ze1vib595n.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_1pj9uj7yzpf from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_1pj9uj7yzpf from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_1pj9uj7yzpf from "node:module";
1
+ import CJS_COMPAT_NODE_URL_ze1vib595n from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_ze1vib595n from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_ze1vib595n from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_1pj9uj7yzpf.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_1pj9uj7yzpf.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_1pj9uj7yzpf.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_ze1vib595n.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_ze1vib595n.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_ze1vib595n.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
package/dist/preset.js CHANGED
@@ -1,19 +1,20 @@
1
- import CJS_COMPAT_NODE_URL_1pj9uj7yzpf from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_1pj9uj7yzpf from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_1pj9uj7yzpf from "node:module";
1
+ import CJS_COMPAT_NODE_URL_ze1vib595n from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_ze1vib595n from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_ze1vib595n from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_1pj9uj7yzpf.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_1pj9uj7yzpf.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_1pj9uj7yzpf.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_ze1vib595n.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_ze1vib595n.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_ze1vib595n.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
12
  import {
13
- ensureCompodocDocumentation,
14
- resolveCompodocConfig
15
- } from "./_node-chunks/chunk-77BJXJPD.js";
16
- import "./_node-chunks/chunk-RC6UIUJ4.js";
13
+ findTsconfigUp
14
+ } from "./_node-chunks/chunk-ORVVXDOZ.js";
15
+ import {
16
+ parseStoryFile
17
+ } from "./_node-chunks/chunk-5LXEVSHB.js";
17
18
 
18
19
  // src/preset.ts
19
20
  import { findConfigFile } from "storybook/internal/common";
@@ -24,30 +25,197 @@ import {
24
25
  getAutomockCode,
25
26
  getRealPath
26
27
  } from "storybook/internal/mocking-utils";
27
- import { readFileSync } from "node:fs";
28
- import { resolve } from "node:path";
28
+ import { readFileSync as readFileSync3 } from "node:fs";
29
+ import { resolve as resolve4 } from "node:path";
29
30
  import { fileURLToPath as fileURLToPath2 } from "node:url";
30
31
 
32
+ // src/compodoc-config.ts
33
+ import { resolve } from "node:path";
34
+ var DEFAULT_COMPODOC_ARGS = ["-e", "json", "-d", "."], DOCUMENTATION_JSON = "documentation.json", readCompodocOutputDir = (compodocArgs) => {
35
+ for (let index = compodocArgs.length - 1; index >= 0; index--) {
36
+ let arg = compodocArgs[index];
37
+ if (arg.startsWith("--output="))
38
+ return arg.slice(9) || void 0;
39
+ if (arg === "-d" || arg === "--output") {
40
+ let value = compodocArgs[index + 1];
41
+ if (typeof value == "string" && !value.startsWith("-"))
42
+ return value;
43
+ }
44
+ }
45
+ }, resolveCompodocConfig = async (options, extra = {}) => {
46
+ let framework = await options?.presets?.apply("framework"), frameworkOptions = typeof framework == "string" ? {} : framework?.options ?? {}, workspaceRoot = options?.angularBuilderContext?.workspaceRoot ?? extra.viteRoot ?? // Mirrors what builder-vite does with Vite's root, which only `viteFinal` can pass along. Without
47
+ // it the docgen reader falls back to cwd and looks in a different directory than the writer.
48
+ (options?.configDir ? resolve(options.configDir, "..") : void 0) ?? process.cwd(), compodocArgs = frameworkOptions.compodocArgs ?? DEFAULT_COMPODOC_ARGS;
49
+ return {
50
+ /** `framework.options.compodoc`: `false` means the user opted out of Compodoc entirely. */
51
+ enabled: frameworkOptions.compodoc !== !1,
52
+ compodocArgs,
53
+ tsconfig: frameworkOptions.tsconfig ?? options?.tsConfig ?? options?.angularBuilderOptions?.tsConfig ?? // The same walk the builders use, so Compodoc is pointed at the tsconfig the Angular build
54
+ // would have picked rather than a different guess.
55
+ (options?.configDir ? findTsconfigUp(options.configDir) : void 0) ?? resolve(workspaceRoot, "tsconfig.json"),
56
+ /** Directory Compodoc runs in, and the base its relative `file` paths are written against. */
57
+ workspaceRoot,
58
+ /** Absolute directory Compodoc writes {@link DOCUMENTATION_JSON} into. */
59
+ outputDir: resolve(workspaceRoot, readCompodocOutputDir(compodocArgs) ?? ".")
60
+ };
61
+ };
62
+
63
+ // src/compodoc/ensure-documentation.ts
64
+ import { withFileLock } from "storybook/internal/common";
65
+ import { logger as logger2 } from "storybook/internal/node-logger";
66
+ import { randomUUID } from "node:crypto";
67
+ import { readFileSync as readFileSync2, writeFileSync } from "node:fs";
68
+ import { join as join2 } from "node:path";
69
+
70
+ // src/compodoc/generate-documentation.ts
71
+ import { executeNodeCommand } from "storybook/internal/common";
72
+ import { logger } from "storybook/internal/node-logger";
73
+ import {
74
+ existsSync,
75
+ mkdirSync,
76
+ mkdtempSync,
77
+ readFileSync,
78
+ readdirSync,
79
+ renameSync,
80
+ rmSync,
81
+ statSync
82
+ } from "node:fs";
83
+ import { createRequire } from "node:module";
84
+ import { dirname, isAbsolute, join, relative, resolve as resolve2 } from "node:path";
85
+ import { pathToFileURL } from "node:url";
86
+ var COMPODOC_TIMEOUT_MS = 600 * 1e3, OUTPUT_TAIL_BYTES = 4e3, SCRATCH_PREFIX = ".compodoc-", resolveCompodocCli = (workspaceRoot) => {
87
+ let searchFrom = [pathToFileURL(join(resolve2(workspaceRoot), "noop.js")).href, import.meta.url];
88
+ for (let from of searchFrom)
89
+ try {
90
+ let packageJsonPath = createRequire(from).resolve("@compodoc/compodoc/package.json"), { bin } = JSON.parse(readFileSync(packageJsonPath, "utf8")), entry = typeof bin == "string" ? bin : bin?.compodoc;
91
+ if (entry)
92
+ return join(dirname(packageJsonPath), entry);
93
+ } catch {
94
+ }
95
+ }, hasTsconfigArg = (args) => args.includes("-p"), toChildRelativePath = (path, cwd) => isAbsolute(path) ? relative(cwd, path) : path, runCli = async (cli, args, cwd, timeoutMs) => {
96
+ let result = await executeNodeCommand({
97
+ scriptPath: cli,
98
+ args,
99
+ options: {
100
+ cwd,
101
+ // Interleaved into one stream, so the failure message reads in the order Compodoc printed it.
102
+ all: !0,
103
+ encoding: "utf8",
104
+ // Failures come back as a result rather than a throw, so a timeout and a non-zero exit are
105
+ // told apart by inspecting one object.
106
+ reject: !1,
107
+ timeout: timeoutMs,
108
+ // Compodoc does not shut down promptly on SIGTERM, and a hung scan would otherwise keep the
109
+ // docgen worker waiting for it.
110
+ killSignal: "SIGKILL"
111
+ }
112
+ });
113
+ if (!result.failed)
114
+ return;
115
+ let output = String(result.all ?? "").trim().slice(-OUTPUT_TAIL_BYTES);
116
+ throw new Error(
117
+ result.timedOut ? `Compodoc did not finish within ${timeoutMs}ms.
118
+ ${output}` : `Compodoc exited with code ${result.exitCode}.
119
+ ${output}`
120
+ );
121
+ }, removeAbandonedScratchDirs = (outputDir, olderThanMs) => {
122
+ let cutoff = Date.now() - olderThanMs;
123
+ for (let entry of readdirSync(outputDir, { withFileTypes: !0 })) {
124
+ if (!entry.isDirectory() || !entry.name.startsWith(SCRATCH_PREFIX))
125
+ continue;
126
+ let path = join(outputDir, entry.name);
127
+ try {
128
+ statSync(path).mtimeMs < cutoff && rmSync(path, { recursive: !0, force: !0 });
129
+ } catch {
130
+ }
131
+ }
132
+ }, generateDocumentation = async ({
133
+ compodocArgs,
134
+ tsconfig,
135
+ workspaceRoot,
136
+ outputDir,
137
+ timeoutMs = COMPODOC_TIMEOUT_MS
138
+ }) => {
139
+ let cli = resolveCompodocCli(workspaceRoot);
140
+ if (!cli)
141
+ throw new Error(
142
+ "@compodoc/compodoc could not be resolved. Install it as a devDependency, or set framework.options.compodoc to false to turn Angular docgen off."
143
+ );
144
+ mkdirSync(outputDir, { recursive: !0 }), removeAbandonedScratchDirs(outputDir, timeoutMs);
145
+ let scratchDir = mkdtempSync(join(outputDir, SCRATCH_PREFIX)), startedAt = Date.now();
146
+ logger.info("[storybook-angular-vite] Generating Angular documentation with Compodoc...");
147
+ try {
148
+ await runCli(
149
+ cli,
150
+ [
151
+ ...hasTsconfigArg(compodocArgs) ? [] : ["-p", toChildRelativePath(tsconfig, workspaceRoot)],
152
+ ...compodocArgs,
153
+ // Last occurrence wins on Compodoc's command line, so this overrides any `-d`/`--output` the
154
+ // user configured. Their directory is where the finished file lands, not where it is built.
155
+ "-d",
156
+ scratchDir
157
+ ],
158
+ workspaceRoot,
159
+ timeoutMs
160
+ );
161
+ let produced = join(scratchDir, DOCUMENTATION_JSON);
162
+ if (!existsSync(produced))
163
+ throw new Error(
164
+ `Compodoc finished without writing ${DOCUMENTATION_JSON}. Check that its arguments still export JSON: ${compodocArgs.join(" ")}`
165
+ );
166
+ renameSync(produced, join(outputDir, DOCUMENTATION_JSON)), logger.debug(
167
+ `[storybook-angular-vite] generated ${DOCUMENTATION_JSON} in ${Date.now() - startedAt}ms`
168
+ );
169
+ } finally {
170
+ rmSync(scratchDir, { recursive: !0, force: !0 });
171
+ }
172
+ };
173
+
174
+ // src/compodoc/ensure-documentation.ts
175
+ var COMPODOC_LOCK = ".compodoc.lock", COMPODOC_RUN_MARKER = ".compodoc.run", RUN_ID_ENV = "STORYBOOK_COMPODOC_RUN_ID", currentRunId = () => process.env[RUN_ID_ENV] ??= randomUUID(), markerRunId = (markerPath) => {
176
+ try {
177
+ return readFileSync2(markerPath, "utf8").trim();
178
+ } catch {
179
+ return;
180
+ }
181
+ }, ensureCompodocDocumentation = async ({
182
+ compodocArgs,
183
+ tsconfig,
184
+ workspaceRoot,
185
+ outputDir,
186
+ waitBudgetMs
187
+ }) => {
188
+ let markerPath = join2(outputDir, COMPODOC_RUN_MARKER), runId = currentRunId();
189
+ if (markerRunId(markerPath) !== runId)
190
+ try {
191
+ await withFileLock(
192
+ join2(outputDir, COMPODOC_LOCK),
193
+ async () => {
194
+ markerRunId(markerPath) !== runId && (await generateDocumentation({ compodocArgs, tsconfig, workspaceRoot, outputDir }), writeFileSync(markerPath, runId));
195
+ },
196
+ { waitBudgetMs }
197
+ ) === "busy" && logger2.debug(
198
+ `[storybook-angular-vite] another process is still generating ${DOCUMENTATION_JSON}; continuing with what is on disk`
199
+ );
200
+ } catch (error) {
201
+ logger2.warn(
202
+ `[storybook-angular-vite] Compodoc generation failed: ${error instanceof Error ? error.message : String(error)}`
203
+ );
204
+ }
205
+ };
206
+
31
207
  // src/docgen/preset.ts
32
208
  import { fileURLToPath } from "node:url";
33
209
  var experimental_docgenProvider = async (existing = [], options) => {
34
210
  let features = await options?.presets?.apply("features", {});
35
- if (!features?.experimentalDocgenServer)
36
- return existing;
37
- let compodocConfig = await resolveCompodocConfig(options);
38
- if (!compodocConfig.enabled)
211
+ if (!features?.experimentalDocgenServer || !(await resolveCompodocConfig(options)).enabled)
39
212
  return existing;
40
213
  let descriptor = {
41
214
  moduleSpecifier: fileURLToPath(
42
215
  import.meta.resolve("@storybook/angular-vite/internal/docgen-worker")
43
216
  ),
44
- // Structured-cloned onto the worker thread: plain JSON only, no closures or class instances.
45
217
  options: {
46
- outputDir: compodocConfig.outputDir,
47
- compodocArgs: compodocConfig.compodocArgs,
48
- workspaceRoot: compodocConfig.workspaceRoot,
49
- angularFilterNonInputControls: features?.angularFilterNonInputControls,
50
- tsconfig: compodocConfig.tsconfig
218
+ angularFilterNonInputControls: features?.angularFilterNonInputControls
51
219
  }
52
220
  };
53
221
  return [...existing, descriptor];
@@ -61,9 +229,319 @@ var experimental_docgenProvider = async (existing = [], options) => {
61
229
  components: {
62
230
  v: existingComponents?.v ?? 0,
63
231
  components: existingComponents?.components ?? {},
64
- meta: { docgen: "compodoc", durationMs: 0 }
232
+ meta: { docgen: "angular-component-meta", durationMs: 0 }
233
+ }
234
+ };
235
+ };
236
+
237
+ // src/docgen/story-docs-preset.ts
238
+ import { STORY_FILE_TEST_REGEXP, getStoryImportPathFromEntry as getStoryImportPathFromEntry2 } from "storybook/internal/common";
239
+ import { getService } from "storybook/internal/core-server";
240
+ import { logger as logger3 } from "storybook/internal/node-logger";
241
+
242
+ // src/docgen/story-docs-build.ts
243
+ import { types as t } from "storybook/internal/babel";
244
+ import { getComponentIdFromEntry, getStoryImportPathFromEntry } from "storybook/internal/common";
245
+ import { storyNameFromExport } from "storybook/internal/csf";
246
+ import {
247
+ argsRecordFromNode,
248
+ buildImportStatements,
249
+ collectImportBindings,
250
+ extractStoryJSDocInfo,
251
+ keyOf,
252
+ mergeArgsRecords,
253
+ resolveComponentImport,
254
+ unwrapExpression
255
+ } from "storybook/internal/csf-tools";
256
+ import { resolve as resolve3 } from "node:path";
257
+
258
+ // src/template-grammar.ts
259
+ var isValidIdentifier = (name) => /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name), formatPropInTemplate = (propertyName) => isValidIdentifier(propertyName) ? propertyName : `this['${propertyName}']`, stringifyCircular = (obj) => {
260
+ let seen = /* @__PURE__ */ new Set();
261
+ return JSON.stringify(obj, (key, value) => {
262
+ if (typeof value == "object" && value !== null) {
263
+ if (seen.has(value))
264
+ return "[Circular]";
265
+ seen.add(value);
65
266
  }
267
+ return value;
268
+ });
269
+ }, singleQuoted = (text) => `'${JSON.stringify(text).slice(1, -1).replace(/\\"/g, '"').replace(/'/g, "\\'").replace(/"/g, "&quot;")}'`, formatJsonValue = (value) => typeof value == "string" ? singleQuoted(value) : Array.isArray(value) ? `[${value.map(formatJsonValue).join(", ")}]` : value !== null && typeof value == "object" ? `{${Object.entries(value).map(
270
+ ([key, item]) => `${isValidIdentifier(key) ? key : singleQuoted(key)}: ${formatJsonValue(item)}`
271
+ ).join(", ")}}` : String(value), formatInputValue = (value) => {
272
+ switch (typeof value) {
273
+ case "string":
274
+ return singleQuoted(value);
275
+ case "object":
276
+ return formatJsonValue(JSON.parse(stringifyCircular(value)));
277
+ default:
278
+ return `${value}`;
279
+ }
280
+ }, VOID_ELEMENTS = /* @__PURE__ */ new Set([
281
+ "area",
282
+ "base",
283
+ "br",
284
+ "col",
285
+ "command",
286
+ "embed",
287
+ "hr",
288
+ "img",
289
+ "input",
290
+ "keygen",
291
+ "link",
292
+ "meta",
293
+ "param",
294
+ "source",
295
+ "track",
296
+ "wbr"
297
+ ]), LEADING_CLASS = /^\..+/, LEADING_ATTRIBUTE = /^\[.+?]/, ID = /#([\w-]+)/, CLASS_RUN = /(\.[\w-]+)+/, ATTRIBUTE = /\[(.+?)]/g, ELEMENT_AND_ATTRIBUTES = /(\S+)(.*)/, MAX_SINGLE_LINE = 80, buildTemplate = (selector, { inputs, outputs, innerTemplate = "" }) => {
298
+ let bindings = [
299
+ ...inputs.map(({ name, expression }) => `[${name}]="${expression}"`),
300
+ ...outputs.map((name) => `(${name})="${formatPropInTemplate(name)}($event)"`)
301
+ ], firstSelector = selector.split(",")[0];
302
+ return (LEADING_CLASS.test(firstSelector) || LEADING_ATTRIBUTE.test(firstSelector) ? `div${firstSelector}` : firstSelector).replace(ID, ' id="$1"').replace(CLASS_RUN, (classes) => ` class="${classes.split(".").join(" ").trim()}"`).replace(ATTRIBUTE, " $1").replace(ELEMENT_AND_ATTRIBUTES, (_, element, attributes) => {
303
+ let inlineTag = `<${element}${attributes}${bindings.map((binding) => ` ${binding}`).join("")}`, inline = VOID_ELEMENTS.has(element) ? `${inlineTag} />` : `${inlineTag}>${innerTemplate}</${element}>`;
304
+ if (inline.length <= MAX_SINGLE_LINE || bindings.length === 0)
305
+ return inline;
306
+ let brokenTag = `<${element}${attributes}
307
+ ${bindings.map((binding) => ` ${binding}`).join(`
308
+ `)}`;
309
+ if (VOID_ELEMENTS.has(element))
310
+ return `${brokenTag} />`;
311
+ let content = innerTemplate === "" ? `
312
+ ` : `
313
+ ${innerTemplate}
314
+ `;
315
+ return `${brokenTag}>${content}</${element}>`;
316
+ });
317
+ }, buildComponentOutletTemplate = (componentName) => `<ng-container *ngComponentOutlet="${componentName}"></ng-container>`;
318
+
319
+ // src/docgen/story-docs-snippet.ts
320
+ var HOST_SELECTOR = "app-demo", HOST_CLASS = "DemoComponent", escapeTemplateLiteral = (template) => template.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
321
+ var memberName = (name) => isValidIdentifier(name) ? name : `['${name}']`, embedTemplate = (template) => template.includes(`
322
+ `) ? `
323
+ ${template.split(`
324
+ `).map((line) => line === "" ? line : ` ${line}`).join(`
325
+ `)}` : template, buildHostComponentSnippet = ({
326
+ template,
327
+ componentName,
328
+ componentImport,
329
+ viaComponentOutlet,
330
+ standalone,
331
+ ngModules,
332
+ outputs
333
+ }) => {
334
+ let importable = viaComponentOutlet || standalone, moduleNames = importable ? [] : ngModules?.names ?? [], imports = [
335
+ ...viaComponentOutlet ? ["import { NgComponentOutlet } from '@angular/common';"] : [],
336
+ "import { Component } from '@angular/core';",
337
+ ...componentImport && importable ? [componentImport] : [],
338
+ ...moduleNames.length > 0 ? ngModules?.importStatements ?? [] : []
339
+ ], declared = viaComponentOutlet ? "NgComponentOutlet" : standalone ? componentName : moduleNames.join(", "), members = [
340
+ ...viaComponentOutlet ? [` protected readonly ${componentName} = ${componentName};`] : [],
341
+ ...outputs.map((name) => ` ${memberName(name)}(event: unknown) {}`)
342
+ ], body = members.length > 0 ? `{
343
+ ${members.join(`
344
+ `)}
345
+ }` : "{}", snippet = [
346
+ imports.join(`
347
+ `),
348
+ "",
349
+ "@Component({",
350
+ ` selector: '${HOST_SELECTOR}',`,
351
+ ` imports: [${declared}],`,
352
+ ` template: \`${embedTemplate(escapeTemplateLiteral(template))}\`,`,
353
+ "})",
354
+ `export class ${HOST_CLASS} ${body}`
355
+ ].join(`
356
+ `), warning = !importable && moduleNames.length === 0 ? `${componentName} is declared with \`standalone: false\`, so it cannot be listed in the host component's \`imports\`. Add the NgModule that declares and exports ${componentName} to \`imports\` to make this snippet compile.` : importable && componentImport === void 0 ? `${componentName} is declared in the story file, so the snippet references it without importing it.` : void 0;
357
+ return warning === void 0 ? { snippet } : { snippet, warning };
358
+ };
359
+
360
+ // src/docgen/story-docs-build.ts
361
+ var buildStoryDocsPayload = async (input, context) => {
362
+ let storyImportPath = getStoryImportPathFromEntry(input.entry);
363
+ if (!storyImportPath)
364
+ return;
365
+ let resolvePath = context.resolvePath ?? ((importPath) => resolve3(process.cwd(), importPath)), parsed = parseStoryFile(resolvePath(storyImportPath), input.entry.title);
366
+ if (!parsed)
367
+ return;
368
+ let { source, csf } = parsed, componentNode = csf._metaAnnotations.component, docgenPayload = componentNode ? await context.getDocgenPayload(getComponentIdFromEntry(input.entry)) : void 0, componentName = componentNameOf(componentNode), importBindings = collectImportBindings(csf._file.path), deps = {
369
+ csf,
370
+ source,
371
+ metaArgs: argsRecordFromNode(csf._metaAnnotations.args),
372
+ metaHasRender: csf._metaAnnotations.render !== void 0,
373
+ snippetMeta: docgenPayload?.angularComponentMeta,
374
+ componentName,
375
+ componentImport: componentName === void 0 ? void 0 : createImportStatement(componentName, importBindings, docgenPayload),
376
+ metaNgModules: ngModulesFromDecorators(csf._metaAnnotations.decorators, componentName),
377
+ importBindings
378
+ }, stories = {};
379
+ for (let [exportName, story] of Object.entries(csf._stories))
380
+ stories[story.id] = buildStoryDoc(exportName, story, deps);
381
+ let titleName = input.entry.title.split("/").at(-1).replace(/\s+/g, "");
382
+ return {
383
+ id: getComponentIdFromEntry(input.entry),
384
+ // The docgen payload knows the class name even when the story file imported it under an alias.
385
+ name: docgenPayload?.name ?? componentName ?? titleName,
386
+ path: storyImportPath,
387
+ stories
66
388
  };
389
+ }, createImportStatement = (componentName, importBindings, docgenPayload) => {
390
+ let ref = resolveComponentImport(componentName, importBindings), importOverride = docgenPayload?.jsDocTags?.import?.[0]?.trim();
391
+ return buildImportStatements({ refs: [{ ...ref, importOverride }] }).join(`
392
+ `) || void 0;
393
+ }, componentNameOf = (node) => {
394
+ let identifier = node && t.isTSInstantiationExpression(node) ? node.expression : node;
395
+ return identifier && t.isIdentifier(identifier) ? identifier.name : void 0;
396
+ }, ngModulesFromDecorators = (decorators, componentName) => {
397
+ let result = { names: [], declaresComponent: !1 }, list = decorators === void 0 ? void 0 : unwrapExpression(decorators);
398
+ if (!list || !t.isArrayExpression(list))
399
+ return result;
400
+ for (let element of list.elements) {
401
+ if (!element || t.isSpreadElement(element))
402
+ continue;
403
+ let call = unwrapExpression(element);
404
+ if (!t.isCallExpression(call) || !t.isIdentifier(call.callee, { name: "moduleMetadata" }))
405
+ continue;
406
+ let [metadataArg] = call.arguments, metadata = metadataArg && t.isExpression(metadataArg) ? unwrapExpression(metadataArg) : void 0;
407
+ if (!(!metadata || !t.isObjectExpression(metadata)))
408
+ for (let property of metadata.properties) {
409
+ if (!t.isObjectProperty(property) || !t.isExpression(property.value))
410
+ continue;
411
+ let key = keyOf(property), value = unwrapExpression(property.value);
412
+ if (!(key !== "imports" && key !== "declarations" || !t.isArrayExpression(value)))
413
+ for (let item of value.elements) {
414
+ if (!item || t.isSpreadElement(item))
415
+ continue;
416
+ let entry = unwrapExpression(item);
417
+ t.isIdentifier(entry) && (key === "imports" ? entry.name !== componentName && !result.names.includes(entry.name) && result.names.push(entry.name) : entry.name === componentName && (result.declaresComponent = !0));
418
+ }
419
+ }
420
+ }
421
+ return result;
422
+ }, storyNgModules = (storyDecorators, { metaNgModules, componentName, importBindings }) => {
423
+ let story = ngModulesFromDecorators(storyDecorators, componentName);
424
+ if (metaNgModules.declaresComponent || story.declaresComponent)
425
+ return;
426
+ let refs = [.../* @__PURE__ */ new Set([...metaNgModules.names, ...story.names])].map((name) => resolveComponentImport(name, importBindings)).filter((ref) => ref.importId);
427
+ if (refs.length !== 0)
428
+ return {
429
+ names: refs.map((ref) => ref.componentName),
430
+ importStatements: buildImportStatements({ refs })
431
+ };
432
+ }, buildStoryDoc = (exportName, story, deps) => {
433
+ let { csf, metaArgs, metaHasRender, snippetMeta } = deps, name = story.name ?? storyNameFromExport(exportName);
434
+ try {
435
+ let { description, summary } = extractStoryJSDocInfo(csf._storyStatements[exportName]), annotations = csf._storyAnnotations[exportName] ?? {}, hasRender = metaHasRender || annotations.render !== void 0, args = mergeArgsRecords(metaArgs, argsRecordFromNode(annotations.args)), rendered = snippetMeta && !hasRender ? renderStorySnippet(snippetMeta, args, annotations.decorators, deps) : void 0;
436
+ return {
437
+ id: story.id,
438
+ name,
439
+ ...rendered === void 0 ? {} : { snippet: rendered.snippet },
440
+ ...rendered?.warning === void 0 ? {} : { warning: rendered.warning },
441
+ ...description ? { description } : {},
442
+ ...summary === void 0 ? {} : { summary }
443
+ };
444
+ } catch (e) {
445
+ let err = e instanceof Error ? e : void 0;
446
+ return {
447
+ id: story.id,
448
+ name,
449
+ error: { name: err?.name ?? "Error", message: err?.message ?? String(e) }
450
+ };
451
+ }
452
+ }, renderStorySnippet = (snippetMeta, args, storyDecorators, deps) => {
453
+ let { source, componentName, componentImport } = deps, localName = componentName ?? snippetMeta.name, viaComponentOutlet = !snippetMeta.selector, template = viaComponentOutlet ? buildComponentOutletTemplate(localName) : buildStoryTemplate(snippetMeta, args, source);
454
+ return buildHostComponentSnippet({
455
+ template,
456
+ componentName: localName,
457
+ componentImport,
458
+ viaComponentOutlet,
459
+ standalone: snippetMeta.standalone,
460
+ ngModules: snippetMeta.standalone ? void 0 : storyNgModules(storyDecorators, deps),
461
+ outputs: viaComponentOutlet ? [] : snippetMeta.outputs
462
+ });
463
+ }, buildStoryTemplate = (snippetMeta, args, source) => {
464
+ let inputNames = new Set(snippetMeta.inputs), inputs = Object.entries(args).filter(([argName]) => inputNames.has(argName)).map(([argName, node]) => ({
465
+ name: argName,
466
+ expression: evaluateArgExpression(node, source, snippetMeta.enums)
467
+ }));
468
+ return buildTemplate(snippetMeta.selector, { inputs, outputs: snippetMeta.outputs });
469
+ }, EVAL_FAILED = /* @__PURE__ */ Symbol("story-docs-eval-failed"), evaluateArgExpression = (node, source, enums) => {
470
+ let unwrapped = unwrapExpression(node), value = evaluateNode(unwrapped, enums);
471
+ return value !== EVAL_FAILED ? formatInputValue(value) : (sourceTextAtLoc(source, unwrapped.loc) ?? "undefined").replace(/"/g, "&quot;");
472
+ }, sourceTextAtLoc = (source, loc) => {
473
+ if (!loc)
474
+ return;
475
+ let lines = source.split(/\r\n|\n|\r/), startLine = loc.start.line - 1, endLine = loc.end.line - 1, start = lines[startLine], end = lines[endLine];
476
+ if (!(start === void 0 || end === void 0))
477
+ return startLine === endLine ? start.slice(loc.start.column, loc.end.column) : [
478
+ start.slice(loc.start.column),
479
+ ...lines.slice(startLine + 1, endLine),
480
+ end.slice(0, loc.end.column)
481
+ ].join(`
482
+ `);
483
+ }, evaluateNode = (node, enums) => {
484
+ let unwrapped = unwrapExpression(node);
485
+ if (t.isStringLiteral(unwrapped) || t.isNumericLiteral(unwrapped) || t.isBooleanLiteral(unwrapped))
486
+ return unwrapped.value;
487
+ if (t.isNullLiteral(unwrapped))
488
+ return null;
489
+ if (!(t.isIdentifier(unwrapped) && unwrapped.name === "undefined")) {
490
+ if (t.isUnaryExpression(unwrapped) && unwrapped.operator === "-" && t.isNumericLiteral(unwrapped.argument))
491
+ return -unwrapped.argument.value;
492
+ if (t.isTemplateLiteral(unwrapped) && unwrapped.expressions.length === 0)
493
+ return unwrapped.quasis[0]?.value.cooked ?? EVAL_FAILED;
494
+ if (t.isArrayExpression(unwrapped)) {
495
+ let values = [];
496
+ for (let element of unwrapped.elements) {
497
+ if (element === null || t.isSpreadElement(element))
498
+ return EVAL_FAILED;
499
+ let value = evaluateNode(element, enums);
500
+ if (value === EVAL_FAILED)
501
+ return EVAL_FAILED;
502
+ values.push(value);
503
+ }
504
+ return values;
505
+ }
506
+ if (t.isObjectExpression(unwrapped)) {
507
+ let value = {};
508
+ for (let property of unwrapped.properties) {
509
+ if (!t.isObjectProperty(property))
510
+ return EVAL_FAILED;
511
+ let key = keyOf(property);
512
+ if (key === null)
513
+ return EVAL_FAILED;
514
+ let propertyValue = evaluateNode(property.value, enums);
515
+ if (propertyValue === EVAL_FAILED)
516
+ return EVAL_FAILED;
517
+ value[key] = propertyValue;
518
+ }
519
+ return value;
520
+ }
521
+ if (t.isMemberExpression(unwrapped) && !unwrapped.computed && t.isIdentifier(unwrapped.object) && t.isIdentifier(unwrapped.property)) {
522
+ let objectName = unwrapped.object.name, propertyName = unwrapped.property.name;
523
+ return enums.find((enumeration) => enumeration.name === objectName)?.members.find((candidate) => candidate.name === propertyName)?.value ?? EVAL_FAILED;
524
+ }
525
+ return EVAL_FAILED;
526
+ }
527
+ };
528
+
529
+ // src/docgen/story-docs-preset.ts
530
+ var warnedMissingDocgenService = !1, getDocgenPayload = async (componentId) => {
531
+ try {
532
+ return await getService("core/docgen", { internal: !0 }).queries.docgen.loaded({ id: componentId });
533
+ } catch (error) {
534
+ warnedMissingDocgenService || (warnedMissingDocgenService = !0, logger3.warn(
535
+ `Angular story snippets are unavailable: querying core/docgen failed. ${error instanceof Error ? error.message : String(error)}`
536
+ ));
537
+ return;
538
+ }
539
+ }, experimental_storyDocsProvider = async (nextStoryDocs) => async (input) => {
540
+ let storyImportPath = getStoryImportPathFromEntry2(input.entry);
541
+ if (!storyImportPath || !STORY_FILE_TEST_REGEXP.test(storyImportPath))
542
+ return nextStoryDocs(input);
543
+ let ours = await buildStoryDocsPayload(input, { getDocgenPayload });
544
+ return ours ? { ...await nextStoryDocs(input), ...ours } : nextStoryDocs(input);
67
545
  };
68
546
 
69
547
  // src/preset.ts
@@ -104,7 +582,7 @@ var viteFinal = async (config, options) => {
104
582
  );
105
583
  } catch {
106
584
  }
107
- config.plugins = (config.plugins ?? []).flat().filter((plugin) => !plugin.name.includes("analogjs")).map((plugin) => plugin?.name === "plugin-csf" && plugin.enforce === "pre" ? { ...plugin, enforce: void 0 } : plugin);
585
+ config.plugins = (config.plugins ?? []).flat().filter((plugin) => !plugin?.name?.includes("analogjs"));
108
586
  let { mergeConfig, normalizePath } = await import("vite"), { default: angular } = await import("@analogjs/vite-plugin-angular"), framework = await options.presets.apply("framework"), compodocConfig = await resolveCompodocConfig(options, { viteRoot: config?.root });
109
587
  compodocConfig.enabled && await ensureCompodocDocumentation({
110
588
  compodocArgs: compodocConfig.compodocArgs,
@@ -187,7 +665,7 @@ function angularOptionsPlugin(options, { normalizePath, zoneless }) {
187
665
  preprocessorOptions: {
188
666
  scss: {
189
667
  ...sassOptions,
190
- loadPaths: loadPaths.map((loadPath) => `${resolve(workspaceRoot, loadPath)}`)
668
+ loadPaths: loadPaths.map((loadPath) => `${resolve4(workspaceRoot, loadPath)}`)
191
669
  }
192
670
  }
193
671
  }
@@ -203,7 +681,7 @@ function angularOptionsPlugin(options, { normalizePath, zoneless }) {
203
681
  let projectRoot = resolvedConfig?.root ?? process.cwd();
204
682
  return {
205
683
  code: `
206
- ${imports.map((extraImport) => extraImport.startsWith(".") || extraImport.startsWith("src") ? `import '${normalizePath(resolve(projectRoot, extraImport))}';` : `import '${extraImport}';`).join(`
684
+ ${imports.map((extraImport) => extraImport.startsWith(".") || extraImport.startsWith("src") ? `import '${normalizePath(resolve4(projectRoot, extraImport))}';` : `import '${extraImport}';`).join(`
207
685
  `)}
208
686
  ${code}
209
687
  `
@@ -248,7 +726,7 @@ function angularViteRedirectReapplyPlugin(options) {
248
726
  for (let r of redirects)
249
727
  if (getRealPath(r.absolutePath, preserveSymlinks) === idNorm)
250
728
  return this.addWatchFile(r.redirectPath), {
251
- code: readFileSync(r.redirectPath, "utf-8"),
729
+ code: readFileSync3(r.redirectPath, "utf-8"),
252
730
  map: { mappings: "" }
253
731
  };
254
732
  for (let a of automocks)
@@ -291,6 +769,7 @@ export {
291
769
  core,
292
770
  experimental_docgenProvider,
293
771
  experimental_manifests,
772
+ experimental_storyDocsProvider,
294
773
  previewAnnotations,
295
774
  typescript,
296
775
  viteFinal