UNPKG

illustrator.js

Version:

JavaScript image processing library

98 lines (97 loc) 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseShapeTool = void 0; const canvas_1 = require("@napi-rs/canvas"); const makeArgs_1 = require("../../utils/makeArgs"); const ToolBox_1 = require("./ToolBox"); class BaseShapeTool extends ToolBox_1.ToolBox { setFillColor(color) { this.history.push((ctx) => { ctx.fillStyle = color; }); return this; } setStrokeColor(color) { this.history.push((ctx) => { ctx.strokeStyle = color; }); return this; } setLineWidth(width) { this.history.push((ctx) => { ctx.lineWidth = width; }); return this; } setLineCap(lineCapStyle) { this.history.push((ctx) => { ctx.lineCap = lineCapStyle; }); return this; } setDashOffset(offset) { this.history.push((ctx) => { ctx.lineDashOffset = offset; }); return this; } setLineJoinStyle(style) { this.history.push((ctx) => { ctx.lineJoin = style; }); return this; } setMiterLimit(limit) { this.history.push((ctx) => { ctx.miterLimit = limit; }); return this; } addPoint() { this.history.push((ctx) => { ctx.beginPath(); }); return this; } removePoint() { this.history.push((ctx) => { ctx.closePath(); }); return this; } move(x, y) { this.history.push((ctx) => { ctx.moveTo(x, y); }); return this; } fill(options) { this.history.push((ctx) => { if (!options) return ctx.fill(); ctx.fill(...(0, makeArgs_1.makeArgs)((arg, idx) => (idx === 0 ? arg instanceof canvas_1.Path2D : idx === 1 ? typeof arg === "string" : false), [options.path, options.fillRule])); }); return this; } stroke(options) { this.history.push((ctx) => { options?.path ? ctx.stroke(options.path) : ctx.stroke(); }); return this; } setLineDash(segments = []) { this.history.push((ctx) => { ctx.setLineDash(segments); }); return this; } clip(options) { this.history.push((ctx) => { if (!options) return ctx.clip(); ctx.clip(...(0, makeArgs_1.makeArgs)((arg, idx) => (idx === 0 ? arg instanceof canvas_1.Path2D : idx === 1 ? typeof arg === "string" : false), [options.path, options.fillRule])); }); return this; } } exports.BaseShapeTool = BaseShapeTool;