@hyperframes/studio 0.9.40 → 0.9.41

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 (56) hide show
  1. package/dist/assets/{codec-BPK_2CLL.js → codec-B_mpbc4w.js} +1 -1
  2. package/dist/assets/{hyperframes-player-D7qTTDIp.js → hyperframes-player-Dvi3I_mv.js} +1 -1
  3. package/dist/assets/{index-CdA00Ybn.js → index-B5ExwsOp.js} +146 -146
  4. package/dist/assets/{index-QS-DuxAU.js → index-BrFm9Y5k.js} +1 -1
  5. package/dist/assets/{pausedVideoDecoder-Byzz98Gb.js → pausedVideoDecoder-MHQ57yZ6.js} +1 -1
  6. package/dist/{chunk-KF6YVXJP.js → chunk-4QQMX4BX.js} +6 -3
  7. package/dist/{chunk-VZ5MD32A.js → chunk-GVW7AU57.js} +190 -254
  8. package/dist/{chunk-AV2PV7NE.js → chunk-VHV2ZDKY.js} +4 -40
  9. package/dist/{domEditingLayers-4KRREI5C.js → domEditingLayers-SA5KLSSS.js} +4 -2
  10. package/dist/index.d.ts +4 -0
  11. package/dist/index.html +1 -1
  12. package/dist/index.js +898 -551
  13. package/dist/player.js +2 -2
  14. package/package.json +8 -8
  15. package/src/components/editor/DomEditOverlay.tsx +3 -15
  16. package/src/components/editor/clickAfterPreventedPress.test.tsx +17 -1
  17. package/src/components/editor/domEditOverlayBasis.ts +7 -2
  18. package/src/components/editor/domEditOverlayCrop.test.ts +1 -1
  19. package/src/components/editor/domEditOverlayCrop.ts +17 -3
  20. package/src/components/editor/domEditOverlayGeometry.ts +64 -139
  21. package/src/components/editor/domEditSelectionRules.ts +138 -0
  22. package/src/components/editor/domEditing.test.ts +6 -28
  23. package/src/components/editor/domEditingDom.preview.test.ts +3 -3
  24. package/src/components/editor/domEditingDom.ts +3 -76
  25. package/src/components/editor/domEditingElement.ts +19 -240
  26. package/src/components/editor/domEditingGroups.ts +0 -31
  27. package/src/components/editor/domEditingLayers.ts +95 -100
  28. package/src/components/editor/domEditingRootLayer.ts +35 -30
  29. package/src/components/editor/domEditingTypes.ts +4 -0
  30. package/src/components/editor/previewGestureStarts.ts +73 -10
  31. package/src/components/editor/previewOverlayRects.test.ts +316 -0
  32. package/src/components/editor/previewOverlayRects.ts +123 -0
  33. package/src/components/editor/previewPointerTargets.test.ts +260 -0
  34. package/src/components/editor/previewSelection.test.ts +481 -0
  35. package/src/components/editor/previewSelection.ts +472 -0
  36. package/src/components/editor/probeSourceElement.ts +19 -1
  37. package/src/components/editor/propertyPanelFill.tsx +5 -1
  38. package/src/components/editor/useDomEditOverlayRects.ts +80 -1
  39. package/src/components/editor/useInlineTextEditing.tsx +1 -6
  40. package/src/hooks/domSelectionTestHarness.ts +1 -1
  41. package/src/hooks/useDomEditSession.test.tsx +23 -1
  42. package/src/hooks/useDomEditSession.ts +2 -1
  43. package/src/hooks/useDomSelection.ts +61 -47
  44. package/src/hooks/useGsapSelectionHandlers.test.tsx +17 -0
  45. package/src/hooks/useGsapSelectionHandlers.ts +2 -1
  46. package/src/hooks/usePreviewInteraction.test.ts +10 -2
  47. package/src/hooks/usePreviewInteraction.ts +5 -4
  48. package/src/hooks/useStudioSelectionPublisher.test.tsx +50 -0
  49. package/src/hooks/useStudioSelectionPublisher.ts +9 -7
  50. package/src/player/lib/previewChannel.ts +4 -3
  51. package/src/player/lib/previewElements.ts +112 -3
  52. package/src/styles/hex-baseline.json +1 -2
  53. package/src/utils/studioHelpers.ts +0 -13
  54. package/src/utils/studioPreviewHelpers.test.ts +8 -8
  55. package/src/utils/studioPreviewHelpers.ts +26 -242
  56. package/src/components/editor/domEditOverlayTransform.ts +0 -126
@@ -1,5 +1,5 @@
1
1
  import { isClipHiddenByRuntime, PREVIEW_ONLY_ATTRS } from "@hyperframes/core/studio-preview-mark";
2
- import { knownSourceAnswer, probeSourceElement, type ProbeTarget } from "./probeSourceElement";
2
+ import { existsInSourceFile } from "./probeSourceElement";
3
3
  import { isAudibleVideoNode } from "../../player/lib/timelineElementHelpers";
4
4
  import type { PatchOperation } from "../../utils/sourcePatcher";
5
5
  import {
@@ -7,7 +7,12 @@ import {
7
7
  resolveEditingSections,
8
8
  type EditableElementFacts,
9
9
  } from "@hyperframes/core/editing";
10
- import { groupScopedLayerRoots, resolveGroupCapture } from "./domEditingGroups";
10
+ import { groupScopedLayerRoots } from "./domEditingGroups";
11
+ import {
12
+ chainLocked,
13
+ selectionTargetIndex,
14
+ type SelectionChainReader,
15
+ } from "./domEditSelectionRules";
11
16
  import type {
12
17
  DomEditCapabilities,
13
18
  DomEditContextOptions,
@@ -18,7 +23,6 @@ import type {
18
23
  import {
19
24
  buildElementLabel,
20
25
  buildStableSelector,
21
- findClosestByAttribute,
22
26
  getCuratedComputedStyles,
23
27
  getDataAttributes,
24
28
  getInlineStyles,
@@ -27,11 +31,7 @@ import {
27
31
  isEditableTextLeaf,
28
32
  isHtmlElement,
29
33
  } from "./domEditingDom";
30
- import {
31
- findElementForSelection,
32
- getSelectionCandidate,
33
- isDomLayerElement,
34
- } from "./domEditingElement";
34
+ import { findElementForSelection, isDomLayerElement } from "./domEditingElement";
35
35
  import { isCompositionRootLayer } from "./domEditingRootLayer";
36
36
  import { withSelectorIndexPass } from "../../utils/sourceScopedSelectorIndex";
37
37
  import { type DomEditLayerWalkCache, readDomEditLayerWalkEntry } from "./domEditLayerWalkCache";
@@ -206,7 +206,7 @@ export function buildTextFieldChildLocator(
206
206
  };
207
207
  }
208
208
 
209
- function capabilityFacts(geometry: {
209
+ export function capabilityFacts(geometry: {
210
210
  hasStableTarget: boolean;
211
211
  tag: string;
212
212
  inlineStyles: Record<string, string>;
@@ -248,7 +248,7 @@ export function domEditSelectionToFacts(
248
248
  hasEditableText: selection.textFields.length > 0,
249
249
  hasTimingStart: selection.dataAttributes.start != null,
250
250
  animationCount,
251
- hasAudio: isAudibleVideoNode(selection.element),
251
+ hasAudio: selection.hasAudio ?? isAudibleVideoNode(selection.element),
252
252
  };
253
253
  }
254
254
 
@@ -296,99 +296,94 @@ export async function resolveDomEditSelection(
296
296
  ): Promise<DomEditSelection | null> {
297
297
  if (!startEl) return null;
298
298
  const doc = startEl.ownerDocument;
299
-
300
- let capture = options.exactTarget
301
- ? ({ kind: "unit", element: startEl } as const)
302
- : resolveGroupCapture(startEl, options.activeGroupElement ?? null);
303
- if (capture.kind === "out-of-scope") {
304
- // Drill-in is non-sticky: clicking/hovering OUTSIDE the drilled-into group
305
- // exits it and resolves the target normally, rather than selecting nothing
306
- // (which felt like "can't select anything" once you'd drilled in).
307
- capture = resolveGroupCapture(startEl, null);
308
- }
309
- let current: HTMLElement | null =
310
- capture.kind === "unit" ? capture.element : getSelectionCandidate(startEl, options);
311
- while (current && current !== doc.body && current !== doc.documentElement) {
312
- const selector = buildStableSelector(current);
313
- const hfId = readHfId(current);
314
- if (!selector && !hfId) {
315
- current = current.parentElement;
316
- continue;
317
- }
318
-
319
- const { sourceFile, compositionPath } = getSourceFileForElement(
320
- current,
321
- options.activeCompositionPath,
322
- );
323
- const selectorIndex = selector
324
- ? getSelectorIndex(doc, current, selector, sourceFile, options.activeCompositionPath)
325
- : undefined;
326
- const compositionSrc =
327
- current.getAttribute("data-composition-src") ??
328
- current.getAttribute("data-composition-file") ??
329
- undefined;
330
- const inlineStyles = getInlineStyles(current);
331
- const computedStyles = getCuratedComputedStyles(current);
332
- const isCompositionRoot =
333
- (current.hasAttribute("data-composition-id") && !compositionSrc) ||
334
- isCompositionRootLayer(current, doc, computedStyles);
335
- const textFields = collectDomEditTextFields(current);
336
- const isInsideLocked = Boolean(findClosestByAttribute(current, ["data-timeline-locked"]));
337
- const probeTarget: ProbeTarget = {};
338
- if (current.id) probeTarget.id = current.id;
339
- if (hfId) probeTarget.hfId = hfId;
340
- if (selector) probeTarget.selector = selector;
341
- if (selectorIndex != null) probeTarget.selectorIndex = selectorIndex;
342
- let existsInSource = knownSourceAnswer(options.previous, current, sourceFile, probeTarget);
343
- const probe = existsInSource === undefined && !options.skipSourceProbe;
344
- if (probe && options.projectId && (current.id || selector || hfId)) {
345
- existsInSource = await probeSourceElement(options.projectId, sourceFile, probeTarget);
346
- }
347
- const capabilities = resolveEditingAffordances(
348
- capabilityFacts({
349
- hasStableTarget: Boolean(selector || hfId),
350
- tag: current.tagName.toLowerCase(),
351
- inlineStyles,
352
- computedStyles,
353
- isCompositionHost: Boolean(compositionSrc),
354
- isCompositionRoot,
355
- isInsideLockedComposition: isInsideLocked,
356
- isMasterView: options.isMasterView,
357
- existsInSource: existsInSource ?? true,
358
- }),
359
- ).capabilities;
360
- const rect = current.getBoundingClientRect();
361
-
362
- return {
363
- element: current,
364
- id: current.id || undefined,
365
- hfId,
366
- selector,
367
- selectorIndex,
368
- sourceFile,
369
- compositionPath,
370
- compositionSrc,
371
- isCompositionHost: Boolean(compositionSrc),
372
- isInsideLockedComposition: isInsideLocked,
373
- label: buildElementLabel(current),
374
- tagName: current.tagName.toLowerCase(),
375
- boundingBox: {
376
- x: rect.left,
377
- y: rect.top,
378
- width: rect.width,
379
- height: rect.height,
380
- },
381
- textContent: current.textContent?.trim() || null,
382
- dataAttributes: getDataAttributes(current),
299
+ const chain: HTMLElement[] = [];
300
+ for (let node: HTMLElement | null = startEl; node; node = node.parentElement) chain.push(node);
301
+ const read = liveChainReader(doc);
302
+ const active = options.activeGroupElement ?? null;
303
+ const index = selectionTargetIndex(chain, read, {
304
+ exactTarget: options.exactTarget,
305
+ preferClipAncestor: options.preferClipAncestor,
306
+ activeGroupIndex: active ? chain.indexOf(active) : null,
307
+ });
308
+ if (index === null) return null;
309
+ const current = chain[index]!;
310
+ const selector = buildStableSelector(current);
311
+ const hfId = readHfId(current);
312
+ const { sourceFile, compositionPath } = getSourceFileForElement(
313
+ current,
314
+ options.activeCompositionPath,
315
+ );
316
+ const selectorIndex = selector
317
+ ? getSelectorIndex(doc, current, selector, sourceFile, options.activeCompositionPath)
318
+ : undefined;
319
+ const compositionSrc =
320
+ current.getAttribute("data-composition-src") ??
321
+ current.getAttribute("data-composition-file") ??
322
+ undefined;
323
+ const inlineStyles = getInlineStyles(current);
324
+ const computedStyles = getCuratedComputedStyles(current);
325
+ const isCompositionRoot =
326
+ (current.hasAttribute("data-composition-id") && !compositionSrc) ||
327
+ isCompositionRootLayer(current, doc, computedStyles);
328
+ const textFields = collectDomEditTextFields(current);
329
+ const isInsideLocked = chainLocked(chain, read, index);
330
+ const existsInSource = await existsInSourceFile(
331
+ options.previous,
332
+ current,
333
+ sourceFile,
334
+ { id: current.id, hfId, selector, selectorIndex },
335
+ options,
336
+ );
337
+ const capabilities = resolveEditingAffordances(
338
+ capabilityFacts({
339
+ hasStableTarget: Boolean(selector || hfId),
340
+ tag: current.tagName.toLowerCase(),
383
341
  inlineStyles,
384
342
  computedStyles,
385
- textFields,
386
- capabilities,
387
- existsInSource,
388
- };
389
- }
343
+ isCompositionHost: Boolean(compositionSrc),
344
+ isCompositionRoot,
345
+ isInsideLockedComposition: isInsideLocked,
346
+ isMasterView: options.isMasterView,
347
+ existsInSource: existsInSource ?? true,
348
+ }),
349
+ ).capabilities;
350
+ const rect = current.getBoundingClientRect();
390
351
 
391
- return null;
352
+ return {
353
+ element: current,
354
+ id: current.id || undefined,
355
+ hfId,
356
+ selector,
357
+ selectorIndex,
358
+ sourceFile,
359
+ compositionPath,
360
+ compositionSrc,
361
+ isCompositionHost: Boolean(compositionSrc),
362
+ isInsideLockedComposition: isInsideLocked,
363
+ label: buildElementLabel(current),
364
+ tagName: current.tagName.toLowerCase(),
365
+ boundingBox: {
366
+ x: rect.left,
367
+ y: rect.top,
368
+ width: rect.width,
369
+ height: rect.height,
370
+ },
371
+ textContent: current.textContent?.trim() || null,
372
+ dataAttributes: getDataAttributes(current),
373
+ inlineStyles,
374
+ computedStyles,
375
+ textFields,
376
+ capabilities,
377
+ existsInSource,
378
+ };
379
+ }
380
+
381
+ function liveChainReader(doc: Document): SelectionChainReader<HTMLElement> {
382
+ return {
383
+ attr: (el, name) => el.getAttribute(name),
384
+ selector: buildStableSelector,
385
+ isDocumentRoot: (el) => el === doc.body || el === doc.documentElement,
386
+ };
392
387
  }
393
388
 
394
389
  export async function refreshDomEditSelection(
@@ -12,32 +12,36 @@ function approximatelyEqual(a: number, b: number) {
12
12
  return Math.abs(a - b) <= COMPOSITION_ROOT_LAYER_EPSILON_PX;
13
13
  }
14
14
 
15
- function getCompositionRootBounds(doc: Document) {
16
- const root =
17
- doc.querySelector<HTMLElement>("[data-composition-id]") ?? doc.documentElement ?? null;
18
- const rootWidth = readPositiveDimension(root?.getAttribute("data-width") ?? null);
19
- const rootHeight = readPositiveDimension(root?.getAttribute("data-height") ?? null);
20
- if (!root || !rootWidth || !rootHeight) return null;
21
- return { rect: root.getBoundingClientRect(), width: rootWidth, height: rootHeight };
15
+ interface Box {
16
+ left: number;
17
+ top: number;
18
+ width: number;
19
+ height: number;
22
20
  }
23
21
 
24
- function getRenderedLayerSize(element: HTMLElement, computedStyles: Record<string, string>) {
25
- const rect = element.getBoundingClientRect();
26
- const width = rect.width || parsePx(computedStyles.width);
27
- const height = rect.height || parsePx(computedStyles.height);
28
- return width && height ? { width, height } : null;
22
+ export interface CompositionRootFacts {
23
+ rect: Box;
24
+ width: string | null;
25
+ height: string | null;
29
26
  }
30
27
 
31
- function matchesCompositionRootBounds(
32
- elementRect: DOMRect,
33
- elementSize: { width: number; height: number },
34
- rootBounds: { rect: DOMRect; width: number; height: number },
35
- ) {
36
- return (
37
- approximatelyEqual(elementRect.left, rootBounds.rect.left) &&
38
- approximatelyEqual(elementRect.top, rootBounds.rect.top) &&
39
- approximatelyEqual(elementSize.width, rootBounds.width) &&
40
- approximatelyEqual(elementSize.height, rootBounds.height)
28
+ export function coversCompositionRoot(
29
+ layer: { rect: Box; computedStyles: Record<string, string> },
30
+ root: CompositionRootFacts | null,
31
+ ): boolean {
32
+ if (isExplicitFullBleedLayer(layer.computedStyles)) return false;
33
+ const rootWidth = readPositiveDimension(root?.width ?? null);
34
+ const rootHeight = readPositiveDimension(root?.height ?? null);
35
+ if (!root || !rootWidth || !rootHeight) return false;
36
+ const width = layer.rect.width || parsePx(layer.computedStyles.width);
37
+ const height = layer.rect.height || parsePx(layer.computedStyles.height);
38
+ return Boolean(
39
+ width &&
40
+ height &&
41
+ approximatelyEqual(layer.rect.left, root.rect.left) &&
42
+ approximatelyEqual(layer.rect.top, root.rect.top) &&
43
+ approximatelyEqual(width, rootWidth) &&
44
+ approximatelyEqual(height, rootHeight),
41
45
  );
42
46
  }
43
47
 
@@ -52,13 +56,14 @@ export function isCompositionRootLayer(
52
56
  ) {
53
57
  if (element.parentElement !== doc.body) return false;
54
58
  if (element.hasAttribute("data-hf-allow-root-edit")) return false;
55
- if (isExplicitFullBleedLayer(computedStyles)) return false;
56
-
57
- const rootBounds = getCompositionRootBounds(doc);
58
- const elementSize = getRenderedLayerSize(element, computedStyles);
59
- return Boolean(
60
- rootBounds &&
61
- elementSize &&
62
- matchesCompositionRootBounds(element.getBoundingClientRect(), elementSize, rootBounds),
59
+ const root =
60
+ doc.querySelector<HTMLElement>("[data-composition-id]") ?? doc.documentElement ?? null;
61
+ return coversCompositionRoot(
62
+ { rect: element.getBoundingClientRect(), computedStyles },
63
+ root && {
64
+ rect: root.getBoundingClientRect(),
65
+ width: root.getAttribute("data-width"),
66
+ height: root.getAttribute("data-height"),
67
+ },
63
68
  );
64
69
  }
@@ -1,5 +1,6 @@
1
1
  import type { PatchTarget } from "../../utils/sourcePatcher";
2
2
  import type { GsapAnimation } from "@hyperframes/parsers/gsap-parser";
3
+ import type { EditingElementHandle } from "@hyperframes/core/runtime/editing-port";
3
4
 
4
5
  export const CURATED_STYLE_PROPERTIES = [
5
6
  "position",
@@ -78,6 +79,9 @@ export interface DomEditTextField {
78
79
 
79
80
  export interface DomEditSelection extends PatchTarget {
80
81
  element: HTMLElement;
82
+ handle?: EditingElementHandle;
83
+ hasAudio?: boolean;
84
+ src?: string | null;
81
85
  label: string;
82
86
  tagName: string;
83
87
  sourceFile: string;
@@ -21,6 +21,17 @@ import { giveUpOnPreviewChange, isPreviewChanging } from "../../player/previewRe
21
21
  import { setStudioWaitingPressCancel } from "../../utils/studioPendingEdits";
22
22
  import { playheadMoment } from "../../hooks/editMoment";
23
23
  import type { EditMoment } from "./manualEditsTypes";
24
+ import { previewFrameOpaque } from "../../player/lib/previewChannel";
25
+ import { findPreviewElementForSelection } from "./previewSelection";
26
+ import { measurePreviewRects } from "./previewOverlayRects";
27
+
28
+ type Shown = { selection: DomEditSelection; rect: OverlayRect };
29
+ type ShownStart = (
30
+ e: React.PointerEvent<HTMLElement>,
31
+ at: EditMoment,
32
+ waited: boolean,
33
+ overChannel?: Shown[],
34
+ ) => boolean;
24
35
 
25
36
  const MAX_SETTLED_WAIT_FRAMES = 60;
26
37
  export const PRESS_WAIT_MAX_MS = 10_000;
@@ -128,12 +139,33 @@ export function createPreviewGestureStarts(
128
139
  };
129
140
  };
130
141
 
142
+ /** An opaque frame's `selections` on the page it shows now, read over its channel; null when any is gone. */
143
+ const shownOverChannel = async (
144
+ iframe: HTMLIFrameElement,
145
+ selections: DomEditSelection[],
146
+ ): Promise<Shown[] | null> => {
147
+ const overlay = opts.overlayRef.current;
148
+ const path = opts.activeCompositionPathRef.current;
149
+ const found = await Promise.all(
150
+ selections.map((selection) => findPreviewElementForSelection(iframe, selection, path)),
151
+ );
152
+ const handles = found.map((element) => element?.handle);
153
+ if (!overlay || !handles.length || !handles.every(Boolean)) return null;
154
+ const rects = await measurePreviewRects(iframe, overlay, handles as string[]);
155
+ const shown = selections.flatMap((selection, i) => {
156
+ const rect = rects?.[i];
157
+ return rect ? [{ selection: { ...selection, handle: handles[i] }, rect }] : [];
158
+ });
159
+ return shown.length === selections.length ? shown : null;
160
+ };
161
+
131
162
  // A press on the page a reload is replacing would edit it by its old rules: it starts on the new page instead.
132
163
  const startOnShownPreview = (
133
164
  e: React.PointerEvent<HTMLElement>,
134
165
  pressed: () => HTMLElement[],
135
- start: (e: React.PointerEvent<HTMLElement>, at: EditMoment, waited: boolean) => boolean,
166
+ start: ShownStart,
136
167
  draw: WaitingPressState["draw"] = null,
168
+ targets: () => DomEditSelection[] = () => [],
137
169
  ): boolean => {
138
170
  const at = playheadMoment();
139
171
  if (!isPreviewChanging() && !opts.waitingPressRef.current) return start(e, at, false);
@@ -170,8 +202,25 @@ export function createPreviewGestureStarts(
170
202
  settledFrames = settled ? settledFrames + 1 : 0;
171
203
  return elements.length;
172
204
  };
205
+ // An opaque frame's pressed elements are found over its channel, once the preview settles.
206
+ const iframe = opts.iframeRef.current;
207
+ const channel = iframe && previewFrameOpaque(iframe) ? iframe : null;
208
+ let overChannel: Shown[] | null | undefined;
209
+ let asked = false;
210
+ const channelStep = (frame: HTMLIFrameElement): "wait" | "lost" | "run" => {
211
+ const overdue = performance.now() - since > PRESS_WAIT_MAX_MS;
212
+ if (overdue) giveUpOnPreviewChange();
213
+ if (isPreviewChanging() && !overdue) return "wait";
214
+ if (!asked) {
215
+ asked = true;
216
+ void shownOverChannel(frame, targets()).then((shown) => (overChannel = shown));
217
+ }
218
+ if (overChannel === undefined) return "wait";
219
+ return overChannel ? "run" : "lost";
220
+ };
173
221
  const waitStep = (): "wait" | "lost" | "run" => {
174
222
  if (press.after && !press.after.ended) return "wait";
223
+ if (channel) return channelStep(channel);
175
224
  const found = countFrame();
176
225
  // A change that never ends (a save with no reply) would hold every press: run on the page shown.
177
226
  const overdue = performance.now() - since > PRESS_WAIT_MAX_MS;
@@ -188,8 +237,8 @@ export function createPreviewGestureStarts(
188
237
  return;
189
238
  }
190
239
  endWaitingPress(press);
191
- if (step === "lost" || !start(down as unknown as React.PointerEvent<HTMLElement>, at, true))
192
- return;
240
+ const pointerDown = down as unknown as React.PointerEvent<HTMLElement>;
241
+ if (step === "lost" || !start(pointerDown, at, true, overChannel ?? undefined)) return;
193
242
  if (press.moved) moveActiveGesture(press.moved);
194
243
  if (press.released) releaseActiveGesture(press.released);
195
244
  };
@@ -208,6 +257,11 @@ export function createPreviewGestureStarts(
208
257
  const iframe = opts.iframeRef.current;
209
258
  return overlay && iframe && orientedGroupAwareOverlayRect(overlay, iframe, element);
210
259
  };
260
+ const shownOnPage = (target: DomEditSelection | null): Shown | null => {
261
+ const selection = target && shownSelection(target);
262
+ const rect = selection && shownRect(selection.element);
263
+ return selection && rect ? { selection, rect } : null;
264
+ };
211
265
 
212
266
  const startGroupDrag = (e: React.PointerEvent<HTMLElement>) => {
213
267
  const items = opts.groupOverlayItemsRef.current;
@@ -218,8 +272,16 @@ export function createPreviewGestureStarts(
218
272
  const selection = shownSelection(item.selection);
219
273
  return selection ? [selection.element] : [];
220
274
  }),
221
- (pressed, at, waited) => {
275
+ (pressed, at, waited, overChannel) => {
222
276
  if (!waited) return _startGroupDrag(pressed, opts, at);
277
+ if (overChannel) {
278
+ const measured = items.map((item, i) => ({ ...item, ...overChannel[i]! }));
279
+ return _startGroupDrag(
280
+ pressed,
281
+ { ...opts, groupOverlayItemsRef: { current: measured } },
282
+ at,
283
+ );
284
+ }
223
285
  const overlay = opts.overlayRef.current;
224
286
  const iframe = opts.iframeRef.current;
225
287
  if (!overlay || !iframe) return false;
@@ -243,6 +305,7 @@ export function createPreviewGestureStarts(
243
305
  opts.setGroupOverlayItems(
244
306
  items.map((item) => ({ ...item, rect: shiftedOverlayRect(item.rect, dx, dy) })),
245
307
  ),
308
+ () => items.map((item) => item.selection),
246
309
  );
247
310
  };
248
311
  const startGesture = (
@@ -270,15 +333,14 @@ export function createPreviewGestureStarts(
270
333
  const shown = target && shownSelection(target);
271
334
  return shown ? [shown.element] : [];
272
335
  },
273
- (pressed, at, waited) => {
336
+ (pressed, at, waited, overChannel) => {
274
337
  if (!waited) return _startGesture(kind, pressed, opts, { ...options, at });
275
- const selection = target && shownSelection(target);
276
- const rect = selection && shownRect(selection.element);
338
+ const shown = overChannel ? overChannel[0] : shownOnPage(target);
277
339
  return (
278
- !!(selection && rect) &&
340
+ !!shown &&
279
341
  _startGesture(kind, pressed, opts, {
280
- selection,
281
- rect,
342
+ selection: shown.selection,
343
+ rect: shown.rect,
282
344
  resizeHandle: options?.resizeHandle,
283
345
  resizeCorner: options?.resizeCorner,
284
346
  at,
@@ -286,6 +348,7 @@ export function createPreviewGestureStarts(
286
348
  );
287
349
  },
288
350
  draw,
351
+ () => (target ? [target] : []),
289
352
  );
290
353
  };
291
354