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