2026-05-31 03:03:49 +07:00
|
|
|
import { getLayerAssetRef, type Project } from "@pien-studio/types";
|
2026-05-10 03:06:54 +07:00
|
|
|
|
|
|
|
|
export function hasProjectChanged(left: Project, right: Project): boolean {
|
|
|
|
|
if (left.id !== right.id) return true;
|
|
|
|
|
if (left.title !== right.title) return true;
|
|
|
|
|
if (left.createdAt !== right.createdAt) return true;
|
|
|
|
|
if (left.updatedAt !== right.updatedAt) return true;
|
|
|
|
|
if (left.aspectRatio !== right.aspectRatio) return true;
|
2026-05-31 03:03:49 +07:00
|
|
|
if (
|
|
|
|
|
left.canvas.width !== right.canvas.width ||
|
|
|
|
|
left.canvas.height !== right.canvas.height ||
|
|
|
|
|
left.canvas.unit !== right.canvas.unit
|
|
|
|
|
) {
|
2026-05-10 03:06:54 +07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (left.layers.length !== right.layers.length) return true;
|
|
|
|
|
|
|
|
|
|
for (let index = 0; index < left.layers.length; index += 1) {
|
|
|
|
|
const a = left.layers[index];
|
|
|
|
|
const b = right.layers[index];
|
|
|
|
|
if (!a || !b) return true;
|
|
|
|
|
if (
|
|
|
|
|
a.id !== b.id ||
|
|
|
|
|
a.type !== b.type ||
|
|
|
|
|
a.name !== b.name ||
|
|
|
|
|
a.x !== b.x ||
|
|
|
|
|
a.y !== b.y ||
|
|
|
|
|
a.width !== b.width ||
|
|
|
|
|
a.height !== b.height ||
|
|
|
|
|
a.scale !== b.scale ||
|
|
|
|
|
a.rotation !== b.rotation ||
|
2026-05-24 21:05:21 +07:00
|
|
|
a.opacity !== b.opacity ||
|
|
|
|
|
a.visible !== b.visible
|
2026-05-10 03:06:54 +07:00
|
|
|
) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-31 03:03:49 +07:00
|
|
|
if (
|
|
|
|
|
JSON.stringify(getLayerAssetRef(a)) !==
|
|
|
|
|
JSON.stringify(getLayerAssetRef(b))
|
|
|
|
|
)
|
|
|
|
|
return true;
|
|
|
|
|
if (
|
|
|
|
|
(a.type === "raster" || a.type === "sticker") &&
|
|
|
|
|
(b.type === "raster" || b.type === "sticker") &&
|
|
|
|
|
a.runtimeSourceUri !== b.runtimeSourceUri
|
|
|
|
|
)
|
|
|
|
|
return true;
|
|
|
|
|
if (
|
|
|
|
|
a.type === "text" &&
|
|
|
|
|
b.type === "text" &&
|
|
|
|
|
(a.text !== b.text ||
|
|
|
|
|
a.fontFamily !== b.fontFamily ||
|
|
|
|
|
a.fontSize !== b.fontSize ||
|
|
|
|
|
a.color !== b.color)
|
|
|
|
|
)
|
|
|
|
|
return true;
|
|
|
|
|
|
2026-05-21 00:02:12 +07:00
|
|
|
if (JSON.stringify(a.effects) !== JSON.stringify(b.effects)) return true;
|
2026-05-10 03:06:54 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|