@wix/himalaya-cli 0.1520.0 → 0.1522.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/webview-page/src/webTransport.d.ts +21 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/webview-page.mjs +223 -1
- package/dist/cli.mjs +1051 -555
- package/dist/preview-assets.generated.bin +0 -0
- package/package.json +2 -2
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HimalayaWorkerBridge } from "./client.js";
|
|
2
|
+
export declare const ANNOUNCE = "webview.announce";
|
|
3
|
+
export declare const PORT = "webview.port";
|
|
4
|
+
export declare const HOST_CONTROL = "webview.host";
|
|
5
|
+
interface FrameWindow {
|
|
6
|
+
parent: unknown;
|
|
7
|
+
addEventListener(type: "message", listener: (event: MessageEvent) => void): void;
|
|
8
|
+
removeEventListener(type: "message", listener: (event: MessageEvent) => void): void;
|
|
9
|
+
setTimeout(handler: () => void, ms: number): unknown;
|
|
10
|
+
clearTimeout(id: unknown): void;
|
|
11
|
+
document?: Document;
|
|
12
|
+
console?: Console;
|
|
13
|
+
MutationObserver?: typeof MutationObserver;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The worker bridge for a page framed by a web host, or `undefined` when this page is not in a frame.
|
|
17
|
+
* Announces at once and keeps announcing until the host answers (the host may still be loading its
|
|
18
|
+
* bridge when the page is ready).
|
|
19
|
+
*/
|
|
20
|
+
export declare function createWebFrameBridge(win: FrameWindow): HimalayaWorkerBridge | undefined;
|
|
21
|
+
export {};
|
|
@@ -266,8 +266,230 @@ function createPageClient(getBridge) {
|
|
|
266
266
|
return { call: call2, on: on2, enabledCapabilities: enabledCapabilities2, isEnabled: isEnabled2, probe: probe2, namespace, merge };
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
+
// ../../core/sdk/webview-page/src/webTransport.ts
|
|
270
|
+
var ANNOUNCE = "webview.announce";
|
|
271
|
+
var PORT = "webview.port";
|
|
272
|
+
var HOST_CONTROL = "webview.host";
|
|
273
|
+
var MAX_HELD = 256;
|
|
274
|
+
var RETRANSMIT_FAST_MS = 250;
|
|
275
|
+
var RETRANSMITS_FAST = 40;
|
|
276
|
+
var RETRANSMIT_SLOW_MS = 2e3;
|
|
277
|
+
var RETRANSMITS = 70;
|
|
278
|
+
function randomDoc() {
|
|
279
|
+
const c = globalThis.crypto;
|
|
280
|
+
if (c && typeof c.getRandomValues === "function") {
|
|
281
|
+
const b = new Uint8Array(12);
|
|
282
|
+
c.getRandomValues(b);
|
|
283
|
+
return Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
284
|
+
}
|
|
285
|
+
return Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
286
|
+
}
|
|
287
|
+
function createWebFrameBridge(win) {
|
|
288
|
+
const parent = win.parent;
|
|
289
|
+
if (!parent || parent === win || typeof parent.postMessage !== "function") return void 0;
|
|
290
|
+
const doc = randomDoc();
|
|
291
|
+
const handlers = [];
|
|
292
|
+
let port = null;
|
|
293
|
+
let held = [];
|
|
294
|
+
let retransmits = 0;
|
|
295
|
+
let timer = null;
|
|
296
|
+
const media = createMediaControls(win);
|
|
297
|
+
const announce = () => {
|
|
298
|
+
timer = null;
|
|
299
|
+
if (port) return;
|
|
300
|
+
try {
|
|
301
|
+
parent.postMessage({ himalaya: ANNOUNCE, v: 1, doc }, "*");
|
|
302
|
+
} catch {
|
|
303
|
+
}
|
|
304
|
+
if (retransmits < RETRANSMITS) {
|
|
305
|
+
timer = win.setTimeout(announce, retransmits < RETRANSMITS_FAST ? RETRANSMIT_FAST_MS : RETRANSMIT_SLOW_MS);
|
|
306
|
+
retransmits++;
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
const deliver = (message) => {
|
|
310
|
+
for (const h of [...handlers]) {
|
|
311
|
+
try {
|
|
312
|
+
h(message);
|
|
313
|
+
} catch {
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
const send = (raw) => {
|
|
318
|
+
if (port) {
|
|
319
|
+
try {
|
|
320
|
+
port.postMessage(raw);
|
|
321
|
+
} catch {
|
|
322
|
+
}
|
|
323
|
+
} else if (held.length < MAX_HELD) {
|
|
324
|
+
held.push(raw);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
const onWindowMessage = (event) => {
|
|
328
|
+
if (port || event.source !== parent) return;
|
|
329
|
+
const data = event.data;
|
|
330
|
+
if (!data || typeof data !== "object" || data.himalaya !== PORT || data.v !== 1 || data.doc !== doc) return;
|
|
331
|
+
const p = event.ports?.[0];
|
|
332
|
+
if (!p) return;
|
|
333
|
+
port = p;
|
|
334
|
+
win.removeEventListener("message", onWindowMessage);
|
|
335
|
+
if (timer != null) {
|
|
336
|
+
win.clearTimeout(timer);
|
|
337
|
+
timer = null;
|
|
338
|
+
}
|
|
339
|
+
p.onmessage = (e) => {
|
|
340
|
+
const m = e.data;
|
|
341
|
+
if (typeof m === "string") {
|
|
342
|
+
let parsed = m;
|
|
343
|
+
try {
|
|
344
|
+
parsed = JSON.parse(m);
|
|
345
|
+
} catch {
|
|
346
|
+
}
|
|
347
|
+
deliver(parsed);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
const c = m;
|
|
351
|
+
if (c && typeof c === "object" && c.himalaya === HOST_CONTROL && c.v === 1 && typeof c.value === "boolean") {
|
|
352
|
+
if (c.op === "active") media.setActive(c.value);
|
|
353
|
+
else if (c.op === "muted") media.setMuted(c.value);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
p.start?.();
|
|
357
|
+
if (data.active === false) media.setActive(false);
|
|
358
|
+
if (data.muted === true) media.setMuted(true);
|
|
359
|
+
const consoleCfg = data.console;
|
|
360
|
+
if (consoleCfg && typeof consoleCfg === "object") {
|
|
361
|
+
wrapConsole(
|
|
362
|
+
win,
|
|
363
|
+
(payload) => send(JSON.stringify({ kind: "worker.message", payload })),
|
|
364
|
+
typeof consoleCfg.maxArgs === "number" ? consoleCfg.maxArgs : 16,
|
|
365
|
+
typeof consoleCfg.argLength === "number" ? consoleCfg.argLength : 2048
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
const queued = held;
|
|
369
|
+
held = [];
|
|
370
|
+
for (const raw of queued) send(raw);
|
|
371
|
+
};
|
|
372
|
+
win.addEventListener("message", onWindowMessage);
|
|
373
|
+
announce();
|
|
374
|
+
return {
|
|
375
|
+
post(message) {
|
|
376
|
+
let raw;
|
|
377
|
+
try {
|
|
378
|
+
raw = JSON.stringify({ kind: "worker.message", payload: message === void 0 ? null : message });
|
|
379
|
+
} catch {
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
send(raw);
|
|
383
|
+
return true;
|
|
384
|
+
},
|
|
385
|
+
onMessage(handler) {
|
|
386
|
+
if (typeof handler === "function") handlers.push(handler);
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function wrapConsole(win, post, maxArgs, maxLength) {
|
|
391
|
+
const c = win.console;
|
|
392
|
+
if (!c || c.__himalayaConsoleForwarding) return;
|
|
393
|
+
Object.defineProperty(c, "__himalayaConsoleForwarding", { value: true });
|
|
394
|
+
const text = (a) => {
|
|
395
|
+
if (a instanceof Error) a = String(a.stack || a);
|
|
396
|
+
let s;
|
|
397
|
+
try {
|
|
398
|
+
s = JSON.stringify(a);
|
|
399
|
+
} catch {
|
|
400
|
+
s = void 0;
|
|
401
|
+
}
|
|
402
|
+
if (typeof s !== "string") {
|
|
403
|
+
try {
|
|
404
|
+
s = JSON.stringify(String(a));
|
|
405
|
+
} catch {
|
|
406
|
+
s = '"[unserializable]"';
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
s = s.replace(/[<\u007f--]/g, (ch) => "\\u" + ("000" + ch.charCodeAt(0).toString(16)).slice(-4));
|
|
410
|
+
return s.length > maxLength ? s.slice(0, maxLength) : s;
|
|
411
|
+
};
|
|
412
|
+
for (const level of ["log", "info", "warn", "error", "debug"]) {
|
|
413
|
+
const original = c[level];
|
|
414
|
+
c[level] = function(...args) {
|
|
415
|
+
try {
|
|
416
|
+
original?.apply(c, args);
|
|
417
|
+
} catch {
|
|
418
|
+
}
|
|
419
|
+
try {
|
|
420
|
+
post({ v: 1, sys: "console", iid: "", level, args: args.slice(0, maxArgs).map(text) });
|
|
421
|
+
} catch {
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function createMediaControls(win) {
|
|
427
|
+
const document = win.document;
|
|
428
|
+
const pausedByUs = /* @__PURE__ */ new Set();
|
|
429
|
+
const mutedByUs = /* @__PURE__ */ new Set();
|
|
430
|
+
let observer = null;
|
|
431
|
+
const all = () => document ? Array.from(document.querySelectorAll("audio,video")) : [];
|
|
432
|
+
const mute = (el) => {
|
|
433
|
+
if (!el.muted) {
|
|
434
|
+
el.muted = true;
|
|
435
|
+
mutedByUs.add(el);
|
|
436
|
+
}
|
|
437
|
+
};
|
|
438
|
+
return {
|
|
439
|
+
setActive(active) {
|
|
440
|
+
if (!document) return;
|
|
441
|
+
if (!active) {
|
|
442
|
+
Object.defineProperty(document, "visibilityState", { configurable: true, get: () => "hidden" });
|
|
443
|
+
Object.defineProperty(document, "hidden", { configurable: true, get: () => true });
|
|
444
|
+
for (const el of all()) if (!el.paused) {
|
|
445
|
+
try {
|
|
446
|
+
el.pause();
|
|
447
|
+
pausedByUs.add(el);
|
|
448
|
+
} catch {
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
} else {
|
|
452
|
+
delete document.visibilityState;
|
|
453
|
+
delete document.hidden;
|
|
454
|
+
for (const el of pausedByUs) {
|
|
455
|
+
try {
|
|
456
|
+
void el.play()?.catch?.(() => {
|
|
457
|
+
});
|
|
458
|
+
} catch {
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
pausedByUs.clear();
|
|
462
|
+
}
|
|
463
|
+
try {
|
|
464
|
+
document.dispatchEvent(new Event("visibilitychange"));
|
|
465
|
+
} catch {
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
setMuted(muted) {
|
|
469
|
+
if (!document) return;
|
|
470
|
+
if (muted) {
|
|
471
|
+
for (const el of all()) mute(el);
|
|
472
|
+
const MO = win.MutationObserver;
|
|
473
|
+
if (!observer && MO && document.documentElement) {
|
|
474
|
+
observer = new MO(() => {
|
|
475
|
+
for (const el of all()) mute(el);
|
|
476
|
+
});
|
|
477
|
+
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
478
|
+
}
|
|
479
|
+
} else {
|
|
480
|
+
observer?.disconnect();
|
|
481
|
+
observer = null;
|
|
482
|
+
for (const el of mutedByUs) el.muted = false;
|
|
483
|
+
mutedByUs.clear();
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
|
|
269
489
|
// ../../core/sdk/webview-page/src/index.ts
|
|
270
|
-
var
|
|
490
|
+
var injected = () => globalThis.HimalayaWorker;
|
|
491
|
+
var webFrame = injected() || typeof window === "undefined" ? void 0 : createWebFrameBridge(window);
|
|
492
|
+
var client = createPageClient(() => injected() ?? webFrame);
|
|
271
493
|
function call(capability, method, args = [], timeoutMs = 3e4) {
|
|
272
494
|
return client.call(capability, method, args, timeoutMs);
|
|
273
495
|
}
|