@r2digisolutions/components 0.21.2 → 0.21.4
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/MediaStage/MediaStage.svelte +92 -38
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/utils/canvasDocument.d.ts +1 -1
- package/dist/utils/canvasDocument.js +10 -7
- package/dist/utils/canvasHierarchy.d.ts +11 -0
- package/dist/utils/canvasHierarchy.js +22 -0
- package/dist/utils/marqueeSelect.d.ts +2 -0
- package/dist/utils/marqueeSelect.js +32 -7
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
} from '../WidgetCanvas/widgetCanvasContext.js';
|
|
14
14
|
import {
|
|
15
15
|
attachMarqueeSelect,
|
|
16
|
+
mergeMarqueeItemsById,
|
|
16
17
|
resolveMarqueeSelection,
|
|
17
18
|
type MarqueeRect as MarqueeBox
|
|
18
19
|
} from '../../../utils/marqueeSelect.js';
|
|
@@ -48,7 +49,9 @@
|
|
|
48
49
|
scrollBoxOverflow,
|
|
49
50
|
scrollBarMetrics,
|
|
50
51
|
selectionAncestorIds,
|
|
51
|
-
clipPathForLayer
|
|
52
|
+
clipPathForLayer,
|
|
53
|
+
topLevelSelectedIds,
|
|
54
|
+
translateSelectionAbsolute
|
|
52
55
|
} from '../../../utils/canvasHierarchy.js';
|
|
53
56
|
import { flattenLayersWithWidgets } from '../../../utils/canvasWidget.js';
|
|
54
57
|
import { backgroundAlpha } from '../../../utils/canvasExport.js';
|
|
@@ -192,6 +195,11 @@
|
|
|
192
195
|
let selectionLive = $state<{ x: number; y: number; w: number; h: number } | null>(null);
|
|
193
196
|
let selectionBaseLayers = $state<CanvasLayer[] | null>(null);
|
|
194
197
|
let selectionBaseBox = $state<{ x: number; y: number; w: number; h: number } | null>(null);
|
|
198
|
+
/** Snapshot for rigid multi-select drag (from pointer-down, not last frame). */
|
|
199
|
+
let moveBaseLayers = $state<CanvasLayer[] | null>(null);
|
|
200
|
+
let moveBaseAbs = $state<Map<string, { x: number; y: number; w: number; h: number }> | null>(
|
|
201
|
+
null
|
|
202
|
+
);
|
|
195
203
|
const selectionFrame = $derived(selectionLive ?? selectionBounds);
|
|
196
204
|
|
|
197
205
|
const fitScale = $derived.by(() => {
|
|
@@ -290,7 +298,14 @@
|
|
|
290
298
|
return r;
|
|
291
299
|
},
|
|
292
300
|
clampRect(rect: WidgetRect, minW: number, minH: number) {
|
|
293
|
-
|
|
301
|
+
const sized = {
|
|
302
|
+
...rect,
|
|
303
|
+
w: Math.max(minW, rect.w),
|
|
304
|
+
h: Math.max(minH, rect.h)
|
|
305
|
+
};
|
|
306
|
+
// Snap on = stay on the artboard. Snap off = free, including off-canvas.
|
|
307
|
+
if (!snap) return sized;
|
|
308
|
+
return clampWidgetRect(sized, { width: doc.width, height: doc.height }, minW, minH);
|
|
294
309
|
}
|
|
295
310
|
};
|
|
296
311
|
|
|
@@ -333,25 +348,53 @@
|
|
|
333
348
|
});
|
|
334
349
|
}
|
|
335
350
|
|
|
336
|
-
function commitGroupGeometry(next: CanvasLayer[]) {
|
|
337
|
-
draftLayers = fitGroupsToChildren(next, { width: doc.width, height: doc.height });
|
|
338
|
-
if (interactCount === 0) commitDraft();
|
|
339
|
-
}
|
|
340
|
-
|
|
341
351
|
function commitDraft() {
|
|
342
352
|
if (!draftLayers) return;
|
|
343
|
-
const layers = draftLayers;
|
|
353
|
+
const layers = fitGroupsToChildren(draftLayers, { width: doc.width, height: doc.height });
|
|
344
354
|
draftLayers = null;
|
|
345
355
|
ondocumentchange?.({ ...doc, layers });
|
|
346
356
|
}
|
|
347
357
|
|
|
358
|
+
function commitGroupGeometry(next: CanvasLayer[]) {
|
|
359
|
+
if (interactCount > 0) {
|
|
360
|
+
draftLayers = next;
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
draftLayers = fitGroupsToChildren(next, { width: doc.width, height: doc.height });
|
|
364
|
+
commitDraft();
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function clearMoveSnapshot() {
|
|
368
|
+
moveBaseLayers = null;
|
|
369
|
+
moveBaseAbs = null;
|
|
370
|
+
}
|
|
371
|
+
|
|
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
|
+
|
|
348
384
|
function handleLayerInteract(active: boolean) {
|
|
349
385
|
if (active) {
|
|
350
386
|
interactCount += 1;
|
|
387
|
+
if (selectedIds.length > 1 && !moveBaseLayers) {
|
|
388
|
+
moveBaseLayers = workingLayers;
|
|
389
|
+
moveBaseAbs = new Map(absMap);
|
|
390
|
+
}
|
|
351
391
|
return;
|
|
352
392
|
}
|
|
353
393
|
interactCount = Math.max(0, interactCount - 1);
|
|
354
|
-
if (interactCount === 0)
|
|
394
|
+
if (interactCount === 0) {
|
|
395
|
+
clearMoveSnapshot();
|
|
396
|
+
commitDraft();
|
|
397
|
+
}
|
|
355
398
|
}
|
|
356
399
|
|
|
357
400
|
function cancelLayerDraft() {
|
|
@@ -360,6 +403,7 @@
|
|
|
360
403
|
selectionBaseLayers = null;
|
|
361
404
|
selectionBaseBox = null;
|
|
362
405
|
selectionLive = null;
|
|
406
|
+
clearMoveSnapshot();
|
|
363
407
|
}
|
|
364
408
|
|
|
365
409
|
function isLayoutLocked(layer: CanvasLayer): boolean {
|
|
@@ -394,7 +438,9 @@
|
|
|
394
438
|
{ width: doc.width, height: doc.height },
|
|
395
439
|
minW,
|
|
396
440
|
minH,
|
|
397
|
-
guideSnapList
|
|
441
|
+
guideSnapList,
|
|
442
|
+
8,
|
|
443
|
+
false
|
|
398
444
|
);
|
|
399
445
|
|
|
400
446
|
const prevAbs = absMap.get(source.id) ?? source.rect;
|
|
@@ -416,21 +462,34 @@
|
|
|
416
462
|
(Math.abs(dx) > 0.01 || Math.abs(dy) > 0.01);
|
|
417
463
|
|
|
418
464
|
if (groupMove) {
|
|
465
|
+
const baseLayers = moveBaseLayers ?? layers;
|
|
466
|
+
const baseAbs = moveBaseAbs ?? absMap;
|
|
467
|
+
const start = baseAbs.get(source.id) ?? source.rect;
|
|
468
|
+
let moveDx = nextAbs.x - start.x;
|
|
469
|
+
let moveDy = nextAbs.y - start.y;
|
|
470
|
+
const movableIds = selectedIds.filter(
|
|
471
|
+
(id) =>
|
|
472
|
+
!isEffectivelyLocked(workingLayers, id, workingById) &&
|
|
473
|
+
!isLayoutPositionLocked(workingLayers, id, workingById)
|
|
474
|
+
);
|
|
475
|
+
if (snap) {
|
|
476
|
+
const top = topLevelSelectedIds(baseLayers, movableIds);
|
|
477
|
+
const union = unionAbsRect(baseAbs, top);
|
|
478
|
+
if (union) {
|
|
479
|
+
const clamped = clampDeltaToKeepUnion(union, moveDx, moveDy);
|
|
480
|
+
moveDx = clamped.dx;
|
|
481
|
+
moveDy = clamped.dy;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
419
484
|
commitGroupGeometry(
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
y: a.y + dy,
|
|
429
|
-
w: a.w,
|
|
430
|
-
h: a.h
|
|
431
|
-
};
|
|
432
|
-
return absToLocalUpdate(l, moved);
|
|
433
|
-
})
|
|
485
|
+
translateSelectionAbsolute(
|
|
486
|
+
baseLayers,
|
|
487
|
+
movableIds,
|
|
488
|
+
moveDx,
|
|
489
|
+
moveDy,
|
|
490
|
+
{ width: doc.width, height: doc.height },
|
|
491
|
+
baseAbs
|
|
492
|
+
)
|
|
434
493
|
);
|
|
435
494
|
return;
|
|
436
495
|
}
|
|
@@ -473,13 +532,10 @@
|
|
|
473
532
|
selectionLive = rect;
|
|
474
533
|
if (!selectionBaseLayers || !selectionBaseBox) return;
|
|
475
534
|
commitGroupGeometry(
|
|
476
|
-
scaleSelectionAbsolute(
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
rect,
|
|
481
|
-
{ width: doc.width, height: doc.height }
|
|
482
|
-
)
|
|
535
|
+
scaleSelectionAbsolute(selectionBaseLayers, selectedIds, selectionBaseBox, rect, {
|
|
536
|
+
width: doc.width,
|
|
537
|
+
height: doc.height
|
|
538
|
+
})
|
|
483
539
|
);
|
|
484
540
|
}
|
|
485
541
|
|
|
@@ -563,16 +619,12 @@
|
|
|
563
619
|
const originX = aRect.left - vRect.left + viewportEl.scrollLeft;
|
|
564
620
|
const originY = aRect.top - vRect.top + viewportEl.scrollTop;
|
|
565
621
|
const s = scale;
|
|
566
|
-
|
|
622
|
+
const items = sorted
|
|
567
623
|
.filter((l) => {
|
|
568
|
-
if (
|
|
569
|
-
!effectivelyVisible.has(l.id) ||
|
|
570
|
-
isEffectivelyLocked(workingLayers, l.id, workingById)
|
|
571
|
-
) {
|
|
572
|
-
return false;
|
|
573
|
-
}
|
|
624
|
+
if (!effectivelyVisible.has(l.id)) return false;
|
|
574
625
|
const realId = resolveSelectableId(l.id);
|
|
575
626
|
if (!sceneLayerIds.has(realId)) return false;
|
|
627
|
+
if (isEffectivelyLocked(workingLayers, realId, workingById)) return false;
|
|
576
628
|
// Don't always rubber-band-select the full-bleed root panel.
|
|
577
629
|
const scene = workingLayers.find((x) => x.id === realId);
|
|
578
630
|
if (scene?.kind === 'canvasPanel') return false;
|
|
@@ -588,6 +640,8 @@
|
|
|
588
640
|
height: r.h * s
|
|
589
641
|
};
|
|
590
642
|
});
|
|
643
|
+
// Flattened widgets emit host + synthetic children with the same selectable id.
|
|
644
|
+
return mergeMarqueeItemsById(items);
|
|
591
645
|
}
|
|
592
646
|
|
|
593
647
|
function clientToDoc(clientX: number, clientY: number) {
|
package/dist/index.d.ts
CHANGED
|
@@ -842,7 +842,7 @@ export type { VisibilityState } from './utils/pageVisibility.svelte.js';
|
|
|
842
842
|
export { network } from './utils/network.svelte.js';
|
|
843
843
|
export { DEFAULT_COLS, DEFAULT_ROW_HEIGHT, DEFAULT_GAP, GRID_DENSITY, clampItem, rectsOverlap, findCollisions, resolveCollisions, compactLayout, updateItem, addItem, removeItem, serializeLayout, parseLayout, layoutBounds, rescaleLayout, resizeItemByEdge } from './utils/layoutGrid.js';
|
|
844
844
|
export type { GridItem, LayoutGridOptions, GridDensity, GridResizeEdge } from './utils/layoutGrid.js';
|
|
845
|
-
export { attachMarqueeSelect, collectMarqueeItems, defaultMarqueeIgnore, getMarqueeModifier, hitTestIds, normalizeRect, rectsIntersect, resolveMarqueeSelection } from './utils/marqueeSelect.js';
|
|
845
|
+
export { attachMarqueeSelect, collectMarqueeItems, defaultMarqueeIgnore, getMarqueeModifier, hitTestIds, mergeMarqueeItemsById, normalizeRect, rectsIntersect, resolveMarqueeSelection } from './utils/marqueeSelect.js';
|
|
846
846
|
export type { AttachMarqueeSelectOptions, MarqueeDragState, MarqueeItemRect, MarqueeModifier, MarqueeRect as MarqueeRectBox } from './utils/marqueeSelect.js';
|
|
847
847
|
export { encodeQR, qrToSvgPath, punchLogoHole } from './utils/qr.js';
|
|
848
848
|
export { renderMarkdown, renderInline, escapeHtml, splitTableRow, slugifyHeading } from './utils/markdown.js';
|
|
@@ -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, 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
|
@@ -573,7 +573,7 @@ export { resolveAccessor, accessorPatchKey, resolveRowKey } from './utils/column
|
|
|
573
573
|
export { pageVisibility } from './utils/pageVisibility.svelte.js';
|
|
574
574
|
export { network } from './utils/network.svelte.js';
|
|
575
575
|
export { DEFAULT_COLS, DEFAULT_ROW_HEIGHT, DEFAULT_GAP, GRID_DENSITY, clampItem, rectsOverlap, findCollisions, resolveCollisions, compactLayout, updateItem, addItem, removeItem, serializeLayout, parseLayout, layoutBounds, rescaleLayout, resizeItemByEdge } from './utils/layoutGrid.js';
|
|
576
|
-
export { attachMarqueeSelect, collectMarqueeItems, defaultMarqueeIgnore, getMarqueeModifier, hitTestIds, normalizeRect, rectsIntersect, resolveMarqueeSelection } from './utils/marqueeSelect.js';
|
|
576
|
+
export { attachMarqueeSelect, collectMarqueeItems, defaultMarqueeIgnore, getMarqueeModifier, hitTestIds, mergeMarqueeItemsById, normalizeRect, rectsIntersect, resolveMarqueeSelection } from './utils/marqueeSelect.js';
|
|
577
577
|
export { encodeQR, qrToSvgPath, punchLogoHole } from './utils/qr.js';
|
|
578
578
|
export { renderMarkdown, renderInline, escapeHtml, splitTableRow, slugifyHeading } from './utils/markdown.js';
|
|
579
579
|
export { diffLines, diffWords, diffStats, toSplitRows } from './utils/diff.js';
|
|
@@ -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, 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. */
|
|
@@ -9,6 +9,8 @@ export declare const LAYOUT_SIZE_KINDS: ReadonlySet<CanvasLayerKind>;
|
|
|
9
9
|
* Structural shells whose empty area should start a marquee (not a layer drag),
|
|
10
10
|
* matching Figma-style select-drag on the canvas / inside frames.
|
|
11
11
|
* Groups are omitted: they behave like a single object (click/drag the group).
|
|
12
|
+
* Widgets pass when unselected so flattened instance bounds don't eat rubber-band;
|
|
13
|
+
* a selected widget still drag-moves.
|
|
12
14
|
*/
|
|
13
15
|
export declare const MARQUEE_PASS_KINDS: ReadonlySet<CanvasLayerKind>;
|
|
14
16
|
export declare function isContainerKind(kind: CanvasLayerKind): boolean;
|
|
@@ -259,3 +261,12 @@ export declare function scaleSelectionAbsolute(layers: CanvasLayer[], selectedId
|
|
|
259
261
|
width: number;
|
|
260
262
|
height: number;
|
|
261
263
|
}): CanvasLayer[];
|
|
264
|
+
/**
|
|
265
|
+
* Translate a multi-selection as one rigid body. Only top-level selected layers
|
|
266
|
+
* move; descendants keep parent-local coords so a group+child selection does not
|
|
267
|
+
* double-shift nested items.
|
|
268
|
+
*/
|
|
269
|
+
export declare function translateSelectionAbsolute(layers: CanvasLayer[], selectedIds: string[], dx: number, dy: number, rootSize: {
|
|
270
|
+
width: number;
|
|
271
|
+
height: number;
|
|
272
|
+
}, absMap?: Map<string, CanvasLayerRect>): CanvasLayer[];
|
|
@@ -40,10 +40,13 @@ export const LAYOUT_SIZE_KINDS = new Set(['uniformGrid', 'scaleBox']);
|
|
|
40
40
|
* Structural shells whose empty area should start a marquee (not a layer drag),
|
|
41
41
|
* matching Figma-style select-drag on the canvas / inside frames.
|
|
42
42
|
* Groups are omitted: they behave like a single object (click/drag the group).
|
|
43
|
+
* Widgets pass when unselected so flattened instance bounds don't eat rubber-band;
|
|
44
|
+
* a selected widget still drag-moves.
|
|
43
45
|
*/
|
|
44
46
|
export const MARQUEE_PASS_KINDS = new Set([
|
|
45
47
|
'canvasPanel',
|
|
46
48
|
'overlay',
|
|
49
|
+
'widget',
|
|
47
50
|
...LAYOUT_BOX_KINDS
|
|
48
51
|
]);
|
|
49
52
|
export function isContainerKind(kind) {
|
|
@@ -982,3 +985,22 @@ export function scaleSelectionAbsolute(layers, selectedIds, prevBox, nextBox, ro
|
|
|
982
985
|
}
|
|
983
986
|
return applyAbsoluteRects(layers, nextAbsMap, absMap, rootSize);
|
|
984
987
|
}
|
|
988
|
+
/**
|
|
989
|
+
* Translate a multi-selection as one rigid body. Only top-level selected layers
|
|
990
|
+
* move; descendants keep parent-local coords so a group+child selection does not
|
|
991
|
+
* double-shift nested items.
|
|
992
|
+
*/
|
|
993
|
+
export function translateSelectionAbsolute(layers, selectedIds, dx, dy, rootSize, absMap = computeAbsoluteRects(layers, rootSize)) {
|
|
994
|
+
if (Math.abs(dx) < 0.01 && Math.abs(dy) < 0.01)
|
|
995
|
+
return layers;
|
|
996
|
+
const byId = new Map(layers.map((l) => [l.id, l]));
|
|
997
|
+
const top = new Set(topLevelSelectedIds(layers, selectedIds));
|
|
998
|
+
return layers.map((l) => {
|
|
999
|
+
if (!top.has(l.id))
|
|
1000
|
+
return l;
|
|
1001
|
+
const a = absMap.get(l.id) ?? l.rect;
|
|
1002
|
+
const parent = l.parentId ? (byId.get(l.parentId) ?? null) : null;
|
|
1003
|
+
const parentAbs = l.parentId ? (absMap.get(l.parentId) ?? null) : rootFrame(rootSize);
|
|
1004
|
+
return layerFromAbsoluteRect(l, { x: a.x + dx, y: a.y + dy, w: a.w, h: a.h }, parentAbs, parent, rootSize);
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
@@ -36,6 +36,8 @@ export interface AttachMarqueeSelectOptions {
|
|
|
36
36
|
export declare function normalizeRect(x0: number, y0: number, x1: number, y1: number): MarqueeRect;
|
|
37
37
|
export declare function rectsIntersect(a: MarqueeRect, b: MarqueeRect): boolean;
|
|
38
38
|
export declare function hitTestIds(marquee: MarqueeRect, items: MarqueeItemRect[]): string[];
|
|
39
|
+
/** Collapse duplicate ids (e.g. widget host + synthetic children) into one union box. */
|
|
40
|
+
export declare function mergeMarqueeItemsById(items: MarqueeItemRect[]): MarqueeItemRect[];
|
|
39
41
|
export declare function getMarqueeModifier(e: Pick<PointerEvent, 'shiftKey' | 'metaKey' | 'ctrlKey'>): MarqueeModifier;
|
|
40
42
|
export declare function resolveMarqueeSelection(hitIds: string[], previousIds: string[], modifier: MarqueeModifier): string[];
|
|
41
43
|
/** Collect `[data-marquee-id]` children in container-local (incl. scroll) coordinates. */
|
|
@@ -9,19 +9,44 @@ export function normalizeRect(x0, y0, x1, y1) {
|
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
11
|
export function rectsIntersect(a, b) {
|
|
12
|
-
return
|
|
13
|
-
a.x + a.width > b.x &&
|
|
14
|
-
a.y < b.y + b.height &&
|
|
15
|
-
a.y + a.height > b.y);
|
|
12
|
+
return a.x < b.x + b.width && a.x + a.width > b.x && a.y < b.y + b.height && a.y + a.height > b.y;
|
|
16
13
|
}
|
|
17
14
|
export function hitTestIds(marquee, items) {
|
|
18
15
|
const ids = [];
|
|
16
|
+
const seen = new Set();
|
|
19
17
|
for (const item of items) {
|
|
20
|
-
if (rectsIntersect(marquee, item))
|
|
21
|
-
|
|
18
|
+
if (!rectsIntersect(marquee, item))
|
|
19
|
+
continue;
|
|
20
|
+
if (seen.has(item.id))
|
|
21
|
+
continue;
|
|
22
|
+
seen.add(item.id);
|
|
23
|
+
ids.push(item.id);
|
|
22
24
|
}
|
|
23
25
|
return ids;
|
|
24
26
|
}
|
|
27
|
+
/** Collapse duplicate ids (e.g. widget host + synthetic children) into one union box. */
|
|
28
|
+
export function mergeMarqueeItemsById(items) {
|
|
29
|
+
const map = new Map();
|
|
30
|
+
for (const item of items) {
|
|
31
|
+
const prev = map.get(item.id);
|
|
32
|
+
if (!prev) {
|
|
33
|
+
map.set(item.id, item);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const left = Math.min(prev.x, item.x);
|
|
37
|
+
const top = Math.min(prev.y, item.y);
|
|
38
|
+
const right = Math.max(prev.x + prev.width, item.x + item.width);
|
|
39
|
+
const bottom = Math.max(prev.y + prev.height, item.y + item.height);
|
|
40
|
+
map.set(item.id, {
|
|
41
|
+
id: item.id,
|
|
42
|
+
x: left,
|
|
43
|
+
y: top,
|
|
44
|
+
width: right - left,
|
|
45
|
+
height: bottom - top
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return [...map.values()];
|
|
49
|
+
}
|
|
25
50
|
export function getMarqueeModifier(e) {
|
|
26
51
|
if (e.metaKey || e.ctrlKey)
|
|
27
52
|
return 'toggle';
|
|
@@ -31,7 +56,7 @@ export function getMarqueeModifier(e) {
|
|
|
31
56
|
}
|
|
32
57
|
export function resolveMarqueeSelection(hitIds, previousIds, modifier) {
|
|
33
58
|
if (modifier === 'replace')
|
|
34
|
-
return [...hitIds];
|
|
59
|
+
return [...new Set(hitIds)];
|
|
35
60
|
if (modifier === 'add')
|
|
36
61
|
return [...new Set([...previousIds, ...hitIds])];
|
|
37
62
|
const set = new Set(previousIds);
|