/** * The canvas layer that the browser can draw: WebGPU where it has it, * WebGL 2 where not. The page loads the one it uses, and that one only, * when it has time. * * import { canvas } from 'gpuslider/canvas'; * import { stretch } from 'gpuslider/effects'; * * createSlider( element, { plugins: [ canvas( { effects: [ stretch() ] } ) ] } ); * * The layer is `slider.plugins.gpu` or `slider.plugins.gl` once it is * there, and tells so: `canvas:ready`, with its name. * * `slider.plugins.canvas.draw( hook )` has a function of the page called * with every slide before it is drawn, with its index and its quad, from * the start on: to place the slides, or to move them, from a script. * * slider.plugins.canvas.draw( ( i, quad ) => { * quad.y += Math.sin( quad.p * Math.PI ) * 40; * } ); * * The canvas is as large as the slider, and what effects lay out beyond * it is cut there. With `stage`, an element around the slider, the canvas * covers that element instead, and the slides are drawn as far as it * reaches: covers that turn out of the slider, a fan wider than it. The * element is measured with the slider, and is positioned (`relative`). * * canvas( { effects: [ coverflow() ], stage: element.parentElement } ) */ import type { Slider } from './index.js'; import type { Effect } from './gl/program.js'; /** A slide as the canvas is about to draw it. What a hook changes is drawn. */ export interface Quad { /** Left edge in the view of the slider, px. */ x: number; /** Top edge, px. */ y: number; /** Width, px. */ w: number; /** Height, px. */ h: number; /** * How far the slide is from its resting place, in slides: -1 is one * before the active one. */ p: number; /** Radius of its corners, px. */ radius: number; /** The exponent of its corners: 2 round, 4 a squircle. */ shape: number; /** * Added to the speed of the slider, for the effects: what moves fast * stretches. */ speed: number; /** How much the effects do, 0 to 1. */ fx: number; /** What its colour is multiplied by, 0 to 1. */ dim: number; /** Whether it stays in the view of the slider. */ clip: boolean; /** Whether it is drawn over the others. */ top: boolean; /** What part of the picture is where; null: it is not drawn. */ a: Float32Array | null; /** Another element whose picture it shows, once there is one. */ media: HTMLElement | null; } /** * What `draw()` takes: is called with the index of every slide and its * quad, every frame. */ export type Hook = (i: number, quad: Quad) => void; export interface Options { /** Effects, in the order they apply. */ effects?: Effect[]; /** Largest side of a texture, px. */ maxSize?: number; /** Most device pixels per px drawn. */ density?: number; /** Distance of the eye for meshes that bend, px. */ perspective?: number; /** Make the canvas with the slider, not at the first sign of use. */ eager?: boolean; /** Keep the drawing readable, for tests. */ preserve?: boolean; /** That layer, whatever the browser has. */ layer?: 'gpu' | 'gl'; /** * An element around the slider that the canvas covers: the slides are * drawn as far as it reaches, not cut at the edge of the slider. */ stage?: HTMLElement; } /** * @param options Options. */ export declare function canvas({ layer, stage, ...options }?: Options): (slider: Slider) => { name: string; /** * @param hook Called with every slide before it is drawn. * @return Takes it away again. */ draw: (hook: Hook) => (() => void); };