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

resize-observer-polyfill

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resize-observer-polyfill - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

src/shims/global.js

187

dist/ResizeObserver.es.js

@@ -0,1 +1,26 @@

/**
* Exports global object for the current environment.
*/
var global$1 = (function () {
if (typeof self != 'undefined' && self.Math === Math) {
return self;
}
if (typeof window != 'undefined' && window.Math === Math) {
return window;
}
if (typeof global != 'undefined' && global.Math === Math) {
return global;
}
// eslint-disable-next-line no-new-func
return Function('return this')();
})();
/**
* Detects whether window and document objects are available in current environment.
*/
var isBrowser = global$1.window === global$1 && typeof document != 'undefined';
var classCallCheck = function (instance, Constructor) {

@@ -56,8 +81,9 @@ if (!(instance instanceof Constructor)) {

* of use cases.
*//* eslint-disable require-jsdoc */
var hasNativeCollections = typeof window.WeakMap === 'function' && typeof window.Map === 'function';
*/
/* eslint-disable require-jsdoc */
var hasNativeCollections = typeof global$1.WeakMap === 'function' && typeof global$1.Map === 'function';
var WeakMap = function () {
if (hasNativeCollections) {
return window.WeakMap;
return global$1.WeakMap;
}

@@ -123,3 +149,3 @@

if (hasNativeCollections) {
return window.Map;
return global$1.Map;
}

@@ -192,5 +218,5 @@

*/
var reqAnimFrame = (function () {
if (typeof window.requestAnimationFrame === 'function') {
return window.requestAnimationFrame;
var requestAnimFrame = (function () {
if (typeof global$1.requestAnimationFrame === 'function') {
return global$1.requestAnimationFrame;
}

@@ -247,3 +273,3 @@

function timeoutCallback() {
afterRAF ? reqAnimFrame(invokeCallback) : invokeCallback();
afterRAF ? requestAnimFrame(invokeCallback) : invokeCallback();
}

@@ -278,3 +304,3 @@

// Define whether the MutationObserver is supported.
var mutationsSupported = typeof window.MutationObserver === 'function';
var mutationsSupported = typeof global$1.MutationObserver === 'function';

@@ -887,3 +913,3 @@ /**

var ResizeObserver$3 = function () {
var ResizeObserver$2 = function () {
/**

@@ -1055,79 +1081,106 @@ * Creates a new instance of ResizeObserver.

// Controller that will be assigned to all instances of ResizeObserver.
var controller = new ResizeObserverController();
var ResizeObserverPolyfill = (function () {
if (!isBrowser) {
/* eslint-disable */
var _ResizeObserver2 = function () {
function _ResizeObserver2() {
classCallCheck(this, _ResizeObserver2);
}
// Registry of the internal observers.
var observers = new WeakMap();
_ResizeObserver2.prototype.observe = function observe() {};
/**
* ResizeObservers' "Proxy" class which is meant to hide private properties and
* methods from public instances.
*
* Additionally implements the "continuousUpdates" static property accessor to
* give control over the behavior of the ResizeObserverController instance.
* Changes made to this property affect all future and existing observers.
*/
var ResizeObserver$2 = function () {
/**
* Creates a new instance of ResizeObserver.
*
* @param {Function} callback - Callback that is invoked when dimensions of
* one of the observed elements change.
*/
function ResizeObserver(callback) {
classCallCheck(this, ResizeObserver);
_ResizeObserver2.prototype.unobserve = function unobserve() {};
if (!arguments.length) {
throw new TypeError('1 argument required, but only 0 present.');
}
_ResizeObserver2.prototype.disconnect = function disconnect() {};
// Create a new instance of the internal ResizeObserver.
var observer = new ResizeObserver$3(callback, controller, this);
return _ResizeObserver2;
}();
/* eslint-enable */
_ResizeObserver2.continuousUpdates = false;
// Register internal observer.
observers.set(this, observer);
return _ResizeObserver2;
}
createClass(ResizeObserver, null, [{
key: 'continuousUpdates',
// Controller that will be assigned to all instances of ResizeObserver.
var controller = new ResizeObserverController();
// Registry of the internal observers.
var observers = new WeakMap();
/**
* ResizeObservers' "Proxy" class which is meant to hide private properties and
* methods from public instances.
*
* Additionally implements the "continuousUpdates" static property accessor to
* give control over the behavior of the ResizeObserverController instance.
* Changes made to this property affect all future and existing observers.
*/
var ResizeObserver = function () {
/**
* Tells whether continuous updates are enabled.
* Creates a new instance of ResizeObserver.
*
* @returns {Boolean}
* @param {Function} callback - Callback that is invoked when dimensions of
* one of the observed elements change.
*/
get: function get() {
return controller.continuousUpdates;
},
function ResizeObserver(callback) {
classCallCheck(this, ResizeObserver);
/**
* Enables or disables continuous updates.
*
* @param {Boolean} value - Whether to enable or disable continuous updates.
*/
set: function set(value) {
if (typeof value !== 'boolean') {
throw new TypeError('type of "continuousUpdates" value must be boolean.');
if (!arguments.length) {
throw new TypeError('1 argument required, but only 0 present.');
}
controller.continuousUpdates = value;
// Create a new instance of the internal ResizeObserver.
var observer = new ResizeObserver$2(callback, controller, this);
// Register internal observer.
observers.set(this, observer);
}
}]);
return ResizeObserver;
}();
// Expose public methods of ResizeObserver.
['observe', 'unobserve', 'disconnect'].forEach(function (method) {
ResizeObserver$2.prototype[method] = function () {
var _observers$get;
createClass(ResizeObserver, null, [{
key: 'continuousUpdates',
return (_observers$get = observers.get(this))[method].apply(_observers$get, arguments);
};
});
/**
* Tells whether continuous updates are enabled.
*
* @returns {Boolean}
*/
get: function get() {
return controller.continuousUpdates;
},
var ResizeObserver = ResizeObserver$2;
/**
* Enables or disables continuous updates.
*
* @param {Boolean} value - Whether to enable or disable continuous updates.
*/
set: function set(value) {
if (typeof value !== 'boolean') {
throw new TypeError('type of "continuousUpdates" value must be boolean.');
}
controller.continuousUpdates = value;
}
}]);
return ResizeObserver;
}();
// Expose public methods of ResizeObserver.
['observe', 'unobserve', 'disconnect'].forEach(function (method) {
ResizeObserver.prototype[method] = function () {
if (isBrowser) {
var _observers$get;
(_observers$get = observers.get(this))[method].apply(_observers$get, arguments);
}
};
});
return ResizeObserver;
})();
var ResizeObserver = ResizeObserverPolyfill;
// Export existing implementation if it's available.
if (typeof window.ResizeObserver === 'function') {
ResizeObserver = window.ResizeObserver;
if (typeof global$1.ResizeObserver === 'function') {
ResizeObserver = global$1.ResizeObserver;
}

@@ -1134,0 +1187,0 @@

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.ResizeObserver = factory());
}(this, (function () { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.ResizeObserver = factory());
}(this, (function () {
'use strict';
/**
* Exports global object for the current environment.
*/
var global$1 = (function () {
if (typeof self != 'undefined' && self.Math === Math) {
return self;
}
if (typeof window != 'undefined' && window.Math === Math) {
return window;
}
if (typeof global != 'undefined' && global.Math === Math) {
return global;
}
// eslint-disable-next-line no-new-func
return Function('return this')();
})();
/**
* Detects whether window and document objects are available in current environment.
*/
var isBrowser = global$1.window === global$1 && typeof document != 'undefined';
var classCallCheck = function (instance, Constructor) {

@@ -62,8 +88,9 @@ if (!(instance instanceof Constructor)) {

* of use cases.
*//* eslint-disable require-jsdoc */
var hasNativeCollections = typeof window.WeakMap === 'function' && typeof window.Map === 'function';
*/
/* eslint-disable require-jsdoc */
var hasNativeCollections = typeof global$1.WeakMap === 'function' && typeof global$1.Map === 'function';
var WeakMap = function () {
if (hasNativeCollections) {
return window.WeakMap;
return global$1.WeakMap;
}

@@ -129,3 +156,3 @@

if (hasNativeCollections) {
return window.Map;
return global$1.Map;
}

@@ -198,5 +225,5 @@

*/
var reqAnimFrame = (function () {
if (typeof window.requestAnimationFrame === 'function') {
return window.requestAnimationFrame;
var requestAnimFrame = (function () {
if (typeof global$1.requestAnimationFrame === 'function') {
return global$1.requestAnimationFrame;
}

@@ -253,3 +280,3 @@

function timeoutCallback() {
afterRAF ? reqAnimFrame(invokeCallback) : invokeCallback();
afterRAF ? requestAnimFrame(invokeCallback) : invokeCallback();
}

@@ -284,3 +311,3 @@

// Define whether the MutationObserver is supported.
var mutationsSupported = typeof window.MutationObserver === 'function';
var mutationsSupported = typeof global$1.MutationObserver === 'function';

@@ -893,3 +920,3 @@ /**

var ResizeObserver$2 = function () {
var ResizeObserver$1 = function () {
/**

@@ -1061,78 +1088,109 @@ * Creates a new instance of ResizeObserver.

// Controller that will be assigned to all instances of ResizeObserver.
var controller = new ResizeObserverController();
var ResizeObserver = (function () {
if (!isBrowser) {
/* eslint-disable */
var _ResizeObserver2 = function () {
function _ResizeObserver2() {
classCallCheck(this, _ResizeObserver2);
}
// Registry of the internal observers.
var observers = new WeakMap();
_ResizeObserver2.prototype.observe = function observe() {};
/**
* ResizeObservers' "Proxy" class which is meant to hide private properties and
* methods from public instances.
*
* Additionally implements the "continuousUpdates" static property accessor to
* give control over the behavior of the ResizeObserverController instance.
* Changes made to this property affect all future and existing observers.
*/
var ResizeObserver = function () {
/**
* Creates a new instance of ResizeObserver.
*
* @param {Function} callback - Callback that is invoked when dimensions of
* one of the observed elements change.
*/
function ResizeObserver(callback) {
classCallCheck(this, ResizeObserver);
_ResizeObserver2.prototype.unobserve = function unobserve() {};
if (!arguments.length) {
throw new TypeError('1 argument required, but only 0 present.');
}
_ResizeObserver2.prototype.disconnect = function disconnect() {};
// Create a new instance of the internal ResizeObserver.
var observer = new ResizeObserver$2(callback, controller, this);
return _ResizeObserver2;
}();
/* eslint-enable */
// Register internal observer.
observers.set(this, observer);
_ResizeObserver2.continuousUpdates = false;
return _ResizeObserver2;
}
createClass(ResizeObserver, null, [{
key: 'continuousUpdates',
// Controller that will be assigned to all instances of ResizeObserver.
var controller = new ResizeObserverController();
// Registry of the internal observers.
var observers = new WeakMap();
/**
* ResizeObservers' "Proxy" class which is meant to hide private properties and
* methods from public instances.
*
* Additionally implements the "continuousUpdates" static property accessor to
* give control over the behavior of the ResizeObserverController instance.
* Changes made to this property affect all future and existing observers.
*/
var ResizeObserver = function () {
/**
* Tells whether continuous updates are enabled.
* Creates a new instance of ResizeObserver.
*
* @returns {Boolean}
* @param {Function} callback - Callback that is invoked when dimensions of
* one of the observed elements change.
*/
get: function get() {
return controller.continuousUpdates;
},
function ResizeObserver(callback) {
classCallCheck(this, ResizeObserver);
/**
* Enables or disables continuous updates.
*
* @param {Boolean} value - Whether to enable or disable continuous updates.
*/
set: function set(value) {
if (typeof value !== 'boolean') {
throw new TypeError('type of "continuousUpdates" value must be boolean.');
if (!arguments.length) {
throw new TypeError('1 argument required, but only 0 present.');
}
controller.continuousUpdates = value;
// Create a new instance of the internal ResizeObserver.
var observer = new ResizeObserver$1(callback, controller, this);
// Register internal observer.
observers.set(this, observer);
}
}]);
return ResizeObserver;
}();
// Expose public methods of ResizeObserver.
['observe', 'unobserve', 'disconnect'].forEach(function (method) {
ResizeObserver.prototype[method] = function () {
var _observers$get;
createClass(ResizeObserver, null, [{
key: 'continuousUpdates',
return (_observers$get = observers.get(this))[method].apply(_observers$get, arguments);
};
});
/**
* Tells whether continuous updates are enabled.
*
* @returns {Boolean}
*/
get: function get() {
return controller.continuousUpdates;
},
if (typeof window.ResizeObserver !== 'function') {
/**
* Enables or disables continuous updates.
*
* @param {Boolean} value - Whether to enable or disable continuous updates.
*/
set: function set(value) {
if (typeof value !== 'boolean') {
throw new TypeError('type of "continuousUpdates" value must be boolean.');
}
controller.continuousUpdates = value;
}
}]);
return ResizeObserver;
}();
// Expose public methods of ResizeObserver.
['observe', 'unobserve', 'disconnect'].forEach(function (method) {
ResizeObserver.prototype[method] = function () {
if (isBrowser) {
var _observers$get;
(_observers$get = observers.get(this))[method].apply(_observers$get, arguments);
}
};
});
return ResizeObserver;
})();
/**
* @deprecated Global version of the polyfill is deprecated and will be removed in the next major release.
*/
if (typeof global$1.ResizeObserver !== 'function') {
// ResizeObserver host property is not enumerable
// in the native implementation.
Object.defineProperty(window, 'ResizeObserver', {
Object.defineProperty(global$1, 'ResizeObserver', {
value: ResizeObserver,

@@ -1146,5 +1204,5 @@ writable: true,

// awkward when a module doesn't export anything.
var index_global = window.ResizeObserver;
var index_global = global$1.ResizeObserver;
return index_global;
})));
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.ResizeObserver = factory());
}(this, (function () { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.ResizeObserver = factory());
}(this, (function () {
'use strict';
/**
* Exports global object for the current environment.
*/
var global$1 = (function () {
if (typeof self != 'undefined' && self.Math === Math) {
return self;
}
if (typeof window != 'undefined' && window.Math === Math) {
return window;
}
if (typeof global != 'undefined' && global.Math === Math) {
return global;
}
// eslint-disable-next-line no-new-func
return Function('return this')();
})();
/**
* Detects whether window and document objects are available in current environment.
*/
var isBrowser = global$1.window === global$1 && typeof document != 'undefined';
var classCallCheck = function (instance, Constructor) {

@@ -62,8 +88,9 @@ if (!(instance instanceof Constructor)) {

* of use cases.
*//* eslint-disable require-jsdoc */
var hasNativeCollections = typeof window.WeakMap === 'function' && typeof window.Map === 'function';
*/
/* eslint-disable require-jsdoc */
var hasNativeCollections = typeof global$1.WeakMap === 'function' && typeof global$1.Map === 'function';
var WeakMap = function () {
if (hasNativeCollections) {
return window.WeakMap;
return global$1.WeakMap;
}

@@ -129,3 +156,3 @@

if (hasNativeCollections) {
return window.Map;
return global$1.Map;
}

@@ -198,5 +225,5 @@

*/
var reqAnimFrame = (function () {
if (typeof window.requestAnimationFrame === 'function') {
return window.requestAnimationFrame;
var requestAnimFrame = (function () {
if (typeof global$1.requestAnimationFrame === 'function') {
return global$1.requestAnimationFrame;
}

@@ -253,3 +280,3 @@

function timeoutCallback() {
afterRAF ? reqAnimFrame(invokeCallback) : invokeCallback();
afterRAF ? requestAnimFrame(invokeCallback) : invokeCallback();
}

@@ -284,3 +311,3 @@

// Define whether the MutationObserver is supported.
var mutationsSupported = typeof window.MutationObserver === 'function';
var mutationsSupported = typeof global$1.MutationObserver === 'function';

@@ -893,3 +920,3 @@ /**

var ResizeObserver$3 = function () {
var ResizeObserver$2 = function () {
/**

@@ -1061,79 +1088,106 @@ * Creates a new instance of ResizeObserver.

// Controller that will be assigned to all instances of ResizeObserver.
var controller = new ResizeObserverController();
var ResizeObserverPolyfill = (function () {
if (!isBrowser) {
/* eslint-disable */
var _ResizeObserver2 = function () {
function _ResizeObserver2() {
classCallCheck(this, _ResizeObserver2);
}
// Registry of the internal observers.
var observers = new WeakMap();
_ResizeObserver2.prototype.observe = function observe() {};
/**
* ResizeObservers' "Proxy" class which is meant to hide private properties and
* methods from public instances.
*
* Additionally implements the "continuousUpdates" static property accessor to
* give control over the behavior of the ResizeObserverController instance.
* Changes made to this property affect all future and existing observers.
*/
var ResizeObserver$2 = function () {
/**
* Creates a new instance of ResizeObserver.
*
* @param {Function} callback - Callback that is invoked when dimensions of
* one of the observed elements change.
*/
function ResizeObserver(callback) {
classCallCheck(this, ResizeObserver);
_ResizeObserver2.prototype.unobserve = function unobserve() {};
if (!arguments.length) {
throw new TypeError('1 argument required, but only 0 present.');
}
_ResizeObserver2.prototype.disconnect = function disconnect() {};
// Create a new instance of the internal ResizeObserver.
var observer = new ResizeObserver$3(callback, controller, this);
return _ResizeObserver2;
}();
/* eslint-enable */
_ResizeObserver2.continuousUpdates = false;
// Register internal observer.
observers.set(this, observer);
return _ResizeObserver2;
}
createClass(ResizeObserver, null, [{
key: 'continuousUpdates',
// Controller that will be assigned to all instances of ResizeObserver.
var controller = new ResizeObserverController();
// Registry of the internal observers.
var observers = new WeakMap();
/**
* ResizeObservers' "Proxy" class which is meant to hide private properties and
* methods from public instances.
*
* Additionally implements the "continuousUpdates" static property accessor to
* give control over the behavior of the ResizeObserverController instance.
* Changes made to this property affect all future and existing observers.
*/
var ResizeObserver = function () {
/**
* Tells whether continuous updates are enabled.
* Creates a new instance of ResizeObserver.
*
* @returns {Boolean}
* @param {Function} callback - Callback that is invoked when dimensions of
* one of the observed elements change.
*/
get: function get() {
return controller.continuousUpdates;
},
function ResizeObserver(callback) {
classCallCheck(this, ResizeObserver);
/**
* Enables or disables continuous updates.
*
* @param {Boolean} value - Whether to enable or disable continuous updates.
*/
set: function set(value) {
if (typeof value !== 'boolean') {
throw new TypeError('type of "continuousUpdates" value must be boolean.');
if (!arguments.length) {
throw new TypeError('1 argument required, but only 0 present.');
}
controller.continuousUpdates = value;
// Create a new instance of the internal ResizeObserver.
var observer = new ResizeObserver$2(callback, controller, this);
// Register internal observer.
observers.set(this, observer);
}
}]);
return ResizeObserver;
}();
// Expose public methods of ResizeObserver.
['observe', 'unobserve', 'disconnect'].forEach(function (method) {
ResizeObserver$2.prototype[method] = function () {
var _observers$get;
createClass(ResizeObserver, null, [{
key: 'continuousUpdates',
return (_observers$get = observers.get(this))[method].apply(_observers$get, arguments);
};
});
/**
* Tells whether continuous updates are enabled.
*
* @returns {Boolean}
*/
get: function get() {
return controller.continuousUpdates;
},
var ResizeObserver = ResizeObserver$2;
/**
* Enables or disables continuous updates.
*
* @param {Boolean} value - Whether to enable or disable continuous updates.
*/
set: function set(value) {
if (typeof value !== 'boolean') {
throw new TypeError('type of "continuousUpdates" value must be boolean.');
}
controller.continuousUpdates = value;
}
}]);
return ResizeObserver;
}();
// Expose public methods of ResizeObserver.
['observe', 'unobserve', 'disconnect'].forEach(function (method) {
ResizeObserver.prototype[method] = function () {
if (isBrowser) {
var _observers$get;
(_observers$get = observers.get(this))[method].apply(_observers$get, arguments);
}
};
});
return ResizeObserver;
})();
var ResizeObserver = ResizeObserverPolyfill;
// Export existing implementation if it's available.
if (typeof window.ResizeObserver === 'function') {
ResizeObserver = window.ResizeObserver;
if (typeof global$1.ResizeObserver === 'function') {
ResizeObserver = global$1.ResizeObserver;
}

@@ -1140,0 +1194,0 @@

/**
* @deprecated Global version of the polyfill is deprecated and will be removed in the next major release.
*/
import global from './src/shims/global';
import ResizeObserver from './src/ResizeObserver';
if (typeof window.ResizeObserver !== 'function') {
if (typeof global.ResizeObserver !== 'function') {
// ResizeObserver host property is not enumerable
// in the native implementation.
Object.defineProperty(window, 'ResizeObserver', {
Object.defineProperty(global, 'ResizeObserver', {
value: ResizeObserver,

@@ -18,2 +19,2 @@ writable: true,

// awkward when a module doesn't export anything.
export default window.ResizeObserver;
export default global.ResizeObserver;

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

import global from './src/shims/global';
import ResizeObserverPolyfill from './src/ResizeObserver';

@@ -6,6 +7,6 @@

// Export existing implementation if it's available.
if (typeof window.ResizeObserver === 'function') {
ResizeObserver = window.ResizeObserver;
if (typeof global.ResizeObserver === 'function') {
ResizeObserver = global.ResizeObserver;
}
export default ResizeObserver;
{
"name": "resize-observer-polyfill",
"author": "Denis Rul <que.etc@gmail.com>",
"version": "1.3.0",
"version": "1.3.1",
"description": "A polyfill for the Resize Observer API",
"main": "dist/ResizeObserver.js",
"jsnext:main": "dist/ResizeObserver.es.js",
"module": "dist/ResizeObserver.es.js",
"scripts": {
"test:lint": "eslint **/*.js --ignore-pattern dist/*",
"test:lint": "eslint **/*.js",
"test:spec": "karma start",

@@ -12,0 +11,0 @@ "test:spec:custom": "karma start --mode custom",

@@ -71,3 +71,3 @@ ResizeObserver Polyfill

Package's main file is a ES5 [UMD](https://github.com/umdjs/umd) module and it will be dynamically substituted by the ES6 version for those bundlers that are aware of the [jnext:main](https://github.com/rollup/rollup/wiki/jsnext:main) or `module` fields, e.g. for [Rollup](https://github.com/rollup/rollup) or [Webpack 2](https://webpack.js.org/).
Package's main file is a ES5 [UMD](https://github.com/umdjs/umd) module and it will be dynamically substituted by the ES6 version for those bundlers that are aware of the [jnext:main](https://github.com/rollup/rollup/wiki/jsnext:main) field, e.g. for [Rollup](https://github.com/rollup/rollup).

@@ -74,0 +74,0 @@ **Note**: global versions (`index.global` and `dist/ResizeObserver.global`) are deprecated and will be removed in the next major release.

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

import isBrowser from './utils/isBrowser';
import {WeakMap} from './shims/es6-collections';

@@ -5,69 +6,89 @@ import ResizeObserverController from './ResizeObserverController';

// Controller that will be assigned to all instances of ResizeObserver.
const controller = new ResizeObserverController();
export default (function () {
// Fall back to a class with empty functions if running in a non-browser
// environment.
if (!isBrowser) {
/* eslint-disable */
class ResizeObserver {
observe() {}
unobserve() {}
disconnect() {}
};
/* eslint-enable */
// Registry of the internal observers.
const observers = new WeakMap();
ResizeObserver.continuousUpdates = false;
/**
* ResizeObservers' "Proxy" class which is meant to hide private properties and
* methods from public instances.
*
* Additionally implements the "continuousUpdates" static property accessor to
* give control over the behavior of the ResizeObserverController instance.
* Changes made to this property affect all future and existing observers.
*/
class ResizeObserver {
/**
* Creates a new instance of ResizeObserver.
*
* @param {Function} callback - Callback that is invoked when dimensions of
* one of the observed elements change.
*/
constructor(callback) {
if (!arguments.length) {
throw new TypeError('1 argument required, but only 0 present.');
}
return ResizeObserver;
}
// Create a new instance of the internal ResizeObserver.
const observer = new _ResizeObserver(callback, controller, this);
// Controller that will be assigned to all instances of ResizeObserver.
const controller = new ResizeObserverController();
// Register internal observer.
observers.set(this, observer);
}
// Registry of the internal observers.
const observers = new WeakMap();
/**
* Tells whether continuous updates are enabled.
* ResizeObservers' "Proxy" class which is meant to hide private properties and
* methods from public instances.
*
* @returns {Boolean}
* Additionally implements the "continuousUpdates" static property accessor to
* give control over the behavior of the ResizeObserverController instance.
* Changes made to this property affect all future and existing observers.
*/
static get continuousUpdates() {
return controller.continuousUpdates;
}
class ResizeObserver {
/**
* Creates a new instance of ResizeObserver.
*
* @param {Function} callback - Callback that is invoked when dimensions of
* one of the observed elements change.
*/
constructor(callback) {
if (!arguments.length) {
throw new TypeError('1 argument required, but only 0 present.');
}
/**
* Enables or disables continuous updates.
*
* @param {Boolean} value - Whether to enable or disable continuous updates.
*/
static set continuousUpdates(value) {
if (typeof value !== 'boolean') {
throw new TypeError('type of "continuousUpdates" value must be boolean.');
// Create a new instance of the internal ResizeObserver.
const observer = new _ResizeObserver(callback, controller, this);
// Register internal observer.
observers.set(this, observer);
}
controller.continuousUpdates = value;
/**
* Tells whether continuous updates are enabled.
*
* @returns {Boolean}
*/
static get continuousUpdates() {
return controller.continuousUpdates;
}
/**
* Enables or disables continuous updates.
*
* @param {Boolean} value - Whether to enable or disable continuous updates.
*/
static set continuousUpdates(value) {
if (typeof value !== 'boolean') {
throw new TypeError('type of "continuousUpdates" value must be boolean.');
}
controller.continuousUpdates = value;
}
}
}
// Expose public methods of ResizeObserver.
[
'observe',
'unobserve',
'disconnect'
].forEach(method => {
ResizeObserver.prototype[method] = function () {
return observers.get(this)[method](...arguments);
};
});
// Expose public methods of ResizeObserver.
[
'observe',
'unobserve',
'disconnect'
].forEach(method => {
ResizeObserver.prototype[method] = function () {
if (isBrowser) {
observers.get(this)[method](...arguments);
}
};
});
export default ResizeObserver;
return ResizeObserver;
})();

@@ -1,5 +0,6 @@

import throttle from './throttle';
import throttle from './utils/throttle';
import global from './shims/global';
// Define whether the MutationObserver is supported.
const mutationsSupported = typeof window.MutationObserver === 'function';
const mutationsSupported = typeof global.MutationObserver === 'function';

@@ -6,0 +7,0 @@ /**

@@ -9,11 +9,12 @@ /**

*/
import global from './global';
/* eslint-disable require-jsdoc */
const hasNativeCollections =
typeof window.WeakMap === 'function' &&
typeof window.Map === 'function';
typeof global.WeakMap === 'function' &&
typeof global.Map === 'function';
const WeakMap = (() => {
if (hasNativeCollections) {
return window.WeakMap;
return global.WeakMap;
}

@@ -75,3 +76,3 @@

if (hasNativeCollections) {
return window.Map;
return global.Map;
}

@@ -78,0 +79,0 @@

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

import global from './global';
/**

@@ -8,4 +10,4 @@ * A shim for requestAnimationFrame which falls back

export default (() => {
if (typeof window.requestAnimationFrame === 'function') {
return window.requestAnimationFrame;
if (typeof global.requestAnimationFrame === 'function') {
return global.requestAnimationFrame;
}

@@ -12,0 +14,0 @@

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