From ab939c202e00399ed94b122a134eb6224031947d Mon Sep 17 00:00:00 2001 From: root Date: Thu, 1 Jan 2026 01:39:03 +0100 Subject: [PATCH] [FEAT] Calc. fixes --- src/composables/useExportLayers.ts | 9 +++++---- src/composables/useLayers.ts | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/composables/useExportLayers.ts b/src/composables/useExportLayers.ts index 8d7440d..90dee94 100644 --- a/src/composables/useExportLayers.ts +++ b/src/composables/useExportLayers.ts @@ -20,10 +20,11 @@ export const useExportLayers = (layersRef: Ref, columns: Ref, n }; } - // Otherwise, calculate from sprite dimensions - const visibleLayers = getVisibleLayers(); - const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(visibleLayers); - const negativeSpacing = calculateNegativeSpacing(getAllVisibleSprites(), negativeSpacingEnabled.value); + // Otherwise, calculate from sprite dimensions across ALL layers (same as canvas) + // This ensures export dimensions match what's shown in the canvas + const { maxWidth, maxHeight } = getMaxDimensionsAcrossLayers(layersRef.value); + const allSprites = getVisibleLayers().flatMap(l => l.sprites); + const negativeSpacing = calculateNegativeSpacing(allSprites, negativeSpacingEnabled.value); return { cellWidth: maxWidth + negativeSpacing, cellHeight: maxHeight + negativeSpacing, diff --git a/src/composables/useLayers.ts b/src/composables/useLayers.ts index 5544008..47d8b8c 100644 --- a/src/composables/useLayers.ts +++ b/src/composables/useLayers.ts @@ -356,8 +356,9 @@ export const useLayers = () => { }; }; -export const getMaxDimensionsAcrossLayers = (layers: Layer[]) => { - // Consider ALL layers regardless of visibility to keep canvas size stable - const sprites = layers.flatMap(l => l.sprites); +export const getMaxDimensionsAcrossLayers = (layers: Layer[], visibleOnly: boolean = false) => { + // When visibleOnly is false (default), consider ALL layers to keep canvas size stable + // When visibleOnly is true (export), only consider visible layers + const sprites = layers.flatMap(l => (visibleOnly ? (l.visible ? l.sprites : []) : l.sprites)); return getMaxDimensionsSingle(sprites); };