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

icojs

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

icojs - npm Package Compare versions

Comparing version 0.18.0 to 0.19.0

types/index.d.ts

4

dist/ico.js
/*!
* icojs v0.18.0
* icojs v0.19.0
* (c) egy186
* https://github.com/egy186/icojs/blob/main/LICENSE
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self,function(){var r=t.ICO,n=t.ICO=e();n.noConflict=function(){return t.ICO=r,n}}())}(this,(function(){"use strict";function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var e="image/png",r=e,n={decode:function(t){return new Promise((function(e){var r=URL.createObjectURL(new Blob([t])),n=document.createElement("img");n.src=r,n.onload=function(){var t=n.naturalHeight,r=n.naturalWidth,i=document.createElement("canvas");i.width=r,i.height=t;var o=i.getContext("2d");o.drawImage(n,0,0);var a=o.getImageData(0,0,r,t).data;e({data:a,height:t,width:r})}}))},encode:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:r;return new Promise((function(r){var n=t.data,i=t.height,o=t.width,a=document.createElement("canvas");a.width=o,a.height=i;for(var f=a.getContext("2d"),u=f.createImageData(o,i),h=u.data,c=0;c<h.length;c++)h[c]=n[c];f.putImageData(u,0,0),r(function(t){for(var e=atob(t.replace(/(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+,/,"")),r=new Uint8Array(e.length),n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r.buffer}(a.toDataURL(e)))}))}},i=n,o=function(t){if(t instanceof Int8Array||t instanceof Uint8Array||t instanceof Uint8ClampedArray)return new DataView(t.buffer,t.byteOffset,t.byteLength);if(t instanceof ArrayBuffer)return new DataView(t);throw new TypeError("Expected `data` to be an ArrayBuffer, Buffer, Int8Array, Uint8Array or Uint8ClampedArray")},a=o,f=function(t){var e=a(t);return 0===e.getUint16(0,!0)&&1===e.getUint16(2,!0)};function u(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function h(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?u(Object(r),!0).forEach((function(e){d(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}function s(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function g(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,p(n.key),n)}}function l(t,e,r){return e&&g(t.prototype,e),r&&g(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function d(t,e,r){return(e=p(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function p(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}var y=new WeakMap,b=new WeakMap,w=l((function t(e,r){for(var n=arguments.length,i=new Array(n>2?n-2:0),o=2;o<n;o++)i[o-2]=arguments[o];if(s(this,t),arguments.length<2)throw new TypeError("Failed to construct 'ImageData': 2 arguments required, but only ".concat(arguments.length," present."));if("object"===c(e)){if(!(e instanceof Uint8ClampedArray))throw new TypeError("Failed to construct 'ImageData': parameter 1 is not of type 'Uint8ClampedArray'.");if("number"!=typeof r||0===r)throw new Error("Failed to construct 'ImageData': The source width is zero or not a number.");if(4*(r>>>=0)>e.length)throw new Error("Failed to construct 'ImageData': The requested image size exceeds the supported range.");if(e.length%4!=0)throw new Error("Failed to construct 'ImageData': The input data length is not a multiple of 4.");if(e.length%(4*r)!=0)throw new Error("Failed to construct 'ImageData': The input data length is not a multiple of (4 * width).");if(void 0!==i[0]){if("number"!=typeof i[0]||0===i[0])throw new Error("Failed to construct 'ImageData': The source height is zero or not a number.");if(i[0]=i[0]>>>0,e.length%(4*r*i[0])!=0)throw new Error("Failed to construct 'ImageData': The input data length is not equal to (4 * width * height).")}y.set(this,r),b.set(this,void 0!==i[0]?i[0]:e.byteLength/r/4),Object.defineProperty(this,"data",{configurable:!0,enumerable:!0,value:e,writable:!1})}else{if("number"!=typeof e||0===e)throw new Error("Failed to construct 'ImageData': The source width is zero or not a number.");if(e>>>=0,"number"!=typeof r||0===r)throw new Error("Failed to construct 'ImageData': The source height is zero or not a number.");if(e*(r>>>=0)>=1<<30)throw new Error("Failed to construct 'ImageData': The requested image size exceeds the supported range.");y.set(this,e),b.set(this,r),Object.defineProperty(this,"data",{configurable:!0,enumerable:!0,value:new Uint8ClampedArray(e*r*4),writable:!1})}}));Object.defineProperty(w.prototype,"width",{enumerable:!0,configurable:!0,get:function(){return y.get(this)}}),Object.defineProperty(w.prototype,"height",{enumerable:!0,configurable:!0,get:function(){return b.get(this)}});var m=w,v=o,U=m;var D=function(){function t(e,r,n){var i,o,a=n.width,f=n.height,u=n.colorDepth,h=n.format;if(s(this,t),this.format=h,this.offset=r,this.depth=u,this.stride=(i=a*this.depth/8,(o=i%4)?i+4-o:i),this.size=this.stride*f,this.data=e.slice(this.offset,this.offset+this.size),this.size!==this.data.byteLength)throw new Error("Truncated bitmap data")}return l(t,[{key:"get",value:function(t,e,r){var n=this.format.indexOf(r);return 1===this.depth?(this.data[e*this.stride+(t/8|0)]&1<<7-t%8*1)>>7-t%8*1:2===this.depth?(this.data[e*this.stride+(t/4|0)]&3<<6-t%4*2)>>>6-t%4*2:4===this.depth?(this.data[e*this.stride+(t/2|0)]&15<<4-t%2*4)>>>4-t%2*4:this.data[e*this.stride+t*(this.depth/8)+n]}}]),t}();var O=o,A=function(t){var e,r,n,i,o,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},f=a.width,u=void 0===f?0:f,h=a.height,c=void 0===h?0:h,s=a.icon,g=void 0!==s&&s,l=v(t);g?(e=l.getUint32(0,!0),r=l.getUint32(4,!0)/1|0,n=l.getUint32(8,!0)/2|0,i=l.getUint16(14,!0),o=l.getUint32(32,!0)):(!function(t){if(19778!==t)throw new Error("Invalid magic byte 0x".concat(t.toString(16)))}(l.getUint16(0,!0)),e=14+l.getUint32(14,!0),r=l.getUint32(18,!0),n=l.getUint32(22,!0),i=l.getUint16(28,!0),o=l.getUint32(46,!0)),0===o&&i<=8&&(o=1<<i);var d=0===r?u:r,p=0===n?c:n,y=new Uint8Array(l.buffer,l.byteOffset+e,l.byteLength-e),b=o?function(t,e){var r=e.width,n=e.height,i=e.colorDepth,o=e.colorCount,a=e.icon;if(8!==i&&4!==i&&2!==i&&1!==i)throw new Error("A color depth of ".concat(i," is not supported"));for(var f=new D(t,0,{width:o,height:1,colorDepth:32,format:"BGRA"}),u=new D(t,f.offset+f.size,{width:r,height:n,colorDepth:i,format:"C"}),h=a?new D(t,u.offset+u.size,{width:r,height:n,colorDepth:1,format:"A"}):null,c=new Uint8Array(r*n*4),s=0,g=0;g<n;g++)for(var l=0;l<r;l++){var d=u.get(l,n-g-1,"C");c[s++]=f.get(d,0,"R"),c[s++]=f.get(d,0,"G"),c[s++]=f.get(d,0,"B"),c[s++]=h&&h.get(l,n-g-1,"A")?0:255}return new Uint8ClampedArray(c.buffer,c.byteOffset,c.byteLength)}(y,{width:d,height:p,colorDepth:i,colorCount:o,icon:g}):function(t,e){var r=e.width,n=e.height,i=e.colorDepth,o=e.icon;if(32!==i&&24!==i)throw new Error("A color depth of ".concat(i," is not supported"));for(var a=new D(t,0,{width:r,height:n,colorDepth:i,format:"BGRA"}),f=24===i&&o?new D(t,a.offset+a.size,{width:r,height:n,colorDepth:1,format:"A"}):null,u=new Uint8Array(r*n*4),h=0,c=0;c<n;c++)for(var s=0;s<r;s++)u[h++]=a.get(s,n-c-1,"R"),u[h++]=a.get(s,n-c-1,"G"),u[h++]=a.get(s,n-c-1,"B"),u[h++]=32===i?a.get(s,n-c-1,"A"):f&&f.get(s,n-c-1,"A")?0:255;return new Uint8ClampedArray(u.buffer,u.byteOffset,u.byteLength)}(y,{width:d,height:p,colorDepth:i,icon:g});return Object.assign(new U(b,d,p),{colorDepth:i})},F=m;function E(t,e){return 2303741511===t.getUint32(e+0)&&218765834===t.getUint32(e+4)}function j(t,e){var r=t.getUint8(e+24),n=t.getUint8(e+25);if(0===n)return 1*r;if(2===n)return 3*r;if(3===n)return 1*r;if(4===n)return 2*r;if(6===n)return 4*r;throw new Error("Invalid PNG colorType")}function I(t,e){return t.getUint32(e+16,!1)}function P(t,e){return t.getUint32(e+20,!1)}function C(t,e,r){return r?e?e(t):t:(t&&t.then||(t=Promise.resolve(t)),e?t.then(e):t)}function T(t){return function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];try{return Promise.resolve(t.apply(this,e))}catch(t){return Promise.reject(t)}}}var L=function(t){var e=O(t);if(e.byteLength<6)throw new Error("Truncated header");if(E(e,0))return[{bpp:j(e,0),data:new Uint8Array(e.buffer,e.byteOffset,e.byteLength),height:P(e,0),hotspot:null,type:"png",width:I(e,0)}];if(0!==e.getUint16(0,!0))throw new Error("Invalid magic bytes");var r=e.getUint16(2,!0);if(1!==r&&2!==r)throw new Error("Invalid image type");var n=e.getUint16(4,!0);if(e.byteLength<6+16*n)throw new Error("Truncated image list");return Array.from({length:n},(function(t,n){var i=e.getUint8(6+16*n+0),o=e.getUint8(6+16*n+1),a=e.getUint32(6+16*n+8,!0),f=e.getUint32(6+16*n+12,!0),u=2!==r?null:{x:e.getUint16(6+16*n+4,!0),y:e.getUint16(6+16*n+6,!0)};if(E(e,f))return{bpp:j(e,f),data:new Uint8Array(e.buffer,e.byteOffset+f,a),height:P(e,f),hotspot:u,type:"png",width:I(e,f)};var h=new Uint8Array(e.buffer,e.byteOffset+f,a),c=A(h,{width:i,height:o,icon:!0}),s={bpp:c.colorDepth,hotspot:u,type:"bmp"};return Object.assign(new F(c.data,c.width,c.height),s)}))},x=e,z=T((function(t,e,r){var n=L(t),i=T((function(t){return e===x&&"png"===t.type?h(h({},t),{},{buffer:t.data.buffer.slice(t.data.byteOffset,t.data.byteOffset+t.data.byteLength)}):(n=function(){return C(r.encode(t,e),(function(r){return Object.assign(t,{buffer:r,type:e.replace("image/","")})}))},(i=function(){if("png"===t.type)return C(r.decode(t.data),(function(e){Object.assign(t,{data:e.data,type:"bmp"})}))}())&&i.then?i.then(n):n(i));var n,i}));return Promise.all(n.map(i))})),B=i,S=z,R=e,k={isICO:f,parse:function(t){return S(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:R,B)}};return t(k)}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):(t="undefined"!=typeof globalThis?globalThis:t||self,function(){var r=t.ICO,n=t.ICO={};e(n),n.noConflict=function(){return t.ICO=r,n}}())}(this,(function(t){"use strict";var e="image/png",r={decode:function(t){return new Promise((function(e){var r=URL.createObjectURL(new Blob([t])),n=document.createElement("img");n.src=r,n.onload=function(){var t=n.naturalHeight,r=n.naturalWidth,i=document.createElement("canvas");i.width=r,i.height=t;var o=i.getContext("2d");o.drawImage(n,0,0);var a=o.getImageData(0,0,r,t).data;e({data:a,height:t,width:r})}}))},encode:function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e;return new Promise((function(e){var n=t.data,i=t.height,o=t.width,a=document.createElement("canvas");a.width=o,a.height=i;for(var f=a.getContext("2d"),u=f.createImageData(o,i),h=u.data,c=0;c<h.length;c++)h[c]=n[c];f.putImageData(u,0,0),e(function(t){for(var e=atob(t.replace(/(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+,/,"")),r=new Uint8Array(e.length),n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r.buffer}(a.toDataURL(r)))}))}};var n=function(t){var e=function(t){if(t instanceof Int8Array||t instanceof Uint8Array||t instanceof Uint8ClampedArray)return new DataView(t.buffer,t.byteOffset,t.byteLength);if(t instanceof ArrayBuffer)return new DataView(t);throw new TypeError("Expected `data` to be an ArrayBuffer, Buffer, Int8Array, Uint8Array or Uint8ClampedArray")}(t);return 0===e.getUint16(0,!0)&&1===e.getUint16(2,!0)};function i(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function o(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?i(Object(r),!0).forEach((function(e){c(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):i(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function a(t){return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},a(t)}function f(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function u(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,s(n.key),n)}}function h(t,e,r){return e&&u(t.prototype,e),r&&u(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function c(t,e,r){return(e=s(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function s(t){var e=function(t,e){if("object"!=typeof t||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:String(e)}function d(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var g=new WeakMap,l=new WeakMap,p=h((function t(e,r){for(var n=arguments.length,i=new Array(n>2?n-2:0),o=2;o<n;o++)i[o-2]=arguments[o];if(f(this,t),arguments.length<2)throw new TypeError("Failed to construct 'ImageData': 2 arguments required, but only ".concat(arguments.length," present."));if("object"===a(e)){if(!(e instanceof Uint8ClampedArray))throw new TypeError("Failed to construct 'ImageData': parameter 1 is not of type 'Uint8ClampedArray'.");if("number"!=typeof r||0===r)throw new Error("Failed to construct 'ImageData': The source width is zero or not a number.");if(4*(r>>>=0)>e.length)throw new Error("Failed to construct 'ImageData': The requested image size exceeds the supported range.");if(e.length%4!=0)throw new Error("Failed to construct 'ImageData': The input data length is not a multiple of 4.");if(e.length%(4*r)!=0)throw new Error("Failed to construct 'ImageData': The input data length is not a multiple of (4 * width).");if(void 0!==i[0]){if("number"!=typeof i[0]||0===i[0])throw new Error("Failed to construct 'ImageData': The source height is zero or not a number.");if(i[0]=i[0]>>>0,e.length%(4*r*i[0])!=0)throw new Error("Failed to construct 'ImageData': The input data length is not equal to (4 * width * height).")}g.set(this,r),l.set(this,void 0!==i[0]?i[0]:e.byteLength/r/4),Object.defineProperty(this,"data",{configurable:!0,enumerable:!0,value:e,writable:!1})}else{if("number"!=typeof e||0===e)throw new Error("Failed to construct 'ImageData': The source width is zero or not a number.");if(e>>>=0,"number"!=typeof r||0===r)throw new Error("Failed to construct 'ImageData': The source height is zero or not a number.");if(e*(r>>>=0)>=1<<30)throw new Error("Failed to construct 'ImageData': The requested image size exceeds the supported range.");g.set(this,e),l.set(this,r),Object.defineProperty(this,"data",{configurable:!0,enumerable:!0,value:new Uint8ClampedArray(e*r*4),writable:!1})}}));Object.defineProperty(p.prototype,"width",{enumerable:!0,configurable:!0,get:function(){return g.get(this)}}),Object.defineProperty(p.prototype,"height",{enumerable:!0,configurable:!0,get:function(){return l.get(this)}});var y=p,w=function(t){if(t instanceof Int8Array||t instanceof Uint8Array||t instanceof Uint8ClampedArray)return new DataView(t.buffer,t.byteOffset,t.byteLength);if(t instanceof ArrayBuffer)return new DataView(t);throw new TypeError("Expected `data` to be an ArrayBuffer, Buffer, Int8Array, Uint8Array or Uint8ClampedArray")},b=y;var m=function(){function t(e,r,n){var i,o,a=n.width,u=n.height,h=n.colorDepth,c=n.format;if(f(this,t),this.format=c,this.offset=r,this.depth=h,this.stride=(i=a*this.depth/8,(o=i%4)?i+4-o:i),this.size=this.stride*u,this.data=e.slice(this.offset,this.offset+this.size),this.size!==this.data.byteLength)throw new Error("Truncated bitmap data")}return h(t,[{key:"get",value:function(t,e,r){var n=this.format.indexOf(r);return 1===this.depth?(this.data[e*this.stride+(t/8|0)]&1<<7-t%8*1)>>7-t%8*1:2===this.depth?(this.data[e*this.stride+(t/4|0)]&3<<6-t%4*2)>>>6-t%4*2:4===this.depth?(this.data[e*this.stride+(t/2|0)]&15<<4-t%2*4)>>>4-t%2*4:this.data[e*this.stride+t*(this.depth/8)+n]}}]),t}();var v=function(t){if(t instanceof Int8Array||t instanceof Uint8Array||t instanceof Uint8ClampedArray)return new DataView(t.buffer,t.byteOffset,t.byteLength);if(t instanceof ArrayBuffer)return new DataView(t);throw new TypeError("Expected `data` to be an ArrayBuffer, Buffer, Int8Array, Uint8Array or Uint8ClampedArray")},U=function(t){var e,r,n,i,o,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},f=a.width,u=void 0===f?0:f,h=a.height,c=void 0===h?0:h,s=a.icon,d=void 0!==s&&s,g=w(t);d?(e=g.getUint32(0,!0),r=g.getUint32(4,!0)/1|0,n=g.getUint32(8,!0)/2|0,i=g.getUint16(14,!0),o=g.getUint32(32,!0)):(!function(t){if(19778!==t)throw new Error("Invalid magic byte 0x".concat(t.toString(16)))}(g.getUint16(0,!0)),e=14+g.getUint32(14,!0),r=g.getUint32(18,!0),n=g.getUint32(22,!0),i=g.getUint16(28,!0),o=g.getUint32(46,!0)),0===o&&i<=8&&(o=1<<i);var l=0===r?u:r,p=0===n?c:n,y=new Uint8Array(g.buffer,g.byteOffset+e,g.byteLength-e),v=o?function(t,e){var r=e.width,n=e.height,i=e.colorDepth,o=e.colorCount,a=e.icon;if(8!==i&&4!==i&&2!==i&&1!==i)throw new Error("A color depth of ".concat(i," is not supported"));for(var f=new m(t,0,{width:o,height:1,colorDepth:32,format:"BGRA"}),u=new m(t,f.offset+f.size,{width:r,height:n,colorDepth:i,format:"C"}),h=a?new m(t,u.offset+u.size,{width:r,height:n,colorDepth:1,format:"A"}):null,c=new Uint8Array(r*n*4),s=0,d=0;d<n;d++)for(var g=0;g<r;g++){var l=u.get(g,n-d-1,"C");c[s++]=f.get(l,0,"R"),c[s++]=f.get(l,0,"G"),c[s++]=f.get(l,0,"B"),c[s++]=h&&h.get(g,n-d-1,"A")?0:255}return new Uint8ClampedArray(c.buffer,c.byteOffset,c.byteLength)}(y,{width:l,height:p,colorDepth:i,colorCount:o,icon:d}):function(t,e){var r=e.width,n=e.height,i=e.colorDepth,o=e.icon;if(32!==i&&24!==i)throw new Error("A color depth of ".concat(i," is not supported"));for(var a=new m(t,0,{width:r,height:n,colorDepth:i,format:"BGRA"}),f=24===i&&o?new m(t,a.offset+a.size,{width:r,height:n,colorDepth:1,format:"A"}):null,u=new Uint8Array(r*n*4),h=0,c=0;c<n;c++)for(var s=0;s<r;s++)u[h++]=a.get(s,n-c-1,"R"),u[h++]=a.get(s,n-c-1,"G"),u[h++]=a.get(s,n-c-1,"B"),u[h++]=32===i?a.get(s,n-c-1,"A"):f&&f.get(s,n-c-1,"A")?0:255;return new Uint8ClampedArray(u.buffer,u.byteOffset,u.byteLength)}(y,{width:l,height:p,colorDepth:i,icon:d});return Object.assign(new b(v,l,p),{colorDepth:i})},O=y;function D(t,e){return 2303741511===t.getUint32(e+0)&&218765834===t.getUint32(e+4)}function A(t,e){var r=t.getUint8(e+24),n=t.getUint8(e+25);if(0===n)return 1*r;if(2===n)return 3*r;if(3===n)return 1*r;if(4===n)return 2*r;if(6===n)return 4*r;throw new Error("Invalid PNG colorType")}function E(t,e){return t.getUint32(e+16,!1)}function F(t,e){return t.getUint32(e+20,!1)}var I=d((function(t){var e=v(t);if(e.byteLength<6)throw new Error("Truncated header");if(D(e,0))return[{bpp:A(e,0),data:new Uint8Array(e.buffer,e.byteOffset,e.byteLength),height:F(e,0),hotspot:null,type:"png",width:E(e,0)}];if(0!==e.getUint16(0,!0))throw new Error("Invalid magic bytes");var r=e.getUint16(2,!0);if(1!==r&&2!==r)throw new Error("Invalid image type");var n=e.getUint16(4,!0);if(e.byteLength<6+16*n)throw new Error("Truncated image list");return Array.from({length:n},(function(t,n){var i=e.getUint8(6+16*n+0),o=e.getUint8(6+16*n+1),a=e.getUint32(6+16*n+8,!0),f=e.getUint32(6+16*n+12,!0),u=2!==r?null:{x:e.getUint16(6+16*n+4,!0),y:e.getUint16(6+16*n+6,!0)};if(D(e,f))return{bpp:A(e,f),data:new Uint8Array(e.buffer,e.byteOffset+f,a),height:F(e,f),hotspot:u,type:"png",width:E(e,f)};var h=new Uint8Array(e.buffer,e.byteOffset+f,a),c=U(h,{width:i,height:o,icon:!0}),s={bpp:c.colorDepth,hotspot:u,type:"bmp"};return Object.assign(new O(c.data,c.width,c.height),s)}))})),C=function(t){return async function(t,r,n){var i=I(t);return await Promise.all(i.map((async function(t){if(r===e&&"png"===t.type)return o(o({},t),{},{buffer:t.data.buffer.slice(t.data.byteOffset,t.data.byteOffset+t.data.byteLength)});if("png"===t.type){var i=await n.decode(t.data);Object.assign(t,{data:i.data,type:"bmp"})}return Object.assign(t,{buffer:await n.encode(t,r),type:r.replace("image/","")})})))}(t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:e,r)},j={isICO:n,parseICO:C};t.default=j,t.isICO=n,t.parseICO=C,Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=ico.js.map
{
"name": "icojs",
"description": "parse ico file",
"version": "0.18.0",
"version": "0.19.0",
"author": "egy186",

@@ -13,6 +13,6 @@ "browser": "browser.js",

"decode-ico": "^0.4.1",
"file-type": "^16.5.4",
"file-type": "^18.7.0",
"jpeg-js": "^0.4.4",
"pngjs": "^7.0.0",
"to-data-view": "^1.1.0"
"to-data-view": "^2.0.0"
},

@@ -29,11 +29,11 @@ "devDependencies": {

"@stylistic/eslint-plugin": "^1.4.1",
"babel-plugin-transform-async-to-promises": "^0.8.18",
"c8": "^8.0.1",
"chai": "^4.3.10",
"chai-as-promised": "^7.0.0",
"data-uri-to-buffer": "^3.0.0",
"data-uri-to-buffer": "^6.0.1",
"ejs": "^3.1.7",
"eslint": "^8.54.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-jsdoc": "^46.9.0",
"eslint-plugin-n": "^16.3.1",
"file-url": "^3.0.0",
"jsdoc-to-markdown": "^8.0.0",

@@ -43,3 +43,2 @@ "jsonfile": "^6.1.0",

"mocha": "^10.2.0",
"nyc": "^15.0.0",
"pixelmatch": "^5.3.0",

@@ -53,9 +52,16 @@ "playwright": "^1.40.0",

},
"exports": {
".": {
"default": "./src/node/index.js",
"types": "./types/index.d.ts"
},
"./browser": {
"default": "./src/browser/index.js",
"types": "./types/index.d.ts"
}
},
"files": [
"dist",
"src",
"browser.js",
"index.js",
"index.d.ts",
"browser.d.ts"
"types"
],

@@ -68,3 +74,2 @@ "homepage": "https://egy186.github.io/icojs",

"license": "MIT",
"main": "index.js",
"repository": {

@@ -85,5 +90,7 @@ "type": "git",

"test:browser": "playwright test",
"test:node": "nyc --reporter lcov --reporter text-summary --report-dir coverage mocha \"test/node/*.spec.js\"",
"test:node": "c8 --reporter lcov --reporter text-summary --report-dir coverage mocha \"test/node/*.spec.js\"",
"version": "npm run docs && git add docs/index.html README.md"
}
},
"type": "module",
"types": "./types/index.d.ts"
}

@@ -5,3 +5,2 @@ # icojs

[![CI](https://github.com/egy186/icojs/actions/workflows/ci.yml/badge.svg)](https://github.com/egy186/icojs/actions/workflows/ci.yml)
[![dependencies Status](https://david-dm.org/egy186/icojs/status.svg)](https://david-dm.org/egy186/icojs)
[![Coverage Status](https://coveralls.io/repos/github/egy186/icojs/badge.svg?branch=main)](https://coveralls.io/github/egy186/icojs?branch=main)

@@ -22,3 +21,3 @@ [![codebeat badge](https://codebeat.co/badges/85bd457f-39b6-43d8-bf8e-c80ace07a8d7)](https://codebeat.co/projects/github-com-egy186-icojs)

```js
const ICO = require('icojs');
import { isICO, parseICO } from 'icojs';
```

@@ -29,3 +28,3 @@

```js
const ICO = require('icojs/browser')
import { isICO, parseICO } from 'icojs/browser';
```

@@ -47,13 +46,12 @@

```js
const fs = require('fs');
const ICO = require('icojs');
import { readFile, writeFile } from 'node:fs/promises';
import { parseICO } from 'icojs';
const buffer = fs.readFileSync('favicon.ico');
ICO.parse(buffer, 'image/png').then(images => {
// save as png files
images.forEach(image => {
const file = `${image.width}x${image.height}-${image.bpp}bit.png`;
const data = Buffer.from(image.buffer);
fs.writeFileSync(file, data);
});
const buffer = await readFile('favicon.ico');
const images = await parseICO(buffer, 'image/png');
// save as png files
images.forEach(image => {
const file = `${image.width}x${image.height}-${image.bpp}bit.png`;
const data = Buffer.from(image.buffer);
writeFile(file, data);
});

@@ -67,10 +65,9 @@ ```

<script>
document.getElementById('input-file').addEventListener('change', function (evt) {
document.getElementById('input-file').addEventListener('change', evt => {
// use FileReader for converting File object to ArrayBuffer object
var reader = new FileReader();
reader.onload = function (e) {
ICO.parse(e.target.result).then(function (images) {
// logs images
console.dir(images);
})
reader.onload = async e => {
const images = await ICO.parseICO(e.target.result);
// logs images
console.dir(images);
};

@@ -94,3 +91,3 @@ reader.readAsArrayBuffer(evt.target.files[0]);

* [isICO(source)](#exp_module_ICO--isICO) ⇒ <code>boolean</code> ⏏
* [parse(buffer, [mime])](#exp_module_ICO--parse) ⇒ <code>Promise.&lt;Array.&lt;ParsedImage&gt;&gt;</code> ⏏
* [parseICO(buffer, [mime])](#exp_module_ICO--parseICO) ⇒ <code>Promise.&lt;Array.&lt;ParsedImage&gt;&gt;</code> ⏏

@@ -109,5 +106,5 @@ <a name="exp_module_ICO--isICO"></a>

<a name="exp_module_ICO--parse"></a>
<a name="exp_module_ICO--parseICO"></a>
#### parse(buffer, [mime]) ⇒ <code>Promise.&lt;Array.&lt;ParsedImage&gt;&gt;</code> ⏏
#### parseICO(buffer, [mime]) ⇒ <code>Promise.&lt;Array.&lt;ParsedImage&gt;&gt;</code> ⏏
Parse ICO and return some images.

@@ -114,0 +111,0 @@

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

'use strict';
import { MIME_PNG } from '../mime.js';
const { MIME_PNG } = require('../mime');
const dataURLToArrayBuffer = dataURL => {

@@ -72,2 +70,2 @@ const string = atob(dataURL.replace(/.+,/u, ''));

module.exports = Image;
export default Image;

@@ -1,15 +0,15 @@

'use strict';
import Image from './image.js';
import { MIME_PNG } from '../mime.js';
import { isICO } from '../is-ico.js';
import { parse } from '../parse.js';
const Image = require('./image');
const isICO = require('../is-ico');
const parseICO = require('../parse');
const { MIME_PNG } = require('../mime');
const parseICO = (arrayBuffer, mime = MIME_PNG) => parse(arrayBuffer, mime, Image);
const parse = (arrayBuffer, mime = MIME_PNG) => parseICO(arrayBuffer, mime, Image);
const ICO = {
isICO,
parse
parseICO
};
module.exports = ICO;
export { isICO, parseICO };
export default ICO;

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

'use strict';
import toDataView from 'to-data-view';
const toDataView = require('to-data-view');
/**

@@ -17,2 +15,4 @@ * Check the ArrayBuffer is valid CUR.

module.exports = isCUR;
export { isCUR };
export default isCUR;

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

'use strict';
import toDataView from 'to-data-view';
const toDataView = require('to-data-view');
/**

@@ -17,2 +15,4 @@ * Check the ArrayBuffer is valid ICO.

module.exports = isICO;
export { isICO };
export default isICO;

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

'use strict';
import toDataView from 'to-data-view';
const toDataView = require('to-data-view');
/**

@@ -17,2 +15,4 @@ * Check the ArrayBuffer is valid PNG.

module.exports = isPNG;
export { isPNG };
export default isPNG;

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

'use strict';
const MIME_BMP = 'image/bmp';

@@ -7,3 +5,3 @@ const MIME_JPEG = 'image/jpeg';

module.exports = {
const mime = {
MIME_BMP,

@@ -14,1 +12,4 @@ MIME_JPEG,

export { MIME_BMP, MIME_JPEG, MIME_PNG };
export default mime;

@@ -1,9 +0,7 @@

'use strict';
import { MIME_BMP, MIME_JPEG, MIME_PNG } from '../mime.js';
import { PNG } from 'pngjs';
import bmp from 'bmp-js';
import { fileTypeFromBuffer } from 'file-type';
import jpeg from 'jpeg-js';
const FileType = require('file-type');
const bmp = require('bmp-js');
const jpeg = require('jpeg-js');
const { MIME_BMP, MIME_JPEG, MIME_PNG } = require('../mime');
const { PNG } = require('pngjs');
const decoders = {

@@ -31,3 +29,3 @@ [MIME_BMP]: bmp.decode,

const buffer = Buffer.from(arrayBuffer);
const { mime } = await FileType.fromBuffer(buffer) || {};
const { mime } = await fileTypeFromBuffer(buffer) || {};
if (!(mime in decoders)) {

@@ -68,2 +66,2 @@ throw new TypeError(`${mime} is not supported`);

module.exports = Image;
export default Image;

@@ -1,8 +0,6 @@

'use strict';
import Image from './image.js';
import { MIME_PNG } from '../mime.js';
import { isICO } from '../is-ico.js';
import { parse } from '../parse.js';
const Image = require('./image');
const isICO = require('../is-ico');
const parseICO = require('../parse');
const { MIME_PNG } = require('../mime');
/**

@@ -16,3 +14,3 @@ * Parse ICO and return some images.

*/
const parse = (buffer, mime = MIME_PNG) => parseICO(buffer, mime, Image);
const parseICO = (buffer, mime = MIME_PNG) => parse(buffer, mime, Image);

@@ -24,5 +22,7 @@ /**

isICO,
parse
parseICO
};
module.exports = ICO;
export { isICO, parseICO };
export default ICO;

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

'use strict';
import { MIME_PNG } from './mime.js';
import decodeIco from 'decode-ico';
const decodeIco = require('decode-ico');
const { MIME_PNG } = require('./mime');
/**

@@ -52,2 +50,4 @@ * @typedef {object} ParsedImage

module.exports = parse;
export { parse };
export default parse;

Sorry, the diff of this file is not supported yet

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