Initial RuneStone project

This commit is contained in:
Knotty Wyvern
2026-09-26 01:25:42 -07:00
commit bdc15e952d
190 changed files with 25986 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
import { isImagePath } from "../workspace/media";
type Point = { x: number; y: number };
const targets = new Map<HTMLElement, (path: string, point: Point) => void>();
let highlighted: HTMLElement | undefined;
export function registerImageDropTarget(element: HTMLElement, drop: (path: string, point: Point) => void) {
targets.set(element, drop);
return () => { targets.delete(element); element.classList.remove("image-drop-target"); };
}
function targetAt(path: string, point: Point) {
if (!isImagePath(path)) return;
const hit = document.elementFromPoint(point.x, point.y);
return [...targets].find(([element]) => element.isConnected && hit && element.contains(hit));
}
export function highlightImageDrop(path?: string, point?: Point): boolean {
highlighted?.classList.remove("image-drop-target");
highlighted = path && point ? targetAt(path, point)?.[0] : undefined;
highlighted?.classList.add("image-drop-target");
return !!highlighted;
}
export function dropWorkspaceImage(path: string, point: Point): boolean {
const target = targetAt(path, point);
highlightImageDrop();
target?.[1](path, point);
return !!target;
}