Optionalprops: ICanvasMediaStaticProps & ICanvasMediaMutableProps & Partial<OptionalonCallbacks: Partial<Retrieves the module's callbacks instance.
Checks if the canvas is ready to render.
The canvas element instance.
Returns the 2D rendering context
Current device pixel ratio.
Canvas height (DPR applied).
Checks if the module has been destroyed.
The name of the module, derived from the class name
Height without DPR scaling.
Width without DPR scaling.
Optional prefix for classnames used by the module
Current properties. Do not mutate these directly, use updateProps instead.
Canvas width (DPR applied).
Protected_addAdds a class name on an element, and keeps track of it for removal when the module is destroyed.
The target DOM element.
The class name to toggle.
Protected_cnHelper function to generate classnames with the module's prefix.
The class names to generate.
A string of class names with the module's prefix applied.
Protected_destroyDestroys the canvas.
Get default mutable properties
Device Pixel Ratio (DPR). Use 'auto' for automatic detection.
Canvas height. Use 'auto' to match the container's height.
Defines how the media element is positioned within the canvas.
Canvas width. Use 'auto' to match the container's width.
Get default static properties
If true, appends the canvas to the container. Ignored if container is null.
If true, video elements will automatically render on each frame update.
Parent element used to determine canvas size. If null, it uses the viewport.
The media element to be rendered. Accepts a Canvas instance or common media elements like images and videos.
Debounce time (ms) for resize handling.
Automatically adjusts canvas size on initialization.
Enables dynamic resizing based on viewport or container changes.
Defines which dimension(s) should trigger a resize.
Protected_handleProtected_setSet events
Destroys the module, cleaning up resources, callbacks, and event listeners.
Adds a custom callback to the module.
The event type to listen for (e.g., 'props', 'destroy').
The function to execute when the event is triggered.
Additional settings for the callback.
Adds a callback on the module's destruction.
The function to execute during destruction.
Pre-renders the media resource onto the canvas.
Resize the canvas
The
CanvasMediaclass allows pre-rendering of media (such as images or video) onto a canvas. This can be useful for reducing payloads by preparing the media for further use in a more optimized form.Documentation