Comparing version 0.10.0 to 0.10.1
/*! | ||
* icojs v0.10.0 | ||
* icojs v0.10.1 | ||
* (c) egy186 | ||
* https://github.com/egy186/icojs/blob/master/LICENSE | ||
*/ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.ICO=n()}(this,function(){"use strict";var t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=function(t){for(var n=atob(t.replace(/.+,/,"")),e=new Uint8Array(n.length),r=0;r<n.length;r++)e[r]=n.charCodeAt(r);return e.buffer},e={decode:function(t){return new Promise(function(n){var e=URL.createObjectURL(new Blob([t])),r=document.createElement("img");r.src=e,r.onload=function(){var t=r.naturalWidth,e=r.naturalHeight,i=document.createElement("canvas");i.width=t,i.height=e;var a=i.getContext("2d");a.drawImage(r,0,0);var o=a.getImageData(0,0,t,e);n({width:o.width,height:o.height,data:o.data})}})},encode:function(t,e){return new Promise(function(r){var i=t.data,a=document.createElement("canvas");a.width=t.width,a.height=t.height;for(var o=a.getContext("2d"),u=o.createImageData(t.width,t.height),f=u.data,c=0;c<f.length;c++)f[c]=i[c];o.putImageData(u,0,0),r(n(a.toDataURL(e||"image/png")))})}},r=function(t){if(!(t instanceof ArrayBuffer))return!1;var n=new DataView(t);return 0===n.getUint16(0,!0)&&1===n.getUint16(2,!0)},i=function(t){var n=new DataView(t),e=n.getUint8(24),r=n.getUint8(25);return 2===r?3*e:4===r?2*e:6===r?4*e:e},a=function(t,n,e){var r={bit:e,buffer:n,height:t.height,width:t.width};return t.hotspot&&(r.hotspot=t.hotspot),r},o=function(t){if(!(t instanceof ArrayBuffer))return!1;var n=new DataView(t);return 2303741511===n.getUint32(0,!1)&&218765834===n.getUint32(4,!1)},u={of1:function(t){for(var n=new Uint8Array(t),e="",r=0;r<n.byteLength;r++)e+=("000000000"+n[r].toString(2)).slice(-8);return e.split("").map(function(t){return parseInt(t,2)})},of4:function(t){for(var n=new Uint8Array(t),e="",r=0;r<n.byteLength;r++)e+=("00"+n[r].toString(16)).slice(-2);return e.split("").map(function(t){return parseInt(t,16)})},of8:function(t){var n=new Uint8Array(t);return Array.from(n)}},f=function(t){return new Array(t).fill(0).map(function(t,n){return n})},c=function(t){return t%4==0?t:t+4-t%4},h=function(t){for(var n=t.width,e=t.height,r=new Uint8ClampedArray(n*e*4),i=new Uint8Array(t.xor),a=u.of1(t.and),o=t.bit/8,f=c(n*o),h=8*c(n/8),d=0;d<e;d++)for(var g=0;g<n;g++){var w=d*f+g*o;r.set([i[w+2],i[w+1],i[w],a[d*h+g]?0:255],function(t,r){return 4*((e-r-1)*n+t)}(g,d))}return{data:r,height:e,width:n}},d=function(t){for(var n=t.width,e=t.height,r=new Uint8ClampedArray(n*e*4),i=new Uint8Array(t.xor),a=!u.of8(i).every(function(t,n){return(n+1)%4!=0||0===t}),o=u.of1(t.and),f=t.bit/8,h=c(n*f),d=8*c(n/8),g=0;g<e;g++)for(var w=0;w<n;w++){var s=g*h+w*f;r.set([i[s+2],i[s+1],i[s],a?i[s+3]:o[g*d+w]?0:255],function(t,r){return 4*((e-r-1)*n+t)}(w,g))}return{data:r,height:e,width:n}},g=function(t){for(var n=t.width,e=t.height,r=new Uint8ClampedArray(n*e*4),i=u["of"+t.bit](t.xor),a=u.of1(t.and),o=8*c(n*t.bit/8)/t.bit,f=8*c(n/8),h=0;h<e;h++)for(var d=0;d<n;d++){var g=h*o+d,w=t.colors[i[g]];r.set([w[2],w[1],w[0],a[h*f+d]?0:255],function(t,r){return 4*((e-r-1)*n+t)}(d,h))}return{data:r,height:e,width:n}},w=function(t){return 32===t.bit?d(t):24===t.bit?h(t):g(t)},s=function(t,n,e){var r=new DataView(e),i=r.getUint32(0,!0),a=r.getUint16(14,!0),o=r.getUint32(32,!0);0===o&&a<=8&&(o=1<<a);var h=i+4*o,d=h+c(t*a/8)*n,g={and:e.slice(d,d+c(t/8)*n),bit:a,colors:f(o).map(function(t){var n=i+4*t;return u.of8(e.slice(n,n+4))}),height:n,width:t,xor:e.slice(h,d)};return Object.assign(w(g),{bit:a})},l=function(t){if(!(t instanceof ArrayBuffer))return!1;var n=new DataView(t);return 0===n.getUint16(0,!0)&&2===n.getUint16(2,!0)},v=function(t){if(!(t instanceof ArrayBuffer))throw new TypeError('"buffer" argument must be an ArrayBuffer');if(!l(t)&&!r(t))throw new Error("buffer is not ico");var n=new DataView(t).getUint16(4,!0),e=f(n).map(function(n){var e=6+16*n;return t.slice(e,e+16)});return f(n).map(function(n){var r=new DataView(e[n]),i=r.getUint32(8,!0),a=r.getUint32(12,!0),o={height:r.getUint8(1)||256,iconImage:t.slice(a,a+i),width:r.getUint8(0)||256};return l(t)&&(o.hotspot={x:r.getUint16(4,!0),y:r.getUint16(6,!0)}),o})},m=function(t,n,e){var r=[];try{r=v(t)}catch(t){return Promise.reject(t)}var u=function(t,n,r){if(o(r)){var a=i(r);return e.decode(r).then(function(t){return Object.assign(t,{bit:a})})}return Promise.resolve(s(t,n,r))},f=r.map(function(t){return u(t.width,t.height,t.iconImage).then(function(r){return e.encode(r,n).then(function(n){return a(t,n,r.bit)})})});return Promise.all(f)},p=t.ICO;return{isICO:r,noConflict:function(){return t.ICO=p,this},parse:function(t,n){return m(t,n,e)}}}); | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):t.ICO=n()}(this,function(){"use strict";var t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=function(t){for(var n=atob(t.replace(/.+,/,"")),e=new Uint8Array(n.length),r=0;r<n.length;r++)e[r]=n.charCodeAt(r);return e.buffer},e={decode:function(t){return new Promise(function(n){var e=URL.createObjectURL(new Blob([t])),r=document.createElement("img");r.src=e,r.onload=function(){var t=r.naturalWidth,e=r.naturalHeight,i=document.createElement("canvas");i.width=t,i.height=e;var a=i.getContext("2d");a.drawImage(r,0,0);var o=a.getImageData(0,0,t,e);n({width:o.width,height:o.height,data:o.data})}})},encode:function(t,e){return new Promise(function(r){var i=t.data,a=document.createElement("canvas");a.width=t.width,a.height=t.height;for(var o=a.getContext("2d"),u=o.createImageData(t.width,t.height),f=u.data,c=0;c<f.length;c++)f[c]=i[c];o.putImageData(u,0,0),r(n(a.toDataURL(e||"image/png")))})}},r=function(t){if(!(t instanceof ArrayBuffer))return!1;var n=new DataView(t);return 0===n.getUint16(0,!0)&&1===n.getUint16(2,!0)},i=function(t){var n=new DataView(t),e=n.getUint8(24),r=n.getUint8(25);return 2===r?3*e:4===r?2*e:6===r?4*e:e},a=function(t,n,e){var r={bit:t.bit,buffer:n,height:t.height,width:t.width};return e&&(r.hotspot=e),r},o=function(t){if(!(t instanceof ArrayBuffer))return!1;var n=new DataView(t);return 2303741511===n.getUint32(0,!1)&&218765834===n.getUint32(4,!1)},u={of1:function(t){for(var n=new Uint8Array(t),e="",r=0;r<n.byteLength;r++)e+=("000000000"+n[r].toString(2)).slice(-8);return e.split("").map(function(t){return parseInt(t,2)})},of4:function(t){for(var n=new Uint8Array(t),e="",r=0;r<n.byteLength;r++)e+=("00"+n[r].toString(16)).slice(-2);return e.split("").map(function(t){return parseInt(t,16)})},of8:function(t){var n=new Uint8Array(t);return Array.from(n)}},f=function(t){return new Array(t).fill(0).map(function(t,n){return n})},c=function(t){return t%4==0?t:t+4-t%4},h=function(t){for(var n=t.width,e=t.height,r=new Uint8ClampedArray(n*e*4),i=new Uint8Array(t.xor),a=u.of1(t.and),o=t.bit/8,f=c(n*o),h=8*c(n/8),d=0;d<e;d++)for(var g=0;g<n;g++){var w=d*f+g*o;r.set([i[w+2],i[w+1],i[w],a[d*h+g]?0:255],function(t,r){return 4*((e-r-1)*n+t)}(g,d))}return{data:r,height:e,width:n}},d=function(t){for(var n=t.width,e=t.height,r=new Uint8ClampedArray(n*e*4),i=new Uint8Array(t.xor),a=!u.of8(i).every(function(t,n){return(n+1)%4!=0||0===t}),o=u.of1(t.and),f=t.bit/8,h=c(n*f),d=8*c(n/8),g=0;g<e;g++)for(var w=0;w<n;w++){var s=g*h+w*f;r.set([i[s+2],i[s+1],i[s],a?i[s+3]:o[g*d+w]?0:255],function(t,r){return 4*((e-r-1)*n+t)}(w,g))}return{data:r,height:e,width:n}},g=function(t){for(var n=t.width,e=t.height,r=new Uint8ClampedArray(n*e*4),i=u["of"+t.bit](t.xor),a=u.of1(t.and),o=8*c(n*t.bit/8)/t.bit,f=8*c(n/8),h=0;h<e;h++)for(var d=0;d<n;d++){var g=h*o+d,w=t.colors[i[g]];r.set([w[2],w[1],w[0],a[h*f+d]?0:255],function(t,r){return 4*((e-r-1)*n+t)}(d,h))}return{data:r,height:e,width:n}},w=function(t){return 32===t.bit?d(t):24===t.bit?h(t):g(t)},s=function(t,n,e){var r=new DataView(e),i=r.getUint32(4,!0),a=r.getUint32(8,!0)/2,o=0===i?t:i,h=0===a?n:a,d=r.getUint32(0,!0),g=r.getUint16(14,!0),s=r.getUint32(32,!0);0===s&&g<=8&&(s=1<<g);var l=d+4*s,v=l+c(o*g/8)*h,m={and:e.slice(v,v+c(o/8)*h),bit:g,colors:f(s).map(function(t){var n=d+4*t;return u.of8(e.slice(n,n+4))}),height:h,width:o,xor:e.slice(l,v)};return Object.assign(w(m),{bit:g})},l=function(t){if(!(t instanceof ArrayBuffer))return!1;var n=new DataView(t);return 0===n.getUint16(0,!0)&&2===n.getUint16(2,!0)},v=function(t){if(!(t instanceof ArrayBuffer))throw new TypeError('"buffer" argument must be an ArrayBuffer');if(!l(t)&&!r(t))throw new Error("buffer is not ico");var n=new DataView(t).getUint16(4,!0),e=f(n).map(function(n){var e=6+16*n;return t.slice(e,e+16)});return f(n).map(function(n){var r=new DataView(e[n]),i=r.getUint32(8,!0),a=r.getUint32(12,!0),o={height:r.getUint8(1)||256,iconImage:t.slice(a,a+i),width:r.getUint8(0)||256};return l(t)&&(o.hotspot={x:r.getUint16(4,!0),y:r.getUint16(6,!0)}),o})},m=function(t,n,e){var r=[];try{r=v(t)}catch(t){return Promise.reject(t)}var u=function(t,n,r){if(o(r)){var a=i(r);return e.decode(r).then(function(t){return Object.assign(t,{bit:a})})}return Promise.resolve(s(t,n,r))},f=r.map(function(t){return u(t.width,t.height,t.iconImage).then(function(r){return e.encode(r,n).then(function(n){return a(r,n,t.hotspot)})})});return Promise.all(f)},U=t.ICO;return{isICO:r,noConflict:function(){return t.ICO=U,this},parse:function(t,n){return m(t,n,e)}}}); | ||
//# sourceMappingURL=ico.js.map |
{ | ||
"name": "icojs", | ||
"description": "parse ico file", | ||
"version": "0.10.0", | ||
"version": "0.10.1", | ||
"author": "egy186", | ||
@@ -34,3 +34,3 @@ "bugs": { | ||
"rimraf": "^2.5.2", | ||
"rollup": "^0.53.0", | ||
"rollup": "^0.54.0", | ||
"rollup-plugin-babel": "^3.0.2", | ||
@@ -37,0 +37,0 @@ "rollup-plugin-commonjs": "^8.2.1", |
@@ -11,4 +11,4 @@ 'use strict'; | ||
* @access private | ||
* @param {Number} width bitmap width | ||
* @param {Number} height bitmap height | ||
* @param {Number} iconWidth bitmap width | ||
* @param {Number} iconHeight bitmap height | ||
* @param {ArrayBuffer} arrayBuffer bitmap buffer | ||
@@ -21,4 +21,8 @@ * @returns {Object} imageData imageData of bitmap | ||
*/ | ||
const parseBMP = (width, height, arrayBuffer) => { | ||
const parseBMP = (iconWidth, iconHeight, arrayBuffer) => { | ||
const dataView = new DataView(arrayBuffer); | ||
const bitmapWidth = dataView.getUint32(4, true); | ||
const bitmapHeight = dataView.getUint32(8, true) / 2; | ||
const width = bitmapWidth === 0 ? iconWidth : bitmapWidth; | ||
const height = bitmapHeight === 0 ? iconHeight : bitmapHeight; | ||
@@ -25,0 +29,0 @@ const headerSize = dataView.getUint32(0, true); |
@@ -35,3 +35,3 @@ 'use strict'; | ||
.then(imageData => Image.encode(imageData, mime) | ||
.then(imageBuffer => parsedImage(iconImageData, imageBuffer, imageData.bit)))); | ||
.then(imageBuffer => parsedImage(imageData, imageBuffer, iconImageData.hotspot)))); | ||
return Promise.all(parsedImages); | ||
@@ -38,0 +38,0 @@ }; |
@@ -13,16 +13,17 @@ 'use strict'; | ||
* Create ParsedImage | ||
* @param {IconImageData} iconImageData {@link IconImageData} | ||
* @access private | ||
* @param {ImageData} imageData ImageData object. | ||
* @param {ArrayBufer} imageBuffer Image buffer. | ||
* @param {Number} bit Image bit depth. | ||
* @param {Object} hotspot Hotspot of CUR file. | ||
* @returns {ParsedImage} ImageData like object. | ||
*/ | ||
const parsedImage = (iconImageData, imageBuffer, bit) => { | ||
const parsedImage = (imageData, imageBuffer, hotspot) => { | ||
const image = { | ||
bit, | ||
bit: imageData.bit, | ||
buffer: imageBuffer, | ||
height: iconImageData.height, | ||
width: iconImageData.width | ||
height: imageData.height, | ||
width: imageData.width | ||
}; | ||
if (iconImageData.hotspot) { | ||
image.hotspot = iconImageData.hotspot; | ||
if (hotspot) { | ||
image.hotspot = hotspot; | ||
} | ||
@@ -29,0 +30,0 @@ return image; |
@@ -32,3 +32,3 @@ 'use strict'; | ||
const imageBuffer = Image.encodeSync(imageData, mime); | ||
return parsedImage(iconImageData, imageBuffer, imageData.bit); | ||
return parsedImage(imageData, imageBuffer, iconImageData.hotspot); | ||
}); | ||
@@ -35,0 +35,0 @@ return parsedImages; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59596
746