♻️ refactor!: massive refactor

This commit is contained in:
2026-05-31 03:04:30 +07:00
parent c1f12c7201
commit df3c944547
86 changed files with 3691 additions and 1129 deletions
+71 -10
View File
@@ -10,7 +10,44 @@ function makeProject(): Project {
updatedAt: "2024-01-01T00:00:00.000Z",
aspectRatio: "1:1",
canvas: { width: 100, height: 100, unit: "px" },
layers: [{ id: "l1", type: "text", x: 0, y: 0, scale: 1, rotation: 0, opacity: 1, effects: [], visible: true }],
layers: [textLayer("l1")],
};
}
function textLayer(id: string) {
return {
id,
type: "text" as const,
x: 0,
y: 0,
width: 120,
height: 48,
scale: 1,
rotation: 0,
opacity: 1,
effects: [],
visible: true,
text: "Text",
fontFamily: "system-ui",
fontSize: 24,
color: "#000",
};
}
function rasterLayer(id: string) {
return {
id,
type: "raster" as const,
x: 0,
y: 0,
width: 120,
height: 80,
scale: 1,
rotation: 0,
opacity: 1,
effects: [],
visible: true,
asset: null,
};
}
@@ -31,18 +68,34 @@ describe("hasProjectChanged", () => {
it("detects face blur region changes", () => {
const a = makeProject();
const b = makeProject();
a.layers[0].type = "raster";
b.layers[0].type = "raster";
a.layers[0].effects = [{ kind: "face-blur", enabled: true, method: "gaussian", amount: 14, regions: [{ x: 1, y: 1, width: 10, height: 10 }] }];
b.layers[0].effects = [{ kind: "face-blur", enabled: true, method: "gaussian", amount: 14, regions: [{ x: 1, y: 1, width: 11, height: 10 }] }];
a.layers[0] = rasterLayer("l1");
b.layers[0] = rasterLayer("l1");
a.layers[0].effects = [
{
kind: "face-blur",
enabled: true,
method: "gaussian",
amount: 14,
regions: [{ x: 1, y: 1, width: 10, height: 10 }],
},
];
b.layers[0].effects = [
{
kind: "face-blur",
enabled: true,
method: "gaussian",
amount: 14,
regions: [{ x: 1, y: 1, width: 11, height: 10 }],
},
];
expect(hasProjectChanged(a, b)).toBe(true);
});
it("detects layer order changes", () => {
const a = makeProject();
const b = makeProject();
a.layers.push({ id: "l2", type: "text", x: 3, y: 4, scale: 1, rotation: 0, opacity: 1, effects: [], visible: true });
b.layers.push({ id: "l2", type: "text", x: 3, y: 4, scale: 1, rotation: 0, opacity: 1, effects: [], visible: true });
a.layers.push({ ...textLayer("l2"), x: 3, y: 4 });
b.layers.push({ ...textLayer("l2"), x: 3, y: 4 });
b.layers = [b.layers[1], b.layers[0]];
expect(hasProjectChanged(a, b)).toBe(true);
});
@@ -65,9 +118,17 @@ describe("hasProjectChanged", () => {
it("detects face blur removal", () => {
const a = makeProject();
const b = makeProject();
a.layers[0].type = "raster";
b.layers[0].type = "raster";
a.layers[0].effects = [{ kind: "face-blur", enabled: true, method: "gaussian", amount: 14, regions: [{ x: 1, y: 1, width: 10, height: 10 }] }];
a.layers[0] = rasterLayer("l1");
b.layers[0] = rasterLayer("l1");
a.layers[0].effects = [
{
kind: "face-blur",
enabled: true,
method: "gaussian",
amount: 14,
regions: [{ x: 1, y: 1, width: 10, height: 10 }],
},
];
expect(hasProjectChanged(a, b)).toBe(true);
});
});