@hyperframes/core 0.9.91 → 0.9.93
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/audioAnalysis.d.ts +3 -0
- package/dist/audioAnalysis.js +18 -1
- package/dist/audioCarve.js +15 -24
- package/dist/audioDecode.d.ts +22 -0
- package/dist/audioDecode.js +64 -0
- package/dist/audioLeveller.js +3 -17
- package/dist/beats/beatDetection.js +2 -3
- package/dist/clipFacts.d.ts +5 -0
- package/dist/clipFacts.js +21 -6
- package/dist/compositionSource.d.ts +2 -0
- package/dist/compositionSource.js +5 -0
- package/dist/generated/runtime-inline.js +1 -1
- package/dist/hyperframe.runtime.iife.js +69 -69
- package/dist/runtime/editing/gsapSet.d.ts +3 -1
- package/dist/runtime/editing/gsapSet.js +4 -2
- package/dist/runtime/editing/gsapSnapshot.d.ts +1 -0
- package/dist/runtime/editing/gsapSnapshot.js +20 -3
- package/dist/runtime/editing/textEdit.d.ts +23 -0
- package/dist/runtime/editing/textEdit.js +88 -3
- package/dist/runtime/editingElement.js +8 -7
- package/dist/runtime/editingGestureStart.d.ts +3 -0
- package/dist/runtime/editingGestureStart.js +46 -3
- package/dist/runtime/editingPort.d.ts +26 -4
- package/dist/runtime/editingPort.js +29 -3
- package/dist/runtime/positionEdits.js +2 -2
- package/dist/safePath.d.ts +5 -1
- package/dist/safePath.js +38 -4
- package/dist/studioPreviewMark.d.ts +1 -0
- package/dist/studioPreviewMark.js +1 -0
- package/dist/utils/htmlAttrSafety.js +7 -1
- package/dist/utils/inlineTextStyleRange.d.ts +33 -0
- package/dist/utils/inlineTextStyleRange.js +503 -0
- package/dist/utils/inlineTextStyleRead.d.ts +20 -0
- package/dist/utils/inlineTextStyleRead.js +72 -0
- package/dist/utils/richTextSanitize.js +16 -2
- package/package.json +12 -4
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type EditingElementHandle } from "../editingElement.js";
|
|
2
|
+
import type { EditingDraft } from "../editingPort.js";
|
|
2
3
|
export type GsapSetParams = {
|
|
3
4
|
handle: EditingElementHandle;
|
|
4
5
|
props: Record<string, number>;
|
|
6
|
+
drafts?: EditingDraft[];
|
|
5
7
|
};
|
|
6
8
|
export declare function parseGsapSet(params: unknown): GsapSetParams | null;
|
|
7
|
-
export declare function gsapSet({ handle, props }: GsapSetParams): {
|
|
9
|
+
export declare function gsapSet({ handle, props, drafts }: GsapSetParams): {
|
|
8
10
|
applied: boolean;
|
|
9
11
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Studio's live value preview (a 3D-transform slider mid-drag) in a frame it cannot script.
|
|
2
|
+
import { drawDrafts, rebaseDrawnPosition } from "../editingDraft.js";
|
|
2
3
|
import { EDITING_ELEMENT_HANDLE } from "../editingElement.js";
|
|
3
4
|
import { elementForHandle } from "../editingHandles.js";
|
|
4
|
-
import { rebaseDrawnPosition } from "../editingDraft.js";
|
|
5
5
|
const GSAP_SET_CHANNELS = new Set([
|
|
6
6
|
"x",
|
|
7
7
|
"y",
|
|
@@ -29,7 +29,9 @@ export function parseGsapSet(params) {
|
|
|
29
29
|
const valid = entries.every(([channel, value]) => GSAP_SET_CHANNELS.has(channel) && typeof value === "number" && Number.isFinite(value));
|
|
30
30
|
return valid && entries.length > 0 ? { handle, props: props } : null;
|
|
31
31
|
}
|
|
32
|
-
export function gsapSet({ handle, props }) {
|
|
32
|
+
export function gsapSet({ handle, props, drafts }) {
|
|
33
|
+
if (drafts)
|
|
34
|
+
drawDrafts(drafts);
|
|
33
35
|
const element = elementForHandle(handle);
|
|
34
36
|
const gsap = window.gsap;
|
|
35
37
|
if (!element || typeof gsap?.set !== "function")
|
|
@@ -37,6 +37,7 @@ export interface GsapSnapshot {
|
|
|
37
37
|
time: number | null;
|
|
38
38
|
defaultEase: string | null;
|
|
39
39
|
timelines: GsapSnapshotTimeline[];
|
|
40
|
+
globalTweens: GsapSnapshotTween[];
|
|
40
41
|
targets: GsapSnapshotTarget[];
|
|
41
42
|
}
|
|
42
43
|
/** Every tween on the frame's timelines, after any seek in flight has painted. Throws past a bound. */
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { handleFor } from "../editingHandles.js";
|
|
2
|
+
import { MOVES, rendersTransform, withoutGsapTakeover } from "../editingGestureStart.js";
|
|
2
3
|
import { isPlainRecord } from "../editingPort.js";
|
|
3
4
|
import { isElementNode } from "../domRealm.js";
|
|
4
5
|
import { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./gsapSnapshotLimits.js";
|
|
@@ -32,10 +33,13 @@ export async function gsapSnapshot() {
|
|
|
32
33
|
const gsap = frame.gsap;
|
|
33
34
|
const reader = new SnapshotReader();
|
|
34
35
|
const timelines = [];
|
|
36
|
+
const held = new Set();
|
|
35
37
|
for (const [id, live] of Object.entries(frame.__timelines ?? {})) {
|
|
36
38
|
if (typeof live?.getChildren !== "function")
|
|
37
39
|
continue;
|
|
38
40
|
const tweens = live.getChildren(true).filter((child) => typeof child.targets === "function");
|
|
41
|
+
for (const tween of tweens)
|
|
42
|
+
held.add(tween);
|
|
39
43
|
if (timelines.length >= MAX_SNAPSHOT_TWEENS)
|
|
40
44
|
throw new SnapshotBound("timelines");
|
|
41
45
|
timelines.push({
|
|
@@ -45,11 +49,15 @@ export async function gsapSnapshot() {
|
|
|
45
49
|
tweens: tweens.map((tween) => reader.tween(tween)),
|
|
46
50
|
});
|
|
47
51
|
}
|
|
52
|
+
const globalTweens = (gsap?.globalTimeline?.getChildren?.(true, true, false) ?? [])
|
|
53
|
+
.filter((child) => typeof child.targets === "function" && !held.has(child))
|
|
54
|
+
.map((tween) => reader.tween(tween));
|
|
48
55
|
const time = frame.__player?.getTime?.();
|
|
49
56
|
return {
|
|
50
57
|
time: typeof time === "number" && Number.isFinite(time) ? time : null,
|
|
51
58
|
defaultEase: text(gsap?.defaults?.().ease),
|
|
52
59
|
timelines,
|
|
60
|
+
globalTweens,
|
|
53
61
|
targets: reader.targets(gsap),
|
|
54
62
|
};
|
|
55
63
|
}
|
|
@@ -76,11 +84,20 @@ class SnapshotReader {
|
|
|
76
84
|
if (channels.size > MAX_SNAPSHOT_CHANNELS)
|
|
77
85
|
throw new SnapshotBound("channels");
|
|
78
86
|
const values = {};
|
|
79
|
-
|
|
87
|
+
const read = (channel) => {
|
|
80
88
|
const value = Number(gsap?.getProperty?.(element, channel));
|
|
81
89
|
if (Number.isFinite(value))
|
|
82
90
|
values[channel] = value;
|
|
83
|
-
}
|
|
91
|
+
};
|
|
92
|
+
const gsapOwnsPosition = rendersTransform(element) || MOVES.some((channel) => channels.has(channel));
|
|
93
|
+
withoutGsapTakeover(element, () => {
|
|
94
|
+
for (const channel of channels)
|
|
95
|
+
read(channel);
|
|
96
|
+
if (gsapOwnsPosition)
|
|
97
|
+
for (const axis of ["x", "y"])
|
|
98
|
+
if (!(axis in values))
|
|
99
|
+
read(axis);
|
|
100
|
+
});
|
|
84
101
|
const className = element.getAttribute("class") ?? "";
|
|
85
102
|
if (className.length > MAX_SNAPSHOT_TEXT)
|
|
86
103
|
throw new SnapshotBound("class names");
|
|
@@ -88,7 +105,7 @@ class SnapshotReader {
|
|
|
88
105
|
});
|
|
89
106
|
}
|
|
90
107
|
note(element, vars, parsed, parts) {
|
|
91
|
-
const channels = this.channels.get(element) ?? new Set(
|
|
108
|
+
const channels = this.channels.get(element) ?? new Set();
|
|
92
109
|
this.channels.set(element, channels);
|
|
93
110
|
const steps = isPlainRecord(vars) ? [vars, ...stepsOf(vars.keyframes)] : [];
|
|
94
111
|
for (const step of steps)
|
|
@@ -3,6 +3,7 @@ type Point = {
|
|
|
3
3
|
x: number;
|
|
4
4
|
y: number;
|
|
5
5
|
};
|
|
6
|
+
type Style = Record<string, string | null>;
|
|
6
7
|
export type TextEditParams = {
|
|
7
8
|
handle: EditingElementHandle;
|
|
8
9
|
action: "start";
|
|
@@ -11,6 +12,10 @@ export type TextEditParams = {
|
|
|
11
12
|
handle: EditingElementHandle;
|
|
12
13
|
action: "end";
|
|
13
14
|
keep: boolean;
|
|
15
|
+
} | {
|
|
16
|
+
handle: EditingElementHandle;
|
|
17
|
+
action: "style";
|
|
18
|
+
style: Style;
|
|
14
19
|
};
|
|
15
20
|
export type TextEditResult = {
|
|
16
21
|
applied: boolean;
|
|
@@ -23,7 +28,25 @@ export type TextEditEndedEvent = {
|
|
|
23
28
|
html: string | null;
|
|
24
29
|
previous: string;
|
|
25
30
|
};
|
|
31
|
+
/** The selection in an open session, posted on its port as it changes; null when nothing is selected in it. */
|
|
32
|
+
export type TextEditSelection = {
|
|
33
|
+
rect: {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
};
|
|
39
|
+
viewportWidth: number;
|
|
40
|
+
styles: Record<string, string>;
|
|
41
|
+
colours: string[];
|
|
42
|
+
painted: string | null;
|
|
43
|
+
};
|
|
44
|
+
export type TextEditSelectionEvent = {
|
|
45
|
+
handle: EditingElementHandle;
|
|
46
|
+
selection: TextEditSelection | null;
|
|
47
|
+
};
|
|
26
48
|
export declare function parseTextEdit(params: unknown): TextEditParams | null;
|
|
49
|
+
export declare function textEditSelectionEvent(data: unknown, version: number): TextEditSelectionEvent | null;
|
|
27
50
|
export declare function textEditEndedEvent(data: unknown, version: number): TextEditEndedEvent | null;
|
|
28
51
|
export declare function textEditResult(reply: unknown): TextEditResult | null;
|
|
29
52
|
/** Ends an open session with its original markup back; the agent's dispose and a page hide call it. */
|
|
@@ -6,7 +6,16 @@ import { isStylableElement } from "../domRealm.js";
|
|
|
6
6
|
import { sanitizeRichTextChildren } from "../../utils/richTextSanitize.js";
|
|
7
7
|
import { openTextEdits, isTextMarkup, MAX_EDIT_VALUE } from "./editElement.js";
|
|
8
8
|
import { isEditableText } from "./textMarkup.js";
|
|
9
|
+
import { applyInlineStyle, INLINE_STYLE_PROPERTIES, readFirstPaintedElement, readInlineStyle, readInlineStyleSpread, } from "../../utils/inlineTextStyleRead.js";
|
|
9
10
|
const EDITING_OUTLINE = "2px solid #3CE6AC";
|
|
11
|
+
const MAX_STYLE_VALUE = 256;
|
|
12
|
+
const MAX_COLOURS = 16;
|
|
13
|
+
const STYLE_VALUES = {
|
|
14
|
+
color: (value) => value.length <= MAX_STYLE_VALUE,
|
|
15
|
+
"font-weight": (value) => value === "700",
|
|
16
|
+
"font-style": (value) => value === "italic",
|
|
17
|
+
"text-decoration-line": (value) => value === "underline",
|
|
18
|
+
};
|
|
10
19
|
const isRecord = (value) => Object.prototype.toString.call(value) === "[object Object]";
|
|
11
20
|
const keysAre = (value, keys) => Object.keys(value).sort().join() === keys;
|
|
12
21
|
const isHandle = (value) => typeof value === "string" && EDITING_ELEMENT_HANDLE.test(value);
|
|
@@ -21,8 +30,41 @@ export function parseTextEdit(params) {
|
|
|
21
30
|
}
|
|
22
31
|
if (action === "end" && keysAre(params, "action,handle,keep") && typeof params.keep === "boolean")
|
|
23
32
|
return { handle, action, keep: params.keep };
|
|
33
|
+
if (action === "style" && keysAre(params, "action,handle,style") && isStyle(params.style))
|
|
34
|
+
return { handle, action, style: params.style };
|
|
24
35
|
return null;
|
|
25
36
|
}
|
|
37
|
+
const isStyle = (value) => isRecord(value) &&
|
|
38
|
+
Object.keys(value).length > 0 &&
|
|
39
|
+
Object.entries(value).every(([key, set]) => Object.hasOwn(STYLE_VALUES, key) &&
|
|
40
|
+
(set === null || (typeof set === "string" && STYLE_VALUES[key](set))));
|
|
41
|
+
const isShortText = (value) => typeof value === "string" && value.length <= MAX_STYLE_VALUE;
|
|
42
|
+
const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
|
|
43
|
+
const isRect = (value) => isRecord(value) &&
|
|
44
|
+
keysAre(value, "height,width,x,y") &&
|
|
45
|
+
Object.values(value).every(isFiniteNumber);
|
|
46
|
+
const isShownStyles = (value) => isRecord(value) &&
|
|
47
|
+
Object.entries(value).every(([key, set]) => Object.hasOwn(STYLE_VALUES, key) && isShortText(set));
|
|
48
|
+
const isColours = (value) => Array.isArray(value) && value.length <= MAX_COLOURS && value.every(isShortText);
|
|
49
|
+
function isSelection(value) {
|
|
50
|
+
if (!isRecord(value) || !keysAre(value, "colours,painted,rect,styles,viewportWidth"))
|
|
51
|
+
return false;
|
|
52
|
+
const { rect, viewportWidth, styles, colours, painted } = value;
|
|
53
|
+
const shown = isFiniteNumber(viewportWidth) && viewportWidth > 0;
|
|
54
|
+
return (shown &&
|
|
55
|
+
isRect(rect) &&
|
|
56
|
+
isShownStyles(styles) &&
|
|
57
|
+
isColours(colours) &&
|
|
58
|
+
(painted === null || isShortText(painted)));
|
|
59
|
+
}
|
|
60
|
+
export function textEditSelectionEvent(data, version) {
|
|
61
|
+
if (!isRecord(data) || !keysAre(data, "event,handle,selection,v"))
|
|
62
|
+
return null;
|
|
63
|
+
if (data.v !== version || data.event !== "text-edit-selection" || !isHandle(data.handle))
|
|
64
|
+
return null;
|
|
65
|
+
const { handle, selection } = data;
|
|
66
|
+
return selection === null || isSelection(selection) ? { handle, selection } : null;
|
|
67
|
+
}
|
|
26
68
|
const isValue = (value) => value === null || (typeof value === "string" && value.length <= MAX_EDIT_VALUE);
|
|
27
69
|
const isTextMarkupOrNull = (value) => value === null || (typeof value === "string" && isTextMarkup(value));
|
|
28
70
|
export function textEditEndedEvent(data, version) {
|
|
@@ -55,6 +97,30 @@ function clearSelectionWithin(element) {
|
|
|
55
97
|
if (element.contains(range.startContainer) || element.contains(range.endContainer))
|
|
56
98
|
selection.removeAllRanges();
|
|
57
99
|
}
|
|
100
|
+
function selectedRange(element) {
|
|
101
|
+
const selection = element.ownerDocument.defaultView?.getSelection();
|
|
102
|
+
if (!selection || selection.rangeCount === 0 || selection.isCollapsed)
|
|
103
|
+
return null;
|
|
104
|
+
const range = selection.getRangeAt(0);
|
|
105
|
+
return element.contains(range.commonAncestorContainer) ? range : null;
|
|
106
|
+
}
|
|
107
|
+
const shortStyles = (styles) => Object.fromEntries(Object.entries(styles).filter(([, value]) => isShortText(value)));
|
|
108
|
+
function selectionIn(element) {
|
|
109
|
+
const range = selectedRange(element);
|
|
110
|
+
const view = element.ownerDocument.defaultView;
|
|
111
|
+
if (!range || !view)
|
|
112
|
+
return null;
|
|
113
|
+
const { left: x, top: y, width, height } = range.getBoundingClientRect();
|
|
114
|
+
const painted = readFirstPaintedElement(range, "color");
|
|
115
|
+
const paintedColour = painted ? view.getComputedStyle(painted).color : null;
|
|
116
|
+
return {
|
|
117
|
+
rect: { x, y, width, height },
|
|
118
|
+
viewportWidth: view.innerWidth || 1,
|
|
119
|
+
styles: shortStyles(readInlineStyle(range, INLINE_STYLE_PROPERTIES)),
|
|
120
|
+
colours: readInlineStyleSpread(range, "color").filter(isShortText).slice(0, MAX_COLOURS),
|
|
121
|
+
painted: isShortText(paintedColour) ? paintedColour : null,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
58
124
|
function keptMarkup(element) {
|
|
59
125
|
sanitizeRichTextChildren(element);
|
|
60
126
|
const html = element.innerHTML;
|
|
@@ -133,7 +199,7 @@ export function takePlainTextOnly(element) {
|
|
|
133
199
|
element.removeEventListener("drop", onDrop);
|
|
134
200
|
};
|
|
135
201
|
}
|
|
136
|
-
function listen(element, endInFrame) {
|
|
202
|
+
function listen(element, endInFrame, report) {
|
|
137
203
|
const onKeyDown = (event) => {
|
|
138
204
|
if ((event.key !== "Enter" || event.shiftKey) && event.key !== "Escape")
|
|
139
205
|
return;
|
|
@@ -149,8 +215,10 @@ function listen(element, endInFrame) {
|
|
|
149
215
|
const releasePlainText = takePlainTextOnly(element);
|
|
150
216
|
element.addEventListener("keydown", onKeyDown);
|
|
151
217
|
element.addEventListener("blur", endInFrame);
|
|
218
|
+
element.ownerDocument.addEventListener("selectionchange", report);
|
|
152
219
|
view?.addEventListener("pagehide", endTextEdit);
|
|
153
220
|
return () => {
|
|
221
|
+
element.ownerDocument.removeEventListener("selectionchange", report);
|
|
154
222
|
releasePlainText();
|
|
155
223
|
element.removeEventListener("keydown", onKeyDown);
|
|
156
224
|
element.removeEventListener("blur", endInFrame);
|
|
@@ -172,14 +240,21 @@ function start(handle, caret, port, version) {
|
|
|
172
240
|
outline: editable.style.outline,
|
|
173
241
|
outlineOffset: editable.style.outlineOffset,
|
|
174
242
|
stop: () => { },
|
|
243
|
+
report: () => {
|
|
244
|
+
if (session !== open)
|
|
245
|
+
return;
|
|
246
|
+
const selection = selectionIn(editable);
|
|
247
|
+
port.postMessage({ v: version, event: "text-edit-selection", handle, selection });
|
|
248
|
+
},
|
|
175
249
|
};
|
|
176
|
-
|
|
250
|
+
const endInFrame = () => {
|
|
177
251
|
if (session !== open)
|
|
178
252
|
return;
|
|
179
253
|
const ended = close(true);
|
|
180
254
|
if (ended)
|
|
181
255
|
port.postMessage({ v: version, event: "text-edit-ended", handle, ...ended });
|
|
182
|
-
}
|
|
256
|
+
};
|
|
257
|
+
open.stop = listen(editable, endInFrame, open.report);
|
|
183
258
|
session = open;
|
|
184
259
|
openTextEdits.add(editable);
|
|
185
260
|
editable.style.outline = EDITING_OUTLINE;
|
|
@@ -194,6 +269,16 @@ export function textEdit(params, port, version) {
|
|
|
194
269
|
return start(params.handle, params.caret, port, version);
|
|
195
270
|
if (session?.handle !== params.handle || session.port !== port)
|
|
196
271
|
return NOTHING;
|
|
272
|
+
if (params.action === "style")
|
|
273
|
+
return styleSelection(session, params.style);
|
|
197
274
|
const ended = close(params.keep);
|
|
198
275
|
return ended ? { applied: true, ...ended } : NOTHING;
|
|
199
276
|
}
|
|
277
|
+
function styleSelection(open, style) {
|
|
278
|
+
const range = selectedRange(open.element);
|
|
279
|
+
if (!range)
|
|
280
|
+
return NOTHING;
|
|
281
|
+
applyInlineStyle(range, style);
|
|
282
|
+
open.report();
|
|
283
|
+
return { applied: true, html: null, previous: null };
|
|
284
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// How an element is addressed in source: one rule for Studio and the runtime's editing agent.
|
|
2
|
+
import { COMPOSITION_ROOT_ATTRS, SOURCE_HOST_ATTRS } from "../compositionSource.js";
|
|
2
3
|
import { isHtmlElement } from "./domRealm.js";
|
|
3
4
|
export const EDITING_ELEMENT_HANDLE = /^[0-9a-f]{16}:[1-9][0-9]{0,14}$/;
|
|
4
5
|
export const MAX_ELEMENT_ENTRIES = 256;
|
|
@@ -118,13 +119,13 @@ function closestWithAny(el, names) {
|
|
|
118
119
|
return null;
|
|
119
120
|
}
|
|
120
121
|
export function readElementSource(el) {
|
|
121
|
-
const
|
|
122
|
-
const
|
|
122
|
+
const [fileAttr, srcAttr] = SOURCE_HOST_ATTRS;
|
|
123
|
+
const [idAttr, originalIdAttr] = COMPOSITION_ROOT_ATTRS;
|
|
124
|
+
const host = closestWithAny(el, SOURCE_HOST_ATTRS);
|
|
125
|
+
const root = closestWithAny(el, [idAttr]);
|
|
123
126
|
return {
|
|
124
|
-
file: host?.getAttribute(
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
compositionId: root?.getAttribute("data-composition-id") ?? null,
|
|
128
|
-
originalCompositionId: root?.getAttribute("data-hf-original-composition-id") ?? null,
|
|
127
|
+
file: host?.getAttribute(fileAttr) ?? host?.getAttribute(srcAttr) ?? null,
|
|
128
|
+
compositionId: root?.getAttribute(idAttr) ?? null,
|
|
129
|
+
originalCompositionId: root?.getAttribute(originalIdAttr) ?? null,
|
|
129
130
|
};
|
|
130
131
|
}
|
|
@@ -33,6 +33,9 @@ export interface EditingGestureStart extends EditingElementGeometry {
|
|
|
33
33
|
d: number;
|
|
34
34
|
} | null;
|
|
35
35
|
}
|
|
36
|
+
export declare const MOVES: string[];
|
|
37
|
+
export declare const rendersTransform: (element: Element) => boolean;
|
|
38
|
+
export declare function withoutGsapTakeover<T>(element: Element, read: () => T): T;
|
|
36
39
|
export type EditingGestureBase = {
|
|
37
40
|
x: number;
|
|
38
41
|
y: number;
|
|
@@ -86,7 +86,7 @@ function measureGrowResponse(element, layout) {
|
|
|
86
86
|
}
|
|
87
87
|
// The channels Studio's move route and drag commit read as GSAP moving an element.
|
|
88
88
|
const POSITION = ["x", "y", "xPercent", "yPercent", "left", "top", "translateX", "translateY"];
|
|
89
|
-
const MOVES = [...POSITION, "motionPath"];
|
|
89
|
+
export const MOVES = [...POSITION, "motionPath"];
|
|
90
90
|
const TURNS = [
|
|
91
91
|
"rotation",
|
|
92
92
|
"rotationX",
|
|
@@ -112,7 +112,48 @@ function tweensOn(element) {
|
|
|
112
112
|
const timelines = Object.values(window.__timelines ?? {});
|
|
113
113
|
return timelines.flatMap((timeline) => (timeline?.getChildren?.(true) ?? []).filter((tween) => (tween.targets?.() ?? []).some((target) => target === element || (!!element.id && target?.id === element.id))));
|
|
114
114
|
}
|
|
115
|
-
const rendersTransform = (element) => !!element._gsap?.renderTransform;
|
|
115
|
+
export const rendersTransform = (element) => !!element._gsap?.renderTransform;
|
|
116
|
+
const isPlainFields = (value) => !!value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
|
|
117
|
+
function keptFields(fields, depth = 1) {
|
|
118
|
+
const values = { ...fields };
|
|
119
|
+
const nested = depth > 0 ? Object.values(fields).filter(isPlainFields) : [];
|
|
120
|
+
const inner = nested.map((value) => keptFields(value, depth - 1));
|
|
121
|
+
return () => {
|
|
122
|
+
for (const key of Object.keys(fields))
|
|
123
|
+
if (!(key in values))
|
|
124
|
+
Reflect.deleteProperty(fields, key);
|
|
125
|
+
Object.assign(fields, values);
|
|
126
|
+
for (const restore of inner)
|
|
127
|
+
restore();
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function keptAttributes(element) {
|
|
131
|
+
const names = element.getAttributeNames();
|
|
132
|
+
const attributes = new Map(names.map((name) => [name, element.getAttribute(name) ?? ""]));
|
|
133
|
+
return () => {
|
|
134
|
+
for (const name of element.getAttributeNames())
|
|
135
|
+
if (!attributes.has(name))
|
|
136
|
+
element.removeAttribute(name);
|
|
137
|
+
for (const [name, value] of attributes)
|
|
138
|
+
if (element.getAttribute(name) !== value)
|
|
139
|
+
element.setAttribute(name, value);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
export function withoutGsapTakeover(element, read) {
|
|
143
|
+
if (rendersTransform(element))
|
|
144
|
+
return read();
|
|
145
|
+
const host = element;
|
|
146
|
+
const cache = host._gsap;
|
|
147
|
+
const restoreCache = cache ? keptFields(cache) : () => Reflect.deleteProperty(host, "_gsap");
|
|
148
|
+
const restoreAttributes = keptAttributes(element);
|
|
149
|
+
try {
|
|
150
|
+
return read();
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
restoreAttributes();
|
|
154
|
+
restoreCache();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
116
157
|
export function gestureBase(handle) {
|
|
117
158
|
const element = elementForHandle(handle);
|
|
118
159
|
const gsap = window.gsap;
|
|
@@ -136,7 +177,9 @@ function gsapPosition(element) {
|
|
|
136
177
|
}
|
|
137
178
|
function gsapRotation(element) {
|
|
138
179
|
const turned = tweensOn(element).some((tween) => tween.vars && carries(tween.vars, TURNS));
|
|
139
|
-
|
|
180
|
+
if (!rendersTransform(element) && !turned)
|
|
181
|
+
return null;
|
|
182
|
+
return withoutGsapTakeover(element, () => readGsap(element, "rotation"));
|
|
140
183
|
}
|
|
141
184
|
function planarOf(element) {
|
|
142
185
|
const matrix = readElementTransformSnapshot(window, element)?.matrix;
|
|
@@ -33,7 +33,7 @@ import { type AssignAudioGroupParams } from "./editing/assignAudioGroup.js";
|
|
|
33
33
|
import { type AudioMeterLevels } from "./editing/audioMeter.js";
|
|
34
34
|
import { type SetAudioGroupAttributeParams } from "./editing/setAudioGroupAttribute.js";
|
|
35
35
|
import { type EditElementParams, type EditElementResult } from "./editing/editElement.js";
|
|
36
|
-
import { type TextEditEndedEvent, type TextEditParams, type TextEditResult } from "./editing/textEdit.js";
|
|
36
|
+
import { type TextEditEndedEvent, type TextEditSelectionEvent, type TextEditParams, type TextEditResult } from "./editing/textEdit.js";
|
|
37
37
|
export { buildStableSelector, escapeCssString, getPreferredClassSelector, isEditableTextLeaf, readElementSource, readTextLayer, EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_TIMELINE_TEXT, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch, type EditingElementSource, type EditingRect, type TextLayerRead, } from "./editingElement.js";
|
|
38
38
|
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";
|
|
39
39
|
export type { EditingGestureBase, EditingGestureStart } from "./editingGestureStart.js";
|
|
@@ -46,7 +46,7 @@ export declare const EDITING_PROTOCOL_VERSION: 1;
|
|
|
46
46
|
export declare const EDITING_CONNECT = "editing-connect";
|
|
47
47
|
/** Frame to parent, on the window: carries the port in its transfer list. */
|
|
48
48
|
export declare const EDITING_PORT = "editing-port";
|
|
49
|
-
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", "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", "stacking-family", "gsap-set", "patch-tweens", "soft-reload", "hold-scenes", "mark-scenes-stale", "swap-scenes", "live-retime", "assets-unloaded", "text-edit", "serve-paused-frames"];
|
|
49
|
+
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", "stacking-family", "gsap-set", "patch-tweens", "soft-reload", "hold-scenes", "mark-scenes-stale", "swap-scenes", "live-retime", "assets-unloaded", "text-edit", "serve-paused-frames"];
|
|
50
50
|
export type EditingRequestKind = (typeof EDITING_REQUEST_KINDS)[number];
|
|
51
51
|
export interface EditingRuntimeSnapshot {
|
|
52
52
|
/** The runtime has installed its player API. */
|
|
@@ -150,6 +150,25 @@ export interface EditingRequests {
|
|
|
150
150
|
styles: Record<string, string> | null;
|
|
151
151
|
};
|
|
152
152
|
};
|
|
153
|
+
"authored-styles": {
|
|
154
|
+
params: {
|
|
155
|
+
handle: EditingElementHandle;
|
|
156
|
+
properties: string[];
|
|
157
|
+
};
|
|
158
|
+
result: {
|
|
159
|
+
styles: Record<string, string> | null;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
"font-faces": {
|
|
163
|
+
params: NoParams;
|
|
164
|
+
result: {
|
|
165
|
+
families: string[];
|
|
166
|
+
ownFaces: Array<{
|
|
167
|
+
family: string;
|
|
168
|
+
src: string;
|
|
169
|
+
}>;
|
|
170
|
+
};
|
|
171
|
+
};
|
|
153
172
|
/** The stack under a viewport point, topmost first, up to MAX_POINT_STACK. Describe one to keep. */
|
|
154
173
|
"elements-at-point": {
|
|
155
174
|
params: {
|
|
@@ -228,7 +247,9 @@ export interface EditingRequests {
|
|
|
228
247
|
params: {
|
|
229
248
|
drafts: EditingDraft[];
|
|
230
249
|
};
|
|
231
|
-
result: EditingDraftReply
|
|
250
|
+
result: EditingDraftReply & {
|
|
251
|
+
gsapSetTakesDrafts?: true;
|
|
252
|
+
};
|
|
232
253
|
};
|
|
233
254
|
"gesture-start": {
|
|
234
255
|
params: {
|
|
@@ -469,6 +490,7 @@ export interface EditingPortClient {
|
|
|
469
490
|
onKey(listener: (key: EditingKeyEvent) => void): () => void;
|
|
470
491
|
onGeometry(listener: (event: EditingGeometryEvent) => void): () => void;
|
|
471
492
|
onTextEditEnded(listener: (event: TextEditEndedEvent) => void): () => void;
|
|
493
|
+
onTextEditSelection(listener: (event: TextEditSelectionEvent) => void): () => void;
|
|
472
494
|
/** Rejects every pending request with `disposed` and closes the port. */
|
|
473
495
|
dispose(): void;
|
|
474
496
|
}
|
|
@@ -483,5 +505,5 @@ export declare function createEditingPortClient(options: {
|
|
|
483
505
|
host?: Window;
|
|
484
506
|
}): EditingPortClient;
|
|
485
507
|
export { elementHome, transformWDivisor, type MotionPathHome } from "./editing/motionPathHome.js";
|
|
486
|
-
export { caretRangeAt, takePlainTextOnly, textEditResult, type TextEditEndedEvent, type TextEditResult, } from "./editing/textEdit.js";
|
|
508
|
+
export { caretRangeAt, takePlainTextOnly, textEditResult, type TextEditEndedEvent, type TextEditResult, type TextEditSelection, type TextEditSelectionEvent, } from "./editing/textEdit.js";
|
|
487
509
|
export { parsePausedFrameAsk, PAUSED_FRAME_BYTES, PAUSED_FRAME_PARAMS, PAUSED_FRAME_SOURCES, type PausedFrameAsk, type PausedFrameAskMessage, type PausedFrameImage, type PausedFrameReply, } from "./editing/pausedFrames.js";
|
|
@@ -17,7 +17,7 @@ import { parseAssignAudioGroup } from "./editing/assignAudioGroup.js";
|
|
|
17
17
|
import { parseAudioMeter } from "./editing/audioMeter.js";
|
|
18
18
|
import { parseSetAudioGroupAttribute, } from "./editing/setAudioGroupAttribute.js";
|
|
19
19
|
import { parseEditElement, } from "./editing/editElement.js";
|
|
20
|
-
import { parseTextEdit, textEditEndedEvent, } from "./editing/textEdit.js";
|
|
20
|
+
import { parseTextEdit, textEditEndedEvent, textEditSelectionEvent, } from "./editing/textEdit.js";
|
|
21
21
|
export { buildStableSelector, escapeCssString, getPreferredClassSelector, isEditableTextLeaf, readElementSource, readTextLayer, EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_TEXT, MAX_ELEMENT_VALUE, MAX_TIMELINE_TEXT, MAX_POINT_STACK, MAX_QUERY_MATCHES, MAX_SOURCE_GROUPS, } from "./editingElement.js";
|
|
22
22
|
export { elementCornerPoints, isElementVisibleThroughAncestors, readElementTransformSnapshot, rotationDegreesFromMatrix, snapCandidates, MAX_GEOMETRY_CHILDREN, MAX_SNAP_TARGETS, ROTATION_GATE_EPSILON_DEG, } from "./editingGeometry.js";
|
|
23
23
|
export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
|
|
@@ -35,6 +35,8 @@ export const EDITING_REQUEST_KINDS = [
|
|
|
35
35
|
"wait-for-seek",
|
|
36
36
|
"set-loop-start",
|
|
37
37
|
"computed-styles",
|
|
38
|
+
"authored-styles",
|
|
39
|
+
"font-faces",
|
|
38
40
|
"elements-at-point",
|
|
39
41
|
"pointer-targets",
|
|
40
42
|
"describe",
|
|
@@ -214,6 +216,14 @@ function draftPropsWithOneXYWriter(value, translate) {
|
|
|
214
216
|
return false;
|
|
215
217
|
return entries.every(isDraftValue);
|
|
216
218
|
}
|
|
219
|
+
function gsapSetWithDrafts(params) {
|
|
220
|
+
if (!isPlainRecord(params) || !("drafts" in params))
|
|
221
|
+
return parseGsapSet(params);
|
|
222
|
+
const { drafts, ...set } = params;
|
|
223
|
+
const parsed = parseGsapSet(set);
|
|
224
|
+
const drawn = draftList({ drafts });
|
|
225
|
+
return parsed && drawn ? { ...parsed, drafts: drawn.drafts } : null;
|
|
226
|
+
}
|
|
217
227
|
function draftList(params) {
|
|
218
228
|
if (!hasKeys(params, "drafts") || !Array.isArray(params.drafts))
|
|
219
229
|
return null;
|
|
@@ -269,6 +279,13 @@ const PARAM_PARSERS = {
|
|
|
269
279
|
const properties = styleProperties(params.properties);
|
|
270
280
|
return target && properties ? { ...target, properties } : null;
|
|
271
281
|
},
|
|
282
|
+
"authored-styles": (params) => {
|
|
283
|
+
if (!hasKeys(params, "handle,properties") || !isHandle(params.handle))
|
|
284
|
+
return null;
|
|
285
|
+
const properties = styleProperties(params.properties);
|
|
286
|
+
return properties?.length ? { handle: params.handle, properties } : null;
|
|
287
|
+
},
|
|
288
|
+
"font-faces": noParams,
|
|
272
289
|
"elements-at-point": point,
|
|
273
290
|
"pointer-targets": point,
|
|
274
291
|
describe: handleList,
|
|
@@ -312,7 +329,7 @@ const PARAM_PARSERS = {
|
|
|
312
329
|
: null,
|
|
313
330
|
"edit-element": parseEditElement,
|
|
314
331
|
"stacking-family": (params) => hasKeys(params, "handle") && isHandle(params.handle) ? { handle: params.handle } : null,
|
|
315
|
-
"gsap-set":
|
|
332
|
+
"gsap-set": gsapSetWithDrafts,
|
|
316
333
|
"patch-tweens": parsePatchTweensRequest,
|
|
317
334
|
"soft-reload": parseSoftReload,
|
|
318
335
|
"hold-scenes": parseHoldScenes,
|
|
@@ -389,6 +406,7 @@ export function createEditingPortClient(options) {
|
|
|
389
406
|
const keyListeners = new Set();
|
|
390
407
|
const geometryListeners = new Set();
|
|
391
408
|
const textEditListeners = new Set();
|
|
409
|
+
const selectionListeners = new Set();
|
|
392
410
|
let watchedGeometry = false;
|
|
393
411
|
let port = null;
|
|
394
412
|
let disposed = false;
|
|
@@ -420,7 +438,10 @@ export function createEditingPortClient(options) {
|
|
|
420
438
|
return geometryListeners.forEach((listener) => listener(geometry));
|
|
421
439
|
const ended = textEditEndedEvent(data, EDITING_PROTOCOL_VERSION);
|
|
422
440
|
if (ended)
|
|
423
|
-
textEditListeners.forEach((listener) => listener(ended));
|
|
441
|
+
return textEditListeners.forEach((listener) => listener(ended));
|
|
442
|
+
const selected = textEditSelectionEvent(data, EDITING_PROTOCOL_VERSION);
|
|
443
|
+
if (selected)
|
|
444
|
+
selectionListeners.forEach((listener) => listener(selected));
|
|
424
445
|
};
|
|
425
446
|
const onReply = (event) => {
|
|
426
447
|
const data = event.data;
|
|
@@ -491,6 +512,10 @@ export function createEditingPortClient(options) {
|
|
|
491
512
|
textEditListeners.add(listener);
|
|
492
513
|
return () => textEditListeners.delete(listener);
|
|
493
514
|
},
|
|
515
|
+
onTextEditSelection(listener) {
|
|
516
|
+
selectionListeners.add(listener);
|
|
517
|
+
return () => selectionListeners.delete(listener);
|
|
518
|
+
},
|
|
494
519
|
dispose() {
|
|
495
520
|
if (disposed)
|
|
496
521
|
return;
|
|
@@ -498,6 +523,7 @@ export function createEditingPortClient(options) {
|
|
|
498
523
|
keyListeners.clear();
|
|
499
524
|
geometryListeners.clear();
|
|
500
525
|
textEditListeners.clear();
|
|
526
|
+
selectionListeners.clear();
|
|
501
527
|
host.removeEventListener("message", onWindowMessage);
|
|
502
528
|
if (watchedGeometry) {
|
|
503
529
|
const stop = { kind: "watch-geometry", params: { handles: [] } };
|
|
@@ -79,8 +79,8 @@ export const composeTranslate = (original, x, y) => {
|
|
|
79
79
|
* the edit translate is written. GSAP folds a CSS `translate` it sees at an
|
|
80
80
|
* element's first parse into its cached transform (losing it per-axis on
|
|
81
81
|
* absolute tweens); once the cache exists, later tweens and positioned set()s
|
|
82
|
-
* reuse it and never read the translate again.
|
|
83
|
-
*
|
|
82
|
+
* reuse it and never read the translate again. The parse also writes the
|
|
83
|
+
* folded transform onto the element. Best-effort — absent or failing GSAP is fine.
|
|
84
84
|
*/
|
|
85
85
|
const primeGsapTransformCache = (el) => {
|
|
86
86
|
try {
|
package/dist/safePath.d.ts
CHANGED
|
@@ -62,5 +62,9 @@ export declare function realFilePath(filePath: string): string;
|
|
|
62
62
|
export type EntryKind = "file" | "folder";
|
|
63
63
|
/** A script only Node runs, whatever folder holds it. */
|
|
64
64
|
export declare function nodeOnlyScript(relPath: string): boolean;
|
|
65
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* A Node-only script, or below (at any depth, past the project too) a package.json that is not the scaffold's: a
|
|
67
|
+
* `.js`/`.mjs` file, an extensionless file, or a file Node resolves before the module of its name plus an extension
|
|
68
|
+
* beside it.
|
|
69
|
+
*/
|
|
66
70
|
export declare function nodeMayRun(projectDir: string, relPath: string, kind: EntryKind): boolean;
|