@r2digisolutions/components 0.21.4 → 0.21.6
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/components/molecules/Chart/Chart.svelte +16 -2
- package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte +12 -4
- package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte.d.ts +5 -0
- package/dist/components/molecules/MediaStage/MediaStage.svelte +14 -16
- package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte +8 -2
- package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte.d.ts +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/utils/canvasHierarchy.d.ts +10 -0
- package/dist/utils/canvasHierarchy.js +15 -0
- package/package.json +1 -1
|
@@ -72,7 +72,14 @@
|
|
|
72
72
|
|
|
73
73
|
<div class={['w-full space-y-3', className]}>
|
|
74
74
|
{#if type === 'bar'}
|
|
75
|
-
<svg
|
|
75
|
+
<svg
|
|
76
|
+
viewBox={`0 0 320 ${height}`}
|
|
77
|
+
preserveAspectRatio="none"
|
|
78
|
+
class="block w-full"
|
|
79
|
+
style:height={`${height}px`}
|
|
80
|
+
role="img"
|
|
81
|
+
aria-label="Bar chart"
|
|
82
|
+
>
|
|
76
83
|
{#each data as d, i}
|
|
77
84
|
{@const bw = Math.max(12, (320 - 32) / data.length - 8)}
|
|
78
85
|
{@const x = 16 + i * ((320 - 32) / data.length)}
|
|
@@ -93,7 +100,14 @@
|
|
|
93
100
|
{/each}
|
|
94
101
|
</svg>
|
|
95
102
|
{:else if type === 'line'}
|
|
96
|
-
<svg
|
|
103
|
+
<svg
|
|
104
|
+
viewBox={`0 0 320 ${height}`}
|
|
105
|
+
preserveAspectRatio="none"
|
|
106
|
+
class="block w-full"
|
|
107
|
+
style:height={`${height}px`}
|
|
108
|
+
role="img"
|
|
109
|
+
aria-label="Line chart"
|
|
110
|
+
>
|
|
97
111
|
<polyline
|
|
98
112
|
points={linePoints}
|
|
99
113
|
fill="none"
|
|
@@ -39,6 +39,11 @@
|
|
|
39
39
|
onchange?: (rect: WidgetRect) => void;
|
|
40
40
|
/** True while this frame is being dragged/resized. */
|
|
41
41
|
oninteract?: (active: boolean) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Parent owns live position (multi-select / selected group). The frame
|
|
44
|
+
* still reports pointer deltas; it must not visually detach from the group.
|
|
45
|
+
*/
|
|
46
|
+
followStageRect?: boolean;
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
let {
|
|
@@ -58,7 +63,8 @@
|
|
|
58
63
|
onclick,
|
|
59
64
|
ondblclick,
|
|
60
65
|
onchange,
|
|
61
|
-
oninteract
|
|
66
|
+
oninteract,
|
|
67
|
+
followStageRect = false
|
|
62
68
|
}: MediaLayerItemProps = $props();
|
|
63
69
|
|
|
64
70
|
const pos = $derived(displayRect ?? layer.rect);
|
|
@@ -68,8 +74,9 @@
|
|
|
68
74
|
let interacting = $state(false);
|
|
69
75
|
|
|
70
76
|
$effect(() => {
|
|
71
|
-
//
|
|
72
|
-
|
|
77
|
+
// Single-item drag/resize: WidgetFrame owns the live rect.
|
|
78
|
+
// Group / multi-select: follow the stage so the grabbed object cannot detach.
|
|
79
|
+
if (interacting && !followStageRect) return;
|
|
73
80
|
rect = { x: pos.x, y: pos.y, w: pos.w, h: pos.h };
|
|
74
81
|
});
|
|
75
82
|
|
|
@@ -148,13 +155,14 @@
|
|
|
148
155
|
draggable={!layer.locked && !readOnly && !noDrag}
|
|
149
156
|
resizable={!layer.locked && !readOnly && !noResize && handlesOn}
|
|
150
157
|
bind:rect
|
|
158
|
+
applyRect={!followStageRect}
|
|
151
159
|
minW={layer.kind === 'line' || layer.kind === 'arrow' || layer.kind === 'path' ? 16 : 40}
|
|
152
160
|
minH={layer.kind === 'line' ? 4 : layer.kind === 'arrow' || layer.kind === 'path' ? 16 : 24}
|
|
153
161
|
class={['bg-transparent', passthrough || readOnly ? 'pointer-events-none' : '']
|
|
154
162
|
.filter(Boolean)
|
|
155
163
|
.join(' ')}
|
|
156
164
|
onchange={(r) => {
|
|
157
|
-
rect = r;
|
|
165
|
+
if (!followStageRect) rect = r;
|
|
158
166
|
onchange?.(r);
|
|
159
167
|
}}
|
|
160
168
|
oninteract={(active) => {
|
|
@@ -33,6 +33,11 @@ interface MediaLayerItemProps {
|
|
|
33
33
|
onchange?: (rect: WidgetRect) => void;
|
|
34
34
|
/** True while this frame is being dragged/resized. */
|
|
35
35
|
oninteract?: (active: boolean) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Parent owns live position (multi-select / selected group). The frame
|
|
38
|
+
* still reports pointer deltas; it must not visually detach from the group.
|
|
39
|
+
*/
|
|
40
|
+
followStageRect?: boolean;
|
|
36
41
|
}
|
|
37
42
|
declare const MediaLayerItem: import("svelte").Component<MediaLayerItemProps, {}, "">;
|
|
38
43
|
type MediaLayerItem = ReturnType<typeof MediaLayerItem>;
|
|
@@ -50,6 +50,9 @@
|
|
|
50
50
|
scrollBarMetrics,
|
|
51
51
|
selectionAncestorIds,
|
|
52
52
|
clipPathForLayer,
|
|
53
|
+
clampDeltaToKeepUnion,
|
|
54
|
+
getAncestors,
|
|
55
|
+
selectedAncestorId,
|
|
53
56
|
topLevelSelectedIds,
|
|
54
57
|
translateSelectionAbsolute
|
|
55
58
|
} from '../../../utils/canvasHierarchy.js';
|
|
@@ -369,22 +372,10 @@
|
|
|
369
372
|
moveBaseAbs = null;
|
|
370
373
|
}
|
|
371
374
|
|
|
372
|
-
function clampDeltaToKeepUnion(
|
|
373
|
-
union: { x: number; y: number; w: number; h: number },
|
|
374
|
-
dx: number,
|
|
375
|
-
dy: number
|
|
376
|
-
) {
|
|
377
|
-
let x = union.x + dx;
|
|
378
|
-
let y = union.y + dy;
|
|
379
|
-
if (union.w < doc.width) x = Math.min(Math.max(0, x), doc.width - union.w);
|
|
380
|
-
if (union.h < doc.height) y = Math.min(Math.max(0, y), doc.height - union.h);
|
|
381
|
-
return { dx: x - union.x, dy: y - union.y };
|
|
382
|
-
}
|
|
383
|
-
|
|
384
375
|
function handleLayerInteract(active: boolean) {
|
|
385
376
|
if (active) {
|
|
386
377
|
interactCount += 1;
|
|
387
|
-
if (
|
|
378
|
+
if (!moveBaseLayers) {
|
|
388
379
|
moveBaseLayers = workingLayers;
|
|
389
380
|
moveBaseAbs = new Map(absMap);
|
|
390
381
|
}
|
|
@@ -454,11 +445,12 @@
|
|
|
454
445
|
const dy = nextAbs.y - prevAbs.y;
|
|
455
446
|
const moving = Math.abs(nextAbs.w - prevAbs.w) < 0.5 && Math.abs(nextAbs.h - prevAbs.h) < 0.5;
|
|
456
447
|
if (moving && Math.abs(dx) < 0.01 && Math.abs(dy) < 0.01) return;
|
|
448
|
+
const ancestorSelected = selectedAncestorId(workingLayers, source.id, selectedSet);
|
|
457
449
|
const groupMove =
|
|
458
450
|
moving &&
|
|
459
451
|
!positionLocked &&
|
|
460
|
-
selectedIds.length > 1 &&
|
|
461
|
-
selectedSet.has(source.id) &&
|
|
452
|
+
(selectedIds.length > 1 || !!ancestorSelected) &&
|
|
453
|
+
(selectedSet.has(source.id) || !!ancestorSelected) &&
|
|
462
454
|
(Math.abs(dx) > 0.01 || Math.abs(dy) > 0.01);
|
|
463
455
|
|
|
464
456
|
if (groupMove) {
|
|
@@ -476,7 +468,10 @@
|
|
|
476
468
|
const top = topLevelSelectedIds(baseLayers, movableIds);
|
|
477
469
|
const union = unionAbsRect(baseAbs, top);
|
|
478
470
|
if (union) {
|
|
479
|
-
const clamped = clampDeltaToKeepUnion(union, moveDx, moveDy
|
|
471
|
+
const clamped = clampDeltaToKeepUnion(union, moveDx, moveDy, {
|
|
472
|
+
width: doc.width,
|
|
473
|
+
height: doc.height
|
|
474
|
+
});
|
|
480
475
|
moveDx = clamped.dx;
|
|
481
476
|
moveDy = clamped.dy;
|
|
482
477
|
}
|
|
@@ -540,6 +535,7 @@
|
|
|
540
535
|
}
|
|
541
536
|
|
|
542
537
|
function groupedChildPassthrough(layer: CanvasLayer): boolean {
|
|
538
|
+
if (getAncestors(workingLayers, layer.id).some((a) => selectedSet.has(a.id))) return true;
|
|
543
539
|
if (selectedSet.has(layer.id)) return false;
|
|
544
540
|
return !!enclosingGroupId(workingLayers, layer.id);
|
|
545
541
|
}
|
|
@@ -1393,6 +1389,8 @@
|
|
|
1393
1389
|
selected={isSelected}
|
|
1394
1390
|
showHandles={isSelected && selectedIds.length === 1}
|
|
1395
1391
|
passthrough={lockedPass || groupedChildPassthrough(layer)}
|
|
1392
|
+
followStageRect={selectedIds.length > 1 ||
|
|
1393
|
+
!!selectedAncestorId(workingLayers, realId, selectedSet)}
|
|
1396
1394
|
readOnly={isSynthetic}
|
|
1397
1395
|
layoutPositionLocked={positionLocked || (marqueeBg && !dragOk)}
|
|
1398
1396
|
layoutSizeLocked={sizeLocked}
|
|
@@ -87,6 +87,11 @@
|
|
|
87
87
|
onreload?: () => void | Promise<void>;
|
|
88
88
|
oncollapse?: (collapsed: boolean) => void;
|
|
89
89
|
onchange?: (rect: WidgetRect) => void;
|
|
90
|
+
/**
|
|
91
|
+
* When false, `onchange` still fires but this frame does not write `rect`.
|
|
92
|
+
* Use when a parent owns live position (rigid multi-select / group move).
|
|
93
|
+
*/
|
|
94
|
+
applyRect?: boolean;
|
|
90
95
|
/** Fired when freeform drag/resize starts (after move threshold) or ends. */
|
|
91
96
|
oninteract?: (active: boolean) => void;
|
|
92
97
|
}
|
|
@@ -130,6 +135,7 @@
|
|
|
130
135
|
onreload,
|
|
131
136
|
oncollapse,
|
|
132
137
|
onchange,
|
|
138
|
+
applyRect = true,
|
|
133
139
|
oninteract
|
|
134
140
|
}: WidgetFrameProps = $props();
|
|
135
141
|
|
|
@@ -212,7 +218,7 @@
|
|
|
212
218
|
|
|
213
219
|
function emitRect(next: WidgetRect) {
|
|
214
220
|
const r = finalizeRect(next);
|
|
215
|
-
rect = r;
|
|
221
|
+
if (applyRect) rect = r;
|
|
216
222
|
onchange?.(r);
|
|
217
223
|
}
|
|
218
224
|
|
|
@@ -353,7 +359,7 @@
|
|
|
353
359
|
}
|
|
354
360
|
if (mode === 'move' && freeform) {
|
|
355
361
|
mode = null;
|
|
356
|
-
emitRect({ ...rect });
|
|
362
|
+
if (applyRect) emitRect({ ...rect });
|
|
357
363
|
oninteract?.(false);
|
|
358
364
|
return;
|
|
359
365
|
}
|
|
@@ -71,6 +71,11 @@ interface WidgetFrameProps {
|
|
|
71
71
|
onreload?: () => void | Promise<void>;
|
|
72
72
|
oncollapse?: (collapsed: boolean) => void;
|
|
73
73
|
onchange?: (rect: WidgetRect) => void;
|
|
74
|
+
/**
|
|
75
|
+
* When false, `onchange` still fires but this frame does not write `rect`.
|
|
76
|
+
* Use when a parent owns live position (rigid multi-select / group move).
|
|
77
|
+
*/
|
|
78
|
+
applyRect?: boolean;
|
|
74
79
|
/** Fired when freeform drag/resize starts (after move threshold) or ends. */
|
|
75
80
|
oninteract?: (active: boolean) => void;
|
|
76
81
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -865,7 +865,7 @@ export type { MediaAsset, MediaAssetKind, MediaClip, MediaClipAlign, MediaClipRe
|
|
|
865
865
|
export { uid, createMediaClip, createMediaTrack, createMediaAsset, clipDurationMs, moveClip, trimClipStart, trimClipEnd, isClipActiveAt, findClipAt, updateClipInTracks, removeClipFromTracks, removeClipsFromTracks, splitClipAt, splitClipsAt, duplicateClipInTracks, mergeClipsInTracks, canMergeMediaClips, moveClipsByDelta, findClipById, nextTrackName, reorderTracks, moveTrack, removeTrack, removeTracks, defaultOverlayRect, defaultMediaClipRect, resolveClipRect, alignClipRect, alignMediaRect, clipHasSpatialRect, isMediaClipFieldModified, resetMediaClipField, findTransitionAt, transitionLayerStyle, transitionDipOverlay, resolvePreviewOpacity, resolveClipOpacity, MEDIA_CLIP_DEFAULTS, kindFromFile, probeMediaSrc } from './utils/mediaTracks.js';
|
|
866
866
|
export { emptyCanvasDocument, createCanvasLayer, createCanvasGuide, createPathFromDocPoints, rebakePathLayer, pathPointsToDoc, reorderCanvasLayers, updateCanvasLayer, updateCanvasLayers, alignLayerRect, snapLayerRect, snapRectToGuides, migrateCanvasDocument, defaultSlotFromRect, rectFromSlot, ensureLayerSlot, canvasLayerFieldDefault, isCanvasFieldModified, resetCanvasField, applyTextAutoSize, CANVAS_PRESETS, presetIdForSize } from './utils/canvasDocument.js';
|
|
867
867
|
export type { CanvasDocument, CanvasLayer, CanvasLayerKind, CanvasLayerRect, CanvasPoint, CanvasObjectFit, CanvasTextAlign, CanvasResettableField, CanvasAlign, CanvasFontStyle, CanvasTextDecoration, CanvasGuide, CanvasGuideOrientation, CanvasAnchors, CanvasSlot, CanvasExposedProp, CanvasWidgetDefinition } from './utils/canvasDocument.js';
|
|
868
|
-
export { isContainerKind, canHaveChildren, getChildren, getDescendantIds, getSubtreeIds, getAncestors, enclosingGroupId, isEffectivelyVisible, isEffectivelyLocked, isLayoutPositionLocked, isLayoutSizeLocked, selectionAncestorIds, LAYOUT_POSITION_KINDS, LAYOUT_SIZE_KINDS, paintTransformForLayer, isDescendant, canReparent, ANCHOR_PRESETS, resolveSlotRect, slotFromLocalRect, translateSlot, stepAxis, computeAbsoluteRects, absoluteRectFor, reparentLayer, wrapSelection, groupLayers, ungroupLayers, layerFromAbsoluteRect, fitGroupsToChildren, scaleSubtreeAbsolute, scaleSelectionAbsolute, shouldAutoSizeChildren, topLevelSelectedIds, translateSelectionAbsolute, unionAbsRect, deleteSubtree, duplicateSubtree, reorderSiblings, clipPathForLayer, scrollBoxOverflow, scrollBarMetrics, applyScrollBoxOffsets } from './utils/canvasHierarchy.js';
|
|
868
|
+
export { isContainerKind, canHaveChildren, getChildren, getDescendantIds, getSubtreeIds, getAncestors, enclosingGroupId, isEffectivelyVisible, isEffectivelyLocked, isLayoutPositionLocked, isLayoutSizeLocked, selectionAncestorIds, LAYOUT_POSITION_KINDS, LAYOUT_SIZE_KINDS, paintTransformForLayer, isDescendant, canReparent, ANCHOR_PRESETS, resolveSlotRect, slotFromLocalRect, translateSlot, stepAxis, computeAbsoluteRects, absoluteRectFor, reparentLayer, wrapSelection, groupLayers, ungroupLayers, layerFromAbsoluteRect, fitGroupsToChildren, scaleSubtreeAbsolute, scaleSelectionAbsolute, shouldAutoSizeChildren, topLevelSelectedIds, translateSelectionAbsolute, unionAbsRect, clampDeltaToKeepUnion, selectedAncestorId, deleteSubtree, duplicateSubtree, reorderSiblings, clipPathForLayer, scrollBoxOverflow, scrollBarMetrics, applyScrollBoxOffsets } from './utils/canvasHierarchy.js';
|
|
869
869
|
export { createWidgetDefinition, createWidgetFromSelection, placeWidgetInstance, resolveWidgetInstance, flattenLayersWithWidgets, breakWidgetInstance, updateWidgetDefinition, deleteWidgetDefinition, renameWidgetDefinition, duplicateWidgetDefinition, syncInstanceSizesToDefinition, setExposedProp, isPropExposed, getExposedProp, getExposedFieldDefault, resolveExposedPropValue, groupExposedPropsByLayer, setInstanceOverride, getNamedSlotsFromDefinition, listFillableSlotsForInstance } from './utils/canvasWidget.js';
|
|
870
870
|
export { createCanvasHistory, pushCanvasHistory, undoCanvasHistory, redoCanvasHistory, serializeCanvasDoc, parseCanvasDoc } from './utils/canvasHistory.js';
|
|
871
871
|
export type { CanvasHistoryState } from './utils/canvasHistory.js';
|
package/dist/index.js
CHANGED
|
@@ -587,7 +587,7 @@ export { emptyBlogDocument, createBlock, createComponentBlock, serializeBlogDocu
|
|
|
587
587
|
export { msToPx, pxToMs, pxPerMsFromZoom, snapMs, clampMs, formatTimecode, ticksForDuration, snapStepForZoom } from './utils/mediaTime.js';
|
|
588
588
|
export { uid, createMediaClip, createMediaTrack, createMediaAsset, clipDurationMs, moveClip, trimClipStart, trimClipEnd, isClipActiveAt, findClipAt, updateClipInTracks, removeClipFromTracks, removeClipsFromTracks, splitClipAt, splitClipsAt, duplicateClipInTracks, mergeClipsInTracks, canMergeMediaClips, moveClipsByDelta, findClipById, nextTrackName, reorderTracks, moveTrack, removeTrack, removeTracks, defaultOverlayRect, defaultMediaClipRect, resolveClipRect, alignClipRect, alignMediaRect, clipHasSpatialRect, isMediaClipFieldModified, resetMediaClipField, findTransitionAt, transitionLayerStyle, transitionDipOverlay, resolvePreviewOpacity, resolveClipOpacity, MEDIA_CLIP_DEFAULTS, kindFromFile, probeMediaSrc } from './utils/mediaTracks.js';
|
|
589
589
|
export { emptyCanvasDocument, createCanvasLayer, createCanvasGuide, createPathFromDocPoints, rebakePathLayer, pathPointsToDoc, reorderCanvasLayers, updateCanvasLayer, updateCanvasLayers, alignLayerRect, snapLayerRect, snapRectToGuides, migrateCanvasDocument, defaultSlotFromRect, rectFromSlot, ensureLayerSlot, canvasLayerFieldDefault, isCanvasFieldModified, resetCanvasField, applyTextAutoSize, CANVAS_PRESETS, presetIdForSize } from './utils/canvasDocument.js';
|
|
590
|
-
export { isContainerKind, canHaveChildren, getChildren, getDescendantIds, getSubtreeIds, getAncestors, enclosingGroupId, isEffectivelyVisible, isEffectivelyLocked, isLayoutPositionLocked, isLayoutSizeLocked, selectionAncestorIds, LAYOUT_POSITION_KINDS, LAYOUT_SIZE_KINDS, paintTransformForLayer, isDescendant, canReparent, ANCHOR_PRESETS, resolveSlotRect, slotFromLocalRect, translateSlot, stepAxis, computeAbsoluteRects, absoluteRectFor, reparentLayer, wrapSelection, groupLayers, ungroupLayers, layerFromAbsoluteRect, fitGroupsToChildren, scaleSubtreeAbsolute, scaleSelectionAbsolute, shouldAutoSizeChildren, topLevelSelectedIds, translateSelectionAbsolute, unionAbsRect, deleteSubtree, duplicateSubtree, reorderSiblings, clipPathForLayer, scrollBoxOverflow, scrollBarMetrics, applyScrollBoxOffsets } from './utils/canvasHierarchy.js';
|
|
590
|
+
export { isContainerKind, canHaveChildren, getChildren, getDescendantIds, getSubtreeIds, getAncestors, enclosingGroupId, isEffectivelyVisible, isEffectivelyLocked, isLayoutPositionLocked, isLayoutSizeLocked, selectionAncestorIds, LAYOUT_POSITION_KINDS, LAYOUT_SIZE_KINDS, paintTransformForLayer, isDescendant, canReparent, ANCHOR_PRESETS, resolveSlotRect, slotFromLocalRect, translateSlot, stepAxis, computeAbsoluteRects, absoluteRectFor, reparentLayer, wrapSelection, groupLayers, ungroupLayers, layerFromAbsoluteRect, fitGroupsToChildren, scaleSubtreeAbsolute, scaleSelectionAbsolute, shouldAutoSizeChildren, topLevelSelectedIds, translateSelectionAbsolute, unionAbsRect, clampDeltaToKeepUnion, selectedAncestorId, deleteSubtree, duplicateSubtree, reorderSiblings, clipPathForLayer, scrollBoxOverflow, scrollBarMetrics, applyScrollBoxOffsets } from './utils/canvasHierarchy.js';
|
|
591
591
|
export { createWidgetDefinition, createWidgetFromSelection, placeWidgetInstance, resolveWidgetInstance, flattenLayersWithWidgets, breakWidgetInstance, updateWidgetDefinition, deleteWidgetDefinition, renameWidgetDefinition, duplicateWidgetDefinition, syncInstanceSizesToDefinition, setExposedProp, isPropExposed, getExposedProp, getExposedFieldDefault, resolveExposedPropValue, groupExposedPropsByLayer, setInstanceOverride, getNamedSlotsFromDefinition, listFillableSlotsForInstance } from './utils/canvasWidget.js';
|
|
592
592
|
export { createCanvasHistory, pushCanvasHistory, undoCanvasHistory, redoCanvasHistory, serializeCanvasDoc, parseCanvasDoc } from './utils/canvasHistory.js';
|
|
593
593
|
export { renderCanvasDocument, exportCanvasBlob, downloadBlob, backgroundAlpha } from './utils/canvasExport.js';
|
|
@@ -241,6 +241,16 @@ export declare function fitGroupsToChildren(layers: CanvasLayer[], rootSize: {
|
|
|
241
241
|
export declare function shouldAutoSizeChildren(layer: CanvasLayer): boolean;
|
|
242
242
|
export declare function topLevelSelectedIds(layers: CanvasLayer[], ids: string[]): string[];
|
|
243
243
|
export declare function unionAbsRect(absMap: Map<string, CanvasLayerRect>, ids: string[]): CanvasLayerRect | null;
|
|
244
|
+
/** Clamp a rigid-body delta so `union` stays on the artboard (snap-to-bounds). */
|
|
245
|
+
export declare function clampDeltaToKeepUnion(union: CanvasLayerRect, dx: number, dy: number, bounds: {
|
|
246
|
+
width: number;
|
|
247
|
+
height: number;
|
|
248
|
+
}): {
|
|
249
|
+
dx: number;
|
|
250
|
+
dy: number;
|
|
251
|
+
};
|
|
252
|
+
/** Selected group/container that contains `layerId`, if any. */
|
|
253
|
+
export declare function selectedAncestorId(layers: CanvasLayer[], layerId: string, selectedIds: Iterable<string>): string | null;
|
|
244
254
|
/**
|
|
245
255
|
* Scale a group (or any subtree) from `prevAbs` to `nextAbs`.
|
|
246
256
|
* Descendants keep their relative placement inside the box unless
|
|
@@ -904,6 +904,21 @@ export function unionAbsRect(absMap, ids) {
|
|
|
904
904
|
return null;
|
|
905
905
|
return { x: minX, y: minY, w: Math.max(1, maxX - minX), h: Math.max(1, maxY - minY) };
|
|
906
906
|
}
|
|
907
|
+
/** Clamp a rigid-body delta so `union` stays on the artboard (snap-to-bounds). */
|
|
908
|
+
export function clampDeltaToKeepUnion(union, dx, dy, bounds) {
|
|
909
|
+
let x = union.x + dx;
|
|
910
|
+
let y = union.y + dy;
|
|
911
|
+
if (union.w < bounds.width)
|
|
912
|
+
x = Math.min(Math.max(0, x), bounds.width - union.w);
|
|
913
|
+
if (union.h < bounds.height)
|
|
914
|
+
y = Math.min(Math.max(0, y), bounds.height - union.h);
|
|
915
|
+
return { dx: x - union.x, dy: y - union.y };
|
|
916
|
+
}
|
|
917
|
+
/** Selected group/container that contains `layerId`, if any. */
|
|
918
|
+
export function selectedAncestorId(layers, layerId, selectedIds) {
|
|
919
|
+
const set = selectedIds instanceof Set ? selectedIds : new Set(selectedIds);
|
|
920
|
+
return getAncestors(layers, layerId).find((a) => set.has(a.id))?.id ?? null;
|
|
921
|
+
}
|
|
907
922
|
function applyAbsoluteRects(layers, nextAbsMap, prevAbsMap, rootSize) {
|
|
908
923
|
const byId = new Map(layers.map((l) => [l.id, l]));
|
|
909
924
|
return layers.map((l) => {
|