import type { SceneOptions, SceneSource } from "./scene.types.ts"; /** A gradient the context makes: only `addColorStop` is called on it. */ export interface CanvasGradientLike { addColorStop(offset: number, color: string): void; } /** * The members of a 2D canvas context that are used, with the types of the standard ones. A `CanvasRenderingContext2D`, an `OffscreenCanvasRenderingContext2D` * and the contexts of the Node canvas libraries all have them. Members marked optional are used only when the context has them. */ export interface CanvasContext { save(): void; restore(): void; setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void; beginPath(): void; moveTo(x: number, y: number): void; lineTo(x: number, y: number): void; bezierCurveTo(c1x: number, c1y: number, c2x: number, c2y: number, x: number, y: number): void; quadraticCurveTo(cx: number, cy: number, x: number, y: number): void; closePath(): void; fill(rule?: "nonzero" | "evenodd"): void; stroke(): void; clip(rule?: "nonzero" | "evenodd"): void; fillText(text: string, x: number, y: number): void; strokeText(text: string, x: number, y: number): void; fillRect?(x: number, y: number, w: number, h: number): void; clearRect?(x: number, y: number, w: number, h: number): void; setLineDash(segments: number[]): void; createLinearGradient?(x0: number, y0: number, x1: number, y1: number): CanvasGradientLike; drawImage?(image: never, x: number, y: number, w: number, h: number): void; /** A colour, or a gradient (or, on a real context, a pattern, which is never written here). */ fillStyle: string | CanvasGradientLike | object; strokeStyle: string | CanvasGradientLike | object; lineWidth: number; lineJoin: string; lineCap: string; globalAlpha: number; font: string; textAlign: string; textBaseline: string; /** CSS filters, where the context has them (a browser's). */ filter?: string; letterSpacing?: string; } /** Where and how large a scene is drawn, and what is not in the scene. */ export interface CanvasOptions extends SceneOptions { /** The width the surface is drawn at, in the context's units (pixels). With a `height` too, the drawing is fitted inside and centred. */ width?: number; height?: number; /** Pixels for one unit of the drawing (a foot, for most). Instead of a width or a height. 1 when none of the three is given. */ scale?: number; /** Where the drawing's top left corner goes. 0, 0. */ x?: number; y?: number; /** Fill the picture's box with this colour first. */ background?: string; /** Clear the picture's box first (where the context can). */ clear?: boolean; /** The picture for a team's logo: given the address in the drawing, it returns something the context's `drawImage` takes (a loaded `Image`, an `ImageBitmap`, a canvas), or nothing, and then that logo is left out. */ images?: (href: string) => unknown; } /** What `drawToCanvas` drew. */ export interface Drawn { /** The box the drawing took, in the context's units. */ width: number; height: number; /** Pixels for one unit of the drawing. */ scale: number; } /** The colour with an alpha: `rgb(...)` of a hex or rgb colour, or the colour itself when it cannot be read (and the alpha is 1). */ export declare function withAlpha(color: string, alpha: number): string; /** * Draw a scene (or the options of `drawKyogijo`, or an SVG the package wrote) onto a canvas context. Give a `width` or a `height` in pixels, or a `scale`; the * drawing keeps its shape. Light or dark by `theme`. A team's logo is drawn only if `images` returns a picture for its address. * @example * ```ts * import { drawToCanvas, type CanvasContext } from "@johnmorrisdotca/kyogijo-stadiums/canvas"; * // Any object with the context's members will do: this one only counts what is drawn. * const counts: Record = {}; * const ctx = new Proxy({} as CanvasContext, { get: (_, name: string) => () => void (counts[name] = (counts[name] ?? 0) + 1), set: () => true }); * const drawn = drawToCanvas(ctx, { sport: "nhl", id: "rink" }, { width: 800 }); * console.log(drawn.width, Math.round(drawn.height), counts.fill > 10); * // 800 374 true * ``` */ export declare function drawToCanvas(ctx: CanvasContext, source: SceneSource, options?: CanvasOptions): Drawn;