Socket
Socket
Sign inDemoInstall

canvas-size

Package Overview
Dependencies
0
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.2.4 to 1.2.5

8

CHANGELOG.md
# Change Log
## 1.2.5
*2021-09-04*
- Update badges in documentation
- Update browser test results (#14)
- Replace Travis CI with GitHub CI
## 1.2.4

@@ -4,0 +12,0 @@

46

dist/canvas-size.esm.js
/*!
* canvas-size
* v1.2.4
* v1.2.5
* https://github.com/jhildenbiddle/canvas-size

@@ -8,16 +8,2 @@ * (c) 2015-2021 John Hildenbiddle <http://hildenbiddle.com>

*/
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {

@@ -27,5 +13,7 @@ var keys = Object.keys(object);

var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter((function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
}));
if (enumerableOnly) {
symbols = symbols.filter((function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
}));
}
keys.push.apply(keys, symbols);

@@ -54,2 +42,16 @@ }

function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectWithoutPropertiesLoose(source, excluded) {

@@ -105,3 +107,3 @@ if (source == null) return {};

function _iterableToArrayLimit(arr, i) {
var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]);
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;

@@ -207,2 +209,4 @@ var _arr = [];

var _excluded = [ "onError", "onSuccess" ];
var defaults = {

@@ -250,3 +254,3 @@ max: null,

var jobID = Date.now();
var _onError = settings.onError, _onSuccess = settings.onSuccess, settingsWithoutCallbacks = _objectWithoutProperties(settings, [ "onError", "onSuccess" ]);
var _onError = settings.onError, _onSuccess = settings.onSuccess, settingsWithoutCallbacks = _objectWithoutProperties(settings, _excluded);
var worker = null;

@@ -381,3 +385,3 @@ if (!hasCanvasSupport) {

export default canvasSize;
export { canvasSize as default };
//# sourceMappingURL=canvas-size.esm.js.map
/*!
* canvas-size
* v1.2.4
* v1.2.5
* https://github.com/jhildenbiddle/canvas-size

@@ -8,3 +8,3 @@ * (c) 2015-2021 John Hildenbiddle <http://hildenbiddle.com>

*/
function e(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function t(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function r(r){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?t(Object(o),!0).forEach((function(t){e(r,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))}))}return r}function n(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null==r)return;var n,o,i=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){s=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw o}}return i}(e,t)||a(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||a(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function c(e){var t,r,n=e.sizes.shift(),o=Math.max(Math.ceil(n[0]),1),i=Math.max(Math.ceil(n[1]),1),a=[o-1,i-1,1,1],s=Date.now(),u="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope;u?(t=new OffscreenCanvas(1,1),r=new OffscreenCanvas(o,i)):((t=document.createElement("canvas")).width=1,t.height=1,(r=document.createElement("canvas")).width=o,r.height=i);var l=t.getContext("2d"),f=r.getContext("2d");f&&(f.fillRect.apply(f,a),l.drawImage(r,o-1,i-1,1,1,0,0,1,1));var h=l&&0!==l.getImageData(0,0,1,1).data[3],p=Date.now()-s;return u?(postMessage({width:o,height:i,benchmark:p,isTestPass:h}),!h&&e.sizes.length&&c(e)):h?e.onSuccess(o,i,p):(e.onError(o,i,p),e.sizes.length&&c(e)),h}var u=[16384,14188,11402,11180,10836,8192,4096,1],l=[8388607,65535,32767,16384,8192,4096,1],f=[4194303,65535,32767,16384,8192,4096,1],h={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},p={};function m(e){var t=e.width===e.height,r=1===e.height,n=1===e.width,o=[];if(e.width&&e.height)for(var i=e.min||h.min,a=e.step||h.step,s=Math.max(e.width,e.height);s>=i;){var c=t||r?s:1,u=t||n?s:1;o.push([c,u]),s-=a}else e.sizes.forEach((function(e){var i=t||r?e:1,a=t||n?e:1;o.push([i,a])}));return o}function d(e){var t=window&&"HTMLCanvasElement"in window,i=window&&"OffscreenCanvas"in window,a=Date.now(),s=e.onError,u=e.onSuccess,l=n(e,["onError","onSuccess"]),f=null;if(!t)return!1;if(e.useWorker&&i){var h="\n var canvasTest = ".concat(c.toString(),";\n onmessage = function(e) {\n canvasTest(e.data);\n };\n "),m=new Blob([h],{type:"application/javascript"}),d=URL.createObjectURL(m);f=new Worker(d),URL.revokeObjectURL(d),f.onmessage=function(e){var t=e.data,r=t.width,n=t.height,o=t.benchmark;t.isTestPass?(p[a].onSuccess(r,n,o),delete p[a]):p[a].onError(r,n,o)}}return e.usePromise?new Promise((function(t,n){var i=r(r({},e),{},{onError:function(t,r,i){var a;if(0===e.sizes.length)a=!0;else{var c=o(e.sizes.slice(-1),1),u=o(c[0],2),l=u[0],f=u[1];a=t===l&&r===f}s(t,r,i),a&&n({width:t,height:r,benchmark:i})},onSuccess:function(e,r,n){u(e,r,n),t({width:e,height:r,benchmark:n})}});if(f){var h=i.onError,m=i.onSuccess;p[a]={onError:h,onSuccess:m},f.postMessage(l)}else c(i)})):f?(p[a]={onError:s,onSuccess:u},void f.postMessage(l)):c(e)}var v={maxArea:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=m({width:e.max,height:e.max,min:e.min,step:e.step,sizes:i(u)}),n=r(r(r({},h),e),{},{sizes:t});return d(n)},maxHeight:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=m({width:1,height:e.max,min:e.min,step:e.step,sizes:i(l)}),n=r(r(r({},h),e),{},{sizes:t});return d(n)},maxWidth:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=m({width:e.max,height:1,min:e.min,step:e.step,sizes:i(f)}),n=r(r(r({},h),e),{},{sizes:t});return d(n)},test:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=r(r({},h),e);return t.sizes=i(t.sizes),t.width&&t.height&&(t.sizes=[[t.width,t.height]]),d(t)}};export default v;
function e(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function t(t){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?e(Object(o),!0).forEach((function(e){r(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function n(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==r)return;var n,o,i=[],a=!0,s=!1;try{for(r=r.call(e);!(a=(n=r.next()).done)&&(i.push(n.value),!t||i.length!==t);a=!0);}catch(e){s=!0,o=e}finally{try{a||null==r.return||r.return()}finally{if(s)throw o}}return i}(e,t)||a(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||a(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,t):void 0}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function c(e){var t,r,n=e.sizes.shift(),o=Math.max(Math.ceil(n[0]),1),i=Math.max(Math.ceil(n[1]),1),a=[o-1,i-1,1,1],s=Date.now(),u="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope;u?(t=new OffscreenCanvas(1,1),r=new OffscreenCanvas(o,i)):((t=document.createElement("canvas")).width=1,t.height=1,(r=document.createElement("canvas")).width=o,r.height=i);var l=t.getContext("2d"),f=r.getContext("2d");f&&(f.fillRect.apply(f,a),l.drawImage(r,o-1,i-1,1,1,0,0,1,1));var h=l&&0!==l.getImageData(0,0,1,1).data[3],p=Date.now()-s;return u?(postMessage({width:o,height:i,benchmark:p,isTestPass:h}),!h&&e.sizes.length&&c(e)):h?e.onSuccess(o,i,p):(e.onError(o,i,p),e.sizes.length&&c(e)),h}var u=[16384,14188,11402,11180,10836,8192,4096,1],l=[8388607,65535,32767,16384,8192,4096,1],f=[4194303,65535,32767,16384,8192,4096,1],h=["onError","onSuccess"],p={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},m={};function d(e){var t=e.width===e.height,r=1===e.height,n=1===e.width,o=[];if(e.width&&e.height)for(var i=e.min||p.min,a=e.step||p.step,s=Math.max(e.width,e.height);s>=i;){var c=t||r?s:1,u=t||n?s:1;o.push([c,u]),s-=a}else e.sizes.forEach((function(e){var i=t||r?e:1,a=t||n?e:1;o.push([i,a])}));return o}function v(e){var r=window&&"HTMLCanvasElement"in window,i=window&&"OffscreenCanvas"in window,a=Date.now(),s=e.onError,u=e.onSuccess,l=n(e,h),f=null;if(!r)return!1;if(e.useWorker&&i){var p="\n var canvasTest = ".concat(c.toString(),";\n onmessage = function(e) {\n canvasTest(e.data);\n };\n "),d=new Blob([p],{type:"application/javascript"}),v=URL.createObjectURL(d);f=new Worker(v),URL.revokeObjectURL(v),f.onmessage=function(e){var t=e.data,r=t.width,n=t.height,o=t.benchmark;t.isTestPass?(m[a].onSuccess(r,n,o),delete m[a]):m[a].onError(r,n,o)}}return e.usePromise?new Promise((function(r,n){var i=t(t({},e),{},{onError:function(t,r,i){var a;if(0===e.sizes.length)a=!0;else{var c=o(e.sizes.slice(-1),1),u=o(c[0],2),l=u[0],f=u[1];a=t===l&&r===f}s(t,r,i),a&&n({width:t,height:r,benchmark:i})},onSuccess:function(e,t,n){u(e,t,n),r({width:e,height:t,benchmark:n})}});if(f){var h=i.onError,p=i.onSuccess;m[a]={onError:h,onSuccess:p},f.postMessage(l)}else c(i)})):f?(m[a]={onError:s,onSuccess:u},void f.postMessage(l)):c(e)}var g={maxArea:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=d({width:e.max,height:e.max,min:e.min,step:e.step,sizes:i(u)}),n=t(t(t({},p),e),{},{sizes:r});return v(n)},maxHeight:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=d({width:1,height:e.max,min:e.min,step:e.step,sizes:i(l)}),n=t(t(t({},p),e),{},{sizes:r});return v(n)},maxWidth:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=d({width:e.max,height:1,min:e.min,step:e.step,sizes:i(f)}),n=t(t(t({},p),e),{},{sizes:r});return v(n)},test:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=t(t({},p),e);return r.sizes=i(r.sizes),r.width&&r.height&&(r.sizes=[[r.width,r.height]]),v(r)}};export{g as default};
//# sourceMappingURL=canvas-size.esm.min.js.map
/*!
* canvas-size
* v1.2.4
* v1.2.5
* https://github.com/jhildenbiddle/canvas-size

@@ -13,15 +13,2 @@ * (c) 2015-2021 John Hildenbiddle <http://hildenbiddle.com>

"use strict";
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {

@@ -31,5 +18,7 @@ var keys = Object.keys(object);

var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter((function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
}));
if (enumerableOnly) {
symbols = symbols.filter((function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
}));
}
keys.push.apply(keys, symbols);

@@ -56,2 +45,15 @@ }

}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _objectWithoutPropertiesLoose(source, excluded) {

@@ -100,3 +102,3 @@ if (source == null) return {};

function _iterableToArrayLimit(arr, i) {
var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]);
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;

@@ -195,2 +197,3 @@ var _arr = [];

};
var _excluded = [ "onError", "onSuccess" ];
var defaults = {

@@ -235,3 +238,3 @@ max: null,

var jobID = Date.now();
var _onError = settings.onError, _onSuccess = settings.onSuccess, settingsWithoutCallbacks = _objectWithoutProperties(settings, [ "onError", "onSuccess" ]);
var _onError = settings.onError, _onSuccess = settings.onSuccess, settingsWithoutCallbacks = _objectWithoutProperties(settings, _excluded);
var worker = null;

@@ -238,0 +241,0 @@ if (!hasCanvasSupport) {

/*!
* canvas-size
* v1.2.4
* v1.2.5
* https://github.com/jhildenbiddle/canvas-size

@@ -8,3 +8,3 @@ * (c) 2015-2021 John Hildenbiddle <http://hildenbiddle.com>

*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).canvasSize=t()}(this,(function(){"use strict";function e(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function t(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function n(n){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?t(Object(o),!0).forEach((function(t){e(n,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach((function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(o,e))}))}return n}function r(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=e&&("undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"]);if(null==n)return;var r,o,i=[],a=!0,s=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){s=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(s)throw o}}return i}(e,t)||a(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||a(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){if(e){if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function c(e){var t,n,r=e.sizes.shift(),o=Math.max(Math.ceil(r[0]),1),i=Math.max(Math.ceil(r[1]),1),a=[o-1,i-1,1,1],s=Date.now(),u="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope;u?(t=new OffscreenCanvas(1,1),n=new OffscreenCanvas(o,i)):((t=document.createElement("canvas")).width=1,t.height=1,(n=document.createElement("canvas")).width=o,n.height=i);var f=t.getContext("2d"),l=n.getContext("2d");l&&(l.fillRect.apply(l,a),f.drawImage(n,o-1,i-1,1,1,0,0,1,1));var h=f&&0!==f.getImageData(0,0,1,1).data[3],p=Date.now()-s;return u?(postMessage({width:o,height:i,benchmark:p,isTestPass:h}),!h&&e.sizes.length&&c(e)):h?e.onSuccess(o,i,p):(e.onError(o,i,p),e.sizes.length&&c(e)),h}var u=[16384,14188,11402,11180,10836,8192,4096,1],f=[8388607,65535,32767,16384,8192,4096,1],l=[4194303,65535,32767,16384,8192,4096,1],h={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},p={};function d(e){var t=e.width===e.height,n=1===e.height,r=1===e.width,o=[];if(e.width&&e.height)for(var i=e.min||h.min,a=e.step||h.step,s=Math.max(e.width,e.height);s>=i;){var c=t||n?s:1,u=t||r?s:1;o.push([c,u]),s-=a}else e.sizes.forEach((function(e){var i=t||n?e:1,a=t||r?e:1;o.push([i,a])}));return o}function m(e){var t=window&&"HTMLCanvasElement"in window,i=window&&"OffscreenCanvas"in window,a=Date.now(),s=e.onError,u=e.onSuccess,f=r(e,["onError","onSuccess"]),l=null;if(!t)return!1;if(e.useWorker&&i){var h="\n var canvasTest = ".concat(c.toString(),";\n onmessage = function(e) {\n canvasTest(e.data);\n };\n "),d=new Blob([h],{type:"application/javascript"}),m=URL.createObjectURL(d);l=new Worker(m),URL.revokeObjectURL(m),l.onmessage=function(e){var t=e.data,n=t.width,r=t.height,o=t.benchmark;t.isTestPass?(p[a].onSuccess(n,r,o),delete p[a]):p[a].onError(n,r,o)}}return e.usePromise?new Promise((function(t,r){var i=n(n({},e),{},{onError:function(t,n,i){var a;if(0===e.sizes.length)a=!0;else{var c=o(e.sizes.slice(-1),1),u=o(c[0],2),f=u[0],l=u[1];a=t===f&&n===l}s(t,n,i),a&&r({width:t,height:n,benchmark:i})},onSuccess:function(e,n,r){u(e,n,r),t({width:e,height:n,benchmark:r})}});if(l){var h=i.onError,d=i.onSuccess;p[a]={onError:h,onSuccess:d},l.postMessage(f)}else c(i)})):l?(p[a]={onError:s,onSuccess:u},void l.postMessage(f)):c(e)}return{maxArea:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=d({width:e.max,height:e.max,min:e.min,step:e.step,sizes:i(u)}),r=n(n(n({},h),e),{},{sizes:t});return m(r)},maxHeight:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=d({width:1,height:e.max,min:e.min,step:e.step,sizes:i(f)}),r=n(n(n({},h),e),{},{sizes:t});return m(r)},maxWidth:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=d({width:e.max,height:1,min:e.min,step:e.step,sizes:i(l)}),r=n(n(n({},h),e),{},{sizes:t});return m(r)},test:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=n(n({},h),e);return t.sizes=i(t.sizes),t.width&&t.height&&(t.sizes=[[t.width,t.height]]),m(t)}}}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).canvasSize=t()}(this,(function(){"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function t(t){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?e(Object(o),!0).forEach((function(e){n(t,e,o[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):e(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}function n(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function r(e,t){if(null==e)return{};var n,r,o=function(e,t){if(null==e)return{};var n,r,o={},i=Object.keys(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,o,i=[],a=!0,s=!1;try{for(n=n.call(e);!(a=(r=n.next()).done)&&(i.push(r.value),!t||i.length!==t);a=!0);}catch(e){s=!0,o=e}finally{try{a||null==n.return||n.return()}finally{if(s)throw o}}return i}(e,t)||a(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e){return function(e){if(Array.isArray(e))return s(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||a(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){if(e){if("string"==typeof e)return s(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?s(e,t):void 0}}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function c(e){var t,n,r=e.sizes.shift(),o=Math.max(Math.ceil(r[0]),1),i=Math.max(Math.ceil(r[1]),1),a=[o-1,i-1,1,1],s=Date.now(),u="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope;u?(t=new OffscreenCanvas(1,1),n=new OffscreenCanvas(o,i)):((t=document.createElement("canvas")).width=1,t.height=1,(n=document.createElement("canvas")).width=o,n.height=i);var l=t.getContext("2d"),f=n.getContext("2d");f&&(f.fillRect.apply(f,a),l.drawImage(n,o-1,i-1,1,1,0,0,1,1));var h=l&&0!==l.getImageData(0,0,1,1).data[3],p=Date.now()-s;return u?(postMessage({width:o,height:i,benchmark:p,isTestPass:h}),!h&&e.sizes.length&&c(e)):h?e.onSuccess(o,i,p):(e.onError(o,i,p),e.sizes.length&&c(e)),h}var u=[16384,14188,11402,11180,10836,8192,4096,1],l=[8388607,65535,32767,16384,8192,4096,1],f=[4194303,65535,32767,16384,8192,4096,1],h=["onError","onSuccess"],p={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},d={};function m(e){var t=e.width===e.height,n=1===e.height,r=1===e.width,o=[];if(e.width&&e.height)for(var i=e.min||p.min,a=e.step||p.step,s=Math.max(e.width,e.height);s>=i;){var c=t||n?s:1,u=t||r?s:1;o.push([c,u]),s-=a}else e.sizes.forEach((function(e){var i=t||n?e:1,a=t||r?e:1;o.push([i,a])}));return o}function g(e){var n=window&&"HTMLCanvasElement"in window,i=window&&"OffscreenCanvas"in window,a=Date.now(),s=e.onError,u=e.onSuccess,l=r(e,h),f=null;if(!n)return!1;if(e.useWorker&&i){var p="\n var canvasTest = ".concat(c.toString(),";\n onmessage = function(e) {\n canvasTest(e.data);\n };\n "),m=new Blob([p],{type:"application/javascript"}),g=URL.createObjectURL(m);f=new Worker(g),URL.revokeObjectURL(g),f.onmessage=function(e){var t=e.data,n=t.width,r=t.height,o=t.benchmark;t.isTestPass?(d[a].onSuccess(n,r,o),delete d[a]):d[a].onError(n,r,o)}}return e.usePromise?new Promise((function(n,r){var i=t(t({},e),{},{onError:function(t,n,i){var a;if(0===e.sizes.length)a=!0;else{var c=o(e.sizes.slice(-1),1),u=o(c[0],2),l=u[0],f=u[1];a=t===l&&n===f}s(t,n,i),a&&r({width:t,height:n,benchmark:i})},onSuccess:function(e,t,r){u(e,t,r),n({width:e,height:t,benchmark:r})}});if(f){var h=i.onError,p=i.onSuccess;d[a]={onError:h,onSuccess:p},f.postMessage(l)}else c(i)})):f?(d[a]={onError:s,onSuccess:u},void f.postMessage(l)):c(e)}return{maxArea:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=m({width:e.max,height:e.max,min:e.min,step:e.step,sizes:i(u)}),r=t(t(t({},p),e),{},{sizes:n});return g(r)},maxHeight:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=m({width:1,height:e.max,min:e.min,step:e.step,sizes:i(l)}),r=t(t(t({},p),e),{},{sizes:n});return g(r)},maxWidth:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=m({width:e.max,height:1,min:e.min,step:e.step,sizes:i(f)}),r=t(t(t({},p),e),{},{sizes:n});return g(r)},test:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t(t({},p),e);return n.sizes=i(n.sizes),n.width&&n.height&&(n.sizes=[[n.width,n.height]]),g(n)}}}));
//# sourceMappingURL=canvas-size.min.js.map
{
"name": "canvas-size",
"version": "1.2.4",
"description": "Determine the maximum size of an HTML canvas element and test support for custom canvas dimensions.",
"version": "1.2.5",
"description": "Determine the maximum size and custom dimension support of an HTML `<canvas>` element.",
"author": "John Hildenbiddle <http://hildenbiddle.com>",

@@ -43,4 +43,5 @@ "license": "MIT",

"dev": "npm start | npm run test-watch",
"lint": "eslint . && markdownlint . --ignore node_modules",
"start": "rimraf coverage/* && npm run build -- --watch",
"test": "rimraf coverage/* && karma start",
"test": "rimraf coverage/* && npm run lint && karma start",
"test-watch": "npm test -- --auto-watch --no-single-run",

@@ -54,2 +55,6 @@ "test-remote": "npm test -- --remote",

"@babel/preset-env": "^7.12.11",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.4",
"babel-loader": "^8.2.2",

@@ -60,5 +65,5 @@ "babel-plugin-istanbul": "^6.0.0",

"eslint-plugin-chai-expect": "^2.2.0",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-mocha": "^9.0.0",
"git-repo-info": "^2.1.1",
"karma": "^5.2.3",
"karma": "^6.3.4",
"karma-browserstack-launcher": "^1.6.0",

@@ -74,10 +79,7 @@ "karma-chai": "^0.1.0",

"lodash.merge": "^4.6.2",
"mocha": "^8.2.1",
"markdownlint-cli": "^0.28.1",
"mocha": "^9.1.1",
"rimraf": "^3.0.2",
"rollup": "^2.38.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-eslint": "^7.0.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^7.0.2",

@@ -84,0 +86,0 @@ "webpack": "^4.46.0"

# canvas-size
[![NPM](https://img.shields.io/npm/v/canvas-size.svg?style=flat-square)](https://www.npmjs.com/package/canvas-size)
[![Build Status](https://img.shields.io/travis/jhildenbiddle/canvas-size/master.svg?style=flat-square)](https://travis-ci.org/jhildenbiddle/canvas-size)
[![Codacy](https://img.shields.io/codacy/grade/d5203341ed494f6c9b877d93e0daf458.svg?style=flat-square)](https://www.codacy.com/app/jhildenbiddle/canvas-size?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=jhildenbiddle/canvas-size&amp;utm_campaign=Badge_Grade)
[![GitHub Workflow Status (master)](https://img.shields.io/github/workflow/status/jhildenbiddle/canvas-size/Build%20&%20Test/master?label=checks&style=flat-square)](https://github.com/jhildenbiddle/canvas-size/actions?query=branch%3Amaster+)
[![Codacy grade](https://img.shields.io/codacy/grade/c39af90445e7478d80fd796d12947495?style=flat-square)](https://app.codacy.com/gh/jhildenbiddle/canvas-size/dashboard?branch=master)
[![Codecov](https://img.shields.io/codecov/c/github/jhildenbiddle/canvas-size.svg?style=flat-square)](https://codecov.io/gh/jhildenbiddle/canvas-size)

@@ -11,7 +11,14 @@ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://github.com/jhildenbiddle/canvas-size/blob/master/LICENSE)

Determine the maximum size of an HTML canvas element and test support for custom canvas dimensions.
Determine the maximum size and custom dimension support of an HTML `<canvas>` element.
- [Demo](https://on690.codesandbox.io) for modern browsers (CodeSandbox)
- [Demo](https://jsbin.com/megedep/1/edit?js,output) for legacy browsers (JSBin)
- [Demo (Codesandbox)](https://on690.codesandbox.io): For modern browsers (ES6+)
- [Demo (JSBin)](https://jsbin.com/megedep/1): For legacy browsers (ES5)
- [Test Results](#test-results): HTML `<canvas>` test results for various platforms and browsers
## Why?
The [HTML canvas](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas) element is [widely supported](http://caniuse.com/#feat=canvas) by modern and legacy browsers, but each browser and platform combination imposes [unique size limitations](#test-results) that will render a canvas unusable when exceeded. Unfortunately, browsers do not provide a way to determine what their limitations are, nor do they provide any kind of feedback after an unusable canvas has been created. This makes working with large canvas elements a challenge, especially for applications that support a variety of browsers and platforms.
This micro-library provides the maximum area, height, and width of an HTML canvas element supported by the browser as well as the ability to test custom canvas dimensions. By collecting this information *before* a new canvas element is created, applications are able to reliably set canvas dimensions within the size limitations of each browser/platform.
## Features

@@ -32,21 +39,2 @@

------
- [Description](#description)
- [Installation](#installation)
- [Usage](#usage)
- [Methods](#methods)
- [Test Results](#test-results)
- [Known Issues](#known-issues)
- [Contact](#contact)
- [License](#license)
------
## Description
The [HTML canvas](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas) element is [widely supported](http://caniuse.com/#feat=canvas) by modern and legacy browsers, but each browser and platform combination imposes [unique size limitations](#test-results) that will render a canvas unusable when exceeded. Unfortunately, browsers do not provide a way to determine what their limitations are, nor do they provide any kind of feedback after an unusable canvas has been created. This makes working with large canvas elements a challenge, especially for applications that support a variety of browsers and platforms.
This micro-library provides the maximum area, height, and width of an HTML canvas element supported by the browser as well as the ability to test custom canvas dimensions. By collecting this information *before* a new canvas element is created, applications are able to reliably set canvas dimensions within the size limitations of each browser/platform.
## Installation

@@ -60,6 +48,8 @@

Git:
```js
import canvasSize from 'canvas-size';
```bash
git clone https://github.com/jhildenbiddle/canvas-size.git
canvasSize.maxArea({
// ...
});
```

@@ -79,3 +69,5 @@

// Do stuff...
canvasSize.maxArea({
// ...
});
</script>

@@ -185,8 +177,4 @@ ```

### maxArea()
### maxArea(), maxHeight(), maxWidth()
### maxHeight()
### maxWidth()
Determines the maximum area/height/width of an HTML canvas element on the client.

@@ -259,2 +247,11 @@

});
// Same options for maxHeight() and maxWidth()
canvasSize.maxHeight({
// ...
});
canvasSize.maxWidth({
// ...
});
```

@@ -291,2 +288,11 @@

});
// Same options for maxHeight() and maxWidth()
canvasSize.maxHeight({
// ...
});
canvasSize.maxWidth({
// ...
});
```

@@ -385,28 +391,33 @@

Tests conducted using [BrowserStack](https://www.browserstack.com/) virtualized device are denoted with an asterisk (`*`). Results from these tests may vary from actual hardware.
Tests were conducted using virtualized device courtesy of [BrowserStack](https://www.browserstack.com/). Results may vary on actual hardware.
### Desktop
| Browser (OS) | Max Width | Max Height | Max Area (Total) |
| ----------------------- | --------: | ---------: | ----------------------------: |
| Chrome 83 (Mac, Win *) | 65,535 | 65,535 | 16,384 x 16,384 (268,435,456) |
| Chrome 70 (Mac, Win *) | 32,767 | 32,767 | 16,384 x 16,384 (268,435,456) |
| Edge 17 * | 16,384 | 16,384 | 16,384 x 16,384 (268,435,456) |
| Firefox 63 (Mac, Win *) | 32,767 | 32,767 | 11,180 x 11,180 (124,992,400) |
| IE 11 * | 16,384 | 16,384 | 8,192 x 8,192 (67,108,864) |
| IE 9 - 10 * | 8,192 | 8,192 | 8,192 x 8,192 (67,108,864) |
| Safari 7 - 12 | 4,194,303 | 8,388,607 | 16,384 x 16,384 (268,435,456) |
| Browser (OS) | Max Width | Max Height | Max Area (Total) |
| ------------------------ | --------: | ---------: | ----------------------------: |
| Chrome >= 73 (Mac, Win) | 65,535 | 65,535 | 16,384 x 16,384 (268,435,456) |
| Chrome <= 72 (Mac, Win) | 32,767 | 32,767 | 16,384 x 16,384 (268,435,456) |
| Edge >= 80 (Mac, Win) | 65,535 | 65,535 | 16,384 x 16,384 (268,435,456) |
| Edge <= 18 (Win) | 16,384 | 16,384 | 16,384 x 16,384 (268,435,456) |
| Firefox >= 60 (Mac, Win) | 32,767 | 32,767 | 11,180 x 11,180 (124,992,400) |
| IE 11 (Win) | 16,384 | 16,384 | 8,192 x 8,192 (67,108,864) |
| IE 9 - 10 (Win) | 8,192 | 8,192 | 8,192 x 8,192 (67,108,864) |
| Safari >= 5 (Mac) | 4,194,303 | 8,388,607 | 16,384 x 16,384 (268,435,456) |
### Mobile
| Browser (OS) | Max Width | Max Height | Max Area (Total) |
| ----------------------------- | --------: | ---------: | ----------------------------: |
| Chrome 68 (Android 9) * | 32,767 | 32,767 | 14,188 x 14,188 (201,299,344) |
| Chrome 68 (Android 7.1 - 8) * | 32,767 | 32,767 | 14,188 x 14,188 (201,299,344) |
| Chrome 68 (Android 6) | 32,767 | 32,767 | 10,836 x 10,836 (117,418,896) |
| Chrome 68 (Android 5) * | 32,767 | 32,767 | 11,402 x 11,402 (130,005,604) |
| Chrome 68 (Android 4.4) * | 32,767 | 32,767 | 16,384 x 16,384 (268,435,456) |
| IE (Windows Phone 8.x) | 4,096 | 4,096 | 4,096 x 4,096 (16,777,216) |
| Safari (iOS 9 - 12) | 4,194,303 | 8,388,607 | 4,096 x 4,096 (16,777,216) |
Be aware that test results can vary between mobile devices running the same platform/browser combination, most notably on older devices with less capable hardware.
| Browser (OS) | Max Width | Max Height | Max Area (Total) |
| --------------------------- | --------: | ---------: | ----------------------------: |
| Chrome 91 (Android 8 - 11) | 65,535 | 65,535 | 16,384 x 16,384 (268,435,456) |
| Chrome 91 (Android 7) | 65,535 | 65,535 | 14,188 x 14,188 (201,299,344) |
| Chrome 91 (Android 6) | 65,535 | 65,535 | 16,384 x 16,384 (268,435,456) |
| Chrome 91 (Android 5) | 65,535 | 65,535 | 11,180 x 11,180 (124,992,400) |
| Chrome 68 (Android 7.1 - 9) | 32,767 | 32,767 | 14,188 x 14,188 (201,299,344) |
| Chrome 68 (Android 6) | 32,767 | 32,767 | 10,836 x 10,836 (117,418,896) |
| Chrome 68 (Android 5) | 32,767 | 32,767 | 11,402 x 11,402 (130,005,604) |
| IE (Windows Phone 8.x) | 4,096 | 4,096 | 4,096 x 4,096 (16,777,216) |
| Safari (iOS >= 9) | 4,194,303 | 8,388,607 | 4,096 x 4,096 (16,777,216) |
## Known Issues

@@ -413,0 +424,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc