fancy-canvas
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -5,4 +5,6 @@ export declare type Size = { | ||
}; | ||
export declare type CanvasConfiguredListener = (this: Binding) => void; | ||
export interface Binding { | ||
destroy(): void; | ||
readonly canvas: HTMLCanvasElement; | ||
/** | ||
@@ -12,4 +14,6 @@ * Canvas element size in CSS pixels | ||
canvasSize: Size; | ||
pixelRatio: number; | ||
readonly pixelRatio: number; | ||
subscribeCanvasConfigured(listener: CanvasConfiguredListener): void; | ||
unsubscribeCanvasConfigured(listener: CanvasConfiguredListener): void; | ||
} | ||
export declare function bindToDevicePixelRatio(canvas: HTMLCanvasElement): Binding; |
@@ -9,2 +9,3 @@ export function bindToDevicePixelRatio(canvas) { | ||
this._resolutionListener = function (ev) { return _this._onResolutionChanged(); }; | ||
this._canvasConfiguredListeners = []; | ||
this._canvas = canvas; | ||
@@ -19,2 +20,3 @@ this._canvasSize = { | ||
DevicePixelRatioBinding.prototype.destroy = function () { | ||
this._canvasConfiguredListeners.length = 0; | ||
this._uninstallResolutionListener(); | ||
@@ -24,2 +26,9 @@ this._canvasSize = null; | ||
}; | ||
Object.defineProperty(DevicePixelRatioBinding.prototype, "canvas", { | ||
get: function () { | ||
return this._canvas; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(DevicePixelRatioBinding.prototype, "canvasSize", { | ||
@@ -50,2 +59,8 @@ get: function () { | ||
}); | ||
DevicePixelRatioBinding.prototype.subscribeCanvasConfigured = function (listener) { | ||
this._canvasConfiguredListeners.push(listener); | ||
}; | ||
DevicePixelRatioBinding.prototype.unsubscribeCanvasConfigured = function (listener) { | ||
this._canvasConfiguredListeners = this._canvasConfiguredListeners.filter(function (l) { return l != listener; }); | ||
}; | ||
DevicePixelRatioBinding.prototype._configureCanvas = function () { | ||
@@ -57,3 +72,8 @@ var ratio = this.pixelRatio; | ||
this._canvas.height = this._canvasSize.height * ratio; | ||
this._emitCanvasConfigured(); | ||
}; | ||
DevicePixelRatioBinding.prototype._emitCanvasConfigured = function () { | ||
var _this = this; | ||
this._canvasConfiguredListeners.forEach(function (listener) { return listener.call(_this); }); | ||
}; | ||
DevicePixelRatioBinding.prototype._installResolutionListener = function () { | ||
@@ -60,0 +80,0 @@ if (this._resolutionMediaQueryList !== null) { |
{ | ||
"name": "fancy-canvas", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"author": "smakarov@tradingview.com", | ||
@@ -5,0 +5,0 @@ "description": "Functionality on top of HTML canvas element, including support for HiDPI and pixel-perfect rendering", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5938
124