feat: masks, properties refactor, shaders, storage migrations, and more

This commit is contained in:
Maze Winther
2026-03-29 15:48:22 +02:00
parent 39ea298a9c
commit 8db3bead13
690 changed files with 35618 additions and 7337 deletions
+48 -6
View File
@@ -1,4 +1,5 @@
import type { ElementWithBounds } from "./element-bounds";
import type { ElementRef } from "@/lib/timeline/types";
function pointInRotatedRect({
px,
@@ -24,14 +25,14 @@ function pointInRotatedRect({
const dy = py - cy;
const localX = dx * cos - dy * sin;
const localY = dx * sin + dy * cos;
const halfW = width / 2;
const halfH = height / 2;
const halfW = Math.abs(width) / 2;
const halfH = Math.abs(height) / 2;
return (
localX >= -halfW && localX <= halfW && localY >= -halfH && localY <= halfH
);
}
export function hitTest({
export function getHitElements({
canvasX,
canvasY,
elementsWithBounds,
@@ -39,7 +40,9 @@ export function hitTest({
canvasX: number;
canvasY: number;
elementsWithBounds: ElementWithBounds[];
}): ElementWithBounds | null {
}): ElementWithBounds[] {
const hits: ElementWithBounds[] = [];
for (let i = elementsWithBounds.length - 1; i >= 0; i--) {
const { bounds } = elementsWithBounds[i];
if (
@@ -53,8 +56,47 @@ export function hitTest({
rotation: bounds.rotation,
})
) {
return elementsWithBounds[i];
hits.push(elementsWithBounds[i]);
}
}
return null;
return hits;
}
export function hitTest({
canvasX,
canvasY,
elementsWithBounds,
}: {
canvasX: number;
canvasY: number;
elementsWithBounds: ElementWithBounds[];
}): ElementWithBounds | null {
return (
getHitElements({
canvasX,
canvasY,
elementsWithBounds,
})[0] ?? null
);
}
export function resolvePreferredHit({
hits,
preferredElements,
}: {
hits: ElementWithBounds[];
preferredElements: ElementRef[];
}): ElementWithBounds | null {
if (preferredElements.length === 0) return null;
return (
hits.find((hit) =>
preferredElements.some(
(preferredElement) =>
preferredElement.trackId === hit.trackId &&
preferredElement.elementId === hit.elementId,
),
) ?? null
);
}