@hyperframes/core 0.9.64 → 0.9.66

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.
Files changed (39) hide show
  1. package/dist/canary.d.ts +15 -0
  2. package/dist/canary.js +1 -1
  3. package/dist/compiler/compositionScoping.d.ts +2 -0
  4. package/dist/compiler/compositionScoping.js +44 -14
  5. package/dist/compiler/htmlBundler.d.ts +5 -1
  6. package/dist/compiler/htmlBundler.js +48 -13
  7. package/dist/compiler/index.d.ts +1 -1
  8. package/dist/compiler/index.js +1 -1
  9. package/dist/compiler/inlineSubCompositions.d.ts +7 -0
  10. package/dist/compiler/inlineSubCompositions.js +36 -17
  11. package/dist/compiler/selectorIdTokens.d.ts +2 -0
  12. package/dist/compiler/selectorIdTokens.js +17 -0
  13. package/dist/compiler/svgIdNamespacing.d.ts +4 -2
  14. package/dist/compiler/svgIdNamespacing.js +58 -18
  15. package/dist/figma/bindings.js +7 -6
  16. package/dist/figma/index.d.ts +2 -1
  17. package/dist/figma/index.js +2 -1
  18. package/dist/figma/manifest.d.ts +2 -0
  19. package/dist/figma/manifest.js +13 -4
  20. package/dist/figma/mediaIndex.d.ts +2 -3
  21. package/dist/figma/mediaIndex.js +17 -17
  22. package/dist/figma/projectFiles.d.ts +16 -0
  23. package/dist/figma/projectFiles.js +81 -0
  24. package/dist/generated/runtime-inline.js +1 -1
  25. package/dist/generated/svg-selector-aliases-inline.js +1 -1
  26. package/dist/hyperframe.runtime.iife.js +72 -71
  27. package/dist/runtime/editing/editElement.d.ts +18 -0
  28. package/dist/runtime/editing/editElement.js +72 -0
  29. package/dist/runtime/editing/gsapSnapshot.d.ts +43 -0
  30. package/dist/runtime/editing/gsapSnapshot.js +169 -0
  31. package/dist/runtime/editing/gsapSnapshotLimits.d.ts +6 -0
  32. package/dist/runtime/editing/gsapSnapshotLimits.js +6 -0
  33. package/dist/runtime/editing/motionPathHome.d.ts +19 -0
  34. package/dist/runtime/editing/motionPathHome.js +85 -0
  35. package/dist/runtime/editingHandles.js +34 -10
  36. package/dist/runtime/editingPort.d.ts +36 -1
  37. package/dist/runtime/editingPort.js +20 -1
  38. package/dist/safePath.js +3 -1
  39. package/package.json +4 -4
@@ -0,0 +1,18 @@
1
+ import { type EditingElementHandle } from "../editingElement.js";
2
+ export type ElementEditEntry = [name: string, value: string | null];
3
+ export type StyleEditEntry = [name: string, value: string | null, priority?: "important"];
4
+ export type EditElementParams = {
5
+ handle: EditingElementHandle;
6
+ styles: StyleEditEntry[];
7
+ attributes: ElementEditEntry[];
8
+ };
9
+ export type EditElementResult = {
10
+ applied: boolean;
11
+ styles: StyleEditEntry[];
12
+ attributes: ElementEditEntry[];
13
+ };
14
+ export declare const MAX_EDIT_ENTRIES = 64;
15
+ export declare const MAX_EDIT_VALUE = 200000;
16
+ export declare function parseEditElement(params: unknown): EditElementParams | null;
17
+ /** Draws nothing it could not put back: a `src` off media, or a value too long to send back. */
18
+ export declare function editElement({ handle, styles, attributes }: EditElementParams): EditElementResult;
@@ -0,0 +1,72 @@
1
+ // `edit-element`: a property panel edit drawn live on one element: inline styles and attributes,
2
+ // null removing one. The reply carries what each name held before, so a failed save can put it back.
3
+ import { EDITING_ELEMENT_HANDLE } from "../editingElement.js";
4
+ import { elementForHandle } from "../editingHandles.js";
5
+ import { isStylableElement } from "../domRealm.js";
6
+ export const MAX_EDIT_ENTRIES = 64;
7
+ export const MAX_EDIT_VALUE = 200_000;
8
+ const STYLE_NAME = /^(?:-?[a-z][a-z0-9-]*|--[\w\u0080-￿-]+)$/;
9
+ const DATA_ATTRIBUTE = /^data-[a-z0-9_-]+$/;
10
+ const PANEL_ATTRIBUTES = new Set(["loop", "muted", "alt", "title", "src"]);
11
+ const MEDIA_TAGS = new Set(["img", "video", "audio"]);
12
+ const isAttributeName = (name) => DATA_ATTRIBUTE.test(name) || PANEL_ATTRIBUTES.has(name);
13
+ const isValue = (value) => value === null || (typeof value === "string" && value.length <= MAX_EDIT_VALUE);
14
+ function entries(value, valid) {
15
+ if (!Array.isArray(value) || value.length > MAX_EDIT_ENTRIES)
16
+ return null;
17
+ const ok = value.every((entry) => Array.isArray(entry) && valid(entry));
18
+ return ok ? value : null;
19
+ }
20
+ const styleEntry = ([name, value, priority, ...rest]) => typeof name === "string" &&
21
+ STYLE_NAME.test(name) &&
22
+ isValue(value) &&
23
+ (priority === undefined || priority === "important") &&
24
+ rest.length === 0;
25
+ const attributeEntry = ([name, value, ...rest]) => typeof name === "string" && isAttributeName(name) && isValue(value) && rest.length === 0;
26
+ export function parseEditElement(params) {
27
+ if (Object.prototype.toString.call(params) !== "[object Object]")
28
+ return null;
29
+ const record = params;
30
+ if (Object.keys(record).sort().join() !== "attributes,handle,styles")
31
+ return null;
32
+ const { handle } = record;
33
+ if (typeof handle !== "string" || !EDITING_ELEMENT_HANDLE.test(handle))
34
+ return null;
35
+ const styles = entries(record.styles, styleEntry);
36
+ const attributes = entries(record.attributes, attributeEntry);
37
+ return styles && attributes ? { handle, styles, attributes } : null;
38
+ }
39
+ const NOT_APPLIED = { applied: false, styles: [], attributes: [] };
40
+ /** Draws nothing it could not put back: a `src` off media, or a value too long to send back. */
41
+ export function editElement({ handle, styles, attributes }) {
42
+ const element = elementForHandle(handle);
43
+ if (!isStylableElement(element))
44
+ return NOT_APPLIED;
45
+ const style = element.style;
46
+ const media = MEDIA_TAGS.has(element.localName);
47
+ if (attributes.some(([name]) => name === "src") && !media)
48
+ return NOT_APPLIED;
49
+ const before = {
50
+ applied: true,
51
+ styles: styles.map(([name]) => {
52
+ const value = style.getPropertyValue(name) || null;
53
+ return style.getPropertyPriority(name) ? [name, value, "important"] : [name, value];
54
+ }),
55
+ attributes: attributes.map(([name]) => [name, element.getAttribute(name)]),
56
+ };
57
+ if (![...before.styles, ...before.attributes].every(([, value]) => isValue(value)))
58
+ return NOT_APPLIED;
59
+ for (const [name, value, priority] of styles) {
60
+ if (value === null)
61
+ style.removeProperty(name);
62
+ else
63
+ style.setProperty(name, value, priority ?? "");
64
+ }
65
+ for (const [name, value] of attributes) {
66
+ if (value === null)
67
+ element.removeAttribute(name);
68
+ else
69
+ element.setAttribute(name, value);
70
+ }
71
+ return before;
72
+ }
@@ -0,0 +1,43 @@
1
+ import type { EditingElementHandle } from "../editingElement.js";
2
+ export type SnapshotValue = number | string | boolean | null | SnapshotValue[] | {
3
+ [key: string]: SnapshotValue;
4
+ };
5
+ export interface GsapSnapshotTween {
6
+ targets: EditingElementHandle[];
7
+ /** The tween's vars; functions, elements and other live objects are left out. */
8
+ vars: Record<string, SnapshotValue>;
9
+ start: number;
10
+ duration: number;
11
+ from: boolean;
12
+ initted: boolean;
13
+ /** GSAP's parse of each channel: start `s` and change `c`. */
14
+ parsed: Array<{
15
+ p: string;
16
+ s: number;
17
+ c: number;
18
+ }>;
19
+ /** A keyframed tween's steps, timed within the tween. */
20
+ parts: GsapSnapshotTween[];
21
+ }
22
+ export interface GsapSnapshotTimeline {
23
+ id: string;
24
+ time: number | null;
25
+ defaultEase: string | null;
26
+ tweens: GsapSnapshotTween[];
27
+ }
28
+ export interface GsapSnapshotTarget {
29
+ handle: EditingElementHandle;
30
+ id: string;
31
+ className: string;
32
+ /** GSAP's current value of each channel a tween animates, and of x and y. */
33
+ values: Record<string, number>;
34
+ }
35
+ export interface GsapSnapshot {
36
+ /** The player's time when read; null without a player. */
37
+ time: number | null;
38
+ defaultEase: string | null;
39
+ timelines: GsapSnapshotTimeline[];
40
+ targets: GsapSnapshotTarget[];
41
+ }
42
+ /** Every tween on the frame's timelines, after any seek in flight has painted. Throws past a bound. */
43
+ export declare function gsapSnapshot(): Promise<GsapSnapshot>;
@@ -0,0 +1,169 @@
1
+ import { handleFor } from "../editingHandles.js";
2
+ import { isPlainRecord } from "../editingPort.js";
3
+ import { isElementNode } from "../domRealm.js";
4
+ import { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./gsapSnapshotLimits.js";
5
+ const VARS_SKIP = new Set([
6
+ "ease",
7
+ "easeEach",
8
+ "duration",
9
+ "delay",
10
+ "stagger",
11
+ "overwrite",
12
+ "data",
13
+ "id",
14
+ ]);
15
+ class SnapshotBound extends Error {
16
+ constructor(what) {
17
+ super(`the preview's GSAP state is past the snapshot bound on ${what}`);
18
+ }
19
+ }
20
+ /** Every text the snapshot carries, keys and ids included, is held to the text bound. */
21
+ function capped(value) {
22
+ if (value.length > MAX_SNAPSHOT_TEXT)
23
+ throw new SnapshotBound("text length");
24
+ return value;
25
+ }
26
+ const text = (value) => (typeof value === "string" ? capped(value) : null);
27
+ const finite = (value) => typeof value === "number" && Number.isFinite(value) ? value : 0;
28
+ /** Every tween on the frame's timelines, after any seek in flight has painted. Throws past a bound. */
29
+ export async function gsapSnapshot() {
30
+ const frame = window;
31
+ await frame.__hfWaitForSeekCompletion?.();
32
+ const gsap = frame.gsap;
33
+ const reader = new SnapshotReader();
34
+ const timelines = [];
35
+ for (const [id, live] of Object.entries(frame.__timelines ?? {})) {
36
+ if (typeof live?.getChildren !== "function")
37
+ continue;
38
+ const tweens = live.getChildren(true).filter((child) => typeof child.targets === "function");
39
+ if (timelines.length >= MAX_SNAPSHOT_TWEENS)
40
+ throw new SnapshotBound("timelines");
41
+ timelines.push({
42
+ id: capped(id),
43
+ time: typeof live.time === "function" ? finite(live.time()) : null,
44
+ defaultEase: text(live.vars?.defaults?.ease),
45
+ tweens: tweens.map((tween) => reader.tween(tween)),
46
+ });
47
+ }
48
+ const time = frame.__player?.getTime?.();
49
+ return {
50
+ time: typeof time === "number" && Number.isFinite(time) ? time : null,
51
+ defaultEase: text(gsap?.defaults?.().ease),
52
+ timelines,
53
+ targets: reader.targets(gsap),
54
+ };
55
+ }
56
+ class SnapshotReader {
57
+ tweens = 0;
58
+ fields = 0;
59
+ channels = new Map();
60
+ tween(live) {
61
+ if (++this.tweens > MAX_SNAPSHOT_TWEENS)
62
+ throw new SnapshotBound("tweens");
63
+ const elements = (live.targets?.() ?? []).filter(isElementNode);
64
+ const vars = this.plain(live.vars, 0);
65
+ const parsed = parsedChannels(live._pt);
66
+ const parts = (live.timeline?.getChildren?.() ?? []).map((part) => this.tween(part));
67
+ for (const element of elements)
68
+ this.note(element, vars, parsed, parts);
69
+ const record = isPlainRecord(vars) ? vars : {};
70
+ return { targets: elements.map(handleFor), vars: record, ...timing(live), parsed, parts };
71
+ }
72
+ targets(gsap) {
73
+ if (this.channels.size > MAX_SNAPSHOT_TARGETS)
74
+ throw new SnapshotBound("targets");
75
+ return [...this.channels].map(([element, channels]) => {
76
+ if (channels.size > MAX_SNAPSHOT_CHANNELS)
77
+ throw new SnapshotBound("channels");
78
+ const values = {};
79
+ for (const channel of channels) {
80
+ const value = Number(gsap?.getProperty?.(element, channel));
81
+ if (Number.isFinite(value))
82
+ values[channel] = value;
83
+ }
84
+ const className = element.getAttribute("class") ?? "";
85
+ if (className.length > MAX_SNAPSHOT_TEXT)
86
+ throw new SnapshotBound("class names");
87
+ return { handle: handleFor(element), id: capped(element.id), className, values };
88
+ });
89
+ }
90
+ note(element, vars, parsed, parts) {
91
+ const channels = this.channels.get(element) ?? new Set(["x", "y"]);
92
+ this.channels.set(element, channels);
93
+ const steps = isPlainRecord(vars) ? [vars, ...stepsOf(vars.keyframes)] : [];
94
+ for (const step of steps)
95
+ for (const [key, value] of Object.entries(step))
96
+ if (!VARS_SKIP.has(key) && isChannelValue(value))
97
+ channels.add(key);
98
+ for (const { p } of [...parsed, ...parts.flatMap((part) => part.parsed)])
99
+ channels.add(p);
100
+ }
101
+ plain(value, depth) {
102
+ if (++this.fields > MAX_SNAPSHOT_FIELDS)
103
+ throw new SnapshotBound("tween fields");
104
+ if (Array.isArray(value))
105
+ return this.list(value, depth);
106
+ if (isLiteralRecord(value))
107
+ return this.record(value, depth);
108
+ return scalar(value);
109
+ }
110
+ list(value, depth) {
111
+ nested(depth);
112
+ return value.map((item) => this.plain(item, depth + 1) ?? null);
113
+ }
114
+ record(value, depth) {
115
+ nested(depth);
116
+ const out = {};
117
+ for (const [key, item] of Object.entries(value)) {
118
+ const kept = this.plain(item, depth + 1);
119
+ if (kept !== undefined)
120
+ out[capped(key)] = kept;
121
+ }
122
+ return out;
123
+ }
124
+ }
125
+ function timing(live) {
126
+ return {
127
+ start: finite(live.startTime?.()),
128
+ duration: finite(live.duration?.()),
129
+ from: Boolean(live._from),
130
+ initted: Boolean(live._initted),
131
+ };
132
+ }
133
+ // GSAP puts live objects on a tween's vars (`parent` is its timeline), and they reach the whole graph.
134
+ const isLiteralRecord = (value) => isPlainRecord(value) && [Object.prototype, null].includes(Object.getPrototypeOf(value));
135
+ function nested(depth) {
136
+ if (depth >= MAX_VARS_DEPTH)
137
+ throw new SnapshotBound("nesting");
138
+ }
139
+ /** A value kept as is; functions, elements and other live objects are left out. */
140
+ function scalar(value) {
141
+ if (typeof value === "number")
142
+ return Number.isFinite(value) ? value : undefined;
143
+ if (typeof value !== "string")
144
+ return typeof value === "boolean" || value === null ? value : undefined;
145
+ return capped(value);
146
+ }
147
+ /** A step's value, or an object-of-arrays keyframe's list of them. */
148
+ const isChannelValue = (value) => typeof value === "number" || typeof value === "string" || Array.isArray(value);
149
+ /** Keyframe steps in any of GSAP's forms; an object of arrays is its own one step. */
150
+ function stepsOf(keyframes) {
151
+ if (Array.isArray(keyframes))
152
+ return keyframes.filter(isPlainRecord);
153
+ if (!isPlainRecord(keyframes))
154
+ return [];
155
+ return [keyframes, ...Object.values(keyframes).filter(isPlainRecord)];
156
+ }
157
+ /** The tween's property tweens, CSSPlugin's nested ones included, in chain order; a node seen before ends a chain. */
158
+ function parsedChannels(first, seen = new Set()) {
159
+ const out = [];
160
+ for (let node = first; node && !seen.has(node); node = node._next) {
161
+ seen.add(node);
162
+ if (typeof node.p === "string" && typeof node.s === "number" && typeof node.c === "number")
163
+ out.push({ p: capped(node.p), s: node.s, c: node.c });
164
+ out.push(...parsedChannels(node.d?._pt, seen));
165
+ if (out.length > MAX_SNAPSHOT_CHANNELS)
166
+ throw new SnapshotBound("parsed channels");
167
+ }
168
+ return out;
169
+ }
@@ -0,0 +1,6 @@
1
+ export declare const MAX_SNAPSHOT_TWEENS = 2048;
2
+ export declare const MAX_SNAPSHOT_TARGETS = 512;
3
+ export declare const MAX_SNAPSHOT_CHANNELS = 64;
4
+ export declare const MAX_SNAPSHOT_FIELDS = 100000;
5
+ export declare const MAX_SNAPSHOT_TEXT = 4096;
6
+ export declare const MAX_VARS_DEPTH = 6;
@@ -0,0 +1,6 @@
1
+ export const MAX_SNAPSHOT_TWEENS = 2_048;
2
+ export const MAX_SNAPSHOT_TARGETS = 512;
3
+ export const MAX_SNAPSHOT_CHANNELS = 64;
4
+ export const MAX_SNAPSHOT_FIELDS = 100_000;
5
+ export const MAX_SNAPSHOT_TEXT = 4_096;
6
+ export const MAX_VARS_DEPTH = 6;
@@ -0,0 +1,19 @@
1
+ /** The layer's centre with no animation, its size, and how far its centre moves per px it grows. */
2
+ export type MotionPathHome = {
3
+ x: number;
4
+ y: number;
5
+ w: number;
6
+ h: number;
7
+ ax: number;
8
+ ay: number;
9
+ };
10
+ export declare function elementHome(el: HTMLElement): MotionPathHome;
11
+ export declare function transformWDivisor(el: HTMLElement): number;
12
+ export interface MotionPathFrameHome {
13
+ home: MotionPathHome | null;
14
+ /** 1/m44 of the element's own transform: how much a depth element magnifies its path. */
15
+ perspective: number;
16
+ visible: boolean;
17
+ plugin: boolean;
18
+ }
19
+ export declare function motionPathHome(selector: string): MotionPathFrameHome;
@@ -0,0 +1,85 @@
1
+ import { isHtmlElement } from "../domRealm.js";
2
+ import { isElementVisibleThroughAncestors } from "../editingGeometry.js";
3
+ const computedTransform = (el) => el.ownerDocument?.defaultView?.getComputedStyle(el).transform ?? "none";
4
+ function matrixTranslate(transform) {
5
+ const match = /(matrix3d|matrix)\(([^)]+)\)/.exec(transform);
6
+ const values = match?.[2]?.split(",") ?? [];
7
+ return match?.[1] === "matrix3d" ? [values[12], values[13]] : [values[4], values[5]];
8
+ }
9
+ function transformTranslate(el) {
10
+ const [x, y] = matrixTranslate(computedTransform(el));
11
+ return { x: Number(x) || 0, y: Number(y) || 0 };
12
+ }
13
+ function cssTranslate(el) {
14
+ const raw = el.ownerDocument?.defaultView?.getComputedStyle(el).translate ?? "none";
15
+ const [x = "0", y = "0"] = raw === "none" ? [] : raw.split(" ");
16
+ const px = (v, size) => v.endsWith("%") ? (Number.parseFloat(v) / 100) * size : Number.parseFloat(v) || 0;
17
+ return [px(x, el.offsetWidth), px(y, el.offsetHeight)];
18
+ }
19
+ /** Centre shift per px grown: 0.5 from a set left/top, -0.5 from a set right/bottom, plus the percent.
20
+ * ponytail: in-flow layers get 0 (layout may centre them); read their anchor if one draws off. */
21
+ function growShares(el, px, py) {
22
+ const style = el.ownerDocument?.defaultView?.getComputedStyle(el);
23
+ if (!style || !/^(absolute|fixed)$/.test(style.position))
24
+ return { ax: 0, ay: 0 };
25
+ const map = el.computedStyleMap?.();
26
+ const auto = (side) => String(map?.get(side) ?? "") === "auto";
27
+ const share = (start, end) => (auto(start) && !auto(end) ? -0.5 : 0.5);
28
+ return { ax: share("left", "right") + px, ay: share("top", "bottom") + py };
29
+ }
30
+ export function elementHome(el) {
31
+ let left = 0;
32
+ let top = 0;
33
+ let node = el;
34
+ while (node) {
35
+ left += node.offsetLeft;
36
+ top += node.offsetTop;
37
+ // Ancestor transforms (a group wrapper GSAP moved) shift where the layer renders; its own
38
+ // transform is the animated offset the path itself draws, so it is left out.
39
+ if (node !== el) {
40
+ const t = transformTranslate(node);
41
+ left += t.x;
42
+ top += t.y;
43
+ }
44
+ const parent = node.offsetParent;
45
+ if (!parent || parent.hasAttribute("data-composition-id"))
46
+ break;
47
+ node = parent;
48
+ }
49
+ // A translate composes once GSAP has parsed the layer; before, its parse sums translate and transform,
50
+ // makes minus half the size xPercent -50 and folds the rest into x, which a path sets (_parseTransform).
51
+ const cache = el._gsap;
52
+ const parsed = cache !== undefined && "x" in cache && !cache.uncache;
53
+ const [tx, ty] = cssTranslate(el);
54
+ const share = (cached, t, size) => parsed ? (Number(cached) || 0) / 100 : t && Math.round(size / 2) === Math.round(-t) ? -0.5 : 0;
55
+ const own = parsed ? { x: 0, y: 0 } : transformTranslate(el);
56
+ const [px, py] = [
57
+ share(cache?.xPercent, tx + own.x, el.offsetWidth),
58
+ share(cache?.yPercent, ty + own.y, el.offsetHeight),
59
+ ];
60
+ const x = left + el.offsetWidth * (0.5 + px) + (parsed ? tx : 0);
61
+ const y = top + el.offsetHeight * (0.5 + py) + (parsed ? ty : 0);
62
+ const { ax, ay } = growShares(el, px, py);
63
+ return { x, y, w: el.offsetWidth, h: el.offsetHeight, ax, ay };
64
+ }
65
+ // A depth element (matrix3d m44) renders 1/m44 larger, so its path's offsets travel 1/m44 further on screen.
66
+ export function transformWDivisor(el) {
67
+ const t = el.ownerDocument?.defaultView?.getComputedStyle(el).transform;
68
+ if (!t || !t.startsWith("matrix3d("))
69
+ return 1;
70
+ const v = t.slice("matrix3d(".length, -1).split(",");
71
+ const w = Number.parseFloat(v[15] ?? "");
72
+ return Number.isFinite(w) && w > 0 ? w : 1;
73
+ }
74
+ export function motionPathHome(selector) {
75
+ const plugin = Boolean(window.MotionPathPlugin);
76
+ const element = document.querySelector(selector);
77
+ if (!isHtmlElement(element))
78
+ return { home: null, perspective: 1, visible: true, plugin };
79
+ return {
80
+ home: elementHome(element),
81
+ perspective: 1 / transformWDivisor(element),
82
+ visible: isElementVisibleThroughAncestors(element),
83
+ plugin,
84
+ };
85
+ }
@@ -44,6 +44,14 @@ export const trackedHandleCount = () => elements.size;
44
44
  const sameSource = (a, b) => a.file === b.file &&
45
45
  a.compositionId === b.compositionId &&
46
46
  a.originalCompositionId === b.originalCompositionId;
47
+ /** The element's source when every field fits the port; null otherwise, since a cut path or id names another file. */
48
+ function boundedSource(element) {
49
+ const source = readElementSource(element);
50
+ const fields = [source.file, source.compositionId, source.originalCompositionId];
51
+ return fields.every((field) => field === null || field.length <= MAX_ELEMENT_VALUE)
52
+ ? source
53
+ : null;
54
+ }
47
55
  function matchesBefore(element, selector) {
48
56
  if (!selector?.startsWith("."))
49
57
  return null;
@@ -58,7 +66,9 @@ function matchesBefore(element, selector) {
58
66
  for (const match of matches) {
59
67
  if (match === element)
60
68
  return groups;
61
- const source = readElementSource(match);
69
+ const source = boundedSource(match);
70
+ if (!source)
71
+ return null;
62
72
  const group = groups.find((entry) => sameSource(entry.source, source));
63
73
  if (group)
64
74
  group.count += 1;
@@ -87,13 +97,18 @@ function inlineStyles(element, state) {
87
97
  state.truncated = true;
88
98
  for (let index = 0; index < Math.min(declared.length, MAX_ELEMENT_ENTRIES); index += 1) {
89
99
  const name = declared.item(index);
100
+ if (name.length > MAX_ELEMENT_VALUE) {
101
+ state.truncated = true;
102
+ continue;
103
+ }
90
104
  styles[name] = cut(declared.getPropertyValue(name), MAX_ELEMENT_VALUE, state, true);
91
105
  }
92
106
  return styles;
93
107
  }
94
108
  function attributes(element, state) {
95
- const kept = Array.from(element.attributes).filter((attribute) => attribute.name !== "style");
96
- if (kept.length > MAX_ELEMENT_ENTRIES)
109
+ const named = Array.from(element.attributes).filter((attribute) => attribute.name !== "style");
110
+ const kept = named.filter((attribute) => attribute.name.length <= MAX_ELEMENT_VALUE);
111
+ if (kept.length < named.length || kept.length > MAX_ELEMENT_ENTRIES)
97
112
  state.truncated = true;
98
113
  return kept
99
114
  .slice(0, MAX_ELEMENT_ENTRIES)
@@ -118,21 +133,25 @@ export function elementHit(element) {
118
133
  const rect = element.getBoundingClientRect();
119
134
  return {
120
135
  handle: handleFor(element),
121
- tag: element.tagName.toLowerCase(),
136
+ tag: element.tagName.toLowerCase().slice(0, MAX_ELEMENT_VALUE),
122
137
  rect: { x: rect.x, y: rect.y, width: rect.width, height: rect.height },
123
138
  };
124
139
  }
140
+ const whole = (value) => value && value.length <= MAX_ELEMENT_VALUE ? value : undefined;
125
141
  function describeElement(element) {
126
- const selector = buildStableSelector(element);
142
+ const source = boundedSource(element);
143
+ if (!source)
144
+ return null;
145
+ const selector = whole(buildStableSelector(element));
127
146
  const state = { truncated: false };
128
147
  return {
129
148
  ...elementHit(element),
130
- label: buildElementLabel(element),
149
+ label: buildElementLabel(element).slice(0, MAX_ELEMENT_VALUE),
131
150
  parent: element.parentElement ? handleFor(element.parentElement) : null,
132
- id: element.id || null,
151
+ id: whole(element.id) ?? null,
133
152
  selector: selector ?? null,
134
153
  matchesBefore: matchesBefore(element, selector),
135
- source: readElementSource(element),
154
+ source,
136
155
  locked: element.closest("[data-timeline-locked]") !== null,
137
156
  attributes: attributes(element, state),
138
157
  inlineStyles: inlineStyles(element, state),
@@ -165,10 +184,15 @@ export function ancestorHandles(requested) {
165
184
  }
166
185
  export function queryElements(selector) {
167
186
  const matches = [];
187
+ let truncated = false;
168
188
  for (const element of document.querySelectorAll(selector)) {
169
189
  if (matches.length === MAX_QUERY_MATCHES)
170
190
  return { matches, truncated: true };
171
- matches.push({ handle: handleFor(element), source: readElementSource(element) });
191
+ const source = boundedSource(element);
192
+ if (source)
193
+ matches.push({ handle: handleFor(element), source });
194
+ else
195
+ truncated = true;
172
196
  }
173
- return { matches, truncated: false };
197
+ return { matches, truncated };
174
198
  }
@@ -14,6 +14,8 @@ import { type EditingGeometryEvent, type WatchGeometryParams } from "./editing/w
14
14
  import { type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch } from "./editingElement.js";
15
15
  import type { EditingElementBox, EditingElementGeometry } from "./editingGeometry.js";
16
16
  import type { EditingGestureStart } from "./editingGestureStart.js";
17
+ import type { GsapSnapshot } from "./editing/gsapSnapshot.js";
18
+ import type { MotionPathFrameHome } from "./editing/motionPathHome.js";
17
19
  import type { EditingLayer } from "./editingLayers.js";
18
20
  import type { RuntimeTimelineMessage } from "./types.js";
19
21
  import { type CaptionWordBox, type CaptionWordsParams } from "./editing/captionWords.js";
@@ -24,10 +26,12 @@ import { type ColorGradingPlaybackRequest } from "./editing/color-grading-playba
24
26
  import { type AssignAudioGroupParams } from "./editing/assignAudioGroup.js";
25
27
  import { type AudioMeterLevels } from "./editing/audioMeter.js";
26
28
  import { type SetAudioGroupAttributeParams } from "./editing/setAudioGroupAttribute.js";
29
+ import { type EditElementParams, type EditElementResult } from "./editing/editElement.js";
27
30
  export { buildStableSelector, escapeCssString, getPreferredClassSelector, readElementSource, EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch, type EditingElementSource, type EditingRect, } from "./editingElement.js";
28
31
  export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, type EditingCorner, type EditingCorners, type EditingElementBox, type EditingElementGeometry, type ElementTransformSnapshot, } from "./editingGeometry.js";
29
32
  export type { EditingGestureStart } from "./editingGestureStart.js";
30
33
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
34
+ export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./editing/gsapSnapshotLimits.js";
31
35
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, type EditingLocalPointer, type EditingViewport, } from "./editingTargets.js";
32
36
  export { elementZIndex, hasOnlyFormattingChildren, isCompositionHost, layerKindOf, type EditingLayer, type LayerKind, } from "./editingLayers.js";
33
37
  export { composeElementTransform, individualRotateDegrees, type PlanarTransformOps, } from "./elementTransform.js";
@@ -36,7 +40,7 @@ export declare const EDITING_PROTOCOL_VERSION: 1;
36
40
  export declare const EDITING_CONNECT = "editing-connect";
37
41
  /** Frame to parent, on the window: carries the port in its transfer list. */
38
42
  export declare const EDITING_PORT = "editing-port";
39
- export declare const EDITING_REQUEST_KINDS: readonly ["hello", "runtime-snapshot", "wait-for-seek", "set-loop-start", "computed-styles", "elements-at-point", "pointer-targets", "describe", "ancestors", "query", "geometry", "layers", "draft", "gesture-start", "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"];
43
+ export declare const EDITING_REQUEST_KINDS: readonly ["hello", "runtime-snapshot", "wait-for-seek", "set-loop-start", "computed-styles", "elements-at-point", "pointer-targets", "describe", "ancestors", "query", "geometry", "layers", "draft", "gesture-start", "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"];
40
44
  export type EditingRequestKind = (typeof EDITING_REQUEST_KINDS)[number];
41
45
  export interface EditingRuntimeSnapshot {
42
46
  /** The runtime has installed its player API. */
@@ -289,6 +293,36 @@ export interface EditingRequests {
289
293
  changed: boolean;
290
294
  };
291
295
  };
296
+ "gsap-snapshot": {
297
+ params: NoParams;
298
+ result: GsapSnapshot;
299
+ };
300
+ "motion-path-home": {
301
+ params: {
302
+ selector: string;
303
+ };
304
+ result: MotionPathFrameHome;
305
+ };
306
+ "max-z-index": {
307
+ params: NoParams;
308
+ result: {
309
+ zIndex: number;
310
+ };
311
+ };
312
+ "crop-lift": {
313
+ params: {
314
+ handle: EditingElementHandle;
315
+ lift: boolean;
316
+ };
317
+ result: {
318
+ lifted: boolean;
319
+ clipPath: string | null;
320
+ };
321
+ };
322
+ "edit-element": {
323
+ params: EditElementParams;
324
+ result: EditElementResult;
325
+ };
292
326
  }
293
327
  export type EditingParams<K extends EditingRequestKind> = EditingRequests[K]["params"];
294
328
  export type EditingResult<K extends EditingRequestKind> = EditingRequests[K]["result"];
@@ -347,3 +381,4 @@ export declare function createEditingPortClient(options: {
347
381
  timeoutMs?: number;
348
382
  host?: Window;
349
383
  }): EditingPortClient;
384
+ export { elementHome, transformWDivisor, type MotionPathHome } from "./editing/motionPathHome.js";
@@ -22,9 +22,11 @@ import { parseColorGradingPlaybackParams, } from "./editing/color-grading-playba
22
22
  import { parseAssignAudioGroup } from "./editing/assignAudioGroup.js";
23
23
  import { parseAudioMeter } from "./editing/audioMeter.js";
24
24
  import { parseSetAudioGroupAttribute, } from "./editing/setAudioGroupAttribute.js";
25
+ import { parseEditElement, } from "./editing/editElement.js";
25
26
  export { buildStableSelector, escapeCssString, getPreferredClassSelector, readElementSource, EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, } from "./editingElement.js";
26
27
  export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, } from "./editingGeometry.js";
27
28
  export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
29
+ export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./editing/gsapSnapshotLimits.js";
28
30
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, } from "./editingTargets.js";
29
31
  export { elementZIndex, hasOnlyFormattingChildren, isCompositionHost, layerKindOf, } from "./editingLayers.js";
30
32
  export { composeElementTransform, individualRotateDegrees, } from "./elementTransform.js";
@@ -61,6 +63,11 @@ export const EDITING_REQUEST_KINDS = [
61
63
  "document-markup",
62
64
  "set-audio-group-attribute",
63
65
  "assign-audio-group",
66
+ "gsap-snapshot",
67
+ "motion-path-home",
68
+ "max-z-index",
69
+ "crop-lift",
70
+ "edit-element",
64
71
  ];
65
72
  export const MAX_DRAFT_PX = 100_000;
66
73
  export const MAX_WATCHED_KEYS = 32;
@@ -224,6 +231,15 @@ const PARAM_PARSERS = {
224
231
  "document-markup": noParams,
225
232
  "set-audio-group-attribute": parseSetAudioGroupAttribute,
226
233
  "assign-audio-group": parseAssignAudioGroup,
234
+ "gsap-snapshot": noParams,
235
+ "motion-path-home": (params) => hasKeys(params, "selector") && isSelector(params.selector)
236
+ ? { selector: params.selector }
237
+ : null,
238
+ "max-z-index": noParams,
239
+ "crop-lift": (params) => hasKeys(params, "handle,lift") && isHandle(params.handle) && typeof params.lift === "boolean"
240
+ ? { handle: params.handle, lift: params.lift }
241
+ : null,
242
+ "edit-element": parseEditElement,
227
243
  };
228
244
  /** Validates one request off the wire. Never throws: anything unusable becomes a typed error. */
229
245
  export function parseEditingRequest(data) {
@@ -277,6 +293,7 @@ function readHandoff(event, frame) {
277
293
  : null;
278
294
  }
279
295
  const onlyPort = (ports) => ports.length === 1 ? (ports[0] ?? null) : null;
296
+ const portsTaken = new WeakSet();
280
297
  /**
281
298
  * The parent's end of the editing channel for one preview frame load. Asks for
282
299
  * the port at once and again on the runtime's `ready`, and takes the first port
@@ -337,8 +354,9 @@ export function createEditingPortClient(options) {
337
354
  const handoff = readHandoff(event, iframe.contentWindow);
338
355
  if (handoff === "ready")
339
356
  return connect();
340
- if (!handoff)
357
+ if (!handoff || portsTaken.has(handoff))
341
358
  return;
359
+ portsTaken.add(handoff);
342
360
  port = handoff;
343
361
  host.removeEventListener("message", onWindowMessage);
344
362
  port.onmessage = onReply;
@@ -400,3 +418,4 @@ export function createEditingPortClient(options) {
400
418
  },
401
419
  };
402
420
  }
421
+ export { elementHome, transformWDivisor } from "./editing/motionPathHome.js";