UNPKG

portable-image

Version:

Image data structure that supports RGB/RGBA/indexed color and arbitrary channels as well as blitters and web's ImageData output.

1 lines 45.7 kB
(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.PortableImage=e()}})(function(){var e,t,r;return function(){function l(a,o,s){function h(r,e){if(!o[r]){if(!a[r]){var t="function"==typeof require&&require;if(!e&&t)return t(r,!0);if(f)return f(r,!0);var i=new Error("Cannot find module '"+r+"'");throw i.code="MODULE_NOT_FOUND",i}var n=o[r]={exports:{}};a[r][0].call(n.exports,function(e){var t=a[r][1][e];return h(t||e)},n,n.exports,l,a,o,s)}return o[r].exports}for(var f="function"==typeof require&&require,e=0;e<s.length;e++)h(s[e]);return h}return l}()({1:[function(e,t,r){"use strict";function i(){this.name="";this.loop=false;this.startFrame=0;this.endFrame=0}t.exports=i},{}],2:[function(e,t,r){"use strict";function i(e,t={}){this.sprite=e;this.startFrame=+t.startFrame||0;this.endFrame=t.endFrame??e.frames.length;this.useCache=!!t.useCache;this.scaleX=t.scaleX??t.scale??1;this.scaleY=t.scaleY??t.scale??1;this.blitParams={scaleX:this.scaleX,scaleY:this.scaleY};this.x=+t.x||0;this.y=+t.y||0;this.imageData=this.sprite.prepareImageData(this.blitParams);this.ctx=t.ctx;this.running=false;this.frameIndex=0}t.exports=i;i.prototype.start=function(){if(this.running){return}this.running=true;this.runLoop()};i.prototype.stop=function(){this.running=false};i.prototype.runLoop=function(){if(!this.running){return}var e,t=this.sprite.frames[this.frameIndex];if(this.useCache){if(!t.imageDataCache){t.updateImageData(null,this.blitParams)}e=t.imageDataCache}else{if(this.imageData){t.updateImageData(this.imageData,this.blitParams)}else{this.imageData=t.createImageData(this.blitParams)}e=this.imageData}this.ctx.putImageData(e,this.x,this.y);this.frameIndex++;if(this.frameIndex>=this.endFrame){this.frameIndex=this.startFrame}setTimeout(()=>this.runLoop(),t.duration)}},{}],3:[function(e,t,r){"use strict";function i(e={}){this.imageIndex=+e.imageIndex||0;this.x=+e.x||0;this.y=+e.y||0}t.exports=i},{}],4:[function(e,t,r){"use strict";function s(e={}){this.channels=Array.isArray(e.channels)?e.channels:s.RGBA;this.indexed=e.indexed||Array.isArray(e.palette);this.bytesPerPixel=this.indexed?1:this.channels.length;this.palette=this.indexed?[]:null;if(Array.isArray(e.palette)){this.setPalette(e.palette)}this.channelIndex={};for(let e=0;e<this.channels.length;e++){this.channelIndex[this.channels[e]]=e}this.isRgbCompatible=this.channels.length>=3&&this.channels[0]==="red"&&this.channels[1]==="green"&&this.channels[2]==="blue";this.isRgbaCompatible=this.channels.length>=4&&this.isRgbCompatible&&this.channels[3]==="alpha";this.isRgb=this.isRgbCompatible&&this.channels.length===3;this.isRgba=this.isRgbaCompatible&&this.channels.length===4;this.isGrayCompatible=this.channels.length>=1&&this.channels[0]==="gray";this.isGrayAlphaCompatible=this.channels.length>=2&&this.isGrayCompatible&&this.channels[1]==="alpha";this.isGray=this.isGrayCompatible&&this.channels.length===1;this.isGrayAlpha=this.isGrayAlphaCompatible&&this.channels.length===2}t.exports=s;const i=s.Mapping=e("./Mapping.js");s.Mapping=i;s.DirectChannelMapping=i.DirectChannelMapping;s.DirectChannelMappingWithDefault=i.DirectChannelMappingWithDefault;s.MatrixChannelMapping=i.MatrixChannelMapping;s.compositing=e("./compositing.js");s.RGB=["red","green","blue"];s.RGBA=["red","green","blue","alpha"];s.GRAY=["gray"];s.GRAY_ALPHA=["gray","alpha"];s.prototype.setPalette=function(t){if(!this.indexed){throw new Error("This is not an indexed image")}this.palette.length=0;for(let e=0;e<t.length;e++){this.setPaletteEntry(e,t[e])}};s.prototype.setPaletteEntry=function(e,t){if(this.isRgb||this.isRgba){return this.setPaletteColor(e,t)}if(!this.indexed){throw new Error("This is not an indexed image")}if(!t){return}var r=this.palette[e];if(!r){r=this.palette[e]=[]}if(Array.isArray(t)){for(let e=0;e<this.channels.length;e++){r[e]=t[e]??0}}else if(typeof t==="object"){for(let e=0;e<this.channels.length;e++){r[e]=t[this.channels[e]]??0}}};const n=255;s.prototype.setPaletteColor=function(e,t){if(!this.indexed){throw new Error("This is not an indexed image")}if(!t){return}var r=this.palette[e];if(!r){r=this.palette[e]=[]}if(Array.isArray(t)){r[0]=t[0]??0;r[1]=t[1]??0;r[2]=t[2]??0;if(this.isRgba){r[3]=t[3]??255}}else if(typeof t==="object"){r[0]=t.R??t.r??0;r[1]=t.G??t.g??0;r[2]=t.B??t.b??0;if(this.isRgba){r[3]=t.A??t.a??255}}else if(typeof t==="string"&&t[0]==="#"){t=t.slice(1);if(t.length===3){t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]}let e=Number.parseInt(t,16);if(t.length===6){r[0]=e>>16&n;r[1]=e>>8&n;r[2]=e&n;if(this.isRgba){r[3]=255}}else if(t.length===8){r[0]=e>>24&n;r[1]=e>>16&n;r[2]=e>>8&n;if(this.isRgba){r[3]=e&n}}}};s.prototype.hasSamePalette=function(i){if(!this.palette||!i.palette){return false}if(this.palette.length!==i.palette.length){return false}for(let r=0;r<this.palette.length;r++){let t=this.palette[r];for(let e=0;e<t.length;e++){if(t[e]!==i.palette[r][e]){return false}}}return true};s.DEFAULT_CHANNEL_VALUES={red:0,green:0,blue:0,alpha:255};s.prototype.getAutoMappingToChannels=function(r,i=s.DEFAULT_CHANNEL_VALUES){var n=new Array(r.length*2);for(let t=0;t<r.length;t++){let e=r[t];if(Object.hasOwn(this.channelIndex,e)){n[t*2]=this.channelIndex[e];n[t*2+1]=null}else{n[t*2]=null;n[t*2+1]=i[e]??0}}return new s.DirectChannelMappingWithDefault(n)};s.getAutoMapping=function(i,n,a=s.DEFAULT_CHANNEL_VALUES){var o=new Array(n.length*2);for(let r=0;r<n.length;r++){let e=n[r];let t=i.indexOf(e);if(t>=0){o[r*2]=t;o[r*2+1]=null}else{o[r*2]=null;o[r*2+1]=a[e]??0}}return new s.DirectChannelMappingWithDefault(o)};s.prototype.getClosestPaletteIndex=n=>{var e=Math.min(this.channels.length,n.length),a=Infinity,o=0;for(let i=0;i<this.palette.length;i++){let r=0;for(let t=0;t<e;t++){let e=this.palette[i][t]-n[t];r+=e*e;if(r<a){a=r;o=i}}}return o}},{"./Mapping.js":8,"./compositing.js":10}],5:[function(e,t,r){"use strict";function i(e={},t=null){Object.defineProperty(this,"sprite",{configurable:true,value:t});this.duration=e.duration;this.cells=[];this.imageDataCache=null}t.exports=i;const n=e("./Sprite.js");const a=e("./Layer.js");const o=e("./Image.js");i.prototype.setParent=function(e){Object.defineProperty(this,"sprite",{value:e})};i.prototype.clearCache=function(){this.imageDataCache=null};i.prototype.addCell=function(e){this.cells.push(e);return this.cells.length-1};i.prototype.toImage=function(e=o){var r=new o({width:this.sprite.width,height:this.sprite.height,channelDef:this.sprite.channelDef});for(let t of this.cells){let e=this.sprite.images[t.imageIndex];e.copyTo(r,{compositing:o.compositing.binaryOver,x:t.x,y:t.y});console.log("Copy from/to:",r,e," --- cell: ",t)}return r};i.prototype.prepareImageData=function(e={}){return this.sprite.prepareImageData(e)};i.prototype.createImageData=function(e={}){var t=this.sprite.prepareImageData(e);this.updateImageData(t,e,true);return t};i.prototype.updateImageData=function(r,i,e=false){i=i?Object.assign({},i):{};if(!r){if(this.imageDataCache){r=this.imageDataCache;if(!e){r.data.fill(0)}}else{r=this.imageDataCache=this.sprite.prepareImageData(i)}}else if(!e){r.data.fill(0)}for(let t of this.cells){let e=this.sprite.images[t.imageIndex];i.innerX=t.x;i.innerY=t.y;i.compositing=o.compositing.binaryOver;e.updateImageData(r,i,true)}}},{"./Image.js":6,"./Layer.js":7,"./Sprite.js":9}],6:[function(e,r,t){(function(t){(function(){"use strict";function h(e={}){this.width=e.width;this.height=e.height;this.channelDef=e.channelDef??new f(e);this.pixelBuffer=null;if(e.pixelBuffer){if(e.pixelBuffer instanceof t){if(e.pixelBuffer.length!==this.width*this.height*this.channelDef.bytesPerPixel){throw new Error("Provided pixel Buffer mismatch the expected size (should be exactly width * height * bytesPerPixel)")}this.pixelBuffer=e.pixelBuffer}else if(e.pixelBuffer instanceof Uint8Array){if(e.pixelBuffer.length!==this.width*this.height*this.channelDef.bytesPerPixel){throw new Error("Provided pixel Uint8Array buffer mismatch the expected size (should be exactly width * height * bytesPerPixel)")}this.pixelBuffer=t.from(e.pixelBuffer)}else{throw new Error("Provided pixel buffer is not a Buffer or a Uint8Array")}}else{this.pixelBuffer=t.allocUnsafe(this.width*this.height*this.channelDef.bytesPerPixel)}}r.exports=h;const f=h.ChannelDef=h.prototype.ChannelDef=e("./ChannelDef.js");h.compositing=e("./compositing.js");h.prototype.setPalette=function(e){this.channelDef.setPalette(e)};h.prototype.setPaletteEntry=function(e,t){this.channelDef.setPaletteEntry(e,t)};h.prototype.setPaletteColor=function(e,t){this.channelDef.setPaletteColor(e,t)};h.prototype.hasSamePalette=function(e){return this.channelDef.hasSamePalette(e.channelDef)};h.prototype.getAutoMappingTo=function(e,t=f.DEFAULT_CHANNEL_VALUES){return this.channelDef.getAutoMappingToChannels(e.channelDef.channels,t)};h.prototype.copyTo=function(e,t={}){var r=t.mapping,i=t.scaleX??t.scale??1,n=t.scaleY??t.scale??1;if(!r){r=this.getAutoMappingTo(e)}let a={buffer:this.pixelBuffer,width:this.width,height:this.height,bytesPerPixel:this.channelDef.bytesPerPixel,x:Math.max(0,-((+t.x||0)/i+(+t.innerX||0))),y:Math.max(0,-((+t.y||0)/n+(+t.innerY||0))),endX:this.width,endY:this.height,channels:this.channelDef.channels.length,scaleX:i,scaleY:n,mapping:r,compositing:t.compositing||null};let o={buffer:e.pixelBuffer,width:e.width,height:e.height,bytesPerPixel:e.channelDef.bytesPerPixel,x:Math.max(0,(+t.x||0)+(+t.innerX||0)*i),y:Math.max(0,(+t.y||0)+(+t.innerY||0)*n),endX:e.width,endY:e.height,channels:e.channelDef.channels.length};if(a.compositing){if(this.channelDef.indexed){if(e.channelDef.indexed){if(!this.hasSamePalette(e)){throw new Error("Uncompatible palettes are not supported yet")}a.palette=this.channelDef.palette;if(a.compositing.id==="binaryOver"&&this.channelDef.channelIndex.alpha!==undefined){a.alphaChannel=this.channelDef.channelIndex.alpha;h.fullIndexedBlitWithTransparency(a,o)}else{throw new Error("Copy indexed to indexed with compositing is not supported yet, except for 'binaryOver' mode")}}else{a.palette=this.channelDef.palette;h.compositingBlitFromIndexed(a,o)}}else{if(e.channelDef.indexed){throw new Error("Copy to indexed portable image is not supported yet")}h.compositingBlit(a,o)}}else{if(this.channelDef.indexed){if(e.channelDef.indexed){if(!this.hasSamePalette(e)){throw new Error("Uncompatible palettes are not supported yet")}a.mapping=f.Mapping.INDEXED_TO_INDEXED;h.blit(a,o)}else{a.palette=this.channelDef.palette;h.blitFromIndexed(a,o)}}else{if(e.channelDef.indexed){throw new Error("Copy to indexed portable image is not supported yet")}h.blit(a,o)}}};h.prototype.prepareImageData=function(e={}){var t=e.scaleX??e.scale??1,r=e.scaleY??e.scale??1;return new ImageData(this.width*t,this.height*r)};h.prototype.createImageData=function(e={}){var t=this.prepareImageData(e);this.updateImageData(t,e,true);return t};h.prototype.updateImageData=function(e,t={},r=false){var i=t.mapping,n=t.scaleX??t.scale??1,a=t.scaleY??t.scale??1;if(!r){e.data.fill(0)}if(!i){if(e.width===this.width&&e.height===this.height&&!t.x&&!t.y&&n===1&&a===1){if(this.channelDef.indexed){if(this.channelDef.isRgbaCompatible){return this.isoIndexedRgbaCompatibleToRgbaBlit(e.data)}if(this.channelDef.isRgbCompatible){return this.isoIndexedRgbCompatibleToRgbaBlit(e.data)}}else{if(this.channelDef.isRgbaCompatible){return this.isoRgbaCompatibleToRgbaBlit(e.data)}if(this.channelDef.isRgbCompatible){return this.isoRgbCompatibleToRgbaBlit(e.data)}}}if(this.channelDef.isRgbaCompatible){i=f.Mapping.RGBA_COMPATIBLE_TO_RGBA}else if(this.channelDef.isRgbCompatible){i=f.Mapping.RGB_COMPATIBLE_TO_RGBA}else if(this.channelDef.isGrayAlphaCompatible){i=f.Mapping.GRAY_ALPHA_COMPATIBLE_TO_RGBA}else if(this.channelDef.isGrayCompatible){i=f.Mapping.GRAY_COMPATIBLE_TO_RGBA}else{throw new Error("Mapping required for image that are not RGB/RGBA/Grayscale/Grayscale+Alpha compatible")}}let o={buffer:this.pixelBuffer,width:this.width,height:this.height,bytesPerPixel:this.channelDef.bytesPerPixel,x:Math.max(0,-((+t.x||0)/n+(+t.innerX||0))),y:Math.max(0,-((+t.y||0)/a+(+t.innerY||0))),endX:this.width,endY:this.height,channels:this.channelDef.channels.length,scaleX:n,scaleY:a,mapping:i,compositing:t.compositing||null};let s={buffer:e.data,width:e.width,height:e.height,bytesPerPixel:4,x:Math.max(0,(+t.x||0)+(+t.innerX||0)*n),y:Math.max(0,(+t.y||0)+(+t.innerY||0)*a),endX:e.width,endY:e.height,channels:4};if(o.compositing){if(this.channelDef.indexed){o.palette=this.channelDef.palette;h.compositingBlitFromIndexed(o,s)}else{h.compositingBlit(o,s)}}else{if(this.channelDef.indexed){o.palette=this.channelDef.palette;h.blitFromIndexed(o,s)}else{h.blit(o,s)}}};h.blit=function(n,a){var e=Math.min(a.endX-a.x,(n.endX-n.x)*n.scaleX),t=Math.min(a.endY-a.y,(n.endY-n.y)*n.scaleY);for(let i=0;i<t;i++){for(let r=0;r<e;r++){let e=((a.y+i)*a.width+(a.x+r))*a.bytesPerPixel;let t=(Math.floor(n.y+i/n.scaleY)*n.width+Math.floor(n.x+r/n.scaleX))*n.bytesPerPixel;n.mapping.map(n,a,t,e)}}};h.blitFromIndexed=function(a,o){var e=Math.min(o.endX-o.x,(a.endX-a.x)*a.scaleX),t=Math.min(o.endY-o.y,(a.endY-a.y)*a.scaleY);for(let n=0;n<t;n++){for(let i=0;i<e;i++){let e=((o.y+n)*o.width+(o.x+i))*o.bytesPerPixel;let t=(Math.floor(a.y+n/a.scaleY)*a.width+Math.floor(a.x+i/a.scaleX))*a.bytesPerPixel;let r=a.palette[a.buffer[t]];a.mapping.map(a,o,0,e,r)}}};h.compositingBlit=function(n,a){var e=Math.min(a.endX-a.x,(n.endX-n.x)*n.scaleX),t=Math.min(a.endY-a.y,(n.endY-n.y)*n.scaleY);for(let i=0;i<t;i++){for(let r=0;r<e;r++){let e=((a.y+i)*a.width+(a.x+r))*a.bytesPerPixel;let t=(Math.floor(n.y+i/n.scaleY)*n.width+Math.floor(n.x+r/n.scaleX))*n.bytesPerPixel;n.mapping.compose(n,a,t,e,n.compositing)}}};h.compositingBlitFromIndexed=function(a,o){var e=Math.min(o.endX-o.x,(a.endX-a.x)*a.scaleX),t=Math.min(o.endY-o.y,(a.endY-a.y)*a.scaleY);for(let n=0;n<t;n++){for(let i=0;i<e;i++){let e=((o.y+n)*o.width+(o.x+i))*o.bytesPerPixel;let t=(Math.floor(a.y+n/a.scaleY)*a.width+Math.floor(a.x+i/a.scaleX))*a.bytesPerPixel;let r=a.palette[a.buffer[t]];a.mapping.compose(a,o,0,e,a.compositing,r)}}};h.fullIndexedBlitWithTransparency=function(n,a){var e=Math.min(a.endX-a.x,(n.endX-n.x)*n.scaleX),t=Math.min(a.endY-a.y,(n.endY-n.y)*n.scaleY);for(let i=0;i<t;i++){for(let r=0;r<e;r++){let e=((a.y+i)*a.width+(a.x+r))*a.bytesPerPixel;let t=(Math.floor(n.y+i/n.scaleY)*n.width+Math.floor(n.x+r/n.scaleX))*n.bytesPerPixel;if(n.palette[n.buffer[t]][n.alphaChannel]){a.buffer[e]=n.buffer[t]}}}};h.prototype.isoRgbCompatibleToRgbaBlit=function(i){for(let r=0,e=this.width*this.height;r<e;r++){let e=r*this.channelDef.bytesPerPixel;let t=r*4;i[t]=this.pixelBuffer[e];i[t+1]=this.pixelBuffer[e+1];i[t+2]=this.pixelBuffer[e+2];i[t+3]=255}};h.prototype.isoRgbaCompatibleToRgbaBlit=function(i){for(let r=0,e=this.width*this.height;r<e;r++){let e=r*this.channelDef.bytesPerPixel;let t=r*4;i[t]=this.pixelBuffer[e];i[t+1]=this.pixelBuffer[e+1];i[t+2]=this.pixelBuffer[e+2];i[t+3]=this.pixelBuffer[e+3]}};h.prototype.isoIndexedRgbCompatibleToRgbaBlit=function(n){for(let i=0,e=this.width*this.height;i<e;i++){let e=i*this.channelDef.bytesPerPixel;let t=i*4;let r=this.channelDef.palette[this.pixelBuffer[e]];n[t]=r[0];n[t+1]=r[1];n[t+2]=r[2];n[t+3]=255}};h.prototype.isoIndexedRgbaCompatibleToRgbaBlit=function(n){for(let i=0,e=this.width*this.height;i<e;i++){let e=i*this.channelDef.bytesPerPixel;let t=i*4;let r=this.channelDef.palette[this.pixelBuffer[e]];n[t]=r[0];n[t+1]=r[1];n[t+2]=r[2];n[t+3]=r[3]}};h.prototype.updateFromImageData=function(e,t){throw new Error("Not coded!")}}).call(this)}).call(this,e("buffer").Buffer)},{"./ChannelDef.js":4,"./compositing.js":10,buffer:13}],7:[function(e,t,r){"use strict";function i(e,t={}){this.name=e||"";this.visible=t.visible??true;this.compositing=t.compositing??null;this.opacity=t.opacity??1;this.order=t.order??0}t.exports=i},{}],8:[function(e,t,r){"use strict";function i(e,t){this.matrix=e;this.alphaChannelDst=t??null;this.composeChannelOrder=null;if(this.alphaChannelDst===null){this.compose=this.map}else{this.composeChannelOrder=[this.alphaChannelDst];for(let e=0;e<this.dstChannels;e++){if(e!==this.alphaChannelDst){this.composeChannelOrder.push(e)}}}}i.prototype.map=function(){};i.prototype.compose=function(){};t.exports=i;function s(e){return Math.max(0,Math.min(255,Math.round(e)))}function l(e){return Math.max(0,Math.min(255,Math.round(255*e)))}function u(e){return Math.max(0,Math.min(1,e/255))}const p={alpha:e=>e,channel:(e,t,r)=>r};function n(e,t){this.dstChannels=e.length;i.call(this,e,t)}n.prototype=Object.create(i.prototype);n.prototype.constructor=n;i.DirectChannelMapping=n;n.prototype.map=function(e,t,r,i,n=e.buffer){for(let e=0;e<t.channels;e++){t.buffer[i+e]=n[r+this.matrix[e]]}};n.prototype.compose=function(e,t,r,i,n=p,a=e.buffer){let o=t.buffer[i+this.alphaChannelDst]/255;let s=1;for(let e of this.composeChannelOrder){if(e===this.alphaChannelDst){s=a[r+this.matrix[e]]/255;t.buffer[i+e]=l(n.alpha(s,o))}else{t.buffer[i+e]=l(n.channel(s,o,a[r+this.matrix[e]]/255,t.buffer[i+e]/255))}}};function a(e,t){this.dstChannels=Math.floor(e.length/2);i.call(this,e,t)}a.prototype=Object.create(i.prototype);a.prototype.constructor=a;i.DirectChannelMappingWithDefault=a;a.prototype.map=function(e,t,r,i,n=e.buffer){for(let e=0;e<t.channels;e++){t.buffer[i+e]=this.matrix[e*2+1]??n[r+this.matrix[e*2]]}};a.prototype.compose=function(e,t,r,i,n=p,a=e.buffer){let o=t.buffer[i+this.alphaChannelDst]/255;let s=1;for(let e of this.composeChannelOrder){if(e===this.alphaChannelDst){s=(this.matrix[e*2+1]??a[r+this.matrix[e*2]])/255;t.buffer[i+e]=l(n.alpha(s,o))}else{t.buffer[i+e]=l(n.channel(s,o,(this.matrix[e*2+1]??a[r+this.matrix[e*2]])/255,t.buffer[i+e]/255))}}};function o(e,t,r){this.dstChannels=Math.floor(e.length/(t+1));this.srcChannelsUsed=t;i.call(this,e,r)}o.prototype=Object.create(i.prototype);o.prototype.constructor=o;i.MatrixChannelMapping=o;o.prototype.map=function(e,r,i,n,a=e.buffer){let o=0;for(let e=0;e<r.channels;e++){let t=0;for(let e=0;e<this.srcChannelsUsed;e++){t+=a[i+e]*this.matrix[o++]}t+=this.matrix[o++];r.buffer[n+e]=s(t)}};o.prototype.compose=function(e,i,n,a,o=p,s=e.buffer){let h=i.buffer[a+this.alphaChannelDst]/255;let f=1;for(let e of this.composeChannelOrder){let t=e*(this.srcChannelsUsed+1);let r=0;for(let e=0;e<this.srcChannelsUsed;e++){r+=s[n+e]*this.matrix[t++]}r+=this.matrix[t++];r=u(r);if(e===this.alphaChannelDst){i.buffer[a+e]=l(o.alpha(r,h))}else{i.buffer[a+e]=l(o.channel(f,h,r,i.buffer[a+e]/255))}}};i.INDEXED_TO_INDEXED=new n([0]);i.RGBA_COMPATIBLE_TO_RGBA=new n([0,1,2,3],3);i.RGB_COMPATIBLE_TO_RGBA=new a([0,null,1,null,2,null,null,255],3);i.GRAY_ALPHA_COMPATIBLE_TO_RGBA=new n([0,0,0,1],3);i.GRAY_COMPATIBLE_TO_RGBA=new a([0,null,0,null,0,null,null,255],3);i.RGBA_COMPATIBLE_TO_GRAY_ALPHA=new o([1/3,1/3,1/3,0,0,0,0,0,1,0],4,1);i.RGB_COMPATIBLE_TO_GRAY_ALPHA=new o([1/3,1/3,1/3,0,0,0,0,255],3,1)},{}],9:[function(e,t,r){"use strict";function i(e={}){this.width=e.width;this.height=e.height;this.channelDef=e.channelDef??new n(e);this.images=[];this.layers=[];this.frames=[];this.animations=[];this.orderedLayers=[];this.animationByName=new Map}t.exports=i;const n=i.ChannelDef=i.prototype.ChannelDef=e("./ChannelDef.js");const a=i.Image=i.prototype.Image=e("./Image.js");const o=i.Frame=i.prototype.Frame=e("./Frame.js");const s=i.Layer=i.prototype.Layer=e("./Layer.js");const h=i.Cell=i.prototype.Cell=e("./Cell.js");const f=i.Animation=i.prototype.Animation=e("./Animation.js");const l=i.Animator=i.prototype.Animator=e("./Animator.js");i.prototype.addImage=function(e){this.images.push(e);return this.images.length-1};i.prototype.addFrame=function(e){e.setParent(this);this.frames.push(e);return this.frames.length-1};i.prototype.toImage=function(e){return this.frames[0].toImage(e)};i.prototype.prepareImageData=function(e={}){var t=e.scaleX??e.scale??1,r=e.scaleY??e.scale??1;return new ImageData(this.width*t,this.height*r)};i.prototype.createAnimator=function(e={}){return new l(this,e)};i.prototype.clearCache=function(){for(let e of this.frames){e.clearCache()}}},{"./Animation.js":1,"./Animator.js":2,"./Cell.js":3,"./ChannelDef.js":4,"./Frame.js":5,"./Image.js":6,"./Layer.js":7}],10:[function(e,t,r){"use strict";const n={};t.exports=n;n.normal=n.over={id:"over",alpha:(e,t)=>e+t*(1-e),channel:(e,t,r,i)=>(r*e+i*t*(1-e))/(e+t*(1-e))||0};n.binaryOver={id:"binaryOver",alpha:(e,t)=>e?1:t,channel:(e,t,r,i)=>e?r:i};n.in={id:"in",alpha:(e,t)=>e*t,channel:n.normal.channel};n.out={id:"out",alpha:(e,t)=>e*(1-t),channel:(e,t,r,i)=>(r*e+i*(1-t)*(1-e))/(e+(1-t)*(1-e))||0};n.atop={id:"atop",alpha:(e,t)=>n.normal.alpha(e,t)*t,channel:n.normal.channel};n.xor={id:"xor",alpha:(e,t)=>e*(1-t)+t*(1-e),channel:n.normal.channel};n.multiply={id:"multiply",alpha:n.normal.alpha,channel:(e,t,r,i)=>n.normal.channel(e,t,r*(1+(i-1)*t),i)};n.screen={id:"screen",alpha:n.normal.alpha,channel:(e,t,r,i)=>n.normal.channel(e,t,1-(1-r)*(1-i*t),i)};n.overlay={id:"overlay",alpha:n.normal.alpha,channel:(e,t,r,i)=>n.normal.channel(e,t,1+(i-1)*t<.5?2*r*(1+(i-1)*t):i*t>.5?1-2*(1-r)*(1-i*t):r,i)}},{}],11:[function(e,t,r){"use strict";const i={};t.exports=i;i.Image=e("./Image.js");i.Sprite=e("./Sprite.js");i.Mapping=e("./Mapping.js");i.compositing=e("./compositing.js")},{"./Image.js":6,"./Mapping.js":8,"./Sprite.js":9,"./compositing.js":10}],12:[function(e,t,r){"use strict";r.byteLength=o;r.toByteArray=s;r.fromByteArray=y;var h=[];var f=[];var l=typeof Uint8Array!=="undefined"?Uint8Array:Array;var i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var n=0,a=i.length;n<a;++n){h[n]=i[n];f[i.charCodeAt(n)]=n}f["-".charCodeAt(0)]=62;f["_".charCodeAt(0)]=63;function u(e){var t=e.length;if(t%4>0){throw new Error("Invalid string. Length must be a multiple of 4")}var r=e.indexOf("=");if(r===-1)r=t;var i=r===t?0:4-r%4;return[r,i]}function o(e){var t=u(e);var r=t[0];var i=t[1];return(r+i)*3/4-i}function p(e,t,r){return(t+r)*3/4-r}function s(e){var t;var r=u(e);var i=r[0];var n=r[1];var a=new l(p(e,i,n));var o=0;var s=n>0?i-4:i;var h;for(h=0;h<s;h+=4){t=f[e.charCodeAt(h)]<<18|f[e.charCodeAt(h+1)]<<12|f[e.charCodeAt(h+2)]<<6|f[e.charCodeAt(h+3)];a[o++]=t>>16&255;a[o++]=t>>8&255;a[o++]=t&255}if(n===2){t=f[e.charCodeAt(h)]<<2|f[e.charCodeAt(h+1)]>>4;a[o++]=t&255}if(n===1){t=f[e.charCodeAt(h)]<<10|f[e.charCodeAt(h+1)]<<4|f[e.charCodeAt(h+2)]>>2;a[o++]=t>>8&255;a[o++]=t&255}return a}function c(e){return h[e>>18&63]+h[e>>12&63]+h[e>>6&63]+h[e&63]}function g(e,t,r){var i;var n=[];for(var a=t;a<r;a+=3){i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255);n.push(c(i))}return n.join("")}function y(e){var t;var r=e.length;var i=r%3;var n=[];var a=16383;for(var o=0,s=r-i;o<s;o+=a){n.push(g(e,o,o+a>s?s:o+a))}if(i===1){t=e[r-1];n.push(h[t>>2]+h[t<<4&63]+"==")}else if(i===2){t=(e[r-2]<<8)+e[r-1];n.push(h[t>>10]+h[t>>4&63]+h[t<<2&63]+"=")}return n.join("")}},{}],13:[function(Z,e,K){(function(e){(function(){"use strict";var i=Z("base64-js");var a=Z("ieee754");K.Buffer=p;K.SlowBuffer=t;K.INSPECT_MAX_BYTES=50;var r=2147483647;K.kMaxLength=r;p.TYPED_ARRAY_SUPPORT=e();if(!p.TYPED_ARRAY_SUPPORT&&typeof console!=="undefined"&&typeof console.error==="function"){console.error("This browser lacks typed array (Uint8Array) support which is required by "+"`buffer` v5.x. Use `buffer` v4.x if you require old browser support.")}function e(){try{var e=new Uint8Array(1);e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}};return e.foo()===42}catch(e){return false}}Object.defineProperty(p.prototype,"parent",{enumerable:true,get:function(){if(!p.isBuffer(this))return undefined;return this.buffer}});Object.defineProperty(p.prototype,"offset",{enumerable:true,get:function(){if(!p.isBuffer(this))return undefined;return this.byteOffset}});function o(e){if(e>r){throw new RangeError('The value "'+e+'" is invalid for option "size"')}var t=new Uint8Array(e);t.__proto__=p.prototype;return t}function p(e,t,r){if(typeof e==="number"){if(typeof t==="string"){throw new TypeError('The "string" argument must be of type string. Received type number')}return f(e)}return n(e,t,r)}if(typeof Symbol!=="undefined"&&Symbol.species!=null&&p[Symbol.species]===p){Object.defineProperty(p,Symbol.species,{value:null,configurable:true,enumerable:false,writable:false})}p.poolSize=8192;function n(e,t,r){if(typeof e==="string"){return l(e,t)}if(ArrayBuffer.isView(e)){return u(e)}if(e==null){throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, "+"or Array-like Object. Received type "+typeof e)}if(U(e,ArrayBuffer)||e&&U(e.buffer,ArrayBuffer)){return c(e,t,r)}if(typeof e==="number"){throw new TypeError('The "value" argument must not be of type number. Received type number')}var i=e.valueOf&&e.valueOf();if(i!=null&&i!==e){return p.from(i,t,r)}var n=g(e);if(n)return n;if(typeof Symbol!=="undefined"&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]==="function"){return p.from(e[Symbol.toPrimitive]("string"),t,r)}throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, "+"or Array-like Object. Received type "+typeof e)}p.from=function(e,t,r){return n(e,t,r)};p.prototype.__proto__=Uint8Array.prototype;p.__proto__=Uint8Array;function s(e){if(typeof e!=="number"){throw new TypeError('"size" argument must be of type number')}else if(e<0){throw new RangeError('The value "'+e+'" is invalid for option "size"')}}function h(e,t,r){s(e);if(e<=0){return o(e)}if(t!==undefined){return typeof r==="string"?o(e).fill(t,r):o(e).fill(t)}return o(e)}p.alloc=function(e,t,r){return h(e,t,r)};function f(e){s(e);return o(e<0?0:y(e)|0)}p.allocUnsafe=function(e){return f(e)};p.allocUnsafeSlow=function(e){return f(e)};function l(e,t){if(typeof t!=="string"||t===""){t="utf8"}if(!p.isEncoding(t)){throw new TypeError("Unknown encoding: "+t)}var r=d(e,t)|0;var i=o(r);var n=i.write(e,t);if(n!==r){i=i.slice(0,n)}return i}function u(e){var t=e.length<0?0:y(e.length)|0;var r=o(t);for(var i=0;i<t;i+=1){r[i]=e[i]&255}return r}function c(e,t,r){if(t<0||e.byteLength<t){throw new RangeError('"offset" is outside of buffer bounds')}if(e.byteLength<t+(r||0)){throw new RangeError('"length" is outside of buffer bounds')}var i;if(t===undefined&&r===undefined){i=new Uint8Array(e)}else if(r===undefined){i=new Uint8Array(e,t)}else{i=new Uint8Array(e,t,r)}i.__proto__=p.prototype;return i}function g(e){if(p.isBuffer(e)){var t=y(e.length)|0;var r=o(t);if(r.length===0){return r}e.copy(r,0,0,t);return r}if(e.length!==undefined){if(typeof e.length!=="number"||O(e.length)){return o(0)}return u(e)}if(e.type==="Buffer"&&Array.isArray(e.data)){return u(e.data)}}function y(e){if(e>=r){throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+r.toString(16)+" bytes")}return e|0}function t(e){if(+e!=e){e=0}return p.alloc(+e)}p.isBuffer=function e(t){return t!=null&&t._isBuffer===true&&t!==p.prototype};p.compare=function e(t,r){if(U(t,Uint8Array))t=p.from(t,t.offset,t.byteLength);if(U(r,Uint8Array))r=p.from(r,r.offset,r.byteLength);if(!p.isBuffer(t)||!p.isBuffer(r)){throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array')}if(t===r)return 0;var i=t.length;var n=r.length;for(var a=0,o=Math.min(i,n);a<o;++a){if(t[a]!==r[a]){i=t[a];n=r[a];break}}if(i<n)return-1;if(n<i)return 1;return 0};p.isEncoding=function e(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return true;default:return false}};p.concat=function e(t,r){if(!Array.isArray(t)){throw new TypeError('"list" argument must be an Array of Buffers')}if(t.length===0){return p.alloc(0)}var i;if(r===undefined){r=0;for(i=0;i<t.length;++i){r+=t[i].length}}var n=p.allocUnsafe(r);var a=0;for(i=0;i<t.length;++i){var o=t[i];if(U(o,Uint8Array)){o=p.from(o)}if(!p.isBuffer(o)){throw new TypeError('"list" argument must be an Array of Buffers')}o.copy(n,a);a+=o.length}return n};function d(e,t){if(p.isBuffer(e)){return e.length}if(ArrayBuffer.isView(e)||U(e,ArrayBuffer)){return e.byteLength}if(typeof e!=="string"){throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. '+"Received type "+typeof e)}var r=e.length;var i=arguments.length>2&&arguments[2]===true;if(!i&&r===0)return 0;var n=false;for(;;){switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return _(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return T(e).length;default:if(n){return i?-1:_(e).length}t=(""+t).toLowerCase();n=true}}}p.byteLength=d;function m(e,t,r){var i=false;if(t===undefined||t<0){t=0}if(t>this.length){return""}if(r===undefined||r>this.length){r=this.length}if(r<=0){return""}r>>>=0;t>>>=0;if(r<=t){return""}if(!e)e="utf8";while(true){switch(e){case"hex":return k(this,t,r);case"utf8":case"utf-8":return B(this,t,r);case"ascii":return F(this,t,r);case"latin1":case"binary":return N(this,t,r);case"base64":return X(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return z(this,t,r);default:if(i)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase();i=true}}}p.prototype._isBuffer=true;function b(e,t,r){var i=e[t];e[t]=e[r];e[r]=i}p.prototype.swap16=function e(){var t=this.length;if(t%2!==0){throw new RangeError("Buffer size must be a multiple of 16-bits")}for(var r=0;r<t;r+=2){b(this,r,r+1)}return this};p.prototype.swap32=function e(){var t=this.length;if(t%4!==0){throw new RangeError("Buffer size must be a multiple of 32-bits")}for(var r=0;r<t;r+=4){b(this,r,r+3);b(this,r+1,r+2)}return this};p.prototype.swap64=function e(){var t=this.length;if(t%8!==0){throw new RangeError("Buffer size must be a multiple of 64-bits")}for(var r=0;r<t;r+=8){b(this,r,r+7);b(this,r+1,r+6);b(this,r+2,r+5);b(this,r+3,r+4)}return this};p.prototype.toString=function e(){var t=this.length;if(t===0)return"";if(arguments.length===0)return B(this,0,t);return m.apply(this,arguments)};p.prototype.toLocaleString=p.prototype.toString;p.prototype.equals=function e(t){if(!p.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(this===t)return true;return p.compare(this,t)===0};p.prototype.inspect=function e(){var t="";var r=K.INSPECT_MAX_BYTES;t=this.toString("hex",0,r).replace(/(.{2})/g,"$1 ").trim();if(this.length>r)t+=" ... ";return"<Buffer "+t+">"};p.prototype.compare=function e(t,r,i,n,a){if(U(t,Uint8Array)){t=p.from(t,t.offset,t.byteLength)}if(!p.isBuffer(t)){throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. '+"Received type "+typeof t)}if(r===undefined){r=0}if(i===undefined){i=t?t.length:0}if(n===undefined){n=0}if(a===undefined){a=this.length}if(r<0||i>t.length||n<0||a>this.length){throw new RangeError("out of range index")}if(n>=a&&r>=i){return 0}if(n>=a){return-1}if(r>=i){return 1}r>>>=0;i>>>=0;n>>>=0;a>>>=0;if(this===t)return 0;var o=a-n;var s=i-r;var h=Math.min(o,s);var f=this.slice(n,a);var l=t.slice(r,i);for(var u=0;u<h;++u){if(f[u]!==l[u]){o=f[u];s=l[u];break}}if(o<s)return-1;if(s<o)return 1;return 0};function w(e,t,r,i,n){if(e.length===0)return-1;if(typeof r==="string"){i=r;r=0}else if(r>2147483647){r=2147483647}else if(r<-2147483648){r=-2147483648}r=+r;if(O(r)){r=n?0:e.length-1}if(r<0)r=e.length+r;if(r>=e.length){if(n)return-1;else r=e.length-1}else if(r<0){if(n)r=0;else return-1}if(typeof t==="string"){t=p.from(t,i)}if(p.isBuffer(t)){if(t.length===0){return-1}return v(e,t,r,i,n)}else if(typeof t==="number"){t=t&255;if(typeof Uint8Array.prototype.indexOf==="function"){if(n){return Uint8Array.prototype.indexOf.call(e,t,r)}else{return Uint8Array.prototype.lastIndexOf.call(e,t,r)}}return v(e,[t],r,i,n)}throw new TypeError("val must be string, number or Buffer")}function v(e,t,r,i,n){var a=1;var o=e.length;var s=t.length;if(i!==undefined){i=String(i).toLowerCase();if(i==="ucs2"||i==="ucs-2"||i==="utf16le"||i==="utf-16le"){if(e.length<2||t.length<2){return-1}a=2;o/=2;s/=2;r/=2}}function h(e,t){if(a===1){return e[t]}else{return e.readUInt16BE(t*a)}}var f;if(n){var l=-1;for(f=r;f<o;f++){if(h(e,f)===h(t,l===-1?0:f-l)){if(l===-1)l=f;if(f-l+1===s)return l*a}else{if(l!==-1)f-=f-l;l=-1}}}else{if(r+s>o)r=o-s;for(f=r;f>=0;f--){var u=true;for(var p=0;p<s;p++){if(h(e,f+p)!==h(t,p)){u=false;break}}if(u)return f}}return-1}p.prototype.includes=function e(t,r,i){return this.indexOf(t,r,i)!==-1};p.prototype.indexOf=function e(t,r,i){return w(this,t,r,i,true)};p.prototype.lastIndexOf=function e(t,r,i){return w(this,t,r,i,false)};function x(e,t,r,i){r=Number(r)||0;var n=e.length-r;if(!i){i=n}else{i=Number(i);if(i>n){i=n}}var a=t.length;if(i>a/2){i=a/2}for(var o=0;o<i;++o){var s=parseInt(t.substr(o*2,2),16);if(O(s))return o;e[r+o]=s}return o}function A(e,t,r,i){return L(_(t,e.length-r),e,r,i)}function C(e,t,r,i){return L(V(t),e,r,i)}function j(e,t,r,i){return C(e,t,r,i)}function Y(e,t,r,i){return L(T(t),e,r,i)}function S(e,t,r,i){return L(J(t,e.length-r),e,r,i)}p.prototype.write=function e(t,r,i,n){if(r===undefined){n="utf8";i=this.length;r=0}else if(i===undefined&&typeof r==="string"){n=r;i=this.length;r=0}else if(isFinite(r)){r=r>>>0;if(isFinite(i)){i=i>>>0;if(n===undefined)n="utf8"}else{n=i;i=undefined}}else{throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported")}var a=this.length-r;if(i===undefined||i>a)i=a;if(t.length>0&&(i<0||r<0)||r>this.length){throw new RangeError("Attempt to write outside buffer bounds")}if(!n)n="utf8";var o=false;for(;;){switch(n){case"hex":return x(this,t,r,i);case"utf8":case"utf-8":return A(this,t,r,i);case"ascii":return C(this,t,r,i);case"latin1":case"binary":return j(this,t,r,i);case"base64":return Y(this,t,r,i);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return S(this,t,r,i);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase();o=true}}};p.prototype.toJSON=function e(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function X(e,t,r){if(t===0&&r===e.length){return i.fromByteArray(e)}else{return i.fromByteArray(e.slice(t,r))}}function B(e,t,r){r=Math.min(e.length,r);var i=[];var n=t;while(n<r){var a=e[n];var o=null;var s=a>239?4:a>223?3:a>191?2:1;if(n+s<=r){var h,f,l,u;switch(s){case 1:if(a<128){o=a}break;case 2:h=e[n+1];if((h&192)===128){u=(a&31)<<6|h&63;if(u>127){o=u}}break;case 3:h=e[n+1];f=e[n+2];if((h&192)===128&&(f&192)===128){u=(a&15)<<12|(h&63)<<6|f&63;if(u>2047&&(u<55296||u>57343)){o=u}}break;case 4:h=e[n+1];f=e[n+2];l=e[n+3];if((h&192)===128&&(f&192)===128&&(l&192)===128){u=(a&15)<<18|(h&63)<<12|(f&63)<<6|l&63;if(u>65535&&u<1114112){o=u}}}}if(o===null){o=65533;s=1}else if(o>65535){o-=65536;i.push(o>>>10&1023|55296);o=56320|o&1023}i.push(o);n+=s}return G(i)}var D=4096;function G(e){var t=e.length;if(t<=D){return String.fromCharCode.apply(String,e)}var r="";var i=0;while(i<t){r+=String.fromCharCode.apply(String,e.slice(i,i+=D))}return r}function F(e,t,r){var i="";r=Math.min(e.length,r);for(var n=t;n<r;++n){i+=String.fromCharCode(e[n]&127)}return i}function N(e,t,r){var i="";r=Math.min(e.length,r);for(var n=t;n<r;++n){i+=String.fromCharCode(e[n])}return i}function k(e,t,r){var i=e.length;if(!t||t<0)t=0;if(!r||r<0||r>i)r=i;var n="";for(var a=t;a<r;++a){n+=q(e[a])}return n}function z(e,t,r){var i=e.slice(t,r);var n="";for(var a=0;a<i.length;a+=2){n+=String.fromCharCode(i[a]+i[a+1]*256)}return n}p.prototype.slice=function e(t,r){var i=this.length;t=~~t;r=r===undefined?i:~~r;if(t<0){t+=i;if(t<0)t=0}else if(t>i){t=i}if(r<0){r+=i;if(r<0)r=0}else if(r>i){r=i}if(r<t)r=t;var n=this.subarray(t,r);n.__proto__=p.prototype;return n};function E(e,t,r){if(e%1!==0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}p.prototype.readUIntLE=function e(t,r,i){t=t>>>0;r=r>>>0;if(!i)E(t,r,this.length);var n=this[t];var a=1;var o=0;while(++o<r&&(a*=256)){n+=this[t+o]*a}return n};p.prototype.readUIntBE=function e(t,r,i){t=t>>>0;r=r>>>0;if(!i){E(t,r,this.length)}var n=this[t+--r];var a=1;while(r>0&&(a*=256)){n+=this[t+--r]*a}return n};p.prototype.readUInt8=function e(t,r){t=t>>>0;if(!r)E(t,1,this.length);return this[t]};p.prototype.readUInt16LE=function e(t,r){t=t>>>0;if(!r)E(t,2,this.length);return this[t]|this[t+1]<<8};p.prototype.readUInt16BE=function e(t,r){t=t>>>0;if(!r)E(t,2,this.length);return this[t]<<8|this[t+1]};p.prototype.readUInt32LE=function e(t,r){t=t>>>0;if(!r)E(t,4,this.length);return(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216};p.prototype.readUInt32BE=function e(t,r){t=t>>>0;if(!r)E(t,4,this.length);return this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};p.prototype.readIntLE=function e(t,r,i){t=t>>>0;r=r>>>0;if(!i)E(t,r,this.length);var n=this[t];var a=1;var o=0;while(++o<r&&(a*=256)){n+=this[t+o]*a}a*=128;if(n>=a)n-=Math.pow(2,8*r);return n};p.prototype.readIntBE=function e(t,r,i){t=t>>>0;r=r>>>0;if(!i)E(t,r,this.length);var n=r;var a=1;var o=this[t+--n];while(n>0&&(a*=256)){o+=this[t+--n]*a}a*=128;if(o>=a)o-=Math.pow(2,8*r);return o};p.prototype.readInt8=function e(t,r){t=t>>>0;if(!r)E(t,1,this.length);if(!(this[t]&128))return this[t];return(255-this[t]+1)*-1};p.prototype.readInt16LE=function e(t,r){t=t>>>0;if(!r)E(t,2,this.length);var i=this[t]|this[t+1]<<8;return i&32768?i|4294901760:i};p.prototype.readInt16BE=function e(t,r){t=t>>>0;if(!r)E(t,2,this.length);var i=this[t+1]|this[t]<<8;return i&32768?i|4294901760:i};p.prototype.readInt32LE=function e(t,r){t=t>>>0;if(!r)E(t,4,this.length);return this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};p.prototype.readInt32BE=function e(t,r){t=t>>>0;if(!r)E(t,4,this.length);return this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};p.prototype.readFloatLE=function e(t,r){t=t>>>0;if(!r)E(t,4,this.length);return a.read(this,t,true,23,4)};p.prototype.readFloatBE=function e(t,r){t=t>>>0;if(!r)E(t,4,this.length);return a.read(this,t,false,23,4)};p.prototype.readDoubleLE=function e(t,r){t=t>>>0;if(!r)E(t,8,this.length);return a.read(this,t,true,52,8)};p.prototype.readDoubleBE=function e(t,r){t=t>>>0;if(!r)E(t,8,this.length);return a.read(this,t,false,52,8)};function I(e,t,r,i,n,a){if(!p.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>n||t<a)throw new RangeError('"value" argument is out of bounds');if(r+i>e.length)throw new RangeError("Index out of range")}p.prototype.writeUIntLE=function e(t,r,i,n){t=+t;r=r>>>0;i=i>>>0;if(!n){var a=Math.pow(2,8*i)-1;I(this,t,r,i,a,0)}var o=1;var s=0;this[r]=t&255;while(++s<i&&(o*=256)){this[r+s]=t/o&255}return r+i};p.prototype.writeUIntBE=function e(t,r,i,n){t=+t;r=r>>>0;i=i>>>0;if(!n){var a=Math.pow(2,8*i)-1;I(this,t,r,i,a,0)}var o=i-1;var s=1;this[r+o]=t&255;while(--o>=0&&(s*=256)){this[r+o]=t/s&255}return r+i};p.prototype.writeUInt8=function e(t,r,i){t=+t;r=r>>>0;if(!i)I(this,t,r,1,255,0);this[r]=t&255;return r+1};p.prototype.writeUInt16LE=function e(t,r,i){t=+t;r=r>>>0;if(!i)I(this,t,r,2,65535,0);this[r]=t&255;this[r+1]=t>>>8;return r+2};p.prototype.writeUInt16BE=function e(t,r,i){t=+t;r=r>>>0;if(!i)I(this,t,r,2,65535,0);this[r]=t>>>8;this[r+1]=t&255;return r+2};p.prototype.writeUInt32LE=function e(t,r,i){t=+t;r=r>>>0;if(!i)I(this,t,r,4,4294967295,0);this[r+3]=t>>>24;this[r+2]=t>>>16;this[r+1]=t>>>8;this[r]=t&255;return r+4};p.prototype.writeUInt32BE=function e(t,r,i){t=+t;r=r>>>0;if(!i)I(this,t,r,4,4294967295,0);this[r]=t>>>24;this[r+1]=t>>>16;this[r+2]=t>>>8;this[r+3]=t&255;return r+4};p.prototype.writeIntLE=function e(t,r,i,n){t=+t;r=r>>>0;if(!n){var a=Math.pow(2,8*i-1);I(this,t,r,i,a-1,-a)}var o=0;var s=1;var h=0;this[r]=t&255;while(++o<i&&(s*=256)){if(t<0&&h===0&&this[r+o-1]!==0){h=1}this[r+o]=(t/s>>0)-h&255}return r+i};p.prototype.writeIntBE=function e(t,r,i,n){t=+t;r=r>>>0;if(!n){var a=Math.pow(2,8*i-1);I(this,t,r,i,a-1,-a)}var o=i-1;var s=1;var h=0;this[r+o]=t&255;while(--o>=0&&(s*=256)){if(t<0&&h===0&&this[r+o+1]!==0){h=1}this[r+o]=(t/s>>0)-h&255}return r+i};p.prototype.writeInt8=function e(t,r,i){t=+t;r=r>>>0;if(!i)I(this,t,r,1,127,-128);if(t<0)t=255+t+1;this[r]=t&255;return r+1};p.prototype.writeInt16LE=function e(t,r,i){t=+t;r=r>>>0;if(!i)I(this,t,r,2,32767,-32768);this[r]=t&255;this[r+1]=t>>>8;return r+2};p.prototype.writeInt16BE=function e(t,r,i){t=+t;r=r>>>0;if(!i)I(this,t,r,2,32767,-32768);this[r]=t>>>8;this[r+1]=t&255;return r+2};p.prototype.writeInt32LE=function e(t,r,i){t=+t;r=r>>>0;if(!i)I(this,t,r,4,2147483647,-2147483648);this[r]=t&255;this[r+1]=t>>>8;this[r+2]=t>>>16;this[r+3]=t>>>24;return r+4};p.prototype.writeInt32BE=function e(t,r,i){t=+t;r=r>>>0;if(!i)I(this,t,r,4,2147483647,-2147483648);if(t<0)t=4294967295+t+1;this[r]=t>>>24;this[r+1]=t>>>16;this[r+2]=t>>>8;this[r+3]=t&255;return r+4};function P(e,t,r,i,n,a){if(r+i>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function M(e,t,r,i,n){t=+t;r=r>>>0;if(!n){P(e,t,r,4,34028234663852886e22,-34028234663852886e22)}a.write(e,t,r,i,23,4);return r+4}p.prototype.writeFloatLE=function e(t,r,i){return M(this,t,r,true,i)};p.prototype.writeFloatBE=function e(t,r,i){return M(this,t,r,false,i)};function R(e,t,r,i,n){t=+t;r=r>>>0;if(!n){P(e,t,r,8,17976931348623157e292,-17976931348623157e292)}a.write(e,t,r,i,52,8);return r+8}p.prototype.writeDoubleLE=function e(t,r,i){return R(this,t,r,true,i)};p.prototype.writeDoubleBE=function e(t,r,i){return R(this,t,r,false,i)};p.prototype.copy=function e(t,r,i,n){if(!p.isBuffer(t))throw new TypeError("argument should be a Buffer");if(!i)i=0;if(!n&&n!==0)n=this.length;if(r>=t.length)r=t.length;if(!r)r=0;if(n>0&&n<i)n=i;if(n===i)return 0;if(t.length===0||this.length===0)return 0;if(r<0){throw new RangeError("targetStart out of bounds")}if(i<0||i>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");if(n>this.length)n=this.length;if(t.length-r<n-i){n=t.length-r+i}var a=n-i;if(this===t&&typeof Uint8Array.prototype.copyWithin==="function"){this.copyWithin(r,i,n)}else if(this===t&&i<r&&r<n){for(var o=a-1;o>=0;--o){t[o+r]=this[o+i]}}else{Uint8Array.prototype.set.call(t,this.subarray(i,n),r)}return a};p.prototype.fill=function e(t,r,i,n){if(typeof t==="string"){if(typeof r==="string"){n=r;r=0;i=this.length}else if(typeof i==="string"){n=i;i=this.length}if(n!==undefined&&typeof n!=="string"){throw new TypeError("encoding must be a string")}if(typeof n==="string"&&!p.isEncoding(n)){throw new TypeError("Unknown encoding: "+n)}if(t.length===1){var a=t.charCodeAt(0);if(n==="utf8"&&a<128||n==="latin1"){t=a}}}else if(typeof t==="number"){t=t&255}if(r<0||this.length<r||this.length<i){throw new RangeError("Out of range index")}if(i<=r){return this}r=r>>>0;i=i===undefined?this.length:i>>>0;if(!t)t=0;var o;if(typeof t==="number"){for(o=r;o<i;++o){this[o]=t}}else{var s=p.isBuffer(t)?t:p.from(t,n);var h=s.length;if(h===0){throw new TypeError('The value "'+t+'" is invalid for argument "value"')}for(o=0;o<i-r;++o){this[o+r]=s[o%h]}}return this};var H=/[^+/0-9A-Za-z-_]/g;function W(e){e=e.split("=")[0];e=e.trim().replace(H,"");if(e.length<2)return"";while(e.length%4!==0){e=e+"="}return e}function q(e){if(e<16)return"0"+e.toString(16);return e.toString(16)}function _(e,t){t=t||Infinity;var r;var i=e.length;var n=null;var a=[];for(var o=0;o<i;++o){r=e.charCodeAt(o);if(r>55295&&r<57344){if(!n){if(r>56319){if((t-=3)>-1)a.push(239,191,189);continue}else if(o+1===i){if((t-=3)>-1)a.push(239,191,189);continue}n=r;continue}if(r<56320){if((t-=3)>-1)a.push(239,191,189);n=r;continue}r=(n-55296<<10|r-56320)+65536}else if(n){if((t-=3)>-1)a.push(239,191,189)}n=null;if(r<128){if((t-=1)<0)break;a.push(r)}else if(r<2048){if((t-=2)<0)break;a.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;a.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;a.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else{throw new Error("Invalid code point")}}return a}function V(e){var t=[];for(var r=0;r<e.length;++r){t.push(e.charCodeAt(r)&255)}return t}function J(e,t){var r,i,n;var a=[];for(var o=0;o<e.length;++o){if((t-=2)<0)break;r=e.charCodeAt(o);i=r>>8;n=r%256;a.push(n);a.push(i)}return a}function T(e){return i.toByteArray(W(e))}function L(e,t,r,i){for(var n=0;n<i;++n){if(n+r>=t.length||n>=e.length)break;t[n+r]=e[n]}return n}function U(e,t){return e instanceof t||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===t.name}function O(e){return e!==e}}).call(this)}).call(this,Z("buffer").Buffer)},{"base64-js":12,buffer:13,ieee754:14}],14:[function(e,t,r){r.read=function(e,t,r,i,n){var a,o;var s=n*8-i-1;var h=(1<<s)-1;var f=h>>1;var l=-7;var u=r?n-1:0;var p=r?-1:1;var c=e[t+u];u+=p;a=c&(1<<-l)-1;c>>=-l;l+=s;for(;l>0;a=a*256+e[t+u],u+=p,l-=8){}o=a&(1<<-l)-1;a>>=-l;l+=i;for(;l>0;o=o*256+e[t+u],u+=p,l-=8){}if(a===0){a=1-f}else if(a===h){return o?NaN:(c?-1:1)*Infinity}else{o=o+Math.pow(2,i);a=a-f}return(c?-1:1)*o*Math.pow(2,a-i)};r.write=function(e,t,r,i,n,a){var o,s,h;var f=a*8-n-1;var l=(1<<f)-1;var u=l>>1;var p=n===23?Math.pow(2,-24)-Math.pow(2,-77):0;var c=i?0:a-1;var g=i?1:-1;var y=t<0||t===0&&1/t<0?1:0;t=Math.abs(t);if(isNaN(t)||t===Infinity){s=isNaN(t)?1:0;o=l}else{o=Math.floor(Math.log(t)/Math.LN2);if(t*(h=Math.pow(2,-o))<1){o--;h*=2}if(o+u>=1){t+=p/h}else{t+=p*Math.pow(2,1-u)}if(t*h>=2){o++;h/=2}if(o+u>=l){s=0;o=l}else if(o+u>=1){s=(t*h-1)*Math.pow(2,n);o=o+u}else{s=t*Math.pow(2,u-1)*Math.pow(2,n);o=0}}for(;n>=8;e[r+c]=s&255,c+=g,s/=256,n-=8){}o=o<<n|s;f+=n;for(;f>0;e[r+c]=o&255,c+=g,o/=256,f-=8){}e[r+c-g]|=y*128}},{}]},{},[11])(11)});