@hyperframes/core 0.9.87 → 0.9.89

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.
@@ -27,6 +27,7 @@ export type PreviewSourceFacts = {
27
27
  variableFrameRate?: boolean;
28
28
  sampleAspectRatio?: number;
29
29
  rotation?: number;
30
+ hasAlpha?: boolean;
30
31
  };
31
32
  export declare const HEAVY_PIXEL_SHARE = 0.5;
32
33
  export declare const HEAVY_BITRATE = 40000000;
@@ -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.getAttributeNames().filter((name) => !keep.has(name));
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
- if (!drop.every(safeToDrop) || !set.every(([name]) => safeToSet(name)))
159
+ const safeSet = settable(el, set);
160
+ if (!drop.every(safeToDrop) || !safeSet)
134
161
  return false;
135
- plan.push([el, drop, set]);
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
- element.style.setProperty("translate", movedTranslate(beforeOf(element).translate, offset));
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 (!hasKeys(value, "handle,size,translate") && !hasKeys(value, "handle,rotate,size,translate"))
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 (draftPart(translate, "x,y", -MAX_DRAFT_PX) &&
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
+ }
@@ -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";
@@ -78,7 +78,8 @@ const OPAQUE_TAGS = new Set([
78
78
  "MATH",
79
79
  ]);
80
80
  /** Anything that reaches out of the stylesheet, in a property that should not. */
81
- const UNSAFE_VALUE = /url\(|expression\(|javascript:|vbscript:|@import|<\//i;
81
+ const UNSAFE_VALUE = /javascript:|vbscript:|@import|<\//i;
82
+ const RESOURCE_FUNCTION = /(?:url|src|image|image-set|cross-fade|element|expression)\(/i;
82
83
  const ELEMENT_NODE = 1;
83
84
  const TEXT_NODE = 3;
84
85
  export function isRichTextFormattingTag(tagName) {
@@ -92,7 +93,8 @@ export function isRichTextFormattingAttribute(name, value) {
92
93
  export function isRichTextFormattingStyle(property, value) {
93
94
  return (FORMATTING_STYLE_PROPS.has(property.toLowerCase()) &&
94
95
  value.length > 0 &&
95
- !UNSAFE_VALUE.test(value));
96
+ !UNSAFE_VALUE.test(value) &&
97
+ !RESOURCE_FUNCTION.test(withoutPlainStrings(value)));
96
98
  }
97
99
  function isElementNode(node) {
98
100
  return node.nodeType === ELEMENT_NODE;
@@ -168,7 +170,7 @@ function stripAttributes(element) {
168
170
  }
169
171
  /** Keep only the allowlisted declarations, and only if their values are inert. */
170
172
  function filterStyle(style) {
171
- return splitDeclarations(style)
173
+ return (splitDeclarations(style) ?? [])
172
174
  .map((declaration) => {
173
175
  const colon = declaration.indexOf(":");
174
176
  if (colon === -1)
@@ -182,45 +184,33 @@ function filterStyle(style) {
182
184
  .filter((declaration) => declaration !== null)
183
185
  .join("; ");
184
186
  }
185
- function isQuoteDelimiter(char) {
186
- return char === "'" || char === '"';
187
- }
188
- function nextParenthesisDepth(depth, char) {
189
- if (char === "(")
190
- return depth + 1;
191
- if (char === ")")
192
- return Math.max(0, depth - 1);
193
- return depth;
194
- }
195
- function isDeclarationSeparator(char, depth, quote) {
196
- return char === ";" && depth === 0 && quote === null;
197
- }
198
- /**
199
- * Split on the semicolons that separate declarations, not the ones inside a
200
- * value. `color: rgb(1, 2, 3)` is one declaration however many separators its
201
- * value contains.
202
- */
187
+ const PLAIN_STRING = /"[^"\\\n\r\f]*"|'[^'\\\n\r\f]*'/g;
188
+ const withoutPlainStrings = (text) => text.replace(PLAIN_STRING, (string) => "_".repeat(string.length));
189
+ // Outside plain strings: an escape, a stray or broken quote, a comment, a bracket no formatting value needs.
190
+ const READ_UNLIKE_CSS = /[\\"'{}[\]]|\/\*/;
191
+ /** Declarations split where a browser splits them, or null for text this split could read differently from CSS. */
203
192
  function splitDeclarations(style) {
193
+ const bare = withoutPlainStrings(style);
194
+ if (READ_UNLIKE_CSS.test(bare) || !bracketsCloseWithoutSemicolon(bare))
195
+ return null;
204
196
  const declarations = [];
205
- let current = "";
197
+ let start = 0;
198
+ for (let end = bare.indexOf(";"); end !== -1; end = bare.indexOf(";", start)) {
199
+ declarations.push(style.slice(start, end));
200
+ start = end + 1;
201
+ }
202
+ declarations.push(style.slice(start));
203
+ return declarations.filter((declaration) => declaration.trim());
204
+ }
205
+ function bracketsCloseWithoutSemicolon(bare) {
206
206
  let depth = 0;
207
- let quote = null;
208
- for (const char of style) {
209
- if (char === quote)
210
- quote = null;
211
- else if (quote === null && isQuoteDelimiter(char))
212
- quote = char;
213
- else if (isDeclarationSeparator(char, depth, quote)) {
214
- declarations.push(current);
215
- current = "";
216
- continue;
217
- }
218
- else if (quote === null) {
219
- depth = nextParenthesisDepth(depth, char);
220
- }
221
- current += char;
207
+ for (const char of bare) {
208
+ if (char === "(")
209
+ depth++;
210
+ else if (char === ")")
211
+ depth--;
212
+ if (depth < 0 || (depth > 0 && char === ";"))
213
+ return false;
222
214
  }
223
- if (current.trim())
224
- declarations.push(current);
225
- return declarations;
215
+ return depth === 0;
226
216
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/core",
3
- "version": "0.9.87",
3
+ "version": "0.9.89",
4
4
  "description": "",
5
5
  "repository": {
6
6
  "type": "git",
@@ -377,6 +377,10 @@
377
377
  "import": "./dist/compiler/compositionSizeLimit.js",
378
378
  "types": "./dist/compiler/compositionSizeLimit.d.ts"
379
379
  },
380
+ "./compiler/html-tokens": {
381
+ "import": "./dist/compiler/htmlTokens.js",
382
+ "types": "./dist/compiler/htmlTokens.d.ts"
383
+ },
380
384
  "./compiler/html-document": {
381
385
  "import": "./dist/compiler/htmlDocument.js",
382
386
  "types": "./dist/compiler/htmlDocument.d.ts"
@@ -501,9 +505,9 @@
501
505
  "linkedom": "^0.18.12",
502
506
  "postcss": "^8.5.8",
503
507
  "wawoff2": "^2.0.1",
504
- "@hyperframes/lint": "0.9.87",
505
- "@hyperframes/parsers": "0.9.87",
506
- "@hyperframes/studio-server": "0.9.87"
508
+ "@hyperframes/lint": "0.9.89",
509
+ "@hyperframes/parsers": "0.9.89",
510
+ "@hyperframes/studio-server": "0.9.89"
507
511
  },
508
512
  "devDependencies": {
509
513
  "@fontsource/archivo-black": "^5.2.8",