@mica-js/editor 0.14.0 → 0.15.1
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 +9 -3
- package/dist/fused-html.d.ts +10 -42
- package/dist/fused-html.js +1 -1
- package/dist/fused-runtime.d.ts +80 -3
- package/dist/fused-runtime.js +1 -1
- package/dist/fused.d.ts +65 -0
- package/dist/fused.js +253 -95
- package/dist/fused.js.map +1 -1
- package/dist/{html-CyZiE7kS.js → html-B0pN-5Mx.js} +30 -70
- package/dist/html-B0pN-5Mx.js.map +1 -0
- package/dist/{runtime-_9IqvWDa.js → runtime-DuxZ_yVl.js} +479 -50
- package/dist/runtime-DuxZ_yVl.js.map +1 -0
- package/dist/style.css +54 -19
- package/dist/view-environment/environment-sw.js +78 -160
- package/dist/view-environment/environment.js +227 -130
- package/dist/workers-BpHcfNEu.js +34 -0
- package/dist/{workers-c759BKce.js.map → workers-BpHcfNEu.js.map} +1 -1
- package/package.json +6 -6
- package/dist/html-CyZiE7kS.js.map +0 -1
- package/dist/runtime-_9IqvWDa.js.map +0 -1
- package/dist/workers-c759BKce.js +0 -34
|
@@ -324,9 +324,12 @@ function l(e) {
|
|
|
324
324
|
//#endregion
|
|
325
325
|
//#region src/fused/runtime/wire.ts
|
|
326
326
|
function u(e) {
|
|
327
|
+
return !(e instanceof Uint8Array) || !(e.buffer instanceof ArrayBuffer) || e.byteOffset !== 0 || e.byteLength !== e.buffer.byteLength ? [] : [e.buffer];
|
|
328
|
+
}
|
|
329
|
+
function d(e) {
|
|
327
330
|
return e instanceof Error ? e.message : String(e);
|
|
328
331
|
}
|
|
329
|
-
var
|
|
332
|
+
var f = "environment-sw.js", p = [
|
|
330
333
|
"default-src 'none'",
|
|
331
334
|
"script-src 'self' 'unsafe-inline'",
|
|
332
335
|
"style-src 'self' 'unsafe-inline'",
|
|
@@ -353,7 +356,7 @@ var d = "environment-sw.js", f = [
|
|
|
353
356
|
"form-action 'none'",
|
|
354
357
|
"base-uri 'self'"
|
|
355
358
|
].join("; ");
|
|
356
|
-
function
|
|
359
|
+
function m(e, t) {
|
|
357
360
|
let n = e.href.endsWith("/") ? e.href : `${e.href}/`, r = t.lastIndexOf("/");
|
|
358
361
|
return r <= 0 ? n : `${n}${t.slice(0, r + 1)}`;
|
|
359
362
|
}
|
|
@@ -381,11 +384,11 @@ Object.freeze({
|
|
|
381
384
|
txt: "text/plain; charset=utf-8",
|
|
382
385
|
bin: "application/octet-stream"
|
|
383
386
|
});
|
|
384
|
-
function
|
|
387
|
+
function h(e, t) {
|
|
385
388
|
let n = [
|
|
386
389
|
"<meta charset=\"utf-8\">",
|
|
387
|
-
`<meta http-equiv="Content-Security-Policy" content="${
|
|
388
|
-
`<base href="${
|
|
390
|
+
`<meta http-equiv="Content-Security-Policy" content="${y(t.policy)}">`,
|
|
391
|
+
`<base href="${y(t.base)}">`,
|
|
389
392
|
`<style>${t.style.replace(/<\/style/gi, "<\\/style")}</style>`
|
|
390
393
|
].join(""), r = /<head\b[^>]*>/i.exec(e);
|
|
391
394
|
if (r !== null) {
|
|
@@ -404,28 +407,113 @@ function m(e, t) {
|
|
|
404
407
|
}
|
|
405
408
|
return `<head>${n}</head>${e}`;
|
|
406
409
|
}
|
|
407
|
-
var
|
|
408
|
-
function
|
|
410
|
+
var g = /^https?:\/\/[^/]+$/;
|
|
411
|
+
function _(e) {
|
|
409
412
|
if (e !== void 0 && e !== "") try {
|
|
410
413
|
let t = new URL(e);
|
|
411
|
-
return t.protocol !== "http:" && t.protocol !== "https:" ? void 0 :
|
|
414
|
+
return t.protocol !== "http:" && t.protocol !== "https:" ? void 0 : g.test(t.origin) ? t.origin : void 0;
|
|
412
415
|
} catch {
|
|
413
416
|
return;
|
|
414
417
|
}
|
|
415
418
|
}
|
|
416
|
-
function
|
|
419
|
+
function v(e) {
|
|
417
420
|
return new TextDecoder().decode(e).replace(/^\uFEFF/, "");
|
|
418
421
|
}
|
|
419
|
-
function
|
|
422
|
+
function y(e) {
|
|
420
423
|
return e.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
421
424
|
}
|
|
422
|
-
var
|
|
425
|
+
var b = "mica:view:ack", x = "mica:view:attach-ack", S = "mica:view:child-connect", C = "view";
|
|
423
426
|
l("fused-html-host");
|
|
424
|
-
var
|
|
425
|
-
l("fused-html-
|
|
427
|
+
var w = l("fused-html-host-control"), T = l("fused-html-asset");
|
|
428
|
+
l("fused-html-content-view");
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/fused/html/environment/asset-grant.ts
|
|
431
|
+
var E = 16, D = /* @__PURE__ */ new Set(["nested"]), O = class {
|
|
432
|
+
#e;
|
|
433
|
+
#t;
|
|
434
|
+
#n;
|
|
435
|
+
constructor(e) {
|
|
436
|
+
this.#e = P(e), this.#t = new URL(e).origin;
|
|
437
|
+
}
|
|
438
|
+
get scope() {
|
|
439
|
+
return this.#e;
|
|
440
|
+
}
|
|
441
|
+
get active() {
|
|
442
|
+
return this.#n === void 0 ? void 0 : k(this.#n);
|
|
443
|
+
}
|
|
444
|
+
grant(e, t) {
|
|
445
|
+
let n = A(e), r = j(e), i = N(t);
|
|
446
|
+
if (n !== void 0 && r !== void 0 && i !== void 0 && F(r, this.#e) && this.#r(t)) return this.#n = {
|
|
447
|
+
token: n,
|
|
448
|
+
root: r,
|
|
449
|
+
parentClientId: i,
|
|
450
|
+
childClientId: void 0
|
|
451
|
+
}, k(this.#n);
|
|
452
|
+
}
|
|
453
|
+
attach(e, t) {
|
|
454
|
+
let n = this.#n;
|
|
455
|
+
if (n === void 0) return;
|
|
456
|
+
let r = A(e), i = N(t);
|
|
457
|
+
if (r !== void 0 && r === n.token && i !== void 0 && M(t) && this.#r(t)) return i !== n.parentClientId && (n.childClientId = i), k(n);
|
|
458
|
+
}
|
|
459
|
+
#r(e) {
|
|
460
|
+
let t = e?.url;
|
|
461
|
+
if (t === void 0 || t === "") return !0;
|
|
462
|
+
let n;
|
|
463
|
+
try {
|
|
464
|
+
n = new URL(t);
|
|
465
|
+
} catch {
|
|
466
|
+
return !1;
|
|
467
|
+
}
|
|
468
|
+
return n.origin === this.#t && F(n.pathname, this.#e);
|
|
469
|
+
}
|
|
470
|
+
serves(e) {
|
|
471
|
+
let t = this.#n;
|
|
472
|
+
if (t === void 0) return;
|
|
473
|
+
let n = N({ id: e });
|
|
474
|
+
if (n !== void 0) return n === t.parentClientId || n === t.childClientId ? t.root : void 0;
|
|
475
|
+
}
|
|
476
|
+
clear() {
|
|
477
|
+
this.#n = void 0;
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
function k(e) {
|
|
481
|
+
return Object.freeze({
|
|
482
|
+
token: e.token,
|
|
483
|
+
root: e.root,
|
|
484
|
+
parentClientId: e.parentClientId,
|
|
485
|
+
childClientId: e.childClientId
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
function A(e) {
|
|
489
|
+
if (typeof e != "object" || !e) return;
|
|
490
|
+
let t = e.token;
|
|
491
|
+
if (!(typeof t != "string" || t.length < E)) return t;
|
|
492
|
+
}
|
|
493
|
+
function j(e) {
|
|
494
|
+
if (typeof e != "object" || !e) return;
|
|
495
|
+
let t = e.root;
|
|
496
|
+
if (typeof t == "string" && t.endsWith("/") && !(!t.startsWith("/") || t.includes("\\") || t.includes("?") || t.includes("#")) && !t.split("/").some((e) => e === "." || e === "..")) return t;
|
|
497
|
+
}
|
|
498
|
+
function M(e) {
|
|
499
|
+
let t = e?.frameType;
|
|
500
|
+
return t === void 0 || D.has(t);
|
|
501
|
+
}
|
|
502
|
+
function N(e) {
|
|
503
|
+
let t = e?.id;
|
|
504
|
+
return typeof t == "string" && t.length > 0 ? t : void 0;
|
|
505
|
+
}
|
|
506
|
+
function P(e) {
|
|
507
|
+
let t = new URL(e).pathname;
|
|
508
|
+
return t.endsWith("/") ? t : `${t}/`;
|
|
509
|
+
}
|
|
510
|
+
function F(e, t) {
|
|
511
|
+
let n = t.endsWith("/") ? t : `${t}/`;
|
|
512
|
+
return e !== n && e.startsWith(n);
|
|
513
|
+
}
|
|
426
514
|
//#endregion
|
|
427
515
|
//#region src/fused/theme.ts
|
|
428
|
-
var
|
|
516
|
+
var I = Object.freeze({
|
|
429
517
|
"workbench.background": "--mica-bg",
|
|
430
518
|
"workbench.foreground": "--mica-text",
|
|
431
519
|
"workbench.mutedForeground": "--mica-muted",
|
|
@@ -443,7 +531,7 @@ var w = Object.freeze({
|
|
|
443
531
|
"canvas.selection": "--mica-canvas-selection",
|
|
444
532
|
"error.foreground": "--mica-error",
|
|
445
533
|
shadow: "--mica-shadow"
|
|
446
|
-
}),
|
|
534
|
+
}), L = Object.freeze({
|
|
447
535
|
"workbench.background": "#1c1c1c",
|
|
448
536
|
"workbench.foreground": "#e5e5e5",
|
|
449
537
|
"workbench.mutedForeground": "#a3a3a3",
|
|
@@ -461,7 +549,7 @@ var w = Object.freeze({
|
|
|
461
549
|
"canvas.selection": "#eeeeee",
|
|
462
550
|
"error.foreground": "#f28b82",
|
|
463
551
|
shadow: "#00000055"
|
|
464
|
-
}),
|
|
552
|
+
}), ee = Object.freeze({
|
|
465
553
|
"workbench.background": "#ffffff",
|
|
466
554
|
"workbench.foreground": "#263247",
|
|
467
555
|
"workbench.mutedForeground": "#748098",
|
|
@@ -479,175 +567,177 @@ var w = Object.freeze({
|
|
|
479
567
|
"canvas.selection": "#4285ff",
|
|
480
568
|
"error.foreground": "#b43b35",
|
|
481
569
|
shadow: "#00000022"
|
|
482
|
-
}),
|
|
570
|
+
}), R = Object.freeze({
|
|
483
571
|
appearance: "dark",
|
|
484
|
-
colors:
|
|
485
|
-
}),
|
|
486
|
-
function
|
|
487
|
-
return e.colors[
|
|
572
|
+
colors: L
|
|
573
|
+
}), z = Object.keys(I), B = "panel.background";
|
|
574
|
+
function V(e) {
|
|
575
|
+
return e.colors[B];
|
|
488
576
|
}
|
|
489
|
-
var
|
|
490
|
-
function
|
|
577
|
+
var H = /[;{}<>\\]/;
|
|
578
|
+
function U(e) {
|
|
491
579
|
if (typeof e != "object" || !e) throw TypeError("An HTML view theme must be an object");
|
|
492
580
|
let t = e, n = t.appearance ?? "dark";
|
|
493
581
|
if (n !== "dark" && n !== "light") throw TypeError(`Unknown HTML view theme appearance: ${String(n)}`);
|
|
494
|
-
let r = { ...n === "dark" ?
|
|
582
|
+
let r = { ...n === "dark" ? L : ee }, i = t.colors;
|
|
495
583
|
if (i != null) {
|
|
496
584
|
if (typeof i != "object") throw TypeError("HTML view theme colors must be an object");
|
|
497
585
|
for (let [e, t] of Object.entries(i)) {
|
|
498
|
-
if (!Object.hasOwn(
|
|
499
|
-
r[e] =
|
|
586
|
+
if (!Object.hasOwn(I, e)) throw TypeError(`Unknown HTML view theme token: ${e}`);
|
|
587
|
+
r[e] = W(e, t);
|
|
500
588
|
}
|
|
501
589
|
}
|
|
502
|
-
for (let e of
|
|
590
|
+
for (let e of z) r[e] ??= W(e, L[e]);
|
|
503
591
|
return Object.freeze({
|
|
504
592
|
appearance: n,
|
|
505
593
|
colors: Object.freeze(r)
|
|
506
594
|
});
|
|
507
595
|
}
|
|
508
|
-
function
|
|
596
|
+
function W(e, t) {
|
|
509
597
|
if (typeof t != "string" || t.trim() === "") throw TypeError(`HTML view theme token ${e} must be a non-empty CSS color`);
|
|
510
|
-
if (
|
|
598
|
+
if (H.test(t)) throw TypeError(`HTML view theme token ${e} must be a plain CSS color`);
|
|
511
599
|
return t.trim();
|
|
512
600
|
}
|
|
513
|
-
function
|
|
514
|
-
let t =
|
|
515
|
-
return t.push(`color-scheme:${e.appearance}`), `:root{background-color:${
|
|
601
|
+
function G(e) {
|
|
602
|
+
let t = z.map((t) => `${I[t]}:${e.colors[t]}`);
|
|
603
|
+
return t.push(`color-scheme:${e.appearance}`), `:root{background-color:${V(e)};${t.join(";")}}`;
|
|
516
604
|
}
|
|
517
|
-
function
|
|
605
|
+
function K(e, t) {
|
|
518
606
|
let n = e.style;
|
|
519
|
-
for (let e of
|
|
520
|
-
n.setProperty("color-scheme", t.appearance), n.setProperty("background-color",
|
|
607
|
+
for (let e of z) n.setProperty(I[e], t.colors[e]);
|
|
608
|
+
n.setProperty("color-scheme", t.appearance), n.setProperty("background-color", V(t));
|
|
521
609
|
}
|
|
522
610
|
//#endregion
|
|
523
611
|
//#region src/fused/html/environment/entry.ts
|
|
524
|
-
async function
|
|
525
|
-
let t = e.window ?? globalThis.window, n = e.document ?? t.document, { message: r, port: i } = await
|
|
612
|
+
async function q(e = {}) {
|
|
613
|
+
let t = e.window ?? globalThis.window, n = e.document ?? t.document, { message: r, port: i } = await re(t, e.handshakeTimeoutMs ?? 15e3);
|
|
526
614
|
t.parent.postMessage({
|
|
527
|
-
type:
|
|
615
|
+
type: b,
|
|
528
616
|
token: r.token
|
|
529
617
|
}, r.parentOrigin);
|
|
530
|
-
let o = a(i).getProxy(
|
|
531
|
-
|
|
532
|
-
},
|
|
618
|
+
let o = a(i), s = o.getProxy(w), c = (e, t) => {
|
|
619
|
+
s.reportFailure(e, t).catch(() => void 0);
|
|
620
|
+
}, l = Y(s, c, n);
|
|
533
621
|
try {
|
|
534
|
-
await
|
|
622
|
+
await l.load();
|
|
623
|
+
let i = await ie(t, e.workerTimeoutMs ?? 1e4);
|
|
624
|
+
o.onDidClose(ae(i, new URL(".", t.location.href), r, s)), J({
|
|
535
625
|
window: t,
|
|
536
626
|
document: n,
|
|
537
|
-
control:
|
|
627
|
+
control: s,
|
|
538
628
|
message: r,
|
|
539
|
-
authored:
|
|
540
|
-
theme:
|
|
629
|
+
authored: v(await s.readAsset(r.target.entry)),
|
|
630
|
+
theme: l,
|
|
541
631
|
contentUrl: e.contentUrl ?? new URL("content.html", import.meta.url).href,
|
|
542
632
|
budgetMs: e.contentTimeoutMs ?? 15e3,
|
|
543
|
-
report:
|
|
633
|
+
report: c
|
|
544
634
|
}), t.addEventListener("pagehide", () => {
|
|
545
635
|
try {
|
|
546
|
-
|
|
636
|
+
s.closed();
|
|
547
637
|
} catch {}
|
|
548
638
|
});
|
|
549
639
|
} catch (e) {
|
|
550
|
-
throw
|
|
640
|
+
throw c("view/load-failed", d(e)), e;
|
|
551
641
|
}
|
|
552
642
|
}
|
|
553
|
-
function
|
|
554
|
-
let { window: t, document: n, control: r, message: i, authored: a, theme: o, report: s } = e, c = i.target, l =
|
|
643
|
+
function J(e) {
|
|
644
|
+
let { window: t, document: n, control: r, message: i, authored: a, theme: o, report: s } = e, c = i.target, l = _(t.location.href);
|
|
555
645
|
if (l === void 0) throw Error("The environment page has no concrete origin.");
|
|
556
|
-
let
|
|
557
|
-
if (
|
|
558
|
-
|
|
559
|
-
let
|
|
560
|
-
|
|
561
|
-
let v = !1, y = !1, b = !1,
|
|
562
|
-
|
|
646
|
+
let u = se(), f = new URL(e.contentUrl);
|
|
647
|
+
if (_(f.href) !== l) throw Error("The content document must be served from the environment origin.");
|
|
648
|
+
f.searchParams.set(C, u);
|
|
649
|
+
let g = n.createElement("iframe");
|
|
650
|
+
g.className = "mica-html-view-document", g.title = `${c.title} — ${c.device}`, g.setAttribute("sandbox", "allow-scripts allow-same-origin"), g.setAttribute("referrerpolicy", "no-referrer"), g.setAttribute("allow", ""), g.style.display = "block", g.style.width = "100%", g.style.height = "100%", g.style.border = "0", g.style.background = V(o.current), o.track(g);
|
|
651
|
+
let v = !1, y = !1, b = !1, x = !1, w, T, E = (e) => {
|
|
652
|
+
x || (x = !0, D(), s("view/execution-failed", e));
|
|
563
653
|
}, D = () => {
|
|
564
654
|
T !== void 0 && (clearTimeout(T), T = void 0);
|
|
565
655
|
}, O = (e) => {
|
|
566
656
|
let t = e.data;
|
|
567
|
-
typeof t == "object" && t && t.type === "mica:view:child-hello" && t.token ===
|
|
568
|
-
if (v ||
|
|
657
|
+
typeof t == "object" && t && t.type === "mica:view:child-hello" && t.token === u && e.source === g.contentWindow && e.origin === l && (x || (v || y ? E("The HTML view document started twice.") : (y = !0, D(), r.contentPort().then((e) => {
|
|
658
|
+
if (v || x) {
|
|
569
659
|
e.close();
|
|
570
660
|
return;
|
|
571
661
|
}
|
|
572
|
-
let t =
|
|
662
|
+
let t = g.contentWindow;
|
|
573
663
|
if (t === null) {
|
|
574
664
|
e.close(), E("The HTML view document frame is not available.");
|
|
575
665
|
return;
|
|
576
666
|
}
|
|
577
|
-
if (
|
|
667
|
+
if (!$(g, f.href)) {
|
|
578
668
|
e.close(), E("The HTML view navigated away from its author document.");
|
|
579
669
|
return;
|
|
580
670
|
}
|
|
581
671
|
y = !1, v = !0;
|
|
582
672
|
let n = {
|
|
583
|
-
type:
|
|
584
|
-
token:
|
|
673
|
+
type: S,
|
|
674
|
+
token: u
|
|
585
675
|
};
|
|
586
676
|
try {
|
|
587
677
|
t.postMessage(n, l, [e]);
|
|
588
678
|
} catch (e) {
|
|
589
|
-
E(`The HTML view bridge port was rejected: ${
|
|
679
|
+
E(`The HTML view bridge port was rejected: ${d(e)}`);
|
|
590
680
|
}
|
|
591
681
|
}, (e) => {
|
|
592
|
-
v ||
|
|
682
|
+
v || x || E(`The HTML view bridge port was not granted: ${d(e)}`);
|
|
593
683
|
}))));
|
|
594
684
|
}, k = (e) => {
|
|
595
685
|
let t = e.data;
|
|
596
|
-
if (typeof t == "object" && t && t.type === "mica:view:child-prepared" && t.token ===
|
|
686
|
+
if (typeof t == "object" && t && t.type === "mica:view:child-prepared" && t.token === u && e.source === g.contentWindow && e.origin === l && v && !x) {
|
|
597
687
|
try {
|
|
598
|
-
|
|
688
|
+
A();
|
|
599
689
|
} catch (e) {
|
|
600
|
-
E(
|
|
690
|
+
E(d(e));
|
|
601
691
|
return;
|
|
602
692
|
}
|
|
603
693
|
r.ready().catch((e) => {
|
|
604
|
-
E(`The HTML view was not reported ready: ${
|
|
694
|
+
E(`The HTML view was not reported ready: ${d(e)}`);
|
|
605
695
|
});
|
|
606
696
|
}
|
|
607
697
|
};
|
|
608
|
-
function
|
|
698
|
+
function A() {
|
|
609
699
|
if (b) throw Error("The author document was already written.");
|
|
610
|
-
let e =
|
|
700
|
+
let e = Q(g);
|
|
611
701
|
if (e === null) throw Error("The HTML view document frame is not available.");
|
|
612
702
|
if (w !== void 0 && e !== w) throw Error("The HTML view document changed before its author document was written.");
|
|
613
|
-
w = e, e.open(),
|
|
614
|
-
base:
|
|
615
|
-
policy:
|
|
616
|
-
style:
|
|
617
|
-
})), e.close(), b = !0, o.track(
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
let e =
|
|
703
|
+
w = e, e.open(), Z(te(g), s), e.write(h(a, {
|
|
704
|
+
base: m(new URL(c.assetRoot), c.entry),
|
|
705
|
+
policy: p,
|
|
706
|
+
style: G(o.current)
|
|
707
|
+
})), e.close(), b = !0, o.track(g);
|
|
708
|
+
}
|
|
709
|
+
g.addEventListener("load", () => {
|
|
710
|
+
let e = Q(g);
|
|
621
711
|
if (e === null) E("The HTML view navigated away from its author document.");
|
|
622
712
|
else if (w === void 0) {
|
|
623
|
-
if (
|
|
713
|
+
if (!$(g, f.href)) {
|
|
624
714
|
E("The HTML view navigated away from its author document.");
|
|
625
715
|
return;
|
|
626
716
|
}
|
|
627
|
-
w = e, o.track(
|
|
628
|
-
} else e === w ? o.track(
|
|
717
|
+
w = e, o.track(g);
|
|
718
|
+
} else e === w ? o.track(g) : E("The HTML view navigated away from its author document.");
|
|
629
719
|
}), t.addEventListener("message", O), t.addEventListener("message", k);
|
|
630
|
-
let
|
|
631
|
-
|
|
720
|
+
let j = n.body ?? n.documentElement;
|
|
721
|
+
g.src = f.href, j.append(g), e.budgetMs > 0 && (T = setTimeout(() => {
|
|
632
722
|
T = void 0, E("The HTML view document did not start in time.");
|
|
633
723
|
}, e.budgetMs));
|
|
634
724
|
}
|
|
635
|
-
function
|
|
636
|
-
let r =
|
|
725
|
+
function Y(e, t, n) {
|
|
726
|
+
let r = R, i = 0, a, o = () => {
|
|
637
727
|
try {
|
|
638
|
-
|
|
728
|
+
K(n.documentElement, r);
|
|
639
729
|
} catch {}
|
|
640
730
|
if (a === void 0) return;
|
|
641
731
|
try {
|
|
642
|
-
a.style.background =
|
|
732
|
+
a.style.background = V(r);
|
|
643
733
|
} catch {}
|
|
644
|
-
let e =
|
|
734
|
+
let e = ne(a);
|
|
645
735
|
if (e !== null) try {
|
|
646
|
-
|
|
736
|
+
K(e, r);
|
|
647
737
|
} catch {}
|
|
648
738
|
};
|
|
649
739
|
return e.onDidThemeChange((e) => {
|
|
650
|
-
i += 1, r =
|
|
740
|
+
i += 1, r = X(e, r, t), o();
|
|
651
741
|
}), {
|
|
652
742
|
get current() {
|
|
653
743
|
return r;
|
|
@@ -657,52 +747,52 @@ function R(e, t, n) {
|
|
|
657
747
|
try {
|
|
658
748
|
n = await e.getTheme();
|
|
659
749
|
} catch (e) {
|
|
660
|
-
t("view/bridge-failed", `The workbench theme is unavailable: ${
|
|
750
|
+
t("view/bridge-failed", `The workbench theme is unavailable: ${d(e)}`);
|
|
661
751
|
return;
|
|
662
752
|
}
|
|
663
|
-
i > 0 || (r =
|
|
753
|
+
i > 0 || (r = X(n, r, t), o());
|
|
664
754
|
},
|
|
665
755
|
track(e) {
|
|
666
756
|
a = e, o();
|
|
667
757
|
}
|
|
668
758
|
};
|
|
669
759
|
}
|
|
670
|
-
function
|
|
760
|
+
function X(e, t, n) {
|
|
671
761
|
try {
|
|
672
|
-
return
|
|
762
|
+
return U(e);
|
|
673
763
|
} catch (e) {
|
|
674
|
-
return n("view/bridge-failed", `The workbench sent an unusable theme: ${
|
|
764
|
+
return n("view/bridge-failed", `The workbench sent an unusable theme: ${d(e)}`), t;
|
|
675
765
|
}
|
|
676
766
|
}
|
|
677
|
-
function
|
|
767
|
+
function Z(e, t) {
|
|
678
768
|
e !== null && (e.addEventListener("error", (e) => {
|
|
679
769
|
t("view/execution-failed", e.message);
|
|
680
770
|
}), e.addEventListener("unhandledrejection", (e) => {
|
|
681
|
-
t("view/execution-failed",
|
|
771
|
+
t("view/execution-failed", d(e.reason));
|
|
682
772
|
}));
|
|
683
773
|
}
|
|
684
|
-
function
|
|
774
|
+
function te(e) {
|
|
685
775
|
try {
|
|
686
776
|
return e.contentWindow;
|
|
687
777
|
} catch {
|
|
688
778
|
return null;
|
|
689
779
|
}
|
|
690
780
|
}
|
|
691
|
-
function
|
|
781
|
+
function ne(e) {
|
|
692
782
|
try {
|
|
693
783
|
return e.contentDocument?.documentElement ?? null;
|
|
694
784
|
} catch {
|
|
695
785
|
return null;
|
|
696
786
|
}
|
|
697
787
|
}
|
|
698
|
-
function
|
|
788
|
+
function Q(e) {
|
|
699
789
|
try {
|
|
700
790
|
return e.contentDocument ?? null;
|
|
701
791
|
} catch {
|
|
702
792
|
return null;
|
|
703
793
|
}
|
|
704
794
|
}
|
|
705
|
-
function
|
|
795
|
+
function $(e, t) {
|
|
706
796
|
try {
|
|
707
797
|
let n = e.contentWindow;
|
|
708
798
|
return n !== null && new URL(n.location.href).href === new URL(t).href;
|
|
@@ -710,7 +800,7 @@ function W(e, t) {
|
|
|
710
800
|
return !1;
|
|
711
801
|
}
|
|
712
802
|
}
|
|
713
|
-
function
|
|
803
|
+
function re(e, t) {
|
|
714
804
|
return new Promise((n, r) => {
|
|
715
805
|
let i = t > 0 ? setTimeout(() => {
|
|
716
806
|
e.removeEventListener("message", a), r(/* @__PURE__ */ Error("The editor did not hand over a bridge port."));
|
|
@@ -735,32 +825,39 @@ function G(e, t) {
|
|
|
735
825
|
e.addEventListener("message", a);
|
|
736
826
|
});
|
|
737
827
|
}
|
|
738
|
-
async function
|
|
739
|
-
let
|
|
740
|
-
if (
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
828
|
+
async function ie(e, t) {
|
|
829
|
+
let n = e.navigator.serviceWorker;
|
|
830
|
+
if (n === void 0) throw Error("This browser has no service worker support, so package files cannot load.");
|
|
831
|
+
return await n.register(new URL(f, import.meta.url), { type: "module" }), await oe(n, t), n;
|
|
832
|
+
}
|
|
833
|
+
function ae(e, t, n, r) {
|
|
834
|
+
let i = new URL(n.target.assetRoot).pathname, o = new O(t.href), s = (t) => {
|
|
835
|
+
if (t.source === null || t.source !== e.controller) return;
|
|
836
|
+
let s = t.ports[0];
|
|
837
|
+
if (s === void 0) return;
|
|
838
|
+
let c = t.data;
|
|
839
|
+
if (c?.type === "mica:view:attach" && c.token === n.token) {
|
|
840
|
+
o.active === void 0 && o.grant({
|
|
841
|
+
token: n.token,
|
|
842
|
+
root: i
|
|
843
|
+
}, c.owner);
|
|
844
|
+
let e = o.attach(c, c.client);
|
|
845
|
+
e !== void 0 && s.postMessage({
|
|
846
|
+
type: x,
|
|
847
|
+
token: e.token
|
|
848
|
+
}), s.close();
|
|
849
|
+
} else if (c?.type === "mica:view:asset-read") {
|
|
850
|
+
let e = a(s);
|
|
851
|
+
e.onDidClose(() => s.close()), e.register(T, { async read(e) {
|
|
852
|
+
return o.serves(c.clientId) === i ? r.readAsset(e) : void 0;
|
|
853
|
+
} }, { transfer: (e, t) => u(t) });
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
return e.addEventListener("message", s), e.startMessages(), () => {
|
|
857
|
+
o.clear(), e.removeEventListener("message", s);
|
|
749
858
|
};
|
|
750
|
-
s.postMessage(f, [c, l.port2]), await u;
|
|
751
|
-
}
|
|
752
|
-
function q(e, t, n) {
|
|
753
|
-
return new Promise((r, i) => {
|
|
754
|
-
let a = n > 0 ? setTimeout(() => {
|
|
755
|
-
e.close(), i(/* @__PURE__ */ Error("The package asset worker did not answer its grant."));
|
|
756
|
-
}, n) : void 0;
|
|
757
|
-
e.addEventListener("message", (n) => {
|
|
758
|
-
let i = n.data;
|
|
759
|
-
typeof i == "object" && i && i.type === "mica:view:assets-ack" && i.token === t && (a !== void 0 && clearTimeout(a), e.close(), r());
|
|
760
|
-
}), e.start();
|
|
761
|
-
});
|
|
762
859
|
}
|
|
763
|
-
function
|
|
860
|
+
function oe(e, t) {
|
|
764
861
|
return e.controller === null ? new Promise((n, r) => {
|
|
765
862
|
let i = () => {
|
|
766
863
|
o !== void 0 && clearTimeout(o), e.removeEventListener("controllerchange", a), n();
|
|
@@ -770,14 +867,14 @@ function J(e, t) {
|
|
|
770
867
|
e.addEventListener("controllerchange", a, { once: !0 }), e.controller !== null && i();
|
|
771
868
|
}) : Promise.resolve();
|
|
772
869
|
}
|
|
773
|
-
function
|
|
870
|
+
function se() {
|
|
774
871
|
let e = /* @__PURE__ */ new Uint8Array(16), t = globalThis.crypto;
|
|
775
872
|
if (typeof t?.getRandomValues == "function") t.getRandomValues(e);
|
|
776
873
|
else for (let t = 0; t < e.length; t += 1) e[t] = Math.random() * 256;
|
|
777
874
|
return [...e].map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
778
875
|
}
|
|
779
|
-
globalThis.window !== void 0 && globalThis.document !== void 0 &&
|
|
876
|
+
globalThis.window !== void 0 && globalThis.document !== void 0 && q().catch((e) => {
|
|
780
877
|
console.error("[@mica-js/editor] device view environment failed", e);
|
|
781
878
|
});
|
|
782
879
|
//#endregion
|
|
783
|
-
export {
|
|
880
|
+
export { q as startHtmlViewEnvironment };
|