Browse Source

Add canvas dynamic style element

canvas-spot
Artur Arseniev 3 years ago
parent
commit
1e61d6cd98
  1. 15
      src/canvas/view/CanvasView.ts

15
src/canvas/view/CanvasView.ts

@ -58,6 +58,7 @@ export default class CanvasView extends ModuleView<Canvas> {
<div class="${pfx}canvas__spots" data-spots style="z-index: 1; position: absolute; pointer-events: none"></div> <div class="${pfx}canvas__spots" data-spots style="z-index: 1; position: absolute; pointer-events: none"></div>
</div> </div>
<div id="${pfx}tools" class="${pfx}canvas__tools" data-tools></div> <div id="${pfx}tools" class="${pfx}canvas__tools" data-tools></div>
<style data-canvas-style></style>
`; `;
} }
/*get className(){ /*get className(){
@ -76,6 +77,8 @@ export default class CanvasView extends ModuleView<Canvas> {
framesArea?: HTMLElement; framesArea?: HTMLElement;
toolsWrapper?: HTMLElement; toolsWrapper?: HTMLElement;
spotsEl?: HTMLElement; spotsEl?: HTMLElement;
cvStyle?: HTMLElement;
clsUnscale: string;
ready = false; ready = false;
frames!: FramesView; frames!: FramesView;
@ -91,6 +94,7 @@ export default class CanvasView extends ModuleView<Canvas> {
bindAll(this, 'clearOff', 'onKeyPress', 'onCanvasMove'); bindAll(this, 'clearOff', 'onKeyPress', 'onCanvasMove');
const { em, pfx } = this; const { em, pfx } = this;
this.className = `${pfx}canvas${!em.config.customUI ? ` ${pfx}canvas-bg` : ''}`; this.className = `${pfx}canvas${!em.config.customUI ? ` ${pfx}canvas-bg` : ''}`;
this.clsUnscale = `${pfx}unscale`;
this._initFrames(); this._initFrames();
this.listenTo(em, 'change:canvasOffset', this.clearOff); this.listenTo(em, 'change:canvasOffset', this.clearOff);
this.listenTo(em, 'component:selected', this.checkSelected); this.listenTo(em, 'component:selected', this.checkSelected);
@ -195,15 +199,21 @@ export default class CanvasView extends ModuleView<Canvas> {
} }
updateFramesArea() { updateFramesArea() {
const { framesArea, model, module } = this; const { framesArea, model, module, cvStyle, clsUnscale } = this;
const mpl = module.getZoomMultiplier();
if (framesArea) { if (framesArea) {
const { x, y } = model.attributes; const { x, y } = model.attributes;
const zoomDc = module.getZoomDecimal(); const zoomDc = module.getZoomDecimal();
const mpl = module.getZoomMultiplier();
framesArea.style.transform = `scale(${zoomDc}) translate(${x * mpl}px, ${y * mpl}px)`; framesArea.style.transform = `scale(${zoomDc}) translate(${x * mpl}px, ${y * mpl}px)`;
} }
if (cvStyle) {
cvStyle.innerHTML = `
.${clsUnscale} { scale: ${mpl} }
`;
}
} }
fitViewport(opts: FitViewportOptions = {}) { fitViewport(opts: FitViewportOptions = {}) {
@ -590,6 +600,7 @@ export default class CanvasView extends ModuleView<Canvas> {
this.fixedOffsetEl = el.querySelector(`.${ppfx}offset-fixed-v`)!; this.fixedOffsetEl = el.querySelector(`.${ppfx}offset-fixed-v`)!;
this.toolsGlobEl = el.querySelector(`.${ppfx}tools-gl`)!; this.toolsGlobEl = el.querySelector(`.${ppfx}tools-gl`)!;
this.spotsEl = el.querySelector('[data-spots]')!; this.spotsEl = el.querySelector('[data-spots]')!;
this.cvStyle = el.querySelector('[data-canvas-style]')!;
this.el.className = getUiClass(em, this.className); this.el.className = getUiClass(em, this.className);
this.ready = true; this.ready = true;
this._renderFrames(); this._renderFrames();

Loading…
Cancel
Save