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

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