@hyperframes/core 0.9.88 → 0.9.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler/htmlDocument.d.ts +2 -2
- package/dist/compiler/htmlDocument.js +2 -42
- package/dist/compiler/htmlTokens.d.ts +7 -0
- package/dist/compiler/htmlTokens.js +43 -0
- package/dist/generated/runtime-inline.js +1 -1
- package/dist/hyperframe.runtime.iife.js +69 -69
- package/dist/previewProxyBox.d.ts +1 -0
- package/dist/runtime/editing/gsapSet.js +2 -0
- package/dist/runtime/editing/patchTween.js +2 -1
- package/dist/runtime/editing/restoreAttributes.js +30 -3
- package/dist/runtime/editingDraft.d.ts +1 -5
- package/dist/runtime/editingDraft.js +111 -3
- package/dist/runtime/editingDraftEnd.d.ts +3 -3
- package/dist/runtime/editingDraftEnd.js +2 -2
- package/dist/runtime/editingGestureStart.d.ts +2 -0
- package/dist/runtime/editingGestureStart.js +2 -2
- package/dist/runtime/editingPort.d.ts +7 -0
- package/dist/runtime/editingPort.js +39 -5
- package/dist/runtime/runtimeAttributes.d.ts +4 -0
- package/dist/runtime/runtimeAttributes.js +17 -0
- package/dist/safePath.d.ts +7 -0
- package/dist/safePath.js +72 -1
- package/dist/studioPreviewMark.d.ts +3 -0
- package/dist/studioPreviewMark.js +5 -0
- package/dist/telemetryRedaction.js +15 -1
- package/dist/utils/richTextSanitize.js +30 -40
- package/package.json +8 -4
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Studio's live value preview (a 3D-transform slider mid-drag) in a frame it cannot script.
|
|
2
2
|
import { EDITING_ELEMENT_HANDLE } from "../editingElement.js";
|
|
3
3
|
import { elementForHandle } from "../editingHandles.js";
|
|
4
|
+
import { rebaseDrawnPosition } from "../editingDraft.js";
|
|
4
5
|
const GSAP_SET_CHANNELS = new Set([
|
|
5
6
|
"x",
|
|
6
7
|
"y",
|
|
@@ -34,5 +35,6 @@ export function gsapSet({ handle, props }) {
|
|
|
34
35
|
if (!element || typeof gsap?.set !== "function")
|
|
35
36
|
return { applied: false };
|
|
36
37
|
gsap.set(element, { ...props });
|
|
38
|
+
rebaseDrawnPosition(element, props);
|
|
37
39
|
return { applied: true };
|
|
38
40
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// a sealed frame on itself through the editing port.
|
|
4
4
|
import { applyAuthoredInlineOpacity, readStampedAuthoredOpacity } from "../../colorGrading.js";
|
|
5
5
|
import { recordLiveSet, swapWaiting } from "./softReload.js";
|
|
6
|
-
import { drawDrafts } from "../editingDraft.js";
|
|
6
|
+
import { drawDrafts, rebaseDrawnPosition } from "../editingDraft.js";
|
|
7
7
|
import { markRestingScenesForRedraw } from "../sceneRest.js";
|
|
8
8
|
import { redrawGsapTimelineAt } from "../adapters/gsap.js";
|
|
9
9
|
import { parseDraftEnd } from "../editingDraftEnd.js";
|
|
@@ -101,6 +101,7 @@ export function applyGlobalSet(target, selector, props) {
|
|
|
101
101
|
if (typeof target.gsap?.set !== "function" || !el || !numeric)
|
|
102
102
|
return null;
|
|
103
103
|
target.gsap.set(el, numeric);
|
|
104
|
+
rebaseDrawnPosition(el, numeric);
|
|
104
105
|
recordLiveSet(el, numeric);
|
|
105
106
|
return el;
|
|
106
107
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// `restore-attributes`: an undo or redo that only changes identified elements' attributes, applied in place.
|
|
2
2
|
// The parent diffs the saved files and sends each changed element's full restored attribute set.
|
|
3
3
|
import { isStudioMotionMark, STUDIO_REAPPLIED_MARKS, STUDIO_SEEK_REAPPLY_STARTED, } from "../../studioReappliedMarks.js";
|
|
4
|
+
import { HF_COLOR_GRADING_ATTR, normalizeHfColorGrading, serializeHfColorGrading, } from "../../colorGrading.js";
|
|
5
|
+
import { isRuntimeAttribute } from "../runtimeAttributes.js";
|
|
4
6
|
const MAX_SCOPES = 64;
|
|
5
7
|
const MAX_ELEMENTS = 2_000;
|
|
6
8
|
const MAX_ATTRIBUTES = 256;
|
|
@@ -117,6 +119,28 @@ function scopeRoots(file) {
|
|
|
117
119
|
return [document];
|
|
118
120
|
return Array.from(document.querySelectorAll("[data-composition-file]")).filter((host) => host.getAttribute("data-composition-file") === file);
|
|
119
121
|
}
|
|
122
|
+
function gradeRebuiltWithoutNewLut(value, current) {
|
|
123
|
+
const next = normalizeHfColorGrading(value);
|
|
124
|
+
if (!next)
|
|
125
|
+
return null;
|
|
126
|
+
if (next.lut && next.lut.src !== normalizeHfColorGrading(current)?.lut?.src)
|
|
127
|
+
return null;
|
|
128
|
+
return serializeHfColorGrading(next);
|
|
129
|
+
}
|
|
130
|
+
function settable(el, set) {
|
|
131
|
+
const safe = [];
|
|
132
|
+
for (const [name, value] of set) {
|
|
133
|
+
const next = name === HF_COLOR_GRADING_ATTR
|
|
134
|
+
? gradeRebuiltWithoutNewLut(value, el.getAttribute(HF_COLOR_GRADING_ATTR))
|
|
135
|
+
: safeToSet(name)
|
|
136
|
+
? value
|
|
137
|
+
: null;
|
|
138
|
+
if (next === null)
|
|
139
|
+
return null;
|
|
140
|
+
safe.push([name, next]);
|
|
141
|
+
}
|
|
142
|
+
return safe;
|
|
143
|
+
}
|
|
120
144
|
/** Adds `root`'s live elements to `plan`; false when any is missing, not the file's own, or unsafe to change. */
|
|
121
145
|
function planRoot(root, elements, plan) {
|
|
122
146
|
const live = identityMap(root);
|
|
@@ -128,11 +152,14 @@ function planRoot(root, elements, plan) {
|
|
|
128
152
|
if (!el || el.hasAttribute("data-hf-inner-root"))
|
|
129
153
|
return false;
|
|
130
154
|
const keep = new Set(attributes.map(([name]) => name));
|
|
131
|
-
const drop = el
|
|
155
|
+
const drop = el
|
|
156
|
+
.getAttributeNames()
|
|
157
|
+
.filter((name) => !keep.has(name) && !isRuntimeAttribute(el, name));
|
|
132
158
|
const set = attributes.filter(([name, value]) => el.getAttribute(name) !== value);
|
|
133
|
-
|
|
159
|
+
const safeSet = settable(el, set);
|
|
160
|
+
if (!drop.every(safeToDrop) || !safeSet)
|
|
134
161
|
return false;
|
|
135
|
-
plan.push([el, drop,
|
|
162
|
+
plan.push([el, drop, safeSet]);
|
|
136
163
|
}
|
|
137
164
|
return true;
|
|
138
165
|
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gesture drafts for the editing channel. A parent that cannot script the frame draws a drag or a
|
|
3
|
-
* resize here, on the element's inline style, so the preview moves with the pointer. What the
|
|
4
|
-
* element had before its first draft is kept until the parent ends the draft or the frame loads again.
|
|
5
|
-
*/
|
|
6
1
|
import { type StylableElement as Styled } from "./domRealm.js";
|
|
7
2
|
import type { EditingDraftReply } from "./editingDraftEnd.js";
|
|
8
3
|
import type { EditingDraft } from "./editingPort.js";
|
|
@@ -12,6 +7,7 @@ export declare function movedTranslate([x, y, z]: string[], offset: {
|
|
|
12
7
|
x: number;
|
|
13
8
|
y: number;
|
|
14
9
|
}): string;
|
|
10
|
+
export declare function rebaseDrawnPosition(element: Element, props: Record<string, unknown>): void;
|
|
15
11
|
export declare function writeDrawnSize(style: CSSStyleDeclaration, size: {
|
|
16
12
|
width: number;
|
|
17
13
|
height: number;
|
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
* resize here, on the element's inline style, so the preview moves with the pointer. What the
|
|
4
4
|
* element had before its first draft is kept until the parent ends the draft or the frame loads again.
|
|
5
5
|
*/
|
|
6
|
+
import { redrawGsapTimelineAt, seekGsapTimeline } from "./adapters/gsap.js";
|
|
6
7
|
import { isStylableElement } from "./domRealm.js";
|
|
7
8
|
import { elementForHandle } from "./editingHandles.js";
|
|
9
|
+
import { revealClip } from "./clipReveal.js";
|
|
8
10
|
export const SIZE_PROPERTIES = [
|
|
9
11
|
"box-sizing",
|
|
10
12
|
"width",
|
|
@@ -16,7 +18,15 @@ export const SIZE_PROPERTIES = [
|
|
|
16
18
|
];
|
|
17
19
|
const DRAWN = ["translate", "rotate", "transform", ...SIZE_PROPERTIES];
|
|
18
20
|
const frameGsap = () => window.gsap;
|
|
21
|
+
/** The film's own timeline, as the unsealed recorder finds it: Studio's `__proxied` mark is no timeline. */
|
|
22
|
+
function rootTimeline() {
|
|
23
|
+
const timelines = window
|
|
24
|
+
.__timelines;
|
|
25
|
+
const found = Object.entries(timelines ?? {}).find(([key, value]) => key !== "__proxied" && typeof value?.seek === "function");
|
|
26
|
+
return found?.[1] ?? null;
|
|
27
|
+
}
|
|
19
28
|
const before = new WeakMap();
|
|
29
|
+
const liveDrafts = new Map();
|
|
20
30
|
let lastDraft = 0;
|
|
21
31
|
/** "calc(50% + 2px) 4px" as its top-level parts. */
|
|
22
32
|
function axes(value) {
|
|
@@ -90,7 +100,37 @@ export function movedTranslate([x = "0px", y = "0px", z], offset) {
|
|
|
90
100
|
return `calc(${x} + ${offset.x}px) calc(${y} + ${offset.y}px)${z ? ` ${z}` : ""}`;
|
|
91
101
|
}
|
|
92
102
|
function drawTranslate(element, offset) {
|
|
93
|
-
|
|
103
|
+
const saved = beforeOf(element);
|
|
104
|
+
if (offset.route !== "gsap")
|
|
105
|
+
return void element.style.setProperty("translate", movedTranslate(saved.translate, offset));
|
|
106
|
+
const gsap = frameGsap();
|
|
107
|
+
const read = (axis) => Number(gsap?.getProperty?.(element, axis)) || 0;
|
|
108
|
+
saved.gsapPosition ??= { x: read("x"), y: read("y") };
|
|
109
|
+
element.style.setProperty("translate", "none");
|
|
110
|
+
gsap?.set?.(element, { x: offset.x, y: offset.y });
|
|
111
|
+
}
|
|
112
|
+
export function rebaseDrawnPosition(element, props) {
|
|
113
|
+
const position = before.get(element)?.gsapPosition;
|
|
114
|
+
for (const axis of ["x", "y"]) {
|
|
115
|
+
const value = props[axis];
|
|
116
|
+
if (position && typeof value === "number" && Number.isFinite(value))
|
|
117
|
+
position[axis] = value;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
function restoreGsapPosition(element) {
|
|
121
|
+
const { gsapPosition } = before.get(element) ?? {};
|
|
122
|
+
if (gsapPosition)
|
|
123
|
+
frameGsap()?.set?.(element, { ...gsapPosition });
|
|
124
|
+
}
|
|
125
|
+
function redrawTimelines() {
|
|
126
|
+
const timelines = Object.values(window.__timelines ?? {});
|
|
127
|
+
for (const timeline of timelines) {
|
|
128
|
+
const time = timeline.totalTime?.();
|
|
129
|
+
if (typeof time !== "number")
|
|
130
|
+
continue;
|
|
131
|
+
seekGsapTimeline(timeline, 0, true);
|
|
132
|
+
seekGsapTimeline(timeline, time, true);
|
|
133
|
+
}
|
|
94
134
|
}
|
|
95
135
|
export function writeDrawnSize(style, size) {
|
|
96
136
|
style.setProperty("box-sizing", "border-box");
|
|
@@ -128,21 +168,58 @@ function drawRotate(element, rotate) {
|
|
|
128
168
|
element.style.setProperty("rotate", "none");
|
|
129
169
|
gsap?.set?.(element, { rotation: rotate.angle });
|
|
130
170
|
}
|
|
171
|
+
function drawProps(element, values) {
|
|
172
|
+
const saved = beforeOf(element);
|
|
173
|
+
element.style.setProperty("translate", "none");
|
|
174
|
+
frameGsap()?.set?.(element, { ...values });
|
|
175
|
+
saved.putMarkBack ??= revealClip(element);
|
|
176
|
+
saved.propsSet = [...new Set([...(saved.propsSet ?? []), ...Object.keys(values)])];
|
|
177
|
+
}
|
|
178
|
+
function clearProps(element, saved) {
|
|
179
|
+
restore(element, DRAWN);
|
|
180
|
+
saved.putMarkBack?.();
|
|
181
|
+
if (saved.propsSet?.length)
|
|
182
|
+
frameGsap()?.set?.(element, { clearProps: saved.propsSet.join(",") });
|
|
183
|
+
const timeline = rootTimeline();
|
|
184
|
+
if (!timeline)
|
|
185
|
+
return;
|
|
186
|
+
redrawGsapTimelineAt(timeline, timeline.time());
|
|
187
|
+
putLiveDraftsBack();
|
|
188
|
+
}
|
|
131
189
|
function end(element, ending) {
|
|
132
190
|
const saved = before.get(element);
|
|
133
191
|
if (!saved || ("draft" in ending && ending.draft !== saved.draft))
|
|
134
|
-
return;
|
|
192
|
+
return false;
|
|
193
|
+
liveDrafts.delete(element);
|
|
194
|
+
if (ending.end === "clear")
|
|
195
|
+
clearProps(element, saved);
|
|
135
196
|
if (ending.end === "restore") {
|
|
136
197
|
restore(element, DRAWN);
|
|
198
|
+
restoreGsapPosition(element);
|
|
137
199
|
restoreGsapRotation(element);
|
|
138
200
|
}
|
|
139
201
|
if (ending.end === "keep-size")
|
|
140
202
|
restore(element, ["translate"]);
|
|
141
203
|
before.delete(element);
|
|
204
|
+
return ending.end === "restore";
|
|
205
|
+
}
|
|
206
|
+
function carriedRotate(last, draft) {
|
|
207
|
+
return !("rotate" in draft) && "rotate" in last ? { rotate: last.rotate } : {};
|
|
208
|
+
}
|
|
209
|
+
function mergedProps(last, draft) {
|
|
210
|
+
if (!last.props || !draft.props)
|
|
211
|
+
return {};
|
|
212
|
+
return { props: { ...draft.props, values: { ...last.props.values, ...draft.props.values } } };
|
|
213
|
+
}
|
|
214
|
+
function liveDraftOf(last, draft) {
|
|
215
|
+
if (!last || "end" in last || "end" in draft)
|
|
216
|
+
return draft;
|
|
217
|
+
return { ...draft, ...carriedRotate(last, draft), ...mergedProps(last, draft) };
|
|
142
218
|
}
|
|
143
219
|
function apply(element, draft) {
|
|
144
220
|
if ("end" in draft)
|
|
145
221
|
return end(element, draft);
|
|
222
|
+
liveDrafts.set(element, liveDraftOf(liveDrafts.get(element), draft));
|
|
146
223
|
if ("rotate" in draft)
|
|
147
224
|
drawRotate(element, draft.rotate ?? null);
|
|
148
225
|
if (draft.translate)
|
|
@@ -153,20 +230,51 @@ function apply(element, draft) {
|
|
|
153
230
|
drawSize(element, draft.size);
|
|
154
231
|
else
|
|
155
232
|
restore(element, SIZE_PROPERTIES);
|
|
233
|
+
if (draft.props) {
|
|
234
|
+
rootTimeline()?.seek(draft.props.seconds);
|
|
235
|
+
drawProps(element, draft.props.values);
|
|
236
|
+
}
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
/** Draws only the parts a live draft carries, so a replay never resets what it leaves out. */
|
|
240
|
+
function redrawOwned(element, draft) {
|
|
241
|
+
if ("rotate" in draft && draft.rotate)
|
|
242
|
+
drawRotate(element, draft.rotate);
|
|
243
|
+
if (draft.translate)
|
|
244
|
+
drawTranslate(element, draft.translate);
|
|
245
|
+
if (draft.size)
|
|
246
|
+
drawSize(element, draft.size);
|
|
247
|
+
if (draft.props)
|
|
248
|
+
drawProps(element, draft.props.values);
|
|
249
|
+
}
|
|
250
|
+
function putLiveDraftsBack() {
|
|
251
|
+
for (const [element, draft] of liveDrafts) {
|
|
252
|
+
if (element.isConnected && !("end" in draft))
|
|
253
|
+
redrawOwned(element, draft);
|
|
254
|
+
else
|
|
255
|
+
liveDrafts.delete(element);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function redrawKeepingLiveDrafts() {
|
|
259
|
+
redrawTimelines();
|
|
260
|
+
putLiveDraftsBack();
|
|
156
261
|
}
|
|
157
262
|
/** Applies each draft in order; one for an element this load no longer has is skipped. */
|
|
158
263
|
export function drawDrafts(drafts) {
|
|
159
264
|
let drawn = 0;
|
|
265
|
+
let restored = false;
|
|
160
266
|
const numbers = {};
|
|
161
267
|
for (const draft of drafts) {
|
|
162
268
|
const element = elementForHandle(draft.handle);
|
|
163
269
|
if (!isStylableElement(element))
|
|
164
270
|
continue;
|
|
165
|
-
apply(element, draft);
|
|
271
|
+
restored = apply(element, draft) || restored;
|
|
166
272
|
drawn++;
|
|
167
273
|
const saved = before.get(element);
|
|
168
274
|
if (saved)
|
|
169
275
|
numbers[draft.handle] = saved.draft;
|
|
170
276
|
}
|
|
277
|
+
if (restored)
|
|
278
|
+
redrawKeepingLiveDrafts();
|
|
171
279
|
return { drawn, drafts: numbers };
|
|
172
280
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type EditingElementHandle } from "./editingElement.js";
|
|
2
|
-
/** `keep-size` drops the drawn translate and keeps the drawn size.
|
|
2
|
+
/** `keep-size` drops the drawn translate and keeps the drawn size; `clear` lets the timeline drive what props set.
|
|
3
3
|
* An end naming an older `draft` than the element has does nothing. */
|
|
4
4
|
export type EditingDraftEnd = {
|
|
5
5
|
handle: EditingElementHandle;
|
|
6
|
-
end: "keep" | "restore";
|
|
6
|
+
end: "keep" | "restore" | "clear";
|
|
7
7
|
} | {
|
|
8
8
|
handle: EditingElementHandle;
|
|
9
|
-
end: "keep" | "restore" | "keep-size";
|
|
9
|
+
end: "keep" | "restore" | "keep-size" | "clear";
|
|
10
10
|
draft: number;
|
|
11
11
|
};
|
|
12
12
|
/** `drafts` numbers each element still drawn, for the end that names its draft. */
|
|
@@ -8,10 +8,10 @@ export function parseDraftEnd(value) {
|
|
|
8
8
|
return null;
|
|
9
9
|
const keys = Object.keys(value).sort().join();
|
|
10
10
|
if (keys === "end,handle")
|
|
11
|
-
return end === "keep" || end === "restore" ? { handle, end } : null;
|
|
11
|
+
return end === "keep" || end === "restore" || end === "clear" ? { handle, end } : null;
|
|
12
12
|
if (keys !== "draft,end,handle" || !Number.isSafeInteger(draft) || draft < 1)
|
|
13
13
|
return null;
|
|
14
|
-
return end === "keep" || end === "restore" || end === "keep-size"
|
|
14
|
+
return end === "keep" || end === "restore" || end === "keep-size" || end === "clear"
|
|
15
15
|
? { handle, end, draft: draft }
|
|
16
16
|
: null;
|
|
17
17
|
}
|
|
@@ -21,6 +21,7 @@ export interface EditingGestureStart extends EditingElementGeometry {
|
|
|
21
21
|
x: number;
|
|
22
22
|
y: number;
|
|
23
23
|
moving: boolean;
|
|
24
|
+
drawsTranslate: true;
|
|
24
25
|
} | null;
|
|
25
26
|
/** GSAP's rotation now when it owns the element's turn; null when it turns by its own CSS `rotate`. */
|
|
26
27
|
gsapRotation: number | null;
|
|
@@ -37,6 +38,7 @@ export type EditingGestureBase = {
|
|
|
37
38
|
y: number;
|
|
38
39
|
opacity: number;
|
|
39
40
|
scale: number;
|
|
41
|
+
drawsProps?: true;
|
|
40
42
|
};
|
|
41
43
|
export declare function gestureBase(handle: EditingElementHandle): EditingGestureBase | null;
|
|
42
44
|
/** Each handle's gesture start, null as in `describe`, and the snap boxes of the page around them. */
|
|
@@ -122,7 +122,7 @@ export function gestureBase(handle) {
|
|
|
122
122
|
return { x: 0, y: 0, opacity: 1, scale: 1 };
|
|
123
123
|
const read = (property) => Number(gsap.getProperty?.(element, property));
|
|
124
124
|
const base = { x: read("x"), y: read("y"), opacity: read("opacity"), scale: read("scaleX") };
|
|
125
|
-
return Object.values(base).every(Number.isFinite) ? base : null;
|
|
125
|
+
return Object.values(base).every(Number.isFinite) ? { ...base, drawsProps: true } : null;
|
|
126
126
|
}
|
|
127
127
|
// Read only once GSAP owns it: asking GSAP for x makes it fold a CSS translate into its transform.
|
|
128
128
|
const readGsap = (element, property) => Number(window.gsap?.getProperty?.(element, property)) || 0;
|
|
@@ -132,7 +132,7 @@ function gsapPosition(element) {
|
|
|
132
132
|
if (!rendersTransform(element) && !tweens.length)
|
|
133
133
|
return null;
|
|
134
134
|
const moving = tweens.some((tween) => (tween.duration?.() ?? 0) > 0);
|
|
135
|
-
return { x: readGsap(element, "x"), y: readGsap(element, "y"), moving };
|
|
135
|
+
return { x: readGsap(element, "x"), y: readGsap(element, "y"), moving, drawsTranslate: true };
|
|
136
136
|
}
|
|
137
137
|
function gsapRotation(element) {
|
|
138
138
|
const turned = tweensOn(element).some((tween) => tween.vars && carries(tween.vars, TURNS));
|
|
@@ -88,18 +88,25 @@ export type EditingDraftRotate = {
|
|
|
88
88
|
value: string;
|
|
89
89
|
};
|
|
90
90
|
export type { EditingDraftEnd };
|
|
91
|
+
export declare const DRAFT_GSAP_PROPS: string[];
|
|
92
|
+
export type EditingDraftProps = {
|
|
93
|
+
seconds: number;
|
|
94
|
+
values: Record<string, number>;
|
|
95
|
+
};
|
|
91
96
|
/** A gesture's draft on one element: null puts that part back; an end keeps what is drawn or restores. */
|
|
92
97
|
export type EditingDraft = {
|
|
93
98
|
handle: EditingElementHandle;
|
|
94
99
|
translate: {
|
|
95
100
|
x: number;
|
|
96
101
|
y: number;
|
|
102
|
+
route?: "gsap";
|
|
97
103
|
} | null;
|
|
98
104
|
size: {
|
|
99
105
|
width: number;
|
|
100
106
|
height: number;
|
|
101
107
|
} | null;
|
|
102
108
|
rotate?: EditingDraftRotate | null;
|
|
109
|
+
props?: EditingDraftProps | null;
|
|
103
110
|
} | EditingDraftEnd;
|
|
104
111
|
type NoParams = Record<string, never>;
|
|
105
112
|
export interface EditingRequests {
|
|
@@ -79,6 +79,16 @@ export { MAX_DRAFT_PX };
|
|
|
79
79
|
export const EDITING_REQUEST_TIMEOUT_MS = 5_000;
|
|
80
80
|
export const MAX_DRAFT_DEG = 36_000;
|
|
81
81
|
export const MAX_WATCHED_KEYS = 32;
|
|
82
|
+
export const DRAFT_GSAP_PROPS = [
|
|
83
|
+
"x",
|
|
84
|
+
"y",
|
|
85
|
+
"opacity",
|
|
86
|
+
"scale",
|
|
87
|
+
"rotation",
|
|
88
|
+
"rotationX",
|
|
89
|
+
"rotationY",
|
|
90
|
+
"z",
|
|
91
|
+
];
|
|
82
92
|
export function isPlainRecord(value) {
|
|
83
93
|
return Object.prototype.toString.call(value) === "[object Object]";
|
|
84
94
|
}
|
|
@@ -158,6 +168,11 @@ const isRotateRoute = (value) => (hasKeys(value, "angle,route") && (value.route
|
|
|
158
168
|
(hasKeys(value, "angle,route,value") &&
|
|
159
169
|
value.route === "transform" &&
|
|
160
170
|
isTransformList(value.value));
|
|
171
|
+
function draftTranslate(value) {
|
|
172
|
+
if (!hasKeys(value, "route,x,y"))
|
|
173
|
+
return draftPart(value, "x,y", -MAX_DRAFT_PX);
|
|
174
|
+
return (value.route === "gsap" && isDraftPx(value.x, -MAX_DRAFT_PX) && isDraftPx(value.y, -MAX_DRAFT_PX));
|
|
175
|
+
}
|
|
161
176
|
function draftRotate(value) {
|
|
162
177
|
if (value === undefined || value === null)
|
|
163
178
|
return true;
|
|
@@ -173,12 +188,31 @@ function draftEntry(value) {
|
|
|
173
188
|
return drawnParts(value) ? value : null;
|
|
174
189
|
}
|
|
175
190
|
function drawnParts(value) {
|
|
176
|
-
const { translate, size, rotate } = value;
|
|
177
|
-
if (!
|
|
191
|
+
const { handle: _handle, translate, size, rotate, props, ...rest } = value;
|
|
192
|
+
if (Object.keys(rest).length || !("translate" in value) || !("size" in value))
|
|
193
|
+
return false;
|
|
194
|
+
const parts = [
|
|
195
|
+
draftTranslate(translate),
|
|
196
|
+
draftPart(size, "height,width", 0),
|
|
197
|
+
draftRotate(rotate),
|
|
198
|
+
];
|
|
199
|
+
return !parts.includes(false) && draftPropsWithOneXYWriter(props, translate);
|
|
200
|
+
}
|
|
201
|
+
const isPropsShape = (value) => hasKeys(value, "seconds,values") &&
|
|
202
|
+
isPlainRecord(value.values) &&
|
|
203
|
+
Number.isFinite(value.seconds) &&
|
|
204
|
+
value.seconds >= 0;
|
|
205
|
+
const isDraftValue = ([key, value]) => DRAFT_GSAP_PROPS.includes(key) && isDraftPx(value, -MAX_DRAFT_PX);
|
|
206
|
+
const setsPosition = (keys) => keys.includes("x") || keys.includes("y");
|
|
207
|
+
function draftPropsWithOneXYWriter(value, translate) {
|
|
208
|
+
if (value === undefined || value === null)
|
|
209
|
+
return true;
|
|
210
|
+
if (!isPropsShape(value))
|
|
211
|
+
return false;
|
|
212
|
+
const entries = Object.entries(value.values);
|
|
213
|
+
if (!entries.length || (translate !== null && setsPosition(entries.map(([key]) => key))))
|
|
178
214
|
return false;
|
|
179
|
-
return (
|
|
180
|
-
draftPart(size, "height,width", 0) &&
|
|
181
|
-
draftRotate(rotate));
|
|
215
|
+
return entries.every(isDraftValue);
|
|
182
216
|
}
|
|
183
217
|
function draftList(params) {
|
|
184
218
|
if (!hasKeys(params, "drafts") || !Array.isArray(params.drafts))
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare function recordRuntimeAttribute(el: object, name: string): void;
|
|
2
|
+
export declare function forgetRuntimeAttribute(el: Element, name: string): boolean;
|
|
3
|
+
export declare function isRuntimeAttribute(el: Element, name: string): boolean;
|
|
4
|
+
export declare function setRuntimePreload(media: Pick<HTMLMediaElement, "preload"> & Partial<Pick<Element, "hasAttribute">>, value: HTMLMediaElement["preload"]): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const addedByRuntime = new WeakMap();
|
|
2
|
+
export function recordRuntimeAttribute(el, name) {
|
|
3
|
+
const names = addedByRuntime.get(el) ?? new Set();
|
|
4
|
+
names.add(name);
|
|
5
|
+
addedByRuntime.set(el, names);
|
|
6
|
+
}
|
|
7
|
+
export function forgetRuntimeAttribute(el, name) {
|
|
8
|
+
return addedByRuntime.get(el)?.delete(name) === true;
|
|
9
|
+
}
|
|
10
|
+
export function isRuntimeAttribute(el, name) {
|
|
11
|
+
return addedByRuntime.get(el)?.has(name) === true;
|
|
12
|
+
}
|
|
13
|
+
export function setRuntimePreload(media, value) {
|
|
14
|
+
if (media.hasAttribute?.("preload") === false)
|
|
15
|
+
recordRuntimeAttribute(media, "preload");
|
|
16
|
+
media.preload = value;
|
|
17
|
+
}
|
package/dist/safePath.d.ts
CHANGED
|
@@ -57,3 +57,10 @@ export declare function realProjectRoot(root: string): string;
|
|
|
57
57
|
* A `dir` outside `root` is created recursively, but only while `root` exists.
|
|
58
58
|
*/
|
|
59
59
|
export declare function mkdirWithinProject(root: string, dir: string): void;
|
|
60
|
+
/** The real path; for a path not there (yet, or any more), the nearest existing folder's real path plus the rest. */
|
|
61
|
+
export declare function realFilePath(filePath: string): string;
|
|
62
|
+
export type EntryKind = "file" | "folder";
|
|
63
|
+
/** A script only Node runs, whatever folder holds it. */
|
|
64
|
+
export declare function nodeOnlyScript(relPath: string): boolean;
|
|
65
|
+
/** A Node-only script, or `.js`/`.mjs` or an extensionless file below (at any depth, past the project too) a package.json that is not the scaffold's. */
|
|
66
|
+
export declare function nodeMayRun(projectDir: string, relPath: string, kind: EntryKind): boolean;
|
package/dist/safePath.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolve, sep, join, dirname, basename, relative, isAbsolute, parse } from "node:path";
|
|
2
|
-
import { lstatSync, mkdirSync, realpath as realpathWalk, realpathSync, statSync } from "node:fs";
|
|
2
|
+
import { lstatSync, mkdirSync, readFileSync, realpath as realpathWalk, realpathSync, statSync, } from "node:fs";
|
|
3
3
|
import { realpath as realpathNative } from "node:fs/promises";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import { projectPathSegments } from "@hyperframes/parsers/private-path";
|
|
@@ -295,3 +295,74 @@ export function mkdirWithinProject(root, dir) {
|
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
|
+
/** The real path; for a path not there (yet, or any more), the nearest existing folder's real path plus the rest. */
|
|
299
|
+
export function realFilePath(filePath) {
|
|
300
|
+
try {
|
|
301
|
+
return realpath(filePath);
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
const dir = dirname(filePath);
|
|
305
|
+
return dir === filePath ? filePath : join(realFilePath(dir), basename(filePath));
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
const NODE_ONLY_SCRIPT = /\.(?:[cm]?ts|tsx|jsx|cjs)$/;
|
|
309
|
+
const BROWSER_OR_NODE_SCRIPT = /\.m?js$/;
|
|
310
|
+
const isExtensionless = (name) => name !== "" && !name.includes(".");
|
|
311
|
+
/** A script only Node runs, whatever folder holds it. */
|
|
312
|
+
export function nodeOnlyScript(relPath) {
|
|
313
|
+
return NODE_ONLY_SCRIPT.test(foldedPath(relPath).split("/").at(-1) ?? "");
|
|
314
|
+
}
|
|
315
|
+
/** A Node-only script, or `.js`/`.mjs` or an extensionless file below (at any depth, past the project too) a package.json that is not the scaffold's. */
|
|
316
|
+
export function nodeMayRun(projectDir, relPath, kind) {
|
|
317
|
+
if (nodeOnlyScript(relPath))
|
|
318
|
+
return true;
|
|
319
|
+
const name = foldedPath(relPath).split("/").at(-1) ?? "";
|
|
320
|
+
const sharedWithNode = BROWSER_OR_NODE_SCRIPT.test(name) || (kind === "file" && isExtensionless(name));
|
|
321
|
+
if (!sharedWithNode)
|
|
322
|
+
return false;
|
|
323
|
+
const folder = dirname(resolve(projectDir, relPath));
|
|
324
|
+
return [folder, realFilePath(folder)].some((from) => foldersUp(from).some(manifestBringsNode));
|
|
325
|
+
}
|
|
326
|
+
function foldersUp(from) {
|
|
327
|
+
const parent = dirname(from);
|
|
328
|
+
return parent === from ? [from] : [from, ...foldersUp(parent)];
|
|
329
|
+
}
|
|
330
|
+
const manifests = new Map();
|
|
331
|
+
function manifestBringsNode(folder) {
|
|
332
|
+
const path = join(folder, "package.json");
|
|
333
|
+
const stat = statSync(path, { throwIfNoEntry: false });
|
|
334
|
+
if (!stat?.isFile())
|
|
335
|
+
return false;
|
|
336
|
+
const key = `${stat.ino}:${stat.size}:${stat.mtimeMs}`;
|
|
337
|
+
const cached = manifests.get(path);
|
|
338
|
+
if (cached?.stat === key)
|
|
339
|
+
return cached.bringsNode;
|
|
340
|
+
const bringsNode = !isScaffoldManifest(readPackageJson(path));
|
|
341
|
+
manifests.set(path, { stat: key, bringsNode });
|
|
342
|
+
return bringsNode;
|
|
343
|
+
}
|
|
344
|
+
function readPackageJson(path) {
|
|
345
|
+
try {
|
|
346
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
347
|
+
}
|
|
348
|
+
catch {
|
|
349
|
+
return null;
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
const INERT_FIELDS = new Set("name version private type description license author contributors keywords homepage repository bugs engines".split(" "));
|
|
353
|
+
const HYPERFRAMES_COMMAND = /^(?:npx (?:--yes |-y )?)?hyperframes(?:@[\w.+-]+)?(?: [\w@=:./+-]+)*$/;
|
|
354
|
+
/** A manifest with nothing but inert fields and scripts that only call the hyperframes CLI, as `hyperframes init` writes. */
|
|
355
|
+
function isScaffoldManifest(pkg) {
|
|
356
|
+
if (!pkg || typeof pkg !== "object" || Array.isArray(pkg))
|
|
357
|
+
return false;
|
|
358
|
+
return Object.entries(pkg).every(([field, value]) => field === "scripts" ? onlyHyperframesScripts(value) : INERT_FIELDS.has(field));
|
|
359
|
+
}
|
|
360
|
+
function onlyHyperframesScripts(scripts) {
|
|
361
|
+
if (!scripts || typeof scripts !== "object" || Array.isArray(scripts))
|
|
362
|
+
return false;
|
|
363
|
+
return Object.values(scripts).every((script) => typeof script === "string" &&
|
|
364
|
+
script.split(" && ").every((command) => HYPERFRAMES_COMMAND.test(command.trim())));
|
|
365
|
+
}
|
|
366
|
+
const foldedPath = (path) => projectPathSegments(path)
|
|
367
|
+
.filter((segment) => segment !== "" && segment !== ".")
|
|
368
|
+
.join("/");
|
|
@@ -15,6 +15,9 @@ export declare function servedToStudio(doc: Document): boolean;
|
|
|
15
15
|
export declare function inPlayerFrame(doc: Document): boolean;
|
|
16
16
|
export declare function defersMediaIn(doc: Document): boolean;
|
|
17
17
|
export declare function capturePageIn(doc: Document): boolean;
|
|
18
|
+
export declare const CAPTURE_STILLS = "hf-capture-stills";
|
|
19
|
+
export declare const CAPTURE_STILL_ATTR = "data-hf-capture-still";
|
|
20
|
+
export declare function captureStillsIn(doc: Document): boolean;
|
|
18
21
|
export declare const STUDIO_PREVIEW_UPCOMING_ATTR = "data-hf-upcoming";
|
|
19
22
|
export declare const STUDIO_PREVIEW_LAZY_ATTR = "data-hf-preview-lazy";
|
|
20
23
|
export declare const STUDIO_PREVIEW_ERRORS = "__hfPreviewErrors";
|
|
@@ -41,6 +41,11 @@ export function capturePageIn(doc) {
|
|
|
41
41
|
return (doc.querySelector(`meta[name="${STUDIO_PREVIEW_MARK_META}"]`)?.getAttribute("content") ===
|
|
42
42
|
STUDIO_PREVIEW_CAPTURE_MODE);
|
|
43
43
|
}
|
|
44
|
+
export const CAPTURE_STILLS = "hf-capture-stills";
|
|
45
|
+
export const CAPTURE_STILL_ATTR = "data-hf-capture-still";
|
|
46
|
+
export function captureStillsIn(doc) {
|
|
47
|
+
return capturePageIn(doc) && doc.querySelector(`meta[name="${CAPTURE_STILLS}"]`) !== null;
|
|
48
|
+
}
|
|
44
49
|
export const STUDIO_PREVIEW_UPCOMING_ATTR = "data-hf-upcoming";
|
|
45
50
|
export const STUDIO_PREVIEW_LAZY_ATTR = "data-hf-preview-lazy";
|
|
46
51
|
export const STUDIO_PREVIEW_ERRORS = "__hfPreviewErrors";
|
|
@@ -129,6 +129,20 @@ function redactFilePaths(value) {
|
|
|
129
129
|
.replace(BARE_RELATIVE_PATH, "[path]")
|
|
130
130
|
.replace(ASSET_BASENAME, "[file]"));
|
|
131
131
|
}
|
|
132
|
+
// The path patterns cost up to the square of a run's length. Before any of them runs, input is cut at whitespace so
|
|
133
|
+
// no path is split, and a long run keeps only its two ends: its start still names a path, its end what follows.
|
|
134
|
+
const MAX_REDACTED_INPUT = 16 * 1024;
|
|
135
|
+
const RUN_KEPT = 256;
|
|
136
|
+
const LONG_RUN = new RegExp(String.raw `(?<![^\s/\\'"])[^\s/\\'"]{${RUN_KEPT + 1},}`, "g");
|
|
137
|
+
function cutAtWhitespace(value) {
|
|
138
|
+
if (value.length <= MAX_REDACTED_INPUT)
|
|
139
|
+
return value;
|
|
140
|
+
let end = MAX_REDACTED_INPUT;
|
|
141
|
+
while (end >= 0 && !/\s/.test(value.charAt(end)))
|
|
142
|
+
end--;
|
|
143
|
+
return `${value.slice(0, end + 1)}…`;
|
|
144
|
+
}
|
|
132
145
|
export function redactTelemetryString(value, maxLength = MAX_TELEMETRY_STRING_LENGTH) {
|
|
133
|
-
|
|
146
|
+
const shortRuns = redactUrlQueryStrings(cutAtWhitespace(value)).replace(LONG_RUN, (run) => `${run.slice(0, RUN_KEPT / 2)}…${run.slice(-RUN_KEPT / 2)}`);
|
|
147
|
+
return truncateTelemetryString(redactFilePaths(shortRuns), maxLength);
|
|
134
148
|
}
|