// Generated by dts-bundle-generator v9.5.1 declare global { interface HTMLAudioElement { /** Deep-clone this audio element, preserving the current `volume`. */ clone(): HTMLAudioElement; } } declare global { interface HTMLAudioElement { /** Volume restored by `stop()` after pausing. If unset, `stop()` leaves `volume` as-is. */ defaultVolume?: number; /** Pause playback, reset `currentTime` to 0, and restore `volume` to `defaultVolume` if set. */ stop(): void; } } /** Object literal compatible with `Vec2` (e.g. `{ x, y }`). */ export interface Vector2 { /** Horizontal component. */ x: number; /** Vertical component. */ y: number; } /** {@link Vector2} plus `w`/`h` for AABB-style values. */ export interface Vector4 extends Vector2 { /** Width. */ w: number; /** Height. */ h: number; } declare class Vec2 { /** Unit vector at angle `rad` (radians), scaled per-axis. `scaleY` defaults to `scaleX`. */ static fromAngle(rad: number, scaleX?: number, scaleY?: number): Vec2; /** Horizontal component. */ x: number; /** Vertical component. */ y: number; constructor(x?: Vector2 | number, y?: number); /** Replace components. Mutates and returns `this`. */ set(v: Vector2): Vec2; set(x: number, y?: number): Vec2; /** Set each component to its absolute value. Mutates and returns `this`. */ abs(): Vec2; /** Per-axis add. Mutates and returns `this`. */ add(v: Vector2): Vec2; add(x: number, y?: number): Vec2; /** Round each component up. Mutates and returns `this`. */ ceil(): Vec2; /** Clamp each axis to its `[min, max]` range. `y` defaults to `x`. Mutates and returns `this`. */ clamp(x: [ number, number ], y?: [ number, number ]): Vec2; /** Per-axis divide. Mutates and returns `this`. */ div(v: Vector2): Vec2; div(x: number, y?: number): Vec2; /** Round each component down. Mutates and returns `this`. */ floor(): Vec2; /** * Apply `callback` to each component (`index` is `0` for x, `1` for y). Mutates and returns `this`. * * @example * ```ts * new Vec2(3.6, -2.1).map(Math.trunc); // Vec2 { x: 3, y: -2 } * new Vec2(2, 5).map((v, i) => v * (i + 1)); // Vec2 { x: 2, y: 10 } * ``` */ map(callback: (value: number, index: number) => number): Vec2; /** Per-axis Euclidean modulo (result sign matches the divisor). Mutates and returns `this`. */ mod(v: Vector2): Vec2; mod(x: number, y?: number): Vec2; /** Per-axis multiply. Mutates and returns `this`. */ mult(v: Vector2): Vec2; mult(x: number, y?: number): Vec2; /** Flip the sign of both components (same as `mult(-1)`). Mutates and returns `this`. */ negate(): Vec2; /** Scale to unit length. Zero-length vectors are left untouched and warn (throttled). Mutates and returns `this`. */ normalize(): Vec2; /** Scale so `|x| + |y| === 1`. Zero-length vectors are left untouched. Mutates and returns `this`. */ normalizeManhattan(): Vec2; /** Per-axis remainder (JavaScript `%`, sign follows the dividend). Mutates and returns `this`. */ rem(v: Vector2): Vec2; rem(x: number, y?: number): Vec2; /** Round each component to the nearest integer. Mutates and returns `this`. */ round(): Vec2; /** Per-axis subtract. Mutates and returns `this`. */ sub(v: Vector2): Vec2; sub(x: number, y?: number): Vec2; /** Angle in radians. No arg: angle of `this` from origin. With `other`: angle from `this` toward `other`. */ angle(other?: Vector2): number; /** Euclidean distance to `other`. */ distance(other: Vector2): number; /** Manhattan distance (`|dx| + |dy|`) to `other`. */ distanceManhattan(other: Vector2): number; /** Dot product with `other`. */ dotProduct(other: Vector2): number; /** `true` when both components are finite (rules out `NaN` and `±Infinity`). */ isValid(): boolean; /** Euclidean magnitude (`sqrt(x² + y²)`). */ length(): number; /** Manhattan magnitude (`|x| + |y|`). */ lengthManhattan(): number; /** Larger of the two components. */ max(): number; /** Smaller of the two components. */ min(): number; /** Tuple `[x, y]`. */ toArray(): [ number, number ]; /** Build a `Rect` with the argument as position and `this` as size. */ toRectAddPos(v: Vector2): Rect; toRectAddPos(x: number, y?: number): Rect; /** Build a `Rect` with `this` as position and the argument as size. */ toRectAddSize(v: Vector2): Rect; toRectAddSize(x: number, y?: number): Rect; /** Debug string like `"Vec2 [x: 1, y: 2]"`. */ toString(): string; /** New `Vec2` with the same components. */ clone(): Vec2; /** Approximate equality (within `approxEqual` tolerance). Scalar broadcasts. */ equals(v: Vector2): boolean; equals(x: number, y?: number): boolean; private calculate; private concat; private getValues; } /** Result of a {@link Polygon.collide} call. */ export interface PolygonCollisionResult { /** `true` if the polygons currently overlap. */ intersect: boolean; /** Smallest displacement that would separate the polygons (zero `Vec2` when they're disjoint). */ minimumTranslationVector: Vec2; /** `true` if applying the `velocity` passed to `collide` would put the polygons into contact. */ willIntersect: boolean; } declare class Polygon { /** * Trace an outline around the opaque pixels of `canvas` via four directional sweeps (top, right, bottom, left). `detail` is the pixel stride (≥ 2) between scanline samples — higher = faster but coarser. `angle` is the simplification threshold in radians: vertices whose turn angle wraps to within ±`angle` of straight are dropped. Throws if fewer than 3 vertices survive. * * **Convex shapes only.** The sweep ignores anything an outer-perimeter ray can't reach: holes (donuts), inward bays (a "C" opening sideways), or any row/column with multiple disjoint opaque spans. For those inputs the result is either a broken polygon or simply the outer hull, and {@link Polygon.collide} relies on convexity anyway. */ static fromCanvas(canvas: HTMLCanvasElement, detail: number, angle: number): Polygon; /** Regular convex polygon with `edges` vertices, inscribed in a bounding box of `size` (number = square). */ static fromEdges(edges: number, size: Vec2 | number): Polygon; /** Polygon from the four corners of `rect`. */ static fromRect(rect: Rect): Polygon; private _center; private _points; private edges; /** Centroid (mean of vertex positions). Recomputed whenever the vertex set changes. */ get center(): Readonly; /** Read-only view of the current vertex list. Use `addPoint`/`offset`/`rotate` to mutate. */ get points(): Readonly; constructor(...points: Vec2[]); /** Stroke the polygon to `context`, shifted by `offset`. Coordinates are truncated to integers (via `| 0`) for crisp lines. */ draw(context: CanvasRenderingContext2D, offset?: Vec2): void; /** Append a single vertex at `(x, y)`. Mutates and returns `this`. */ addPoint(x: number, y: number): Polygon; /** Append cloned copies of every passed vertex. Mutates and returns `this`. */ addPoints(...points: Vec2[]): Polygon; /** Translate every vertex by `(x, y)`. Mutates and returns `this`. */ offset(x?: number, y?: number): Polygon; /** Rotate by `angle` radians around `pos` (defaults to the centroid). Mutates and returns `this`. */ rotate(angle: number, pos?: Readonly): this; /** SAT collision against `otherPolygon`. **Both polygons must be convex** — SAT silently misses collisions for concave shapes. Pass a non-zero `velocity` to also compute whether the polygons would intersect after that displacement. Warns and returns a no-collision result if either polygon has zero edges. */ collide(otherPolygon: Polygon, velocity?: Vec2): PolygonCollisionResult; /** New `Polygon` with the same vertices. */ clone(): Polygon; private update; } /** Derived geometry returned by {@link Rect.sides}. */ export interface Sides { /** Lower edge (`y + h`). */ bottom: number; /** Center point. */ centerPos: Vec2; /** Half the width and height. */ halfSize: Vec2; /** Right edge (`x + w`). */ right: number; } declare class Rect { /** Build from an `HTMLElement` (via `getBoundingClientRect`) or a `DOMRect`. */ static fromBoundingClientRect(rect: DOMRect | HTMLElement): Rect; /** Axis-aligned bounding box of a polygon's points. Throws if the polygon has no points. */ static fromPolygon(polygon: Polygon): Rect; private _x; private _y; private _w; private _h; private _sides; private sideIsDirty; /** Top-left x. */ get x(): number; /** Top-left x. */ set x(value: number); /** Top-left y. */ get y(): number; /** Top-left y. */ set y(value: number); /** Width. */ get w(): number; /** Width. */ set w(value: number); /** Height. */ get h(): number; /** Height. */ set h(value: number); /** Derived sides/center/halfSize. Lazily recomputed after any `x`/`y`/`w`/`h` change. */ get sides(): Readonly; constructor(x?: number, y?: number, w?: number, h?: number); /** Grow on every side by `delta` (`x`/`y` shift in, `w`/`h` grow by `2*delta`). Pass a negative value to shrink. Mutates and returns `this`. */ inflate(delta: number): Rect; /** Round `x` and `y` to the nearest integer. `w`/`h` are unchanged. Mutates and returns `this`. */ round(): Rect; /** * Replace fields. The first arg may be a `Vector4` (sets all four), a `Vector2` (sets `x`/`y` only, unless explicit `w`/`h` follow), or `x` as a number with separate `y`/`w`/`h`. Mutates and returns `this`. */ set(x?: Vector4 | Vector2 | number, y?: number, w?: number, h?: number): Rect; /** AABB-vs-AABB overlap test (inclusive of touching edges). */ collide(rect: Rect): boolean; /** `true` when `rect` is fully inside `this`. */ collideFull(rect: Rect): boolean; /** `true` when `vec` lies inside `this` (inclusive of edges). */ collidePoint(vec: Vector2): boolean; /** Side of `this` that `rect` overlaps from, or `"none"` if disjoint. Useful for picking a bounce axis. */ collideSide(rect: Rect): "none" | "top" | "bottom" | "left" | "right"; /** Top-left corner as a new `Vec2`. */ pos(): Vec2; /** Width and height as a new `Vec2`. */ size(): Vec2; /** Debug string like `"Rect [x: 0, y: 0, w: 10, h: 20]"`. */ toString(): string; /** New `Rect` with the same values. */ clone(): Rect; /** Approximate equality. Pass `withSize: false` to compare position only. */ equals(other: Rect, withSize?: boolean): boolean; } export type Mode = "fill" | "stroke"; declare global { interface CanvasRenderingContext2D { /** * Fill a two-color bar sized by `amount`. Writes `fillStyle`; persists on the context — wrap in `save()`/`restore()` to preserve prior state. * @param c1 background, default `"white"` * @param c2 foreground, default `"black"` */ fillBar(rect: Vector4, amount: number, c1?: string, c2?: string): void; } } declare global { interface CanvasRenderingContext2D { /** * Fill a three-layer framed bar (outer band, frame, fill scaled by `amount`). Writes `fillStyle`; persists on the context — wrap in `save()`/`restore()` to preserve prior state. * @param amount fill fraction in `[0, 1]`. Default `0.8`. `≤ 0` skips the fill layer. * @param padding frame inset on all sides. Default `4`. * @param colors outer band, frame, fill. Default `["white", "black", "red"]`. */ fillFramedBar(rect: Vector4, amount?: number, padding?: number, colors?: [ string, string, string ]): void; } } declare global { interface CanvasRenderingContext2D { /** * Draws a circle centered at `vecPos`. * @param amount sweep fraction in `[0, 1]`. Default `1` (full circle). */ drawCircle(vecPos: Vector2, rad: number, mode: Mode, amount?: number): void; } } declare global { interface CanvasRenderingContext2D { /** Draws a rectangle (from `Vector4` or `x, y, w, h`). */ drawRect(rect: Vector4, mode: Mode): void; drawRect(x: number, y: number, w: number, h: number, mode: Mode): void; } } export interface DrawRoundRectOptions { /** Inset from the rect edges. Default `0` (no inset). */ padding?: number; /** Corner radius. Default `16`. */ radius?: number; } declare global { interface CanvasRenderingContext2D { /** Draw a rounded rectangle from a `Vector4` or `x, y, w, h` plus an options bag. Delegates the corner path to native `roundRect` (Safari 16+ / Chrome 99+ / Firefox 113+). */ drawRoundRect(rect: Vector4, mode: Mode, options?: DrawRoundRectOptions): void; drawRoundRect(x: number, y: number, w: number, h: number, mode: Mode, options?: DrawRoundRectOptions): void; } } declare global { interface CanvasRenderingContext2D { /** Stroke a dotted rectangle. Writes `lineWidth` and `setLineDash` — wrap in `save()`/`restore()` to preserve prior state. */ strokeDottedRect(rect: Vector4): void; } } declare global { interface CanvasRenderingContext2D { /** Draw a line segment from `(x1, y1)` to `(x2, y2)`. */ strokeLine(x1: number, y1: number, x2: number, y2: number): void; } } declare global { interface CanvasRenderingContext2D { /** * Draw a regular polygon centered in `rect`, with vertices on a circle of radius `min(rect.w, rect.h) * 0.5`. */ drawPolygon(sides: number, rect: Vector4, mode: Mode): void; } } declare global { interface CanvasRenderingContext2D { /** Draw a triangle: top-left → top-right → bottom-center. */ drawTriangle(rect: Vector4, mode: Mode): void; } } declare global { interface CanvasRenderingContext2D { /** * Write text horizontally offset around `x` by `measureTextOffset` of its measured width. * @param measureTextOffset in `[0, 1]`. Default `0.5` (centered around `x`). */ writeText(text: string, x: number, y: number, measureTextOffset?: number): void; } } declare global { interface CanvasRenderingContext2D { /** * Word-wrap `text` into lines of pixel width `width`, drawing each line via `writeText`. Returns `false` and logs to `console.error` if `maxAttempts` is reached. * @param lineOffset vertical spacing between lines in px. Default `50`. * @param maxAttempts safety cap on wrap iterations. Default `50`. */ writeMultilineText(text: string, x: number, y: number, width: number, lineOffset?: number, maxAttempts?: number): boolean; } } declare global { interface CanvasRenderingContext2D { /** * Draw `image` rotated by `radians` around the center of its placement at `(x, y)`. Saves and restores the transform. * @param radians clockwise positive, in radians. */ drawImageRotated(image: HTMLCanvasElement, x: number, y: number, radians: number): void; } } declare global { interface CanvasRenderingContext2D { /** Build a colored rounded-rect stencil with a `drawPartialRoundRect` helper. The returned helper writes `fillStyle = "white"` on the caller's context — wrap in `save()`/`restore()` to preserve prior state. */ generateColor(size: number, color: string): { colors: [ number, number ][]; image: HTMLCanvasElement; drawPartialRoundRect: (rect: Rect, amount: number, offsetX?: number, offsetY?: number) => void; }; } } /** `[r, g, b]` tuple of integer channel values, each in `[0, 255]`. */ export type RGB = [ number, number, number ]; declare global { interface HTMLCanvasElement { /** `true` if any pixel has a non-zero RGBA byte. */ hasAnyColor(): boolean; } } declare global { interface HTMLCanvasElement { /** * Read the pixel at `(x, y)`. Out-of-bounds reads return zero/transparent. Not for hot paths — each call issues a fresh `getImageData`. For bulk reads, call `getImageData` once and index into the buffer. * @param output return format. Default `"integer"`. */ getPixelAt(x: number, y: number, output?: "integer"): number; getPixelAt(x: number, y: number, output: "array"): [ ...RGB, number ]; getPixelAt(x: number, y: number, output: "json"): { r: number; g: number; b: number; a: number; }; getPixelAt(x: number, y: number, output: "string"): string; } } declare global { interface HTMLCanvasElement { /** * Replace pixel colors by RGB hex key. Alpha is ignored — fully-transparent pixels are skipped, semi-transparent pixels keep their alpha. */ replaceColors(replacements: Record): HTMLCanvasElement; } } declare global { interface HTMLCanvasElement { /** Rotate around the center into a new square canvas sized to fit any rotation (`diam = ceil(sqrt(w² + h²))`). */ rotateBy(radians: number): HTMLCanvasElement; } } declare global { interface HTMLCanvasElement { /** Rotate around the center within the original `width × height`; corners that fall outside are clipped. */ rotateByAligned(radians: number): HTMLCanvasElement; } } declare global { interface HTMLCanvasElement { /** Trim fully-transparent borders. Returns a new canvas cropped to the bounding box of opaque pixels. */ autoCrop(): HTMLCanvasElement; } } declare global { interface HTMLCanvasElement { /** * Scale into a new canvas. Throws if any factor is `≤ 0`. * @param scaleX horizontal scale factor. Default `1`. * @param scaleY vertical scale factor. Default = `scaleX`. */ scaleBy(scaleX?: number, scaleY?: number): HTMLCanvasElement; } } declare global { interface HTMLCanvasElement { /** * Scale into a new canvas so the chosen axis equals `size`, preserving aspect ratio. * @param isWidth match `size` against width when `true`, height when `false`. Default `true`. */ resize(size: number, isWidth?: boolean): HTMLCanvasElement; } } declare global { interface HTMLCanvasElement { /** * Mirror horizontally into a new canvas. * @param offsetX horizontal shift applied after flipping. Default `0`. */ flipX(offsetX?: number): HTMLCanvasElement; } } declare global { interface HTMLCanvasElement { /** * Mirror vertically into a new canvas. * @param offsetY vertical shift applied after flipping. Default `0`. */ flipY(offsetY?: number): HTMLCanvasElement; } } declare global { interface HTMLCanvasElement { /** * Crop a `(w, h)` sub-region starting at `(x, y)` into a new canvas. * @param w default `this.width` * @param h default `this.height` */ subImage(x: number, y: number, w?: number, h?: number): HTMLCanvasElement; } } declare global { interface HTMLCanvasElement { /** Copy this canvas (same dimensions, content, `id`, and `dataset`) into a new canvas. */ clone(): HTMLCanvasElement; } } declare global { interface HTMLCanvasElement { /** Convert image canvas to `Promise` via `toDataURL`. */ toImage(): Promise; } } declare global { interface HTMLImageElement { /** * Crop a `(w, h)` sub-region starting at `(x, y)` into a new canvas. * @param w default `this.width` * @param h default `this.height` */ subImage(x: number, y: number, w?: number, h?: number): HTMLCanvasElement; } } export {};