@fastkit/plugboy-vanilla-extract-plugin 4.0.0-next.6 → 4.0.0-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,1409 +1,8 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
1
|
import { definePlugin, findFile, findProjectPlugin } from "@fastkit/plugboy";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
|
|
7
|
-
|
|
8
|
-
//#region rolldown:runtime
|
|
9
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
2
|
+
import { vanillaExtractPlugin } from "@vanilla-extract/rollup-plugin";
|
|
3
|
+
import { vanillaExtractPlugin as vanillaExtractPlugin$1 } from "@vanilla-extract/vite-plugin";
|
|
12
4
|
//#region src/types.ts
|
|
13
5
|
const PLUGIN_NAME = "plugboy-vanilla-extract";
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
17
|
-
var comma = ",".charCodeAt(0);
|
|
18
|
-
var semicolon = ";".charCodeAt(0);
|
|
19
|
-
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
20
|
-
var intToChar = new Uint8Array(64);
|
|
21
|
-
var charToInt = new Uint8Array(128);
|
|
22
|
-
for (let i = 0; i < chars.length; i++) {
|
|
23
|
-
const c = chars.charCodeAt(i);
|
|
24
|
-
intToChar[i] = c;
|
|
25
|
-
charToInt[c] = i;
|
|
26
|
-
}
|
|
27
|
-
function encodeInteger(builder, num, relative) {
|
|
28
|
-
let delta = num - relative;
|
|
29
|
-
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
30
|
-
do {
|
|
31
|
-
let clamped = delta & 31;
|
|
32
|
-
delta >>>= 5;
|
|
33
|
-
if (delta > 0) clamped |= 32;
|
|
34
|
-
builder.write(intToChar[clamped]);
|
|
35
|
-
} while (delta > 0);
|
|
36
|
-
return num;
|
|
37
|
-
}
|
|
38
|
-
var bufLength = 1024 * 16;
|
|
39
|
-
var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
|
|
40
|
-
return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
|
|
41
|
-
} } : { decode(buf) {
|
|
42
|
-
let out = "";
|
|
43
|
-
for (let i = 0; i < buf.length; i++) out += String.fromCharCode(buf[i]);
|
|
44
|
-
return out;
|
|
45
|
-
} };
|
|
46
|
-
var StringWriter = class {
|
|
47
|
-
constructor() {
|
|
48
|
-
this.pos = 0;
|
|
49
|
-
this.out = "";
|
|
50
|
-
this.buffer = new Uint8Array(bufLength);
|
|
51
|
-
}
|
|
52
|
-
write(v) {
|
|
53
|
-
const { buffer } = this;
|
|
54
|
-
buffer[this.pos++] = v;
|
|
55
|
-
if (this.pos === bufLength) {
|
|
56
|
-
this.out += td.decode(buffer);
|
|
57
|
-
this.pos = 0;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
flush() {
|
|
61
|
-
const { buffer, out, pos } = this;
|
|
62
|
-
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
function encode(decoded) {
|
|
66
|
-
const writer = new StringWriter();
|
|
67
|
-
let sourcesIndex = 0;
|
|
68
|
-
let sourceLine = 0;
|
|
69
|
-
let sourceColumn = 0;
|
|
70
|
-
let namesIndex = 0;
|
|
71
|
-
for (let i = 0; i < decoded.length; i++) {
|
|
72
|
-
const line = decoded[i];
|
|
73
|
-
if (i > 0) writer.write(semicolon);
|
|
74
|
-
if (line.length === 0) continue;
|
|
75
|
-
let genColumn = 0;
|
|
76
|
-
for (let j = 0; j < line.length; j++) {
|
|
77
|
-
const segment = line[j];
|
|
78
|
-
if (j > 0) writer.write(comma);
|
|
79
|
-
genColumn = encodeInteger(writer, segment[0], genColumn);
|
|
80
|
-
if (segment.length === 1) continue;
|
|
81
|
-
sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
|
|
82
|
-
sourceLine = encodeInteger(writer, segment[2], sourceLine);
|
|
83
|
-
sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
|
|
84
|
-
if (segment.length === 4) continue;
|
|
85
|
-
namesIndex = encodeInteger(writer, segment[4], namesIndex);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return writer.flush();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
//#endregion
|
|
92
|
-
//#region ../../node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs
|
|
93
|
-
var BitSet = class BitSet {
|
|
94
|
-
constructor(arg) {
|
|
95
|
-
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
96
|
-
}
|
|
97
|
-
add(n) {
|
|
98
|
-
this.bits[n >> 5] |= 1 << (n & 31);
|
|
99
|
-
}
|
|
100
|
-
has(n) {
|
|
101
|
-
return !!(this.bits[n >> 5] & 1 << (n & 31));
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
var Chunk = class Chunk {
|
|
105
|
-
constructor(start, end, content) {
|
|
106
|
-
this.start = start;
|
|
107
|
-
this.end = end;
|
|
108
|
-
this.original = content;
|
|
109
|
-
this.intro = "";
|
|
110
|
-
this.outro = "";
|
|
111
|
-
this.content = content;
|
|
112
|
-
this.storeName = false;
|
|
113
|
-
this.edited = false;
|
|
114
|
-
this.previous = null;
|
|
115
|
-
this.next = null;
|
|
116
|
-
}
|
|
117
|
-
appendLeft(content) {
|
|
118
|
-
this.outro += content;
|
|
119
|
-
}
|
|
120
|
-
appendRight(content) {
|
|
121
|
-
this.intro = this.intro + content;
|
|
122
|
-
}
|
|
123
|
-
clone() {
|
|
124
|
-
const chunk = new Chunk(this.start, this.end, this.original);
|
|
125
|
-
chunk.intro = this.intro;
|
|
126
|
-
chunk.outro = this.outro;
|
|
127
|
-
chunk.content = this.content;
|
|
128
|
-
chunk.storeName = this.storeName;
|
|
129
|
-
chunk.edited = this.edited;
|
|
130
|
-
return chunk;
|
|
131
|
-
}
|
|
132
|
-
contains(index) {
|
|
133
|
-
return this.start < index && index < this.end;
|
|
134
|
-
}
|
|
135
|
-
eachNext(fn) {
|
|
136
|
-
let chunk = this;
|
|
137
|
-
while (chunk) {
|
|
138
|
-
fn(chunk);
|
|
139
|
-
chunk = chunk.next;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
eachPrevious(fn) {
|
|
143
|
-
let chunk = this;
|
|
144
|
-
while (chunk) {
|
|
145
|
-
fn(chunk);
|
|
146
|
-
chunk = chunk.previous;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
edit(content, storeName, contentOnly) {
|
|
150
|
-
this.content = content;
|
|
151
|
-
if (!contentOnly) {
|
|
152
|
-
this.intro = "";
|
|
153
|
-
this.outro = "";
|
|
154
|
-
}
|
|
155
|
-
this.storeName = storeName;
|
|
156
|
-
this.edited = true;
|
|
157
|
-
return this;
|
|
158
|
-
}
|
|
159
|
-
prependLeft(content) {
|
|
160
|
-
this.outro = content + this.outro;
|
|
161
|
-
}
|
|
162
|
-
prependRight(content) {
|
|
163
|
-
this.intro = content + this.intro;
|
|
164
|
-
}
|
|
165
|
-
reset() {
|
|
166
|
-
this.intro = "";
|
|
167
|
-
this.outro = "";
|
|
168
|
-
if (this.edited) {
|
|
169
|
-
this.content = this.original;
|
|
170
|
-
this.storeName = false;
|
|
171
|
-
this.edited = false;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
split(index) {
|
|
175
|
-
const sliceIndex = index - this.start;
|
|
176
|
-
const originalBefore = this.original.slice(0, sliceIndex);
|
|
177
|
-
const originalAfter = this.original.slice(sliceIndex);
|
|
178
|
-
this.original = originalBefore;
|
|
179
|
-
const newChunk = new Chunk(index, this.end, originalAfter);
|
|
180
|
-
newChunk.outro = this.outro;
|
|
181
|
-
this.outro = "";
|
|
182
|
-
this.end = index;
|
|
183
|
-
if (this.edited) {
|
|
184
|
-
newChunk.edit("", false);
|
|
185
|
-
this.content = "";
|
|
186
|
-
} else this.content = originalBefore;
|
|
187
|
-
newChunk.next = this.next;
|
|
188
|
-
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
189
|
-
newChunk.previous = this;
|
|
190
|
-
this.next = newChunk;
|
|
191
|
-
return newChunk;
|
|
192
|
-
}
|
|
193
|
-
toString() {
|
|
194
|
-
return this.intro + this.content + this.outro;
|
|
195
|
-
}
|
|
196
|
-
trimEnd(rx) {
|
|
197
|
-
this.outro = this.outro.replace(rx, "");
|
|
198
|
-
if (this.outro.length) return true;
|
|
199
|
-
const trimmed = this.content.replace(rx, "");
|
|
200
|
-
if (trimmed.length) {
|
|
201
|
-
if (trimmed !== this.content) {
|
|
202
|
-
this.split(this.start + trimmed.length).edit("", void 0, true);
|
|
203
|
-
if (this.edited) this.edit(trimmed, this.storeName, true);
|
|
204
|
-
}
|
|
205
|
-
return true;
|
|
206
|
-
} else {
|
|
207
|
-
this.edit("", void 0, true);
|
|
208
|
-
this.intro = this.intro.replace(rx, "");
|
|
209
|
-
if (this.intro.length) return true;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
trimStart(rx) {
|
|
213
|
-
this.intro = this.intro.replace(rx, "");
|
|
214
|
-
if (this.intro.length) return true;
|
|
215
|
-
const trimmed = this.content.replace(rx, "");
|
|
216
|
-
if (trimmed.length) {
|
|
217
|
-
if (trimmed !== this.content) {
|
|
218
|
-
const newChunk = this.split(this.end - trimmed.length);
|
|
219
|
-
if (this.edited) newChunk.edit(trimmed, this.storeName, true);
|
|
220
|
-
this.edit("", void 0, true);
|
|
221
|
-
}
|
|
222
|
-
return true;
|
|
223
|
-
} else {
|
|
224
|
-
this.edit("", void 0, true);
|
|
225
|
-
this.outro = this.outro.replace(rx, "");
|
|
226
|
-
if (this.outro.length) return true;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
function getBtoa() {
|
|
231
|
-
if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
|
|
232
|
-
else if (typeof Buffer === "function") return (str) => Buffer.from(str, "utf-8").toString("base64");
|
|
233
|
-
else return () => {
|
|
234
|
-
throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
const btoa = /* @__PURE__ */ getBtoa();
|
|
238
|
-
var SourceMap = class {
|
|
239
|
-
constructor(properties) {
|
|
240
|
-
this.version = 3;
|
|
241
|
-
this.file = properties.file;
|
|
242
|
-
this.sources = properties.sources;
|
|
243
|
-
this.sourcesContent = properties.sourcesContent;
|
|
244
|
-
this.names = properties.names;
|
|
245
|
-
this.mappings = encode(properties.mappings);
|
|
246
|
-
if (typeof properties.x_google_ignoreList !== "undefined") this.x_google_ignoreList = properties.x_google_ignoreList;
|
|
247
|
-
if (typeof properties.debugId !== "undefined") this.debugId = properties.debugId;
|
|
248
|
-
}
|
|
249
|
-
toString() {
|
|
250
|
-
return JSON.stringify(this);
|
|
251
|
-
}
|
|
252
|
-
toUrl() {
|
|
253
|
-
return "data:application/json;charset=utf-8;base64," + btoa(this.toString());
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
function guessIndent(code) {
|
|
257
|
-
const lines = code.split("\n");
|
|
258
|
-
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
259
|
-
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
260
|
-
if (tabbed.length === 0 && spaced.length === 0) return null;
|
|
261
|
-
if (tabbed.length >= spaced.length) return " ";
|
|
262
|
-
const min = spaced.reduce((previous, current) => {
|
|
263
|
-
const numSpaces = /^ +/.exec(current)[0].length;
|
|
264
|
-
return Math.min(numSpaces, previous);
|
|
265
|
-
}, Infinity);
|
|
266
|
-
return new Array(min + 1).join(" ");
|
|
267
|
-
}
|
|
268
|
-
function getRelativePath(from, to) {
|
|
269
|
-
const fromParts = from.split(/[/\\]/);
|
|
270
|
-
const toParts = to.split(/[/\\]/);
|
|
271
|
-
fromParts.pop();
|
|
272
|
-
while (fromParts[0] === toParts[0]) {
|
|
273
|
-
fromParts.shift();
|
|
274
|
-
toParts.shift();
|
|
275
|
-
}
|
|
276
|
-
if (fromParts.length) {
|
|
277
|
-
let i = fromParts.length;
|
|
278
|
-
while (i--) fromParts[i] = "..";
|
|
279
|
-
}
|
|
280
|
-
return fromParts.concat(toParts).join("/");
|
|
281
|
-
}
|
|
282
|
-
const toString = Object.prototype.toString;
|
|
283
|
-
function isObject(thing) {
|
|
284
|
-
return toString.call(thing) === "[object Object]";
|
|
285
|
-
}
|
|
286
|
-
function getLocator(source) {
|
|
287
|
-
const originalLines = source.split("\n");
|
|
288
|
-
const lineOffsets = [];
|
|
289
|
-
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
290
|
-
lineOffsets.push(pos);
|
|
291
|
-
pos += originalLines[i].length + 1;
|
|
292
|
-
}
|
|
293
|
-
return function locate(index) {
|
|
294
|
-
let i = 0;
|
|
295
|
-
let j = lineOffsets.length;
|
|
296
|
-
while (i < j) {
|
|
297
|
-
const m = i + j >> 1;
|
|
298
|
-
if (index < lineOffsets[m]) j = m;
|
|
299
|
-
else i = m + 1;
|
|
300
|
-
}
|
|
301
|
-
const line = i - 1;
|
|
302
|
-
return {
|
|
303
|
-
line,
|
|
304
|
-
column: index - lineOffsets[line]
|
|
305
|
-
};
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
const wordRegex = /\w/;
|
|
309
|
-
var Mappings = class {
|
|
310
|
-
constructor(hires) {
|
|
311
|
-
this.hires = hires;
|
|
312
|
-
this.generatedCodeLine = 0;
|
|
313
|
-
this.generatedCodeColumn = 0;
|
|
314
|
-
this.raw = [];
|
|
315
|
-
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
316
|
-
this.pending = null;
|
|
317
|
-
}
|
|
318
|
-
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
319
|
-
if (content.length) {
|
|
320
|
-
const contentLengthMinusOne = content.length - 1;
|
|
321
|
-
let contentLineEnd = content.indexOf("\n", 0);
|
|
322
|
-
let previousContentLineEnd = -1;
|
|
323
|
-
while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
|
|
324
|
-
const segment = [
|
|
325
|
-
this.generatedCodeColumn,
|
|
326
|
-
sourceIndex,
|
|
327
|
-
loc.line,
|
|
328
|
-
loc.column
|
|
329
|
-
];
|
|
330
|
-
if (nameIndex >= 0) segment.push(nameIndex);
|
|
331
|
-
this.rawSegments.push(segment);
|
|
332
|
-
this.generatedCodeLine += 1;
|
|
333
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
334
|
-
this.generatedCodeColumn = 0;
|
|
335
|
-
previousContentLineEnd = contentLineEnd;
|
|
336
|
-
contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
|
|
337
|
-
}
|
|
338
|
-
const segment = [
|
|
339
|
-
this.generatedCodeColumn,
|
|
340
|
-
sourceIndex,
|
|
341
|
-
loc.line,
|
|
342
|
-
loc.column
|
|
343
|
-
];
|
|
344
|
-
if (nameIndex >= 0) segment.push(nameIndex);
|
|
345
|
-
this.rawSegments.push(segment);
|
|
346
|
-
this.advance(content.slice(previousContentLineEnd + 1));
|
|
347
|
-
} else if (this.pending) {
|
|
348
|
-
this.rawSegments.push(this.pending);
|
|
349
|
-
this.advance(content);
|
|
350
|
-
}
|
|
351
|
-
this.pending = null;
|
|
352
|
-
}
|
|
353
|
-
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
354
|
-
let originalCharIndex = chunk.start;
|
|
355
|
-
let first = true;
|
|
356
|
-
let charInHiresBoundary = false;
|
|
357
|
-
while (originalCharIndex < chunk.end) {
|
|
358
|
-
if (original[originalCharIndex] === "\n") {
|
|
359
|
-
loc.line += 1;
|
|
360
|
-
loc.column = 0;
|
|
361
|
-
this.generatedCodeLine += 1;
|
|
362
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
363
|
-
this.generatedCodeColumn = 0;
|
|
364
|
-
first = true;
|
|
365
|
-
charInHiresBoundary = false;
|
|
366
|
-
} else {
|
|
367
|
-
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
368
|
-
const segment = [
|
|
369
|
-
this.generatedCodeColumn,
|
|
370
|
-
sourceIndex,
|
|
371
|
-
loc.line,
|
|
372
|
-
loc.column
|
|
373
|
-
];
|
|
374
|
-
if (this.hires === "boundary") if (wordRegex.test(original[originalCharIndex])) {
|
|
375
|
-
if (!charInHiresBoundary) {
|
|
376
|
-
this.rawSegments.push(segment);
|
|
377
|
-
charInHiresBoundary = true;
|
|
378
|
-
}
|
|
379
|
-
} else {
|
|
380
|
-
this.rawSegments.push(segment);
|
|
381
|
-
charInHiresBoundary = false;
|
|
382
|
-
}
|
|
383
|
-
else this.rawSegments.push(segment);
|
|
384
|
-
}
|
|
385
|
-
loc.column += 1;
|
|
386
|
-
this.generatedCodeColumn += 1;
|
|
387
|
-
first = false;
|
|
388
|
-
}
|
|
389
|
-
originalCharIndex += 1;
|
|
390
|
-
}
|
|
391
|
-
this.pending = null;
|
|
392
|
-
}
|
|
393
|
-
advance(str) {
|
|
394
|
-
if (!str) return;
|
|
395
|
-
const lines = str.split("\n");
|
|
396
|
-
if (lines.length > 1) {
|
|
397
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
398
|
-
this.generatedCodeLine++;
|
|
399
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
400
|
-
}
|
|
401
|
-
this.generatedCodeColumn = 0;
|
|
402
|
-
}
|
|
403
|
-
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
404
|
-
}
|
|
405
|
-
};
|
|
406
|
-
const n = "\n";
|
|
407
|
-
const warned = {
|
|
408
|
-
insertLeft: false,
|
|
409
|
-
insertRight: false,
|
|
410
|
-
storeName: false
|
|
411
|
-
};
|
|
412
|
-
var MagicString = class MagicString {
|
|
413
|
-
constructor(string, options = {}) {
|
|
414
|
-
const chunk = new Chunk(0, string.length, string);
|
|
415
|
-
Object.defineProperties(this, {
|
|
416
|
-
original: {
|
|
417
|
-
writable: true,
|
|
418
|
-
value: string
|
|
419
|
-
},
|
|
420
|
-
outro: {
|
|
421
|
-
writable: true,
|
|
422
|
-
value: ""
|
|
423
|
-
},
|
|
424
|
-
intro: {
|
|
425
|
-
writable: true,
|
|
426
|
-
value: ""
|
|
427
|
-
},
|
|
428
|
-
firstChunk: {
|
|
429
|
-
writable: true,
|
|
430
|
-
value: chunk
|
|
431
|
-
},
|
|
432
|
-
lastChunk: {
|
|
433
|
-
writable: true,
|
|
434
|
-
value: chunk
|
|
435
|
-
},
|
|
436
|
-
lastSearchedChunk: {
|
|
437
|
-
writable: true,
|
|
438
|
-
value: chunk
|
|
439
|
-
},
|
|
440
|
-
byStart: {
|
|
441
|
-
writable: true,
|
|
442
|
-
value: {}
|
|
443
|
-
},
|
|
444
|
-
byEnd: {
|
|
445
|
-
writable: true,
|
|
446
|
-
value: {}
|
|
447
|
-
},
|
|
448
|
-
filename: {
|
|
449
|
-
writable: true,
|
|
450
|
-
value: options.filename
|
|
451
|
-
},
|
|
452
|
-
indentExclusionRanges: {
|
|
453
|
-
writable: true,
|
|
454
|
-
value: options.indentExclusionRanges
|
|
455
|
-
},
|
|
456
|
-
sourcemapLocations: {
|
|
457
|
-
writable: true,
|
|
458
|
-
value: new BitSet()
|
|
459
|
-
},
|
|
460
|
-
storedNames: {
|
|
461
|
-
writable: true,
|
|
462
|
-
value: {}
|
|
463
|
-
},
|
|
464
|
-
indentStr: {
|
|
465
|
-
writable: true,
|
|
466
|
-
value: void 0
|
|
467
|
-
},
|
|
468
|
-
ignoreList: {
|
|
469
|
-
writable: true,
|
|
470
|
-
value: options.ignoreList
|
|
471
|
-
},
|
|
472
|
-
offset: {
|
|
473
|
-
writable: true,
|
|
474
|
-
value: options.offset || 0
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
this.byStart[0] = chunk;
|
|
478
|
-
this.byEnd[string.length] = chunk;
|
|
479
|
-
}
|
|
480
|
-
addSourcemapLocation(char) {
|
|
481
|
-
this.sourcemapLocations.add(char);
|
|
482
|
-
}
|
|
483
|
-
append(content) {
|
|
484
|
-
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
485
|
-
this.outro += content;
|
|
486
|
-
return this;
|
|
487
|
-
}
|
|
488
|
-
appendLeft(index, content) {
|
|
489
|
-
index = index + this.offset;
|
|
490
|
-
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
491
|
-
this._split(index);
|
|
492
|
-
const chunk = this.byEnd[index];
|
|
493
|
-
if (chunk) chunk.appendLeft(content);
|
|
494
|
-
else this.intro += content;
|
|
495
|
-
return this;
|
|
496
|
-
}
|
|
497
|
-
appendRight(index, content) {
|
|
498
|
-
index = index + this.offset;
|
|
499
|
-
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
500
|
-
this._split(index);
|
|
501
|
-
const chunk = this.byStart[index];
|
|
502
|
-
if (chunk) chunk.appendRight(content);
|
|
503
|
-
else this.outro += content;
|
|
504
|
-
return this;
|
|
505
|
-
}
|
|
506
|
-
clone() {
|
|
507
|
-
const cloned = new MagicString(this.original, {
|
|
508
|
-
filename: this.filename,
|
|
509
|
-
offset: this.offset
|
|
510
|
-
});
|
|
511
|
-
let originalChunk = this.firstChunk;
|
|
512
|
-
let clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
|
513
|
-
while (originalChunk) {
|
|
514
|
-
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
515
|
-
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
516
|
-
const nextOriginalChunk = originalChunk.next;
|
|
517
|
-
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
518
|
-
if (nextClonedChunk) {
|
|
519
|
-
clonedChunk.next = nextClonedChunk;
|
|
520
|
-
nextClonedChunk.previous = clonedChunk;
|
|
521
|
-
clonedChunk = nextClonedChunk;
|
|
522
|
-
}
|
|
523
|
-
originalChunk = nextOriginalChunk;
|
|
524
|
-
}
|
|
525
|
-
cloned.lastChunk = clonedChunk;
|
|
526
|
-
if (this.indentExclusionRanges) cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
527
|
-
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
528
|
-
cloned.intro = this.intro;
|
|
529
|
-
cloned.outro = this.outro;
|
|
530
|
-
return cloned;
|
|
531
|
-
}
|
|
532
|
-
generateDecodedMap(options) {
|
|
533
|
-
options = options || {};
|
|
534
|
-
const sourceIndex = 0;
|
|
535
|
-
const names = Object.keys(this.storedNames);
|
|
536
|
-
const mappings = new Mappings(options.hires);
|
|
537
|
-
const locate = getLocator(this.original);
|
|
538
|
-
if (this.intro) mappings.advance(this.intro);
|
|
539
|
-
this.firstChunk.eachNext((chunk) => {
|
|
540
|
-
const loc = locate(chunk.start);
|
|
541
|
-
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
542
|
-
if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
|
|
543
|
-
else mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
544
|
-
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
545
|
-
});
|
|
546
|
-
if (this.outro) mappings.advance(this.outro);
|
|
547
|
-
return {
|
|
548
|
-
file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
|
|
549
|
-
sources: [options.source ? getRelativePath(options.file || "", options.source) : options.file || ""],
|
|
550
|
-
sourcesContent: options.includeContent ? [this.original] : void 0,
|
|
551
|
-
names,
|
|
552
|
-
mappings: mappings.raw,
|
|
553
|
-
x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
|
|
554
|
-
};
|
|
555
|
-
}
|
|
556
|
-
generateMap(options) {
|
|
557
|
-
return new SourceMap(this.generateDecodedMap(options));
|
|
558
|
-
}
|
|
559
|
-
_ensureindentStr() {
|
|
560
|
-
if (this.indentStr === void 0) this.indentStr = guessIndent(this.original);
|
|
561
|
-
}
|
|
562
|
-
_getRawIndentString() {
|
|
563
|
-
this._ensureindentStr();
|
|
564
|
-
return this.indentStr;
|
|
565
|
-
}
|
|
566
|
-
getIndentString() {
|
|
567
|
-
this._ensureindentStr();
|
|
568
|
-
return this.indentStr === null ? " " : this.indentStr;
|
|
569
|
-
}
|
|
570
|
-
indent(indentStr, options) {
|
|
571
|
-
const pattern = /^[^\r\n]/gm;
|
|
572
|
-
if (isObject(indentStr)) {
|
|
573
|
-
options = indentStr;
|
|
574
|
-
indentStr = void 0;
|
|
575
|
-
}
|
|
576
|
-
if (indentStr === void 0) {
|
|
577
|
-
this._ensureindentStr();
|
|
578
|
-
indentStr = this.indentStr || " ";
|
|
579
|
-
}
|
|
580
|
-
if (indentStr === "") return this;
|
|
581
|
-
options = options || {};
|
|
582
|
-
const isExcluded = {};
|
|
583
|
-
if (options.exclude) (typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude).forEach((exclusion) => {
|
|
584
|
-
for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded[i] = true;
|
|
585
|
-
});
|
|
586
|
-
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
587
|
-
const replacer = (match) => {
|
|
588
|
-
if (shouldIndentNextCharacter) return `${indentStr}${match}`;
|
|
589
|
-
shouldIndentNextCharacter = true;
|
|
590
|
-
return match;
|
|
591
|
-
};
|
|
592
|
-
this.intro = this.intro.replace(pattern, replacer);
|
|
593
|
-
let charIndex = 0;
|
|
594
|
-
let chunk = this.firstChunk;
|
|
595
|
-
while (chunk) {
|
|
596
|
-
const end = chunk.end;
|
|
597
|
-
if (chunk.edited) {
|
|
598
|
-
if (!isExcluded[charIndex]) {
|
|
599
|
-
chunk.content = chunk.content.replace(pattern, replacer);
|
|
600
|
-
if (chunk.content.length) shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
|
|
601
|
-
}
|
|
602
|
-
} else {
|
|
603
|
-
charIndex = chunk.start;
|
|
604
|
-
while (charIndex < end) {
|
|
605
|
-
if (!isExcluded[charIndex]) {
|
|
606
|
-
const char = this.original[charIndex];
|
|
607
|
-
if (char === "\n") shouldIndentNextCharacter = true;
|
|
608
|
-
else if (char !== "\r" && shouldIndentNextCharacter) {
|
|
609
|
-
shouldIndentNextCharacter = false;
|
|
610
|
-
if (charIndex === chunk.start) chunk.prependRight(indentStr);
|
|
611
|
-
else {
|
|
612
|
-
this._splitChunk(chunk, charIndex);
|
|
613
|
-
chunk = chunk.next;
|
|
614
|
-
chunk.prependRight(indentStr);
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
charIndex += 1;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
charIndex = chunk.end;
|
|
622
|
-
chunk = chunk.next;
|
|
623
|
-
}
|
|
624
|
-
this.outro = this.outro.replace(pattern, replacer);
|
|
625
|
-
return this;
|
|
626
|
-
}
|
|
627
|
-
insert() {
|
|
628
|
-
throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)");
|
|
629
|
-
}
|
|
630
|
-
insertLeft(index, content) {
|
|
631
|
-
if (!warned.insertLeft) {
|
|
632
|
-
console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead");
|
|
633
|
-
warned.insertLeft = true;
|
|
634
|
-
}
|
|
635
|
-
return this.appendLeft(index, content);
|
|
636
|
-
}
|
|
637
|
-
insertRight(index, content) {
|
|
638
|
-
if (!warned.insertRight) {
|
|
639
|
-
console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead");
|
|
640
|
-
warned.insertRight = true;
|
|
641
|
-
}
|
|
642
|
-
return this.prependRight(index, content);
|
|
643
|
-
}
|
|
644
|
-
move(start, end, index) {
|
|
645
|
-
start = start + this.offset;
|
|
646
|
-
end = end + this.offset;
|
|
647
|
-
index = index + this.offset;
|
|
648
|
-
if (index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
|
|
649
|
-
this._split(start);
|
|
650
|
-
this._split(end);
|
|
651
|
-
this._split(index);
|
|
652
|
-
const first = this.byStart[start];
|
|
653
|
-
const last = this.byEnd[end];
|
|
654
|
-
const oldLeft = first.previous;
|
|
655
|
-
const oldRight = last.next;
|
|
656
|
-
const newRight = this.byStart[index];
|
|
657
|
-
if (!newRight && last === this.lastChunk) return this;
|
|
658
|
-
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
659
|
-
if (oldLeft) oldLeft.next = oldRight;
|
|
660
|
-
if (oldRight) oldRight.previous = oldLeft;
|
|
661
|
-
if (newLeft) newLeft.next = first;
|
|
662
|
-
if (newRight) newRight.previous = last;
|
|
663
|
-
if (!first.previous) this.firstChunk = last.next;
|
|
664
|
-
if (!last.next) {
|
|
665
|
-
this.lastChunk = first.previous;
|
|
666
|
-
this.lastChunk.next = null;
|
|
667
|
-
}
|
|
668
|
-
first.previous = newLeft;
|
|
669
|
-
last.next = newRight || null;
|
|
670
|
-
if (!newLeft) this.firstChunk = first;
|
|
671
|
-
if (!newRight) this.lastChunk = last;
|
|
672
|
-
return this;
|
|
673
|
-
}
|
|
674
|
-
overwrite(start, end, content, options) {
|
|
675
|
-
options = options || {};
|
|
676
|
-
return this.update(start, end, content, {
|
|
677
|
-
...options,
|
|
678
|
-
overwrite: !options.contentOnly
|
|
679
|
-
});
|
|
680
|
-
}
|
|
681
|
-
update(start, end, content, options) {
|
|
682
|
-
start = start + this.offset;
|
|
683
|
-
end = end + this.offset;
|
|
684
|
-
if (typeof content !== "string") throw new TypeError("replacement content must be a string");
|
|
685
|
-
if (this.original.length !== 0) {
|
|
686
|
-
while (start < 0) start += this.original.length;
|
|
687
|
-
while (end < 0) end += this.original.length;
|
|
688
|
-
}
|
|
689
|
-
if (end > this.original.length) throw new Error("end is out of bounds");
|
|
690
|
-
if (start === end) throw new Error("Cannot overwrite a zero-length range – use appendLeft or prependRight instead");
|
|
691
|
-
this._split(start);
|
|
692
|
-
this._split(end);
|
|
693
|
-
if (options === true) {
|
|
694
|
-
if (!warned.storeName) {
|
|
695
|
-
console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string");
|
|
696
|
-
warned.storeName = true;
|
|
697
|
-
}
|
|
698
|
-
options = { storeName: true };
|
|
699
|
-
}
|
|
700
|
-
const storeName = options !== void 0 ? options.storeName : false;
|
|
701
|
-
const overwrite = options !== void 0 ? options.overwrite : false;
|
|
702
|
-
if (storeName) {
|
|
703
|
-
const original = this.original.slice(start, end);
|
|
704
|
-
Object.defineProperty(this.storedNames, original, {
|
|
705
|
-
writable: true,
|
|
706
|
-
value: true,
|
|
707
|
-
enumerable: true
|
|
708
|
-
});
|
|
709
|
-
}
|
|
710
|
-
const first = this.byStart[start];
|
|
711
|
-
const last = this.byEnd[end];
|
|
712
|
-
if (first) {
|
|
713
|
-
let chunk = first;
|
|
714
|
-
while (chunk !== last) {
|
|
715
|
-
if (chunk.next !== this.byStart[chunk.end]) throw new Error("Cannot overwrite across a split point");
|
|
716
|
-
chunk = chunk.next;
|
|
717
|
-
chunk.edit("", false);
|
|
718
|
-
}
|
|
719
|
-
first.edit(content, storeName, !overwrite);
|
|
720
|
-
} else {
|
|
721
|
-
const newChunk = new Chunk(start, end, "").edit(content, storeName);
|
|
722
|
-
last.next = newChunk;
|
|
723
|
-
newChunk.previous = last;
|
|
724
|
-
}
|
|
725
|
-
return this;
|
|
726
|
-
}
|
|
727
|
-
prepend(content) {
|
|
728
|
-
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
729
|
-
this.intro = content + this.intro;
|
|
730
|
-
return this;
|
|
731
|
-
}
|
|
732
|
-
prependLeft(index, content) {
|
|
733
|
-
index = index + this.offset;
|
|
734
|
-
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
735
|
-
this._split(index);
|
|
736
|
-
const chunk = this.byEnd[index];
|
|
737
|
-
if (chunk) chunk.prependLeft(content);
|
|
738
|
-
else this.intro = content + this.intro;
|
|
739
|
-
return this;
|
|
740
|
-
}
|
|
741
|
-
prependRight(index, content) {
|
|
742
|
-
index = index + this.offset;
|
|
743
|
-
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
744
|
-
this._split(index);
|
|
745
|
-
const chunk = this.byStart[index];
|
|
746
|
-
if (chunk) chunk.prependRight(content);
|
|
747
|
-
else this.outro = content + this.outro;
|
|
748
|
-
return this;
|
|
749
|
-
}
|
|
750
|
-
remove(start, end) {
|
|
751
|
-
start = start + this.offset;
|
|
752
|
-
end = end + this.offset;
|
|
753
|
-
if (this.original.length !== 0) {
|
|
754
|
-
while (start < 0) start += this.original.length;
|
|
755
|
-
while (end < 0) end += this.original.length;
|
|
756
|
-
}
|
|
757
|
-
if (start === end) return this;
|
|
758
|
-
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
759
|
-
if (start > end) throw new Error("end must be greater than start");
|
|
760
|
-
this._split(start);
|
|
761
|
-
this._split(end);
|
|
762
|
-
let chunk = this.byStart[start];
|
|
763
|
-
while (chunk) {
|
|
764
|
-
chunk.intro = "";
|
|
765
|
-
chunk.outro = "";
|
|
766
|
-
chunk.edit("");
|
|
767
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
768
|
-
}
|
|
769
|
-
return this;
|
|
770
|
-
}
|
|
771
|
-
reset(start, end) {
|
|
772
|
-
start = start + this.offset;
|
|
773
|
-
end = end + this.offset;
|
|
774
|
-
if (this.original.length !== 0) {
|
|
775
|
-
while (start < 0) start += this.original.length;
|
|
776
|
-
while (end < 0) end += this.original.length;
|
|
777
|
-
}
|
|
778
|
-
if (start === end) return this;
|
|
779
|
-
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
780
|
-
if (start > end) throw new Error("end must be greater than start");
|
|
781
|
-
this._split(start);
|
|
782
|
-
this._split(end);
|
|
783
|
-
let chunk = this.byStart[start];
|
|
784
|
-
while (chunk) {
|
|
785
|
-
chunk.reset();
|
|
786
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
787
|
-
}
|
|
788
|
-
return this;
|
|
789
|
-
}
|
|
790
|
-
lastChar() {
|
|
791
|
-
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
792
|
-
let chunk = this.lastChunk;
|
|
793
|
-
do {
|
|
794
|
-
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
795
|
-
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
796
|
-
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
797
|
-
} while (chunk = chunk.previous);
|
|
798
|
-
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
799
|
-
return "";
|
|
800
|
-
}
|
|
801
|
-
lastLine() {
|
|
802
|
-
let lineIndex = this.outro.lastIndexOf(n);
|
|
803
|
-
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
804
|
-
let lineStr = this.outro;
|
|
805
|
-
let chunk = this.lastChunk;
|
|
806
|
-
do {
|
|
807
|
-
if (chunk.outro.length > 0) {
|
|
808
|
-
lineIndex = chunk.outro.lastIndexOf(n);
|
|
809
|
-
if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
810
|
-
lineStr = chunk.outro + lineStr;
|
|
811
|
-
}
|
|
812
|
-
if (chunk.content.length > 0) {
|
|
813
|
-
lineIndex = chunk.content.lastIndexOf(n);
|
|
814
|
-
if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
|
|
815
|
-
lineStr = chunk.content + lineStr;
|
|
816
|
-
}
|
|
817
|
-
if (chunk.intro.length > 0) {
|
|
818
|
-
lineIndex = chunk.intro.lastIndexOf(n);
|
|
819
|
-
if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
820
|
-
lineStr = chunk.intro + lineStr;
|
|
821
|
-
}
|
|
822
|
-
} while (chunk = chunk.previous);
|
|
823
|
-
lineIndex = this.intro.lastIndexOf(n);
|
|
824
|
-
if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
|
|
825
|
-
return this.intro + lineStr;
|
|
826
|
-
}
|
|
827
|
-
slice(start = 0, end = this.original.length - this.offset) {
|
|
828
|
-
start = start + this.offset;
|
|
829
|
-
end = end + this.offset;
|
|
830
|
-
if (this.original.length !== 0) {
|
|
831
|
-
while (start < 0) start += this.original.length;
|
|
832
|
-
while (end < 0) end += this.original.length;
|
|
833
|
-
}
|
|
834
|
-
let result = "";
|
|
835
|
-
let chunk = this.firstChunk;
|
|
836
|
-
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
837
|
-
if (chunk.start < end && chunk.end >= end) return result;
|
|
838
|
-
chunk = chunk.next;
|
|
839
|
-
}
|
|
840
|
-
if (chunk && chunk.edited && chunk.start !== start) throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
841
|
-
const startChunk = chunk;
|
|
842
|
-
while (chunk) {
|
|
843
|
-
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) result += chunk.intro;
|
|
844
|
-
const containsEnd = chunk.start < end && chunk.end >= end;
|
|
845
|
-
if (containsEnd && chunk.edited && chunk.end !== end) throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
846
|
-
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
847
|
-
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
848
|
-
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
849
|
-
if (chunk.outro && (!containsEnd || chunk.end === end)) result += chunk.outro;
|
|
850
|
-
if (containsEnd) break;
|
|
851
|
-
chunk = chunk.next;
|
|
852
|
-
}
|
|
853
|
-
return result;
|
|
854
|
-
}
|
|
855
|
-
snip(start, end) {
|
|
856
|
-
const clone = this.clone();
|
|
857
|
-
clone.remove(0, start);
|
|
858
|
-
clone.remove(end, clone.original.length);
|
|
859
|
-
return clone;
|
|
860
|
-
}
|
|
861
|
-
_split(index) {
|
|
862
|
-
if (this.byStart[index] || this.byEnd[index]) return;
|
|
863
|
-
let chunk = this.lastSearchedChunk;
|
|
864
|
-
let previousChunk = chunk;
|
|
865
|
-
const searchForward = index > chunk.end;
|
|
866
|
-
while (chunk) {
|
|
867
|
-
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
868
|
-
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
869
|
-
if (chunk === previousChunk) return;
|
|
870
|
-
previousChunk = chunk;
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
_splitChunk(chunk, index) {
|
|
874
|
-
if (chunk.edited && chunk.content.length) {
|
|
875
|
-
const loc = getLocator(this.original)(index);
|
|
876
|
-
throw new Error(`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`);
|
|
877
|
-
}
|
|
878
|
-
const newChunk = chunk.split(index);
|
|
879
|
-
this.byEnd[index] = chunk;
|
|
880
|
-
this.byStart[index] = newChunk;
|
|
881
|
-
this.byEnd[newChunk.end] = newChunk;
|
|
882
|
-
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
883
|
-
this.lastSearchedChunk = chunk;
|
|
884
|
-
return true;
|
|
885
|
-
}
|
|
886
|
-
toString() {
|
|
887
|
-
let str = this.intro;
|
|
888
|
-
let chunk = this.firstChunk;
|
|
889
|
-
while (chunk) {
|
|
890
|
-
str += chunk.toString();
|
|
891
|
-
chunk = chunk.next;
|
|
892
|
-
}
|
|
893
|
-
return str + this.outro;
|
|
894
|
-
}
|
|
895
|
-
isEmpty() {
|
|
896
|
-
let chunk = this.firstChunk;
|
|
897
|
-
do
|
|
898
|
-
if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim()) return false;
|
|
899
|
-
while (chunk = chunk.next);
|
|
900
|
-
return true;
|
|
901
|
-
}
|
|
902
|
-
length() {
|
|
903
|
-
let chunk = this.firstChunk;
|
|
904
|
-
let length = 0;
|
|
905
|
-
do
|
|
906
|
-
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
907
|
-
while (chunk = chunk.next);
|
|
908
|
-
return length;
|
|
909
|
-
}
|
|
910
|
-
trimLines() {
|
|
911
|
-
return this.trim("[\\r\\n]");
|
|
912
|
-
}
|
|
913
|
-
trim(charType) {
|
|
914
|
-
return this.trimStart(charType).trimEnd(charType);
|
|
915
|
-
}
|
|
916
|
-
trimEndAborted(charType) {
|
|
917
|
-
const rx = new RegExp((charType || "\\s") + "+$");
|
|
918
|
-
this.outro = this.outro.replace(rx, "");
|
|
919
|
-
if (this.outro.length) return true;
|
|
920
|
-
let chunk = this.lastChunk;
|
|
921
|
-
do {
|
|
922
|
-
const end = chunk.end;
|
|
923
|
-
const aborted = chunk.trimEnd(rx);
|
|
924
|
-
if (chunk.end !== end) {
|
|
925
|
-
if (this.lastChunk === chunk) this.lastChunk = chunk.next;
|
|
926
|
-
this.byEnd[chunk.end] = chunk;
|
|
927
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
928
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
929
|
-
}
|
|
930
|
-
if (aborted) return true;
|
|
931
|
-
chunk = chunk.previous;
|
|
932
|
-
} while (chunk);
|
|
933
|
-
return false;
|
|
934
|
-
}
|
|
935
|
-
trimEnd(charType) {
|
|
936
|
-
this.trimEndAborted(charType);
|
|
937
|
-
return this;
|
|
938
|
-
}
|
|
939
|
-
trimStartAborted(charType) {
|
|
940
|
-
const rx = new RegExp("^" + (charType || "\\s") + "+");
|
|
941
|
-
this.intro = this.intro.replace(rx, "");
|
|
942
|
-
if (this.intro.length) return true;
|
|
943
|
-
let chunk = this.firstChunk;
|
|
944
|
-
do {
|
|
945
|
-
const end = chunk.end;
|
|
946
|
-
const aborted = chunk.trimStart(rx);
|
|
947
|
-
if (chunk.end !== end) {
|
|
948
|
-
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
949
|
-
this.byEnd[chunk.end] = chunk;
|
|
950
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
951
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
952
|
-
}
|
|
953
|
-
if (aborted) return true;
|
|
954
|
-
chunk = chunk.next;
|
|
955
|
-
} while (chunk);
|
|
956
|
-
return false;
|
|
957
|
-
}
|
|
958
|
-
trimStart(charType) {
|
|
959
|
-
this.trimStartAborted(charType);
|
|
960
|
-
return this;
|
|
961
|
-
}
|
|
962
|
-
hasChanged() {
|
|
963
|
-
return this.original !== this.toString();
|
|
964
|
-
}
|
|
965
|
-
_replaceRegexp(searchValue, replacement) {
|
|
966
|
-
function getReplacement(match, str) {
|
|
967
|
-
if (typeof replacement === "string") return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
968
|
-
if (i === "$") return "$";
|
|
969
|
-
if (i === "&") return match[0];
|
|
970
|
-
if (+i < match.length) return match[+i];
|
|
971
|
-
return `$${i}`;
|
|
972
|
-
});
|
|
973
|
-
else return replacement(...match, match.index, str, match.groups);
|
|
974
|
-
}
|
|
975
|
-
function matchAll(re, str) {
|
|
976
|
-
let match;
|
|
977
|
-
const matches = [];
|
|
978
|
-
while (match = re.exec(str)) matches.push(match);
|
|
979
|
-
return matches;
|
|
980
|
-
}
|
|
981
|
-
if (searchValue.global) matchAll(searchValue, this.original).forEach((match) => {
|
|
982
|
-
if (match.index != null) {
|
|
983
|
-
const replacement = getReplacement(match, this.original);
|
|
984
|
-
if (replacement !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
985
|
-
}
|
|
986
|
-
});
|
|
987
|
-
else {
|
|
988
|
-
const match = this.original.match(searchValue);
|
|
989
|
-
if (match && match.index != null) {
|
|
990
|
-
const replacement = getReplacement(match, this.original);
|
|
991
|
-
if (replacement !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
return this;
|
|
995
|
-
}
|
|
996
|
-
_replaceString(string, replacement) {
|
|
997
|
-
const { original } = this;
|
|
998
|
-
const index = original.indexOf(string);
|
|
999
|
-
if (index !== -1) {
|
|
1000
|
-
if (typeof replacement === "function") replacement = replacement(string, index, original);
|
|
1001
|
-
if (string !== replacement) this.overwrite(index, index + string.length, replacement);
|
|
1002
|
-
}
|
|
1003
|
-
return this;
|
|
1004
|
-
}
|
|
1005
|
-
replace(searchValue, replacement) {
|
|
1006
|
-
if (typeof searchValue === "string") return this._replaceString(searchValue, replacement);
|
|
1007
|
-
return this._replaceRegexp(searchValue, replacement);
|
|
1008
|
-
}
|
|
1009
|
-
_replaceAllString(string, replacement) {
|
|
1010
|
-
const { original } = this;
|
|
1011
|
-
const stringLength = string.length;
|
|
1012
|
-
for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
|
|
1013
|
-
const previous = original.slice(index, index + stringLength);
|
|
1014
|
-
let _replacement = replacement;
|
|
1015
|
-
if (typeof replacement === "function") _replacement = replacement(previous, index, original);
|
|
1016
|
-
if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
|
|
1017
|
-
}
|
|
1018
|
-
return this;
|
|
1019
|
-
}
|
|
1020
|
-
replaceAll(searchValue, replacement) {
|
|
1021
|
-
if (typeof searchValue === "string") return this._replaceAllString(searchValue, replacement);
|
|
1022
|
-
if (!searchValue.global) throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
|
|
1023
|
-
return this._replaceRegexp(searchValue, replacement);
|
|
1024
|
-
}
|
|
1025
|
-
};
|
|
1026
|
-
const hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1027
|
-
var Bundle = class Bundle {
|
|
1028
|
-
constructor(options = {}) {
|
|
1029
|
-
this.intro = options.intro || "";
|
|
1030
|
-
this.separator = options.separator !== void 0 ? options.separator : "\n";
|
|
1031
|
-
this.sources = [];
|
|
1032
|
-
this.uniqueSources = [];
|
|
1033
|
-
this.uniqueSourceIndexByFilename = {};
|
|
1034
|
-
}
|
|
1035
|
-
addSource(source) {
|
|
1036
|
-
if (source instanceof MagicString) return this.addSource({
|
|
1037
|
-
content: source,
|
|
1038
|
-
filename: source.filename,
|
|
1039
|
-
separator: this.separator
|
|
1040
|
-
});
|
|
1041
|
-
if (!isObject(source) || !source.content) throw new Error("bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`");
|
|
1042
|
-
[
|
|
1043
|
-
"filename",
|
|
1044
|
-
"ignoreList",
|
|
1045
|
-
"indentExclusionRanges",
|
|
1046
|
-
"separator"
|
|
1047
|
-
].forEach((option) => {
|
|
1048
|
-
if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
|
|
1049
|
-
});
|
|
1050
|
-
if (source.separator === void 0) source.separator = this.separator;
|
|
1051
|
-
if (source.filename) if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
|
|
1052
|
-
this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
|
|
1053
|
-
this.uniqueSources.push({
|
|
1054
|
-
filename: source.filename,
|
|
1055
|
-
content: source.content.original
|
|
1056
|
-
});
|
|
1057
|
-
} else {
|
|
1058
|
-
const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
|
|
1059
|
-
if (source.content.original !== uniqueSource.content) throw new Error(`Illegal source: same filename (${source.filename}), different contents`);
|
|
1060
|
-
}
|
|
1061
|
-
this.sources.push(source);
|
|
1062
|
-
return this;
|
|
1063
|
-
}
|
|
1064
|
-
append(str, options) {
|
|
1065
|
-
this.addSource({
|
|
1066
|
-
content: new MagicString(str),
|
|
1067
|
-
separator: options && options.separator || ""
|
|
1068
|
-
});
|
|
1069
|
-
return this;
|
|
1070
|
-
}
|
|
1071
|
-
clone() {
|
|
1072
|
-
const bundle = new Bundle({
|
|
1073
|
-
intro: this.intro,
|
|
1074
|
-
separator: this.separator
|
|
1075
|
-
});
|
|
1076
|
-
this.sources.forEach((source) => {
|
|
1077
|
-
bundle.addSource({
|
|
1078
|
-
filename: source.filename,
|
|
1079
|
-
content: source.content.clone(),
|
|
1080
|
-
separator: source.separator
|
|
1081
|
-
});
|
|
1082
|
-
});
|
|
1083
|
-
return bundle;
|
|
1084
|
-
}
|
|
1085
|
-
generateDecodedMap(options = {}) {
|
|
1086
|
-
const names = [];
|
|
1087
|
-
let x_google_ignoreList = void 0;
|
|
1088
|
-
this.sources.forEach((source) => {
|
|
1089
|
-
Object.keys(source.content.storedNames).forEach((name) => {
|
|
1090
|
-
if (!~names.indexOf(name)) names.push(name);
|
|
1091
|
-
});
|
|
1092
|
-
});
|
|
1093
|
-
const mappings = new Mappings(options.hires);
|
|
1094
|
-
if (this.intro) mappings.advance(this.intro);
|
|
1095
|
-
this.sources.forEach((source, i) => {
|
|
1096
|
-
if (i > 0) mappings.advance(this.separator);
|
|
1097
|
-
const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
|
|
1098
|
-
const magicString = source.content;
|
|
1099
|
-
const locate = getLocator(magicString.original);
|
|
1100
|
-
if (magicString.intro) mappings.advance(magicString.intro);
|
|
1101
|
-
magicString.firstChunk.eachNext((chunk) => {
|
|
1102
|
-
const loc = locate(chunk.start);
|
|
1103
|
-
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
1104
|
-
if (source.filename) if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
|
|
1105
|
-
else mappings.addUneditedChunk(sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations);
|
|
1106
|
-
else mappings.advance(chunk.content);
|
|
1107
|
-
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
1108
|
-
});
|
|
1109
|
-
if (magicString.outro) mappings.advance(magicString.outro);
|
|
1110
|
-
if (source.ignoreList && sourceIndex !== -1) {
|
|
1111
|
-
if (x_google_ignoreList === void 0) x_google_ignoreList = [];
|
|
1112
|
-
x_google_ignoreList.push(sourceIndex);
|
|
1113
|
-
}
|
|
1114
|
-
});
|
|
1115
|
-
return {
|
|
1116
|
-
file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
|
|
1117
|
-
sources: this.uniqueSources.map((source) => {
|
|
1118
|
-
return options.file ? getRelativePath(options.file, source.filename) : source.filename;
|
|
1119
|
-
}),
|
|
1120
|
-
sourcesContent: this.uniqueSources.map((source) => {
|
|
1121
|
-
return options.includeContent ? source.content : null;
|
|
1122
|
-
}),
|
|
1123
|
-
names,
|
|
1124
|
-
mappings: mappings.raw,
|
|
1125
|
-
x_google_ignoreList
|
|
1126
|
-
};
|
|
1127
|
-
}
|
|
1128
|
-
generateMap(options) {
|
|
1129
|
-
return new SourceMap(this.generateDecodedMap(options));
|
|
1130
|
-
}
|
|
1131
|
-
getIndentString() {
|
|
1132
|
-
const indentStringCounts = {};
|
|
1133
|
-
this.sources.forEach((source) => {
|
|
1134
|
-
const indentStr = source.content._getRawIndentString();
|
|
1135
|
-
if (indentStr === null) return;
|
|
1136
|
-
if (!indentStringCounts[indentStr]) indentStringCounts[indentStr] = 0;
|
|
1137
|
-
indentStringCounts[indentStr] += 1;
|
|
1138
|
-
});
|
|
1139
|
-
return Object.keys(indentStringCounts).sort((a, b) => {
|
|
1140
|
-
return indentStringCounts[a] - indentStringCounts[b];
|
|
1141
|
-
})[0] || " ";
|
|
1142
|
-
}
|
|
1143
|
-
indent(indentStr) {
|
|
1144
|
-
if (!arguments.length) indentStr = this.getIndentString();
|
|
1145
|
-
if (indentStr === "") return this;
|
|
1146
|
-
let trailingNewline = !this.intro || this.intro.slice(-1) === "\n";
|
|
1147
|
-
this.sources.forEach((source, i) => {
|
|
1148
|
-
const separator = source.separator !== void 0 ? source.separator : this.separator;
|
|
1149
|
-
const indentStart = trailingNewline || i > 0 && /\r?\n$/.test(separator);
|
|
1150
|
-
source.content.indent(indentStr, {
|
|
1151
|
-
exclude: source.indentExclusionRanges,
|
|
1152
|
-
indentStart
|
|
1153
|
-
});
|
|
1154
|
-
trailingNewline = source.content.lastChar() === "\n";
|
|
1155
|
-
});
|
|
1156
|
-
if (this.intro) this.intro = indentStr + this.intro.replace(/^[^\n]/gm, (match, index) => {
|
|
1157
|
-
return index > 0 ? indentStr + match : match;
|
|
1158
|
-
});
|
|
1159
|
-
return this;
|
|
1160
|
-
}
|
|
1161
|
-
prepend(str) {
|
|
1162
|
-
this.intro = str + this.intro;
|
|
1163
|
-
return this;
|
|
1164
|
-
}
|
|
1165
|
-
toString() {
|
|
1166
|
-
const body = this.sources.map((source, i) => {
|
|
1167
|
-
const separator = source.separator !== void 0 ? source.separator : this.separator;
|
|
1168
|
-
return (i > 0 ? separator : "") + source.content.toString();
|
|
1169
|
-
}).join("");
|
|
1170
|
-
return this.intro + body;
|
|
1171
|
-
}
|
|
1172
|
-
isEmpty() {
|
|
1173
|
-
if (this.intro.length && this.intro.trim()) return false;
|
|
1174
|
-
if (this.sources.some((source) => !source.content.isEmpty())) return false;
|
|
1175
|
-
return true;
|
|
1176
|
-
}
|
|
1177
|
-
length() {
|
|
1178
|
-
return this.sources.reduce((length, source) => length + source.content.length(), this.intro.length);
|
|
1179
|
-
}
|
|
1180
|
-
trimLines() {
|
|
1181
|
-
return this.trim("[\\r\\n]");
|
|
1182
|
-
}
|
|
1183
|
-
trim(charType) {
|
|
1184
|
-
return this.trimStart(charType).trimEnd(charType);
|
|
1185
|
-
}
|
|
1186
|
-
trimStart(charType) {
|
|
1187
|
-
const rx = new RegExp("^" + (charType || "\\s") + "+");
|
|
1188
|
-
this.intro = this.intro.replace(rx, "");
|
|
1189
|
-
if (!this.intro) {
|
|
1190
|
-
let source;
|
|
1191
|
-
let i = 0;
|
|
1192
|
-
do {
|
|
1193
|
-
source = this.sources[i++];
|
|
1194
|
-
if (!source) break;
|
|
1195
|
-
} while (!source.content.trimStartAborted(charType));
|
|
1196
|
-
}
|
|
1197
|
-
return this;
|
|
1198
|
-
}
|
|
1199
|
-
trimEnd(charType) {
|
|
1200
|
-
const rx = new RegExp((charType || "\\s") + "+$");
|
|
1201
|
-
let source;
|
|
1202
|
-
let i = this.sources.length - 1;
|
|
1203
|
-
do {
|
|
1204
|
-
source = this.sources[i--];
|
|
1205
|
-
if (!source) {
|
|
1206
|
-
this.intro = this.intro.replace(rx, "");
|
|
1207
|
-
break;
|
|
1208
|
-
}
|
|
1209
|
-
} while (!source.content.trimEndAborted(charType));
|
|
1210
|
-
return this;
|
|
1211
|
-
}
|
|
1212
|
-
};
|
|
1213
|
-
|
|
1214
|
-
//#endregion
|
|
1215
|
-
//#region src/_origin/lib.ts
|
|
1216
|
-
/** Generate a CSS bundle from Rollup context */
|
|
1217
|
-
function generateCssBundle(plugin) {
|
|
1218
|
-
const cssBundle = new Bundle();
|
|
1219
|
-
const extractedCssIds = /* @__PURE__ */ new Set();
|
|
1220
|
-
const cssFiles = {};
|
|
1221
|
-
for (const id of plugin.getModuleIds()) if (cssFileFilter.test(id)) cssFiles[id] = buildImportChain(id, plugin);
|
|
1222
|
-
for (const id of sortModules(cssFiles)) {
|
|
1223
|
-
const { importedIds } = plugin.getModuleInfo(id) ?? {};
|
|
1224
|
-
for (const importedId of importedIds ?? []) {
|
|
1225
|
-
const resolution = plugin.getModuleInfo(importedId);
|
|
1226
|
-
if (resolution?.meta.css && !extractedCssIds.has(resolution.id)) {
|
|
1227
|
-
extractedCssIds.add(resolution.id);
|
|
1228
|
-
cssBundle.addSource({
|
|
1229
|
-
filename: resolution.id,
|
|
1230
|
-
content: new MagicString(resolution.meta.css)
|
|
1231
|
-
});
|
|
1232
|
-
}
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
return {
|
|
1236
|
-
bundle: cssBundle,
|
|
1237
|
-
extractedCssIds
|
|
1238
|
-
};
|
|
1239
|
-
}
|
|
1240
|
-
/** Trace a file back through its importers, building an ordered list */
|
|
1241
|
-
function buildImportChain(id, plugin) {
|
|
1242
|
-
let mod = plugin.getModuleInfo(id);
|
|
1243
|
-
if (!mod) return [];
|
|
1244
|
-
/** [id, order] */
|
|
1245
|
-
const chain = [[id, -1]];
|
|
1246
|
-
while (!mod.isEntry) {
|
|
1247
|
-
const { id: currentId, importers } = mod;
|
|
1248
|
-
const lastImporterId = importers.at(-1);
|
|
1249
|
-
if (!lastImporterId) break;
|
|
1250
|
-
if (chain.some(([id]) => id === lastImporterId)) {
|
|
1251
|
-
plugin.warn(`Circular import detected. Can’t determine ideal import order of module.\n${chain.reverse().join("\n → ")}`);
|
|
1252
|
-
break;
|
|
1253
|
-
}
|
|
1254
|
-
mod = plugin.getModuleInfo(lastImporterId);
|
|
1255
|
-
if (!mod) break;
|
|
1256
|
-
chain.push([lastImporterId, mod.importedIds.indexOf(currentId)]);
|
|
1257
|
-
}
|
|
1258
|
-
return chain.reverse();
|
|
1259
|
-
}
|
|
1260
|
-
/** Compare import chains to determine a flat ordering for modules */
|
|
1261
|
-
function sortModules(modules) {
|
|
1262
|
-
const sortedModules = Object.entries(modules);
|
|
1263
|
-
sortedModules.sort(([_idA, chainA], [_idB, chainB]) => {
|
|
1264
|
-
const shorterChain = Math.min(chainA.length, chainB.length);
|
|
1265
|
-
for (let i = 0; i < shorterChain; i++) {
|
|
1266
|
-
const [moduleA, orderA] = chainA[i];
|
|
1267
|
-
const [moduleB, orderB] = chainB[i];
|
|
1268
|
-
if (moduleA === moduleB && orderA === orderB) continue;
|
|
1269
|
-
if (orderA !== orderB) return orderA - orderB;
|
|
1270
|
-
}
|
|
1271
|
-
return 0;
|
|
1272
|
-
});
|
|
1273
|
-
return sortedModules.map(([id]) => id);
|
|
1274
|
-
}
|
|
1275
|
-
const SIDE_EFFECT_IMPORT_RE = /^\s*import\s+['"]([^'"]+)['"]\s*;?\s*/gm;
|
|
1276
|
-
/** Remove specific side effect imports from JS */
|
|
1277
|
-
function stripSideEffectImportsMatching(code, sources) {
|
|
1278
|
-
const matches = code.matchAll(SIDE_EFFECT_IMPORT_RE);
|
|
1279
|
-
if (!matches) return code;
|
|
1280
|
-
let output = code;
|
|
1281
|
-
for (const match of matches) {
|
|
1282
|
-
if (!match[1] || !sources.includes(match[1])) continue;
|
|
1283
|
-
output = output.replace(match[0], "");
|
|
1284
|
-
}
|
|
1285
|
-
return output;
|
|
1286
|
-
}
|
|
1287
|
-
async function tryGetPackageName(cwd) {
|
|
1288
|
-
try {
|
|
1289
|
-
return __require(posix.join(cwd, "package.json"))?.name || null;
|
|
1290
|
-
} catch {
|
|
1291
|
-
return null;
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
//#endregion
|
|
1296
|
-
//#region src/_origin/index.ts
|
|
1297
|
-
const { relative, normalize, dirname } = posix;
|
|
1298
|
-
const TSDOWN_CSS_FILE_NAME = "__ve-tmp__.css";
|
|
1299
|
-
function vanillaExtractPlugin$1({ identifiers, cwd = process.cwd(), esbuildOptions, extract = false, unstable_injectFilescopes = false, prepend } = {}, filterAvailableEntries) {
|
|
1300
|
-
if (extract === true) extract = {};
|
|
1301
|
-
const prependFn = typeof prepend === "string" ? () => prepend : prepend ? prepend : () => {};
|
|
1302
|
-
const isProduction = process.env.NODE_ENV === "production";
|
|
1303
|
-
let extractedCssIds = /* @__PURE__ */ new Set();
|
|
1304
|
-
return {
|
|
1305
|
-
name: "vanilla-extract",
|
|
1306
|
-
buildStart() {
|
|
1307
|
-
extractedCssIds = /* @__PURE__ */ new Set();
|
|
1308
|
-
},
|
|
1309
|
-
async transform(code, id) {
|
|
1310
|
-
if (!cssFileFilter.test(id)) return null;
|
|
1311
|
-
const identOption = identifiers ?? (isProduction ? "short" : "debug");
|
|
1312
|
-
const [filePath] = id.split("?");
|
|
1313
|
-
if (unstable_injectFilescopes) return {
|
|
1314
|
-
code: await transform({
|
|
1315
|
-
source: code,
|
|
1316
|
-
filePath: id,
|
|
1317
|
-
rootPath: cwd,
|
|
1318
|
-
packageName: await tryGetPackageName(cwd) ?? "",
|
|
1319
|
-
identOption
|
|
1320
|
-
}),
|
|
1321
|
-
map: { mappings: "" }
|
|
1322
|
-
};
|
|
1323
|
-
const { source, watchFiles } = await compile({
|
|
1324
|
-
filePath,
|
|
1325
|
-
cwd,
|
|
1326
|
-
esbuildOptions,
|
|
1327
|
-
identOption
|
|
1328
|
-
});
|
|
1329
|
-
for (const file of watchFiles) this.addWatchFile(file);
|
|
1330
|
-
return {
|
|
1331
|
-
code: await processVanillaFile({
|
|
1332
|
-
source,
|
|
1333
|
-
filePath,
|
|
1334
|
-
identOption
|
|
1335
|
-
}),
|
|
1336
|
-
map: { mappings: "" }
|
|
1337
|
-
};
|
|
1338
|
-
},
|
|
1339
|
-
async resolveId(id) {
|
|
1340
|
-
if (!virtualCssFileFilter.test(id)) return null;
|
|
1341
|
-
const { fileName, source } = await getSourceFromVirtualCssFile(id);
|
|
1342
|
-
return {
|
|
1343
|
-
id: fileName,
|
|
1344
|
-
external: true,
|
|
1345
|
-
meta: { css: source }
|
|
1346
|
-
};
|
|
1347
|
-
},
|
|
1348
|
-
renderChunk(code, chunkInfo) {
|
|
1349
|
-
const chunkPath = dirname(chunkInfo.fileName);
|
|
1350
|
-
return {
|
|
1351
|
-
code: chunkInfo.imports.reduce((codeResult, importPath) => {
|
|
1352
|
-
const moduleInfo = this.getModuleInfo(importPath);
|
|
1353
|
-
if (!moduleInfo?.meta.css || extract) return codeResult;
|
|
1354
|
-
const assetId = this.emitFile({
|
|
1355
|
-
type: "asset",
|
|
1356
|
-
name: moduleInfo.id,
|
|
1357
|
-
source: moduleInfo.meta.css
|
|
1358
|
-
});
|
|
1359
|
-
const relativeAssetPath = `./${normalize(relative(chunkPath, this.getFileName(assetId)))}`;
|
|
1360
|
-
return codeResult.replace(importPath, relativeAssetPath);
|
|
1361
|
-
}, code),
|
|
1362
|
-
map: null
|
|
1363
|
-
};
|
|
1364
|
-
},
|
|
1365
|
-
async generateBundle(_options, bundle) {
|
|
1366
|
-
if (!extract) return;
|
|
1367
|
-
const tsdownCssBundle = bundle[TSDOWN_CSS_FILE_NAME];
|
|
1368
|
-
if (tsdownCssBundle) delete bundle[TSDOWN_CSS_FILE_NAME];
|
|
1369
|
-
const availableEntries = filterAvailableEntries();
|
|
1370
|
-
for (const chunk of Object.values(bundle)) {
|
|
1371
|
-
if (chunk.type !== "chunk" || !chunk.isEntry) continue;
|
|
1372
|
-
if (availableEntries && !availableEntries.includes(chunk.name)) continue;
|
|
1373
|
-
const jsFileName = chunk.fileName;
|
|
1374
|
-
if (/\.d\.(ts|mts|cts)$/.test(jsFileName)) continue;
|
|
1375
|
-
const extractName = extract.name || "[name].css";
|
|
1376
|
-
const name = jsFileName.replace(/\.(js|mjs)$/, "");
|
|
1377
|
-
const cssFileName = typeof extractName === "function" ? extractName(chunk) : extractName.replace("[name]", name);
|
|
1378
|
-
const { bundle: cssBundle, extractedCssIds: extractedIds } = generateCssBundle(this);
|
|
1379
|
-
extractedCssIds = extractedIds;
|
|
1380
|
-
const prependCode = await prependFn({ cssFileName });
|
|
1381
|
-
const tsdownCssCode = tsdownCssBundle && tsdownCssBundle.type === "asset" ? tsdownCssBundle.source.toString() + "\n" : "";
|
|
1382
|
-
this.emitFile({
|
|
1383
|
-
type: "asset",
|
|
1384
|
-
fileName: cssFileName,
|
|
1385
|
-
source: (prependCode || "") + tsdownCssCode + cssBundle.toString()
|
|
1386
|
-
});
|
|
1387
|
-
if (extract.sourcemap) {
|
|
1388
|
-
const sourcemapName = `${cssFileName}.map`;
|
|
1389
|
-
this.emitFile({
|
|
1390
|
-
type: "asset",
|
|
1391
|
-
name: sourcemapName,
|
|
1392
|
-
originalFileName: sourcemapName,
|
|
1393
|
-
source: cssBundle.generateMap({
|
|
1394
|
-
file: name,
|
|
1395
|
-
includeContent: true
|
|
1396
|
-
}).toString()
|
|
1397
|
-
});
|
|
1398
|
-
}
|
|
1399
|
-
}
|
|
1400
|
-
await Promise.all(Object.entries(bundle).map(async ([id, chunk]) => {
|
|
1401
|
-
if (chunk.type === "chunk" && (id.endsWith(".js") || id.endsWith(".mjs")) && chunk.imports.some((specifier) => extractedCssIds.has(specifier))) chunk.code = await stripSideEffectImportsMatching(chunk.code, [...extractedCssIds]);
|
|
1402
|
-
}));
|
|
1403
|
-
}
|
|
1404
|
-
};
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
6
|
//#endregion
|
|
1408
7
|
//#region src/plugin.ts
|
|
1409
8
|
async function createVanillaExtractPlugin(options = {}) {
|
|
@@ -1411,32 +10,44 @@ async function createVanillaExtractPlugin(options = {}) {
|
|
|
1411
10
|
name: PLUGIN_NAME,
|
|
1412
11
|
_options: options,
|
|
1413
12
|
hooks: { async setupWorkspace(ctx, getWorkspace) {
|
|
13
|
+
const entryIds = Object.keys(ctx.config.entries);
|
|
14
|
+
const cssFileName = `${entryIds.includes(".") ? ctx.dir.basename : entryIds[0] ?? ctx.dir.basename}.css`;
|
|
1414
15
|
ctx.css = {
|
|
1415
16
|
splitting: false,
|
|
1416
|
-
fileName:
|
|
17
|
+
fileName: cssFileName
|
|
1417
18
|
};
|
|
1418
19
|
ctx.mergeExternals(/@vanilla-extract/);
|
|
1419
20
|
ctx.meta.hasVanillaExtract = !!await findFile(ctx.dirs.src.value, /\.css\.ts$/);
|
|
1420
21
|
if (ctx.meta.hasVanillaExtract) {
|
|
1421
|
-
const originalPlugin = vanillaExtractPlugin
|
|
22
|
+
const originalPlugin = vanillaExtractPlugin({
|
|
1422
23
|
...options,
|
|
1423
|
-
extract:
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
return exportItems.filter((item) => item.id.endsWith(".css")).map((item) => path.parse(item.id).name);
|
|
24
|
+
extract: {
|
|
25
|
+
name: cssFileName,
|
|
26
|
+
sourcemap: false
|
|
27
|
+
}
|
|
1428
28
|
});
|
|
1429
29
|
ctx.plugins.push(originalPlugin);
|
|
30
|
+
ctx.plugins.push({
|
|
31
|
+
name: `${PLUGIN_NAME}:rename-css`,
|
|
32
|
+
outputOptions(opts) {
|
|
33
|
+
const original = opts.assetFileNames;
|
|
34
|
+
opts.assetFileNames = (assetInfo) => {
|
|
35
|
+
if (assetInfo.names.includes(cssFileName)) return cssFileName;
|
|
36
|
+
if (typeof original === "function") return original(assetInfo);
|
|
37
|
+
return original ?? "assets/[name]-[hash][extname]";
|
|
38
|
+
};
|
|
39
|
+
return opts;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
1430
42
|
}
|
|
1431
43
|
} }
|
|
1432
44
|
});
|
|
1433
45
|
}
|
|
1434
|
-
|
|
1435
46
|
//#endregion
|
|
1436
47
|
//#region src/vite.ts
|
|
1437
48
|
async function ViteVanillaExtractPlugin(options = {}) {
|
|
1438
|
-
const { identifiers: baseIdentifiers } = (await findProjectPlugin(
|
|
1439
|
-
return [...vanillaExtractPlugin({
|
|
49
|
+
const { identifiers: baseIdentifiers } = (await findProjectPlugin("plugboy-vanilla-extract"))?._options || {};
|
|
50
|
+
return [...vanillaExtractPlugin$1({
|
|
1440
51
|
identifiers: baseIdentifiers,
|
|
1441
52
|
...options
|
|
1442
53
|
}), {
|
|
@@ -1448,7 +59,7 @@ async function ViteVanillaExtractPlugin(options = {}) {
|
|
|
1448
59
|
}
|
|
1449
60
|
}];
|
|
1450
61
|
}
|
|
1451
|
-
|
|
1452
62
|
//#endregion
|
|
1453
63
|
export { PLUGIN_NAME, ViteVanillaExtractPlugin, createVanillaExtractPlugin };
|
|
64
|
+
|
|
1454
65
|
//# sourceMappingURL=plugboy-vanilla-extract-plugin.mjs.map
|