"use strict";
var M = Object.create;
var E = Object.defineProperty;
var j = Object.getOwnPropertyDescriptor;
var L = Object.getOwnPropertyNames;
var G = Object.getPrototypeOf, H = Object.prototype.hasOwnProperty;
var r = (t, e) => E(t, "name", { value: e, configurable: !0 });
var F = (t, e) => () => (e || t((e = { exports: {} }).exports, e), e.exports), U = (t, e) => {
  for (var o in e)
    E(t, o, { get: e[o], enumerable: !0 });
}, W = (t, e, o, i) => {
  if (e && typeof e == "object" || typeof e == "function")
    for (let l of L(e))
      !H.call(t, l) && l !== o && E(t, l, { get: () => e[l], enumerable: !(i = j(e, l)) || i.enumerable });
  return t;
};
var X = (t, e, o) => (o = t != null ? M(G(t)) : {}, W(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  e || !t || !t.__esModule ? E(o, "default", { value: t, enumerable: !0 }) : o,
  t
)), Y = (t) => W(E({}, "__esModule", { value: !0 }), t);

// ../node_modules/ts-dedent/dist/index.js
var O = F((h) => {
  "use strict";
  Object.defineProperty(h, "__esModule", { value: !0 });
  h.dedent = void 0;
  function A(t) {
    for (var e = [], o = 1; o < arguments.length; o++)
      e[o - 1] = arguments[o];
    var i = Array.from(typeof t == "string" ? [t] : t);
    i[i.length - 1] = i[i.length - 1].replace(/\r?\n([\t ]*)$/, "");
    var l = i.reduce(function(d, m) {
      var y = m.match(/\n([\t ]+|(?!\s).)/g);
      return y ? d.concat(y.map(function(R) {
        var c, u;
        return (u = (c = R.match(/[\t ]/g)) === null || c === void 0 ? void 0 : c.length) !== null && u !== void 0 ? u : 0;
      })) : d;
    }, []);
    if (l.length) {
      var C = new RegExp(`
[	 ]{` + Math.min.apply(Math, l) + "}", "g");
      i = i.map(function(d) {
        return d.replace(C, `
`);
      });
    }
    i[0] = i[0].replace(/^\r?\n/, "");
    var p = i[0];
    return e.forEach(function(d, m) {
      var y = p.match(/(?:^|\n)( *)$/), R = y ? y[1] : "", c = d;
      typeof d == "string" && d.includes(`
`) && (c = String(d).split(`
`).map(function(u, D) {
        return D === 0 ? u : "" + R + u;
      }).join(`
`)), p += c + i[m + 1];
    }), p;
  }
  r(A, "dedent");
  h.dedent = A;
  h.default = A;
});

// src/preview-errors.ts
var J = {};
U(J, {
  CalledExtractOnStoreError: () => b,
  CalledPreviewMethodBeforeInitializationError: () => _,
  Category: () => $,
  EmptyIndexError: () => S,
  ImplicitActionsDuringRendering: () => f,
  MdxFileWithNoCsfReferencesError: () => x,
  MissingRenderToCanvasError: () => I,
  MissingStoryAfterHmrError: () => g,
  MissingStoryFromCsfFileError: () => N,
  NextJsSharpError: () => k,
  NextjsRouterMocksNotAvailable: () => v,
  NoStoryMatchError: () => T,
  StoryIndexFetchError: () => P,
  StoryStoreAccessedBeforeInitializationError: () => V,
  UnknownArgTypesError: () => w
});
module.exports = Y(J);
var s = X(O(), 1);

// src/storybook-error.ts
var n = class extends Error {
  static {
    r(this, "StorybookError");
  }
  /**
   * Data associated with the error. Used to provide additional information in the error message or to be passed to telemetry.
   */
  data = {};
  /**
   * Specifies the documentation for the error.
   * - If `true`, links to a documentation page on the Storybook website (make sure it exists before enabling).
   * - If a string, uses the provided URL for documentation (external or FAQ links).
   * - If `false` (default), no documentation link is added.
   */
  documentation = !1;
  /**
   * Flag used to easily determine if the error originates from Storybook.
   */
  fromStorybook = !0;
  get fullErrorCode() {
    let e = String(this.code).padStart(4, "0");
    return `SB_${this.category}_${e}`;
  }
  /**
   * Overrides the default `Error.name` property in the format: SB_<CATEGORY>_<CODE>.
   */
  get name() {
    let e = this.constructor.name;
    return `${this.fullErrorCode} (${e})`;
  }
  /**
   * Generates the error message along with additional documentation link (if applicable).
   */
  get message() {
    let e;
    return this.documentation === !0 ? e = `https://storybook.js.org/error/${this.fullErrorCode}` : typeof this.documentation == "string" ? e =
    this.documentation : Array.isArray(this.documentation) && (e = `
${this.documentation.map((o) => `	- ${o}`).join(`
`)}`), `${this.template()}${e != null ? `

More info: ${e}
` : ""}`;
  }
};

// src/preview-errors.ts
var $ = /* @__PURE__ */ ((a) => (a.DOCS_TOOLS = "DOCS-TOOLS", a.PREVIEW_CLIENT_LOGGER = "PREVIEW_CLIENT-LOGGER", a.PREVIEW_CHANNELS = "PREVI\
EW_CHANNELS", a.PREVIEW_CORE_EVENTS = "PREVIEW_CORE-EVENTS", a.PREVIEW_INSTRUMENTER = "PREVIEW_INSTRUMENTER", a.PREVIEW_API = "PREVIEW_API",
a.PREVIEW_REACT_DOM_SHIM = "PREVIEW_REACT-DOM-SHIM", a.PREVIEW_ROUTER = "PREVIEW_ROUTER", a.PREVIEW_THEMING = "PREVIEW_THEMING", a.RENDERER_HTML =
"RENDERER_HTML", a.RENDERER_PREACT = "RENDERER_PREACT", a.RENDERER_REACT = "RENDERER_REACT", a.RENDERER_SERVER = "RENDERER_SERVER", a.RENDERER_SVELTE =
"RENDERER_SVELTE", a.RENDERER_VUE = "RENDERER_VUE", a.RENDERER_VUE3 = "RENDERER_VUE3", a.RENDERER_WEB_COMPONENTS = "RENDERER_WEB-COMPONENTS",
a.FRAMEWORK_NEXTJS = "FRAMEWORK_NEXTJS", a))($ || {}), g = class extends n {
  constructor(o) {
    super();
    this.data = o;
  }
  static {
    r(this, "MissingStoryAfterHmrError");
  }
  category = "PREVIEW_API";
  code = 1;
  template() {
    return s.dedent`
    Couldn't find story matching id '${this.data.storyId}' after HMR.
    - Did you just rename a story?
    - Did you remove it from your CSF file?
    - Are you sure a story with the id '${this.data.storyId}' exists?
    - Please check the values in the stories field of your main.js config and see if they would match your CSF File.
    - Also check the browser console and terminal for potential error messages.`;
  }
}, f = class extends n {
  constructor(o) {
    super();
    this.data = o;
  }
  static {
    r(this, "ImplicitActionsDuringRendering");
  }
  category = "PREVIEW_API";
  code = 2;
  documentation = "https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#using-implicit-actions-during-rendering-is-deprecated-for\
-example-in-the-play-function";
  template() {
    return s.dedent`
      We detected that you use an implicit action arg while ${this.data.phase} of your story.  
      ${this.data.deprecated ? `
This is deprecated and won't work in Storybook 8 anymore.
` : ""}
      Please provide an explicit spy to your args like this:
        import { fn } from '@storybook/test';
        ... 
        args: {
         ${this.data.name}: fn()
        }
    `;
  }
}, b = class extends n {
  static {
    r(this, "CalledExtractOnStoreError");
  }
  category = "PREVIEW_API";
  code = 3;
  template() {
    return s.dedent`
    Cannot call \`storyStore.extract()\` without calling \`storyStore.cacheAllCsfFiles()\` first.

    You probably meant to call \`await preview.extract()\` which does the above for you.`;
  }
}, I = class extends n {
  static {
    r(this, "MissingRenderToCanvasError");
  }
  category = "PREVIEW_API";
  code = 4;
  documentation = "https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#mainjs-framework-field";
  template() {
    return s.dedent`
      Expected your framework's preset to export a \`renderToCanvas\` field.

      Perhaps it needs to be upgraded for Storybook 6.4?`;
  }
}, _ = class extends n {
  constructor(o) {
    super();
    this.data = o;
  }
  static {
    r(this, "CalledPreviewMethodBeforeInitializationError");
  }
  category = "PREVIEW_API";
  code = 5;
  template() {
    return s.dedent`
      Called \`Preview.${this.data.methodName}()\` before initialization.
      
      The preview needs to load the story index before most methods can be called. If you want
      to call \`${this.data.methodName}\`, try \`await preview.initializationPromise;\` first.
      
      If you didn't call the above code, then likely it was called by an addon that needs to
      do the above.`;
  }
}, P = class extends n {
  constructor(o) {
    super();
    this.data = o;
  }
  static {
    r(this, "StoryIndexFetchError");
  }
  category = "PREVIEW_API";
  code = 6;
  template() {
    return s.dedent`
      Error fetching \`/index.json\`:
      
      ${this.data.text}

      If you are in development, this likely indicates a problem with your Storybook process,
      check the terminal for errors.

      If you are in a deployed Storybook, there may have been an issue deploying the full Storybook
      build.`;
  }
}, x = class extends n {
  constructor(o) {
    super();
    this.data = o;
  }
  static {
    r(this, "MdxFileWithNoCsfReferencesError");
  }
  category = "PREVIEW_API";
  code = 7;
  template() {
    return s.dedent`
      Tried to render docs entry ${this.data.storyId} but it is a MDX file that has no CSF
      references, or autodocs for a CSF file that some doesn't refer to itself.
      
      This likely is an internal error in Storybook's indexing, or you've attached the
      \`attached-mdx\` tag to an MDX file that is not attached.`;
  }
}, S = class extends n {
  static {
    r(this, "EmptyIndexError");
  }
  category = "PREVIEW_API";
  code = 8;
  template() {
    return s.dedent`
      Couldn't find any stories in your Storybook.

        - Please check your stories field of your main.js config: does it match correctly?
        - Also check the browser console and terminal for error messages.`;
  }
}, T = class extends n {
  constructor(o) {
    super();
    this.data = o;
  }
  static {
    r(this, "NoStoryMatchError");
  }
  category = "PREVIEW_API";
  code = 9;
  template() {
    return s.dedent`
      Couldn't find story matching '${this.data.storySpecifier}'.

        - Are you sure a story with that id exists?
        - Please check your stories field of your main.js config.
        - Also check the browser console and terminal for error messages.`;
  }
}, N = class extends n {
  constructor(o) {
    super();
    this.data = o;
  }
  static {
    r(this, "MissingStoryFromCsfFileError");
  }
  category = "PREVIEW_API";
  code = 10;
  template() {
    return s.dedent`
    Couldn't find story matching id '${this.data.storyId}' after importing a CSF file.

    The file was indexed as if the story was there, but then after importing the file in the browser
    we didn't find the story. Possible reasons:
    - You are using a custom story indexer that is misbehaving.
    - You have a custom file loader that is removing or renaming exports.

    Please check your browser console and terminal for errors that may explain the issue.`;
  }
}, V = class extends n {
  static {
    r(this, "StoryStoreAccessedBeforeInitializationError");
  }
  category = "PREVIEW_API";
  code = 11;
  template() {
    return s.dedent`
    Cannot access the Story Store until the index is ready.

    It is not recommended to use methods directly on the Story Store anyway, in Storybook 9 we will
    remove access to the store entirely`;
  }
}, k = class extends n {
  static {
    r(this, "NextJsSharpError");
  }
  category = "FRAMEWORK_NEXTJS";
  code = 1;
  documentation = "https://storybook.js.org/docs/get-started/nextjs#faq";
  template() {
    return s.dedent`
    You are importing avif images, but you don't have sharp installed.

    You have to install sharp in order to use image optimization features in Next.js.
    `;
  }
}, v = class extends n {
  constructor(o) {
    super();
    this.data = o;
  }
  static {
    r(this, "NextjsRouterMocksNotAvailable");
  }
  category = "FRAMEWORK_NEXTJS";
  code = 2;
  template() {
    return s.dedent`
      Tried to access router mocks from "${this.data.importType}" but they were not created yet. You might be running code in an unsupported environment.
    `;
  }
}, w = class extends n {
  constructor(o) {
    super();
    this.data = o;
  }
  static {
    r(this, "UnknownArgTypesError");
  }
  category = "DOCS-TOOLS";
  code = 1;
  documentation = "https://github.com/storybookjs/storybook/issues/26606";
  template() {
    return s.dedent`There was a failure when generating detailed ArgTypes in ${this.data.language} for:
    
    ${JSON.stringify(this.data.type, null, 2)} 
    
    Storybook will fall back to use a generic type description instead.

    This type is either not supported or it is a bug in the docgen generation in Storybook.
    If you think this is a bug, please detail it as much as possible in the Github issue.`;
  }
};
