@mica-js/editor 0.3.3 → 0.4.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/README.md +96 -1
- package/dist/fused-html.d.ts +849 -0
- package/dist/fused-html.js +1 -0
- package/dist/fused-runtime.d.ts +685 -0
- package/dist/fused-runtime.js +3 -0
- package/dist/fused.d.ts +537 -0
- package/dist/fused.js +6725 -0
- package/dist/fused.js.map +1 -0
- package/dist/html-HXwZq1my.js +1618 -0
- package/dist/html-HXwZq1my.js.map +1 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.js +174 -280
- package/dist/index.js.map +1 -1
- package/dist/runtime-CXYJzbbj.js +1739 -0
- package/dist/runtime-CXYJzbbj.js.map +1 -0
- package/dist/style.css +1486 -0
- package/dist/view-environment/content.html +36 -0
- package/dist/view-environment/content.js +666 -0
- package/dist/view-environment/environment-sw.js +632 -0
- package/dist/view-environment/environment.js +783 -0
- package/dist/view-environment/index.html +32 -0
- package/dist/wire-BDHL5Aj9.js +183 -0
- package/dist/wire-BDHL5Aj9.js.map +1 -0
- package/dist/wire-JZIiIOI0.js +260 -0
- package/dist/wire-JZIiIOI0.js.map +1 -0
- package/dist/workers-BsocIPUc.js +34 -0
- package/dist/workers-BsocIPUc.js.map +1 -0
- package/package.json +41 -5
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
//#region ../core/src/lifecycle/index.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
let t = !1;
|
|
4
|
+
return { dispose() {
|
|
5
|
+
t || (t = !0, e());
|
|
6
|
+
} };
|
|
7
|
+
}
|
|
8
|
+
var t = class {
|
|
9
|
+
#e = /* @__PURE__ */ new Set();
|
|
10
|
+
#t = !1;
|
|
11
|
+
event = (t, n, r) => {
|
|
12
|
+
if (this.#t) return e(() => {});
|
|
13
|
+
let i = {
|
|
14
|
+
listener: t,
|
|
15
|
+
thisArgs: n
|
|
16
|
+
};
|
|
17
|
+
this.#e.add(i);
|
|
18
|
+
let a = e(() => {
|
|
19
|
+
this.#e.delete(i);
|
|
20
|
+
});
|
|
21
|
+
return r?.push(a), a;
|
|
22
|
+
};
|
|
23
|
+
get hasListeners() {
|
|
24
|
+
return this.#e.size > 0;
|
|
25
|
+
}
|
|
26
|
+
fire(e) {
|
|
27
|
+
if (!this.#t) for (let t of [...this.#e]) t.listener.call(t.thisArgs, e);
|
|
28
|
+
}
|
|
29
|
+
dispose() {
|
|
30
|
+
this.#t || (this.#t = !0, this.#e.clear());
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region ../core/src/rpc/protocol.ts
|
|
35
|
+
function n(e) {
|
|
36
|
+
if (typeof e != "object" || !e || Array.isArray(e)) return !1;
|
|
37
|
+
let t = e;
|
|
38
|
+
if (t.kind === "close") return !0;
|
|
39
|
+
if (!Number.isSafeInteger(t.id) || t.id <= 0) return !1;
|
|
40
|
+
switch (t.kind) {
|
|
41
|
+
case "call":
|
|
42
|
+
case "listen": return typeof t.service == "string" && t.service.length > 0 && typeof t.member == "string" && t.member.length > 0 && Array.isArray(t.args) && (t.kind !== "listen" || t.args.length === 0);
|
|
43
|
+
case "unlisten": return !0;
|
|
44
|
+
case "result": return Object.hasOwn(t, "value");
|
|
45
|
+
case "error":
|
|
46
|
+
case "subscription-error": return typeof t.name == "string" && typeof t.message == "string";
|
|
47
|
+
case "event": return Array.isArray(t.args);
|
|
48
|
+
default: return !1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region ../core/src/rpc/rpc.ts
|
|
53
|
+
function r(e, t) {
|
|
54
|
+
return Object.assign(Error(t), { name: e });
|
|
55
|
+
}
|
|
56
|
+
function i(e, t) {
|
|
57
|
+
if ([
|
|
58
|
+
"constructor",
|
|
59
|
+
"__proto__",
|
|
60
|
+
"prototype",
|
|
61
|
+
"then"
|
|
62
|
+
].includes(t)) throw r("MethodNotFound", `Method is not exposed: ${t}`);
|
|
63
|
+
for (let n = e; n && n !== Object.prototype; n = Object.getPrototypeOf(n)) {
|
|
64
|
+
let e = Object.getOwnPropertyDescriptor(n, t);
|
|
65
|
+
if (e) {
|
|
66
|
+
if (typeof e.value == "function") return e.value;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
throw r("MethodNotFound", `Method is not callable: ${t}`);
|
|
71
|
+
}
|
|
72
|
+
function a(a, l = {}) {
|
|
73
|
+
let u = l, d = c(u.timeoutMs ?? 0), f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Map(), g = new t(), _ = new t(), v = 0, y = 0, b = !1;
|
|
74
|
+
function x(e) {
|
|
75
|
+
let t = o(e);
|
|
76
|
+
try {
|
|
77
|
+
u.onError?.(t);
|
|
78
|
+
} catch {}
|
|
79
|
+
g.fire(t);
|
|
80
|
+
}
|
|
81
|
+
function S() {
|
|
82
|
+
if (b) throw r("RpcDisconnectedError", "RPC endpoint is closed");
|
|
83
|
+
}
|
|
84
|
+
function C() {
|
|
85
|
+
if (v === 2 ** 53 - 1) throw RangeError("RPC request IDs exhausted");
|
|
86
|
+
return ++v;
|
|
87
|
+
}
|
|
88
|
+
function w(e, t) {
|
|
89
|
+
S(), a.postMessage(e, t ? [...t] : void 0);
|
|
90
|
+
}
|
|
91
|
+
function T(e) {
|
|
92
|
+
let t = p.get(e);
|
|
93
|
+
return p.delete(e), t?.timer !== void 0 && clearTimeout(t.timer), t;
|
|
94
|
+
}
|
|
95
|
+
function E(e, t, n) {
|
|
96
|
+
return new Promise((i, a) => {
|
|
97
|
+
let s = t > 0 ? setTimeout(() => {
|
|
98
|
+
T(e.id)?.reject(r("RpcTimeoutError", `RPC ${e.service}.${e.member} timed out`));
|
|
99
|
+
}, t) : void 0;
|
|
100
|
+
p.set(e.id, {
|
|
101
|
+
resolve: i,
|
|
102
|
+
reject: a,
|
|
103
|
+
timer: s
|
|
104
|
+
});
|
|
105
|
+
try {
|
|
106
|
+
w(e, n);
|
|
107
|
+
} catch (t) {
|
|
108
|
+
T(e.id)?.reject(o(t));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function D(e) {
|
|
113
|
+
let t = h.get(e);
|
|
114
|
+
h.delete(e);
|
|
115
|
+
try {
|
|
116
|
+
t?.stop?.();
|
|
117
|
+
} catch (e) {
|
|
118
|
+
x(e);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
function O(e, t, n) {
|
|
122
|
+
if (b) return;
|
|
123
|
+
let r = o(n);
|
|
124
|
+
try {
|
|
125
|
+
w({
|
|
126
|
+
kind: e,
|
|
127
|
+
id: t,
|
|
128
|
+
name: r.name,
|
|
129
|
+
message: r.message
|
|
130
|
+
});
|
|
131
|
+
} catch (e) {
|
|
132
|
+
x(e), A();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function k() {
|
|
136
|
+
if (!b) {
|
|
137
|
+
b = !0, a.removeEventListener("message", M), a.removeEventListener("close", k), a.removeEventListener("messageerror", A);
|
|
138
|
+
for (let e of p.keys()) T(e)?.reject(r("RpcDisconnectedError", "RPC endpoint is closed"));
|
|
139
|
+
m.clear();
|
|
140
|
+
for (let e of h.keys()) D(e);
|
|
141
|
+
f.clear(), _.fire(void 0), _.dispose(), g.dispose();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function A() {
|
|
145
|
+
if (!b) {
|
|
146
|
+
try {
|
|
147
|
+
w({ kind: "close" });
|
|
148
|
+
} catch (e) {
|
|
149
|
+
x(e);
|
|
150
|
+
}
|
|
151
|
+
k();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async function j(e) {
|
|
155
|
+
try {
|
|
156
|
+
let t = f.get(e.service);
|
|
157
|
+
if (!t) throw r("ServiceNotFound", `Unknown service: ${e.service}`);
|
|
158
|
+
let n = t.implementation, a = i(n, e.member);
|
|
159
|
+
if (e.kind === "listen") {
|
|
160
|
+
if (!/^onDid[A-Z]/.test(e.member)) throw r("InvalidSubscription", "Event members must start with onDid");
|
|
161
|
+
let i = {
|
|
162
|
+
registration: t,
|
|
163
|
+
stop: void 0
|
|
164
|
+
};
|
|
165
|
+
h.set(e.id, i);
|
|
166
|
+
let o = a.call(n, (...n) => {
|
|
167
|
+
if (!(b || h.get(e.id) !== i)) try {
|
|
168
|
+
w({
|
|
169
|
+
kind: "event",
|
|
170
|
+
id: e.id,
|
|
171
|
+
args: n
|
|
172
|
+
}, t.options.transfer?.(e.member, n));
|
|
173
|
+
} catch (t) {
|
|
174
|
+
D(e.id), O("subscription-error", e.id, t);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
if (typeof o != "function") throw r("InvalidSubscription", "Event registration must return an unsubscribe function");
|
|
178
|
+
i.stop = o, h.get(e.id) !== i && i.stop(), b || w({
|
|
179
|
+
kind: "result",
|
|
180
|
+
id: e.id,
|
|
181
|
+
value: void 0
|
|
182
|
+
});
|
|
183
|
+
} else {
|
|
184
|
+
if (/^onDid[A-Z]/.test(e.member)) throw r("InvalidCall", "Event members require a subscription");
|
|
185
|
+
let i = await a.apply(n, e.args);
|
|
186
|
+
b || w({
|
|
187
|
+
kind: "result",
|
|
188
|
+
id: e.id,
|
|
189
|
+
value: i
|
|
190
|
+
}, t.options.transfer?.(e.member, i));
|
|
191
|
+
}
|
|
192
|
+
} catch (t) {
|
|
193
|
+
e.kind === "listen" && D(e.id), O("error", e.id, t);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function M(e) {
|
|
197
|
+
let t = e.data;
|
|
198
|
+
if (!n(t)) x(r("RpcProtocolError", "Malformed RPC message"));
|
|
199
|
+
else switch (t.kind) {
|
|
200
|
+
case "call":
|
|
201
|
+
case "listen":
|
|
202
|
+
if (t.id <= y) {
|
|
203
|
+
x(r("RpcProtocolError", "Request IDs must increase"));
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
y = t.id, j(t);
|
|
207
|
+
break;
|
|
208
|
+
case "unlisten":
|
|
209
|
+
D(t.id);
|
|
210
|
+
break;
|
|
211
|
+
case "result":
|
|
212
|
+
T(t.id)?.resolve(t.value);
|
|
213
|
+
break;
|
|
214
|
+
case "error":
|
|
215
|
+
T(t.id)?.reject(r(t.name, t.message));
|
|
216
|
+
break;
|
|
217
|
+
case "subscription-error": {
|
|
218
|
+
let e = r(t.name, t.message), n = m.delete(t.id), i = T(t.id);
|
|
219
|
+
i ? i.reject(e) : n && x(e);
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
case "event":
|
|
223
|
+
try {
|
|
224
|
+
m.get(t.id)?.(...t.args);
|
|
225
|
+
} catch (e) {
|
|
226
|
+
x(e);
|
|
227
|
+
}
|
|
228
|
+
break;
|
|
229
|
+
case "close": k();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return a.addEventListener("message", M), a.addEventListener("close", k), a.addEventListener("messageerror", A), a.start?.(), {
|
|
233
|
+
register(t, n, i = {}) {
|
|
234
|
+
S();
|
|
235
|
+
let a = s(t);
|
|
236
|
+
if (typeof n != "object" || !n) throw TypeError("RPC services must be objects");
|
|
237
|
+
if (f.has(a)) throw Error(`Service already registered: ${a}`);
|
|
238
|
+
let o = {
|
|
239
|
+
implementation: n,
|
|
240
|
+
options: i
|
|
241
|
+
};
|
|
242
|
+
return f.set(a, o), e(() => {
|
|
243
|
+
if (f.get(a) === o) {
|
|
244
|
+
f.delete(a);
|
|
245
|
+
for (let [e, t] of h) t.registration === o && (D(e), O("subscription-error", e, r("ServiceUnregistered", `Service unregistered: ${a}`)));
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
},
|
|
249
|
+
getProxy(t, n = {}) {
|
|
250
|
+
let r = s(t), i = c(n.timeoutMs ?? d), a = /* @__PURE__ */ new Map();
|
|
251
|
+
return new Proxy(Object.create(null), { get(t, o) {
|
|
252
|
+
if (typeof o == "string" && o !== "then") return a.has(o) || a.set(o, /^onDid[A-Z]/.test(o) ? (t) => {
|
|
253
|
+
if (S(), typeof t != "function") throw TypeError("Expected an event listener");
|
|
254
|
+
let n = C();
|
|
255
|
+
m.set(n, t), E({
|
|
256
|
+
kind: "listen",
|
|
257
|
+
id: n,
|
|
258
|
+
service: r,
|
|
259
|
+
member: o,
|
|
260
|
+
args: []
|
|
261
|
+
}, i).catch((e) => {
|
|
262
|
+
if (m.delete(n), !b) try {
|
|
263
|
+
w({
|
|
264
|
+
kind: "unlisten",
|
|
265
|
+
id: n
|
|
266
|
+
});
|
|
267
|
+
} catch (e) {
|
|
268
|
+
x(e);
|
|
269
|
+
}
|
|
270
|
+
x(e);
|
|
271
|
+
});
|
|
272
|
+
let a = e(() => {
|
|
273
|
+
if (m.delete(n) && (T(n)?.resolve(void 0), !b)) try {
|
|
274
|
+
w({
|
|
275
|
+
kind: "unlisten",
|
|
276
|
+
id: n
|
|
277
|
+
});
|
|
278
|
+
} catch (e) {
|
|
279
|
+
x(e);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
return () => a.dispose();
|
|
283
|
+
} : async (...e) => (S(), E({
|
|
284
|
+
kind: "call",
|
|
285
|
+
id: C(),
|
|
286
|
+
service: r,
|
|
287
|
+
member: o,
|
|
288
|
+
args: e
|
|
289
|
+
}, i, n.transfer?.(o, e)))), a.get(o);
|
|
290
|
+
} });
|
|
291
|
+
},
|
|
292
|
+
onDidError: (e, t, n) => g.event((n) => {
|
|
293
|
+
try {
|
|
294
|
+
e.call(t, n);
|
|
295
|
+
} catch {}
|
|
296
|
+
}, void 0, n),
|
|
297
|
+
onDidClose: (t, n, r) => b ? (t.call(n, void 0), e(() => {})) : _.event((e) => {
|
|
298
|
+
try {
|
|
299
|
+
t.call(n, e);
|
|
300
|
+
} catch (e) {
|
|
301
|
+
x(e);
|
|
302
|
+
}
|
|
303
|
+
}, void 0, r),
|
|
304
|
+
dispose: A
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
function o(e) {
|
|
308
|
+
return e instanceof Error ? e : Error(String(e));
|
|
309
|
+
}
|
|
310
|
+
function s(e) {
|
|
311
|
+
if (typeof e != "string" || e.length === 0) throw TypeError("RPC service name must be nonempty");
|
|
312
|
+
return e;
|
|
313
|
+
}
|
|
314
|
+
function c(e) {
|
|
315
|
+
if (!Number.isSafeInteger(e) || e < 0 || e > 2147483647) throw RangeError("RPC timeout must be an integer between 0 and 2147483647");
|
|
316
|
+
return e;
|
|
317
|
+
}
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region ../core/src/rpc/types.ts
|
|
320
|
+
function l(e) {
|
|
321
|
+
if (typeof e != "string" || e.length === 0) throw TypeError("RPC service name must be nonempty");
|
|
322
|
+
return e;
|
|
323
|
+
}
|
|
324
|
+
var u = "mica:view:assets-ack", d = "mica:view:attach-ack";
|
|
325
|
+
l("fused-html-host"), l("fused-html-host-control");
|
|
326
|
+
var f = l("fused-html-asset");
|
|
327
|
+
l("fused-html-content-view");
|
|
328
|
+
//#endregion
|
|
329
|
+
//#region ../document/src/fused/rules.ts
|
|
330
|
+
var p = /^[A-Za-z]:/, m = /^[A-Za-z][A-Za-z0-9+.-]*:/;
|
|
331
|
+
function h(e) {
|
|
332
|
+
for (let t of e) {
|
|
333
|
+
let e = t.codePointAt(0) ?? 0;
|
|
334
|
+
if (e < 32 || e === 127) return !0;
|
|
335
|
+
}
|
|
336
|
+
return !1;
|
|
337
|
+
}
|
|
338
|
+
function g(e) {
|
|
339
|
+
return _(e, "package root");
|
|
340
|
+
}
|
|
341
|
+
function _(e, t) {
|
|
342
|
+
if (e.length === 0) return "must not be empty";
|
|
343
|
+
if (e.startsWith("/")) return `must be relative to the ${t}, not absolute`;
|
|
344
|
+
if (p.test(e)) return "must not carry a drive letter";
|
|
345
|
+
if (m.test(e)) return "must not be a URL";
|
|
346
|
+
if (e.includes("\\")) return "must use POSIX separators";
|
|
347
|
+
if (h(e)) return "must not contain control characters";
|
|
348
|
+
let n = e.split("/");
|
|
349
|
+
if (n[n.length - 1] === "") return "must name a file, not a directory";
|
|
350
|
+
for (let e of n) {
|
|
351
|
+
if (e.length === 0) return "must not contain empty segments";
|
|
352
|
+
if (e === "." || e === "..") return `must not contain "${e}" segments`;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
//#endregion
|
|
356
|
+
//#region src/fused/html/paths.ts
|
|
357
|
+
var v = "__mica_package__/";
|
|
358
|
+
[
|
|
359
|
+
"default-src 'none'",
|
|
360
|
+
"script-src 'self' 'unsafe-inline'",
|
|
361
|
+
"style-src 'self' 'unsafe-inline'",
|
|
362
|
+
"img-src 'self' data: blob:",
|
|
363
|
+
"font-src 'self' data: blob:",
|
|
364
|
+
"media-src 'self' data: blob:",
|
|
365
|
+
"connect-src 'self' blob:",
|
|
366
|
+
"frame-src 'none'",
|
|
367
|
+
"object-src 'none'",
|
|
368
|
+
"form-action 'none'",
|
|
369
|
+
"base-uri 'self'"
|
|
370
|
+
].join("; "), [
|
|
371
|
+
"default-src 'none'",
|
|
372
|
+
"script-src 'self' 'unsafe-inline'",
|
|
373
|
+
"style-src 'self' 'unsafe-inline'",
|
|
374
|
+
"img-src 'self' data: blob:",
|
|
375
|
+
"font-src 'self' data: blob:",
|
|
376
|
+
"media-src 'self' data: blob:",
|
|
377
|
+
"connect-src 'self' blob:",
|
|
378
|
+
"worker-src 'self'",
|
|
379
|
+
"frame-src 'self'",
|
|
380
|
+
"object-src 'none'",
|
|
381
|
+
"form-action 'none'",
|
|
382
|
+
"base-uri 'self'"
|
|
383
|
+
].join("; ");
|
|
384
|
+
function y(e, t) {
|
|
385
|
+
let n = t.endsWith("/") ? t : `${t}/`;
|
|
386
|
+
if (!e.startsWith(n)) return;
|
|
387
|
+
let r = e.slice(n.length);
|
|
388
|
+
if (r.length === 0) return;
|
|
389
|
+
let i = [];
|
|
390
|
+
for (let e of r.split("/")) {
|
|
391
|
+
let t;
|
|
392
|
+
try {
|
|
393
|
+
t = decodeURIComponent(e);
|
|
394
|
+
} catch {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (t.length === 0 || t === "." || t === ".." || t.includes("/") || t.includes("\\")) return;
|
|
398
|
+
i.push(t);
|
|
399
|
+
}
|
|
400
|
+
let a = i.join("/");
|
|
401
|
+
return g(a) === void 0 ? a : void 0;
|
|
402
|
+
}
|
|
403
|
+
var b = Object.freeze({
|
|
404
|
+
html: "text/html; charset=utf-8",
|
|
405
|
+
htm: "text/html; charset=utf-8",
|
|
406
|
+
js: "text/javascript; charset=utf-8",
|
|
407
|
+
mjs: "text/javascript; charset=utf-8",
|
|
408
|
+
css: "text/css; charset=utf-8",
|
|
409
|
+
json: "application/json; charset=utf-8",
|
|
410
|
+
map: "application/json; charset=utf-8",
|
|
411
|
+
svg: "image/svg+xml",
|
|
412
|
+
png: "image/png",
|
|
413
|
+
jpg: "image/jpeg",
|
|
414
|
+
jpeg: "image/jpeg",
|
|
415
|
+
gif: "image/gif",
|
|
416
|
+
webp: "image/webp",
|
|
417
|
+
avif: "image/avif",
|
|
418
|
+
ico: "image/x-icon",
|
|
419
|
+
woff: "font/woff",
|
|
420
|
+
woff2: "font/woff2",
|
|
421
|
+
ttf: "font/ttf",
|
|
422
|
+
otf: "font/otf",
|
|
423
|
+
wasm: "application/wasm",
|
|
424
|
+
txt: "text/plain; charset=utf-8",
|
|
425
|
+
bin: "application/octet-stream"
|
|
426
|
+
});
|
|
427
|
+
function x(e) {
|
|
428
|
+
let t = e.lastIndexOf(".");
|
|
429
|
+
return t <= 0 ? "application/octet-stream" : b[e.slice(t + 1).toLowerCase()] ?? "application/octet-stream";
|
|
430
|
+
}
|
|
431
|
+
function S(e) {
|
|
432
|
+
let t = new Uint8Array(e.byteLength);
|
|
433
|
+
return t.set(e), t.buffer;
|
|
434
|
+
}
|
|
435
|
+
//#endregion
|
|
436
|
+
//#region src/fused/html/environment/asset-grant.ts
|
|
437
|
+
var C = 16, w = /* @__PURE__ */ new Set(["nested"]), T = class {
|
|
438
|
+
#e;
|
|
439
|
+
#t;
|
|
440
|
+
#n;
|
|
441
|
+
constructor(e) {
|
|
442
|
+
this.#e = j(e), this.#t = new URL(e).origin;
|
|
443
|
+
}
|
|
444
|
+
get scope() {
|
|
445
|
+
return this.#e;
|
|
446
|
+
}
|
|
447
|
+
get active() {
|
|
448
|
+
return this.#n === void 0 ? void 0 : E(this.#n);
|
|
449
|
+
}
|
|
450
|
+
grant(e, t) {
|
|
451
|
+
let n = D(e), r = O(e), i = A(t);
|
|
452
|
+
if (n !== void 0 && r !== void 0 && i !== void 0 && M(r, this.#e) && this.#r(t)) return this.#n = {
|
|
453
|
+
token: n,
|
|
454
|
+
root: r,
|
|
455
|
+
parentClientId: i,
|
|
456
|
+
childClientId: void 0
|
|
457
|
+
}, E(this.#n);
|
|
458
|
+
}
|
|
459
|
+
attach(e, t) {
|
|
460
|
+
let n = this.#n;
|
|
461
|
+
if (n === void 0) return;
|
|
462
|
+
let r = D(e), i = A(t);
|
|
463
|
+
if (r !== void 0 && r === n.token && i !== void 0 && k(t) && this.#r(t)) return i !== n.parentClientId && (n.childClientId = i), E(n);
|
|
464
|
+
}
|
|
465
|
+
#r(e) {
|
|
466
|
+
let t = e?.url;
|
|
467
|
+
if (t === void 0 || t === "") return !0;
|
|
468
|
+
let n;
|
|
469
|
+
try {
|
|
470
|
+
n = new URL(t);
|
|
471
|
+
} catch {
|
|
472
|
+
return !1;
|
|
473
|
+
}
|
|
474
|
+
return n.origin === this.#t && M(n.pathname, this.#e);
|
|
475
|
+
}
|
|
476
|
+
serves(e) {
|
|
477
|
+
let t = this.#n;
|
|
478
|
+
if (t === void 0) return;
|
|
479
|
+
let n = A({ id: e });
|
|
480
|
+
if (n !== void 0) return n === t.parentClientId || n === t.childClientId ? t.root : void 0;
|
|
481
|
+
}
|
|
482
|
+
clear() {
|
|
483
|
+
this.#n = void 0;
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
function E(e) {
|
|
487
|
+
return Object.freeze({
|
|
488
|
+
token: e.token,
|
|
489
|
+
root: e.root,
|
|
490
|
+
parentClientId: e.parentClientId,
|
|
491
|
+
childClientId: e.childClientId
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
function D(e) {
|
|
495
|
+
if (typeof e != "object" || !e) return;
|
|
496
|
+
let t = e.token;
|
|
497
|
+
if (!(typeof t != "string" || t.length < C)) return t;
|
|
498
|
+
}
|
|
499
|
+
function O(e) {
|
|
500
|
+
if (typeof e != "object" || !e) return;
|
|
501
|
+
let t = e.root;
|
|
502
|
+
if (typeof t == "string" && t.endsWith("/") && !(!t.startsWith("/") || t.includes("\\") || t.includes("?") || t.includes("#")) && !t.split("/").some((e) => e === "." || e === "..")) return t;
|
|
503
|
+
}
|
|
504
|
+
function k(e) {
|
|
505
|
+
let t = e?.frameType;
|
|
506
|
+
return t === void 0 || w.has(t);
|
|
507
|
+
}
|
|
508
|
+
function A(e) {
|
|
509
|
+
let t = e?.id;
|
|
510
|
+
return typeof t == "string" && t.length > 0 ? t : void 0;
|
|
511
|
+
}
|
|
512
|
+
function j(e) {
|
|
513
|
+
let t = new URL(e).pathname;
|
|
514
|
+
return t.endsWith("/") ? t : `${t}/`;
|
|
515
|
+
}
|
|
516
|
+
function M(e, t) {
|
|
517
|
+
let n = t.endsWith("/") ? t : `${t}/`;
|
|
518
|
+
return e !== n && e.startsWith(n);
|
|
519
|
+
}
|
|
520
|
+
//#endregion
|
|
521
|
+
//#region src/fused/html/environment/asset-response.ts
|
|
522
|
+
async function N(e, t) {
|
|
523
|
+
let n;
|
|
524
|
+
try {
|
|
525
|
+
n = new URL(e.url);
|
|
526
|
+
} catch {
|
|
527
|
+
return I("Unreadable asset request.", 400);
|
|
528
|
+
}
|
|
529
|
+
if (e.destination === "document") return I("Device view navigation is not allowed.", 403);
|
|
530
|
+
if (e.method !== "GET" && e.method !== "HEAD") return new Response(null, {
|
|
531
|
+
status: 405,
|
|
532
|
+
headers: { allow: "GET, HEAD" }
|
|
533
|
+
});
|
|
534
|
+
if (n.origin !== t.origin) return I("Device views reach no other origin.", 404);
|
|
535
|
+
let r = y(n.pathname, t.root);
|
|
536
|
+
if (r === void 0) return I("Package file unavailable.", 404);
|
|
537
|
+
try {
|
|
538
|
+
let n = await t.assets.read(r);
|
|
539
|
+
return new Response(e.method === "HEAD" ? null : S(n), {
|
|
540
|
+
status: 200,
|
|
541
|
+
headers: {
|
|
542
|
+
"content-type": x(r),
|
|
543
|
+
"cache-control": "no-store",
|
|
544
|
+
"x-content-type-options": "nosniff"
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
} catch {
|
|
548
|
+
return I("Package file unavailable.", 404);
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
function P() {
|
|
552
|
+
return I("Package files are reserved for the authorized device view.", 403);
|
|
553
|
+
}
|
|
554
|
+
function F(e, t) {
|
|
555
|
+
let n = t.endsWith("/") ? t.slice(0, -1) : t, r = e;
|
|
556
|
+
try {
|
|
557
|
+
r = decodeURIComponent(e);
|
|
558
|
+
} catch {}
|
|
559
|
+
return r === n || r.startsWith(`${n}/`);
|
|
560
|
+
}
|
|
561
|
+
function I(e, t) {
|
|
562
|
+
return new Response(e, {
|
|
563
|
+
status: t,
|
|
564
|
+
headers: {
|
|
565
|
+
"content-type": "text/plain; charset=utf-8",
|
|
566
|
+
"cache-control": "no-store"
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
//#endregion
|
|
571
|
+
//#region src/fused/html/environment/package-fetch.ts
|
|
572
|
+
function L(e, t) {
|
|
573
|
+
let n;
|
|
574
|
+
try {
|
|
575
|
+
n = new URL(e.request.url);
|
|
576
|
+
} catch {
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (n.origin !== t.origin || !F(n.pathname, t.packagePrefix)) return;
|
|
580
|
+
let r = t.authorizedRoot(e.clientId), i = t.assets;
|
|
581
|
+
r === void 0 || i === void 0 || y(n.pathname, r) === void 0 ? e.respondWith(P()) : e.respondWith(N(e.request, {
|
|
582
|
+
origin: t.origin,
|
|
583
|
+
root: r,
|
|
584
|
+
assets: i
|
|
585
|
+
}));
|
|
586
|
+
}
|
|
587
|
+
//#endregion
|
|
588
|
+
//#region src/fused/html/environment/service-worker.ts
|
|
589
|
+
var R = globalThis, z = new T(R.registration.scope), B = new URL(v, R.registration.scope).pathname, V;
|
|
590
|
+
R.addEventListener("install", () => {
|
|
591
|
+
R.skipWaiting?.();
|
|
592
|
+
}), R.addEventListener("activate", (e) => {
|
|
593
|
+
e.waitUntil(R.clients.claim());
|
|
594
|
+
}), R.addEventListener("message", (e) => {
|
|
595
|
+
let t = e.data;
|
|
596
|
+
typeof t == "object" && t && (t.type === "mica:view:assets" ? H(e) : t.type === "mica:view:attach" && U(e));
|
|
597
|
+
});
|
|
598
|
+
function H(e) {
|
|
599
|
+
let t = e.ports[0];
|
|
600
|
+
if (t === void 0) return;
|
|
601
|
+
let n = z.grant(e.data, e.source);
|
|
602
|
+
if (n === void 0) return;
|
|
603
|
+
V?.endpoint.dispose();
|
|
604
|
+
let r = a(t), i = {
|
|
605
|
+
endpoint: r,
|
|
606
|
+
assets: r.getProxy(f)
|
|
607
|
+
};
|
|
608
|
+
r.onDidClose(() => {
|
|
609
|
+
V === i && (V = void 0);
|
|
610
|
+
}), V = i;
|
|
611
|
+
let o = {
|
|
612
|
+
type: u,
|
|
613
|
+
token: n.token
|
|
614
|
+
};
|
|
615
|
+
e.ports[1]?.postMessage(o);
|
|
616
|
+
}
|
|
617
|
+
function U(e) {
|
|
618
|
+
let t = z.attach(e.data, e.source);
|
|
619
|
+
t !== void 0 && e.ports[0]?.postMessage({
|
|
620
|
+
type: d,
|
|
621
|
+
token: t.token
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
R.addEventListener("fetch", (e) => {
|
|
625
|
+
L(e, {
|
|
626
|
+
origin: R.location.origin,
|
|
627
|
+
packagePrefix: B,
|
|
628
|
+
authorizedRoot: (e) => z.serves(e),
|
|
629
|
+
assets: V?.assets
|
|
630
|
+
});
|
|
631
|
+
});
|
|
632
|
+
//#endregion
|