UNPKG

@visactor/vrender-core

Version:

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

154 lines (147 loc) 5.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.DefaultWindow = exports.WindowHandlerContribution = exports.VWindow = void 0; const vutils_1 = require("@visactor/vutils"), generator_1 = require("../common/generator"), tapable_1 = require("../tapable"), application_1 = require("../application"), event_listener_manager_1 = require("../common/event-listener-manager"); function defaultWindowHandlerFactory(env) { const handlerFactory = application_1.application.windowHandlerFactory; if (!handlerFactory) throw new Error("Window handler factory is not configured."); return handlerFactory(env); } exports.VWindow = Symbol.for("VWindow"), exports.WindowHandlerContribution = Symbol.for("WindowHandlerContribution"); class DefaultWindow extends event_listener_manager_1.EventListenerManager { get width() { if (this._handler) { const wh = this._handler.getWH(); return this._width = wh.width; } return this._width; } get height() { if (this._handler) { const wh = this._handler.getWH(); return this._height = wh.height; } return this._height; } get dpr() { return this._handler.getDpr(); } constructor(vRenderGlobal = application_1.application.global, handlerFactory = defaultWindowHandlerFactory) { super(), this.handlerFactory = handlerFactory, this.hooks = { onChange: new tapable_1.SyncHook([ "x", "y", "width", "height" ]) }, this.active = () => { const vRenderGlobal = this.global; if (!vRenderGlobal.env || this.actived) return; this.handlerFactory(vRenderGlobal.env).configure(this, vRenderGlobal), this.actived = !0; }, this._uid = generator_1.Generator.GenAutoIncrementId(), this.global = vRenderGlobal, this.postInit(); } _nativeAddEventListener(type, listener, options) { return this._handler.addEventListener(type, listener, options); } _nativeRemoveEventListener(type, listener, options) { return this._handler.removeEventListener(type, listener, options); } _nativeDispatchEvent(event) { return this._handler.dispatchEvent(event); } postInit() { this.global.hooks.onSetEnv.tap("window", this.active), this.active(); } get style() { var _a; return null !== (_a = this._handler.getStyle()) && void 0 !== _a ? _a : {}; } set style(style) { this._handler.setStyle(style); } create(params) { var _a, _b; this._handler.createWindow(params); const windowWH = this._handler.getWH(); this._width = windowWH.width, this._height = windowWH.height, params.viewBox ? this.setViewBox(params.viewBox) : !1 !== params.canvasControled ? this.setViewBox({ x1: 0, y1: 0, x2: this._width, y2: this._height }) : this.setViewBox({ x1: 0, y1: 0, x2: null !== (_a = params.width) && void 0 !== _a ? _a : this._width, y2: null !== (_b = params.height) && void 0 !== _b ? _b : this._height }), this.title = this._handler.getTitle(), this.resizable = !0; } setWindowHandler(handler) { this._handler = handler; } setDpr(dpr) { return this._handler.setDpr(dpr); } resize(w, h) { return this._handler.resizeWindow(w, h); } configure() { throw new Error("暂不支持"); } release() { return this.global.hooks.onSetEnv.unTap("window", this.active), this.clearAllEventListeners(), this._handler.releaseWindow(); } getContext() { return this._handler.getContext(); } getNativeHandler() { return this._handler.getNativeHandler(); } getImageBuffer(type) { return this._handler.getImageBuffer ? this._handler.getImageBuffer(type) : null; } getBoundingClientRect() { return this._handler.getBoundingClientRect(); } getContainer() { return this._handler.container; } clearViewBox(color) { this._handler.clearViewBox(color); } setViewBox(viewBox) { this._handler.setViewBox(viewBox); } setViewBoxTransform(a, b, c, d, e, f) { this._handler.setViewBoxTransform(a, b, c, d, e, f); } getViewBox() { return this._handler.getViewBox(); } getViewBoxTransform() { return this._handler.getViewBoxTransform(); } pointTransform(x, y) { const vb = this._handler.getViewBox(), nextP = { x: x, y: y }; return this._handler.getViewBoxTransform().transformPoint({ x: x, y: y }, nextP), nextP.x -= vb.x1, nextP.y -= vb.y1, nextP; } hasSubView() { const viewBox = this._handler.getViewBox(); return !(0 === viewBox.x1 && 0 === viewBox.y1 && (0, vutils_1.isNumberClose)(this.width, viewBox.width()) && (0, vutils_1.isNumberClose)(this.height, viewBox.height())); } isVisible(bbox) { return this._handler.isVisible(bbox); } onVisibleChange(cb) { return this._handler.onVisibleChange(cb); } getTopLeft(baseWindow) { return this._handler.getTopLeft(baseWindow); } } exports.DefaultWindow = DefaultWindow; //# sourceMappingURL=window.js.map