import { copyAndPast } from '../diagram/group-select-applay.js'; import { classAdd, classDel, clickForAll, listen, classSingleAdd, evtTargetAttr } from '../infrastructure/util.js'; import { modalCreate } from './modal-create.js'; import { ShapeSmbl } from './shape-smbl.js'; /** * @param {import('../infrastructure/canvas-smbl.js').CanvasElement} canvas * @param {import('./shape-smbl').ShapeElement} shapeElement * @param {number} bottomX positon of the bottom left corner of the panel * @param {number} bottomY positon of the bottom left corner of the panel */ export const rectTxtSettingsPnlCreate = (canvas, shapeElement, bottomX, bottomY) => modalCreate(bottomX, bottomY, new RectTxtSettings(canvas, shapeElement)); class RectTxtSettings extends HTMLElement { /** * @param {import('../infrastructure/canvas-smbl.js').CanvasElement} canvas * @param {import('./shape-smbl').ShapeElement} rectElement */ constructor(canvas, rectElement) { super(); /** @private */ this._rectElement = rectElement; /** @private */ this._canvas = canvas; } connectedCallback() { const shadow = this.attachShadow({ mode: 'closed' }); shadow.innerHTML = `
`; const rectData = /** @type {import('./rect.js').RectData} */(this._rectElement[ShapeSmbl].data); const editEl = shadow.getElementById('edit'); classAdd(editEl, `ta-${rectData.a}`); // colors, del listen(editEl, 'cmd', /** @param {CustomEvent<{cmd:string, arg:string}>} evt */ evt => { switch (evt.detail.cmd) { case 'style': classSingleAdd(this._rectElement, rectData, 'cl-', evt.detail.arg); break; case 'del': this._rectElement[ShapeSmbl].del(); break; case 'copy': copyAndPast(this._canvas, [this._rectElement]); break; } }); // text align clickForAll(shadow, '[data-cmd]', evt => { const alignNew = /** @type {1|2|3} */(Number.parseInt(evtTargetAttr(evt, 'data-cmd-arg'))); if (alignNew === rectData.a) { return; } const alignOld = rectData.a; // applay text align to shape rectData.a = alignNew; this._rectElement[ShapeSmbl].draw(); // highlight text align btn in settings panel classDel(editEl, `ta-${alignOld}`); classAdd(editEl, `ta-${rectData.a}`); }); } } customElements.define('ap-rect-txt-settings', RectTxtSettings);