tempo-sdk 0.0.28 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canvas/editor.d.ts +29 -1
- package/dist/canvas/editor.js +50 -5
- package/dist/canvas/editor.js.map +1 -1
- package/dist/canvas/index.d.ts +3 -66
- package/dist/canvas/index.js +56 -940
- package/dist/canvas/index.js.map +1 -1
- package/dist/canvas/interact-projection.js +2679 -1956
- package/dist/canvas/interact-projection.js.map +1 -1
- package/dist/canvas/parser.d.ts +6 -0
- package/dist/canvas/parser.js +1 -1
- package/dist/canvas/svelte.d.ts +18 -0
- package/dist/canvas/svelte.js +68 -0
- package/dist/canvas/svelte.js.map +1 -0
- package/dist/chunk-DXKG4IGS.js +919 -0
- package/dist/chunk-DXKG4IGS.js.map +1 -0
- package/dist/chunk-F3KJDCMU.js +19 -0
- package/dist/chunk-F3KJDCMU.js.map +1 -0
- package/dist/{chunk-2MAQPUCU.js → chunk-QP2NTODB.js} +19 -12
- package/dist/chunk-QP2NTODB.js.map +1 -0
- package/dist/{chunk-XEXMGSTU.js → chunk-YZ3TMGUC.js} +21 -2
- package/dist/{chunk-XEXMGSTU.js.map → chunk-YZ3TMGUC.js.map} +1 -1
- package/dist/index.js +23 -16
- package/dist/index.js.map +1 -1
- package/dist/nextjs/plugin.js +1 -1
- package/dist/nextjs.cjs +20 -1
- package/dist/nextjs.cjs.map +1 -1
- package/dist/nextjs.js +1 -1
- package/dist/storyboard-xVaRTJAu.d.ts +69 -0
- package/dist/svelte.d.ts +21 -0
- package/dist/svelte.js +1898 -0
- package/dist/svelte.js.map +1 -0
- package/package.json +20 -1
- package/dist/chunk-2MAQPUCU.js.map +0 -1
package/dist/svelte.js
ADDED
|
@@ -0,0 +1,1898 @@
|
|
|
1
|
+
import {
|
|
2
|
+
sourceVersionHash
|
|
3
|
+
} from "./chunk-F3KJDCMU.js";
|
|
4
|
+
|
|
5
|
+
// svelte.ts
|
|
6
|
+
import { statSync } from "fs";
|
|
7
|
+
import { isAbsolute, relative, resolve } from "path";
|
|
8
|
+
|
|
9
|
+
// ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
10
|
+
var comma = ",".charCodeAt(0);
|
|
11
|
+
var semicolon = ";".charCodeAt(0);
|
|
12
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
13
|
+
var intToChar = new Uint8Array(64);
|
|
14
|
+
var charToInt = new Uint8Array(128);
|
|
15
|
+
for (let i = 0; i < chars.length; i++) {
|
|
16
|
+
const c = chars.charCodeAt(i);
|
|
17
|
+
intToChar[i] = c;
|
|
18
|
+
charToInt[c] = i;
|
|
19
|
+
}
|
|
20
|
+
function encodeInteger(builder, num, relative2) {
|
|
21
|
+
let delta = num - relative2;
|
|
22
|
+
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
23
|
+
do {
|
|
24
|
+
let clamped = delta & 31;
|
|
25
|
+
delta >>>= 5;
|
|
26
|
+
if (delta > 0) clamped |= 32;
|
|
27
|
+
builder.write(intToChar[clamped]);
|
|
28
|
+
} while (delta > 0);
|
|
29
|
+
return num;
|
|
30
|
+
}
|
|
31
|
+
var bufLength = 1024 * 16;
|
|
32
|
+
var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
|
|
33
|
+
decode(buf) {
|
|
34
|
+
const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
35
|
+
return out.toString();
|
|
36
|
+
}
|
|
37
|
+
} : {
|
|
38
|
+
decode(buf) {
|
|
39
|
+
let out = "";
|
|
40
|
+
for (let i = 0; i < buf.length; i++) {
|
|
41
|
+
out += String.fromCharCode(buf[i]);
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var StringWriter = class {
|
|
47
|
+
constructor() {
|
|
48
|
+
this.pos = 0;
|
|
49
|
+
this.out = "";
|
|
50
|
+
this.buffer = new Uint8Array(bufLength);
|
|
51
|
+
}
|
|
52
|
+
write(v) {
|
|
53
|
+
const { buffer } = this;
|
|
54
|
+
buffer[this.pos++] = v;
|
|
55
|
+
if (this.pos === bufLength) {
|
|
56
|
+
this.out += td.decode(buffer);
|
|
57
|
+
this.pos = 0;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
flush() {
|
|
61
|
+
const { buffer, out, pos } = this;
|
|
62
|
+
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
function encode(decoded) {
|
|
66
|
+
const writer = new StringWriter();
|
|
67
|
+
let sourcesIndex = 0;
|
|
68
|
+
let sourceLine = 0;
|
|
69
|
+
let sourceColumn = 0;
|
|
70
|
+
let namesIndex = 0;
|
|
71
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
72
|
+
const line = decoded[i];
|
|
73
|
+
if (i > 0) writer.write(semicolon);
|
|
74
|
+
if (line.length === 0) continue;
|
|
75
|
+
let genColumn = 0;
|
|
76
|
+
for (let j = 0; j < line.length; j++) {
|
|
77
|
+
const segment = line[j];
|
|
78
|
+
if (j > 0) writer.write(comma);
|
|
79
|
+
genColumn = encodeInteger(writer, segment[0], genColumn);
|
|
80
|
+
if (segment.length === 1) continue;
|
|
81
|
+
sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
|
|
82
|
+
sourceLine = encodeInteger(writer, segment[2], sourceLine);
|
|
83
|
+
sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
|
|
84
|
+
if (segment.length === 4) continue;
|
|
85
|
+
namesIndex = encodeInteger(writer, segment[4], namesIndex);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return writer.flush();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ../../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(n2) {
|
|
97
|
+
this.bits[n2 >> 5] |= 1 << (n2 & 31);
|
|
98
|
+
}
|
|
99
|
+
has(n2) {
|
|
100
|
+
return !!(this.bits[n2 >> 5] & 1 << (n2 & 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
|
+
{
|
|
114
|
+
this.previous = null;
|
|
115
|
+
this.next = null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
appendLeft(content) {
|
|
119
|
+
this.outro += content;
|
|
120
|
+
}
|
|
121
|
+
appendRight(content) {
|
|
122
|
+
this.intro = this.intro + content;
|
|
123
|
+
}
|
|
124
|
+
clone() {
|
|
125
|
+
const chunk = new _Chunk(this.start, this.end, this.original);
|
|
126
|
+
chunk.intro = this.intro;
|
|
127
|
+
chunk.outro = this.outro;
|
|
128
|
+
chunk.content = this.content;
|
|
129
|
+
chunk.storeName = this.storeName;
|
|
130
|
+
chunk.edited = this.edited;
|
|
131
|
+
return chunk;
|
|
132
|
+
}
|
|
133
|
+
contains(index) {
|
|
134
|
+
return this.start < index && index < this.end;
|
|
135
|
+
}
|
|
136
|
+
eachNext(fn) {
|
|
137
|
+
let chunk = this;
|
|
138
|
+
while (chunk) {
|
|
139
|
+
fn(chunk);
|
|
140
|
+
chunk = chunk.next;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
eachPrevious(fn) {
|
|
144
|
+
let chunk = this;
|
|
145
|
+
while (chunk) {
|
|
146
|
+
fn(chunk);
|
|
147
|
+
chunk = chunk.previous;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
edit(content, storeName, contentOnly) {
|
|
151
|
+
this.content = content;
|
|
152
|
+
if (!contentOnly) {
|
|
153
|
+
this.intro = "";
|
|
154
|
+
this.outro = "";
|
|
155
|
+
}
|
|
156
|
+
this.storeName = storeName;
|
|
157
|
+
this.edited = true;
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
prependLeft(content) {
|
|
161
|
+
this.outro = content + this.outro;
|
|
162
|
+
}
|
|
163
|
+
prependRight(content) {
|
|
164
|
+
this.intro = content + this.intro;
|
|
165
|
+
}
|
|
166
|
+
reset() {
|
|
167
|
+
this.intro = "";
|
|
168
|
+
this.outro = "";
|
|
169
|
+
if (this.edited) {
|
|
170
|
+
this.content = this.original;
|
|
171
|
+
this.storeName = false;
|
|
172
|
+
this.edited = false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
split(index) {
|
|
176
|
+
const sliceIndex = index - this.start;
|
|
177
|
+
const originalBefore = this.original.slice(0, sliceIndex);
|
|
178
|
+
const originalAfter = this.original.slice(sliceIndex);
|
|
179
|
+
this.original = originalBefore;
|
|
180
|
+
const newChunk = new _Chunk(index, this.end, originalAfter);
|
|
181
|
+
newChunk.outro = this.outro;
|
|
182
|
+
this.outro = "";
|
|
183
|
+
this.end = index;
|
|
184
|
+
if (this.edited) {
|
|
185
|
+
newChunk.edit("", false);
|
|
186
|
+
this.content = "";
|
|
187
|
+
} else {
|
|
188
|
+
this.content = originalBefore;
|
|
189
|
+
}
|
|
190
|
+
newChunk.next = this.next;
|
|
191
|
+
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
192
|
+
newChunk.previous = this;
|
|
193
|
+
this.next = newChunk;
|
|
194
|
+
return newChunk;
|
|
195
|
+
}
|
|
196
|
+
toString() {
|
|
197
|
+
return this.intro + this.content + this.outro;
|
|
198
|
+
}
|
|
199
|
+
trimEnd(rx) {
|
|
200
|
+
this.outro = this.outro.replace(rx, "");
|
|
201
|
+
if (this.outro.length) return true;
|
|
202
|
+
const trimmed = this.content.replace(rx, "");
|
|
203
|
+
if (trimmed.length) {
|
|
204
|
+
if (trimmed !== this.content) {
|
|
205
|
+
this.split(this.start + trimmed.length).edit("", void 0, true);
|
|
206
|
+
if (this.edited) {
|
|
207
|
+
this.edit(trimmed, this.storeName, true);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return true;
|
|
211
|
+
} else {
|
|
212
|
+
this.edit("", void 0, true);
|
|
213
|
+
this.intro = this.intro.replace(rx, "");
|
|
214
|
+
if (this.intro.length) return true;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
trimStart(rx) {
|
|
218
|
+
this.intro = this.intro.replace(rx, "");
|
|
219
|
+
if (this.intro.length) return true;
|
|
220
|
+
const trimmed = this.content.replace(rx, "");
|
|
221
|
+
if (trimmed.length) {
|
|
222
|
+
if (trimmed !== this.content) {
|
|
223
|
+
const newChunk = this.split(this.end - trimmed.length);
|
|
224
|
+
if (this.edited) {
|
|
225
|
+
newChunk.edit(trimmed, this.storeName, true);
|
|
226
|
+
}
|
|
227
|
+
this.edit("", void 0, true);
|
|
228
|
+
}
|
|
229
|
+
return true;
|
|
230
|
+
} else {
|
|
231
|
+
this.edit("", void 0, true);
|
|
232
|
+
this.outro = this.outro.replace(rx, "");
|
|
233
|
+
if (this.outro.length) return true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
function getBtoa() {
|
|
238
|
+
if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") {
|
|
239
|
+
return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
|
|
240
|
+
} else if (typeof Buffer === "function") {
|
|
241
|
+
return (str) => Buffer.from(str, "utf-8").toString("base64");
|
|
242
|
+
} else {
|
|
243
|
+
return () => {
|
|
244
|
+
throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
var btoa = /* @__PURE__ */ getBtoa();
|
|
249
|
+
var SourceMap = class {
|
|
250
|
+
constructor(properties) {
|
|
251
|
+
this.version = 3;
|
|
252
|
+
this.file = properties.file;
|
|
253
|
+
this.sources = properties.sources;
|
|
254
|
+
this.sourcesContent = properties.sourcesContent;
|
|
255
|
+
this.names = properties.names;
|
|
256
|
+
this.mappings = encode(properties.mappings);
|
|
257
|
+
if (typeof properties.x_google_ignoreList !== "undefined") {
|
|
258
|
+
this.x_google_ignoreList = properties.x_google_ignoreList;
|
|
259
|
+
}
|
|
260
|
+
if (typeof properties.debugId !== "undefined") {
|
|
261
|
+
this.debugId = properties.debugId;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
toString() {
|
|
265
|
+
return JSON.stringify(this);
|
|
266
|
+
}
|
|
267
|
+
toUrl() {
|
|
268
|
+
return "data:application/json;charset=utf-8;base64," + btoa(this.toString());
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
function guessIndent(code) {
|
|
272
|
+
const lines = code.split("\n");
|
|
273
|
+
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
274
|
+
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
275
|
+
if (tabbed.length === 0 && spaced.length === 0) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
if (tabbed.length >= spaced.length) {
|
|
279
|
+
return " ";
|
|
280
|
+
}
|
|
281
|
+
const min = spaced.reduce((previous, current) => {
|
|
282
|
+
const numSpaces = /^ +/.exec(current)[0].length;
|
|
283
|
+
return Math.min(numSpaces, previous);
|
|
284
|
+
}, Infinity);
|
|
285
|
+
return new Array(min + 1).join(" ");
|
|
286
|
+
}
|
|
287
|
+
function getRelativePath(from, to) {
|
|
288
|
+
const fromParts = from.split(/[/\\]/);
|
|
289
|
+
const toParts = to.split(/[/\\]/);
|
|
290
|
+
fromParts.pop();
|
|
291
|
+
while (fromParts[0] === toParts[0]) {
|
|
292
|
+
fromParts.shift();
|
|
293
|
+
toParts.shift();
|
|
294
|
+
}
|
|
295
|
+
if (fromParts.length) {
|
|
296
|
+
let i = fromParts.length;
|
|
297
|
+
while (i--) fromParts[i] = "..";
|
|
298
|
+
}
|
|
299
|
+
return fromParts.concat(toParts).join("/");
|
|
300
|
+
}
|
|
301
|
+
var toString = Object.prototype.toString;
|
|
302
|
+
function isObject(thing) {
|
|
303
|
+
return toString.call(thing) === "[object Object]";
|
|
304
|
+
}
|
|
305
|
+
function getLocator(source) {
|
|
306
|
+
const originalLines = source.split("\n");
|
|
307
|
+
const lineOffsets = [];
|
|
308
|
+
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
309
|
+
lineOffsets.push(pos);
|
|
310
|
+
pos += originalLines[i].length + 1;
|
|
311
|
+
}
|
|
312
|
+
return function locate(index) {
|
|
313
|
+
let i = 0;
|
|
314
|
+
let j = lineOffsets.length;
|
|
315
|
+
while (i < j) {
|
|
316
|
+
const m = i + j >> 1;
|
|
317
|
+
if (index < lineOffsets[m]) {
|
|
318
|
+
j = m;
|
|
319
|
+
} else {
|
|
320
|
+
i = m + 1;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
const line = i - 1;
|
|
324
|
+
const column = index - lineOffsets[line];
|
|
325
|
+
return { line, column };
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
var wordRegex = /\w/;
|
|
329
|
+
var Mappings = class {
|
|
330
|
+
constructor(hires) {
|
|
331
|
+
this.hires = hires;
|
|
332
|
+
this.generatedCodeLine = 0;
|
|
333
|
+
this.generatedCodeColumn = 0;
|
|
334
|
+
this.raw = [];
|
|
335
|
+
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
336
|
+
this.pending = null;
|
|
337
|
+
}
|
|
338
|
+
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
339
|
+
if (content.length) {
|
|
340
|
+
const contentLengthMinusOne = content.length - 1;
|
|
341
|
+
let contentLineEnd = content.indexOf("\n", 0);
|
|
342
|
+
let previousContentLineEnd = -1;
|
|
343
|
+
while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
|
|
344
|
+
const segment2 = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
345
|
+
if (nameIndex >= 0) {
|
|
346
|
+
segment2.push(nameIndex);
|
|
347
|
+
}
|
|
348
|
+
this.rawSegments.push(segment2);
|
|
349
|
+
this.generatedCodeLine += 1;
|
|
350
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
351
|
+
this.generatedCodeColumn = 0;
|
|
352
|
+
previousContentLineEnd = contentLineEnd;
|
|
353
|
+
contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
|
|
354
|
+
}
|
|
355
|
+
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
356
|
+
if (nameIndex >= 0) {
|
|
357
|
+
segment.push(nameIndex);
|
|
358
|
+
}
|
|
359
|
+
this.rawSegments.push(segment);
|
|
360
|
+
this.advance(content.slice(previousContentLineEnd + 1));
|
|
361
|
+
} else if (this.pending) {
|
|
362
|
+
this.rawSegments.push(this.pending);
|
|
363
|
+
this.advance(content);
|
|
364
|
+
}
|
|
365
|
+
this.pending = null;
|
|
366
|
+
}
|
|
367
|
+
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
368
|
+
let originalCharIndex = chunk.start;
|
|
369
|
+
let first = true;
|
|
370
|
+
let charInHiresBoundary = false;
|
|
371
|
+
while (originalCharIndex < chunk.end) {
|
|
372
|
+
if (original[originalCharIndex] === "\n") {
|
|
373
|
+
loc.line += 1;
|
|
374
|
+
loc.column = 0;
|
|
375
|
+
this.generatedCodeLine += 1;
|
|
376
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
377
|
+
this.generatedCodeColumn = 0;
|
|
378
|
+
first = true;
|
|
379
|
+
charInHiresBoundary = false;
|
|
380
|
+
} else {
|
|
381
|
+
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
382
|
+
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
383
|
+
if (this.hires === "boundary") {
|
|
384
|
+
if (wordRegex.test(original[originalCharIndex])) {
|
|
385
|
+
if (!charInHiresBoundary) {
|
|
386
|
+
this.rawSegments.push(segment);
|
|
387
|
+
charInHiresBoundary = true;
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
this.rawSegments.push(segment);
|
|
391
|
+
charInHiresBoundary = false;
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
this.rawSegments.push(segment);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
loc.column += 1;
|
|
398
|
+
this.generatedCodeColumn += 1;
|
|
399
|
+
first = false;
|
|
400
|
+
}
|
|
401
|
+
originalCharIndex += 1;
|
|
402
|
+
}
|
|
403
|
+
this.pending = null;
|
|
404
|
+
}
|
|
405
|
+
advance(str) {
|
|
406
|
+
if (!str) return;
|
|
407
|
+
const lines = str.split("\n");
|
|
408
|
+
if (lines.length > 1) {
|
|
409
|
+
for (let i = 0; i < lines.length - 1; i++) {
|
|
410
|
+
this.generatedCodeLine++;
|
|
411
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
412
|
+
}
|
|
413
|
+
this.generatedCodeColumn = 0;
|
|
414
|
+
}
|
|
415
|
+
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
var n = "\n";
|
|
419
|
+
var warned = {
|
|
420
|
+
insertLeft: false,
|
|
421
|
+
insertRight: false,
|
|
422
|
+
storeName: false
|
|
423
|
+
};
|
|
424
|
+
var MagicString = class _MagicString {
|
|
425
|
+
constructor(string, options = {}) {
|
|
426
|
+
const chunk = new Chunk(0, string.length, string);
|
|
427
|
+
Object.defineProperties(this, {
|
|
428
|
+
original: { writable: true, value: string },
|
|
429
|
+
outro: { writable: true, value: "" },
|
|
430
|
+
intro: { writable: true, value: "" },
|
|
431
|
+
firstChunk: { writable: true, value: chunk },
|
|
432
|
+
lastChunk: { writable: true, value: chunk },
|
|
433
|
+
lastSearchedChunk: { writable: true, value: chunk },
|
|
434
|
+
byStart: { writable: true, value: {} },
|
|
435
|
+
byEnd: { writable: true, value: {} },
|
|
436
|
+
filename: { writable: true, value: options.filename },
|
|
437
|
+
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
|
438
|
+
sourcemapLocations: { writable: true, value: new BitSet() },
|
|
439
|
+
storedNames: { writable: true, value: {} },
|
|
440
|
+
indentStr: { writable: true, value: void 0 },
|
|
441
|
+
ignoreList: { writable: true, value: options.ignoreList },
|
|
442
|
+
offset: { writable: true, value: options.offset || 0 }
|
|
443
|
+
});
|
|
444
|
+
this.byStart[0] = chunk;
|
|
445
|
+
this.byEnd[string.length] = chunk;
|
|
446
|
+
}
|
|
447
|
+
addSourcemapLocation(char) {
|
|
448
|
+
this.sourcemapLocations.add(char);
|
|
449
|
+
}
|
|
450
|
+
append(content) {
|
|
451
|
+
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
452
|
+
this.outro += content;
|
|
453
|
+
return this;
|
|
454
|
+
}
|
|
455
|
+
appendLeft(index, content) {
|
|
456
|
+
index = index + this.offset;
|
|
457
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
458
|
+
this._split(index);
|
|
459
|
+
const chunk = this.byEnd[index];
|
|
460
|
+
if (chunk) {
|
|
461
|
+
chunk.appendLeft(content);
|
|
462
|
+
} else {
|
|
463
|
+
this.intro += content;
|
|
464
|
+
}
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
appendRight(index, content) {
|
|
468
|
+
index = index + this.offset;
|
|
469
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
470
|
+
this._split(index);
|
|
471
|
+
const chunk = this.byStart[index];
|
|
472
|
+
if (chunk) {
|
|
473
|
+
chunk.appendRight(content);
|
|
474
|
+
} else {
|
|
475
|
+
this.outro += content;
|
|
476
|
+
}
|
|
477
|
+
return this;
|
|
478
|
+
}
|
|
479
|
+
clone() {
|
|
480
|
+
const cloned = new _MagicString(this.original, { filename: this.filename, offset: this.offset });
|
|
481
|
+
let originalChunk = this.firstChunk;
|
|
482
|
+
let clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
|
483
|
+
while (originalChunk) {
|
|
484
|
+
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
485
|
+
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
486
|
+
const nextOriginalChunk = originalChunk.next;
|
|
487
|
+
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
488
|
+
if (nextClonedChunk) {
|
|
489
|
+
clonedChunk.next = nextClonedChunk;
|
|
490
|
+
nextClonedChunk.previous = clonedChunk;
|
|
491
|
+
clonedChunk = nextClonedChunk;
|
|
492
|
+
}
|
|
493
|
+
originalChunk = nextOriginalChunk;
|
|
494
|
+
}
|
|
495
|
+
cloned.lastChunk = clonedChunk;
|
|
496
|
+
if (this.indentExclusionRanges) {
|
|
497
|
+
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
498
|
+
}
|
|
499
|
+
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
500
|
+
cloned.intro = this.intro;
|
|
501
|
+
cloned.outro = this.outro;
|
|
502
|
+
return cloned;
|
|
503
|
+
}
|
|
504
|
+
generateDecodedMap(options) {
|
|
505
|
+
options = options || {};
|
|
506
|
+
const sourceIndex = 0;
|
|
507
|
+
const names = Object.keys(this.storedNames);
|
|
508
|
+
const mappings = new Mappings(options.hires);
|
|
509
|
+
const locate = getLocator(this.original);
|
|
510
|
+
if (this.intro) {
|
|
511
|
+
mappings.advance(this.intro);
|
|
512
|
+
}
|
|
513
|
+
this.firstChunk.eachNext((chunk) => {
|
|
514
|
+
const loc = locate(chunk.start);
|
|
515
|
+
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
516
|
+
if (chunk.edited) {
|
|
517
|
+
mappings.addEdit(
|
|
518
|
+
sourceIndex,
|
|
519
|
+
chunk.content,
|
|
520
|
+
loc,
|
|
521
|
+
chunk.storeName ? names.indexOf(chunk.original) : -1
|
|
522
|
+
);
|
|
523
|
+
} else {
|
|
524
|
+
mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
525
|
+
}
|
|
526
|
+
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
527
|
+
});
|
|
528
|
+
if (this.outro) {
|
|
529
|
+
mappings.advance(this.outro);
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
|
|
533
|
+
sources: [
|
|
534
|
+
options.source ? getRelativePath(options.file || "", options.source) : options.file || ""
|
|
535
|
+
],
|
|
536
|
+
sourcesContent: options.includeContent ? [this.original] : void 0,
|
|
537
|
+
names,
|
|
538
|
+
mappings: mappings.raw,
|
|
539
|
+
x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
generateMap(options) {
|
|
543
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
544
|
+
}
|
|
545
|
+
_ensureindentStr() {
|
|
546
|
+
if (this.indentStr === void 0) {
|
|
547
|
+
this.indentStr = guessIndent(this.original);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
_getRawIndentString() {
|
|
551
|
+
this._ensureindentStr();
|
|
552
|
+
return this.indentStr;
|
|
553
|
+
}
|
|
554
|
+
getIndentString() {
|
|
555
|
+
this._ensureindentStr();
|
|
556
|
+
return this.indentStr === null ? " " : this.indentStr;
|
|
557
|
+
}
|
|
558
|
+
indent(indentStr, options) {
|
|
559
|
+
const pattern = /^[^\r\n]/gm;
|
|
560
|
+
if (isObject(indentStr)) {
|
|
561
|
+
options = indentStr;
|
|
562
|
+
indentStr = void 0;
|
|
563
|
+
}
|
|
564
|
+
if (indentStr === void 0) {
|
|
565
|
+
this._ensureindentStr();
|
|
566
|
+
indentStr = this.indentStr || " ";
|
|
567
|
+
}
|
|
568
|
+
if (indentStr === "") return this;
|
|
569
|
+
options = options || {};
|
|
570
|
+
const isExcluded = {};
|
|
571
|
+
if (options.exclude) {
|
|
572
|
+
const exclusions = typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude;
|
|
573
|
+
exclusions.forEach((exclusion) => {
|
|
574
|
+
for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
|
|
575
|
+
isExcluded[i] = true;
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
580
|
+
const replacer = (match) => {
|
|
581
|
+
if (shouldIndentNextCharacter) return `${indentStr}${match}`;
|
|
582
|
+
shouldIndentNextCharacter = true;
|
|
583
|
+
return match;
|
|
584
|
+
};
|
|
585
|
+
this.intro = this.intro.replace(pattern, replacer);
|
|
586
|
+
let charIndex = 0;
|
|
587
|
+
let chunk = this.firstChunk;
|
|
588
|
+
while (chunk) {
|
|
589
|
+
const end = chunk.end;
|
|
590
|
+
if (chunk.edited) {
|
|
591
|
+
if (!isExcluded[charIndex]) {
|
|
592
|
+
chunk.content = chunk.content.replace(pattern, replacer);
|
|
593
|
+
if (chunk.content.length) {
|
|
594
|
+
shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
} else {
|
|
598
|
+
charIndex = chunk.start;
|
|
599
|
+
while (charIndex < end) {
|
|
600
|
+
if (!isExcluded[charIndex]) {
|
|
601
|
+
const char = this.original[charIndex];
|
|
602
|
+
if (char === "\n") {
|
|
603
|
+
shouldIndentNextCharacter = true;
|
|
604
|
+
} else if (char !== "\r" && shouldIndentNextCharacter) {
|
|
605
|
+
shouldIndentNextCharacter = false;
|
|
606
|
+
if (charIndex === chunk.start) {
|
|
607
|
+
chunk.prependRight(indentStr);
|
|
608
|
+
} else {
|
|
609
|
+
this._splitChunk(chunk, charIndex);
|
|
610
|
+
chunk = chunk.next;
|
|
611
|
+
chunk.prependRight(indentStr);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
charIndex += 1;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
charIndex = chunk.end;
|
|
619
|
+
chunk = chunk.next;
|
|
620
|
+
}
|
|
621
|
+
this.outro = this.outro.replace(pattern, replacer);
|
|
622
|
+
return this;
|
|
623
|
+
}
|
|
624
|
+
insert() {
|
|
625
|
+
throw new Error(
|
|
626
|
+
"magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)"
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
insertLeft(index, content) {
|
|
630
|
+
if (!warned.insertLeft) {
|
|
631
|
+
console.warn(
|
|
632
|
+
"magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"
|
|
633
|
+
);
|
|
634
|
+
warned.insertLeft = true;
|
|
635
|
+
}
|
|
636
|
+
return this.appendLeft(index, content);
|
|
637
|
+
}
|
|
638
|
+
insertRight(index, content) {
|
|
639
|
+
if (!warned.insertRight) {
|
|
640
|
+
console.warn(
|
|
641
|
+
"magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"
|
|
642
|
+
);
|
|
643
|
+
warned.insertRight = true;
|
|
644
|
+
}
|
|
645
|
+
return this.prependRight(index, content);
|
|
646
|
+
}
|
|
647
|
+
move(start, end, index) {
|
|
648
|
+
start = start + this.offset;
|
|
649
|
+
end = end + this.offset;
|
|
650
|
+
index = index + this.offset;
|
|
651
|
+
if (index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
|
|
652
|
+
this._split(start);
|
|
653
|
+
this._split(end);
|
|
654
|
+
this._split(index);
|
|
655
|
+
const first = this.byStart[start];
|
|
656
|
+
const last = this.byEnd[end];
|
|
657
|
+
const oldLeft = first.previous;
|
|
658
|
+
const oldRight = last.next;
|
|
659
|
+
const newRight = this.byStart[index];
|
|
660
|
+
if (!newRight && last === this.lastChunk) return this;
|
|
661
|
+
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
662
|
+
if (oldLeft) oldLeft.next = oldRight;
|
|
663
|
+
if (oldRight) oldRight.previous = oldLeft;
|
|
664
|
+
if (newLeft) newLeft.next = first;
|
|
665
|
+
if (newRight) newRight.previous = last;
|
|
666
|
+
if (!first.previous) this.firstChunk = last.next;
|
|
667
|
+
if (!last.next) {
|
|
668
|
+
this.lastChunk = first.previous;
|
|
669
|
+
this.lastChunk.next = null;
|
|
670
|
+
}
|
|
671
|
+
first.previous = newLeft;
|
|
672
|
+
last.next = newRight || null;
|
|
673
|
+
if (!newLeft) this.firstChunk = first;
|
|
674
|
+
if (!newRight) this.lastChunk = last;
|
|
675
|
+
return this;
|
|
676
|
+
}
|
|
677
|
+
overwrite(start, end, content, options) {
|
|
678
|
+
options = options || {};
|
|
679
|
+
return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
|
|
680
|
+
}
|
|
681
|
+
update(start, end, content, options) {
|
|
682
|
+
start = start + this.offset;
|
|
683
|
+
end = end + this.offset;
|
|
684
|
+
if (typeof content !== "string") throw new TypeError("replacement content must be a string");
|
|
685
|
+
if (this.original.length !== 0) {
|
|
686
|
+
while (start < 0) start += this.original.length;
|
|
687
|
+
while (end < 0) end += this.original.length;
|
|
688
|
+
}
|
|
689
|
+
if (end > this.original.length) throw new Error("end is out of bounds");
|
|
690
|
+
if (start === end)
|
|
691
|
+
throw new Error(
|
|
692
|
+
"Cannot overwrite a zero-length range \u2013 use appendLeft or prependRight instead"
|
|
693
|
+
);
|
|
694
|
+
this._split(start);
|
|
695
|
+
this._split(end);
|
|
696
|
+
if (options === true) {
|
|
697
|
+
if (!warned.storeName) {
|
|
698
|
+
console.warn(
|
|
699
|
+
"The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"
|
|
700
|
+
);
|
|
701
|
+
warned.storeName = true;
|
|
702
|
+
}
|
|
703
|
+
options = { storeName: true };
|
|
704
|
+
}
|
|
705
|
+
const storeName = options !== void 0 ? options.storeName : false;
|
|
706
|
+
const overwrite = options !== void 0 ? options.overwrite : false;
|
|
707
|
+
if (storeName) {
|
|
708
|
+
const original = this.original.slice(start, end);
|
|
709
|
+
Object.defineProperty(this.storedNames, original, {
|
|
710
|
+
writable: true,
|
|
711
|
+
value: true,
|
|
712
|
+
enumerable: true
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
const first = this.byStart[start];
|
|
716
|
+
const last = this.byEnd[end];
|
|
717
|
+
if (first) {
|
|
718
|
+
let chunk = first;
|
|
719
|
+
while (chunk !== last) {
|
|
720
|
+
if (chunk.next !== this.byStart[chunk.end]) {
|
|
721
|
+
throw new Error("Cannot overwrite across a split point");
|
|
722
|
+
}
|
|
723
|
+
chunk = chunk.next;
|
|
724
|
+
chunk.edit("", false);
|
|
725
|
+
}
|
|
726
|
+
first.edit(content, storeName, !overwrite);
|
|
727
|
+
} else {
|
|
728
|
+
const newChunk = new Chunk(start, end, "").edit(content, storeName);
|
|
729
|
+
last.next = newChunk;
|
|
730
|
+
newChunk.previous = last;
|
|
731
|
+
}
|
|
732
|
+
return this;
|
|
733
|
+
}
|
|
734
|
+
prepend(content) {
|
|
735
|
+
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
736
|
+
this.intro = content + this.intro;
|
|
737
|
+
return this;
|
|
738
|
+
}
|
|
739
|
+
prependLeft(index, content) {
|
|
740
|
+
index = index + this.offset;
|
|
741
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
742
|
+
this._split(index);
|
|
743
|
+
const chunk = this.byEnd[index];
|
|
744
|
+
if (chunk) {
|
|
745
|
+
chunk.prependLeft(content);
|
|
746
|
+
} else {
|
|
747
|
+
this.intro = content + this.intro;
|
|
748
|
+
}
|
|
749
|
+
return this;
|
|
750
|
+
}
|
|
751
|
+
prependRight(index, content) {
|
|
752
|
+
index = index + this.offset;
|
|
753
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
754
|
+
this._split(index);
|
|
755
|
+
const chunk = this.byStart[index];
|
|
756
|
+
if (chunk) {
|
|
757
|
+
chunk.prependRight(content);
|
|
758
|
+
} else {
|
|
759
|
+
this.outro = content + this.outro;
|
|
760
|
+
}
|
|
761
|
+
return this;
|
|
762
|
+
}
|
|
763
|
+
remove(start, end) {
|
|
764
|
+
start = start + this.offset;
|
|
765
|
+
end = end + this.offset;
|
|
766
|
+
if (this.original.length !== 0) {
|
|
767
|
+
while (start < 0) start += this.original.length;
|
|
768
|
+
while (end < 0) end += this.original.length;
|
|
769
|
+
}
|
|
770
|
+
if (start === end) return this;
|
|
771
|
+
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
772
|
+
if (start > end) throw new Error("end must be greater than start");
|
|
773
|
+
this._split(start);
|
|
774
|
+
this._split(end);
|
|
775
|
+
let chunk = this.byStart[start];
|
|
776
|
+
while (chunk) {
|
|
777
|
+
chunk.intro = "";
|
|
778
|
+
chunk.outro = "";
|
|
779
|
+
chunk.edit("");
|
|
780
|
+
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
781
|
+
}
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
784
|
+
reset(start, end) {
|
|
785
|
+
start = start + this.offset;
|
|
786
|
+
end = end + this.offset;
|
|
787
|
+
if (this.original.length !== 0) {
|
|
788
|
+
while (start < 0) start += this.original.length;
|
|
789
|
+
while (end < 0) end += this.original.length;
|
|
790
|
+
}
|
|
791
|
+
if (start === end) return this;
|
|
792
|
+
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
793
|
+
if (start > end) throw new Error("end must be greater than start");
|
|
794
|
+
this._split(start);
|
|
795
|
+
this._split(end);
|
|
796
|
+
let chunk = this.byStart[start];
|
|
797
|
+
while (chunk) {
|
|
798
|
+
chunk.reset();
|
|
799
|
+
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
800
|
+
}
|
|
801
|
+
return this;
|
|
802
|
+
}
|
|
803
|
+
lastChar() {
|
|
804
|
+
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
805
|
+
let chunk = this.lastChunk;
|
|
806
|
+
do {
|
|
807
|
+
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
808
|
+
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
809
|
+
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
810
|
+
} while (chunk = chunk.previous);
|
|
811
|
+
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
812
|
+
return "";
|
|
813
|
+
}
|
|
814
|
+
lastLine() {
|
|
815
|
+
let lineIndex = this.outro.lastIndexOf(n);
|
|
816
|
+
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
817
|
+
let lineStr = this.outro;
|
|
818
|
+
let chunk = this.lastChunk;
|
|
819
|
+
do {
|
|
820
|
+
if (chunk.outro.length > 0) {
|
|
821
|
+
lineIndex = chunk.outro.lastIndexOf(n);
|
|
822
|
+
if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
823
|
+
lineStr = chunk.outro + lineStr;
|
|
824
|
+
}
|
|
825
|
+
if (chunk.content.length > 0) {
|
|
826
|
+
lineIndex = chunk.content.lastIndexOf(n);
|
|
827
|
+
if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
|
|
828
|
+
lineStr = chunk.content + lineStr;
|
|
829
|
+
}
|
|
830
|
+
if (chunk.intro.length > 0) {
|
|
831
|
+
lineIndex = chunk.intro.lastIndexOf(n);
|
|
832
|
+
if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
833
|
+
lineStr = chunk.intro + lineStr;
|
|
834
|
+
}
|
|
835
|
+
} while (chunk = chunk.previous);
|
|
836
|
+
lineIndex = this.intro.lastIndexOf(n);
|
|
837
|
+
if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
|
|
838
|
+
return this.intro + lineStr;
|
|
839
|
+
}
|
|
840
|
+
slice(start = 0, end = this.original.length - this.offset) {
|
|
841
|
+
start = start + this.offset;
|
|
842
|
+
end = end + this.offset;
|
|
843
|
+
if (this.original.length !== 0) {
|
|
844
|
+
while (start < 0) start += this.original.length;
|
|
845
|
+
while (end < 0) end += this.original.length;
|
|
846
|
+
}
|
|
847
|
+
let result = "";
|
|
848
|
+
let chunk = this.firstChunk;
|
|
849
|
+
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
850
|
+
if (chunk.start < end && chunk.end >= end) {
|
|
851
|
+
return result;
|
|
852
|
+
}
|
|
853
|
+
chunk = chunk.next;
|
|
854
|
+
}
|
|
855
|
+
if (chunk && chunk.edited && chunk.start !== start)
|
|
856
|
+
throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
857
|
+
const startChunk = chunk;
|
|
858
|
+
while (chunk) {
|
|
859
|
+
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
|
|
860
|
+
result += chunk.intro;
|
|
861
|
+
}
|
|
862
|
+
const containsEnd = chunk.start < end && chunk.end >= end;
|
|
863
|
+
if (containsEnd && chunk.edited && chunk.end !== end)
|
|
864
|
+
throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
865
|
+
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
866
|
+
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
867
|
+
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
868
|
+
if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
|
869
|
+
result += chunk.outro;
|
|
870
|
+
}
|
|
871
|
+
if (containsEnd) {
|
|
872
|
+
break;
|
|
873
|
+
}
|
|
874
|
+
chunk = chunk.next;
|
|
875
|
+
}
|
|
876
|
+
return result;
|
|
877
|
+
}
|
|
878
|
+
// TODO deprecate this? not really very useful
|
|
879
|
+
snip(start, end) {
|
|
880
|
+
const clone = this.clone();
|
|
881
|
+
clone.remove(0, start);
|
|
882
|
+
clone.remove(end, clone.original.length);
|
|
883
|
+
return clone;
|
|
884
|
+
}
|
|
885
|
+
_split(index) {
|
|
886
|
+
if (this.byStart[index] || this.byEnd[index]) return;
|
|
887
|
+
let chunk = this.lastSearchedChunk;
|
|
888
|
+
let previousChunk = chunk;
|
|
889
|
+
const searchForward = index > chunk.end;
|
|
890
|
+
while (chunk) {
|
|
891
|
+
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
892
|
+
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
893
|
+
if (chunk === previousChunk) return;
|
|
894
|
+
previousChunk = chunk;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
_splitChunk(chunk, index) {
|
|
898
|
+
if (chunk.edited && chunk.content.length) {
|
|
899
|
+
const loc = getLocator(this.original)(index);
|
|
900
|
+
throw new Error(
|
|
901
|
+
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} \u2013 "${chunk.original}")`
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
const newChunk = chunk.split(index);
|
|
905
|
+
this.byEnd[index] = chunk;
|
|
906
|
+
this.byStart[index] = newChunk;
|
|
907
|
+
this.byEnd[newChunk.end] = newChunk;
|
|
908
|
+
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
909
|
+
this.lastSearchedChunk = chunk;
|
|
910
|
+
return true;
|
|
911
|
+
}
|
|
912
|
+
toString() {
|
|
913
|
+
let str = this.intro;
|
|
914
|
+
let chunk = this.firstChunk;
|
|
915
|
+
while (chunk) {
|
|
916
|
+
str += chunk.toString();
|
|
917
|
+
chunk = chunk.next;
|
|
918
|
+
}
|
|
919
|
+
return str + this.outro;
|
|
920
|
+
}
|
|
921
|
+
isEmpty() {
|
|
922
|
+
let chunk = this.firstChunk;
|
|
923
|
+
do {
|
|
924
|
+
if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim())
|
|
925
|
+
return false;
|
|
926
|
+
} while (chunk = chunk.next);
|
|
927
|
+
return true;
|
|
928
|
+
}
|
|
929
|
+
length() {
|
|
930
|
+
let chunk = this.firstChunk;
|
|
931
|
+
let length = 0;
|
|
932
|
+
do {
|
|
933
|
+
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
934
|
+
} while (chunk = chunk.next);
|
|
935
|
+
return length;
|
|
936
|
+
}
|
|
937
|
+
trimLines() {
|
|
938
|
+
return this.trim("[\\r\\n]");
|
|
939
|
+
}
|
|
940
|
+
trim(charType) {
|
|
941
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
942
|
+
}
|
|
943
|
+
trimEndAborted(charType) {
|
|
944
|
+
const rx = new RegExp((charType || "\\s") + "+$");
|
|
945
|
+
this.outro = this.outro.replace(rx, "");
|
|
946
|
+
if (this.outro.length) return true;
|
|
947
|
+
let chunk = this.lastChunk;
|
|
948
|
+
do {
|
|
949
|
+
const end = chunk.end;
|
|
950
|
+
const aborted = chunk.trimEnd(rx);
|
|
951
|
+
if (chunk.end !== end) {
|
|
952
|
+
if (this.lastChunk === chunk) {
|
|
953
|
+
this.lastChunk = chunk.next;
|
|
954
|
+
}
|
|
955
|
+
this.byEnd[chunk.end] = chunk;
|
|
956
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
957
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
958
|
+
}
|
|
959
|
+
if (aborted) return true;
|
|
960
|
+
chunk = chunk.previous;
|
|
961
|
+
} while (chunk);
|
|
962
|
+
return false;
|
|
963
|
+
}
|
|
964
|
+
trimEnd(charType) {
|
|
965
|
+
this.trimEndAborted(charType);
|
|
966
|
+
return this;
|
|
967
|
+
}
|
|
968
|
+
trimStartAborted(charType) {
|
|
969
|
+
const rx = new RegExp("^" + (charType || "\\s") + "+");
|
|
970
|
+
this.intro = this.intro.replace(rx, "");
|
|
971
|
+
if (this.intro.length) return true;
|
|
972
|
+
let chunk = this.firstChunk;
|
|
973
|
+
do {
|
|
974
|
+
const end = chunk.end;
|
|
975
|
+
const aborted = chunk.trimStart(rx);
|
|
976
|
+
if (chunk.end !== end) {
|
|
977
|
+
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
978
|
+
this.byEnd[chunk.end] = chunk;
|
|
979
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
980
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
981
|
+
}
|
|
982
|
+
if (aborted) return true;
|
|
983
|
+
chunk = chunk.next;
|
|
984
|
+
} while (chunk);
|
|
985
|
+
return false;
|
|
986
|
+
}
|
|
987
|
+
trimStart(charType) {
|
|
988
|
+
this.trimStartAborted(charType);
|
|
989
|
+
return this;
|
|
990
|
+
}
|
|
991
|
+
hasChanged() {
|
|
992
|
+
return this.original !== this.toString();
|
|
993
|
+
}
|
|
994
|
+
_replaceRegexp(searchValue, replacement) {
|
|
995
|
+
function getReplacement(match, str) {
|
|
996
|
+
if (typeof replacement === "string") {
|
|
997
|
+
return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
998
|
+
if (i === "$") return "$";
|
|
999
|
+
if (i === "&") return match[0];
|
|
1000
|
+
const num = +i;
|
|
1001
|
+
if (num < match.length) return match[+i];
|
|
1002
|
+
return `$${i}`;
|
|
1003
|
+
});
|
|
1004
|
+
} else {
|
|
1005
|
+
return replacement(...match, match.index, str, match.groups);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
function matchAll(re, str) {
|
|
1009
|
+
let match;
|
|
1010
|
+
const matches = [];
|
|
1011
|
+
while (match = re.exec(str)) {
|
|
1012
|
+
matches.push(match);
|
|
1013
|
+
}
|
|
1014
|
+
return matches;
|
|
1015
|
+
}
|
|
1016
|
+
if (searchValue.global) {
|
|
1017
|
+
const matches = matchAll(searchValue, this.original);
|
|
1018
|
+
matches.forEach((match) => {
|
|
1019
|
+
if (match.index != null) {
|
|
1020
|
+
const replacement2 = getReplacement(match, this.original);
|
|
1021
|
+
if (replacement2 !== match[0]) {
|
|
1022
|
+
this.overwrite(match.index, match.index + match[0].length, replacement2);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
1026
|
+
} else {
|
|
1027
|
+
const match = this.original.match(searchValue);
|
|
1028
|
+
if (match && match.index != null) {
|
|
1029
|
+
const replacement2 = getReplacement(match, this.original);
|
|
1030
|
+
if (replacement2 !== match[0]) {
|
|
1031
|
+
this.overwrite(match.index, match.index + match[0].length, replacement2);
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
return this;
|
|
1036
|
+
}
|
|
1037
|
+
_replaceString(string, replacement) {
|
|
1038
|
+
const { original } = this;
|
|
1039
|
+
const index = original.indexOf(string);
|
|
1040
|
+
if (index !== -1) {
|
|
1041
|
+
if (typeof replacement === "function") {
|
|
1042
|
+
replacement = replacement(string, index, original);
|
|
1043
|
+
}
|
|
1044
|
+
if (string !== replacement) {
|
|
1045
|
+
this.overwrite(index, index + string.length, replacement);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return this;
|
|
1049
|
+
}
|
|
1050
|
+
replace(searchValue, replacement) {
|
|
1051
|
+
if (typeof searchValue === "string") {
|
|
1052
|
+
return this._replaceString(searchValue, replacement);
|
|
1053
|
+
}
|
|
1054
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
1055
|
+
}
|
|
1056
|
+
_replaceAllString(string, replacement) {
|
|
1057
|
+
const { original } = this;
|
|
1058
|
+
const stringLength = string.length;
|
|
1059
|
+
for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
|
|
1060
|
+
const previous = original.slice(index, index + stringLength);
|
|
1061
|
+
let _replacement = replacement;
|
|
1062
|
+
if (typeof replacement === "function") {
|
|
1063
|
+
_replacement = replacement(previous, index, original);
|
|
1064
|
+
}
|
|
1065
|
+
if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
|
|
1066
|
+
}
|
|
1067
|
+
return this;
|
|
1068
|
+
}
|
|
1069
|
+
replaceAll(searchValue, replacement) {
|
|
1070
|
+
if (typeof searchValue === "string") {
|
|
1071
|
+
return this._replaceAllString(searchValue, replacement);
|
|
1072
|
+
}
|
|
1073
|
+
if (!searchValue.global) {
|
|
1074
|
+
throw new TypeError(
|
|
1075
|
+
"MagicString.prototype.replaceAll called with a non-global RegExp argument"
|
|
1076
|
+
);
|
|
1077
|
+
}
|
|
1078
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
|
|
1082
|
+
// ../../modules/svelte-editor/annotate.ts
|
|
1083
|
+
import { compile as compile2 } from "svelte/compiler";
|
|
1084
|
+
|
|
1085
|
+
// ../../modules/svelte-editor/edits.ts
|
|
1086
|
+
var InvalidStringEditError = class extends Error {
|
|
1087
|
+
constructor(message) {
|
|
1088
|
+
super(message);
|
|
1089
|
+
this.name = "InvalidStringEditError";
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
function applyStringEdits(source, edits) {
|
|
1093
|
+
const sorted = validateStringEdits(source, edits);
|
|
1094
|
+
let nextSource = source;
|
|
1095
|
+
for (const edit of sorted) {
|
|
1096
|
+
nextSource = nextSource.slice(0, edit.start) + edit.replacement + nextSource.slice(edit.end);
|
|
1097
|
+
}
|
|
1098
|
+
return nextSource;
|
|
1099
|
+
}
|
|
1100
|
+
function validateStringEdits(source, edits) {
|
|
1101
|
+
return validateEditShape(edits, source.length);
|
|
1102
|
+
}
|
|
1103
|
+
function validateEditShape(edits, sourceLength) {
|
|
1104
|
+
const sorted = [...edits].sort(
|
|
1105
|
+
(left, right) => right.start - left.start || right.end - left.end
|
|
1106
|
+
);
|
|
1107
|
+
for (const edit of sorted) {
|
|
1108
|
+
if (!Number.isInteger(edit.start) || !Number.isInteger(edit.end)) {
|
|
1109
|
+
throw new InvalidStringEditError("edit offsets must be integers");
|
|
1110
|
+
}
|
|
1111
|
+
if (edit.start < 0 || edit.end < edit.start || sourceLength !== void 0 && edit.end > sourceLength) {
|
|
1112
|
+
throw new InvalidStringEditError(
|
|
1113
|
+
sourceLength === void 0 ? `edit [${edit.start}, ${edit.end}) is not a valid source range` : `edit [${edit.start}, ${edit.end}) is outside source length ${sourceLength}`
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
for (let index = 0; index < sorted.length - 1; index += 1) {
|
|
1118
|
+
const later = sorted[index];
|
|
1119
|
+
const earlier = sorted[index + 1];
|
|
1120
|
+
if (!later || !earlier) continue;
|
|
1121
|
+
if (earlier.start === later.start && (earlier.start === earlier.end || later.start === later.end)) {
|
|
1122
|
+
throw new InvalidStringEditError(
|
|
1123
|
+
`an insertion and another edit at offset ${earlier.start} have ambiguous order`
|
|
1124
|
+
);
|
|
1125
|
+
}
|
|
1126
|
+
if (earlier.end > later.start) {
|
|
1127
|
+
throw new InvalidStringEditError(
|
|
1128
|
+
`edits [${earlier.start}, ${earlier.end}) and [${later.start}, ${later.end}) overlap`
|
|
1129
|
+
);
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return sorted;
|
|
1133
|
+
}
|
|
1134
|
+
function mapOffsetThroughStringEdits(offset, edits) {
|
|
1135
|
+
if (!Number.isInteger(offset) || offset < 0) {
|
|
1136
|
+
throw new InvalidStringEditError(
|
|
1137
|
+
"the mapped source offset must be a non-negative integer"
|
|
1138
|
+
);
|
|
1139
|
+
}
|
|
1140
|
+
let delta = 0;
|
|
1141
|
+
for (const edit of [...validateEditShape(edits)].reverse()) {
|
|
1142
|
+
if (offset < edit.start) break;
|
|
1143
|
+
if (offset < edit.end) return null;
|
|
1144
|
+
delta += edit.replacement.length - (edit.end - edit.start);
|
|
1145
|
+
}
|
|
1146
|
+
return offset + delta;
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
// ../../modules/svelte-editor/escape.ts
|
|
1150
|
+
function escapeSvelteAttributeValue(value, quote) {
|
|
1151
|
+
let escaped = value.split("&").join("&").split("<").join("<").split(">").join(">").split("{").join("{").split("}").join("}");
|
|
1152
|
+
escaped = quote === '"' ? escaped.split('"').join(""") : escaped.split("'").join("'");
|
|
1153
|
+
return escaped;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/walker.js
|
|
1157
|
+
var WalkerBase = class {
|
|
1158
|
+
constructor() {
|
|
1159
|
+
this.should_skip = false;
|
|
1160
|
+
this.should_remove = false;
|
|
1161
|
+
this.replacement = null;
|
|
1162
|
+
this.context = {
|
|
1163
|
+
skip: () => this.should_skip = true,
|
|
1164
|
+
remove: () => this.should_remove = true,
|
|
1165
|
+
replace: (node) => this.replacement = node
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* @template {Node} Parent
|
|
1170
|
+
* @param {Parent | null | undefined} parent
|
|
1171
|
+
* @param {keyof Parent | null | undefined} prop
|
|
1172
|
+
* @param {number | null | undefined} index
|
|
1173
|
+
* @param {Node} node
|
|
1174
|
+
*/
|
|
1175
|
+
replace(parent, prop, index, node) {
|
|
1176
|
+
if (parent && prop) {
|
|
1177
|
+
if (index != null) {
|
|
1178
|
+
parent[prop][index] = node;
|
|
1179
|
+
} else {
|
|
1180
|
+
parent[prop] = node;
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* @template {Node} Parent
|
|
1186
|
+
* @param {Parent | null | undefined} parent
|
|
1187
|
+
* @param {keyof Parent | null | undefined} prop
|
|
1188
|
+
* @param {number | null | undefined} index
|
|
1189
|
+
*/
|
|
1190
|
+
remove(parent, prop, index) {
|
|
1191
|
+
if (parent && prop) {
|
|
1192
|
+
if (index !== null && index !== void 0) {
|
|
1193
|
+
parent[prop].splice(index, 1);
|
|
1194
|
+
} else {
|
|
1195
|
+
delete parent[prop];
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1201
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/sync.js
|
|
1202
|
+
var SyncWalker = class extends WalkerBase {
|
|
1203
|
+
/**
|
|
1204
|
+
*
|
|
1205
|
+
* @param {SyncHandler} [enter]
|
|
1206
|
+
* @param {SyncHandler} [leave]
|
|
1207
|
+
*/
|
|
1208
|
+
constructor(enter, leave) {
|
|
1209
|
+
super();
|
|
1210
|
+
this.should_skip = false;
|
|
1211
|
+
this.should_remove = false;
|
|
1212
|
+
this.replacement = null;
|
|
1213
|
+
this.context = {
|
|
1214
|
+
skip: () => this.should_skip = true,
|
|
1215
|
+
remove: () => this.should_remove = true,
|
|
1216
|
+
replace: (node) => this.replacement = node
|
|
1217
|
+
};
|
|
1218
|
+
this.enter = enter;
|
|
1219
|
+
this.leave = leave;
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* @template {Node} Parent
|
|
1223
|
+
* @param {Node} node
|
|
1224
|
+
* @param {Parent | null} parent
|
|
1225
|
+
* @param {keyof Parent} [prop]
|
|
1226
|
+
* @param {number | null} [index]
|
|
1227
|
+
* @returns {Node | null}
|
|
1228
|
+
*/
|
|
1229
|
+
visit(node, parent, prop, index) {
|
|
1230
|
+
if (node) {
|
|
1231
|
+
if (this.enter) {
|
|
1232
|
+
const _should_skip = this.should_skip;
|
|
1233
|
+
const _should_remove = this.should_remove;
|
|
1234
|
+
const _replacement = this.replacement;
|
|
1235
|
+
this.should_skip = false;
|
|
1236
|
+
this.should_remove = false;
|
|
1237
|
+
this.replacement = null;
|
|
1238
|
+
this.enter.call(this.context, node, parent, prop, index);
|
|
1239
|
+
if (this.replacement) {
|
|
1240
|
+
node = this.replacement;
|
|
1241
|
+
this.replace(parent, prop, index, node);
|
|
1242
|
+
}
|
|
1243
|
+
if (this.should_remove) {
|
|
1244
|
+
this.remove(parent, prop, index);
|
|
1245
|
+
}
|
|
1246
|
+
const skipped = this.should_skip;
|
|
1247
|
+
const removed = this.should_remove;
|
|
1248
|
+
this.should_skip = _should_skip;
|
|
1249
|
+
this.should_remove = _should_remove;
|
|
1250
|
+
this.replacement = _replacement;
|
|
1251
|
+
if (skipped) return node;
|
|
1252
|
+
if (removed) return null;
|
|
1253
|
+
}
|
|
1254
|
+
let key;
|
|
1255
|
+
for (key in node) {
|
|
1256
|
+
const value = node[key];
|
|
1257
|
+
if (value && typeof value === "object") {
|
|
1258
|
+
if (Array.isArray(value)) {
|
|
1259
|
+
const nodes = (
|
|
1260
|
+
/** @type {Array<unknown>} */
|
|
1261
|
+
value
|
|
1262
|
+
);
|
|
1263
|
+
for (let i = 0; i < nodes.length; i += 1) {
|
|
1264
|
+
const item = nodes[i];
|
|
1265
|
+
if (isNode(item)) {
|
|
1266
|
+
if (!this.visit(item, node, key, i)) {
|
|
1267
|
+
i--;
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
} else if (isNode(value)) {
|
|
1272
|
+
this.visit(value, node, key, null);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
if (this.leave) {
|
|
1277
|
+
const _replacement = this.replacement;
|
|
1278
|
+
const _should_remove = this.should_remove;
|
|
1279
|
+
this.replacement = null;
|
|
1280
|
+
this.should_remove = false;
|
|
1281
|
+
this.leave.call(this.context, node, parent, prop, index);
|
|
1282
|
+
if (this.replacement) {
|
|
1283
|
+
node = this.replacement;
|
|
1284
|
+
this.replace(parent, prop, index, node);
|
|
1285
|
+
}
|
|
1286
|
+
if (this.should_remove) {
|
|
1287
|
+
this.remove(parent, prop, index);
|
|
1288
|
+
}
|
|
1289
|
+
const removed = this.should_remove;
|
|
1290
|
+
this.replacement = _replacement;
|
|
1291
|
+
this.should_remove = _should_remove;
|
|
1292
|
+
if (removed) return null;
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
return node;
|
|
1296
|
+
}
|
|
1297
|
+
};
|
|
1298
|
+
function isNode(value) {
|
|
1299
|
+
return value !== null && typeof value === "object" && "type" in value && typeof value.type === "string";
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// ../../node_modules/.pnpm/estree-walker@3.0.3/node_modules/estree-walker/src/index.js
|
|
1303
|
+
function walk(ast, { enter, leave }) {
|
|
1304
|
+
const instance = new SyncWalker(enter, leave);
|
|
1305
|
+
return instance.visit(ast, null);
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
// ../../modules/svelte-editor/parse.ts
|
|
1309
|
+
import {
|
|
1310
|
+
compile,
|
|
1311
|
+
parse
|
|
1312
|
+
} from "svelte/compiler";
|
|
1313
|
+
function parseSvelteSourceInternal(source, filename, validation = "compiler") {
|
|
1314
|
+
const cacheKey = `${validation}\0${filename}\0${source}`;
|
|
1315
|
+
const cached = parseCache.get(cacheKey);
|
|
1316
|
+
if (cached) {
|
|
1317
|
+
parseCache.delete(cacheKey);
|
|
1318
|
+
parseCache.set(cacheKey, cached);
|
|
1319
|
+
return cached;
|
|
1320
|
+
}
|
|
1321
|
+
try {
|
|
1322
|
+
if (validation === "compiler") {
|
|
1323
|
+
compile(source, { filename, generate: false });
|
|
1324
|
+
}
|
|
1325
|
+
const ast = parse(source, { filename, modern: true });
|
|
1326
|
+
const elements = /* @__PURE__ */ new Map();
|
|
1327
|
+
const targets = /* @__PURE__ */ new Map();
|
|
1328
|
+
const targetNodes = /* @__PURE__ */ new Map();
|
|
1329
|
+
const elementStack = [];
|
|
1330
|
+
const fragmentOwnerTypes = /* @__PURE__ */ new WeakMap();
|
|
1331
|
+
walk(ast, {
|
|
1332
|
+
enter(node, parent) {
|
|
1333
|
+
const svelteNode = node;
|
|
1334
|
+
if (svelteNode.type === "Fragment") {
|
|
1335
|
+
fragmentOwnerTypes.set(
|
|
1336
|
+
node,
|
|
1337
|
+
parent?.type ?? null
|
|
1338
|
+
);
|
|
1339
|
+
}
|
|
1340
|
+
const target = toTargetInfo(
|
|
1341
|
+
node
|
|
1342
|
+
);
|
|
1343
|
+
if (target) {
|
|
1344
|
+
targets.set(target.start, target);
|
|
1345
|
+
targetNodes.set(
|
|
1346
|
+
target.start,
|
|
1347
|
+
node
|
|
1348
|
+
);
|
|
1349
|
+
}
|
|
1350
|
+
if (svelteNode.type !== "RegularElement") return;
|
|
1351
|
+
const element = node;
|
|
1352
|
+
const parentFragment = parent;
|
|
1353
|
+
if (parentFragment.type !== "Fragment") {
|
|
1354
|
+
throw new Error(
|
|
1355
|
+
`native element at offset ${element.start} has no exact template fragment parent`
|
|
1356
|
+
);
|
|
1357
|
+
}
|
|
1358
|
+
const opening = locateOpeningTagEnd(source, element);
|
|
1359
|
+
if (opening.kind === "invalid") {
|
|
1360
|
+
throw new Error(opening.message);
|
|
1361
|
+
}
|
|
1362
|
+
if (elements.has(element.start)) {
|
|
1363
|
+
throw new Error(
|
|
1364
|
+
`multiple native elements start at UTF-16 offset ${element.start}`
|
|
1365
|
+
);
|
|
1366
|
+
}
|
|
1367
|
+
elements.set(element.start, {
|
|
1368
|
+
node: element,
|
|
1369
|
+
tagName: element.name,
|
|
1370
|
+
start: element.start,
|
|
1371
|
+
end: element.end,
|
|
1372
|
+
openingEnd: opening.openingEnd,
|
|
1373
|
+
selfClosing: opening.selfClosing,
|
|
1374
|
+
childrenStart: opening.selfClosing ? null : opening.openingEnd,
|
|
1375
|
+
childrenEnd: opening.selfClosing ? null : locateClosingTagStart(source, element, opening.openingEnd),
|
|
1376
|
+
parentElementStart: elementStack[elementStack.length - 1]?.start ?? null,
|
|
1377
|
+
parentFragment,
|
|
1378
|
+
parentFragmentOwnerType: fragmentOwnerTypes.get(parentFragment) ?? null,
|
|
1379
|
+
containsDynamicTemplateSyntax: containsDynamicSyntax(element),
|
|
1380
|
+
attributeNames: element.attributes.filter(
|
|
1381
|
+
(attribute) => attribute.type === "Attribute"
|
|
1382
|
+
).map((attribute) => attribute.name),
|
|
1383
|
+
hasSpreadAttributes: element.attributes.some(
|
|
1384
|
+
(attribute) => attribute.type === "SpreadAttribute"
|
|
1385
|
+
),
|
|
1386
|
+
directiveTypes: element.attributes.filter(
|
|
1387
|
+
(attribute) => attribute.type !== "Attribute" && attribute.type !== "SpreadAttribute"
|
|
1388
|
+
).map((attribute) => attribute.type)
|
|
1389
|
+
});
|
|
1390
|
+
elementStack.push(element);
|
|
1391
|
+
},
|
|
1392
|
+
leave(node) {
|
|
1393
|
+
const svelteNode = node;
|
|
1394
|
+
if (svelteNode.type === "RegularElement") elementStack.pop();
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
const result = { kind: "ok", elements, targets, targetNodes };
|
|
1398
|
+
rememberParse(cacheKey, result);
|
|
1399
|
+
return result;
|
|
1400
|
+
} catch (error) {
|
|
1401
|
+
const result = compilerError(error);
|
|
1402
|
+
rememberParse(cacheKey, result);
|
|
1403
|
+
return result;
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
function toTargetInfo(node) {
|
|
1407
|
+
if (node.type === "RegularElement") {
|
|
1408
|
+
return {
|
|
1409
|
+
kind: "native-element",
|
|
1410
|
+
tagName: node.name ?? "",
|
|
1411
|
+
start: node.start,
|
|
1412
|
+
end: node.end,
|
|
1413
|
+
...targetAttributeFacts(node.attributes ?? [])
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
if (node.type === "Component") {
|
|
1417
|
+
return {
|
|
1418
|
+
kind: "component",
|
|
1419
|
+
tagName: node.name ?? "",
|
|
1420
|
+
start: node.start,
|
|
1421
|
+
end: node.end,
|
|
1422
|
+
...targetAttributeFacts(node.attributes ?? [])
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
if (node.type === "SvelteComponent") {
|
|
1426
|
+
return {
|
|
1427
|
+
kind: "component",
|
|
1428
|
+
tagName: node.name ?? node.type,
|
|
1429
|
+
start: node.start,
|
|
1430
|
+
end: node.end,
|
|
1431
|
+
...targetAttributeFacts(node.attributes ?? [])
|
|
1432
|
+
};
|
|
1433
|
+
}
|
|
1434
|
+
if (node.type === "SvelteElement") {
|
|
1435
|
+
return {
|
|
1436
|
+
kind: "dynamic-element",
|
|
1437
|
+
tagName: node.name ?? node.type,
|
|
1438
|
+
start: node.start,
|
|
1439
|
+
end: node.end,
|
|
1440
|
+
...targetAttributeFacts(node.attributes ?? [])
|
|
1441
|
+
};
|
|
1442
|
+
}
|
|
1443
|
+
if (node.type === "SlotElement" || node.type === "TitleElement" || node.type === "SvelteBody" || node.type === "SvelteBoundary" || node.type === "SvelteDocument" || node.type === "SvelteFragment" || node.type === "SvelteHead" || node.type === "SvelteSelf" || node.type === "SvelteWindow") {
|
|
1444
|
+
return {
|
|
1445
|
+
kind: "special-element",
|
|
1446
|
+
tagName: node.name ?? node.type,
|
|
1447
|
+
start: node.start,
|
|
1448
|
+
end: node.end
|
|
1449
|
+
};
|
|
1450
|
+
}
|
|
1451
|
+
return null;
|
|
1452
|
+
}
|
|
1453
|
+
function targetAttributeFacts(attributes) {
|
|
1454
|
+
const staticAttributes = {};
|
|
1455
|
+
for (const attribute of attributes) {
|
|
1456
|
+
if (attribute.type !== "Attribute") continue;
|
|
1457
|
+
if (attribute.value === true) {
|
|
1458
|
+
staticAttributes[attribute.name] = true;
|
|
1459
|
+
continue;
|
|
1460
|
+
}
|
|
1461
|
+
if (Array.isArray(attribute.value) && attribute.value.every((part) => part.type === "Text")) {
|
|
1462
|
+
staticAttributes[attribute.name] = attribute.value.map((part) => part.data).join("");
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
return {
|
|
1466
|
+
attributeNames: attributes.filter(
|
|
1467
|
+
(attribute) => attribute.type === "Attribute"
|
|
1468
|
+
).map((attribute) => attribute.name),
|
|
1469
|
+
hasSpreadAttributes: attributes.some(
|
|
1470
|
+
(attribute) => attribute.type === "SpreadAttribute"
|
|
1471
|
+
),
|
|
1472
|
+
directiveTypes: attributes.filter(
|
|
1473
|
+
(attribute) => attribute.type !== "Attribute" && attribute.type !== "SpreadAttribute"
|
|
1474
|
+
).map((attribute) => attribute.type),
|
|
1475
|
+
staticAttributes
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
var PARSE_CACHE_LIMIT = 16;
|
|
1479
|
+
var parseCache = /* @__PURE__ */ new Map();
|
|
1480
|
+
function rememberParse(key, result) {
|
|
1481
|
+
parseCache.set(key, result);
|
|
1482
|
+
while (parseCache.size > PARSE_CACHE_LIMIT) {
|
|
1483
|
+
const oldest = parseCache.keys().next().value;
|
|
1484
|
+
if (oldest === void 0) break;
|
|
1485
|
+
parseCache.delete(oldest);
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
function locateOpeningTagEnd(source, element) {
|
|
1489
|
+
const lastAttribute = element.attributes[element.attributes.length - 1];
|
|
1490
|
+
const afterName = element.start + 1 + element.name.length;
|
|
1491
|
+
const cursor = lastAttribute?.end ?? afterName;
|
|
1492
|
+
const tail = source.slice(cursor, element.end);
|
|
1493
|
+
const closing = /^(\s*)(\/?)>/.exec(tail);
|
|
1494
|
+
if (!closing) {
|
|
1495
|
+
return {
|
|
1496
|
+
kind: "invalid",
|
|
1497
|
+
message: `could not locate the opening-tag terminator for <${element.name}> at UTF-16 offset ${element.start}`
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
return {
|
|
1501
|
+
kind: "ok",
|
|
1502
|
+
openingEnd: cursor + closing[0].length,
|
|
1503
|
+
selfClosing: closing[2] === "/"
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
function locateClosingTagStart(source, element, openingEnd) {
|
|
1507
|
+
const escapedName = element.name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1508
|
+
const match = new RegExp(`</${escapedName}\\s*>$`).exec(
|
|
1509
|
+
source.slice(openingEnd, element.end)
|
|
1510
|
+
);
|
|
1511
|
+
return match ? openingEnd + match.index : null;
|
|
1512
|
+
}
|
|
1513
|
+
function containsDynamicSyntax(element) {
|
|
1514
|
+
let dynamic = false;
|
|
1515
|
+
walk(element, {
|
|
1516
|
+
enter(node) {
|
|
1517
|
+
const type = node.type;
|
|
1518
|
+
if (type === "ExpressionTag" || type === "HtmlTag" || type === "RenderTag" || type === "AttachTag" || type === "ConstTag" || type === "DeclarationTag" || type === "DebugTag" || type === "SpreadAttribute" || typeof type === "string" && type.endsWith("Directive") || type === "Component" || type === "SvelteComponent" || type === "SvelteElement" || type === "EachBlock" || type === "IfBlock" || type === "AwaitBlock" || type === "KeyBlock" || type === "SnippetBlock") {
|
|
1519
|
+
dynamic = true;
|
|
1520
|
+
this.skip();
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
});
|
|
1524
|
+
return dynamic;
|
|
1525
|
+
}
|
|
1526
|
+
function compilerError(error) {
|
|
1527
|
+
if (error && typeof error === "object") {
|
|
1528
|
+
const value = error;
|
|
1529
|
+
return {
|
|
1530
|
+
kind: "invalid",
|
|
1531
|
+
code: typeof value.code === "string" ? value.code : "invalid_svelte",
|
|
1532
|
+
message: typeof value.message === "string" ? value.message : (
|
|
1533
|
+
/* v8 ignore next -- Svelte compiler diagnostics always carry messages */
|
|
1534
|
+
"Svelte source could not be parsed"
|
|
1535
|
+
)
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
return {
|
|
1539
|
+
kind: "invalid",
|
|
1540
|
+
code: "invalid_svelte",
|
|
1541
|
+
message: String(error)
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
// ../../modules/svelte-editor/annotate.ts
|
|
1546
|
+
var TEMPO_ATTRIBUTE_NAMES = [
|
|
1547
|
+
"data-tempo-filepath",
|
|
1548
|
+
"data-tempo-position",
|
|
1549
|
+
"data-tempo-modifiedts",
|
|
1550
|
+
"data-tempo-source-version"
|
|
1551
|
+
];
|
|
1552
|
+
var TEMPO_ATTRIBUTE_NAME_SET = new Set(TEMPO_ATTRIBUTE_NAMES);
|
|
1553
|
+
var TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE = "data-tempo-svelte-source-registry";
|
|
1554
|
+
function annotateSvelteSource(options) {
|
|
1555
|
+
if (!options.filepath || !options.filename || !Number.isFinite(options.modifiedTs) || !Number.isInteger(options.modifiedTs) || options.modifiedTs < 0 || options.sourceVersion === "") {
|
|
1556
|
+
return {
|
|
1557
|
+
kind: "refused",
|
|
1558
|
+
code: "invalid_metadata",
|
|
1559
|
+
message: "filename, filepath, a non-negative integer modifiedTs, and a non-empty sourceVersion are required"
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1562
|
+
const inputSource = removeGeneratedSourceRegistries(options.source);
|
|
1563
|
+
const validation = options.validation ?? "compiler";
|
|
1564
|
+
const parsed = parseSvelteSourceInternal(
|
|
1565
|
+
inputSource,
|
|
1566
|
+
options.filename,
|
|
1567
|
+
validation
|
|
1568
|
+
);
|
|
1569
|
+
if (parsed.kind === "invalid") {
|
|
1570
|
+
return { kind: "refused", code: "invalid_source", message: parsed.message };
|
|
1571
|
+
}
|
|
1572
|
+
const removalEdits = [];
|
|
1573
|
+
const existing = /* @__PURE__ */ new Map();
|
|
1574
|
+
for (const element of parsed.elements.values()) {
|
|
1575
|
+
const tempoAttributes = element.node.attributes.filter(
|
|
1576
|
+
(attribute) => attribute.type === "Attribute" && TEMPO_ATTRIBUTE_NAME_SET.has(attribute.name)
|
|
1577
|
+
);
|
|
1578
|
+
if (tempoAttributes.length === 0) continue;
|
|
1579
|
+
const conflict = readExistingAnnotation(inputSource, element.node);
|
|
1580
|
+
if (conflict.kind === "refused") return conflict;
|
|
1581
|
+
existing.set(element.start, conflict.metadata);
|
|
1582
|
+
removalEdits.push(conflict.removalEdit);
|
|
1583
|
+
}
|
|
1584
|
+
const baseSource = applyStringEdits(inputSource, removalEdits);
|
|
1585
|
+
const baseParsed = parseSvelteSourceInternal(
|
|
1586
|
+
baseSource,
|
|
1587
|
+
options.filename,
|
|
1588
|
+
validation
|
|
1589
|
+
);
|
|
1590
|
+
if (baseParsed.kind === "invalid") {
|
|
1591
|
+
return {
|
|
1592
|
+
kind: "refused",
|
|
1593
|
+
code: "annotation_conflict",
|
|
1594
|
+
message: "removing existing Tempo annotations did not recover valid source"
|
|
1595
|
+
};
|
|
1596
|
+
}
|
|
1597
|
+
const version = options.sourceVersion ?? sourceVersionHash(baseSource);
|
|
1598
|
+
for (const [currentOffset, metadata] of existing) {
|
|
1599
|
+
const baseOffset = mapOffsetThroughStringEdits(currentOffset, removalEdits);
|
|
1600
|
+
if (baseOffset === null || !baseParsed.elements.has(baseOffset) || metadata.filepath !== options.filepath || metadata.position !== baseOffset || metadata.modifiedTs !== options.modifiedTs || metadata.sourceVersion !== version) {
|
|
1601
|
+
return {
|
|
1602
|
+
kind: "refused",
|
|
1603
|
+
code: "annotation_conflict",
|
|
1604
|
+
message: `existing Tempo annotations at UTF-16 offset ${currentOffset} do not exactly match the recovered source identity`
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
const edits = [];
|
|
1609
|
+
const skippedExistingAnnotations = [];
|
|
1610
|
+
for (const element of parsed.elements.values()) {
|
|
1611
|
+
const baseOffset = mapOffsetThroughStringEdits(element.start, removalEdits);
|
|
1612
|
+
if (baseOffset === null || !baseParsed.elements.has(baseOffset)) {
|
|
1613
|
+
return {
|
|
1614
|
+
kind: "refused",
|
|
1615
|
+
code: "annotation_conflict",
|
|
1616
|
+
message: `could not map element at UTF-16 offset ${element.start} to recovered source`
|
|
1617
|
+
};
|
|
1618
|
+
}
|
|
1619
|
+
if (existing.has(element.start)) {
|
|
1620
|
+
skippedExistingAnnotations.push(baseOffset);
|
|
1621
|
+
continue;
|
|
1622
|
+
}
|
|
1623
|
+
const insertionOffset = element.node.attributes[element.node.attributes.length - 1]?.end ?? element.start + 1 + element.tagName.length;
|
|
1624
|
+
edits.push({
|
|
1625
|
+
start: insertionOffset,
|
|
1626
|
+
end: insertionOffset,
|
|
1627
|
+
replacement: serializeAnnotations({
|
|
1628
|
+
filepath: options.filepath,
|
|
1629
|
+
position: baseOffset,
|
|
1630
|
+
modifiedTs: options.modifiedTs,
|
|
1631
|
+
sourceVersion: version
|
|
1632
|
+
})
|
|
1633
|
+
});
|
|
1634
|
+
}
|
|
1635
|
+
const annotatedCode = applyStringEdits(inputSource, edits);
|
|
1636
|
+
const sourceRecords = buildSourceRecords({
|
|
1637
|
+
parsed,
|
|
1638
|
+
removalEdits,
|
|
1639
|
+
annotationEdits: edits,
|
|
1640
|
+
annotatedCode
|
|
1641
|
+
});
|
|
1642
|
+
const registry = {
|
|
1643
|
+
filename: options.filename,
|
|
1644
|
+
filepath: options.filepath,
|
|
1645
|
+
modifiedTs: options.modifiedTs,
|
|
1646
|
+
sourceVersion: version,
|
|
1647
|
+
components: sourceRecords.components,
|
|
1648
|
+
hosts: sourceRecords.hosts
|
|
1649
|
+
};
|
|
1650
|
+
const registryEdit = {
|
|
1651
|
+
start: inputSource.length,
|
|
1652
|
+
end: inputSource.length,
|
|
1653
|
+
replacement: `
|
|
1654
|
+
<template ${TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE}="${escapeSvelteAttributeValue(JSON.stringify(registry), '"')}"></template>
|
|
1655
|
+
`
|
|
1656
|
+
};
|
|
1657
|
+
const transformEdits = [...edits, registryEdit];
|
|
1658
|
+
const code = applyStringEdits(inputSource, transformEdits);
|
|
1659
|
+
try {
|
|
1660
|
+
if (validation === "compiler") {
|
|
1661
|
+
compile2(code, { filename: options.filename, generate: false });
|
|
1662
|
+
} else {
|
|
1663
|
+
const parsedOutput = parseSvelteSourceInternal(
|
|
1664
|
+
code,
|
|
1665
|
+
options.filename,
|
|
1666
|
+
"syntax"
|
|
1667
|
+
);
|
|
1668
|
+
if (parsedOutput.kind === "invalid")
|
|
1669
|
+
throw new Error(parsedOutput.message);
|
|
1670
|
+
}
|
|
1671
|
+
} catch (error) {
|
|
1672
|
+
return {
|
|
1673
|
+
kind: "refused",
|
|
1674
|
+
code: "invalid_output",
|
|
1675
|
+
message: error instanceof Error ? error.message : String(error)
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
const magic = new MagicString(inputSource);
|
|
1679
|
+
for (const edit of transformEdits) {
|
|
1680
|
+
magic.appendLeft(edit.start, edit.replacement);
|
|
1681
|
+
}
|
|
1682
|
+
if (magic.toString() !== code) {
|
|
1683
|
+
return {
|
|
1684
|
+
kind: "refused",
|
|
1685
|
+
code: "invalid_output",
|
|
1686
|
+
message: "annotation code and source-map transform outputs diverged"
|
|
1687
|
+
};
|
|
1688
|
+
}
|
|
1689
|
+
return {
|
|
1690
|
+
kind: "ok",
|
|
1691
|
+
code,
|
|
1692
|
+
map: magic.generateMap({
|
|
1693
|
+
source: options.filename,
|
|
1694
|
+
includeContent: true,
|
|
1695
|
+
hires: true
|
|
1696
|
+
}),
|
|
1697
|
+
edits,
|
|
1698
|
+
elementsAnnotated: edits.length,
|
|
1699
|
+
skippedExistingAnnotations,
|
|
1700
|
+
sourceVersion: version
|
|
1701
|
+
};
|
|
1702
|
+
}
|
|
1703
|
+
function removeGeneratedSourceRegistries(source) {
|
|
1704
|
+
const escaped = TEMPO_SVELTE_SOURCE_REGISTRY_ATTRIBUTE.replace(
|
|
1705
|
+
/[.*+?^${}()|[\]\\]/g,
|
|
1706
|
+
"\\$&"
|
|
1707
|
+
);
|
|
1708
|
+
return source.replace(
|
|
1709
|
+
new RegExp(
|
|
1710
|
+
`\\n?<template\\s+${escaped}=(?:"[^"]*"|'[^']*')\\s*><\\/template>\\n?`,
|
|
1711
|
+
"g"
|
|
1712
|
+
),
|
|
1713
|
+
""
|
|
1714
|
+
);
|
|
1715
|
+
}
|
|
1716
|
+
function buildSourceRecords(options) {
|
|
1717
|
+
const components = [];
|
|
1718
|
+
const hosts = [];
|
|
1719
|
+
for (const target of options.parsed.targets.values()) {
|
|
1720
|
+
if (target.kind !== "component" && target.kind !== "native-element" && target.kind !== "dynamic-element") {
|
|
1721
|
+
continue;
|
|
1722
|
+
}
|
|
1723
|
+
const position = mapOffsetThroughStringEdits(
|
|
1724
|
+
target.start,
|
|
1725
|
+
options.removalEdits
|
|
1726
|
+
);
|
|
1727
|
+
if (position === null) continue;
|
|
1728
|
+
const compiledOffset = mapOffsetForward(target.start, options.annotationEdits);
|
|
1729
|
+
const location = sourceLocationAt(options.annotatedCode, compiledOffset);
|
|
1730
|
+
const classValue = target.staticAttributes?.class;
|
|
1731
|
+
const styleValue = target.staticAttributes?.style;
|
|
1732
|
+
const hasSpread = target.hasSpreadAttributes === true;
|
|
1733
|
+
const directives = new Set(target.directiveTypes ?? []);
|
|
1734
|
+
const attributes = new Set(target.attributeNames ?? []);
|
|
1735
|
+
const common = {
|
|
1736
|
+
name: target.tagName,
|
|
1737
|
+
line: location.line,
|
|
1738
|
+
column: location.column,
|
|
1739
|
+
position,
|
|
1740
|
+
...typeof classValue === "string" ? { className: classValue } : {},
|
|
1741
|
+
...typeof styleValue === "string" ? { style: styleValue } : {},
|
|
1742
|
+
supportsClassName: !hasSpread && !directives.has("ClassDirective") && (!attributes.has("class") || typeof classValue === "string"),
|
|
1743
|
+
supportsStyle: !hasSpread && !directives.has("StyleDirective") && (!attributes.has("style") || typeof styleValue === "string")
|
|
1744
|
+
};
|
|
1745
|
+
if (target.kind === "component") {
|
|
1746
|
+
components.push({ kind: "component", ...common });
|
|
1747
|
+
} else {
|
|
1748
|
+
hosts.push({ kind: "host", ...common });
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
return { components, hosts };
|
|
1752
|
+
}
|
|
1753
|
+
function mapOffsetForward(offset, edits) {
|
|
1754
|
+
let mapped = offset;
|
|
1755
|
+
for (const edit of edits) {
|
|
1756
|
+
if (edit.start > offset) continue;
|
|
1757
|
+
mapped += edit.replacement.length - (edit.end - edit.start);
|
|
1758
|
+
}
|
|
1759
|
+
return mapped;
|
|
1760
|
+
}
|
|
1761
|
+
function sourceLocationAt(source, offset) {
|
|
1762
|
+
const before = source.slice(0, offset);
|
|
1763
|
+
const lines = before.split("\n");
|
|
1764
|
+
return {
|
|
1765
|
+
line: lines.length,
|
|
1766
|
+
column: lines[lines.length - 1]?.length ?? 0
|
|
1767
|
+
};
|
|
1768
|
+
}
|
|
1769
|
+
function createSvelteAnnotationPreprocessor(options) {
|
|
1770
|
+
return {
|
|
1771
|
+
name: "svelte-source-annotation",
|
|
1772
|
+
markup: ({ content, filename }) => {
|
|
1773
|
+
const metadata = options.metadata({ filename, source: content });
|
|
1774
|
+
if (metadata === null) return void 0;
|
|
1775
|
+
const result = annotateSvelteSource({
|
|
1776
|
+
source: content,
|
|
1777
|
+
filename: filename ?? metadata.filepath,
|
|
1778
|
+
...metadata,
|
|
1779
|
+
validation: "syntax"
|
|
1780
|
+
});
|
|
1781
|
+
if (result.kind === "refused") {
|
|
1782
|
+
throw new Error(`${result.code}: ${result.message}`);
|
|
1783
|
+
}
|
|
1784
|
+
return { code: result.code, map: result.map };
|
|
1785
|
+
}
|
|
1786
|
+
};
|
|
1787
|
+
}
|
|
1788
|
+
function readExistingAnnotation(source, element) {
|
|
1789
|
+
const attributes = element.attributes.filter(
|
|
1790
|
+
(attribute) => attribute.type === "Attribute"
|
|
1791
|
+
);
|
|
1792
|
+
const tempo = attributes.filter(
|
|
1793
|
+
(attribute) => TEMPO_ATTRIBUTE_NAME_SET.has(attribute.name)
|
|
1794
|
+
);
|
|
1795
|
+
const names = tempo.map((attribute) => attribute.name);
|
|
1796
|
+
if (tempo.length !== TEMPO_ATTRIBUTE_NAMES.length || TEMPO_ATTRIBUTE_NAMES.some((name, index) => names[index] !== name) || attributes.slice(-TEMPO_ATTRIBUTE_NAMES.length).some((attribute, index) => attribute !== tempo[index]) || tempo.some((attribute) => !isStaticLiteralAttribute(attribute))) {
|
|
1797
|
+
return annotationConflict(element.start);
|
|
1798
|
+
}
|
|
1799
|
+
const [
|
|
1800
|
+
filepathAttribute,
|
|
1801
|
+
positionAttribute,
|
|
1802
|
+
modifiedAttribute,
|
|
1803
|
+
versionAttribute
|
|
1804
|
+
] = tempo;
|
|
1805
|
+
if (!filepathAttribute || !positionAttribute || !modifiedAttribute || !versionAttribute) {
|
|
1806
|
+
return annotationConflict(element.start);
|
|
1807
|
+
}
|
|
1808
|
+
const filepath = staticLiteralAttributeValue(filepathAttribute);
|
|
1809
|
+
const positionText = staticLiteralAttributeValue(positionAttribute);
|
|
1810
|
+
const modifiedText = staticLiteralAttributeValue(modifiedAttribute);
|
|
1811
|
+
const sourceVersion = staticLiteralAttributeValue(versionAttribute);
|
|
1812
|
+
const position = Number(positionText);
|
|
1813
|
+
const modifiedTs = Number(modifiedText);
|
|
1814
|
+
const first = tempo[0];
|
|
1815
|
+
const last = tempo[tempo.length - 1];
|
|
1816
|
+
if (!first || !last || source[first.start - 1] !== " " || !Number.isSafeInteger(position) || position < 0 || !Number.isSafeInteger(modifiedTs) || modifiedTs < 0 || !filepath || !sourceVersion) {
|
|
1817
|
+
return annotationConflict(element.start);
|
|
1818
|
+
}
|
|
1819
|
+
const expected = serializeAnnotations({
|
|
1820
|
+
filepath,
|
|
1821
|
+
position,
|
|
1822
|
+
modifiedTs,
|
|
1823
|
+
sourceVersion
|
|
1824
|
+
}).slice(1);
|
|
1825
|
+
if (source.slice(first.start, last.end) !== expected) {
|
|
1826
|
+
return annotationConflict(element.start);
|
|
1827
|
+
}
|
|
1828
|
+
return {
|
|
1829
|
+
kind: "ok",
|
|
1830
|
+
metadata: { filepath, position, modifiedTs, sourceVersion },
|
|
1831
|
+
removalEdit: {
|
|
1832
|
+
start: first.start - 1,
|
|
1833
|
+
end: last.end,
|
|
1834
|
+
replacement: ""
|
|
1835
|
+
}
|
|
1836
|
+
};
|
|
1837
|
+
}
|
|
1838
|
+
function annotationConflict(offset) {
|
|
1839
|
+
return {
|
|
1840
|
+
kind: "refused",
|
|
1841
|
+
code: "annotation_conflict",
|
|
1842
|
+
message: `element at UTF-16 offset ${offset} has partial, dynamic, reordered, or conflicting Tempo annotations`
|
|
1843
|
+
};
|
|
1844
|
+
}
|
|
1845
|
+
function isStaticLiteralAttribute(attribute) {
|
|
1846
|
+
return Array.isArray(attribute.value) && attribute.value.every((part) => part.type === "Text");
|
|
1847
|
+
}
|
|
1848
|
+
function staticLiteralAttributeValue(attribute) {
|
|
1849
|
+
return Array.isArray(attribute.value) ? attribute.value.map((part) => part.type === "Text" ? part.data : "").join("") : "";
|
|
1850
|
+
}
|
|
1851
|
+
function serializeAnnotations(metadata) {
|
|
1852
|
+
const values = {
|
|
1853
|
+
"data-tempo-filepath": metadata.filepath,
|
|
1854
|
+
"data-tempo-position": String(metadata.position),
|
|
1855
|
+
"data-tempo-modifiedts": String(metadata.modifiedTs),
|
|
1856
|
+
"data-tempo-source-version": metadata.sourceVersion
|
|
1857
|
+
};
|
|
1858
|
+
return Object.entries(values).map(
|
|
1859
|
+
([name, value]) => ` ${name}="${escapeSvelteAttributeValue(value, '"')}"`
|
|
1860
|
+
).join("");
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
// ../../modules/svelte-editor/plan.ts
|
|
1864
|
+
import {
|
|
1865
|
+
compile as compile3,
|
|
1866
|
+
parse as parse2
|
|
1867
|
+
} from "svelte/compiler";
|
|
1868
|
+
|
|
1869
|
+
// ../../modules/svelte-editor/transfer.ts
|
|
1870
|
+
import { parse as parse3 } from "svelte/compiler";
|
|
1871
|
+
|
|
1872
|
+
// svelte.ts
|
|
1873
|
+
function tempoSveltePreprocess(options = {}) {
|
|
1874
|
+
const root = resolve(options.root ?? process.cwd());
|
|
1875
|
+
const sourceRoot = resolve(options.sourceRoot ?? root);
|
|
1876
|
+
const enabled = options.enabled ?? Boolean(process.env.TEMPO);
|
|
1877
|
+
return createSvelteAnnotationPreprocessor({
|
|
1878
|
+
metadata({ filename }) {
|
|
1879
|
+
if (!enabled || !filename) return null;
|
|
1880
|
+
const absoluteFilename = resolve(filename);
|
|
1881
|
+
if (!absoluteFilename.endsWith(".svelte")) return null;
|
|
1882
|
+
const sourcePath = relative(sourceRoot, absoluteFilename);
|
|
1883
|
+
if (!sourcePath || sourcePath.startsWith("../") || isAbsolute(sourcePath) || sourcePath.split(/[\\/]/).includes("node_modules")) {
|
|
1884
|
+
return null;
|
|
1885
|
+
}
|
|
1886
|
+
const filepath = relative(root, absoluteFilename).replace(/\\/g, "/");
|
|
1887
|
+
if (!filepath || isAbsolute(filepath)) return null;
|
|
1888
|
+
return {
|
|
1889
|
+
filepath,
|
|
1890
|
+
modifiedTs: Math.trunc(statSync(absoluteFilename).mtimeMs)
|
|
1891
|
+
};
|
|
1892
|
+
}
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
export {
|
|
1896
|
+
tempoSveltePreprocess
|
|
1897
|
+
};
|
|
1898
|
+
//# sourceMappingURL=svelte.js.map
|