@bagelink/blox 1.15.145 → 1.15.151

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,1075 +1,7 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { join, dirname } from "node:path";
3
3
  import process from "node:process";
4
- var comma = ",".charCodeAt(0);
5
- var semicolon = ";".charCodeAt(0);
6
- var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
7
- var intToChar = new Uint8Array(64);
8
- var charToInt = new Uint8Array(128);
9
- for (let i = 0; i < chars.length; i++) {
10
- const c = chars.charCodeAt(i);
11
- intToChar[i] = c;
12
- charToInt[c] = i;
13
- }
14
- function encodeInteger(builder, num, relative) {
15
- let delta = num - relative;
16
- delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
17
- do {
18
- let clamped = delta & 31;
19
- delta >>>= 5;
20
- if (delta > 0) clamped |= 32;
21
- builder.write(intToChar[clamped]);
22
- } while (delta > 0);
23
- return num;
24
- }
25
- var bufLength = 1024 * 16;
26
- var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
27
- decode(buf) {
28
- const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
29
- return out.toString();
30
- }
31
- } : {
32
- decode(buf) {
33
- let out = "";
34
- for (let i = 0; i < buf.length; i++) {
35
- out += String.fromCharCode(buf[i]);
36
- }
37
- return out;
38
- }
39
- };
40
- var StringWriter = class {
41
- constructor() {
42
- this.pos = 0;
43
- this.out = "";
44
- this.buffer = new Uint8Array(bufLength);
45
- }
46
- write(v) {
47
- const { buffer } = this;
48
- buffer[this.pos++] = v;
49
- if (this.pos === bufLength) {
50
- this.out += td.decode(buffer);
51
- this.pos = 0;
52
- }
53
- }
54
- flush() {
55
- const { buffer, out, pos } = this;
56
- return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
57
- }
58
- };
59
- function encode(decoded) {
60
- const writer = new StringWriter();
61
- let sourcesIndex = 0;
62
- let sourceLine = 0;
63
- let sourceColumn = 0;
64
- let namesIndex = 0;
65
- for (let i = 0; i < decoded.length; i++) {
66
- const line = decoded[i];
67
- if (i > 0) writer.write(semicolon);
68
- if (line.length === 0) continue;
69
- let genColumn = 0;
70
- for (let j = 0; j < line.length; j++) {
71
- const segment = line[j];
72
- if (j > 0) writer.write(comma);
73
- genColumn = encodeInteger(writer, segment[0], genColumn);
74
- if (segment.length === 1) continue;
75
- sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
76
- sourceLine = encodeInteger(writer, segment[2], sourceLine);
77
- sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
78
- if (segment.length === 4) continue;
79
- namesIndex = encodeInteger(writer, segment[4], namesIndex);
80
- }
81
- }
82
- return writer.flush();
83
- }
84
- class BitSet {
85
- constructor(arg) {
86
- this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
87
- }
88
- add(n2) {
89
- this.bits[n2 >> 5] |= 1 << (n2 & 31);
90
- }
91
- has(n2) {
92
- return !!(this.bits[n2 >> 5] & 1 << (n2 & 31));
93
- }
94
- }
95
- class Chunk {
96
- constructor(start, end, content) {
97
- this.start = start;
98
- this.end = end;
99
- this.original = content;
100
- this.intro = "";
101
- this.outro = "";
102
- this.content = content;
103
- this.storeName = false;
104
- this.edited = false;
105
- {
106
- this.previous = null;
107
- this.next = null;
108
- }
109
- }
110
- appendLeft(content) {
111
- this.outro += content;
112
- }
113
- appendRight(content) {
114
- this.intro = this.intro + content;
115
- }
116
- clone() {
117
- const chunk = new Chunk(this.start, this.end, this.original);
118
- chunk.intro = this.intro;
119
- chunk.outro = this.outro;
120
- chunk.content = this.content;
121
- chunk.storeName = this.storeName;
122
- chunk.edited = this.edited;
123
- return chunk;
124
- }
125
- contains(index) {
126
- return this.start < index && index < this.end;
127
- }
128
- eachNext(fn) {
129
- let chunk = this;
130
- while (chunk) {
131
- fn(chunk);
132
- chunk = chunk.next;
133
- }
134
- }
135
- eachPrevious(fn) {
136
- let chunk = this;
137
- while (chunk) {
138
- fn(chunk);
139
- chunk = chunk.previous;
140
- }
141
- }
142
- edit(content, storeName, contentOnly) {
143
- this.content = content;
144
- if (!contentOnly) {
145
- this.intro = "";
146
- this.outro = "";
147
- }
148
- this.storeName = storeName;
149
- this.edited = true;
150
- return this;
151
- }
152
- prependLeft(content) {
153
- this.outro = content + this.outro;
154
- }
155
- prependRight(content) {
156
- this.intro = content + this.intro;
157
- }
158
- reset() {
159
- this.intro = "";
160
- this.outro = "";
161
- if (this.edited) {
162
- this.content = this.original;
163
- this.storeName = false;
164
- this.edited = false;
165
- }
166
- }
167
- split(index) {
168
- const sliceIndex = index - this.start;
169
- const originalBefore = this.original.slice(0, sliceIndex);
170
- const originalAfter = this.original.slice(sliceIndex);
171
- this.original = originalBefore;
172
- const newChunk = new Chunk(index, this.end, originalAfter);
173
- newChunk.outro = this.outro;
174
- this.outro = "";
175
- this.end = index;
176
- if (this.edited) {
177
- newChunk.edit("", false);
178
- this.content = "";
179
- } else {
180
- this.content = originalBefore;
181
- }
182
- newChunk.next = this.next;
183
- if (newChunk.next) newChunk.next.previous = newChunk;
184
- newChunk.previous = this;
185
- this.next = newChunk;
186
- return newChunk;
187
- }
188
- toString() {
189
- return this.intro + this.content + this.outro;
190
- }
191
- trimEnd(rx) {
192
- this.outro = this.outro.replace(rx, "");
193
- if (this.outro.length) return true;
194
- const trimmed = this.content.replace(rx, "");
195
- if (trimmed.length) {
196
- if (trimmed !== this.content) {
197
- this.split(this.start + trimmed.length).edit("", void 0, true);
198
- if (this.edited) {
199
- this.edit(trimmed, this.storeName, true);
200
- }
201
- }
202
- return true;
203
- } else {
204
- this.edit("", void 0, true);
205
- this.intro = this.intro.replace(rx, "");
206
- if (this.intro.length) return true;
207
- }
208
- }
209
- trimStart(rx) {
210
- this.intro = this.intro.replace(rx, "");
211
- if (this.intro.length) return true;
212
- const trimmed = this.content.replace(rx, "");
213
- if (trimmed.length) {
214
- if (trimmed !== this.content) {
215
- const newChunk = this.split(this.end - trimmed.length);
216
- if (this.edited) {
217
- newChunk.edit(trimmed, this.storeName, true);
218
- }
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") {
231
- return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
232
- } else if (typeof Buffer === "function") {
233
- return (str) => Buffer.from(str, "utf-8").toString("base64");
234
- } else {
235
- return () => {
236
- throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
237
- };
238
- }
239
- }
240
- const btoa = /* @__PURE__ */ getBtoa();
241
- class SourceMap {
242
- constructor(properties) {
243
- this.version = 3;
244
- this.file = properties.file;
245
- this.sources = properties.sources;
246
- this.sourcesContent = properties.sourcesContent;
247
- this.names = properties.names;
248
- this.mappings = encode(properties.mappings);
249
- if (typeof properties.x_google_ignoreList !== "undefined") {
250
- this.x_google_ignoreList = properties.x_google_ignoreList;
251
- }
252
- if (typeof properties.debugId !== "undefined") {
253
- this.debugId = properties.debugId;
254
- }
255
- }
256
- toString() {
257
- return JSON.stringify(this);
258
- }
259
- toUrl() {
260
- return "data:application/json;charset=utf-8;base64," + btoa(this.toString());
261
- }
262
- }
263
- function guessIndent(code) {
264
- const lines = code.split("\n");
265
- const tabbed = lines.filter((line) => /^\t+/.test(line));
266
- const spaced = lines.filter((line) => /^ {2,}/.test(line));
267
- if (tabbed.length === 0 && spaced.length === 0) {
268
- return null;
269
- }
270
- if (tabbed.length >= spaced.length) {
271
- return " ";
272
- }
273
- const min = spaced.reduce((previous, current) => {
274
- const numSpaces = /^ +/.exec(current)[0].length;
275
- return Math.min(numSpaces, previous);
276
- }, Infinity);
277
- return new Array(min + 1).join(" ");
278
- }
279
- function getRelativePath(from, to) {
280
- const fromParts = from.split(/[/\\]/);
281
- const toParts = to.split(/[/\\]/);
282
- fromParts.pop();
283
- while (fromParts[0] === toParts[0]) {
284
- fromParts.shift();
285
- toParts.shift();
286
- }
287
- if (fromParts.length) {
288
- let i = fromParts.length;
289
- while (i--) fromParts[i] = "..";
290
- }
291
- return fromParts.concat(toParts).join("/");
292
- }
293
- const toString = Object.prototype.toString;
294
- function isObject(thing) {
295
- return toString.call(thing) === "[object Object]";
296
- }
297
- function getLocator(source) {
298
- const originalLines = source.split("\n");
299
- const lineOffsets = [];
300
- for (let i = 0, pos = 0; i < originalLines.length; i++) {
301
- lineOffsets.push(pos);
302
- pos += originalLines[i].length + 1;
303
- }
304
- return function locate(index) {
305
- let i = 0;
306
- let j = lineOffsets.length;
307
- while (i < j) {
308
- const m = i + j >> 1;
309
- if (index < lineOffsets[m]) {
310
- j = m;
311
- } else {
312
- i = m + 1;
313
- }
314
- }
315
- const line = i - 1;
316
- const column = index - lineOffsets[line];
317
- return { line, column };
318
- };
319
- }
320
- const wordRegex = /\w/;
321
- class Mappings {
322
- constructor(hires) {
323
- this.hires = hires;
324
- this.generatedCodeLine = 0;
325
- this.generatedCodeColumn = 0;
326
- this.raw = [];
327
- this.rawSegments = this.raw[this.generatedCodeLine] = [];
328
- this.pending = null;
329
- }
330
- addEdit(sourceIndex, content, loc, nameIndex) {
331
- if (content.length) {
332
- const contentLengthMinusOne = content.length - 1;
333
- let contentLineEnd = content.indexOf("\n", 0);
334
- let previousContentLineEnd = -1;
335
- while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
336
- const segment2 = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
337
- if (nameIndex >= 0) {
338
- segment2.push(nameIndex);
339
- }
340
- this.rawSegments.push(segment2);
341
- this.generatedCodeLine += 1;
342
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
343
- this.generatedCodeColumn = 0;
344
- previousContentLineEnd = contentLineEnd;
345
- contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
346
- }
347
- const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
348
- if (nameIndex >= 0) {
349
- segment.push(nameIndex);
350
- }
351
- this.rawSegments.push(segment);
352
- this.advance(content.slice(previousContentLineEnd + 1));
353
- } else if (this.pending) {
354
- this.rawSegments.push(this.pending);
355
- this.advance(content);
356
- }
357
- this.pending = null;
358
- }
359
- addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
360
- let originalCharIndex = chunk.start;
361
- let first = true;
362
- let charInHiresBoundary = false;
363
- while (originalCharIndex < chunk.end) {
364
- if (original[originalCharIndex] === "\n") {
365
- loc.line += 1;
366
- loc.column = 0;
367
- this.generatedCodeLine += 1;
368
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
369
- this.generatedCodeColumn = 0;
370
- first = true;
371
- charInHiresBoundary = false;
372
- } else {
373
- if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
374
- const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
375
- if (this.hires === "boundary") {
376
- if (wordRegex.test(original[originalCharIndex])) {
377
- if (!charInHiresBoundary) {
378
- this.rawSegments.push(segment);
379
- charInHiresBoundary = true;
380
- }
381
- } else {
382
- this.rawSegments.push(segment);
383
- charInHiresBoundary = false;
384
- }
385
- } else {
386
- this.rawSegments.push(segment);
387
- }
388
- }
389
- loc.column += 1;
390
- this.generatedCodeColumn += 1;
391
- first = false;
392
- }
393
- originalCharIndex += 1;
394
- }
395
- this.pending = null;
396
- }
397
- advance(str) {
398
- if (!str) return;
399
- const lines = str.split("\n");
400
- if (lines.length > 1) {
401
- for (let i = 0; i < lines.length - 1; i++) {
402
- this.generatedCodeLine++;
403
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
404
- }
405
- this.generatedCodeColumn = 0;
406
- }
407
- this.generatedCodeColumn += lines[lines.length - 1].length;
408
- }
409
- }
410
- const n = "\n";
411
- const warned = {
412
- insertLeft: false,
413
- insertRight: false,
414
- storeName: false
415
- };
416
- class MagicString {
417
- constructor(string, options = {}) {
418
- const chunk = new Chunk(0, string.length, string);
419
- Object.defineProperties(this, {
420
- original: { writable: true, value: string },
421
- outro: { writable: true, value: "" },
422
- intro: { writable: true, value: "" },
423
- firstChunk: { writable: true, value: chunk },
424
- lastChunk: { writable: true, value: chunk },
425
- lastSearchedChunk: { writable: true, value: chunk },
426
- byStart: { writable: true, value: {} },
427
- byEnd: { writable: true, value: {} },
428
- filename: { writable: true, value: options.filename },
429
- indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
430
- sourcemapLocations: { writable: true, value: new BitSet() },
431
- storedNames: { writable: true, value: {} },
432
- indentStr: { writable: true, value: void 0 },
433
- ignoreList: { writable: true, value: options.ignoreList },
434
- offset: { writable: true, value: options.offset || 0 }
435
- });
436
- this.byStart[0] = chunk;
437
- this.byEnd[string.length] = chunk;
438
- }
439
- addSourcemapLocation(char) {
440
- this.sourcemapLocations.add(char);
441
- }
442
- append(content) {
443
- if (typeof content !== "string") throw new TypeError("outro content must be a string");
444
- this.outro += content;
445
- return this;
446
- }
447
- appendLeft(index, content) {
448
- index = index + this.offset;
449
- if (typeof content !== "string") throw new TypeError("inserted content must be a string");
450
- this._split(index);
451
- const chunk = this.byEnd[index];
452
- if (chunk) {
453
- chunk.appendLeft(content);
454
- } else {
455
- this.intro += content;
456
- }
457
- return this;
458
- }
459
- appendRight(index, content) {
460
- index = index + this.offset;
461
- if (typeof content !== "string") throw new TypeError("inserted content must be a string");
462
- this._split(index);
463
- const chunk = this.byStart[index];
464
- if (chunk) {
465
- chunk.appendRight(content);
466
- } else {
467
- this.outro += content;
468
- }
469
- return this;
470
- }
471
- clone() {
472
- const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
473
- let originalChunk = this.firstChunk;
474
- let clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
475
- while (originalChunk) {
476
- cloned.byStart[clonedChunk.start] = clonedChunk;
477
- cloned.byEnd[clonedChunk.end] = clonedChunk;
478
- const nextOriginalChunk = originalChunk.next;
479
- const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
480
- if (nextClonedChunk) {
481
- clonedChunk.next = nextClonedChunk;
482
- nextClonedChunk.previous = clonedChunk;
483
- clonedChunk = nextClonedChunk;
484
- }
485
- originalChunk = nextOriginalChunk;
486
- }
487
- cloned.lastChunk = clonedChunk;
488
- if (this.indentExclusionRanges) {
489
- cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
490
- }
491
- cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
492
- cloned.intro = this.intro;
493
- cloned.outro = this.outro;
494
- return cloned;
495
- }
496
- generateDecodedMap(options) {
497
- options = options || {};
498
- const sourceIndex = 0;
499
- const names = Object.keys(this.storedNames);
500
- const mappings = new Mappings(options.hires);
501
- const locate = getLocator(this.original);
502
- if (this.intro) {
503
- mappings.advance(this.intro);
504
- }
505
- this.firstChunk.eachNext((chunk) => {
506
- const loc = locate(chunk.start);
507
- if (chunk.intro.length) mappings.advance(chunk.intro);
508
- if (chunk.edited) {
509
- mappings.addEdit(
510
- sourceIndex,
511
- chunk.content,
512
- loc,
513
- chunk.storeName ? names.indexOf(chunk.original) : -1
514
- );
515
- } else {
516
- mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
517
- }
518
- if (chunk.outro.length) mappings.advance(chunk.outro);
519
- });
520
- if (this.outro) {
521
- mappings.advance(this.outro);
522
- }
523
- return {
524
- file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
525
- sources: [
526
- options.source ? getRelativePath(options.file || "", options.source) : options.file || ""
527
- ],
528
- sourcesContent: options.includeContent ? [this.original] : void 0,
529
- names,
530
- mappings: mappings.raw,
531
- x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
532
- };
533
- }
534
- generateMap(options) {
535
- return new SourceMap(this.generateDecodedMap(options));
536
- }
537
- _ensureindentStr() {
538
- if (this.indentStr === void 0) {
539
- this.indentStr = guessIndent(this.original);
540
- }
541
- }
542
- _getRawIndentString() {
543
- this._ensureindentStr();
544
- return this.indentStr;
545
- }
546
- getIndentString() {
547
- this._ensureindentStr();
548
- return this.indentStr === null ? " " : this.indentStr;
549
- }
550
- indent(indentStr, options) {
551
- const pattern = /^[^\r\n]/gm;
552
- if (isObject(indentStr)) {
553
- options = indentStr;
554
- indentStr = void 0;
555
- }
556
- if (indentStr === void 0) {
557
- this._ensureindentStr();
558
- indentStr = this.indentStr || " ";
559
- }
560
- if (indentStr === "") return this;
561
- options = options || {};
562
- const isExcluded = {};
563
- if (options.exclude) {
564
- const exclusions = typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude;
565
- exclusions.forEach((exclusion) => {
566
- for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
567
- isExcluded[i] = true;
568
- }
569
- });
570
- }
571
- let shouldIndentNextCharacter = options.indentStart !== false;
572
- const replacer = (match) => {
573
- if (shouldIndentNextCharacter) return `${indentStr}${match}`;
574
- shouldIndentNextCharacter = true;
575
- return match;
576
- };
577
- this.intro = this.intro.replace(pattern, replacer);
578
- let charIndex = 0;
579
- let chunk = this.firstChunk;
580
- while (chunk) {
581
- const end = chunk.end;
582
- if (chunk.edited) {
583
- if (!isExcluded[charIndex]) {
584
- chunk.content = chunk.content.replace(pattern, replacer);
585
- if (chunk.content.length) {
586
- shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
587
- }
588
- }
589
- } else {
590
- charIndex = chunk.start;
591
- while (charIndex < end) {
592
- if (!isExcluded[charIndex]) {
593
- const char = this.original[charIndex];
594
- if (char === "\n") {
595
- shouldIndentNextCharacter = true;
596
- } else if (char !== "\r" && shouldIndentNextCharacter) {
597
- shouldIndentNextCharacter = false;
598
- if (charIndex === chunk.start) {
599
- chunk.prependRight(indentStr);
600
- } else {
601
- this._splitChunk(chunk, charIndex);
602
- chunk = chunk.next;
603
- chunk.prependRight(indentStr);
604
- }
605
- }
606
- }
607
- charIndex += 1;
608
- }
609
- }
610
- charIndex = chunk.end;
611
- chunk = chunk.next;
612
- }
613
- this.outro = this.outro.replace(pattern, replacer);
614
- return this;
615
- }
616
- insert() {
617
- throw new Error(
618
- "magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)"
619
- );
620
- }
621
- insertLeft(index, content) {
622
- if (!warned.insertLeft) {
623
- console.warn(
624
- "magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"
625
- );
626
- warned.insertLeft = true;
627
- }
628
- return this.appendLeft(index, content);
629
- }
630
- insertRight(index, content) {
631
- if (!warned.insertRight) {
632
- console.warn(
633
- "magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"
634
- );
635
- warned.insertRight = true;
636
- }
637
- return this.prependRight(index, content);
638
- }
639
- move(start, end, index) {
640
- start = start + this.offset;
641
- end = end + this.offset;
642
- index = index + this.offset;
643
- if (index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
644
- this._split(start);
645
- this._split(end);
646
- this._split(index);
647
- const first = this.byStart[start];
648
- const last = this.byEnd[end];
649
- const oldLeft = first.previous;
650
- const oldRight = last.next;
651
- const newRight = this.byStart[index];
652
- if (!newRight && last === this.lastChunk) return this;
653
- const newLeft = newRight ? newRight.previous : this.lastChunk;
654
- if (oldLeft) oldLeft.next = oldRight;
655
- if (oldRight) oldRight.previous = oldLeft;
656
- if (newLeft) newLeft.next = first;
657
- if (newRight) newRight.previous = last;
658
- if (!first.previous) this.firstChunk = last.next;
659
- if (!last.next) {
660
- this.lastChunk = first.previous;
661
- this.lastChunk.next = null;
662
- }
663
- first.previous = newLeft;
664
- last.next = newRight || null;
665
- if (!newLeft) this.firstChunk = first;
666
- if (!newRight) this.lastChunk = last;
667
- return this;
668
- }
669
- overwrite(start, end, content, options) {
670
- options = options || {};
671
- return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
672
- }
673
- update(start, end, content, options) {
674
- start = start + this.offset;
675
- end = end + this.offset;
676
- if (typeof content !== "string") throw new TypeError("replacement content must be a string");
677
- if (this.original.length !== 0) {
678
- while (start < 0) start += this.original.length;
679
- while (end < 0) end += this.original.length;
680
- }
681
- if (end > this.original.length) throw new Error("end is out of bounds");
682
- if (start === end)
683
- throw new Error(
684
- "Cannot overwrite a zero-length range – use appendLeft or prependRight instead"
685
- );
686
- this._split(start);
687
- this._split(end);
688
- if (options === true) {
689
- if (!warned.storeName) {
690
- console.warn(
691
- "The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"
692
- );
693
- warned.storeName = true;
694
- }
695
- options = { storeName: true };
696
- }
697
- const storeName = options !== void 0 ? options.storeName : false;
698
- const overwrite = options !== void 0 ? options.overwrite : false;
699
- if (storeName) {
700
- const original = this.original.slice(start, end);
701
- Object.defineProperty(this.storedNames, original, {
702
- writable: true,
703
- value: true,
704
- enumerable: true
705
- });
706
- }
707
- const first = this.byStart[start];
708
- const last = this.byEnd[end];
709
- if (first) {
710
- let chunk = first;
711
- while (chunk !== last) {
712
- if (chunk.next !== this.byStart[chunk.end]) {
713
- throw new Error("Cannot overwrite across a split point");
714
- }
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) {
737
- chunk.prependLeft(content);
738
- } else {
739
- this.intro = content + this.intro;
740
- }
741
- return this;
742
- }
743
- prependRight(index, content) {
744
- index = index + this.offset;
745
- if (typeof content !== "string") throw new TypeError("inserted content must be a string");
746
- this._split(index);
747
- const chunk = this.byStart[index];
748
- if (chunk) {
749
- chunk.prependRight(content);
750
- } else {
751
- this.outro = content + this.outro;
752
- }
753
- return this;
754
- }
755
- remove(start, end) {
756
- start = start + this.offset;
757
- end = end + this.offset;
758
- if (this.original.length !== 0) {
759
- while (start < 0) start += this.original.length;
760
- while (end < 0) end += this.original.length;
761
- }
762
- if (start === end) return this;
763
- if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
764
- if (start > end) throw new Error("end must be greater than start");
765
- this._split(start);
766
- this._split(end);
767
- let chunk = this.byStart[start];
768
- while (chunk) {
769
- chunk.intro = "";
770
- chunk.outro = "";
771
- chunk.edit("");
772
- chunk = end > chunk.end ? this.byStart[chunk.end] : null;
773
- }
774
- return this;
775
- }
776
- reset(start, end) {
777
- start = start + this.offset;
778
- end = end + this.offset;
779
- if (this.original.length !== 0) {
780
- while (start < 0) start += this.original.length;
781
- while (end < 0) end += this.original.length;
782
- }
783
- if (start === end) return this;
784
- if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
785
- if (start > end) throw new Error("end must be greater than start");
786
- this._split(start);
787
- this._split(end);
788
- let chunk = this.byStart[start];
789
- while (chunk) {
790
- chunk.reset();
791
- chunk = end > chunk.end ? this.byStart[chunk.end] : null;
792
- }
793
- return this;
794
- }
795
- lastChar() {
796
- if (this.outro.length) return this.outro[this.outro.length - 1];
797
- let chunk = this.lastChunk;
798
- do {
799
- if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
800
- if (chunk.content.length) return chunk.content[chunk.content.length - 1];
801
- if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
802
- } while (chunk = chunk.previous);
803
- if (this.intro.length) return this.intro[this.intro.length - 1];
804
- return "";
805
- }
806
- lastLine() {
807
- let lineIndex = this.outro.lastIndexOf(n);
808
- if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
809
- let lineStr = this.outro;
810
- let chunk = this.lastChunk;
811
- do {
812
- if (chunk.outro.length > 0) {
813
- lineIndex = chunk.outro.lastIndexOf(n);
814
- if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
815
- lineStr = chunk.outro + lineStr;
816
- }
817
- if (chunk.content.length > 0) {
818
- lineIndex = chunk.content.lastIndexOf(n);
819
- if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
820
- lineStr = chunk.content + lineStr;
821
- }
822
- if (chunk.intro.length > 0) {
823
- lineIndex = chunk.intro.lastIndexOf(n);
824
- if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
825
- lineStr = chunk.intro + lineStr;
826
- }
827
- } while (chunk = chunk.previous);
828
- lineIndex = this.intro.lastIndexOf(n);
829
- if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
830
- return this.intro + lineStr;
831
- }
832
- slice(start = 0, end = this.original.length - this.offset) {
833
- start = start + this.offset;
834
- end = end + this.offset;
835
- if (this.original.length !== 0) {
836
- while (start < 0) start += this.original.length;
837
- while (end < 0) end += this.original.length;
838
- }
839
- let result = "";
840
- let chunk = this.firstChunk;
841
- while (chunk && (chunk.start > start || chunk.end <= start)) {
842
- if (chunk.start < end && chunk.end >= end) {
843
- return result;
844
- }
845
- chunk = chunk.next;
846
- }
847
- if (chunk && chunk.edited && chunk.start !== start)
848
- throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
849
- const startChunk = chunk;
850
- while (chunk) {
851
- if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
852
- result += chunk.intro;
853
- }
854
- const containsEnd = chunk.start < end && chunk.end >= end;
855
- if (containsEnd && chunk.edited && chunk.end !== end)
856
- throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
857
- const sliceStart = startChunk === chunk ? start - chunk.start : 0;
858
- const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
859
- result += chunk.content.slice(sliceStart, sliceEnd);
860
- if (chunk.outro && (!containsEnd || chunk.end === end)) {
861
- result += chunk.outro;
862
- }
863
- if (containsEnd) {
864
- break;
865
- }
866
- chunk = chunk.next;
867
- }
868
- return result;
869
- }
870
- // TODO deprecate this? not really very useful
871
- snip(start, end) {
872
- const clone = this.clone();
873
- clone.remove(0, start);
874
- clone.remove(end, clone.original.length);
875
- return clone;
876
- }
877
- _split(index) {
878
- if (this.byStart[index] || this.byEnd[index]) return;
879
- let chunk = this.lastSearchedChunk;
880
- let previousChunk = chunk;
881
- const searchForward = index > chunk.end;
882
- while (chunk) {
883
- if (chunk.contains(index)) return this._splitChunk(chunk, index);
884
- chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
885
- if (chunk === previousChunk) return;
886
- previousChunk = chunk;
887
- }
888
- }
889
- _splitChunk(chunk, index) {
890
- if (chunk.edited && chunk.content.length) {
891
- const loc = getLocator(this.original)(index);
892
- throw new Error(
893
- `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
894
- );
895
- }
896
- const newChunk = chunk.split(index);
897
- this.byEnd[index] = chunk;
898
- this.byStart[index] = newChunk;
899
- this.byEnd[newChunk.end] = newChunk;
900
- if (chunk === this.lastChunk) this.lastChunk = newChunk;
901
- this.lastSearchedChunk = chunk;
902
- return true;
903
- }
904
- toString() {
905
- let str = this.intro;
906
- let chunk = this.firstChunk;
907
- while (chunk) {
908
- str += chunk.toString();
909
- chunk = chunk.next;
910
- }
911
- return str + this.outro;
912
- }
913
- isEmpty() {
914
- let chunk = this.firstChunk;
915
- do {
916
- if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim())
917
- return false;
918
- } while (chunk = chunk.next);
919
- return true;
920
- }
921
- length() {
922
- let chunk = this.firstChunk;
923
- let length = 0;
924
- do {
925
- length += chunk.intro.length + chunk.content.length + chunk.outro.length;
926
- } while (chunk = chunk.next);
927
- return length;
928
- }
929
- trimLines() {
930
- return this.trim("[\\r\\n]");
931
- }
932
- trim(charType) {
933
- return this.trimStart(charType).trimEnd(charType);
934
- }
935
- trimEndAborted(charType) {
936
- const rx = new RegExp((charType || "\\s") + "+$");
937
- this.outro = this.outro.replace(rx, "");
938
- if (this.outro.length) return true;
939
- let chunk = this.lastChunk;
940
- do {
941
- const end = chunk.end;
942
- const aborted = chunk.trimEnd(rx);
943
- if (chunk.end !== end) {
944
- if (this.lastChunk === chunk) {
945
- this.lastChunk = chunk.next;
946
- }
947
- this.byEnd[chunk.end] = chunk;
948
- this.byStart[chunk.next.start] = chunk.next;
949
- this.byEnd[chunk.next.end] = chunk.next;
950
- }
951
- if (aborted) return true;
952
- chunk = chunk.previous;
953
- } while (chunk);
954
- return false;
955
- }
956
- trimEnd(charType) {
957
- this.trimEndAborted(charType);
958
- return this;
959
- }
960
- trimStartAborted(charType) {
961
- const rx = new RegExp("^" + (charType || "\\s") + "+");
962
- this.intro = this.intro.replace(rx, "");
963
- if (this.intro.length) return true;
964
- let chunk = this.firstChunk;
965
- do {
966
- const end = chunk.end;
967
- const aborted = chunk.trimStart(rx);
968
- if (chunk.end !== end) {
969
- if (chunk === this.lastChunk) this.lastChunk = chunk.next;
970
- this.byEnd[chunk.end] = chunk;
971
- this.byStart[chunk.next.start] = chunk.next;
972
- this.byEnd[chunk.next.end] = chunk.next;
973
- }
974
- if (aborted) return true;
975
- chunk = chunk.next;
976
- } while (chunk);
977
- return false;
978
- }
979
- trimStart(charType) {
980
- this.trimStartAborted(charType);
981
- return this;
982
- }
983
- hasChanged() {
984
- return this.original !== this.toString();
985
- }
986
- _replaceRegexp(searchValue, replacement) {
987
- function getReplacement(match, str) {
988
- if (typeof replacement === "string") {
989
- return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
990
- if (i === "$") return "$";
991
- if (i === "&") return match[0];
992
- const num = +i;
993
- if (num < match.length) return match[+i];
994
- return `$${i}`;
995
- });
996
- } else {
997
- return replacement(...match, match.index, str, match.groups);
998
- }
999
- }
1000
- function matchAll(re, str) {
1001
- let match;
1002
- const matches = [];
1003
- while (match = re.exec(str)) {
1004
- matches.push(match);
1005
- }
1006
- return matches;
1007
- }
1008
- if (searchValue.global) {
1009
- const matches = matchAll(searchValue, this.original);
1010
- matches.forEach((match) => {
1011
- if (match.index != null) {
1012
- const replacement2 = getReplacement(match, this.original);
1013
- if (replacement2 !== match[0]) {
1014
- this.overwrite(match.index, match.index + match[0].length, replacement2);
1015
- }
1016
- }
1017
- });
1018
- } else {
1019
- const match = this.original.match(searchValue);
1020
- if (match && match.index != null) {
1021
- const replacement2 = getReplacement(match, this.original);
1022
- if (replacement2 !== match[0]) {
1023
- this.overwrite(match.index, match.index + match[0].length, replacement2);
1024
- }
1025
- }
1026
- }
1027
- return this;
1028
- }
1029
- _replaceString(string, replacement) {
1030
- const { original } = this;
1031
- const index = original.indexOf(string);
1032
- if (index !== -1) {
1033
- if (typeof replacement === "function") {
1034
- replacement = replacement(string, index, original);
1035
- }
1036
- if (string !== replacement) {
1037
- this.overwrite(index, index + string.length, replacement);
1038
- }
1039
- }
1040
- return this;
1041
- }
1042
- replace(searchValue, replacement) {
1043
- if (typeof searchValue === "string") {
1044
- return this._replaceString(searchValue, replacement);
1045
- }
1046
- return this._replaceRegexp(searchValue, replacement);
1047
- }
1048
- _replaceAllString(string, replacement) {
1049
- const { original } = this;
1050
- const stringLength = string.length;
1051
- for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
1052
- const previous = original.slice(index, index + stringLength);
1053
- let _replacement = replacement;
1054
- if (typeof replacement === "function") {
1055
- _replacement = replacement(previous, index, original);
1056
- }
1057
- if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
1058
- }
1059
- return this;
1060
- }
1061
- replaceAll(searchValue, replacement) {
1062
- if (typeof searchValue === "string") {
1063
- return this._replaceAllString(searchValue, replacement);
1064
- }
1065
- if (!searchValue.global) {
1066
- throw new TypeError(
1067
- "MagicString.prototype.replaceAll called with a non-global RegExp argument"
1068
- );
1069
- }
1070
- return this._replaceRegexp(searchValue, replacement);
1071
- }
1072
- }
4
+ import MagicString from "magic-string";
1073
5
  function bloxPlugin(options = {}) {
1074
6
  const enableSSR = options.ssr ?? false;
1075
7
  const plugins = [];
@@ -1207,6 +139,69 @@ function bloxPlugin(options = {}) {
1207
139
  }
1208
140
  });
1209
141
  }
142
+ if (options.emitManifest ?? false) {
143
+ const glob = options.manifestGlob ?? "./src/components/blocks/*.vue";
144
+ const fileName = options.manifestFileName ?? ".blox-manifest.json";
145
+ const VIRTUAL_ENTRY = "virtual:blox-manifest-entry";
146
+ const RESOLVED_ENTRY = `\0${VIRTUAL_ENTRY}`;
147
+ let root = process.cwd();
148
+ let outDir = "dist";
149
+ let isSsrBuild = false;
150
+ plugins.push({
151
+ name: "vite-plugin-blox-manifest",
152
+ apply: "build",
153
+ configResolved(resolved) {
154
+ root = resolved.root;
155
+ outDir = resolved.build.outDir;
156
+ isSsrBuild = !!resolved.build.ssr;
157
+ },
158
+ resolveId(id) {
159
+ if (id === VIRTUAL_ENTRY) return RESOLVED_ENTRY;
160
+ },
161
+ // A tiny entry module that registers all block SFCs into a Blox
162
+ // instance and serializes the resulting registry. Executed via the
163
+ // SSR runner in closeBundle (below).
164
+ load(id) {
165
+ if (id !== RESOLVED_ENTRY) return;
166
+ return [
167
+ `import { createBlox } from '@bagelink/blox'`,
168
+ `import { serializeRegistry } from '@bagelink/blox'`,
169
+ `const mods = import.meta.glob(${JSON.stringify(glob)}, { eager: true })`,
170
+ `export function build() {`,
171
+ ` const blox = createBlox({ modules: mods })`,
172
+ ` return serializeRegistry(blox.getRegistry())`,
173
+ `}`
174
+ ].join("\n");
175
+ },
176
+ async closeBundle() {
177
+ var _a;
178
+ if (isSsrBuild) return;
179
+ const { createServer } = await import("vite");
180
+ const server = await createServer({
181
+ root,
182
+ configFile: false,
183
+ logLevel: "silent",
184
+ server: { middlewareMode: true, hmr: false },
185
+ plugins: bloxPlugin()
186
+ });
187
+ try {
188
+ const mod = await server.ssrLoadModule(VIRTUAL_ENTRY);
189
+ const manifest = mod.build();
190
+ const { writeFile, mkdir } = await import("node:fs/promises");
191
+ const target = join(root, outDir, fileName);
192
+ await mkdir(dirname(target), { recursive: true });
193
+ await writeFile(target, `${JSON.stringify(manifest, null, 2)}
194
+ `);
195
+ const count = ((_a = manifest.blocks) == null ? void 0 : _a.length) ?? 0;
196
+ console.log(`[vite-plugin-blox-manifest] wrote ${count} blocks -> ${join(outDir, fileName)}`);
197
+ } catch (e) {
198
+ console.warn("[vite-plugin-blox-manifest] failed to emit manifest:", e.message);
199
+ } finally {
200
+ await server.close();
201
+ }
202
+ }
203
+ });
204
+ }
1210
205
  plugins.push({
1211
206
  name: "vite-plugin-blox",
1212
207
  enforce: "pre",
@@ -1277,7 +272,7 @@ function bloxPlugin(options = {}) {
1277
272
  const hoistedImports = [];
1278
273
  const importRe = /^[ \t]*import\s+(\{[^}]*\})\s+from\s+(['"](?:@bagelink\/blox|@bagelink\/vue)['"])\s*;?[ \t]*$/gm;
1279
274
  remaining = remaining.replace(importRe, (match, namedGroup, source) => {
1280
- const names = namedGroup.replace(/[{}]/g, "").split(",").map((n2) => n2.trim()).filter(Boolean);
275
+ const names = namedGroup.replace(/[{}]/g, "").split(",").map((n) => n.trim()).filter(Boolean);
1281
276
  const hoist = [];
1282
277
  const keep = [];
1283
278
  for (const name of names) {