gemi 0.52.0 → 0.54.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.
- package/dist/app/index.js +2 -2
- package/dist/app/index.js.map +1 -1
- package/dist/bin/gemi.js +1456 -5
- package/dist/bin/gemi.js.map +9 -5
- package/dist/broadcasting/index.js +1 -1
- package/dist/bun/plugin.js +2 -2
- package/dist/bun/plugin.js.map +1 -1
- package/dist/bun/preload.js +2 -2
- package/dist/bun/preload.js.map +1 -1
- package/dist/{chunk-msz8rngs.js → chunk-004bcmsa.js} +2 -2
- package/dist/chunk-004bcmsa.js.map +10 -0
- package/dist/chunk-07t0dmdg.js +4 -0
- package/dist/{chunk-faa987e4.js.map → chunk-07t0dmdg.js.map} +2 -2
- package/dist/{chunk-4t6a82fh.js → chunk-0weeq0ke.js} +2 -2
- package/dist/{chunk-4t6a82fh.js.map → chunk-0weeq0ke.js.map} +1 -1
- package/dist/chunk-113khwbw.js +5 -0
- package/dist/{chunk-2qn472j4.js.map → chunk-113khwbw.js.map} +1 -1
- package/dist/{chunk-tmk4zfz9.js → chunk-1sh6kqjn.js} +3 -3
- package/dist/{chunk-tmk4zfz9.js.map → chunk-1sh6kqjn.js.map} +1 -1
- package/dist/{chunk-2gw6cyyj.js → chunk-1snh7yc4.js} +2 -2
- package/dist/{chunk-2gw6cyyj.js.map → chunk-1snh7yc4.js.map} +1 -1
- package/dist/chunk-26r8dcxd.js +6 -0
- package/dist/{chunk-hbycemy5.js.map → chunk-26r8dcxd.js.map} +2 -2
- package/dist/{chunk-ebcgdv00.js → chunk-2pt6kyn9.js} +3 -3
- package/dist/{chunk-ebcgdv00.js.map → chunk-2pt6kyn9.js.map} +1 -1
- package/dist/{chunk-jdfe4dmh.js → chunk-2zmz3pjk.js} +3 -3
- package/dist/{chunk-jdfe4dmh.js.map → chunk-2zmz3pjk.js.map} +1 -1
- package/dist/{chunk-zhsaz9cr.js → chunk-3bw1jk21.js} +1 -1
- package/dist/chunk-4qkzdyj7.js +4 -0
- package/dist/{chunk-4e61qbp4.js.map → chunk-4qkzdyj7.js.map} +1 -1
- package/dist/{chunk-d1ahbza9.js → chunk-50vm7x98.js} +3 -3
- package/dist/{chunk-d1ahbza9.js.map → chunk-50vm7x98.js.map} +1 -1
- package/dist/{chunk-qyaqg07q.js → chunk-6j1z2cqt.js} +2 -2
- package/dist/{chunk-qyaqg07q.js.map → chunk-6j1z2cqt.js.map} +1 -1
- package/dist/chunk-6rhebm18.js +5 -0
- package/dist/chunk-6rhebm18.js.map +10 -0
- package/dist/{chunk-rq770c71.js → chunk-71m47kad.js} +2 -2
- package/dist/{chunk-rq770c71.js.map → chunk-71m47kad.js.map} +1 -1
- package/dist/{chunk-0h3jr9d9.js → chunk-7f5ad759.js} +2 -2
- package/dist/{chunk-8p6rqegw.js.map → chunk-7f5ad759.js.map} +1 -1
- package/dist/{chunk-qj4mmner.js → chunk-85av4ncy.js} +2 -2
- package/dist/{chunk-qj4mmner.js.map → chunk-85av4ncy.js.map} +1 -1
- package/dist/{chunk-23g7qdpg.js → chunk-9taz1h3t.js} +3 -3
- package/dist/{chunk-23g7qdpg.js.map → chunk-9taz1h3t.js.map} +1 -1
- package/dist/{chunk-ppt296ye.js → chunk-agabw2w1.js} +2 -2
- package/dist/{chunk-ppt296ye.js.map → chunk-agabw2w1.js.map} +1 -1
- package/dist/{chunk-092pj2j2.js → chunk-bb3zvxsf.js} +3 -3
- package/dist/{chunk-092pj2j2.js.map → chunk-bb3zvxsf.js.map} +1 -1
- package/dist/{chunk-h7jv3ame.js → chunk-br8ten26.js} +2 -2
- package/dist/{chunk-h7jv3ame.js.map → chunk-br8ten26.js.map} +1 -1
- package/dist/{chunk-4e61qbp4.js → chunk-bzhtymvv.js} +2 -2
- package/dist/{chunk-0h3jr9d9.js.map → chunk-bzhtymvv.js.map} +1 -1
- package/dist/{chunk-68w225rv.js → chunk-c0wcsmpj.js} +2 -2
- package/dist/{chunk-68w225rv.js.map → chunk-c0wcsmpj.js.map} +1 -1
- package/dist/{chunk-xsmt86n3.js → chunk-c22vcxty.js} +2 -2
- package/dist/{chunk-xsmt86n3.js.map → chunk-c22vcxty.js.map} +1 -1
- package/dist/{chunk-a0sy9f9x.js → chunk-c2pv3ah8.js} +2 -2
- package/dist/{chunk-a0sy9f9x.js.map → chunk-c2pv3ah8.js.map} +2 -2
- package/dist/{chunk-q09mmr05.js → chunk-cz3szqhq.js} +2 -2
- package/dist/{chunk-q09mmr05.js.map → chunk-cz3szqhq.js.map} +1 -1
- package/dist/{chunk-69w4egkg.js → chunk-dwx2y7br.js} +4 -4
- package/dist/{chunk-69w4egkg.js.map → chunk-dwx2y7br.js.map} +1 -1
- package/dist/{chunk-2sfz64xh.js → chunk-dxw8k6f1.js} +2 -2
- package/dist/{chunk-2sfz64xh.js.map → chunk-dxw8k6f1.js.map} +1 -1
- package/dist/chunk-e3mggavt.js +5 -0
- package/dist/chunk-e3mggavt.js.map +11 -0
- package/dist/{chunk-j1knf8gv.js → chunk-efsk1wy0.js} +3 -3
- package/dist/{chunk-j1knf8gv.js.map → chunk-efsk1wy0.js.map} +1 -1
- package/dist/{chunk-t4n25km9.js → chunk-f13f68c0.js} +2 -2
- package/dist/{chunk-t4n25km9.js.map → chunk-f13f68c0.js.map} +1 -1
- package/dist/{chunk-vv72kw74.js → chunk-f418jh9k.js} +2 -2
- package/dist/{chunk-vv72kw74.js.map → chunk-f418jh9k.js.map} +1 -1
- package/dist/chunk-f4e7fh95.js +17 -0
- package/dist/chunk-f4e7fh95.js.map +14 -0
- package/dist/{chunk-ewgv1j8q.js → chunk-fcqc3e3r.js} +2 -2
- package/dist/{chunk-ewgv1j8q.js.map → chunk-fcqc3e3r.js.map} +1 -1
- package/dist/{chunk-3y9nf09k.js → chunk-g5tj10p8.js} +2 -2
- package/dist/{chunk-3y9nf09k.js.map → chunk-g5tj10p8.js.map} +1 -1
- package/dist/chunk-gn9zjgep.js +5 -0
- package/dist/chunk-gn9zjgep.js.map +10 -0
- package/dist/{chunk-5s45prj5.js → chunk-h7mcwfg5.js} +4 -4
- package/dist/{chunk-5s45prj5.js.map → chunk-h7mcwfg5.js.map} +1 -1
- package/dist/chunk-hk067634.js +4 -0
- package/dist/{chunk-vnjvd82s.js.map → chunk-hk067634.js.map} +2 -2
- package/dist/{chunk-qx6sahe0.js → chunk-hrrmxreg.js} +2 -2
- package/dist/{chunk-qx6sahe0.js.map → chunk-hrrmxreg.js.map} +1 -1
- package/dist/{chunk-p22rkf1g.js → chunk-jb022m7n.js} +2 -2
- package/dist/{chunk-p22rkf1g.js.map → chunk-jb022m7n.js.map} +1 -1
- package/dist/chunk-jb2nst6v.js +4 -0
- package/dist/{chunk-6scjrbw7.js.map → chunk-jb2nst6v.js.map} +2 -2
- package/dist/{chunk-kxzwem3g.js → chunk-jdgvdddd.js} +2 -2
- package/dist/{chunk-kxzwem3g.js.map → chunk-jdgvdddd.js.map} +1 -1
- package/dist/{chunk-2yth3kk2.js → chunk-jp4pf3yt.js} +4 -4
- package/dist/{chunk-2yth3kk2.js.map → chunk-jp4pf3yt.js.map} +1 -1
- package/dist/{chunk-0tbwn6er.js → chunk-k14dmqwh.js} +3 -3
- package/dist/{chunk-0tbwn6er.js.map → chunk-k14dmqwh.js.map} +1 -1
- package/dist/{chunk-1ce7veh9.js → chunk-k8endm5j.js} +3 -3
- package/dist/{chunk-1ce7veh9.js.map → chunk-k8endm5j.js.map} +1 -1
- package/dist/chunk-kkkqyvwv.js +81 -0
- package/dist/{chunk-km6x37ws.js.map → chunk-kkkqyvwv.js.map} +5 -5
- package/dist/{chunk-cmq5t8p9.js → chunk-kv2ep453.js} +3 -3
- package/dist/{chunk-cmq5t8p9.js.map → chunk-kv2ep453.js.map} +1 -1
- package/dist/{chunk-z4q1ty6w.js → chunk-kz39hphm.js} +3 -3
- package/dist/{chunk-z4q1ty6w.js.map → chunk-kz39hphm.js.map} +1 -1
- package/dist/{chunk-kaxvw75w.js → chunk-ms8qd7da.js} +3 -3
- package/dist/{chunk-kaxvw75w.js.map → chunk-ms8qd7da.js.map} +1 -1
- package/dist/{chunk-ttzkn1qd.js → chunk-n1tkn8gv.js} +2 -2
- package/dist/{chunk-ttzkn1qd.js.map → chunk-n1tkn8gv.js.map} +1 -1
- package/dist/chunk-nncwsdzz.js +5 -0
- package/dist/chunk-nncwsdzz.js.map +10 -0
- package/dist/{chunk-et0j6jx8.js → chunk-pgjk5ft3.js} +3 -3
- package/dist/{chunk-et0j6jx8.js.map → chunk-pgjk5ft3.js.map} +1 -1
- package/dist/{chunk-tztqkat2.js → chunk-r06rxn19.js} +2 -2
- package/dist/{chunk-tztqkat2.js.map → chunk-r06rxn19.js.map} +1 -1
- package/dist/chunk-r9z5rrk0.js +4 -0
- package/dist/{chunk-1ab1ptq5.js.map → chunk-r9z5rrk0.js.map} +2 -2
- package/dist/{chunk-h5g05qwb.js → chunk-s6e7cvek.js} +2 -2
- package/dist/{chunk-h5g05qwb.js.map → chunk-s6e7cvek.js.map} +1 -1
- package/dist/{chunk-53e48ce8.js → chunk-sqp7kn7h.js} +3 -3
- package/dist/{chunk-53e48ce8.js.map → chunk-sqp7kn7h.js.map} +1 -1
- package/dist/{chunk-mt2755rs.js → chunk-w6gb9gc5.js} +3 -3
- package/dist/{chunk-mt2755rs.js.map → chunk-w6gb9gc5.js.map} +1 -1
- package/dist/{chunk-ha7n1c94.js → chunk-xxw0gz4q.js} +2 -2
- package/dist/{chunk-ha7n1c94.js.map → chunk-xxw0gz4q.js.map} +1 -1
- package/dist/chunk-ywr2vd5r.js +5 -0
- package/dist/{chunk-f29vd5mc.js.map → chunk-ywr2vd5r.js.map} +2 -2
- package/dist/{chunk-38ma6gg3.js → chunk-zckj6bs6.js} +3 -3
- package/dist/{chunk-38ma6gg3.js.map → chunk-zckj6bs6.js.map} +1 -1
- package/dist/chunks/ThemeProvider-Bk1eZymb.js +2901 -0
- package/dist/chunks/ThemeProvider-Bk1eZymb.js.map +1 -0
- package/dist/client/ComponentContext.d.ts.map +1 -1
- package/dist/client/DictionarySinkContext.d.ts +10 -0
- package/dist/client/DictionarySinkContext.d.ts.map +1 -0
- package/dist/client/Mutation.d.ts +1 -1
- package/dist/client/Mutation.d.ts.map +1 -1
- package/dist/client/ThemeProvider.d.ts +7 -0
- package/dist/client/ThemeProvider.d.ts.map +1 -1
- package/dist/client/createRoot.d.ts.map +1 -1
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +242 -2629
- package/dist/client/index.js.map +1 -1
- package/dist/client/useDictionary.d.ts +34 -0
- package/dist/client/useDictionary.d.ts.map +1 -0
- package/dist/client/useDictionary.test-d.d.ts +2 -0
- package/dist/client/useDictionary.test-d.d.ts.map +1 -0
- package/dist/client/useIsNavigationPending.d.ts.map +1 -1
- package/dist/client/useMutate.d.ts.map +1 -1
- package/dist/client/useTranslator.d.ts +8 -0
- package/dist/client/useTranslator.d.ts.map +1 -1
- package/dist/config/index.js +1 -1
- package/dist/console/run.js +2 -2
- package/dist/console/run.js.map +1 -1
- package/dist/container/index.js +2 -2
- package/dist/container/index.js.map +1 -1
- package/dist/database/index.js +2 -2
- package/dist/database/index.js.map +1 -1
- package/dist/email/index.js +2 -2
- package/dist/email/index.js.map +1 -1
- package/dist/facades/Lang.d.ts.map +1 -1
- package/dist/facades/index.js +2 -2
- package/dist/facades/index.js.map +1 -1
- package/dist/foundation/index.js +2 -2
- package/dist/foundation/index.js.map +1 -1
- package/dist/http/index.js +2 -2
- package/dist/http/index.js.map +1 -1
- package/dist/i18n/Dictionary.d.ts +7 -0
- package/dist/i18n/Dictionary.d.ts.map +1 -1
- package/dist/i18n/Translator.d.ts +12 -0
- package/dist/i18n/Translator.d.ts.map +1 -1
- package/dist/i18n/config.d.ts +6 -0
- package/dist/i18n/config.d.ts.map +1 -1
- package/dist/i18n/defineDictionary.d.ts +65 -0
- package/dist/i18n/defineDictionary.d.ts.map +1 -0
- package/dist/i18n/dictionaryRegistry.d.ts +85 -0
- package/dist/i18n/dictionaryRegistry.d.ts.map +1 -0
- package/dist/i18n/dictionaryRuntime.d.ts +16 -0
- package/dist/i18n/dictionaryRuntime.d.ts.map +1 -0
- package/dist/i18n/dictionaryRuntime.js +4 -0
- package/dist/i18n/dictionaryRuntime.js.map +9 -0
- package/dist/i18n/dictionaryShape.d.ts +66 -0
- package/dist/i18n/dictionaryShape.d.ts.map +1 -0
- package/dist/i18n/dictionarySink.d.ts +31 -0
- package/dist/i18n/dictionarySink.d.ts.map +1 -0
- package/dist/i18n/index.d.ts +3 -0
- package/dist/i18n/index.d.ts.map +1 -1
- package/dist/i18n/index.js +2 -2
- package/dist/i18n/index.js.map +5 -4
- package/dist/i18n/translate.d.ts +21 -0
- package/dist/i18n/translate.d.ts.map +1 -0
- package/dist/internal/gemiExternals.d.ts +1 -1
- package/dist/internal/gemiExternals.d.ts.map +1 -1
- package/dist/kernel/index.js +2 -2
- package/dist/kernel/index.js.map +2 -2
- package/dist/orm/index.js +2 -2
- package/dist/orm/index.js.map +2 -2
- package/dist/server/index.js +2 -2
- package/dist/server/index.js.map +1 -1
- package/dist/services/index.js +4 -4
- package/dist/services/index.js.map +2 -2
- package/dist/services/router/ViewRouteDispatcher.d.ts.map +1 -1
- package/dist/services/router/streamQueryInjection.d.ts +9 -1
- package/dist/services/router/streamQueryInjection.d.ts.map +1 -1
- package/dist/support/index.js +2 -2
- package/dist/support/index.js.map +1 -1
- package/dist/testing/Page.d.ts +166 -0
- package/dist/testing/Page.d.ts.map +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +352 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/utils/Subject.d.ts.map +1 -1
- package/dist/utils/variantKey.d.ts +19 -0
- package/dist/utils/variantKey.d.ts.map +1 -0
- package/dist/vite/__vite-browser-external-S5EYS4bz.mjs +7 -0
- package/dist/vite/api_vite-DSBC5Nzy.mjs +5 -0
- package/dist/vite/browser-DFEUWTkA.mjs +6086 -0
- package/dist/vite/build-C0lmnz6d.mjs +5326 -0
- package/dist/vite/index.mjs +1349 -1
- package/dist/vite/lib-TT6NqN6b.mjs +363 -0
- package/dist/vite/lib-U4DF62jt.mjs +48846 -0
- package/dist/vite/main-Drp2rSLR.mjs +2123 -0
- package/dist/vite/node-BgyIm-M7.mjs +17799 -0
- package/dist/vite/node-yGkKTK1d.mjs +789 -0
- package/dist/vite/postcss-hCXrlC4m.mjs +3515 -0
- package/dist/vite/postcss-import-rYEe0OKc.mjs +448 -0
- package/dist/vite/prompt--dNycKSZ-BmZ8jzP_.mjs +889 -0
- package/dist/vite/rolldown-runtime-B4lejLz5.mjs +37 -0
- package/package.json +4 -1
- package/dist/chunk-1ab1ptq5.js +0 -4
- package/dist/chunk-2qn472j4.js +0 -5
- package/dist/chunk-6scjrbw7.js +0 -4
- package/dist/chunk-88pq4gmf.js +0 -5
- package/dist/chunk-88pq4gmf.js.map +0 -10
- package/dist/chunk-8p6rqegw.js +0 -4
- package/dist/chunk-f29vd5mc.js +0 -5
- package/dist/chunk-faa987e4.js +0 -4
- package/dist/chunk-hbycemy5.js +0 -6
- package/dist/chunk-km6x37ws.js +0 -81
- package/dist/chunk-msz8rngs.js.map +0 -10
- package/dist/chunk-vnjvd82s.js +0 -4
- package/dist/chunk-xw44bwnh.js +0 -5
- package/dist/chunk-xw44bwnh.js.map +0 -11
- /package/dist/{chunk-zhsaz9cr.js.map → chunk-3bw1jk21.js.map} +0 -0
package/dist/vite/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { r as parseAstAsync$1 } from "./node-BgyIm-M7.mjs";
|
|
1
2
|
import { existsSync } from "node:fs";
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
//#region config/load.ts
|
|
@@ -22,6 +23,1352 @@ function isGemiExternal(id) {
|
|
|
22
23
|
return id === "gemi" || id.startsWith("gemi/");
|
|
23
24
|
}
|
|
24
25
|
//#endregion
|
|
26
|
+
//#region ../../node_modules/.bun/@jridgewell+sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
27
|
+
var comma = ",".charCodeAt(0);
|
|
28
|
+
var semicolon = ";".charCodeAt(0);
|
|
29
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
30
|
+
var intToChar = /* @__PURE__ */ new Uint8Array(64);
|
|
31
|
+
var charToInt = /* @__PURE__ */ new Uint8Array(128);
|
|
32
|
+
for (let i = 0; i < chars.length; i++) {
|
|
33
|
+
const c = chars.charCodeAt(i);
|
|
34
|
+
intToChar[i] = c;
|
|
35
|
+
charToInt[c] = i;
|
|
36
|
+
}
|
|
37
|
+
function encodeInteger(builder, num, relative) {
|
|
38
|
+
let delta = num - relative;
|
|
39
|
+
delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
|
|
40
|
+
do {
|
|
41
|
+
let clamped = delta & 31;
|
|
42
|
+
delta >>>= 5;
|
|
43
|
+
if (delta > 0) clamped |= 32;
|
|
44
|
+
builder.write(intToChar[clamped]);
|
|
45
|
+
} while (delta > 0);
|
|
46
|
+
return num;
|
|
47
|
+
}
|
|
48
|
+
var bufLength = 1024 * 16;
|
|
49
|
+
var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
|
|
50
|
+
return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
|
|
51
|
+
} } : { decode(buf) {
|
|
52
|
+
let out = "";
|
|
53
|
+
for (let i = 0; i < buf.length; i++) out += String.fromCharCode(buf[i]);
|
|
54
|
+
return out;
|
|
55
|
+
} };
|
|
56
|
+
var StringWriter = class {
|
|
57
|
+
constructor() {
|
|
58
|
+
this.pos = 0;
|
|
59
|
+
this.out = "";
|
|
60
|
+
this.buffer = new Uint8Array(bufLength);
|
|
61
|
+
}
|
|
62
|
+
write(v) {
|
|
63
|
+
const { buffer } = this;
|
|
64
|
+
buffer[this.pos++] = v;
|
|
65
|
+
if (this.pos === bufLength) {
|
|
66
|
+
this.out += td.decode(buffer);
|
|
67
|
+
this.pos = 0;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
flush() {
|
|
71
|
+
const { buffer, out, pos } = this;
|
|
72
|
+
return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function encode(decoded) {
|
|
76
|
+
const writer = new StringWriter();
|
|
77
|
+
let sourcesIndex = 0;
|
|
78
|
+
let sourceLine = 0;
|
|
79
|
+
let sourceColumn = 0;
|
|
80
|
+
let namesIndex = 0;
|
|
81
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
82
|
+
const line = decoded[i];
|
|
83
|
+
if (i > 0) writer.write(semicolon);
|
|
84
|
+
if (line.length === 0) continue;
|
|
85
|
+
let genColumn = 0;
|
|
86
|
+
for (let j = 0; j < line.length; j++) {
|
|
87
|
+
const segment = line[j];
|
|
88
|
+
if (j > 0) writer.write(comma);
|
|
89
|
+
genColumn = encodeInteger(writer, segment[0], genColumn);
|
|
90
|
+
if (segment.length === 1) continue;
|
|
91
|
+
sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
|
|
92
|
+
sourceLine = encodeInteger(writer, segment[2], sourceLine);
|
|
93
|
+
sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
|
|
94
|
+
if (segment.length === 4) continue;
|
|
95
|
+
namesIndex = encodeInteger(writer, segment[4], namesIndex);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return writer.flush();
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region ../../node_modules/.bun/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs
|
|
102
|
+
var BitSet = class BitSet {
|
|
103
|
+
constructor(arg) {
|
|
104
|
+
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
105
|
+
}
|
|
106
|
+
add(n) {
|
|
107
|
+
this.bits[n >> 5] |= 1 << (n & 31);
|
|
108
|
+
}
|
|
109
|
+
has(n) {
|
|
110
|
+
return !!(this.bits[n >> 5] & 1 << (n & 31));
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
var Chunk = class Chunk {
|
|
114
|
+
constructor(start, end, content) {
|
|
115
|
+
this.start = start;
|
|
116
|
+
this.end = end;
|
|
117
|
+
this.original = content;
|
|
118
|
+
this.intro = "";
|
|
119
|
+
this.outro = "";
|
|
120
|
+
this.content = content;
|
|
121
|
+
this.storeName = false;
|
|
122
|
+
this.edited = false;
|
|
123
|
+
this.previous = null;
|
|
124
|
+
this.next = null;
|
|
125
|
+
}
|
|
126
|
+
appendLeft(content) {
|
|
127
|
+
this.outro += content;
|
|
128
|
+
}
|
|
129
|
+
appendRight(content) {
|
|
130
|
+
this.intro = this.intro + content;
|
|
131
|
+
}
|
|
132
|
+
clone() {
|
|
133
|
+
const chunk = new Chunk(this.start, this.end, this.original);
|
|
134
|
+
chunk.intro = this.intro;
|
|
135
|
+
chunk.outro = this.outro;
|
|
136
|
+
chunk.content = this.content;
|
|
137
|
+
chunk.storeName = this.storeName;
|
|
138
|
+
chunk.edited = this.edited;
|
|
139
|
+
return chunk;
|
|
140
|
+
}
|
|
141
|
+
contains(index) {
|
|
142
|
+
return this.start < index && index < this.end;
|
|
143
|
+
}
|
|
144
|
+
eachNext(fn) {
|
|
145
|
+
let chunk = this;
|
|
146
|
+
while (chunk) {
|
|
147
|
+
fn(chunk);
|
|
148
|
+
chunk = chunk.next;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
eachPrevious(fn) {
|
|
152
|
+
let chunk = this;
|
|
153
|
+
while (chunk) {
|
|
154
|
+
fn(chunk);
|
|
155
|
+
chunk = chunk.previous;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
edit(content, storeName, contentOnly) {
|
|
159
|
+
this.content = content;
|
|
160
|
+
if (!contentOnly) {
|
|
161
|
+
this.intro = "";
|
|
162
|
+
this.outro = "";
|
|
163
|
+
}
|
|
164
|
+
this.storeName = storeName;
|
|
165
|
+
this.edited = true;
|
|
166
|
+
return this;
|
|
167
|
+
}
|
|
168
|
+
prependLeft(content) {
|
|
169
|
+
this.outro = content + this.outro;
|
|
170
|
+
}
|
|
171
|
+
prependRight(content) {
|
|
172
|
+
this.intro = content + this.intro;
|
|
173
|
+
}
|
|
174
|
+
reset() {
|
|
175
|
+
this.intro = "";
|
|
176
|
+
this.outro = "";
|
|
177
|
+
if (this.edited) {
|
|
178
|
+
this.content = this.original;
|
|
179
|
+
this.storeName = false;
|
|
180
|
+
this.edited = false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
split(index) {
|
|
184
|
+
const sliceIndex = index - this.start;
|
|
185
|
+
const originalBefore = this.original.slice(0, sliceIndex);
|
|
186
|
+
const originalAfter = this.original.slice(sliceIndex);
|
|
187
|
+
this.original = originalBefore;
|
|
188
|
+
const newChunk = new Chunk(index, this.end, originalAfter);
|
|
189
|
+
newChunk.outro = this.outro;
|
|
190
|
+
this.outro = "";
|
|
191
|
+
this.end = index;
|
|
192
|
+
if (this.edited) {
|
|
193
|
+
newChunk.edit("", false);
|
|
194
|
+
this.content = "";
|
|
195
|
+
} else this.content = originalBefore;
|
|
196
|
+
newChunk.next = this.next;
|
|
197
|
+
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
198
|
+
newChunk.previous = this;
|
|
199
|
+
this.next = newChunk;
|
|
200
|
+
return newChunk;
|
|
201
|
+
}
|
|
202
|
+
toString() {
|
|
203
|
+
return this.intro + this.content + this.outro;
|
|
204
|
+
}
|
|
205
|
+
trimEnd(rx) {
|
|
206
|
+
this.outro = this.outro.replace(rx, "");
|
|
207
|
+
if (this.outro.length) return true;
|
|
208
|
+
const trimmed = this.content.replace(rx, "");
|
|
209
|
+
if (trimmed.length) {
|
|
210
|
+
if (trimmed !== this.content) {
|
|
211
|
+
this.split(this.start + trimmed.length).edit("", void 0, true);
|
|
212
|
+
if (this.edited) this.edit(trimmed, this.storeName, true);
|
|
213
|
+
}
|
|
214
|
+
return true;
|
|
215
|
+
} else {
|
|
216
|
+
this.edit("", void 0, true);
|
|
217
|
+
this.intro = this.intro.replace(rx, "");
|
|
218
|
+
if (this.intro.length) return true;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
trimStart(rx) {
|
|
222
|
+
this.intro = this.intro.replace(rx, "");
|
|
223
|
+
if (this.intro.length) return true;
|
|
224
|
+
const trimmed = this.content.replace(rx, "");
|
|
225
|
+
if (trimmed.length) {
|
|
226
|
+
if (trimmed !== this.content) {
|
|
227
|
+
const newChunk = this.split(this.end - trimmed.length);
|
|
228
|
+
if (this.edited) newChunk.edit(trimmed, this.storeName, true);
|
|
229
|
+
this.edit("", void 0, true);
|
|
230
|
+
}
|
|
231
|
+
return true;
|
|
232
|
+
} else {
|
|
233
|
+
this.edit("", void 0, true);
|
|
234
|
+
this.outro = this.outro.replace(rx, "");
|
|
235
|
+
if (this.outro.length) return true;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
function getBtoa() {
|
|
240
|
+
if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
|
|
241
|
+
else if (typeof Buffer === "function") return (str) => Buffer.from(str, "utf-8").toString("base64");
|
|
242
|
+
else return () => {
|
|
243
|
+
throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
var btoa = /*#__PURE__*/ getBtoa();
|
|
247
|
+
var SourceMap = class {
|
|
248
|
+
constructor(properties) {
|
|
249
|
+
this.version = 3;
|
|
250
|
+
this.file = properties.file;
|
|
251
|
+
this.sources = properties.sources;
|
|
252
|
+
this.sourcesContent = properties.sourcesContent;
|
|
253
|
+
this.names = properties.names;
|
|
254
|
+
this.mappings = encode(properties.mappings);
|
|
255
|
+
if (typeof properties.x_google_ignoreList !== "undefined") this.x_google_ignoreList = properties.x_google_ignoreList;
|
|
256
|
+
if (typeof properties.debugId !== "undefined") this.debugId = properties.debugId;
|
|
257
|
+
}
|
|
258
|
+
toString() {
|
|
259
|
+
return JSON.stringify(this);
|
|
260
|
+
}
|
|
261
|
+
toUrl() {
|
|
262
|
+
return "data:application/json;charset=utf-8;base64," + btoa(this.toString());
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
function guessIndent(code) {
|
|
266
|
+
const lines = code.split("\n");
|
|
267
|
+
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
268
|
+
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
269
|
+
if (tabbed.length === 0 && spaced.length === 0) return null;
|
|
270
|
+
if (tabbed.length >= spaced.length) return " ";
|
|
271
|
+
const min = spaced.reduce((previous, current) => {
|
|
272
|
+
const numSpaces = /^ +/.exec(current)[0].length;
|
|
273
|
+
return Math.min(numSpaces, previous);
|
|
274
|
+
}, Infinity);
|
|
275
|
+
return new Array(min + 1).join(" ");
|
|
276
|
+
}
|
|
277
|
+
function getRelativePath(from, to) {
|
|
278
|
+
const fromParts = from.split(/[/\\]/);
|
|
279
|
+
const toParts = to.split(/[/\\]/);
|
|
280
|
+
fromParts.pop();
|
|
281
|
+
while (fromParts[0] === toParts[0]) {
|
|
282
|
+
fromParts.shift();
|
|
283
|
+
toParts.shift();
|
|
284
|
+
}
|
|
285
|
+
if (fromParts.length) {
|
|
286
|
+
let i = fromParts.length;
|
|
287
|
+
while (i--) fromParts[i] = "..";
|
|
288
|
+
}
|
|
289
|
+
return fromParts.concat(toParts).join("/");
|
|
290
|
+
}
|
|
291
|
+
var toString = Object.prototype.toString;
|
|
292
|
+
function isObject(thing) {
|
|
293
|
+
return toString.call(thing) === "[object Object]";
|
|
294
|
+
}
|
|
295
|
+
function getLocator(source) {
|
|
296
|
+
const originalLines = source.split("\n");
|
|
297
|
+
const lineOffsets = [];
|
|
298
|
+
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
299
|
+
lineOffsets.push(pos);
|
|
300
|
+
pos += originalLines[i].length + 1;
|
|
301
|
+
}
|
|
302
|
+
return function locate(index) {
|
|
303
|
+
let i = 0;
|
|
304
|
+
let j = lineOffsets.length;
|
|
305
|
+
while (i < j) {
|
|
306
|
+
const m = i + j >> 1;
|
|
307
|
+
if (index < lineOffsets[m]) j = m;
|
|
308
|
+
else i = m + 1;
|
|
309
|
+
}
|
|
310
|
+
const line = i - 1;
|
|
311
|
+
return {
|
|
312
|
+
line,
|
|
313
|
+
column: index - lineOffsets[line]
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
var wordRegex = /\w/;
|
|
318
|
+
var Mappings = class {
|
|
319
|
+
constructor(hires) {
|
|
320
|
+
this.hires = hires;
|
|
321
|
+
this.generatedCodeLine = 0;
|
|
322
|
+
this.generatedCodeColumn = 0;
|
|
323
|
+
this.raw = [];
|
|
324
|
+
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
325
|
+
this.pending = null;
|
|
326
|
+
}
|
|
327
|
+
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
328
|
+
if (content.length) {
|
|
329
|
+
const contentLengthMinusOne = content.length - 1;
|
|
330
|
+
let contentLineEnd = content.indexOf("\n", 0);
|
|
331
|
+
let previousContentLineEnd = -1;
|
|
332
|
+
while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
|
|
333
|
+
const segment = [
|
|
334
|
+
this.generatedCodeColumn,
|
|
335
|
+
sourceIndex,
|
|
336
|
+
loc.line,
|
|
337
|
+
loc.column
|
|
338
|
+
];
|
|
339
|
+
if (nameIndex >= 0) segment.push(nameIndex);
|
|
340
|
+
this.rawSegments.push(segment);
|
|
341
|
+
this.generatedCodeLine += 1;
|
|
342
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
343
|
+
this.generatedCodeColumn = 0;
|
|
344
|
+
previousContentLineEnd = contentLineEnd;
|
|
345
|
+
contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
|
|
346
|
+
}
|
|
347
|
+
const segment = [
|
|
348
|
+
this.generatedCodeColumn,
|
|
349
|
+
sourceIndex,
|
|
350
|
+
loc.line,
|
|
351
|
+
loc.column
|
|
352
|
+
];
|
|
353
|
+
if (nameIndex >= 0) segment.push(nameIndex);
|
|
354
|
+
this.rawSegments.push(segment);
|
|
355
|
+
this.advance(content.slice(previousContentLineEnd + 1));
|
|
356
|
+
} else if (this.pending) {
|
|
357
|
+
this.rawSegments.push(this.pending);
|
|
358
|
+
this.advance(content);
|
|
359
|
+
}
|
|
360
|
+
this.pending = null;
|
|
361
|
+
}
|
|
362
|
+
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
363
|
+
let originalCharIndex = chunk.start;
|
|
364
|
+
let first = true;
|
|
365
|
+
let charInHiresBoundary = false;
|
|
366
|
+
while (originalCharIndex < chunk.end) {
|
|
367
|
+
if (original[originalCharIndex] === "\n") {
|
|
368
|
+
loc.line += 1;
|
|
369
|
+
loc.column = 0;
|
|
370
|
+
this.generatedCodeLine += 1;
|
|
371
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
372
|
+
this.generatedCodeColumn = 0;
|
|
373
|
+
first = true;
|
|
374
|
+
charInHiresBoundary = false;
|
|
375
|
+
} else {
|
|
376
|
+
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
377
|
+
const segment = [
|
|
378
|
+
this.generatedCodeColumn,
|
|
379
|
+
sourceIndex,
|
|
380
|
+
loc.line,
|
|
381
|
+
loc.column
|
|
382
|
+
];
|
|
383
|
+
if (this.hires === "boundary") if (wordRegex.test(original[originalCharIndex])) {
|
|
384
|
+
if (!charInHiresBoundary) {
|
|
385
|
+
this.rawSegments.push(segment);
|
|
386
|
+
charInHiresBoundary = true;
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
this.rawSegments.push(segment);
|
|
390
|
+
charInHiresBoundary = false;
|
|
391
|
+
}
|
|
392
|
+
else this.rawSegments.push(segment);
|
|
393
|
+
}
|
|
394
|
+
loc.column += 1;
|
|
395
|
+
this.generatedCodeColumn += 1;
|
|
396
|
+
first = false;
|
|
397
|
+
}
|
|
398
|
+
originalCharIndex += 1;
|
|
399
|
+
}
|
|
400
|
+
this.pending = null;
|
|
401
|
+
}
|
|
402
|
+
advance(str) {
|
|
403
|
+
if (!str) return;
|
|
404
|
+
const lines = str.split("\n");
|
|
405
|
+
if (lines.length > 1) {
|
|
406
|
+
for (let i = 0; i < lines.length - 1; i++) {
|
|
407
|
+
this.generatedCodeLine++;
|
|
408
|
+
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
409
|
+
}
|
|
410
|
+
this.generatedCodeColumn = 0;
|
|
411
|
+
}
|
|
412
|
+
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
var n = "\n";
|
|
416
|
+
var warned = {
|
|
417
|
+
insertLeft: false,
|
|
418
|
+
insertRight: false,
|
|
419
|
+
storeName: false
|
|
420
|
+
};
|
|
421
|
+
var MagicString = class MagicString {
|
|
422
|
+
constructor(string, options = {}) {
|
|
423
|
+
const chunk = new Chunk(0, string.length, string);
|
|
424
|
+
Object.defineProperties(this, {
|
|
425
|
+
original: {
|
|
426
|
+
writable: true,
|
|
427
|
+
value: string
|
|
428
|
+
},
|
|
429
|
+
outro: {
|
|
430
|
+
writable: true,
|
|
431
|
+
value: ""
|
|
432
|
+
},
|
|
433
|
+
intro: {
|
|
434
|
+
writable: true,
|
|
435
|
+
value: ""
|
|
436
|
+
},
|
|
437
|
+
firstChunk: {
|
|
438
|
+
writable: true,
|
|
439
|
+
value: chunk
|
|
440
|
+
},
|
|
441
|
+
lastChunk: {
|
|
442
|
+
writable: true,
|
|
443
|
+
value: chunk
|
|
444
|
+
},
|
|
445
|
+
lastSearchedChunk: {
|
|
446
|
+
writable: true,
|
|
447
|
+
value: chunk
|
|
448
|
+
},
|
|
449
|
+
byStart: {
|
|
450
|
+
writable: true,
|
|
451
|
+
value: {}
|
|
452
|
+
},
|
|
453
|
+
byEnd: {
|
|
454
|
+
writable: true,
|
|
455
|
+
value: {}
|
|
456
|
+
},
|
|
457
|
+
filename: {
|
|
458
|
+
writable: true,
|
|
459
|
+
value: options.filename
|
|
460
|
+
},
|
|
461
|
+
indentExclusionRanges: {
|
|
462
|
+
writable: true,
|
|
463
|
+
value: options.indentExclusionRanges
|
|
464
|
+
},
|
|
465
|
+
sourcemapLocations: {
|
|
466
|
+
writable: true,
|
|
467
|
+
value: new BitSet()
|
|
468
|
+
},
|
|
469
|
+
storedNames: {
|
|
470
|
+
writable: true,
|
|
471
|
+
value: {}
|
|
472
|
+
},
|
|
473
|
+
indentStr: {
|
|
474
|
+
writable: true,
|
|
475
|
+
value: void 0
|
|
476
|
+
},
|
|
477
|
+
ignoreList: {
|
|
478
|
+
writable: true,
|
|
479
|
+
value: options.ignoreList
|
|
480
|
+
},
|
|
481
|
+
offset: {
|
|
482
|
+
writable: true,
|
|
483
|
+
value: options.offset || 0
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
this.byStart[0] = chunk;
|
|
487
|
+
this.byEnd[string.length] = chunk;
|
|
488
|
+
}
|
|
489
|
+
addSourcemapLocation(char) {
|
|
490
|
+
this.sourcemapLocations.add(char);
|
|
491
|
+
}
|
|
492
|
+
append(content) {
|
|
493
|
+
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
494
|
+
this.outro += content;
|
|
495
|
+
return this;
|
|
496
|
+
}
|
|
497
|
+
appendLeft(index, content) {
|
|
498
|
+
index = index + this.offset;
|
|
499
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
500
|
+
this._split(index);
|
|
501
|
+
const chunk = this.byEnd[index];
|
|
502
|
+
if (chunk) chunk.appendLeft(content);
|
|
503
|
+
else this.intro += content;
|
|
504
|
+
return this;
|
|
505
|
+
}
|
|
506
|
+
appendRight(index, content) {
|
|
507
|
+
index = index + this.offset;
|
|
508
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
509
|
+
this._split(index);
|
|
510
|
+
const chunk = this.byStart[index];
|
|
511
|
+
if (chunk) chunk.appendRight(content);
|
|
512
|
+
else this.outro += content;
|
|
513
|
+
return this;
|
|
514
|
+
}
|
|
515
|
+
clone() {
|
|
516
|
+
const cloned = new MagicString(this.original, {
|
|
517
|
+
filename: this.filename,
|
|
518
|
+
offset: this.offset
|
|
519
|
+
});
|
|
520
|
+
let originalChunk = this.firstChunk;
|
|
521
|
+
let clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
|
522
|
+
while (originalChunk) {
|
|
523
|
+
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
524
|
+
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
525
|
+
const nextOriginalChunk = originalChunk.next;
|
|
526
|
+
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
527
|
+
if (nextClonedChunk) {
|
|
528
|
+
clonedChunk.next = nextClonedChunk;
|
|
529
|
+
nextClonedChunk.previous = clonedChunk;
|
|
530
|
+
clonedChunk = nextClonedChunk;
|
|
531
|
+
}
|
|
532
|
+
originalChunk = nextOriginalChunk;
|
|
533
|
+
}
|
|
534
|
+
cloned.lastChunk = clonedChunk;
|
|
535
|
+
if (this.indentExclusionRanges) cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
536
|
+
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
537
|
+
cloned.intro = this.intro;
|
|
538
|
+
cloned.outro = this.outro;
|
|
539
|
+
return cloned;
|
|
540
|
+
}
|
|
541
|
+
generateDecodedMap(options) {
|
|
542
|
+
options = options || {};
|
|
543
|
+
const sourceIndex = 0;
|
|
544
|
+
const names = Object.keys(this.storedNames);
|
|
545
|
+
const mappings = new Mappings(options.hires);
|
|
546
|
+
const locate = getLocator(this.original);
|
|
547
|
+
if (this.intro) mappings.advance(this.intro);
|
|
548
|
+
this.firstChunk.eachNext((chunk) => {
|
|
549
|
+
const loc = locate(chunk.start);
|
|
550
|
+
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
551
|
+
if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
|
|
552
|
+
else mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
553
|
+
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
554
|
+
});
|
|
555
|
+
if (this.outro) mappings.advance(this.outro);
|
|
556
|
+
return {
|
|
557
|
+
file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
|
|
558
|
+
sources: [options.source ? getRelativePath(options.file || "", options.source) : options.file || ""],
|
|
559
|
+
sourcesContent: options.includeContent ? [this.original] : void 0,
|
|
560
|
+
names,
|
|
561
|
+
mappings: mappings.raw,
|
|
562
|
+
x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
generateMap(options) {
|
|
566
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
567
|
+
}
|
|
568
|
+
_ensureindentStr() {
|
|
569
|
+
if (this.indentStr === void 0) this.indentStr = guessIndent(this.original);
|
|
570
|
+
}
|
|
571
|
+
_getRawIndentString() {
|
|
572
|
+
this._ensureindentStr();
|
|
573
|
+
return this.indentStr;
|
|
574
|
+
}
|
|
575
|
+
getIndentString() {
|
|
576
|
+
this._ensureindentStr();
|
|
577
|
+
return this.indentStr === null ? " " : this.indentStr;
|
|
578
|
+
}
|
|
579
|
+
indent(indentStr, options) {
|
|
580
|
+
const pattern = /^[^\r\n]/gm;
|
|
581
|
+
if (isObject(indentStr)) {
|
|
582
|
+
options = indentStr;
|
|
583
|
+
indentStr = void 0;
|
|
584
|
+
}
|
|
585
|
+
if (indentStr === void 0) {
|
|
586
|
+
this._ensureindentStr();
|
|
587
|
+
indentStr = this.indentStr || " ";
|
|
588
|
+
}
|
|
589
|
+
if (indentStr === "") return this;
|
|
590
|
+
options = options || {};
|
|
591
|
+
const isExcluded = {};
|
|
592
|
+
if (options.exclude) (typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude).forEach((exclusion) => {
|
|
593
|
+
for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded[i] = true;
|
|
594
|
+
});
|
|
595
|
+
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
596
|
+
const replacer = (match) => {
|
|
597
|
+
if (shouldIndentNextCharacter) return `${indentStr}${match}`;
|
|
598
|
+
shouldIndentNextCharacter = true;
|
|
599
|
+
return match;
|
|
600
|
+
};
|
|
601
|
+
this.intro = this.intro.replace(pattern, replacer);
|
|
602
|
+
let charIndex = 0;
|
|
603
|
+
let chunk = this.firstChunk;
|
|
604
|
+
while (chunk) {
|
|
605
|
+
const end = chunk.end;
|
|
606
|
+
if (chunk.edited) {
|
|
607
|
+
if (!isExcluded[charIndex]) {
|
|
608
|
+
chunk.content = chunk.content.replace(pattern, replacer);
|
|
609
|
+
if (chunk.content.length) shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
|
|
610
|
+
}
|
|
611
|
+
} else {
|
|
612
|
+
charIndex = chunk.start;
|
|
613
|
+
while (charIndex < end) {
|
|
614
|
+
if (!isExcluded[charIndex]) {
|
|
615
|
+
const char = this.original[charIndex];
|
|
616
|
+
if (char === "\n") shouldIndentNextCharacter = true;
|
|
617
|
+
else if (char !== "\r" && shouldIndentNextCharacter) {
|
|
618
|
+
shouldIndentNextCharacter = false;
|
|
619
|
+
if (charIndex === chunk.start) chunk.prependRight(indentStr);
|
|
620
|
+
else {
|
|
621
|
+
this._splitChunk(chunk, charIndex);
|
|
622
|
+
chunk = chunk.next;
|
|
623
|
+
chunk.prependRight(indentStr);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
charIndex += 1;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
charIndex = chunk.end;
|
|
631
|
+
chunk = chunk.next;
|
|
632
|
+
}
|
|
633
|
+
this.outro = this.outro.replace(pattern, replacer);
|
|
634
|
+
return this;
|
|
635
|
+
}
|
|
636
|
+
insert() {
|
|
637
|
+
throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)");
|
|
638
|
+
}
|
|
639
|
+
insertLeft(index, content) {
|
|
640
|
+
if (!warned.insertLeft) {
|
|
641
|
+
console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead");
|
|
642
|
+
warned.insertLeft = true;
|
|
643
|
+
}
|
|
644
|
+
return this.appendLeft(index, content);
|
|
645
|
+
}
|
|
646
|
+
insertRight(index, content) {
|
|
647
|
+
if (!warned.insertRight) {
|
|
648
|
+
console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead");
|
|
649
|
+
warned.insertRight = true;
|
|
650
|
+
}
|
|
651
|
+
return this.prependRight(index, content);
|
|
652
|
+
}
|
|
653
|
+
move(start, end, index) {
|
|
654
|
+
start = start + this.offset;
|
|
655
|
+
end = end + this.offset;
|
|
656
|
+
index = index + this.offset;
|
|
657
|
+
if (index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
|
|
658
|
+
this._split(start);
|
|
659
|
+
this._split(end);
|
|
660
|
+
this._split(index);
|
|
661
|
+
const first = this.byStart[start];
|
|
662
|
+
const last = this.byEnd[end];
|
|
663
|
+
const oldLeft = first.previous;
|
|
664
|
+
const oldRight = last.next;
|
|
665
|
+
const newRight = this.byStart[index];
|
|
666
|
+
if (!newRight && last === this.lastChunk) return this;
|
|
667
|
+
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
668
|
+
if (oldLeft) oldLeft.next = oldRight;
|
|
669
|
+
if (oldRight) oldRight.previous = oldLeft;
|
|
670
|
+
if (newLeft) newLeft.next = first;
|
|
671
|
+
if (newRight) newRight.previous = last;
|
|
672
|
+
if (!first.previous) this.firstChunk = last.next;
|
|
673
|
+
if (!last.next) {
|
|
674
|
+
this.lastChunk = first.previous;
|
|
675
|
+
this.lastChunk.next = null;
|
|
676
|
+
}
|
|
677
|
+
first.previous = newLeft;
|
|
678
|
+
last.next = newRight || null;
|
|
679
|
+
if (!newLeft) this.firstChunk = first;
|
|
680
|
+
if (!newRight) this.lastChunk = last;
|
|
681
|
+
return this;
|
|
682
|
+
}
|
|
683
|
+
overwrite(start, end, content, options) {
|
|
684
|
+
options = options || {};
|
|
685
|
+
return this.update(start, end, content, {
|
|
686
|
+
...options,
|
|
687
|
+
overwrite: !options.contentOnly
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
update(start, end, content, options) {
|
|
691
|
+
start = start + this.offset;
|
|
692
|
+
end = end + this.offset;
|
|
693
|
+
if (typeof content !== "string") throw new TypeError("replacement content must be a string");
|
|
694
|
+
if (this.original.length !== 0) {
|
|
695
|
+
while (start < 0) start += this.original.length;
|
|
696
|
+
while (end < 0) end += this.original.length;
|
|
697
|
+
}
|
|
698
|
+
if (end > this.original.length) throw new Error("end is out of bounds");
|
|
699
|
+
if (start === end) throw new Error("Cannot overwrite a zero-length range – use appendLeft or prependRight instead");
|
|
700
|
+
this._split(start);
|
|
701
|
+
this._split(end);
|
|
702
|
+
if (options === true) {
|
|
703
|
+
if (!warned.storeName) {
|
|
704
|
+
console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string");
|
|
705
|
+
warned.storeName = true;
|
|
706
|
+
}
|
|
707
|
+
options = { storeName: true };
|
|
708
|
+
}
|
|
709
|
+
const storeName = options !== void 0 ? options.storeName : false;
|
|
710
|
+
const overwrite = options !== void 0 ? options.overwrite : false;
|
|
711
|
+
if (storeName) {
|
|
712
|
+
const original = this.original.slice(start, end);
|
|
713
|
+
Object.defineProperty(this.storedNames, original, {
|
|
714
|
+
writable: true,
|
|
715
|
+
value: true,
|
|
716
|
+
enumerable: true
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
const first = this.byStart[start];
|
|
720
|
+
const last = this.byEnd[end];
|
|
721
|
+
if (first) {
|
|
722
|
+
let chunk = first;
|
|
723
|
+
while (chunk !== last) {
|
|
724
|
+
if (chunk.next !== this.byStart[chunk.end]) throw new Error("Cannot overwrite across a split point");
|
|
725
|
+
chunk = chunk.next;
|
|
726
|
+
chunk.edit("", false);
|
|
727
|
+
}
|
|
728
|
+
first.edit(content, storeName, !overwrite);
|
|
729
|
+
} else {
|
|
730
|
+
const newChunk = new Chunk(start, end, "").edit(content, storeName);
|
|
731
|
+
last.next = newChunk;
|
|
732
|
+
newChunk.previous = last;
|
|
733
|
+
}
|
|
734
|
+
return this;
|
|
735
|
+
}
|
|
736
|
+
prepend(content) {
|
|
737
|
+
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
738
|
+
this.intro = content + this.intro;
|
|
739
|
+
return this;
|
|
740
|
+
}
|
|
741
|
+
prependLeft(index, content) {
|
|
742
|
+
index = index + this.offset;
|
|
743
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
744
|
+
this._split(index);
|
|
745
|
+
const chunk = this.byEnd[index];
|
|
746
|
+
if (chunk) chunk.prependLeft(content);
|
|
747
|
+
else this.intro = content + this.intro;
|
|
748
|
+
return this;
|
|
749
|
+
}
|
|
750
|
+
prependRight(index, content) {
|
|
751
|
+
index = index + this.offset;
|
|
752
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
753
|
+
this._split(index);
|
|
754
|
+
const chunk = this.byStart[index];
|
|
755
|
+
if (chunk) chunk.prependRight(content);
|
|
756
|
+
else this.outro = content + this.outro;
|
|
757
|
+
return this;
|
|
758
|
+
}
|
|
759
|
+
remove(start, end) {
|
|
760
|
+
start = start + this.offset;
|
|
761
|
+
end = end + this.offset;
|
|
762
|
+
if (this.original.length !== 0) {
|
|
763
|
+
while (start < 0) start += this.original.length;
|
|
764
|
+
while (end < 0) end += this.original.length;
|
|
765
|
+
}
|
|
766
|
+
if (start === end) return this;
|
|
767
|
+
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
768
|
+
if (start > end) throw new Error("end must be greater than start");
|
|
769
|
+
this._split(start);
|
|
770
|
+
this._split(end);
|
|
771
|
+
let chunk = this.byStart[start];
|
|
772
|
+
while (chunk) {
|
|
773
|
+
chunk.intro = "";
|
|
774
|
+
chunk.outro = "";
|
|
775
|
+
chunk.edit("");
|
|
776
|
+
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
777
|
+
}
|
|
778
|
+
return this;
|
|
779
|
+
}
|
|
780
|
+
reset(start, end) {
|
|
781
|
+
start = start + this.offset;
|
|
782
|
+
end = end + this.offset;
|
|
783
|
+
if (this.original.length !== 0) {
|
|
784
|
+
while (start < 0) start += this.original.length;
|
|
785
|
+
while (end < 0) end += this.original.length;
|
|
786
|
+
}
|
|
787
|
+
if (start === end) return this;
|
|
788
|
+
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
789
|
+
if (start > end) throw new Error("end must be greater than start");
|
|
790
|
+
this._split(start);
|
|
791
|
+
this._split(end);
|
|
792
|
+
let chunk = this.byStart[start];
|
|
793
|
+
while (chunk) {
|
|
794
|
+
chunk.reset();
|
|
795
|
+
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
796
|
+
}
|
|
797
|
+
return this;
|
|
798
|
+
}
|
|
799
|
+
lastChar() {
|
|
800
|
+
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
801
|
+
let chunk = this.lastChunk;
|
|
802
|
+
do {
|
|
803
|
+
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
804
|
+
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
805
|
+
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
806
|
+
} while (chunk = chunk.previous);
|
|
807
|
+
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
808
|
+
return "";
|
|
809
|
+
}
|
|
810
|
+
lastLine() {
|
|
811
|
+
let lineIndex = this.outro.lastIndexOf(n);
|
|
812
|
+
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
813
|
+
let lineStr = this.outro;
|
|
814
|
+
let chunk = this.lastChunk;
|
|
815
|
+
do {
|
|
816
|
+
if (chunk.outro.length > 0) {
|
|
817
|
+
lineIndex = chunk.outro.lastIndexOf(n);
|
|
818
|
+
if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
819
|
+
lineStr = chunk.outro + lineStr;
|
|
820
|
+
}
|
|
821
|
+
if (chunk.content.length > 0) {
|
|
822
|
+
lineIndex = chunk.content.lastIndexOf(n);
|
|
823
|
+
if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
|
|
824
|
+
lineStr = chunk.content + lineStr;
|
|
825
|
+
}
|
|
826
|
+
if (chunk.intro.length > 0) {
|
|
827
|
+
lineIndex = chunk.intro.lastIndexOf(n);
|
|
828
|
+
if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
829
|
+
lineStr = chunk.intro + lineStr;
|
|
830
|
+
}
|
|
831
|
+
} while (chunk = chunk.previous);
|
|
832
|
+
lineIndex = this.intro.lastIndexOf(n);
|
|
833
|
+
if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
|
|
834
|
+
return this.intro + lineStr;
|
|
835
|
+
}
|
|
836
|
+
slice(start = 0, end = this.original.length - this.offset) {
|
|
837
|
+
start = start + this.offset;
|
|
838
|
+
end = end + this.offset;
|
|
839
|
+
if (this.original.length !== 0) {
|
|
840
|
+
while (start < 0) start += this.original.length;
|
|
841
|
+
while (end < 0) end += this.original.length;
|
|
842
|
+
}
|
|
843
|
+
let result = "";
|
|
844
|
+
let chunk = this.firstChunk;
|
|
845
|
+
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
846
|
+
if (chunk.start < end && chunk.end >= end) return result;
|
|
847
|
+
chunk = chunk.next;
|
|
848
|
+
}
|
|
849
|
+
if (chunk && chunk.edited && chunk.start !== start) throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
850
|
+
const startChunk = chunk;
|
|
851
|
+
while (chunk) {
|
|
852
|
+
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) result += chunk.intro;
|
|
853
|
+
const containsEnd = chunk.start < end && chunk.end >= end;
|
|
854
|
+
if (containsEnd && chunk.edited && chunk.end !== end) throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
855
|
+
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
856
|
+
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
857
|
+
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
858
|
+
if (chunk.outro && (!containsEnd || chunk.end === end)) result += chunk.outro;
|
|
859
|
+
if (containsEnd) break;
|
|
860
|
+
chunk = chunk.next;
|
|
861
|
+
}
|
|
862
|
+
return result;
|
|
863
|
+
}
|
|
864
|
+
snip(start, end) {
|
|
865
|
+
const clone = this.clone();
|
|
866
|
+
clone.remove(0, start);
|
|
867
|
+
clone.remove(end, clone.original.length);
|
|
868
|
+
return clone;
|
|
869
|
+
}
|
|
870
|
+
_split(index) {
|
|
871
|
+
if (this.byStart[index] || this.byEnd[index]) return;
|
|
872
|
+
let chunk = this.lastSearchedChunk;
|
|
873
|
+
let previousChunk = chunk;
|
|
874
|
+
const searchForward = index > chunk.end;
|
|
875
|
+
while (chunk) {
|
|
876
|
+
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
877
|
+
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
878
|
+
if (chunk === previousChunk) return;
|
|
879
|
+
previousChunk = chunk;
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
_splitChunk(chunk, index) {
|
|
883
|
+
if (chunk.edited && chunk.content.length) {
|
|
884
|
+
const loc = getLocator(this.original)(index);
|
|
885
|
+
throw new Error(`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`);
|
|
886
|
+
}
|
|
887
|
+
const newChunk = chunk.split(index);
|
|
888
|
+
this.byEnd[index] = chunk;
|
|
889
|
+
this.byStart[index] = newChunk;
|
|
890
|
+
this.byEnd[newChunk.end] = newChunk;
|
|
891
|
+
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
892
|
+
this.lastSearchedChunk = chunk;
|
|
893
|
+
return true;
|
|
894
|
+
}
|
|
895
|
+
toString() {
|
|
896
|
+
let str = this.intro;
|
|
897
|
+
let chunk = this.firstChunk;
|
|
898
|
+
while (chunk) {
|
|
899
|
+
str += chunk.toString();
|
|
900
|
+
chunk = chunk.next;
|
|
901
|
+
}
|
|
902
|
+
return str + this.outro;
|
|
903
|
+
}
|
|
904
|
+
isEmpty() {
|
|
905
|
+
let chunk = this.firstChunk;
|
|
906
|
+
do
|
|
907
|
+
if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim()) return false;
|
|
908
|
+
while (chunk = chunk.next);
|
|
909
|
+
return true;
|
|
910
|
+
}
|
|
911
|
+
length() {
|
|
912
|
+
let chunk = this.firstChunk;
|
|
913
|
+
let length = 0;
|
|
914
|
+
do
|
|
915
|
+
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
916
|
+
while (chunk = chunk.next);
|
|
917
|
+
return length;
|
|
918
|
+
}
|
|
919
|
+
trimLines() {
|
|
920
|
+
return this.trim("[\\r\\n]");
|
|
921
|
+
}
|
|
922
|
+
trim(charType) {
|
|
923
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
924
|
+
}
|
|
925
|
+
trimEndAborted(charType) {
|
|
926
|
+
const rx = new RegExp((charType || "\\s") + "+$");
|
|
927
|
+
this.outro = this.outro.replace(rx, "");
|
|
928
|
+
if (this.outro.length) return true;
|
|
929
|
+
let chunk = this.lastChunk;
|
|
930
|
+
do {
|
|
931
|
+
const end = chunk.end;
|
|
932
|
+
const aborted = chunk.trimEnd(rx);
|
|
933
|
+
if (chunk.end !== end) {
|
|
934
|
+
if (this.lastChunk === chunk) this.lastChunk = chunk.next;
|
|
935
|
+
this.byEnd[chunk.end] = chunk;
|
|
936
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
937
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
938
|
+
}
|
|
939
|
+
if (aborted) return true;
|
|
940
|
+
chunk = chunk.previous;
|
|
941
|
+
} while (chunk);
|
|
942
|
+
return false;
|
|
943
|
+
}
|
|
944
|
+
trimEnd(charType) {
|
|
945
|
+
this.trimEndAborted(charType);
|
|
946
|
+
return this;
|
|
947
|
+
}
|
|
948
|
+
trimStartAborted(charType) {
|
|
949
|
+
const rx = new RegExp("^" + (charType || "\\s") + "+");
|
|
950
|
+
this.intro = this.intro.replace(rx, "");
|
|
951
|
+
if (this.intro.length) return true;
|
|
952
|
+
let chunk = this.firstChunk;
|
|
953
|
+
do {
|
|
954
|
+
const end = chunk.end;
|
|
955
|
+
const aborted = chunk.trimStart(rx);
|
|
956
|
+
if (chunk.end !== end) {
|
|
957
|
+
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
958
|
+
this.byEnd[chunk.end] = chunk;
|
|
959
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
960
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
961
|
+
}
|
|
962
|
+
if (aborted) return true;
|
|
963
|
+
chunk = chunk.next;
|
|
964
|
+
} while (chunk);
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
trimStart(charType) {
|
|
968
|
+
this.trimStartAborted(charType);
|
|
969
|
+
return this;
|
|
970
|
+
}
|
|
971
|
+
hasChanged() {
|
|
972
|
+
return this.original !== this.toString();
|
|
973
|
+
}
|
|
974
|
+
_replaceRegexp(searchValue, replacement) {
|
|
975
|
+
function getReplacement(match, str) {
|
|
976
|
+
if (typeof replacement === "string") return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
977
|
+
if (i === "$") return "$";
|
|
978
|
+
if (i === "&") return match[0];
|
|
979
|
+
if (+i < match.length) return match[+i];
|
|
980
|
+
return `$${i}`;
|
|
981
|
+
});
|
|
982
|
+
else return replacement(...match, match.index, str, match.groups);
|
|
983
|
+
}
|
|
984
|
+
function matchAll(re, str) {
|
|
985
|
+
let match;
|
|
986
|
+
const matches = [];
|
|
987
|
+
while (match = re.exec(str)) matches.push(match);
|
|
988
|
+
return matches;
|
|
989
|
+
}
|
|
990
|
+
if (searchValue.global) matchAll(searchValue, this.original).forEach((match) => {
|
|
991
|
+
if (match.index != null) {
|
|
992
|
+
const replacement = getReplacement(match, this.original);
|
|
993
|
+
if (replacement !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
994
|
+
}
|
|
995
|
+
});
|
|
996
|
+
else {
|
|
997
|
+
const match = this.original.match(searchValue);
|
|
998
|
+
if (match && match.index != null) {
|
|
999
|
+
const replacement = getReplacement(match, this.original);
|
|
1000
|
+
if (replacement !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
return this;
|
|
1004
|
+
}
|
|
1005
|
+
_replaceString(string, replacement) {
|
|
1006
|
+
const { original } = this;
|
|
1007
|
+
const index = original.indexOf(string);
|
|
1008
|
+
if (index !== -1) {
|
|
1009
|
+
if (typeof replacement === "function") replacement = replacement(string, index, original);
|
|
1010
|
+
if (string !== replacement) this.overwrite(index, index + string.length, replacement);
|
|
1011
|
+
}
|
|
1012
|
+
return this;
|
|
1013
|
+
}
|
|
1014
|
+
replace(searchValue, replacement) {
|
|
1015
|
+
if (typeof searchValue === "string") return this._replaceString(searchValue, replacement);
|
|
1016
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
1017
|
+
}
|
|
1018
|
+
_replaceAllString(string, replacement) {
|
|
1019
|
+
const { original } = this;
|
|
1020
|
+
const stringLength = string.length;
|
|
1021
|
+
for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
|
|
1022
|
+
const previous = original.slice(index, index + stringLength);
|
|
1023
|
+
let _replacement = replacement;
|
|
1024
|
+
if (typeof replacement === "function") _replacement = replacement(previous, index, original);
|
|
1025
|
+
if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
|
|
1026
|
+
}
|
|
1027
|
+
return this;
|
|
1028
|
+
}
|
|
1029
|
+
replaceAll(searchValue, replacement) {
|
|
1030
|
+
if (typeof searchValue === "string") return this._replaceAllString(searchValue, replacement);
|
|
1031
|
+
if (!searchValue.global) throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
|
|
1032
|
+
return this._replaceRegexp(searchValue, replacement);
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
//#endregion
|
|
1036
|
+
//#region i18n/dictionaryShape.ts
|
|
1037
|
+
/**
|
|
1038
|
+
* Locales the dictionary declares, source language first.
|
|
1039
|
+
*
|
|
1040
|
+
* The order is meaningful: the first locale is the source language, and a key
|
|
1041
|
+
* missing from some other locale falls back along this list.
|
|
1042
|
+
*
|
|
1043
|
+
* `sourceLocale` pins that choice. Without it the source language is whichever
|
|
1044
|
+
* locale is seen first while walking the literal, which makes it an emergent
|
|
1045
|
+
* property of key order — adding a key at the top of a dictionary whose other
|
|
1046
|
+
* keys happen to lack `en-US` would silently re-point every fallback in it. Any
|
|
1047
|
+
* dictionary that is not uniformly translated should say which locale it is
|
|
1048
|
+
* authored in.
|
|
1049
|
+
*/
|
|
1050
|
+
function dictionaryLocales(translations, sourceLocale) {
|
|
1051
|
+
const locales = [];
|
|
1052
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1053
|
+
if (sourceLocale) {
|
|
1054
|
+
seen.add(sourceLocale);
|
|
1055
|
+
locales.push(sourceLocale);
|
|
1056
|
+
}
|
|
1057
|
+
for (const byLocale of Object.values(translations)) for (const locale of Object.keys(byLocale)) if (!seen.has(locale)) {
|
|
1058
|
+
seen.add(locale);
|
|
1059
|
+
locales.push(locale);
|
|
1060
|
+
}
|
|
1061
|
+
return locales;
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* Flatten one locale out of a dictionary.
|
|
1065
|
+
*
|
|
1066
|
+
* A key with no string for `locale` falls back along the declared locale order
|
|
1067
|
+
* rather than vanishing, so a half-translated dictionary degrades one string at
|
|
1068
|
+
* a time instead of rendering the whole component as raw keys.
|
|
1069
|
+
*/
|
|
1070
|
+
function localeStrings(translations, locale, fallbackOrder = dictionaryLocales(translations)) {
|
|
1071
|
+
const out = {};
|
|
1072
|
+
for (const [key, byLocale] of Object.entries(translations)) {
|
|
1073
|
+
let value = byLocale?.[locale];
|
|
1074
|
+
if (typeof value !== "string") for (const candidate of fallbackOrder) {
|
|
1075
|
+
const fallback = byLocale?.[candidate];
|
|
1076
|
+
if (typeof fallback === "string") {
|
|
1077
|
+
value = fallback;
|
|
1078
|
+
break;
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
if (typeof value === "string") out[key] = value;
|
|
1082
|
+
}
|
|
1083
|
+
return out;
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Whether the inferred source language survives reordering the literal.
|
|
1087
|
+
*
|
|
1088
|
+
* `dictionaryLocales` collects locales entry by entry, so `locales[0]` is the
|
|
1089
|
+
* first locale of the first entry. That is invariant under key reordering
|
|
1090
|
+
* exactly when every entry lists the same locale first — and order-dependent
|
|
1091
|
+
* the moment two entries disagree, because then whichever happens to be written
|
|
1092
|
+
* first decides what the *whole* dictionary falls back to. Adding one key at
|
|
1093
|
+
* the top can flip every other key's fallback language, from a diff that reads
|
|
1094
|
+
* as an addition.
|
|
1095
|
+
*
|
|
1096
|
+
* Returns the disagreement so the build can name both keys; `null` when the
|
|
1097
|
+
* inference is stable. `sourceLocale` settles it and makes the question moot.
|
|
1098
|
+
*/
|
|
1099
|
+
function findSourceDisagreement(translations) {
|
|
1100
|
+
let againstKey;
|
|
1101
|
+
let againstFirst;
|
|
1102
|
+
for (const [key, byLocale] of Object.entries(translations)) {
|
|
1103
|
+
const first = Object.keys(byLocale ?? {})[0];
|
|
1104
|
+
if (first === void 0) continue;
|
|
1105
|
+
if (againstFirst === void 0) {
|
|
1106
|
+
againstFirst = first;
|
|
1107
|
+
againstKey = key;
|
|
1108
|
+
continue;
|
|
1109
|
+
}
|
|
1110
|
+
if (first !== againstFirst) return {
|
|
1111
|
+
key,
|
|
1112
|
+
first,
|
|
1113
|
+
againstKey,
|
|
1114
|
+
againstFirst
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
return null;
|
|
1118
|
+
}
|
|
1119
|
+
/**
|
|
1120
|
+
* Canonical serialization — key order in the source file must not change the
|
|
1121
|
+
* id, or an innocuous reordering would break the payload/registry match.
|
|
1122
|
+
*/
|
|
1123
|
+
function canonicalizeDictionary(translations) {
|
|
1124
|
+
return `{${Object.keys(translations).sort().map((key) => {
|
|
1125
|
+
const byLocale = translations[key] ?? {};
|
|
1126
|
+
const inner = Object.keys(byLocale).sort().map((l) => JSON.stringify([l, byLocale[l]])).join(",");
|
|
1127
|
+
return `${JSON.stringify(key)}:[${inner}]`;
|
|
1128
|
+
}).join(",")}}`;
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* FNV-1a, run twice with different offsets for a 64-bit-wide id. No crypto
|
|
1132
|
+
* import, and it has to work identically in the browser bundle, under Bun on
|
|
1133
|
+
* the server, and inside the Vite plugin.
|
|
1134
|
+
*/
|
|
1135
|
+
function dictionaryId(translations) {
|
|
1136
|
+
const input = canonicalizeDictionary(translations);
|
|
1137
|
+
let a = 2166136261;
|
|
1138
|
+
let b = 16777619;
|
|
1139
|
+
for (let i = 0; i < input.length; i++) {
|
|
1140
|
+
const c = input.charCodeAt(i);
|
|
1141
|
+
a = Math.imul(a ^ c, 16777619);
|
|
1142
|
+
b = Math.imul(b ^ c, 2166136261);
|
|
1143
|
+
}
|
|
1144
|
+
const hex = (n) => (n >>> 0).toString(16).padStart(8, "0");
|
|
1145
|
+
return `d_${hex(a)}${hex(b)}`;
|
|
1146
|
+
}
|
|
1147
|
+
//#endregion
|
|
1148
|
+
//#region vite/dictionaryPlugin.ts
|
|
1149
|
+
/**
|
|
1150
|
+
* Splits `defineDictionary({...})` literals into one chunk per locale.
|
|
1151
|
+
*
|
|
1152
|
+
* Authoring keeps every locale in one file next to the component. This rewrites
|
|
1153
|
+
* the call so the strings themselves leave the module entirely:
|
|
1154
|
+
*
|
|
1155
|
+
* const dict = defineDictionary({ title: { "en-US": "Hi", "tr-TR": "Selam" } })
|
|
1156
|
+
*
|
|
1157
|
+
* becomes
|
|
1158
|
+
*
|
|
1159
|
+
* const dict = __gemi_dict__("d_1a2b3c4d5e6f7081", {
|
|
1160
|
+
* "en-US": () => import("virtual:gemi-dict/<src>/d_.../en-US"),
|
|
1161
|
+
* "tr-TR": () => import("virtual:gemi-dict/<src>/d_.../tr-TR"),
|
|
1162
|
+
* })
|
|
1163
|
+
*
|
|
1164
|
+
* An explicit map rather than a template-literal `import()`: the bundler sees
|
|
1165
|
+
* static specifiers, so it emits a real chunk per locale and module-preload
|
|
1166
|
+
* hints keep working. A page then downloads only the locale it renders in.
|
|
1167
|
+
*
|
|
1168
|
+
* This is purely an optimization. `defineDictionary` untransformed holds every
|
|
1169
|
+
* locale and answers synchronously, which is what keeps `bun test` and server
|
|
1170
|
+
* code that never meets the bundler working with no special casing.
|
|
1171
|
+
*/
|
|
1172
|
+
var VIRTUAL_PREFIX = "virtual:gemi-dict/";
|
|
1173
|
+
var RESOLVED_PREFIX = "\0virtual:gemi-dict/";
|
|
1174
|
+
/** Entrypoints that may export `defineDictionary`. */
|
|
1175
|
+
var DICTIONARY_SOURCES = /* @__PURE__ */ new Set([
|
|
1176
|
+
"gemi/dictionary",
|
|
1177
|
+
"gemi/client",
|
|
1178
|
+
"gemi/i18n"
|
|
1179
|
+
]);
|
|
1180
|
+
/** Where the rewritten call reads `__gemi_dict__` from.
|
|
1181
|
+
*
|
|
1182
|
+
* `gemi/dictionary` is a deliberately tiny entrypoint holding only the registry
|
|
1183
|
+
* and the handle factory: it is in `GEMI_EXTERNAL_SPECIFIERS`, so under SSR it
|
|
1184
|
+
* resolves to the server's own instance and the registry the view router
|
|
1185
|
+
* preloads through is the same one the views register into. Pointing this at a
|
|
1186
|
+
* bundled copy instead would give the server two registries.
|
|
1187
|
+
*/
|
|
1188
|
+
var RUNTIME_SOURCE = "gemi/dictionary";
|
|
1189
|
+
function gemiDictionaryPlugin() {
|
|
1190
|
+
const extracted = /* @__PURE__ */ new Map();
|
|
1191
|
+
return {
|
|
1192
|
+
name: "gemi-plugin-dictionary",
|
|
1193
|
+
enforce: "post",
|
|
1194
|
+
resolveId(id) {
|
|
1195
|
+
if (id.startsWith(VIRTUAL_PREFIX)) return `\0${id}`;
|
|
1196
|
+
return null;
|
|
1197
|
+
},
|
|
1198
|
+
async load(id) {
|
|
1199
|
+
if (!id.startsWith(RESOLVED_PREFIX)) return null;
|
|
1200
|
+
const rest = id.slice(19);
|
|
1201
|
+
const slash = rest.lastIndexOf("/");
|
|
1202
|
+
const virtualKey = rest.slice(0, slash);
|
|
1203
|
+
const locale = rest.slice(slash + 1);
|
|
1204
|
+
let entry = extracted.get(virtualKey);
|
|
1205
|
+
if (!entry) {
|
|
1206
|
+
const sourceId = decodeSourceId(virtualKey);
|
|
1207
|
+
if (sourceId) {
|
|
1208
|
+
try {
|
|
1209
|
+
await this.load({ id: sourceId });
|
|
1210
|
+
} catch {}
|
|
1211
|
+
entry = extracted.get(virtualKey);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
if (!entry) {
|
|
1215
|
+
this.error(`No dictionary registered for "${virtualKey}". If this persists, restart the dev server.`);
|
|
1216
|
+
return null;
|
|
1217
|
+
}
|
|
1218
|
+
const strings = localeStrings(entry.translations, locale, entry.locales);
|
|
1219
|
+
return `export default ${JSON.stringify(strings)};\n`;
|
|
1220
|
+
},
|
|
1221
|
+
async transform(code, id) {
|
|
1222
|
+
if (!code.includes("defineDictionary")) return null;
|
|
1223
|
+
if (id.startsWith("\0") || id.includes("/node_modules/")) return null;
|
|
1224
|
+
const ast = await parseAstAsync$1(code);
|
|
1225
|
+
const localNames = /* @__PURE__ */ new Set();
|
|
1226
|
+
for (const node of ast.body) {
|
|
1227
|
+
if (node.type !== "ImportDeclaration") continue;
|
|
1228
|
+
if (!DICTIONARY_SOURCES.has(node.source?.value)) continue;
|
|
1229
|
+
for (const spec of node.specifiers ?? []) if (spec.type === "ImportSpecifier" && spec.imported?.name === "defineDictionary") localNames.add(spec.local.name);
|
|
1230
|
+
}
|
|
1231
|
+
const calls = [];
|
|
1232
|
+
let unresolved = 0;
|
|
1233
|
+
walk(ast, (node) => {
|
|
1234
|
+
if (node.type !== "CallExpression") return;
|
|
1235
|
+
const callee = node.callee;
|
|
1236
|
+
if (callee?.type === "Identifier" && localNames.has(callee.name)) {
|
|
1237
|
+
calls.push(node);
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
if ((callee?.type === "Identifier" ? callee.name : callee?.type === "MemberExpression" && !callee.computed ? callee.property?.name : void 0) === "defineDictionary") unresolved++;
|
|
1241
|
+
});
|
|
1242
|
+
if (unresolved > 0 && declaresOwn(ast, "defineDictionary")) unresolved = 0;
|
|
1243
|
+
if (unresolved > 0) this.warn(`${id}: ${unresolved} defineDictionary() call(s) could not be traced to an import of "gemi/dictionary", "gemi/client" or "gemi/i18n", so their locales were left inline and will all ship to the browser. Import defineDictionary directly by name rather than through a namespace import or a local re-export.`);
|
|
1244
|
+
if (calls.length === 0) return null;
|
|
1245
|
+
const s = new MagicString(code);
|
|
1246
|
+
let rewrote = false;
|
|
1247
|
+
for (const call of calls) {
|
|
1248
|
+
if (call.arguments?.length < 1 || call.arguments?.length > 2) this.error({
|
|
1249
|
+
message: `defineDictionary() takes an object literal and an optional options object.`,
|
|
1250
|
+
pos: call.start
|
|
1251
|
+
});
|
|
1252
|
+
const translations = readObjectLiteral(call.arguments[0], (message) => this.error({
|
|
1253
|
+
message,
|
|
1254
|
+
pos: call.arguments[0]?.start ?? call.start
|
|
1255
|
+
}));
|
|
1256
|
+
const sourceLocale = readSourceLocale(call.arguments[1], (message) => this.error({
|
|
1257
|
+
message,
|
|
1258
|
+
pos: call.arguments[1]?.start ?? call.start
|
|
1259
|
+
}));
|
|
1260
|
+
const runtimeId = dictionaryId(translations);
|
|
1261
|
+
const virtualKey = `${Buffer.from(id).toString("base64url")}/${runtimeId}`;
|
|
1262
|
+
const locales = dictionaryLocales(translations, sourceLocale);
|
|
1263
|
+
if (locales.length === 0) this.error({
|
|
1264
|
+
message: `defineDictionary() declares no locales — every key needs at least one "<locale>": "<string>" entry.`,
|
|
1265
|
+
pos: call.start
|
|
1266
|
+
});
|
|
1267
|
+
if (!sourceLocale) {
|
|
1268
|
+
const clash = findSourceDisagreement(translations);
|
|
1269
|
+
if (clash) this.error({
|
|
1270
|
+
message: `defineDictionary() cannot infer a source language. Key "${clash.againstKey}" lists "${clash.againstFirst}" first but "${clash.key}" lists "${clash.first}" first, so the locale every key falls back to depends on the order they are written in — moving one key would change what language a reader sees. Pass { sourceLocale: "<locale>" } as the second argument to pin it.`,
|
|
1271
|
+
pos: call.start
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
extracted.set(virtualKey, {
|
|
1275
|
+
id: runtimeId,
|
|
1276
|
+
locales,
|
|
1277
|
+
translations
|
|
1278
|
+
});
|
|
1279
|
+
const loaders = locales.map((locale) => `${JSON.stringify(locale)}:()=>import(${JSON.stringify(`${VIRTUAL_PREFIX}${virtualKey}/${locale}`)})`).join(",");
|
|
1280
|
+
s.overwrite(call.start, call.end, `__gemi_dict__(${JSON.stringify(runtimeId)},{${loaders}})`);
|
|
1281
|
+
rewrote = true;
|
|
1282
|
+
}
|
|
1283
|
+
if (!rewrote) return null;
|
|
1284
|
+
s.append(`\nimport { __gemi_dict__ } from ${JSON.stringify(RUNTIME_SOURCE)};\n`);
|
|
1285
|
+
return {
|
|
1286
|
+
code: s.toString(),
|
|
1287
|
+
map: s.generateMap({ hires: true })
|
|
1288
|
+
};
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* The virtual key carries the source module alongside the content hash, so a
|
|
1294
|
+
* cold `load` can find its way back to the module that declared it.
|
|
1295
|
+
*/
|
|
1296
|
+
function decodeSourceId(virtualKey) {
|
|
1297
|
+
const slash = virtualKey.indexOf("/");
|
|
1298
|
+
if (slash === -1) return null;
|
|
1299
|
+
try {
|
|
1300
|
+
return Buffer.from(virtualKey.slice(0, slash), "base64url").toString("utf8");
|
|
1301
|
+
} catch {
|
|
1302
|
+
return null;
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
/**
|
|
1306
|
+
* A dictionary has to be readable at build time, so the literal must be fully
|
|
1307
|
+
* static. Anything else fails the build with the offending key named — a silent
|
|
1308
|
+
* fallback to "leave this one un-split" would ship every locale to the browser
|
|
1309
|
+
* and nobody would notice.
|
|
1310
|
+
*/
|
|
1311
|
+
function readObjectLiteral(node, fail) {
|
|
1312
|
+
if (node?.type !== "ObjectExpression") fail(`defineDictionary() needs an inline object literal — it is read at build time, so a variable or spread cannot be resolved.`);
|
|
1313
|
+
const out = {};
|
|
1314
|
+
for (const prop of node.properties) {
|
|
1315
|
+
const key = propertyName(prop);
|
|
1316
|
+
if (key === null) fail(`defineDictionary() keys must be plain string keys — computed keys and spreads cannot be read at build time.`);
|
|
1317
|
+
if (prop.value?.type !== "ObjectExpression") fail(`defineDictionary() entry "${key}" must be an object of "<locale>": "<string>" pairs.`);
|
|
1318
|
+
const byLocale = {};
|
|
1319
|
+
for (const localeProp of prop.value.properties) {
|
|
1320
|
+
const locale = propertyName(localeProp);
|
|
1321
|
+
if (locale === null) fail(`defineDictionary() entry "${key}" has a locale key that cannot be read at build time.`);
|
|
1322
|
+
const value = localeProp.value;
|
|
1323
|
+
if (value?.type !== "Literal" || typeof value.value !== "string") fail(`defineDictionary() entry "${key}" locale "${locale}" must be a string literal. Use {{param}} interpolation instead of a template literal or a function.`);
|
|
1324
|
+
byLocale[locale] = value.value;
|
|
1325
|
+
}
|
|
1326
|
+
out[key] = byLocale;
|
|
1327
|
+
}
|
|
1328
|
+
return out;
|
|
1329
|
+
}
|
|
1330
|
+
/** The `sourceLocale` from `defineDictionary`'s optional options argument. */
|
|
1331
|
+
function readSourceLocale(node, fail) {
|
|
1332
|
+
if (node === void 0) return;
|
|
1333
|
+
if (node.type !== "ObjectExpression") fail(`defineDictionary() options must be an inline object literal — it is read at build time.`);
|
|
1334
|
+
for (const prop of node.properties) {
|
|
1335
|
+
if (propertyName(prop) !== "sourceLocale") continue;
|
|
1336
|
+
const value = prop.value;
|
|
1337
|
+
if (value?.type !== "Literal" || typeof value.value !== "string") fail(`defineDictionary() sourceLocale must be a string literal.`);
|
|
1338
|
+
return value.value;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
/** Whether the module declares `name` itself, rather than importing it. */
|
|
1342
|
+
function declaresOwn(ast, name) {
|
|
1343
|
+
let found = false;
|
|
1344
|
+
walk(ast, (node) => {
|
|
1345
|
+
if (found) return;
|
|
1346
|
+
if (node.type === "FunctionDeclaration" && node.id?.name === name) found = true;
|
|
1347
|
+
if (node.type === "VariableDeclarator" && node.id?.name === name) found = true;
|
|
1348
|
+
});
|
|
1349
|
+
return found;
|
|
1350
|
+
}
|
|
1351
|
+
function propertyName(prop) {
|
|
1352
|
+
if (prop?.type !== "Property" || prop.computed) return null;
|
|
1353
|
+
if (prop.key?.type === "Identifier") return prop.key.name;
|
|
1354
|
+
if (prop.key?.type === "Literal" && typeof prop.key.value === "string") return prop.key.value;
|
|
1355
|
+
return null;
|
|
1356
|
+
}
|
|
1357
|
+
/** Minimal ESTree walk — enough to find call expressions, no extra dependency. */
|
|
1358
|
+
function walk(node, visit) {
|
|
1359
|
+
if (node === null || typeof node !== "object") return;
|
|
1360
|
+
if (Array.isArray(node)) {
|
|
1361
|
+
for (const child of node) walk(child, visit);
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
if (typeof node.type === "string") visit(node);
|
|
1365
|
+
for (const key of Object.keys(node)) {
|
|
1366
|
+
if (key === "parent") continue;
|
|
1367
|
+
const value = node[key];
|
|
1368
|
+
if (value && typeof value === "object") walk(value, visit);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
//#endregion
|
|
25
1372
|
//#region vite/index.ts
|
|
26
1373
|
var gemi = async () => {
|
|
27
1374
|
const { plugins: userVitePlugins = [], ...userViteConfig } = (await loadGemiConfig(process.cwd())).vite ?? {};
|
|
@@ -57,7 +1404,8 @@ var gemi = async () => {
|
|
|
57
1404
|
if (modules?.[0]?.id?.includes("/app/http/")) return [];
|
|
58
1405
|
}
|
|
59
1406
|
},
|
|
60
|
-
...userVitePlugins
|
|
1407
|
+
...userVitePlugins,
|
|
1408
|
+
gemiDictionaryPlugin()
|
|
61
1409
|
];
|
|
62
1410
|
};
|
|
63
1411
|
//#endregion
|