@hyperframes/core 0.9.103 → 0.9.104
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/compiler/compositionScoping.js +3 -3
- package/dist/compiler/svgIdNamespacing.js +2 -2
- package/dist/fonts/authoredGoogleFonts.js +2 -2
- package/dist/fonts/deterministicFonts.js +2 -2
- package/dist/generated/runtime-inline.js +1 -1
- package/dist/hyperframe.runtime.iife.js +69 -69
- package/dist/runtime/editing/canvasKeys.d.ts +0 -1
- package/dist/runtime/editing/canvasKeys.js +4 -28
- package/dist/runtime/editing/pausedFrames.js +7 -7
- package/dist/runtime/editing/stageAct.js +3 -2
- package/dist/runtime/editing/textEdit.js +4 -3
- package/dist/runtime/editing/watchGeometry.js +8 -8
- package/dist/runtime/editingPort.d.ts +4 -1
- package/dist/runtime/editingPort.js +18 -2
- package/dist/runtime/runtimePort.d.ts +21 -0
- package/dist/runtime/runtimePort.js +122 -0
- package/dist/studioPreviewMark.d.ts +1 -0
- package/dist/studioPreviewMark.js +1 -0
- package/package.json +4 -4
|
@@ -52,7 +52,6 @@ export type CanvasKeyActionEvent = {
|
|
|
52
52
|
export declare function parseArmCanvasKeys(params: unknown): ArmCanvasKeysParams | null;
|
|
53
53
|
export declare function parseResolveCanvasKeyAction(params: unknown): ResolveCanvasKeyActionParams | null;
|
|
54
54
|
export declare function canvasKeyActionEvent(data: unknown, version: number): CanvasKeyActionEvent | null;
|
|
55
|
-
export declare function createRuntimeChannel(): MessageChannel;
|
|
56
55
|
export declare function listenFrameKeydown(view: Window, listener: (event: KeyboardEvent) => void): () => void;
|
|
57
56
|
/**
|
|
58
57
|
* Installs capture-first window key listeners in opaque-origin Studio preview frames only (never
|
|
@@ -3,6 +3,7 @@ import { matchCombo, parseCombo } from "../../keyCombo.js";
|
|
|
3
3
|
import { capturePageIn, markedForStudio } from "../../studioPreviewMark.js";
|
|
4
4
|
import { swallow } from "../diagnostics.js";
|
|
5
5
|
import { isDomNode, isElementNode, isStylableElement } from "../domRealm.js";
|
|
6
|
+
import { postOnPort } from "../runtimePort.js";
|
|
6
7
|
import { drawDrafts } from "../editingDraft.js";
|
|
7
8
|
import { EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, } from "../editingElement.js";
|
|
8
9
|
import { gsapPosition } from "../editingGestureStart.js";
|
|
@@ -142,31 +143,6 @@ const nativePreventDefault = typeof Event !== "undefined" ? Event.prototype.prev
|
|
|
142
143
|
const nativeIsTrustedGetter = typeof Event !== "undefined"
|
|
143
144
|
? Object.getOwnPropertyDescriptor(Event.prototype, "isTrusted")?.get
|
|
144
145
|
: undefined;
|
|
145
|
-
const NativeMessageChannel = typeof MessageChannel !== "undefined" ? MessageChannel : null;
|
|
146
|
-
const nativePortPostMessage = (() => {
|
|
147
|
-
if (!NativeMessageChannel)
|
|
148
|
-
return null;
|
|
149
|
-
try {
|
|
150
|
-
const probe = new NativeMessageChannel();
|
|
151
|
-
const post = Object.getPrototypeOf(probe.port1)?.postMessage;
|
|
152
|
-
probe.port1.close();
|
|
153
|
-
probe.port2.close();
|
|
154
|
-
return typeof post === "function" ? post : null;
|
|
155
|
-
}
|
|
156
|
-
catch {
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
})();
|
|
160
|
-
export function createRuntimeChannel() {
|
|
161
|
-
const Ctor = NativeMessageChannel ?? MessageChannel;
|
|
162
|
-
return new Ctor();
|
|
163
|
-
}
|
|
164
|
-
function postRuntimePort(port, message) {
|
|
165
|
-
if (nativePortPostMessage)
|
|
166
|
-
nativePortPostMessage.call(port, message);
|
|
167
|
-
else
|
|
168
|
-
port.postMessage(message);
|
|
169
|
-
}
|
|
170
146
|
function stopEvent(event) {
|
|
171
147
|
if (nativeStopImmediatePropagation)
|
|
172
148
|
nativeStopImmediatePropagation.call(event);
|
|
@@ -249,7 +225,7 @@ function runLocalDelete(state) {
|
|
|
249
225
|
}
|
|
250
226
|
const actionId = ++lastActionId;
|
|
251
227
|
pendingDeletes.set(actionId, detached);
|
|
252
|
-
|
|
228
|
+
postOnPort(state.port, {
|
|
253
229
|
v: state.version,
|
|
254
230
|
event: "canvas-key-action",
|
|
255
231
|
action: "delete",
|
|
@@ -288,7 +264,7 @@ function runLocalNudge(state, nudge, dx, dy) {
|
|
|
288
264
|
if (gsap)
|
|
289
265
|
baseGsap[handle] = { x: gsap.x, y: gsap.y };
|
|
290
266
|
const actionId = ++lastActionId;
|
|
291
|
-
|
|
267
|
+
postOnPort(state.port, {
|
|
292
268
|
v: state.version,
|
|
293
269
|
event: "canvas-key-action",
|
|
294
270
|
action: "nudge",
|
|
@@ -304,7 +280,7 @@ function runLocalNudge(state, nudge, dx, dy) {
|
|
|
304
280
|
});
|
|
305
281
|
}
|
|
306
282
|
function forwardTrustedKey(state, event) {
|
|
307
|
-
|
|
283
|
+
postOnPort(state.port, {
|
|
308
284
|
v: state.version,
|
|
309
285
|
event: "key",
|
|
310
286
|
key: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Paused video frames for a frame Studio cannot script: the runtime asks over a port Studio handed it, and Studio
|
|
2
2
|
// decodes. An ask names a path on the frame's own server and the proxy options it played, never a URL: Studio
|
|
3
3
|
// resolves it against its own project before reading anything.
|
|
4
|
+
import { closePort, onPortMessage, postOnPort } from "../runtimePort.js";
|
|
4
5
|
import { sourceFactsOfSrc } from "../mediaSourceLookup.js";
|
|
5
6
|
import { isMessageList } from "../protocol.js";
|
|
6
7
|
/** The query options the runtime's media proxy adds to a src; any other key never leaves the frame. */
|
|
@@ -95,21 +96,20 @@ export function portPausedVideoProvider(port) {
|
|
|
95
96
|
if (isRecord(frame))
|
|
96
97
|
frame.image?.close?.();
|
|
97
98
|
};
|
|
98
|
-
port
|
|
99
|
-
const reply = event.data;
|
|
99
|
+
onPortMessage(port, (reply) => {
|
|
100
100
|
const entry = isRecord(reply) && isId(reply.id) ? pending.get(reply.id) : undefined;
|
|
101
101
|
if (!entry)
|
|
102
102
|
return closeImages(reply);
|
|
103
103
|
pending.delete(reply.id);
|
|
104
104
|
entry.resolve(reply);
|
|
105
|
-
};
|
|
105
|
+
});
|
|
106
106
|
const ask = (message, signal) => new Promise((resolve, reject) => {
|
|
107
107
|
if (disposed)
|
|
108
108
|
return reject(aborted());
|
|
109
109
|
const onAbort = () => {
|
|
110
110
|
if (!pending.delete(message.id))
|
|
111
111
|
return;
|
|
112
|
-
port
|
|
112
|
+
postOnPort(port, { type: "abort", id: message.id });
|
|
113
113
|
reject(aborted());
|
|
114
114
|
};
|
|
115
115
|
pending.set(message.id, {
|
|
@@ -120,7 +120,7 @@ export function portPausedVideoProvider(port) {
|
|
|
120
120
|
reject,
|
|
121
121
|
});
|
|
122
122
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
123
|
-
port
|
|
123
|
+
postOnPort(port, message);
|
|
124
124
|
});
|
|
125
125
|
const provider = {
|
|
126
126
|
async decode(requests, signal) {
|
|
@@ -167,10 +167,10 @@ export function portPausedVideoProvider(port) {
|
|
|
167
167
|
entry.reject(aborted());
|
|
168
168
|
pending.clear();
|
|
169
169
|
try {
|
|
170
|
-
port
|
|
170
|
+
postOnPort(port, { type: "close" });
|
|
171
171
|
}
|
|
172
172
|
catch { }
|
|
173
|
-
port
|
|
173
|
+
closePort(port);
|
|
174
174
|
window.removeEventListener("pagehide", onPageHide);
|
|
175
175
|
},
|
|
176
176
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Studio's stage acts inside a sealed frame: hold an element's before look, apply the parent's draws, give it back.
|
|
2
2
|
// The parent owns every motion and easing; the frame only borrows named properties, writes validated values and
|
|
3
3
|
// reports boxes, so a sealed act paints what an open one does without the parent touching the frame's document.
|
|
4
|
+
import { postOnPort } from "../runtimePort.js";
|
|
4
5
|
import { MAX_DRAFT_PX, MAX_ELEMENT_TEXT } from "../editingElement.js";
|
|
5
6
|
import { listenFrameKeydown } from "./canvasKeys.js";
|
|
6
7
|
import { captureStageGhosts, inertStageGhost, MAX_STAGE_GHOST_MARKUP, } from "./stageGhost.js";
|
|
@@ -403,7 +404,7 @@ function start(doc, params, port, version) {
|
|
|
403
404
|
const onInput = (event) => {
|
|
404
405
|
const key = event instanceof KeyboardEvent ? event.key.slice(0, MAX_INPUT_KEY) : null;
|
|
405
406
|
const { metaKey = false, ctrlKey = false } = event;
|
|
406
|
-
port
|
|
407
|
+
postOnPort(port, { v: version, event: "stage-input", type: event.type, key, metaKey, ctrlKey });
|
|
407
408
|
};
|
|
408
409
|
const stopInputs = view ? listenStageInputs(view, onInput) : () => { };
|
|
409
410
|
// Observer callbacks run before the frame paints: an element its seek reveals is held before it shows.
|
|
@@ -411,7 +412,7 @@ function start(doc, params, port, version) {
|
|
|
411
412
|
? new view.MutationObserver(() => {
|
|
412
413
|
const now = holdWaiting(open, doc);
|
|
413
414
|
if (now.length > 0)
|
|
414
|
-
port
|
|
415
|
+
postOnPort(port, { v: version, event: "stage-act-ready", held: now });
|
|
415
416
|
if (open.waiting.size === 0)
|
|
416
417
|
watch?.disconnect();
|
|
417
418
|
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// `text-edit`: one in-place text editing session in the frame, for a parent that cannot script it.
|
|
2
2
|
// It edits only an element it handed a handle for, and lets out nothing but text markup.
|
|
3
|
+
import { postOnPort } from "../runtimePort.js";
|
|
3
4
|
import { EDITING_ELEMENT_HANDLE } from "../editingElement.js";
|
|
4
5
|
import { elementForHandle } from "../editingHandles.js";
|
|
5
6
|
import { isDomNode, isStylableElement } from "../domRealm.js";
|
|
@@ -347,7 +348,7 @@ function start(handle, caret, hostTakesAway, port, version) {
|
|
|
347
348
|
return;
|
|
348
349
|
const selection = selectionIn(editable);
|
|
349
350
|
const caret = caretOf(open);
|
|
350
|
-
port
|
|
351
|
+
postOnPort(port, { v: version, event: "text-edit-selection", handle, selection, caret });
|
|
351
352
|
},
|
|
352
353
|
};
|
|
353
354
|
const endInFrame = () => {
|
|
@@ -355,12 +356,12 @@ function start(handle, caret, hostTakesAway, port, version) {
|
|
|
355
356
|
return;
|
|
356
357
|
const ended = close(true);
|
|
357
358
|
if (ended)
|
|
358
|
-
port
|
|
359
|
+
postOnPort(port, { v: version, event: "text-edit-ended", handle, ...ended });
|
|
359
360
|
};
|
|
360
361
|
const stopListening = listen(editable, endInFrame, open.report);
|
|
361
362
|
const stopFollowing = followCaret(editable, open);
|
|
362
363
|
const stopPassing = hostTakesAway
|
|
363
|
-
? passAway(editable, (away) => port
|
|
364
|
+
? passAway(editable, (away) => postOnPort(port, { v: version, event: "text-edit-away", handle, ...away }))
|
|
364
365
|
: () => { };
|
|
365
366
|
open.stop = () => {
|
|
366
367
|
stopListening();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// `watch-geometry`: the frame pushes the named elements' `geometry` fields once per animation frame,
|
|
2
2
|
// stamped on the clock both windows share, until an empty list, the page hiding, or the parent's release.
|
|
3
|
+
import { portMap, postOnPort } from "../runtimePort.js";
|
|
3
4
|
import { EDITING_ELEMENT_HANDLE, MAX_DRAFT_PX, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_VALUE, } from "../editingElement.js";
|
|
4
5
|
import { swallow } from "../diagnostics.js";
|
|
5
6
|
import { elementGeometry } from "../editingGeometry.js";
|
|
@@ -54,12 +55,12 @@ export function geometryEvent(data, version) {
|
|
|
54
55
|
return null;
|
|
55
56
|
return elements.every((e) => e === null || isGeometry(e)) ? { at, elements } : null;
|
|
56
57
|
}
|
|
57
|
-
const watches =
|
|
58
|
+
const watches = portMap();
|
|
58
59
|
let wireVersion = 0;
|
|
59
60
|
function pushTo(port, handles, at) {
|
|
60
61
|
const { elements } = elementGeometry(handles, undefined);
|
|
61
62
|
try {
|
|
62
|
-
port
|
|
63
|
+
postOnPort(port, { v: wireVersion, event: "geometry", at, elements });
|
|
63
64
|
}
|
|
64
65
|
catch {
|
|
65
66
|
watches.delete(port);
|
|
@@ -70,8 +71,7 @@ function push() {
|
|
|
70
71
|
observing = false;
|
|
71
72
|
const at = performance.timeOrigin + performance.now();
|
|
72
73
|
try {
|
|
73
|
-
|
|
74
|
-
pushTo(port, handles, at);
|
|
74
|
+
watches.forEach((handles, port) => pushTo(port, handles, at));
|
|
75
75
|
}
|
|
76
76
|
catch (err) {
|
|
77
77
|
swallow("watchGeometry.push", err);
|
|
@@ -88,16 +88,16 @@ let observing = false;
|
|
|
88
88
|
let nextFrame = 0;
|
|
89
89
|
function observeThisFrame() {
|
|
90
90
|
nextFrame = 0;
|
|
91
|
-
if (!watches.size)
|
|
91
|
+
if (!watches.size())
|
|
92
92
|
return;
|
|
93
93
|
observer ??= new ResizeObserver(push);
|
|
94
94
|
observer.observe(document.documentElement);
|
|
95
95
|
observing = true;
|
|
96
96
|
}
|
|
97
97
|
function schedule() {
|
|
98
|
-
if (watches.size && !nextFrame && !observing)
|
|
98
|
+
if (watches.size() && !nextFrame && !observing)
|
|
99
99
|
nextFrame = requestAnimationFrame(observeThisFrame);
|
|
100
|
-
if (watches.size)
|
|
100
|
+
if (watches.size())
|
|
101
101
|
return;
|
|
102
102
|
if (nextFrame)
|
|
103
103
|
cancelAnimationFrame(nextFrame);
|
|
@@ -118,7 +118,7 @@ const stopAll = () => stopWatchingGeometry();
|
|
|
118
118
|
export function watchGeometry(port, { handles }, version) {
|
|
119
119
|
if (!handles.length)
|
|
120
120
|
watches.delete(port);
|
|
121
|
-
else if (watches.has(port) || watches.size < MAX_GEOMETRY_WATCHERS)
|
|
121
|
+
else if (watches.has(port) || watches.size() < MAX_GEOMETRY_WATCHERS)
|
|
122
122
|
watches.set(port, handles);
|
|
123
123
|
else
|
|
124
124
|
throw new Error(`at most ${MAX_GEOMETRY_WATCHERS} ports may watch geometry`);
|
|
@@ -118,6 +118,9 @@ export type EditingDraft = {
|
|
|
118
118
|
props?: EditingDraftProps | null;
|
|
119
119
|
} | EditingDraftEnd;
|
|
120
120
|
type NoParams = Record<string, never>;
|
|
121
|
+
export type FramePresentedParams = {
|
|
122
|
+
waitMs?: number;
|
|
123
|
+
};
|
|
121
124
|
export interface EditingRequests {
|
|
122
125
|
hello: {
|
|
123
126
|
params: NoParams;
|
|
@@ -473,7 +476,7 @@ export interface EditingRequests {
|
|
|
473
476
|
};
|
|
474
477
|
};
|
|
475
478
|
"frame-presented": {
|
|
476
|
-
params:
|
|
479
|
+
params: FramePresentedParams;
|
|
477
480
|
result: {
|
|
478
481
|
presented: boolean;
|
|
479
482
|
};
|
|
@@ -107,6 +107,7 @@ export const DRAFT_GSAP_PROPS = [
|
|
|
107
107
|
"rotationY",
|
|
108
108
|
"z",
|
|
109
109
|
];
|
|
110
|
+
const MAX_FRAME_PRESENTED_WAIT_MS = 15_000;
|
|
110
111
|
export function isPlainRecord(value) {
|
|
111
112
|
return Object.prototype.toString.call(value) === "[object Object]";
|
|
112
113
|
}
|
|
@@ -116,6 +117,21 @@ const MAX_STYLE_PROPERTY_LENGTH = 256;
|
|
|
116
117
|
const STYLE_PROPERTY = /^(?:[a-z][a-z0-9-]*|--[\w\u0080-\uffff-]+)$/;
|
|
117
118
|
const hasKeys = (params, keys) => isPlainRecord(params) && Object.keys(params).sort().join() === keys;
|
|
118
119
|
const noParams = (params) => params === undefined || (isPlainRecord(params) && Object.keys(params).length === 0) ? {} : null;
|
|
120
|
+
function parseFramePresented(params) {
|
|
121
|
+
if (noParams(params))
|
|
122
|
+
return {};
|
|
123
|
+
if (!hasKeys(params, "waitMs"))
|
|
124
|
+
return null;
|
|
125
|
+
const { waitMs } = params;
|
|
126
|
+
const bounded = typeof waitMs === "number" &&
|
|
127
|
+
Number.isFinite(waitMs) &&
|
|
128
|
+
waitMs > 0 &&
|
|
129
|
+
waitMs <= MAX_FRAME_PRESENTED_WAIT_MS;
|
|
130
|
+
return bounded ? { waitMs } : null;
|
|
131
|
+
}
|
|
132
|
+
const clientWaitPastFrameDeadline = (kind, params) => kind === "frame-presented" && isPlainRecord(params) && typeof params.waitMs === "number"
|
|
133
|
+
? params.waitMs + 1_000
|
|
134
|
+
: 0;
|
|
119
135
|
const isSelector = (value) => typeof value === "string" && value.length > 0 && value.length <= MAX_SELECTOR_LENGTH;
|
|
120
136
|
const isHandle = (value) => typeof value === "string" && EDITING_ELEMENT_HANDLE.test(value);
|
|
121
137
|
function styleTarget(params) {
|
|
@@ -368,7 +384,7 @@ const PARAM_PARSERS = {
|
|
|
368
384
|
"serve-paused-frames": (params) => hasKeys(params, "channel") && params.channel instanceof MessagePort
|
|
369
385
|
? { channel: params.channel }
|
|
370
386
|
: null,
|
|
371
|
-
"frame-presented":
|
|
387
|
+
"frame-presented": parseFramePresented,
|
|
372
388
|
"arm-canvas-keys": parseArmCanvasKeys,
|
|
373
389
|
"resolve-canvas-key-action": parseResolveCanvasKeyAction,
|
|
374
390
|
"stage-measure": parseStageMeasureParams,
|
|
@@ -525,7 +541,7 @@ export function createEditingPortClient(options) {
|
|
|
525
541
|
const id = ++lastId;
|
|
526
542
|
if (kind === "watch-geometry")
|
|
527
543
|
watchedGeometry = true;
|
|
528
|
-
const limit = requestOptions?.timeoutMs ?? timeoutMs;
|
|
544
|
+
const limit = requestOptions?.timeoutMs ?? Math.max(timeoutMs, clientWaitPastFrameDeadline(kind, params));
|
|
529
545
|
const result = new Promise((resolve, reject) => {
|
|
530
546
|
const timer = wallSetTimeout(() => settle(id, { error: new EditingPortError("timeout", `${kind} timed out`) }), limit);
|
|
531
547
|
pending.set(id, { resolve, reject, timer });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Tests only: stand-in ports and events from another realm (jsdom over Node) keep their own methods. */
|
|
2
|
+
export declare function allowPortStandInsForTests(): void;
|
|
3
|
+
/** Null when the browser's own port methods could not be read at load: the agent then never connects. */
|
|
4
|
+
export declare function createRuntimeChannel(): {
|
|
5
|
+
port1: MessagePort;
|
|
6
|
+
port2: MessagePort;
|
|
7
|
+
} | null;
|
|
8
|
+
export declare function postOnPort(port: MessagePort, message: unknown, transfer?: Transferable[]): void;
|
|
9
|
+
export declare function onPortMessage(port: MessagePort, handler: (data: unknown) => void): void;
|
|
10
|
+
export declare function closePort(port: MessagePort): void;
|
|
11
|
+
/** A Map keyed by ports whose calls never reach a patched Map.prototype. */
|
|
12
|
+
export interface PortMap<V> {
|
|
13
|
+
get(port: MessagePort): V | undefined;
|
|
14
|
+
set(port: MessagePort, value: V): void;
|
|
15
|
+
has(port: MessagePort): boolean;
|
|
16
|
+
delete(port: MessagePort): boolean;
|
|
17
|
+
clear(): void;
|
|
18
|
+
forEach(each: (value: V, port: MessagePort) => void): void;
|
|
19
|
+
size(): number;
|
|
20
|
+
}
|
|
21
|
+
export declare function portMap<V>(): PortMap<V>;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// The runtime's MessagePort calls, bound to built-ins read when the runtime first evaluates, before any
|
|
2
|
+
// composition script runs. Best-effort: it covers the port, channel, event-data and container calls the
|
|
3
|
+
// runtime makes with a port; a built-in reached some other way after load is not covered.
|
|
4
|
+
const apply = Reflect.apply;
|
|
5
|
+
const protoOf = Object.getPrototypeOf;
|
|
6
|
+
const descriptor = Object.getOwnPropertyDescriptor;
|
|
7
|
+
const NativeMessageChannel = typeof MessageChannel !== "undefined" ? MessageChannel : null;
|
|
8
|
+
function accessor(proto, name, kind) {
|
|
9
|
+
for (let at = proto; at; at = protoOf(at)) {
|
|
10
|
+
const found = descriptor(at, name)?.[kind];
|
|
11
|
+
if (found)
|
|
12
|
+
return found;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
// Browsers expose a channel's ports through prototype getters; Node keeps them as the channel's own data.
|
|
17
|
+
function channelPort(channel, getter, name) {
|
|
18
|
+
return (getter ? apply(getter, channel, []) : descriptor(channel, name)?.value);
|
|
19
|
+
}
|
|
20
|
+
const native = (() => {
|
|
21
|
+
if (!NativeMessageChannel)
|
|
22
|
+
return null;
|
|
23
|
+
try {
|
|
24
|
+
const probe = new NativeMessageChannel();
|
|
25
|
+
const channelProto = protoOf(probe);
|
|
26
|
+
const port1 = accessor(channelProto, "port1", "get");
|
|
27
|
+
const port2 = accessor(channelProto, "port2", "get");
|
|
28
|
+
const proto = protoOf(channelPort(probe, port1, "port1"));
|
|
29
|
+
const setOnMessage = accessor(proto, "onmessage", "set");
|
|
30
|
+
const eventProto = typeof MessageEvent !== "undefined" ? MessageEvent.prototype : null;
|
|
31
|
+
const eventData = accessor(eventProto, "data", "get");
|
|
32
|
+
if (!setOnMessage)
|
|
33
|
+
return null;
|
|
34
|
+
const methods = {
|
|
35
|
+
proto,
|
|
36
|
+
post: proto.postMessage,
|
|
37
|
+
close: proto.close,
|
|
38
|
+
setOnMessage,
|
|
39
|
+
port1,
|
|
40
|
+
port2,
|
|
41
|
+
eventData,
|
|
42
|
+
eventProto,
|
|
43
|
+
};
|
|
44
|
+
apply(methods.close, channelPort(probe, port1, "port1"), []);
|
|
45
|
+
apply(methods.close, channelPort(probe, port2, "port2"), []);
|
|
46
|
+
return methods;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
52
|
+
let standIns = false;
|
|
53
|
+
/** Tests only: stand-in ports and events from another realm (jsdom over Node) keep their own methods. */
|
|
54
|
+
export function allowPortStandInsForTests() {
|
|
55
|
+
standIns = true;
|
|
56
|
+
}
|
|
57
|
+
function bound(port) {
|
|
58
|
+
if (native && protoOf(port) === native.proto)
|
|
59
|
+
return native;
|
|
60
|
+
if (standIns)
|
|
61
|
+
return null;
|
|
62
|
+
throw new Error("not a runtime port");
|
|
63
|
+
}
|
|
64
|
+
/** Null when the browser's own port methods could not be read at load: the agent then never connects. */
|
|
65
|
+
export function createRuntimeChannel() {
|
|
66
|
+
if (!native || !NativeMessageChannel || !(native.eventData || standIns))
|
|
67
|
+
return null;
|
|
68
|
+
const channel = new NativeMessageChannel();
|
|
69
|
+
return {
|
|
70
|
+
port1: channelPort(channel, native.port1, "port1"),
|
|
71
|
+
port2: channelPort(channel, native.port2, "port2"),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
export function postOnPort(port, message, transfer) {
|
|
75
|
+
const methods = bound(port);
|
|
76
|
+
if (methods)
|
|
77
|
+
apply(methods.post, port, [message, transfer ?? []]);
|
|
78
|
+
else if (transfer)
|
|
79
|
+
port.postMessage(message, transfer);
|
|
80
|
+
else
|
|
81
|
+
port.postMessage(message);
|
|
82
|
+
}
|
|
83
|
+
export function onPortMessage(port, handler) {
|
|
84
|
+
const methods = bound(port);
|
|
85
|
+
const onMessage = (event) => {
|
|
86
|
+
const read = native?.eventData;
|
|
87
|
+
if (read && protoOf(event) === native?.eventProto)
|
|
88
|
+
handler(apply(read, event, []));
|
|
89
|
+
else if (standIns)
|
|
90
|
+
handler(event.data);
|
|
91
|
+
};
|
|
92
|
+
if (methods)
|
|
93
|
+
apply(methods.setOnMessage, port, [onMessage]);
|
|
94
|
+
else
|
|
95
|
+
port.onmessage = onMessage;
|
|
96
|
+
}
|
|
97
|
+
export function closePort(port) {
|
|
98
|
+
const methods = bound(port);
|
|
99
|
+
if (methods)
|
|
100
|
+
apply(methods.close, port, []);
|
|
101
|
+
else
|
|
102
|
+
port.close();
|
|
103
|
+
}
|
|
104
|
+
const mapGet = Map.prototype.get;
|
|
105
|
+
const mapSet = Map.prototype.set;
|
|
106
|
+
const mapHas = Map.prototype.has;
|
|
107
|
+
const mapDelete = Map.prototype.delete;
|
|
108
|
+
const mapClear = Map.prototype.clear;
|
|
109
|
+
const mapForEach = Map.prototype.forEach;
|
|
110
|
+
const mapSize = accessor(Map.prototype, "size", "get");
|
|
111
|
+
export function portMap() {
|
|
112
|
+
const map = new Map();
|
|
113
|
+
return {
|
|
114
|
+
get: (port) => apply(mapGet, map, [port]),
|
|
115
|
+
set: (port, value) => void apply(mapSet, map, [port, value]),
|
|
116
|
+
has: (port) => apply(mapHas, map, [port]),
|
|
117
|
+
delete: (port) => apply(mapDelete, map, [port]),
|
|
118
|
+
clear: () => void apply(mapClear, map, []),
|
|
119
|
+
forEach: (each) => void apply(mapForEach, map, [each]),
|
|
120
|
+
size: () => apply(mapSize, map, []),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -23,6 +23,7 @@ export declare const STUDIO_PREVIEW_LAZY_ATTR = "data-hf-preview-lazy";
|
|
|
23
23
|
export declare const STUDIO_PREVIEW_ERRORS = "__hfPreviewErrors";
|
|
24
24
|
export declare const STUDIO_PREVIEW_ERROR_MESSAGE = "preview-error";
|
|
25
25
|
export declare const STUDIO_PREVIEW_ERROR_KINDS = "__hfPreviewErrorKinds";
|
|
26
|
+
export declare const STUDIO_PREVIEW_RETRY_AFTER = "__hfPreviewRetryAfter";
|
|
26
27
|
export declare function previewConsoleErrorText(args: readonly unknown[]): string | null;
|
|
27
28
|
export declare const refusedPreviewMessage: (status: number) => string;
|
|
28
29
|
export declare function refusedPreviewStatus(message: string): number | null;
|
|
@@ -51,6 +51,7 @@ export const STUDIO_PREVIEW_LAZY_ATTR = "data-hf-preview-lazy";
|
|
|
51
51
|
export const STUDIO_PREVIEW_ERRORS = "__hfPreviewErrors";
|
|
52
52
|
export const STUDIO_PREVIEW_ERROR_MESSAGE = "preview-error";
|
|
53
53
|
export const STUDIO_PREVIEW_ERROR_KINDS = "__hfPreviewErrorKinds";
|
|
54
|
+
export const STUDIO_PREVIEW_RETRY_AFTER = "__hfPreviewRetryAfter";
|
|
54
55
|
export function previewConsoleErrorText(args) {
|
|
55
56
|
const text = args.map((a) => (a instanceof Error ? a.message : String(a))).join(" ");
|
|
56
57
|
return text.includes("favicon") ? null : text;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/core",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.104",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -525,9 +525,9 @@
|
|
|
525
525
|
"linkedom": "^0.18.12",
|
|
526
526
|
"postcss": "^8.5.8",
|
|
527
527
|
"wawoff2": "^2.0.1",
|
|
528
|
-
"@hyperframes/lint": "0.9.
|
|
529
|
-
"@hyperframes/studio-server": "0.9.
|
|
530
|
-
"@hyperframes/parsers": "0.9.
|
|
528
|
+
"@hyperframes/lint": "0.9.104",
|
|
529
|
+
"@hyperframes/studio-server": "0.9.104",
|
|
530
|
+
"@hyperframes/parsers": "0.9.104"
|
|
531
531
|
},
|
|
532
532
|
"devDependencies": {
|
|
533
533
|
"@fontsource/archivo-black": "^5.2.8",
|