storybook 10.1.0-alpha.8 → 10.1.0-beta.0
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.
- package/dist/_browser-chunks/Color-FTG7SQDA.js +1097 -0
- package/dist/_browser-chunks/WithTooltip-LMROHDUP.js +1651 -0
- package/dist/_browser-chunks/chunk-2FRVAXCZ.js +7 -0
- package/dist/_browser-chunks/{chunk-FDWKXLBI.js → chunk-2XZMBGTA.js} +44 -109
- package/dist/_browser-chunks/chunk-3IAH5M2U.js +171 -0
- package/dist/_browser-chunks/chunk-3OXGAGBE.js +779 -0
- package/dist/_browser-chunks/{chunk-TMDZCWME.js → chunk-3PJE6VLG.js} +1 -3
- package/dist/_browser-chunks/{chunk-VAMFPZY3.js → chunk-45UGUKRX.js} +2 -7
- package/dist/_browser-chunks/chunk-6XWLIJQL.js +11 -0
- package/dist/_browser-chunks/{chunk-MM7DTO55.js → chunk-A242L54C.js} +10 -16
- package/dist/_browser-chunks/chunk-AIOS4NGK.js +252 -0
- package/dist/_browser-chunks/chunk-AS2HQEYC.js +14 -0
- package/dist/_browser-chunks/chunk-AXG2BOBL.js +836 -0
- package/dist/_browser-chunks/{chunk-MH6AXFXB.js → chunk-CHUV5WSW.js} +0 -5
- package/dist/_browser-chunks/chunk-EUVGDK4H.js +93 -0
- package/dist/_browser-chunks/chunk-EZSQOHRI.js +18 -0
- package/dist/_browser-chunks/{chunk-CADGRH3P.js → chunk-FNXWN6IK.js} +3 -8
- package/dist/_browser-chunks/chunk-FQ7SLVLR.js +66 -0
- package/dist/_browser-chunks/chunk-GFLS4VP3.js +64 -0
- package/dist/_browser-chunks/chunk-GFY5R5EY.js +47 -0
- package/dist/_browser-chunks/{chunk-L2D73C6Z.js → chunk-H6XK3RSC.js} +13 -21
- package/dist/_browser-chunks/chunk-IPA5A322.js +71 -0
- package/dist/_browser-chunks/chunk-JP7NCOJX.js +37 -0
- package/dist/_browser-chunks/chunk-KJHJLCBK.js +11 -0
- package/dist/_browser-chunks/{chunk-OWPZQM2D.js → chunk-L4RMQ7D7.js} +60 -110
- package/dist/_browser-chunks/chunk-P4F4UVXX.js +951 -0
- package/dist/_browser-chunks/{chunk-AB7OOPUX.js → chunk-QKODTO7K.js} +0 -5
- package/dist/_browser-chunks/chunk-RP5RXKFU.js +2491 -0
- package/dist/_browser-chunks/chunk-SL75JR6Y.js +9 -0
- package/dist/_browser-chunks/chunk-SS2NHR7W.js +2969 -0
- package/dist/_browser-chunks/chunk-UD6FQLAF.js +1481 -0
- package/dist/_browser-chunks/chunk-VYJQ7RU5.js +2853 -0
- package/dist/_browser-chunks/chunk-WJYERY3R.js +136 -0
- package/dist/_browser-chunks/chunk-XJNX76GA.js +85 -0
- package/dist/_browser-chunks/{chunk-F4Q6SGTB.js → chunk-YKE5S47A.js} +177 -399
- package/dist/_browser-chunks/{chunk-SN4J4IQ3.js → chunk-ZUWEVLDX.js} +1 -7
- package/dist/_browser-chunks/{formatter-OMEEQ6HG.js → formatter-QJ4M4OGQ.js} +4 -9
- package/dist/_browser-chunks/{syntaxhighlighter-CAVLW7PM.js → syntaxhighlighter-IQDEPFLK.js} +704 -1848
- package/dist/_node-chunks/{builder-manager-57OYTFQ5.js → builder-manager-BDAQHXFI.js} +510 -1019
- package/dist/_node-chunks/camelcase-3C7DZZPX.js +37 -0
- package/dist/_node-chunks/chunk-2IIQTGNE.js +6024 -0
- package/dist/_node-chunks/chunk-56U5LEMP.js +3043 -0
- package/dist/_node-chunks/chunk-7LIRCAQE.js +20 -0
- package/dist/_node-chunks/chunk-7RN6TXKP.js +603 -0
- package/dist/_node-chunks/chunk-7SJ7PZNL.js +4523 -0
- package/dist/_node-chunks/{chunk-2GK7NW46.js → chunk-BG4RDXG7.js} +8 -10
- package/dist/_node-chunks/chunk-CBQKMXLQ.js +18 -0
- package/dist/_node-chunks/chunk-CN2IW2KQ.js +1564 -0
- package/dist/_node-chunks/chunk-CQMAU6UQ.js +943 -0
- package/dist/_node-chunks/{chunk-RG4Z25PY.js → chunk-D6ND3TVY.js} +116 -276
- package/dist/_node-chunks/chunk-DC355CYB.js +61 -0
- package/dist/_node-chunks/{chunk-EBYCXVVR.js → chunk-EVK2SBW5.js} +292 -688
- package/dist/_node-chunks/chunk-IXWEUXJ2.js +119 -0
- package/dist/_node-chunks/{chunk-6F6CCOXH.js → chunk-KVRF22SH.js} +469 -983
- package/dist/_node-chunks/chunk-LEDP4QQW.js +919 -0
- package/dist/_node-chunks/{chunk-C4KEDJ6O.js → chunk-MMVV6DGG.js} +8133 -8887
- package/dist/_node-chunks/chunk-O5CGEVRI.js +29 -0
- package/dist/_node-chunks/chunk-OZZO56XN.js +299 -0
- package/dist/_node-chunks/chunk-POT2EVGD.js +78 -0
- package/dist/_node-chunks/chunk-R5YGFSTV.js +3781 -0
- package/dist/_node-chunks/chunk-SQCTM2OS.js +23 -0
- package/dist/_node-chunks/chunk-UFOFO5H7.js +54 -0
- package/dist/_node-chunks/chunk-VBF7ALJF.js +72 -0
- package/dist/_node-chunks/chunk-W6MAMTUF.js +70 -0
- package/dist/_node-chunks/chunk-WURL4XOT.js +46662 -0
- package/dist/_node-chunks/chunk-XGK6MVKR.js +61 -0
- package/dist/_node-chunks/chunk-YV3GDSDT.js +765 -0
- package/dist/_node-chunks/{chunk-RSHLCHYY.js → chunk-YWV55YW3.js} +15 -24
- package/dist/_node-chunks/dist-KEP4IFRN.js +121 -0
- package/dist/_node-chunks/globby-4WUBTDCN.js +3452 -0
- package/dist/_node-chunks/lib-JVOEKTYM.js +366 -0
- package/dist/_node-chunks/mdx-N42X6CFJ-C5WFYYXR.js +14329 -0
- package/dist/_node-chunks/p-limit-LDY632RS.js +116 -0
- package/dist/actions/decorator.js +21 -42
- package/dist/actions/index.js +3 -3
- package/dist/babel/index.d.ts +671 -335
- package/dist/babel/index.js +10 -11
- package/dist/bin/core.js +601 -1548
- package/dist/bin/dispatcher.js +36 -36
- package/dist/bin/loader.js +24 -38
- package/dist/channels/index.js +98 -234
- package/dist/cli/index.d.ts +1479 -133
- package/dist/cli/index.js +30 -8540
- package/dist/client-logger/index.js +31 -61
- package/dist/common/index.d.ts +139 -62
- package/dist/common/index.js +66 -51
- package/dist/components/index.d.ts +575 -273
- package/dist/components/index.js +14863 -4313
- package/dist/core-events/index.js +2 -66
- package/dist/core-server/index.d.ts +3 -2
- package/dist/core-server/index.js +2910 -8519
- package/dist/core-server/presets/common-manager.css +2 -2
- package/dist/core-server/presets/common-manager.js +2521 -5233
- package/dist/core-server/presets/common-override-preset.js +31 -60
- package/dist/core-server/presets/common-preset.js +663 -962
- package/dist/csf/index.js +534 -1179
- package/dist/csf-tools/index.js +9 -9
- package/dist/docs-tools/index.js +6 -6
- package/dist/highlight/index.js +2 -2
- package/dist/instrumenter/index.js +199 -415
- package/dist/manager/globals-runtime.js +59044 -67141
- package/dist/manager/globals.js +2 -3
- package/dist/manager/manager-stores.d.ts +1 -0
- package/dist/manager/manager-stores.js +23 -0
- package/dist/manager/runtime.js +11511 -10953
- package/dist/manager-api/index.d.ts +1811 -2
- package/dist/manager-api/index.js +1348 -2401
- package/dist/manager-errors.d.ts +9 -0
- package/dist/manager-errors.js +3 -3
- package/dist/mocking-utils/index.d.ts +1126 -0
- package/dist/mocking-utils/index.js +1181 -0
- package/dist/node-logger/index.d.ts +192 -24
- package/dist/node-logger/index.js +23 -4471
- package/dist/preview/globals.js +2 -3
- package/dist/preview/runtime.js +10799 -22393
- package/dist/preview-api/index.d.ts +1 -1
- package/dist/preview-api/index.js +13 -13
- package/dist/preview-errors.d.ts +9 -0
- package/dist/preview-errors.js +4 -4
- package/dist/router/index.js +347 -899
- package/dist/server-errors.d.ts +34 -1
- package/dist/server-errors.js +17 -10
- package/dist/telemetry/index.d.ts +24 -3
- package/dist/telemetry/index.js +25 -24
- package/dist/test/index.js +6131 -11916
- package/dist/theming/create.d.ts +1 -0
- package/dist/theming/create.js +4 -4
- package/dist/theming/index.d.ts +3366 -2599
- package/dist/theming/index.js +501 -1091
- package/dist/types/index.d.ts +72 -8
- package/dist/types/index.js +27 -12
- package/dist/viewport/index.js +3 -3
- package/package.json +26 -17
- package/dist/_browser-chunks/Color-7ZNS6F6B.js +0 -1676
- package/dist/_browser-chunks/WithTooltip-SK46ZJ2J.js +0 -13
- package/dist/_browser-chunks/chunk-6A7OIVEL.js +0 -66
- package/dist/_browser-chunks/chunk-B4A3ADP3.js +0 -3816
- package/dist/_browser-chunks/chunk-BOOOPFZF.js +0 -2335
- package/dist/_browser-chunks/chunk-FSBVR7H5.js +0 -106
- package/dist/_browser-chunks/chunk-FUOHXXZT.js +0 -23
- package/dist/_browser-chunks/chunk-GTKOCWCT.js +0 -17
- package/dist/_browser-chunks/chunk-HHW4FUMO.js +0 -12
- package/dist/_browser-chunks/chunk-JVSKG4YS.js +0 -4052
- package/dist/_browser-chunks/chunk-LASUB7TL.js +0 -76
- package/dist/_browser-chunks/chunk-LYCSRYYR.js +0 -101
- package/dist/_browser-chunks/chunk-NVV6MIOE.js +0 -243
- package/dist/_browser-chunks/chunk-OBXWFEPB.js +0 -852
- package/dist/_browser-chunks/chunk-OPCDBBL3.js +0 -48
- package/dist/_browser-chunks/chunk-PB6FZ3WE.js +0 -130
- package/dist/_browser-chunks/chunk-RNE2IUTB.js +0 -1300
- package/dist/_browser-chunks/chunk-RW5PKMWM.js +0 -4182
- package/dist/_browser-chunks/chunk-SYS437NN.js +0 -122
- package/dist/_browser-chunks/chunk-U46RQHA4.js +0 -12
- package/dist/_browser-chunks/chunk-UTNZYD2N.js +0 -311
- package/dist/_browser-chunks/chunk-VUAFL5XK.js +0 -20
- package/dist/_browser-chunks/chunk-XDGMHOV7.js +0 -2197
- package/dist/_browser-chunks/chunk-XW6KSYKF.js +0 -16
- package/dist/_browser-chunks/chunk-Y3M7TW6K.js +0 -1041
- package/dist/_browser-chunks/chunk-ZNRFDIVA.js +0 -233
- package/dist/_node-chunks/camelcase-2KEDZHZ2.js +0 -18
- package/dist/_node-chunks/chunk-34NNXTBR.js +0 -28
- package/dist/_node-chunks/chunk-3N2A3KZX.js +0 -420
- package/dist/_node-chunks/chunk-5P7P5KDN.js +0 -90
- package/dist/_node-chunks/chunk-5WBRBDXI.js +0 -79
- package/dist/_node-chunks/chunk-7PWTU7T2.js +0 -697
- package/dist/_node-chunks/chunk-CHRHQ7AZ.js +0 -4272
- package/dist/_node-chunks/chunk-D4EGQLJI.js +0 -64656
- package/dist/_node-chunks/chunk-EKCURTKU.js +0 -1544
- package/dist/_node-chunks/chunk-GBVPPW4H.js +0 -1657
- package/dist/_node-chunks/chunk-J6VOKT2F.js +0 -220
- package/dist/_node-chunks/chunk-JLBYSGXS.js +0 -69
- package/dist/_node-chunks/chunk-LLCELSUL.js +0 -1198
- package/dist/_node-chunks/chunk-NS4OCQ4F.js +0 -61
- package/dist/_node-chunks/chunk-NXVLFYDR.js +0 -1518
- package/dist/_node-chunks/chunk-NZPWAJOZ.js +0 -304
- package/dist/_node-chunks/chunk-OYFSIV3I.js +0 -6712
- package/dist/_node-chunks/chunk-OZ43LMDF.js +0 -5029
- package/dist/_node-chunks/chunk-Q5HJHFF2.js +0 -61
- package/dist/_node-chunks/chunk-QHER4CEN.js +0 -34
- package/dist/_node-chunks/chunk-RF2PJM54.js +0 -1531
- package/dist/_node-chunks/chunk-S3OHGEE3.js +0 -101
- package/dist/_node-chunks/chunk-S5XOMVSV.js +0 -2256
- package/dist/_node-chunks/chunk-SGXQZ47H.js +0 -1586
- package/dist/_node-chunks/chunk-TDU6OVUH.js +0 -111
- package/dist/_node-chunks/chunk-TYQQFNQX.js +0 -1250
- package/dist/_node-chunks/chunk-WNGLARN2.js +0 -4741
- package/dist/_node-chunks/chunk-YUOVDCXL.js +0 -18
- package/dist/_node-chunks/dist-O5FB7YUW.js +0 -175
- package/dist/_node-chunks/globby-3NMV7WHX.js +0 -5222
- package/dist/_node-chunks/lib-VZD7BRSA.js +0 -518
- package/dist/_node-chunks/mdx-N42X6CFJ-3RP7RKKU.js +0 -22017
- package/dist/_node-chunks/p-limit-LIKBTXEJ.js +0 -168
- package/dist/_node-chunks/plugin-2NYZBK4A.js +0 -129
- package/dist/_node-chunks/plugin-6QGMO7J7.js +0 -159
- package/dist/_node-chunks/webpack-inject-mocker-runtime-plugin-Z2JI6J2H.js +0 -69102
- package/dist/_node-chunks/webpack-mock-plugin-D4BE2SSI.js +0 -124
- package/dist/core-server/presets/webpack/loaders/storybook-mock-transform-loader.js +0 -36
- package/dist/core-server/presets/webpack/loaders/webpack-automock-loader.js +0 -33
|
@@ -1,1250 +0,0 @@
|
|
|
1
|
-
import CJS_COMPAT_NODE_URL_rqth4iav4b from 'node:url';
|
|
2
|
-
import CJS_COMPAT_NODE_PATH_rqth4iav4b from 'node:path';
|
|
3
|
-
import CJS_COMPAT_NODE_MODULE_rqth4iav4b from "node:module";
|
|
4
|
-
|
|
5
|
-
var __filename = CJS_COMPAT_NODE_URL_rqth4iav4b.fileURLToPath(import.meta.url);
|
|
6
|
-
var __dirname = CJS_COMPAT_NODE_PATH_rqth4iav4b.dirname(__filename);
|
|
7
|
-
var require = CJS_COMPAT_NODE_MODULE_rqth4iav4b.createRequire(import.meta.url);
|
|
8
|
-
|
|
9
|
-
// ------------------------------------------------------------
|
|
10
|
-
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
|
-
// ------------------------------------------------------------
|
|
12
|
-
import {
|
|
13
|
-
__name
|
|
14
|
-
} from "./chunk-Q5HJHFF2.js";
|
|
15
|
-
|
|
16
|
-
// ../node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
17
|
-
var comma = ",".charCodeAt(0);
|
|
18
|
-
var semicolon = ";".charCodeAt(0);
|
|
19
|
-
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
20
|
-
var intToChar = new Uint8Array(64);
|
|
21
|
-
var charToInt = new Uint8Array(128);
|
|
22
|
-
for (let i = 0; i < chars.length; i++) {
|
|
23
|
-
const c = chars.charCodeAt(i);
|
|
24
|
-
intToChar[i] = c;
|
|
25
|
-
charToInt[c] = i;
|
|
26
|
-
}
|
|
27
|
-
function encodeInteger(builder, num, relative) {
|
|
28
|
-
let delta = num - relative;
|
|
29
|
-
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
30
|
-
do {
|
|
31
|
-
let clamped = delta & 31;
|
|
32
|
-
delta >>>= 5;
|
|
33
|
-
if (delta > 0) clamped |= 32;
|
|
34
|
-
builder.write(intToChar[clamped]);
|
|
35
|
-
} while (delta > 0);
|
|
36
|
-
return num;
|
|
37
|
-
}
|
|
38
|
-
__name(encodeInteger, "encodeInteger");
|
|
39
|
-
var bufLength = 1024 * 16;
|
|
40
|
-
var td = typeof TextDecoder !== "undefined" ? new TextDecoder() : typeof Buffer !== "undefined" ? {
|
|
41
|
-
decode(buf) {
|
|
42
|
-
const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
43
|
-
return out.toString();
|
|
44
|
-
}
|
|
45
|
-
} : {
|
|
46
|
-
decode(buf) {
|
|
47
|
-
let out = "";
|
|
48
|
-
for (let i = 0; i < buf.length; i++) {
|
|
49
|
-
out += String.fromCharCode(buf[i]);
|
|
50
|
-
}
|
|
51
|
-
return out;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var StringWriter = class {
|
|
55
|
-
static {
|
|
56
|
-
__name(this, "StringWriter");
|
|
57
|
-
}
|
|
58
|
-
constructor() {
|
|
59
|
-
this.pos = 0;
|
|
60
|
-
this.out = "";
|
|
61
|
-
this.buffer = new Uint8Array(bufLength);
|
|
62
|
-
}
|
|
63
|
-
write(v) {
|
|
64
|
-
const { buffer } = this;
|
|
65
|
-
buffer[this.pos++] = v;
|
|
66
|
-
if (this.pos === bufLength) {
|
|
67
|
-
this.out += td.decode(buffer);
|
|
68
|
-
this.pos = 0;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
flush() {
|
|
72
|
-
const { buffer, out, pos } = this;
|
|
73
|
-
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
function encode(decoded) {
|
|
77
|
-
const writer = new StringWriter();
|
|
78
|
-
let sourcesIndex = 0;
|
|
79
|
-
let sourceLine = 0;
|
|
80
|
-
let sourceColumn = 0;
|
|
81
|
-
let namesIndex = 0;
|
|
82
|
-
for (let i = 0; i < decoded.length; i++) {
|
|
83
|
-
const line = decoded[i];
|
|
84
|
-
if (i > 0) writer.write(semicolon);
|
|
85
|
-
if (line.length === 0) continue;
|
|
86
|
-
let genColumn = 0;
|
|
87
|
-
for (let j = 0; j < line.length; j++) {
|
|
88
|
-
const segment = line[j];
|
|
89
|
-
if (j > 0) writer.write(comma);
|
|
90
|
-
genColumn = encodeInteger(writer, segment[0], genColumn);
|
|
91
|
-
if (segment.length === 1) continue;
|
|
92
|
-
sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
|
|
93
|
-
sourceLine = encodeInteger(writer, segment[2], sourceLine);
|
|
94
|
-
sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
|
|
95
|
-
if (segment.length === 4) continue;
|
|
96
|
-
namesIndex = encodeInteger(writer, segment[4], namesIndex);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return writer.flush();
|
|
100
|
-
}
|
|
101
|
-
__name(encode, "encode");
|
|
102
|
-
|
|
103
|
-
// ../node_modules/magic-string/dist/magic-string.es.mjs
|
|
104
|
-
var BitSet = class _BitSet {
|
|
105
|
-
static {
|
|
106
|
-
__name(this, "BitSet");
|
|
107
|
-
}
|
|
108
|
-
constructor(arg) {
|
|
109
|
-
this.bits = arg instanceof _BitSet ? arg.bits.slice() : [];
|
|
110
|
-
}
|
|
111
|
-
add(n2) {
|
|
112
|
-
this.bits[n2 >> 5] |= 1 << (n2 & 31);
|
|
113
|
-
}
|
|
114
|
-
has(n2) {
|
|
115
|
-
return !!(this.bits[n2 >> 5] & 1 << (n2 & 31));
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
var Chunk = class _Chunk {
|
|
119
|
-
static {
|
|
120
|
-
__name(this, "Chunk");
|
|
121
|
-
}
|
|
122
|
-
constructor(start, end, content) {
|
|
123
|
-
this.start = start;
|
|
124
|
-
this.end = end;
|
|
125
|
-
this.original = content;
|
|
126
|
-
this.intro = "";
|
|
127
|
-
this.outro = "";
|
|
128
|
-
this.content = content;
|
|
129
|
-
this.storeName = false;
|
|
130
|
-
this.edited = false;
|
|
131
|
-
{
|
|
132
|
-
this.previous = null;
|
|
133
|
-
this.next = null;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
appendLeft(content) {
|
|
137
|
-
this.outro += content;
|
|
138
|
-
}
|
|
139
|
-
appendRight(content) {
|
|
140
|
-
this.intro = this.intro + content;
|
|
141
|
-
}
|
|
142
|
-
clone() {
|
|
143
|
-
const chunk = new _Chunk(this.start, this.end, this.original);
|
|
144
|
-
chunk.intro = this.intro;
|
|
145
|
-
chunk.outro = this.outro;
|
|
146
|
-
chunk.content = this.content;
|
|
147
|
-
chunk.storeName = this.storeName;
|
|
148
|
-
chunk.edited = this.edited;
|
|
149
|
-
return chunk;
|
|
150
|
-
}
|
|
151
|
-
contains(index) {
|
|
152
|
-
return this.start < index && index < this.end;
|
|
153
|
-
}
|
|
154
|
-
eachNext(fn) {
|
|
155
|
-
let chunk = this;
|
|
156
|
-
while (chunk) {
|
|
157
|
-
fn(chunk);
|
|
158
|
-
chunk = chunk.next;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
eachPrevious(fn) {
|
|
162
|
-
let chunk = this;
|
|
163
|
-
while (chunk) {
|
|
164
|
-
fn(chunk);
|
|
165
|
-
chunk = chunk.previous;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
edit(content, storeName, contentOnly) {
|
|
169
|
-
this.content = content;
|
|
170
|
-
if (!contentOnly) {
|
|
171
|
-
this.intro = "";
|
|
172
|
-
this.outro = "";
|
|
173
|
-
}
|
|
174
|
-
this.storeName = storeName;
|
|
175
|
-
this.edited = true;
|
|
176
|
-
return this;
|
|
177
|
-
}
|
|
178
|
-
prependLeft(content) {
|
|
179
|
-
this.outro = content + this.outro;
|
|
180
|
-
}
|
|
181
|
-
prependRight(content) {
|
|
182
|
-
this.intro = content + this.intro;
|
|
183
|
-
}
|
|
184
|
-
reset() {
|
|
185
|
-
this.intro = "";
|
|
186
|
-
this.outro = "";
|
|
187
|
-
if (this.edited) {
|
|
188
|
-
this.content = this.original;
|
|
189
|
-
this.storeName = false;
|
|
190
|
-
this.edited = false;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
split(index) {
|
|
194
|
-
const sliceIndex = index - this.start;
|
|
195
|
-
const originalBefore = this.original.slice(0, sliceIndex);
|
|
196
|
-
const originalAfter = this.original.slice(sliceIndex);
|
|
197
|
-
this.original = originalBefore;
|
|
198
|
-
const newChunk = new _Chunk(index, this.end, originalAfter);
|
|
199
|
-
newChunk.outro = this.outro;
|
|
200
|
-
this.outro = "";
|
|
201
|
-
this.end = index;
|
|
202
|
-
if (this.edited) {
|
|
203
|
-
newChunk.edit("", false);
|
|
204
|
-
this.content = "";
|
|
205
|
-
} else {
|
|
206
|
-
this.content = originalBefore;
|
|
207
|
-
}
|
|
208
|
-
newChunk.next = this.next;
|
|
209
|
-
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
210
|
-
newChunk.previous = this;
|
|
211
|
-
this.next = newChunk;
|
|
212
|
-
return newChunk;
|
|
213
|
-
}
|
|
214
|
-
toString() {
|
|
215
|
-
return this.intro + this.content + this.outro;
|
|
216
|
-
}
|
|
217
|
-
trimEnd(rx) {
|
|
218
|
-
this.outro = this.outro.replace(rx, "");
|
|
219
|
-
if (this.outro.length) return true;
|
|
220
|
-
const trimmed = this.content.replace(rx, "");
|
|
221
|
-
if (trimmed.length) {
|
|
222
|
-
if (trimmed !== this.content) {
|
|
223
|
-
this.split(this.start + trimmed.length).edit("", void 0, true);
|
|
224
|
-
if (this.edited) {
|
|
225
|
-
this.edit(trimmed, this.storeName, true);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return true;
|
|
229
|
-
} else {
|
|
230
|
-
this.edit("", void 0, true);
|
|
231
|
-
this.intro = this.intro.replace(rx, "");
|
|
232
|
-
if (this.intro.length) return true;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
trimStart(rx) {
|
|
236
|
-
this.intro = this.intro.replace(rx, "");
|
|
237
|
-
if (this.intro.length) return true;
|
|
238
|
-
const trimmed = this.content.replace(rx, "");
|
|
239
|
-
if (trimmed.length) {
|
|
240
|
-
if (trimmed !== this.content) {
|
|
241
|
-
const newChunk = this.split(this.end - trimmed.length);
|
|
242
|
-
if (this.edited) {
|
|
243
|
-
newChunk.edit(trimmed, this.storeName, true);
|
|
244
|
-
}
|
|
245
|
-
this.edit("", void 0, true);
|
|
246
|
-
}
|
|
247
|
-
return true;
|
|
248
|
-
} else {
|
|
249
|
-
this.edit("", void 0, true);
|
|
250
|
-
this.outro = this.outro.replace(rx, "");
|
|
251
|
-
if (this.outro.length) return true;
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
function getBtoa() {
|
|
256
|
-
if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") {
|
|
257
|
-
return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
|
|
258
|
-
} else if (typeof Buffer === "function") {
|
|
259
|
-
return (str) => Buffer.from(str, "utf-8").toString("base64");
|
|
260
|
-
} else {
|
|
261
|
-
return () => {
|
|
262
|
-
throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
__name(getBtoa, "getBtoa");
|
|
267
|
-
var btoa = getBtoa();
|
|
268
|
-
var SourceMap = class {
|
|
269
|
-
static {
|
|
270
|
-
__name(this, "SourceMap");
|
|
271
|
-
}
|
|
272
|
-
constructor(properties) {
|
|
273
|
-
this.version = 3;
|
|
274
|
-
this.file = properties.file;
|
|
275
|
-
this.sources = properties.sources;
|
|
276
|
-
this.sourcesContent = properties.sourcesContent;
|
|
277
|
-
this.names = properties.names;
|
|
278
|
-
this.mappings = encode(properties.mappings);
|
|
279
|
-
if (typeof properties.x_google_ignoreList !== "undefined") {
|
|
280
|
-
this.x_google_ignoreList = properties.x_google_ignoreList;
|
|
281
|
-
}
|
|
282
|
-
if (typeof properties.debugId !== "undefined") {
|
|
283
|
-
this.debugId = properties.debugId;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
toString() {
|
|
287
|
-
return JSON.stringify(this);
|
|
288
|
-
}
|
|
289
|
-
toUrl() {
|
|
290
|
-
return "data:application/json;charset=utf-8;base64," + btoa(this.toString());
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
function guessIndent(code) {
|
|
294
|
-
const lines = code.split("\n");
|
|
295
|
-
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
296
|
-
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
297
|
-
if (tabbed.length === 0 && spaced.length === 0) {
|
|
298
|
-
return null;
|
|
299
|
-
}
|
|
300
|
-
if (tabbed.length >= spaced.length) {
|
|
301
|
-
return " ";
|
|
302
|
-
}
|
|
303
|
-
const min = spaced.reduce((previous, current) => {
|
|
304
|
-
const numSpaces = /^ +/.exec(current)[0].length;
|
|
305
|
-
return Math.min(numSpaces, previous);
|
|
306
|
-
}, Infinity);
|
|
307
|
-
return new Array(min + 1).join(" ");
|
|
308
|
-
}
|
|
309
|
-
__name(guessIndent, "guessIndent");
|
|
310
|
-
function getRelativePath(from, to) {
|
|
311
|
-
const fromParts = from.split(/[/\\]/);
|
|
312
|
-
const toParts = to.split(/[/\\]/);
|
|
313
|
-
fromParts.pop();
|
|
314
|
-
while (fromParts[0] === toParts[0]) {
|
|
315
|
-
fromParts.shift();
|
|
316
|
-
toParts.shift();
|
|
317
|
-
}
|
|
318
|
-
if (fromParts.length) {
|
|
319
|
-
let i = fromParts.length;
|
|
320
|
-
while (i--) fromParts[i] = "..";
|
|
321
|
-
}
|
|
322
|
-
return fromParts.concat(toParts).join("/");
|
|
323
|
-
}
|
|
324
|
-
__name(getRelativePath, "getRelativePath");
|
|
325
|
-
var toString = Object.prototype.toString;
|
|
326
|
-
function isObject(thing) {
|
|
327
|
-
return toString.call(thing) === "[object Object]";
|
|
328
|
-
}
|
|
329
|
-
__name(isObject, "isObject");
|
|
330
|
-
function getLocator(source) {
|
|
331
|
-
const originalLines = source.split("\n");
|
|
332
|
-
const lineOffsets = [];
|
|
333
|
-
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
334
|
-
lineOffsets.push(pos);
|
|
335
|
-
pos += originalLines[i].length + 1;
|
|
336
|
-
}
|
|
337
|
-
return /* @__PURE__ */ __name(function locate(index) {
|
|
338
|
-
let i = 0;
|
|
339
|
-
let j = lineOffsets.length;
|
|
340
|
-
while (i < j) {
|
|
341
|
-
const m = i + j >> 1;
|
|
342
|
-
if (index < lineOffsets[m]) {
|
|
343
|
-
j = m;
|
|
344
|
-
} else {
|
|
345
|
-
i = m + 1;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
const line = i - 1;
|
|
349
|
-
const column = index - lineOffsets[line];
|
|
350
|
-
return { line, column };
|
|
351
|
-
}, "locate");
|
|
352
|
-
}
|
|
353
|
-
__name(getLocator, "getLocator");
|
|
354
|
-
var wordRegex = /\w/;
|
|
355
|
-
var Mappings = class {
|
|
356
|
-
static {
|
|
357
|
-
__name(this, "Mappings");
|
|
358
|
-
}
|
|
359
|
-
constructor(hires) {
|
|
360
|
-
this.hires = hires;
|
|
361
|
-
this.generatedCodeLine = 0;
|
|
362
|
-
this.generatedCodeColumn = 0;
|
|
363
|
-
this.raw = [];
|
|
364
|
-
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
365
|
-
this.pending = null;
|
|
366
|
-
}
|
|
367
|
-
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
368
|
-
if (content.length) {
|
|
369
|
-
const contentLengthMinusOne = content.length - 1;
|
|
370
|
-
let contentLineEnd = content.indexOf("\n", 0);
|
|
371
|
-
let previousContentLineEnd = -1;
|
|
372
|
-
while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
|
|
373
|
-
const segment2 = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
374
|
-
if (nameIndex >= 0) {
|
|
375
|
-
segment2.push(nameIndex);
|
|
376
|
-
}
|
|
377
|
-
this.rawSegments.push(segment2);
|
|
378
|
-
this.generatedCodeLine += 1;
|
|
379
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
380
|
-
this.generatedCodeColumn = 0;
|
|
381
|
-
previousContentLineEnd = contentLineEnd;
|
|
382
|
-
contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
|
|
383
|
-
}
|
|
384
|
-
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
385
|
-
if (nameIndex >= 0) {
|
|
386
|
-
segment.push(nameIndex);
|
|
387
|
-
}
|
|
388
|
-
this.rawSegments.push(segment);
|
|
389
|
-
this.advance(content.slice(previousContentLineEnd + 1));
|
|
390
|
-
} else if (this.pending) {
|
|
391
|
-
this.rawSegments.push(this.pending);
|
|
392
|
-
this.advance(content);
|
|
393
|
-
}
|
|
394
|
-
this.pending = null;
|
|
395
|
-
}
|
|
396
|
-
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
397
|
-
let originalCharIndex = chunk.start;
|
|
398
|
-
let first = true;
|
|
399
|
-
let charInHiresBoundary = false;
|
|
400
|
-
while (originalCharIndex < chunk.end) {
|
|
401
|
-
if (original[originalCharIndex] === "\n") {
|
|
402
|
-
loc.line += 1;
|
|
403
|
-
loc.column = 0;
|
|
404
|
-
this.generatedCodeLine += 1;
|
|
405
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
406
|
-
this.generatedCodeColumn = 0;
|
|
407
|
-
first = true;
|
|
408
|
-
charInHiresBoundary = false;
|
|
409
|
-
} else {
|
|
410
|
-
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
411
|
-
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
412
|
-
if (this.hires === "boundary") {
|
|
413
|
-
if (wordRegex.test(original[originalCharIndex])) {
|
|
414
|
-
if (!charInHiresBoundary) {
|
|
415
|
-
this.rawSegments.push(segment);
|
|
416
|
-
charInHiresBoundary = true;
|
|
417
|
-
}
|
|
418
|
-
} else {
|
|
419
|
-
this.rawSegments.push(segment);
|
|
420
|
-
charInHiresBoundary = false;
|
|
421
|
-
}
|
|
422
|
-
} else {
|
|
423
|
-
this.rawSegments.push(segment);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
loc.column += 1;
|
|
427
|
-
this.generatedCodeColumn += 1;
|
|
428
|
-
first = false;
|
|
429
|
-
}
|
|
430
|
-
originalCharIndex += 1;
|
|
431
|
-
}
|
|
432
|
-
this.pending = null;
|
|
433
|
-
}
|
|
434
|
-
advance(str) {
|
|
435
|
-
if (!str) return;
|
|
436
|
-
const lines = str.split("\n");
|
|
437
|
-
if (lines.length > 1) {
|
|
438
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
439
|
-
this.generatedCodeLine++;
|
|
440
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
441
|
-
}
|
|
442
|
-
this.generatedCodeColumn = 0;
|
|
443
|
-
}
|
|
444
|
-
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
var n = "\n";
|
|
448
|
-
var warned = {
|
|
449
|
-
insertLeft: false,
|
|
450
|
-
insertRight: false,
|
|
451
|
-
storeName: false
|
|
452
|
-
};
|
|
453
|
-
var MagicString = class _MagicString {
|
|
454
|
-
static {
|
|
455
|
-
__name(this, "MagicString");
|
|
456
|
-
}
|
|
457
|
-
constructor(string, options = {}) {
|
|
458
|
-
const chunk = new Chunk(0, string.length, string);
|
|
459
|
-
Object.defineProperties(this, {
|
|
460
|
-
original: { writable: true, value: string },
|
|
461
|
-
outro: { writable: true, value: "" },
|
|
462
|
-
intro: { writable: true, value: "" },
|
|
463
|
-
firstChunk: { writable: true, value: chunk },
|
|
464
|
-
lastChunk: { writable: true, value: chunk },
|
|
465
|
-
lastSearchedChunk: { writable: true, value: chunk },
|
|
466
|
-
byStart: { writable: true, value: {} },
|
|
467
|
-
byEnd: { writable: true, value: {} },
|
|
468
|
-
filename: { writable: true, value: options.filename },
|
|
469
|
-
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
|
470
|
-
sourcemapLocations: { writable: true, value: new BitSet() },
|
|
471
|
-
storedNames: { writable: true, value: {} },
|
|
472
|
-
indentStr: { writable: true, value: void 0 },
|
|
473
|
-
ignoreList: { writable: true, value: options.ignoreList },
|
|
474
|
-
offset: { writable: true, value: options.offset || 0 }
|
|
475
|
-
});
|
|
476
|
-
this.byStart[0] = chunk;
|
|
477
|
-
this.byEnd[string.length] = chunk;
|
|
478
|
-
}
|
|
479
|
-
addSourcemapLocation(char) {
|
|
480
|
-
this.sourcemapLocations.add(char);
|
|
481
|
-
}
|
|
482
|
-
append(content) {
|
|
483
|
-
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
484
|
-
this.outro += content;
|
|
485
|
-
return this;
|
|
486
|
-
}
|
|
487
|
-
appendLeft(index, content) {
|
|
488
|
-
index = index + this.offset;
|
|
489
|
-
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
490
|
-
this._split(index);
|
|
491
|
-
const chunk = this.byEnd[index];
|
|
492
|
-
if (chunk) {
|
|
493
|
-
chunk.appendLeft(content);
|
|
494
|
-
} else {
|
|
495
|
-
this.intro += content;
|
|
496
|
-
}
|
|
497
|
-
return this;
|
|
498
|
-
}
|
|
499
|
-
appendRight(index, content) {
|
|
500
|
-
index = index + this.offset;
|
|
501
|
-
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
502
|
-
this._split(index);
|
|
503
|
-
const chunk = this.byStart[index];
|
|
504
|
-
if (chunk) {
|
|
505
|
-
chunk.appendRight(content);
|
|
506
|
-
} else {
|
|
507
|
-
this.outro += content;
|
|
508
|
-
}
|
|
509
|
-
return this;
|
|
510
|
-
}
|
|
511
|
-
clone() {
|
|
512
|
-
const cloned = new _MagicString(this.original, { filename: this.filename, offset: this.offset });
|
|
513
|
-
let originalChunk = this.firstChunk;
|
|
514
|
-
let clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
|
515
|
-
while (originalChunk) {
|
|
516
|
-
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
517
|
-
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
518
|
-
const nextOriginalChunk = originalChunk.next;
|
|
519
|
-
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
520
|
-
if (nextClonedChunk) {
|
|
521
|
-
clonedChunk.next = nextClonedChunk;
|
|
522
|
-
nextClonedChunk.previous = clonedChunk;
|
|
523
|
-
clonedChunk = nextClonedChunk;
|
|
524
|
-
}
|
|
525
|
-
originalChunk = nextOriginalChunk;
|
|
526
|
-
}
|
|
527
|
-
cloned.lastChunk = clonedChunk;
|
|
528
|
-
if (this.indentExclusionRanges) {
|
|
529
|
-
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
530
|
-
}
|
|
531
|
-
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
532
|
-
cloned.intro = this.intro;
|
|
533
|
-
cloned.outro = this.outro;
|
|
534
|
-
return cloned;
|
|
535
|
-
}
|
|
536
|
-
generateDecodedMap(options) {
|
|
537
|
-
options = options || {};
|
|
538
|
-
const sourceIndex = 0;
|
|
539
|
-
const names = Object.keys(this.storedNames);
|
|
540
|
-
const mappings = new Mappings(options.hires);
|
|
541
|
-
const locate = getLocator(this.original);
|
|
542
|
-
if (this.intro) {
|
|
543
|
-
mappings.advance(this.intro);
|
|
544
|
-
}
|
|
545
|
-
this.firstChunk.eachNext((chunk) => {
|
|
546
|
-
const loc = locate(chunk.start);
|
|
547
|
-
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
548
|
-
if (chunk.edited) {
|
|
549
|
-
mappings.addEdit(
|
|
550
|
-
sourceIndex,
|
|
551
|
-
chunk.content,
|
|
552
|
-
loc,
|
|
553
|
-
chunk.storeName ? names.indexOf(chunk.original) : -1
|
|
554
|
-
);
|
|
555
|
-
} else {
|
|
556
|
-
mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
557
|
-
}
|
|
558
|
-
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
559
|
-
});
|
|
560
|
-
if (this.outro) {
|
|
561
|
-
mappings.advance(this.outro);
|
|
562
|
-
}
|
|
563
|
-
return {
|
|
564
|
-
file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
|
|
565
|
-
sources: [
|
|
566
|
-
options.source ? getRelativePath(options.file || "", options.source) : options.file || ""
|
|
567
|
-
],
|
|
568
|
-
sourcesContent: options.includeContent ? [this.original] : void 0,
|
|
569
|
-
names,
|
|
570
|
-
mappings: mappings.raw,
|
|
571
|
-
x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
|
|
572
|
-
};
|
|
573
|
-
}
|
|
574
|
-
generateMap(options) {
|
|
575
|
-
return new SourceMap(this.generateDecodedMap(options));
|
|
576
|
-
}
|
|
577
|
-
_ensureindentStr() {
|
|
578
|
-
if (this.indentStr === void 0) {
|
|
579
|
-
this.indentStr = guessIndent(this.original);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
_getRawIndentString() {
|
|
583
|
-
this._ensureindentStr();
|
|
584
|
-
return this.indentStr;
|
|
585
|
-
}
|
|
586
|
-
getIndentString() {
|
|
587
|
-
this._ensureindentStr();
|
|
588
|
-
return this.indentStr === null ? " " : this.indentStr;
|
|
589
|
-
}
|
|
590
|
-
indent(indentStr, options) {
|
|
591
|
-
const pattern = /^[^\r\n]/gm;
|
|
592
|
-
if (isObject(indentStr)) {
|
|
593
|
-
options = indentStr;
|
|
594
|
-
indentStr = void 0;
|
|
595
|
-
}
|
|
596
|
-
if (indentStr === void 0) {
|
|
597
|
-
this._ensureindentStr();
|
|
598
|
-
indentStr = this.indentStr || " ";
|
|
599
|
-
}
|
|
600
|
-
if (indentStr === "") return this;
|
|
601
|
-
options = options || {};
|
|
602
|
-
const isExcluded = {};
|
|
603
|
-
if (options.exclude) {
|
|
604
|
-
const exclusions = typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude;
|
|
605
|
-
exclusions.forEach((exclusion) => {
|
|
606
|
-
for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
|
|
607
|
-
isExcluded[i] = true;
|
|
608
|
-
}
|
|
609
|
-
});
|
|
610
|
-
}
|
|
611
|
-
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
612
|
-
const replacer = /* @__PURE__ */ __name((match) => {
|
|
613
|
-
if (shouldIndentNextCharacter) return `${indentStr}${match}`;
|
|
614
|
-
shouldIndentNextCharacter = true;
|
|
615
|
-
return match;
|
|
616
|
-
}, "replacer");
|
|
617
|
-
this.intro = this.intro.replace(pattern, replacer);
|
|
618
|
-
let charIndex = 0;
|
|
619
|
-
let chunk = this.firstChunk;
|
|
620
|
-
while (chunk) {
|
|
621
|
-
const end = chunk.end;
|
|
622
|
-
if (chunk.edited) {
|
|
623
|
-
if (!isExcluded[charIndex]) {
|
|
624
|
-
chunk.content = chunk.content.replace(pattern, replacer);
|
|
625
|
-
if (chunk.content.length) {
|
|
626
|
-
shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
} else {
|
|
630
|
-
charIndex = chunk.start;
|
|
631
|
-
while (charIndex < end) {
|
|
632
|
-
if (!isExcluded[charIndex]) {
|
|
633
|
-
const char = this.original[charIndex];
|
|
634
|
-
if (char === "\n") {
|
|
635
|
-
shouldIndentNextCharacter = true;
|
|
636
|
-
} else if (char !== "\r" && shouldIndentNextCharacter) {
|
|
637
|
-
shouldIndentNextCharacter = false;
|
|
638
|
-
if (charIndex === chunk.start) {
|
|
639
|
-
chunk.prependRight(indentStr);
|
|
640
|
-
} else {
|
|
641
|
-
this._splitChunk(chunk, charIndex);
|
|
642
|
-
chunk = chunk.next;
|
|
643
|
-
chunk.prependRight(indentStr);
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
charIndex += 1;
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
charIndex = chunk.end;
|
|
651
|
-
chunk = chunk.next;
|
|
652
|
-
}
|
|
653
|
-
this.outro = this.outro.replace(pattern, replacer);
|
|
654
|
-
return this;
|
|
655
|
-
}
|
|
656
|
-
insert() {
|
|
657
|
-
throw new Error(
|
|
658
|
-
"magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)"
|
|
659
|
-
);
|
|
660
|
-
}
|
|
661
|
-
insertLeft(index, content) {
|
|
662
|
-
if (!warned.insertLeft) {
|
|
663
|
-
console.warn(
|
|
664
|
-
"magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"
|
|
665
|
-
);
|
|
666
|
-
warned.insertLeft = true;
|
|
667
|
-
}
|
|
668
|
-
return this.appendLeft(index, content);
|
|
669
|
-
}
|
|
670
|
-
insertRight(index, content) {
|
|
671
|
-
if (!warned.insertRight) {
|
|
672
|
-
console.warn(
|
|
673
|
-
"magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"
|
|
674
|
-
);
|
|
675
|
-
warned.insertRight = true;
|
|
676
|
-
}
|
|
677
|
-
return this.prependRight(index, content);
|
|
678
|
-
}
|
|
679
|
-
move(start, end, index) {
|
|
680
|
-
start = start + this.offset;
|
|
681
|
-
end = end + this.offset;
|
|
682
|
-
index = index + this.offset;
|
|
683
|
-
if (index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
|
|
684
|
-
this._split(start);
|
|
685
|
-
this._split(end);
|
|
686
|
-
this._split(index);
|
|
687
|
-
const first = this.byStart[start];
|
|
688
|
-
const last = this.byEnd[end];
|
|
689
|
-
const oldLeft = first.previous;
|
|
690
|
-
const oldRight = last.next;
|
|
691
|
-
const newRight = this.byStart[index];
|
|
692
|
-
if (!newRight && last === this.lastChunk) return this;
|
|
693
|
-
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
694
|
-
if (oldLeft) oldLeft.next = oldRight;
|
|
695
|
-
if (oldRight) oldRight.previous = oldLeft;
|
|
696
|
-
if (newLeft) newLeft.next = first;
|
|
697
|
-
if (newRight) newRight.previous = last;
|
|
698
|
-
if (!first.previous) this.firstChunk = last.next;
|
|
699
|
-
if (!last.next) {
|
|
700
|
-
this.lastChunk = first.previous;
|
|
701
|
-
this.lastChunk.next = null;
|
|
702
|
-
}
|
|
703
|
-
first.previous = newLeft;
|
|
704
|
-
last.next = newRight || null;
|
|
705
|
-
if (!newLeft) this.firstChunk = first;
|
|
706
|
-
if (!newRight) this.lastChunk = last;
|
|
707
|
-
return this;
|
|
708
|
-
}
|
|
709
|
-
overwrite(start, end, content, options) {
|
|
710
|
-
options = options || {};
|
|
711
|
-
return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
|
|
712
|
-
}
|
|
713
|
-
update(start, end, content, options) {
|
|
714
|
-
start = start + this.offset;
|
|
715
|
-
end = end + this.offset;
|
|
716
|
-
if (typeof content !== "string") throw new TypeError("replacement content must be a string");
|
|
717
|
-
if (this.original.length !== 0) {
|
|
718
|
-
while (start < 0) start += this.original.length;
|
|
719
|
-
while (end < 0) end += this.original.length;
|
|
720
|
-
}
|
|
721
|
-
if (end > this.original.length) throw new Error("end is out of bounds");
|
|
722
|
-
if (start === end)
|
|
723
|
-
throw new Error(
|
|
724
|
-
"Cannot overwrite a zero-length range \u2013 use appendLeft or prependRight instead"
|
|
725
|
-
);
|
|
726
|
-
this._split(start);
|
|
727
|
-
this._split(end);
|
|
728
|
-
if (options === true) {
|
|
729
|
-
if (!warned.storeName) {
|
|
730
|
-
console.warn(
|
|
731
|
-
"The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"
|
|
732
|
-
);
|
|
733
|
-
warned.storeName = true;
|
|
734
|
-
}
|
|
735
|
-
options = { storeName: true };
|
|
736
|
-
}
|
|
737
|
-
const storeName = options !== void 0 ? options.storeName : false;
|
|
738
|
-
const overwrite = options !== void 0 ? options.overwrite : false;
|
|
739
|
-
if (storeName) {
|
|
740
|
-
const original = this.original.slice(start, end);
|
|
741
|
-
Object.defineProperty(this.storedNames, original, {
|
|
742
|
-
writable: true,
|
|
743
|
-
value: true,
|
|
744
|
-
enumerable: true
|
|
745
|
-
});
|
|
746
|
-
}
|
|
747
|
-
const first = this.byStart[start];
|
|
748
|
-
const last = this.byEnd[end];
|
|
749
|
-
if (first) {
|
|
750
|
-
let chunk = first;
|
|
751
|
-
while (chunk !== last) {
|
|
752
|
-
if (chunk.next !== this.byStart[chunk.end]) {
|
|
753
|
-
throw new Error("Cannot overwrite across a split point");
|
|
754
|
-
}
|
|
755
|
-
chunk = chunk.next;
|
|
756
|
-
chunk.edit("", false);
|
|
757
|
-
}
|
|
758
|
-
first.edit(content, storeName, !overwrite);
|
|
759
|
-
} else {
|
|
760
|
-
const newChunk = new Chunk(start, end, "").edit(content, storeName);
|
|
761
|
-
last.next = newChunk;
|
|
762
|
-
newChunk.previous = last;
|
|
763
|
-
}
|
|
764
|
-
return this;
|
|
765
|
-
}
|
|
766
|
-
prepend(content) {
|
|
767
|
-
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
768
|
-
this.intro = content + this.intro;
|
|
769
|
-
return this;
|
|
770
|
-
}
|
|
771
|
-
prependLeft(index, content) {
|
|
772
|
-
index = index + this.offset;
|
|
773
|
-
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
774
|
-
this._split(index);
|
|
775
|
-
const chunk = this.byEnd[index];
|
|
776
|
-
if (chunk) {
|
|
777
|
-
chunk.prependLeft(content);
|
|
778
|
-
} else {
|
|
779
|
-
this.intro = content + this.intro;
|
|
780
|
-
}
|
|
781
|
-
return this;
|
|
782
|
-
}
|
|
783
|
-
prependRight(index, content) {
|
|
784
|
-
index = index + this.offset;
|
|
785
|
-
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
786
|
-
this._split(index);
|
|
787
|
-
const chunk = this.byStart[index];
|
|
788
|
-
if (chunk) {
|
|
789
|
-
chunk.prependRight(content);
|
|
790
|
-
} else {
|
|
791
|
-
this.outro = content + this.outro;
|
|
792
|
-
}
|
|
793
|
-
return this;
|
|
794
|
-
}
|
|
795
|
-
remove(start, end) {
|
|
796
|
-
start = start + this.offset;
|
|
797
|
-
end = end + this.offset;
|
|
798
|
-
if (this.original.length !== 0) {
|
|
799
|
-
while (start < 0) start += this.original.length;
|
|
800
|
-
while (end < 0) end += this.original.length;
|
|
801
|
-
}
|
|
802
|
-
if (start === end) return this;
|
|
803
|
-
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
804
|
-
if (start > end) throw new Error("end must be greater than start");
|
|
805
|
-
this._split(start);
|
|
806
|
-
this._split(end);
|
|
807
|
-
let chunk = this.byStart[start];
|
|
808
|
-
while (chunk) {
|
|
809
|
-
chunk.intro = "";
|
|
810
|
-
chunk.outro = "";
|
|
811
|
-
chunk.edit("");
|
|
812
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
813
|
-
}
|
|
814
|
-
return this;
|
|
815
|
-
}
|
|
816
|
-
reset(start, end) {
|
|
817
|
-
start = start + this.offset;
|
|
818
|
-
end = end + this.offset;
|
|
819
|
-
if (this.original.length !== 0) {
|
|
820
|
-
while (start < 0) start += this.original.length;
|
|
821
|
-
while (end < 0) end += this.original.length;
|
|
822
|
-
}
|
|
823
|
-
if (start === end) return this;
|
|
824
|
-
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
825
|
-
if (start > end) throw new Error("end must be greater than start");
|
|
826
|
-
this._split(start);
|
|
827
|
-
this._split(end);
|
|
828
|
-
let chunk = this.byStart[start];
|
|
829
|
-
while (chunk) {
|
|
830
|
-
chunk.reset();
|
|
831
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
832
|
-
}
|
|
833
|
-
return this;
|
|
834
|
-
}
|
|
835
|
-
lastChar() {
|
|
836
|
-
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
837
|
-
let chunk = this.lastChunk;
|
|
838
|
-
do {
|
|
839
|
-
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
840
|
-
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
841
|
-
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
842
|
-
} while (chunk = chunk.previous);
|
|
843
|
-
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
844
|
-
return "";
|
|
845
|
-
}
|
|
846
|
-
lastLine() {
|
|
847
|
-
let lineIndex = this.outro.lastIndexOf(n);
|
|
848
|
-
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
849
|
-
let lineStr = this.outro;
|
|
850
|
-
let chunk = this.lastChunk;
|
|
851
|
-
do {
|
|
852
|
-
if (chunk.outro.length > 0) {
|
|
853
|
-
lineIndex = chunk.outro.lastIndexOf(n);
|
|
854
|
-
if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
855
|
-
lineStr = chunk.outro + lineStr;
|
|
856
|
-
}
|
|
857
|
-
if (chunk.content.length > 0) {
|
|
858
|
-
lineIndex = chunk.content.lastIndexOf(n);
|
|
859
|
-
if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
|
|
860
|
-
lineStr = chunk.content + lineStr;
|
|
861
|
-
}
|
|
862
|
-
if (chunk.intro.length > 0) {
|
|
863
|
-
lineIndex = chunk.intro.lastIndexOf(n);
|
|
864
|
-
if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
865
|
-
lineStr = chunk.intro + lineStr;
|
|
866
|
-
}
|
|
867
|
-
} while (chunk = chunk.previous);
|
|
868
|
-
lineIndex = this.intro.lastIndexOf(n);
|
|
869
|
-
if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
|
|
870
|
-
return this.intro + lineStr;
|
|
871
|
-
}
|
|
872
|
-
slice(start = 0, end = this.original.length - this.offset) {
|
|
873
|
-
start = start + this.offset;
|
|
874
|
-
end = end + this.offset;
|
|
875
|
-
if (this.original.length !== 0) {
|
|
876
|
-
while (start < 0) start += this.original.length;
|
|
877
|
-
while (end < 0) end += this.original.length;
|
|
878
|
-
}
|
|
879
|
-
let result = "";
|
|
880
|
-
let chunk = this.firstChunk;
|
|
881
|
-
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
882
|
-
if (chunk.start < end && chunk.end >= end) {
|
|
883
|
-
return result;
|
|
884
|
-
}
|
|
885
|
-
chunk = chunk.next;
|
|
886
|
-
}
|
|
887
|
-
if (chunk && chunk.edited && chunk.start !== start)
|
|
888
|
-
throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
889
|
-
const startChunk = chunk;
|
|
890
|
-
while (chunk) {
|
|
891
|
-
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
|
|
892
|
-
result += chunk.intro;
|
|
893
|
-
}
|
|
894
|
-
const containsEnd = chunk.start < end && chunk.end >= end;
|
|
895
|
-
if (containsEnd && chunk.edited && chunk.end !== end)
|
|
896
|
-
throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
897
|
-
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
898
|
-
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
899
|
-
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
900
|
-
if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
|
901
|
-
result += chunk.outro;
|
|
902
|
-
}
|
|
903
|
-
if (containsEnd) {
|
|
904
|
-
break;
|
|
905
|
-
}
|
|
906
|
-
chunk = chunk.next;
|
|
907
|
-
}
|
|
908
|
-
return result;
|
|
909
|
-
}
|
|
910
|
-
// TODO deprecate this? not really very useful
|
|
911
|
-
snip(start, end) {
|
|
912
|
-
const clone = this.clone();
|
|
913
|
-
clone.remove(0, start);
|
|
914
|
-
clone.remove(end, clone.original.length);
|
|
915
|
-
return clone;
|
|
916
|
-
}
|
|
917
|
-
_split(index) {
|
|
918
|
-
if (this.byStart[index] || this.byEnd[index]) return;
|
|
919
|
-
let chunk = this.lastSearchedChunk;
|
|
920
|
-
let previousChunk = chunk;
|
|
921
|
-
const searchForward = index > chunk.end;
|
|
922
|
-
while (chunk) {
|
|
923
|
-
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
924
|
-
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
925
|
-
if (chunk === previousChunk) return;
|
|
926
|
-
previousChunk = chunk;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
_splitChunk(chunk, index) {
|
|
930
|
-
if (chunk.edited && chunk.content.length) {
|
|
931
|
-
const loc = getLocator(this.original)(index);
|
|
932
|
-
throw new Error(
|
|
933
|
-
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} \u2013 "${chunk.original}")`
|
|
934
|
-
);
|
|
935
|
-
}
|
|
936
|
-
const newChunk = chunk.split(index);
|
|
937
|
-
this.byEnd[index] = chunk;
|
|
938
|
-
this.byStart[index] = newChunk;
|
|
939
|
-
this.byEnd[newChunk.end] = newChunk;
|
|
940
|
-
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
941
|
-
this.lastSearchedChunk = chunk;
|
|
942
|
-
return true;
|
|
943
|
-
}
|
|
944
|
-
toString() {
|
|
945
|
-
let str = this.intro;
|
|
946
|
-
let chunk = this.firstChunk;
|
|
947
|
-
while (chunk) {
|
|
948
|
-
str += chunk.toString();
|
|
949
|
-
chunk = chunk.next;
|
|
950
|
-
}
|
|
951
|
-
return str + this.outro;
|
|
952
|
-
}
|
|
953
|
-
isEmpty() {
|
|
954
|
-
let chunk = this.firstChunk;
|
|
955
|
-
do {
|
|
956
|
-
if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim())
|
|
957
|
-
return false;
|
|
958
|
-
} while (chunk = chunk.next);
|
|
959
|
-
return true;
|
|
960
|
-
}
|
|
961
|
-
length() {
|
|
962
|
-
let chunk = this.firstChunk;
|
|
963
|
-
let length = 0;
|
|
964
|
-
do {
|
|
965
|
-
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
966
|
-
} while (chunk = chunk.next);
|
|
967
|
-
return length;
|
|
968
|
-
}
|
|
969
|
-
trimLines() {
|
|
970
|
-
return this.trim("[\\r\\n]");
|
|
971
|
-
}
|
|
972
|
-
trim(charType) {
|
|
973
|
-
return this.trimStart(charType).trimEnd(charType);
|
|
974
|
-
}
|
|
975
|
-
trimEndAborted(charType) {
|
|
976
|
-
const rx = new RegExp((charType || "\\s") + "+$");
|
|
977
|
-
this.outro = this.outro.replace(rx, "");
|
|
978
|
-
if (this.outro.length) return true;
|
|
979
|
-
let chunk = this.lastChunk;
|
|
980
|
-
do {
|
|
981
|
-
const end = chunk.end;
|
|
982
|
-
const aborted = chunk.trimEnd(rx);
|
|
983
|
-
if (chunk.end !== end) {
|
|
984
|
-
if (this.lastChunk === chunk) {
|
|
985
|
-
this.lastChunk = chunk.next;
|
|
986
|
-
}
|
|
987
|
-
this.byEnd[chunk.end] = chunk;
|
|
988
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
989
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
990
|
-
}
|
|
991
|
-
if (aborted) return true;
|
|
992
|
-
chunk = chunk.previous;
|
|
993
|
-
} while (chunk);
|
|
994
|
-
return false;
|
|
995
|
-
}
|
|
996
|
-
trimEnd(charType) {
|
|
997
|
-
this.trimEndAborted(charType);
|
|
998
|
-
return this;
|
|
999
|
-
}
|
|
1000
|
-
trimStartAborted(charType) {
|
|
1001
|
-
const rx = new RegExp("^" + (charType || "\\s") + "+");
|
|
1002
|
-
this.intro = this.intro.replace(rx, "");
|
|
1003
|
-
if (this.intro.length) return true;
|
|
1004
|
-
let chunk = this.firstChunk;
|
|
1005
|
-
do {
|
|
1006
|
-
const end = chunk.end;
|
|
1007
|
-
const aborted = chunk.trimStart(rx);
|
|
1008
|
-
if (chunk.end !== end) {
|
|
1009
|
-
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
1010
|
-
this.byEnd[chunk.end] = chunk;
|
|
1011
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
1012
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
1013
|
-
}
|
|
1014
|
-
if (aborted) return true;
|
|
1015
|
-
chunk = chunk.next;
|
|
1016
|
-
} while (chunk);
|
|
1017
|
-
return false;
|
|
1018
|
-
}
|
|
1019
|
-
trimStart(charType) {
|
|
1020
|
-
this.trimStartAborted(charType);
|
|
1021
|
-
return this;
|
|
1022
|
-
}
|
|
1023
|
-
hasChanged() {
|
|
1024
|
-
return this.original !== this.toString();
|
|
1025
|
-
}
|
|
1026
|
-
_replaceRegexp(searchValue, replacement) {
|
|
1027
|
-
function getReplacement(match, str) {
|
|
1028
|
-
if (typeof replacement === "string") {
|
|
1029
|
-
return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
1030
|
-
if (i === "$") return "$";
|
|
1031
|
-
if (i === "&") return match[0];
|
|
1032
|
-
const num = +i;
|
|
1033
|
-
if (num < match.length) return match[+i];
|
|
1034
|
-
return `$${i}`;
|
|
1035
|
-
});
|
|
1036
|
-
} else {
|
|
1037
|
-
return replacement(...match, match.index, str, match.groups);
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
__name(getReplacement, "getReplacement");
|
|
1041
|
-
function matchAll(re, str) {
|
|
1042
|
-
let match;
|
|
1043
|
-
const matches = [];
|
|
1044
|
-
while (match = re.exec(str)) {
|
|
1045
|
-
matches.push(match);
|
|
1046
|
-
}
|
|
1047
|
-
return matches;
|
|
1048
|
-
}
|
|
1049
|
-
__name(matchAll, "matchAll");
|
|
1050
|
-
if (searchValue.global) {
|
|
1051
|
-
const matches = matchAll(searchValue, this.original);
|
|
1052
|
-
matches.forEach((match) => {
|
|
1053
|
-
if (match.index != null) {
|
|
1054
|
-
const replacement2 = getReplacement(match, this.original);
|
|
1055
|
-
if (replacement2 !== match[0]) {
|
|
1056
|
-
this.overwrite(match.index, match.index + match[0].length, replacement2);
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
});
|
|
1060
|
-
} else {
|
|
1061
|
-
const match = this.original.match(searchValue);
|
|
1062
|
-
if (match && match.index != null) {
|
|
1063
|
-
const replacement2 = getReplacement(match, this.original);
|
|
1064
|
-
if (replacement2 !== match[0]) {
|
|
1065
|
-
this.overwrite(match.index, match.index + match[0].length, replacement2);
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
return this;
|
|
1070
|
-
}
|
|
1071
|
-
_replaceString(string, replacement) {
|
|
1072
|
-
const { original } = this;
|
|
1073
|
-
const index = original.indexOf(string);
|
|
1074
|
-
if (index !== -1) {
|
|
1075
|
-
if (typeof replacement === "function") {
|
|
1076
|
-
replacement = replacement(string, index, original);
|
|
1077
|
-
}
|
|
1078
|
-
if (string !== replacement) {
|
|
1079
|
-
this.overwrite(index, index + string.length, replacement);
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
return this;
|
|
1083
|
-
}
|
|
1084
|
-
replace(searchValue, replacement) {
|
|
1085
|
-
if (typeof searchValue === "string") {
|
|
1086
|
-
return this._replaceString(searchValue, replacement);
|
|
1087
|
-
}
|
|
1088
|
-
return this._replaceRegexp(searchValue, replacement);
|
|
1089
|
-
}
|
|
1090
|
-
_replaceAllString(string, replacement) {
|
|
1091
|
-
const { original } = this;
|
|
1092
|
-
const stringLength = string.length;
|
|
1093
|
-
for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
|
|
1094
|
-
const previous = original.slice(index, index + stringLength);
|
|
1095
|
-
let _replacement = replacement;
|
|
1096
|
-
if (typeof replacement === "function") {
|
|
1097
|
-
_replacement = replacement(previous, index, original);
|
|
1098
|
-
}
|
|
1099
|
-
if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
|
|
1100
|
-
}
|
|
1101
|
-
return this;
|
|
1102
|
-
}
|
|
1103
|
-
replaceAll(searchValue, replacement) {
|
|
1104
|
-
if (typeof searchValue === "string") {
|
|
1105
|
-
return this._replaceAllString(searchValue, replacement);
|
|
1106
|
-
}
|
|
1107
|
-
if (!searchValue.global) {
|
|
1108
|
-
throw new TypeError(
|
|
1109
|
-
"MagicString.prototype.replaceAll called with a non-global RegExp argument"
|
|
1110
|
-
);
|
|
1111
|
-
}
|
|
1112
|
-
return this._replaceRegexp(searchValue, replacement);
|
|
1113
|
-
}
|
|
1114
|
-
};
|
|
1115
|
-
|
|
1116
|
-
// src/core-server/presets/vitePlugins/vite-inject-mocker/constants.ts
|
|
1117
|
-
var __STORYBOOK_GLOBAL_THIS_ACCESSOR__ = "__vitest_mocker__";
|
|
1118
|
-
|
|
1119
|
-
// src/core-server/mocking-utils/esmWalker.ts
|
|
1120
|
-
function getArbitraryModuleIdentifier(node) {
|
|
1121
|
-
return node.type === "Identifier" ? node.name : node.raw;
|
|
1122
|
-
}
|
|
1123
|
-
__name(getArbitraryModuleIdentifier, "getArbitraryModuleIdentifier");
|
|
1124
|
-
|
|
1125
|
-
// src/core-server/mocking-utils/automock.ts
|
|
1126
|
-
function getAutomockCode(originalCode, isSpy, parse) {
|
|
1127
|
-
const mocked = automockModule(originalCode, isSpy ? "autospy" : "automock", parse, {
|
|
1128
|
-
globalThisAccessor: JSON.stringify(__STORYBOOK_GLOBAL_THIS_ACCESSOR__)
|
|
1129
|
-
});
|
|
1130
|
-
return mocked;
|
|
1131
|
-
}
|
|
1132
|
-
__name(getAutomockCode, "getAutomockCode");
|
|
1133
|
-
function automockModule(code, mockType, parse, options = {}) {
|
|
1134
|
-
const globalThisAccessor = options.globalThisAccessor || '"__vitest_mocker__"';
|
|
1135
|
-
const ast = parse(code);
|
|
1136
|
-
const m = new MagicString(code);
|
|
1137
|
-
const allSpecifiers = [];
|
|
1138
|
-
let importIndex = 0;
|
|
1139
|
-
for (const _node of ast.body) {
|
|
1140
|
-
if (_node.type === "ExportAllDeclaration") {
|
|
1141
|
-
throw new Error(
|
|
1142
|
-
`automocking files with \`export *\` is not supported in browser mode because it cannot be statically analysed`
|
|
1143
|
-
);
|
|
1144
|
-
}
|
|
1145
|
-
if (_node.type === "ExportNamedDeclaration") {
|
|
1146
|
-
let traversePattern2 = function(expression) {
|
|
1147
|
-
if (expression.type === "Identifier") {
|
|
1148
|
-
allSpecifiers.push({ name: expression.name });
|
|
1149
|
-
} else if (expression.type === "ArrayPattern") {
|
|
1150
|
-
expression.elements.forEach((element) => {
|
|
1151
|
-
if (!element) {
|
|
1152
|
-
return;
|
|
1153
|
-
}
|
|
1154
|
-
traversePattern2(element);
|
|
1155
|
-
});
|
|
1156
|
-
} else if (expression.type === "ObjectPattern") {
|
|
1157
|
-
expression.properties.forEach((property) => {
|
|
1158
|
-
if (property.type === "RestElement") {
|
|
1159
|
-
traversePattern2(property);
|
|
1160
|
-
} else if (property.type === "Property") {
|
|
1161
|
-
traversePattern2(property.value);
|
|
1162
|
-
} else {
|
|
1163
|
-
property;
|
|
1164
|
-
}
|
|
1165
|
-
});
|
|
1166
|
-
} else if (expression.type === "RestElement") {
|
|
1167
|
-
traversePattern2(expression.argument);
|
|
1168
|
-
} else if (expression.type === "AssignmentPattern") {
|
|
1169
|
-
throw new Error(`AssignmentPattern is not supported. Please open a new bug report.`);
|
|
1170
|
-
} else if (expression.type === "MemberExpression") {
|
|
1171
|
-
throw new Error(`MemberExpression is not supported. Please open a new bug report.`);
|
|
1172
|
-
} else {
|
|
1173
|
-
expression;
|
|
1174
|
-
}
|
|
1175
|
-
};
|
|
1176
|
-
var traversePattern = traversePattern2;
|
|
1177
|
-
__name(traversePattern2, "traversePattern");
|
|
1178
|
-
const node = _node;
|
|
1179
|
-
const declaration = node.declaration;
|
|
1180
|
-
if (declaration) {
|
|
1181
|
-
if (declaration.type === "FunctionDeclaration") {
|
|
1182
|
-
allSpecifiers.push({ name: declaration.id.name });
|
|
1183
|
-
} else if (declaration.type === "VariableDeclaration") {
|
|
1184
|
-
declaration.declarations.forEach((declaration2) => {
|
|
1185
|
-
traversePattern2(declaration2.id);
|
|
1186
|
-
});
|
|
1187
|
-
} else if (declaration.type === "ClassDeclaration") {
|
|
1188
|
-
allSpecifiers.push({ name: declaration.id.name });
|
|
1189
|
-
} else {
|
|
1190
|
-
declaration;
|
|
1191
|
-
}
|
|
1192
|
-
m.remove(node.start, declaration.start);
|
|
1193
|
-
}
|
|
1194
|
-
const specifiers = node.specifiers || [];
|
|
1195
|
-
const source = node.source;
|
|
1196
|
-
if (!source && specifiers.length) {
|
|
1197
|
-
specifiers.forEach((specifier) => {
|
|
1198
|
-
allSpecifiers.push({
|
|
1199
|
-
alias: getArbitraryModuleIdentifier(specifier.exported),
|
|
1200
|
-
name: getArbitraryModuleIdentifier(specifier.local)
|
|
1201
|
-
});
|
|
1202
|
-
});
|
|
1203
|
-
m.remove(node.start, node.end);
|
|
1204
|
-
} else if (source && specifiers.length) {
|
|
1205
|
-
const importNames = [];
|
|
1206
|
-
specifiers.forEach((specifier) => {
|
|
1207
|
-
const importedName = `__vitest_imported_${importIndex++}__`;
|
|
1208
|
-
importNames.push([getArbitraryModuleIdentifier(specifier.local), importedName]);
|
|
1209
|
-
allSpecifiers.push({
|
|
1210
|
-
name: importedName,
|
|
1211
|
-
alias: getArbitraryModuleIdentifier(specifier.exported)
|
|
1212
|
-
});
|
|
1213
|
-
});
|
|
1214
|
-
const importString = `import { ${importNames.map(([name, alias]) => `${name} as ${alias}`).join(", ")} } from '${source.value}'`;
|
|
1215
|
-
m.overwrite(node.start, node.end, importString);
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
if (_node.type === "ExportDefaultDeclaration") {
|
|
1219
|
-
const node = _node;
|
|
1220
|
-
const declaration = node.declaration;
|
|
1221
|
-
allSpecifiers.push({ name: "__vitest_default", alias: "default" });
|
|
1222
|
-
m.overwrite(node.start, declaration.start, `const __vitest_default = `);
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
const moduleObject = `
|
|
1226
|
-
const __vitest_current_es_module__ = {
|
|
1227
|
-
__esModule: true,
|
|
1228
|
-
${allSpecifiers.map(({ name }) => `["${name}"]: ${name},`).join("\n ")}
|
|
1229
|
-
}
|
|
1230
|
-
const __vitest_mocked_module__ = globalThis[${globalThisAccessor}].mockObject(__vitest_current_es_module__, "${mockType}")
|
|
1231
|
-
`;
|
|
1232
|
-
const assigning = allSpecifiers.map(({ name }, index) => {
|
|
1233
|
-
return `const __vitest_mocked_${index}__ = __vitest_mocked_module__["${name}"]`;
|
|
1234
|
-
}).join("\n");
|
|
1235
|
-
const redeclarations = allSpecifiers.map(({ name, alias }, index) => {
|
|
1236
|
-
return ` __vitest_mocked_${index}__ as ${alias || name},`;
|
|
1237
|
-
}).join("\n");
|
|
1238
|
-
const specifiersExports = `
|
|
1239
|
-
export {
|
|
1240
|
-
${redeclarations}
|
|
1241
|
-
}
|
|
1242
|
-
`;
|
|
1243
|
-
m.append(moduleObject + assigning + specifiersExports);
|
|
1244
|
-
return m;
|
|
1245
|
-
}
|
|
1246
|
-
__name(automockModule, "automockModule");
|
|
1247
|
-
|
|
1248
|
-
export {
|
|
1249
|
-
getAutomockCode
|
|
1250
|
-
};
|