@hyperframes/core 0.9.81 → 0.9.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/audibleVideo.d.ts +9 -0
  2. package/dist/audibleVideo.js +31 -0
  3. package/dist/compiler/index.d.ts +1 -1
  4. package/dist/compiler/index.js +1 -1
  5. package/dist/compiler/inlineSubCompositions.js +3 -2
  6. package/dist/compiler/timingCompiler.js +39 -35
  7. package/dist/compositionSource.d.ts +2 -0
  8. package/dist/compositionSource.js +2 -0
  9. package/dist/generated/runtime-inline.js +1 -1
  10. package/dist/gsapCdn.d.ts +11 -1
  11. package/dist/gsapCdn.js +24 -1
  12. package/dist/hyperframe.runtime.iife.js +69 -69
  13. package/dist/runtime/bridge.d.ts +1 -0
  14. package/dist/runtime/bridge.js +4 -1
  15. package/dist/runtime/editing/patchTween.d.ts +1 -1
  16. package/dist/runtime/editing/patchTween.js +34 -12
  17. package/dist/runtime/editing/softReload.d.ts +0 -1
  18. package/dist/runtime/editing/softReload.js +28 -5
  19. package/dist/runtime/editing/watchGeometry.js +5 -2
  20. package/dist/runtime/editingElement.d.ts +1 -0
  21. package/dist/runtime/editingElement.js +1 -0
  22. package/dist/runtime/editingGeometry.d.ts +4 -0
  23. package/dist/runtime/editingGeometry.js +10 -9
  24. package/dist/runtime/editingGestureStart.d.ts +0 -5
  25. package/dist/runtime/editingGestureStart.js +1 -4
  26. package/dist/runtime/editingPort.d.ts +2 -3
  27. package/dist/runtime/editingPort.js +2 -3
  28. package/dist/runtime/elementTransform.d.ts +12 -55
  29. package/dist/runtime/elementTransform.js +50 -75
  30. package/dist/runtime/protocol.d.ts +1 -1
  31. package/dist/runtime/protocol.js +1 -0
  32. package/dist/runtime/sceneRest.d.ts +4 -0
  33. package/dist/runtime/sceneRest.js +15 -0
  34. package/dist/runtime/state.d.ts +1 -5
  35. package/dist/runtime/transitionLabels.js +9 -2
  36. package/dist/runtime/types.d.ts +2 -0
  37. package/dist/utils/htmlAttrSafety.js +3 -0
  38. package/package.json +4 -4
@@ -27,6 +27,7 @@ type BridgeDeps = {
27
27
  onSetCopiesAhead?: (on: boolean) => void;
28
28
  onRetryPreviewCopies?: () => void;
29
29
  onRequestPreviewFacts?: () => void;
30
+ onAnnounceTimeline?: () => void;
30
31
  onScrubAudio?: (target: PreviewTarget | null, time: number | null, volume: number) => void;
31
32
  getCanonicalFps: () => number;
32
33
  };
@@ -24,11 +24,13 @@ const ANOTHER_SITE_DRIVES = new Set([
24
24
  ]);
25
25
  let markedForAnotherSite = false;
26
26
  const forAnotherSite = () => (markedForAnotherSite ||= typeof document !== "undefined" && servedToAnotherSite(document));
27
+ const UNSEEDED_DOCUMENT_ID = crypto.randomUUID?.() ?? String(performance.timeOrigin);
27
28
  export function postRuntimeMessage(payload) {
28
29
  if (forAnotherSite() && !ANOTHER_SITE_SEES.has(payload.type))
29
30
  return;
30
31
  try {
31
- window.parent.postMessage({ ...payload, ...runtimeProtocolMetadata(runtimeProtocolFps) }, "*");
32
+ const metadata = runtimeProtocolMetadata(runtimeProtocolFps);
33
+ window.parent.postMessage({ ...payload, ...metadata, documentId: UNSEEDED_DOCUMENT_ID }, "*");
32
34
  }
33
35
  catch (err) {
34
36
  // Cross-frame posting can throw if the parent is gone or origin-isolated.
@@ -133,6 +135,7 @@ const CONTROL_HANDLERS = new Map(Object.entries({
133
135
  "set-copies-ahead": (data, deps) => deps.onSetCopiesAhead?.(data.on === true),
134
136
  "retry-preview-copies": (_d, deps) => deps.onRetryPreviewCopies?.(),
135
137
  "request-preview-facts": (_d, deps) => deps.onRequestPreviewFacts?.(),
138
+ "announce-timeline": (_d, deps) => deps.onAnnounceTimeline?.(),
136
139
  "set-root-duration": (data, deps) => {
137
140
  const durationSeconds = readNumber(data.durationSeconds, 0);
138
141
  if (durationSeconds !== null)
@@ -70,7 +70,7 @@ export declare function applyGlobalSet(target: PatchTarget, selector: string, pr
70
70
  /** `deferSeek`: a group commit renders once after its last patch, or queued members repaint stale. */
71
71
  export declare function patchTween(target: PatchTarget, selector: string, change: Exclude<RuntimeTweenChange, {
72
72
  kind: "global-set";
73
- }>, compositionId?: string, deferSeek?: boolean): boolean;
73
+ }>, compositionId?: string, deferSeek?: boolean, patchedTweens?: PatchableTween[]): boolean;
74
74
  /** A base value never renders, so a batch renders on its last tween patch, whatever follows it. */
75
75
  export declare function lastTweenPatch(patches: ReadonlyArray<{
76
76
  change: RuntimeTweenChange;
@@ -4,6 +4,7 @@
4
4
  import { applyAuthoredInlineOpacity, readStampedAuthoredOpacity } from "../../colorGrading.js";
5
5
  import { recordLiveSet, swapWaiting } from "./softReload.js";
6
6
  import { drawDrafts } from "../editingDraft.js";
7
+ import { markRestingScenesForRedraw } from "../sceneRest.js";
7
8
  import { parseDraftEnd } from "../editingDraftEnd.js";
8
9
  const SET_CHANNELS = [
9
10
  "x",
@@ -166,16 +167,18 @@ function keyframeObject(vars) {
166
167
  const finiteStep = (props) => Object.values(props).every((v) => typeof v === "number" && Number.isFinite(v));
167
168
  function rebuildKeyframeTween(tween, pct, props) {
168
169
  if (!replaceable(tween) || !finiteStep(props))
169
- return false;
170
+ return null;
170
171
  const kf = keyframeObject(tween.vars);
171
172
  const targets = tween.targets?.();
172
173
  if (!kf || !targets || targets.length === 0)
173
- return false;
174
+ return null;
174
175
  const next = mergeKeyframeStep(kf, pct, props);
175
176
  const position = tween.startTime();
177
+ const parent = tween.parent;
176
178
  tween.kill();
177
- tween.parent.to(targets, { ...tween.vars, keyframes: next }, position);
178
- return true;
179
+ const before = new Set(parent.getChildren?.(false));
180
+ parent.to(targets, { ...tween.vars, keyframes: next }, position);
181
+ return parent.getChildren?.(false).find((child) => !before.has(child)) ?? null;
179
182
  }
180
183
  function changeChannels(change) {
181
184
  if (change.kind === "set")
@@ -204,12 +207,24 @@ function restoreAuthoredOpacityForCapture(tween) {
204
207
  }
205
208
  function applyChange(tween, change) {
206
209
  if (change.kind === "set")
207
- return patchSet(tween, change.props);
210
+ return patchSet(tween, change.props) ? tween : null;
208
211
  if (change.kind === "keyframes")
209
- return patchKeyframes(tween, change.keyframes);
212
+ return patchKeyframes(tween, change.keyframes) ? tween : null;
210
213
  if (change.kind === "keyframe-rebuild")
211
214
  return rebuildKeyframeTween(tween, change.pct, change.props);
212
- return false;
215
+ return null;
216
+ }
217
+ /** Reads GSAP's internal `_initted`: invalidate() clears it and the tween's next render sets it. */
218
+ const renderedOnceReached = (tween) => {
219
+ const now = tween.parent?.time?.();
220
+ const reached = typeof now === "number" && now >= (tween.startTime?.() ?? 0);
221
+ return !reached || Boolean(tween._initted);
222
+ };
223
+ function timelinesAbove(tween) {
224
+ const chain = [];
225
+ for (let parent = tween.parent; parent; parent = parent.parent)
226
+ chain.push(parent);
227
+ return chain;
213
228
  }
214
229
  function seekToCurrent(target, timeline) {
215
230
  const player = target.player;
@@ -221,7 +236,7 @@ function seekToCurrent(target, timeline) {
221
236
  player?.seek?.(Number.isFinite(currentTime) ? currentTime : 0);
222
237
  }
223
238
  /** `deferSeek`: a group commit renders once after its last patch, or queued members repaint stale. */
224
- export function patchTween(target, selector, change, compositionId, deferSeek = false) {
239
+ export function patchTween(target, selector, change, compositionId, deferSeek = false, patchedTweens = []) {
225
240
  try {
226
241
  const kind = change.kind === "set" ? "set" : "keyframe";
227
242
  const resolved = resolveTween(target, selector, kind, compositionId, changeChannels(change));
@@ -230,12 +245,15 @@ export function patchTween(target, selector, change, compositionId, deferSeek =
230
245
  const { tween, timeline } = resolved;
231
246
  if (changeTouchesOpacity(change))
232
247
  restoreAuthoredOpacityForCapture(tween);
233
- if (!applyChange(tween, change))
248
+ const patched = applyChange(tween, change);
249
+ if (!patched)
234
250
  return false;
251
+ patchedTweens.push(patched);
235
252
  // Only the edited tween: a timeline-wide invalidate re-captures every from() against
236
253
  // the grading engine's opacity-0 hide, and graded elements vanish.
237
254
  if (change.kind !== "keyframe-rebuild")
238
255
  tween.invalidate?.();
256
+ markRestingScenesForRedraw(timelinesAbove(patched));
239
257
  if (!deferSeek)
240
258
  seekToCurrent(target, timeline);
241
259
  return true;
@@ -344,12 +362,16 @@ export function patchTweens({ patches, seek, endsDrafts }) {
344
362
  if (swapWaiting())
345
363
  return { patched: false };
346
364
  const renderAt = lastTweenPatch(patches);
365
+ const patchedTweens = [];
347
366
  const missed = patches.find(({ selector, change }, index) => {
348
367
  if (change.kind === "global-set")
349
368
  return applyGlobalSet(target, selector, change.props) === null;
350
- return !patchTween(target, selector, change, undefined, !(seek && index === renderAt));
369
+ const defer = !(seek && index === renderAt);
370
+ return !patchTween(target, selector, change, undefined, defer, patchedTweens);
351
371
  });
352
- if (missed === undefined && endsDrafts)
372
+ const shown = !seek || patchedTweens.every(renderedOnceReached);
373
+ const patched = missed === undefined && shown;
374
+ if (patched && endsDrafts)
353
375
  drawDrafts(endsDrafts);
354
- return { patched: missed === undefined };
376
+ return { patched };
355
377
  }
@@ -64,7 +64,6 @@ export declare function timelineKeys(scriptText: string): string[];
64
64
  export declare function scriptsRegistering(scripts: readonly HTMLScriptElement[], keys: readonly string[]): HTMLScriptElement[];
65
65
  export declare function restoreAuthoredStyle(style: CSSStyleDeclaration, authored: CSSStyleDeclaration | null, tweened: Set<string>): void;
66
66
  export declare function finalizeSoftReload(win: SoftReloadWindow, currentTime: number): void;
67
- export declare function previewMotionPathUrl(doc: Document, version?: string): string;
68
67
  export declare function swapWaiting(win?: SoftReloadWindow): boolean;
69
68
  /** Loads and registers MotionPathPlugin ahead of a re-run that needs it, unless the page is marked path-free. */
70
69
  export declare function preloadMotionPath(win?: SoftReloadWindow, doc?: Document): void;
@@ -1,7 +1,8 @@
1
1
  // A GSAP script edit re-runs the edited composition's script in the live preview, without a reload.
2
2
  // Studio runs it on a frame it can reach; a sealed frame runs it on itself through the editing port,
3
3
  // with the script Studio saved and the authored styles Studio read from that file.
4
- import { GSAP_BASE_URL_META, GSAP_PLUGIN_LOAD_ATTR, NO_PATH_TWEEN_META, motionPathPluginUrl, namesMotionPath, } from "../../gsapCdn.js";
4
+ import { GSAP_BASE_URL_META, GSAP_PLUGIN_LOAD_ATTR, NO_PATH_TWEEN_META, isGsapCoreUrl, previewMotionPathSrc, namesMotionPath, } from "../../gsapCdn.js";
5
+ import { INLINED_FILE_ATTR } from "../../compiler/scriptRuns.js";
5
6
  import { applyAuthoredInlineOpacity, readStampedAuthoredOpacity } from "../../colorGrading.js";
6
7
  import { escapeCssString } from "../editingElement.js";
7
8
  import { applyAuthoredTiming } from "../../studioPreviewMark.js";
@@ -226,9 +227,25 @@ export function finalizeSoftReload(win, currentTime) {
226
227
  if (wasPlaying)
227
228
  win.__player?.play?.();
228
229
  }
229
- export function previewMotionPathUrl(doc, version) {
230
- const baseUrl = doc.head.querySelector(`meta[name="${GSAP_BASE_URL_META}"]`)?.content;
231
- return motionPathPluginUrl(version, baseUrl);
230
+ const scriptFile = (script) => script.getAttribute("src") ?? script.getAttribute(INLINED_FILE_ATTR);
231
+ function pageGsapFile(doc) {
232
+ for (const script of doc.querySelectorAll(`script[src], script[${INLINED_FILE_ATTR}]`)) {
233
+ const file = scriptFile(script);
234
+ if (file && isGsapCoreUrl(file))
235
+ return file;
236
+ }
237
+ return null;
238
+ }
239
+ const gsapMirror = (doc) => doc.head.querySelector(`meta[name="${GSAP_BASE_URL_META}"]`)?.content;
240
+ function previewMotionPathUrl(doc, version, pageOwned = true) {
241
+ return previewMotionPathSrc({
242
+ gsapFile: pageGsapFile(doc),
243
+ mirror: gsapMirror(doc),
244
+ version,
245
+ documentUrl: doc.URL,
246
+ baseUrl: doc.baseURI,
247
+ pageOwned,
248
+ });
232
249
  }
233
250
  function runSuppressed(win, reload) {
234
251
  try {
@@ -291,8 +308,11 @@ function whenMotionPathLoaded(win, doc, ready, failed) {
291
308
  for (const [onReady, onFailed] of waiters)
292
309
  (loaded ? onReady : onFailed)();
293
310
  };
311
+ const src = previewMotionPathUrl(doc, win.gsap?.version);
312
+ if (!src)
313
+ return settle(false);
294
314
  const pluginScript = doc.createElement("script");
295
- pluginScript.src = previewMotionPathUrl(doc, win.gsap?.version);
315
+ pluginScript.src = src;
296
316
  pluginScript.setAttribute(GSAP_PLUGIN_LOAD_ATTR, "");
297
317
  pluginScript.onload = () => settle(Boolean(win.MotionPathPlugin));
298
318
  // Running the script without the plugin would leave a motionPath tween that cannot play.
@@ -340,6 +360,9 @@ export function preloadMotionPath(win = window, doc = document) {
340
360
  return;
341
361
  if (doc.querySelector(`meta[name="${NO_PATH_TWEEN_META}"]`))
342
362
  return;
363
+ // Ahead of any path tween, only a request that stays local: the document's origin or the host's mirror.
364
+ if (!previewMotionPathUrl(doc, win.gsap.version, false))
365
+ return;
343
366
  const register = () => win.MotionPathPlugin && win.gsap?.registerPlugin?.(win.MotionPathPlugin);
344
367
  whenMotionPathLoaded(win, doc, register, () => { });
345
368
  }
@@ -1,6 +1,6 @@
1
1
  // `watch-geometry`: the frame pushes the named elements' `geometry` fields once per animation frame,
2
2
  // stamped on the clock both windows share, until an empty list, the page hiding, or the parent's release.
3
- import { EDITING_ELEMENT_HANDLE, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_VALUE, } from "../editingElement.js";
3
+ import { EDITING_ELEMENT_HANDLE, MAX_DRAFT_PX, MAX_ELEMENT_ENTRIES, MAX_ELEMENT_VALUE, } from "../editingElement.js";
4
4
  import { swallow } from "../diagnostics.js";
5
5
  import { elementGeometry } from "../editingGeometry.js";
6
6
  export const MAX_WATCHED_GEOMETRY = 32;
@@ -28,12 +28,15 @@ const isSource = (value) => value === null ||
28
28
  finiteOrNull(value.declaredWidth) &&
29
29
  finiteOrNull(value.declaredHeight));
30
30
  const isClipPath = (value) => value === null || (typeof value === "string" && value.length <= MAX_ELEMENT_VALUE);
31
+ const isLayout = (value) => keysAre(value, "height,width") &&
32
+ [value.width, value.height].every((side) => finite(side) && side >= 0 && side <= MAX_DRAFT_PX);
31
33
  const isMembers = (value) => value === null ||
32
34
  (Array.isArray(value) && value.length <= MAX_ELEMENT_ENTRIES && value.every(isRect));
33
35
  function isGeometry(value) {
34
- if (!keysAre(value, "angle,clipPath,corners,members,rect,source,visible"))
36
+ if (!keysAre(value, "angle,clipPath,corners,layout,members,rect,source,visible"))
35
37
  return false;
36
38
  return (isRect(value.rect) &&
39
+ isLayout(value.layout) &&
37
40
  finite(value.angle) &&
38
41
  isCorners(value.corners) &&
39
42
  isSource(value.source) &&
@@ -60,6 +60,7 @@ export interface EditingElementMatch {
60
60
  export declare const MAX_ELEMENT_ENTRIES = 256;
61
61
  export declare const MAX_ELEMENT_TEXT = 10000;
62
62
  export declare const MAX_ELEMENT_VALUE = 2000;
63
+ export declare const MAX_DRAFT_PX = 100000;
63
64
  export declare const MAX_SOURCE_GROUPS = 64;
64
65
  export declare const MAX_DESCRIBE_HANDLES = 256;
65
66
  export declare const MAX_POINT_STACK = 64;
@@ -4,6 +4,7 @@ export const EDITING_ELEMENT_HANDLE = /^[0-9a-f]{16}:[1-9][0-9]{0,14}$/;
4
4
  export const MAX_ELEMENT_ENTRIES = 256;
5
5
  export const MAX_ELEMENT_TEXT = 10_000;
6
6
  export const MAX_ELEMENT_VALUE = 2_000;
7
+ export const MAX_DRAFT_PX = 100_000;
7
8
  export const MAX_SOURCE_GROUPS = 64;
8
9
  export const MAX_DESCRIBE_HANDLES = 256;
9
10
  export const MAX_POINT_STACK = 64;
@@ -19,6 +19,10 @@ export interface EditingElementBox {
19
19
  } | null;
20
20
  /** Inline `clip-path`, else the computed one; null when longer than MAX_ELEMENT_VALUE. */
21
21
  clipPath: string | null;
22
+ layout: {
23
+ width: number;
24
+ height: number;
25
+ };
22
26
  }
23
27
  export interface EditingElementGeometry extends EditingElementBox {
24
28
  /** It and every ancestor render: displayed, not hidden, not transparent. */
@@ -54,15 +54,8 @@ export function readElementTransformSnapshot(win, element, memo) {
54
54
  if (!DOMMatrixCtor)
55
55
  return null;
56
56
  const cs = win.getComputedStyle(element);
57
- // The corner math transforms points, so this keeps the full matrix, translation included.
58
- const ops = {
59
- identity: () => new DOMMatrixCtor(),
60
- fromTransform: (value) => new DOMMatrixCtor(value),
61
- fromRotate: (degrees) => new DOMMatrixCtor().rotateSelf(degrees),
62
- compose: (outer, inner) => outer.multiply(inner),
63
- };
64
57
  try {
65
- const matrix = composeElementTransform(element, ops, (node) => (node === element ? cs : win.getComputedStyle(node)), memo);
58
+ const matrix = composeElementTransform(element, DOMMatrixCtor, (node) => (node === element ? cs : win.getComputedStyle(node)), memo);
66
59
  return matrix ? { matrix, cs } : null;
67
60
  }
68
61
  catch {
@@ -139,20 +132,28 @@ function clipPathOf(element) {
139
132
  window.getComputedStyle(element).getPropertyValue("clip-path").trim();
140
133
  return value.length <= MAX_ELEMENT_VALUE ? value : null;
141
134
  }
135
+ function layoutOf(element) {
136
+ const { offsetWidth = 0, offsetHeight = 0 } = element;
137
+ return { width: offsetWidth, height: offsetHeight };
138
+ }
142
139
  const finiteCorners = (corners) => corners && Object.values(corners).every((p) => Number.isFinite(p.x) && Number.isFinite(p.y))
143
140
  ? corners
144
141
  : null;
142
+ const turnedMirroredOrSkewed = ({ a, b, c, d }) => b !== 0 || c !== 0 || a < 0 || d < 0;
145
143
  export function boxOf(element, memo) {
146
144
  const transform = readElementTransformSnapshot(window, element, memo);
147
145
  const turned = transform ? rotationDegreesFromMatrix(transform.matrix) : 0;
148
146
  const angle = Math.abs(turned) < ROTATION_GATE_EPSILON_DEG ? 0 : turned;
149
- const corners = angle && transform ? elementCornerPoints(window, element, transform) : null;
147
+ const corners = transform && turnedMirroredOrSkewed(transform.matrix)
148
+ ? elementCornerPoints(window, element, transform)
149
+ : null;
150
150
  return {
151
151
  rect: rectOf(element),
152
152
  angle,
153
153
  corners: finiteCorners(corners),
154
154
  source: sourceOf(element),
155
155
  clipPath: clipPathOf(element),
156
+ layout: layoutOf(element),
156
157
  };
157
158
  }
158
159
  export const MAX_SNAP_TARGETS = 80;
@@ -2,11 +2,6 @@ import type { EditingElementHandle } from "./editingElement.js";
2
2
  import { type CssRotationStart } from "./editing/cssRotation.js";
3
3
  import { type EditingElementBox, type EditingElementGeometry } from "./editingGeometry.js";
4
4
  export interface EditingGestureStart extends EditingElementGeometry {
5
- /** The transform-free border box a resize grows from. */
6
- layout: {
7
- width: number;
8
- height: number;
9
- };
10
5
  /** Frame px its centre moves per px of translate, columns `a, b` (x) and `c, d` (y); null when it does not move measurably. */
11
6
  move: {
12
7
  a: number;
@@ -134,14 +134,11 @@ export function gestureStart(handles) {
134
134
  const element = pressed[i];
135
135
  if (!geometry || !isStylableElement(element))
136
136
  return null;
137
- const { offsetWidth = 0, offsetHeight = 0 } = element;
138
- const layout = { width: offsetWidth, height: offsetHeight };
139
137
  const rotation = gsapRotation(element);
140
138
  return {
141
139
  ...geometry,
142
- layout,
143
140
  move: measureMoveResponse(element),
144
- grow: measureGrowResponse(element, layout),
141
+ grow: measureGrowResponse(element, geometry.layout),
145
142
  gsap: gsapPosition(element),
146
143
  gsapRotation: rotation,
147
144
  cssRotation: rotation === null ? readCssRotationStart(element) : null,
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import type { RestoreAttributesParams } from "./editing/restoreAttributes.js";
13
13
  import { type EditingGeometryEvent, type WatchGeometryParams } from "./editing/watchGeometry.js";
14
- import { type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch } from "./editingElement.js";
14
+ import { MAX_DRAFT_PX, type EditingElementDescription, type EditingElementHandle, type EditingElementHit, type EditingElementMatch } from "./editingElement.js";
15
15
  import type { EditingElementBox, EditingElementGeometry } from "./editingGeometry.js";
16
16
  import type { EditingGestureStart } from "./editingGestureStart.js";
17
17
  import type { GsapSnapshot } from "./editing/gsapSnapshot.js";
@@ -41,7 +41,6 @@ export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
41
41
  export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./editing/gsapSnapshotLimits.js";
42
42
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, type EditingLocalPointer, type EditingViewport, } from "./editingTargets.js";
43
43
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, type EditingLayer, type EditingStackingSibling, type LayerKind, } from "./editingLayers.js";
44
- export { composeElementTransform, individualRotateDegrees, type PlanarTransformOps, } from "./elementTransform.js";
45
44
  export declare const EDITING_PROTOCOL_VERSION: 1;
46
45
  /** Parent to frame, on the window: asks the runtime for the port. */
47
46
  export declare const EDITING_CONNECT = "editing-connect";
@@ -59,7 +58,7 @@ export interface EditingRuntimeSnapshot {
59
58
  /** `[childId, parentId]` for each nested clip in the runtime's clip tree. */
60
59
  clipParents: Array<[string, string]>;
61
60
  }
62
- export declare const MAX_DRAFT_PX = 100000;
61
+ export { MAX_DRAFT_PX };
63
62
  export declare const MAX_DRAFT_DEG = 36000;
64
63
  export declare const MAX_WATCHED_KEYS = 32;
65
64
  /** A keystroke the frame forwards for `watch-keys`, as an unasked port message with no id. */
@@ -1,5 +1,5 @@
1
1
  import { geometryEvent, parseWatchGeometry, } from "./editing/watchGeometry.js";
2
- import { EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, } from "./editingElement.js";
2
+ import { EDITING_ELEMENT_HANDLE, MAX_DESCRIBE_HANDLES, MAX_DRAFT_PX, } from "./editingElement.js";
3
3
  import { parseGsapSet } from "./editing/gsapSet.js";
4
4
  import { parsePatchTweensRequest } from "./editing/patchTween.js";
5
5
  import { parseDraftEnd } from "./editingDraftEnd.js";
@@ -24,7 +24,6 @@ export { MAX_CAPTION_TRANSFORM } from "./editing/captionTransform.js";
24
24
  export { MAX_SNAPSHOT_CHANNELS, MAX_SNAPSHOT_FIELDS, MAX_SNAPSHOT_TARGETS, MAX_SNAPSHOT_TEXT, MAX_SNAPSHOT_TWEENS, MAX_VARS_DEPTH, } from "./editing/gsapSnapshotLimits.js";
25
25
  export { compositionPoint, coversComposition, isDomLayerElement, isInspectableLayerElement, pointerTarget, pointerTargets, resolveAllVisualDomEditTargets, resolveLayerSelector, } from "./editingTargets.js";
26
26
  export { elementZIndex, hasOnlyFormattingChildren, NON_PAINTING_TAGS, isCompositionHost, layerKindOf, } from "./editingLayers.js";
27
- export { composeElementTransform, individualRotateDegrees, } from "./elementTransform.js";
28
27
  export const EDITING_PROTOCOL_VERSION = 1;
29
28
  /** Parent to frame, on the window: asks the runtime for the port. */
30
29
  export const EDITING_CONNECT = "editing-connect";
@@ -75,7 +74,7 @@ export const EDITING_REQUEST_KINDS = [
75
74
  "text-edit",
76
75
  "serve-paused-frames",
77
76
  ];
78
- export const MAX_DRAFT_PX = 100_000;
77
+ export { MAX_DRAFT_PX };
79
78
  export const MAX_DRAFT_DEG = 36_000;
80
79
  export const MAX_WATCHED_KEYS = 32;
81
80
  export function isPlainRecord(value) {
@@ -1,60 +1,17 @@
1
1
  /**
2
- * One walk from an element up to its composition root, composing the transform
3
- * it actually paints under.
4
- *
5
- * The overlay measures an element's angle in two places — the selection box and
6
- * the crop frame — and they need different arithmetic: one works in DOMMatrix
7
- * because it goes on to transform corner points, the other in plain 2D
8
- * components because it only needs an angle and a scale. What they must never
9
- * differ on is *which* transforms count and in what order, because when they
10
- * disagree the chrome disagrees with itself: the selection box drawn at one
11
- * angle and the crop outline at another, on the same element.
12
- *
13
- * So the walk lives here once and takes the arithmetic as a parameter. Adding
14
- * an individual property CSS grew later — `translate`, `scale` — means adding
15
- * one step here and one method to each algebra, rather than finding both walks
16
- * and hoping.
17
- */
18
- /**
19
- * The arithmetic the walk needs, whatever the caller's matrix type is.
20
- *
21
- * `fromTransform` returns null for a transform the caller cannot use — a
22
- * perspective matrix, say — which aborts the walk rather than composing a
23
- * matrix that describes something other than what is painted.
2
+ * The one matrix every overlay measure reads: each node's `rotate`, `scale` and `transform`, in CSS's
3
+ * order, parsed and composed by the browser's `DOMMatrix`; null once a node or the chain leaves the plane. `translate`
4
+ * never changes a shape (callers re-anchor to the measured box) and `DOMMatrix` refuses its `50%`.
24
5
  */
25
- export interface PlanarTransformOps<M> {
26
- identity(): M;
27
- fromTransform(value: string): M | null;
28
- fromRotate(degrees: number): M;
29
- /** `outer` applied around `inner`, as an ancestor composes over a child. */
30
- compose(outer: M, inner: M): M;
31
- }
6
+ /** Computed `rotate` (`45deg`, `x 30deg`, `1 1 0 30deg`) as its transform function; "" for none. */
7
+ export declare function rotateFunction(value: string | undefined): string;
8
+ /** Computed `scale` (`2`, `2 3`, `1 1 2`) as its transform function; "" for none. */
9
+ export declare function scaleFunction(value: string | undefined): string;
32
10
  /**
33
- * The planar rotation in the CSS `rotate` property, in degrees.
34
- *
35
- * Computes to `none`, an angle (`-22deg`), or an axis plus an angle
36
- * (`0 0 1 -22deg`). Only a rotation about z stays in the overlay's plane; any
37
- * other axis is 3D and reports 0, which leaves the caller on its axis-aligned
38
- * fallback rather than drawing a box at a plausible-looking wrong angle.
39
- */
40
- export declare function individualRotateDegrees(value: string | undefined): number;
41
- /**
42
- * The element's transform composed with every ancestor's, up to the composition
43
- * root.
44
- *
45
- * Within a node, CSS applies the individual properties before `transform`, so
46
- * `rotate` composes on the left of it. Between nodes, an ancestor applies
47
- * outside its child. Null means some node's transform was unusable and the
48
- * caller should fall back rather than guess.
49
- *
50
- * `memo` holds each node's COMPOSED chain, for a caller walking many elements
51
- * in one synchronous pass.
11
+ * The element's transform composed with every ancestor's, up to the composition root; an ancestor
12
+ * applies outside its child. Null when some node's transform cannot be parsed, so the caller falls back.
52
13
  *
53
- * A chain is `chain(parent)` composed with the node's own, so siblings share
54
- * everything above them and the whole tree costs one style read and one
55
- * compose per node instead of one per node PER DESCENDANT. Valid only for the
56
- * length of one pass, which is why the caller owns it: nothing here writes to
57
- * the DOM, so nothing can move under it, and it is dropped before anything
58
- * else runs. Omitted, every call composes its own chain from scratch.
14
+ * `memo` holds each node's composed chain for a caller walking many elements in one synchronous pass:
15
+ * siblings share everything above them. Valid only for that pass, which is why the caller owns it.
59
16
  */
60
- export declare function composeElementTransform<M>(element: HTMLElement, ops: PlanarTransformOps<M>, getStyle: (node: HTMLElement) => CSSStyleDeclaration | null, memo?: Map<HTMLElement, M | null>): M | null;
17
+ export declare function composeElementTransform(element: HTMLElement, Matrix: typeof DOMMatrix, getStyle: (node: HTMLElement) => CSSStyleDeclaration | null, memo?: Map<HTMLElement, DOMMatrix | null>): DOMMatrix | null;
@@ -1,86 +1,62 @@
1
1
  /**
2
- * One walk from an element up to its composition root, composing the transform
3
- * it actually paints under.
4
- *
5
- * The overlay measures an element's angle in two places — the selection box and
6
- * the crop frame — and they need different arithmetic: one works in DOMMatrix
7
- * because it goes on to transform corner points, the other in plain 2D
8
- * components because it only needs an angle and a scale. What they must never
9
- * differ on is *which* transforms count and in what order, because when they
10
- * disagree the chrome disagrees with itself: the selection box drawn at one
11
- * angle and the crop outline at another, on the same element.
12
- *
13
- * So the walk lives here once and takes the arithmetic as a parameter. Adding
14
- * an individual property CSS grew later — `translate`, `scale` — means adding
15
- * one step here and one method to each algebra, rather than finding both walks
16
- * and hoping.
2
+ * The one matrix every overlay measure reads: each node's `rotate`, `scale` and `transform`, in CSS's
3
+ * order, parsed and composed by the browser's `DOMMatrix`; null once a node or the chain leaves the plane. `translate`
4
+ * never changes a shape (callers re-anchor to the measured box) and `DOMMatrix` refuses its `50%`.
17
5
  */
18
6
  /** The composition's own root; the walk stops there rather than at the document. */
19
7
  const COMPOSITION_ROOT_ATTR = "data-composition-id";
20
- /**
21
- * The planar rotation in the CSS `rotate` property, in degrees.
22
- *
23
- * Computes to `none`, an angle (`-22deg`), or an axis plus an angle
24
- * (`0 0 1 -22deg`). Only a rotation about z stays in the overlay's plane; any
25
- * other axis is 3D and reports 0, which leaves the caller on its axis-aligned
26
- * fallback rather than drawing a box at a plausible-looking wrong angle.
27
- */
28
- export function individualRotateDegrees(value) {
29
- if (!value || value === "none")
30
- return 0;
31
- const parts = value.trim().split(/\s+/);
32
- const angle = parts.at(-1);
33
- if (!angle?.endsWith("deg"))
34
- return 0;
35
- if (parts.length === 4) {
36
- const [x, y, z] = parts;
37
- if (Number(x) !== 0 || Number(y) !== 0 || Math.abs(Number(z)) !== 1)
38
- return 0;
39
- const deg = Number.parseFloat(angle);
40
- return Number.isFinite(deg) ? deg * Math.sign(Number(z)) : 0;
41
- }
42
- if (parts.length !== 1)
43
- return 0;
44
- const deg = Number.parseFloat(angle);
45
- return Number.isFinite(deg) ? deg : 0;
8
+ /** Computed `rotate` (`45deg`, `x 30deg`, `1 1 0 30deg`) as its transform function; "" for none. */
9
+ export function rotateFunction(value) {
10
+ const parts = value && value !== "none" ? value.trim().split(/\s+/) : [];
11
+ const angle = parts.pop();
12
+ if (!angle)
13
+ return "";
14
+ if (parts.length === 0)
15
+ return `rotate(${angle})`;
16
+ if (parts.length === 1)
17
+ return `rotate${parts[0].toUpperCase()}(${angle})`;
18
+ return `rotate3d(${parts.join(", ")}, ${angle})`;
46
19
  }
47
- /** One node's own contribution, with the individual properties applied before
48
- * `transform` the way CSS does. Null when the node's transform is unusable. */
49
- function ownNodeTransform(node, ops, getStyle) {
20
+ /** Computed `scale` (`2`, `2 3`, `1 1 2`) as its transform function; "" for none. */
21
+ export function scaleFunction(value) {
22
+ const parts = value && value !== "none" ? value.trim().split(/\s+/) : [];
23
+ if (parts.length === 0)
24
+ return "";
25
+ return `${parts.length === 3 ? "scale3d" : "scale"}(${parts.join(", ")})`;
26
+ }
27
+ function ownNodeTransform(node, Matrix, getStyle) {
50
28
  const style = getStyle(node);
51
- if (!style)
29
+ if (!style || inThreeDContext(node, getStyle))
52
30
  return null;
53
- const transform = style.transform;
54
- const own = transform && transform !== "none" ? ops.fromTransform(transform) : ops.identity();
55
- if (!own)
31
+ const transform = style.transform && style.transform !== "none" ? style.transform : "";
32
+ const list = [rotateFunction(style.rotate), scaleFunction(style.scale), transform];
33
+ try {
34
+ const own = new Matrix(list.filter(Boolean).join(" "));
35
+ return planar(own) ? own : null;
36
+ }
37
+ catch {
56
38
  return null;
57
- const spin = individualRotateDegrees(style.rotate);
58
- return spin === 0 ? own : ops.compose(ops.fromRotate(spin), own);
39
+ }
59
40
  }
41
+ /** A parent's `perspective` or `preserve-3d` projects its children in ways a matrix product does not show. */
42
+ function inThreeDContext(node, getStyle) {
43
+ const parent = node.parentElement && getStyle(node.parentElement);
44
+ if (!parent)
45
+ return false;
46
+ return ((!!parent.perspective && parent.perspective !== "none") ||
47
+ parent.transformStyle === "preserve-3d");
48
+ }
49
+ /** Keeps the layer's plane flat and unprojected; anything else is left to the box the browser paints. */
50
+ const planar = (m) => [m.m13, m.m23, m.m14, m.m24, m.m44 - 1].every((v) => Math.abs(v) < 1e-9);
60
51
  /**
61
- * The element's transform composed with every ancestor's, up to the composition
62
- * root.
63
- *
64
- * Within a node, CSS applies the individual properties before `transform`, so
65
- * `rotate` composes on the left of it. Between nodes, an ancestor applies
66
- * outside its child. Null means some node's transform was unusable and the
67
- * caller should fall back rather than guess.
68
- *
69
- * `memo` holds each node's COMPOSED chain, for a caller walking many elements
70
- * in one synchronous pass.
52
+ * The element's transform composed with every ancestor's, up to the composition root; an ancestor
53
+ * applies outside its child. Null when some node's transform cannot be parsed, so the caller falls back.
71
54
  *
72
- * A chain is `chain(parent)` composed with the node's own, so siblings share
73
- * everything above them and the whole tree costs one style read and one
74
- * compose per node instead of one per node PER DESCENDANT. Valid only for the
75
- * length of one pass, which is why the caller owns it: nothing here writes to
76
- * the DOM, so nothing can move under it, and it is dropped before anything
77
- * else runs. Omitted, every call composes its own chain from scratch.
55
+ * `memo` holds each node's composed chain for a caller walking many elements in one synchronous pass:
56
+ * siblings share everything above them. Valid only for that pass, which is why the caller owns it.
78
57
  */
79
- export function composeElementTransform(element, ops, getStyle, memo) {
58
+ export function composeElementTransform(element, Matrix, getStyle, memo) {
80
59
  const pending = [];
81
- // `undefined` means nothing on the way up was already composed, so the chain
82
- // starts from identity. A memoized `null` is an answer, not a miss: some node
83
- // above carries a transform this algebra cannot represent.
84
60
  let above;
85
61
  for (let node = element; node; node = node.parentElement) {
86
62
  above = memo?.get(node);
@@ -90,14 +66,13 @@ export function composeElementTransform(element, ops, getStyle, memo) {
90
66
  if (node.hasAttribute(COMPOSITION_ROOT_ATTR))
91
67
  break;
92
68
  }
93
- let acc = above === undefined ? ops.identity() : above;
69
+ let acc = above === undefined ? new Matrix() : above;
94
70
  for (let i = pending.length - 1; i >= 0; i -= 1) {
95
71
  const node = pending[i];
96
72
  if (acc !== null) {
97
- const own = ownNodeTransform(node, ops, getStyle);
98
- // The ancestors' chain is the OUTER of the pair, as an ancestor applies
99
- // around its child.
100
- acc = own === null ? null : ops.compose(acc, own);
73
+ const own = ownNodeTransform(node, Matrix, getStyle);
74
+ const composed = own && acc.multiply(own);
75
+ acc = composed && planar(composed) ? composed : null;
101
76
  }
102
77
  memo?.set(node, acc);
103
78
  }