@cuadra-ai/uikit 0.2.0 → 0.3.0

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.
Files changed (44) hide show
  1. package/README.md +142 -2
  2. package/dist/adapters/attachmentAdapter.d.ts +63 -4
  3. package/dist/adapters/attachmentAdapter.d.ts.map +1 -1
  4. package/dist/components/CuadraChat.d.ts +54 -110
  5. package/dist/components/CuadraChat.d.ts.map +1 -1
  6. package/dist/components/CuadraChatContext.d.ts +141 -0
  7. package/dist/components/CuadraChatContext.d.ts.map +1 -0
  8. package/dist/components/ErrorBoundary.d.ts +79 -0
  9. package/dist/components/ErrorBoundary.d.ts.map +1 -0
  10. package/dist/index.cjs +425 -18
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.ts +8 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.mjs +52836 -2805
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/lib/cuadraChatClient.d.ts +2 -1
  17. package/dist/lib/cuadraChatClient.d.ts.map +1 -1
  18. package/dist/magic-string.es-B81Zo59j.cjs +11 -0
  19. package/dist/magic-string.es-B81Zo59j.cjs.map +1 -0
  20. package/dist/magic-string.es-uPKorP4O.js +664 -0
  21. package/dist/magic-string.es-uPKorP4O.js.map +1 -0
  22. package/dist/test/fixtures/index.d.ts +7 -0
  23. package/dist/test/fixtures/index.d.ts.map +1 -0
  24. package/dist/test/fixtures/mockChats.d.ts +41 -0
  25. package/dist/test/fixtures/mockChats.d.ts.map +1 -0
  26. package/dist/test/fixtures/mockModels.d.ts +31 -0
  27. package/dist/test/fixtures/mockModels.d.ts.map +1 -0
  28. package/dist/test/fixtures/mockStreams.d.ts +60 -0
  29. package/dist/test/fixtures/mockStreams.d.ts.map +1 -0
  30. package/dist/test/utils/index.d.ts +6 -0
  31. package/dist/test/utils/index.d.ts.map +1 -0
  32. package/dist/test/utils/mockFetch.d.ts +67 -0
  33. package/dist/test/utils/mockFetch.d.ts.map +1 -0
  34. package/dist/test/utils/renderWithProviders.d.ts +136 -0
  35. package/dist/test/utils/renderWithProviders.d.ts.map +1 -0
  36. package/dist/types/props.d.ts +500 -0
  37. package/dist/types/props.d.ts.map +1 -0
  38. package/dist/uikit.css +1 -1
  39. package/dist/utils/sanitize.d.ts +90 -0
  40. package/dist/utils/sanitize.d.ts.map +1 -0
  41. package/dist/widget/cuadra-uikit.css +1 -1
  42. package/dist/widget/cuadra-uikit.umd.js +24 -24
  43. package/dist/widget/cuadra-uikit.umd.js.map +1 -1
  44. package/package.json +1 -1
@@ -0,0 +1,664 @@
1
+ var x = 44, E = 59, m = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", S = new Uint8Array(64), k = new Uint8Array(128);
2
+ for (let u = 0; u < m.length; u++) {
3
+ const t = m.charCodeAt(u);
4
+ S[u] = t, k[t] = u;
5
+ }
6
+ function c(u, t, e) {
7
+ let i = t - e;
8
+ i = i < 0 ? -i << 1 | 1 : i << 1;
9
+ do {
10
+ let n = i & 31;
11
+ i >>>= 5, i > 0 && (n |= 32), u.write(S[n]);
12
+ } while (i > 0);
13
+ return t;
14
+ }
15
+ var b = 1024 * 16, C = typeof TextDecoder < "u" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer < "u" ? {
16
+ decode(u) {
17
+ return Buffer.from(u.buffer, u.byteOffset, u.byteLength).toString();
18
+ }
19
+ } : {
20
+ decode(u) {
21
+ let t = "";
22
+ for (let e = 0; e < u.length; e++)
23
+ t += String.fromCharCode(u[e]);
24
+ return t;
25
+ }
26
+ }, L = class {
27
+ constructor() {
28
+ this.pos = 0, this.out = "", this.buffer = new Uint8Array(b);
29
+ }
30
+ write(u) {
31
+ const { buffer: t } = this;
32
+ t[this.pos++] = u, this.pos === b && (this.out += C.decode(t), this.pos = 0);
33
+ }
34
+ flush() {
35
+ const { buffer: u, out: t, pos: e } = this;
36
+ return e > 0 ? t + C.decode(u.subarray(0, e)) : t;
37
+ }
38
+ };
39
+ function R(u) {
40
+ const t = new L();
41
+ let e = 0, i = 0, n = 0, r = 0;
42
+ for (let s = 0; s < u.length; s++) {
43
+ const h = u[s];
44
+ if (s > 0 && t.write(E), h.length === 0) continue;
45
+ let o = 0;
46
+ for (let l = 0; l < h.length; l++) {
47
+ const a = h[l];
48
+ l > 0 && t.write(x), o = c(t, a[0], o), a.length !== 1 && (e = c(t, a[1], e), i = c(t, a[2], i), n = c(t, a[3], n), a.length !== 4 && (r = c(t, a[4], r)));
49
+ }
50
+ }
51
+ return t.flush();
52
+ }
53
+ class p {
54
+ constructor(t) {
55
+ this.bits = t instanceof p ? t.bits.slice() : [];
56
+ }
57
+ add(t) {
58
+ this.bits[t >> 5] |= 1 << (t & 31);
59
+ }
60
+ has(t) {
61
+ return !!(this.bits[t >> 5] & 1 << (t & 31));
62
+ }
63
+ }
64
+ class g {
65
+ constructor(t, e, i) {
66
+ this.start = t, this.end = e, this.original = i, this.intro = "", this.outro = "", this.content = i, this.storeName = !1, this.edited = !1, this.previous = null, this.next = null;
67
+ }
68
+ appendLeft(t) {
69
+ this.outro += t;
70
+ }
71
+ appendRight(t) {
72
+ this.intro = this.intro + t;
73
+ }
74
+ clone() {
75
+ const t = new g(this.start, this.end, this.original);
76
+ return t.intro = this.intro, t.outro = this.outro, t.content = this.content, t.storeName = this.storeName, t.edited = this.edited, t;
77
+ }
78
+ contains(t) {
79
+ return this.start < t && t < this.end;
80
+ }
81
+ eachNext(t) {
82
+ let e = this;
83
+ for (; e; )
84
+ t(e), e = e.next;
85
+ }
86
+ eachPrevious(t) {
87
+ let e = this;
88
+ for (; e; )
89
+ t(e), e = e.previous;
90
+ }
91
+ edit(t, e, i) {
92
+ return this.content = t, i || (this.intro = "", this.outro = ""), this.storeName = e, this.edited = !0, this;
93
+ }
94
+ prependLeft(t) {
95
+ this.outro = t + this.outro;
96
+ }
97
+ prependRight(t) {
98
+ this.intro = t + this.intro;
99
+ }
100
+ reset() {
101
+ this.intro = "", this.outro = "", this.edited && (this.content = this.original, this.storeName = !1, this.edited = !1);
102
+ }
103
+ split(t) {
104
+ const e = t - this.start, i = this.original.slice(0, e), n = this.original.slice(e);
105
+ this.original = i;
106
+ const r = new g(t, this.end, n);
107
+ return r.outro = this.outro, this.outro = "", this.end = t, this.edited ? (r.edit("", !1), this.content = "") : this.content = i, r.next = this.next, r.next && (r.next.previous = r), r.previous = this, this.next = r, r;
108
+ }
109
+ toString() {
110
+ return this.intro + this.content + this.outro;
111
+ }
112
+ trimEnd(t) {
113
+ if (this.outro = this.outro.replace(t, ""), this.outro.length) return !0;
114
+ const e = this.content.replace(t, "");
115
+ if (e.length)
116
+ return e !== this.content && (this.split(this.start + e.length).edit("", void 0, !0), this.edited && this.edit(e, this.storeName, !0)), !0;
117
+ if (this.edit("", void 0, !0), this.intro = this.intro.replace(t, ""), this.intro.length) return !0;
118
+ }
119
+ trimStart(t) {
120
+ if (this.intro = this.intro.replace(t, ""), this.intro.length) return !0;
121
+ const e = this.content.replace(t, "");
122
+ if (e.length) {
123
+ if (e !== this.content) {
124
+ const i = this.split(this.end - e.length);
125
+ this.edited && i.edit(e, this.storeName, !0), this.edit("", void 0, !0);
126
+ }
127
+ return !0;
128
+ } else if (this.edit("", void 0, !0), this.outro = this.outro.replace(t, ""), this.outro.length) return !0;
129
+ }
130
+ }
131
+ function _() {
132
+ return typeof globalThis < "u" && typeof globalThis.btoa == "function" ? (u) => globalThis.btoa(unescape(encodeURIComponent(u))) : typeof Buffer == "function" ? (u) => Buffer.from(u, "utf-8").toString("base64") : () => {
133
+ throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
134
+ };
135
+ }
136
+ const O = /* @__PURE__ */ _();
137
+ class N {
138
+ constructor(t) {
139
+ this.version = 3, this.file = t.file, this.sources = t.sources, this.sourcesContent = t.sourcesContent, this.names = t.names, this.mappings = R(t.mappings), typeof t.x_google_ignoreList < "u" && (this.x_google_ignoreList = t.x_google_ignoreList), typeof t.debugId < "u" && (this.debugId = t.debugId);
140
+ }
141
+ toString() {
142
+ return JSON.stringify(this);
143
+ }
144
+ toUrl() {
145
+ return "data:application/json;charset=utf-8;base64," + O(this.toString());
146
+ }
147
+ }
148
+ function I(u) {
149
+ const t = u.split(`
150
+ `), e = t.filter((r) => /^\t+/.test(r)), i = t.filter((r) => /^ {2,}/.test(r));
151
+ if (e.length === 0 && i.length === 0)
152
+ return null;
153
+ if (e.length >= i.length)
154
+ return " ";
155
+ const n = i.reduce((r, s) => {
156
+ const h = /^ +/.exec(s)[0].length;
157
+ return Math.min(h, r);
158
+ }, 1 / 0);
159
+ return new Array(n + 1).join(" ");
160
+ }
161
+ function A(u, t) {
162
+ const e = u.split(/[/\\]/), i = t.split(/[/\\]/);
163
+ for (e.pop(); e[0] === i[0]; )
164
+ e.shift(), i.shift();
165
+ if (e.length) {
166
+ let n = e.length;
167
+ for (; n--; ) e[n] = "..";
168
+ }
169
+ return e.concat(i).join("/");
170
+ }
171
+ const T = Object.prototype.toString;
172
+ function j(u) {
173
+ return T.call(u) === "[object Object]";
174
+ }
175
+ function y(u) {
176
+ const t = u.split(`
177
+ `), e = [];
178
+ for (let i = 0, n = 0; i < t.length; i++)
179
+ e.push(n), n += t[i].length + 1;
180
+ return function(n) {
181
+ let r = 0, s = e.length;
182
+ for (; r < s; ) {
183
+ const l = r + s >> 1;
184
+ n < e[l] ? s = l : r = l + 1;
185
+ }
186
+ const h = r - 1, o = n - e[h];
187
+ return { line: h, column: o };
188
+ };
189
+ }
190
+ const $ = /\w/;
191
+ class U {
192
+ constructor(t) {
193
+ this.hires = t, this.generatedCodeLine = 0, this.generatedCodeColumn = 0, this.raw = [], this.rawSegments = this.raw[this.generatedCodeLine] = [], this.pending = null;
194
+ }
195
+ addEdit(t, e, i, n) {
196
+ if (e.length) {
197
+ const r = e.length - 1;
198
+ let s = e.indexOf(`
199
+ `, 0), h = -1;
200
+ for (; s >= 0 && r > s; ) {
201
+ const l = [this.generatedCodeColumn, t, i.line, i.column];
202
+ n >= 0 && l.push(n), this.rawSegments.push(l), this.generatedCodeLine += 1, this.raw[this.generatedCodeLine] = this.rawSegments = [], this.generatedCodeColumn = 0, h = s, s = e.indexOf(`
203
+ `, s + 1);
204
+ }
205
+ const o = [this.generatedCodeColumn, t, i.line, i.column];
206
+ n >= 0 && o.push(n), this.rawSegments.push(o), this.advance(e.slice(h + 1));
207
+ } else this.pending && (this.rawSegments.push(this.pending), this.advance(e));
208
+ this.pending = null;
209
+ }
210
+ addUneditedChunk(t, e, i, n, r) {
211
+ let s = e.start, h = !0, o = !1;
212
+ for (; s < e.end; ) {
213
+ if (i[s] === `
214
+ `)
215
+ n.line += 1, n.column = 0, this.generatedCodeLine += 1, this.raw[this.generatedCodeLine] = this.rawSegments = [], this.generatedCodeColumn = 0, h = !0, o = !1;
216
+ else {
217
+ if (this.hires || h || r.has(s)) {
218
+ const l = [this.generatedCodeColumn, t, n.line, n.column];
219
+ this.hires === "boundary" ? $.test(i[s]) ? o || (this.rawSegments.push(l), o = !0) : (this.rawSegments.push(l), o = !1) : this.rawSegments.push(l);
220
+ }
221
+ n.column += 1, this.generatedCodeColumn += 1, h = !1;
222
+ }
223
+ s += 1;
224
+ }
225
+ this.pending = null;
226
+ }
227
+ advance(t) {
228
+ if (!t) return;
229
+ const e = t.split(`
230
+ `);
231
+ if (e.length > 1) {
232
+ for (let i = 0; i < e.length - 1; i++)
233
+ this.generatedCodeLine++, this.raw[this.generatedCodeLine] = this.rawSegments = [];
234
+ this.generatedCodeColumn = 0;
235
+ }
236
+ this.generatedCodeColumn += e[e.length - 1].length;
237
+ }
238
+ }
239
+ const d = `
240
+ `, f = {
241
+ insertLeft: !1,
242
+ insertRight: !1,
243
+ storeName: !1
244
+ };
245
+ class v {
246
+ constructor(t, e = {}) {
247
+ const i = new g(0, t.length, t);
248
+ Object.defineProperties(this, {
249
+ original: { writable: !0, value: t },
250
+ outro: { writable: !0, value: "" },
251
+ intro: { writable: !0, value: "" },
252
+ firstChunk: { writable: !0, value: i },
253
+ lastChunk: { writable: !0, value: i },
254
+ lastSearchedChunk: { writable: !0, value: i },
255
+ byStart: { writable: !0, value: {} },
256
+ byEnd: { writable: !0, value: {} },
257
+ filename: { writable: !0, value: e.filename },
258
+ indentExclusionRanges: { writable: !0, value: e.indentExclusionRanges },
259
+ sourcemapLocations: { writable: !0, value: new p() },
260
+ storedNames: { writable: !0, value: {} },
261
+ indentStr: { writable: !0, value: void 0 },
262
+ ignoreList: { writable: !0, value: e.ignoreList },
263
+ offset: { writable: !0, value: e.offset || 0 }
264
+ }), this.byStart[0] = i, this.byEnd[t.length] = i;
265
+ }
266
+ addSourcemapLocation(t) {
267
+ this.sourcemapLocations.add(t);
268
+ }
269
+ append(t) {
270
+ if (typeof t != "string") throw new TypeError("outro content must be a string");
271
+ return this.outro += t, this;
272
+ }
273
+ appendLeft(t, e) {
274
+ if (t = t + this.offset, typeof e != "string") throw new TypeError("inserted content must be a string");
275
+ this._split(t);
276
+ const i = this.byEnd[t];
277
+ return i ? i.appendLeft(e) : this.intro += e, this;
278
+ }
279
+ appendRight(t, e) {
280
+ if (t = t + this.offset, typeof e != "string") throw new TypeError("inserted content must be a string");
281
+ this._split(t);
282
+ const i = this.byStart[t];
283
+ return i ? i.appendRight(e) : this.outro += e, this;
284
+ }
285
+ clone() {
286
+ const t = new v(this.original, { filename: this.filename, offset: this.offset });
287
+ let e = this.firstChunk, i = t.firstChunk = t.lastSearchedChunk = e.clone();
288
+ for (; e; ) {
289
+ t.byStart[i.start] = i, t.byEnd[i.end] = i;
290
+ const n = e.next, r = n && n.clone();
291
+ r && (i.next = r, r.previous = i, i = r), e = n;
292
+ }
293
+ return t.lastChunk = i, this.indentExclusionRanges && (t.indentExclusionRanges = this.indentExclusionRanges.slice()), t.sourcemapLocations = new p(this.sourcemapLocations), t.intro = this.intro, t.outro = this.outro, t;
294
+ }
295
+ generateDecodedMap(t) {
296
+ t = t || {};
297
+ const e = 0, i = Object.keys(this.storedNames), n = new U(t.hires), r = y(this.original);
298
+ return this.intro && n.advance(this.intro), this.firstChunk.eachNext((s) => {
299
+ const h = r(s.start);
300
+ s.intro.length && n.advance(s.intro), s.edited ? n.addEdit(
301
+ e,
302
+ s.content,
303
+ h,
304
+ s.storeName ? i.indexOf(s.original) : -1
305
+ ) : n.addUneditedChunk(e, s, this.original, h, this.sourcemapLocations), s.outro.length && n.advance(s.outro);
306
+ }), this.outro && n.advance(this.outro), {
307
+ file: t.file ? t.file.split(/[/\\]/).pop() : void 0,
308
+ sources: [
309
+ t.source ? A(t.file || "", t.source) : t.file || ""
310
+ ],
311
+ sourcesContent: t.includeContent ? [this.original] : void 0,
312
+ names: i,
313
+ mappings: n.raw,
314
+ x_google_ignoreList: this.ignoreList ? [e] : void 0
315
+ };
316
+ }
317
+ generateMap(t) {
318
+ return new N(this.generateDecodedMap(t));
319
+ }
320
+ _ensureindentStr() {
321
+ this.indentStr === void 0 && (this.indentStr = I(this.original));
322
+ }
323
+ _getRawIndentString() {
324
+ return this._ensureindentStr(), this.indentStr;
325
+ }
326
+ getIndentString() {
327
+ return this._ensureindentStr(), this.indentStr === null ? " " : this.indentStr;
328
+ }
329
+ indent(t, e) {
330
+ const i = /^[^\r\n]/gm;
331
+ if (j(t) && (e = t, t = void 0), t === void 0 && (this._ensureindentStr(), t = this.indentStr || " "), t === "") return this;
332
+ e = e || {};
333
+ const n = {};
334
+ e.exclude && (typeof e.exclude[0] == "number" ? [e.exclude] : e.exclude).forEach((a) => {
335
+ for (let w = a[0]; w < a[1]; w += 1)
336
+ n[w] = !0;
337
+ });
338
+ let r = e.indentStart !== !1;
339
+ const s = (l) => r ? `${t}${l}` : (r = !0, l);
340
+ this.intro = this.intro.replace(i, s);
341
+ let h = 0, o = this.firstChunk;
342
+ for (; o; ) {
343
+ const l = o.end;
344
+ if (o.edited)
345
+ n[h] || (o.content = o.content.replace(i, s), o.content.length && (r = o.content[o.content.length - 1] === `
346
+ `));
347
+ else
348
+ for (h = o.start; h < l; ) {
349
+ if (!n[h]) {
350
+ const a = this.original[h];
351
+ a === `
352
+ ` ? r = !0 : a !== "\r" && r && (r = !1, h === o.start || (this._splitChunk(o, h), o = o.next), o.prependRight(t));
353
+ }
354
+ h += 1;
355
+ }
356
+ h = o.end, o = o.next;
357
+ }
358
+ return this.outro = this.outro.replace(i, s), this;
359
+ }
360
+ insert() {
361
+ throw new Error(
362
+ "magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)"
363
+ );
364
+ }
365
+ insertLeft(t, e) {
366
+ return f.insertLeft || (console.warn(
367
+ "magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead"
368
+ ), f.insertLeft = !0), this.appendLeft(t, e);
369
+ }
370
+ insertRight(t, e) {
371
+ return f.insertRight || (console.warn(
372
+ "magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead"
373
+ ), f.insertRight = !0), this.prependRight(t, e);
374
+ }
375
+ move(t, e, i) {
376
+ if (t = t + this.offset, e = e + this.offset, i = i + this.offset, i >= t && i <= e) throw new Error("Cannot move a selection inside itself");
377
+ this._split(t), this._split(e), this._split(i);
378
+ const n = this.byStart[t], r = this.byEnd[e], s = n.previous, h = r.next, o = this.byStart[i];
379
+ if (!o && r === this.lastChunk) return this;
380
+ const l = o ? o.previous : this.lastChunk;
381
+ return s && (s.next = h), h && (h.previous = s), l && (l.next = n), o && (o.previous = r), n.previous || (this.firstChunk = r.next), r.next || (this.lastChunk = n.previous, this.lastChunk.next = null), n.previous = l, r.next = o || null, l || (this.firstChunk = n), o || (this.lastChunk = r), this;
382
+ }
383
+ overwrite(t, e, i, n) {
384
+ return n = n || {}, this.update(t, e, i, { ...n, overwrite: !n.contentOnly });
385
+ }
386
+ update(t, e, i, n) {
387
+ if (t = t + this.offset, e = e + this.offset, typeof i != "string") throw new TypeError("replacement content must be a string");
388
+ if (this.original.length !== 0) {
389
+ for (; t < 0; ) t += this.original.length;
390
+ for (; e < 0; ) e += this.original.length;
391
+ }
392
+ if (e > this.original.length) throw new Error("end is out of bounds");
393
+ if (t === e)
394
+ throw new Error(
395
+ "Cannot overwrite a zero-length range – use appendLeft or prependRight instead"
396
+ );
397
+ this._split(t), this._split(e), n === !0 && (f.storeName || (console.warn(
398
+ "The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string"
399
+ ), f.storeName = !0), n = { storeName: !0 });
400
+ const r = n !== void 0 ? n.storeName : !1, s = n !== void 0 ? n.overwrite : !1;
401
+ if (r) {
402
+ const l = this.original.slice(t, e);
403
+ Object.defineProperty(this.storedNames, l, {
404
+ writable: !0,
405
+ value: !0,
406
+ enumerable: !0
407
+ });
408
+ }
409
+ const h = this.byStart[t], o = this.byEnd[e];
410
+ if (h) {
411
+ let l = h;
412
+ for (; l !== o; ) {
413
+ if (l.next !== this.byStart[l.end])
414
+ throw new Error("Cannot overwrite across a split point");
415
+ l = l.next, l.edit("", !1);
416
+ }
417
+ h.edit(i, r, !s);
418
+ } else {
419
+ const l = new g(t, e, "").edit(i, r);
420
+ o.next = l, l.previous = o;
421
+ }
422
+ return this;
423
+ }
424
+ prepend(t) {
425
+ if (typeof t != "string") throw new TypeError("outro content must be a string");
426
+ return this.intro = t + this.intro, this;
427
+ }
428
+ prependLeft(t, e) {
429
+ if (t = t + this.offset, typeof e != "string") throw new TypeError("inserted content must be a string");
430
+ this._split(t);
431
+ const i = this.byEnd[t];
432
+ return i ? i.prependLeft(e) : this.intro = e + this.intro, this;
433
+ }
434
+ prependRight(t, e) {
435
+ if (t = t + this.offset, typeof e != "string") throw new TypeError("inserted content must be a string");
436
+ this._split(t);
437
+ const i = this.byStart[t];
438
+ return i ? i.prependRight(e) : this.outro = e + this.outro, this;
439
+ }
440
+ remove(t, e) {
441
+ if (t = t + this.offset, e = e + this.offset, this.original.length !== 0) {
442
+ for (; t < 0; ) t += this.original.length;
443
+ for (; e < 0; ) e += this.original.length;
444
+ }
445
+ if (t === e) return this;
446
+ if (t < 0 || e > this.original.length) throw new Error("Character is out of bounds");
447
+ if (t > e) throw new Error("end must be greater than start");
448
+ this._split(t), this._split(e);
449
+ let i = this.byStart[t];
450
+ for (; i; )
451
+ i.intro = "", i.outro = "", i.edit(""), i = e > i.end ? this.byStart[i.end] : null;
452
+ return this;
453
+ }
454
+ reset(t, e) {
455
+ if (t = t + this.offset, e = e + this.offset, this.original.length !== 0) {
456
+ for (; t < 0; ) t += this.original.length;
457
+ for (; e < 0; ) e += this.original.length;
458
+ }
459
+ if (t === e) return this;
460
+ if (t < 0 || e > this.original.length) throw new Error("Character is out of bounds");
461
+ if (t > e) throw new Error("end must be greater than start");
462
+ this._split(t), this._split(e);
463
+ let i = this.byStart[t];
464
+ for (; i; )
465
+ i.reset(), i = e > i.end ? this.byStart[i.end] : null;
466
+ return this;
467
+ }
468
+ lastChar() {
469
+ if (this.outro.length) return this.outro[this.outro.length - 1];
470
+ let t = this.lastChunk;
471
+ do {
472
+ if (t.outro.length) return t.outro[t.outro.length - 1];
473
+ if (t.content.length) return t.content[t.content.length - 1];
474
+ if (t.intro.length) return t.intro[t.intro.length - 1];
475
+ } while (t = t.previous);
476
+ return this.intro.length ? this.intro[this.intro.length - 1] : "";
477
+ }
478
+ lastLine() {
479
+ let t = this.outro.lastIndexOf(d);
480
+ if (t !== -1) return this.outro.substr(t + 1);
481
+ let e = this.outro, i = this.lastChunk;
482
+ do {
483
+ if (i.outro.length > 0) {
484
+ if (t = i.outro.lastIndexOf(d), t !== -1) return i.outro.substr(t + 1) + e;
485
+ e = i.outro + e;
486
+ }
487
+ if (i.content.length > 0) {
488
+ if (t = i.content.lastIndexOf(d), t !== -1) return i.content.substr(t + 1) + e;
489
+ e = i.content + e;
490
+ }
491
+ if (i.intro.length > 0) {
492
+ if (t = i.intro.lastIndexOf(d), t !== -1) return i.intro.substr(t + 1) + e;
493
+ e = i.intro + e;
494
+ }
495
+ } while (i = i.previous);
496
+ return t = this.intro.lastIndexOf(d), t !== -1 ? this.intro.substr(t + 1) + e : this.intro + e;
497
+ }
498
+ slice(t = 0, e = this.original.length - this.offset) {
499
+ if (t = t + this.offset, e = e + this.offset, this.original.length !== 0) {
500
+ for (; t < 0; ) t += this.original.length;
501
+ for (; e < 0; ) e += this.original.length;
502
+ }
503
+ let i = "", n = this.firstChunk;
504
+ for (; n && (n.start > t || n.end <= t); ) {
505
+ if (n.start < e && n.end >= e)
506
+ return i;
507
+ n = n.next;
508
+ }
509
+ if (n && n.edited && n.start !== t)
510
+ throw new Error(`Cannot use replaced character ${t} as slice start anchor.`);
511
+ const r = n;
512
+ for (; n; ) {
513
+ n.intro && (r !== n || n.start === t) && (i += n.intro);
514
+ const s = n.start < e && n.end >= e;
515
+ if (s && n.edited && n.end !== e)
516
+ throw new Error(`Cannot use replaced character ${e} as slice end anchor.`);
517
+ const h = r === n ? t - n.start : 0, o = s ? n.content.length + e - n.end : n.content.length;
518
+ if (i += n.content.slice(h, o), n.outro && (!s || n.end === e) && (i += n.outro), s)
519
+ break;
520
+ n = n.next;
521
+ }
522
+ return i;
523
+ }
524
+ // TODO deprecate this? not really very useful
525
+ snip(t, e) {
526
+ const i = this.clone();
527
+ return i.remove(0, t), i.remove(e, i.original.length), i;
528
+ }
529
+ _split(t) {
530
+ if (this.byStart[t] || this.byEnd[t]) return;
531
+ let e = this.lastSearchedChunk, i = e;
532
+ const n = t > e.end;
533
+ for (; e; ) {
534
+ if (e.contains(t)) return this._splitChunk(e, t);
535
+ if (e = n ? this.byStart[e.end] : this.byEnd[e.start], e === i) return;
536
+ i = e;
537
+ }
538
+ }
539
+ _splitChunk(t, e) {
540
+ if (t.edited && t.content.length) {
541
+ const n = y(this.original)(e);
542
+ throw new Error(
543
+ `Cannot split a chunk that has already been edited (${n.line}:${n.column} – "${t.original}")`
544
+ );
545
+ }
546
+ const i = t.split(e);
547
+ return this.byEnd[e] = t, this.byStart[e] = i, this.byEnd[i.end] = i, t === this.lastChunk && (this.lastChunk = i), this.lastSearchedChunk = t, !0;
548
+ }
549
+ toString() {
550
+ let t = this.intro, e = this.firstChunk;
551
+ for (; e; )
552
+ t += e.toString(), e = e.next;
553
+ return t + this.outro;
554
+ }
555
+ isEmpty() {
556
+ let t = this.firstChunk;
557
+ do
558
+ if (t.intro.length && t.intro.trim() || t.content.length && t.content.trim() || t.outro.length && t.outro.trim())
559
+ return !1;
560
+ while (t = t.next);
561
+ return !0;
562
+ }
563
+ length() {
564
+ let t = this.firstChunk, e = 0;
565
+ do
566
+ e += t.intro.length + t.content.length + t.outro.length;
567
+ while (t = t.next);
568
+ return e;
569
+ }
570
+ trimLines() {
571
+ return this.trim("[\\r\\n]");
572
+ }
573
+ trim(t) {
574
+ return this.trimStart(t).trimEnd(t);
575
+ }
576
+ trimEndAborted(t) {
577
+ const e = new RegExp((t || "\\s") + "+$");
578
+ if (this.outro = this.outro.replace(e, ""), this.outro.length) return !0;
579
+ let i = this.lastChunk;
580
+ do {
581
+ const n = i.end, r = i.trimEnd(e);
582
+ if (i.end !== n && (this.lastChunk === i && (this.lastChunk = i.next), this.byEnd[i.end] = i, this.byStart[i.next.start] = i.next, this.byEnd[i.next.end] = i.next), r) return !0;
583
+ i = i.previous;
584
+ } while (i);
585
+ return !1;
586
+ }
587
+ trimEnd(t) {
588
+ return this.trimEndAborted(t), this;
589
+ }
590
+ trimStartAborted(t) {
591
+ const e = new RegExp("^" + (t || "\\s") + "+");
592
+ if (this.intro = this.intro.replace(e, ""), this.intro.length) return !0;
593
+ let i = this.firstChunk;
594
+ do {
595
+ const n = i.end, r = i.trimStart(e);
596
+ if (i.end !== n && (i === this.lastChunk && (this.lastChunk = i.next), this.byEnd[i.end] = i, this.byStart[i.next.start] = i.next, this.byEnd[i.next.end] = i.next), r) return !0;
597
+ i = i.next;
598
+ } while (i);
599
+ return !1;
600
+ }
601
+ trimStart(t) {
602
+ return this.trimStartAborted(t), this;
603
+ }
604
+ hasChanged() {
605
+ return this.original !== this.toString();
606
+ }
607
+ _replaceRegexp(t, e) {
608
+ function i(r, s) {
609
+ return typeof e == "string" ? e.replace(/\$(\$|&|\d+)/g, (h, o) => o === "$" ? "$" : o === "&" ? r[0] : +o < r.length ? r[+o] : `$${o}`) : e(...r, r.index, s, r.groups);
610
+ }
611
+ function n(r, s) {
612
+ let h;
613
+ const o = [];
614
+ for (; h = r.exec(s); )
615
+ o.push(h);
616
+ return o;
617
+ }
618
+ if (t.global)
619
+ n(t, this.original).forEach((s) => {
620
+ if (s.index != null) {
621
+ const h = i(s, this.original);
622
+ h !== s[0] && this.overwrite(s.index, s.index + s[0].length, h);
623
+ }
624
+ });
625
+ else {
626
+ const r = this.original.match(t);
627
+ if (r && r.index != null) {
628
+ const s = i(r, this.original);
629
+ s !== r[0] && this.overwrite(r.index, r.index + r[0].length, s);
630
+ }
631
+ }
632
+ return this;
633
+ }
634
+ _replaceString(t, e) {
635
+ const { original: i } = this, n = i.indexOf(t);
636
+ return n !== -1 && (typeof e == "function" && (e = e(t, n, i)), t !== e && this.overwrite(n, n + t.length, e)), this;
637
+ }
638
+ replace(t, e) {
639
+ return typeof t == "string" ? this._replaceString(t, e) : this._replaceRegexp(t, e);
640
+ }
641
+ _replaceAllString(t, e) {
642
+ const { original: i } = this, n = t.length;
643
+ for (let r = i.indexOf(t); r !== -1; r = i.indexOf(t, r + n)) {
644
+ const s = i.slice(r, r + n);
645
+ let h = e;
646
+ typeof e == "function" && (h = e(s, r, i)), s !== h && this.overwrite(r, r + n, h);
647
+ }
648
+ return this;
649
+ }
650
+ replaceAll(t, e) {
651
+ if (typeof t == "string")
652
+ return this._replaceAllString(t, e);
653
+ if (!t.global)
654
+ throw new TypeError(
655
+ "MagicString.prototype.replaceAll called with a non-global RegExp argument"
656
+ );
657
+ return this._replaceRegexp(t, e);
658
+ }
659
+ }
660
+ export {
661
+ N as SourceMap,
662
+ v as default
663
+ };
664
+ //# sourceMappingURL=magic-string.es-uPKorP4O.js.map