@storybook/web-components 11.0.0-alpha.4 → 11.0.0-alpha.5

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/preset.js CHANGED
@@ -1,20 +1,22 @@
1
- import CJS_COMPAT_NODE_URL_ntm93oozfz from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_ntm93oozfz from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_ntm93oozfz from "node:module";
1
+ import CJS_COMPAT_NODE_URL_kx3y04w7glc from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_kx3y04w7glc from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_kx3y04w7glc from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_ntm93oozfz.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_ntm93oozfz.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_ntm93oozfz.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_kx3y04w7glc.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_kx3y04w7glc.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_kx3y04w7glc.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
- DEFAULT_TYPE_PROPERTY
14
- } from "./_node-chunks/chunk-3OPBLV6G.js";
13
+ DEFAULT_TYPE_PROPERTY,
14
+ parseStoryFile,
15
+ resolveStoryComponent
16
+ } from "./_node-chunks/chunk-RKWQNNM2.js";
15
17
 
16
18
  // src/preset.ts
17
- import { fileURLToPath as fileURLToPath2 } from "node:url";
19
+ import { fileURLToPath as fileURLToPath3 } from "node:url";
18
20
 
19
21
  // src/docgen/preset.ts
20
22
  import { fileURLToPath } from "node:url";
@@ -38,8 +40,6 @@ var DOCGEN_WORKER_SPECIFIER = "@storybook/web-components/internal/docgen-worker"
38
40
 
39
41
  // src/docgen/preset.ts
40
42
  var experimental_docgenProvider = async (existing = [], options) => {
41
- if (!(await options.presets.apply("features", {}))?.experimentalDocgenServer)
42
- return existing;
43
43
  let frameworkOptions = await options.presets.apply(
44
44
  "frameworkOptions"
45
45
  ) ?? {}, descriptor = {
@@ -52,7 +52,7 @@ var experimental_docgenProvider = async (existing = [], options) => {
52
52
  return [...existing, descriptor];
53
53
  }, experimental_manifests = async (existingManifests = {}, options) => {
54
54
  let features = await options.presets.apply("features", {});
55
- return !features?.experimentalDocgenServer || !features?.componentsManifest ? existingManifests : {
55
+ return !features?.docgenServer || !features?.componentsManifest ? existingManifests : {
56
56
  ...existingManifests,
57
57
  components: {
58
58
  v: 0,
@@ -62,18 +62,1787 @@ var experimental_docgenProvider = async (existing = [], options) => {
62
62
  };
63
63
  };
64
64
 
65
+ // src/docgen/story-docs-preset.ts
66
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
67
+ import { STORY_FILE_TEST_REGEXP, getStoryImportPathFromEntry as getStoryImportPathFromEntry2 } from "storybook/internal/common";
68
+ import { getService } from "storybook/internal/core-server";
69
+ import { logger } from "storybook/internal/node-logger";
70
+
71
+ // src/docgen/story-docs/build-story-docs.ts
72
+ import { types as t7 } from "storybook/internal/babel";
73
+ import { getComponentIdFromEntry, getStoryImportPathFromEntry } from "storybook/internal/common";
74
+ import { storyNameFromExport } from "storybook/internal/csf";
75
+ import {
76
+ authoredSource,
77
+ createStoryArgsResolver,
78
+ createStoryReferenceResolver,
79
+ extractStoryJSDocInfo,
80
+ noSnippetWarning,
81
+ sourceOf as sourceOf6,
82
+ unwrapExpression as unwrapExpression5,
83
+ unresolvedWarning
84
+ } from "storybook/internal/csf-tools";
85
+ import { resolve as resolve2 } from "node:path";
86
+
87
+ // src/docgen/story-docs/arg-values.ts
88
+ import { types as t } from "storybook/internal/babel";
89
+ import { keyOf, sourceOf, templateParts, unwrapExpression } from "storybook/internal/csf-tools";
90
+ var FAILED = /* @__PURE__ */ Symbol("failed");
91
+ function evaluateArgValue(node) {
92
+ let value = evaluate(node);
93
+ if (value === FAILED) {
94
+ let unwrapped = unwrapExpression(node);
95
+ return t.isFunction(unwrapped) ? { kind: "function" } : { kind: "unresolved", source: sourceOf(node) };
96
+ }
97
+ return value === void 0 ? { kind: "unset" } : { kind: "value", value };
98
+ }
99
+ var evaluate = (node) => {
100
+ let unwrapped = unwrapExpression(node);
101
+ if (t.isStringLiteral(unwrapped) || t.isNumericLiteral(unwrapped) || t.isBooleanLiteral(unwrapped))
102
+ return unwrapped.value;
103
+ if (t.isNullLiteral(unwrapped)) return null;
104
+ if (t.isIdentifier(unwrapped, { name: "undefined" }) || t.isUnaryExpression(unwrapped) && unwrapped.operator === "void") return;
105
+ if (t.isUnaryExpression(unwrapped) && (unwrapped.operator === "-" || unwrapped.operator === "+") && t.isNumericLiteral(unwrapped.argument))
106
+ return unwrapped.operator === "-" ? -unwrapped.argument.value : unwrapped.argument.value;
107
+ let parts = templateParts(unwrapped);
108
+ return parts && parts.expressions.length === 0 ? parts.quasis[0] ?? FAILED : t.isFunction(unwrapped) ? FAILED : t.isArrayExpression(unwrapped) ? evaluateArray(unwrapped) : t.isObjectExpression(unwrapped) ? evaluateObject(unwrapped) : FAILED;
109
+ }, evaluateArray = (node) => {
110
+ let values = [];
111
+ for (let element of node.elements) {
112
+ if (element === null || t.isSpreadElement(element))
113
+ return FAILED;
114
+ let value = evaluate(element);
115
+ if (value === FAILED)
116
+ return FAILED;
117
+ values.push(value);
118
+ }
119
+ return values;
120
+ }, evaluateObject = (node) => {
121
+ let values = {};
122
+ for (let property of node.properties) {
123
+ if (!t.isObjectProperty(property) || property.computed || t.isSpreadElement(property))
124
+ return FAILED;
125
+ let key = keyOf(property), value = evaluate(property.value);
126
+ if (key === null || value === FAILED)
127
+ return FAILED;
128
+ values[key] = value;
129
+ }
130
+ return values;
131
+ };
132
+
133
+ // ../../../node_modules/es-toolkit/dist/string/capitalize.mjs
134
+ function capitalize(str) {
135
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
136
+ }
137
+
138
+ // ../../../node_modules/es-toolkit/dist/string/words.mjs
139
+ var CASE_SPLIT_PATTERN = new RegExp("\\p{Lu}?\\p{Ll}+|[0-9]+|\\p{Lu}+(?!\\p{Ll})|\\p{Emoji_Presentation}|\\p{Extended_Pictographic}|\\p{L}+", "gu");
140
+ function words(str) {
141
+ return Array.from(str.match(CASE_SPLIT_PATTERN) ?? []);
142
+ }
143
+
144
+ // ../../../node_modules/es-toolkit/dist/string/pascalCase.mjs
145
+ function pascalCase(str) {
146
+ return words(str).map((word) => capitalize(word)).join("");
147
+ }
148
+
149
+ // src/docgen/component-docgen/arg-types/event-action-name.ts
150
+ function eventActionName(name) {
151
+ return `on${pascalCase(name)}`;
152
+ }
153
+
154
+ // src/docgen/story-docs/classify-args.ts
155
+ function classifyArg(key, isFunction, argTypes, declaration) {
156
+ let row = argTypes[key];
157
+ if (row) {
158
+ let event = row.table?.category === "events" ? row.name ?? key : eventForArg(key, declaration);
159
+ if (isFunction || row.action)
160
+ return { event, kind: "listener" };
161
+ let name = row.name ?? key;
162
+ switch (row.table?.category) {
163
+ case "attributes":
164
+ return attributeBinding(
165
+ name,
166
+ attributeViaField(key, name, declaration),
167
+ attributeDefault(key, name, declaration)
168
+ );
169
+ case "properties": {
170
+ let attribute = pairedAttribute(name, declaration);
171
+ return attribute ? attributeBinding(
172
+ attribute,
173
+ !0,
174
+ fieldDefault(name, declaration) ?? attributeDefault(name, attribute, declaration)
175
+ ) : { kind: "property", name };
176
+ }
177
+ case "events":
178
+ return { event: name, kind: "listener" };
179
+ case "methods":
180
+ return { kind: "method" };
181
+ case "slots":
182
+ return { kind: "slot", name };
183
+ case "css shadow parts":
184
+ return { kind: "cssPart", name };
185
+ case "css states":
186
+ return { kind: "cssState", name };
187
+ case "css custom properties":
188
+ return { kind: "cssProperty", name };
189
+ default:
190
+ break;
191
+ }
192
+ }
193
+ return isFunction ? { event: eventForArg(key, declaration), kind: "listener" } : { kind: "unknown" };
194
+ }
195
+ var fieldDefault = (fieldName, declaration) => fieldDeclaration(fieldName, declaration)?.default, pairedAttribute = (fieldName, declaration) => {
196
+ let field = fieldDeclaration(fieldName, declaration);
197
+ return field?.attribute ? field.attribute : declaration.attributes?.find((attribute) => attribute.fieldName === fieldName)?.name;
198
+ }, attributeBinding = (name, viaField, defaultValue) => ({
199
+ kind: "attribute",
200
+ name,
201
+ viaField,
202
+ ...defaultValue === void 0 ? {} : { defaultValue }
203
+ }), fieldDeclaration = (fieldName, declaration) => declaration.members?.find(
204
+ (member) => member.kind === "field" && member.name === fieldName
205
+ ), attributeDeclaration = (attributeName, declaration) => declaration.attributes?.find((attribute) => attribute.name === attributeName), attributeViaField = (key, attributeName, declaration) => pairedAttribute(key, declaration) === attributeName, attributeDefault = (key, attributeName, declaration) => {
206
+ let attribute = attributeDeclaration(attributeName, declaration), fieldName = attribute?.fieldName === key || pairedAttribute(key, declaration) === attributeName ? key : void 0;
207
+ return (fieldName ? fieldDefault(fieldName, declaration) : void 0) ?? attribute?.default;
208
+ }, eventForArg = (key, declaration) => {
209
+ let matches = declaration.events?.filter(
210
+ (event) => key === event.name || key === eventActionName(event.name)
211
+ ) ?? [];
212
+ return matches.length === 1 ? matches[0].name : void 0;
213
+ };
214
+
215
+ // src/docgen/story-docs/html-tree.ts
216
+ var INLINE_LIMIT = 80, INDENT = " ", RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set(["pre", "script", "style", "textarea", "title"]), VOID_ELEMENTS = /* @__PURE__ */ new Set([
217
+ "area",
218
+ "base",
219
+ "br",
220
+ "col",
221
+ "embed",
222
+ "hr",
223
+ "img",
224
+ "input",
225
+ "link",
226
+ "meta",
227
+ "source",
228
+ "track",
229
+ "wbr"
230
+ ]);
231
+ function parseHtml(source) {
232
+ let root = { children: [] }, stack = [root], offset = 0;
233
+ for (; offset < source.length; ) {
234
+ let read = readToken(source, offset);
235
+ if (!read) {
236
+ current(stack).children.push({ kind: "malformed", text: source.slice(offset) });
237
+ break;
238
+ }
239
+ offset = read.end;
240
+ let token = read.token;
241
+ switch (token.kind) {
242
+ case "comment":
243
+ case "text":
244
+ current(stack).children.push(token);
245
+ break;
246
+ case "start": {
247
+ let node = {
248
+ attributes: token.attributes,
249
+ children: [],
250
+ closed: token.selfClosing || VOID_ELEMENTS.has(token.name.toLowerCase()),
251
+ kind: "element",
252
+ name: token.name,
253
+ selfClosing: token.selfClosing
254
+ };
255
+ current(stack).children.push(node), node.closed || stack.push(node);
256
+ break;
257
+ }
258
+ case "raw":
259
+ current(stack).children.push({
260
+ attributes: token.attributes,
261
+ closed: !0,
262
+ kind: "rawText",
263
+ name: token.name,
264
+ text: token.text
265
+ });
266
+ break;
267
+ case "end": {
268
+ let top = stack.at(-1);
269
+ if (VOID_ELEMENTS.has(token.name))
270
+ break;
271
+ if (!("kind" in top) || top.kind !== "element" || top.name.toLowerCase() !== token.name)
272
+ return current(stack).children.push({ kind: "malformed", text: source.slice(read.start) }), root.children;
273
+ top.closed = !0, stack.pop();
274
+ break;
275
+ }
276
+ default:
277
+ return token;
278
+ }
279
+ }
280
+ return root.children;
281
+ }
282
+ function printHtml(nodes) {
283
+ return printableChildren(nodes).map((node) => printNode(node, 0)).join(`
284
+ `);
285
+ }
286
+ var current = (stack) => stack[stack.length - 1], readToken = (source, start) => {
287
+ if (source[start] !== "<") {
288
+ let next = source.indexOf("<", start), end2 = next === -1 ? source.length : next;
289
+ return { end: end2, start, token: { kind: "text", text: source.slice(start, end2) } };
290
+ }
291
+ if (source.startsWith("<!--", start)) {
292
+ let end2 = source.indexOf("-->", start + 4);
293
+ return end2 === -1 ? void 0 : { end: end2 + 3, start, token: { kind: "comment", text: source.slice(start, end2 + 3) } };
294
+ }
295
+ let end = findTagEnd(source, start);
296
+ if (end === void 0)
297
+ return;
298
+ let raw = source.slice(start, end), endMatch = /^<\/\s*([^\s>]+)\s*>$/.exec(raw);
299
+ if (endMatch)
300
+ return { end, start, token: { kind: "end", name: endMatch[1].toLowerCase() } };
301
+ let startMatch = /^<\s*([^\s/>]+)([\s\S]*?)>$/.exec(raw);
302
+ if (!startMatch)
303
+ return { end, start, token: { kind: "text", text: raw } };
304
+ let name = startMatch[1], rest = startMatch[2], selfClosing = hasSelfClosingSlash(rest), attrs = selfClosing ? rest.replace(/\/\s*$/, "") : rest, attributes = parseAttributes(attrs.trim());
305
+ if (!selfClosing && RAW_TEXT_ELEMENTS.has(name.toLowerCase())) {
306
+ let rawEnd = findRawTextEnd(source, end, name);
307
+ if (rawEnd)
308
+ return {
309
+ end: rawEnd.end,
310
+ start,
311
+ token: { attributes, kind: "raw", name, text: source.slice(end, rawEnd.start) }
312
+ };
313
+ }
314
+ return { end, start, token: { attributes, kind: "start", name, selfClosing } };
315
+ }, parseAttributes = (source) => {
316
+ let attributes = [], index = 0;
317
+ for (; index < source.length; ) {
318
+ for (; /\s/.test(source[index] ?? ""); )
319
+ index += 1;
320
+ if (index >= source.length)
321
+ break;
322
+ let nameStart = index;
323
+ for (; index < source.length && !/[\s=]/.test(source[index]); )
324
+ index += 1;
325
+ let name = source.slice(nameStart, index);
326
+ for (; /\s/.test(source[index] ?? ""); )
327
+ index += 1;
328
+ if (source[index] !== "=") {
329
+ attributes.push({ name, value: void 0 });
330
+ continue;
331
+ }
332
+ for (index += 1; /\s/.test(source[index] ?? ""); )
333
+ index += 1;
334
+ let quote = source[index] === '"' || source[index] === "'" ? source[index] : void 0;
335
+ if (quote) {
336
+ index += 1;
337
+ let valueStart2 = index;
338
+ for (; index < source.length && source[index] !== quote; )
339
+ index += 1;
340
+ attributes.push({
341
+ name,
342
+ quoted: !0,
343
+ value: decodeAttribute(source.slice(valueStart2, index))
344
+ }), source[index] === quote && (index += 1);
345
+ continue;
346
+ }
347
+ let valueStart = index;
348
+ for (; index < source.length && !/\s/.test(source[index]); )
349
+ index += 1;
350
+ attributes.push({ name, value: decodeAttribute(source.slice(valueStart, index)) });
351
+ }
352
+ return attributes;
353
+ }, printNode = (node, depth) => {
354
+ let indent = INDENT.repeat(depth);
355
+ switch (node.kind) {
356
+ case "comment":
357
+ return `${indent}${node.text}`;
358
+ case "element":
359
+ return printElement(node, depth);
360
+ case "malformed":
361
+ return node.text;
362
+ case "rawText":
363
+ return printRawTextElement(node, depth);
364
+ case "text":
365
+ return `${indent}${collapseText(node.text)}`;
366
+ default:
367
+ return node;
368
+ }
369
+ }, printElement = (node, depth) => {
370
+ let indent = INDENT.repeat(depth), startTag = printStartTag(node, depth);
371
+ if (VOID_ELEMENTS.has(node.name.toLowerCase()))
372
+ return startTag;
373
+ if (node.selfClosing)
374
+ return `${startTag}</${node.name}>`;
375
+ if (printableChildren(node.children).length === 0)
376
+ return node.closed ? `${startTag}</${node.name}>` : startTag;
377
+ let inline = inlineElementText(node, !0)?.text;
378
+ if (inline && indent.length + inline.length <= INLINE_LIMIT)
379
+ return `${indent}${inline}`;
380
+ let body = printChildLines(node.children, depth + 1).join(`
381
+ `);
382
+ return node.closed ? `${startTag}
383
+ ${body}
384
+ ${indent}</${node.name}>` : `${startTag}
385
+ ${body}`;
386
+ }, printChildLines = (children, depth) => {
387
+ let lines = [], group = [], flushGroup = () => {
388
+ if (group.length === 0)
389
+ return;
390
+ let inline = inlineChildrenText(group), indent = INDENT.repeat(depth);
391
+ inline && inline.hasText && indent.length + inline.text.length <= INLINE_LIMIT ? lines.push(`${indent}${inline.text}`) : group.forEach((child) => lines.push(printNode(child, depth))), group = [];
392
+ };
393
+ for (let child of children) {
394
+ if (child.kind === "text" && collapseText(child.text) === "") {
395
+ flushGroup();
396
+ continue;
397
+ }
398
+ if (inlineChildText(child)) {
399
+ group.push(child);
400
+ continue;
401
+ }
402
+ flushGroup(), lines.push(printNode(child, depth));
403
+ }
404
+ return flushGroup(), lines;
405
+ }, inlineElementText = (node, requireText = !0) => {
406
+ let lowerName = node.name.toLowerCase();
407
+ if (VOID_ELEMENTS.has(lowerName))
408
+ return { hasText: !1, text: printCompactStartTag(node) };
409
+ if (node.selfClosing)
410
+ return { hasText: !1, text: `${printCompactStartTag(node)}</${node.name}>` };
411
+ if (printableChildren(node.children).length === 0)
412
+ return { hasText: !1, text: node.closed ? `${printCompactStartTag(node)}</${node.name}>` : printCompactStartTag(node) };
413
+ let childrenText = inlineChildrenText(node.children);
414
+ return childrenText === void 0 || requireText && !childrenText.hasText ? void 0 : {
415
+ hasText: childrenText.hasText,
416
+ text: `${printCompactStartTag(node)}${childrenText.text}</${node.name}>`
417
+ };
418
+ }, inlineChildrenText = (children) => {
419
+ let parts = [], hasText = !1;
420
+ for (let index = 0; index < children.length; index += 1) {
421
+ let child = children[index], part = inlineChildText(child);
422
+ if (part === void 0)
423
+ return;
424
+ part.text !== "" && parts.push(
425
+ child.kind === "text" ? inlineText(child.text, index === 0, index === children.length - 1) : part.text
426
+ ), hasText ||= part.hasText;
427
+ }
428
+ return { hasText, text: parts.join("") };
429
+ }, inlineChildText = (node) => {
430
+ switch (node.kind) {
431
+ case "text":
432
+ return collapseText(node.text) === "" ? void 0 : { hasText: !0, text: node.text };
433
+ case "element": {
434
+ if (!isInlineChildElement(node))
435
+ return;
436
+ let inline = inlineElementText(node, !1);
437
+ return inline ? { hasText: !1, text: inline.text } : void 0;
438
+ }
439
+ case "comment":
440
+ case "malformed":
441
+ case "rawText":
442
+ return;
443
+ default:
444
+ return node;
445
+ }
446
+ }, isInlineChildElement = (node) => !VOID_ELEMENTS.has(node.name.toLowerCase()) && printableChildren(node.children).every((child) => child.kind === "text"), printRawTextElement = (node, depth) => {
447
+ let startTag = printStartTag({ attributes: node.attributes, name: node.name }, depth);
448
+ return node.closed ? `${startTag}${node.text}</${node.name}>` : `${startTag}${node.text}`;
449
+ }, printStartTag = (node, depth) => {
450
+ let indent = INDENT.repeat(depth), compact = printCompactStartTag(node);
451
+ return indent.length + compact.length <= INLINE_LIMIT ? `${indent}${compact}` : node.attributes.length === 0 ? `${indent}<${node.name}>` : [
452
+ `${indent}<${node.name}`,
453
+ ...node.attributes.map((attr) => `${indent}${INDENT}${printHtmlAttribute(attr)}`),
454
+ `${indent}>`
455
+ ].join(`
456
+ `);
457
+ }, printCompactStartTag = (node) => {
458
+ let attrs = node.attributes.map(printHtmlAttribute).join(" "), suffix = attrs ? ` ${attrs}` : "";
459
+ return `<${node.name}${suffix}>`;
460
+ }, printHtmlAttribute = ({ name, value }) => value === void 0 ? name : `${name}="${escapeAttribute(value)}"`, decodeAttribute = (value) => value.replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&lt;/g, "<").replace(/&amp;/g, "&"), printableChildren = (children) => children.filter((child) => child.kind !== "text" || collapseText(child.text) !== ""), collapseText = (text) => text.trim().replace(/\s+/g, " "), inlineText = (text, first, last) => {
461
+ let collapsed = text.replace(/\s+/g, " ");
462
+ return first && (collapsed = collapsed.trimStart()), last && (collapsed = collapsed.trimEnd()), collapsed;
463
+ }, hasSelfClosingSlash = (rest) => {
464
+ let index = rest.length - 1;
465
+ for (; index >= 0 && /\s/.test(rest[index]); )
466
+ index -= 1;
467
+ return rest[index] !== "/" ? !1 : index === 0 || /\s/.test(rest[index - 1]);
468
+ }, findTagEnd = (source, start) => {
469
+ let quote, canOpenQuote = !1;
470
+ for (let index = start + 1; index < source.length; index += 1) {
471
+ let char = source[index];
472
+ if (quote) {
473
+ char === quote && (quote = void 0);
474
+ continue;
475
+ }
476
+ if ((char === '"' || char === "'") && canOpenQuote) {
477
+ quote = char;
478
+ continue;
479
+ }
480
+ if (/\s|=/.test(char) && (canOpenQuote = !0), char === ">")
481
+ return index + 1;
482
+ }
483
+ }, findRawTextEnd = (source, start, name) => {
484
+ let lower = source.toLowerCase(), close = `</${name.toLowerCase()}`, index = start;
485
+ for (; index < source.length; ) {
486
+ let found = lower.indexOf(close, index);
487
+ if (found === -1)
488
+ return;
489
+ let boundary = source[found + close.length];
490
+ if (boundary !== void 0 && /[\s>]/.test(boundary)) {
491
+ let end = findTagEnd(source, found);
492
+ return end === void 0 ? void 0 : { end, start: found };
493
+ }
494
+ index = found + close.length;
495
+ }
496
+ };
497
+
498
+ // src/docgen/story-docs/print-element.ts
499
+ function escapeAttribute(value, quote = '"') {
500
+ let escaped = value.replace(/&/g, "&amp;").replace(/</g, "&lt;");
501
+ return quote === "'" ? escaped.replace(/'/g, "&#39;") : escaped.replace(/"/g, "&quot;");
502
+ }
503
+ function printElementSnippet(snippet) {
504
+ let nodes = [
505
+ ...styleNodes(snippet.styleRules),
506
+ {
507
+ attributes: elementAttributes(snippet),
508
+ children: slotNodes(snippet.slots),
509
+ closed: !0,
510
+ kind: "element",
511
+ name: snippet.tag,
512
+ selfClosing: !1
513
+ }
514
+ ], element = printHtml(nodes), listenerScript = printListenerScript(snippet.tag, snippet.listeners);
515
+ return listenerScript ? `${element}
516
+ ${listenerScript}` : element;
517
+ }
518
+ function printListenerScript(tag, listeners) {
519
+ let uniqueListeners = uniqueListenersByEvent(
520
+ listeners.filter((listener) => listener.tag === tag)
521
+ );
522
+ return uniqueListeners.length === 0 ? void 0 : `<script>
523
+ {
524
+ const host = document.currentScript.previousElementSibling;
525
+ ${uniqueListeners.map(({ event, handler }) => ` host.addEventListener('${escapeScriptString(
526
+ event
527
+ )}', ${sanitizeScriptHandler(handler)});`).join(`
528
+ `)}
529
+ }
530
+ </script>`;
531
+ }
532
+ function printRootListenerScript(listeners) {
533
+ let uniqueListeners = uniqueListenersByEvent(listeners);
534
+ return uniqueListeners.length === 0 ? void 0 : `<script>
535
+ {
536
+ const host = document.currentScript.previousElementSibling;
537
+ ${uniqueListeners.map(
538
+ ({ event, handler }) => ` host.addEventListener('${escapeScriptString(event)}', ${sanitizeScriptHandler(handler)});`
539
+ ).join(`
540
+ `)}
541
+ }
542
+ </script>`;
543
+ }
544
+ var uniqueListenersByEvent = (listeners) => {
545
+ let events = /* @__PURE__ */ new Set();
546
+ return listeners.filter(({ event }) => events.has(event) ? !1 : (events.add(event), !0));
547
+ }, styleNodes = (rules) => rules.length === 0 ? [] : [
548
+ {
549
+ attributes: [],
550
+ closed: !0,
551
+ kind: "rawText",
552
+ name: "style",
553
+ text: `
554
+ ${rules.map(({ selector, declarations }) => ` ${selector} { ${declarations} }`).join(`
555
+ `)}
556
+ `
557
+ }
558
+ ], elementAttributes = (snippet) => {
559
+ let attributes = snippet.attributes.map(attributeNode).filter((attribute) => attribute !== void 0), style = printCssProperties(snippet.cssProperties);
560
+ return [...attributes, ...style ? [{ name: "style", value: style }] : []];
561
+ };
562
+ function printAttribute({
563
+ name,
564
+ value,
565
+ viaField
566
+ }) {
567
+ if (value === !0)
568
+ return name;
569
+ if (value === "")
570
+ return viaField ? `${name}=""` : void 0;
571
+ if (value === !1 || value === null || value === void 0)
572
+ return;
573
+ let text = typeof value == "object" ? JSON.stringify(value) : String(value);
574
+ return `${name}="${escapeAttribute(text)}"`;
575
+ }
576
+ var printCssProperties = (properties) => {
577
+ let declarations = properties.filter(({ value }) => value != null && value !== "").map(({ name, value }) => `${name}: ${String(value)};`);
578
+ return declarations.length === 0 ? void 0 : declarations.join(" ");
579
+ }, attributeNode = ({
580
+ name,
581
+ value,
582
+ viaField
583
+ }) => {
584
+ if (value === !0)
585
+ return { name, value: void 0 };
586
+ if (value === "")
587
+ return viaField ? { name, value: "" } : void 0;
588
+ if (value === !1 || value === null || value === void 0)
589
+ return;
590
+ let text = typeof value == "object" ? JSON.stringify(value) : String(value);
591
+ return { name, value: text };
592
+ }, hasSlotContent = ({ html }) => html != null && html !== "", slotNodes = (slots) => slots.filter(hasSlotContent).flatMap(({ name, html }, index) => [
593
+ ...index === 0 ? [] : [slotSeparatorNode()],
594
+ ...nodesForSlot(name, String(html))
595
+ ]), slotSeparatorNode = () => ({ kind: "text", text: `
596
+ ` }), nodesForSlot = (name, content) => {
597
+ let nodes = parseHtml(content);
598
+ if (name === "default")
599
+ return nodes;
600
+ let [only] = nodes;
601
+ return nodes.length === 1 && only?.kind === "element" && !only.selfClosing && !hasSlotAttribute(only) ? (only.attributes.push({ name: "slot", value: name }), nodes) : [
602
+ {
603
+ attributes: [{ name: "slot", value: name }],
604
+ children: nodes,
605
+ closed: !0,
606
+ kind: "element",
607
+ name: "span",
608
+ selfClosing: !1
609
+ }
610
+ ];
611
+ }, hasSlotAttribute = (node) => node.attributes.some((attribute) => attribute.name === "slot"), escapeScriptString = (value) => value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/</g, "\\x3C"), sanitizeScriptHandler = (value) => value.replace(/<!--/g, "<\\!--").replace(/<script/gi, "<\\script").replace(/<\/script/gi, "<\\/script");
612
+
613
+ // src/docgen/story-docs/template-print.ts
614
+ import { sourceOf as sourceOf4 } from "storybook/internal/csf-tools";
615
+
616
+ // src/docgen/story-docs/template-holes.ts
617
+ import { types as t3 } from "storybook/internal/babel";
618
+ import { sourceOf as sourceOf3, unwrapExpression as unwrapExpression3 } from "storybook/internal/csf-tools";
619
+
620
+ // src/docgen/story-docs/template-scope.ts
621
+ import { types as t2 } from "storybook/internal/babel";
622
+ import {
623
+ collectImportBindings,
624
+ keyOf as keyOf2,
625
+ returnedExpressionPath,
626
+ sourceOf as sourceOf2,
627
+ unwrapExpression as unwrapExpression2
628
+ } from "storybook/internal/csf-tools";
629
+ var TEMPLATE_TAG_SOURCES = ["lit", "lit-html", "lit-element"];
630
+ function resolveHtmlTemplate(renderFunction, csf) {
631
+ let bindings = collectImportBindings(csf._file.path), returned = returnedTemplateExpression(renderFunction, bindings);
632
+ return returned ? templateFromExpression(unwrapExpression2(returned.node), bindings, returned.scope) : void 0;
633
+ }
634
+ function templateFromExpression(expression, bindings, scope) {
635
+ if (t2.isStringLiteral(expression))
636
+ return {
637
+ bindings,
638
+ expressions: [],
639
+ lit: !1,
640
+ quasis: [expression.value],
641
+ scope,
642
+ source: sourceOf2(expression)
643
+ };
644
+ if (t2.isTemplateLiteral(expression))
645
+ return templateFromLiteral(expression, bindings, !1, scope, sourceOf2(expression));
646
+ if (!(!t2.isTaggedTemplateExpression(expression) || !t2.isIdentifier(expression.tag)))
647
+ return isImported(expression.tag.name, "html", TEMPLATE_TAG_SOURCES, bindings) || isImported(expression.tag.name, "default", TEMPLATE_TAG_SOURCES, bindings) ? templateFromLiteral(expression.quasi, bindings, !0, scope, sourceOf2(expression)) : void 0;
648
+ }
649
+ function aliasValueForIdentifier(expression, scope) {
650
+ return scope.aliases.get(expression.name);
651
+ }
652
+ function argReferenceForExpression(expression, scope) {
653
+ let unwrapped = unwrapExpression2(expression);
654
+ if (t2.isIdentifier(unwrapped)) {
655
+ let alias = aliasValueForIdentifier(unwrapped, scope);
656
+ return alias?.kind === "arg" ? { name: alias.name, path: alias.path } : parameterArgReference(unwrapped, scope);
657
+ }
658
+ if (!t2.isMemberExpression(unwrapped))
659
+ return;
660
+ let property = memberPropertyName(unwrapped);
661
+ if (property === void 0)
662
+ return;
663
+ if (scope.args && t2.isIdentifier(unwrapped.object, { name: scope.args }))
664
+ return { name: property, path: [] };
665
+ if (!t2.isExpression(unwrapped.object))
666
+ return;
667
+ let object = argReferenceForExpression(unwrapped.object, scope);
668
+ return object ? { name: object.name, path: [...object.path, property] } : void 0;
669
+ }
670
+ var returnedTemplateExpression = (renderFunction, bindings) => {
671
+ let baseScope = scopeForRenderFunction(renderFunction), strict = returnedExpressionPath(renderFunction);
672
+ if (strict)
673
+ return { node: strict.node, scope: baseScope };
674
+ if (!t2.isBlockStatement(renderFunction.node.body))
675
+ return;
676
+ let statements = renderFunction.node.body.body, returned = statements.at(-1);
677
+ if (!t2.isReturnStatement(returned) || !t2.isExpression(returned.argument))
678
+ return;
679
+ let scope = copyScope(baseScope);
680
+ for (let statement of statements.slice(0, -1))
681
+ if (!t2.isVariableDeclaration(statement) || statement.kind !== "const" && statement.kind !== "let" || !addVariableAliases(statement, scope, bindings))
682
+ return;
683
+ return { node: returned.argument, scope };
684
+ }, scopeForRenderFunction = (renderFunction) => {
685
+ let [first] = renderFunction.node.params, scope = { aliases: /* @__PURE__ */ new Map(), destructured: /* @__PURE__ */ new Map() };
686
+ if (t2.isIdentifier(first))
687
+ return scope.args = first.name, scope;
688
+ if (!t2.isObjectPattern(first))
689
+ return scope;
690
+ let destructured = destructuredAliases(first, { name: "", path: [] });
691
+ if (!destructured)
692
+ return scope;
693
+ for (let [local, value] of destructured)
694
+ scope.aliases.set(local, value), value.kind === "arg" && value.path.length === 0 && scope.destructured.set(local, value.name);
695
+ return scope;
696
+ }, addVariableAliases = (declaration, scope, bindings) => {
697
+ for (let declarator of declaration.declarations) {
698
+ if (!t2.isExpression(declarator.init))
699
+ return !1;
700
+ if (t2.isIdentifier(declarator.id)) {
701
+ let alias = aliasForExpression(declarator.init, scope, bindings);
702
+ if (!alias)
703
+ return !1;
704
+ scope.aliases.set(declarator.id.name, alias);
705
+ continue;
706
+ }
707
+ if (t2.isObjectPattern(declarator.id)) {
708
+ let source = destructureSourceForExpression(declarator.init, scope);
709
+ if (!source)
710
+ return !1;
711
+ let aliases = destructuredAliases(declarator.id, source);
712
+ if (!aliases)
713
+ return !1;
714
+ aliases.forEach((alias, name) => scope.aliases.set(name, alias));
715
+ continue;
716
+ }
717
+ return !1;
718
+ }
719
+ return !0;
720
+ }, destructureSourceForExpression = (expression, scope) => {
721
+ let unwrapped = unwrapExpression2(expression);
722
+ return scope.args && t2.isIdentifier(unwrapped, { name: scope.args }) ? { name: "", path: [] } : argReferenceForExpression(expression, scope);
723
+ }, aliasForExpression = (expression, scope, bindings) => {
724
+ let unwrapped = unwrapExpression2(expression), arg = t2.isExpression(unwrapped) ? argReferenceForExpression(unwrapped, scope) : void 0;
725
+ if (arg)
726
+ return { kind: "arg", source: sourceOf2(expression), ...arg };
727
+ if (isStaticLiteral(unwrapped))
728
+ return { kind: "value", value: literalValue(unwrapped) };
729
+ let template = templateFromExpression(unwrapped, bindings, copyScope(scope));
730
+ if (template)
731
+ return { kind: "template", source: sourceOf2(expression), template };
732
+ }, destructuredAliases = (pattern, source) => {
733
+ let aliases = /* @__PURE__ */ new Map();
734
+ for (let property of pattern.properties) {
735
+ if (!t2.isObjectProperty(property) || property.computed)
736
+ return;
737
+ let key = keyOf2(property);
738
+ if (!key)
739
+ return;
740
+ let root = source.name === "" ? { name: key, path: [] } : { name: source.name, path: [...source.path, key] };
741
+ if (t2.isIdentifier(property.value))
742
+ aliases.set(property.value.name, { kind: "arg", ...root });
743
+ else if (t2.isObjectPattern(property.value)) {
744
+ let nested = destructuredAliases(property.value, root);
745
+ if (!nested)
746
+ return;
747
+ nested.forEach((alias, name) => aliases.set(name, alias));
748
+ } else
749
+ return;
750
+ }
751
+ return aliases;
752
+ }, parameterArgReference = (expression, scope) => {
753
+ let arg = scope.destructured.get(expression.name);
754
+ return arg ? { name: arg, path: [] } : void 0;
755
+ }, memberPropertyName = (expression) => !expression.computed && t2.isIdentifier(expression.property) ? expression.property.name : expression.computed && t2.isStringLiteral(expression.property) ? expression.property.value : void 0, templateFromLiteral = (literal, bindings, lit, scope, source) => ({
756
+ bindings,
757
+ expressions: literal.expressions.filter(
758
+ (expression) => t2.isExpression(expression)
759
+ ),
760
+ lit,
761
+ quasis: literal.quasis.map((quasi) => quasi.value.raw),
762
+ scope,
763
+ source
764
+ }), copyScope = (scope) => ({
765
+ ...scope,
766
+ aliases: new Map(scope.aliases),
767
+ destructured: new Map(scope.destructured)
768
+ }), isImported = (local, importName, sources, bindings) => {
769
+ let binding = bindings.get(local);
770
+ return !!binding && sources.includes(binding.importId) && binding.importName === importName;
771
+ }, isStaticLiteral = (expression) => t2.isStringLiteral(expression) || t2.isNumericLiteral(expression) || t2.isBooleanLiteral(expression) || t2.isTemplateLiteral(expression) && expression.expressions.length === 0, literalValue = (expression) => {
772
+ if (t2.isStringLiteral(expression) || t2.isNumericLiteral(expression) || t2.isBooleanLiteral(expression))
773
+ return expression.value;
774
+ if (t2.isTemplateLiteral(expression))
775
+ return expression.quasis[0]?.value.cooked ?? expression.quasis[0]?.value.raw ?? "";
776
+ };
777
+
778
+ // src/docgen/story-docs/template-holes.ts
779
+ var TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURCES = ["lit/directives/if-defined.js", "lit-html/directives/if-defined.js"], resolveHoleValue = (expression, context) => {
780
+ let expressionNode = unwrapExpression3(expression), alias = t3.isIdentifier(expressionNode) ? aliasValueForIdentifier(expressionNode, context.scope) : void 0;
781
+ if (alias)
782
+ return resolveAlias(alias, context, sourceOf3(expression));
783
+ let arg = argReferenceForExpression(expression, context.scope);
784
+ if (arg)
785
+ return resolveArgReference(arg, context.storyArgs[arg.name], sourceOf3(expression));
786
+ let unwrapped = expressionNode;
787
+ if (isNothingExpression(unwrapped, context.bindings))
788
+ return { kind: "nothing" };
789
+ if (isStaticLiteral2(unwrapped))
790
+ return { kind: "value", value: literalValue2(unwrapped) };
791
+ if (t3.isFunction(unwrapped))
792
+ return { handler: sourceOf3(expression), kind: "function" };
793
+ let nested = templateFromExpression(unwrapped, context.bindings, context.scope);
794
+ if (nested)
795
+ return { kind: "template", source: sourceOf3(expression), template: nested };
796
+ if (isIfDefinedCall(unwrapped, context.bindings)) {
797
+ let value = resolveHoleValue(unwrapped.arguments[0], context);
798
+ return value.kind === "value" && value.value !== null && value.value !== void 0 ? value : { kind: "nothing", ...value.arg ? { arg: value.arg } : {} };
799
+ }
800
+ if (t3.isConditionalExpression(unwrapped)) {
801
+ let test = resolveConditionalTest(unwrapped.test, context);
802
+ if (test.kind === "unresolved")
803
+ return test;
804
+ let branch = resolveHoleValue(
805
+ test.truthy ? unwrapped.consequent : unwrapped.alternate,
806
+ context
807
+ );
808
+ return test.arg && !branch.arg ? { ...branch, arg: test.arg } : branch;
809
+ }
810
+ return { kind: "unresolved", source: sourceOf3(expression) };
811
+ }, collectReferencedArgs = (expression, scope) => {
812
+ let referenced = /* @__PURE__ */ new Set(), visit = (node) => {
813
+ if (t3.isExpression(node)) {
814
+ let args = referencedArgsForExpression(node, scope);
815
+ for (let arg of args)
816
+ referenced.add(arg);
817
+ }
818
+ for (let key of t3.VISITOR_KEYS[node.type] ?? []) {
819
+ if (skipsReferenceChild(node, key))
820
+ continue;
821
+ let child = node[key];
822
+ Array.isArray(child) ? child.forEach((entry) => {
823
+ t3.isNode(entry) && visit(entry);
824
+ }) : t3.isNode(child) && visit(child);
825
+ }
826
+ };
827
+ return visit(expression), referenced;
828
+ }, isTruthyAttributeValue = (value) => value.kind === "value" ? !!value.value : value.kind === "template" || value.kind === "function", attributeValue = (value, context, referenced) => {
829
+ if (value.kind === "empty" || value.kind === "function" || value.kind === "nothing")
830
+ return { kind: "value", value: void 0 };
831
+ if (value.kind === "value")
832
+ return { kind: "value", value: value.value };
833
+ if (value.template.lit)
834
+ return { kind: "unresolved", source: value.source ?? value.template.source };
835
+ let resolved = templateAttributeText(value.template, context, referenced);
836
+ return resolved.kind === "unresolved" ? resolved : { kind: "value", value: resolved.text };
837
+ }, listenerHandler = (value) => value.kind === "function" ? value.handler : "() => {}", escapeText = (value) => value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"), resolveArg = (arg, node) => {
838
+ if (!node)
839
+ return { kind: "value", arg, value: void 0 };
840
+ let value = evaluateArgValue(node);
841
+ switch (value.kind) {
842
+ case "function":
843
+ return { handler: sourceOf3(node), kind: "function", arg };
844
+ case "unset":
845
+ return { kind: "value", arg, value: void 0 };
846
+ case "unresolved":
847
+ return { arg, kind: "unresolved", source: value.source };
848
+ case "value":
849
+ return { kind: "value", arg, value: value.value };
850
+ default:
851
+ return value;
852
+ }
853
+ }, resolveAlias = (alias, context, source) => {
854
+ switch (alias.kind) {
855
+ case "arg":
856
+ return resolveArgReference(alias, context.storyArgs[alias.name], source ?? alias.source);
857
+ case "template":
858
+ return { kind: "template", source: source ?? alias.source, template: alias.template };
859
+ case "value":
860
+ return { kind: "value", value: alias.value };
861
+ default:
862
+ return alias;
863
+ }
864
+ }, resolveArgReference = (reference, node, missingPathSource) => {
865
+ let value = resolveArg(reference.name, node);
866
+ if (value.kind === "function" && missingPathSource)
867
+ return { ...value, source: missingPathSource };
868
+ if (value.kind !== "value" || reference.path.length === 0)
869
+ return value;
870
+ let current2 = value.value;
871
+ for (let part of reference.path) {
872
+ let object = current2 == null ? void 0 : Object(current2);
873
+ if (object === void 0 || !(part in object))
874
+ return missingPathSource ? { arg: reference.name, kind: "unresolved", source: missingPathSource } : { arg: reference.name, kind: "empty" };
875
+ current2 = object[part];
876
+ }
877
+ return current2 === void 0 ? missingPathSource ? { arg: reference.name, kind: "unresolved", source: missingPathSource } : { arg: reference.name, kind: "empty" } : { arg: reference.name, kind: "value", value: current2 };
878
+ }, referencedArgsForExpression = (expression, scope) => {
879
+ let alias = t3.isIdentifier(expression) ? aliasValueForIdentifier(expression, scope) : void 0;
880
+ if (alias)
881
+ return referencedArgsForAlias(alias);
882
+ let arg = argReferenceForExpression(expression, scope);
883
+ return arg ? /* @__PURE__ */ new Set([arg.name]) : /* @__PURE__ */ new Set();
884
+ }, referencedArgsForAlias = (alias) => {
885
+ switch (alias.kind) {
886
+ case "arg":
887
+ return /* @__PURE__ */ new Set([alias.name]);
888
+ case "template": {
889
+ let referenced = /* @__PURE__ */ new Set();
890
+ for (let expression of alias.template.expressions)
891
+ collectReferencedArgs(expression, alias.template.scope).forEach(
892
+ (arg) => referenced.add(arg)
893
+ );
894
+ return referenced;
895
+ }
896
+ case "value":
897
+ return /* @__PURE__ */ new Set();
898
+ default:
899
+ return alias;
900
+ }
901
+ }, skipsReferenceChild = (node, key) => t3.isMemberExpression(node) && key === "property" && !node.computed || (t3.isObjectProperty(node) || t3.isObjectMethod(node)) && key === "key" && !node.computed, isNothingExpression = (expression, bindings) => t3.isIdentifier(expression) && isImported2(expression.name, "nothing", TEMPLATE_TAG_SOURCES2, bindings), isStaticLiteral2 = (expression) => t3.isNullLiteral(expression) || t3.isStringLiteral(expression) || t3.isNumericLiteral(expression) || t3.isBooleanLiteral(expression) || t3.isIdentifier(expression, { name: "undefined" }) || t3.isUnaryExpression(expression) && expression.operator === "void" || t3.isTemplateLiteral(expression) && expression.expressions.length === 0, literalValue2 = (expression) => {
902
+ if (t3.isNullLiteral(expression))
903
+ return null;
904
+ if (t3.isStringLiteral(expression) || t3.isNumericLiteral(expression) || t3.isBooleanLiteral(expression))
905
+ return expression.value;
906
+ if (!t3.isIdentifier(expression, { name: "undefined" }) && !(t3.isUnaryExpression(expression) && expression.operator === "void") && t3.isTemplateLiteral(expression))
907
+ return expression.quasis[0]?.value.cooked ?? expression.quasis[0]?.value.raw ?? "";
908
+ }, isIfDefinedCall = (expression, bindings) => t3.isCallExpression(expression) && expression.arguments.length === 1 && t3.isExpression(expression.arguments[0]) && t3.isIdentifier(expression.callee) && isImported2(expression.callee.name, "ifDefined", IF_DEFINED_SOURCES, bindings), resolveConditionalTest = (expression, context) => {
909
+ let arg = argReferenceForExpression(expression, context.scope);
910
+ if (arg) {
911
+ let value = resolveArgReference(arg, context.storyArgs[arg.name], sourceOf3(expression));
912
+ return value.kind === "value" || value.kind === "empty" ? { arg: arg.name, kind: "value", truthy: value.kind === "value" && !!value.value } : {
913
+ kind: "unresolved",
914
+ source: value.kind === "unresolved" ? value.source : sourceOf3(expression)
915
+ };
916
+ }
917
+ let unwrapped = unwrapExpression3(expression);
918
+ return isNothingExpression(unwrapped, context.bindings) ? { kind: "value", truthy: !1 } : isStaticLiteral2(unwrapped) ? { kind: "value", truthy: !!literalValue2(unwrapped) } : { kind: "unresolved", source: sourceOf3(expression) };
919
+ }, templateAttributeText = (template, context, referenced) => {
920
+ let scopedContext = { ...context, bindings: template.bindings, scope: template.scope }, text = "";
921
+ for (let index = 0; index < template.expressions.length; index += 1) {
922
+ text += template.quasis[index] ?? "";
923
+ let expression = template.expressions[index], value = resolveHoleValue(expression, scopedContext);
924
+ if (value.kind === "unresolved")
925
+ return { kind: "unresolved", source: value.source };
926
+ value.arg && referenced?.add(value.arg);
927
+ let resolved = attributeValue(value, scopedContext, referenced);
928
+ if (resolved.kind === "unresolved")
929
+ return resolved;
930
+ text += resolved.value === void 0 ? "" : String(resolved.value);
931
+ }
932
+ return text += template.quasis.at(-1) ?? "", { kind: "text", text };
933
+ }, isImported2 = (local, importName, sources, bindings) => {
934
+ let binding = bindings.get(local);
935
+ return !!binding && sources.includes(binding.importId) && binding.importName === importName;
936
+ };
937
+
938
+ // src/docgen/story-docs/template-print.ts
939
+ function printHtmlTemplate(template, storyArgs, declaration) {
940
+ return printTemplate(template, {
941
+ bindings: template.bindings,
942
+ declaration,
943
+ scope: template.scope,
944
+ storyArgs
945
+ });
946
+ }
947
+ var printTemplate = (template, context) => printTemplateWithListeners(template, context, !0), printTemplateWithListeners = (template, context, allowRootListeners) => {
948
+ let scopedContext = { ...context, bindings: template.bindings, scope: template.scope }, nonce = `${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`, markers = /* @__PURE__ */ new Map(), source = template.quasis.reduce((html, quasi, index) => {
949
+ let expression = template.expressions[index];
950
+ if (!expression)
951
+ return html + quasi;
952
+ let marker = `__STORYBOOK_HOLE_${nonce}_${index}__`;
953
+ return markers.set(marker, expression), `${html}${quasi}${marker}`;
954
+ }, ""), state = {
955
+ context: scopedContext,
956
+ falseDefaults: /* @__PURE__ */ new Set(),
957
+ listeners: [],
958
+ listenersNotShown: /* @__PURE__ */ new Set(),
959
+ lit: template.lit,
960
+ markers,
961
+ properties: /* @__PURE__ */ new Set(),
962
+ referenced: /* @__PURE__ */ new Set(),
963
+ unresolved: /* @__PURE__ */ new Set()
964
+ };
965
+ for (let expression of template.expressions)
966
+ collectReferencedArgs(expression, scopedContext.scope).forEach(
967
+ (arg) => state.referenced.add(arg)
968
+ );
969
+ let nodes = resolveTemplateNodes(parseHtml(source), state, 0), hostRoots = nodes.filter((node) => node.kind === "element" && node.name !== "style"), rootElements = nodes.filter((node) => node.kind === "element" || node.kind === "rawText");
970
+ !(allowRootListeners && hostRoots.length === 1 && rootElements.at(-1) === hostRoots[0]) && state.listeners.length > 0 && (state.listeners.forEach((listener) => state.listenersNotShown.add(`@${listener.event}`)), state.listeners = []);
971
+ let script = printRootListenerScript(state.listeners), snippet = printHtml(nodes);
972
+ return {
973
+ ...state.falseDefaults.size === 0 ? {} : { falseDefaults: [...state.falseDefaults] },
974
+ listeners: state.listeners,
975
+ ...state.listenersNotShown.size === 0 ? {} : { listenersNotShown: [...state.listenersNotShown] },
976
+ properties: [...state.properties],
977
+ referenced: [...state.referenced],
978
+ snippet: script ? `${snippet}
979
+ ${script}` : snippet,
980
+ unresolved: [...state.unresolved]
981
+ };
982
+ }, resolveTemplateNodes = (nodes, state, depth) => nodes.flatMap((node) => resolveTemplateNode(node, state, depth)), resolveTemplateNode = (node, state, depth) => {
983
+ switch (node.kind) {
984
+ case "element":
985
+ return [
986
+ {
987
+ ...node,
988
+ attributes: resolveAttributes(node.name, node.attributes, state, depth),
989
+ children: resolveTemplateNodes(node.children, state, depth + 1)
990
+ }
991
+ ];
992
+ case "text":
993
+ return resolveTextNode(node.text, state);
994
+ case "comment":
995
+ return [{ ...node, text: removeUnsupportedMarkers(node.text, state) }];
996
+ case "rawText":
997
+ return [{ ...node, text: removeUnsupportedMarkers(node.text, state) }];
998
+ case "malformed":
999
+ return [{ ...node, text: removeUnsupportedMarkers(node.text, state) }];
1000
+ default:
1001
+ return node;
1002
+ }
1003
+ }, resolveAttributes = (tag, attributes, state, depth) => {
1004
+ let resolved = [];
1005
+ for (let attribute of attributes) {
1006
+ let next = resolveAttribute(tag, attribute, state, depth);
1007
+ next && upsertAttribute(resolved, next);
1008
+ }
1009
+ return resolved;
1010
+ }, resolveAttribute = (tag, attribute, state, depth) => {
1011
+ if (containsMarker(attribute.name, state)) {
1012
+ unresolvedMarkers(attribute.name, state);
1013
+ return;
1014
+ }
1015
+ if (attribute.value === void 0 || !containsMarker(attribute.value, state))
1016
+ return attribute;
1017
+ let prefix = state.lit ? attribute.name[0] : void 0;
1018
+ if (prefix === "?") {
1019
+ let value = resolveFirstMarker(attribute.value, state);
1020
+ return value && isTruthyAttributeValue(value) ? { name: attribute.name.slice(1), value: void 0 } : void 0;
1021
+ }
1022
+ if (prefix === "@") {
1023
+ let value = resolveFirstMarker(attribute.value, state), event = attribute.name.slice(1);
1024
+ depth === 0 ? state.listeners.push({
1025
+ event,
1026
+ handler: value ? listenerHandler(value) : "() => {}"
1027
+ }) : state.listenersNotShown.add(`@${event}`);
1028
+ return;
1029
+ }
1030
+ if (prefix === ".") {
1031
+ let property = attribute.name.slice(1), paired = pairedAttribute(property, state.context.declaration);
1032
+ if (!paired) {
1033
+ state.properties.add(property);
1034
+ return;
1035
+ }
1036
+ let markers2 = markersIn(attribute.value, state), value = markers2.length === 1 && attribute.value === markers2[0] ? resolveFirstMarker(attribute.value, state) : void 0;
1037
+ if (!value || value.kind === "unresolved") {
1038
+ state.unresolved.add(
1039
+ value?.kind === "unresolved" ? value.source : markerSources(markers2, state)
1040
+ );
1041
+ return;
1042
+ }
1043
+ let resolved = attributeValue(value, state.context, state.referenced);
1044
+ if (resolved.kind === "unresolved") {
1045
+ state.unresolved.add(resolved.source);
1046
+ return;
1047
+ }
1048
+ return resolved.value === !1 && fieldDefault(property, state.context.declaration) === "true" && state.falseDefaults.add(property), attributeFromPrinted(
1049
+ printAttribute({ name: paired, value: resolved.value, viaField: !0 })
1050
+ );
1051
+ }
1052
+ let markers = markersIn(attribute.value, state), singleDynamicValue = markers.length === 1 && attribute.value === markers[0], text = attribute.value;
1053
+ for (let marker of markers) {
1054
+ let expression = state.markers.get(marker);
1055
+ if (!expression)
1056
+ continue;
1057
+ let value = resolveMarkerValue(expression, state);
1058
+ if (value.kind === "function") {
1059
+ state.unresolved.add(sourceOf4(expression));
1060
+ return;
1061
+ }
1062
+ if (value.kind === "nothing")
1063
+ return;
1064
+ if (value.kind === "unresolved") {
1065
+ state.unresolved.add(value.source);
1066
+ return;
1067
+ }
1068
+ let resolved = attributeValue(value, state.context, state.referenced);
1069
+ if (resolved.kind === "unresolved") {
1070
+ state.unresolved.add(resolved.source);
1071
+ return;
1072
+ }
1073
+ if (!attribute.quoted && !singleDynamicValue && resolved.value === void 0 && text.startsWith(marker))
1074
+ return;
1075
+ let valueText = resolved.value === null || resolved.value === void 0 ? "" : String(resolved.value);
1076
+ text = text.replace(marker, valueText);
1077
+ }
1078
+ return { name: attribute.name, value: text };
1079
+ }, resolveTextNode = (text, state) => {
1080
+ let markers = markersIn(text, state);
1081
+ if (markers.length === 0)
1082
+ return [{ kind: "text", text }];
1083
+ let nodes = [], rest = text;
1084
+ for (let marker of markers) {
1085
+ let [before, after] = rest.split(marker);
1086
+ before && nodes.push({ kind: "text", text: before });
1087
+ let expression = state.markers.get(marker);
1088
+ expression && nodes.push(...nodesForChildValue(resolveMarkerValue(expression, state), state)), rest = after ?? "";
1089
+ }
1090
+ return rest && nodes.push({ kind: "text", text: rest }), nodes;
1091
+ }, nodesForChildValue = (value, state) => {
1092
+ switch (value.kind) {
1093
+ case "empty":
1094
+ case "nothing":
1095
+ return [];
1096
+ case "function":
1097
+ return state.unresolved.add(value.source ?? value.handler), [];
1098
+ case "template": {
1099
+ let nested = printTemplateWithListeners(value.template, state.context, !1);
1100
+ return nested.properties.forEach((property) => state.properties.add(property)), nested.referenced.forEach((arg) => state.referenced.add(arg)), nested.unresolved.forEach((source) => state.unresolved.add(source)), nested.listenersNotShown?.forEach((listener) => state.listenersNotShown.add(listener)), parseHtml(nested.snippet.replace(/<script>[\s\S]*<\/script>$/, ""));
1101
+ }
1102
+ case "unresolved":
1103
+ return state.unresolved.add(value.source), [];
1104
+ case "value":
1105
+ if (value.value === null || value.value === void 0 || value.value === "")
1106
+ return [];
1107
+ if (Array.isArray(value.value)) {
1108
+ let text = value.value.map((item) => item ?? "").join("");
1109
+ return state.lit ? [{ kind: "text", text: escapeText(text) }] : parseHtml(text);
1110
+ }
1111
+ return state.lit ? [{ kind: "text", text: escapeText(String(value.value)) }] : parseHtml(String(value.value));
1112
+ default:
1113
+ return value;
1114
+ }
1115
+ }, resolveMarkerValue = (expression, state) => {
1116
+ let value = resolveHoleValue(expression, state.context);
1117
+ return value.arg && state.referenced.add(value.arg), value;
1118
+ }, resolveFirstMarker = (text, state) => {
1119
+ let marker = markersIn(text, state)[0], expression = marker ? state.markers.get(marker) : void 0;
1120
+ return expression ? resolveMarkerValue(expression, state) : void 0;
1121
+ }, removeUnsupportedMarkers = (text, state) => {
1122
+ let next = text;
1123
+ for (let marker of markersIn(text, state)) {
1124
+ let expression = state.markers.get(marker);
1125
+ expression && state.unresolved.add(sourceOf4(expression)), next = next.replace(marker, "");
1126
+ }
1127
+ return next;
1128
+ }, unresolvedMarkers = (text, state) => {
1129
+ for (let marker of markersIn(text, state)) {
1130
+ let expression = state.markers.get(marker);
1131
+ expression && state.unresolved.add(sourceOf4(expression));
1132
+ }
1133
+ }, containsMarker = (text, state) => markersIn(text, state).length > 0, markersIn = (text, state) => [...state.markers.keys()].filter((marker) => text.includes(marker)), markerSources = (markers, state) => markers.map((marker) => state.markers.get(marker)).filter((expression) => expression !== void 0).map(sourceOf4).join(", "), attributeFromPrinted = (attribute) => {
1134
+ if (!attribute)
1135
+ return;
1136
+ let [node] = parseHtml(`<x ${attribute}></x>`);
1137
+ return node?.kind === "element" ? node.attributes[0] : void 0;
1138
+ }, upsertAttribute = (attributes, next) => {
1139
+ let index = attributes.findIndex((attribute) => attribute.name === next.name);
1140
+ if (index === -1) {
1141
+ attributes.push(next);
1142
+ return;
1143
+ }
1144
+ attributes[index] = next;
1145
+ };
1146
+
1147
+ // ../../core/src/csf-tools/story-shape/utils.ts
1148
+ import { types as t4 } from "storybook/internal/babel";
1149
+ var unwrapExpression4 = (node) => t4.isTSAsExpression(node) || t4.isTSSatisfiesExpression(node) || t4.isTSNonNullExpression(node) || t4.isTSTypeAssertion(node) || t4.isParenthesizedExpression(node) ? unwrapExpression4(node.expression) : node, isCanonicalCsf2BindCall = (node) => t4.isCallExpression(node) && t4.isMemberExpression(node.callee) && !node.callee.computed && t4.isIdentifier(node.callee.object) && t4.isIdentifier(node.callee.property, { name: "bind" }) && (node.arguments.length === 0 || node.arguments.length === 1 && t4.isObjectExpression(node.arguments[0]) && node.arguments[0].properties.length === 0), withoutTypeCalls = (object) => t4.isCallExpression(object) && object.arguments.length === 0 && t4.isMemberExpression(object.callee) && !object.callee.computed && t4.isIdentifier(object.callee.property, { name: "type" }) ? withoutTypeCalls(object.callee.object) : object, isCsfFactoryCall = (node) => t4.isCallExpression(node) && t4.isMemberExpression(node.callee) && !node.callee.computed && t4.isIdentifier(withoutTypeCalls(node.callee.object)) && t4.isIdentifier(node.callee.property) && (node.callee.property.name === "story" || node.callee.property.name === "extend"), csfFactoryReceiver = (node) => withoutTypeCalls(node.callee.object);
1150
+ var keyOf3 = (p) => t4.isStringLiteral(p.key) ? p.key.value : !p.computed && t4.isIdentifier(p.key) ? p.key.name : null;
1151
+ function resolveIdentifierInit(storyPath, identifier) {
1152
+ let programPath = storyPath.findParent((p) => p.isProgram());
1153
+ if (!programPath)
1154
+ return null;
1155
+ for (let stmt of programPath.get("body")) {
1156
+ if (stmt.isFunctionDeclaration() && stmt.node.id?.name === identifier.node.name)
1157
+ return stmt;
1158
+ if (stmt.isExportNamedDeclaration()) {
1159
+ let decl = stmt.get("declaration");
1160
+ if (decl.isFunctionDeclaration() && decl.node.id?.name === identifier.node.name)
1161
+ return decl;
1162
+ }
1163
+ }
1164
+ let match = programPath.get("body").flatMap((stmt) => {
1165
+ if (stmt.isVariableDeclaration())
1166
+ return stmt.get("declarations");
1167
+ if (stmt.isExportNamedDeclaration()) {
1168
+ let decl = stmt.get("declaration");
1169
+ if (decl && decl.isVariableDeclaration())
1170
+ return decl.get("declarations");
1171
+ }
1172
+ return [];
1173
+ }).find((d) => {
1174
+ let id = d.get("id");
1175
+ return id.isIdentifier() && id.node.name === identifier.node.name;
1176
+ });
1177
+ if (!match)
1178
+ return null;
1179
+ let init = match.get("init");
1180
+ return init && init.isExpression() ? init : null;
1181
+ }
1182
+ function pathForNode(program, target) {
1183
+ if (!target)
1184
+ return;
1185
+ let found;
1186
+ return program.traverse({
1187
+ enter(p) {
1188
+ p.node && p.node === target && (found = p, p.stop());
1189
+ }
1190
+ }), found;
1191
+ }
1192
+ function metaObjectPath(csf) {
1193
+ let metaPath = pathForNode(csf._file.path, csf._metaNode);
1194
+ return metaPath?.isObjectExpression() ? metaPath : void 0;
1195
+ }
1196
+
1197
+ // ../../core/src/csf-tools/story-shape/normalize-story.ts
1198
+ function normalizeStoryDeclaration(storyDeclaration) {
1199
+ let storyPath = declarationExpression(storyDeclaration), normalizedPath = bindInitializer(storyDeclaration, storyPath) ?? factoryArgumentExpression(storyPath), unwrappedPath = unwrapTypeExpression(normalizedPath);
1200
+ return classifyStoryPath(unwrappedPath);
1201
+ }
1202
+ function declarationExpression(storyDeclaration) {
1203
+ if (storyDeclaration.isFunctionDeclaration())
1204
+ return storyDeclaration;
1205
+ if (storyDeclaration.isVariableDeclarator()) {
1206
+ let init = storyDeclaration.get("init");
1207
+ if (!init.isExpression())
1208
+ throw storyDeclaration.buildCodeFrameError("Expected story initializer to be an expression");
1209
+ return init;
1210
+ }
1211
+ throw storyDeclaration.buildCodeFrameError(
1212
+ "Expected story to be a function or variable declaration"
1213
+ );
1214
+ }
1215
+ function bindInitializer(storyDeclaration, storyPath) {
1216
+ if (!storyPath.isCallExpression() || !isCanonicalCsf2BindCall(storyPath.node))
1217
+ return null;
1218
+ let callee = storyPath.get("callee");
1219
+ if (!callee.isMemberExpression())
1220
+ return null;
1221
+ let obj = callee.get("object");
1222
+ return obj.isIdentifier() ? resolveIdentifierInit(storyDeclaration, obj) : null;
1223
+ }
1224
+ function factoryArgumentExpression(storyPath) {
1225
+ if (!storyPath.isCallExpression() || !isCsfFactoryCall(storyPath.node))
1226
+ return storyPath;
1227
+ let args = storyPath.get("arguments");
1228
+ if (args.length === 0)
1229
+ return storyPath;
1230
+ if (args.length !== 1 || !args[0].isExpression())
1231
+ throw storyPath.buildCodeFrameError("Could not evaluate story expression");
1232
+ return args[0];
1233
+ }
1234
+ function unwrapTypeExpression(storyPath) {
1235
+ return storyPath.isTSSatisfiesExpression() || storyPath.isTSAsExpression() ? storyPath.get("expression") : storyPath;
1236
+ }
1237
+ function classifyStoryPath(storyPath) {
1238
+ if (storyPath.isObjectExpression())
1239
+ return { type: "config", path: storyPath };
1240
+ if (storyPath.isArrowFunctionExpression() || storyPath.isFunctionExpression() || storyPath.isFunctionDeclaration())
1241
+ return { type: "fn", path: storyPath };
1242
+ if (storyPath.isCallExpression() && isCsfFactoryCall(storyPath.node) && storyPath.node.arguments.length === 0)
1243
+ return { type: "emptyConfig", path: storyPath };
1244
+ throw storyPath.buildCodeFrameError(
1245
+ "Expected story to be csf factory, function or an object expression"
1246
+ );
1247
+ }
1248
+
1249
+ // ../../core/src/csf-tools/story-shape/resolve-members.ts
1250
+ import { generate, types as t6 } from "storybook/internal/babel";
1251
+
1252
+ // ../../core/src/csf-tools/story-shape/imports.ts
1253
+ import { types as t5 } from "storybook/internal/babel";
1254
+ var isTypeSpecifier = (s) => t5.isImportSpecifier(s) && s.importKind === "type", importedName = (im) => t5.isIdentifier(im) ? im.name : im.value;
1255
+
1256
+ // ../../core/src/csf-tools/story-shape/resolve-members.ts
1257
+ var sourceOf5 = (node) => generate(node, { concise: !0, comments: !1 }).code, complete = (properties = {}) => ({
1258
+ properties,
1259
+ shadowed: [],
1260
+ unresolved: []
1261
+ }), resolveObjectMembers = (object, ctx) => membersOf(object, ctx, /* @__PURE__ */ new Set());
1262
+ var membersOf = (object, ctx, visited) => {
1263
+ let properties = {}, unresolved = [], shadowed = /* @__PURE__ */ new Set(), shadowKnownMembers = (source) => {
1264
+ unresolved.push(source);
1265
+ for (let key of Object.keys(properties))
1266
+ shadowed.add(key);
1267
+ };
1268
+ for (let property of object.properties) {
1269
+ if (t6.isSpreadElement(property)) {
1270
+ let spread = spreadMembers(ctx, property, visited);
1271
+ if (spread === void 0 || spread.unresolved.length > 0) {
1272
+ shadowKnownMembers(sourceOf5(property));
1273
+ continue;
1274
+ }
1275
+ for (let [key2, value] of Object.entries(spread.properties))
1276
+ properties[key2] = value, shadowed.delete(key2);
1277
+ continue;
1278
+ }
1279
+ let key = keyOf3(property);
1280
+ if (key === null) {
1281
+ shadowKnownMembers(sourceOf5(property));
1282
+ continue;
1283
+ }
1284
+ if (t6.isObjectMethod(property) && (property.kind !== "method" || property.generator)) {
1285
+ delete properties[key], shadowed.delete(key), unresolved.push(sourceOf5(property));
1286
+ continue;
1287
+ }
1288
+ properties[key] = t6.isObjectMethod(property) ? property : property.value, shadowed.delete(key);
1289
+ }
1290
+ return { properties, shadowed: [...shadowed], unresolved };
1291
+ }, spreadMembers = (ctx, spread, visited) => {
1292
+ let argument = unwrapExpression4(spread.argument);
1293
+ return t6.isObjectExpression(argument) ? membersOf(argument, ctx, visited) : resolveReference(ctx, argument, spread.start ?? void 0, visited);
1294
+ }, memberChain = (node) => {
1295
+ let path = [], current2 = unwrapExpression4(node);
1296
+ for (; t6.isMemberExpression(current2); ) {
1297
+ let key = t6.isIdentifier(current2.property) && !current2.computed ? current2.property.name : t6.isStringLiteral(current2.property) ? current2.property.value : void 0;
1298
+ if (key === void 0)
1299
+ return;
1300
+ path.unshift(key), current2 = unwrapExpression4(current2.object);
1301
+ }
1302
+ return t6.isIdentifier(current2) ? { root: current2.name, path } : void 0;
1303
+ }, resolveReference = (ctx, expression, position, visited) => {
1304
+ let chain = memberChain(expression);
1305
+ if (!chain)
1306
+ return;
1307
+ let key = `ref:${ctx.filePath}#${chain.root}.${chain.path.join(".")}`;
1308
+ if (!visited.has(key)) {
1309
+ visited.add(key);
1310
+ try {
1311
+ return unguardedResolveReference(ctx, chain, position, visited);
1312
+ } finally {
1313
+ visited.delete(key);
1314
+ }
1315
+ }
1316
+ }, unguardedResolveReference = (ctx, chain, position, visited) => {
1317
+ let located = locate(ctx, chain, position, visited);
1318
+ if (!located)
1319
+ return;
1320
+ let members = located.members, scope = located.ctx;
1321
+ for (let [index, key] of located.path.entries()) {
1322
+ if (members.unresolved.length > 0)
1323
+ return;
1324
+ let value = members.properties[key];
1325
+ if (value === void 0)
1326
+ return index === located.path.length - 1 ? complete() : void 0;
1327
+ let unwrapped = unwrapExpression4(value);
1328
+ if (!t6.isObjectExpression(unwrapped))
1329
+ return;
1330
+ members = membersOf(unwrapped, scope, visited);
1331
+ }
1332
+ return located.external ? externalized(members, scope) : members;
1333
+ }, locate = (ctx, chain, position, visited) => {
1334
+ let binding = bindingMembers(ctx, chain.root, position, visited);
1335
+ if (!binding)
1336
+ return;
1337
+ if (binding.kind === "namespace") {
1338
+ let [exportName, ...path] = chain.path;
1339
+ if (exportName === void 0)
1340
+ return;
1341
+ let exported = bindingMembers(binding.ctx, exportName, void 0, visited);
1342
+ if (exported === void 0 || exported.kind === "namespace")
1343
+ return;
1344
+ let located2 = withAccessor(exported, path);
1345
+ return located2 === void 0 ? void 0 : { ...located2, external: !0 };
1346
+ }
1347
+ let located = withAccessor(binding, chain.path);
1348
+ return located === void 0 ? void 0 : { ...located, external: binding.external };
1349
+ }, withAccessor = (binding, path) => binding.accessor === void 0 ? { members: binding.members, ctx: binding.ctx, path } : path[0] === binding.accessor ? { members: binding.members, ctx: binding.ctx, path: path.slice(1) } : void 0, externalized = (members, ctx) => {
1350
+ if (!ctx.externalize)
1351
+ return members;
1352
+ let properties = {};
1353
+ for (let [key, node] of Object.entries(members.properties)) {
1354
+ let value = ctx.externalize(node);
1355
+ if (value === void 0)
1356
+ return;
1357
+ properties[key] = value;
1358
+ }
1359
+ return {
1360
+ properties,
1361
+ shadowed: members.shadowed,
1362
+ unresolved: members.unresolved
1363
+ };
1364
+ }, bindingMembers = (ctx, name, position, visited) => {
1365
+ let key = `${ctx.filePath}#${name}`;
1366
+ if (!visited.has(key)) {
1367
+ visited.add(key);
1368
+ try {
1369
+ return unguardedBindingMembers(ctx, name, position, visited);
1370
+ } finally {
1371
+ visited.delete(key);
1372
+ }
1373
+ }
1374
+ }, unguardedBindingMembers = (ctx, name, position, visited) => {
1375
+ let binding = ctx.program.scope.getBinding(name);
1376
+ if (!binding)
1377
+ return;
1378
+ if (binding.kind === "module")
1379
+ return importedBinding(ctx, binding.path, visited);
1380
+ if (!binding.constant)
1381
+ return;
1382
+ let declared = declaredBindingMembers(ctx, binding.path.node, position, visited);
1383
+ if (declared === void 0)
1384
+ return;
1385
+ let assigned = assignedMembers(ctx, name, position);
1386
+ return {
1387
+ kind: "members",
1388
+ ctx,
1389
+ external: !1,
1390
+ ...declared.accessor ? { accessor: declared.accessor } : {},
1391
+ members: {
1392
+ properties: { ...declared.members.properties, ...assigned.properties },
1393
+ shadowed: declared.members.shadowed.filter((key) => !(key in assigned.properties)),
1394
+ unresolved: [...declared.members.unresolved, ...assigned.unresolved]
1395
+ }
1396
+ };
1397
+ }, declaredBindingMembers = (ctx, node, position, visited) => {
1398
+ if (t6.isFunctionDeclaration(node))
1399
+ return { members: complete() };
1400
+ if (t6.isVariableDeclarator(node) && !(position !== void 0 && (node.start ?? Number.POSITIVE_INFINITY) > position))
1401
+ return node.init ? declaredMembers(ctx, node.init, position, visited) : { members: complete() };
1402
+ }, declaredMembers = (ctx, init, position, visited) => {
1403
+ let unwrapped = unwrapExpression4(init);
1404
+ if (t6.isObjectExpression(unwrapped))
1405
+ return { members: membersOf(unwrapped, ctx, visited) };
1406
+ let factory = factoryCall(unwrapped);
1407
+ if (factory === void 0 && (t6.isFunction(unwrapped) || isCanonicalCsf2BindCall(unwrapped)))
1408
+ return { members: complete() };
1409
+ if (factory === void 0)
1410
+ return {
1411
+ members: { properties: {}, shadowed: [], unresolved: [sourceOf5(unwrapped)] }
1412
+ };
1413
+ let config = factory.config ? membersOf(factory.config, ctx, visited) : complete();
1414
+ if (factory.method === "story")
1415
+ return { members: config, accessor: "input" };
1416
+ let parent = bindingMembers(ctx, factory.parent, position, visited);
1417
+ return parent === void 0 || parent.kind === "namespace" || parent.accessor !== "input" || parent.external ? void 0 : {
1418
+ members: {
1419
+ properties: mergedAnnotations(parent.members, config).properties,
1420
+ shadowed: [
1421
+ ...parent.members.shadowed.filter((key) => !(key in config.properties)),
1422
+ ...config.shadowed
1423
+ ],
1424
+ unresolved: [...parent.members.unresolved, ...config.unresolved]
1425
+ },
1426
+ accessor: "input"
1427
+ };
1428
+ }, MERGED_ANNOTATIONS = ["args", "argTypes", "parameters", "globals"], mergedAnnotations = (parent, child) => {
1429
+ let properties = { ...parent.properties, ...child.properties };
1430
+ for (let key of MERGED_ANNOTATIONS) {
1431
+ let from = parent.properties[key], over = child.properties[key];
1432
+ from === void 0 || over === void 0 || !t6.isExpression(from) || !t6.isExpression(over) || (properties[key] = t6.objectExpression([t6.spreadElement(from), t6.spreadElement(over)]));
1433
+ }
1434
+ return { properties };
1435
+ }, factoryCall = (node) => {
1436
+ if (!isCsfFactoryCall(node))
1437
+ return;
1438
+ let method = node.callee.property.name;
1439
+ if (method !== "story" && method !== "extend")
1440
+ return;
1441
+ let [argument] = node.arguments, config = argument && unwrapExpression4(argument);
1442
+ if (!(argument !== void 0 && (config === void 0 || !t6.isObjectExpression(config))))
1443
+ return {
1444
+ method,
1445
+ parent: csfFactoryReceiver(node).name,
1446
+ ...config && t6.isObjectExpression(config) ? { config } : {}
1447
+ };
1448
+ }, assignedMembers = (ctx, name, position) => {
1449
+ let properties = {}, unresolved = [];
1450
+ for (let statement of ctx.program.node.body) {
1451
+ if (!t6.isExpressionStatement(statement) || !t6.isAssignmentExpression(statement.expression))
1452
+ continue;
1453
+ let assignment = statement.expression, target = assignment.left, depth = 0, outermost;
1454
+ for (; t6.isMemberExpression(target); )
1455
+ depth += 1, outermost = t6.isIdentifier(target.property) && !target.computed ? target.property.name : t6.isStringLiteral(target.property) ? target.property.value : void 0, target = target.object;
1456
+ if (!(depth === 0 || !t6.isIdentifier(target) || target.name !== name) && !(position !== void 0 && (assignment.start ?? 0) > position)) {
1457
+ if (depth > 1 || outermost === void 0 || assignment.operator !== "=") {
1458
+ unresolved.push(sourceOf5(assignment));
1459
+ continue;
1460
+ }
1461
+ properties[outermost] = assignment.right;
1462
+ }
1463
+ }
1464
+ return { properties, unresolved };
1465
+ }, importedBinding = (ctx, specifierPath, visited) => {
1466
+ let specifier = specifierPath.node, declaration = specifierPath.parent;
1467
+ if (!t6.isImportDeclaration(declaration) || declaration.importKind === "type" || !(t6.isImportSpecifier(specifier) || t6.isImportDefaultSpecifier(specifier) || t6.isImportNamespaceSpecifier(specifier)) || isTypeSpecifier(specifier))
1468
+ return;
1469
+ let target = resolveTargetModule(ctx, declaration.source.value);
1470
+ if (!target)
1471
+ return;
1472
+ if (t6.isImportNamespaceSpecifier(specifier))
1473
+ return { kind: "namespace", ctx: target };
1474
+ let exportName = t6.isImportDefaultSpecifier(specifier) ? "default" : importedName(specifier.imported);
1475
+ return exportedBinding(target, exportName, visited);
1476
+ }, resolveTargetModule = (ctx, specifier) => {
1477
+ let target = ctx.resolveModule?.(ctx.filePath, specifier);
1478
+ return target ? { ...ctx, ...target } : void 0;
1479
+ }, exportedBinding = (ctx, exportName, visited) => {
1480
+ let asExternal = (bound) => bound === void 0 || bound.kind === "namespace" ? bound : { ...bound, external: !0 };
1481
+ for (let statement of ctx.program.node.body) {
1482
+ if (t6.isExportDefaultDeclaration(statement) && exportName === "default") {
1483
+ let declaration = unwrapExpression4(statement.declaration);
1484
+ return t6.isIdentifier(declaration) ? asExternal(bindingMembers(ctx, declaration.name, void 0, visited)) : t6.isObjectExpression(declaration) ? {
1485
+ kind: "members",
1486
+ ctx,
1487
+ external: !0,
1488
+ members: membersOf(declaration, ctx, visited)
1489
+ } : void 0;
1490
+ }
1491
+ if (!t6.isExportNamedDeclaration(statement) || statement.exportKind === "type")
1492
+ continue;
1493
+ let specifier = statement.specifiers.find(
1494
+ (candidate) => t6.isExportSpecifier(candidate) && candidate.exportKind !== "type" && importedName(candidate.exported) === exportName
1495
+ );
1496
+ if (!specifier)
1497
+ continue;
1498
+ if (!statement.source)
1499
+ return asExternal(bindingMembers(ctx, specifier.local.name, void 0, visited));
1500
+ let target = resolveTargetModule(ctx, statement.source.value);
1501
+ return target ? exportedBinding(target, specifier.local.name, visited) : void 0;
1502
+ }
1503
+ return exportName === "default" ? void 0 : asExternal(bindingMembers(ctx, exportName, void 0, visited));
1504
+ };
1505
+
1506
+ // ../../core/src/csf-tools/story-shape/render.ts
1507
+ var isRenderFunction = (path) => path.isArrowFunctionExpression() || path.isFunctionExpression() || path.isFunctionDeclaration();
1508
+ function resolveEffectiveRender(csf, exportName, references) {
1509
+ let declaration = csf._storyDeclarationPath[exportName], normalized = normalizeStoryDeclarationForRender(declaration);
1510
+ if (normalized.type === "fn")
1511
+ return { kind: "resolved", path: normalized.path };
1512
+ let storyRender = readRender(
1513
+ normalized.type === "config" ? normalized.path : void 0,
1514
+ declaration,
1515
+ references
1516
+ );
1517
+ if (storyRender.kind === "invalid")
1518
+ return { kind: "unresolved" };
1519
+ if (storyRender.kind !== "missing")
1520
+ return storyRender;
1521
+ let metaRender = readRender(metaObjectPath(csf), declaration, references);
1522
+ return metaRender.kind === "invalid" ? { kind: "unresolved" } : metaRender;
1523
+ }
1524
+ var normalizeStoryDeclarationForRender = normalizeStoryDeclaration, readRender = (config, storyDeclaration, references) => {
1525
+ let properties = config?.get("properties") ?? [], renderIndex = -1;
1526
+ for (let index = properties.length - 1; index >= 0; index -= 1) {
1527
+ let property = properties[index];
1528
+ if ((property.isObjectProperty() || property.isObjectMethod()) && keyOf3(property.node) === "render") {
1529
+ renderIndex = index;
1530
+ break;
1531
+ }
1532
+ }
1533
+ let throughSpreads = () => config && references ? renderFromMembers(
1534
+ resolveObjectMembers(config.node, references),
1535
+ references,
1536
+ storyDeclaration
1537
+ ) : { kind: "unresolved" };
1538
+ if (renderIndex === -1)
1539
+ return properties.some((property) => property.isSpreadElement()) ? throughSpreads() : { kind: "missing" };
1540
+ let resolved = readRenderProperty(properties[renderIndex], storyDeclaration);
1541
+ if (properties.some((property, index) => index > renderIndex && property.isSpreadElement())) {
1542
+ let read = throughSpreads();
1543
+ return read.kind !== "unresolved" ? read : resolved.kind === "resolved" ? { kind: "unresolved", shadowedRender: resolved.path } : { kind: "unresolved" };
1544
+ }
1545
+ return resolved;
1546
+ };
1547
+ function renderFromMembers(members, references, storyDeclaration) {
1548
+ if (members.unresolved.length > 0)
1549
+ return { kind: "unresolved" };
1550
+ let node = members.properties.render;
1551
+ if (node === void 0)
1552
+ return { kind: "missing" };
1553
+ let path = pathForNode(references.program, node);
1554
+ if (!path)
1555
+ return { kind: "unresolved" };
1556
+ if (path.isObjectMethod())
1557
+ return path.node.kind === "method" && !path.node.generator ? { kind: "resolved", path } : { kind: "unresolved" };
1558
+ if (path.isIdentifier()) {
1559
+ let resolved = resolveIdentifierInit(storyDeclaration, path);
1560
+ return resolved && isRenderFunction(resolved) ? { kind: "resolved", path: resolved } : { kind: "unresolved" };
1561
+ }
1562
+ return isRenderFunction(path) ? { kind: "resolved", path } : { kind: "unresolved" };
1563
+ }
1564
+ function readRenderProperty(renderProperty, storyDeclaration) {
1565
+ if (renderProperty.isObjectMethod())
1566
+ return renderProperty.node.kind === "method" && !renderProperty.node.generator ? { kind: "resolved", path: renderProperty } : { kind: "unresolved" };
1567
+ let renderPath = renderProperty.get("value");
1568
+ if (renderPath.isIdentifier()) {
1569
+ let resolved = resolveIdentifierInit(storyDeclaration, renderPath);
1570
+ return resolved && isRenderFunction(resolved) ? { kind: "resolved", path: resolved } : { kind: "unresolved" };
1571
+ }
1572
+ return isRenderFunction(renderPath) ? { kind: "resolved", path: renderPath } : { kind: "invalid", path: renderPath };
1573
+ }
1574
+
1575
+ // src/docgen/story-docs/build-story-docs.ts
1576
+ var NO_COMPONENT_WARNING = "No static snippet: `meta.component` is not set.", openStoryReferences = createStoryReferenceResolver();
1577
+ async function buildStoryDocsPayload(input, context) {
1578
+ let storyImportPath = getStoryImportPathFromEntry(input.entry);
1579
+ if (!storyImportPath)
1580
+ return;
1581
+ let storyFilePath = (context.resolvePath ?? ((importPath) => resolve2(process.cwd(), importPath)))(storyImportPath), csf = parseStoryFile(storyFilePath, input.entry.title);
1582
+ if (!csf)
1583
+ return;
1584
+ let resolved = resolveStoryComponent(csf);
1585
+ if ("reason" in resolved && resolved.reason === "no-meta-component") {
1586
+ let titleName = input.entry.title.slice(input.entry.title.lastIndexOf("/") + 1);
1587
+ return buildPayload(
1588
+ input,
1589
+ storyImportPath,
1590
+ csf,
1591
+ authoredSnippetFactory(csf, storyFilePath, () => ({ warning: NO_COMPONENT_WARNING })),
1592
+ titleName
1593
+ );
1594
+ }
1595
+ let docgenPayload = await context.getDocgenPayload(getComponentIdFromEntry(input.entry));
1596
+ if (!docgenPayload)
1597
+ return;
1598
+ let declaration = docgenPayload?.customElementsManifest?.declaration, snippetFor = declaration ? renderedSnippetFactory(csf, declaration, docgenPayload, storyFilePath) : authoredSnippetFactory(csf, storyFilePath, () => ({
1599
+ warning: `No static snippet: ${docgenPayload.error?.message ?? "no Custom Elements Manifest declaration for this component."}`
1600
+ }));
1601
+ return buildPayload(input, storyImportPath, csf, snippetFor, docgenPayload.name);
1602
+ }
1603
+ var buildPayload = (input, storyImportPath, csf, snippetFor, name) => {
1604
+ let stories = Object.fromEntries(
1605
+ Object.entries(csf._stories).map(([exportName, story]) => [
1606
+ story.id,
1607
+ buildStoryDoc(exportName, story, csf, snippetFor)
1608
+ ])
1609
+ );
1610
+ return {
1611
+ id: getComponentIdFromEntry(input.entry),
1612
+ name,
1613
+ path: storyImportPath,
1614
+ stories
1615
+ };
1616
+ }, renderedSnippetFactory = (csf, declaration, docgenPayload, storyFilePath) => {
1617
+ let references = storyReferences(storyFilePath), deps = {
1618
+ csf,
1619
+ declaration,
1620
+ docgenPayload,
1621
+ resolveStoryArgs: createStoryArgsResolver(csf, references),
1622
+ tag: declaration.tagName ?? docgenPayload.name
1623
+ };
1624
+ return (exportName) => renderedSnippet(exportName, deps);
1625
+ }, storyReferences = (storyFilePath) => ({
1626
+ filePath: storyFilePath,
1627
+ resolveModule: openStoryReferences().resolveModule
1628
+ }), baseStoryDoc = (csf, exportName, story, result) => {
1629
+ let { description, summary } = extractStoryJSDocInfo(csf._storyStatements[exportName]);
1630
+ return {
1631
+ id: story.id,
1632
+ name: story.name ?? storyNameFromExport(exportName),
1633
+ ...result.snippet === void 0 ? {} : { snippet: result.snippet },
1634
+ ...result.warning === void 0 ? {} : { warning: result.warning },
1635
+ ...description ? { description } : {},
1636
+ ...summary === void 0 ? {} : { summary }
1637
+ };
1638
+ }, buildStoryDoc = (exportName, story, csf, snippetFor) => {
1639
+ try {
1640
+ return baseStoryDoc(csf, exportName, story, snippetFor(exportName));
1641
+ } catch (e) {
1642
+ let err = e instanceof Error ? e : void 0;
1643
+ return {
1644
+ id: story.id,
1645
+ name: story.name ?? storyNameFromExport(exportName),
1646
+ error: { name: err?.name ?? "Error", message: err?.message ?? String(e) }
1647
+ };
1648
+ }
1649
+ }, renderedSnippet = (exportName, deps) => authoredOrFallback(
1650
+ exportName,
1651
+ deps.resolveStoryArgs,
1652
+ (resolved) => renderedArgsSnippet(exportName, resolved, deps)
1653
+ ), authoredSnippetFactory = (csf, storyFilePath, fallback) => {
1654
+ let resolveStoryArgs = createStoryArgsResolver(csf, storyReferences(storyFilePath));
1655
+ return (exportName) => authoredOrFallback(exportName, resolveStoryArgs, fallback);
1656
+ }, authoredOrFallback = (exportName, resolveStoryArgs, fallback) => {
1657
+ let resolved = resolveStoryArgs.resolve(exportName), warnings = [], authored = authoredSource(resolved, resolveStoryArgs.ctx);
1658
+ if (authored.kind === "code")
1659
+ return { snippet: authored.code };
1660
+ if (authored.kind === "disabled")
1661
+ return {};
1662
+ authored.kind === "unresolvable" && warnings.push(unresolvedWarning([authored.source]));
1663
+ let result = fallback(resolved);
1664
+ return { ...result, ...joinWarnings([...warnings, result.warning]) };
1665
+ }, renderedArgsSnippet = (exportName, resolved, deps) => {
1666
+ let warnings = [], render = resolveEffectiveRender(deps.csf, exportName, deps.resolveStoryArgs.ctx);
1667
+ if (render.kind === "resolved") {
1668
+ let template = resolveHtmlTemplate(render.path, deps.csf);
1669
+ if (template) {
1670
+ let printed = printHtmlTemplate(template, resolved.args, deps.declaration), unresolved = [...resolved.unresolved, ...printed.unresolved];
1671
+ warnings.push(unresolvedWarning(unresolved)), warnings.push(incompleteList(printed.properties, "properties without an attribute")), warnings.push(
1672
+ incompleteList(printed.falseDefaults ?? [], "false values that HTML cannot express")
1673
+ ), warnings.push(incompleteList(printed.listenersNotShown ?? [], "listeners not shown")), warnings.push(unboundTemplateArgs(resolved.args, printed.referenced));
1674
+ let hasFailedHole = unresolved.length > 0 || printed.properties.length > 0, hasSnippet = printed.snippet !== "" || !hasFailedHole;
1675
+ return {
1676
+ ...hasSnippet ? { snippet: printed.snippet } : {},
1677
+ ...joinWarnings(hasSnippet ? warnings : [...warnings, noSnippetWarning(unresolved)])
1678
+ };
1679
+ }
1680
+ warnings.push(unresolvedWarning([sourceOf6(render.path.node)]));
1681
+ } else render.kind === "unresolved" && warnings.push(unresolvedWarning(unresolvedRenderSource(render, resolved)));
1682
+ let args = argsSnippet(
1683
+ resolved.args,
1684
+ deps.declaration,
1685
+ deps.docgenPayload.argTypes ?? {},
1686
+ deps.tag,
1687
+ resolved.unresolved
1688
+ );
1689
+ return warnings.push(args.warning), {
1690
+ ...args.snippet ? { snippet: args.snippet } : {},
1691
+ ...joinWarnings(warnings)
1692
+ };
1693
+ }, unboundTemplateArgs = (args, referenced) => {
1694
+ let bound = new Set(referenced), unbound = Object.entries(args).filter(([name, node]) => !bound.has(name) && evaluateArgValue(node).kind !== "unset").map(([name]) => name);
1695
+ return incompleteList(unbound, "args not bound by the render template");
1696
+ }, unresolvedRenderSource = (render, resolved) => {
1697
+ let node = resolved.storyMembers.properties.render ?? resolved.metaMembers.properties.render ?? render.shadowedRender?.node;
1698
+ return node ? [sourceOf6(node)] : [];
1699
+ }, argsSnippet = (args, declaration, argTypes, tag, unresolvedArgs) => {
1700
+ let snippet = {
1701
+ tag,
1702
+ attributes: [],
1703
+ cssProperties: [],
1704
+ listeners: [],
1705
+ slots: [],
1706
+ styleRules: []
1707
+ }, unresolved = [], listeners = [], properties = [], unknown = [];
1708
+ for (let [key, node] of Object.entries(args)) {
1709
+ let value = evaluateArgValue(node);
1710
+ if (value.kind === "unset")
1711
+ continue;
1712
+ let binding = classifyArg(key, value.kind === "function", argTypes ?? {}, declaration);
1713
+ switch (binding.kind) {
1714
+ case "listener":
1715
+ binding.event ? snippet.listeners.push({ event: binding.event, handler: listenerHandler2(node), tag }) : listeners.push(key);
1716
+ break;
1717
+ case "property":
1718
+ properties.push(key);
1719
+ break;
1720
+ case "method":
1721
+ break;
1722
+ case "unknown":
1723
+ unknown.push(key);
1724
+ break;
1725
+ case "attribute":
1726
+ case "cssProperty":
1727
+ case "slot":
1728
+ case "cssPart":
1729
+ case "cssState":
1730
+ value.kind === "value" ? addBoundValue(snippet, binding, key, value.value, tag) : value.kind === "unresolved" && unresolved.push(value.source);
1731
+ break;
1732
+ default:
1733
+ return binding;
1734
+ }
1735
+ }
1736
+ let warnings = [
1737
+ incompleteList(listeners, "listeners the HTML snippet cannot express"),
1738
+ incompleteList(properties, "properties without an attribute"),
1739
+ incompleteList(unknown, `args not declared by \`${tag}\``),
1740
+ incompleteList(falseDefaultAttributes(snippet), "false values that HTML cannot express")
1741
+ ], allUnresolved = [...unresolvedArgs, ...unresolved], printed = hasSnippetContent(snippet) || allUnresolved.length === 0;
1742
+ return warnings.push(printed ? unresolvedWarning(allUnresolved) : noSnippetWarning(allUnresolved)), {
1743
+ ...printed ? { snippet: printElementSnippet(snippet) } : {},
1744
+ ...joinWarnings(warnings)
1745
+ };
1746
+ }, addBoundValue = (snippet, binding, source, value, tag) => {
1747
+ switch (binding.kind) {
1748
+ case "attribute":
1749
+ upsertByName(snippet.attributes, {
1750
+ name: binding.name,
1751
+ value,
1752
+ viaField: binding.viaField,
1753
+ defaultValue: binding.defaultValue,
1754
+ source
1755
+ });
1756
+ break;
1757
+ case "cssProperty":
1758
+ upsertByName(snippet.cssProperties, { name: binding.name, value });
1759
+ break;
1760
+ case "slot":
1761
+ upsertByName(snippet.slots, { name: binding.name, html: value });
1762
+ break;
1763
+ case "cssPart":
1764
+ upsertBySelector(snippet.styleRules, {
1765
+ selector: `${tag}::part(${binding.name})`,
1766
+ declarations: String(value)
1767
+ });
1768
+ break;
1769
+ case "cssState":
1770
+ upsertBySelector(snippet.styleRules, {
1771
+ selector: `${tag}:state(${binding.name})`,
1772
+ declarations: String(value)
1773
+ });
1774
+ break;
1775
+ default:
1776
+ return binding;
1777
+ }
1778
+ }, upsertByName = (items, next) => {
1779
+ let index = items.findIndex((item) => item.name === next.name);
1780
+ if (index === -1) {
1781
+ items.push(next);
1782
+ return;
1783
+ }
1784
+ items[index] = next;
1785
+ }, upsertBySelector = (items, next) => {
1786
+ let index = items.findIndex((item) => item.selector === next.selector);
1787
+ if (index === -1) {
1788
+ items.push(next);
1789
+ return;
1790
+ }
1791
+ items[index] = next;
1792
+ }, falseDefaultAttributes = (snippet) => snippet.attributes.filter(({ value, defaultValue }) => value === !1 && defaultValue === "true").map(({ source, name }) => source ?? name), hasSnippetContent = (snippet) => snippet.attributes.length > 0 || snippet.cssProperties.length > 0 || snippet.listeners.length > 0 || snippet.slots.length > 0 || snippet.styleRules.length > 0, listenerHandler2 = (node) => {
1793
+ let unwrapped = t7.isExpression(node) ? unwrapExpression5(node) : node;
1794
+ return t7.isFunction(unwrapped) ? sourceOf6(node) : "() => {}";
1795
+ }, incompleteList = (names, suffix) => names.length === 0 ? void 0 : `Incomplete snippet: ${suffix}: ${names.map((name) => `\`${name}\``).join(", ")}.`, joinWarnings = (parts) => {
1796
+ let warning = [...new Set(parts.filter((part) => part !== void 0))].join(`
1797
+ `);
1798
+ return warning === "" ? {} : { warning };
1799
+ };
1800
+
1801
+ // src/docgen/story-docs-preset.ts
1802
+ var warnedMissingDocgenService = !1, getDocgenPayload = async (componentId) => {
1803
+ try {
1804
+ return await getService("core/docgen", { internal: !0 }).queries.docgen.loaded({ id: componentId });
1805
+ } catch (error) {
1806
+ warnedMissingDocgenService || (warnedMissingDocgenService = !0, logger.warn(
1807
+ `Web Components story snippets are unavailable: querying core/docgen failed. ${error instanceof Error ? error.message : String(error)}`
1808
+ ));
1809
+ return;
1810
+ }
1811
+ }, experimental_storyDocsProvider = async (nextStoryDocs, options) => {
1812
+ let descriptors = await options.presets.apply(
1813
+ "experimental_docgenProvider",
1814
+ []
1815
+ ), worker = fileURLToPath2(import.meta.resolve(DOCGEN_WORKER_SPECIFIER));
1816
+ return descriptors.some((descriptor) => descriptor.moduleSpecifier === worker) ? async (input) => {
1817
+ let storyImportPath = getStoryImportPathFromEntry2(input.entry);
1818
+ if (!storyImportPath || !STORY_FILE_TEST_REGEXP.test(storyImportPath))
1819
+ return nextStoryDocs(input);
1820
+ let ours;
1821
+ try {
1822
+ ours = await buildStoryDocsPayload(input, { getDocgenPayload });
1823
+ } catch (error) {
1824
+ return logger.debug(
1825
+ `Web Components story snippets are unavailable for ${storyImportPath}: ${error instanceof Error ? error.message : String(error)}`
1826
+ ), nextStoryDocs(input);
1827
+ }
1828
+ return ours ? { ...await nextStoryDocs(input), ...ours } : nextStoryDocs(input);
1829
+ } : nextStoryDocs;
1830
+ };
1831
+
65
1832
  // src/preset.ts
66
- var previewAnnotations = async (input = [], options) => {
1833
+ var isDocgenProviderEnabled = !0, previewAnnotations = async (input = [], options) => {
67
1834
  let docsEnabled = Object.keys(await options.presets.apply("docs", {}, options)).length > 0;
68
1835
  return [].concat(input).concat([
69
- fileURLToPath2(import.meta.resolve("@storybook/web-components/entry-preview")),
70
- fileURLToPath2(import.meta.resolve("@storybook/web-components/entry-preview-argtypes"))
1836
+ fileURLToPath3(import.meta.resolve("@storybook/web-components/entry-preview")),
1837
+ fileURLToPath3(import.meta.resolve("@storybook/web-components/entry-preview-argtypes"))
71
1838
  ]).concat(
72
- docsEnabled ? [fileURLToPath2(import.meta.resolve("@storybook/web-components/entry-preview-docs"))] : []
1839
+ docsEnabled ? [fileURLToPath3(import.meta.resolve("@storybook/web-components/entry-preview-docs"))] : []
73
1840
  );
74
1841
  };
75
1842
  export {
76
1843
  experimental_docgenProvider,
77
1844
  experimental_manifests,
1845
+ experimental_storyDocsProvider,
1846
+ isDocgenProviderEnabled,
78
1847
  previewAnnotations
79
1848
  };