@storybook/web-components 11.0.0-alpha.7 → 11.0.0-alpha.9

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,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_seyt09815b from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_seyt09815b from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_seyt09815b from "node:module";
1
+ import CJS_COMPAT_NODE_URL_mslipd8609 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_mslipd8609 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_mslipd8609 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_seyt09815b.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_seyt09815b.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_seyt09815b.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_mslipd8609.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_mslipd8609.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_mslipd8609.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -12,14 +12,11 @@ var require = CJS_COMPAT_NODE_MODULE_seyt09815b.createRequire(import.meta.url);
12
12
  import {
13
13
  parseStoryFile,
14
14
  resolveStoryComponent
15
- } from "./_node-chunks/chunk-MMJPCIXK.js";
15
+ } from "./_node-chunks/chunk-RDLB2FIM.js";
16
16
 
17
17
  // src/preset.ts
18
18
  import { fileURLToPath as fileURLToPath3 } from "node:url";
19
-
20
- // src/docgen/preset.ts
21
- import { loadPreviewOrConfigFile } from "storybook/internal/common";
22
- import { fileURLToPath } from "node:url";
19
+ import { isTypeScriptReadyForDocgen } from "storybook/internal/common";
23
20
 
24
21
  // src/docgen/component-docgen/config/resolve-manifest-paths.ts
25
22
  import { findFilesUp } from "storybook/internal/common";
@@ -35,6 +32,10 @@ var asPathArray = (value) => typeof value == "string" ? [value] : Array.isArray(
35
32
  );
36
33
  }, resolveFrameworkManifestPaths = (configDir, frameworkOptions) => asPathArray(frameworkOptions.customElementsManifest).map((path) => resolve(configDir, path)), resolveManifestPaths = (configDir, frameworkOptions) => frameworkOptions.customElementsManifest === void 0 ? readPackageCustomElements(configDir) : resolveFrameworkManifestPaths(configDir, frameworkOptions);
37
34
 
35
+ // src/docgen/preset.ts
36
+ import { loadPreviewOrConfigFile } from "storybook/internal/common";
37
+ import { fileURLToPath } from "node:url";
38
+
38
39
  // src/docgen/worker-specifier.ts
39
40
  var DOCGEN_WORKER_SPECIFIER = "@storybook/web-components/internal/docgen-worker";
40
41
 
@@ -68,7 +69,6 @@ import { createWorkerGatedStoryDocsProvider, getService } from "storybook/intern
68
69
  import { logger } from "storybook/internal/node-logger";
69
70
 
70
71
  // src/docgen/story-docs/build-story-docs.ts
71
- import { types as t7 } from "storybook/internal/babel";
72
72
  import { getComponentIdFromEntry, getStoryImportPathFromEntry } from "storybook/internal/common";
73
73
  import { storyNameFromExport } from "storybook/internal/csf";
74
74
  import {
@@ -77,38 +77,41 @@ import {
77
77
  createStoryReferenceResolver,
78
78
  extractStoryJSDocInfo,
79
79
  noSnippetWarning,
80
- sourceOf as sourceOf6,
81
- unwrapExpression as unwrapExpression5,
80
+ resolveEffectiveRender,
81
+ oneLineTextOf as oneLineTextOf5,
82
+ unwrapExpression as unwrapExpression4,
82
83
  unresolvedWarning
83
84
  } from "storybook/internal/csf-tools";
84
85
  import { resolve as resolve2 } from "node:path";
85
86
 
86
87
  // src/docgen/story-docs/arg-values.ts
87
- import { types as t } from "storybook/internal/babel";
88
- import { keyOf, sourceOf, templateParts, unwrapExpression } from "storybook/internal/csf-tools";
89
- var FAILED = /* @__PURE__ */ Symbol("failed");
88
+ import {
89
+ staticKey,
90
+ oneLineTextOf,
91
+ templateParts,
92
+ unwrapExpression
93
+ } from "storybook/internal/csf-tools";
94
+ var FAILED = /* @__PURE__ */ Symbol("failed"), isFunctionNode = (node) => node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration", primitiveLiteralValue = (node) => node.type !== "Literal" ? FAILED : ["string", "number", "boolean"].includes(typeof node.value) ? node.value : node.value === null && !("regex" in node) && !("bigint" in node) ? null : FAILED;
90
95
  function evaluateArgValue(node) {
91
96
  let value = evaluate(node);
92
97
  if (value === FAILED) {
93
98
  let unwrapped = unwrapExpression(node);
94
- return t.isFunction(unwrapped) ? { kind: "function" } : { kind: "unresolved", source: sourceOf(node) };
99
+ return isFunctionNode(unwrapped) ? { kind: "function" } : { kind: "unresolved", source: oneLineTextOf(node) };
95
100
  }
96
101
  return value === void 0 ? { kind: "unset" } : { kind: "value", value };
97
102
  }
98
103
  var evaluate = (node) => {
99
- let unwrapped = unwrapExpression(node);
100
- if (t.isStringLiteral(unwrapped) || t.isNumericLiteral(unwrapped) || t.isBooleanLiteral(unwrapped))
101
- return unwrapped.value;
102
- if (t.isNullLiteral(unwrapped)) return null;
103
- if (t.isIdentifier(unwrapped, { name: "undefined" }) || t.isUnaryExpression(unwrapped) && unwrapped.operator === "void") return;
104
- if (t.isUnaryExpression(unwrapped) && (unwrapped.operator === "-" || unwrapped.operator === "+") && t.isNumericLiteral(unwrapped.argument))
104
+ let unwrapped = unwrapExpression(node), literal = primitiveLiteralValue(unwrapped);
105
+ if (literal !== FAILED) return literal;
106
+ if (unwrapped.type === "Identifier" && unwrapped.name === "undefined" || unwrapped.type === "UnaryExpression" && unwrapped.operator === "void") return;
107
+ if (unwrapped.type === "UnaryExpression" && (unwrapped.operator === "-" || unwrapped.operator === "+") && unwrapped.argument.type === "Literal" && typeof unwrapped.argument.value == "number")
105
108
  return unwrapped.operator === "-" ? -unwrapped.argument.value : unwrapped.argument.value;
106
109
  let parts = templateParts(unwrapped);
107
- 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;
110
+ return parts && parts.expressions.length === 0 ? parts.quasis[0] ?? FAILED : isFunctionNode(unwrapped) ? FAILED : unwrapped.type === "ArrayExpression" ? evaluateArray(unwrapped) : unwrapped.type === "ObjectExpression" ? evaluateObject(unwrapped) : FAILED;
108
111
  }, evaluateArray = (node) => {
109
112
  let values = [];
110
113
  for (let element of node.elements) {
111
- if (element === null || t.isSpreadElement(element))
114
+ if (element === null || element.type === "SpreadElement")
112
115
  return FAILED;
113
116
  let value = evaluate(element);
114
117
  if (value === FAILED)
@@ -119,10 +122,10 @@ var evaluate = (node) => {
119
122
  }, evaluateObject = (node) => {
120
123
  let values = {};
121
124
  for (let property of node.properties) {
122
- if (!t.isObjectProperty(property) || property.computed || t.isSpreadElement(property))
125
+ if (property.type !== "Property" || property.method || property.kind !== "init" || property.computed)
123
126
  return FAILED;
124
- let key = keyOf(property), value = evaluate(property.value);
125
- if (key === null || value === FAILED)
127
+ let key = staticKey(property), value = evaluate(property.value);
128
+ if (key === void 0 || value === FAILED)
126
129
  return FAILED;
127
130
  values[key] = value;
128
131
  }
@@ -162,15 +165,15 @@ function classifyArg(key, isFunction, argTypes, declaration) {
162
165
  case "attributes":
163
166
  return attributeBinding(
164
167
  name,
165
- attributeViaField(key, name, declaration),
166
- attributeDefault(key, name, declaration)
168
+ attributeViaField(name, declaration),
169
+ attributeDefault(name, declaration)
167
170
  );
168
171
  case "properties": {
169
172
  let attribute = pairedAttribute(name, declaration);
170
173
  return attribute ? attributeBinding(
171
174
  attribute,
172
175
  !0,
173
- fieldDefault(name, declaration) ?? attributeDefault(name, attribute, declaration)
176
+ fieldDefault(name, declaration) ?? attributeDefault(attribute, declaration)
174
177
  ) : { kind: "property", name };
175
178
  }
176
179
  case "events":
@@ -201,8 +204,8 @@ var fieldDefault = (fieldName, declaration) => fieldDeclaration(fieldName, decla
201
204
  ...defaultValue === void 0 ? {} : { defaultValue }
202
205
  }), fieldDeclaration = (fieldName, declaration) => declaration.members?.find(
203
206
  (member) => member.kind === "field" && member.name === fieldName
204
- ), attributeDeclaration = (attributeName, declaration) => declaration.attributes?.find((attribute) => attribute.name === attributeName), attributeViaField = (key, attributeName, declaration) => pairedAttribute(key, declaration) === attributeName, attributeDefault = (key, attributeName, declaration) => {
205
- let attribute = attributeDeclaration(attributeName, declaration), fieldName = attribute?.fieldName === key || pairedAttribute(key, declaration) === attributeName ? key : void 0;
207
+ ), attributeDeclaration = (attributeName, declaration) => declaration.attributes?.find((attribute) => attribute.name === attributeName), attributeViaField = (attributeName, declaration) => pairedAttribute(attributeName, declaration) === attributeName, attributeDefault = (attributeName, declaration) => {
208
+ let attribute = attributeDeclaration(attributeName, declaration), fieldName = attribute?.fieldName ?? (attributeViaField(attributeName, declaration) ? attributeName : void 0);
206
209
  return (fieldName ? fieldDefault(fieldName, declaration) : void 0) ?? attribute?.default;
207
210
  }, eventForArg = (key, declaration) => {
208
211
  let matches = declaration.events?.filter(
@@ -609,82 +612,82 @@ var printCssProperties = (properties) => {
609
612
  ];
610
613
  }, 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");
611
614
 
612
- // src/docgen/story-docs/template-print.ts
613
- import { sourceOf as sourceOf4 } from "storybook/internal/csf-tools";
614
-
615
615
  // src/docgen/story-docs/template-holes.ts
616
- import { types as t3 } from "storybook/internal/babel";
617
- import { sourceOf as sourceOf3, unwrapExpression as unwrapExpression3 } from "storybook/internal/csf-tools";
616
+ import {
617
+ detachedTextOf,
618
+ oneLineTextOf as oneLineTextOf3,
619
+ reindent,
620
+ unwrapExpression as unwrapExpression3,
621
+ walk
622
+ } from "storybook/internal/csf-tools";
618
623
 
619
624
  // src/docgen/story-docs/template-scope.ts
620
- import { types as t2 } from "storybook/internal/babel";
621
625
  import {
622
626
  collectImportBindings,
623
- keyOf as keyOf2,
624
- returnedExpressionPath,
625
- sourceOf as sourceOf2,
627
+ isStringLiteral,
628
+ staticKey as staticKey2,
629
+ returnedExpression,
630
+ oneLineTextOf as oneLineTextOf2,
626
631
  unwrapExpression as unwrapExpression2
627
632
  } from "storybook/internal/csf-tools";
628
633
  var TEMPLATE_TAG_SOURCES = ["lit", "lit-html", "lit-element"];
629
634
  function resolveHtmlTemplate(renderFunction, csf) {
630
- let bindings = collectImportBindings(csf._file.path), returned = returnedTemplateExpression(renderFunction, bindings);
635
+ let bindings = collectImportBindings(csf.program), returned = returnedTemplateExpression(renderFunction, bindings);
631
636
  return returned ? templateFromExpression(unwrapExpression2(returned.node), bindings, returned.scope) : void 0;
632
637
  }
633
638
  function templateFromExpression(expression, bindings, scope) {
634
- if (t2.isStringLiteral(expression))
639
+ if (isStringLiteral(expression))
635
640
  return {
636
641
  bindings,
637
642
  expressions: [],
638
643
  lit: !1,
639
644
  quasis: [expression.value],
640
645
  scope,
641
- source: sourceOf2(expression)
646
+ source: oneLineTextOf2(expression)
642
647
  };
643
- if (t2.isTemplateLiteral(expression))
644
- return templateFromLiteral(expression, bindings, !1, scope, sourceOf2(expression));
645
- if (!(!t2.isTaggedTemplateExpression(expression) || !t2.isIdentifier(expression.tag)))
646
- 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
+ if (expression.type === "TemplateLiteral")
649
+ return templateFromLiteral(expression, bindings, !1, scope, oneLineTextOf2(expression));
650
+ if (!(expression.type !== "TaggedTemplateExpression" || expression.tag.type !== "Identifier"))
651
+ 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, oneLineTextOf2(expression)) : void 0;
647
652
  }
648
653
  function aliasValueForIdentifier(expression, scope) {
649
654
  return scope.aliases.get(expression.name);
650
655
  }
651
656
  function argReferenceForExpression(expression, scope) {
652
657
  let unwrapped = unwrapExpression2(expression);
653
- if (t2.isIdentifier(unwrapped)) {
658
+ if (unwrapped.type === "Identifier") {
654
659
  let alias = aliasValueForIdentifier(unwrapped, scope);
655
660
  return alias?.kind === "arg" ? { name: alias.name, path: alias.path } : parameterArgReference(unwrapped, scope);
656
661
  }
657
- if (!t2.isMemberExpression(unwrapped))
662
+ if (unwrapped.type !== "MemberExpression")
658
663
  return;
659
664
  let property = memberPropertyName(unwrapped);
660
665
  if (property === void 0)
661
666
  return;
662
- if (scope.args && t2.isIdentifier(unwrapped.object, { name: scope.args }))
667
+ if (scope.args && unwrapped.object.type === "Identifier" && unwrapped.object.name === scope.args)
663
668
  return { name: property, path: [] };
664
- if (!t2.isExpression(unwrapped.object))
665
- return;
666
669
  let object = argReferenceForExpression(unwrapped.object, scope);
667
670
  return object ? { name: object.name, path: [...object.path, property] } : void 0;
668
671
  }
669
672
  var returnedTemplateExpression = (renderFunction, bindings) => {
670
- let baseScope = scopeForRenderFunction(renderFunction), strict = returnedExpressionPath(renderFunction);
673
+ let baseScope = scopeForRenderFunction(renderFunction), strict = returnedExpression(renderFunction);
671
674
  if (strict)
672
- return { node: strict.node, scope: baseScope };
673
- if (!t2.isBlockStatement(renderFunction.node.body))
675
+ return { node: strict, scope: baseScope };
676
+ if (renderFunction.body?.type !== "BlockStatement")
674
677
  return;
675
- let statements = renderFunction.node.body.body, returned = statements.at(-1);
676
- if (!t2.isReturnStatement(returned) || !t2.isExpression(returned.argument))
678
+ let statements = renderFunction.body.body, returned = statements.at(-1);
679
+ if (returned?.type !== "ReturnStatement" || !returned.argument)
677
680
  return;
678
681
  let scope = copyScope(baseScope);
679
682
  for (let statement of statements.slice(0, -1))
680
- if (!t2.isVariableDeclaration(statement) || statement.kind !== "const" && statement.kind !== "let" || !addVariableAliases(statement, scope, bindings))
683
+ if (statement.type !== "VariableDeclaration" || statement.kind !== "const" && statement.kind !== "let" || !addVariableAliases(statement, scope, bindings))
681
684
  return;
682
685
  return { node: returned.argument, scope };
683
686
  }, scopeForRenderFunction = (renderFunction) => {
684
- let [first] = renderFunction.node.params, scope = { aliases: /* @__PURE__ */ new Map(), destructured: /* @__PURE__ */ new Map() };
685
- if (t2.isIdentifier(first))
687
+ let [first] = renderFunction.params, scope = { aliases: /* @__PURE__ */ new Map(), destructured: /* @__PURE__ */ new Map() };
688
+ if (first?.type === "Identifier")
686
689
  return scope.args = first.name, scope;
687
- if (!t2.isObjectPattern(first))
690
+ if (first?.type !== "ObjectPattern")
688
691
  return scope;
689
692
  let destructured = destructuredAliases(first, { name: "", path: [] });
690
693
  if (!destructured)
@@ -694,16 +697,16 @@ var returnedTemplateExpression = (renderFunction, bindings) => {
694
697
  return scope;
695
698
  }, addVariableAliases = (declaration, scope, bindings) => {
696
699
  for (let declarator of declaration.declarations) {
697
- if (!t2.isExpression(declarator.init))
700
+ if (!declarator.init)
698
701
  return !1;
699
- if (t2.isIdentifier(declarator.id)) {
702
+ if (declarator.id.type === "Identifier") {
700
703
  let alias = aliasForExpression(declarator.init, scope, bindings);
701
704
  if (!alias)
702
705
  return !1;
703
706
  scope.aliases.set(declarator.id.name, alias);
704
707
  continue;
705
708
  }
706
- if (t2.isObjectPattern(declarator.id)) {
709
+ if (declarator.id.type === "ObjectPattern") {
707
710
  let source = destructureSourceForExpression(declarator.init, scope);
708
711
  if (!source)
709
712
  return !1;
@@ -718,28 +721,28 @@ var returnedTemplateExpression = (renderFunction, bindings) => {
718
721
  return !0;
719
722
  }, destructureSourceForExpression = (expression, scope) => {
720
723
  let unwrapped = unwrapExpression2(expression);
721
- return scope.args && t2.isIdentifier(unwrapped, { name: scope.args }) ? { name: "", path: [] } : argReferenceForExpression(expression, scope);
724
+ return scope.args && unwrapped.type === "Identifier" && unwrapped.name === scope.args ? { name: "", path: [] } : argReferenceForExpression(expression, scope);
722
725
  }, aliasForExpression = (expression, scope, bindings) => {
723
- let unwrapped = unwrapExpression2(expression), arg = t2.isExpression(unwrapped) ? argReferenceForExpression(unwrapped, scope) : void 0;
726
+ let unwrapped = unwrapExpression2(expression), arg = argReferenceForExpression(unwrapped, scope);
724
727
  if (arg)
725
- return { kind: "arg", source: sourceOf2(expression), ...arg };
728
+ return { kind: "arg", source: oneLineTextOf2(expression), ...arg };
726
729
  if (isStaticLiteral(unwrapped))
727
730
  return { kind: "value", value: literalValue(unwrapped) };
728
731
  let template = templateFromExpression(unwrapped, bindings, copyScope(scope));
729
732
  if (template)
730
- return { kind: "template", source: sourceOf2(expression), template };
733
+ return { kind: "template", source: oneLineTextOf2(expression), template };
731
734
  }, destructuredAliases = (pattern, source) => {
732
735
  let aliases = /* @__PURE__ */ new Map();
733
736
  for (let property of pattern.properties) {
734
- if (!t2.isObjectProperty(property) || property.computed)
737
+ if (property.type !== "Property" || property.computed)
735
738
  return;
736
- let key = keyOf2(property);
739
+ let key = staticKey2(property);
737
740
  if (!key)
738
741
  return;
739
742
  let root = source.name === "" ? { name: key, path: [] } : { name: source.name, path: [...source.path, key] };
740
- if (t2.isIdentifier(property.value))
743
+ if (property.value.type === "Identifier")
741
744
  aliases.set(property.value.name, { kind: "arg", ...root });
742
- else if (t2.isObjectPattern(property.value)) {
745
+ else if (property.value.type === "ObjectPattern") {
743
746
  let nested = destructuredAliases(property.value, root);
744
747
  if (!nested)
745
748
  return;
@@ -751,11 +754,9 @@ var returnedTemplateExpression = (renderFunction, bindings) => {
751
754
  }, parameterArgReference = (expression, scope) => {
752
755
  let arg = scope.destructured.get(expression.name);
753
756
  return arg ? { name: arg, path: [] } : void 0;
754
- }, 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) => ({
757
+ }, memberPropertyName = (expression) => !expression.computed && expression.property.type === "Identifier" ? expression.property.name : expression.computed && isStringLiteral(expression.property) ? expression.property.value : void 0, templateFromLiteral = (literal, bindings, lit, scope, source) => ({
755
758
  bindings,
756
- expressions: literal.expressions.filter(
757
- (expression) => t2.isExpression(expression)
758
- ),
759
+ expressions: literal.expressions,
759
760
  lit,
760
761
  quasis: literal.quasis.map((quasi) => quasi.value.raw),
761
762
  scope,
@@ -767,36 +768,43 @@ var returnedTemplateExpression = (renderFunction, bindings) => {
767
768
  }), isImported = (local, importName, sources, bindings) => {
768
769
  let binding = bindings.get(local);
769
770
  return !!binding && sources.includes(binding.importId) && binding.importName === importName;
770
- }, isStaticLiteral = (expression) => t2.isStringLiteral(expression) || t2.isNumericLiteral(expression) || t2.isBooleanLiteral(expression) || t2.isTemplateLiteral(expression) && expression.expressions.length === 0, literalValue = (expression) => {
771
- if (t2.isStringLiteral(expression) || t2.isNumericLiteral(expression) || t2.isBooleanLiteral(expression))
772
- return expression.value;
773
- if (t2.isTemplateLiteral(expression))
771
+ }, isStaticLiteral = (expression) => {
772
+ let value = primitiveLiteralValue(expression);
773
+ return value !== FAILED && value !== null || expression.type === "TemplateLiteral" && expression.expressions.length === 0;
774
+ }, literalValue = (expression) => {
775
+ if (expression.type === "TemplateLiteral")
774
776
  return expression.quasis[0]?.value.cooked ?? expression.quasis[0]?.value.raw ?? "";
777
+ let value = primitiveLiteralValue(expression);
778
+ return value === FAILED ? void 0 : value;
775
779
  };
776
780
 
777
781
  // src/docgen/story-docs/template-holes.ts
778
- 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) => {
779
- let expressionNode = unwrapExpression3(expression), alias = t3.isIdentifier(expressionNode) ? aliasValueForIdentifier(expressionNode, context.scope) : void 0;
782
+ var handlerText = (node) => reindent(detachedTextOf(node), "", " "), 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) => {
783
+ let expressionNode = unwrapExpression3(expression), alias = expressionNode.type === "Identifier" ? aliasValueForIdentifier(expressionNode, context.scope) : void 0;
780
784
  if (alias)
781
- return resolveAlias(alias, context, sourceOf3(expression));
785
+ return resolveAlias(alias, context, oneLineTextOf3(expression));
782
786
  let arg = argReferenceForExpression(expression, context.scope);
783
787
  if (arg)
784
- return resolveArgReference(arg, context.storyArgs[arg.name], sourceOf3(expression));
788
+ return resolveArgReference(arg, context.storyArgs[arg.name], oneLineTextOf3(expression));
785
789
  let unwrapped = expressionNode;
786
790
  if (isNothingExpression(unwrapped, context.bindings))
787
791
  return { kind: "nothing" };
788
792
  if (isStaticLiteral2(unwrapped))
789
793
  return { kind: "value", value: literalValue2(unwrapped) };
790
- if (t3.isFunction(unwrapped))
791
- return { handler: sourceOf3(expression), kind: "function" };
794
+ if (isFunctionNode(unwrapped))
795
+ return {
796
+ handler: handlerText(expression),
797
+ kind: "function",
798
+ source: oneLineTextOf3(expression)
799
+ };
792
800
  let nested = templateFromExpression(unwrapped, context.bindings, context.scope);
793
801
  if (nested)
794
- return { kind: "template", source: sourceOf3(expression), template: nested };
802
+ return { kind: "template", source: oneLineTextOf3(expression), template: nested };
795
803
  if (isIfDefinedCall(unwrapped, context.bindings)) {
796
804
  let value = resolveHoleValue(unwrapped.arguments[0], context);
797
805
  return value.kind === "value" && value.value !== null && value.value !== void 0 ? value : { kind: "nothing", ...value.arg ? { arg: value.arg } : {} };
798
806
  }
799
- if (t3.isConditionalExpression(unwrapped)) {
807
+ if (unwrapped.type === "ConditionalExpression") {
800
808
  let test = resolveConditionalTest(unwrapped.test, context);
801
809
  if (test.kind === "unresolved")
802
810
  return test;
@@ -806,24 +814,14 @@ var TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURC
806
814
  );
807
815
  return test.arg && !branch.arg ? { ...branch, arg: test.arg } : branch;
808
816
  }
809
- return { kind: "unresolved", source: sourceOf3(expression) };
817
+ return { kind: "unresolved", source: oneLineTextOf3(expression) };
810
818
  }, collectReferencedArgs = (expression, scope) => {
811
- let referenced = /* @__PURE__ */ new Set(), visit = (node) => {
812
- if (t3.isExpression(node)) {
813
- let args = referencedArgsForExpression(node, scope);
814
- for (let arg of args)
815
- referenced.add(arg);
816
- }
817
- for (let key of t3.VISITOR_KEYS[node.type] ?? []) {
818
- if (skipsReferenceChild(node, key))
819
- continue;
820
- let child = node[key];
821
- Array.isArray(child) ? child.forEach((entry) => {
822
- t3.isNode(entry) && visit(entry);
823
- }) : t3.isNode(child) && visit(child);
824
- }
825
- };
826
- return visit(expression), referenced;
819
+ let referenced = /* @__PURE__ */ new Set();
820
+ return walk(expression, (node, parent) => {
821
+ if (isStaticName(node, parent))
822
+ return !1;
823
+ referencedArgsForExpression(node, scope).forEach((arg) => referenced.add(arg));
824
+ }), referenced;
827
825
  }, isTruthyAttributeValue = (value) => value.kind === "value" ? !!value.value : value.kind === "template" || value.kind === "function", attributeValue = (value, context, referenced) => {
828
826
  if (value.kind === "empty" || value.kind === "function" || value.kind === "nothing")
829
827
  return { kind: "value", value: void 0 };
@@ -839,7 +837,7 @@ var TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURC
839
837
  let value = evaluateArgValue(node);
840
838
  switch (value.kind) {
841
839
  case "function":
842
- return { handler: sourceOf3(node), kind: "function", arg };
840
+ return { handler: handlerText(node), kind: "function", arg, source: oneLineTextOf3(node) };
843
841
  case "unset":
844
842
  return { kind: "value", arg, value: void 0 };
845
843
  case "unresolved":
@@ -875,7 +873,7 @@ var TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURC
875
873
  }
876
874
  return current2 === void 0 ? missingPathSource ? { arg: reference.name, kind: "unresolved", source: missingPathSource } : { arg: reference.name, kind: "empty" } : { arg: reference.name, kind: "value", value: current2 };
877
875
  }, referencedArgsForExpression = (expression, scope) => {
878
- let alias = t3.isIdentifier(expression) ? aliasValueForIdentifier(expression, scope) : void 0;
876
+ let alias = expression.type === "Identifier" ? aliasValueForIdentifier(expression, scope) : void 0;
879
877
  if (alias)
880
878
  return referencedArgsForAlias(alias);
881
879
  let arg = argReferenceForExpression(expression, scope);
@@ -897,24 +895,22 @@ var TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURC
897
895
  default:
898
896
  return alias;
899
897
  }
900
- }, 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) => {
901
- if (t3.isNullLiteral(expression))
902
- return null;
903
- if (t3.isStringLiteral(expression) || t3.isNumericLiteral(expression) || t3.isBooleanLiteral(expression))
904
- return expression.value;
905
- if (!t3.isIdentifier(expression, { name: "undefined" }) && !(t3.isUnaryExpression(expression) && expression.operator === "void") && t3.isTemplateLiteral(expression))
898
+ }, isStaticName = (node, parent) => parent?.type === "MemberExpression" && parent.property === node && !parent.computed || parent?.type === "Property" && parent.key === node && parent.value !== node && !parent.computed, isNothingExpression = (expression, bindings) => expression.type === "Identifier" && isImported2(expression.name, "nothing", TEMPLATE_TAG_SOURCES2, bindings), isStaticLiteral2 = (expression) => primitiveLiteralValue(expression) !== FAILED || expression.type === "Identifier" && expression.name === "undefined" || expression.type === "UnaryExpression" && expression.operator === "void" || expression.type === "TemplateLiteral" && expression.expressions.length === 0, literalValue2 = (expression) => {
899
+ if (expression.type === "TemplateLiteral")
906
900
  return expression.quasis[0]?.value.cooked ?? expression.quasis[0]?.value.raw ?? "";
907
- }, 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) => {
901
+ let value = primitiveLiteralValue(expression);
902
+ return value === FAILED ? void 0 : value;
903
+ }, isIfDefinedCall = (expression, bindings) => expression.type === "CallExpression" && expression.arguments.length === 1 && expression.arguments[0].type !== "SpreadElement" && expression.callee.type === "Identifier" && isImported2(expression.callee.name, "ifDefined", IF_DEFINED_SOURCES, bindings), resolveConditionalTest = (expression, context) => {
908
904
  let arg = argReferenceForExpression(expression, context.scope);
909
905
  if (arg) {
910
- let value = resolveArgReference(arg, context.storyArgs[arg.name], sourceOf3(expression));
906
+ let value = resolveArgReference(arg, context.storyArgs[arg.name], oneLineTextOf3(expression));
911
907
  return value.kind === "value" || value.kind === "empty" ? { arg: arg.name, kind: "value", truthy: value.kind === "value" && !!value.value } : {
912
908
  kind: "unresolved",
913
- source: value.kind === "unresolved" ? value.source : sourceOf3(expression)
909
+ source: value.kind === "unresolved" ? value.source : oneLineTextOf3(expression)
914
910
  };
915
911
  }
916
912
  let unwrapped = unwrapExpression3(expression);
917
- return isNothingExpression(unwrapped, context.bindings) ? { kind: "value", truthy: !1 } : isStaticLiteral2(unwrapped) ? { kind: "value", truthy: !!literalValue2(unwrapped) } : { kind: "unresolved", source: sourceOf3(expression) };
913
+ return isNothingExpression(unwrapped, context.bindings) ? { kind: "value", truthy: !1 } : isStaticLiteral2(unwrapped) ? { kind: "value", truthy: !!literalValue2(unwrapped) } : { kind: "unresolved", source: oneLineTextOf3(expression) };
918
914
  }, templateAttributeText = (template, context, referenced) => {
919
915
  let scopedContext = { ...context, bindings: template.bindings, scope: template.scope }, text = "";
920
916
  for (let index = 0; index < template.expressions.length; index += 1) {
@@ -935,6 +931,7 @@ var TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURC
935
931
  };
936
932
 
937
933
  // src/docgen/story-docs/template-print.ts
934
+ import { oneLineTextOf as oneLineTextOf4 } from "storybook/internal/csf-tools";
938
935
  function printHtmlTemplate(template, storyArgs, declaration) {
939
936
  return printTemplate(template, {
940
937
  bindings: template.bindings,
@@ -1055,7 +1052,7 @@ ${script}` : snippet,
1055
1052
  continue;
1056
1053
  let value = resolveMarkerValue(expression, state);
1057
1054
  if (value.kind === "function") {
1058
- state.unresolved.add(sourceOf4(expression));
1055
+ state.unresolved.add(oneLineTextOf4(expression));
1059
1056
  return;
1060
1057
  }
1061
1058
  if (value.kind === "nothing")
@@ -1121,15 +1118,15 @@ ${script}` : snippet,
1121
1118
  let next = text;
1122
1119
  for (let marker of markersIn(text, state)) {
1123
1120
  let expression = state.markers.get(marker);
1124
- expression && state.unresolved.add(sourceOf4(expression)), next = next.replace(marker, "");
1121
+ expression && state.unresolved.add(oneLineTextOf4(expression)), next = next.replace(marker, "");
1125
1122
  }
1126
1123
  return next;
1127
1124
  }, unresolvedMarkers = (text, state) => {
1128
1125
  for (let marker of markersIn(text, state)) {
1129
1126
  let expression = state.markers.get(marker);
1130
- expression && state.unresolved.add(sourceOf4(expression));
1127
+ expression && state.unresolved.add(oneLineTextOf4(expression));
1131
1128
  }
1132
- }, 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) => {
1129
+ }, 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(oneLineTextOf4).join(", "), attributeFromPrinted = (attribute) => {
1133
1130
  if (!attribute)
1134
1131
  return;
1135
1132
  let [node] = parseHtml(`<x ${attribute}></x>`);
@@ -1143,482 +1140,6 @@ ${script}` : snippet,
1143
1140
  attributes[index] = next;
1144
1141
  };
1145
1142
 
1146
- // ../../core/src/csf-tools/story-shape/utils.ts
1147
- import { types as t4 } from "storybook/internal/babel";
1148
- 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);
1149
- var keyOf3 = (p) => t4.isStringLiteral(p.key) ? p.key.value : !p.computed && t4.isIdentifier(p.key) ? p.key.name : null;
1150
- function resolveIdentifierInit(storyPath, identifier) {
1151
- let programPath = storyPath.findParent((p) => p.isProgram());
1152
- if (!programPath)
1153
- return null;
1154
- for (let stmt of programPath.get("body")) {
1155
- if (stmt.isFunctionDeclaration() && stmt.node.id?.name === identifier.node.name)
1156
- return stmt;
1157
- if (stmt.isExportNamedDeclaration()) {
1158
- let decl = stmt.get("declaration");
1159
- if (decl.isFunctionDeclaration() && decl.node.id?.name === identifier.node.name)
1160
- return decl;
1161
- }
1162
- }
1163
- let match = programPath.get("body").flatMap((stmt) => {
1164
- if (stmt.isVariableDeclaration())
1165
- return stmt.get("declarations");
1166
- if (stmt.isExportNamedDeclaration()) {
1167
- let decl = stmt.get("declaration");
1168
- if (decl && decl.isVariableDeclaration())
1169
- return decl.get("declarations");
1170
- }
1171
- return [];
1172
- }).find((d) => {
1173
- let id = d.get("id");
1174
- return id.isIdentifier() && id.node.name === identifier.node.name;
1175
- });
1176
- if (!match)
1177
- return null;
1178
- let init = match.get("init");
1179
- return init && init.isExpression() ? init : null;
1180
- }
1181
- function pathForNode(program, target) {
1182
- if (!target)
1183
- return;
1184
- let found;
1185
- return program.traverse({
1186
- enter(p) {
1187
- p.node && p.node === target && (found = p, p.stop());
1188
- }
1189
- }), found;
1190
- }
1191
- function metaObjectPath(csf) {
1192
- let metaPath = pathForNode(csf._file.path, csf._metaNode);
1193
- return metaPath?.isObjectExpression() ? metaPath : void 0;
1194
- }
1195
-
1196
- // ../../core/src/csf-tools/story-shape/normalize-story.ts
1197
- function normalizeStoryDeclaration(storyDeclaration) {
1198
- let storyPath = declarationExpression(storyDeclaration), resolvedStoryPath = resolveLocalStory(storyDeclaration, storyPath), normalizedPath = bindInitializer(storyDeclaration, resolvedStoryPath) ?? factoryArgumentExpression(resolvedStoryPath), unwrappedPath = unwrapTypeExpression(normalizedPath);
1199
- return classifyStoryPath(unwrappedPath);
1200
- }
1201
- function resolveLocalStory(declaration, expression) {
1202
- let visited = /* @__PURE__ */ new Set(), current2 = unwrapTypeExpression(expression);
1203
- for (; current2.isIdentifier(); ) {
1204
- let name = current2.node.name;
1205
- if (visited.has(name) || !current2.scope.getBinding(name)?.constant)
1206
- break;
1207
- visited.add(name);
1208
- let resolved = resolveIdentifierInit(declaration, current2);
1209
- if (!resolved)
1210
- break;
1211
- current2 = unwrapTypeExpression(resolved);
1212
- }
1213
- return current2;
1214
- }
1215
- function declarationExpression(storyDeclaration) {
1216
- if (storyDeclaration.isFunctionDeclaration())
1217
- return storyDeclaration;
1218
- if (storyDeclaration.isVariableDeclarator()) {
1219
- let init = storyDeclaration.get("init");
1220
- if (!init.isExpression())
1221
- throw storyDeclaration.buildCodeFrameError("Expected story initializer to be an expression");
1222
- return init;
1223
- }
1224
- throw storyDeclaration.buildCodeFrameError(
1225
- "Expected story to be a function or variable declaration"
1226
- );
1227
- }
1228
- function bindInitializer(storyDeclaration, storyPath) {
1229
- if (!storyPath.isCallExpression() || !isCanonicalCsf2BindCall(storyPath.node))
1230
- return null;
1231
- let callee = storyPath.get("callee");
1232
- if (!callee.isMemberExpression())
1233
- return null;
1234
- let obj = callee.get("object");
1235
- return obj.isIdentifier() ? resolveIdentifierInit(storyDeclaration, obj) : null;
1236
- }
1237
- function factoryArgumentExpression(storyPath) {
1238
- if (!storyPath.isCallExpression() || !isCsfFactoryCall(storyPath.node))
1239
- return storyPath;
1240
- let args = storyPath.get("arguments");
1241
- if (args.length === 0)
1242
- return storyPath;
1243
- if (args.length !== 1 || !args[0].isExpression())
1244
- throw storyPath.buildCodeFrameError("Could not evaluate story expression");
1245
- return args[0];
1246
- }
1247
- function unwrapTypeExpression(storyPath) {
1248
- return storyPath.isTSSatisfiesExpression() || storyPath.isTSAsExpression() ? storyPath.get("expression") : storyPath;
1249
- }
1250
- function classifyStoryPath(storyPath) {
1251
- if (storyPath.isObjectExpression())
1252
- return { type: "config", path: storyPath };
1253
- if (storyPath.isArrowFunctionExpression() || storyPath.isFunctionExpression() || storyPath.isFunctionDeclaration())
1254
- return { type: "fn", path: storyPath };
1255
- if (storyPath.isCallExpression() && isCsfFactoryCall(storyPath.node) && storyPath.node.arguments.length === 0)
1256
- return { type: "emptyConfig", path: storyPath };
1257
- throw storyPath.buildCodeFrameError(
1258
- "Expected story to be csf factory, function or an object expression"
1259
- );
1260
- }
1261
-
1262
- // ../../core/src/csf-tools/story-shape/resolve-members.ts
1263
- import { generate, types as t6 } from "storybook/internal/babel";
1264
-
1265
- // ../../core/src/csf-tools/story-shape/imports.ts
1266
- import { types as t5 } from "storybook/internal/babel";
1267
- var isTypeSpecifier = (s) => t5.isImportSpecifier(s) && s.importKind === "type", importedName = (im) => t5.isIdentifier(im) ? im.name : im.value;
1268
-
1269
- // ../../core/src/csf-tools/story-shape/resolve-members.ts
1270
- var sourceOf5 = (node) => generate(node, { concise: !0, comments: !1 }).code, complete = (properties = {}) => ({
1271
- properties,
1272
- shadowed: [],
1273
- unresolved: []
1274
- }), resolveObjectMembers = (object, ctx) => membersOf(object, ctx, /* @__PURE__ */ new Set());
1275
- var membersOf = (object, ctx, visited) => {
1276
- let properties = {}, unresolved = [], shadowed = /* @__PURE__ */ new Set(), shadowKnownMembers = (source) => {
1277
- unresolved.push(source);
1278
- for (let key of Object.keys(properties))
1279
- shadowed.add(key);
1280
- };
1281
- for (let property of object.properties) {
1282
- if (t6.isSpreadElement(property)) {
1283
- let spread = spreadMembers(ctx, property, visited);
1284
- if (spread === void 0 || spread.unresolved.length > 0) {
1285
- shadowKnownMembers(sourceOf5(property));
1286
- continue;
1287
- }
1288
- for (let [key2, value] of Object.entries(spread.properties))
1289
- properties[key2] = value, shadowed.delete(key2);
1290
- continue;
1291
- }
1292
- let key = keyOf3(property);
1293
- if (key === null) {
1294
- shadowKnownMembers(sourceOf5(property));
1295
- continue;
1296
- }
1297
- if (t6.isObjectMethod(property) && (property.kind !== "method" || property.generator)) {
1298
- delete properties[key], shadowed.delete(key), unresolved.push(sourceOf5(property));
1299
- continue;
1300
- }
1301
- properties[key] = t6.isObjectMethod(property) ? property : property.value, shadowed.delete(key);
1302
- }
1303
- return { properties, shadowed: [...shadowed], unresolved };
1304
- }, spreadMembers = (ctx, spread, visited) => {
1305
- let argument = unwrapExpression4(spread.argument);
1306
- return t6.isObjectExpression(argument) ? membersOf(argument, ctx, visited) : resolveReference(ctx, argument, spread.start ?? void 0, visited);
1307
- }, memberChain = (node) => {
1308
- let path = [], current2 = unwrapExpression4(node);
1309
- for (; t6.isMemberExpression(current2); ) {
1310
- let key = t6.isIdentifier(current2.property) && !current2.computed ? current2.property.name : t6.isStringLiteral(current2.property) ? current2.property.value : void 0;
1311
- if (key === void 0)
1312
- return;
1313
- path.unshift(key), current2 = unwrapExpression4(current2.object);
1314
- }
1315
- return t6.isIdentifier(current2) ? { root: current2.name, path } : void 0;
1316
- }, resolveReference = (ctx, expression, position, visited) => {
1317
- let chain = memberChain(expression);
1318
- if (!chain)
1319
- return;
1320
- let key = `ref:${ctx.filePath}#${chain.root}.${chain.path.join(".")}`;
1321
- if (!visited.has(key)) {
1322
- visited.add(key);
1323
- try {
1324
- return unguardedResolveReference(ctx, chain, position, visited);
1325
- } finally {
1326
- visited.delete(key);
1327
- }
1328
- }
1329
- }, unguardedResolveReference = (ctx, chain, position, visited) => {
1330
- let located = locate(ctx, chain, position, visited);
1331
- if (!located)
1332
- return;
1333
- let members = located.members, scope = located.ctx;
1334
- for (let [index, key] of located.path.entries()) {
1335
- if (members.unresolved.length > 0)
1336
- return;
1337
- let value = members.properties[key];
1338
- if (value === void 0)
1339
- return index === located.path.length - 1 ? complete() : void 0;
1340
- let unwrapped = unwrapExpression4(value);
1341
- if (!t6.isObjectExpression(unwrapped))
1342
- return;
1343
- members = membersOf(unwrapped, scope, visited);
1344
- }
1345
- return located.external ? externalized(members, scope) : members;
1346
- }, locate = (ctx, chain, position, visited) => {
1347
- let binding = bindingMembers(ctx, chain.root, position, visited);
1348
- if (!binding)
1349
- return;
1350
- if (binding.kind === "namespace") {
1351
- let [exportName, ...path] = chain.path;
1352
- if (exportName === void 0)
1353
- return;
1354
- let exported = bindingMembers(binding.ctx, exportName, void 0, visited);
1355
- if (exported === void 0 || exported.kind === "namespace")
1356
- return;
1357
- let located2 = withAccessor(exported, path);
1358
- return located2 === void 0 ? void 0 : { ...located2, external: !0 };
1359
- }
1360
- let located = withAccessor(binding, chain.path);
1361
- return located === void 0 ? void 0 : { ...located, external: binding.external };
1362
- }, 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) => {
1363
- if (!ctx.externalize)
1364
- return members;
1365
- let properties = {};
1366
- for (let [key, node] of Object.entries(members.properties)) {
1367
- let value = ctx.externalize(node);
1368
- if (value === void 0)
1369
- return;
1370
- properties[key] = value;
1371
- }
1372
- return {
1373
- properties,
1374
- shadowed: members.shadowed,
1375
- unresolved: members.unresolved
1376
- };
1377
- }, bindingMembers = (ctx, name, position, visited) => {
1378
- let key = `${ctx.filePath}#${name}`;
1379
- if (!visited.has(key)) {
1380
- visited.add(key);
1381
- try {
1382
- return unguardedBindingMembers(ctx, name, position, visited);
1383
- } finally {
1384
- visited.delete(key);
1385
- }
1386
- }
1387
- }, unguardedBindingMembers = (ctx, name, position, visited) => {
1388
- let binding = ctx.program.scope.getBinding(name);
1389
- if (!binding)
1390
- return;
1391
- if (binding.kind === "module")
1392
- return importedBinding(ctx, binding.path, visited);
1393
- if (!binding.constant)
1394
- return;
1395
- let rootName = localAliasRoot(ctx, name), rootBinding = ctx.program.scope.getBinding(rootName), declared = declaredBindingMembers(
1396
- ctx,
1397
- rootBinding?.path.node ?? binding.path.node,
1398
- position,
1399
- visited
1400
- );
1401
- if (declared === void 0)
1402
- return;
1403
- let assigned = assignedMembers(ctx, localAliases(ctx, rootName), position);
1404
- return {
1405
- kind: "members",
1406
- ctx,
1407
- external: !1,
1408
- ...declared.accessor ? { accessor: declared.accessor } : {},
1409
- members: {
1410
- properties: { ...declared.members.properties, ...assigned.properties },
1411
- shadowed: declared.members.shadowed.filter((key) => !(key in assigned.properties)),
1412
- unresolved: [...declared.members.unresolved, ...assigned.unresolved]
1413
- }
1414
- };
1415
- }, declaredBindingMembers = (ctx, node, position, visited) => {
1416
- if (t6.isFunctionDeclaration(node))
1417
- return { members: complete() };
1418
- if (t6.isVariableDeclarator(node) && !(position !== void 0 && (node.start ?? Number.POSITIVE_INFINITY) > position))
1419
- return node.init ? declaredMembers(ctx, node.init, position, visited) : { members: complete() };
1420
- }, declaredMembers = (ctx, init, position, visited) => {
1421
- let unwrapped = unwrapExpression4(init);
1422
- if (t6.isObjectExpression(unwrapped))
1423
- return { members: membersOf(unwrapped, ctx, visited) };
1424
- let factory = factoryCall(unwrapped);
1425
- if (factory === void 0 && (t6.isFunction(unwrapped) || isCanonicalCsf2BindCall(unwrapped)))
1426
- return { members: complete() };
1427
- if (t6.isIdentifier(unwrapped)) {
1428
- let referenced = bindingMembers(ctx, unwrapped.name, position, visited);
1429
- if (referenced?.kind === "members") {
1430
- let members = referenced.external ? ctx.externalize && externalized(referenced.members, referenced.ctx) : referenced.members;
1431
- if (members)
1432
- return { members, ...referenced.accessor ? { accessor: referenced.accessor } : {} };
1433
- }
1434
- }
1435
- if (factory === void 0)
1436
- return {
1437
- members: { properties: {}, shadowed: [], unresolved: [sourceOf5(unwrapped)] }
1438
- };
1439
- let config = factory.config ? membersOf(factory.config, ctx, visited) : complete();
1440
- if (factory.method === "story")
1441
- return { members: config, accessor: "input" };
1442
- let parent = bindingMembers(ctx, factory.parent, position, visited);
1443
- return parent === void 0 || parent.kind === "namespace" || parent.accessor !== "input" || parent.external ? void 0 : {
1444
- members: {
1445
- properties: mergedAnnotations(parent.members, config).properties,
1446
- shadowed: [
1447
- ...parent.members.shadowed.filter((key) => !(key in config.properties)),
1448
- ...config.shadowed
1449
- ],
1450
- unresolved: [...parent.members.unresolved, ...config.unresolved]
1451
- },
1452
- accessor: "input"
1453
- };
1454
- }, MERGED_ANNOTATIONS = ["args", "argTypes", "parameters", "globals"], localAliasRoot = (ctx, name) => {
1455
- let visited = /* @__PURE__ */ new Set(), current2 = name;
1456
- for (; !visited.has(current2); ) {
1457
- visited.add(current2);
1458
- let binding = ctx.program.scope.getBinding(current2), node = binding?.path.node;
1459
- if (!binding?.constant || !t6.isVariableDeclarator(node) || !node.init)
1460
- break;
1461
- let init = unwrapExpression4(node.init);
1462
- if (!t6.isIdentifier(init))
1463
- break;
1464
- let target = ctx.program.scope.getBinding(init.name);
1465
- if (!target?.constant || target.kind === "module")
1466
- break;
1467
- current2 = init.name;
1468
- }
1469
- return current2;
1470
- }, localAliases = (ctx, root) => {
1471
- let aliases = /* @__PURE__ */ new Map([[root, Number.NEGATIVE_INFINITY]]);
1472
- for (let [name, binding] of Object.entries(ctx.program.scope.bindings))
1473
- name !== root && binding.constant && localAliasRoot(ctx, name) === root && aliases.set(name, binding.path.node.start ?? Number.POSITIVE_INFINITY);
1474
- return aliases;
1475
- }, mergedAnnotations = (parent, child) => {
1476
- let properties = { ...parent.properties, ...child.properties };
1477
- for (let key of MERGED_ANNOTATIONS) {
1478
- let from = parent.properties[key], over = child.properties[key];
1479
- from === void 0 || over === void 0 || !t6.isExpression(from) || !t6.isExpression(over) || (properties[key] = t6.objectExpression([t6.spreadElement(from), t6.spreadElement(over)]));
1480
- }
1481
- return { properties };
1482
- }, factoryCall = (node) => {
1483
- if (!isCsfFactoryCall(node))
1484
- return;
1485
- let method = node.callee.property.name;
1486
- if (method !== "story" && method !== "extend")
1487
- return;
1488
- let [argument] = node.arguments, config = argument && unwrapExpression4(argument);
1489
- if (!(argument !== void 0 && (config === void 0 || !t6.isObjectExpression(config))))
1490
- return {
1491
- method,
1492
- parent: csfFactoryReceiver(node).name,
1493
- ...config && t6.isObjectExpression(config) ? { config } : {}
1494
- };
1495
- }, assignedMembers = (ctx, aliases, position) => {
1496
- let properties = {}, unresolved = [];
1497
- for (let statement of ctx.program.node.body) {
1498
- if (!t6.isExpressionStatement(statement) || !t6.isAssignmentExpression(statement.expression))
1499
- continue;
1500
- let assignment = statement.expression, target = assignment.left, depth = 0, outermost;
1501
- for (; t6.isMemberExpression(target); )
1502
- depth += 1, outermost = t6.isIdentifier(target.property) && !target.computed ? target.property.name : t6.isStringLiteral(target.property) ? target.property.value : void 0, target = target.object;
1503
- if (!(depth === 0 || !t6.isIdentifier(target) || !aliases.has(target.name)) && !((assignment.start ?? 0) < aliases.get(target.name)) && !(position !== void 0 && (assignment.start ?? 0) > position)) {
1504
- if (depth > 1 || outermost === void 0 || assignment.operator !== "=") {
1505
- unresolved.push(sourceOf5(assignment));
1506
- continue;
1507
- }
1508
- properties[outermost] = assignment.right;
1509
- }
1510
- }
1511
- return { properties, unresolved };
1512
- }, importedBinding = (ctx, specifierPath, visited) => {
1513
- let specifier = specifierPath.node, declaration = specifierPath.parent;
1514
- if (!t6.isImportDeclaration(declaration) || declaration.importKind === "type" || !(t6.isImportSpecifier(specifier) || t6.isImportDefaultSpecifier(specifier) || t6.isImportNamespaceSpecifier(specifier)) || isTypeSpecifier(specifier))
1515
- return;
1516
- let target = resolveTargetModule(ctx, declaration.source.value);
1517
- if (!target)
1518
- return;
1519
- if (t6.isImportNamespaceSpecifier(specifier))
1520
- return { kind: "namespace", ctx: target };
1521
- let exportName = t6.isImportDefaultSpecifier(specifier) ? "default" : importedName(specifier.imported);
1522
- return exportedBinding(target, exportName, visited);
1523
- }, resolveTargetModule = (ctx, specifier) => {
1524
- let target = ctx.resolveModule?.(ctx.filePath, specifier);
1525
- return target ? { ...ctx, ...target } : void 0;
1526
- }, exportedBinding = (ctx, exportName, visited) => {
1527
- let asExternal = (bound) => bound === void 0 || bound.kind === "namespace" ? bound : { ...bound, external: !0 };
1528
- for (let statement of ctx.program.node.body) {
1529
- if (t6.isExportDefaultDeclaration(statement) && exportName === "default") {
1530
- let declaration = unwrapExpression4(statement.declaration);
1531
- return t6.isIdentifier(declaration) ? asExternal(bindingMembers(ctx, declaration.name, void 0, visited)) : t6.isObjectExpression(declaration) ? {
1532
- kind: "members",
1533
- ctx,
1534
- external: !0,
1535
- members: membersOf(declaration, ctx, visited)
1536
- } : void 0;
1537
- }
1538
- if (!t6.isExportNamedDeclaration(statement) || statement.exportKind === "type")
1539
- continue;
1540
- let specifier = statement.specifiers.find(
1541
- (candidate) => t6.isExportSpecifier(candidate) && candidate.exportKind !== "type" && importedName(candidate.exported) === exportName
1542
- );
1543
- if (!specifier)
1544
- continue;
1545
- if (!statement.source)
1546
- return asExternal(bindingMembers(ctx, specifier.local.name, void 0, visited));
1547
- let target = resolveTargetModule(ctx, statement.source.value);
1548
- return target ? exportedBinding(target, specifier.local.name, visited) : void 0;
1549
- }
1550
- return exportName === "default" ? void 0 : asExternal(bindingMembers(ctx, exportName, void 0, visited));
1551
- };
1552
-
1553
- // ../../core/src/csf-tools/story-shape/render.ts
1554
- var isRenderFunction = (path) => path.isArrowFunctionExpression() || path.isFunctionExpression() || path.isFunctionDeclaration();
1555
- function resolveEffectiveRender(csf, exportName, references) {
1556
- let declaration = csf._storyDeclarationPath[exportName], normalized = normalizeStoryDeclarationForRender(declaration);
1557
- if (normalized.type === "fn")
1558
- return { kind: "resolved", path: normalized.path };
1559
- let storyRender = readRender(
1560
- normalized.type === "config" ? normalized.path : void 0,
1561
- declaration,
1562
- references
1563
- );
1564
- if (storyRender.kind === "invalid")
1565
- return { kind: "unresolved" };
1566
- if (storyRender.kind !== "missing")
1567
- return storyRender;
1568
- let metaRender = readRender(metaObjectPath(csf), declaration, references);
1569
- return metaRender.kind === "invalid" ? { kind: "unresolved" } : metaRender;
1570
- }
1571
- var normalizeStoryDeclarationForRender = normalizeStoryDeclaration, readRender = (config, storyDeclaration, references) => {
1572
- let properties = config?.get("properties") ?? [], renderIndex = -1;
1573
- for (let index = properties.length - 1; index >= 0; index -= 1) {
1574
- let property = properties[index];
1575
- if ((property.isObjectProperty() || property.isObjectMethod()) && keyOf3(property.node) === "render") {
1576
- renderIndex = index;
1577
- break;
1578
- }
1579
- }
1580
- let throughSpreads = () => config && references ? renderFromMembers(
1581
- resolveObjectMembers(config.node, references),
1582
- references,
1583
- storyDeclaration
1584
- ) : { kind: "unresolved" };
1585
- if (renderIndex === -1)
1586
- return properties.some((property) => property.isSpreadElement()) ? throughSpreads() : { kind: "missing" };
1587
- let resolved = readRenderProperty(properties[renderIndex], storyDeclaration);
1588
- if (properties.some((property, index) => index > renderIndex && property.isSpreadElement())) {
1589
- let read = throughSpreads();
1590
- return read.kind !== "unresolved" ? read : resolved.kind === "resolved" ? { kind: "unresolved", shadowedRender: resolved.path } : { kind: "unresolved" };
1591
- }
1592
- return resolved;
1593
- };
1594
- function renderFromMembers(members, references, storyDeclaration) {
1595
- if (members.unresolved.length > 0)
1596
- return { kind: "unresolved" };
1597
- let node = members.properties.render;
1598
- if (node === void 0)
1599
- return { kind: "missing" };
1600
- let path = pathForNode(references.program, node);
1601
- if (!path)
1602
- return { kind: "unresolved" };
1603
- if (path.isObjectMethod())
1604
- return path.node.kind === "method" && !path.node.generator ? { kind: "resolved", path } : { kind: "unresolved" };
1605
- if (path.isIdentifier()) {
1606
- let resolved = resolveIdentifierInit(storyDeclaration, path);
1607
- return resolved && isRenderFunction(resolved) ? { kind: "resolved", path: resolved } : { kind: "unresolved" };
1608
- }
1609
- return isRenderFunction(path) ? { kind: "resolved", path } : { kind: "unresolved" };
1610
- }
1611
- function readRenderProperty(renderProperty, storyDeclaration) {
1612
- if (renderProperty.isObjectMethod())
1613
- return renderProperty.node.kind === "method" && !renderProperty.node.generator ? { kind: "resolved", path: renderProperty } : { kind: "unresolved" };
1614
- let renderPath = renderProperty.get("value");
1615
- if (renderPath.isIdentifier()) {
1616
- let resolved = resolveIdentifierInit(storyDeclaration, renderPath);
1617
- return resolved && isRenderFunction(resolved) ? { kind: "resolved", path: resolved } : { kind: "unresolved" };
1618
- }
1619
- return isRenderFunction(renderPath) ? { kind: "resolved", path: renderPath } : { kind: "invalid", path: renderPath };
1620
- }
1621
-
1622
1143
  // src/docgen/story-docs/build-story-docs.ts
1623
1144
  var NO_COMPONENT_WARNING = "No static snippet: `meta.component` is not set.", openStoryReferences = createStoryReferenceResolver();
1624
1145
  async function buildStoryDocsPayload(input, context) {
@@ -1673,7 +1194,10 @@ var buildPayload = (input, storyImportPath, csf, snippetFor, name) => {
1673
1194
  filePath: storyFilePath,
1674
1195
  resolveModule: openStoryReferences().resolveModule
1675
1196
  }), baseStoryDoc = (csf, exportName, story, result) => {
1676
- let { description, summary } = extractStoryJSDocInfo(csf._storyStatements[exportName]);
1197
+ let { description, summary } = extractStoryJSDocInfo(
1198
+ csf._storyStatements[exportName],
1199
+ csf.editor
1200
+ );
1677
1201
  return {
1678
1202
  id: story.id,
1679
1203
  name: story.name ?? storyNameFromExport(exportName),
@@ -1712,7 +1236,7 @@ var buildPayload = (input, storyImportPath, csf, snippetFor, name) => {
1712
1236
  }, renderedArgsSnippet = (exportName, resolved, deps) => {
1713
1237
  let warnings = [], render = resolveEffectiveRender(deps.csf, exportName, deps.resolveStoryArgs.ctx);
1714
1238
  if (render.kind === "resolved") {
1715
- let template = resolveHtmlTemplate(render.path, deps.csf);
1239
+ let template = resolveHtmlTemplate(render.node, deps.csf);
1716
1240
  if (template) {
1717
1241
  let printed = printHtmlTemplate(template, resolved.args, deps.declaration), unresolved = [...resolved.unresolved, ...printed.unresolved];
1718
1242
  warnings.push(unresolvedWarning(unresolved)), warnings.push(incompleteList(printed.properties, "properties without an attribute")), warnings.push(
@@ -1724,7 +1248,7 @@ var buildPayload = (input, storyImportPath, csf, snippetFor, name) => {
1724
1248
  ...joinWarnings(hasSnippet ? warnings : [...warnings, noSnippetWarning(unresolved)])
1725
1249
  };
1726
1250
  }
1727
- warnings.push(unresolvedWarning([sourceOf6(render.path.node)]));
1251
+ warnings.push(unresolvedWarning([oneLineTextOf5(render.node)]));
1728
1252
  } else render.kind === "unresolved" && warnings.push(unresolvedWarning(unresolvedRenderSource(render, resolved)));
1729
1253
  let args = argsSnippet(
1730
1254
  resolved.args,
@@ -1741,8 +1265,8 @@ var buildPayload = (input, storyImportPath, csf, snippetFor, name) => {
1741
1265
  let bound = new Set(referenced), unbound = Object.entries(args).filter(([name, node]) => !bound.has(name) && evaluateArgValue(node).kind !== "unset").map(([name]) => name);
1742
1266
  return incompleteList(unbound, "args not bound by the render template");
1743
1267
  }, unresolvedRenderSource = (render, resolved) => {
1744
- let node = resolved.storyMembers.properties.render ?? resolved.metaMembers.properties.render ?? render.shadowedRender?.node;
1745
- return node ? [sourceOf6(node)] : [];
1268
+ let node = resolved.storyMembers.properties.render ?? resolved.metaMembers.properties.render ?? render.shadowedRender;
1269
+ return node ? [oneLineTextOf5(node)] : [];
1746
1270
  }, argsSnippet = (args, declaration, argTypes, tag, unresolvedArgs) => {
1747
1271
  let snippet = {
1748
1272
  tag,
@@ -1836,10 +1360,7 @@ var buildPayload = (input, storyImportPath, csf, snippetFor, name) => {
1836
1360
  return;
1837
1361
  }
1838
1362
  items[index] = next;
1839
- }, 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) => {
1840
- let unwrapped = t7.isExpression(node) ? unwrapExpression5(node) : node;
1841
- return t7.isFunction(unwrapped) ? sourceOf6(node) : "() => {}";
1842
- }, incompleteList = (names, suffix) => names.length === 0 ? void 0 : `Incomplete snippet: ${suffix}: ${names.map((name) => `\`${name}\``).join(", ")}.`, joinWarnings = (parts) => {
1363
+ }, 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) => isFunctionNode(unwrapExpression4(node)) ? handlerText(node) : "() => {}", incompleteList = (names, suffix) => names.length === 0 ? void 0 : `Incomplete snippet: ${suffix}: ${names.map((name) => `\`${name}\``).join(", ")}.`, joinWarnings = (parts) => {
1843
1364
  let warning = [...new Set(parts.filter((part) => part !== void 0))].join(`
1844
1365
  `);
1845
1366
  return warning === "" ? {} : { warning };
@@ -1862,7 +1383,12 @@ var warnedMissingDocgenService = !1, getDocgenPayload = async (componentId) => {
1862
1383
  });
1863
1384
 
1864
1385
  // src/preset.ts
1865
- var isDocgenProviderEnabled = !0, previewAnnotations = async (input = [], options) => {
1386
+ var isDocgenProviderEnabled = async (_existing, options) => {
1387
+ let frameworkOptions = await options.presets.apply(
1388
+ "frameworkOptions"
1389
+ ) ?? {};
1390
+ return resolveManifestPaths(options.configDir, frameworkOptions).length > 0 || await isTypeScriptReadyForDocgen((specifier) => import.meta.resolve(specifier), options);
1391
+ }, previewAnnotations = async (input = [], options) => {
1866
1392
  let docsEnabled = Object.keys(await options.presets.apply("docs", {}, options)).length > 0;
1867
1393
  return [].concat(input).concat([
1868
1394
  fileURLToPath3(import.meta.resolve("@storybook/web-components/entry-preview")),