feat: add contextual layer inspector

This commit is contained in:
syntaxbullet
2026-07-11 12:07:36 +02:00
parent bef2fb3051
commit 4d7358af4b
14 changed files with 405 additions and 42 deletions

View File

@@ -143,6 +143,25 @@ export function addLayerMask(documentIndex: DocumentReadIndex, layerInfo: Indexe
});
}
export function duplicateLayer(documentIndex: DocumentReadIndex, layerInfo: IndexedLayerInfo, dispatch: AppStore["dispatch"]) {
const ids = collectDuplicateIds(layerInfo.layer, layerInfo.siblings);
dispatch(commandIds.documentDuplicateLayer, {
layerId: layerInfo.layer.id,
idByLayerId: Object.fromEntries(ids.map((id) => [id, crypto.randomUUID()])),
});
}
function collectDuplicateIds(layer: Layer, siblings: readonly Layer[]): string[] {
const ids = collectTreeIds(layer);
const maskId = getLayerMask(layer)?.maskLayerId;
const mask = maskId ? siblings.find((candidate) => candidate.id === maskId) : undefined;
return mask ? [...collectTreeIds(mask), ...ids] : ids;
}
function collectTreeIds(layer: Layer): string[] {
return [layer.id, ...(layer.type === "group" ? layer.children.flatMap(collectTreeIds) : [])];
}
const emptyLayerIds = new Set<string>();
function createGroup(name: string): Extract<Layer, { type: "group" }> {