UNPKG

@visactor/vrender-core

Version:

```typescript import { xxx } from '@visactor/vrender-core'; ```

76 lines (73 loc) 3 kB
import { wrapCanvas } from "../../../canvas/util"; import { application } from "../../../application"; export class CanvasLayerHandlerContribution { constructor() { this.type = "static", this.offscreen = !1, this.global = application.global; } setDpr(dpr) { this.canvas.dpr = dpr; } init(layer, window, params) { if (this.layer = layer, this.window = window, params.main) this.main = !0, this.context = window.getContext(), this.canvas = this.context.getCanvas(); else { let nativeCanvas; this.main = !1, params.canvasId && (nativeCanvas = this.global.getElementById(params.canvasId)), nativeCanvas || (nativeCanvas = this.global.createCanvas({ id: params.canvasId, width: window.width, height: window.height })), nativeCanvas.style && (nativeCanvas.style["pointer-events"] = "none"); const windowCanvas = window.getContext().getCanvas().nativeCanvas, canvas = wrapCanvas({ nativeCanvas: nativeCanvas, width: window.width, height: window.height, dpr: window.dpr, id: params.canvasId, canvasControled: !0, container: window.getContainer(), x: windowCanvas.offsetLeft, y: windowCanvas.offsetTop }); canvas.applyPosition(), this.canvas = canvas, this.context = canvas.getContext(); } } resize(w, h) { this.canvas.resize(w, h); } resizeView(w, h) {} render(group, params, userParams) { var _a; if (!this.main) { const windowCanvas = this.window.getContext().getCanvas().nativeCanvas; !windowCanvas || this.canvas.x === windowCanvas.offsetLeft && this.canvas.y === windowCanvas.offsetTop || (this.canvas.x = windowCanvas.offsetLeft, this.canvas.y = windowCanvas.offsetTop, this.canvas.applyPosition()); } params.renderService.render(group, Object.assign(Object.assign({ context: this.context, clear: null !== (_a = params.background) && void 0 !== _a ? _a : "#ffffff" }, params), userParams)); } merge(layerHandlers) { layerHandlers.forEach((l => { const canvas = l.getContext().canvas.nativeCanvas; this.context.drawImage(canvas, 0, 0); })); } prepare(dirtyBounds, params) {} drawTo(target, group, params) { var _a; const context = target.getContext(); params.renderService.render(group, Object.assign(Object.assign({ context: context }, params), { clear: params.clear ? null !== (_a = params.background) && void 0 !== _a ? _a : "#fff" : void 0 })); } getContext() { return this.context; } release() { this.canvas.release(); } } //# sourceMappingURL=canvas2d-contribution.js.map