@mica-js/editor 0.3.2 → 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,783 @@
|
|
|
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
|
+
//#endregion
|
|
325
|
+
//#region src/fused/runtime/wire.ts
|
|
326
|
+
function u(e) {
|
|
327
|
+
return e instanceof Error ? e.message : String(e);
|
|
328
|
+
}
|
|
329
|
+
var d = "environment-sw.js", f = [
|
|
330
|
+
"default-src 'none'",
|
|
331
|
+
"script-src 'self' 'unsafe-inline'",
|
|
332
|
+
"style-src 'self' 'unsafe-inline'",
|
|
333
|
+
"img-src 'self' data: blob:",
|
|
334
|
+
"font-src 'self' data: blob:",
|
|
335
|
+
"media-src 'self' data: blob:",
|
|
336
|
+
"connect-src 'self' blob:",
|
|
337
|
+
"frame-src 'none'",
|
|
338
|
+
"object-src 'none'",
|
|
339
|
+
"form-action 'none'",
|
|
340
|
+
"base-uri 'self'"
|
|
341
|
+
].join("; ");
|
|
342
|
+
[
|
|
343
|
+
"default-src 'none'",
|
|
344
|
+
"script-src 'self' 'unsafe-inline'",
|
|
345
|
+
"style-src 'self' 'unsafe-inline'",
|
|
346
|
+
"img-src 'self' data: blob:",
|
|
347
|
+
"font-src 'self' data: blob:",
|
|
348
|
+
"media-src 'self' data: blob:",
|
|
349
|
+
"connect-src 'self' blob:",
|
|
350
|
+
"worker-src 'self'",
|
|
351
|
+
"frame-src 'self'",
|
|
352
|
+
"object-src 'none'",
|
|
353
|
+
"form-action 'none'",
|
|
354
|
+
"base-uri 'self'"
|
|
355
|
+
].join("; ");
|
|
356
|
+
function p(e, t) {
|
|
357
|
+
let n = e.href.endsWith("/") ? e.href : `${e.href}/`, r = t.lastIndexOf("/");
|
|
358
|
+
return r <= 0 ? n : `${n}${t.slice(0, r + 1)}`;
|
|
359
|
+
}
|
|
360
|
+
Object.freeze({
|
|
361
|
+
html: "text/html; charset=utf-8",
|
|
362
|
+
htm: "text/html; charset=utf-8",
|
|
363
|
+
js: "text/javascript; charset=utf-8",
|
|
364
|
+
mjs: "text/javascript; charset=utf-8",
|
|
365
|
+
css: "text/css; charset=utf-8",
|
|
366
|
+
json: "application/json; charset=utf-8",
|
|
367
|
+
map: "application/json; charset=utf-8",
|
|
368
|
+
svg: "image/svg+xml",
|
|
369
|
+
png: "image/png",
|
|
370
|
+
jpg: "image/jpeg",
|
|
371
|
+
jpeg: "image/jpeg",
|
|
372
|
+
gif: "image/gif",
|
|
373
|
+
webp: "image/webp",
|
|
374
|
+
avif: "image/avif",
|
|
375
|
+
ico: "image/x-icon",
|
|
376
|
+
woff: "font/woff",
|
|
377
|
+
woff2: "font/woff2",
|
|
378
|
+
ttf: "font/ttf",
|
|
379
|
+
otf: "font/otf",
|
|
380
|
+
wasm: "application/wasm",
|
|
381
|
+
txt: "text/plain; charset=utf-8",
|
|
382
|
+
bin: "application/octet-stream"
|
|
383
|
+
});
|
|
384
|
+
function m(e, t) {
|
|
385
|
+
let n = [
|
|
386
|
+
"<meta charset=\"utf-8\">",
|
|
387
|
+
`<meta http-equiv="Content-Security-Policy" content="${v(t.policy)}">`,
|
|
388
|
+
`<base href="${v(t.base)}">`,
|
|
389
|
+
`<style>${t.style.replace(/<\/style/gi, "<\\/style")}</style>`
|
|
390
|
+
].join(""), r = /<head\b[^>]*>/i.exec(e);
|
|
391
|
+
if (r !== null) {
|
|
392
|
+
let t = r.index + r[0].length;
|
|
393
|
+
return `${e.slice(0, t)}${n}${e.slice(t)}`;
|
|
394
|
+
}
|
|
395
|
+
let i = /<html\b[^>]*>/i.exec(e);
|
|
396
|
+
if (i !== null) {
|
|
397
|
+
let t = i.index + i[0].length;
|
|
398
|
+
return `${e.slice(0, t)}<head>${n}</head>${e.slice(t)}`;
|
|
399
|
+
}
|
|
400
|
+
let a = /<!doctype[^>]*>/i.exec(e);
|
|
401
|
+
if (a !== null) {
|
|
402
|
+
let t = a.index + a[0].length;
|
|
403
|
+
return `${e.slice(0, t)}<head>${n}</head>${e.slice(t)}`;
|
|
404
|
+
}
|
|
405
|
+
return `<head>${n}</head>${e}`;
|
|
406
|
+
}
|
|
407
|
+
var h = /^https?:\/\/[^/]+$/;
|
|
408
|
+
function g(e) {
|
|
409
|
+
if (e !== void 0 && e !== "") try {
|
|
410
|
+
let t = new URL(e);
|
|
411
|
+
return t.protocol !== "http:" && t.protocol !== "https:" ? void 0 : h.test(t.origin) ? t.origin : void 0;
|
|
412
|
+
} catch {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
function _(e) {
|
|
417
|
+
return new TextDecoder().decode(e).replace(/^\uFEFF/, "");
|
|
418
|
+
}
|
|
419
|
+
function v(e) {
|
|
420
|
+
return e.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
421
|
+
}
|
|
422
|
+
var y = "mica:view:ack", b = "mica:view:assets", x = "mica:view:child-connect", S = "view";
|
|
423
|
+
l("fused-html-host");
|
|
424
|
+
var C = l("fused-html-host-control");
|
|
425
|
+
l("fused-html-asset"), l("fused-html-content-view");
|
|
426
|
+
//#endregion
|
|
427
|
+
//#region src/fused/theme.ts
|
|
428
|
+
var w = Object.freeze({
|
|
429
|
+
"workbench.background": "--mica-bg",
|
|
430
|
+
"workbench.foreground": "--mica-text",
|
|
431
|
+
"workbench.mutedForeground": "--mica-muted",
|
|
432
|
+
"panel.background": "--mica-panel",
|
|
433
|
+
border: "--mica-border",
|
|
434
|
+
accent: "--mica-accent",
|
|
435
|
+
"accent.foreground": "--mica-accent-foreground",
|
|
436
|
+
"selection.background": "--mica-active",
|
|
437
|
+
"focus.border": "--mica-focus",
|
|
438
|
+
"canvas.background": "--mica-canvas-background",
|
|
439
|
+
"canvas.grid": "--mica-canvas-grid",
|
|
440
|
+
"canvas.foreground": "--mica-canvas-foreground",
|
|
441
|
+
"canvas.wire": "--mica-canvas-wire",
|
|
442
|
+
"canvas.pin": "--mica-canvas-pin",
|
|
443
|
+
"canvas.selection": "--mica-canvas-selection",
|
|
444
|
+
"error.foreground": "--mica-error",
|
|
445
|
+
shadow: "--mica-shadow"
|
|
446
|
+
}), T = Object.freeze({
|
|
447
|
+
"workbench.background": "#1c1c1c",
|
|
448
|
+
"workbench.foreground": "#e5e5e5",
|
|
449
|
+
"workbench.mutedForeground": "#a3a3a3",
|
|
450
|
+
"panel.background": "#242424",
|
|
451
|
+
border: "#383838",
|
|
452
|
+
accent: "#d4d4d4",
|
|
453
|
+
"accent.foreground": "#171717",
|
|
454
|
+
"selection.background": "#353535",
|
|
455
|
+
"focus.border": "#b8b8b8",
|
|
456
|
+
"canvas.background": "#151515",
|
|
457
|
+
"canvas.grid": "#303030",
|
|
458
|
+
"canvas.foreground": "#d4d4d4",
|
|
459
|
+
"canvas.wire": "#a3a3a3",
|
|
460
|
+
"canvas.pin": "#c4c4c4",
|
|
461
|
+
"canvas.selection": "#eeeeee",
|
|
462
|
+
"error.foreground": "#f28b82",
|
|
463
|
+
shadow: "#00000055"
|
|
464
|
+
}), E = Object.freeze({
|
|
465
|
+
"workbench.background": "#ffffff",
|
|
466
|
+
"workbench.foreground": "#263247",
|
|
467
|
+
"workbench.mutedForeground": "#748098",
|
|
468
|
+
"panel.background": "#fafbfe",
|
|
469
|
+
border: "#e2e6ed",
|
|
470
|
+
accent: "#336df0",
|
|
471
|
+
"accent.foreground": "#ffffff",
|
|
472
|
+
"selection.background": "#e8efff",
|
|
473
|
+
"focus.border": "#336df0",
|
|
474
|
+
"canvas.background": "#f6f7fa",
|
|
475
|
+
"canvas.grid": "#cdd3de",
|
|
476
|
+
"canvas.foreground": "#354058",
|
|
477
|
+
"canvas.wire": "#508d79",
|
|
478
|
+
"canvas.pin": "#4285ff",
|
|
479
|
+
"canvas.selection": "#4285ff",
|
|
480
|
+
"error.foreground": "#b43b35",
|
|
481
|
+
shadow: "#00000022"
|
|
482
|
+
}), D = Object.freeze({
|
|
483
|
+
appearance: "dark",
|
|
484
|
+
colors: T
|
|
485
|
+
}), O = Object.keys(w), k = "panel.background";
|
|
486
|
+
function A(e) {
|
|
487
|
+
return e.colors[k];
|
|
488
|
+
}
|
|
489
|
+
var j = /[;{}<>\\]/;
|
|
490
|
+
function M(e) {
|
|
491
|
+
if (typeof e != "object" || !e) throw TypeError("An HTML view theme must be an object");
|
|
492
|
+
let t = e, n = t.appearance ?? "dark";
|
|
493
|
+
if (n !== "dark" && n !== "light") throw TypeError(`Unknown HTML view theme appearance: ${String(n)}`);
|
|
494
|
+
let r = { ...n === "dark" ? T : E }, i = t.colors;
|
|
495
|
+
if (i != null) {
|
|
496
|
+
if (typeof i != "object") throw TypeError("HTML view theme colors must be an object");
|
|
497
|
+
for (let [e, t] of Object.entries(i)) {
|
|
498
|
+
if (!Object.hasOwn(w, e)) throw TypeError(`Unknown HTML view theme token: ${e}`);
|
|
499
|
+
r[e] = N(e, t);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
for (let e of O) r[e] ??= N(e, T[e]);
|
|
503
|
+
return Object.freeze({
|
|
504
|
+
appearance: n,
|
|
505
|
+
colors: Object.freeze(r)
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
function N(e, t) {
|
|
509
|
+
if (typeof t != "string" || t.trim() === "") throw TypeError(`HTML view theme token ${e} must be a non-empty CSS color`);
|
|
510
|
+
if (j.test(t)) throw TypeError(`HTML view theme token ${e} must be a plain CSS color`);
|
|
511
|
+
return t.trim();
|
|
512
|
+
}
|
|
513
|
+
function P(e) {
|
|
514
|
+
let t = O.map((t) => `${w[t]}:${e.colors[t]}`);
|
|
515
|
+
return t.push(`color-scheme:${e.appearance}`), `:root{background-color:${A(e)};${t.join(";")}}`;
|
|
516
|
+
}
|
|
517
|
+
function F(e, t) {
|
|
518
|
+
let n = e.style;
|
|
519
|
+
for (let e of O) n.setProperty(w[e], t.colors[e]);
|
|
520
|
+
n.setProperty("color-scheme", t.appearance), n.setProperty("background-color", A(t));
|
|
521
|
+
}
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region src/fused/html/environment/entry.ts
|
|
524
|
+
async function I(e = {}) {
|
|
525
|
+
let t = e.window ?? globalThis.window, n = e.document ?? t.document, { message: r, port: i } = await G(t, e.handshakeTimeoutMs ?? 15e3);
|
|
526
|
+
t.parent.postMessage({
|
|
527
|
+
type: y,
|
|
528
|
+
token: r.token
|
|
529
|
+
}, r.parentOrigin);
|
|
530
|
+
let o = a(i).getProxy(C), s = (e, t) => {
|
|
531
|
+
o.reportFailure(e, t).catch(() => void 0);
|
|
532
|
+
}, c = R(o, s, n);
|
|
533
|
+
try {
|
|
534
|
+
await c.load(), await K(t, r, o, e.workerTimeoutMs ?? 1e4), L({
|
|
535
|
+
window: t,
|
|
536
|
+
document: n,
|
|
537
|
+
control: o,
|
|
538
|
+
message: r,
|
|
539
|
+
authored: _(await o.readAsset(r.target.entry)),
|
|
540
|
+
theme: c,
|
|
541
|
+
contentUrl: e.contentUrl ?? new URL("content.html", import.meta.url).href,
|
|
542
|
+
budgetMs: e.contentTimeoutMs ?? 15e3,
|
|
543
|
+
report: s
|
|
544
|
+
}), t.addEventListener("pagehide", () => {
|
|
545
|
+
try {
|
|
546
|
+
o.closed();
|
|
547
|
+
} catch {}
|
|
548
|
+
});
|
|
549
|
+
} catch (e) {
|
|
550
|
+
throw s("view/load-failed", u(e)), e;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function L(e) {
|
|
554
|
+
let { window: t, document: n, control: r, message: i, authored: a, theme: o, report: s } = e, c = i.target, l = g(t.location.href);
|
|
555
|
+
if (l === void 0) throw Error("The environment page has no concrete origin.");
|
|
556
|
+
let d = Y(), h = new URL(e.contentUrl);
|
|
557
|
+
if (g(h.href) !== l) throw Error("The content document must be served from the environment origin.");
|
|
558
|
+
h.searchParams.set(S, d);
|
|
559
|
+
let _ = n.createElement("iframe");
|
|
560
|
+
_.className = "mica-html-view-document", _.title = `${c.title} — ${c.device}`, _.setAttribute("sandbox", "allow-scripts allow-same-origin"), _.setAttribute("referrerpolicy", "no-referrer"), _.setAttribute("allow", ""), _.style.display = "block", _.style.width = "100%", _.style.height = "100%", _.style.border = "0", _.style.background = A(o.current), o.track(_);
|
|
561
|
+
let v = !1, y = !1, b = !1, C = !1, w, T, E = (e) => {
|
|
562
|
+
C || (C = !0, D(), s("view/execution-failed", e));
|
|
563
|
+
}, D = () => {
|
|
564
|
+
T !== void 0 && (clearTimeout(T), T = void 0);
|
|
565
|
+
}, O = (e) => {
|
|
566
|
+
let t = e.data;
|
|
567
|
+
typeof t == "object" && t && t.type === "mica:view:child-hello" && t.token === d && e.source === _.contentWindow && e.origin === l && (C || (v || y ? E("The HTML view document started twice.") : (y = !0, D(), r.contentPort().then((e) => {
|
|
568
|
+
if (v || C) {
|
|
569
|
+
e.close();
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
let t = _.contentWindow;
|
|
573
|
+
if (t === null) {
|
|
574
|
+
e.close(), E("The HTML view document frame is not available.");
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (!W(_, h.href)) {
|
|
578
|
+
e.close(), E("The HTML view navigated away from its author document.");
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
y = !1, v = !0;
|
|
582
|
+
let n = {
|
|
583
|
+
type: x,
|
|
584
|
+
token: d
|
|
585
|
+
};
|
|
586
|
+
try {
|
|
587
|
+
t.postMessage(n, l, [e]);
|
|
588
|
+
} catch (e) {
|
|
589
|
+
E(`The HTML view bridge port was rejected: ${u(e)}`);
|
|
590
|
+
}
|
|
591
|
+
}, (e) => {
|
|
592
|
+
v || C || E(`The HTML view bridge port was not granted: ${u(e)}`);
|
|
593
|
+
}))));
|
|
594
|
+
}, k = (e) => {
|
|
595
|
+
let t = e.data;
|
|
596
|
+
if (typeof t == "object" && t && t.type === "mica:view:child-prepared" && t.token === d && e.source === _.contentWindow && e.origin === l && v && !C) {
|
|
597
|
+
try {
|
|
598
|
+
j();
|
|
599
|
+
} catch (e) {
|
|
600
|
+
E(u(e));
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
r.ready().catch((e) => {
|
|
604
|
+
E(`The HTML view was not reported ready: ${u(e)}`);
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
function j() {
|
|
609
|
+
if (b) throw Error("The author document was already written.");
|
|
610
|
+
let e = U(_);
|
|
611
|
+
if (e === null) throw Error("The HTML view document frame is not available.");
|
|
612
|
+
if (w !== void 0 && e !== w) throw Error("The HTML view document changed before its author document was written.");
|
|
613
|
+
w = e, e.open(), B(V(_), s), e.write(m(a, {
|
|
614
|
+
base: p(new URL(c.assetRoot), c.entry),
|
|
615
|
+
policy: f,
|
|
616
|
+
style: P(o.current)
|
|
617
|
+
})), e.close(), b = !0, o.track(_);
|
|
618
|
+
}
|
|
619
|
+
_.addEventListener("load", () => {
|
|
620
|
+
let e = U(_);
|
|
621
|
+
if (e === null) E("The HTML view navigated away from its author document.");
|
|
622
|
+
else if (w === void 0) {
|
|
623
|
+
if (!W(_, h.href)) {
|
|
624
|
+
E("The HTML view navigated away from its author document.");
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
w = e, o.track(_);
|
|
628
|
+
} else e === w ? o.track(_) : E("The HTML view navigated away from its author document.");
|
|
629
|
+
}), t.addEventListener("message", O), t.addEventListener("message", k);
|
|
630
|
+
let M = n.body ?? n.documentElement;
|
|
631
|
+
_.src = h.href, M.append(_), e.budgetMs > 0 && (T = setTimeout(() => {
|
|
632
|
+
T = void 0, E("The HTML view document did not start in time.");
|
|
633
|
+
}, e.budgetMs));
|
|
634
|
+
}
|
|
635
|
+
function R(e, t, n) {
|
|
636
|
+
let r = D, i = 0, a, o = () => {
|
|
637
|
+
try {
|
|
638
|
+
F(n.documentElement, r);
|
|
639
|
+
} catch {}
|
|
640
|
+
if (a === void 0) return;
|
|
641
|
+
try {
|
|
642
|
+
a.style.background = A(r);
|
|
643
|
+
} catch {}
|
|
644
|
+
let e = H(a);
|
|
645
|
+
if (e !== null) try {
|
|
646
|
+
F(e, r);
|
|
647
|
+
} catch {}
|
|
648
|
+
};
|
|
649
|
+
return e.onDidThemeChange((e) => {
|
|
650
|
+
i += 1, r = z(e, r, t), o();
|
|
651
|
+
}), {
|
|
652
|
+
get current() {
|
|
653
|
+
return r;
|
|
654
|
+
},
|
|
655
|
+
async load() {
|
|
656
|
+
let n;
|
|
657
|
+
try {
|
|
658
|
+
n = await e.getTheme();
|
|
659
|
+
} catch (e) {
|
|
660
|
+
t("view/bridge-failed", `The workbench theme is unavailable: ${u(e)}`);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
i > 0 || (r = z(n, r, t), o());
|
|
664
|
+
},
|
|
665
|
+
track(e) {
|
|
666
|
+
a = e, o();
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
function z(e, t, n) {
|
|
671
|
+
try {
|
|
672
|
+
return M(e);
|
|
673
|
+
} catch (e) {
|
|
674
|
+
return n("view/bridge-failed", `The workbench sent an unusable theme: ${u(e)}`), t;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function B(e, t) {
|
|
678
|
+
e !== null && (e.addEventListener("error", (e) => {
|
|
679
|
+
t("view/execution-failed", e.message);
|
|
680
|
+
}), e.addEventListener("unhandledrejection", (e) => {
|
|
681
|
+
t("view/execution-failed", u(e.reason));
|
|
682
|
+
}));
|
|
683
|
+
}
|
|
684
|
+
function V(e) {
|
|
685
|
+
try {
|
|
686
|
+
return e.contentWindow;
|
|
687
|
+
} catch {
|
|
688
|
+
return null;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
function H(e) {
|
|
692
|
+
try {
|
|
693
|
+
return e.contentDocument?.documentElement ?? null;
|
|
694
|
+
} catch {
|
|
695
|
+
return null;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
function U(e) {
|
|
699
|
+
try {
|
|
700
|
+
return e.contentDocument ?? null;
|
|
701
|
+
} catch {
|
|
702
|
+
return null;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
function W(e, t) {
|
|
706
|
+
try {
|
|
707
|
+
let n = e.contentWindow;
|
|
708
|
+
return n !== null && new URL(n.location.href).href === new URL(t).href;
|
|
709
|
+
} catch {
|
|
710
|
+
return !1;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
function G(e, t) {
|
|
714
|
+
return new Promise((n, r) => {
|
|
715
|
+
let i = t > 0 ? setTimeout(() => {
|
|
716
|
+
e.removeEventListener("message", a), r(/* @__PURE__ */ Error("The editor did not hand over a bridge port."));
|
|
717
|
+
}, t) : void 0, a = (t) => {
|
|
718
|
+
let r = t.data;
|
|
719
|
+
if (typeof r != "object" || !r || r.type !== "mica:view:connect" || t.source !== e.parent || typeof r.token != "string" || r.token.length === 0 || typeof r.parentOrigin != "string" || !/^https?:\/\/[^/]+$/.test(r.parentOrigin)) return;
|
|
720
|
+
let o = r.target;
|
|
721
|
+
if (typeof o != "object" || !o || typeof o.entry != "string" || typeof o.assetRoot != "string") return;
|
|
722
|
+
let s;
|
|
723
|
+
try {
|
|
724
|
+
s = new URL(o.assetRoot).origin;
|
|
725
|
+
} catch {
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
if (s !== e.location.origin) return;
|
|
729
|
+
let c = t.ports[0];
|
|
730
|
+
c !== void 0 && (i !== void 0 && clearTimeout(i), e.removeEventListener("message", a), n({
|
|
731
|
+
message: r,
|
|
732
|
+
port: c
|
|
733
|
+
}));
|
|
734
|
+
};
|
|
735
|
+
e.addEventListener("message", a);
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
async function K(e, t, n, r) {
|
|
739
|
+
let i = new URL(t.target.assetRoot), a = e.navigator;
|
|
740
|
+
if (!("serviceWorker" in a) || a.serviceWorker === void 0) throw Error("This browser has no service worker support, so package files cannot load.");
|
|
741
|
+
let o = a.serviceWorker;
|
|
742
|
+
await o.register(new URL(d, import.meta.url), { type: "module" }), await J(o, r);
|
|
743
|
+
let s = o.controller;
|
|
744
|
+
if (s === null) throw Error("The package asset worker did not activate.");
|
|
745
|
+
let c = await n.assetPort(), l = new MessageChannel(), u = q(l.port1, t.token, r), f = {
|
|
746
|
+
type: b,
|
|
747
|
+
token: t.token,
|
|
748
|
+
root: i.pathname
|
|
749
|
+
};
|
|
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
|
+
}
|
|
763
|
+
function J(e, t) {
|
|
764
|
+
return e.controller === null ? new Promise((n, r) => {
|
|
765
|
+
let i = () => {
|
|
766
|
+
o !== void 0 && clearTimeout(o), e.removeEventListener("controllerchange", a), n();
|
|
767
|
+
}, a = () => i(), o = t > 0 ? setTimeout(() => {
|
|
768
|
+
e.removeEventListener("controllerchange", a), r(/* @__PURE__ */ Error("The package asset worker did not take control of the view."));
|
|
769
|
+
}, t) : void 0;
|
|
770
|
+
e.addEventListener("controllerchange", a, { once: !0 }), e.controller !== null && i();
|
|
771
|
+
}) : Promise.resolve();
|
|
772
|
+
}
|
|
773
|
+
function Y() {
|
|
774
|
+
let e = /* @__PURE__ */ new Uint8Array(16), t = globalThis.crypto;
|
|
775
|
+
if (typeof t?.getRandomValues == "function") t.getRandomValues(e);
|
|
776
|
+
else for (let t = 0; t < e.length; t += 1) e[t] = Math.random() * 256;
|
|
777
|
+
return [...e].map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
778
|
+
}
|
|
779
|
+
globalThis.window !== void 0 && globalThis.document !== void 0 && I().catch((e) => {
|
|
780
|
+
console.error("[@mica-js/editor] device view environment failed", e);
|
|
781
|
+
});
|
|
782
|
+
//#endregion
|
|
783
|
+
export { I as startHtmlViewEnvironment };
|