Files
game-cards-poker-design/frontend/node_modules/fabric/extensions/aligning_guidelines/util/get-objects-by-target.ts
Poker Design Developer 5dbcebf7a2 Fix frontend blank page issues
- Fix router import path in main.js
- Handle Django REST Framework pagination format in API calls
- Add getTemplates function to project API
- Restart frontend development server
2026-05-31 18:40:56 +08:00

46 lines
1.2 KiB
TypeScript

import type { FabricObject } from 'fabric';
import { ActiveSelection, Group } from 'fabric';
export function getObjectsByTarget(target: FabricObject) {
const objects = new Set<FabricObject>();
const canvas = target.canvas;
if (!canvas) return objects;
const children =
target instanceof ActiveSelection ? target.getObjects() : [target];
canvas.forEachObject((o) => {
if (!o.isOnScreen()) return;
if (!o.visible) return;
if (o.constructor == Group) {
collectObjectsByGroup(objects, o);
return;
}
objects.add(o);
});
deleteObjectsByList(objects, children);
return objects;
}
function deleteObjectsByList(objects: Set<FabricObject>, list: FabricObject[]) {
for (const target of list) {
if (target.constructor == Group) {
deleteObjectsByList(objects, (target as Group).getObjects());
} else {
objects.delete(target);
}
}
}
function collectObjectsByGroup(objects: Set<FabricObject>, g: Group) {
const children = g.getObjects();
for (const child of children) {
if (!child.visible) continue;
if (child.constructor == Group) {
collectObjectsByGroup(objects, child);
continue;
}
objects.add(child);
}
}