@avolutions/canvas-painter
Version:
CanvasPainter.js is a simple yet powerful JavaScript library for drawing basic shapes (rectangles, circles, etc.) on HTML5 Canvas with ease. Perfect for creating 2D graphics in your web projects.
37 lines (36 loc) • 995 B
JavaScript
import { CanvasCursorStyle } from "./CanvasCursorStyle.js";
/**
* Class representing the style of a canvas.
*/
export class CanvasStyle {
/**
* Default color for canvas shapes.
*/
color;
/**
* Cursor style configuration for different canvas interaction states.
*/
cursor;
/**
* Default style for the canvas.
*/
static DefaultStyle = {
color: '#000000',
cursor: CanvasCursorStyle.DefaultStyle
};
/**
* Creates a new instance of CanvasStyle.
*
* @param style - The partial style provided by the user.
*/
constructor(style = {}) {
// Handle partial CanvasCursorStyle
const canvasCursorStyle = new CanvasCursorStyle(style.cursor || {});
const styleWithDefaults = {
...CanvasStyle.DefaultStyle,
...style,
cursor: canvasCursorStyle, // Ensure cursor is correctly merged
};
Object.assign(this, styleWithDefaults);
}
}