@r2digisolutions/components 0.21.3 → 0.21.5
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/MediaLayerItem/MediaLayerItem.svelte +12 -4
- package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte.d.ts +5 -0
- package/dist/components/molecules/MediaStage/MediaStage.svelte +82 -26
- 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/canvasDocument.d.ts +1 -1
- package/dist/utils/canvasDocument.js +10 -7
- package/dist/utils/canvasHierarchy.d.ts +19 -0
- package/dist/utils/canvasHierarchy.js +34 -0
- package/package.json +1 -1
|
@@ -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>;
|
|
@@ -49,7 +49,12 @@
|
|
|
49
49
|
scrollBoxOverflow,
|
|
50
50
|
scrollBarMetrics,
|
|
51
51
|
selectionAncestorIds,
|
|
52
|
-
clipPathForLayer
|
|
52
|
+
clipPathForLayer,
|
|
53
|
+
clampDeltaToKeepUnion,
|
|
54
|
+
getAncestors,
|
|
55
|
+
selectedAncestorId,
|
|
56
|
+
topLevelSelectedIds,
|
|
57
|
+
translateSelectionAbsolute
|
|
53
58
|
} from '../../../utils/canvasHierarchy.js';
|
|
54
59
|
import { flattenLayersWithWidgets } from '../../../utils/canvasWidget.js';
|
|
55
60
|
import { backgroundAlpha } from '../../../utils/canvasExport.js';
|
|
@@ -193,6 +198,11 @@
|
|
|
193
198
|
let selectionLive = $state<{ x: number; y: number; w: number; h: number } | null>(null);
|
|
194
199
|
let selectionBaseLayers = $state<CanvasLayer[] | null>(null);
|
|
195
200
|
let selectionBaseBox = $state<{ x: number; y: number; w: number; h: number } | null>(null);
|
|
201
|
+
/** Snapshot for rigid multi-select drag (from pointer-down, not last frame). */
|
|
202
|
+
let moveBaseLayers = $state<CanvasLayer[] | null>(null);
|
|
203
|
+
let moveBaseAbs = $state<Map<string, { x: number; y: number; w: number; h: number }> | null>(
|
|
204
|
+
null
|
|
205
|
+
);
|
|
196
206
|
const selectionFrame = $derived(selectionLive ?? selectionBounds);
|
|
197
207
|
|
|
198
208
|
const fitScale = $derived.by(() => {
|
|
@@ -291,7 +301,14 @@
|
|
|
291
301
|
return r;
|
|
292
302
|
},
|
|
293
303
|
clampRect(rect: WidgetRect, minW: number, minH: number) {
|
|
294
|
-
|
|
304
|
+
const sized = {
|
|
305
|
+
...rect,
|
|
306
|
+
w: Math.max(minW, rect.w),
|
|
307
|
+
h: Math.max(minH, rect.h)
|
|
308
|
+
};
|
|
309
|
+
// Snap on = stay on the artboard. Snap off = free, including off-canvas.
|
|
310
|
+
if (!snap) return sized;
|
|
311
|
+
return clampWidgetRect(sized, { width: doc.width, height: doc.height }, minW, minH);
|
|
295
312
|
}
|
|
296
313
|
};
|
|
297
314
|
|
|
@@ -334,25 +351,41 @@
|
|
|
334
351
|
});
|
|
335
352
|
}
|
|
336
353
|
|
|
337
|
-
function commitGroupGeometry(next: CanvasLayer[]) {
|
|
338
|
-
draftLayers = fitGroupsToChildren(next, { width: doc.width, height: doc.height });
|
|
339
|
-
if (interactCount === 0) commitDraft();
|
|
340
|
-
}
|
|
341
|
-
|
|
342
354
|
function commitDraft() {
|
|
343
355
|
if (!draftLayers) return;
|
|
344
|
-
const layers = draftLayers;
|
|
356
|
+
const layers = fitGroupsToChildren(draftLayers, { width: doc.width, height: doc.height });
|
|
345
357
|
draftLayers = null;
|
|
346
358
|
ondocumentchange?.({ ...doc, layers });
|
|
347
359
|
}
|
|
348
360
|
|
|
361
|
+
function commitGroupGeometry(next: CanvasLayer[]) {
|
|
362
|
+
if (interactCount > 0) {
|
|
363
|
+
draftLayers = next;
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
draftLayers = fitGroupsToChildren(next, { width: doc.width, height: doc.height });
|
|
367
|
+
commitDraft();
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function clearMoveSnapshot() {
|
|
371
|
+
moveBaseLayers = null;
|
|
372
|
+
moveBaseAbs = null;
|
|
373
|
+
}
|
|
374
|
+
|
|
349
375
|
function handleLayerInteract(active: boolean) {
|
|
350
376
|
if (active) {
|
|
351
377
|
interactCount += 1;
|
|
378
|
+
if (!moveBaseLayers) {
|
|
379
|
+
moveBaseLayers = workingLayers;
|
|
380
|
+
moveBaseAbs = new Map(absMap);
|
|
381
|
+
}
|
|
352
382
|
return;
|
|
353
383
|
}
|
|
354
384
|
interactCount = Math.max(0, interactCount - 1);
|
|
355
|
-
if (interactCount === 0)
|
|
385
|
+
if (interactCount === 0) {
|
|
386
|
+
clearMoveSnapshot();
|
|
387
|
+
commitDraft();
|
|
388
|
+
}
|
|
356
389
|
}
|
|
357
390
|
|
|
358
391
|
function cancelLayerDraft() {
|
|
@@ -361,6 +394,7 @@
|
|
|
361
394
|
selectionBaseLayers = null;
|
|
362
395
|
selectionBaseBox = null;
|
|
363
396
|
selectionLive = null;
|
|
397
|
+
clearMoveSnapshot();
|
|
364
398
|
}
|
|
365
399
|
|
|
366
400
|
function isLayoutLocked(layer: CanvasLayer): boolean {
|
|
@@ -395,7 +429,9 @@
|
|
|
395
429
|
{ width: doc.width, height: doc.height },
|
|
396
430
|
minW,
|
|
397
431
|
minH,
|
|
398
|
-
guideSnapList
|
|
432
|
+
guideSnapList,
|
|
433
|
+
8,
|
|
434
|
+
false
|
|
399
435
|
);
|
|
400
436
|
|
|
401
437
|
const prevAbs = absMap.get(source.id) ?? source.rect;
|
|
@@ -409,29 +445,46 @@
|
|
|
409
445
|
const dy = nextAbs.y - prevAbs.y;
|
|
410
446
|
const moving = Math.abs(nextAbs.w - prevAbs.w) < 0.5 && Math.abs(nextAbs.h - prevAbs.h) < 0.5;
|
|
411
447
|
if (moving && Math.abs(dx) < 0.01 && Math.abs(dy) < 0.01) return;
|
|
448
|
+
const ancestorSelected = selectedAncestorId(workingLayers, source.id, selectedSet);
|
|
412
449
|
const groupMove =
|
|
413
450
|
moving &&
|
|
414
451
|
!positionLocked &&
|
|
415
|
-
selectedIds.length > 1 &&
|
|
416
|
-
selectedSet.has(source.id) &&
|
|
452
|
+
(selectedIds.length > 1 || !!ancestorSelected) &&
|
|
453
|
+
(selectedSet.has(source.id) || !!ancestorSelected) &&
|
|
417
454
|
(Math.abs(dx) > 0.01 || Math.abs(dy) > 0.01);
|
|
418
455
|
|
|
419
456
|
if (groupMove) {
|
|
457
|
+
const baseLayers = moveBaseLayers ?? layers;
|
|
458
|
+
const baseAbs = moveBaseAbs ?? absMap;
|
|
459
|
+
const start = baseAbs.get(source.id) ?? source.rect;
|
|
460
|
+
let moveDx = nextAbs.x - start.x;
|
|
461
|
+
let moveDy = nextAbs.y - start.y;
|
|
462
|
+
const movableIds = selectedIds.filter(
|
|
463
|
+
(id) =>
|
|
464
|
+
!isEffectivelyLocked(workingLayers, id, workingById) &&
|
|
465
|
+
!isLayoutPositionLocked(workingLayers, id, workingById)
|
|
466
|
+
);
|
|
467
|
+
if (snap) {
|
|
468
|
+
const top = topLevelSelectedIds(baseLayers, movableIds);
|
|
469
|
+
const union = unionAbsRect(baseAbs, top);
|
|
470
|
+
if (union) {
|
|
471
|
+
const clamped = clampDeltaToKeepUnion(union, moveDx, moveDy, {
|
|
472
|
+
width: doc.width,
|
|
473
|
+
height: doc.height
|
|
474
|
+
});
|
|
475
|
+
moveDx = clamped.dx;
|
|
476
|
+
moveDy = clamped.dy;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
420
479
|
commitGroupGeometry(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
y: a.y + dy,
|
|
430
|
-
w: a.w,
|
|
431
|
-
h: a.h
|
|
432
|
-
};
|
|
433
|
-
return absToLocalUpdate(l, moved);
|
|
434
|
-
})
|
|
480
|
+
translateSelectionAbsolute(
|
|
481
|
+
baseLayers,
|
|
482
|
+
movableIds,
|
|
483
|
+
moveDx,
|
|
484
|
+
moveDy,
|
|
485
|
+
{ width: doc.width, height: doc.height },
|
|
486
|
+
baseAbs
|
|
487
|
+
)
|
|
435
488
|
);
|
|
436
489
|
return;
|
|
437
490
|
}
|
|
@@ -482,6 +535,7 @@
|
|
|
482
535
|
}
|
|
483
536
|
|
|
484
537
|
function groupedChildPassthrough(layer: CanvasLayer): boolean {
|
|
538
|
+
if (getAncestors(workingLayers, layer.id).some((a) => selectedSet.has(a.id))) return true;
|
|
485
539
|
if (selectedSet.has(layer.id)) return false;
|
|
486
540
|
return !!enclosingGroupId(workingLayers, layer.id);
|
|
487
541
|
}
|
|
@@ -1335,6 +1389,8 @@
|
|
|
1335
1389
|
selected={isSelected}
|
|
1336
1390
|
showHandles={isSelected && selectedIds.length === 1}
|
|
1337
1391
|
passthrough={lockedPass || groupedChildPassthrough(layer)}
|
|
1392
|
+
followStageRect={selectedIds.length > 1 ||
|
|
1393
|
+
!!selectedAncestorId(workingLayers, realId, selectedSet)}
|
|
1338
1394
|
readOnly={isSynthetic}
|
|
1339
1395
|
layoutPositionLocked={positionLocked || (marqueeBg && !dragOk)}
|
|
1340
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, 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, 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';
|
|
@@ -182,7 +182,7 @@ export declare function updateCanvasLayers(doc: CanvasDocument, ids: string[], u
|
|
|
182
182
|
export declare function snapLayerRect(rect: CanvasLayerRect, cellSize: number, enabled: boolean, bounds: {
|
|
183
183
|
width: number;
|
|
184
184
|
height: number;
|
|
185
|
-
}, minW?: number, minH?: number, guides?: Pick<CanvasGuide, 'orientation' | 'position'>[], guideThreshold?: number): CanvasLayerRect;
|
|
185
|
+
}, minW?: number, minH?: number, guides?: Pick<CanvasGuide, 'orientation' | 'position'>[], guideThreshold?: number, clampToBounds?: boolean): CanvasLayerRect;
|
|
186
186
|
/** Snap left / center / right (or top / middle / bottom) edges to guides. */
|
|
187
187
|
export declare function snapRectToGuides(rect: CanvasLayerRect, guides: Pick<CanvasGuide, 'orientation' | 'position'>[], threshold?: number): CanvasLayerRect;
|
|
188
188
|
export declare function alignLayerRect(rect: CanvasLayerRect, bounds: {
|
|
@@ -149,7 +149,8 @@ export function createCanvasLayer(kind, partial) {
|
|
|
149
149
|
text: partial?.text ?? d.text,
|
|
150
150
|
fill: partial?.fill ?? d.fill,
|
|
151
151
|
stroke: partial?.stroke,
|
|
152
|
-
strokeWidth: partial?.strokeWidth ??
|
|
152
|
+
strokeWidth: partial?.strokeWidth ??
|
|
153
|
+
(kind === 'line' || kind === 'arrow' || kind === 'path' ? 4 : undefined),
|
|
153
154
|
fontSize: partial?.fontSize ?? d.fontSize,
|
|
154
155
|
fontWeight: partial?.fontWeight,
|
|
155
156
|
fontFamily: partial?.fontFamily,
|
|
@@ -176,7 +177,7 @@ export function createCanvasLayer(kind, partial) {
|
|
|
176
177
|
clipChildren: partial?.clipChildren ?? d.clipChildren ?? false,
|
|
177
178
|
autoSizeChildren: partial?.autoSizeChildren ?? d.autoSizeChildren ?? (kind === 'group' ? true : undefined),
|
|
178
179
|
gap: partial?.gap ?? d.gap,
|
|
179
|
-
slotName: partial?.slotName ?? (kind === 'namedSlot' ? partial?.name ?? d.name : undefined),
|
|
180
|
+
slotName: partial?.slotName ?? (kind === 'namedSlot' ? (partial?.name ?? d.name) : undefined),
|
|
180
181
|
fillSlot: partial?.fillSlot,
|
|
181
182
|
columns: partial?.columns ?? (kind === 'uniformGrid' ? 2 : undefined),
|
|
182
183
|
definitionId: partial?.definitionId,
|
|
@@ -324,7 +325,7 @@ export function updateCanvasLayers(doc, ids, updater) {
|
|
|
324
325
|
layers: doc.layers.map((l) => (set.has(l.id) ? updater(l) : l))
|
|
325
326
|
};
|
|
326
327
|
}
|
|
327
|
-
export function snapLayerRect(rect, cellSize, enabled, bounds, minW = 24, minH = 24, guides = [], guideThreshold = 8) {
|
|
328
|
+
export function snapLayerRect(rect, cellSize, enabled, bounds, minW = 24, minH = 24, guides = [], guideThreshold = 8, clampToBounds = true) {
|
|
328
329
|
const snap = (v) => (enabled ? Math.round(v / cellSize) * cellSize : v);
|
|
329
330
|
let w = Math.max(minW, enabled ? snap(rect.w) : rect.w);
|
|
330
331
|
let h = Math.max(minH, enabled ? snap(rect.h) : rect.h);
|
|
@@ -335,10 +336,12 @@ export function snapLayerRect(rect, cellSize, enabled, bounds, minW = 24, minH =
|
|
|
335
336
|
x = snapped.x;
|
|
336
337
|
y = snapped.y;
|
|
337
338
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
if (clampToBounds) {
|
|
340
|
+
x = Math.min(Math.max(0, x), Math.max(0, bounds.width - w));
|
|
341
|
+
y = Math.min(Math.max(0, y), Math.max(0, bounds.height - h));
|
|
342
|
+
w = Math.min(w, bounds.width - x);
|
|
343
|
+
h = Math.min(h, bounds.height - y);
|
|
344
|
+
}
|
|
342
345
|
return { x, y, w, h };
|
|
343
346
|
}
|
|
344
347
|
/** Snap left / center / right (or top / middle / bottom) edges to guides. */
|
|
@@ -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
|
|
@@ -261,3 +271,12 @@ export declare function scaleSelectionAbsolute(layers: CanvasLayer[], selectedId
|
|
|
261
271
|
width: number;
|
|
262
272
|
height: number;
|
|
263
273
|
}): CanvasLayer[];
|
|
274
|
+
/**
|
|
275
|
+
* Translate a multi-selection as one rigid body. Only top-level selected layers
|
|
276
|
+
* move; descendants keep parent-local coords so a group+child selection does not
|
|
277
|
+
* double-shift nested items.
|
|
278
|
+
*/
|
|
279
|
+
export declare function translateSelectionAbsolute(layers: CanvasLayer[], selectedIds: string[], dx: number, dy: number, rootSize: {
|
|
280
|
+
width: number;
|
|
281
|
+
height: number;
|
|
282
|
+
}, absMap?: Map<string, CanvasLayerRect>): CanvasLayer[];
|
|
@@ -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) => {
|
|
@@ -985,3 +1000,22 @@ export function scaleSelectionAbsolute(layers, selectedIds, prevBox, nextBox, ro
|
|
|
985
1000
|
}
|
|
986
1001
|
return applyAbsoluteRects(layers, nextAbsMap, absMap, rootSize);
|
|
987
1002
|
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Translate a multi-selection as one rigid body. Only top-level selected layers
|
|
1005
|
+
* move; descendants keep parent-local coords so a group+child selection does not
|
|
1006
|
+
* double-shift nested items.
|
|
1007
|
+
*/
|
|
1008
|
+
export function translateSelectionAbsolute(layers, selectedIds, dx, dy, rootSize, absMap = computeAbsoluteRects(layers, rootSize)) {
|
|
1009
|
+
if (Math.abs(dx) < 0.01 && Math.abs(dy) < 0.01)
|
|
1010
|
+
return layers;
|
|
1011
|
+
const byId = new Map(layers.map((l) => [l.id, l]));
|
|
1012
|
+
const top = new Set(topLevelSelectedIds(layers, selectedIds));
|
|
1013
|
+
return layers.map((l) => {
|
|
1014
|
+
if (!top.has(l.id))
|
|
1015
|
+
return l;
|
|
1016
|
+
const a = absMap.get(l.id) ?? l.rect;
|
|
1017
|
+
const parent = l.parentId ? (byId.get(l.parentId) ?? null) : null;
|
|
1018
|
+
const parentAbs = l.parentId ? (absMap.get(l.parentId) ?? null) : rootFrame(rootSize);
|
|
1019
|
+
return layerFromAbsoluteRect(l, { x: a.x + dx, y: a.y + dy, w: a.w, h: a.h }, parentAbs, parent, rootSize);
|
|
1020
|
+
});
|
|
1021
|
+
}
|