initial commit
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
shadow$provide.module$node_modules$pixi_DOT_js$lib$dom$CanvasObserver = function(global, require, module, exports) {
|
||||
var _const = require("module$node_modules$pixi_DOT_js$lib$ticker$const"), Ticker = require("module$node_modules$pixi_DOT_js$lib$ticker$Ticker");
|
||||
"use strict";
|
||||
class CanvasObserver {
|
||||
constructor(options) {
|
||||
this._lastTransform = "";
|
||||
this._observer = null;
|
||||
this._tickerAttached = !1;
|
||||
this.updateTranslation = () => {
|
||||
if (this._canvas) {
|
||||
var rect = this._canvas.getBoundingClientRect();
|
||||
rect = `translate(${rect.left}px, ${rect.top}px) scale(${rect.width / this._canvas.width * this._renderer.resolution}, ${rect.height / this._canvas.height * this._renderer.resolution})`;
|
||||
rect !== this._lastTransform && (this._lastTransform = this._domElement.style.transform = rect);
|
||||
}
|
||||
};
|
||||
this._domElement = options.domElement;
|
||||
this._renderer = options.renderer;
|
||||
globalThis.OffscreenCanvas && this._renderer.canvas instanceof OffscreenCanvas || (this._canvas = this._renderer.canvas, this._attachObserver());
|
||||
}
|
||||
get canvas() {
|
||||
return this._canvas;
|
||||
}
|
||||
ensureAttached() {
|
||||
!this._domElement.parentNode && this._canvas.parentNode && (this._canvas.parentNode.appendChild(this._domElement), this.updateTranslation());
|
||||
}
|
||||
_attachObserver() {
|
||||
"ResizeObserver" in globalThis ? (this._observer && (this._observer.disconnect(), this._observer = null), this._observer = new ResizeObserver(entries => {
|
||||
for (const entry of entries) {
|
||||
if (entry.target !== this._canvas) {
|
||||
continue;
|
||||
}
|
||||
entries = entry.contentRect.width / this.canvas.width * this._renderer.resolution;
|
||||
const sy = entry.contentRect.height / this.canvas.height * this._renderer.resolution;
|
||||
if (this._lastScaleX !== entries || this._lastScaleY !== sy) {
|
||||
this.updateTranslation(), this._lastScaleX = entries, this._lastScaleY = sy;
|
||||
}
|
||||
}
|
||||
}), this._observer.observe(this._canvas)) : this._tickerAttached || Ticker.Ticker.shared.add(this.updateTranslation, this, _const.UPDATE_PRIORITY.HIGH);
|
||||
}
|
||||
destroy() {
|
||||
this._observer ? (this._observer.disconnect(), this._observer = null) : this._tickerAttached && Ticker.Ticker.shared.remove(this.updateTranslation);
|
||||
this._canvas = this._renderer = this._domElement = null;
|
||||
this._tickerAttached = !1;
|
||||
this._lastTransform = "";
|
||||
this._lastScaleY = this._lastScaleX = null;
|
||||
}
|
||||
}
|
||||
exports.CanvasObserver = CanvasObserver;
|
||||
};
|
||||
|
||||
//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$dom$CanvasObserver.js.map
|
||||
Reference in New Issue
Block a user