@hyperframes/core 0.9.104 → 0.9.107

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.
@@ -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. */
@@ -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
+ }
@@ -3,7 +3,7 @@
3
3
  import { EDITING_ELEMENT_HANDLE } from "../editingElement.js";
4
4
  import { elementForHandle } from "../editingHandles.js";
5
5
  import { isStylableElement } from "../domRealm.js";
6
- import { DATA_ATTRIBUTE, holdsOnlyTextMarkup, MAX_EDIT_VALUE } from "./textMarkup.js";
6
+ import { DATA_ATTRIBUTE, holdsOnlyTextMarkup, MAX_EDIT_VALUE, MAX_TEXT_MARKUP } from "./textMarkup.js";
7
7
  export const MAX_EDIT_ENTRIES = 64;
8
8
  export { MAX_EDIT_VALUE };
9
9
  const STYLE_NAME = /^(?:-?[a-z][a-z0-9-]*|--[\w\u0080-\uffff-]+)$/;
@@ -11,7 +11,7 @@ const PANEL_ATTRIBUTES = new Set(["loop", "muted", "alt", "title", "src"]);
11
11
  const MEDIA_TAGS = new Set(["img", "video", "audio"]);
12
12
  const isAttributeName = (name) => DATA_ATTRIBUTE.test(name) || PANEL_ATTRIBUTES.has(name);
13
13
  export function isTextMarkup(html) {
14
- if (html.length > MAX_EDIT_VALUE)
14
+ if (html.length > MAX_TEXT_MARKUP)
15
15
  return false;
16
16
  const holder = document.createElement("template");
17
17
  holder.innerHTML = html;
@@ -36,7 +36,7 @@ const EDIT_KEYS = new Set([
36
36
  "attributes,handle,html,styles",
37
37
  "attributes,expect,handle,html,styles",
38
38
  ]);
39
- const isOptionalMarkup = (value) => value === undefined || (typeof value === "string" && value.length <= MAX_EDIT_VALUE);
39
+ const isOptionalMarkup = (value) => value === undefined || (typeof value === "string" && value.length <= MAX_TEXT_MARKUP);
40
40
  const markupFieldsOk = (html, expect) => isOptionalMarkup(html) &&
41
41
  isOptionalMarkup(expect) &&
42
42
  (expect === undefined || html !== undefined);
@@ -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
- style.transform = authored?.transform ?? "";
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 ["translate", "rotate", "scale", ...tweened]) {
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));
@@ -5,8 +5,8 @@ import { EDITING_ELEMENT_HANDLE } from "../editingElement.js";
5
5
  import { elementForHandle } from "../editingHandles.js";
6
6
  import { isDomNode, isStylableElement } from "../domRealm.js";
7
7
  import { sanitizeRichTextChildren } from "../../utils/richTextSanitize.js";
8
- import { openTextEdits, isTextMarkup, MAX_EDIT_VALUE } from "./editElement.js";
9
- import { isEditableText } from "./textMarkup.js";
8
+ import { openTextEdits, isTextMarkup } from "./editElement.js";
9
+ import { isEditableText, MAX_TEXT_MARKUP } from "./textMarkup.js";
10
10
  import { caretBoxIn, caretColorOf, caretSideAfterKey, placeCaretAtEnd, } from "./textCaret.js";
11
11
  import { applyInlineStyle, INLINE_STYLE_PROPERTIES, readFirstPaintedElement, readInlineStyle, readInlineStyleSpread, } from "../../utils/inlineTextStyleRead.js";
12
12
  const EDITING_OUTLINE = "2px solid #3CE6AC";
@@ -101,7 +101,7 @@ export function textEditAwayEvent(data, version) {
101
101
  return null;
102
102
  return { handle, button, point, viewportWidth, keys };
103
103
  }
104
- const isValue = (value) => value === null || (typeof value === "string" && value.length <= MAX_EDIT_VALUE);
104
+ const isValue = (value) => value === null || (typeof value === "string" && value.length <= MAX_TEXT_MARKUP);
105
105
  const isTextMarkupOrNull = (value) => value === null || (typeof value === "string" && isTextMarkup(value));
106
106
  export function textEditEndedEvent(data, version) {
107
107
  if (!isRecord(data) || !keysAre(data, "event,handle,html,previous,v"))
@@ -1,4 +1,5 @@
1
1
  export declare const DATA_ATTRIBUTE: RegExp;
2
2
  export declare const MAX_EDIT_VALUE = 200000;
3
+ export declare const MAX_TEXT_MARKUP: number;
3
4
  export declare const holdsOnlyTextMarkup: (root: ParentNode) => boolean;
4
5
  export declare const isEditableText: (element: Element) => boolean;
@@ -1,6 +1,7 @@
1
1
  // Text markup: text in inline text tags carrying plain attributes, so no URL and no handler.
2
2
  export const DATA_ATTRIBUTE = /^data-[a-z0-9_-]+$/;
3
3
  export const MAX_EDIT_VALUE = 200_000;
4
+ export const MAX_TEXT_MARKUP = 32 * 1024 * 1024;
4
5
  const TEXT_TAGS = new Set([
5
6
  "span",
6
7
  "strong",
@@ -19,4 +20,4 @@ export const holdsOnlyTextMarkup = (root) => Array.from(root.querySelectorAll("*
19
20
  el
20
21
  .getAttributeNames()
21
22
  .every((name) => TEXT_ATTRIBUTES.has(name) || DATA_ATTRIBUTE.test(name)));
22
- export const isEditableText = (element) => holdsOnlyTextMarkup(element) && element.innerHTML.length <= MAX_EDIT_VALUE;
23
+ export const isEditableText = (element) => holdsOnlyTextMarkup(element) && element.innerHTML.length <= MAX_TEXT_MARKUP;
@@ -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; one for an element this load no longer has is skipped. */
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 { computedTranslateAxes, movedTranslate, SIZE_PROPERTIES, writeDrawnSize } from "./drawnBox.js";
11
- const DRAWN = ["translate", "rotate", "transform", ...SIZE_PROPERTIES];
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: DRAWN.map((name) => [
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, DRAWN);
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, DRAWN);
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; one for an element this load no longer has is skipped. */
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
- return { drawn, drafts: numbers };
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
  }
@@ -13,5 +13,6 @@ export type EditingDraftEnd = {
13
13
  export type EditingDraftReply = {
14
14
  drawn: number;
15
15
  drafts: Record<EditingElementHandle, number>;
16
+ chromeDrawn?: boolean;
16
17
  };
17
18
  export declare function parseDraftEnd(value: unknown): EditingDraftEnd | null;
@@ -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);