@coderline/alphatab 1.7.0-alpha.1529 → 1.7.0-alpha.1536
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/alphaTab.core.min.mjs +2 -2
- package/dist/alphaTab.core.mjs +4 -4
- package/dist/alphaTab.js +4 -4
- package/dist/alphaTab.min.js +2 -2
- package/dist/alphaTab.min.mjs +1 -1
- package/dist/alphaTab.mjs +1 -1
- package/dist/alphaTab.vite.core.js +2388 -0
- package/dist/alphaTab.vite.core.mjs +2363 -0
- package/dist/alphaTab.vite.d.ts +0 -1
- package/dist/alphaTab.vite.js +3 -2723
- package/dist/alphaTab.vite.mjs +2 -2697
- package/dist/alphaTab.webpack.core.js +739 -0
- package/dist/alphaTab.webpack.core.mjs +713 -0
- package/dist/alphaTab.webpack.d.ts +0 -1
- package/dist/alphaTab.webpack.js +3 -759
- package/dist/alphaTab.webpack.mjs +2 -733
- package/dist/alphaTab.worker.min.mjs +1 -1
- package/dist/alphaTab.worker.mjs +1 -1
- package/dist/alphaTab.worklet.min.mjs +1 -1
- package/dist/alphaTab.worklet.mjs +1 -1
- package/package.json +9 -40
package/dist/alphaTab.vite.mjs
CHANGED
|
@@ -1,2699 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* alphaTab v1.7.0-alpha.1529 (develop, build 1529)
|
|
3
|
-
*
|
|
4
|
-
* Copyright © 2025, Daniel Kuschny and Contributors, All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
7
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
8
|
-
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
9
|
-
*
|
|
10
|
-
* Integrated Libraries:
|
|
11
|
-
*
|
|
12
|
-
* Library: TinySoundFont
|
|
13
|
-
* License: MIT
|
|
14
|
-
* Copyright: Copyright (C) 2017, 2018 Bernhard Schelling
|
|
15
|
-
* URL: https://github.com/schellingb/TinySoundFont
|
|
16
|
-
* Purpose: SoundFont loading and Audio Synthesis
|
|
17
|
-
*
|
|
18
|
-
* Library: SFZero
|
|
19
|
-
* License: MIT
|
|
20
|
-
* Copyright: Copyright (C) 2012 Steve Folta ()
|
|
21
|
-
* URL: https://github.com/stevefolta/SFZero
|
|
22
|
-
* Purpose: TinySoundFont is based on SFZEro
|
|
23
|
-
*
|
|
24
|
-
* Library: Haxe Standard Library
|
|
25
|
-
* License: MIT
|
|
26
|
-
* Copyright: Copyright (C)2005-2025 Haxe Foundation
|
|
27
|
-
* URL: https://github.com/HaxeFoundation/haxe/tree/development/std
|
|
28
|
-
* Purpose: XML Parser & Zip Inflate Algorithm
|
|
29
|
-
*
|
|
30
|
-
* Library: SharpZipLib
|
|
31
|
-
* License: MIT
|
|
32
|
-
* Copyright: Copyright © 2000-2018 SharpZipLib Contributors
|
|
33
|
-
* URL: https://github.com/icsharpcode/SharpZipLib
|
|
34
|
-
* Purpose: Zip Deflate Algorithm for writing compressed Zips
|
|
35
|
-
*
|
|
36
|
-
* Library: NVorbis
|
|
37
|
-
* License: MIT
|
|
38
|
-
* Copyright: Copyright (c) 2020 Andrew Ward
|
|
39
|
-
* URL: https://github.com/NVorbis/NVorbis
|
|
40
|
-
* Purpose: Vorbis Stream Decoding
|
|
41
|
-
*
|
|
42
|
-
* Library: libvorbis
|
|
43
|
-
* License: BSD-3-Clause
|
|
44
|
-
* Copyright: Copyright (c) 2002-2020 Xiph.org Foundation
|
|
45
|
-
* URL: https://github.com/xiph/vorbis
|
|
46
|
-
* Purpose: NVorbis adopted some code from libvorbis.
|
|
47
|
-
*
|
|
48
|
-
* @preserve
|
|
49
|
-
* @license
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
import * as path from 'node:path';
|
|
53
|
-
import path__default from 'node:path';
|
|
54
|
-
import * as fs from 'node:fs';
|
|
55
|
-
import { createHash } from 'node:crypto';
|
|
56
|
-
import { normalizePath, BuildEnvironment } from 'vite';
|
|
57
|
-
import * as url from 'node:url';
|
|
58
|
-
|
|
59
|
-
var sourcemapCodec_umd$1 = {exports: {}};
|
|
60
|
-
|
|
61
|
-
var sourcemapCodec_umd = sourcemapCodec_umd$1.exports;
|
|
62
|
-
|
|
63
|
-
var hasRequiredSourcemapCodec_umd;
|
|
64
|
-
|
|
65
|
-
function requireSourcemapCodec_umd () {
|
|
66
|
-
if (hasRequiredSourcemapCodec_umd) return sourcemapCodec_umd$1.exports;
|
|
67
|
-
hasRequiredSourcemapCodec_umd = 1;
|
|
68
|
-
(function (module, exports) {
|
|
69
|
-
(function (global, factory) {
|
|
70
|
-
factory(exports) ;
|
|
71
|
-
})(sourcemapCodec_umd, (function (exports) {
|
|
72
|
-
const comma = ','.charCodeAt(0);
|
|
73
|
-
const semicolon = ';'.charCodeAt(0);
|
|
74
|
-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
75
|
-
const intToChar = new Uint8Array(64); // 64 possible chars.
|
|
76
|
-
const charToInt = new Uint8Array(128); // z is 122 in ASCII
|
|
77
|
-
for (let i = 0; i < chars.length; i++) {
|
|
78
|
-
const c = chars.charCodeAt(i);
|
|
79
|
-
intToChar[i] = c;
|
|
80
|
-
charToInt[c] = i;
|
|
81
|
-
}
|
|
82
|
-
function decodeInteger(reader, relative) {
|
|
83
|
-
let value = 0;
|
|
84
|
-
let shift = 0;
|
|
85
|
-
let integer = 0;
|
|
86
|
-
do {
|
|
87
|
-
const c = reader.next();
|
|
88
|
-
integer = charToInt[c];
|
|
89
|
-
value |= (integer & 31) << shift;
|
|
90
|
-
shift += 5;
|
|
91
|
-
} while (integer & 32);
|
|
92
|
-
const shouldNegate = value & 1;
|
|
93
|
-
value >>>= 1;
|
|
94
|
-
if (shouldNegate) {
|
|
95
|
-
value = -2147483648 | -value;
|
|
96
|
-
}
|
|
97
|
-
return relative + value;
|
|
98
|
-
}
|
|
99
|
-
function encodeInteger(builder, num, relative) {
|
|
100
|
-
let delta = num - relative;
|
|
101
|
-
delta = delta < 0 ? (-delta << 1) | 1 : delta << 1;
|
|
102
|
-
do {
|
|
103
|
-
let clamped = delta & 0b011111;
|
|
104
|
-
delta >>>= 5;
|
|
105
|
-
if (delta > 0)
|
|
106
|
-
clamped |= 0b100000;
|
|
107
|
-
builder.write(intToChar[clamped]);
|
|
108
|
-
} while (delta > 0);
|
|
109
|
-
return num;
|
|
110
|
-
}
|
|
111
|
-
function hasMoreVlq(reader, max) {
|
|
112
|
-
if (reader.pos >= max)
|
|
113
|
-
return false;
|
|
114
|
-
return reader.peek() !== comma;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const bufLength = 1024 * 16;
|
|
118
|
-
// Provide a fallback for older environments.
|
|
119
|
-
const td = typeof TextDecoder !== 'undefined'
|
|
120
|
-
? /* #__PURE__ */ new TextDecoder()
|
|
121
|
-
: typeof Buffer !== 'undefined'
|
|
122
|
-
? {
|
|
123
|
-
decode(buf) {
|
|
124
|
-
const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
125
|
-
return out.toString();
|
|
126
|
-
},
|
|
127
|
-
}
|
|
128
|
-
: {
|
|
129
|
-
decode(buf) {
|
|
130
|
-
let out = '';
|
|
131
|
-
for (let i = 0; i < buf.length; i++) {
|
|
132
|
-
out += String.fromCharCode(buf[i]);
|
|
133
|
-
}
|
|
134
|
-
return out;
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
class StringWriter {
|
|
138
|
-
constructor() {
|
|
139
|
-
this.pos = 0;
|
|
140
|
-
this.out = '';
|
|
141
|
-
this.buffer = new Uint8Array(bufLength);
|
|
142
|
-
}
|
|
143
|
-
write(v) {
|
|
144
|
-
const { buffer } = this;
|
|
145
|
-
buffer[this.pos++] = v;
|
|
146
|
-
if (this.pos === bufLength) {
|
|
147
|
-
this.out += td.decode(buffer);
|
|
148
|
-
this.pos = 0;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
flush() {
|
|
152
|
-
const { buffer, out, pos } = this;
|
|
153
|
-
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
class StringReader {
|
|
157
|
-
constructor(buffer) {
|
|
158
|
-
this.pos = 0;
|
|
159
|
-
this.buffer = buffer;
|
|
160
|
-
}
|
|
161
|
-
next() {
|
|
162
|
-
return this.buffer.charCodeAt(this.pos++);
|
|
163
|
-
}
|
|
164
|
-
peek() {
|
|
165
|
-
return this.buffer.charCodeAt(this.pos);
|
|
166
|
-
}
|
|
167
|
-
indexOf(char) {
|
|
168
|
-
const { buffer, pos } = this;
|
|
169
|
-
const idx = buffer.indexOf(char, pos);
|
|
170
|
-
return idx === -1 ? buffer.length : idx;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
const EMPTY = [];
|
|
175
|
-
function decodeOriginalScopes(input) {
|
|
176
|
-
const { length } = input;
|
|
177
|
-
const reader = new StringReader(input);
|
|
178
|
-
const scopes = [];
|
|
179
|
-
const stack = [];
|
|
180
|
-
let line = 0;
|
|
181
|
-
for (; reader.pos < length; reader.pos++) {
|
|
182
|
-
line = decodeInteger(reader, line);
|
|
183
|
-
const column = decodeInteger(reader, 0);
|
|
184
|
-
if (!hasMoreVlq(reader, length)) {
|
|
185
|
-
const last = stack.pop();
|
|
186
|
-
last[2] = line;
|
|
187
|
-
last[3] = column;
|
|
188
|
-
continue;
|
|
189
|
-
}
|
|
190
|
-
const kind = decodeInteger(reader, 0);
|
|
191
|
-
const fields = decodeInteger(reader, 0);
|
|
192
|
-
const hasName = fields & 0b0001;
|
|
193
|
-
const scope = (hasName ? [line, column, 0, 0, kind, decodeInteger(reader, 0)] : [line, column, 0, 0, kind]);
|
|
194
|
-
let vars = EMPTY;
|
|
195
|
-
if (hasMoreVlq(reader, length)) {
|
|
196
|
-
vars = [];
|
|
197
|
-
do {
|
|
198
|
-
const varsIndex = decodeInteger(reader, 0);
|
|
199
|
-
vars.push(varsIndex);
|
|
200
|
-
} while (hasMoreVlq(reader, length));
|
|
201
|
-
}
|
|
202
|
-
scope.vars = vars;
|
|
203
|
-
scopes.push(scope);
|
|
204
|
-
stack.push(scope);
|
|
205
|
-
}
|
|
206
|
-
return scopes;
|
|
207
|
-
}
|
|
208
|
-
function encodeOriginalScopes(scopes) {
|
|
209
|
-
const writer = new StringWriter();
|
|
210
|
-
for (let i = 0; i < scopes.length;) {
|
|
211
|
-
i = _encodeOriginalScopes(scopes, i, writer, [0]);
|
|
212
|
-
}
|
|
213
|
-
return writer.flush();
|
|
214
|
-
}
|
|
215
|
-
function _encodeOriginalScopes(scopes, index, writer, state) {
|
|
216
|
-
const scope = scopes[index];
|
|
217
|
-
const { 0: startLine, 1: startColumn, 2: endLine, 3: endColumn, 4: kind, vars } = scope;
|
|
218
|
-
if (index > 0)
|
|
219
|
-
writer.write(comma);
|
|
220
|
-
state[0] = encodeInteger(writer, startLine, state[0]);
|
|
221
|
-
encodeInteger(writer, startColumn, 0);
|
|
222
|
-
encodeInteger(writer, kind, 0);
|
|
223
|
-
const fields = scope.length === 6 ? 0b0001 : 0;
|
|
224
|
-
encodeInteger(writer, fields, 0);
|
|
225
|
-
if (scope.length === 6)
|
|
226
|
-
encodeInteger(writer, scope[5], 0);
|
|
227
|
-
for (const v of vars) {
|
|
228
|
-
encodeInteger(writer, v, 0);
|
|
229
|
-
}
|
|
230
|
-
for (index++; index < scopes.length;) {
|
|
231
|
-
const next = scopes[index];
|
|
232
|
-
const { 0: l, 1: c } = next;
|
|
233
|
-
if (l > endLine || (l === endLine && c >= endColumn)) {
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
index = _encodeOriginalScopes(scopes, index, writer, state);
|
|
237
|
-
}
|
|
238
|
-
writer.write(comma);
|
|
239
|
-
state[0] = encodeInteger(writer, endLine, state[0]);
|
|
240
|
-
encodeInteger(writer, endColumn, 0);
|
|
241
|
-
return index;
|
|
242
|
-
}
|
|
243
|
-
function decodeGeneratedRanges(input) {
|
|
244
|
-
const { length } = input;
|
|
245
|
-
const reader = new StringReader(input);
|
|
246
|
-
const ranges = [];
|
|
247
|
-
const stack = [];
|
|
248
|
-
let genLine = 0;
|
|
249
|
-
let definitionSourcesIndex = 0;
|
|
250
|
-
let definitionScopeIndex = 0;
|
|
251
|
-
let callsiteSourcesIndex = 0;
|
|
252
|
-
let callsiteLine = 0;
|
|
253
|
-
let callsiteColumn = 0;
|
|
254
|
-
let bindingLine = 0;
|
|
255
|
-
let bindingColumn = 0;
|
|
256
|
-
do {
|
|
257
|
-
const semi = reader.indexOf(';');
|
|
258
|
-
let genColumn = 0;
|
|
259
|
-
for (; reader.pos < semi; reader.pos++) {
|
|
260
|
-
genColumn = decodeInteger(reader, genColumn);
|
|
261
|
-
if (!hasMoreVlq(reader, semi)) {
|
|
262
|
-
const last = stack.pop();
|
|
263
|
-
last[2] = genLine;
|
|
264
|
-
last[3] = genColumn;
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
const fields = decodeInteger(reader, 0);
|
|
268
|
-
const hasDefinition = fields & 0b0001;
|
|
269
|
-
const hasCallsite = fields & 0b0010;
|
|
270
|
-
const hasScope = fields & 0b0100;
|
|
271
|
-
let callsite = null;
|
|
272
|
-
let bindings = EMPTY;
|
|
273
|
-
let range;
|
|
274
|
-
if (hasDefinition) {
|
|
275
|
-
const defSourcesIndex = decodeInteger(reader, definitionSourcesIndex);
|
|
276
|
-
definitionScopeIndex = decodeInteger(reader, definitionSourcesIndex === defSourcesIndex ? definitionScopeIndex : 0);
|
|
277
|
-
definitionSourcesIndex = defSourcesIndex;
|
|
278
|
-
range = [genLine, genColumn, 0, 0, defSourcesIndex, definitionScopeIndex];
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
range = [genLine, genColumn, 0, 0];
|
|
282
|
-
}
|
|
283
|
-
range.isScope = !!hasScope;
|
|
284
|
-
if (hasCallsite) {
|
|
285
|
-
const prevCsi = callsiteSourcesIndex;
|
|
286
|
-
const prevLine = callsiteLine;
|
|
287
|
-
callsiteSourcesIndex = decodeInteger(reader, callsiteSourcesIndex);
|
|
288
|
-
const sameSource = prevCsi === callsiteSourcesIndex;
|
|
289
|
-
callsiteLine = decodeInteger(reader, sameSource ? callsiteLine : 0);
|
|
290
|
-
callsiteColumn = decodeInteger(reader, sameSource && prevLine === callsiteLine ? callsiteColumn : 0);
|
|
291
|
-
callsite = [callsiteSourcesIndex, callsiteLine, callsiteColumn];
|
|
292
|
-
}
|
|
293
|
-
range.callsite = callsite;
|
|
294
|
-
if (hasMoreVlq(reader, semi)) {
|
|
295
|
-
bindings = [];
|
|
296
|
-
do {
|
|
297
|
-
bindingLine = genLine;
|
|
298
|
-
bindingColumn = genColumn;
|
|
299
|
-
const expressionsCount = decodeInteger(reader, 0);
|
|
300
|
-
let expressionRanges;
|
|
301
|
-
if (expressionsCount < -1) {
|
|
302
|
-
expressionRanges = [[decodeInteger(reader, 0)]];
|
|
303
|
-
for (let i = -1; i > expressionsCount; i--) {
|
|
304
|
-
const prevBl = bindingLine;
|
|
305
|
-
bindingLine = decodeInteger(reader, bindingLine);
|
|
306
|
-
bindingColumn = decodeInteger(reader, bindingLine === prevBl ? bindingColumn : 0);
|
|
307
|
-
const expression = decodeInteger(reader, 0);
|
|
308
|
-
expressionRanges.push([expression, bindingLine, bindingColumn]);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
expressionRanges = [[expressionsCount]];
|
|
313
|
-
}
|
|
314
|
-
bindings.push(expressionRanges);
|
|
315
|
-
} while (hasMoreVlq(reader, semi));
|
|
316
|
-
}
|
|
317
|
-
range.bindings = bindings;
|
|
318
|
-
ranges.push(range);
|
|
319
|
-
stack.push(range);
|
|
320
|
-
}
|
|
321
|
-
genLine++;
|
|
322
|
-
reader.pos = semi + 1;
|
|
323
|
-
} while (reader.pos < length);
|
|
324
|
-
return ranges;
|
|
325
|
-
}
|
|
326
|
-
function encodeGeneratedRanges(ranges) {
|
|
327
|
-
if (ranges.length === 0)
|
|
328
|
-
return '';
|
|
329
|
-
const writer = new StringWriter();
|
|
330
|
-
for (let i = 0; i < ranges.length;) {
|
|
331
|
-
i = _encodeGeneratedRanges(ranges, i, writer, [0, 0, 0, 0, 0, 0, 0]);
|
|
332
|
-
}
|
|
333
|
-
return writer.flush();
|
|
334
|
-
}
|
|
335
|
-
function _encodeGeneratedRanges(ranges, index, writer, state) {
|
|
336
|
-
const range = ranges[index];
|
|
337
|
-
const { 0: startLine, 1: startColumn, 2: endLine, 3: endColumn, isScope, callsite, bindings, } = range;
|
|
338
|
-
if (state[0] < startLine) {
|
|
339
|
-
catchupLine(writer, state[0], startLine);
|
|
340
|
-
state[0] = startLine;
|
|
341
|
-
state[1] = 0;
|
|
342
|
-
}
|
|
343
|
-
else if (index > 0) {
|
|
344
|
-
writer.write(comma);
|
|
345
|
-
}
|
|
346
|
-
state[1] = encodeInteger(writer, range[1], state[1]);
|
|
347
|
-
const fields = (range.length === 6 ? 0b0001 : 0) | (callsite ? 0b0010 : 0) | (isScope ? 0b0100 : 0);
|
|
348
|
-
encodeInteger(writer, fields, 0);
|
|
349
|
-
if (range.length === 6) {
|
|
350
|
-
const { 4: sourcesIndex, 5: scopesIndex } = range;
|
|
351
|
-
if (sourcesIndex !== state[2]) {
|
|
352
|
-
state[3] = 0;
|
|
353
|
-
}
|
|
354
|
-
state[2] = encodeInteger(writer, sourcesIndex, state[2]);
|
|
355
|
-
state[3] = encodeInteger(writer, scopesIndex, state[3]);
|
|
356
|
-
}
|
|
357
|
-
if (callsite) {
|
|
358
|
-
const { 0: sourcesIndex, 1: callLine, 2: callColumn } = range.callsite;
|
|
359
|
-
if (sourcesIndex !== state[4]) {
|
|
360
|
-
state[5] = 0;
|
|
361
|
-
state[6] = 0;
|
|
362
|
-
}
|
|
363
|
-
else if (callLine !== state[5]) {
|
|
364
|
-
state[6] = 0;
|
|
365
|
-
}
|
|
366
|
-
state[4] = encodeInteger(writer, sourcesIndex, state[4]);
|
|
367
|
-
state[5] = encodeInteger(writer, callLine, state[5]);
|
|
368
|
-
state[6] = encodeInteger(writer, callColumn, state[6]);
|
|
369
|
-
}
|
|
370
|
-
if (bindings) {
|
|
371
|
-
for (const binding of bindings) {
|
|
372
|
-
if (binding.length > 1)
|
|
373
|
-
encodeInteger(writer, -binding.length, 0);
|
|
374
|
-
const expression = binding[0][0];
|
|
375
|
-
encodeInteger(writer, expression, 0);
|
|
376
|
-
let bindingStartLine = startLine;
|
|
377
|
-
let bindingStartColumn = startColumn;
|
|
378
|
-
for (let i = 1; i < binding.length; i++) {
|
|
379
|
-
const expRange = binding[i];
|
|
380
|
-
bindingStartLine = encodeInteger(writer, expRange[1], bindingStartLine);
|
|
381
|
-
bindingStartColumn = encodeInteger(writer, expRange[2], bindingStartColumn);
|
|
382
|
-
encodeInteger(writer, expRange[0], 0);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
for (index++; index < ranges.length;) {
|
|
387
|
-
const next = ranges[index];
|
|
388
|
-
const { 0: l, 1: c } = next;
|
|
389
|
-
if (l > endLine || (l === endLine && c >= endColumn)) {
|
|
390
|
-
break;
|
|
391
|
-
}
|
|
392
|
-
index = _encodeGeneratedRanges(ranges, index, writer, state);
|
|
393
|
-
}
|
|
394
|
-
if (state[0] < endLine) {
|
|
395
|
-
catchupLine(writer, state[0], endLine);
|
|
396
|
-
state[0] = endLine;
|
|
397
|
-
state[1] = 0;
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
writer.write(comma);
|
|
401
|
-
}
|
|
402
|
-
state[1] = encodeInteger(writer, endColumn, state[1]);
|
|
403
|
-
return index;
|
|
404
|
-
}
|
|
405
|
-
function catchupLine(writer, lastLine, line) {
|
|
406
|
-
do {
|
|
407
|
-
writer.write(semicolon);
|
|
408
|
-
} while (++lastLine < line);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
function decode(mappings) {
|
|
412
|
-
const { length } = mappings;
|
|
413
|
-
const reader = new StringReader(mappings);
|
|
414
|
-
const decoded = [];
|
|
415
|
-
let genColumn = 0;
|
|
416
|
-
let sourcesIndex = 0;
|
|
417
|
-
let sourceLine = 0;
|
|
418
|
-
let sourceColumn = 0;
|
|
419
|
-
let namesIndex = 0;
|
|
420
|
-
do {
|
|
421
|
-
const semi = reader.indexOf(';');
|
|
422
|
-
const line = [];
|
|
423
|
-
let sorted = true;
|
|
424
|
-
let lastCol = 0;
|
|
425
|
-
genColumn = 0;
|
|
426
|
-
while (reader.pos < semi) {
|
|
427
|
-
let seg;
|
|
428
|
-
genColumn = decodeInteger(reader, genColumn);
|
|
429
|
-
if (genColumn < lastCol)
|
|
430
|
-
sorted = false;
|
|
431
|
-
lastCol = genColumn;
|
|
432
|
-
if (hasMoreVlq(reader, semi)) {
|
|
433
|
-
sourcesIndex = decodeInteger(reader, sourcesIndex);
|
|
434
|
-
sourceLine = decodeInteger(reader, sourceLine);
|
|
435
|
-
sourceColumn = decodeInteger(reader, sourceColumn);
|
|
436
|
-
if (hasMoreVlq(reader, semi)) {
|
|
437
|
-
namesIndex = decodeInteger(reader, namesIndex);
|
|
438
|
-
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
|
|
439
|
-
}
|
|
440
|
-
else {
|
|
441
|
-
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
seg = [genColumn];
|
|
446
|
-
}
|
|
447
|
-
line.push(seg);
|
|
448
|
-
reader.pos++;
|
|
449
|
-
}
|
|
450
|
-
if (!sorted)
|
|
451
|
-
sort(line);
|
|
452
|
-
decoded.push(line);
|
|
453
|
-
reader.pos = semi + 1;
|
|
454
|
-
} while (reader.pos <= length);
|
|
455
|
-
return decoded;
|
|
456
|
-
}
|
|
457
|
-
function sort(line) {
|
|
458
|
-
line.sort(sortComparator);
|
|
459
|
-
}
|
|
460
|
-
function sortComparator(a, b) {
|
|
461
|
-
return a[0] - b[0];
|
|
462
|
-
}
|
|
463
|
-
function encode(decoded) {
|
|
464
|
-
const writer = new StringWriter();
|
|
465
|
-
let sourcesIndex = 0;
|
|
466
|
-
let sourceLine = 0;
|
|
467
|
-
let sourceColumn = 0;
|
|
468
|
-
let namesIndex = 0;
|
|
469
|
-
for (let i = 0; i < decoded.length; i++) {
|
|
470
|
-
const line = decoded[i];
|
|
471
|
-
if (i > 0)
|
|
472
|
-
writer.write(semicolon);
|
|
473
|
-
if (line.length === 0)
|
|
474
|
-
continue;
|
|
475
|
-
let genColumn = 0;
|
|
476
|
-
for (let j = 0; j < line.length; j++) {
|
|
477
|
-
const segment = line[j];
|
|
478
|
-
if (j > 0)
|
|
479
|
-
writer.write(comma);
|
|
480
|
-
genColumn = encodeInteger(writer, segment[0], genColumn);
|
|
481
|
-
if (segment.length === 1)
|
|
482
|
-
continue;
|
|
483
|
-
sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
|
|
484
|
-
sourceLine = encodeInteger(writer, segment[2], sourceLine);
|
|
485
|
-
sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
|
|
486
|
-
if (segment.length === 4)
|
|
487
|
-
continue;
|
|
488
|
-
namesIndex = encodeInteger(writer, segment[4], namesIndex);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
return writer.flush();
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
exports.decode = decode;
|
|
495
|
-
exports.decodeGeneratedRanges = decodeGeneratedRanges;
|
|
496
|
-
exports.decodeOriginalScopes = decodeOriginalScopes;
|
|
497
|
-
exports.encode = encode;
|
|
498
|
-
exports.encodeGeneratedRanges = encodeGeneratedRanges;
|
|
499
|
-
exports.encodeOriginalScopes = encodeOriginalScopes;
|
|
500
|
-
|
|
501
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
502
|
-
|
|
503
|
-
}));
|
|
504
|
-
|
|
505
|
-
} (sourcemapCodec_umd$1, sourcemapCodec_umd$1.exports));
|
|
506
|
-
return sourcemapCodec_umd$1.exports;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
var sourcemapCodec_umdExports = requireSourcemapCodec_umd();
|
|
510
|
-
|
|
511
|
-
class BitSet {
|
|
512
|
-
constructor(arg) {
|
|
513
|
-
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
add(n) {
|
|
517
|
-
this.bits[n >> 5] |= 1 << (n & 31);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
has(n) {
|
|
521
|
-
return !!(this.bits[n >> 5] & (1 << (n & 31)));
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
class Chunk {
|
|
526
|
-
constructor(start, end, content) {
|
|
527
|
-
this.start = start;
|
|
528
|
-
this.end = end;
|
|
529
|
-
this.original = content;
|
|
530
|
-
|
|
531
|
-
this.intro = '';
|
|
532
|
-
this.outro = '';
|
|
533
|
-
|
|
534
|
-
this.content = content;
|
|
535
|
-
this.storeName = false;
|
|
536
|
-
this.edited = false;
|
|
537
|
-
|
|
538
|
-
{
|
|
539
|
-
this.previous = null;
|
|
540
|
-
this.next = null;
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
appendLeft(content) {
|
|
545
|
-
this.outro += content;
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
appendRight(content) {
|
|
549
|
-
this.intro = this.intro + content;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
clone() {
|
|
553
|
-
const chunk = new Chunk(this.start, this.end, this.original);
|
|
554
|
-
|
|
555
|
-
chunk.intro = this.intro;
|
|
556
|
-
chunk.outro = this.outro;
|
|
557
|
-
chunk.content = this.content;
|
|
558
|
-
chunk.storeName = this.storeName;
|
|
559
|
-
chunk.edited = this.edited;
|
|
560
|
-
|
|
561
|
-
return chunk;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
contains(index) {
|
|
565
|
-
return this.start < index && index < this.end;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
eachNext(fn) {
|
|
569
|
-
let chunk = this;
|
|
570
|
-
while (chunk) {
|
|
571
|
-
fn(chunk);
|
|
572
|
-
chunk = chunk.next;
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
eachPrevious(fn) {
|
|
577
|
-
let chunk = this;
|
|
578
|
-
while (chunk) {
|
|
579
|
-
fn(chunk);
|
|
580
|
-
chunk = chunk.previous;
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
edit(content, storeName, contentOnly) {
|
|
585
|
-
this.content = content;
|
|
586
|
-
if (!contentOnly) {
|
|
587
|
-
this.intro = '';
|
|
588
|
-
this.outro = '';
|
|
589
|
-
}
|
|
590
|
-
this.storeName = storeName;
|
|
591
|
-
|
|
592
|
-
this.edited = true;
|
|
593
|
-
|
|
594
|
-
return this;
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
prependLeft(content) {
|
|
598
|
-
this.outro = content + this.outro;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
prependRight(content) {
|
|
602
|
-
this.intro = content + this.intro;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
reset() {
|
|
606
|
-
this.intro = '';
|
|
607
|
-
this.outro = '';
|
|
608
|
-
if (this.edited) {
|
|
609
|
-
this.content = this.original;
|
|
610
|
-
this.storeName = false;
|
|
611
|
-
this.edited = false;
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
split(index) {
|
|
616
|
-
const sliceIndex = index - this.start;
|
|
617
|
-
|
|
618
|
-
const originalBefore = this.original.slice(0, sliceIndex);
|
|
619
|
-
const originalAfter = this.original.slice(sliceIndex);
|
|
620
|
-
|
|
621
|
-
this.original = originalBefore;
|
|
622
|
-
|
|
623
|
-
const newChunk = new Chunk(index, this.end, originalAfter);
|
|
624
|
-
newChunk.outro = this.outro;
|
|
625
|
-
this.outro = '';
|
|
626
|
-
|
|
627
|
-
this.end = index;
|
|
628
|
-
|
|
629
|
-
if (this.edited) {
|
|
630
|
-
// after split we should save the edit content record into the correct chunk
|
|
631
|
-
// to make sure sourcemap correct
|
|
632
|
-
// For example:
|
|
633
|
-
// ' test'.trim()
|
|
634
|
-
// split -> ' ' + 'test'
|
|
635
|
-
// ✔️ edit -> '' + 'test'
|
|
636
|
-
// ✖️ edit -> 'test' + ''
|
|
637
|
-
// TODO is this block necessary?...
|
|
638
|
-
newChunk.edit('', false);
|
|
639
|
-
this.content = '';
|
|
640
|
-
} else {
|
|
641
|
-
this.content = originalBefore;
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
newChunk.next = this.next;
|
|
645
|
-
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
646
|
-
newChunk.previous = this;
|
|
647
|
-
this.next = newChunk;
|
|
648
|
-
|
|
649
|
-
return newChunk;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
toString() {
|
|
653
|
-
return this.intro + this.content + this.outro;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
trimEnd(rx) {
|
|
657
|
-
this.outro = this.outro.replace(rx, '');
|
|
658
|
-
if (this.outro.length) return true;
|
|
659
|
-
|
|
660
|
-
const trimmed = this.content.replace(rx, '');
|
|
661
|
-
|
|
662
|
-
if (trimmed.length) {
|
|
663
|
-
if (trimmed !== this.content) {
|
|
664
|
-
this.split(this.start + trimmed.length).edit('', undefined, true);
|
|
665
|
-
if (this.edited) {
|
|
666
|
-
// save the change, if it has been edited
|
|
667
|
-
this.edit(trimmed, this.storeName, true);
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
return true;
|
|
671
|
-
} else {
|
|
672
|
-
this.edit('', undefined, true);
|
|
673
|
-
|
|
674
|
-
this.intro = this.intro.replace(rx, '');
|
|
675
|
-
if (this.intro.length) return true;
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
trimStart(rx) {
|
|
680
|
-
this.intro = this.intro.replace(rx, '');
|
|
681
|
-
if (this.intro.length) return true;
|
|
682
|
-
|
|
683
|
-
const trimmed = this.content.replace(rx, '');
|
|
684
|
-
|
|
685
|
-
if (trimmed.length) {
|
|
686
|
-
if (trimmed !== this.content) {
|
|
687
|
-
const newChunk = this.split(this.end - trimmed.length);
|
|
688
|
-
if (this.edited) {
|
|
689
|
-
// save the change, if it has been edited
|
|
690
|
-
newChunk.edit(trimmed, this.storeName, true);
|
|
691
|
-
}
|
|
692
|
-
this.edit('', undefined, true);
|
|
693
|
-
}
|
|
694
|
-
return true;
|
|
695
|
-
} else {
|
|
696
|
-
this.edit('', undefined, true);
|
|
697
|
-
|
|
698
|
-
this.outro = this.outro.replace(rx, '');
|
|
699
|
-
if (this.outro.length) return true;
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
function getBtoa() {
|
|
705
|
-
if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
|
|
706
|
-
return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
|
|
707
|
-
} else if (typeof Buffer === 'function') {
|
|
708
|
-
return (str) => Buffer.from(str, 'utf-8').toString('base64');
|
|
709
|
-
} else {
|
|
710
|
-
return () => {
|
|
711
|
-
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
|
|
712
|
-
};
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
const btoa = /*#__PURE__*/ getBtoa();
|
|
717
|
-
|
|
718
|
-
class SourceMap {
|
|
719
|
-
constructor(properties) {
|
|
720
|
-
this.version = 3;
|
|
721
|
-
this.file = properties.file;
|
|
722
|
-
this.sources = properties.sources;
|
|
723
|
-
this.sourcesContent = properties.sourcesContent;
|
|
724
|
-
this.names = properties.names;
|
|
725
|
-
this.mappings = sourcemapCodec_umdExports.encode(properties.mappings);
|
|
726
|
-
if (typeof properties.x_google_ignoreList !== 'undefined') {
|
|
727
|
-
this.x_google_ignoreList = properties.x_google_ignoreList;
|
|
728
|
-
}
|
|
729
|
-
if (typeof properties.debugId !== 'undefined') {
|
|
730
|
-
this.debugId = properties.debugId;
|
|
731
|
-
}
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
toString() {
|
|
735
|
-
return JSON.stringify(this);
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
toUrl() {
|
|
739
|
-
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
function guessIndent(code) {
|
|
744
|
-
const lines = code.split('\n');
|
|
745
|
-
|
|
746
|
-
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
747
|
-
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
748
|
-
|
|
749
|
-
if (tabbed.length === 0 && spaced.length === 0) {
|
|
750
|
-
return null;
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
// More lines tabbed than spaced? Assume tabs, and
|
|
754
|
-
// default to tabs in the case of a tie (or nothing
|
|
755
|
-
// to go on)
|
|
756
|
-
if (tabbed.length >= spaced.length) {
|
|
757
|
-
return '\t';
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
// Otherwise, we need to guess the multiple
|
|
761
|
-
const min = spaced.reduce((previous, current) => {
|
|
762
|
-
const numSpaces = /^ +/.exec(current)[0].length;
|
|
763
|
-
return Math.min(numSpaces, previous);
|
|
764
|
-
}, Infinity);
|
|
765
|
-
|
|
766
|
-
return new Array(min + 1).join(' ');
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
function getRelativePath(from, to) {
|
|
770
|
-
const fromParts = from.split(/[/\\]/);
|
|
771
|
-
const toParts = to.split(/[/\\]/);
|
|
772
|
-
|
|
773
|
-
fromParts.pop(); // get dirname
|
|
774
|
-
|
|
775
|
-
while (fromParts[0] === toParts[0]) {
|
|
776
|
-
fromParts.shift();
|
|
777
|
-
toParts.shift();
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
if (fromParts.length) {
|
|
781
|
-
let i = fromParts.length;
|
|
782
|
-
while (i--) fromParts[i] = '..';
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
return fromParts.concat(toParts).join('/');
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
const toString = Object.prototype.toString;
|
|
789
|
-
|
|
790
|
-
function isObject(thing) {
|
|
791
|
-
return toString.call(thing) === '[object Object]';
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
function getLocator(source) {
|
|
795
|
-
const originalLines = source.split('\n');
|
|
796
|
-
const lineOffsets = [];
|
|
797
|
-
|
|
798
|
-
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
799
|
-
lineOffsets.push(pos);
|
|
800
|
-
pos += originalLines[i].length + 1;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
return function locate(index) {
|
|
804
|
-
let i = 0;
|
|
805
|
-
let j = lineOffsets.length;
|
|
806
|
-
while (i < j) {
|
|
807
|
-
const m = (i + j) >> 1;
|
|
808
|
-
if (index < lineOffsets[m]) {
|
|
809
|
-
j = m;
|
|
810
|
-
} else {
|
|
811
|
-
i = m + 1;
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
const line = i - 1;
|
|
815
|
-
const column = index - lineOffsets[line];
|
|
816
|
-
return { line, column };
|
|
817
|
-
};
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
const wordRegex = /\w/;
|
|
821
|
-
|
|
822
|
-
class Mappings {
|
|
823
|
-
constructor(hires) {
|
|
824
|
-
this.hires = hires;
|
|
825
|
-
this.generatedCodeLine = 0;
|
|
826
|
-
this.generatedCodeColumn = 0;
|
|
827
|
-
this.raw = [];
|
|
828
|
-
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
829
|
-
this.pending = null;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
833
|
-
if (content.length) {
|
|
834
|
-
const contentLengthMinusOne = content.length - 1;
|
|
835
|
-
let contentLineEnd = content.indexOf('\n', 0);
|
|
836
|
-
let previousContentLineEnd = -1;
|
|
837
|
-
// Loop through each line in the content and add a segment, but stop if the last line is empty,
|
|
838
|
-
// else code afterwards would fill one line too many
|
|
839
|
-
while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
|
|
840
|
-
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
841
|
-
if (nameIndex >= 0) {
|
|
842
|
-
segment.push(nameIndex);
|
|
843
|
-
}
|
|
844
|
-
this.rawSegments.push(segment);
|
|
845
|
-
|
|
846
|
-
this.generatedCodeLine += 1;
|
|
847
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
848
|
-
this.generatedCodeColumn = 0;
|
|
849
|
-
|
|
850
|
-
previousContentLineEnd = contentLineEnd;
|
|
851
|
-
contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
855
|
-
if (nameIndex >= 0) {
|
|
856
|
-
segment.push(nameIndex);
|
|
857
|
-
}
|
|
858
|
-
this.rawSegments.push(segment);
|
|
859
|
-
|
|
860
|
-
this.advance(content.slice(previousContentLineEnd + 1));
|
|
861
|
-
} else if (this.pending) {
|
|
862
|
-
this.rawSegments.push(this.pending);
|
|
863
|
-
this.advance(content);
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
this.pending = null;
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
870
|
-
let originalCharIndex = chunk.start;
|
|
871
|
-
let first = true;
|
|
872
|
-
// when iterating each char, check if it's in a word boundary
|
|
873
|
-
let charInHiresBoundary = false;
|
|
874
|
-
|
|
875
|
-
while (originalCharIndex < chunk.end) {
|
|
876
|
-
if (original[originalCharIndex] === '\n') {
|
|
877
|
-
loc.line += 1;
|
|
878
|
-
loc.column = 0;
|
|
879
|
-
this.generatedCodeLine += 1;
|
|
880
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
881
|
-
this.generatedCodeColumn = 0;
|
|
882
|
-
first = true;
|
|
883
|
-
charInHiresBoundary = false;
|
|
884
|
-
} else {
|
|
885
|
-
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
886
|
-
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
887
|
-
|
|
888
|
-
if (this.hires === 'boundary') {
|
|
889
|
-
// in hires "boundary", group segments per word boundary than per char
|
|
890
|
-
if (wordRegex.test(original[originalCharIndex])) {
|
|
891
|
-
// for first char in the boundary found, start the boundary by pushing a segment
|
|
892
|
-
if (!charInHiresBoundary) {
|
|
893
|
-
this.rawSegments.push(segment);
|
|
894
|
-
charInHiresBoundary = true;
|
|
895
|
-
}
|
|
896
|
-
} else {
|
|
897
|
-
// for non-word char, end the boundary by pushing a segment
|
|
898
|
-
this.rawSegments.push(segment);
|
|
899
|
-
charInHiresBoundary = false;
|
|
900
|
-
}
|
|
901
|
-
} else {
|
|
902
|
-
this.rawSegments.push(segment);
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
|
|
906
|
-
loc.column += 1;
|
|
907
|
-
this.generatedCodeColumn += 1;
|
|
908
|
-
first = false;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
originalCharIndex += 1;
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
this.pending = null;
|
|
915
|
-
}
|
|
916
|
-
|
|
917
|
-
advance(str) {
|
|
918
|
-
if (!str) return;
|
|
919
|
-
|
|
920
|
-
const lines = str.split('\n');
|
|
921
|
-
|
|
922
|
-
if (lines.length > 1) {
|
|
923
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
924
|
-
this.generatedCodeLine++;
|
|
925
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
926
|
-
}
|
|
927
|
-
this.generatedCodeColumn = 0;
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
const n = '\n';
|
|
935
|
-
|
|
936
|
-
const warned = {
|
|
937
|
-
insertLeft: false,
|
|
938
|
-
insertRight: false,
|
|
939
|
-
storeName: false,
|
|
940
|
-
};
|
|
941
|
-
|
|
942
|
-
class MagicString {
|
|
943
|
-
constructor(string, options = {}) {
|
|
944
|
-
const chunk = new Chunk(0, string.length, string);
|
|
945
|
-
|
|
946
|
-
Object.defineProperties(this, {
|
|
947
|
-
original: { writable: true, value: string },
|
|
948
|
-
outro: { writable: true, value: '' },
|
|
949
|
-
intro: { writable: true, value: '' },
|
|
950
|
-
firstChunk: { writable: true, value: chunk },
|
|
951
|
-
lastChunk: { writable: true, value: chunk },
|
|
952
|
-
lastSearchedChunk: { writable: true, value: chunk },
|
|
953
|
-
byStart: { writable: true, value: {} },
|
|
954
|
-
byEnd: { writable: true, value: {} },
|
|
955
|
-
filename: { writable: true, value: options.filename },
|
|
956
|
-
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
|
957
|
-
sourcemapLocations: { writable: true, value: new BitSet() },
|
|
958
|
-
storedNames: { writable: true, value: {} },
|
|
959
|
-
indentStr: { writable: true, value: undefined },
|
|
960
|
-
ignoreList: { writable: true, value: options.ignoreList },
|
|
961
|
-
offset: { writable: true, value: options.offset || 0 },
|
|
962
|
-
});
|
|
963
|
-
|
|
964
|
-
this.byStart[0] = chunk;
|
|
965
|
-
this.byEnd[string.length] = chunk;
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
addSourcemapLocation(char) {
|
|
969
|
-
this.sourcemapLocations.add(char);
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
append(content) {
|
|
973
|
-
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
974
|
-
|
|
975
|
-
this.outro += content;
|
|
976
|
-
return this;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
appendLeft(index, content) {
|
|
980
|
-
index = index + this.offset;
|
|
981
|
-
|
|
982
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
983
|
-
|
|
984
|
-
this._split(index);
|
|
985
|
-
|
|
986
|
-
const chunk = this.byEnd[index];
|
|
987
|
-
|
|
988
|
-
if (chunk) {
|
|
989
|
-
chunk.appendLeft(content);
|
|
990
|
-
} else {
|
|
991
|
-
this.intro += content;
|
|
992
|
-
}
|
|
993
|
-
return this;
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
appendRight(index, content) {
|
|
997
|
-
index = index + this.offset;
|
|
998
|
-
|
|
999
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1000
|
-
|
|
1001
|
-
this._split(index);
|
|
1002
|
-
|
|
1003
|
-
const chunk = this.byStart[index];
|
|
1004
|
-
|
|
1005
|
-
if (chunk) {
|
|
1006
|
-
chunk.appendRight(content);
|
|
1007
|
-
} else {
|
|
1008
|
-
this.outro += content;
|
|
1009
|
-
}
|
|
1010
|
-
return this;
|
|
1011
|
-
}
|
|
1012
|
-
|
|
1013
|
-
clone() {
|
|
1014
|
-
const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
|
|
1015
|
-
|
|
1016
|
-
let originalChunk = this.firstChunk;
|
|
1017
|
-
let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
|
|
1018
|
-
|
|
1019
|
-
while (originalChunk) {
|
|
1020
|
-
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
1021
|
-
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
1022
|
-
|
|
1023
|
-
const nextOriginalChunk = originalChunk.next;
|
|
1024
|
-
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
1025
|
-
|
|
1026
|
-
if (nextClonedChunk) {
|
|
1027
|
-
clonedChunk.next = nextClonedChunk;
|
|
1028
|
-
nextClonedChunk.previous = clonedChunk;
|
|
1029
|
-
|
|
1030
|
-
clonedChunk = nextClonedChunk;
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
originalChunk = nextOriginalChunk;
|
|
1034
|
-
}
|
|
1035
|
-
|
|
1036
|
-
cloned.lastChunk = clonedChunk;
|
|
1037
|
-
|
|
1038
|
-
if (this.indentExclusionRanges) {
|
|
1039
|
-
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
1043
|
-
|
|
1044
|
-
cloned.intro = this.intro;
|
|
1045
|
-
cloned.outro = this.outro;
|
|
1046
|
-
|
|
1047
|
-
return cloned;
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
generateDecodedMap(options) {
|
|
1051
|
-
options = options || {};
|
|
1052
|
-
|
|
1053
|
-
const sourceIndex = 0;
|
|
1054
|
-
const names = Object.keys(this.storedNames);
|
|
1055
|
-
const mappings = new Mappings(options.hires);
|
|
1056
|
-
|
|
1057
|
-
const locate = getLocator(this.original);
|
|
1058
|
-
|
|
1059
|
-
if (this.intro) {
|
|
1060
|
-
mappings.advance(this.intro);
|
|
1061
|
-
}
|
|
1062
|
-
|
|
1063
|
-
this.firstChunk.eachNext((chunk) => {
|
|
1064
|
-
const loc = locate(chunk.start);
|
|
1065
|
-
|
|
1066
|
-
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
1067
|
-
|
|
1068
|
-
if (chunk.edited) {
|
|
1069
|
-
mappings.addEdit(
|
|
1070
|
-
sourceIndex,
|
|
1071
|
-
chunk.content,
|
|
1072
|
-
loc,
|
|
1073
|
-
chunk.storeName ? names.indexOf(chunk.original) : -1,
|
|
1074
|
-
);
|
|
1075
|
-
} else {
|
|
1076
|
-
mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
1077
|
-
}
|
|
1078
|
-
|
|
1079
|
-
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
1080
|
-
});
|
|
1081
|
-
|
|
1082
|
-
return {
|
|
1083
|
-
file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
|
|
1084
|
-
sources: [
|
|
1085
|
-
options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
|
|
1086
|
-
],
|
|
1087
|
-
sourcesContent: options.includeContent ? [this.original] : undefined,
|
|
1088
|
-
names,
|
|
1089
|
-
mappings: mappings.raw,
|
|
1090
|
-
x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
|
|
1091
|
-
};
|
|
1092
|
-
}
|
|
1093
|
-
|
|
1094
|
-
generateMap(options) {
|
|
1095
|
-
return new SourceMap(this.generateDecodedMap(options));
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
_ensureindentStr() {
|
|
1099
|
-
if (this.indentStr === undefined) {
|
|
1100
|
-
this.indentStr = guessIndent(this.original);
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
_getRawIndentString() {
|
|
1105
|
-
this._ensureindentStr();
|
|
1106
|
-
return this.indentStr;
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
getIndentString() {
|
|
1110
|
-
this._ensureindentStr();
|
|
1111
|
-
return this.indentStr === null ? '\t' : this.indentStr;
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
indent(indentStr, options) {
|
|
1115
|
-
const pattern = /^[^\r\n]/gm;
|
|
1116
|
-
|
|
1117
|
-
if (isObject(indentStr)) {
|
|
1118
|
-
options = indentStr;
|
|
1119
|
-
indentStr = undefined;
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
if (indentStr === undefined) {
|
|
1123
|
-
this._ensureindentStr();
|
|
1124
|
-
indentStr = this.indentStr || '\t';
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
if (indentStr === '') return this; // noop
|
|
1128
|
-
|
|
1129
|
-
options = options || {};
|
|
1130
|
-
|
|
1131
|
-
// Process exclusion ranges
|
|
1132
|
-
const isExcluded = {};
|
|
1133
|
-
|
|
1134
|
-
if (options.exclude) {
|
|
1135
|
-
const exclusions =
|
|
1136
|
-
typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
|
|
1137
|
-
exclusions.forEach((exclusion) => {
|
|
1138
|
-
for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
|
|
1139
|
-
isExcluded[i] = true;
|
|
1140
|
-
}
|
|
1141
|
-
});
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
1145
|
-
const replacer = (match) => {
|
|
1146
|
-
if (shouldIndentNextCharacter) return `${indentStr}${match}`;
|
|
1147
|
-
shouldIndentNextCharacter = true;
|
|
1148
|
-
return match;
|
|
1149
|
-
};
|
|
1150
|
-
|
|
1151
|
-
this.intro = this.intro.replace(pattern, replacer);
|
|
1152
|
-
|
|
1153
|
-
let charIndex = 0;
|
|
1154
|
-
let chunk = this.firstChunk;
|
|
1155
|
-
|
|
1156
|
-
while (chunk) {
|
|
1157
|
-
const end = chunk.end;
|
|
1158
|
-
|
|
1159
|
-
if (chunk.edited) {
|
|
1160
|
-
if (!isExcluded[charIndex]) {
|
|
1161
|
-
chunk.content = chunk.content.replace(pattern, replacer);
|
|
1162
|
-
|
|
1163
|
-
if (chunk.content.length) {
|
|
1164
|
-
shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
} else {
|
|
1168
|
-
charIndex = chunk.start;
|
|
1169
|
-
|
|
1170
|
-
while (charIndex < end) {
|
|
1171
|
-
if (!isExcluded[charIndex]) {
|
|
1172
|
-
const char = this.original[charIndex];
|
|
1173
|
-
|
|
1174
|
-
if (char === '\n') {
|
|
1175
|
-
shouldIndentNextCharacter = true;
|
|
1176
|
-
} else if (char !== '\r' && shouldIndentNextCharacter) {
|
|
1177
|
-
shouldIndentNextCharacter = false;
|
|
1178
|
-
|
|
1179
|
-
if (charIndex === chunk.start) {
|
|
1180
|
-
chunk.prependRight(indentStr);
|
|
1181
|
-
} else {
|
|
1182
|
-
this._splitChunk(chunk, charIndex);
|
|
1183
|
-
chunk = chunk.next;
|
|
1184
|
-
chunk.prependRight(indentStr);
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
charIndex += 1;
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
charIndex = chunk.end;
|
|
1194
|
-
chunk = chunk.next;
|
|
1195
|
-
}
|
|
1196
|
-
|
|
1197
|
-
this.outro = this.outro.replace(pattern, replacer);
|
|
1198
|
-
|
|
1199
|
-
return this;
|
|
1200
|
-
}
|
|
1201
|
-
|
|
1202
|
-
insert() {
|
|
1203
|
-
throw new Error(
|
|
1204
|
-
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
|
|
1205
|
-
);
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
|
-
insertLeft(index, content) {
|
|
1209
|
-
if (!warned.insertLeft) {
|
|
1210
|
-
console.warn(
|
|
1211
|
-
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
|
|
1212
|
-
);
|
|
1213
|
-
warned.insertLeft = true;
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
return this.appendLeft(index, content);
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
insertRight(index, content) {
|
|
1220
|
-
if (!warned.insertRight) {
|
|
1221
|
-
console.warn(
|
|
1222
|
-
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
|
|
1223
|
-
);
|
|
1224
|
-
warned.insertRight = true;
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
return this.prependRight(index, content);
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
move(start, end, index) {
|
|
1231
|
-
start = start + this.offset;
|
|
1232
|
-
end = end + this.offset;
|
|
1233
|
-
index = index + this.offset;
|
|
1234
|
-
|
|
1235
|
-
if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
|
|
1236
|
-
|
|
1237
|
-
this._split(start);
|
|
1238
|
-
this._split(end);
|
|
1239
|
-
this._split(index);
|
|
1240
|
-
|
|
1241
|
-
const first = this.byStart[start];
|
|
1242
|
-
const last = this.byEnd[end];
|
|
1243
|
-
|
|
1244
|
-
const oldLeft = first.previous;
|
|
1245
|
-
const oldRight = last.next;
|
|
1246
|
-
|
|
1247
|
-
const newRight = this.byStart[index];
|
|
1248
|
-
if (!newRight && last === this.lastChunk) return this;
|
|
1249
|
-
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
1250
|
-
|
|
1251
|
-
if (oldLeft) oldLeft.next = oldRight;
|
|
1252
|
-
if (oldRight) oldRight.previous = oldLeft;
|
|
1253
|
-
|
|
1254
|
-
if (newLeft) newLeft.next = first;
|
|
1255
|
-
if (newRight) newRight.previous = last;
|
|
1256
|
-
|
|
1257
|
-
if (!first.previous) this.firstChunk = last.next;
|
|
1258
|
-
if (!last.next) {
|
|
1259
|
-
this.lastChunk = first.previous;
|
|
1260
|
-
this.lastChunk.next = null;
|
|
1261
|
-
}
|
|
1262
|
-
|
|
1263
|
-
first.previous = newLeft;
|
|
1264
|
-
last.next = newRight || null;
|
|
1265
|
-
|
|
1266
|
-
if (!newLeft) this.firstChunk = first;
|
|
1267
|
-
if (!newRight) this.lastChunk = last;
|
|
1268
|
-
return this;
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
overwrite(start, end, content, options) {
|
|
1272
|
-
options = options || {};
|
|
1273
|
-
return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
|
|
1274
|
-
}
|
|
1275
|
-
|
|
1276
|
-
update(start, end, content, options) {
|
|
1277
|
-
start = start + this.offset;
|
|
1278
|
-
end = end + this.offset;
|
|
1279
|
-
|
|
1280
|
-
if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
|
|
1281
|
-
|
|
1282
|
-
if (this.original.length !== 0) {
|
|
1283
|
-
while (start < 0) start += this.original.length;
|
|
1284
|
-
while (end < 0) end += this.original.length;
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
if (end > this.original.length) throw new Error('end is out of bounds');
|
|
1288
|
-
if (start === end)
|
|
1289
|
-
throw new Error(
|
|
1290
|
-
'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
|
|
1291
|
-
);
|
|
1292
|
-
|
|
1293
|
-
this._split(start);
|
|
1294
|
-
this._split(end);
|
|
1295
|
-
|
|
1296
|
-
if (options === true) {
|
|
1297
|
-
if (!warned.storeName) {
|
|
1298
|
-
console.warn(
|
|
1299
|
-
'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
|
|
1300
|
-
);
|
|
1301
|
-
warned.storeName = true;
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
options = { storeName: true };
|
|
1305
|
-
}
|
|
1306
|
-
const storeName = options !== undefined ? options.storeName : false;
|
|
1307
|
-
const overwrite = options !== undefined ? options.overwrite : false;
|
|
1308
|
-
|
|
1309
|
-
if (storeName) {
|
|
1310
|
-
const original = this.original.slice(start, end);
|
|
1311
|
-
Object.defineProperty(this.storedNames, original, {
|
|
1312
|
-
writable: true,
|
|
1313
|
-
value: true,
|
|
1314
|
-
enumerable: true,
|
|
1315
|
-
});
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
const first = this.byStart[start];
|
|
1319
|
-
const last = this.byEnd[end];
|
|
1320
|
-
|
|
1321
|
-
if (first) {
|
|
1322
|
-
let chunk = first;
|
|
1323
|
-
while (chunk !== last) {
|
|
1324
|
-
if (chunk.next !== this.byStart[chunk.end]) {
|
|
1325
|
-
throw new Error('Cannot overwrite across a split point');
|
|
1326
|
-
}
|
|
1327
|
-
chunk = chunk.next;
|
|
1328
|
-
chunk.edit('', false);
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
first.edit(content, storeName, !overwrite);
|
|
1332
|
-
} else {
|
|
1333
|
-
// must be inserting at the end
|
|
1334
|
-
const newChunk = new Chunk(start, end, '').edit(content, storeName);
|
|
1335
|
-
|
|
1336
|
-
// TODO last chunk in the array may not be the last chunk, if it's moved...
|
|
1337
|
-
last.next = newChunk;
|
|
1338
|
-
newChunk.previous = last;
|
|
1339
|
-
}
|
|
1340
|
-
return this;
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
prepend(content) {
|
|
1344
|
-
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
1345
|
-
|
|
1346
|
-
this.intro = content + this.intro;
|
|
1347
|
-
return this;
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
prependLeft(index, content) {
|
|
1351
|
-
index = index + this.offset;
|
|
1352
|
-
|
|
1353
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1354
|
-
|
|
1355
|
-
this._split(index);
|
|
1356
|
-
|
|
1357
|
-
const chunk = this.byEnd[index];
|
|
1358
|
-
|
|
1359
|
-
if (chunk) {
|
|
1360
|
-
chunk.prependLeft(content);
|
|
1361
|
-
} else {
|
|
1362
|
-
this.intro = content + this.intro;
|
|
1363
|
-
}
|
|
1364
|
-
return this;
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
prependRight(index, content) {
|
|
1368
|
-
index = index + this.offset;
|
|
1369
|
-
|
|
1370
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1371
|
-
|
|
1372
|
-
this._split(index);
|
|
1373
|
-
|
|
1374
|
-
const chunk = this.byStart[index];
|
|
1375
|
-
|
|
1376
|
-
if (chunk) {
|
|
1377
|
-
chunk.prependRight(content);
|
|
1378
|
-
} else {
|
|
1379
|
-
this.outro = content + this.outro;
|
|
1380
|
-
}
|
|
1381
|
-
return this;
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
|
-
remove(start, end) {
|
|
1385
|
-
start = start + this.offset;
|
|
1386
|
-
end = end + this.offset;
|
|
1387
|
-
|
|
1388
|
-
if (this.original.length !== 0) {
|
|
1389
|
-
while (start < 0) start += this.original.length;
|
|
1390
|
-
while (end < 0) end += this.original.length;
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
if (start === end) return this;
|
|
1394
|
-
|
|
1395
|
-
if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
|
|
1396
|
-
if (start > end) throw new Error('end must be greater than start');
|
|
1397
|
-
|
|
1398
|
-
this._split(start);
|
|
1399
|
-
this._split(end);
|
|
1400
|
-
|
|
1401
|
-
let chunk = this.byStart[start];
|
|
1402
|
-
|
|
1403
|
-
while (chunk) {
|
|
1404
|
-
chunk.intro = '';
|
|
1405
|
-
chunk.outro = '';
|
|
1406
|
-
chunk.edit('');
|
|
1407
|
-
|
|
1408
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
1409
|
-
}
|
|
1410
|
-
return this;
|
|
1411
|
-
}
|
|
1412
|
-
|
|
1413
|
-
reset(start, end) {
|
|
1414
|
-
start = start + this.offset;
|
|
1415
|
-
end = end + this.offset;
|
|
1416
|
-
|
|
1417
|
-
if (this.original.length !== 0) {
|
|
1418
|
-
while (start < 0) start += this.original.length;
|
|
1419
|
-
while (end < 0) end += this.original.length;
|
|
1420
|
-
}
|
|
1421
|
-
|
|
1422
|
-
if (start === end) return this;
|
|
1423
|
-
|
|
1424
|
-
if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
|
|
1425
|
-
if (start > end) throw new Error('end must be greater than start');
|
|
1426
|
-
|
|
1427
|
-
this._split(start);
|
|
1428
|
-
this._split(end);
|
|
1429
|
-
|
|
1430
|
-
let chunk = this.byStart[start];
|
|
1431
|
-
|
|
1432
|
-
while (chunk) {
|
|
1433
|
-
chunk.reset();
|
|
1434
|
-
|
|
1435
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
1436
|
-
}
|
|
1437
|
-
return this;
|
|
1438
|
-
}
|
|
1439
|
-
|
|
1440
|
-
lastChar() {
|
|
1441
|
-
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
1442
|
-
let chunk = this.lastChunk;
|
|
1443
|
-
do {
|
|
1444
|
-
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
1445
|
-
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
1446
|
-
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
1447
|
-
} while ((chunk = chunk.previous));
|
|
1448
|
-
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
1449
|
-
return '';
|
|
1450
|
-
}
|
|
1451
|
-
|
|
1452
|
-
lastLine() {
|
|
1453
|
-
let lineIndex = this.outro.lastIndexOf(n);
|
|
1454
|
-
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
1455
|
-
let lineStr = this.outro;
|
|
1456
|
-
let chunk = this.lastChunk;
|
|
1457
|
-
do {
|
|
1458
|
-
if (chunk.outro.length > 0) {
|
|
1459
|
-
lineIndex = chunk.outro.lastIndexOf(n);
|
|
1460
|
-
if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
1461
|
-
lineStr = chunk.outro + lineStr;
|
|
1462
|
-
}
|
|
1463
|
-
|
|
1464
|
-
if (chunk.content.length > 0) {
|
|
1465
|
-
lineIndex = chunk.content.lastIndexOf(n);
|
|
1466
|
-
if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
|
|
1467
|
-
lineStr = chunk.content + lineStr;
|
|
1468
|
-
}
|
|
1469
|
-
|
|
1470
|
-
if (chunk.intro.length > 0) {
|
|
1471
|
-
lineIndex = chunk.intro.lastIndexOf(n);
|
|
1472
|
-
if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
1473
|
-
lineStr = chunk.intro + lineStr;
|
|
1474
|
-
}
|
|
1475
|
-
} while ((chunk = chunk.previous));
|
|
1476
|
-
lineIndex = this.intro.lastIndexOf(n);
|
|
1477
|
-
if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
|
|
1478
|
-
return this.intro + lineStr;
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
slice(start = 0, end = this.original.length - this.offset) {
|
|
1482
|
-
start = start + this.offset;
|
|
1483
|
-
end = end + this.offset;
|
|
1484
|
-
|
|
1485
|
-
if (this.original.length !== 0) {
|
|
1486
|
-
while (start < 0) start += this.original.length;
|
|
1487
|
-
while (end < 0) end += this.original.length;
|
|
1488
|
-
}
|
|
1489
|
-
|
|
1490
|
-
let result = '';
|
|
1491
|
-
|
|
1492
|
-
// find start chunk
|
|
1493
|
-
let chunk = this.firstChunk;
|
|
1494
|
-
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
1495
|
-
// found end chunk before start
|
|
1496
|
-
if (chunk.start < end && chunk.end >= end) {
|
|
1497
|
-
return result;
|
|
1498
|
-
}
|
|
1499
|
-
|
|
1500
|
-
chunk = chunk.next;
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
if (chunk && chunk.edited && chunk.start !== start)
|
|
1504
|
-
throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
1505
|
-
|
|
1506
|
-
const startChunk = chunk;
|
|
1507
|
-
while (chunk) {
|
|
1508
|
-
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
|
|
1509
|
-
result += chunk.intro;
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
const containsEnd = chunk.start < end && chunk.end >= end;
|
|
1513
|
-
if (containsEnd && chunk.edited && chunk.end !== end)
|
|
1514
|
-
throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
1515
|
-
|
|
1516
|
-
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
1517
|
-
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
1518
|
-
|
|
1519
|
-
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
1520
|
-
|
|
1521
|
-
if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
|
1522
|
-
result += chunk.outro;
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
if (containsEnd) {
|
|
1526
|
-
break;
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
chunk = chunk.next;
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1532
|
-
return result;
|
|
1533
|
-
}
|
|
1534
|
-
|
|
1535
|
-
// TODO deprecate this? not really very useful
|
|
1536
|
-
snip(start, end) {
|
|
1537
|
-
const clone = this.clone();
|
|
1538
|
-
clone.remove(0, start);
|
|
1539
|
-
clone.remove(end, clone.original.length);
|
|
1540
|
-
|
|
1541
|
-
return clone;
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
_split(index) {
|
|
1545
|
-
if (this.byStart[index] || this.byEnd[index]) return;
|
|
1546
|
-
|
|
1547
|
-
let chunk = this.lastSearchedChunk;
|
|
1548
|
-
const searchForward = index > chunk.end;
|
|
1549
|
-
|
|
1550
|
-
while (chunk) {
|
|
1551
|
-
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
1552
|
-
|
|
1553
|
-
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
_splitChunk(chunk, index) {
|
|
1558
|
-
if (chunk.edited && chunk.content.length) {
|
|
1559
|
-
// zero-length edited chunks are a special case (overlapping replacements)
|
|
1560
|
-
const loc = getLocator(this.original)(index);
|
|
1561
|
-
throw new Error(
|
|
1562
|
-
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
|
|
1563
|
-
);
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
|
-
const newChunk = chunk.split(index);
|
|
1567
|
-
|
|
1568
|
-
this.byEnd[index] = chunk;
|
|
1569
|
-
this.byStart[index] = newChunk;
|
|
1570
|
-
this.byEnd[newChunk.end] = newChunk;
|
|
1571
|
-
|
|
1572
|
-
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
1573
|
-
|
|
1574
|
-
this.lastSearchedChunk = chunk;
|
|
1575
|
-
return true;
|
|
1576
|
-
}
|
|
1577
|
-
|
|
1578
|
-
toString() {
|
|
1579
|
-
let str = this.intro;
|
|
1580
|
-
|
|
1581
|
-
let chunk = this.firstChunk;
|
|
1582
|
-
while (chunk) {
|
|
1583
|
-
str += chunk.toString();
|
|
1584
|
-
chunk = chunk.next;
|
|
1585
|
-
}
|
|
1586
|
-
|
|
1587
|
-
return str + this.outro;
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
isEmpty() {
|
|
1591
|
-
let chunk = this.firstChunk;
|
|
1592
|
-
do {
|
|
1593
|
-
if (
|
|
1594
|
-
(chunk.intro.length && chunk.intro.trim()) ||
|
|
1595
|
-
(chunk.content.length && chunk.content.trim()) ||
|
|
1596
|
-
(chunk.outro.length && chunk.outro.trim())
|
|
1597
|
-
)
|
|
1598
|
-
return false;
|
|
1599
|
-
} while ((chunk = chunk.next));
|
|
1600
|
-
return true;
|
|
1601
|
-
}
|
|
1602
|
-
|
|
1603
|
-
length() {
|
|
1604
|
-
let chunk = this.firstChunk;
|
|
1605
|
-
let length = 0;
|
|
1606
|
-
do {
|
|
1607
|
-
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
1608
|
-
} while ((chunk = chunk.next));
|
|
1609
|
-
return length;
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
trimLines() {
|
|
1613
|
-
return this.trim('[\\r\\n]');
|
|
1614
|
-
}
|
|
1615
|
-
|
|
1616
|
-
trim(charType) {
|
|
1617
|
-
return this.trimStart(charType).trimEnd(charType);
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
trimEndAborted(charType) {
|
|
1621
|
-
const rx = new RegExp((charType || '\\s') + '+$');
|
|
1622
|
-
|
|
1623
|
-
this.outro = this.outro.replace(rx, '');
|
|
1624
|
-
if (this.outro.length) return true;
|
|
1625
|
-
|
|
1626
|
-
let chunk = this.lastChunk;
|
|
1627
|
-
|
|
1628
|
-
do {
|
|
1629
|
-
const end = chunk.end;
|
|
1630
|
-
const aborted = chunk.trimEnd(rx);
|
|
1631
|
-
|
|
1632
|
-
// if chunk was trimmed, we have a new lastChunk
|
|
1633
|
-
if (chunk.end !== end) {
|
|
1634
|
-
if (this.lastChunk === chunk) {
|
|
1635
|
-
this.lastChunk = chunk.next;
|
|
1636
|
-
}
|
|
1637
|
-
|
|
1638
|
-
this.byEnd[chunk.end] = chunk;
|
|
1639
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
1640
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
if (aborted) return true;
|
|
1644
|
-
chunk = chunk.previous;
|
|
1645
|
-
} while (chunk);
|
|
1646
|
-
|
|
1647
|
-
return false;
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
|
-
trimEnd(charType) {
|
|
1651
|
-
this.trimEndAborted(charType);
|
|
1652
|
-
return this;
|
|
1653
|
-
}
|
|
1654
|
-
trimStartAborted(charType) {
|
|
1655
|
-
const rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
1656
|
-
|
|
1657
|
-
this.intro = this.intro.replace(rx, '');
|
|
1658
|
-
if (this.intro.length) return true;
|
|
1659
|
-
|
|
1660
|
-
let chunk = this.firstChunk;
|
|
1661
|
-
|
|
1662
|
-
do {
|
|
1663
|
-
const end = chunk.end;
|
|
1664
|
-
const aborted = chunk.trimStart(rx);
|
|
1665
|
-
|
|
1666
|
-
if (chunk.end !== end) {
|
|
1667
|
-
// special case...
|
|
1668
|
-
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
1669
|
-
|
|
1670
|
-
this.byEnd[chunk.end] = chunk;
|
|
1671
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
1672
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
if (aborted) return true;
|
|
1676
|
-
chunk = chunk.next;
|
|
1677
|
-
} while (chunk);
|
|
1678
|
-
|
|
1679
|
-
return false;
|
|
1680
|
-
}
|
|
1681
|
-
|
|
1682
|
-
trimStart(charType) {
|
|
1683
|
-
this.trimStartAborted(charType);
|
|
1684
|
-
return this;
|
|
1685
|
-
}
|
|
1686
|
-
|
|
1687
|
-
hasChanged() {
|
|
1688
|
-
return this.original !== this.toString();
|
|
1689
|
-
}
|
|
1690
|
-
|
|
1691
|
-
_replaceRegexp(searchValue, replacement) {
|
|
1692
|
-
function getReplacement(match, str) {
|
|
1693
|
-
if (typeof replacement === 'string') {
|
|
1694
|
-
return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
1695
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
|
|
1696
|
-
if (i === '$') return '$';
|
|
1697
|
-
if (i === '&') return match[0];
|
|
1698
|
-
const num = +i;
|
|
1699
|
-
if (num < match.length) return match[+i];
|
|
1700
|
-
return `$${i}`;
|
|
1701
|
-
});
|
|
1702
|
-
} else {
|
|
1703
|
-
return replacement(...match, match.index, str, match.groups);
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
function matchAll(re, str) {
|
|
1707
|
-
let match;
|
|
1708
|
-
const matches = [];
|
|
1709
|
-
while ((match = re.exec(str))) {
|
|
1710
|
-
matches.push(match);
|
|
1711
|
-
}
|
|
1712
|
-
return matches;
|
|
1713
|
-
}
|
|
1714
|
-
if (searchValue.global) {
|
|
1715
|
-
const matches = matchAll(searchValue, this.original);
|
|
1716
|
-
matches.forEach((match) => {
|
|
1717
|
-
if (match.index != null) {
|
|
1718
|
-
const replacement = getReplacement(match, this.original);
|
|
1719
|
-
if (replacement !== match[0]) {
|
|
1720
|
-
this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
1721
|
-
}
|
|
1722
|
-
}
|
|
1723
|
-
});
|
|
1724
|
-
} else {
|
|
1725
|
-
const match = this.original.match(searchValue);
|
|
1726
|
-
if (match && match.index != null) {
|
|
1727
|
-
const replacement = getReplacement(match, this.original);
|
|
1728
|
-
if (replacement !== match[0]) {
|
|
1729
|
-
this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
return this;
|
|
1734
|
-
}
|
|
1735
|
-
|
|
1736
|
-
_replaceString(string, replacement) {
|
|
1737
|
-
const { original } = this;
|
|
1738
|
-
const index = original.indexOf(string);
|
|
1739
|
-
|
|
1740
|
-
if (index !== -1) {
|
|
1741
|
-
this.overwrite(index, index + string.length, replacement);
|
|
1742
|
-
}
|
|
1743
|
-
|
|
1744
|
-
return this;
|
|
1745
|
-
}
|
|
1746
|
-
|
|
1747
|
-
replace(searchValue, replacement) {
|
|
1748
|
-
if (typeof searchValue === 'string') {
|
|
1749
|
-
return this._replaceString(searchValue, replacement);
|
|
1750
|
-
}
|
|
1751
|
-
|
|
1752
|
-
return this._replaceRegexp(searchValue, replacement);
|
|
1753
|
-
}
|
|
1754
|
-
|
|
1755
|
-
_replaceAllString(string, replacement) {
|
|
1756
|
-
const { original } = this;
|
|
1757
|
-
const stringLength = string.length;
|
|
1758
|
-
for (
|
|
1759
|
-
let index = original.indexOf(string);
|
|
1760
|
-
index !== -1;
|
|
1761
|
-
index = original.indexOf(string, index + stringLength)
|
|
1762
|
-
) {
|
|
1763
|
-
const previous = original.slice(index, index + stringLength);
|
|
1764
|
-
if (previous !== replacement) this.overwrite(index, index + stringLength, replacement);
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
return this;
|
|
1768
|
-
}
|
|
1769
|
-
|
|
1770
|
-
replaceAll(searchValue, replacement) {
|
|
1771
|
-
if (typeof searchValue === 'string') {
|
|
1772
|
-
return this._replaceAllString(searchValue, replacement);
|
|
1773
|
-
}
|
|
1774
|
-
|
|
1775
|
-
if (!searchValue.global) {
|
|
1776
|
-
throw new TypeError(
|
|
1777
|
-
'MagicString.prototype.replaceAll called with a non-global RegExp argument',
|
|
1778
|
-
);
|
|
1779
|
-
}
|
|
1780
|
-
|
|
1781
|
-
return this._replaceRegexp(searchValue, replacement);
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
|
|
1785
|
-
/**@target web */
|
|
1786
|
-
// index.ts for more details on contents and license of this file
|
|
1787
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1302
|
|
1788
|
-
function evalValue(rawValue) {
|
|
1789
|
-
const fn = new Function(`
|
|
1790
|
-
var console, exports, global, module, process, require
|
|
1791
|
-
return (\n${rawValue}\n)
|
|
1792
|
-
`);
|
|
1793
|
-
return fn();
|
|
1794
|
-
}
|
|
1795
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/shared/utils.ts#L31-L34
|
|
1796
|
-
const postfixRE = /[?#].*$/;
|
|
1797
|
-
function cleanUrl(url) {
|
|
1798
|
-
return url.replace(postfixRE, '');
|
|
1799
|
-
}
|
|
1800
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L393
|
|
1801
|
-
function tryStatSync(file) {
|
|
1802
|
-
try {
|
|
1803
|
-
// The "throwIfNoEntry" is a performance optimization for cases where the file does not exist
|
|
1804
|
-
return fs.statSync(file, { throwIfNoEntry: false });
|
|
1805
|
-
}
|
|
1806
|
-
catch {
|
|
1807
|
-
}
|
|
1808
|
-
return;
|
|
1809
|
-
}
|
|
1810
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1030
|
|
1811
|
-
function getHash(text, length = 8) {
|
|
1812
|
-
const h = createHash('sha256').update(text).digest('hex').substring(0, length);
|
|
1813
|
-
if (length <= 64) {
|
|
1814
|
-
return h;
|
|
1815
|
-
}
|
|
1816
|
-
return h.padEnd(length, '_');
|
|
1817
|
-
}
|
|
1818
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/shared/utils.ts#L40
|
|
1819
|
-
function withTrailingSlash(path) {
|
|
1820
|
-
if (path[path.length - 1] !== '/') {
|
|
1821
|
-
return `${path}/`;
|
|
1822
|
-
}
|
|
1823
|
-
return path;
|
|
1824
|
-
}
|
|
1825
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1268
|
|
1826
|
-
function joinUrlSegments(a, b) {
|
|
1827
|
-
if (!a || !b) {
|
|
1828
|
-
return a || b || '';
|
|
1829
|
-
}
|
|
1830
|
-
if (a[a.length - 1] === '/') {
|
|
1831
|
-
a = a.substring(0, a.length - 1);
|
|
1832
|
-
}
|
|
1833
|
-
if (b[0] !== '/') {
|
|
1834
|
-
b = `/${b}`;
|
|
1835
|
-
}
|
|
1836
|
-
return a + b;
|
|
1837
|
-
}
|
|
1838
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1281
|
|
1839
|
-
function removeLeadingSlash(str) {
|
|
1840
|
-
return str[0] === '/' ? str.slice(1) : str;
|
|
1841
|
-
}
|
|
1842
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L319
|
|
1843
|
-
function injectQuery(builtUrl, query) {
|
|
1844
|
-
const queryIndex = builtUrl.indexOf('?');
|
|
1845
|
-
return builtUrl + (queryIndex === -1 ? '?' : '&') + query;
|
|
1846
|
-
}
|
|
1847
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1435
|
|
1848
|
-
function partialEncodeURIPath(uri) {
|
|
1849
|
-
if (uri.startsWith('data:')) {
|
|
1850
|
-
return uri;
|
|
1851
|
-
}
|
|
1852
|
-
const filePath = cleanUrl(uri);
|
|
1853
|
-
const postfix = filePath !== uri ? uri.slice(filePath.length) : '';
|
|
1854
|
-
return filePath.replaceAll('%', '%25') + postfix;
|
|
1855
|
-
}
|
|
1856
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/utils.ts#L1424
|
|
1857
|
-
function encodeURIPath(uri) {
|
|
1858
|
-
if (uri.startsWith('data:')) {
|
|
1859
|
-
return uri;
|
|
1860
|
-
}
|
|
1861
|
-
const filePath = cleanUrl(uri);
|
|
1862
|
-
const postfix = filePath !== uri ? uri.slice(filePath.length) : '';
|
|
1863
|
-
return encodeURI(filePath) + postfix;
|
|
1864
|
-
}
|
|
1865
|
-
|
|
1866
|
-
/**@target web */
|
|
1867
|
-
const FS_PREFIX = '/@fs/';
|
|
1868
|
-
async function fileToUrl(id, config) {
|
|
1869
|
-
let rtn;
|
|
1870
|
-
if (id.startsWith(withTrailingSlash(config.root))) {
|
|
1871
|
-
// in project root, infer short public path
|
|
1872
|
-
rtn = `/${path.posix.relative(config.root, id)}`;
|
|
1873
|
-
}
|
|
1874
|
-
else {
|
|
1875
|
-
// outside of project root, use absolute fs path
|
|
1876
|
-
// (this is special handled by the serve static middleware
|
|
1877
|
-
rtn = path.posix.join(FS_PREFIX, id);
|
|
1878
|
-
}
|
|
1879
|
-
const base = joinUrlSegments(config.server?.origin ?? '', config.base);
|
|
1880
|
-
return joinUrlSegments(base, removeLeadingSlash(rtn));
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
/**@target web */
|
|
1884
|
-
// index.ts for more details on contents and license of this file
|
|
1885
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/constants.ts#L143
|
|
1886
|
-
const METADATA_FILENAME = '_metadata.json';
|
|
1887
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/constants.ts#L63
|
|
1888
|
-
const ENV_PUBLIC_PATH = '/@vite/env';
|
|
1889
|
-
// https://github.com/vitejs/vite/blob/v6.1.1/packages/vite/src/node/constants.ts#L10C1-L38C32
|
|
1890
|
-
const ROLLUP_HOOKS = [
|
|
1891
|
-
'options',
|
|
1892
|
-
'buildStart',
|
|
1893
|
-
'buildEnd',
|
|
1894
|
-
'renderStart',
|
|
1895
|
-
'renderError',
|
|
1896
|
-
'renderChunk',
|
|
1897
|
-
'writeBundle',
|
|
1898
|
-
'generateBundle',
|
|
1899
|
-
'banner',
|
|
1900
|
-
'footer',
|
|
1901
|
-
'augmentChunkHash',
|
|
1902
|
-
'outputOptions',
|
|
1903
|
-
'renderDynamicImport',
|
|
1904
|
-
'resolveFileUrl',
|
|
1905
|
-
'resolveImportMeta',
|
|
1906
|
-
'intro',
|
|
1907
|
-
'outro',
|
|
1908
|
-
'closeBundle',
|
|
1909
|
-
'closeWatcher',
|
|
1910
|
-
'load',
|
|
1911
|
-
'moduleParsed',
|
|
1912
|
-
'watchChange',
|
|
1913
|
-
'resolveDynamicImport',
|
|
1914
|
-
'resolveId',
|
|
1915
|
-
'shouldTransformCachedModule',
|
|
1916
|
-
'transform',
|
|
1917
|
-
'onLog'
|
|
1918
|
-
];
|
|
1919
|
-
|
|
1920
|
-
/**@target web */
|
|
1921
|
-
// https://github.com/vitejs/vite/blob/v6.1.1/packages/vite/src/node/plugins/index.ts#L161
|
|
1922
|
-
// biome-ignore lint/complexity/noBannedTypes: Function type needed here
|
|
1923
|
-
function getHookHandler(hook) {
|
|
1924
|
-
return (typeof hook === 'object' ? hook.handler : hook);
|
|
1925
|
-
}
|
|
1926
|
-
|
|
1927
|
-
/**@target web */
|
|
1928
|
-
const needsEscapeRegEx = /[\n\r'\\\u2028\u2029]/;
|
|
1929
|
-
const quoteNewlineRegEx = /([\n\r'\u2028\u2029])/g;
|
|
1930
|
-
const backSlashRegEx = /\\/g;
|
|
1931
|
-
function escapeId(id) {
|
|
1932
|
-
if (!needsEscapeRegEx.test(id)) {
|
|
1933
|
-
return id;
|
|
1934
|
-
}
|
|
1935
|
-
return id.replace(backSlashRegEx, '\\\\').replace(quoteNewlineRegEx, '\\$1');
|
|
1936
|
-
}
|
|
1937
|
-
const getResolveUrl = (path, URL = 'URL') => `new ${URL}(${path}).href`;
|
|
1938
|
-
const getRelativeUrlFromDocument = (relativePath, umd = false) => getResolveUrl(`'${escapeId(partialEncodeURIPath(relativePath))}', ${umd ? `typeof document === 'undefined' ? location.href : ` : ''}document.currentScript && document.currentScript.src || document.baseURI`);
|
|
1939
|
-
const getFileUrlFromFullPath = (path) => `require('u' + 'rl').pathToFileURL(${path}).href`;
|
|
1940
|
-
const getFileUrlFromRelativePath = (path) => getFileUrlFromFullPath(`__dirname + '/${escapeId(path)}'`);
|
|
1941
|
-
const relativeUrlMechanisms = {
|
|
1942
|
-
amd: relativePath => {
|
|
1943
|
-
if (relativePath[0] !== '.') {
|
|
1944
|
-
relativePath = `./${relativePath}`;
|
|
1945
|
-
}
|
|
1946
|
-
return getResolveUrl(`require.toUrl('${escapeId(relativePath)}'), document.baseURI`);
|
|
1947
|
-
},
|
|
1948
|
-
cjs: relativePath => `(typeof document === 'undefined' ? ${getFileUrlFromRelativePath(relativePath)} : ${getRelativeUrlFromDocument(relativePath)})`,
|
|
1949
|
-
es: relativePath => getResolveUrl(`'${escapeId(partialEncodeURIPath(relativePath))}', import.meta.url`),
|
|
1950
|
-
iife: relativePath => getRelativeUrlFromDocument(relativePath),
|
|
1951
|
-
// NOTE: make sure rollup generate `module` params
|
|
1952
|
-
system: relativePath => getResolveUrl(`'${escapeId(partialEncodeURIPath(relativePath))}', module.meta.url`),
|
|
1953
|
-
umd: relativePath => `(typeof document === 'undefined' && typeof location === 'undefined' ? ${getFileUrlFromRelativePath(relativePath)} : ${getRelativeUrlFromDocument(relativePath, true)})`
|
|
1954
|
-
};
|
|
1955
|
-
const customRelativeUrlMechanisms = {
|
|
1956
|
-
...relativeUrlMechanisms,
|
|
1957
|
-
'worker-iife': relativePath => getResolveUrl(`'${escapeId(partialEncodeURIPath(relativePath))}', self.location.href`)
|
|
1958
|
-
};
|
|
1959
|
-
function createToImportMetaURLBasedRelativeRuntime(format, isWorker) {
|
|
1960
|
-
const formatLong = isWorker && format === 'iife' ? 'worker-iife' : format;
|
|
1961
|
-
const toRelativePath = customRelativeUrlMechanisms[formatLong];
|
|
1962
|
-
return (filename, importer) => ({
|
|
1963
|
-
runtime: toRelativePath(path.posix.relative(path.dirname(importer), filename))
|
|
1964
|
-
});
|
|
1965
|
-
}
|
|
1966
|
-
function toOutputFilePathInJS(filename, type, hostId, hostType, config, toRelative) {
|
|
1967
|
-
const { renderBuiltUrl } = config.experimental;
|
|
1968
|
-
let relative = config.base === '' || config.base === '@src/vite/bridge/';
|
|
1969
|
-
if (renderBuiltUrl) {
|
|
1970
|
-
const result = renderBuiltUrl(filename, {
|
|
1971
|
-
hostId,
|
|
1972
|
-
hostType,
|
|
1973
|
-
type,
|
|
1974
|
-
ssr: !!config.build.ssr
|
|
1975
|
-
});
|
|
1976
|
-
if (typeof result === 'object') {
|
|
1977
|
-
if (result.runtime) {
|
|
1978
|
-
return { runtime: result.runtime };
|
|
1979
|
-
}
|
|
1980
|
-
if (typeof result.relative === 'boolean') {
|
|
1981
|
-
relative = result.relative;
|
|
1982
|
-
}
|
|
1983
|
-
}
|
|
1984
|
-
else if (result) {
|
|
1985
|
-
return result;
|
|
1986
|
-
}
|
|
1987
|
-
}
|
|
1988
|
-
if (relative && !config.build.ssr) {
|
|
1989
|
-
return toRelative(filename, hostId);
|
|
1990
|
-
}
|
|
1991
|
-
return joinUrlSegments(config.base, filename);
|
|
1992
|
-
}
|
|
1993
|
-
// https://github.com/vitejs/vite/blob/v6.1.1/packages/vite/src/node/build.ts#L1131
|
|
1994
|
-
function injectEnvironmentToHooks(environment, plugin) {
|
|
1995
|
-
const { resolveId, load, transform } = plugin;
|
|
1996
|
-
const clone = { ...plugin };
|
|
1997
|
-
for (const hook of Object.keys(clone)) {
|
|
1998
|
-
switch (hook) {
|
|
1999
|
-
case 'resolveId':
|
|
2000
|
-
clone[hook] = wrapEnvironmentResolveId(environment, resolveId);
|
|
2001
|
-
break;
|
|
2002
|
-
case 'load':
|
|
2003
|
-
clone[hook] = wrapEnvironmentLoad(environment, load);
|
|
2004
|
-
break;
|
|
2005
|
-
case 'transform':
|
|
2006
|
-
clone[hook] = wrapEnvironmentTransform(environment, transform);
|
|
2007
|
-
break;
|
|
2008
|
-
default:
|
|
2009
|
-
if (ROLLUP_HOOKS.includes(hook)) {
|
|
2010
|
-
clone[hook] = wrapEnvironmentHook(environment, clone[hook]);
|
|
2011
|
-
}
|
|
2012
|
-
break;
|
|
2013
|
-
}
|
|
2014
|
-
}
|
|
2015
|
-
return clone;
|
|
2016
|
-
}
|
|
2017
|
-
function wrapEnvironmentResolveId(environment, hook) {
|
|
2018
|
-
if (!hook) {
|
|
2019
|
-
return;
|
|
2020
|
-
}
|
|
2021
|
-
const fn = getHookHandler(hook);
|
|
2022
|
-
const handler = function (id, importer, options) {
|
|
2023
|
-
return fn.call(injectEnvironmentInContext(this, environment), id, importer, injectSsrFlag(options, environment));
|
|
2024
|
-
};
|
|
2025
|
-
if ('handler' in hook) {
|
|
2026
|
-
return {
|
|
2027
|
-
...hook,
|
|
2028
|
-
handler
|
|
2029
|
-
};
|
|
2030
|
-
}
|
|
2031
|
-
return handler;
|
|
2032
|
-
}
|
|
2033
|
-
function wrapEnvironmentLoad(environment, hook) {
|
|
2034
|
-
if (!hook) {
|
|
2035
|
-
return;
|
|
2036
|
-
}
|
|
2037
|
-
const fn = getHookHandler(hook);
|
|
2038
|
-
const handler = function (id, ...args) {
|
|
2039
|
-
return fn.call(injectEnvironmentInContext(this, environment), id, injectSsrFlag(args[0], environment));
|
|
2040
|
-
};
|
|
2041
|
-
if ('handler' in hook) {
|
|
2042
|
-
return {
|
|
2043
|
-
...hook,
|
|
2044
|
-
handler
|
|
2045
|
-
};
|
|
2046
|
-
}
|
|
2047
|
-
return handler;
|
|
2048
|
-
}
|
|
2049
|
-
function wrapEnvironmentTransform(environment, hook) {
|
|
2050
|
-
if (!hook) {
|
|
2051
|
-
return;
|
|
2052
|
-
}
|
|
2053
|
-
const fn = getHookHandler(hook);
|
|
2054
|
-
const handler = function (code, importer, ...args) {
|
|
2055
|
-
return fn.call(injectEnvironmentInContext(this, environment), code, importer, injectSsrFlag(args[0], environment));
|
|
2056
|
-
};
|
|
2057
|
-
if ('handler' in hook) {
|
|
2058
|
-
return {
|
|
2059
|
-
...hook,
|
|
2060
|
-
handler
|
|
2061
|
-
};
|
|
2062
|
-
}
|
|
2063
|
-
return handler;
|
|
2064
|
-
}
|
|
2065
|
-
function wrapEnvironmentHook(environment, hook) {
|
|
2066
|
-
if (!hook) {
|
|
2067
|
-
return;
|
|
2068
|
-
}
|
|
2069
|
-
const fn = getHookHandler(hook);
|
|
2070
|
-
if (typeof fn !== 'function') {
|
|
2071
|
-
return hook;
|
|
2072
|
-
}
|
|
2073
|
-
const handler = function (...args) {
|
|
2074
|
-
return fn.call(injectEnvironmentInContext(this, environment), ...args);
|
|
2075
|
-
};
|
|
2076
|
-
if ('handler' in hook) {
|
|
2077
|
-
return {
|
|
2078
|
-
...hook,
|
|
2079
|
-
handler
|
|
2080
|
-
};
|
|
2081
|
-
}
|
|
2082
|
-
return handler;
|
|
2083
|
-
}
|
|
2084
|
-
function injectEnvironmentInContext(context, environment) {
|
|
2085
|
-
context.environment ?? (context.environment = environment);
|
|
2086
|
-
return context;
|
|
2087
|
-
}
|
|
2088
|
-
function injectSsrFlag(options, environment) {
|
|
2089
|
-
const ssr = environment ? environment.config.consumer === 'server' : true;
|
|
2090
|
-
return { ...(options ?? {}), ssr };
|
|
2091
|
-
}
|
|
2092
|
-
|
|
2093
|
-
/**@target web */
|
|
2094
|
-
// index.ts for more details on contents and license of this file
|
|
2095
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/fsUtils.ts#L388
|
|
2096
|
-
function tryResolveRealFile(file, preserveSymlinks) {
|
|
2097
|
-
const fileStat = tryStatSync(file);
|
|
2098
|
-
if (fileStat?.isFile()) {
|
|
2099
|
-
return file;
|
|
2100
|
-
}
|
|
2101
|
-
if (fileStat?.isSymbolicLink()) {
|
|
2102
|
-
return preserveSymlinks ? file : fs.realpathSync(file);
|
|
2103
|
-
}
|
|
2104
|
-
return undefined;
|
|
2105
|
-
}
|
|
2106
|
-
|
|
2107
|
-
/**@target web */
|
|
2108
|
-
// index.ts for more details on contents and license of this file
|
|
2109
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/resolve.ts#L534
|
|
2110
|
-
function splitFileAndPostfix(path) {
|
|
2111
|
-
const file = cleanUrl(path);
|
|
2112
|
-
return { file, postfix: path.slice(file.length) };
|
|
2113
|
-
}
|
|
2114
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/resolve.ts#L566-L574
|
|
2115
|
-
function tryFsResolve(fsPath, preserveSymlinks) {
|
|
2116
|
-
const { file, postfix } = splitFileAndPostfix(fsPath);
|
|
2117
|
-
const res = tryCleanFsResolve(file, preserveSymlinks);
|
|
2118
|
-
if (res) {
|
|
2119
|
-
return res + postfix;
|
|
2120
|
-
}
|
|
2121
|
-
return;
|
|
2122
|
-
}
|
|
2123
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/resolve.ts#L580
|
|
2124
|
-
function tryCleanFsResolve(file, preserveSymlinks) {
|
|
2125
|
-
if (file.includes('node_modules')) {
|
|
2126
|
-
return tryResolveRealFile(file, preserveSymlinks);
|
|
2127
|
-
}
|
|
2128
|
-
const normalizedResolved = tryResolveRealFile(normalizePath(file));
|
|
2129
|
-
if (!normalizedResolved) {
|
|
2130
|
-
return tryResolveRealFile(file, preserveSymlinks);
|
|
2131
|
-
}
|
|
2132
|
-
return normalizedResolved;
|
|
2133
|
-
}
|
|
2134
|
-
|
|
2135
|
-
/**@target web */
|
|
2136
|
-
// index.ts for more details on contents and license of this file
|
|
2137
|
-
// https://github.com/Danielku15/vite/blob/88b7def341f12d07d7d4f83cbe3dc73cc8c6b7be/packages/vite/src/node/optimizer/index.ts#L1356
|
|
2138
|
-
function tryOptimizedDepResolve(config, ssr, url, depId, preserveSymlinks) {
|
|
2139
|
-
const optimizer = getDepsOptimizer(config, ssr);
|
|
2140
|
-
if (optimizer?.isOptimizedDepFile(depId)) {
|
|
2141
|
-
const depFile = cleanUrl(depId);
|
|
2142
|
-
const info = optimizedDepInfoFromFile(optimizer.metadata, depFile);
|
|
2143
|
-
const depSrc = info?.src;
|
|
2144
|
-
if (depSrc) {
|
|
2145
|
-
const resolvedFile = path.resolve(path.dirname(depSrc), url);
|
|
2146
|
-
return tryFsResolve(resolvedFile, preserveSymlinks);
|
|
2147
|
-
}
|
|
2148
|
-
}
|
|
2149
|
-
return undefined;
|
|
2150
|
-
}
|
|
2151
|
-
// https://github.com/Danielku15/vite/blob/88b7def341f12d07d7d4f83cbe3dc73cc8c6b7be/packages/vite/src/node/optimizer/optimizer.ts#L32-L40
|
|
2152
|
-
const depsOptimizerMap = new WeakMap();
|
|
2153
|
-
const devSsrDepsOptimizerMap = new WeakMap();
|
|
2154
|
-
function getDepsOptimizer(config, ssr) {
|
|
2155
|
-
const map = ssr ? devSsrDepsOptimizerMap : depsOptimizerMap;
|
|
2156
|
-
let optimizer = map.get(config);
|
|
2157
|
-
if (!optimizer) {
|
|
2158
|
-
optimizer = createDepsOptimizer(config);
|
|
2159
|
-
map.set(config, optimizer);
|
|
2160
|
-
}
|
|
2161
|
-
return optimizer;
|
|
2162
|
-
}
|
|
2163
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/optimizer/optimizer.ts#L79
|
|
2164
|
-
function createDepsOptimizer(config) {
|
|
2165
|
-
const depsCacheDirPrefix = normalizePath(path.resolve(config.cacheDir, 'deps'));
|
|
2166
|
-
const metadata = parseDepsOptimizerMetadata(fs.readFileSync(path.join(depsCacheDirPrefix, METADATA_FILENAME), 'utf8'), depsCacheDirPrefix);
|
|
2167
|
-
const notImplemented = () => {
|
|
2168
|
-
throw new Error('not implemented');
|
|
2169
|
-
};
|
|
2170
|
-
const depsOptimizer = {
|
|
2171
|
-
async init() {
|
|
2172
|
-
},
|
|
2173
|
-
metadata,
|
|
2174
|
-
registerMissingImport: notImplemented,
|
|
2175
|
-
run: notImplemented,
|
|
2176
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/optimizer/index.ts#L916
|
|
2177
|
-
isOptimizedDepFile: id => id.startsWith(depsCacheDirPrefix),
|
|
2178
|
-
isOptimizedDepUrl: notImplemented,
|
|
2179
|
-
getOptimizedDepId: notImplemented,
|
|
2180
|
-
close: notImplemented,
|
|
2181
|
-
options: {}
|
|
2182
|
-
};
|
|
2183
|
-
return depsOptimizer;
|
|
2184
|
-
}
|
|
2185
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/optimizer/index.ts#L944
|
|
2186
|
-
function parseDepsOptimizerMetadata(jsonMetadata, depsCacheDir) {
|
|
2187
|
-
const { hash, lockfileHash, configHash, browserHash, optimized, chunks } = JSON.parse(jsonMetadata, (key, value) => {
|
|
2188
|
-
if (key === 'file' || key === 'src') {
|
|
2189
|
-
return normalizePath(path.resolve(depsCacheDir, value));
|
|
2190
|
-
}
|
|
2191
|
-
return value;
|
|
2192
|
-
});
|
|
2193
|
-
if (!chunks || Object.values(optimized).some(depInfo => !depInfo.fileHash)) {
|
|
2194
|
-
// outdated _metadata.json version, ignore
|
|
2195
|
-
return;
|
|
2196
|
-
}
|
|
2197
|
-
const metadata = {
|
|
2198
|
-
hash,
|
|
2199
|
-
lockfileHash,
|
|
2200
|
-
configHash,
|
|
2201
|
-
browserHash,
|
|
2202
|
-
optimized: {},
|
|
2203
|
-
discovered: {},
|
|
2204
|
-
chunks: {},
|
|
2205
|
-
depInfoList: []
|
|
2206
|
-
};
|
|
2207
|
-
for (const id of Object.keys(optimized)) {
|
|
2208
|
-
addOptimizedDepInfo(metadata, 'optimized', {
|
|
2209
|
-
...optimized[id],
|
|
2210
|
-
id,
|
|
2211
|
-
browserHash
|
|
2212
|
-
});
|
|
2213
|
-
}
|
|
2214
|
-
for (const id of Object.keys(chunks)) {
|
|
2215
|
-
addOptimizedDepInfo(metadata, 'chunks', {
|
|
2216
|
-
...chunks[id],
|
|
2217
|
-
id,
|
|
2218
|
-
browserHash,
|
|
2219
|
-
needsInterop: false
|
|
2220
|
-
});
|
|
2221
|
-
}
|
|
2222
|
-
return metadata;
|
|
2223
|
-
}
|
|
2224
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/optimizer/index.ts#L322
|
|
2225
|
-
function addOptimizedDepInfo(metadata, type, depInfo) {
|
|
2226
|
-
metadata[type][depInfo.id] = depInfo;
|
|
2227
|
-
metadata.depInfoList.push(depInfo);
|
|
2228
|
-
return depInfo;
|
|
2229
|
-
}
|
|
2230
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/optimizer/index.ts#L1248
|
|
2231
|
-
function optimizedDepInfoFromFile(metadata, file) {
|
|
2232
|
-
return metadata.depInfoList.find(depInfo => depInfo.file === file);
|
|
2233
|
-
}
|
|
2234
|
-
|
|
2235
|
-
/**@target web */
|
|
2236
|
-
// biome-ignore lint/suspicious/noConstEnum: Exception where we use them
|
|
2237
|
-
var AlphaTabWorkerTypes;
|
|
2238
|
-
(function (AlphaTabWorkerTypes) {
|
|
2239
|
-
AlphaTabWorkerTypes["WorkerClassic"] = "worker_classic";
|
|
2240
|
-
AlphaTabWorkerTypes["WorkerModule"] = "worker_module";
|
|
2241
|
-
AlphaTabWorkerTypes["AudioWorklet"] = "audio_worklet";
|
|
2242
|
-
})(AlphaTabWorkerTypes || (AlphaTabWorkerTypes = {}));
|
|
2243
|
-
const workerCache = new WeakMap();
|
|
2244
|
-
const WORKER_FILE_ID = 'alphatab_worker';
|
|
2245
|
-
const WORKER_ASSET_ID = '__ALPHATAB_WORKER_ASSET__';
|
|
2246
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L47
|
|
2247
|
-
function saveEmitWorkerAsset(config, asset) {
|
|
2248
|
-
const workerMap = workerCache.get(config.mainConfig || config);
|
|
2249
|
-
workerMap.assets.set(asset.fileName, asset);
|
|
2250
|
-
}
|
|
2251
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L161
|
|
2252
|
-
async function workerFileToUrl(config, id) {
|
|
2253
|
-
const workerMap = workerCache.get(config.mainConfig || config);
|
|
2254
|
-
let fileName = workerMap.bundle.get(id);
|
|
2255
|
-
if (!fileName) {
|
|
2256
|
-
const outputChunk = await bundleWorkerEntry(config, id);
|
|
2257
|
-
fileName = outputChunk.fileName;
|
|
2258
|
-
saveEmitWorkerAsset(config, {
|
|
2259
|
-
fileName,
|
|
2260
|
-
source: outputChunk.code
|
|
2261
|
-
});
|
|
2262
|
-
workerMap.bundle.set(id, fileName);
|
|
2263
|
-
}
|
|
2264
|
-
return encodeWorkerAssetFileName(fileName, workerMap);
|
|
2265
|
-
}
|
|
2266
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L149
|
|
2267
|
-
function encodeWorkerAssetFileName(fileName, workerCache) {
|
|
2268
|
-
const { fileNameHash } = workerCache;
|
|
2269
|
-
const hash = getHash(fileName);
|
|
2270
|
-
if (!fileNameHash.get(hash)) {
|
|
2271
|
-
fileNameHash.set(hash, fileName);
|
|
2272
|
-
}
|
|
2273
|
-
return `${WORKER_ASSET_ID}${hash}__`;
|
|
2274
|
-
}
|
|
2275
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L55
|
|
2276
|
-
async function bundleWorkerEntry(config, id) {
|
|
2277
|
-
const input = cleanUrl(id);
|
|
2278
|
-
const bundleChain = config.bundleChain ?? [];
|
|
2279
|
-
const newBundleChain = [...bundleChain, input];
|
|
2280
|
-
if (bundleChain.includes(input)) {
|
|
2281
|
-
throw new Error(`Circular worker imports detected. Vite does not support it. Import chain: ${newBundleChain.join(' -> ')}`);
|
|
2282
|
-
}
|
|
2283
|
-
// bundle the file as entry to support imports
|
|
2284
|
-
const { rollup } = await import('rollup');
|
|
2285
|
-
const { plugins, rollupOptions, format } = config.worker;
|
|
2286
|
-
const workerConfig = await plugins(newBundleChain);
|
|
2287
|
-
const workerEnvironment = new BuildEnvironment('client', workerConfig); // TODO: should this be 'worker'?
|
|
2288
|
-
await workerEnvironment.init();
|
|
2289
|
-
const bundle = await rollup({
|
|
2290
|
-
...rollupOptions,
|
|
2291
|
-
input,
|
|
2292
|
-
plugins: workerEnvironment.plugins.map(p => injectEnvironmentToHooks(workerEnvironment, p)),
|
|
2293
|
-
preserveEntrySignatures: false
|
|
2294
|
-
});
|
|
2295
|
-
let chunk;
|
|
2296
|
-
try {
|
|
2297
|
-
const workerOutputConfig = config.worker.rollupOptions.output;
|
|
2298
|
-
const workerConfig = workerOutputConfig
|
|
2299
|
-
? Array.isArray(workerOutputConfig)
|
|
2300
|
-
? workerOutputConfig[0] || {}
|
|
2301
|
-
: workerOutputConfig
|
|
2302
|
-
: {};
|
|
2303
|
-
const { output: [outputChunk, ...outputChunks] } = await bundle.generate({
|
|
2304
|
-
entryFileNames: path.posix.join(config.build.assetsDir, '[name]-[hash].js'),
|
|
2305
|
-
chunkFileNames: path.posix.join(config.build.assetsDir, '[name]-[hash].js'),
|
|
2306
|
-
assetFileNames: path.posix.join(config.build.assetsDir, '[name]-[hash].[ext]'),
|
|
2307
|
-
...workerConfig,
|
|
2308
|
-
format,
|
|
2309
|
-
sourcemap: config.build.sourcemap
|
|
2310
|
-
});
|
|
2311
|
-
chunk = outputChunk;
|
|
2312
|
-
for (const outputChunk of outputChunks) {
|
|
2313
|
-
if (outputChunk.type === 'asset') {
|
|
2314
|
-
saveEmitWorkerAsset(config, outputChunk);
|
|
2315
|
-
}
|
|
2316
|
-
else if (outputChunk.type === 'chunk') {
|
|
2317
|
-
saveEmitWorkerAsset(config, {
|
|
2318
|
-
fileName: outputChunk.fileName,
|
|
2319
|
-
source: outputChunk.code
|
|
2320
|
-
});
|
|
2321
|
-
}
|
|
2322
|
-
}
|
|
2323
|
-
}
|
|
2324
|
-
finally {
|
|
2325
|
-
await bundle.close();
|
|
2326
|
-
}
|
|
2327
|
-
return emitSourcemapForWorkerEntry(config, chunk);
|
|
2328
|
-
}
|
|
2329
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L124
|
|
2330
|
-
function emitSourcemapForWorkerEntry(config, chunk) {
|
|
2331
|
-
const { map: sourcemap } = chunk;
|
|
2332
|
-
if (sourcemap) {
|
|
2333
|
-
if (config.build.sourcemap === 'hidden' || config.build.sourcemap === true) {
|
|
2334
|
-
const data = sourcemap.toString();
|
|
2335
|
-
const mapFileName = `${chunk.fileName}.map`;
|
|
2336
|
-
saveEmitWorkerAsset(config, {
|
|
2337
|
-
fileName: mapFileName,
|
|
2338
|
-
source: data
|
|
2339
|
-
});
|
|
2340
|
-
}
|
|
2341
|
-
}
|
|
2342
|
-
return chunk;
|
|
2343
|
-
}
|
|
2344
|
-
// https://github.com/vitejs/vite/blob/b7ddfae5f852c2948fab03e94751ce56f5f31ce0/packages/vite/src/node/plugins/worker.ts#L458
|
|
2345
|
-
function isSameContent(a, b) {
|
|
2346
|
-
if (typeof a === 'string') {
|
|
2347
|
-
if (typeof b === 'string') {
|
|
2348
|
-
return a === b;
|
|
2349
|
-
}
|
|
2350
|
-
return Buffer.from(a).equals(b);
|
|
2351
|
-
}
|
|
2352
|
-
return Buffer.from(b).equals(a);
|
|
2353
|
-
}
|
|
2354
|
-
|
|
2355
|
-
/**@target web */
|
|
2356
|
-
const alphaTabWorkerPatterns = [
|
|
2357
|
-
['alphaTabWorker', 'new', 'alphaTabUrl', 'import.meta.url'],
|
|
2358
|
-
['alphaTabWorklet.addModule', 'new', 'alphaTabUrl', 'import.meta.url']
|
|
2359
|
-
];
|
|
2360
|
-
function includesAlphaTabWorker(code) {
|
|
2361
|
-
for (const pattern of alphaTabWorkerPatterns) {
|
|
2362
|
-
let position = 0;
|
|
2363
|
-
for (const match of pattern) {
|
|
2364
|
-
position = code.indexOf(match, position);
|
|
2365
|
-
if (position === -1) {
|
|
2366
|
-
break;
|
|
2367
|
-
}
|
|
2368
|
-
}
|
|
2369
|
-
if (position !== -1) {
|
|
2370
|
-
return true;
|
|
2371
|
-
}
|
|
2372
|
-
}
|
|
2373
|
-
return false;
|
|
2374
|
-
}
|
|
2375
|
-
function getWorkerType(code, match) {
|
|
2376
|
-
if (match[1].includes('.addModule')) {
|
|
2377
|
-
return AlphaTabWorkerTypes.AudioWorklet;
|
|
2378
|
-
}
|
|
2379
|
-
const endOfMatch = match.indices[0][1];
|
|
2380
|
-
const startOfOptions = code.indexOf('{', endOfMatch);
|
|
2381
|
-
if (startOfOptions === -1) {
|
|
2382
|
-
return AlphaTabWorkerTypes.WorkerClassic;
|
|
2383
|
-
}
|
|
2384
|
-
const endOfOptions = code.indexOf('}', endOfMatch);
|
|
2385
|
-
if (endOfOptions === -1) {
|
|
2386
|
-
return AlphaTabWorkerTypes.WorkerClassic;
|
|
2387
|
-
}
|
|
2388
|
-
const endOfWorkerCreate = code.indexOf(')', endOfMatch);
|
|
2389
|
-
if (startOfOptions > endOfWorkerCreate || endOfOptions > endOfWorkerCreate) {
|
|
2390
|
-
return AlphaTabWorkerTypes.WorkerClassic;
|
|
2391
|
-
}
|
|
2392
|
-
let workerOptions = code.slice(startOfOptions, endOfOptions + 1);
|
|
2393
|
-
try {
|
|
2394
|
-
workerOptions = evalValue(workerOptions);
|
|
2395
|
-
}
|
|
2396
|
-
catch {
|
|
2397
|
-
return AlphaTabWorkerTypes.WorkerClassic;
|
|
2398
|
-
}
|
|
2399
|
-
if (typeof workerOptions === 'object' && workerOptions?.type === 'module') {
|
|
2400
|
-
return AlphaTabWorkerTypes.WorkerModule;
|
|
2401
|
-
}
|
|
2402
|
-
return AlphaTabWorkerTypes.WorkerClassic;
|
|
2403
|
-
}
|
|
2404
|
-
function importMetaUrlPlugin(options) {
|
|
2405
|
-
let resolvedConfig;
|
|
2406
|
-
let isBuild;
|
|
2407
|
-
let preserveSymlinks;
|
|
2408
|
-
const isWorkerActive = options.webWorkers !== false;
|
|
2409
|
-
const isWorkletActive = options.audioWorklets !== false;
|
|
2410
|
-
const isActive = isWorkerActive || isWorkletActive;
|
|
2411
|
-
return {
|
|
2412
|
-
name: 'vite-plugin-alphatab-url',
|
|
2413
|
-
enforce: 'pre',
|
|
2414
|
-
configResolved(config) {
|
|
2415
|
-
resolvedConfig = config;
|
|
2416
|
-
isBuild = config.command === 'build';
|
|
2417
|
-
preserveSymlinks = config.resolve.preserveSymlinks;
|
|
2418
|
-
},
|
|
2419
|
-
shouldTransformCachedModule({ code }) {
|
|
2420
|
-
if (isActive && isBuild && resolvedConfig.build.watch && includesAlphaTabWorker(code)) {
|
|
2421
|
-
return true;
|
|
2422
|
-
}
|
|
2423
|
-
return;
|
|
2424
|
-
},
|
|
2425
|
-
async transform(code, id, options) {
|
|
2426
|
-
if (!isActive || options?.ssr || !includesAlphaTabWorker(code)) {
|
|
2427
|
-
return;
|
|
2428
|
-
}
|
|
2429
|
-
let s;
|
|
2430
|
-
const alphaTabWorkerPattern =
|
|
2431
|
-
// @ts-expect-error For the Vite plugin we expect newer node than for alphaTab itself (-> migrate to monorepo)
|
|
2432
|
-
/\b(alphaTabWorker|alphaTabWorklet\.addModule)\s*\(\s*(new\s+[^ (]+alphaTabUrl\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\))/dg;
|
|
2433
|
-
let match = alphaTabWorkerPattern.exec(code);
|
|
2434
|
-
while (match) {
|
|
2435
|
-
const workerType = getWorkerType(code, match);
|
|
2436
|
-
let typeActive = false;
|
|
2437
|
-
switch (workerType) {
|
|
2438
|
-
case AlphaTabWorkerTypes.WorkerClassic:
|
|
2439
|
-
case AlphaTabWorkerTypes.WorkerModule:
|
|
2440
|
-
typeActive = isWorkerActive;
|
|
2441
|
-
break;
|
|
2442
|
-
case AlphaTabWorkerTypes.AudioWorklet:
|
|
2443
|
-
typeActive = isWorkletActive;
|
|
2444
|
-
break;
|
|
2445
|
-
}
|
|
2446
|
-
if (!typeActive) {
|
|
2447
|
-
match = alphaTabWorkerPattern.exec(code);
|
|
2448
|
-
continue;
|
|
2449
|
-
}
|
|
2450
|
-
s ?? (s = new MagicString(code));
|
|
2451
|
-
const url = code.slice(match.indices[3][0] + 1, match.indices[3][1] - 1);
|
|
2452
|
-
let file = path__default.resolve(path__default.dirname(id), url);
|
|
2453
|
-
file =
|
|
2454
|
-
tryFsResolve(file, preserveSymlinks) ??
|
|
2455
|
-
tryOptimizedDepResolve(resolvedConfig, options?.ssr === true, url, id, preserveSymlinks) ??
|
|
2456
|
-
file;
|
|
2457
|
-
let builtUrl;
|
|
2458
|
-
if (isBuild) {
|
|
2459
|
-
builtUrl = await workerFileToUrl(resolvedConfig, file);
|
|
2460
|
-
}
|
|
2461
|
-
else {
|
|
2462
|
-
builtUrl = await fileToUrl(cleanUrl(file), resolvedConfig);
|
|
2463
|
-
builtUrl = injectQuery(builtUrl, `${WORKER_FILE_ID}&type=${workerType}`);
|
|
2464
|
-
}
|
|
2465
|
-
s.update(match.indices[3][0], match.indices[3][1],
|
|
2466
|
-
// add `'' +` to skip vite:asset-import-meta-url plugin
|
|
2467
|
-
`new URL('' + ${JSON.stringify(builtUrl)}, import.meta.url)`);
|
|
2468
|
-
match = alphaTabWorkerPattern.exec(code);
|
|
2469
|
-
}
|
|
2470
|
-
if (s) {
|
|
2471
|
-
return {
|
|
2472
|
-
code: s.toString(),
|
|
2473
|
-
map: resolvedConfig.command === 'build' && resolvedConfig.build.sourcemap
|
|
2474
|
-
? s.generateMap({ hires: 'boundary', source: id })
|
|
2475
|
-
: null
|
|
2476
|
-
};
|
|
2477
|
-
}
|
|
2478
|
-
return null;
|
|
2479
|
-
}
|
|
2480
|
-
};
|
|
2481
|
-
}
|
|
2482
|
-
|
|
2483
|
-
/**@target web */
|
|
2484
|
-
function copyAssetsPlugin(options) {
|
|
2485
|
-
let resolvedConfig;
|
|
2486
|
-
let output = false;
|
|
2487
|
-
return {
|
|
2488
|
-
name: 'vite-plugin-alphatab-copy',
|
|
2489
|
-
enforce: 'pre',
|
|
2490
|
-
configResolved(config) {
|
|
2491
|
-
resolvedConfig = config;
|
|
2492
|
-
},
|
|
2493
|
-
buildEnd() {
|
|
2494
|
-
// reset for watch mode
|
|
2495
|
-
output = false;
|
|
2496
|
-
},
|
|
2497
|
-
async buildStart() {
|
|
2498
|
-
// run copy only once even if multiple bundles are generated
|
|
2499
|
-
if (output) {
|
|
2500
|
-
return;
|
|
2501
|
-
}
|
|
2502
|
-
output = true;
|
|
2503
|
-
let alphaTabSourceDir = options.alphaTabSourceDir;
|
|
2504
|
-
if (!alphaTabSourceDir) {
|
|
2505
|
-
try {
|
|
2506
|
-
const isEsm = typeof import.meta.url === 'string';
|
|
2507
|
-
if (isEsm) {
|
|
2508
|
-
alphaTabSourceDir = url.fileURLToPath(import.meta.resolve('@coderline/alphatab'));
|
|
2509
|
-
}
|
|
2510
|
-
else {
|
|
2511
|
-
alphaTabSourceDir = require.resolve('@coderline/alphatab');
|
|
2512
|
-
}
|
|
2513
|
-
alphaTabSourceDir = path.resolve(alphaTabSourceDir, '..');
|
|
2514
|
-
}
|
|
2515
|
-
catch {
|
|
2516
|
-
alphaTabSourceDir = path.join(resolvedConfig.root, 'node_modules/@coderline/alphatab/dist/');
|
|
2517
|
-
}
|
|
2518
|
-
}
|
|
2519
|
-
let isValidAlphaTabSourceDir;
|
|
2520
|
-
if (alphaTabSourceDir) {
|
|
2521
|
-
try {
|
|
2522
|
-
await fs.promises.access(path.join(alphaTabSourceDir, 'alphaTab.mjs'), fs.constants.F_OK);
|
|
2523
|
-
isValidAlphaTabSourceDir = true;
|
|
2524
|
-
}
|
|
2525
|
-
catch {
|
|
2526
|
-
isValidAlphaTabSourceDir = false;
|
|
2527
|
-
}
|
|
2528
|
-
}
|
|
2529
|
-
else {
|
|
2530
|
-
isValidAlphaTabSourceDir = false;
|
|
2531
|
-
}
|
|
2532
|
-
if (!isValidAlphaTabSourceDir) {
|
|
2533
|
-
resolvedConfig.logger.error('Could not find alphaTab, please ensure it is installed into node_modules or configure alphaTabSourceDir');
|
|
2534
|
-
return;
|
|
2535
|
-
}
|
|
2536
|
-
const outputPath = (options.assetOutputDir ?? resolvedConfig.publicDir);
|
|
2537
|
-
if (!outputPath) {
|
|
2538
|
-
return;
|
|
2539
|
-
}
|
|
2540
|
-
async function copyFiles(subdir) {
|
|
2541
|
-
const fullDir = path.join(alphaTabSourceDir, subdir);
|
|
2542
|
-
const files = await fs.promises.readdir(fullDir, {
|
|
2543
|
-
withFileTypes: true
|
|
2544
|
-
});
|
|
2545
|
-
await fs.promises.mkdir(path.join(outputPath, subdir), {
|
|
2546
|
-
recursive: true
|
|
2547
|
-
});
|
|
2548
|
-
await Promise.all(files
|
|
2549
|
-
.filter(f => f.isFile())
|
|
2550
|
-
.map(async (file) => {
|
|
2551
|
-
// node v20.12.0 has parentPath pointing to the path (not the file)
|
|
2552
|
-
// see https://github.com/nodejs/node/pull/50976
|
|
2553
|
-
const sourceFilename = path.join(file.parentPath ?? file.path, file.name);
|
|
2554
|
-
await fs.promises.copyFile(sourceFilename, path.join(outputPath, subdir, file.name));
|
|
2555
|
-
}));
|
|
2556
|
-
}
|
|
2557
|
-
await Promise.all([copyFiles('font'), copyFiles('soundfont')]);
|
|
2558
|
-
}
|
|
2559
|
-
};
|
|
2560
|
-
}
|
|
2561
|
-
|
|
2562
|
-
/**@target web */
|
|
2563
|
-
const workerFileRE = new RegExp(`(?:\\?|&)${WORKER_FILE_ID}&type=(\\w+)(?:&|$)`);
|
|
2564
|
-
const workerAssetUrlRE = new RegExp(`${WORKER_ASSET_ID}([a-z\\d]{8})__`, 'g');
|
|
2565
|
-
function workerPlugin(options) {
|
|
2566
|
-
let resolvedConfig;
|
|
2567
|
-
let isBuild;
|
|
2568
|
-
let isWorker;
|
|
2569
|
-
const isWorkerActive = options.webWorkers !== false;
|
|
2570
|
-
const isWorkletActive = options.audioWorklets !== false;
|
|
2571
|
-
const isActive = isWorkerActive || isWorkletActive;
|
|
2572
|
-
return {
|
|
2573
|
-
name: 'vite-plugin-alphatab-worker',
|
|
2574
|
-
configResolved(config) {
|
|
2575
|
-
resolvedConfig = config;
|
|
2576
|
-
isBuild = config.command === 'build';
|
|
2577
|
-
isWorker = config.isWorker;
|
|
2578
|
-
},
|
|
2579
|
-
buildStart() {
|
|
2580
|
-
if (!isActive || isWorker) {
|
|
2581
|
-
return;
|
|
2582
|
-
}
|
|
2583
|
-
workerCache.set(resolvedConfig, {
|
|
2584
|
-
assets: new Map(),
|
|
2585
|
-
bundle: new Map(),
|
|
2586
|
-
fileNameHash: new Map()
|
|
2587
|
-
});
|
|
2588
|
-
},
|
|
2589
|
-
load(id) {
|
|
2590
|
-
if (isActive && isBuild && id.includes(WORKER_FILE_ID)) {
|
|
2591
|
-
return '';
|
|
2592
|
-
}
|
|
2593
|
-
return;
|
|
2594
|
-
},
|
|
2595
|
-
shouldTransformCachedModule({ id }) {
|
|
2596
|
-
if (isActive && isBuild && resolvedConfig.build.watch && id.includes(WORKER_FILE_ID)) {
|
|
2597
|
-
return true;
|
|
2598
|
-
}
|
|
2599
|
-
return;
|
|
2600
|
-
},
|
|
2601
|
-
async transform(raw, id) {
|
|
2602
|
-
if (!isActive) {
|
|
2603
|
-
return;
|
|
2604
|
-
}
|
|
2605
|
-
const match = workerFileRE.exec(id);
|
|
2606
|
-
if (!match) {
|
|
2607
|
-
return;
|
|
2608
|
-
}
|
|
2609
|
-
// inject env to worker file, might be needed by imported scripts
|
|
2610
|
-
const envScriptPath = JSON.stringify(path.posix.join(resolvedConfig.base, ENV_PUBLIC_PATH));
|
|
2611
|
-
const workerType = match[1];
|
|
2612
|
-
let injectEnv = '';
|
|
2613
|
-
switch (workerType) {
|
|
2614
|
-
case AlphaTabWorkerTypes.WorkerClassic:
|
|
2615
|
-
injectEnv = `importScripts(${envScriptPath})\n`;
|
|
2616
|
-
break;
|
|
2617
|
-
case AlphaTabWorkerTypes.WorkerModule:
|
|
2618
|
-
case AlphaTabWorkerTypes.AudioWorklet:
|
|
2619
|
-
injectEnv = `import ${envScriptPath}\n`;
|
|
2620
|
-
break;
|
|
2621
|
-
}
|
|
2622
|
-
if (injectEnv) {
|
|
2623
|
-
const s = new MagicString(raw);
|
|
2624
|
-
s.prepend(injectEnv);
|
|
2625
|
-
return {
|
|
2626
|
-
code: s.toString(),
|
|
2627
|
-
map: s.generateMap({ hires: 'boundary' })
|
|
2628
|
-
};
|
|
2629
|
-
}
|
|
2630
|
-
return;
|
|
2631
|
-
},
|
|
2632
|
-
renderChunk(code, chunk, outputOptions) {
|
|
2633
|
-
// when building the worker URLs are replaced with some placeholders
|
|
2634
|
-
// here we replace those placeholders with the final file names respecting chunks
|
|
2635
|
-
let s;
|
|
2636
|
-
const result = () => {
|
|
2637
|
-
return (s && {
|
|
2638
|
-
code: s.toString(),
|
|
2639
|
-
map: resolvedConfig.build.sourcemap ? s.generateMap({ hires: 'boundary' }) : null
|
|
2640
|
-
});
|
|
2641
|
-
};
|
|
2642
|
-
workerAssetUrlRE.lastIndex = 0;
|
|
2643
|
-
if (workerAssetUrlRE.test(code)) {
|
|
2644
|
-
const toRelativeRuntime = createToImportMetaURLBasedRelativeRuntime(outputOptions.format, resolvedConfig.isWorker);
|
|
2645
|
-
s = new MagicString(code);
|
|
2646
|
-
workerAssetUrlRE.lastIndex = 0;
|
|
2647
|
-
// Replace "/" using relative paths
|
|
2648
|
-
const workerMap = workerCache.get(resolvedConfig.mainConfig || resolvedConfig);
|
|
2649
|
-
const { fileNameHash } = workerMap;
|
|
2650
|
-
let match = workerAssetUrlRE.exec(code);
|
|
2651
|
-
while (match) {
|
|
2652
|
-
const [full, hash] = match;
|
|
2653
|
-
const filename = fileNameHash.get(hash);
|
|
2654
|
-
const replacement = toOutputFilePathInJS(filename, 'asset', chunk.fileName, 'js', resolvedConfig, toRelativeRuntime);
|
|
2655
|
-
const replacementString = typeof replacement === 'string'
|
|
2656
|
-
? JSON.stringify(encodeURIPath(replacement)).slice(1, -1)
|
|
2657
|
-
: `"+${replacement.runtime}+"`;
|
|
2658
|
-
s.update(match.index, match.index + full.length, replacementString);
|
|
2659
|
-
match = workerAssetUrlRE.exec(code);
|
|
2660
|
-
}
|
|
2661
|
-
}
|
|
2662
|
-
return result();
|
|
2663
|
-
},
|
|
2664
|
-
generateBundle(_, bundle) {
|
|
2665
|
-
if (isWorker) {
|
|
2666
|
-
return;
|
|
2667
|
-
}
|
|
2668
|
-
const workerMap = workerCache.get(resolvedConfig);
|
|
2669
|
-
for (const asset of workerMap.assets.values()) {
|
|
2670
|
-
const duplicateAsset = bundle[asset.fileName];
|
|
2671
|
-
if (duplicateAsset) {
|
|
2672
|
-
const content = duplicateAsset.type === 'asset' ? duplicateAsset.source : duplicateAsset.code;
|
|
2673
|
-
// don't emit if the file name and the content is same
|
|
2674
|
-
if (isSameContent(content, asset.source)) {
|
|
2675
|
-
return;
|
|
2676
|
-
}
|
|
2677
|
-
}
|
|
2678
|
-
this.emitFile({
|
|
2679
|
-
type: 'asset',
|
|
2680
|
-
fileName: asset.fileName,
|
|
2681
|
-
source: asset.source
|
|
2682
|
-
});
|
|
2683
|
-
}
|
|
2684
|
-
workerMap.assets.clear();
|
|
2685
|
-
}
|
|
2686
|
-
};
|
|
2687
|
-
}
|
|
2688
|
-
|
|
2689
|
-
/**@target web */
|
|
2690
|
-
function alphaTab(options) {
|
|
2691
|
-
const plugins = [];
|
|
2692
|
-
options ?? (options = {});
|
|
2693
|
-
plugins.push(importMetaUrlPlugin(options));
|
|
2694
|
-
plugins.push(workerPlugin(options));
|
|
2695
|
-
plugins.push(copyAssetsPlugin(options));
|
|
2696
|
-
return plugins;
|
|
2697
|
-
}
|
|
1
|
+
import { alphaTab } from './alphaTab.vite.core.mjs';
|
|
2698
2
|
|
|
3
|
+
console.warn('[alphaTab] The use of alphaTab.vite.mjs via @coderline/alphatab is deprecated. Please use the new @coderline/alphatab-vite npm package.');
|
|
2699
4
|
export { alphaTab };
|