Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fancy-canvas

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fancy-canvas - npm Package Compare versions

Comparing version 2.1.0-beta.1 to 2.1.0

canvas-element-bitmap-size.d.mts

0

canvas-element-bitmap-size.d.ts

@@ -0,0 +0,0 @@ import Disposable from './disposable.js';

54

canvas-element-bitmap-size.js

@@ -1,3 +0,6 @@

import { equalSizes, size } from './size.js';
import { createObservable as createDevicePixelRatioObservable } from './device-pixel-ratio.js';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bindTo = void 0;
var size_js_1 = require("./size.js");
var device_pixel_ratio_js_1 = require("./device-pixel-ratio.js");
var DevicePixelContentBoxBinding = /** @class */ (function () {

@@ -15,3 +18,3 @@ function DevicePixelContentBoxBinding(canvasElement, transformBitmapSize, options) {

this._canvasElement = canvasElement;
this._canvasElementClientSize = size({
this._canvasElementClientSize = (0, size_js_1.size)({
width: this._canvasElement.clientWidth,

@@ -28,3 +31,3 @@ height: this._canvasElement.clientHeight,

if (this._canvasElement === null) {
throw new Error("Object is disposed");
throw new Error('Object is disposed');
}

@@ -42,3 +45,3 @@ (_a = this._canvasElementResizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();

if (this._canvasElement === null) {
throw new Error("Object is disposed");
throw new Error('Object is disposed');
}

@@ -59,3 +62,3 @@ return this._canvasElement;

get: function () {
return size({
return (0, size_js_1.size)({
width: this.canvasElement.width,

@@ -73,3 +76,3 @@ height: this.canvasElement.height,

DevicePixelContentBoxBinding.prototype.resizeCanvasElement = function (clientSize) {
this._canvasElementClientSize = size(clientSize);
this._canvasElementClientSize = (0, size_js_1.size)(clientSize);
this.canvasElement.style.width = "".concat(this._canvasElementClientSize.width, "px");

@@ -83,3 +86,3 @@ this.canvasElement.style.height = "".concat(this._canvasElementClientSize.height, "px");

DevicePixelContentBoxBinding.prototype.unsubscribeBitmapSizeChanged = function (listener) {
this._bitmapSizeChangedListeners = this._bitmapSizeChangedListeners.filter(function (l) { return l != listener; });
this._bitmapSizeChangedListeners = this._bitmapSizeChangedListeners.filter(function (l) { return l !== listener; });
};

@@ -97,3 +100,3 @@ Object.defineProperty(DevicePixelContentBoxBinding.prototype, "suggestedBitmapSize", {

DevicePixelContentBoxBinding.prototype.unsubscribeSuggestedBitmapSizeChanged = function (listener) {
this._suggestedBitmapSizeChangedListeners = this._suggestedBitmapSizeChangedListeners.filter(function (l) { return l != listener; });
this._suggestedBitmapSizeChangedListeners = this._suggestedBitmapSizeChangedListeners.filter(function (l) { return l !== listener; });
};

@@ -112,3 +115,3 @@ DevicePixelContentBoxBinding.prototype.applySuggestedBitmapSize = function () {

var oldSize = this.bitmapSize;
if (equalSizes(oldSize, newSize)) {
if ((0, size_js_1.equalSizes)(oldSize, newSize)) {
return;

@@ -126,4 +129,4 @@ }

var oldSuggestedSize = this._suggestedBitmapSize;
var finalNewSize = size(this._transformBitmapSize(newSize, this._canvasElementClientSize));
var newSuggestedSize = equalSizes(this.bitmapSize, finalNewSize) ? null : finalNewSize;
var finalNewSize = (0, size_js_1.size)(this._transformBitmapSize(newSize, this._canvasElementClientSize));
var newSuggestedSize = (0, size_js_1.equalSizes)(this.bitmapSize, finalNewSize) ? null : finalNewSize;
if (oldSuggestedSize === null && newSuggestedSize === null) {

@@ -133,3 +136,3 @@ return;

if (oldSuggestedSize !== null && newSuggestedSize !== null
&& equalSizes(oldSuggestedSize, newSuggestedSize)) {
&& (0, size_js_1.equalSizes)(oldSuggestedSize, newSuggestedSize)) {
return;

@@ -165,6 +168,6 @@ }

var win = canvasElementWindow(this._canvasElement);
if (win == null) {
if (win === null) {
throw new Error('No window is associated with the canvas');
}
this._devicePixelRatioObservable = createDevicePixelRatioObservable(win);
this._devicePixelRatioObservable = (0, device_pixel_ratio_js_1.createObservable)(win);
this._devicePixelRatioObservable.subscribe(function () { return _this._invalidateBitmapSize(); });

@@ -180,3 +183,3 @@ this._invalidateBitmapSize();

var win = canvasElementWindow(this._canvasElement);
if (win == null) {
if (win === null) {
return;

@@ -186,5 +189,7 @@ }

var canvasRects = this._canvasElement.getClientRects();
var newSize = canvasRects.length > 0 ?
var newSize =
// eslint-disable-next-line no-negated-condition
canvasRects[0] !== undefined ?
predictedBitmapSize(canvasRects[0], ratio) :
size({
(0, size_js_1.size)({
width: this._canvasElementClientSize.width * ratio,

@@ -204,7 +209,7 @@ height: this._canvasElementClientSize.height * ratio,

var entry = entries.find(function (entry) { return entry.target === _this._canvasElement; });
if (!entry || !entry.devicePixelContentBoxSize) {
if (!entry || !entry.devicePixelContentBoxSize || !entry.devicePixelContentBoxSize[0]) {
return;
}
var entrySize = entry.devicePixelContentBoxSize[0];
var newSize = size({
var newSize = (0, size_js_1.size)({
width: entrySize.inlineSize,

@@ -219,10 +224,9 @@ height: entrySize.blockSize,

}());
export function bindTo(canvasElement, target) {
function bindTo(canvasElement, target) {
if (target.type === 'device-pixel-content-box') {
return new DevicePixelContentBoxBinding(canvasElement, target.transform, target.options);
}
else {
throw new Error('Unsupported binding target');
}
throw new Error('Unsupported binding target');
}
exports.bindTo = bindTo;
function canvasElementWindow(canvasElement) {

@@ -245,3 +249,3 @@ // According to DOM Level 2 Core specification, ownerDocument should never be null for HTMLCanvasElement

function predictedBitmapSize(canvasRect, ratio) {
return size({
return (0, size_js_1.size)({
width: Math.round(canvasRect.left * ratio + canvasRect.width * ratio) -

@@ -248,0 +252,0 @@ Math.round(canvasRect.left * ratio),

@@ -1,3 +0,3 @@

import { Size } from './size';
import { Binding as CanvasElementBitmapSizeBinding } from './canvas-element-bitmap-size';
import { Size } from './size.js';
import { Binding as CanvasElementBitmapSizeBinding } from './canvas-element-bitmap-size.js';
/**

@@ -4,0 +4,0 @@ * @experimental

@@ -0,1 +1,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tryCreateCanvasRenderingTarget2D = exports.createCanvasRenderingTarget2D = exports.CanvasRenderingTarget2D = void 0;
/**

@@ -23,3 +26,6 @@ * @experimental

this._context.scale(this._horizontalPixelRatio, this._verticalPixelRatio);
return f({ context: this._context, mediaSize: this._mediaSize });
return f({
context: this._context,
mediaSize: this._mediaSize,
});
}

@@ -63,7 +69,7 @@ finally {

}());
export { CanvasRenderingTarget2D };
exports.CanvasRenderingTarget2D = CanvasRenderingTarget2D;
/**
* @experimental
*/
export function createCanvasRenderingTarget2D(binding, contextOptions) {
function createCanvasRenderingTarget2D(binding, contextOptions) {
var mediaSize = binding.canvasElementClientSize;

@@ -77,6 +83,7 @@ var bitmapSize = binding.bitmapSize;

}
exports.createCanvasRenderingTarget2D = createCanvasRenderingTarget2D;
/**
* @experimental
*/
export function tryCreateCanvasRenderingTarget2D(binding, contextOptions) {
function tryCreateCanvasRenderingTarget2D(binding, contextOptions) {
var mediaSize = binding.canvasElementClientSize;

@@ -96,1 +103,2 @@ if (mediaSize.width === 0 || mediaSize.height === 0) {

}
exports.tryCreateCanvasRenderingTarget2D = tryCreateCanvasRenderingTarget2D;
import Disposable from './disposable.js';
import { BehaviorSubject } from './rx.js';
export declare function createObservable(win: Window): BehaviorSubject<number> & Disposable;

@@ -0,1 +1,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createObservable = void 0;
var Observable = /** @class */ (function () {

@@ -25,3 +28,7 @@ function Observable(win) {

this._observers.push(observer);
return { unsubscribe: function () { return _this._observers = _this._observers.filter(function (o) { return o != observer; }); } };
return {
unsubscribe: function () {
_this._observers = _this._observers.filter(function (o) { return o !== observer; });
},
};
};

@@ -55,4 +62,5 @@ Observable.prototype._installResolutionListener = function () {

}());
export function createObservable(win) {
function createObservable(win) {
return new Observable(win);
}
exports.createObservable = createObservable;
export default interface Disposable {
dispose(): void;
}

@@ -1,1 +0,2 @@

export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
export { default as Disposable } from './disposable.js';
export { Size, size, equalSizes } from './size.js';
export { Binding as CanvasElementBitmapSizeBinding, BindingTarget as CanvasElementBitmapSizeBindingTarget, BitmapSizeChangedListener, bindTo as bindCanvasElementBitmapSizeTo } from './canvas-element-bitmap-size.js';
export { CanvasRenderingTarget2D, MediaCoordinatesRenderingScope, BitmapCoordinatesRenderingScope, createCanvasRenderingTarget2D, tryCreateCanvasRenderingTarget2D } from './canvas-rendering-target';
export { Binding as CanvasElementBitmapSizeBinding, BindingTarget as CanvasElementBitmapSizeBindingTarget, BitmapSizeChangedListener, bindTo as bindCanvasElementBitmapSizeTo, } from './canvas-element-bitmap-size.js';
export { CanvasRenderingTarget2D, MediaCoordinatesRenderingScope, BitmapCoordinatesRenderingScope, createCanvasRenderingTarget2D, tryCreateCanvasRenderingTarget2D, } from './canvas-rendering-target.js';

@@ -1,3 +0,12 @@

export { size, equalSizes } from './size.js';
export { bindTo as bindCanvasElementBitmapSizeTo } from './canvas-element-bitmap-size.js';
export { CanvasRenderingTarget2D, createCanvasRenderingTarget2D, tryCreateCanvasRenderingTarget2D } from './canvas-rendering-target';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.tryCreateCanvasRenderingTarget2D = exports.createCanvasRenderingTarget2D = exports.CanvasRenderingTarget2D = exports.bindCanvasElementBitmapSizeTo = exports.equalSizes = exports.size = void 0;
var size_js_1 = require("./size.js");
Object.defineProperty(exports, "size", { enumerable: true, get: function () { return size_js_1.size; } });
Object.defineProperty(exports, "equalSizes", { enumerable: true, get: function () { return size_js_1.equalSizes; } });
var canvas_element_bitmap_size_js_1 = require("./canvas-element-bitmap-size.js");
Object.defineProperty(exports, "bindCanvasElementBitmapSizeTo", { enumerable: true, get: function () { return canvas_element_bitmap_size_js_1.bindTo; } });
var canvas_rendering_target_js_1 = require("./canvas-rendering-target.js");
Object.defineProperty(exports, "CanvasRenderingTarget2D", { enumerable: true, get: function () { return canvas_rendering_target_js_1.CanvasRenderingTarget2D; } });
Object.defineProperty(exports, "createCanvasRenderingTarget2D", { enumerable: true, get: function () { return canvas_rendering_target_js_1.createCanvasRenderingTarget2D; } });
Object.defineProperty(exports, "tryCreateCanvasRenderingTarget2D", { enumerable: true, get: function () { return canvas_rendering_target_js_1.tryCreateCanvasRenderingTarget2D; } });
{
"name": "fancy-canvas",
"version": "2.1.0-beta.1",
"version": "2.1.0",
"author": "smakarov@tradingview.com",

@@ -15,7 +15,10 @@ "description": "Functionality on top of HTML canvas element, including support for HiDPI and pixel-perfect rendering",

"exports": {
"import": "./index.js"
"import": "./index.mjs",
"require": "./index.js"
},
"module": "./index.js",
"type": "module",
"module": "./index.mjs",
"type": "commonjs",
"files": [
"**/*.mjs",
"**/*.d.mts",
"**/*.js",

@@ -22,0 +25,0 @@ "**/*.d.ts"

@@ -0,0 +0,0 @@ export interface NextObserver<T> {

@@ -1,1 +0,2 @@

export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

@@ -0,0 +0,0 @@ export declare type Size = Readonly<{

@@ -1,2 +0,5 @@

export function size(_a) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.equalSizes = exports.size = void 0;
function size(_a) {
var width = _a.width, height = _a.height;

@@ -9,7 +12,12 @@ if (width < 0) {

}
return { width: width, height: height };
return {
width: width,
height: height,
};
}
export function equalSizes(first, second) {
exports.size = size;
function equalSizes(first, second) {
return (first.width === second.width) &&
(first.height === second.height);
}
exports.equalSizes = equalSizes;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc