2026-05-21 00:02:12 +07:00
|
|
|
export { createProject, setCanvasSize } from "./project";
|
2026-05-31 03:03:49 +07:00
|
|
|
export {
|
|
|
|
|
createLayer,
|
|
|
|
|
addLayer,
|
|
|
|
|
removeLayer,
|
|
|
|
|
moveLayer,
|
|
|
|
|
updateLayerTransform,
|
|
|
|
|
reorderLayer,
|
|
|
|
|
setLayerEffect,
|
|
|
|
|
removeLayerEffect,
|
|
|
|
|
setLayerVisible,
|
|
|
|
|
setEffectEnabled,
|
|
|
|
|
} from "./layers";
|
2026-05-21 00:02:12 +07:00
|
|
|
export type { LayerFactoryOptions, TransformPatch } from "./layers";
|
|
|
|
|
export { normalizeProject } from "./normalize";
|
|
|
|
|
export { serializeProjectFile, parseProjectFile } from "./serialization";
|
|
|
|
|
export { getEffectDefinition, normalizeEffect } from "./effects/registry";
|
|
|
|
|
export type { EffectDefinition } from "./effects/registry";
|
|
|
|
|
export { faceBlurDefinition } from "./effects/face-blur";
|
|
|
|
|
export { getToolDefinition, getAllTools } from "./tools/registry";
|
2026-05-31 03:03:49 +07:00
|
|
|
export type {
|
|
|
|
|
ToolDefinition,
|
|
|
|
|
ToolInteractionMode,
|
|
|
|
|
EditorToolId,
|
|
|
|
|
} from "./tools/registry";
|
|
|
|
|
export {
|
|
|
|
|
HISTORY_LIMIT,
|
|
|
|
|
capHistory,
|
|
|
|
|
cloneLayer,
|
|
|
|
|
cloneProject,
|
|
|
|
|
computeHistoryFlags,
|
|
|
|
|
deepClone,
|
|
|
|
|
makeHistory,
|
|
|
|
|
resolveSelectedLayerId,
|
|
|
|
|
} from "./history";
|
|
|
|
|
export type { HistoryState } from "./history";
|
2026-05-10 03:06:54 +07:00
|
|
|
|
2026-05-21 00:02:12 +07:00
|
|
|
import type { Layer, LayerEffect, Project } from "@pien-studio/types";
|
2026-05-31 03:03:49 +07:00
|
|
|
import {
|
|
|
|
|
addLayer,
|
|
|
|
|
moveLayer,
|
|
|
|
|
removeLayer,
|
|
|
|
|
reorderLayer,
|
|
|
|
|
setLayerEffect,
|
|
|
|
|
updateLayerTransform,
|
|
|
|
|
} from "./layers";
|
2026-05-21 00:02:12 +07:00
|
|
|
import { setCanvasSize } from "./project";
|
2026-05-10 03:06:54 +07:00
|
|
|
|
|
|
|
|
export type EditorOperation =
|
|
|
|
|
| { type: "addLayer"; layer: Layer }
|
|
|
|
|
| { type: "removeLayer"; layerId: string }
|
2026-05-21 00:02:12 +07:00
|
|
|
| { type: "moveLayer"; layerId: string; delta: { dx: number; dy: number } }
|
2026-05-31 03:03:49 +07:00
|
|
|
| {
|
|
|
|
|
type: "updateLayerTransform";
|
|
|
|
|
layerId: string;
|
|
|
|
|
patch: import("./layers").TransformPatch;
|
|
|
|
|
}
|
2026-05-10 03:06:54 +07:00
|
|
|
| { type: "reorderLayer"; layerId: string; toIndex: number }
|
2026-05-21 00:02:12 +07:00
|
|
|
| { type: "setLayerEffect"; layerId: string; effect: LayerEffect }
|
2026-05-31 03:03:49 +07:00
|
|
|
| {
|
|
|
|
|
type: "setCanvasSize";
|
|
|
|
|
width: number;
|
|
|
|
|
height: number;
|
|
|
|
|
unit?: "px" | "in" | "cm";
|
|
|
|
|
};
|
2026-05-10 03:06:54 +07:00
|
|
|
|
2026-05-31 03:03:49 +07:00
|
|
|
export function applyOperation(
|
|
|
|
|
project: Project,
|
|
|
|
|
operation: EditorOperation,
|
|
|
|
|
): Project {
|
2026-05-10 03:06:54 +07:00
|
|
|
switch (operation.type) {
|
2026-05-31 03:03:49 +07:00
|
|
|
case "addLayer":
|
|
|
|
|
return addLayer(project, operation.layer);
|
|
|
|
|
case "removeLayer":
|
|
|
|
|
return removeLayer(project, operation.layerId);
|
|
|
|
|
case "moveLayer":
|
|
|
|
|
return moveLayer(project, operation.layerId, operation.delta);
|
|
|
|
|
case "updateLayerTransform":
|
|
|
|
|
return updateLayerTransform(project, operation.layerId, operation.patch);
|
|
|
|
|
case "reorderLayer":
|
|
|
|
|
return reorderLayer(project, operation.layerId, operation.toIndex);
|
|
|
|
|
case "setLayerEffect":
|
|
|
|
|
return setLayerEffect(project, operation.layerId, operation.effect);
|
|
|
|
|
case "setCanvasSize":
|
|
|
|
|
return setCanvasSize(
|
|
|
|
|
project,
|
|
|
|
|
operation.width,
|
|
|
|
|
operation.height,
|
|
|
|
|
operation.unit,
|
|
|
|
|
);
|
|
|
|
|
default:
|
|
|
|
|
return project;
|
2026-05-10 03:06:54 +07:00
|
|
|
}
|
|
|
|
|
}
|