@storybook/builder-vite 10.6.0-alpha.2 → 10.6.0-alpha.4
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
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_3u00ejc6ctm from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_3u00ejc6ctm from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_3u00ejc6ctm from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_3u00ejc6ctm.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_3u00ejc6ctm.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_3u00ejc6ctm.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -620,7 +620,7 @@ function viteMockPlugin(options) {
|
|
|
620
620
|
let automockedCode = getAutomockCode(code, call.spy, babelParser2);
|
|
621
621
|
return {
|
|
622
622
|
code: automockedCode.toString(),
|
|
623
|
-
map: automockedCode.generateMap()
|
|
623
|
+
map: automockedCode.generateMap().toString()
|
|
624
624
|
};
|
|
625
625
|
}
|
|
626
626
|
} catch (e) {
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_3u00ejc6ctm from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_3u00ejc6ctm from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_3u00ejc6ctm from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_3u00ejc6ctm.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_3u00ejc6ctm.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_3u00ejc6ctm.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
normalize,
|
|
25
25
|
relative,
|
|
26
26
|
viteCorePlugins
|
|
27
|
-
} from "./_node-chunks/chunk-
|
|
27
|
+
} from "./_node-chunks/chunk-2LU3AW27.js";
|
|
28
28
|
|
|
29
29
|
// ../../../node_modules/picocolors/picocolors.js
|
|
30
30
|
var require_picocolors = __commonJS({
|
|
@@ -550,10 +550,10 @@ function encode(decoded) {
|
|
|
550
550
|
return writer.flush();
|
|
551
551
|
}
|
|
552
552
|
|
|
553
|
-
// ../../../node_modules/magic-string/dist/
|
|
554
|
-
var BitSet = class
|
|
553
|
+
// ../../../node_modules/magic-string/dist/index.mjs
|
|
554
|
+
var BitSet = class BitSet2 {
|
|
555
555
|
constructor(arg) {
|
|
556
|
-
this.bits = arg instanceof
|
|
556
|
+
this.bits = arg instanceof BitSet2 ? arg.bits.slice() : [];
|
|
557
557
|
}
|
|
558
558
|
add(n2) {
|
|
559
559
|
this.bits[n2 >> 5] |= 1 << (n2 & 31);
|
|
@@ -561,7 +561,7 @@ var BitSet = class _BitSet {
|
|
|
561
561
|
has(n2) {
|
|
562
562
|
return !!(this.bits[n2 >> 5] & 1 << (n2 & 31));
|
|
563
563
|
}
|
|
564
|
-
}, Chunk = class
|
|
564
|
+
}, Chunk = class Chunk2 {
|
|
565
565
|
constructor(start2, end, content) {
|
|
566
566
|
this.start = start2, this.end = end, this.original = content, this.intro = "", this.outro = "", this.content = content, this.storeName = !1, this.edited = !1, this.previous = null, this.next = null;
|
|
567
567
|
}
|
|
@@ -572,19 +572,21 @@ var BitSet = class _BitSet {
|
|
|
572
572
|
this.intro = this.intro + content;
|
|
573
573
|
}
|
|
574
574
|
clone() {
|
|
575
|
-
let chunk = new
|
|
575
|
+
let chunk = new Chunk2(this.start, this.end, this.original);
|
|
576
576
|
return chunk.intro = this.intro, chunk.outro = this.outro, chunk.content = this.content, chunk.storeName = this.storeName, chunk.edited = this.edited, chunk;
|
|
577
577
|
}
|
|
578
578
|
contains(index) {
|
|
579
579
|
return this.start < index && index < this.end;
|
|
580
580
|
}
|
|
581
581
|
eachNext(fn) {
|
|
582
|
-
|
|
582
|
+
fn(this);
|
|
583
|
+
let chunk = this.next;
|
|
583
584
|
for (; chunk; )
|
|
584
585
|
fn(chunk), chunk = chunk.next;
|
|
585
586
|
}
|
|
586
587
|
eachPrevious(fn) {
|
|
587
|
-
|
|
588
|
+
fn(this);
|
|
589
|
+
let chunk = this.previous;
|
|
588
590
|
for (; chunk; )
|
|
589
591
|
fn(chunk), chunk = chunk.previous;
|
|
590
592
|
}
|
|
@@ -603,7 +605,7 @@ var BitSet = class _BitSet {
|
|
|
603
605
|
split(index) {
|
|
604
606
|
let sliceIndex = index - this.start, originalBefore = this.original.slice(0, sliceIndex), originalAfter = this.original.slice(sliceIndex);
|
|
605
607
|
this.original = originalBefore;
|
|
606
|
-
let newChunk = new
|
|
608
|
+
let newChunk = new Chunk2(index, this.end, originalAfter);
|
|
607
609
|
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;
|
|
608
610
|
}
|
|
609
611
|
toString() {
|
|
@@ -613,23 +615,21 @@ var BitSet = class _BitSet {
|
|
|
613
615
|
if (this.outro = this.outro.replace(rx, ""), this.outro.length) return !0;
|
|
614
616
|
let trimmed = this.content.replace(rx, "");
|
|
615
617
|
if (trimmed.length)
|
|
616
|
-
return trimmed !== this.content && (this.split(this.start + trimmed.length).edit("", void 0, !0)
|
|
618
|
+
return trimmed !== this.content && (this.edited ? this.edit(trimmed, this.storeName, !0) : this.split(this.start + trimmed.length).edit("", void 0, !0)), !0;
|
|
617
619
|
if (this.edit("", void 0, !0), this.intro = this.intro.replace(rx, ""), this.intro.length) return !0;
|
|
618
620
|
}
|
|
619
621
|
trimStart(rx) {
|
|
620
622
|
if (this.intro = this.intro.replace(rx, ""), this.intro.length) return !0;
|
|
621
623
|
let trimmed = this.content.replace(rx, "");
|
|
622
|
-
if (trimmed.length)
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
this.edited && newChunk.edit(trimmed, this.storeName, !0), this.edit("", void 0, !0);
|
|
626
|
-
}
|
|
627
|
-
return !0;
|
|
628
|
-
} else if (this.edit("", void 0, !0), this.outro = this.outro.replace(rx, ""), this.outro.length) return !0;
|
|
624
|
+
if (trimmed.length)
|
|
625
|
+
return trimmed !== this.content && (this.edited ? this.edit(trimmed, this.storeName, !0) : (this.split(this.end - trimmed.length), this.edit("", void 0, !0))), !0;
|
|
626
|
+
if (this.edit("", void 0, !0), this.outro = this.outro.replace(rx, ""), this.outro.length) return !0;
|
|
629
627
|
}
|
|
630
628
|
};
|
|
631
629
|
function getBtoa() {
|
|
632
|
-
|
|
630
|
+
if (typeof globalThis < "u" && typeof globalThis.btoa == "function") return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
|
|
631
|
+
let buffer = globalThis.Buffer;
|
|
632
|
+
return buffer ? (str) => buffer.from(str, "utf-8").toString("base64") : () => {
|
|
633
633
|
throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
|
|
634
634
|
};
|
|
635
635
|
}
|
|
@@ -637,25 +637,37 @@ var btoa = getBtoa(), SourceMap = class {
|
|
|
637
637
|
constructor(properties) {
|
|
638
638
|
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);
|
|
639
639
|
}
|
|
640
|
+
/**
|
|
641
|
+
* Returns the equivalent of `JSON.stringify(map)`
|
|
642
|
+
*/
|
|
640
643
|
toString() {
|
|
641
644
|
return JSON.stringify(this);
|
|
642
645
|
}
|
|
646
|
+
/**
|
|
647
|
+
* Returns a DataURI containing the sourcemap. Useful for doing this sort of thing:
|
|
648
|
+
* `generateMap(options?: SourceMapOptions): SourceMap;`
|
|
649
|
+
*/
|
|
643
650
|
toUrl() {
|
|
644
|
-
return
|
|
651
|
+
return `data:application/json;charset=utf-8;base64,${btoa(this.toString())}`;
|
|
645
652
|
}
|
|
646
653
|
};
|
|
647
|
-
function
|
|
648
|
-
let
|
|
649
|
-
`),
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
654
|
+
function getLocator(source) {
|
|
655
|
+
let originalLines = source.split(`
|
|
656
|
+
`), lineOffsets = [];
|
|
657
|
+
for (let i = 0, pos = 0; i < originalLines.length; i++)
|
|
658
|
+
lineOffsets.push(pos), pos += originalLines[i].length + 1;
|
|
659
|
+
return function(index) {
|
|
660
|
+
let i = 0, j = lineOffsets.length;
|
|
661
|
+
for (; i < j; ) {
|
|
662
|
+
let m = i + j >> 1;
|
|
663
|
+
index < lineOffsets[m] ? j = m : i = m + 1;
|
|
664
|
+
}
|
|
665
|
+
let line = i - 1;
|
|
666
|
+
return {
|
|
667
|
+
line,
|
|
668
|
+
column: index - lineOffsets[line]
|
|
669
|
+
};
|
|
670
|
+
};
|
|
659
671
|
}
|
|
660
672
|
function getRelativePath(from, to) {
|
|
661
673
|
let fromParts = from.split(/[/\\]/), toParts = to.split(/[/\\]/);
|
|
@@ -667,25 +679,21 @@ function getRelativePath(from, to) {
|
|
|
667
679
|
}
|
|
668
680
|
return fromParts.concat(toParts).join("/");
|
|
669
681
|
}
|
|
682
|
+
function guessIndent(code) {
|
|
683
|
+
let lines = code.split(`
|
|
684
|
+
`), tabbed = lines.filter((line) => /^\t+/.test(line)), spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
685
|
+
if (tabbed.length === 0 && spaced.length === 0) return null;
|
|
686
|
+
if (tabbed.length >= spaced.length) return " ";
|
|
687
|
+
let min = spaced.reduce((previous, current) => {
|
|
688
|
+
let numSpaces = /^ +/.exec(current)[0].length;
|
|
689
|
+
return Math.min(numSpaces, previous);
|
|
690
|
+
}, 1 / 0);
|
|
691
|
+
return " ".repeat(min);
|
|
692
|
+
}
|
|
670
693
|
var toString = Object.prototype.toString;
|
|
671
694
|
function isObject(thing) {
|
|
672
695
|
return toString.call(thing) === "[object Object]";
|
|
673
696
|
}
|
|
674
|
-
function getLocator(source) {
|
|
675
|
-
let originalLines = source.split(`
|
|
676
|
-
`), lineOffsets = [];
|
|
677
|
-
for (let i = 0, pos = 0; i < originalLines.length; i++)
|
|
678
|
-
lineOffsets.push(pos), pos += originalLines[i].length + 1;
|
|
679
|
-
return function(index) {
|
|
680
|
-
let i = 0, j = lineOffsets.length;
|
|
681
|
-
for (; i < j; ) {
|
|
682
|
-
let m = i + j >> 1;
|
|
683
|
-
index < lineOffsets[m] ? j = m : i = m + 1;
|
|
684
|
-
}
|
|
685
|
-
let line = i - 1, column = index - lineOffsets[line];
|
|
686
|
-
return { line, column };
|
|
687
|
-
};
|
|
688
|
-
}
|
|
689
697
|
var wordRegex = /\w/, Mappings = class {
|
|
690
698
|
constructor(hires) {
|
|
691
699
|
this.hires = hires, this.generatedCodeLine = 0, this.generatedCodeColumn = 0, this.raw = [], this.rawSegments = this.raw[this.generatedCodeLine] = [], this.pending = null;
|
|
@@ -695,11 +703,21 @@ var wordRegex = /\w/, Mappings = class {
|
|
|
695
703
|
let contentLengthMinusOne = content.length - 1, contentLineEnd = content.indexOf(`
|
|
696
704
|
`, 0), previousContentLineEnd = -1;
|
|
697
705
|
for (; contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd; ) {
|
|
698
|
-
let segment2 = [
|
|
706
|
+
let segment2 = [
|
|
707
|
+
this.generatedCodeColumn,
|
|
708
|
+
sourceIndex,
|
|
709
|
+
loc.line,
|
|
710
|
+
loc.column
|
|
711
|
+
];
|
|
699
712
|
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(`
|
|
700
713
|
`, contentLineEnd + 1);
|
|
701
714
|
}
|
|
702
|
-
let segment = [
|
|
715
|
+
let segment = [
|
|
716
|
+
this.generatedCodeColumn,
|
|
717
|
+
sourceIndex,
|
|
718
|
+
loc.line,
|
|
719
|
+
loc.column
|
|
720
|
+
];
|
|
703
721
|
nameIndex >= 0 && segment.push(nameIndex), this.rawSegments.push(segment), this.advance(content.slice(previousContentLineEnd + 1));
|
|
704
722
|
} else this.pending && (this.rawSegments.push(this.pending), this.advance(content));
|
|
705
723
|
this.pending = null;
|
|
@@ -712,7 +730,12 @@ var wordRegex = /\w/, Mappings = class {
|
|
|
712
730
|
loc.line += 1, loc.column = 0, this.generatedCodeLine += 1, this.raw[this.generatedCodeLine] = this.rawSegments = [], this.generatedCodeColumn = 0, first = !0, charInHiresBoundary = !1;
|
|
713
731
|
else {
|
|
714
732
|
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
715
|
-
let segment = [
|
|
733
|
+
let segment = [
|
|
734
|
+
this.generatedCodeColumn,
|
|
735
|
+
sourceIndex,
|
|
736
|
+
loc.line,
|
|
737
|
+
loc.column
|
|
738
|
+
];
|
|
716
739
|
this.hires === "boundary" ? wordRegex.test(original[originalCharIndex]) ? charInHiresBoundary || (this.rawSegments.push(segment), charInHiresBoundary = !0) : (this.rawSegments.push(segment), charInHiresBoundary = !1) : this.rawSegments.push(segment);
|
|
717
740
|
}
|
|
718
741
|
loc.column += 1, this.generatedCodeColumn += 1, first = !1;
|
|
@@ -733,87 +756,156 @@ var wordRegex = /\w/, Mappings = class {
|
|
|
733
756
|
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
734
757
|
}
|
|
735
758
|
}, n = `
|
|
736
|
-
`, warned = {
|
|
759
|
+
`, NEWLINE_CHAR = 10, CR_CHAR = 13, warned = {
|
|
737
760
|
insertLeft: !1,
|
|
738
761
|
insertRight: !1,
|
|
739
762
|
storeName: !1
|
|
740
|
-
}, MagicString = class
|
|
763
|
+
}, MagicString = class MagicString2 {
|
|
741
764
|
constructor(string, options = {}) {
|
|
742
765
|
let chunk = new Chunk(0, string.length, string);
|
|
743
766
|
Object.defineProperties(this, {
|
|
744
|
-
original: {
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
767
|
+
original: {
|
|
768
|
+
writable: !0,
|
|
769
|
+
value: string
|
|
770
|
+
},
|
|
771
|
+
outro: {
|
|
772
|
+
writable: !0,
|
|
773
|
+
value: ""
|
|
774
|
+
},
|
|
775
|
+
intro: {
|
|
776
|
+
writable: !0,
|
|
777
|
+
value: ""
|
|
778
|
+
},
|
|
779
|
+
firstChunk: {
|
|
780
|
+
writable: !0,
|
|
781
|
+
value: chunk
|
|
782
|
+
},
|
|
783
|
+
lastChunk: {
|
|
784
|
+
writable: !0,
|
|
785
|
+
value: chunk
|
|
786
|
+
},
|
|
787
|
+
lastSearchedChunk: {
|
|
788
|
+
writable: !0,
|
|
789
|
+
value: chunk
|
|
790
|
+
},
|
|
791
|
+
byStart: {
|
|
792
|
+
writable: !0,
|
|
793
|
+
value: {}
|
|
794
|
+
},
|
|
795
|
+
byEnd: {
|
|
796
|
+
writable: !0,
|
|
797
|
+
value: {}
|
|
798
|
+
},
|
|
799
|
+
filename: {
|
|
800
|
+
writable: !0,
|
|
801
|
+
value: options.filename
|
|
802
|
+
},
|
|
803
|
+
indentExclusionRanges: {
|
|
804
|
+
writable: !0,
|
|
805
|
+
value: options.indentExclusionRanges
|
|
806
|
+
},
|
|
807
|
+
sourcemapLocations: {
|
|
808
|
+
writable: !0,
|
|
809
|
+
value: new BitSet()
|
|
810
|
+
},
|
|
811
|
+
storedNames: {
|
|
812
|
+
writable: !0,
|
|
813
|
+
value: {}
|
|
814
|
+
},
|
|
815
|
+
indentStr: {
|
|
816
|
+
writable: !0,
|
|
817
|
+
value: void 0
|
|
818
|
+
},
|
|
819
|
+
ignoreList: {
|
|
820
|
+
writable: !0,
|
|
821
|
+
value: options.ignoreList
|
|
822
|
+
},
|
|
823
|
+
offset: {
|
|
824
|
+
writable: !0,
|
|
825
|
+
value: options.offset || 0
|
|
826
|
+
}
|
|
827
|
+
}), this.byStart = /* @__PURE__ */ new Map([[0, chunk]]), this.byEnd = /* @__PURE__ */ new Map([[string.length, chunk]]);
|
|
760
828
|
}
|
|
829
|
+
/**
|
|
830
|
+
* Adds the specified character index (with respect to the original string) to sourcemap mappings, if `hires` is false.
|
|
831
|
+
*/
|
|
761
832
|
addSourcemapLocation(char) {
|
|
762
833
|
this.sourcemapLocations.add(char);
|
|
763
834
|
}
|
|
835
|
+
/**
|
|
836
|
+
* Appends the specified content to the end of the string.
|
|
837
|
+
*/
|
|
764
838
|
append(content) {
|
|
765
839
|
if (typeof content != "string") throw new TypeError("outro content must be a string");
|
|
766
840
|
return this.outro += content, this;
|
|
767
841
|
}
|
|
842
|
+
/**
|
|
843
|
+
* Appends the specified content at the index in the original string.
|
|
844
|
+
* If a range *ending* with index is subsequently moved, the insert will be moved with it.
|
|
845
|
+
* See also `s.prependLeft(...)`.
|
|
846
|
+
*/
|
|
768
847
|
appendLeft(index, content) {
|
|
769
848
|
if (index = index + this.offset, typeof content != "string") throw new TypeError("inserted content must be a string");
|
|
770
849
|
this._split(index);
|
|
771
|
-
let chunk = this.byEnd
|
|
850
|
+
let chunk = this.byEnd.get(index);
|
|
772
851
|
return chunk ? chunk.appendLeft(content) : this.intro += content, this;
|
|
773
852
|
}
|
|
853
|
+
/**
|
|
854
|
+
* Appends the specified content at the index in the original string.
|
|
855
|
+
* If a range *starting* with index is subsequently moved, the insert will be moved with it.
|
|
856
|
+
* See also `s.prependRight(...)`.
|
|
857
|
+
*/
|
|
774
858
|
appendRight(index, content) {
|
|
775
859
|
if (index = index + this.offset, typeof content != "string") throw new TypeError("inserted content must be a string");
|
|
776
860
|
this._split(index);
|
|
777
|
-
let chunk = this.byStart
|
|
861
|
+
let chunk = this.byStart.get(index);
|
|
778
862
|
return chunk ? chunk.appendRight(content) : this.outro += content, this;
|
|
779
863
|
}
|
|
864
|
+
/**
|
|
865
|
+
* Does what you'd expect.
|
|
866
|
+
*/
|
|
780
867
|
clone() {
|
|
781
|
-
let cloned = new
|
|
868
|
+
let cloned = new MagicString2(this.original, {
|
|
869
|
+
filename: this.filename,
|
|
870
|
+
offset: this.offset
|
|
871
|
+
}), originalChunk = this.firstChunk, clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
|
782
872
|
for (; originalChunk; ) {
|
|
783
|
-
cloned.byStart
|
|
873
|
+
cloned.byStart.set(clonedChunk.start, clonedChunk), cloned.byEnd.set(clonedChunk.end, clonedChunk);
|
|
784
874
|
let nextOriginalChunk = originalChunk.next, nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
785
875
|
nextClonedChunk && (clonedChunk.next = nextClonedChunk, nextClonedChunk.previous = clonedChunk, clonedChunk = nextClonedChunk), originalChunk = nextOriginalChunk;
|
|
786
876
|
}
|
|
787
877
|
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;
|
|
788
878
|
}
|
|
879
|
+
/**
|
|
880
|
+
* Generates a sourcemap object with raw mappings in array form, rather than encoded as a string.
|
|
881
|
+
* Useful if you need to manipulate the sourcemap further, but most of the time you will use `generateMap` instead.
|
|
882
|
+
*/
|
|
789
883
|
generateDecodedMap(options) {
|
|
790
884
|
options = options || {};
|
|
791
885
|
let sourceIndex = 0, names = Object.keys(this.storedNames), mappings = new Mappings(options.hires), locate = getLocator(this.original);
|
|
792
886
|
return this.intro && mappings.advance(this.intro), this.firstChunk.eachNext((chunk) => {
|
|
793
887
|
let loc = locate(chunk.start);
|
|
794
|
-
chunk.intro.length && mappings.advance(chunk.intro), chunk.edited ? mappings.addEdit(
|
|
795
|
-
sourceIndex,
|
|
796
|
-
chunk.content,
|
|
797
|
-
loc,
|
|
798
|
-
chunk.storeName ? names.indexOf(chunk.original) : -1
|
|
799
|
-
) : mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations), chunk.outro.length && mappings.advance(chunk.outro);
|
|
888
|
+
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);
|
|
800
889
|
}), this.outro && mappings.advance(this.outro), {
|
|
801
890
|
file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
|
|
802
|
-
sources: [
|
|
803
|
-
options.source ? getRelativePath(options.file || "", options.source) : options.file || ""
|
|
804
|
-
],
|
|
891
|
+
sources: [options.source ? getRelativePath(options.file || "", options.source) : options.file || ""],
|
|
805
892
|
sourcesContent: options.includeContent ? [this.original] : void 0,
|
|
806
893
|
names,
|
|
807
894
|
mappings: mappings.raw,
|
|
808
895
|
x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
|
|
809
896
|
};
|
|
810
897
|
}
|
|
898
|
+
/**
|
|
899
|
+
* Generates a version 3 sourcemap.
|
|
900
|
+
*/
|
|
811
901
|
generateMap(options) {
|
|
812
902
|
return new SourceMap(this.generateDecodedMap(options));
|
|
813
903
|
}
|
|
904
|
+
/** @internal */
|
|
814
905
|
_ensureindentStr() {
|
|
815
906
|
this.indentStr === void 0 && (this.indentStr = guessIndent(this.original));
|
|
816
907
|
}
|
|
908
|
+
/** @internal */
|
|
817
909
|
_getRawIndentString() {
|
|
818
910
|
return this._ensureindentStr(), this.indentStr;
|
|
819
911
|
}
|
|
@@ -823,59 +915,97 @@ var wordRegex = /\w/, Mappings = class {
|
|
|
823
915
|
indent(indentStr, options) {
|
|
824
916
|
let pattern = /^[^\r\n]/gm;
|
|
825
917
|
if (isObject(indentStr) && (options = indentStr, indentStr = void 0), indentStr === void 0 && (this._ensureindentStr(), indentStr = this.indentStr || " "), indentStr === "") return this;
|
|
918
|
+
let resolvedIndentStr = indentStr;
|
|
826
919
|
options = options || {};
|
|
827
920
|
let isExcluded = {};
|
|
828
921
|
options.exclude && (typeof options.exclude[0] == "number" ? [options.exclude] : options.exclude).forEach((exclusion) => {
|
|
829
|
-
for (let i = exclusion[0]; i < exclusion[1]; i += 1)
|
|
830
|
-
isExcluded[i] = !0;
|
|
922
|
+
for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded[i] = !0;
|
|
831
923
|
});
|
|
832
|
-
let shouldIndentNextCharacter = options.indentStart !== !1, replacer = (match) => shouldIndentNextCharacter ? `${
|
|
924
|
+
let shouldIndentNextCharacter = options.indentStart !== !1, replacer = (match) => shouldIndentNextCharacter ? `${resolvedIndentStr}${match}` : (shouldIndentNextCharacter = !0, match);
|
|
833
925
|
this.intro = this.intro.replace(pattern, replacer);
|
|
834
|
-
let charIndex = 0, chunk = this.firstChunk
|
|
926
|
+
let charIndex = 0, chunk = this.firstChunk, indentAt = (index) => {
|
|
927
|
+
shouldIndentNextCharacter = !1, index === chunk.start || (this._splitChunk(chunk, index), chunk = chunk.next), chunk.prependRight(resolvedIndentStr);
|
|
928
|
+
};
|
|
835
929
|
for (; chunk; ) {
|
|
836
930
|
let end = chunk.end;
|
|
837
931
|
if (chunk.edited)
|
|
838
932
|
isExcluded[charIndex] || (chunk.content = chunk.content.replace(pattern, replacer), chunk.content.length && (shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === `
|
|
839
933
|
`));
|
|
840
|
-
else
|
|
934
|
+
else if (options.exclude)
|
|
841
935
|
for (charIndex = chunk.start; charIndex < end; ) {
|
|
842
936
|
if (!isExcluded[charIndex]) {
|
|
843
|
-
let char = this.original
|
|
844
|
-
char ===
|
|
845
|
-
` ? shouldIndentNextCharacter = !0 : char !== "\r" && shouldIndentNextCharacter && (shouldIndentNextCharacter = !1, charIndex === chunk.start || (this._splitChunk(chunk, charIndex), chunk = chunk.next), chunk.prependRight(indentStr));
|
|
937
|
+
let char = this.original.charCodeAt(charIndex);
|
|
938
|
+
char === NEWLINE_CHAR ? shouldIndentNextCharacter = !0 : char !== CR_CHAR && shouldIndentNextCharacter && indentAt(charIndex);
|
|
846
939
|
}
|
|
847
940
|
charIndex += 1;
|
|
848
941
|
}
|
|
942
|
+
else
|
|
943
|
+
for (charIndex = chunk.start; charIndex < end; ) {
|
|
944
|
+
if (!shouldIndentNextCharacter) {
|
|
945
|
+
let nextLine = this.original.indexOf(n, charIndex);
|
|
946
|
+
if (nextLine === -1 || nextLine >= end) break;
|
|
947
|
+
shouldIndentNextCharacter = !0, charIndex = nextLine + 1;
|
|
948
|
+
continue;
|
|
949
|
+
}
|
|
950
|
+
let char = this.original.charCodeAt(charIndex);
|
|
951
|
+
if (char === NEWLINE_CHAR || char === CR_CHAR) {
|
|
952
|
+
charIndex += 1;
|
|
953
|
+
continue;
|
|
954
|
+
}
|
|
955
|
+
indentAt(charIndex), charIndex += 1;
|
|
956
|
+
}
|
|
849
957
|
charIndex = chunk.end, chunk = chunk.next;
|
|
850
958
|
}
|
|
851
959
|
return this.outro = this.outro.replace(pattern, replacer), this;
|
|
852
960
|
}
|
|
961
|
+
/** @internal */
|
|
853
962
|
insert() {
|
|
854
|
-
throw new Error(
|
|
855
|
-
"magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)"
|
|
856
|
-
);
|
|
963
|
+
throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)");
|
|
857
964
|
}
|
|
965
|
+
/** @internal */
|
|
858
966
|
insertLeft(index, content) {
|
|
859
|
-
return warned.insertLeft || (console.warn(
|
|
860
|
-
"magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"
|
|
861
|
-
), warned.insertLeft = !0), this.appendLeft(index, content);
|
|
967
|
+
return warned.insertLeft || (console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"), warned.insertLeft = !0), this.appendLeft(index, content);
|
|
862
968
|
}
|
|
969
|
+
/** @internal */
|
|
863
970
|
insertRight(index, content) {
|
|
864
|
-
return warned.insertRight || (console.warn(
|
|
865
|
-
"magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"
|
|
866
|
-
), warned.insertRight = !0), this.prependRight(index, content);
|
|
971
|
+
return warned.insertRight || (console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"), warned.insertRight = !0), this.prependRight(index, content);
|
|
867
972
|
}
|
|
973
|
+
/**
|
|
974
|
+
* Moves the characters from `start` and `end` to `index`.
|
|
975
|
+
*/
|
|
868
976
|
move(start2, end, index) {
|
|
869
|
-
if (start2 = start2 + this.offset, end = end + this.offset, index = index + this.offset,
|
|
977
|
+
if (start2 = start2 + this.offset, end = end + this.offset, index = index + this.offset, start2 === end) return this;
|
|
978
|
+
if (index >= start2 && index <= end) throw new Error("Cannot move a selection inside itself");
|
|
870
979
|
this._split(start2), this._split(end), this._split(index);
|
|
871
|
-
let first = this.byStart
|
|
980
|
+
let first = this.byStart.get(start2), last = this.byEnd.get(end), oldLeft = first.previous, oldRight = last.next, newRight = this.byStart.get(index);
|
|
872
981
|
if (!newRight && last === this.lastChunk) return this;
|
|
873
982
|
let newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
874
983
|
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;
|
|
875
984
|
}
|
|
985
|
+
/**
|
|
986
|
+
* Replaces the characters from `start` to `end` with `content`, along with the appended/prepended content in
|
|
987
|
+
* that range. The same restrictions as `s.remove()` apply.
|
|
988
|
+
*
|
|
989
|
+
* The fourth argument is optional. It can have a storeName property - if true, the original name will be stored
|
|
990
|
+
* for later inclusion in a sourcemap's names array - and a contentOnly property which determines whether only
|
|
991
|
+
* the content is overwritten, or anything that was appended/prepended to the range as well.
|
|
992
|
+
*
|
|
993
|
+
* It may be preferred to use `s.update(...)` instead if you wish to avoid overwriting the appended/prepended content.
|
|
994
|
+
*/
|
|
876
995
|
overwrite(start2, end, content, options) {
|
|
877
|
-
|
|
996
|
+
let optionObject = typeof options == "object" && options ? options : {};
|
|
997
|
+
return this.update(start2, end, content, {
|
|
998
|
+
...optionObject,
|
|
999
|
+
overwrite: !optionObject.contentOnly
|
|
1000
|
+
});
|
|
878
1001
|
}
|
|
1002
|
+
/**
|
|
1003
|
+
* Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply.
|
|
1004
|
+
*
|
|
1005
|
+
* The fourth argument is optional. It can have a storeName property - if true, the original name will be stored
|
|
1006
|
+
* for later inclusion in a sourcemap's names array - and an overwrite property which determines whether only
|
|
1007
|
+
* the content is overwritten, or anything that was appended/prepended to the range as well.
|
|
1008
|
+
*/
|
|
879
1009
|
update(start2, end, content, options) {
|
|
880
1010
|
if (start2 = start2 + this.offset, end = end + this.offset, typeof content != "string") throw new TypeError("replacement content must be a string");
|
|
881
1011
|
if (this.original.length !== 0) {
|
|
@@ -883,14 +1013,9 @@ var wordRegex = /\w/, Mappings = class {
|
|
|
883
1013
|
for (; end < 0; ) end += this.original.length;
|
|
884
1014
|
}
|
|
885
1015
|
if (end > this.original.length) throw new Error("end is out of bounds");
|
|
886
|
-
if (start2 === end)
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
);
|
|
890
|
-
this._split(start2), this._split(end), options === !0 && (warned.storeName || (console.warn(
|
|
891
|
-
"The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"
|
|
892
|
-
), warned.storeName = !0), options = { storeName: !0 });
|
|
893
|
-
let storeName = options !== void 0 ? options.storeName : !1, overwrite = options !== void 0 ? options.overwrite : !1;
|
|
1016
|
+
if (start2 === end) throw new Error("Cannot overwrite a zero-length range \u2013 use appendLeft or prependRight instead");
|
|
1017
|
+
this._split(start2), 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 });
|
|
1018
|
+
let optionObject = typeof options == "object" && options ? options : {}, storeName = optionObject.storeName || !1, overwrite = optionObject.overwrite || !1;
|
|
894
1019
|
if (storeName) {
|
|
895
1020
|
let original = this.original.slice(start2, end);
|
|
896
1021
|
Object.defineProperty(this.storedNames, original, {
|
|
@@ -899,12 +1024,11 @@ var wordRegex = /\w/, Mappings = class {
|
|
|
899
1024
|
enumerable: !0
|
|
900
1025
|
});
|
|
901
1026
|
}
|
|
902
|
-
let first = this.byStart
|
|
1027
|
+
let first = this.byStart.get(start2), last = this.byEnd.get(end);
|
|
903
1028
|
if (first) {
|
|
904
1029
|
let chunk = first;
|
|
905
1030
|
for (; chunk !== last; ) {
|
|
906
|
-
if (chunk.next !== this.byStart
|
|
907
|
-
throw new Error("Cannot overwrite across a split point");
|
|
1031
|
+
if (chunk.next !== this.byStart.get(chunk.end)) throw new Error("Cannot overwrite across a split point");
|
|
908
1032
|
chunk = chunk.next, chunk.edit("", !1);
|
|
909
1033
|
}
|
|
910
1034
|
first.edit(content, storeName, !overwrite);
|
|
@@ -914,22 +1038,35 @@ var wordRegex = /\w/, Mappings = class {
|
|
|
914
1038
|
}
|
|
915
1039
|
return this;
|
|
916
1040
|
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Prepends the string with the specified content.
|
|
1043
|
+
*/
|
|
917
1044
|
prepend(content) {
|
|
918
1045
|
if (typeof content != "string") throw new TypeError("outro content must be a string");
|
|
919
1046
|
return this.intro = content + this.intro, this;
|
|
920
1047
|
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
|
|
1050
|
+
*/
|
|
921
1051
|
prependLeft(index, content) {
|
|
922
1052
|
if (index = index + this.offset, typeof content != "string") throw new TypeError("inserted content must be a string");
|
|
923
1053
|
this._split(index);
|
|
924
|
-
let chunk = this.byEnd
|
|
1054
|
+
let chunk = this.byEnd.get(index);
|
|
925
1055
|
return chunk ? chunk.prependLeft(content) : this.intro = content + this.intro, this;
|
|
926
1056
|
}
|
|
1057
|
+
/**
|
|
1058
|
+
* Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
|
|
1059
|
+
*/
|
|
927
1060
|
prependRight(index, content) {
|
|
928
1061
|
if (index = index + this.offset, typeof content != "string") throw new TypeError("inserted content must be a string");
|
|
929
1062
|
this._split(index);
|
|
930
|
-
let chunk = this.byStart
|
|
1063
|
+
let chunk = this.byStart.get(index);
|
|
931
1064
|
return chunk ? chunk.prependRight(content) : this.outro = content + this.outro, this;
|
|
932
1065
|
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Removes the characters from `start` to `end` (of the original string, **not** the generated string).
|
|
1068
|
+
* Removing the same content twice, or making removals that partially overlap, will cause an error.
|
|
1069
|
+
*/
|
|
933
1070
|
remove(start2, end) {
|
|
934
1071
|
if (start2 = start2 + this.offset, end = end + this.offset, this.original.length !== 0) {
|
|
935
1072
|
for (; start2 < 0; ) start2 += this.original.length;
|
|
@@ -939,11 +1076,14 @@ var wordRegex = /\w/, Mappings = class {
|
|
|
939
1076
|
if (start2 < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
940
1077
|
if (start2 > end) throw new Error("end must be greater than start");
|
|
941
1078
|
this._split(start2), this._split(end);
|
|
942
|
-
let chunk = this.byStart
|
|
1079
|
+
let chunk = this.byStart.get(start2);
|
|
943
1080
|
for (; chunk; )
|
|
944
|
-
chunk.intro = "", chunk.outro = "", chunk.edit(""), chunk = end > chunk.end ? this.byStart
|
|
1081
|
+
chunk.intro = "", chunk.outro = "", chunk.edit(""), chunk = end > chunk.end ? this.byStart.get(chunk.end) : null;
|
|
945
1082
|
return this;
|
|
946
1083
|
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
|
|
1086
|
+
*/
|
|
947
1087
|
reset(start2, end) {
|
|
948
1088
|
if (start2 = start2 + this.offset, end = end + this.offset, this.original.length !== 0) {
|
|
949
1089
|
for (; start2 < 0; ) start2 += this.original.length;
|
|
@@ -953,26 +1093,27 @@ var wordRegex = /\w/, Mappings = class {
|
|
|
953
1093
|
if (start2 < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
954
1094
|
if (start2 > end) throw new Error("end must be greater than start");
|
|
955
1095
|
this._split(start2), this._split(end);
|
|
956
|
-
let chunk = this.byStart
|
|
1096
|
+
let chunk = this.byStart.get(start2);
|
|
957
1097
|
for (; chunk; )
|
|
958
|
-
chunk.reset(), chunk = end > chunk.end ? this.byStart
|
|
1098
|
+
chunk.reset(), chunk = end > chunk.end ? this.byStart.get(chunk.end) : null;
|
|
959
1099
|
return this;
|
|
960
1100
|
}
|
|
961
1101
|
lastChar() {
|
|
962
1102
|
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
963
1103
|
let chunk = this.lastChunk;
|
|
964
|
-
|
|
1104
|
+
for (; chunk; ) {
|
|
965
1105
|
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
966
1106
|
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
967
1107
|
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
968
|
-
|
|
1108
|
+
chunk = chunk.previous;
|
|
1109
|
+
}
|
|
969
1110
|
return this.intro.length ? this.intro[this.intro.length - 1] : "";
|
|
970
1111
|
}
|
|
971
1112
|
lastLine() {
|
|
972
1113
|
let lineIndex = this.outro.lastIndexOf(n);
|
|
973
1114
|
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
974
1115
|
let lineStr = this.outro, chunk = this.lastChunk;
|
|
975
|
-
|
|
1116
|
+
for (; chunk; ) {
|
|
976
1117
|
if (chunk.outro.length > 0) {
|
|
977
1118
|
if (lineIndex = chunk.outro.lastIndexOf(n), lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
978
1119
|
lineStr = chunk.outro + lineStr;
|
|
@@ -985,9 +1126,14 @@ var wordRegex = /\w/, Mappings = class {
|
|
|
985
1126
|
if (lineIndex = chunk.intro.lastIndexOf(n), lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
986
1127
|
lineStr = chunk.intro + lineStr;
|
|
987
1128
|
}
|
|
988
|
-
|
|
1129
|
+
chunk = chunk.previous;
|
|
1130
|
+
}
|
|
989
1131
|
return lineIndex = this.intro.lastIndexOf(n), lineIndex !== -1 ? this.intro.substr(lineIndex + 1) + lineStr : this.intro + lineStr;
|
|
990
1132
|
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Returns the content of the generated string that corresponds to the slice between `start` and `end` of the original string.
|
|
1135
|
+
* Throws error if the indices are for characters that were already removed.
|
|
1136
|
+
*/
|
|
991
1137
|
slice(start2 = 0, end = this.original.length - this.offset) {
|
|
992
1138
|
if (start2 = start2 + this.offset, end = end + this.offset, this.original.length !== 0) {
|
|
993
1139
|
for (; start2 < 0; ) start2 += this.original.length;
|
|
@@ -995,124 +1141,147 @@ var wordRegex = /\w/, Mappings = class {
|
|
|
995
1141
|
}
|
|
996
1142
|
let result = "", chunk = this.firstChunk;
|
|
997
1143
|
for (; chunk && (chunk.start > start2 || chunk.end <= start2); ) {
|
|
998
|
-
if (chunk.start < end && chunk.end >= end)
|
|
999
|
-
return result;
|
|
1144
|
+
if (chunk.start < end && chunk.end >= end) return result;
|
|
1000
1145
|
chunk = chunk.next;
|
|
1001
1146
|
}
|
|
1002
|
-
if (chunk && chunk.edited && chunk.start !== start2)
|
|
1003
|
-
throw new Error(`Cannot use replaced character ${start2} as slice start anchor.`);
|
|
1147
|
+
if (chunk && chunk.edited && chunk.start !== start2) throw new Error(`Cannot use replaced character ${start2} as slice start anchor.`);
|
|
1004
1148
|
let startChunk = chunk;
|
|
1005
1149
|
for (; chunk; ) {
|
|
1006
1150
|
chunk.intro && (startChunk !== chunk || chunk.start === start2) && (result += chunk.intro);
|
|
1007
1151
|
let containsEnd = chunk.start < end && chunk.end >= end;
|
|
1008
|
-
if (containsEnd && chunk.edited && chunk.end !== end)
|
|
1009
|
-
throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
1152
|
+
if (containsEnd && chunk.edited && chunk.end !== end) throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
1010
1153
|
let sliceStart = startChunk === chunk ? start2 - chunk.start : 0, sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
1011
|
-
if (result += chunk.content.slice(sliceStart, sliceEnd), chunk.outro && (!containsEnd || chunk.end === end) && (result += chunk.outro), containsEnd)
|
|
1012
|
-
break;
|
|
1154
|
+
if (result += chunk.content.slice(sliceStart, sliceEnd), chunk.outro && (!containsEnd || chunk.end === end) && (result += chunk.outro), containsEnd) break;
|
|
1013
1155
|
chunk = chunk.next;
|
|
1014
1156
|
}
|
|
1015
1157
|
return result;
|
|
1016
1158
|
}
|
|
1017
|
-
|
|
1159
|
+
/**
|
|
1160
|
+
* Returns a clone of `s`, with all content before the `start` and `end` characters of the original string removed.
|
|
1161
|
+
*/
|
|
1018
1162
|
snip(start2, end) {
|
|
1019
1163
|
let clone = this.clone();
|
|
1020
1164
|
return clone.remove(0, start2), clone.remove(end, clone.original.length), clone;
|
|
1021
1165
|
}
|
|
1166
|
+
/** @internal */
|
|
1022
1167
|
_split(index) {
|
|
1023
|
-
if (this.byStart
|
|
1168
|
+
if (this.byStart.get(index) || this.byEnd.get(index)) return;
|
|
1024
1169
|
let chunk = this.lastSearchedChunk, previousChunk = chunk, searchForward = index > chunk.end;
|
|
1025
1170
|
for (; chunk; ) {
|
|
1026
1171
|
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
1027
|
-
if (chunk = searchForward ? this.byStart
|
|
1172
|
+
if (chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start), chunk === previousChunk) return;
|
|
1028
1173
|
previousChunk = chunk;
|
|
1029
1174
|
}
|
|
1030
1175
|
}
|
|
1176
|
+
/** @internal */
|
|
1031
1177
|
_splitChunk(chunk, index) {
|
|
1032
1178
|
if (chunk.edited && chunk.content.length) {
|
|
1033
1179
|
let loc = getLocator(this.original)(index);
|
|
1034
|
-
throw new Error(
|
|
1035
|
-
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} \u2013 "${chunk.original}")`
|
|
1036
|
-
);
|
|
1180
|
+
throw new Error(`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} \u2013 "${chunk.original}")`);
|
|
1037
1181
|
}
|
|
1038
1182
|
let newChunk = chunk.split(index);
|
|
1039
|
-
return this.byEnd
|
|
1183
|
+
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;
|
|
1040
1184
|
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Returns the generated string.
|
|
1187
|
+
*/
|
|
1041
1188
|
toString() {
|
|
1042
1189
|
let str = this.intro, chunk = this.firstChunk;
|
|
1043
1190
|
for (; chunk; )
|
|
1044
1191
|
str += chunk.toString(), chunk = chunk.next;
|
|
1045
1192
|
return str + this.outro;
|
|
1046
1193
|
}
|
|
1194
|
+
/**
|
|
1195
|
+
* Returns true if the resulting source is empty (disregarding white space).
|
|
1196
|
+
*/
|
|
1047
1197
|
isEmpty() {
|
|
1048
1198
|
let chunk = this.firstChunk;
|
|
1049
|
-
|
|
1050
|
-
if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim())
|
|
1051
|
-
|
|
1052
|
-
|
|
1199
|
+
for (; chunk; ) {
|
|
1200
|
+
if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim()) return !1;
|
|
1201
|
+
chunk = chunk.next;
|
|
1202
|
+
}
|
|
1053
1203
|
return !0;
|
|
1054
1204
|
}
|
|
1055
1205
|
length() {
|
|
1056
1206
|
let chunk = this.firstChunk, length = 0;
|
|
1057
|
-
|
|
1058
|
-
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
1059
|
-
while (chunk = chunk.next);
|
|
1207
|
+
for (; chunk; )
|
|
1208
|
+
length += chunk.intro.length + chunk.content.length + chunk.outro.length, chunk = chunk.next;
|
|
1060
1209
|
return length;
|
|
1061
1210
|
}
|
|
1211
|
+
/**
|
|
1212
|
+
* Removes empty lines from the start and end.
|
|
1213
|
+
*/
|
|
1062
1214
|
trimLines() {
|
|
1063
1215
|
return this.trim("[\\r\\n]");
|
|
1064
1216
|
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start and end.
|
|
1219
|
+
*/
|
|
1065
1220
|
trim(charType) {
|
|
1066
1221
|
return this.trimStart(charType).trimEnd(charType);
|
|
1067
1222
|
}
|
|
1223
|
+
/** @internal */
|
|
1068
1224
|
trimEndAborted(charType) {
|
|
1069
|
-
let rx = new RegExp(
|
|
1225
|
+
let rx = new RegExp(`${charType || "\\s"}+$`);
|
|
1070
1226
|
if (this.outro = this.outro.replace(rx, ""), this.outro.length) return !0;
|
|
1071
1227
|
let chunk = this.lastChunk;
|
|
1072
1228
|
do {
|
|
1073
1229
|
let end = chunk.end, aborted = chunk.trimEnd(rx);
|
|
1074
|
-
if (chunk.end !== end && (this.lastChunk === chunk && (this.lastChunk = chunk.next), this.byEnd
|
|
1230
|
+
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;
|
|
1075
1231
|
chunk = chunk.previous;
|
|
1076
1232
|
} while (chunk);
|
|
1077
1233
|
return !1;
|
|
1078
1234
|
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
|
|
1237
|
+
*/
|
|
1079
1238
|
trimEnd(charType) {
|
|
1080
1239
|
return this.trimEndAborted(charType), this;
|
|
1081
1240
|
}
|
|
1241
|
+
/** @internal */
|
|
1082
1242
|
trimStartAborted(charType) {
|
|
1083
|
-
let rx = new RegExp(
|
|
1243
|
+
let rx = new RegExp(`^${charType || "\\s"}+`);
|
|
1084
1244
|
if (this.intro = this.intro.replace(rx, ""), this.intro.length) return !0;
|
|
1085
1245
|
let chunk = this.firstChunk;
|
|
1086
1246
|
do {
|
|
1087
1247
|
let end = chunk.end, aborted = chunk.trimStart(rx);
|
|
1088
|
-
if (chunk.end !== end && (chunk === this.lastChunk && (this.lastChunk = chunk.next), this.byEnd
|
|
1248
|
+
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;
|
|
1089
1249
|
chunk = chunk.next;
|
|
1090
1250
|
} while (chunk);
|
|
1091
1251
|
return !1;
|
|
1092
1252
|
}
|
|
1253
|
+
/**
|
|
1254
|
+
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
|
|
1255
|
+
*/
|
|
1093
1256
|
trimStart(charType) {
|
|
1094
1257
|
return this.trimStartAborted(charType), this;
|
|
1095
1258
|
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Indicates if the string has been changed.
|
|
1261
|
+
*/
|
|
1096
1262
|
hasChanged() {
|
|
1097
1263
|
return this.original !== this.toString();
|
|
1098
1264
|
}
|
|
1265
|
+
/** @internal */
|
|
1099
1266
|
_replaceRegexp(searchValue, replacement) {
|
|
1100
1267
|
function getReplacement(match, str) {
|
|
1101
|
-
return typeof replacement == "string" ? replacement.replace(/\$(\$|&|\d+)/g, (_, i) => i === "$" ? "$" : i === "&" ? match[0] : +i < match.length ? match[+i] : `$${i}`) : replacement(...match, match.index, str, match.groups);
|
|
1268
|
+
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);
|
|
1102
1269
|
}
|
|
1103
1270
|
function matchAll(re, str) {
|
|
1104
|
-
let
|
|
1105
|
-
for (;
|
|
1271
|
+
let matches = [];
|
|
1272
|
+
for (; ; ) {
|
|
1273
|
+
let match = re.exec(str);
|
|
1274
|
+
if (!match) break;
|
|
1106
1275
|
matches.push(match);
|
|
1276
|
+
}
|
|
1107
1277
|
return matches;
|
|
1108
1278
|
}
|
|
1109
|
-
if (searchValue.global)
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
});
|
|
1279
|
+
if (searchValue.global) matchAll(searchValue, this.original).forEach((match) => {
|
|
1280
|
+
if (match.index != null) {
|
|
1281
|
+
let replacement2 = getReplacement(match, this.original);
|
|
1282
|
+
replacement2 !== match[0] && this.overwrite(match.index, match.index + match[0].length, replacement2);
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1116
1285
|
else {
|
|
1117
1286
|
let match = this.original.match(searchValue);
|
|
1118
1287
|
if (match && match.index != null) {
|
|
@@ -1122,28 +1291,32 @@ var wordRegex = /\w/, Mappings = class {
|
|
|
1122
1291
|
}
|
|
1123
1292
|
return this;
|
|
1124
1293
|
}
|
|
1294
|
+
/** @internal */
|
|
1125
1295
|
_replaceString(string, replacement) {
|
|
1126
1296
|
let { original } = this, index = original.indexOf(string);
|
|
1127
1297
|
return index !== -1 && (typeof replacement == "function" && (replacement = replacement(string, index, original)), string !== replacement && this.overwrite(index, index + string.length, replacement)), this;
|
|
1128
1298
|
}
|
|
1299
|
+
/**
|
|
1300
|
+
* String replacement with RegExp or string.
|
|
1301
|
+
*/
|
|
1129
1302
|
replace(searchValue, replacement) {
|
|
1130
1303
|
return typeof searchValue == "string" ? this._replaceString(searchValue, replacement) : this._replaceRegexp(searchValue, replacement);
|
|
1131
1304
|
}
|
|
1305
|
+
/** @internal */
|
|
1132
1306
|
_replaceAllString(string, replacement) {
|
|
1133
1307
|
let { original } = this, stringLength = string.length;
|
|
1134
1308
|
for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
|
|
1135
|
-
let previous = original.slice(index, index + stringLength), _replacement = replacement;
|
|
1136
|
-
|
|
1309
|
+
let previous = original.slice(index, index + stringLength), _replacement = typeof replacement == "function" ? replacement(previous, index, original) : replacement;
|
|
1310
|
+
previous !== _replacement && this.overwrite(index, index + stringLength, _replacement);
|
|
1137
1311
|
}
|
|
1138
1312
|
return this;
|
|
1139
1313
|
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Same as `s.replace`, but replace all matched strings instead of just one.
|
|
1316
|
+
*/
|
|
1140
1317
|
replaceAll(searchValue, replacement) {
|
|
1141
|
-
if (typeof searchValue == "string")
|
|
1142
|
-
|
|
1143
|
-
if (!searchValue.global)
|
|
1144
|
-
throw new TypeError(
|
|
1145
|
-
"MagicString.prototype.replaceAll called with a non-global RegExp argument"
|
|
1146
|
-
);
|
|
1318
|
+
if (typeof searchValue == "string") return this._replaceAllString(searchValue, replacement);
|
|
1319
|
+
if (!searchValue.global) throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
|
|
1147
1320
|
return this._replaceRegexp(searchValue, replacement);
|
|
1148
1321
|
}
|
|
1149
1322
|
};
|
|
@@ -1166,7 +1339,7 @@ async function injectExportOrderPlugin() {
|
|
|
1166
1339
|
let s = new MagicString(code), orderedExports = exportNames.filter((e) => e !== "default");
|
|
1167
1340
|
return s.append(`;export const __namedExportsOrder = ${JSON.stringify(orderedExports)};`), {
|
|
1168
1341
|
code: s.toString(),
|
|
1169
|
-
map: s.generateMap({ hires: !0, source: id })
|
|
1342
|
+
map: s.generateMap({ hires: !0, source: id }).toString()
|
|
1170
1343
|
};
|
|
1171
1344
|
}
|
|
1172
1345
|
}
|
|
@@ -1187,7 +1360,7 @@ async function stripStoryHMRBoundary() {
|
|
|
1187
1360
|
let s = new MagicString(src);
|
|
1188
1361
|
return s.replace(/import\.meta\.hot\.accept\w*/, "(function hmrBoundaryNoop(){})"), {
|
|
1189
1362
|
code: s.toString(),
|
|
1190
|
-
map: s.generateMap({ hires: !0, source: id })
|
|
1363
|
+
map: s.generateMap({ hires: !0, source: id }).toString()
|
|
1191
1364
|
};
|
|
1192
1365
|
}
|
|
1193
1366
|
}
|
package/dist/preset.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_3u00ejc6ctm from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_3u00ejc6ctm from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_3u00ejc6ctm from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_3u00ejc6ctm.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_3u00ejc6ctm.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_3u00ejc6ctm.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -12,7 +12,7 @@ var require = CJS_COMPAT_NODE_MODULE_bdw69tdwtqr.createRequire(import.meta.url);
|
|
|
12
12
|
import {
|
|
13
13
|
optimizeViteDeps,
|
|
14
14
|
viteCorePlugins
|
|
15
|
-
} from "./_node-chunks/chunk-
|
|
15
|
+
} from "./_node-chunks/chunk-2LU3AW27.js";
|
|
16
16
|
export {
|
|
17
17
|
optimizeViteDeps,
|
|
18
18
|
viteCorePlugins
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/builder-vite",
|
|
3
|
-
"version": "10.6.0-alpha.
|
|
3
|
+
"version": "10.6.0-alpha.4",
|
|
4
4
|
"description": "A Storybook builder to dev and build with Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"!src/**/*"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@storybook/csf-plugin": "10.6.0-alpha.
|
|
50
|
+
"@storybook/csf-plugin": "10.6.0-alpha.4",
|
|
51
51
|
"ts-dedent": "^2.0.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
"es-module-lexer": "^1.5.0",
|
|
57
57
|
"glob": "^10.5.0",
|
|
58
58
|
"knitwork": "^1.1.0",
|
|
59
|
-
"magic-string": "^
|
|
59
|
+
"magic-string": "^1.1.0",
|
|
60
60
|
"pathe": "^1.1.2",
|
|
61
61
|
"slash": "^5.0.0",
|
|
62
62
|
"vite": "^7.0.4"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"storybook": "^10.6.0-alpha.
|
|
65
|
+
"storybook": "^10.6.0-alpha.4",
|
|
66
66
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
67
67
|
},
|
|
68
68
|
"publishConfig": {
|