UNPKG

@visactor/vrender-core

Version:
40 lines (35 loc) 3.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: !0 }), exports.DirtyBoundsPlugin = void 0; const vutils_1 = require("@visactor/vutils"), generator_1 = require("../../common/generator"), application_1 = require("../../application"), globalBounds = new vutils_1.AABBBounds; class DirtyBoundsPlugin { constructor() { this.name = "DirtyBoundsPlugin", this.activeEvent = "onRegister", this._uid = generator_1.Generator.GenAutoIncrementId(), this.key = this.name + this._uid; } activate(context) { this.pluginService = context, context.stage.hooks.afterRender.tap(this.key, (stage => { stage && stage === this.pluginService.stage && stage.dirtyBounds.clear(); })), application_1.application.graphicService.hooks.beforeUpdateAABBBounds.tap(this.key, ((graphic, stage, willUpdate, bounds) => { graphic.glyphHost && (graphic = graphic.glyphHost), stage && stage === this.pluginService.stage && stage.renderCount && (graphic.isContainer && !graphic.shouldSelfChangeUpdateAABBBounds() || willUpdate && (globalBounds.setValue(bounds.x1, bounds.y1, bounds.x2, bounds.y2), stage.dirty(globalBounds, graphic.parent && graphic.parent.globalTransMatrix))); })), application_1.application.graphicService.hooks.afterUpdateAABBBounds.tap(this.key, ((graphic, stage, bounds, params, selfChange) => { stage && stage === this.pluginService.stage && stage.renderCount && (graphic.isContainer && !selfChange || stage.dirty(params.globalAABBBounds)); })), application_1.application.graphicService.hooks.clearAABBBounds.tap(this.key, ((graphic, stage, bounds) => { stage && stage === this.pluginService.stage && stage.renderCount && stage && stage.dirty(bounds); })), application_1.application.graphicService.hooks.onRemove.tap(this.key, (graphic => { const stage = graphic.stage; stage && stage === this.pluginService.stage && stage.renderCount && stage && stage.dirty(graphic.globalAABBBounds); })); } deactivate(context) { application_1.application.graphicService.hooks.beforeUpdateAABBBounds.taps = application_1.application.graphicService.hooks.beforeUpdateAABBBounds.taps.filter((item => item.name !== this.key)), application_1.application.graphicService.hooks.afterUpdateAABBBounds.taps = application_1.application.graphicService.hooks.afterUpdateAABBBounds.taps.filter((item => item.name !== this.key)), application_1.application.graphicService.hooks.clearAABBBounds.taps = application_1.application.graphicService.hooks.clearAABBBounds.taps.filter((item => item.name !== this.key)), context.stage.hooks.afterRender.taps = context.stage.hooks.afterRender.taps.filter((item => item.name !== this.key)), application_1.application.graphicService.hooks.onRemove.taps = application_1.application.graphicService.hooks.onRemove.taps.filter((item => item.name !== this.key)); } } exports.DirtyBoundsPlugin = DirtyBoundsPlugin; //# sourceMappingURL=dirty-bounds-plugin.js.map