@storybook/builder-vite 11.0.0-alpha.1 → 11.0.0-alpha.3

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.
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_h8sjn8ghzhs from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_h8sjn8ghzhs from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_h8sjn8ghzhs from "node:module";
1
+ import CJS_COMPAT_NODE_URL_5sdm6laaeno from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_5sdm6laaeno from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_5sdm6laaeno from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_h8sjn8ghzhs.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_h8sjn8ghzhs.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_h8sjn8ghzhs.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_5sdm6laaeno.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_5sdm6laaeno.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_5sdm6laaeno.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -1339,6 +1339,9 @@ var relative = function(from, to) {
1339
1339
  _from.shift(), _to.shift();
1340
1340
  }
1341
1341
  return [..._from.map(() => ".."), ..._to].join("/");
1342
+ }, dirname = function(p) {
1343
+ let segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
1344
+ return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
1342
1345
  };
1343
1346
 
1344
1347
  // src/utils/process-preview-annotation.ts
@@ -1836,6 +1839,10 @@ function viteMockPlugin(options) {
1836
1839
  ];
1837
1840
  }
1838
1841
 
1842
+ // src/utils/preview-runtime-path.ts
1843
+ import { createRequire } from "node:module";
1844
+ var builderRequire = createRequire(import.meta.url), corePath = dirname(builderRequire.resolve("storybook/package.json")), previewRuntimePath = join(corePath, "dist", "preview", "runtime.js");
1845
+
1839
1846
  // src/vite-config.ts
1840
1847
  import { existsSync as existsSync4 } from "node:fs";
1841
1848
  import { resolve as resolve4 } from "node:path";
@@ -2024,7 +2031,7 @@ async function generateModernIframeScriptCodeFromPreviews(options) {
2024
2031
  });
2025
2032
  }`.trim();
2026
2033
  return dedent3`
2027
- import { setup } from 'storybook/internal/preview/runtime';
2034
+ import { setup } from '${previewRuntimePath}';
2028
2035
 
2029
2036
  import '${SB_VIRTUAL_FILES.VIRTUAL_ADDON_SETUP_FILE}';
2030
2037
 
@@ -2333,12 +2340,17 @@ var BitSet = class BitSet2 {
2333
2340
  return trimmed !== this.content && (this.edited ? this.edit(trimmed, this.storeName, !0) : (this.split(this.end - trimmed.length), this.edit("", void 0, !0))), !0;
2334
2341
  if (this.edit("", void 0, !0), this.outro = this.outro.replace(rx, ""), this.outro.length) return !0;
2335
2342
  }
2343
+ }, MagicStringError = class extends Error {
2344
+ name = "MagicStringError";
2345
+ constructor(message, options) {
2346
+ super(`[MagicString] ${message}`, options);
2347
+ }
2336
2348
  };
2337
2349
  function getBtoa() {
2338
2350
  if (typeof globalThis < "u" && typeof globalThis.btoa == "function") return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
2339
2351
  let buffer = globalThis.Buffer;
2340
2352
  return buffer ? (str) => buffer.from(str, "utf-8").toString("base64") : () => {
2341
- throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
2353
+ throw new MagicStringError("unsupported environment: `btoa` or `Buffer` is required");
2342
2354
  };
2343
2355
  }
2344
2356
  var btoa = getBtoa(), SourceMap = class {
@@ -2498,11 +2510,11 @@ var wordRegex = /\w/, Mappings = class {
2498
2510
  },
2499
2511
  byStart: {
2500
2512
  writable: !0,
2501
- value: {}
2513
+ value: /* @__PURE__ */ new Map([[0, chunk]])
2502
2514
  },
2503
2515
  byEnd: {
2504
2516
  writable: !0,
2505
- value: {}
2517
+ value: /* @__PURE__ */ new Map([[string.length, chunk]])
2506
2518
  },
2507
2519
  filename: {
2508
2520
  writable: !0,
@@ -2531,8 +2543,12 @@ var wordRegex = /\w/, Mappings = class {
2531
2543
  offset: {
2532
2544
  writable: !0,
2533
2545
  value: options.offset || 0
2546
+ },
2547
+ hasMovedChunks: {
2548
+ writable: !0,
2549
+ value: !1
2534
2550
  }
2535
- }), this.byStart = /* @__PURE__ */ new Map([[0, chunk]]), this.byEnd = /* @__PURE__ */ new Map([[string.length, chunk]]);
2551
+ });
2536
2552
  }
2537
2553
  /**
2538
2554
  * Adds the specified character index (with respect to the original string) to sourcemap mappings, if `hires` is false.
@@ -2544,7 +2560,7 @@ var wordRegex = /\w/, Mappings = class {
2544
2560
  * Appends the specified content to the end of the string.
2545
2561
  */
2546
2562
  append(content) {
2547
- if (typeof content != "string") throw new TypeError("outro content must be a string");
2563
+ if (typeof content != "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
2548
2564
  return this.outro += content, this;
2549
2565
  }
2550
2566
  /**
@@ -2553,7 +2569,7 @@ var wordRegex = /\w/, Mappings = class {
2553
2569
  * See also `s.prependLeft(...)`.
2554
2570
  */
2555
2571
  appendLeft(index, content) {
2556
- if (index = index + this.offset, typeof content != "string") throw new TypeError("inserted content must be a string");
2572
+ if (index = index + this.offset, typeof content != "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
2557
2573
  this._split(index);
2558
2574
  let chunk = this.byEnd.get(index);
2559
2575
  return chunk ? chunk.appendLeft(content) : this.intro += content, this;
@@ -2564,7 +2580,7 @@ var wordRegex = /\w/, Mappings = class {
2564
2580
  * See also `s.prependRight(...)`.
2565
2581
  */
2566
2582
  appendRight(index, content) {
2567
- if (index = index + this.offset, typeof content != "string") throw new TypeError("inserted content must be a string");
2583
+ if (index = index + this.offset, typeof content != "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
2568
2584
  this._split(index);
2569
2585
  let chunk = this.byStart.get(index);
2570
2586
  return chunk ? chunk.appendRight(content) : this.outro += content, this;
@@ -2575,6 +2591,7 @@ var wordRegex = /\w/, Mappings = class {
2575
2591
  clone() {
2576
2592
  let cloned = new MagicString2(this.original, {
2577
2593
  filename: this.filename,
2594
+ ignoreList: this.ignoreList,
2578
2595
  offset: this.offset
2579
2596
  }), originalChunk = this.firstChunk, clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
2580
2597
  for (; originalChunk; ) {
@@ -2582,7 +2599,7 @@ var wordRegex = /\w/, Mappings = class {
2582
2599
  let nextOriginalChunk = originalChunk.next, nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
2583
2600
  nextClonedChunk && (clonedChunk.next = nextClonedChunk, nextClonedChunk.previous = clonedChunk, clonedChunk = nextClonedChunk), originalChunk = nextOriginalChunk;
2584
2601
  }
2585
- return cloned.lastChunk = clonedChunk, this.indentExclusionRanges && (cloned.indentExclusionRanges = this.indentExclusionRanges.slice()), cloned.sourcemapLocations = new BitSet(this.sourcemapLocations), cloned.intro = this.intro, cloned.outro = this.outro, cloned;
2602
+ return cloned.lastChunk = clonedChunk, this.indentExclusionRanges && (cloned.indentExclusionRanges = this.indentExclusionRanges.slice()), cloned.sourcemapLocations = new BitSet(this.sourcemapLocations), cloned.storedNames = { ...this.storedNames }, cloned.intro = this.intro, cloned.outro = this.outro, cloned.hasMovedChunks = this.hasMovedChunks, cloned;
2586
2603
  }
2587
2604
  /**
2588
2605
  * Generates a sourcemap object with raw mappings in array form, rather than encoded as a string.
@@ -2668,7 +2685,7 @@ var wordRegex = /\w/, Mappings = class {
2668
2685
  }
2669
2686
  /** @internal */
2670
2687
  insert() {
2671
- throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)");
2688
+ throw new MagicStringError("insert() is deprecated, use appendLeft() or prependRight()");
2672
2689
  }
2673
2690
  /** @internal */
2674
2691
  insertLeft(index, content) {
@@ -2683,12 +2700,18 @@ var wordRegex = /\w/, Mappings = class {
2683
2700
  */
2684
2701
  move(start, end, index) {
2685
2702
  if (start = start + this.offset, end = end + this.offset, index = index + this.offset, start === end) return this;
2686
- if (index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
2703
+ if (index >= start && index <= end) throw new MagicStringError("cannot move a selection inside itself");
2687
2704
  this._split(start), this._split(end), this._split(index);
2688
- let first = this.byStart.get(start), last = this.byEnd.get(end), oldLeft = first.previous, oldRight = last.next, newRight = this.byStart.get(index);
2705
+ let first = this.byStart.get(start), last = this.byEnd.get(end);
2706
+ if (this.hasMovedChunks) {
2707
+ let cursor = first;
2708
+ for (; cursor !== last; )
2709
+ if (cursor = cursor.next, !cursor || cursor.start < start || cursor.end > end) throw new MagicStringError(`cannot move ${start} to ${end} because an earlier move split that range`);
2710
+ }
2711
+ let oldLeft = first.previous, oldRight = last.next, newRight = this.byStart.get(index);
2689
2712
  if (!newRight && last === this.lastChunk) return this;
2690
2713
  let newLeft = newRight ? newRight.previous : this.lastChunk;
2691
- return oldLeft && (oldLeft.next = oldRight), oldRight && (oldRight.previous = oldLeft), newLeft && (newLeft.next = first), newRight && (newRight.previous = last), first.previous || (this.firstChunk = last.next), last.next || (this.lastChunk = first.previous, this.lastChunk.next = null), first.previous = newLeft, last.next = newRight || null, newLeft || (this.firstChunk = first), newRight || (this.lastChunk = last), this;
2714
+ return oldLeft && (oldLeft.next = oldRight), oldRight && (oldRight.previous = oldLeft), newLeft && (newLeft.next = first), newRight && (newRight.previous = last), first.previous || (this.firstChunk = last.next), last.next || (this.lastChunk = first.previous, this.lastChunk.next = null), first.previous = newLeft, last.next = newRight || null, newLeft || (this.firstChunk = first), newRight || (this.lastChunk = last), this.hasMovedChunks = !0, this;
2692
2715
  }
2693
2716
  /**
2694
2717
  * Replaces the characters from `start` to `end` with `content`, along with the appended/prepended content in
@@ -2715,13 +2738,11 @@ var wordRegex = /\w/, Mappings = class {
2715
2738
  * the content is overwritten, or anything that was appended/prepended to the range as well.
2716
2739
  */
2717
2740
  update(start, end, content, options) {
2718
- if (start = start + this.offset, end = end + this.offset, typeof content != "string") throw new TypeError("replacement content must be a string");
2719
- if (this.original.length !== 0) {
2720
- for (; start < 0; ) start += this.original.length;
2721
- for (; end < 0; ) end += this.original.length;
2722
- }
2723
- if (end > this.original.length) throw new Error("end is out of bounds");
2724
- if (start === end) throw new Error("Cannot overwrite a zero-length range \u2013 use appendLeft or prependRight instead");
2741
+ if (start = start + this.offset, end = end + this.offset, typeof content != "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
2742
+ if (this.original.length !== 0 && (start < 0 && (start = Math.max(0, start + this.original.length)), end < 0 && (end = Math.max(0, end + this.original.length))), start < 0) throw new MagicStringError(`start ${start} is out of bounds`);
2743
+ if (end > this.original.length) throw new MagicStringError(`end ${end} is out of bounds`);
2744
+ if (start === end) throw new MagicStringError(`cannot overwrite a zero-length range at ${start}, use appendLeft() or prependRight()`);
2745
+ if (start > end) throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`);
2725
2746
  this._split(start), this._split(end), options === !0 && (warned.storeName || (console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"), warned.storeName = !0), options = { storeName: !0 });
2726
2747
  let optionObject = typeof options == "object" && options ? options : {}, storeName = optionObject.storeName || !1, overwrite = optionObject.overwrite || !1;
2727
2748
  if (storeName) {
@@ -2736,7 +2757,7 @@ var wordRegex = /\w/, Mappings = class {
2736
2757
  if (first) {
2737
2758
  let chunk = first;
2738
2759
  for (; chunk !== last; ) {
2739
- if (chunk.next !== this.byStart.get(chunk.end)) throw new Error("Cannot overwrite across a split point");
2760
+ if (chunk.next !== this.byStart.get(chunk.end)) throw new MagicStringError("cannot overwrite across a split point");
2740
2761
  chunk = chunk.next, chunk.edit("", !1);
2741
2762
  }
2742
2763
  first.edit(content, storeName, !overwrite);
@@ -2750,14 +2771,14 @@ var wordRegex = /\w/, Mappings = class {
2750
2771
  * Prepends the string with the specified content.
2751
2772
  */
2752
2773
  prepend(content) {
2753
- if (typeof content != "string") throw new TypeError("outro content must be a string");
2774
+ if (typeof content != "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
2754
2775
  return this.intro = content + this.intro, this;
2755
2776
  }
2756
2777
  /**
2757
2778
  * Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
2758
2779
  */
2759
2780
  prependLeft(index, content) {
2760
- if (index = index + this.offset, typeof content != "string") throw new TypeError("inserted content must be a string");
2781
+ if (index = index + this.offset, typeof content != "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
2761
2782
  this._split(index);
2762
2783
  let chunk = this.byEnd.get(index);
2763
2784
  return chunk ? chunk.prependLeft(content) : this.intro = content + this.intro, this;
@@ -2766,7 +2787,7 @@ var wordRegex = /\w/, Mappings = class {
2766
2787
  * Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
2767
2788
  */
2768
2789
  prependRight(index, content) {
2769
- if (index = index + this.offset, typeof content != "string") throw new TypeError("inserted content must be a string");
2790
+ if (index = index + this.offset, typeof content != "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
2770
2791
  this._split(index);
2771
2792
  let chunk = this.byStart.get(index);
2772
2793
  return chunk ? chunk.prependRight(content) : this.outro = content + this.outro, this;
@@ -2776,13 +2797,9 @@ var wordRegex = /\w/, Mappings = class {
2776
2797
  * Removing the same content twice, or making removals that partially overlap, will cause an error.
2777
2798
  */
2778
2799
  remove(start, end) {
2779
- if (start = start + this.offset, end = end + this.offset, this.original.length !== 0) {
2780
- for (; start < 0; ) start += this.original.length;
2781
- for (; end < 0; ) end += this.original.length;
2782
- }
2783
- if (start === end) return this;
2784
- if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
2785
- if (start > end) throw new Error("end must be greater than start");
2800
+ if (start = start + this.offset, end = end + this.offset, this.original.length !== 0 && (start < 0 && (start = Math.max(0, start + this.original.length)), end < 0 && (end = Math.max(0, end + this.original.length))), start === end) return this;
2801
+ if (start < 0 || end > this.original.length) throw new MagicStringError(`range ${start}\u2013${end} is out of bounds`);
2802
+ if (start > end) throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`);
2786
2803
  this._split(start), this._split(end);
2787
2804
  let chunk = this.byStart.get(start);
2788
2805
  for (; chunk; )
@@ -2793,13 +2810,9 @@ var wordRegex = /\w/, Mappings = class {
2793
2810
  * Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
2794
2811
  */
2795
2812
  reset(start, end) {
2796
- if (start = start + this.offset, end = end + this.offset, this.original.length !== 0) {
2797
- for (; start < 0; ) start += this.original.length;
2798
- for (; end < 0; ) end += this.original.length;
2799
- }
2800
- if (start === end) return this;
2801
- if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
2802
- if (start > end) throw new Error("end must be greater than start");
2813
+ if (start = start + this.offset, end = end + this.offset, this.original.length !== 0 && (start < 0 && (start = Math.max(0, start + this.original.length)), end < 0 && (end = Math.max(0, end + this.original.length))), start === end) return this;
2814
+ if (start < 0 || end > this.original.length) throw new MagicStringError(`range ${start}\u2013${end} is out of bounds`);
2815
+ if (start > end) throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`);
2803
2816
  this._split(start), this._split(end);
2804
2817
  let chunk = this.byStart.get(start);
2805
2818
  for (; chunk; )
@@ -2843,21 +2856,18 @@ var wordRegex = /\w/, Mappings = class {
2843
2856
  * Throws error if the indices are for characters that were already removed.
2844
2857
  */
2845
2858
  slice(start = 0, end = this.original.length - this.offset) {
2846
- if (start = start + this.offset, end = end + this.offset, this.original.length !== 0) {
2847
- for (; start < 0; ) start += this.original.length;
2848
- for (; end < 0; ) end += this.original.length;
2849
- }
2859
+ start = start + this.offset, end = end + this.offset, this.original.length !== 0 && (start < 0 && (start = Math.max(0, start + this.original.length)), end < 0 && (end = Math.max(0, end + this.original.length)));
2850
2860
  let result = "", chunk = this.firstChunk;
2851
2861
  for (; chunk && (chunk.start > start || chunk.end <= start); ) {
2852
2862
  if (chunk.start < end && chunk.end >= end) return result;
2853
2863
  chunk = chunk.next;
2854
2864
  }
2855
- if (chunk && chunk.edited && chunk.start !== start) throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
2865
+ if (chunk && chunk.edited && chunk.start !== start) throw new MagicStringError(`cannot use edited character ${start} as slice start anchor`);
2856
2866
  let startChunk = chunk;
2857
2867
  for (; chunk; ) {
2858
2868
  chunk.intro && (startChunk !== chunk || chunk.start === start) && (result += chunk.intro);
2859
2869
  let containsEnd = chunk.start < end && chunk.end >= end;
2860
- if (containsEnd && chunk.edited && chunk.end !== end) throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
2870
+ if (containsEnd && chunk.edited && chunk.end !== end) throw new MagicStringError(`cannot use edited character ${end} as slice end anchor`);
2861
2871
  let sliceStart = startChunk === chunk ? start - chunk.start : 0, sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
2862
2872
  if (result += chunk.content.slice(sliceStart, sliceEnd), chunk.outro && (!containsEnd || chunk.end === end) && (result += chunk.outro), containsEnd) break;
2863
2873
  chunk = chunk.next;
@@ -2885,7 +2895,7 @@ var wordRegex = /\w/, Mappings = class {
2885
2895
  _splitChunk(chunk, index) {
2886
2896
  if (chunk.edited && chunk.content.length) {
2887
2897
  let loc = getLocator(this.original)(index);
2888
- throw new Error(`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} \u2013 "${chunk.original}")`);
2898
+ throw new MagicStringError(`cannot split a chunk that has already been edited (${loc.line}:${loc.column} \u2013 "${chunk.original}")`);
2889
2899
  }
2890
2900
  let newChunk = chunk.split(index);
2891
2901
  return this.byEnd.set(index, chunk), this.byStart.set(index, newChunk), this.byEnd.set(newChunk.end, newChunk), chunk === this.lastChunk && (this.lastChunk = newChunk), this.lastSearchedChunk = chunk, !0;
@@ -2968,41 +2978,42 @@ var wordRegex = /\w/, Mappings = class {
2968
2978
  * Indicates if the string has been changed.
2969
2979
  */
2970
2980
  hasChanged() {
2971
- return this.original !== this.toString();
2981
+ if (this.intro || this.outro) return !0;
2982
+ let outputIndex = 0, chunk = this.firstChunk;
2983
+ for (; chunk; ) {
2984
+ if (chunk.intro || chunk.outro) return !0;
2985
+ if (!chunk.edited && chunk.start === outputIndex) outputIndex = chunk.end;
2986
+ else {
2987
+ if (!this.original.startsWith(chunk.content, outputIndex)) return !0;
2988
+ outputIndex += chunk.content.length;
2989
+ }
2990
+ chunk = chunk.next;
2991
+ }
2992
+ return outputIndex !== this.original.length;
2972
2993
  }
2973
2994
  /** @internal */
2974
2995
  _replaceRegexp(searchValue, replacement) {
2975
2996
  function getReplacement(match, str) {
2976
2997
  return typeof replacement == "string" ? replacement.replace(/\$(\$|&|\d+)/g, (_, i) => i === "$" ? "$" : i === "&" ? match[0] : +i < match.length ? match[+i] : `$${i}`) : replacement(match[0], ...match.slice(1), match.index, str, match.groups);
2977
2998
  }
2978
- function matchAll(re, str) {
2979
- let matches = [];
2980
- for (; ; ) {
2981
- let match = re.exec(str);
2982
- if (!match) break;
2983
- matches.push(match);
2984
- }
2985
- return matches;
2986
- }
2987
- if (searchValue.global) matchAll(searchValue, this.original).forEach((match) => {
2988
- if (match.index != null) {
2989
- let replacement2 = getReplacement(match, this.original);
2990
- replacement2 !== match[0] && this.overwrite(match.index, match.index + match[0].length, replacement2);
2991
- }
2992
- });
2993
- else {
2999
+ let replaceMatch = (match) => {
3000
+ if (match.index == null) return;
3001
+ let replacement2 = getReplacement(match, this.original);
3002
+ replacement2 !== match[0] && (match[0].length === 0 ? this.appendRight(match.index, replacement2) : this.overwrite(match.index, match.index + match[0].length, replacement2));
3003
+ };
3004
+ if (searchValue.global) {
3005
+ searchValue.lastIndex = 0;
3006
+ for (let match of this.original.matchAll(searchValue)) replaceMatch(match);
3007
+ } else {
2994
3008
  let match = this.original.match(searchValue);
2995
- if (match && match.index != null) {
2996
- let replacement2 = getReplacement(match, this.original);
2997
- replacement2 !== match[0] && this.overwrite(match.index, match.index + match[0].length, replacement2);
2998
- }
3009
+ match && replaceMatch(match);
2999
3010
  }
3000
3011
  return this;
3001
3012
  }
3002
3013
  /** @internal */
3003
3014
  _replaceString(string, replacement) {
3004
3015
  let { original } = this, index = original.indexOf(string);
3005
- return index !== -1 && (typeof replacement == "function" && (replacement = replacement(string, index, original)), string !== replacement && this.overwrite(index, index + string.length, replacement)), this;
3016
+ return index !== -1 && (typeof replacement == "function" && (replacement = replacement(string, index, original)), string !== replacement && (string.length === 0 ? this.appendRight(index, replacement) : this.overwrite(index, index + string.length, replacement))), this;
3006
3017
  }
3007
3018
  /**
3008
3019
  * String replacement with RegExp or string.
@@ -3013,6 +3024,13 @@ var wordRegex = /\w/, Mappings = class {
3013
3024
  /** @internal */
3014
3025
  _replaceAllString(string, replacement) {
3015
3026
  let { original } = this, stringLength = string.length;
3027
+ if (stringLength === 0) {
3028
+ for (let index = 0; index <= original.length; index += 1) {
3029
+ let _replacement = typeof replacement == "function" ? replacement("", index, original) : replacement;
3030
+ _replacement !== "" && this.appendRight(index, _replacement);
3031
+ }
3032
+ return this;
3033
+ }
3016
3034
  for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
3017
3035
  let previous = original.slice(index, index + stringLength), _replacement = typeof replacement == "function" ? replacement(previous, index, original) : replacement;
3018
3036
  previous !== _replacement && this.overwrite(index, index + stringLength, _replacement);
@@ -3024,7 +3042,7 @@ var wordRegex = /\w/, Mappings = class {
3024
3042
  */
3025
3043
  replaceAll(searchValue, replacement) {
3026
3044
  if (typeof searchValue == "string") return this._replaceAllString(searchValue, replacement);
3027
- if (!searchValue.global) throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
3045
+ if (!searchValue.global) throw new MagicStringError("replaceAll() requires a global RegExp");
3028
3046
  return this._replaceRegexp(searchValue, replacement);
3029
3047
  }
3030
3048
  };
@@ -3358,7 +3376,7 @@ async function pluginConfig(options) {
3358
3376
  }
3359
3377
 
3360
3378
  // src/preset.ts
3361
- var optimizeViteDeps = ["storybook/internal/preview/runtime"];
3379
+ var optimizeViteDeps = [previewRuntimePath];
3362
3380
  async function viteCorePlugins(_, options) {
3363
3381
  let previewConfigPath = findConfigFile("preview", options.configDir);
3364
3382
  return [
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_h8sjn8ghzhs from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_h8sjn8ghzhs from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_h8sjn8ghzhs from "node:module";
1
+ import CJS_COMPAT_NODE_URL_5sdm6laaeno from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_5sdm6laaeno from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_5sdm6laaeno from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_h8sjn8ghzhs.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_h8sjn8ghzhs.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_h8sjn8ghzhs.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_5sdm6laaeno.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_5sdm6laaeno.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_5sdm6laaeno.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -15,7 +15,7 @@ import {
15
15
  bundlerOptionsKey,
16
16
  commonConfig,
17
17
  normalize
18
- } from "./_node-chunks/chunk-QUB7HIJP.js";
18
+ } from "./_node-chunks/chunk-QSTTKXRT.js";
19
19
 
20
20
  // ../../../node_modules/picocolors/picocolors.js
21
21
  var require_picocolors = __commonJS({
package/dist/preset.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_h8sjn8ghzhs from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_h8sjn8ghzhs from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_h8sjn8ghzhs from "node:module";
1
+ import CJS_COMPAT_NODE_URL_5sdm6laaeno from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_5sdm6laaeno from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_5sdm6laaeno from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_h8sjn8ghzhs.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_h8sjn8ghzhs.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_h8sjn8ghzhs.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_5sdm6laaeno.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_5sdm6laaeno.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_5sdm6laaeno.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -13,7 +13,7 @@ import {
13
13
  optimizeViteDeps,
14
14
  staticDirs,
15
15
  viteCorePlugins
16
- } from "./_node-chunks/chunk-QUB7HIJP.js";
16
+ } from "./_node-chunks/chunk-QSTTKXRT.js";
17
17
  export {
18
18
  optimizeViteDeps,
19
19
  staticDirs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/builder-vite",
3
- "version": "11.0.0-alpha.1",
3
+ "version": "11.0.0-alpha.3",
4
4
  "description": "A Storybook builder to dev and build with Vite",
5
5
  "keywords": [
6
6
  "storybook",
@@ -61,7 +61,7 @@
61
61
  "vite": "^7.0.4"
62
62
  },
63
63
  "peerDependencies": {
64
- "storybook": "^11.0.0-alpha.1",
64
+ "storybook": "^11.0.0-alpha.3",
65
65
  "vite": "^6.3.0 || ^7.0.0 || ^8.0.0"
66
66
  },
67
67
  "publishConfig": {