@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 9.1 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import{Milliseconds as e}from"../time.js";var r,t={},n={},i={};function a(){if(r)return i;r=1,Object.defineProperty(i,"__esModule",{value:!0}),i.loop=i.conditional=i.parse=void 0;var e=function e(r,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:n;if(Array.isArray(t))t.forEach((function(t){return e(r,t,n,i)}));else if("function"==typeof t)t(r,n,i,e);else{var a=Object.keys(t)[0];Array.isArray(t[a])?(i[a]={},e(r,t[a],n,i[a])):i[a]=t[a](r,n,i,e)}return n};i.parse=e;var t=function(e,r){return function(t,n,i,a){r(t,n,i)&&a(t,e,n,i)}};i.conditional=t;var n=function(e,r){return function(t,n,i,a){for(var o=[],d=t.pos;r(t,n,i);){var s={};if(a(t,e,n,s),t.pos===d)break;d=t.pos,o.push(s)}return o}};return i.loop=n,i}var o,d,s={};function u(){if(o)return s;o=1,Object.defineProperty(s,"__esModule",{value:!0}),s.readBits=s.readArray=s.readUnsigned=s.readString=s.peekBytes=s.readBytes=s.peekByte=s.readByte=s.buildStream=void 0;var e=function(e){return{data:e,pos:0}};s.buildStream=e;var r=function(){return function(e){return e.data[e.pos++]}};s.readByte=r;var t=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return function(r){return r.data[r.pos+e]}};s.peekByte=t;var n=function(e){return function(r){return r.data.subarray(r.pos,r.pos+=e)}};s.readBytes=n;var i=function(e){return function(r){return r.data.subarray(r.pos,r.pos+e)}};s.peekBytes=i;var a=function(e){return function(r){return Array.from(n(e)(r)).map((function(e){return String.fromCharCode(e)})).join("")}};s.readString=a;var d=function(e){return function(r){var t=n(2)(r);return e?(t[1]<<8)+t[0]:(t[0]<<8)+t[1]}};s.readUnsigned=d;var u=function(e,r){return function(t,i,a){for(var o="function"==typeof r?r(t,i,a):r,d=n(e),s=new Array(o),u=0;u<o;u++)s[u]=d(t);return s}};s.readArray=u;var c=function(e,r,t){for(var n=0,i=0;i<t;i++)n+=e[r+i]&&Math.pow(2,t-i-1);return n},f=function(e){return function(t){for(var n=r()(t),i=new Array(8),a=0;a<8;a++)i[7-a]=!!(n&1<<a);return Object.keys(e).reduce((function(r,t){var n=e[t];return n.length?r[t]=c(i,n.index,n.length):r[t]=i[n.index],r}),{})}};return s.readBits=f,s}function c(){return d||(d=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var r=a(),t=u(),n={blocks:function(e){for(var r=0,n=[],i=e.data.length,a=0,o=(0,t.readByte)()(e);o!==r&&o;o=(0,t.readByte)()(e)){if(e.pos+o>=i){var d=i-e.pos;n.push((0,t.readBytes)(d)(e)),a+=d;break}n.push((0,t.readBytes)(o)(e)),a+=o}for(var s=new Uint8Array(a),u=0,c=0;c<n.length;c++)s.set(n[c],u),u+=n[c].length;return s}},i=(0,r.conditional)({gce:[{codes:(0,t.readBytes)(2)},{byteSize:(0,t.readByte)()},{extras:(0,t.readBits)({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:(0,t.readUnsigned)(!0)},{transparentColorIndex:(0,t.readByte)()},{terminator:(0,t.readByte)()}]},(function(e){var r=(0,t.peekBytes)(2)(e);return 33===r[0]&&249===r[1]})),o=(0,r.conditional)({image:[{code:(0,t.readByte)()},{descriptor:[{left:(0,t.readUnsigned)(!0)},{top:(0,t.readUnsigned)(!0)},{width:(0,t.readUnsigned)(!0)},{height:(0,t.readUnsigned)(!0)},{lct:(0,t.readBits)({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},(0,r.conditional)({lct:(0,t.readArray)(3,(function(e,r,t){return Math.pow(2,t.descriptor.lct.size+1)}))},(function(e,r,t){return t.descriptor.lct.exists})),{data:[{minCodeSize:(0,t.readByte)()},n]}]},(function(e){return 44===(0,t.peekByte)()(e)})),d=(0,r.conditional)({text:[{codes:(0,t.readBytes)(2)},{blockSize:(0,t.readByte)()},{preData:function(e,r,n){return(0,t.readBytes)(n.text.blockSize)(e)}},n]},(function(e){var r=(0,t.peekBytes)(2)(e);return 33===r[0]&&1===r[1]})),s=(0,r.conditional)({application:[{codes:(0,t.readBytes)(2)},{blockSize:(0,t.readByte)()},{id:function(e,r,n){return(0,t.readString)(n.blockSize)(e)}},n]},(function(e){var r=(0,t.peekBytes)(2)(e);return 33===r[0]&&255===r[1]})),c=(0,r.conditional)({comment:[{codes:(0,t.readBytes)(2)},n]},(function(e){var r=(0,t.peekBytes)(2)(e);return 33===r[0]&&254===r[1]})),f=[{header:[{signature:(0,t.readString)(3)},{version:(0,t.readString)(3)}]},{lsd:[{width:(0,t.readUnsigned)(!0)},{height:(0,t.readUnsigned)(!0)},{gct:(0,t.readBits)({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:(0,t.readByte)()},{pixelAspectRatio:(0,t.readByte)()}]},(0,r.conditional)({gct:(0,t.readArray)(3,(function(e,r){return Math.pow(2,r.lsd.gct.size+1)}))},(function(e,r){return r.lsd.gct.exists})),{frames:(0,r.loop)([i,s,c,o,d],(function(e){var r=(0,t.peekByte)()(e);return 33===r||44===r}))}];e.default=f}(n)),n}var f,l={};function p(){if(f)return l;f=1,Object.defineProperty(l,"__esModule",{value:!0}),l.deinterlace=void 0;var e=function(e,r){for(var t=new Array(e.length),n=e.length/r,i=function(n,i){var a=e.slice(i*r,(i+1)*r);t.splice.apply(t,[n*r,r].concat(a))},a=[0,4,2,1],o=[8,8,4,2],d=0,s=0;s<4;s++)for(var u=a[s];u<n;u+=o[s])i(u,d),d++;return t};return l.deinterlace=e,l}var g,y,h={};function v(){if(g)return h;g=1,Object.defineProperty(h,"__esModule",{value:!0}),h.lzw=void 0;var e=function(e,r,t){var n,i,a,o,d,s,u,c,f,l,p,g,y,h,v,m,w=4096,x=-1,B=t,b=new Array(t),k=new Array(w),A=new Array(w),U=new Array(w+1);for(d=(i=1<<(l=e))+1,n=i+2,u=x,a=(1<<(o=l+1))-1,c=0;c<i;c++)k[c]=0,A[c]=c;for(p=g=y=h=v=m=0,f=0;f<B;){if(0===h){if(g<o){p+=r[m]<<g,g+=8,m++;continue}if(c=p&a,p>>=o,g-=o,c>n||c==d)break;if(c==i){a=(1<<(o=l+1))-1,n=i+2,u=x;continue}if(u==x){U[h++]=A[c],u=c,y=c;continue}for(s=c,c==n&&(U[h++]=y,c=u);c>i;)U[h++]=A[c],c=k[c];y=255&A[c],U[h++]=y,n<w&&(k[n]=u,A[n]=y,0===(++n&a)&&n<w&&(o++,a+=n)),u=s}h--,b[v++]=U[h],f++}for(f=v;f<B;f++)b[f]=0;return b};return h.lzw=e,h}function m(){if(y)return t;y=1,Object.defineProperty(t,"__esModule",{value:!0}),t.decompressFrames=t.decompressFrame=t.parseGIF=void 0;var e=d(c()),r=a(),n=u(),i=p(),o=v();function d(e){return e&&e.__esModule?e:{default:e}}var s=function(t){var i=new Uint8Array(t);return(0,r.parse)((0,n.buildStream)(i),e.default)};t.parseGIF=s;var f=function(e){for(var r=e.pixels.length,t=new Uint8ClampedArray(4*r),n=0;n<r;n++){var i=4*n,a=e.pixels[n],o=e.colorTable[a]||[0,0,0];t[i]=o[0],t[i+1]=o[1],t[i+2]=o[2],t[i+3]=a!==e.transparentIndex?255:0}return t},l=function(e,r,t){if(e.image){var n=e.image,a=n.descriptor.width*n.descriptor.height,d=(0,o.lzw)(n.data.minCodeSize,n.data.blocks,a);n.descriptor.lct.interlaced&&(d=(0,i.deinterlace)(d,n.descriptor.width));var s={pixels:d,dims:{top:e.image.descriptor.top,left:e.image.descriptor.left,width:e.image.descriptor.width,height:e.image.descriptor.height}};return n.descriptor.lct&&n.descriptor.lct.exists?s.colorTable=n.lct:s.colorTable=r,e.gce&&(s.delay=10*(e.gce.delay||10),s.disposalType=e.gce.extras.disposal,e.gce.extras.transparentColorGiven&&(s.transparentIndex=e.gce.transparentColorIndex)),t&&(s.patch=f(s)),s}console.warn("gif frame does not have associated image.")};t.decompressFrame=l;var g=function(e,r){return e.frames.filter((function(e){return e.image})).map((function(t){return l(t,e.gct,r)}))};return t.decompressFrames=g,t}var w=m();let x,B,b;function k(e,r){return x??=document.createElement("canvas"),x.width=e,x.height=r,x.getContext("2d",{willReadFrequently:!0})}async function A(r,t){const n=w.parseGIF(r),i=w.decompressFrames(n,!0),{width:a,height:o}=n.lsd,d=k(a,o),s=[],u=[];let c=0;for(const f of i){const r=e(f.delay||100);u.push(r),c+=r;const t=U(new ImageData(f.patch,f.dims.width,f.dims.height)),n=3===f.disposalType?d.getImageData(f.dims.left,f.dims.top,f.dims.width,f.dims.height):void 0;d.drawImage(t,f.dims.left,f.dims.top);const i=d.getImageData(0,0,a,o);s.push(i),1===f.disposalType||(2===f.disposalType?d.clearRect(f.dims.left,f.dims.top,f.dims.width,f.dims.height):3===f.disposalType&&d.putImageData(n,f.dims.left,f.dims.top))}return{frameCount:i.length,duration:c,frameDurations:u,getFrame:e=>s[e],width:a,height:o}}function U(e){return B??=document.createElement("canvas"),b??=B.getContext("2d",{willReadFrequently:!0}),B.width=e.width,B.height=e.height,b.putImageData(e,0,0),B}const S=[71,73,70];function I(e){const r=new Uint8Array(e);return!S.some(((e,t)=>e!==r[t]))}function z(e){if(!I(e))return!1;const r=new DataView(e),t=r.getUint8(10);let n=13+(128&t?3*2**(1+(7&t)):0),i=0,a=!1;for(;!a;){switch(r.getUint8(n++)){case 33:if(!o())return!1;break;case 44:d();break;case 59:a=!0;break;default:return!1}if(i>1)return!0}function o(){switch(r.getUint8(n++)){case 249:s();break;case 1:u();break;case 254:c();break;case 255:f();break;default:return!1}return!0}function d(){i++,n+=8;const e=r.getUint8(n++);n+=128&e?3*2**(1+(7&e)):0,n++,l()}function s(){n++,n+=4,l()}function u(){i++,n++,n+=12,l()}function c(){l()}function f(){n++,n+=8,n+=3,l()}function l(){let e;for(;e=r.getUint8(n++);)n+=e}return!1}export{z as isAnimatedGIF,I as isGIF,A as parseGif};