diff --git a/src/Drawer.ts b/src/Drawer.ts index 170a8fc..52fd829 100644 --- a/src/Drawer.ts +++ b/src/Drawer.ts @@ -36,6 +36,7 @@ export class Drawer extends History { dotted: boolean = false; // options options: DrawerOptions = defaultOptionsDrawer; + customBtn: { [key: string]: HTMLButtonElement } = {}; // HTML Elements declare $canvas: HTMLCanvasElement; $sourceElement: HTMLElement; @@ -107,9 +108,9 @@ export class Drawer extends History { */ private _buildDrawer() { try { - this.$drawerContainer = stringToHTMLElement(/*html*/`
`); - const canvas = /*html*/` - + this.$drawerContainer = stringToHTMLElement(/*html*/ `
`); + const canvas = /*html*/ ` + `; this.$canvas = stringToHTMLElement(canvas); this.ctx = this.$canvas.getContext('2d', { alpha: true, willReadFrequently: true }) as CanvasRenderingContext2D; @@ -189,11 +190,8 @@ export class Drawer extends History { this.ctx.fillStyle = this.options.color; // passing selectedColor as fill style // Update icon color for indicate to user - if (this.$colorPickerLabel) { - const $icon = this.$colorPickerLabel.querySelector('svg'); - if ($icon) { - $icon.style.color = color; - } + if (this.$colorPicker) { + this.$colorPicker.value = this.ctx.strokeStyle; } this.$canvas.dispatchEvent(DrawEvent('update.color', { color })); @@ -282,7 +280,7 @@ export class Drawer extends History { $btn = this.$shapeBtn; } - if ($btn) this.setActiveBtn($btn); + this.setActiveBtn($btn); this.$canvas.dispatchEvent(DrawEvent('update.tool', { toolName })); resolve(true); } @@ -378,7 +376,7 @@ export class Drawer extends History { addToolbar(): Promise { return new Promise((resolve, reject) => { try { - const toolbar = /*html*/`
`; + const toolbar = /*html*/ `
`; this.$toolbar = stringToHTMLElement(toolbar); this.$toolbar.style.maxWidth = this.$canvas.width + 'px'; @@ -428,7 +426,7 @@ export class Drawer extends History { return new Promise((resolve, reject) => { try { if (this.$toolbar && !this.$undoBtn) { - const undoBtn = /*html*/``; + const undoBtn = /*html*/ ``; const $undoBtn = stringToHTMLElement(undoBtn); this.$undoBtn = $undoBtn; @@ -461,7 +459,7 @@ export class Drawer extends History { return new Promise((resolve, reject) => { try { if (this.$toolbar && !this.$redoBtn) { - const redoBtn = /*html*/``; + const redoBtn = /*html*/ ``; const $redoBtn = stringToHTMLElement(redoBtn); this.$redoBtn = $redoBtn; @@ -495,7 +493,7 @@ export class Drawer extends History { return new Promise((resolve, reject) => { try { if (this.$toolbar && !this.$brushBtn) { - const brushBtn = /*html*/``; + const brushBtn = /*html*/ ``; const $brushBtn = stringToHTMLElement(brushBtn); this.$brushBtn = $brushBtn; @@ -528,7 +526,7 @@ export class Drawer extends History { return new Promise((resolve, reject) => { try { if (this.$toolbar && !this.$eraserBtn) { - const eraserBtn = /*html*/``; + const eraserBtn = /*html*/ ``; const $eraserBtn = stringToHTMLElement(eraserBtn); this.$eraserBtn = $eraserBtn; @@ -561,7 +559,7 @@ export class Drawer extends History { return new Promise((resolve, reject) => { try { if (this.$toolbar && !this.$clearBtn) { - const clearBtn = /*html*/``; + const clearBtn = /*html*/ ``; const $clearBtn = stringToHTMLElement(clearBtn); this.$clearBtn = $clearBtn; @@ -594,9 +592,9 @@ export class Drawer extends History { return new Promise((resolve, reject) => { try { if (this.$toolbar && !this.$shapeBtn) { - const shapeBtn = /*html*/``; + const shapeBtn = /*html*/ ``; - const shapeMenu = /*html*/` + const shapeMenu = /*html*/ `
  • @@ -670,6 +668,7 @@ export class Drawer extends History { } }); } + /** * Add text button to toolbar if exist * see {@link addToolbar} before use it @@ -679,8 +678,7 @@ export class Drawer extends History { return new Promise((resolve, reject) => { try { if (this.$toolbar && !this.$textBtn) { - const textBtn = /*html*/``; - const $textBtn = stringToHTMLElement(textBtn); + const $textBtn = stringToHTMLElement(this.textBtnHtml()); this.$textBtn = $textBtn; this.$toolbar.appendChild(this.$textBtn); @@ -712,7 +710,7 @@ export class Drawer extends History { return new Promise((resolve, reject) => { try { if (this.$toolbar && !this.$lineThickness) { - const lineThickness = /*html*/` + const lineThickness = /*html*/ `