@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,36 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<!--
|
|
7
|
+
Inner author document of one device HTML view environment (RFC 0023). Deploy this file next to
|
|
8
|
+
index.html, environment.js, environment-sw.js and content.js.
|
|
9
|
+
|
|
10
|
+
This is a real same-origin document of the environment deployment directory, so both frames
|
|
11
|
+
compare exact origins and the environment reaches this document through `contentDocument`.
|
|
12
|
+
Nothing is rendered before the environment writes the author document into it: content.js
|
|
13
|
+
installs `acquireDeviceViewApi`, authorizes this client in the package worker and only then
|
|
14
|
+
announces that the document may be written, which keeps the API available before any author
|
|
15
|
+
script runs.
|
|
16
|
+
|
|
17
|
+
The inline policy mirrors HTML_VIEW_CONTENT_POLICY in paths.ts: no further frames, no other
|
|
18
|
+
origin and no form targets.
|
|
19
|
+
-->
|
|
20
|
+
<meta
|
|
21
|
+
http-equiv="Content-Security-Policy"
|
|
22
|
+
content="default-src 'none'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data: blob:; media-src 'self' data: blob:; connect-src 'self' blob:; frame-src 'none'; object-src 'none'; form-action 'none'; base-uri 'self'"
|
|
23
|
+
/>
|
|
24
|
+
<title>Mica device view document</title>
|
|
25
|
+
<style>
|
|
26
|
+
html,
|
|
27
|
+
body {
|
|
28
|
+
margin: 0;
|
|
29
|
+
height: 100%;
|
|
30
|
+
background: transparent;
|
|
31
|
+
}
|
|
32
|
+
</style>
|
|
33
|
+
<script type="module" src="./content.js"></script>
|
|
34
|
+
</head>
|
|
35
|
+
<body></body>
|
|
36
|
+
</html>
|
|
@@ -0,0 +1,666 @@
|
|
|
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 = class extends Error {
|
|
325
|
+
code;
|
|
326
|
+
instanceId;
|
|
327
|
+
details;
|
|
328
|
+
constructor(e, t, n = {}) {
|
|
329
|
+
super(t), this.name = n.name ?? "FusedBridgeError", this.code = e, this.instanceId = n.instanceId, this.details = n.details;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
function d(e) {
|
|
333
|
+
if (!(e instanceof Error) || e.name !== "FusedSandboxFailure") return e instanceof Error ? e : Error(String(e));
|
|
334
|
+
let t = p(e.message);
|
|
335
|
+
return t === void 0 ? e : new u(t.code, t.message, {
|
|
336
|
+
...t.kind === "method" ? { name: "MethodError" } : {},
|
|
337
|
+
...t.instanceId === void 0 ? {} : { instanceId: t.instanceId },
|
|
338
|
+
...t.details === void 0 ? {} : { details: t.details }
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
async function f(e) {
|
|
342
|
+
try {
|
|
343
|
+
return await e();
|
|
344
|
+
} catch (e) {
|
|
345
|
+
throw d(e);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
function p(e) {
|
|
349
|
+
let t;
|
|
350
|
+
try {
|
|
351
|
+
t = JSON.parse(e);
|
|
352
|
+
} catch {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
if (typeof t != "object" || !t) return;
|
|
356
|
+
let n = t;
|
|
357
|
+
if (typeof n.code == "string" && typeof n.message == "string") return {
|
|
358
|
+
kind: n.kind === "method" || n.kind === "runtime" ? n.kind : "failure",
|
|
359
|
+
code: n.code,
|
|
360
|
+
message: n.message,
|
|
361
|
+
...typeof n.instanceId == "string" ? { instanceId: n.instanceId } : {},
|
|
362
|
+
...n.details === void 0 ? {} : { details: n.details }
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function m(e) {
|
|
366
|
+
return e instanceof Error ? e.message : String(e);
|
|
367
|
+
}
|
|
368
|
+
//#endregion
|
|
369
|
+
//#region ../document/src/fused/rules.ts
|
|
370
|
+
var h = /^[A-Za-z]:/, g = /^[A-Za-z][A-Za-z0-9+.-]*:/;
|
|
371
|
+
function _(e) {
|
|
372
|
+
for (let t of e) {
|
|
373
|
+
let e = t.codePointAt(0) ?? 0;
|
|
374
|
+
if (e < 32 || e === 127) return !0;
|
|
375
|
+
}
|
|
376
|
+
return !1;
|
|
377
|
+
}
|
|
378
|
+
function v(e) {
|
|
379
|
+
return y(e, "package root");
|
|
380
|
+
}
|
|
381
|
+
function y(e, t) {
|
|
382
|
+
if (e.length === 0) return "must not be empty";
|
|
383
|
+
if (e.startsWith("/")) return `must be relative to the ${t}, not absolute`;
|
|
384
|
+
if (h.test(e)) return "must not carry a drive letter";
|
|
385
|
+
if (g.test(e)) return "must not be a URL";
|
|
386
|
+
if (e.includes("\\")) return "must use POSIX separators";
|
|
387
|
+
if (_(e)) return "must not contain control characters";
|
|
388
|
+
let n = e.split("/");
|
|
389
|
+
if (n[n.length - 1] === "") return "must name a file, not a directory";
|
|
390
|
+
for (let e of n) {
|
|
391
|
+
if (e.length === 0) return "must not contain empty segments";
|
|
392
|
+
if (e === "." || e === "..") return `must not contain "${e}" segments`;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
[
|
|
396
|
+
"default-src 'none'",
|
|
397
|
+
"script-src 'self' 'unsafe-inline'",
|
|
398
|
+
"style-src 'self' 'unsafe-inline'",
|
|
399
|
+
"img-src 'self' data: blob:",
|
|
400
|
+
"font-src 'self' data: blob:",
|
|
401
|
+
"media-src 'self' data: blob:",
|
|
402
|
+
"connect-src 'self' blob:",
|
|
403
|
+
"frame-src 'none'",
|
|
404
|
+
"object-src 'none'",
|
|
405
|
+
"form-action 'none'",
|
|
406
|
+
"base-uri 'self'"
|
|
407
|
+
].join("; "), [
|
|
408
|
+
"default-src 'none'",
|
|
409
|
+
"script-src 'self' 'unsafe-inline'",
|
|
410
|
+
"style-src 'self' 'unsafe-inline'",
|
|
411
|
+
"img-src 'self' data: blob:",
|
|
412
|
+
"font-src 'self' data: blob:",
|
|
413
|
+
"media-src 'self' data: blob:",
|
|
414
|
+
"connect-src 'self' blob:",
|
|
415
|
+
"worker-src 'self'",
|
|
416
|
+
"frame-src 'self'",
|
|
417
|
+
"object-src 'none'",
|
|
418
|
+
"form-action 'none'",
|
|
419
|
+
"base-uri 'self'"
|
|
420
|
+
].join("; ");
|
|
421
|
+
var b = Object.freeze({
|
|
422
|
+
html: "text/html; charset=utf-8",
|
|
423
|
+
htm: "text/html; charset=utf-8",
|
|
424
|
+
js: "text/javascript; charset=utf-8",
|
|
425
|
+
mjs: "text/javascript; charset=utf-8",
|
|
426
|
+
css: "text/css; charset=utf-8",
|
|
427
|
+
json: "application/json; charset=utf-8",
|
|
428
|
+
map: "application/json; charset=utf-8",
|
|
429
|
+
svg: "image/svg+xml",
|
|
430
|
+
png: "image/png",
|
|
431
|
+
jpg: "image/jpeg",
|
|
432
|
+
jpeg: "image/jpeg",
|
|
433
|
+
gif: "image/gif",
|
|
434
|
+
webp: "image/webp",
|
|
435
|
+
avif: "image/avif",
|
|
436
|
+
ico: "image/x-icon",
|
|
437
|
+
woff: "font/woff",
|
|
438
|
+
woff2: "font/woff2",
|
|
439
|
+
ttf: "font/ttf",
|
|
440
|
+
otf: "font/otf",
|
|
441
|
+
wasm: "application/wasm",
|
|
442
|
+
txt: "text/plain; charset=utf-8",
|
|
443
|
+
bin: "application/octet-stream"
|
|
444
|
+
});
|
|
445
|
+
function x(e) {
|
|
446
|
+
let t = e.lastIndexOf(".");
|
|
447
|
+
return t <= 0 ? "application/octet-stream" : b[e.slice(t + 1).toLowerCase()] ?? "application/octet-stream";
|
|
448
|
+
}
|
|
449
|
+
var S = /^https?:\/\/[^/]+$/;
|
|
450
|
+
function C(e) {
|
|
451
|
+
if (e !== void 0 && e !== "") try {
|
|
452
|
+
let t = new URL(e);
|
|
453
|
+
return t.protocol !== "http:" && t.protocol !== "https:" ? void 0 : S.test(t.origin) ? t.origin : void 0;
|
|
454
|
+
} catch {
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
function w(e) {
|
|
459
|
+
let t = new Uint8Array(e.byteLength);
|
|
460
|
+
return t.set(e), t.buffer;
|
|
461
|
+
}
|
|
462
|
+
//#endregion
|
|
463
|
+
//#region src/fused/html/protocol.ts
|
|
464
|
+
var T = class extends Error {
|
|
465
|
+
code;
|
|
466
|
+
instanceId;
|
|
467
|
+
viewId;
|
|
468
|
+
constructor(e, t, n = {}) {
|
|
469
|
+
super(t), this.name = "HtmlViewError", this.code = e, this.instanceId = n.instanceId, this.viewId = n.viewId;
|
|
470
|
+
}
|
|
471
|
+
}, E = "mica:view:attach", D = "mica:view:child-hello", O = "mica:view:child-prepared", k = "view", A = l("fused-html-host");
|
|
472
|
+
l("fused-html-host-control"), l("fused-html-asset");
|
|
473
|
+
var j = l("fused-html-content-view");
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region src/fused/html/client.ts
|
|
476
|
+
function M(n) {
|
|
477
|
+
let { host: r, target: i } = n, a = n.createObjectUrl ?? ((e) => URL.createObjectURL(e)), o = n.revokeObjectUrl ?? ((e) => URL.revokeObjectURL(e)), s = new Set(i.methods), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Set(), u = new t(), d = !1, p = !1, h = (e, t) => {
|
|
478
|
+
p || d || (p = !0, n.reportFailure(e, t));
|
|
479
|
+
}, g = (n) => (i) => {
|
|
480
|
+
if (d) return e(() => void 0);
|
|
481
|
+
let a = c.get(n);
|
|
482
|
+
a === void 0 && (a = {
|
|
483
|
+
emitter: new t(),
|
|
484
|
+
listeners: 0
|
|
485
|
+
}, c.set(n, a));
|
|
486
|
+
let o = a;
|
|
487
|
+
o.listeners += 1, o.listeners === 1 && _(n);
|
|
488
|
+
let s = o.emitter.event(i);
|
|
489
|
+
return e(() => {
|
|
490
|
+
s.dispose(), --o.listeners, !(o.listeners > 0) && (c.delete(n), o.emitter.dispose(), r.unsubscribe(n).catch(() => void 0));
|
|
491
|
+
});
|
|
492
|
+
};
|
|
493
|
+
async function _(e) {
|
|
494
|
+
try {
|
|
495
|
+
await r.subscribe(e);
|
|
496
|
+
} catch (t) {
|
|
497
|
+
h("view/bridge-failed", `Subscribing to "${e}" failed: ${m(t)}`);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
let v = new Proxy(Object.create(null), {
|
|
501
|
+
get(e, t) {
|
|
502
|
+
if (typeof t == "string" && s.has(t)) return async (e) => {
|
|
503
|
+
if (d) throw new T("view/bridge-failed", "The device view is closed.");
|
|
504
|
+
return f(() => r.callModel(t, e));
|
|
505
|
+
};
|
|
506
|
+
},
|
|
507
|
+
has(e, t) {
|
|
508
|
+
return typeof t == "string" && s.has(t);
|
|
509
|
+
}
|
|
510
|
+
}), y = {};
|
|
511
|
+
for (let e of i.events) y[e] = g(e);
|
|
512
|
+
let b = {
|
|
513
|
+
async read(e) {
|
|
514
|
+
if (N(e), d) throw new T("view/bridge-failed", "The device view is closed.");
|
|
515
|
+
let t = await f(() => r.readAsset(e));
|
|
516
|
+
if (!(t instanceof Uint8Array)) throw new T("view/load-failed", `The host returned no bytes for ${e}.`);
|
|
517
|
+
return t;
|
|
518
|
+
},
|
|
519
|
+
async getUrl(e) {
|
|
520
|
+
let t = await b.read(e), n = a(new Blob([w(t)], { type: x(e) }));
|
|
521
|
+
if (d) throw o(n), new T("view/bridge-failed", "The device view is closed.");
|
|
522
|
+
return l.add(n), n;
|
|
523
|
+
}
|
|
524
|
+
}, S = Object.freeze({
|
|
525
|
+
props: Object.freeze({ ...i.props }),
|
|
526
|
+
model: i.hasModel ? Object.freeze({
|
|
527
|
+
methods: v,
|
|
528
|
+
events: Object.freeze(y)
|
|
529
|
+
}) : void 0,
|
|
530
|
+
assets: b,
|
|
531
|
+
onDidClose: (t) => d ? (t(), e(() => void 0)) : u.event(t)
|
|
532
|
+
}), C = () => {
|
|
533
|
+
if (!d) {
|
|
534
|
+
d = !0;
|
|
535
|
+
for (let e of c.values()) e.emitter.dispose();
|
|
536
|
+
c.clear();
|
|
537
|
+
for (let e of l) try {
|
|
538
|
+
o(e);
|
|
539
|
+
} catch {}
|
|
540
|
+
l.clear();
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
return {
|
|
544
|
+
api: S,
|
|
545
|
+
get closed() {
|
|
546
|
+
return d;
|
|
547
|
+
},
|
|
548
|
+
deliver(e) {
|
|
549
|
+
if (d) return;
|
|
550
|
+
let t = c.get(e.name);
|
|
551
|
+
if (t !== void 0) try {
|
|
552
|
+
t.emitter.fire(e.payload);
|
|
553
|
+
} catch (t) {
|
|
554
|
+
h("view/execution-failed", `Listener of "${e.name}" failed: ${m(t)}`);
|
|
555
|
+
}
|
|
556
|
+
},
|
|
557
|
+
close() {
|
|
558
|
+
if (!d) try {
|
|
559
|
+
u.fire(void 0);
|
|
560
|
+
} finally {
|
|
561
|
+
u.dispose(), C();
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
dispose() {
|
|
565
|
+
u.dispose(), C();
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
function N(e) {
|
|
570
|
+
let t = typeof e == "string" ? v(e) : "must be a string";
|
|
571
|
+
if (t !== void 0) throw new T("view/load-failed", `Asset path ${JSON.stringify(e)} ${t}.`);
|
|
572
|
+
}
|
|
573
|
+
//#endregion
|
|
574
|
+
//#region src/fused/html/environment/content.ts
|
|
575
|
+
var P = 16;
|
|
576
|
+
async function F(e = {}) {
|
|
577
|
+
let t = e.window ?? globalThis.window, n = C(t.location.href);
|
|
578
|
+
if (n === void 0) throw Error("The HTML view content frame has no concrete environment origin.");
|
|
579
|
+
let r = I(t.location);
|
|
580
|
+
if (r === void 0) throw Error("The HTML view content frame carries no view token.");
|
|
581
|
+
let i = a(await L(t, r, n, e.connectTimeoutMs ?? 15e3)), o = i.getProxy(A), s = i.getProxy(j), c = (e, t) => {
|
|
582
|
+
o.reportFailure(e, t).catch(() => void 0);
|
|
583
|
+
};
|
|
584
|
+
try {
|
|
585
|
+
let i = await s.view(), a = M({
|
|
586
|
+
host: o,
|
|
587
|
+
target: i.target,
|
|
588
|
+
reportFailure: c
|
|
589
|
+
});
|
|
590
|
+
o.onDidModelEvent((e) => a.deliver(e)), o.onDidClose(() => a.close()), B(t, a), await R(t, i.token, e.attachTimeoutMs ?? 1e4);
|
|
591
|
+
let l = {
|
|
592
|
+
type: O,
|
|
593
|
+
token: r
|
|
594
|
+
};
|
|
595
|
+
t.parent.postMessage(l, n);
|
|
596
|
+
} catch (e) {
|
|
597
|
+
throw c("view/load-failed", m(e)), e;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
function I(e) {
|
|
601
|
+
let t = new URLSearchParams(e.search).get(k);
|
|
602
|
+
return t !== null && t.length >= P ? t : void 0;
|
|
603
|
+
}
|
|
604
|
+
function L(e, t, n, r) {
|
|
605
|
+
return new Promise((i, a) => {
|
|
606
|
+
let o = r > 0 ? setTimeout(() => {
|
|
607
|
+
e.removeEventListener("message", s), a(/* @__PURE__ */ Error("The environment did not hand over a bridge port."));
|
|
608
|
+
}, r) : void 0, s = (r) => {
|
|
609
|
+
let a = r.data;
|
|
610
|
+
if (typeof a != "object" || !a || a.type !== "mica:view:child-connect" || a.token !== t || r.source !== e.parent || r.origin !== n) return;
|
|
611
|
+
let c = r.ports[0];
|
|
612
|
+
c !== void 0 && (o !== void 0 && clearTimeout(o), e.removeEventListener("message", s), i(c));
|
|
613
|
+
};
|
|
614
|
+
e.addEventListener("message", s);
|
|
615
|
+
let c = {
|
|
616
|
+
type: D,
|
|
617
|
+
token: t
|
|
618
|
+
};
|
|
619
|
+
e.parent.postMessage(c, n);
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
async function R(e, t, n) {
|
|
623
|
+
let r = e.navigator?.serviceWorker;
|
|
624
|
+
if (r === void 0) throw Error("This browser has no service worker support, so package files cannot load.");
|
|
625
|
+
let i = await z(r, n);
|
|
626
|
+
return new Promise((e, r) => {
|
|
627
|
+
let a = new MessageChannel(), o = n > 0 ? setTimeout(() => {
|
|
628
|
+
a.port1.close(), r(/* @__PURE__ */ Error("The package asset worker did not authorize the view."));
|
|
629
|
+
}, n) : void 0;
|
|
630
|
+
a.port1.addEventListener("message", (n) => {
|
|
631
|
+
let r = n.data;
|
|
632
|
+
typeof r == "object" && r && r.type === "mica:view:attach-ack" && r.token === t && (o !== void 0 && clearTimeout(o), a.port1.close(), e());
|
|
633
|
+
}), a.port1.start();
|
|
634
|
+
let s = {
|
|
635
|
+
type: E,
|
|
636
|
+
token: t
|
|
637
|
+
};
|
|
638
|
+
i.postMessage(s, [a.port2]);
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
function z(e, t) {
|
|
642
|
+
let n = e.controller;
|
|
643
|
+
return n === null ? new Promise((n, r) => {
|
|
644
|
+
let i = () => {
|
|
645
|
+
let t = e.controller;
|
|
646
|
+
t !== null && (a !== void 0 && clearTimeout(a), e.removeEventListener("controllerchange", i), n(t));
|
|
647
|
+
}, a = t > 0 ? setTimeout(() => {
|
|
648
|
+
e.removeEventListener("controllerchange", i), r(/* @__PURE__ */ Error("The package asset worker does not control the view."));
|
|
649
|
+
}, t) : void 0;
|
|
650
|
+
e.addEventListener("controllerchange", i, { once: !0 }), i();
|
|
651
|
+
}) : Promise.resolve(n);
|
|
652
|
+
}
|
|
653
|
+
function B(e, t) {
|
|
654
|
+
let n;
|
|
655
|
+
Object.defineProperty(e, "acquireDeviceViewApi", {
|
|
656
|
+
value: () => n ??= Promise.resolve(t.api),
|
|
657
|
+
enumerable: !1,
|
|
658
|
+
writable: !1,
|
|
659
|
+
configurable: !1
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
globalThis.window !== void 0 && globalThis.document !== void 0 && F().catch((e) => {
|
|
663
|
+
console.error("[@mica-js/editor] device view content failed", e);
|
|
664
|
+
});
|
|
665
|
+
//#endregion
|
|
666
|
+
export { F as startHtmlViewContent };
|