@hyperframes/core 0.9.104 → 0.9.106
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/htmlDocument.js +9 -2
- package/dist/fonts/deterministicFonts.js +12 -10
- package/dist/fonts/fontDiagnostics.d.ts +3 -0
- package/dist/fonts/fontDiagnostics.js +32 -1
- package/dist/generated/runtime-inline.js +1 -1
- package/dist/hyperframe.runtime.iife.js +67 -67
- package/dist/runtime/drawnBox.d.ts +5 -0
- package/dist/runtime/drawnBox.js +5 -0
- package/dist/runtime/editing/dragChrome.d.ts +32 -0
- package/dist/runtime/editing/dragChrome.js +154 -0
- package/dist/runtime/editing/softReload.js +4 -2
- package/dist/runtime/editing/watchPointer.d.ts +26 -0
- package/dist/runtime/editing/watchPointer.js +105 -0
- package/dist/runtime/editingDraft.d.ts +3 -2
- package/dist/runtime/editingDraft.js +13 -8
- package/dist/runtime/editingDraftEnd.d.ts +1 -0
- package/dist/runtime/editingElement.d.ts +4 -0
- package/dist/runtime/editingGeometry.js +1 -4
- package/dist/runtime/editingHandles.d.ts +0 -5
- package/dist/runtime/editingHandles.js +7 -0
- package/dist/runtime/editingPort.d.ts +18 -2
- package/dist/runtime/editingPort.js +45 -6
- package/dist/runtime/mediaProxy.js +78 -7
- package/dist/studioPreviewMark.d.ts +1 -0
- package/dist/studioPreviewMark.js +1 -0
- package/package.json +4 -4
|
@@ -4,6 +4,11 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import type { StylableElement as Styled } from "./domRealm.js";
|
|
6
6
|
export declare const SIZE_PROPERTIES: readonly ["box-sizing", "width", "height", "min-width", "min-height", "max-width", "max-height"];
|
|
7
|
+
export declare function layoutOf(element: Element): {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const DRAFT_DRAWN: readonly ["translate", "rotate", "transform", "box-sizing", "width", "height", "min-width", "min-height", "max-width", "max-height"];
|
|
7
12
|
export declare const PROBE_PX = 100;
|
|
8
13
|
export declare const MIN_PROBE_RESPONSE = 0.01;
|
|
9
14
|
/** Frame px its centre moves per px of drawn width, `a, b`, and height, `c, d`; null when it has no box. */
|
package/dist/runtime/drawnBox.js
CHANGED
|
@@ -7,6 +7,11 @@ export const SIZE_PROPERTIES = [
|
|
|
7
7
|
"max-width",
|
|
8
8
|
"max-height",
|
|
9
9
|
];
|
|
10
|
+
export function layoutOf(element) {
|
|
11
|
+
const { offsetWidth = 0, offsetHeight = 0 } = element;
|
|
12
|
+
return { width: offsetWidth, height: offsetHeight };
|
|
13
|
+
}
|
|
14
|
+
export const DRAFT_DRAWN = ["translate", "rotate", "transform", ...SIZE_PROPERTIES];
|
|
10
15
|
export const PROBE_PX = 100;
|
|
11
16
|
export const MIN_PROBE_RESPONSE = 0.01;
|
|
12
17
|
/** "calc(50% + 2px) 4px" as its top-level parts. */
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type EditingDragChromeTag = "div" | "span" | "svg" | "path";
|
|
2
|
+
/** One node of Studio's chrome: `look` is its computed paint, set once; `children` in document order. */
|
|
3
|
+
export type EditingDragChromeNode = {
|
|
4
|
+
tag: EditingDragChromeTag;
|
|
5
|
+
look: Record<string, string>;
|
|
6
|
+
attrs?: Record<string, string>;
|
|
7
|
+
children?: EditingDragChromeNode[];
|
|
8
|
+
};
|
|
9
|
+
/** `place` is each node's inline style this step, in document order; `origin` and `scale` map overlay px
|
|
10
|
+
* to the frame's (frame = (overlay - origin) / scale). `nodes` (re)mounts the copy; null clears it. */
|
|
11
|
+
export type EditingDragChrome = {
|
|
12
|
+
origin: {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
};
|
|
16
|
+
scale: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
place: Array<Record<string, string>>;
|
|
21
|
+
nodes?: EditingDragChromeNode[];
|
|
22
|
+
} | null;
|
|
23
|
+
export declare const MAX_DRAG_CHROME_NODES = 64;
|
|
24
|
+
export declare const MAX_DRAG_CHROME_BYTES = 32768;
|
|
25
|
+
/** The chrome a draft request carries, or undefined when it is malformed or over the caps. */
|
|
26
|
+
export declare function parseDragChrome(value: unknown): EditingDragChrome | undefined;
|
|
27
|
+
export declare const isDragChromeHost: (element: Element) => boolean;
|
|
28
|
+
/** Mounts, places or clears the chrome in the drafts' turn; false when this place fits no mounted copy. */
|
|
29
|
+
export declare function drawDragChrome(chrome: EditingDragChrome): boolean;
|
|
30
|
+
export declare function clearDragChrome(): void;
|
|
31
|
+
/** Runs `read` with the chrome host out of the document, so nothing it reads carries it. */
|
|
32
|
+
export declare function withoutDragChrome<T>(read: () => T): T;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Studio's selection chrome painted inside a sealed frame during a drag, in the same turn as the layer's draft.
|
|
3
|
+
* Studio owns the look (a copy sent as data); it lives in a closed shadow root that exists only during the drag.
|
|
4
|
+
*/
|
|
5
|
+
const isPlainRecord = (value) => Object.prototype.toString.call(value) === "[object Object]";
|
|
6
|
+
export const MAX_DRAG_CHROME_NODES = 64;
|
|
7
|
+
export const MAX_DRAG_CHROME_BYTES = 32_768;
|
|
8
|
+
const MAX_DEPTH = 6;
|
|
9
|
+
const MAX_PROPS = 48;
|
|
10
|
+
const TAGS = ["div", "span", "svg", "path"];
|
|
11
|
+
const ATTRS = [
|
|
12
|
+
"d",
|
|
13
|
+
"viewBox",
|
|
14
|
+
"fill",
|
|
15
|
+
"stroke",
|
|
16
|
+
"stroke-width",
|
|
17
|
+
"stroke-linecap",
|
|
18
|
+
"stroke-linejoin",
|
|
19
|
+
"width",
|
|
20
|
+
"height",
|
|
21
|
+
];
|
|
22
|
+
const PROP_NAME = /^-?[a-z][a-z0-9-]{0,63}$/;
|
|
23
|
+
// Paint only: nothing in the copy may make the frame fetch, nor a CSS escape that spells a fetch.
|
|
24
|
+
const FETCHES = /\\|url\(|image\(|image-set\(|src\(/i;
|
|
25
|
+
const isText = (value, max) => typeof value === "string" && value.length <= max;
|
|
26
|
+
function isMap(value, name) {
|
|
27
|
+
if (!isPlainRecord(value))
|
|
28
|
+
return false;
|
|
29
|
+
const entries = Object.entries(value);
|
|
30
|
+
return (entries.length <= MAX_PROPS &&
|
|
31
|
+
entries.every(([key, v]) => name(key) && isText(v, 512) && !FETCHES.test(v)));
|
|
32
|
+
}
|
|
33
|
+
const isStyleMap = (value) => isMap(value, (key) => PROP_NAME.test(key));
|
|
34
|
+
function nodesWithin(nodes, depth, count) {
|
|
35
|
+
if (!Array.isArray(nodes) || depth > MAX_DEPTH)
|
|
36
|
+
return false;
|
|
37
|
+
return nodes.every((node) => {
|
|
38
|
+
if (!isPlainRecord(node) || ++count.n > MAX_DRAG_CHROME_NODES)
|
|
39
|
+
return false;
|
|
40
|
+
const { tag, look, attrs, children, ...rest } = node;
|
|
41
|
+
return (!Object.keys(rest).length &&
|
|
42
|
+
TAGS.includes(tag) &&
|
|
43
|
+
isStyleMap(look) &&
|
|
44
|
+
(attrs === undefined || isMap(attrs, (key) => ATTRS.includes(key))) &&
|
|
45
|
+
(children === undefined || nodesWithin(children, depth + 1, count)));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const isPair = (value, positive) => isPlainRecord(value) &&
|
|
49
|
+
Object.keys(value).sort().join() === "x,y" &&
|
|
50
|
+
[value.x, value.y].every((n) => Number.isFinite(n) && (!positive || n > 0));
|
|
51
|
+
/** The chrome a draft request carries, or undefined when it is malformed or over the caps. */
|
|
52
|
+
export function parseDragChrome(value) {
|
|
53
|
+
if (value === null)
|
|
54
|
+
return null;
|
|
55
|
+
if (!isPlainRecord(value))
|
|
56
|
+
return undefined;
|
|
57
|
+
const { origin, scale, place, nodes, ...rest } = value;
|
|
58
|
+
const count = { n: 0 };
|
|
59
|
+
const valid = [
|
|
60
|
+
!Object.keys(rest).length,
|
|
61
|
+
isPair(origin, false),
|
|
62
|
+
isPair(scale, true),
|
|
63
|
+
Array.isArray(place) && place.length <= MAX_DRAG_CHROME_NODES && place.every(isStyleMap),
|
|
64
|
+
nodes === undefined ||
|
|
65
|
+
(nodesWithin(nodes, 1, count) && JSON.stringify(nodes).length <= MAX_DRAG_CHROME_BYTES),
|
|
66
|
+
];
|
|
67
|
+
return valid.includes(false) ? undefined : value;
|
|
68
|
+
}
|
|
69
|
+
const SVG_NS = "http://www.w3.org/2000/svg";
|
|
70
|
+
const HOST_MARKS = [
|
|
71
|
+
"data-hf-ignore",
|
|
72
|
+
"data-hyperframes-ignore",
|
|
73
|
+
"data-hyperframes-picker-ignore",
|
|
74
|
+
"data-layout-ignore",
|
|
75
|
+
];
|
|
76
|
+
let host = null;
|
|
77
|
+
let plane = null;
|
|
78
|
+
let placed = [];
|
|
79
|
+
let looks = [];
|
|
80
|
+
export const isDragChromeHost = (element) => element === host;
|
|
81
|
+
function build(node, into) {
|
|
82
|
+
const element = node.tag === "svg" || node.tag === "path"
|
|
83
|
+
? document.createElementNS(SVG_NS, node.tag)
|
|
84
|
+
: document.createElement(node.tag);
|
|
85
|
+
for (const [name, value] of Object.entries(node.attrs ?? {}))
|
|
86
|
+
element.setAttribute(name, value);
|
|
87
|
+
placed.push(element);
|
|
88
|
+
looks.push(node.look);
|
|
89
|
+
into.appendChild(element);
|
|
90
|
+
for (const child of node.children ?? [])
|
|
91
|
+
build(child, element);
|
|
92
|
+
}
|
|
93
|
+
function mount(nodes) {
|
|
94
|
+
clearDragChrome();
|
|
95
|
+
host = document.createElement("div");
|
|
96
|
+
for (const mark of HOST_MARKS)
|
|
97
|
+
host.setAttribute(mark, "");
|
|
98
|
+
host.setAttribute("aria-hidden", "true");
|
|
99
|
+
host.style.cssText =
|
|
100
|
+
"all:initial;position:fixed;inset:0;pointer-events:none;z-index:2147483647;overflow:visible";
|
|
101
|
+
const root = host.attachShadow({ mode: "closed" });
|
|
102
|
+
plane = document.createElement("div");
|
|
103
|
+
plane.style.cssText = "position:absolute;left:0;top:0;transform-origin:0 0";
|
|
104
|
+
root.appendChild(plane);
|
|
105
|
+
for (const node of nodes)
|
|
106
|
+
build(node, plane);
|
|
107
|
+
document.documentElement.appendChild(host);
|
|
108
|
+
}
|
|
109
|
+
function writeStyle(element, props) {
|
|
110
|
+
for (const [name, value] of Object.entries(props))
|
|
111
|
+
element.style.setProperty(name, value);
|
|
112
|
+
}
|
|
113
|
+
/** Mounts, places or clears the chrome in the drafts' turn; false when this place fits no mounted copy. */
|
|
114
|
+
export function drawDragChrome(chrome) {
|
|
115
|
+
if (chrome === null) {
|
|
116
|
+
clearDragChrome();
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
if (chrome.nodes)
|
|
120
|
+
mount(chrome.nodes);
|
|
121
|
+
if (!plane || chrome.place.length !== placed.length)
|
|
122
|
+
return false;
|
|
123
|
+
const { origin, scale } = chrome;
|
|
124
|
+
plane.style.transform = `scale(${1 / scale.x}, ${1 / scale.y}) translate(${-origin.x}px, ${-origin.y}px)`;
|
|
125
|
+
placed.forEach((element, i) => {
|
|
126
|
+
element.removeAttribute("style");
|
|
127
|
+
writeStyle(element, looks[i]);
|
|
128
|
+
writeStyle(element, chrome.place[i]);
|
|
129
|
+
element.style.setProperty("pointer-events", "none", "important");
|
|
130
|
+
});
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
export function clearDragChrome() {
|
|
134
|
+
host?.remove();
|
|
135
|
+
host = plane = null;
|
|
136
|
+
placed = [];
|
|
137
|
+
looks = [];
|
|
138
|
+
}
|
|
139
|
+
/** Runs `read` with the chrome host out of the document, so nothing it reads carries it. */
|
|
140
|
+
export function withoutDragChrome(read) {
|
|
141
|
+
const mounted = host;
|
|
142
|
+
if (!mounted?.isConnected)
|
|
143
|
+
return read();
|
|
144
|
+
const html = document.documentElement;
|
|
145
|
+
const next = mounted.nextSibling;
|
|
146
|
+
mounted.remove();
|
|
147
|
+
try {
|
|
148
|
+
return read();
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
if (host === mounted)
|
|
152
|
+
html.insertBefore(mounted, next?.parentNode === html ? next : null);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -208,10 +208,12 @@ function verifyTimelinesPopulated(win, targetKeys) {
|
|
|
208
208
|
// GSAP masks a folded CSS translate/rotate/scale with `none`, and a tween writes what it animates
|
|
209
209
|
// inline; a fresh load has only what the file authors. Opacity has its own restore.
|
|
210
210
|
export function restoreAuthoredStyle(style, authored, tweened) {
|
|
211
|
-
|
|
211
|
+
for (const prop of ["transform", "translate", "rotate", "scale"]) {
|
|
212
|
+
style.setProperty(prop, authored?.getPropertyValue(prop) ?? "", authored?.getPropertyPriority(prop) ?? "");
|
|
213
|
+
}
|
|
212
214
|
if (!authored)
|
|
213
215
|
return;
|
|
214
|
-
for (const prop of
|
|
216
|
+
for (const prop of tweened) {
|
|
215
217
|
if (prop === "opacity")
|
|
216
218
|
continue;
|
|
217
219
|
style.setProperty(prop, authored.getPropertyValue(prop), authored.getPropertyPriority(prop));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type EditingElementHit } from "../editingElement.js";
|
|
2
|
+
export declare const MAX_POINTER_WATCHERS = 8;
|
|
3
|
+
export declare const MAX_POINT_SEQ: number;
|
|
4
|
+
/** `point` is in fractions of the root's box, as `pointer-targets` takes it; null stops the watch. */
|
|
5
|
+
export type WatchPointerParams = {
|
|
6
|
+
point: {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
} | null;
|
|
10
|
+
seq?: number;
|
|
11
|
+
};
|
|
12
|
+
/** `at` is `performance.timeOrigin + performance.now()` in the frame when it hit-tested. */
|
|
13
|
+
export type EditingPointerEvent = {
|
|
14
|
+
at: number;
|
|
15
|
+
target: EditingElementHit | null;
|
|
16
|
+
stack: EditingElementHit[];
|
|
17
|
+
seq?: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function parseWatchPointer(params: unknown): WatchPointerParams | null;
|
|
20
|
+
/** One pushed message off the port, or null for anything with a field it does not allow. */
|
|
21
|
+
export declare function pointerEvent(data: unknown, version: number): EditingPointerEvent | null;
|
|
22
|
+
/** Stops `port`'s watch, or every watch when no port is named. */
|
|
23
|
+
export declare function stopWatchingPointer(port?: MessagePort): void;
|
|
24
|
+
export declare function watchPointer(port: MessagePort, { point, seq }: WatchPointerParams, version: number): {
|
|
25
|
+
watching: boolean;
|
|
26
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// `watch-pointer`: while the parent's pointer rests on the frame, the frame hit-tests that point each animation frame
|
|
2
|
+
// and pushes the `pointer-targets` answer only when it changes, until a null point, pagehide, or the release. A hidden
|
|
3
|
+
// page pauses it.
|
|
4
|
+
import { portMap, postOnPort } from "../runtimePort.js";
|
|
5
|
+
import { EDITING_ELEMENT_HANDLE, MAX_ELEMENT_VALUE, MAX_POINT_STACK, } from "../editingElement.js";
|
|
6
|
+
import { swallow } from "../diagnostics.js";
|
|
7
|
+
import { pointerTargetsAt } from "../editingTargets.js";
|
|
8
|
+
export const MAX_POINTER_WATCHERS = 8;
|
|
9
|
+
export const MAX_POINT_SEQ = 2 ** 31 - 1;
|
|
10
|
+
const isRecord = (value) => Object.prototype.toString.call(value) === "[object Object]";
|
|
11
|
+
const keysAre = (value, keys) => isRecord(value) && Object.keys(value).sort().join() === keys;
|
|
12
|
+
const finite = (value) => Number.isFinite(value);
|
|
13
|
+
const isSeq = (value) => Number.isSafeInteger(value) && value >= 0 && value <= MAX_POINT_SEQ;
|
|
14
|
+
const seqOf = (fields) => (isSeq(fields.seq) ? { seq: fields.seq } : {});
|
|
15
|
+
export function parseWatchPointer(params) {
|
|
16
|
+
if (!keysAre(params, "point") && !(keysAre(params, "point,seq") && isSeq(params.seq)))
|
|
17
|
+
return null;
|
|
18
|
+
const { point } = params;
|
|
19
|
+
if (point === null)
|
|
20
|
+
return { point: null };
|
|
21
|
+
return keysAre(point, "x,y") && finite(point.x) && finite(point.y)
|
|
22
|
+
? { point: { x: point.x, y: point.y }, ...seqOf(params) }
|
|
23
|
+
: null;
|
|
24
|
+
}
|
|
25
|
+
const isHit = (value) => keysAre(value, "handle,rect,tag") &&
|
|
26
|
+
typeof value.handle === "string" &&
|
|
27
|
+
EDITING_ELEMENT_HANDLE.test(value.handle) &&
|
|
28
|
+
typeof value.tag === "string" &&
|
|
29
|
+
value.tag.length <= MAX_ELEMENT_VALUE &&
|
|
30
|
+
keysAre(value.rect, "height,width,x,y") &&
|
|
31
|
+
[value.rect.x, value.rect.y, value.rect.width, value.rect.height].every(finite);
|
|
32
|
+
/** One pushed message off the port, or null for anything with a field it does not allow. */
|
|
33
|
+
export function pointerEvent(data, version) {
|
|
34
|
+
const tagged = keysAre(data, "at,event,seq,stack,target,v") && isSeq(data.seq);
|
|
35
|
+
if ((!tagged && !keysAre(data, "at,event,stack,target,v")) || data.v !== version)
|
|
36
|
+
return null;
|
|
37
|
+
const { at, target, stack } = data;
|
|
38
|
+
if (data.event !== "pointer-targets" || !finite(at) || !Array.isArray(stack))
|
|
39
|
+
return null;
|
|
40
|
+
if (stack.length > MAX_POINT_STACK || !stack.every(isHit))
|
|
41
|
+
return null;
|
|
42
|
+
return target === null || isHit(target) ? { at, target, stack, ...seqOf(data) } : null;
|
|
43
|
+
}
|
|
44
|
+
const watches = portMap();
|
|
45
|
+
let wireVersion = 0;
|
|
46
|
+
let nextFrame = 0;
|
|
47
|
+
function check(port, watch, at) {
|
|
48
|
+
const { target, stack } = pointerTargetsAt(watch.x, watch.y);
|
|
49
|
+
const answer = JSON.stringify([target, stack]);
|
|
50
|
+
if (answer === watch.last)
|
|
51
|
+
return;
|
|
52
|
+
watch.last = answer;
|
|
53
|
+
try {
|
|
54
|
+
const seq = watch.seq === undefined ? {} : { seq: watch.seq };
|
|
55
|
+
postOnPort(port, { v: wireVersion, event: "pointer-targets", at, target, stack, ...seq });
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
watches.delete(port);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function checkAll() {
|
|
62
|
+
nextFrame = 0;
|
|
63
|
+
const at = performance.timeOrigin + performance.now();
|
|
64
|
+
try {
|
|
65
|
+
watches.forEach((watch, port) => check(port, watch, at));
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
swallow("watchPointer.check", err);
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
schedule();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function schedule() {
|
|
75
|
+
if (watches.size() && !document.hidden) {
|
|
76
|
+
nextFrame ||= requestAnimationFrame(checkAll);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (nextFrame)
|
|
80
|
+
cancelAnimationFrame(nextFrame);
|
|
81
|
+
nextFrame = 0;
|
|
82
|
+
}
|
|
83
|
+
/** Stops `port`'s watch, or every watch when no port is named. */
|
|
84
|
+
export function stopWatchingPointer(port) {
|
|
85
|
+
if (port)
|
|
86
|
+
watches.delete(port);
|
|
87
|
+
else
|
|
88
|
+
watches.clear();
|
|
89
|
+
schedule();
|
|
90
|
+
}
|
|
91
|
+
const stopAll = () => stopWatchingPointer();
|
|
92
|
+
export function watchPointer(port, { point, seq }, version) {
|
|
93
|
+
if (!point)
|
|
94
|
+
watches.delete(port);
|
|
95
|
+
else if (watches.has(port) || watches.size() < MAX_POINTER_WATCHERS)
|
|
96
|
+
watches.set(port, { x: point.x, y: point.y, last: null, seq });
|
|
97
|
+
else
|
|
98
|
+
throw new Error(`at most ${MAX_POINTER_WATCHERS} ports may watch the pointer`);
|
|
99
|
+
wireVersion = version;
|
|
100
|
+
window.addEventListener("pagehide", stopAll);
|
|
101
|
+
// A hidden page checks nothing; its watch resumes when shown, so the parent never holds an answer it thinks is live.
|
|
102
|
+
document.addEventListener("visibilitychange", schedule);
|
|
103
|
+
schedule();
|
|
104
|
+
return { watching: point !== null };
|
|
105
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { EditingDraftReply } from "./editingDraftEnd.js";
|
|
2
2
|
import type { EditingDraft } from "./editingPort.js";
|
|
3
|
+
import { type EditingDragChrome } from "./editing/dragChrome.js";
|
|
3
4
|
export declare function rebaseDrawnPosition(element: Element, props: Record<string, unknown>): void;
|
|
4
|
-
/** Applies each draft in order
|
|
5
|
-
export declare function drawDrafts(drafts: readonly EditingDraft[]): EditingDraftReply;
|
|
5
|
+
/** Applies each draft in order, then `chrome`; one for an element this load no longer has is skipped. */
|
|
6
|
+
export declare function drawDrafts(drafts: readonly EditingDraft[], chrome?: EditingDragChrome): EditingDraftReply;
|
|
@@ -7,8 +7,8 @@ import { redrawGsapTimelineAt, seekGsapTimeline } from "./adapters/gsap.js";
|
|
|
7
7
|
import { isStylableElement } from "./domRealm.js";
|
|
8
8
|
import { elementForHandle } from "./editingHandles.js";
|
|
9
9
|
import { revealClip } from "./clipReveal.js";
|
|
10
|
-
import {
|
|
11
|
-
|
|
10
|
+
import { clearDragChrome, drawDragChrome } from "./editing/dragChrome.js";
|
|
11
|
+
import { computedTranslateAxes, DRAFT_DRAWN, movedTranslate, SIZE_PROPERTIES, writeDrawnSize, } from "./drawnBox.js";
|
|
12
12
|
const frameGsap = () => window.gsap;
|
|
13
13
|
/** The film's own timeline, as the unsealed recorder finds it: Studio's `__proxied` mark is no timeline. */
|
|
14
14
|
function rootTimeline() {
|
|
@@ -26,7 +26,7 @@ function beforeOf(element) {
|
|
|
26
26
|
const { style } = element;
|
|
27
27
|
saved = {
|
|
28
28
|
draft: ++lastDraft,
|
|
29
|
-
inline:
|
|
29
|
+
inline: DRAFT_DRAWN.map((name) => [
|
|
30
30
|
name,
|
|
31
31
|
style.getPropertyValue(name),
|
|
32
32
|
style.getPropertyPriority(name),
|
|
@@ -126,7 +126,7 @@ function drawProps(element, values) {
|
|
|
126
126
|
saved.propsSet = [...new Set([...(saved.propsSet ?? []), ...Object.keys(values)])];
|
|
127
127
|
}
|
|
128
128
|
function clearProps(element, saved) {
|
|
129
|
-
restore(element,
|
|
129
|
+
restore(element, DRAFT_DRAWN);
|
|
130
130
|
saved.putMarkBack?.();
|
|
131
131
|
if (saved.propsSet?.length)
|
|
132
132
|
frameGsap()?.set?.(element, { clearProps: saved.propsSet.join(",") });
|
|
@@ -156,7 +156,7 @@ function end(element, ending) {
|
|
|
156
156
|
if (ending.end === "clear")
|
|
157
157
|
clearProps(element, saved);
|
|
158
158
|
if (ending.end === "restore") {
|
|
159
|
-
restore(element,
|
|
159
|
+
restore(element, DRAFT_DRAWN);
|
|
160
160
|
restoreGsapPosition(element);
|
|
161
161
|
restoreGsapRotation(element);
|
|
162
162
|
}
|
|
@@ -221,8 +221,8 @@ function redrawKeepingLiveDrafts() {
|
|
|
221
221
|
redrawTimelines();
|
|
222
222
|
putLiveDraftsBack();
|
|
223
223
|
}
|
|
224
|
-
/** Applies each draft in order
|
|
225
|
-
export function drawDrafts(drafts) {
|
|
224
|
+
/** Applies each draft in order, then `chrome`; one for an element this load no longer has is skipped. */
|
|
225
|
+
export function drawDrafts(drafts, chrome) {
|
|
226
226
|
let drawn = 0;
|
|
227
227
|
let restored = false;
|
|
228
228
|
const numbers = {};
|
|
@@ -238,5 +238,10 @@ export function drawDrafts(drafts) {
|
|
|
238
238
|
}
|
|
239
239
|
if (restored)
|
|
240
240
|
redrawKeepingLiveDrafts();
|
|
241
|
-
|
|
241
|
+
if (chrome === undefined) {
|
|
242
|
+
if (!liveDrafts.size)
|
|
243
|
+
clearDragChrome();
|
|
244
|
+
return { drawn, drafts: numbers };
|
|
245
|
+
}
|
|
246
|
+
return { drawn, drafts: numbers, chromeDrawn: drawDragChrome(chrome) };
|
|
242
247
|
}
|
|
@@ -53,6 +53,10 @@ export interface EditingElementDescription extends EditingElementHit {
|
|
|
53
53
|
}>;
|
|
54
54
|
truncated: boolean;
|
|
55
55
|
textMarkup?: boolean;
|
|
56
|
+
layout?: {
|
|
57
|
+
width: number;
|
|
58
|
+
height: number;
|
|
59
|
+
};
|
|
56
60
|
}
|
|
57
61
|
export interface EditingElementMatch {
|
|
58
62
|
handle: EditingElementHandle;
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { COLOR_GRADING_SOURCE_HIDDEN_ATTR } from "../colorGrading.js";
|
|
7
7
|
import { getLogicalOpacity } from "../studioPreviewMark.js";
|
|
8
8
|
import { MAX_ELEMENT_ENTRIES, MAX_ELEMENT_VALUE, } from "./editingElement.js";
|
|
9
|
+
import { layoutOf } from "./drawnBox.js";
|
|
9
10
|
import { elementForHandle } from "./editingHandles.js";
|
|
10
11
|
import { composeElementTransform } from "./elementTransform.js";
|
|
11
12
|
export const MAX_GEOMETRY_CHILDREN = 60;
|
|
@@ -132,10 +133,6 @@ function clipPathOf(element) {
|
|
|
132
133
|
window.getComputedStyle(element).getPropertyValue("clip-path").trim();
|
|
133
134
|
return value.length <= MAX_ELEMENT_VALUE ? value : null;
|
|
134
135
|
}
|
|
135
|
-
function layoutOf(element) {
|
|
136
|
-
const { offsetWidth = 0, offsetHeight = 0 } = element;
|
|
137
|
-
return { width: offsetWidth, height: offsetHeight };
|
|
138
|
-
}
|
|
139
136
|
const finiteCorners = (corners) => corners && Object.values(corners).every((p) => Number.isFinite(p.x) && Number.isFinite(p.y))
|
|
140
137
|
? corners
|
|
141
138
|
: null;
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Element handles for the editing channel. The parent never receives an element, only a handle this
|
|
3
|
-
* module gives it and the plain data `describeElement` reads from it. Handles live for one page load:
|
|
4
|
-
* the maps are module state, and an entry goes once its element is garbage-collected.
|
|
5
|
-
*/
|
|
6
1
|
import { type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch } from "./editingElement.js";
|
|
7
2
|
export declare function handleFor(element: Element): EditingElementHandle;
|
|
8
3
|
/** The live element in this document behind `handle`, else null. */
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* module gives it and the plain data `describeElement` reads from it. Handles live for one page load:
|
|
4
4
|
* the maps are module state, and an entry goes once its element is garbage-collected.
|
|
5
5
|
*/
|
|
6
|
+
import { isDragChromeHost } from "./editing/dragChrome.js";
|
|
6
7
|
import { buildStableSelector, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, readElementSource, } from "./editingElement.js";
|
|
7
8
|
import { buildElementLabel, NO_TEXT, renderedTextOf } from "./elementLabel.js";
|
|
9
|
+
import { layoutOf } from "./drawnBox.js";
|
|
8
10
|
import { isEditableText } from "./editing/textMarkup.js";
|
|
9
11
|
// Drawn on first use, not at load: a render seeds getRandomValues, and a draw here would shift the
|
|
10
12
|
// composition's own random values.
|
|
@@ -160,6 +162,7 @@ function describeElement(element) {
|
|
|
160
162
|
children: children(element, state),
|
|
161
163
|
truncated: state.truncated,
|
|
162
164
|
textMarkup: isEditableText(element),
|
|
165
|
+
layout: layoutOf(element),
|
|
163
166
|
};
|
|
164
167
|
}
|
|
165
168
|
export function elementsAtPoint(x, y) {
|
|
@@ -187,6 +190,8 @@ export function ancestorHandles(requested) {
|
|
|
187
190
|
export function readEveryMatch(selector, read) {
|
|
188
191
|
const matches = [];
|
|
189
192
|
for (const element of document.querySelectorAll(selector)) {
|
|
193
|
+
if (isDragChromeHost(element))
|
|
194
|
+
continue;
|
|
190
195
|
if (matches.length === MAX_QUERY_MATCHES)
|
|
191
196
|
return { matches, truncated: true };
|
|
192
197
|
matches.push(boundedSource(element) ? read(element) : null);
|
|
@@ -197,6 +202,8 @@ export function queryElements(selector) {
|
|
|
197
202
|
const matches = [];
|
|
198
203
|
let truncated = false;
|
|
199
204
|
for (const element of document.querySelectorAll(selector)) {
|
|
205
|
+
if (isDragChromeHost(element))
|
|
206
|
+
continue;
|
|
200
207
|
if (matches.length === MAX_QUERY_MATCHES)
|
|
201
208
|
return { matches, truncated: true };
|
|
202
209
|
const source = boundedSource(element);
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import type { RestoreAttributesParams } from "./editing/restoreAttributes.js";
|
|
13
13
|
import { type EditingGeometryEvent, type WatchGeometryParams } from "./editing/watchGeometry.js";
|
|
14
|
+
import { type EditingPointerEvent, type WatchPointerParams } from "./editing/watchPointer.js";
|
|
14
15
|
import { MAX_DRAFT_PX, type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch } from "./editingElement.js";
|
|
15
16
|
import type { EditingElementBox, EditingElementGeometry } from "./editingGeometry.js";
|
|
16
17
|
import type { EditingGestureBase, EditingGestureStart } from "./editingGestureStart.js";
|
|
@@ -20,6 +21,7 @@ import type { EditingLayer, EditingStackingSibling } from "./editingLayers.js";
|
|
|
20
21
|
import { type GsapSetParams } from "./editing/gsapSet.js";
|
|
21
22
|
import { type PatchTweensParams } from "./editing/patchTween.js";
|
|
22
23
|
import { type EditingDraftEnd, type EditingDraftReply } from "./editingDraftEnd.js";
|
|
24
|
+
import { type EditingDragChrome } from "./editing/dragChrome.js";
|
|
23
25
|
import { type SoftReloadParams, type SoftReloadResult } from "./editing/softReload.js";
|
|
24
26
|
import { type HoldScenesParams, type MarkScenesStaleParams, type SwapScenesParams, type SwapScenesResult } from "./editing/scenes.js";
|
|
25
27
|
import { type LiveRetimeParams, type LiveRetimeResult } from "./editing/liveRetime.js";
|
|
@@ -42,6 +44,7 @@ export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTrans
|
|
|
42
44
|
export type { EditingGestureBase, EditingGestureStart } from "./editingGestureStart.js";
|
|
43
45
|
export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
|
|
44
46
|
export { MAX_EDIT_ENTRIES } from "./editing/editElement.js";
|
|
47
|
+
export { MAX_DRAG_CHROME_BYTES, MAX_DRAG_CHROME_NODES, parseDragChrome, type EditingDragChrome, type EditingDragChromeNode, } from "./editing/dragChrome.js";
|
|
45
48
|
export { MAX_FONT_FACES } from "./editing/textStyleReads.js";
|
|
46
49
|
export { MAX_STAGE_CLIP_KEYS, MAX_STAGE_ITEMS, type StageMeasuredItem, type StageMeasureParams, type StageMeasureResult, type StageTextStart, } from "./editing/stageMeasure.js";
|
|
47
50
|
export { isStageColour, MAX_STAGE_ACTS, readStageActHeld, readStageRect, STAGE_ACT_BORROWS, STAGE_ACT_STYLES, type StageActBorrow, type StageActDraw, type StageActElementHold, type StageActGhostHold, type StageActHeld, type StageActHold, type StageActParams, type StageActReadyEvent, type StageActRect, type StageActResult, type StageActStyle, type StageActTarget, type StageInputEvent, } from "./editing/stageAct.js";
|
|
@@ -51,11 +54,14 @@ export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_S
|
|
|
51
54
|
export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, type EditingLocalPointer, type EditingViewport, } from "./editingTargets.js";
|
|
52
55
|
export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, type EditingLayer, type EditingStackingSibling, type LayerKind, } from "./editingLayers.js";
|
|
53
56
|
export declare const EDITING_PROTOCOL_VERSION: 1;
|
|
57
|
+
export declare const DRAFT_CHROME = "draft-chrome";
|
|
54
58
|
/** Parent to frame, on the window: asks the runtime for the port. */
|
|
55
59
|
export declare const EDITING_CONNECT = "editing-connect";
|
|
60
|
+
export declare const PAGE_SHOWN = "page-shown";
|
|
61
|
+
export declare const PAGE_LEFT = "page-left";
|
|
56
62
|
/** Frame to parent, on the window: carries the port in its transfer list. */
|
|
57
63
|
export declare const EDITING_PORT = "editing-port";
|
|
58
|
-
export declare const EDITING_REQUEST_KINDS: readonly ["hello", "runtime-snapshot", "wait-for-seek", "set-loop-start", "computed-styles", "authored-styles", "font-faces", "elements-at-point", "pointer-targets", "describe", "ancestors", "query", "geometry", "layers", "draft", "gesture-start", "gesture-base", "console-errors", "watch-keys", "restore-attributes", "caption-words", "caption-transform", "color-grading-status", "color-grading-previews", "color-grading-playback", "watch-geometry", "audio-meter", "document-markup", "set-audio-group-attribute", "assign-audio-group", "gsap-snapshot", "motion-path-home", "max-z-index", "crop-lift", "edit-element", "remove-elements", "stacking-family", "gsap-set", "patch-tweens", "soft-reload", "hold-scenes", "mark-scenes-stale", "swap-scenes", "live-retime", "rebind-timing", "assets-unloaded", "text-edit", "serve-paused-frames", "frame-presented", "arm-canvas-keys", "resolve-canvas-key-action", "stage-measure", "stage-act"];
|
|
64
|
+
export declare const EDITING_REQUEST_KINDS: readonly ["hello", "runtime-snapshot", "wait-for-seek", "set-loop-start", "computed-styles", "authored-styles", "font-faces", "elements-at-point", "pointer-targets", "describe", "ancestors", "query", "geometry", "layers", "draft", "gesture-start", "gesture-base", "console-errors", "watch-keys", "restore-attributes", "caption-words", "caption-transform", "color-grading-status", "color-grading-previews", "color-grading-playback", "watch-geometry", "watch-pointer", "audio-meter", "document-markup", "set-audio-group-attribute", "assign-audio-group", "gsap-snapshot", "motion-path-home", "max-z-index", "crop-lift", "edit-element", "remove-elements", "stacking-family", "gsap-set", "patch-tweens", "soft-reload", "hold-scenes", "mark-scenes-stale", "swap-scenes", "live-retime", "rebind-timing", "assets-unloaded", "text-edit", "serve-paused-frames", "frame-presented", "arm-canvas-keys", "resolve-canvas-key-action", "stage-measure", "stage-act"];
|
|
59
65
|
export type EditingRequestKind = (typeof EDITING_REQUEST_KINDS)[number];
|
|
60
66
|
export interface EditingRuntimeSnapshot {
|
|
61
67
|
/** The runtime has installed its player API. */
|
|
@@ -127,6 +133,7 @@ export interface EditingRequests {
|
|
|
127
133
|
result: {
|
|
128
134
|
version: typeof EDITING_PROTOCOL_VERSION;
|
|
129
135
|
kinds: string[];
|
|
136
|
+
accepts?: string[];
|
|
130
137
|
};
|
|
131
138
|
};
|
|
132
139
|
"runtime-snapshot": {
|
|
@@ -259,10 +266,11 @@ export interface EditingRequests {
|
|
|
259
266
|
missingGroup: boolean;
|
|
260
267
|
};
|
|
261
268
|
};
|
|
262
|
-
/** Gesture drafts in order, up to MAX_DESCRIBE_HANDLES
|
|
269
|
+
/** Gesture drafts in order, up to MAX_DESCRIBE_HANDLES, and the chrome painted with them (null clears it). */
|
|
263
270
|
draft: {
|
|
264
271
|
params: {
|
|
265
272
|
drafts: EditingDraft[];
|
|
273
|
+
chrome?: EditingDragChrome;
|
|
266
274
|
};
|
|
267
275
|
result: EditingDraftReply & {
|
|
268
276
|
gsapSetTakesDrafts?: true;
|
|
@@ -333,6 +341,12 @@ export interface EditingRequests {
|
|
|
333
341
|
watching: number;
|
|
334
342
|
};
|
|
335
343
|
};
|
|
344
|
+
"watch-pointer": {
|
|
345
|
+
params: WatchPointerParams;
|
|
346
|
+
result: {
|
|
347
|
+
watching: boolean;
|
|
348
|
+
};
|
|
349
|
+
};
|
|
336
350
|
"audio-meter": {
|
|
337
351
|
params: {
|
|
338
352
|
on: boolean;
|
|
@@ -545,6 +559,7 @@ export interface EditingPortClient {
|
|
|
545
559
|
/** Calls `listener` with each key the frame forwards for `watch-keys`; returns the unsubscribe. */
|
|
546
560
|
onKey(listener: (key: EditingKeyEvent) => void): () => void;
|
|
547
561
|
onGeometry(listener: (event: EditingGeometryEvent) => void): () => void;
|
|
562
|
+
onPointerTargets(listener: (event: EditingPointerEvent) => void): () => void;
|
|
548
563
|
onTextEditEnded(listener: (event: TextEditEndedEvent) => void): () => void;
|
|
549
564
|
onTextEditAway(listener: (event: TextEditAwayEvent) => void): () => void;
|
|
550
565
|
onTextEditSelection(listener: (event: TextEditSelectionEvent) => void): () => void;
|
|
@@ -563,6 +578,7 @@ export declare function createEditingPortClient(options: {
|
|
|
563
578
|
iframe: HTMLIFrameElement;
|
|
564
579
|
timeoutMs?: number;
|
|
565
580
|
host?: Window;
|
|
581
|
+
gate?: Promise<boolean>;
|
|
566
582
|
}): EditingPortClient;
|
|
567
583
|
export { elementHome, transformWDivisor, type MotionPathHome } from "./editing/motionPathHome.js";
|
|
568
584
|
export { MAX_CANVAS_KEY_COMBOS, type ArmCanvasKeysParams, type ArmCanvasKeysResult, type CanvasKeyActionEvent, type CanvasKeyNudgeCombo, type ResolveCanvasKeyActionParams, type ResolveCanvasKeyActionResult, } from "./editing/canvasKeys.js";
|