| | import { Graphics, Rectangle, type Renderer, type Container } from "pixi.js"; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | export function make_graphics(z_index: number): Graphics { |
| | const graphics = new Graphics(); |
| | graphics.eventMode = "none"; |
| | graphics.zIndex = z_index; |
| |
|
| | return graphics; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | export function clamp(n: number, min: number, max: number): number { |
| | return n < min ? min : n > max ? max : n; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | export function get_canvas_blob( |
| | renderer: Renderer, |
| | obj: Container | null, |
| | bounds?: { x: number; y: number; width: number; height: number } |
| | ): Promise<Blob | null> { |
| | return new Promise((resolve) => { |
| | if (!obj) { |
| | resolve(null); |
| | return; |
| | } |
| |
|
| | const image_bounds = obj.getLocalBounds(); |
| | const frame = bounds |
| | ? new Rectangle(bounds.x, bounds.y, bounds.width, bounds.height) |
| | : new Rectangle(0, 0, image_bounds.width, image_bounds.height); |
| |
|
| | const src_canvas = renderer.extract.canvas({ |
| | target: obj, |
| | resolution: 1, |
| | frame |
| | }); |
| |
|
| | src_canvas.toBlob?.((blob) => { |
| | if (!blob) { |
| | resolve(null); |
| | } |
| | resolve(blob); |
| | }); |
| | }); |
| | } |
| |
|
| | export interface ImageBlobs { |
| | background: Blob | null; |
| | layers: (Blob | null)[]; |
| | composite: Blob | null; |
| | } |
| |
|