@storybook/builder-vite 11.0.0-alpha.4 → 11.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_dlda4qyr6ec from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_dlda4qyr6ec from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_dlda4qyr6ec from "node:module";
1
+ import CJS_COMPAT_NODE_URL_zwca6w95nf from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_zwca6w95nf from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_zwca6w95nf from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_dlda4qyr6ec.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_dlda4qyr6ec.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_dlda4qyr6ec.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_zwca6w95nf.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_zwca6w95nf.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_zwca6w95nf.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -2068,14 +2068,15 @@ async function generateAddonSetupCode() {
2068
2068
  // src/transform-iframe-html.ts
2069
2069
  import { normalizeStories } from "storybook/internal/common";
2070
2070
  async function transformIframeHtml(html, options) {
2071
- let { configType, features, presets } = options, build = await presets.apply("build"), frameworkOptions = await presets.apply("frameworkOptions"), headHtmlSnippet = await presets.apply("previewHead"), bodyHtmlSnippet = await presets.apply("previewBody"), logLevel = await presets.apply("logLevel", void 0), docsOptions = await presets.apply("docs"), tagsOptions = await presets.apply("tags"), coreOptions = await presets.apply("core"), stories = normalizeStories(await options.presets.apply("stories", [], options), {
2071
+ let { configType, features, presets } = options, build = await presets.apply("build"), frameworkOptions = await presets.apply("frameworkOptions"), headHtmlSnippet = await presets.apply("previewHead"), bodyHtmlSnippet = await presets.apply("previewBody"), logLevel = await presets.apply("logLevel", void 0), docsOptions = await presets.apply("docs"), tagsOptions = await presets.apply("tags"), security = await presets.apply("security"), coreOptions = await presets.apply("core"), stories = normalizeStories(await options.presets.apply("stories", [], options), {
2072
2072
  configDir: options.configDir,
2073
2073
  workingDir: process.cwd()
2074
2074
  }).map((specifier) => ({
2075
2075
  ...specifier,
2076
2076
  importPathMatcher: specifier.importPathMatcher.source
2077
2077
  })), otherGlobals = {
2078
- ...build?.test?.disableBlocks ? { __STORYBOOK_BLOCKS_EMPTY_MODULE__: {} } : {}
2078
+ ...build?.test?.disableBlocks ? { __STORYBOOK_BLOCKS_EMPTY_MODULE__: {} } : {},
2079
+ ...security?.insecureIframeMessaging ? { INSECURE_IFRAME_MESSAGING: !0 } : {}
2079
2080
  }, transformedHtml = html.replace("[CONFIG_TYPE HERE]", configType || "").replace("[LOGLEVEL HERE]", logLevel || "").replace("'[FRAMEWORK_OPTIONS HERE]'", JSON.stringify(frameworkOptions)).replace(
2080
2081
  "('OTHER_GLOBALS HERE');",
2081
2082
  Object.entries(otherGlobals).map(([k, v]) => `window["${k}"] = ${JSON.stringify(v)};`).join("")
@@ -2218,14 +2219,14 @@ for (let i = 0; i < chars.length; i++) {
2218
2219
  let c = chars.charCodeAt(i);
2219
2220
  intToChar[i] = c, charToInt[c] = i;
2220
2221
  }
2221
- function encodeInteger(builder, num, relative4) {
2222
- let delta = num - relative4;
2223
- delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
2222
+ function encodeInteger(builder, num) {
2224
2223
  do {
2225
- let clamped = delta & 31;
2226
- delta >>>= 5, delta > 0 && (clamped |= 32), builder.write(intToChar[clamped]);
2227
- } while (delta > 0);
2228
- return num;
2224
+ let clamped = num & 31;
2225
+ num >>>= 5, num > 0 && (clamped |= 32), builder.write(intToChar[clamped]);
2226
+ } while (num > 0);
2227
+ }
2228
+ function encodeSign(num) {
2229
+ return num < 0 ? -num << 1 | 1 : num << 1;
2229
2230
  }
2230
2231
  var bufLength = 1024 * 16, td = typeof TextDecoder < "u" ? new TextDecoder() : typeof Buffer < "u" ? {
2231
2232
  decode(buf) {
@@ -2251,6 +2252,20 @@ var bufLength = 1024 * 16, td = typeof TextDecoder < "u" ? new TextDecoder() : t
2251
2252
  return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
2252
2253
  }
2253
2254
  };
2255
+ function encodeRangeMappings(decoded) {
2256
+ if (decoded.length === 0) return "";
2257
+ let writer = new StringWriter();
2258
+ for (let i = 0; i < decoded.length; i++) {
2259
+ let indices = decoded[i];
2260
+ i > 0 && writer.write(semicolon);
2261
+ let index = 0;
2262
+ for (let j = 0; j < indices.length; j++) {
2263
+ let offset = indices[j];
2264
+ encodeInteger(writer, offset - index), index = offset;
2265
+ }
2266
+ }
2267
+ return writer.flush();
2268
+ }
2254
2269
  function encode(decoded) {
2255
2270
  let writer = new StringWriter(), sourcesIndex = 0, sourceLine = 0, sourceColumn = 0, namesIndex = 0;
2256
2271
  for (let i = 0; i < decoded.length; i++) {
@@ -2259,7 +2274,7 @@ function encode(decoded) {
2259
2274
  let genColumn = 0;
2260
2275
  for (let j = 0; j < line.length; j++) {
2261
2276
  let segment = line[j];
2262
- j > 0 && writer.write(comma), genColumn = encodeInteger(writer, segment[0], genColumn), segment.length !== 1 && (sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex), sourceLine = encodeInteger(writer, segment[2], sourceLine), sourceColumn = encodeInteger(writer, segment[3], sourceColumn), segment.length !== 4 && (namesIndex = encodeInteger(writer, segment[4], namesIndex)));
2277
+ j > 0 && writer.write(comma), encodeInteger(writer, encodeSign(segment[0] - genColumn)), genColumn = segment[0], segment.length !== 1 && (encodeInteger(writer, encodeSign(segment[1] - sourcesIndex)), encodeInteger(writer, encodeSign(segment[2] - sourceLine)), encodeInteger(writer, encodeSign(segment[3] - sourceColumn)), sourcesIndex = segment[1], sourceLine = segment[2], sourceColumn = segment[3], segment.length !== 4 && (encodeInteger(writer, encodeSign(segment[4] - namesIndex)), namesIndex = segment[4]));
2263
2278
  }
2264
2279
  }
2265
2280
  return writer.flush();
@@ -2321,7 +2336,7 @@ var BitSet = class BitSet2 {
2321
2336
  let sliceIndex = index - this.start, originalBefore = this.original.slice(0, sliceIndex), originalAfter = this.original.slice(sliceIndex);
2322
2337
  this.original = originalBefore;
2323
2338
  let newChunk = new Chunk2(index, this.end, originalAfter);
2324
- return newChunk.outro = this.outro, this.outro = "", this.end = index, this.edited ? (newChunk.edit("", !1), this.content = "") : this.content = originalBefore, newChunk.next = this.next, newChunk.next && (newChunk.next.previous = newChunk), newChunk.previous = this, this.next = newChunk, newChunk;
2339
+ return newChunk.outro = this.outro, this.outro = "", this.end = index, this.edited ? (newChunk.edit("", !1, !0), this.content = "") : this.content = originalBefore, newChunk.next = this.next, newChunk.next && (newChunk.next.previous = newChunk), newChunk.previous = this, this.next = newChunk, newChunk;
2325
2340
  }
2326
2341
  toString() {
2327
2342
  return this.intro + this.content + this.outro;
@@ -2355,7 +2370,14 @@ function getBtoa() {
2355
2370
  }
2356
2371
  var btoa = getBtoa(), SourceMap = class {
2357
2372
  constructor(properties) {
2358
- this.version = 3, this.file = properties.file, this.sources = properties.sources, this.sourcesContent = properties.sourcesContent, this.names = properties.names, this.mappings = encode(properties.mappings), typeof properties.x_google_ignoreList < "u" && (this.x_google_ignoreList = properties.x_google_ignoreList), typeof properties.debugId < "u" && (this.debugId = properties.debugId);
2373
+ if (this.version = 3, this.file = properties.file, this.sources = properties.sources, this.sourcesContent = properties.sourcesContent, this.names = properties.names, this.mappings = typeof properties.mappings == "string" ? properties.mappings : encode(properties.mappings), typeof properties.x_google_ignoreList < "u" && (this.x_google_ignoreList = properties.x_google_ignoreList), typeof properties.debugId < "u" && (this.debugId = properties.debugId), typeof properties.rangeMappings < "u") {
2374
+ let shouldOutputRangeMapping = !1;
2375
+ for (let line of properties.rangeMappings) if (line.length !== 0) {
2376
+ shouldOutputRangeMapping = !0;
2377
+ break;
2378
+ }
2379
+ shouldOutputRangeMapping && (this.rangeMappings = encodeRangeMappings(properties.rangeMappings));
2380
+ }
2359
2381
  }
2360
2382
  /**
2361
2383
  * Returns the equivalent of `JSON.stringify(map)`
@@ -2372,10 +2394,10 @@ var btoa = getBtoa(), SourceMap = class {
2372
2394
  }
2373
2395
  };
2374
2396
  function getLocator(source) {
2375
- let originalLines = source.split(`
2376
- `), lineOffsets = [];
2377
- for (let i = 0, pos = 0; i < originalLines.length; i++)
2378
- lineOffsets.push(pos), pos += originalLines[i].length + 1;
2397
+ let lineOffsets = [0];
2398
+ for (let i = source.indexOf(`
2399
+ `); i !== -1; i = source.indexOf(`
2400
+ `, i + 1)) lineOffsets.push(i + 1);
2379
2401
  return function(index) {
2380
2402
  let i = 0, j = lineOffsets.length;
2381
2403
  for (; i < j; ) {
@@ -2414,9 +2436,59 @@ var toString = Object.prototype.toString;
2414
2436
  function isObject(thing) {
2415
2437
  return toString.call(thing) === "[object Object]";
2416
2438
  }
2417
- var wordRegex = /\w/, Mappings = class {
2418
- constructor(hires) {
2419
- this.hires = hires, this.generatedCodeLine = 0, this.generatedCodeColumn = 0, this.raw = [], this.rawSegments = this.raw[this.generatedCodeLine] = [], this.pending = null;
2439
+ var BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", intToChar2 = (() => {
2440
+ let chars2 = new Uint8Array(64);
2441
+ for (let i = 0; i < 64; i++) chars2[i] = BASE64_CHARS.charCodeAt(i);
2442
+ return chars2;
2443
+ })(), COMMA = 44, SEMICOLON = 59, BUFFER_SIZE = 16384, FLUSH_THRESHOLD = 16348, scratch = new Uint8Array(BUFFER_SIZE);
2444
+ function writeVlq(pos, num) {
2445
+ num = num < 0 ? -num << 1 | 1 : num << 1;
2446
+ do {
2447
+ let clamped = num & 31;
2448
+ num >>>= 5, num > 0 && (clamped |= 32), scratch[pos++] = intToChar2[clamped];
2449
+ } while (num > 0);
2450
+ return pos;
2451
+ }
2452
+ var decoder = new TextDecoder(), MappingsEncoder = class {
2453
+ constructor() {
2454
+ this.out = "", this.pos = 0, this.lines = [], this.buffered = 0, this.needsComma = !1, this.prevGenColumn = 0, this.prevSourceIndex = 0, this.prevSourceLine = 0, this.prevSourceColumn = 0, this.prevNameIndex = 0;
2455
+ }
2456
+ endLine(segments) {
2457
+ this.lines.push(segments), this.buffered += segments.length + 1, this.buffered >= 4096 && this.drain(null);
2458
+ }
2459
+ segments(segments) {
2460
+ this.drain(segments);
2461
+ }
2462
+ finish(segments) {
2463
+ return this.drain(segments), this.flush(), this.out;
2464
+ }
2465
+ drain(trailing) {
2466
+ let lines = this.lines, lineCount = lines.length;
2467
+ for (let l = 0; l <= lineCount; l++) {
2468
+ let line = l < lineCount ? lines[l] : trailing;
2469
+ if (line === null) break;
2470
+ for (let i = 0; i < line.length; i++) {
2471
+ this.pos > FLUSH_THRESHOLD && this.flush();
2472
+ let segment = line[i];
2473
+ this.needsComma && (scratch[this.pos++] = COMMA), this.needsComma = !0, this.pos = writeVlq(this.pos, segment[0] - this.prevGenColumn), this.prevGenColumn = segment[0], this.pos = writeVlq(this.pos, segment[1] - this.prevSourceIndex), this.prevSourceIndex = segment[1], this.pos = writeVlq(this.pos, segment[2] - this.prevSourceLine), this.prevSourceLine = segment[2], this.pos = writeVlq(this.pos, segment[3] - this.prevSourceColumn), this.prevSourceColumn = segment[3], segment.length === 5 && (this.pos = writeVlq(this.pos, segment[4] - this.prevNameIndex), this.prevNameIndex = segment[4]);
2474
+ }
2475
+ l < lineCount && (this.pos > FLUSH_THRESHOLD && this.flush(), scratch[this.pos++] = SEMICOLON, this.needsComma = !1, this.prevGenColumn = 0);
2476
+ }
2477
+ lines.length = 0, this.buffered = 0, this.flush();
2478
+ }
2479
+ flush() {
2480
+ this.out += decoder.decode(scratch.subarray(0, this.pos)), this.pos = 0;
2481
+ }
2482
+ }, NEWLINE_CHAR$1 = 10;
2483
+ function isWordCode(code) {
2484
+ return code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57 || code === 95;
2485
+ }
2486
+ var Mappings = class {
2487
+ constructor(hires, encoder = null) {
2488
+ this.hires = hires, this.generatedCodeLine = 0, this.generatedCodeColumn = 0, this.raw = [], this.rawSegments = this.raw[this.generatedCodeLine] = [], this.rawRangeMappings = [], this.rawRangeMappingsIndices = this.rawRangeMappings[this.generatedCodeLine] = [], this.encoder = encoder;
2489
+ }
2490
+ nextLine() {
2491
+ this.encoder === null ? (this.generatedCodeLine += 1, this.raw[this.generatedCodeLine] = this.rawSegments = []) : (this.encoder.endLine(this.rawSegments), this.rawSegments = [], this.generatedCodeLine += 1), this.generatedCodeColumn = 0, this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
2420
2492
  }
2421
2493
  addEdit(sourceIndex, content, loc, nameIndex) {
2422
2494
  if (content.length) {
@@ -2429,7 +2501,7 @@ var wordRegex = /\w/, Mappings = class {
2429
2501
  loc.line,
2430
2502
  loc.column
2431
2503
  ];
2432
- nameIndex >= 0 && segment2.push(nameIndex), this.rawSegments.push(segment2), this.generatedCodeLine += 1, this.raw[this.generatedCodeLine] = this.rawSegments = [], this.generatedCodeColumn = 0, previousContentLineEnd = contentLineEnd, contentLineEnd = content.indexOf(`
2504
+ nameIndex >= 0 && segment2.push(nameIndex), this.rawSegments.push(segment2), this.nextLine(), previousContentLineEnd = contentLineEnd, contentLineEnd = content.indexOf(`
2433
2505
  `, contentLineEnd + 1);
2434
2506
  }
2435
2507
  let segment = [
@@ -2439,48 +2511,124 @@ var wordRegex = /\w/, Mappings = class {
2439
2511
  loc.column
2440
2512
  ];
2441
2513
  nameIndex >= 0 && segment.push(nameIndex), this.rawSegments.push(segment), this.advance(content.slice(previousContentLineEnd + 1));
2442
- } else this.pending && (this.rawSegments.push(this.pending), this.advance(content));
2443
- this.pending = null;
2514
+ }
2444
2515
  }
2445
2516
  addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
2446
- let originalCharIndex = chunk.start, first = !0, charInHiresBoundary = !1;
2447
- for (; originalCharIndex < chunk.end; ) {
2448
- if (original[originalCharIndex] === `
2449
- `)
2450
- loc.line += 1, loc.column = 0, this.generatedCodeLine += 1, this.raw[this.generatedCodeLine] = this.rawSegments = [], this.generatedCodeColumn = 0, first = !0, charInHiresBoundary = !1;
2451
- else {
2452
- if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
2453
- let segment = [
2517
+ let end = chunk.end, i = chunk.start;
2518
+ if (this.hires) {
2519
+ let boundary = this.hires === "boundary", experimentalRange = this.hires === "experimental-range", encoder = experimentalRange ? null : this.encoder, charInHiresBoundary = !1;
2520
+ for (; i < end; ) {
2521
+ encoder !== null && this.rawSegments.length >= 4096 && (encoder.segments(this.rawSegments), this.rawSegments.length = 0), experimentalRange && i + 1 >= end && this.rawSegments.push([
2522
+ this.generatedCodeColumn,
2523
+ sourceIndex,
2524
+ loc.line,
2525
+ loc.column
2526
+ ]);
2527
+ let code = original.charCodeAt(i);
2528
+ code === NEWLINE_CHAR$1 ? (loc.line += 1, loc.column = 0, this.nextLine(), charInHiresBoundary = !1) : (boundary ? isWordCode(code) ? charInHiresBoundary || (this.rawSegments.push([
2529
+ this.generatedCodeColumn,
2530
+ sourceIndex,
2531
+ loc.line,
2532
+ loc.column
2533
+ ]), charInHiresBoundary = !0) : (this.rawSegments.push([
2534
+ this.generatedCodeColumn,
2535
+ sourceIndex,
2536
+ loc.line,
2537
+ loc.column
2538
+ ]), charInHiresBoundary = !1) : experimentalRange ? i === chunk.start && (this.rawRangeMappingsIndices.push(this.rawSegments.length), this.rawSegments.push([
2539
+ this.generatedCodeColumn,
2540
+ sourceIndex,
2541
+ loc.line,
2542
+ loc.column
2543
+ ])) : this.rawSegments.push([
2544
+ this.generatedCodeColumn,
2545
+ sourceIndex,
2546
+ loc.line,
2547
+ loc.column
2548
+ ]), loc.column += 1, this.generatedCodeColumn += 1), i += 1;
2549
+ }
2550
+ } else {
2551
+ let bits = sourcemapLocations.bits;
2552
+ for (; i < end; ) {
2553
+ let newline = original.indexOf(`
2554
+ `, i);
2555
+ if ((newline === -1 || newline > end) && (newline = end), newline > i) {
2556
+ this.rawSegments.push([
2454
2557
  this.generatedCodeColumn,
2455
2558
  sourceIndex,
2456
2559
  loc.line,
2457
2560
  loc.column
2458
- ];
2459
- this.hires === "boundary" ? wordRegex.test(original[originalCharIndex]) ? charInHiresBoundary || (this.rawSegments.push(segment), charInHiresBoundary = !0) : (this.rawSegments.push(segment), charInHiresBoundary = !1) : this.rawSegments.push(segment);
2561
+ ]);
2562
+ for (let w = i + 1 >> 5, last = newline - 1 >> 5; w <= last; w++) {
2563
+ let word = bits[w];
2564
+ if (!word) continue;
2565
+ let base = w << 5;
2566
+ for (; word; ) {
2567
+ let lowest = word & -word, index = base + 31 - Math.clz32(lowest);
2568
+ if (index > i && index < newline) {
2569
+ let offset = index - i;
2570
+ this.rawSegments.push([
2571
+ this.generatedCodeColumn + offset,
2572
+ sourceIndex,
2573
+ loc.line,
2574
+ loc.column + offset
2575
+ ]);
2576
+ }
2577
+ word ^= lowest;
2578
+ }
2579
+ }
2580
+ loc.column += newline - i, this.generatedCodeColumn += newline - i;
2460
2581
  }
2461
- loc.column += 1, this.generatedCodeColumn += 1, first = !1;
2582
+ if (newline === end) break;
2583
+ loc.line += 1, loc.column = 0, this.nextLine(), i = newline + 1;
2462
2584
  }
2463
- originalCharIndex += 1;
2464
2585
  }
2465
- this.pending = null;
2466
2586
  }
2467
2587
  advance(str) {
2468
2588
  if (!str) return;
2469
- let lines = str.split(`
2589
+ let lastNewline = str.lastIndexOf(`
2470
2590
  `);
2471
- if (lines.length > 1) {
2472
- for (let i = 0; i < lines.length - 1; i++)
2473
- this.generatedCodeLine++, this.raw[this.generatedCodeLine] = this.rawSegments = [];
2474
- this.generatedCodeColumn = 0;
2475
- }
2476
- this.generatedCodeColumn += lines[lines.length - 1].length;
2591
+ for (let i = str.indexOf(`
2592
+ `); i !== -1; i = str.indexOf(`
2593
+ `, i + 1)) this.nextLine();
2594
+ this.generatedCodeColumn += str.length - lastNewline - 1;
2477
2595
  }
2478
2596
  }, n = `
2479
2597
  `, NEWLINE_CHAR = 10, CR_CHAR = 13, warned = {
2480
2598
  insertLeft: !1,
2481
2599
  insertRight: !1,
2482
2600
  storeName: !1
2483
- }, MagicString = class MagicString2 {
2601
+ };
2602
+ function expandReplacement(replacement, matched, position, str, captures, namedCaptures) {
2603
+ if (!replacement.includes("$")) return replacement;
2604
+ let result = "", index = 0;
2605
+ for (; index < replacement.length; ) {
2606
+ let dollar = replacement.indexOf("$", index);
2607
+ if (dollar === -1) {
2608
+ result += replacement.slice(index);
2609
+ break;
2610
+ }
2611
+ result += replacement.slice(index, dollar);
2612
+ let char = replacement[dollar + 1], expansion = "$", consumed = 1;
2613
+ if (char === "$") consumed = 2;
2614
+ else if (char === "&")
2615
+ expansion = matched, consumed = 2;
2616
+ else if (char === "`")
2617
+ expansion = str.slice(0, position), consumed = 2;
2618
+ else if (char === "'")
2619
+ expansion = str.slice(position + matched.length), consumed = 2;
2620
+ else if (char === "<" && namedCaptures !== void 0) {
2621
+ let close = replacement.indexOf(">", dollar + 2);
2622
+ close !== -1 && (expansion = namedCaptures[replacement.slice(dollar + 2, close)] ?? "", consumed = close + 1 - dollar);
2623
+ } else if (char >= "0" && char <= "9") {
2624
+ let second = replacement[dollar + 2], double = second >= "0" && second <= "9" ? Number(char + second) : NaN, single = Number(char);
2625
+ double >= 1 && double <= captures.length ? (expansion = captures[double - 1] ?? "", consumed = 3) : single >= 1 && single <= captures.length && (expansion = captures[single - 1] ?? "", consumed = 2);
2626
+ }
2627
+ result += expansion, index = dollar + consumed;
2628
+ }
2629
+ return result;
2630
+ }
2631
+ var MagicString = class MagicString2 {
2484
2632
  constructor(string, options = {}) {
2485
2633
  let chunk = new Chunk(0, string.length, string);
2486
2634
  Object.defineProperties(this, {
@@ -2607,24 +2755,42 @@ var wordRegex = /\w/, Mappings = class {
2607
2755
  */
2608
2756
  generateDecodedMap(options) {
2609
2757
  options = options || {};
2610
- let sourceIndex = 0, names = Object.keys(this.storedNames), mappings = new Mappings(options.hires), locate = getLocator(this.original);
2611
- return this.intro && mappings.advance(this.intro), this.firstChunk.eachNext((chunk) => {
2612
- let loc = locate(chunk.start);
2613
- chunk.intro.length && mappings.advance(chunk.intro), chunk.edited ? mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1) : mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations), chunk.outro.length && mappings.advance(chunk.outro);
2614
- }), this.outro && mappings.advance(this.outro), {
2615
- file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
2616
- sources: [options.source ? getRelativePath(options.file || "", options.source) : options.file || ""],
2617
- sourcesContent: options.includeContent ? [this.original] : void 0,
2618
- names,
2758
+ let mappings = new Mappings(options.hires), names = this._generateMappings(mappings);
2759
+ return {
2760
+ ...this._mapProperties(options, names),
2619
2761
  mappings: mappings.raw,
2620
- x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
2762
+ rangeMappings: mappings.rawRangeMappings
2621
2763
  };
2622
2764
  }
2623
2765
  /**
2624
2766
  * Generates a version 3 sourcemap.
2625
2767
  */
2626
2768
  generateMap(options) {
2627
- return new SourceMap(this.generateDecodedMap(options));
2769
+ options = options || {};
2770
+ let encoder = new MappingsEncoder(), mappings = new Mappings(options.hires, encoder), names = this._generateMappings(mappings);
2771
+ return new SourceMap({
2772
+ ...this._mapProperties(options, names),
2773
+ mappings: encoder.finish(mappings.rawSegments),
2774
+ rangeMappings: mappings.rawRangeMappings
2775
+ });
2776
+ }
2777
+ /** @internal */
2778
+ _generateMappings(mappings) {
2779
+ let names = Object.keys(this.storedNames), locate = getLocator(this.original);
2780
+ return this.intro && mappings.advance(this.intro), this.firstChunk.eachNext((chunk) => {
2781
+ let loc = locate(chunk.start);
2782
+ chunk.intro.length && mappings.advance(chunk.intro), chunk.edited ? mappings.addEdit(0, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1) : mappings.addUneditedChunk(0, chunk, this.original, loc, this.sourcemapLocations), chunk.outro.length && mappings.advance(chunk.outro);
2783
+ }), this.outro && mappings.advance(this.outro), names;
2784
+ }
2785
+ /** @internal */
2786
+ _mapProperties(options, names) {
2787
+ return {
2788
+ file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
2789
+ sources: [options.source ? getRelativePath(options.file || "", options.source) : options.file || ""],
2790
+ sourcesContent: options.includeContent ? [this.original] : void 0,
2791
+ names,
2792
+ x_google_ignoreList: this.ignoreList ? [0] : void 0
2793
+ };
2628
2794
  }
2629
2795
  /** @internal */
2630
2796
  _ensureindentStr() {
@@ -2646,16 +2812,20 @@ var wordRegex = /\w/, Mappings = class {
2646
2812
  options.exclude && (typeof options.exclude[0] == "number" ? [options.exclude] : options.exclude).forEach((exclusion) => {
2647
2813
  for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded[i] = !0;
2648
2814
  });
2649
- let shouldIndentNextCharacter = options.indentStart !== !1, replacer = (match) => shouldIndentNextCharacter ? `${resolvedIndentStr}${match}` : (shouldIndentNextCharacter = !0, match);
2650
- this.intro = this.intro.replace(pattern, replacer);
2815
+ let shouldIndentNextCharacter = options.indentStart !== !1, indentPiece = (str) => {
2816
+ if (str === "") return str;
2817
+ let indented = str.replace(pattern, (match, offset) => offset > 0 || shouldIndentNextCharacter ? `${resolvedIndentStr}${match}` : match);
2818
+ return shouldIndentNextCharacter = str[str.length - 1] === `
2819
+ `, indented;
2820
+ };
2821
+ this.intro = indentPiece(this.intro);
2651
2822
  let charIndex = 0, chunk = this.firstChunk, indentAt = (index) => {
2652
- shouldIndentNextCharacter = !1, index === chunk.start || (this._splitChunk(chunk, index), chunk = chunk.next), chunk.prependRight(resolvedIndentStr);
2823
+ shouldIndentNextCharacter = !1, index === chunk.start ? chunk.appendRight(resolvedIndentStr) : (this._splitChunk(chunk, index), chunk = chunk.next, chunk.prependRight(resolvedIndentStr));
2653
2824
  };
2654
2825
  for (; chunk; ) {
2655
2826
  let end = chunk.end;
2656
- if (chunk.edited)
2657
- isExcluded[charIndex] || (chunk.content = chunk.content.replace(pattern, replacer), chunk.content.length && (shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === `
2658
- `));
2827
+ if (isExcluded[chunk.start] || (chunk.intro = indentPiece(chunk.intro)), chunk.edited)
2828
+ isExcluded[charIndex] || (chunk.content = indentPiece(chunk.content));
2659
2829
  else if (options.exclude)
2660
2830
  for (charIndex = chunk.start; charIndex < end; ) {
2661
2831
  if (!isExcluded[charIndex]) {
@@ -2679,9 +2849,9 @@ var wordRegex = /\w/, Mappings = class {
2679
2849
  }
2680
2850
  indentAt(charIndex), charIndex += 1;
2681
2851
  }
2682
- charIndex = chunk.end, chunk = chunk.next;
2852
+ isExcluded[chunk.end - 1] || (chunk.outro = indentPiece(chunk.outro)), charIndex = chunk.end, chunk = chunk.next;
2683
2853
  }
2684
- return this.outro = this.outro.replace(pattern, replacer), this;
2854
+ return this.outro = indentPiece(this.outro), this;
2685
2855
  }
2686
2856
  /** @internal */
2687
2857
  insert() {
@@ -2697,8 +2867,14 @@ var wordRegex = /\w/, Mappings = class {
2697
2867
  }
2698
2868
  /**
2699
2869
  * Moves the characters from `start` and `end` to `index`.
2870
+ *
2871
+ * `affinity` controls where the range is anchored at `index`. With the
2872
+ * default `'right'`, it is inserted before the content that starts at `index`;
2873
+ * with `'left'`, it is inserted after the content that ends at `index`. The
2874
+ * two differ only when other content has already been moved to that boundary,
2875
+ * mirroring the `appendLeft`/`appendRight` distinction.
2700
2876
  */
2701
- move(start, end, index) {
2877
+ move(start, end, index, affinity = "right") {
2702
2878
  if (start = start + this.offset, end = end + this.offset, index = index + this.offset, start === end) return this;
2703
2879
  if (index >= start && index <= end) throw new MagicStringError("cannot move a selection inside itself");
2704
2880
  this._split(start), this._split(end), this._split(index);
@@ -2708,9 +2884,22 @@ var wordRegex = /\w/, Mappings = class {
2708
2884
  for (; cursor !== last; )
2709
2885
  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
2886
  }
2711
- let oldLeft = first.previous, oldRight = last.next, newRight = this.byStart.get(index);
2712
- if (!newRight && last === this.lastChunk) return this;
2713
- let newLeft = newRight ? newRight.previous : this.lastChunk;
2887
+ let oldLeft = first.previous, oldRight = last.next, newLeft, newRight;
2888
+ if (affinity === "left")
2889
+ if (newLeft = this.byEnd.get(index) ?? null, newLeft) {
2890
+ if (newLeft.next === first) return this;
2891
+ newRight = newLeft.next;
2892
+ } else {
2893
+ if (first === this.firstChunk) return this;
2894
+ newRight = this.firstChunk;
2895
+ }
2896
+ else if (newRight = this.byStart.get(index) ?? null, newRight) {
2897
+ if (newRight.previous === last) return this;
2898
+ newLeft = newRight.previous;
2899
+ } else {
2900
+ if (last === this.lastChunk) return this;
2901
+ newLeft = this.lastChunk;
2902
+ }
2714
2903
  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;
2715
2904
  }
2716
2905
  /**
@@ -2794,7 +2983,10 @@ var wordRegex = /\w/, Mappings = class {
2794
2983
  }
2795
2984
  /**
2796
2985
  * Removes the characters from `start` to `end` (of the original string, **not** the generated string).
2797
- * Removing the same content twice, or making removals that partially overlap, will cause an error.
2986
+ * Content appended or prepended at positions strictly inside the range is removed with it, while
2987
+ * content attached at `start` or `end` is preserved — use `s.overwrite(start, end, '')` to remove
2988
+ * the range including its edge inserts.
2989
+ * Repeated removals and removals with partially overlapping ranges are allowed.
2798
2990
  */
2799
2991
  remove(start, end) {
2800
2992
  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;
@@ -2803,7 +2995,7 @@ var wordRegex = /\w/, Mappings = class {
2803
2995
  this._split(start), this._split(end);
2804
2996
  let chunk = this.byStart.get(start);
2805
2997
  for (; chunk; )
2806
- chunk.intro = "", chunk.outro = "", chunk.edit(""), chunk = end > chunk.end ? this.byStart.get(chunk.end) : null;
2998
+ chunk.start > start && (chunk.intro = ""), chunk.end < end && (chunk.outro = ""), chunk.edit("", !1, !0), chunk = end > chunk.end ? this.byStart.get(chunk.end) : null;
2807
2999
  return this;
2808
3000
  }
2809
3001
  /**
@@ -2859,12 +3051,12 @@ var wordRegex = /\w/, Mappings = class {
2859
3051
  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)));
2860
3052
  let result = "", chunk = this.firstChunk;
2861
3053
  for (; chunk && (chunk.start > start || chunk.end <= start); ) {
2862
- if (chunk.start < end && chunk.end >= end) return result;
3054
+ if (chunk.start < end && chunk.end >= end || end === 0 && chunk.start === 0) return result;
2863
3055
  chunk = chunk.next;
2864
3056
  }
2865
3057
  if (chunk && chunk.edited && chunk.start !== start) throw new MagicStringError(`cannot use edited character ${start} as slice start anchor`);
2866
3058
  let startChunk = chunk;
2867
- for (; chunk; ) {
3059
+ for (; chunk && !(end === 0 && chunk.start === 0); ) {
2868
3060
  chunk.intro && (startChunk !== chunk || chunk.start === start) && (result += chunk.intro);
2869
3061
  let containsEnd = chunk.start < end && chunk.end >= end;
2870
3062
  if (containsEnd && chunk.edited && chunk.end !== end) throw new MagicStringError(`cannot use edited character ${end} as slice end anchor`);
@@ -2913,12 +3105,13 @@ var wordRegex = /\w/, Mappings = class {
2913
3105
  * Returns true if the resulting source is empty (disregarding white space).
2914
3106
  */
2915
3107
  isEmpty() {
3108
+ if (this.intro.length && this.intro.trim()) return !1;
2916
3109
  let chunk = this.firstChunk;
2917
3110
  for (; chunk; ) {
2918
3111
  if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim()) return !1;
2919
3112
  chunk = chunk.next;
2920
3113
  }
2921
- return !0;
3114
+ return !(this.outro.length && this.outro.trim());
2922
3115
  }
2923
3116
  length() {
2924
3117
  let chunk = this.firstChunk, length = 0;
@@ -2948,7 +3141,7 @@ var wordRegex = /\w/, Mappings = class {
2948
3141
  if (chunk.end !== end && (this.lastChunk === chunk && (this.lastChunk = chunk.next), this.byEnd.set(chunk.end, chunk), this.byStart.set(chunk.next.start, chunk.next), this.byEnd.set(chunk.next.end, chunk.next)), aborted) return !0;
2949
3142
  chunk = chunk.previous;
2950
3143
  } while (chunk);
2951
- return !1;
3144
+ return this.intro = this.intro.replace(rx, ""), this.intro.length > 0;
2952
3145
  }
2953
3146
  /**
2954
3147
  * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
@@ -2966,7 +3159,7 @@ var wordRegex = /\w/, Mappings = class {
2966
3159
  if (chunk.end !== end && (chunk === this.lastChunk && (this.lastChunk = chunk.next), this.byEnd.set(chunk.end, chunk), this.byStart.set(chunk.next.start, chunk.next), this.byEnd.set(chunk.next.end, chunk.next)), aborted) return !0;
2967
3160
  chunk = chunk.next;
2968
3161
  } while (chunk);
2969
- return !1;
3162
+ return this.outro = this.outro.replace(rx, ""), this.outro.length > 0;
2970
3163
  }
2971
3164
  /**
2972
3165
  * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
@@ -2991,29 +3184,62 @@ var wordRegex = /\w/, Mappings = class {
2991
3184
  }
2992
3185
  return outputIndex !== this.original.length;
2993
3186
  }
3187
+ /**
3188
+ * Whether the original range [start, end) has had any of its characters
3189
+ * removed. `replace`/`replaceAll` search `original`, so a match can land on
3190
+ * text that is no longer in the output - overwriting it would resurrect the
3191
+ * removed characters, so such matches are skipped instead.
3192
+ *
3193
+ * @internal
3194
+ */
3195
+ _hasRemovedContent(start, end) {
3196
+ let chunk = this.byStart.get(start);
3197
+ if (!chunk) {
3198
+ chunk = this.lastSearchedChunk;
3199
+ let searchForward = start >= chunk.end;
3200
+ for (; chunk && !chunk.contains(start); ) chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start);
3201
+ chunk && (this.lastSearchedChunk = chunk);
3202
+ }
3203
+ for (; chunk && chunk.start < end; ) {
3204
+ if (chunk.content === "") return !0;
3205
+ chunk = this.byStart.get(chunk.end);
3206
+ }
3207
+ return !1;
3208
+ }
2994
3209
  /** @internal */
2995
3210
  _replaceRegexp(searchValue, replacement) {
2996
3211
  function getReplacement(match, str) {
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);
3212
+ return typeof replacement == "string" ? expandReplacement(replacement, match[0], match.index, str, match.slice(1), match.groups) : match.groups === void 0 ? replacement(match[0], ...match.slice(1), match.index, str) : replacement(match[0], ...match.slice(1), match.index, str, match.groups);
2998
3213
  }
2999
3214
  let replaceMatch = (match) => {
3000
- if (match.index == null) return;
3215
+ if (match.index == null || this._hasRemovedContent(match.index, match.index + match[0].length)) return !1;
3001
3216
  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));
3217
+ return replacement2 === match[0] || (match[0].length === 0 ? this.appendRight(match.index, replacement2) : this.overwrite(match.index, match.index + match[0].length, replacement2)), !0;
3003
3218
  };
3004
3219
  if (searchValue.global) {
3005
3220
  searchValue.lastIndex = 0;
3006
3221
  for (let match of this.original.matchAll(searchValue)) replaceMatch(match);
3007
3222
  } else {
3008
3223
  let match = this.original.match(searchValue);
3009
- match && replaceMatch(match);
3224
+ if (match && !replaceMatch(match)) {
3225
+ let global = new RegExp(searchValue.source, `${searchValue.flags}g`);
3226
+ for (let next of this.original.matchAll(global)) if (replaceMatch(next)) break;
3227
+ }
3010
3228
  }
3011
3229
  return this;
3012
3230
  }
3013
3231
  /** @internal */
3014
3232
  _replaceString(string, replacement) {
3015
3233
  let { original } = this, index = original.indexOf(string);
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;
3234
+ for (; index !== -1; ) {
3235
+ if (this._hasRemovedContent(index, index + string.length)) {
3236
+ index = original.indexOf(string, index + string.length);
3237
+ continue;
3238
+ }
3239
+ typeof replacement == "function" ? replacement = replacement(string, index, original) : replacement = expandReplacement(replacement, string, index, original, [], void 0), string !== replacement && (string.length === 0 ? this.appendRight(index, replacement) : this.overwrite(index, index + string.length, replacement));
3240
+ break;
3241
+ }
3242
+ return this;
3017
3243
  }
3018
3244
  /**
3019
3245
  * String replacement with RegExp or string.
@@ -3026,13 +3252,15 @@ var wordRegex = /\w/, Mappings = class {
3026
3252
  let { original } = this, stringLength = string.length;
3027
3253
  if (stringLength === 0) {
3028
3254
  for (let index = 0; index <= original.length; index += 1) {
3029
- let _replacement = typeof replacement == "function" ? replacement("", index, original) : replacement;
3255
+ if (this._hasRemovedContent(index, index)) continue;
3256
+ let _replacement = typeof replacement == "function" ? replacement("", index, original) : expandReplacement(replacement, "", index, original, [], void 0);
3030
3257
  _replacement !== "" && this.appendRight(index, _replacement);
3031
3258
  }
3032
3259
  return this;
3033
3260
  }
3034
3261
  for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
3035
- let previous = original.slice(index, index + stringLength), _replacement = typeof replacement == "function" ? replacement(previous, index, original) : replacement;
3262
+ if (this._hasRemovedContent(index, index + stringLength)) continue;
3263
+ let previous = original.slice(index, index + stringLength), _replacement = typeof replacement == "function" ? replacement(previous, index, original) : expandReplacement(replacement, previous, index, original, [], void 0);
3036
3264
  previous !== _replacement && this.overwrite(index, index + stringLength, _replacement);
3037
3265
  }
3038
3266
  return this;
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_dlda4qyr6ec from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_dlda4qyr6ec from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_dlda4qyr6ec from "node:module";
1
+ import CJS_COMPAT_NODE_URL_zwca6w95nf from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_zwca6w95nf from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_zwca6w95nf from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_dlda4qyr6ec.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_dlda4qyr6ec.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_dlda4qyr6ec.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_zwca6w95nf.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_zwca6w95nf.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_zwca6w95nf.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-XBTGK4RH.js";
18
+ } from "./_node-chunks/chunk-TTIQ3XRQ.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_dlda4qyr6ec from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_dlda4qyr6ec from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_dlda4qyr6ec from "node:module";
1
+ import CJS_COMPAT_NODE_URL_zwca6w95nf from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_zwca6w95nf from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_zwca6w95nf from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_dlda4qyr6ec.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_dlda4qyr6ec.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_dlda4qyr6ec.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_zwca6w95nf.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_zwca6w95nf.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_zwca6w95nf.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-XBTGK4RH.js";
16
+ } from "./_node-chunks/chunk-TTIQ3XRQ.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.4",
3
+ "version": "11.0.0-alpha.6",
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.4",
64
+ "storybook": "^11.0.0-alpha.6",
65
65
  "vite": "^6.3.0 || ^7.0.0 || ^8.0.0"
66
66
  },
67
67
  "publishConfig": {