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

flipnote.js

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flipnote.js - npm Package Compare versions

Comparing version 4.0.2 to 4.1.0

dist/component/utils.d.ts

2

dist/encoders/gif.d.ts

@@ -22,3 +22,3 @@ import { ByteArray } from '../utils/index';

writeFrame(pixels: Uint8Array): void;
getBuffer(): ArrayBuffer | SharedArrayBuffer;
getBuffer(): ArrayBufferLike;
getBlob(): Blob;

@@ -25,0 +25,0 @@ getUrl(): string;

/*!!
flipnote.js v4.0.2 (web ver)
flipnote.js v4.1.0 (web version)
Browser-based playback of .ppm and .kwz animations from Flipnote Studio and Flipnote Studio 3D

@@ -8,2 +8,2 @@ 2018 - 2020 James Daniel

*/
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t=t||self).flipnote={})}(this,function(t){"use strict";var h=[{matches:function(t){return"string"==typeof t},load:function(t,i,s){var n=new XMLHttpRequest;n.open("GET",t,!0),n.responseType="arraybuffer",n.onreadystatechange=function(t){4===n.readyState&&(200<=n.status&&n.status<300?i(n.response):s({type:"httpError",status:n.status,statusText:n.statusText}))},n.send(null)}},{matches:function(t){return"undefined"!=typeof File&&t instanceof File},load:function(t,i,s){var n;"undefined"!=typeof FileReader?((n=new FileReader).onload=function(t){i(n.result)},n.onerror=function(t){s({type:"fileReadError"})},n.readAsArrayBuffer(t)):s()}},{matches:function(t){return t instanceof ArrayBuffer},load:function(t,i,s){i(t)}}];var n=function(t,i){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var s in i)i.hasOwnProperty(s)&&(t[s]=i[s])})(t,i)};function i(t,i){function s(){this.constructor=t}n(t,i),t.prototype=null===i?Object.create(i):(s.prototype=i.prototype,new s)}function r(t,e,o,u){return new(o=o||Promise)(function(s,i){function n(t){try{r(u.next(t))}catch(t){i(t)}}function h(t){try{r(u.throw(t))}catch(t){i(t)}}function r(t){var i;t.done?s(t.value):((i=t.value)instanceof o?i:new o(function(t){t(i)})).then(n,h)}r((u=u.apply(t,e||[])).next())})}function e(s,n){var h,r,e,o={label:0,sent:function(){if(1&e[0])throw e[1];return e[1]},trys:[],ops:[]},t={next:i(0),throw:i(1),return:i(2)};return"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function i(i){return function(t){return function(i){if(h)throw new TypeError("Generator is already executing.");for(;o;)try{if(h=1,r&&(e=2&i[0]?r.return:i[0]?r.throw||((e=r.return)&&e.call(r),0):r.next)&&!(e=e.call(r,i[1])).done)return e;switch(r=0,e&&(i=[2&i[0],e.value]),i[0]){case 0:case 1:e=i;break;case 4:return o.label++,{value:i[1],done:!1};case 5:o.label++,r=i[1],i=[0];continue;case 7:i=o.ops.pop(),o.trys.pop();continue;default:if(!(e=0<(e=o.trys).length&&e[e.length-1])&&(6===i[0]||2===i[0])){o=0;continue}if(3===i[0]&&(!e||i[1]>e[0]&&i[1]<e[3])){o.label=i[1];break}if(6===i[0]&&o.label<e[1]){o.label=e[1],e=i;break}if(e&&o.label<e[2]){o.label=e[2],o.ops.push(i);break}e[2]&&o.ops.pop(),o.trys.pop();continue}i=n.call(s,o)}catch(t){i=[6,t],r=0}finally{h=e=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,t])}}}var s=(o.prototype.newPage=function(){this.pages[++this.page]=new Uint8Array(o.pageSize),this.cursor=0},o.prototype.getData=function(){var s=this,n=new Uint8Array(this.page*o.pageSize+this.cursor);return this.pages.map(function(t,i){i===s.page?n.set(t.slice(0,s.cursor),i*o.pageSize):n.set(t,i*o.pageSize)}),n},o.prototype.getBuffer=function(){return this.getData().buffer},o.prototype.writeByte=function(t){this.cursor>=o.pageSize&&this.newPage(),this.pages[this.page][this.cursor++]=t},o.prototype.writeBytes=function(t,i,s){for(var n=s||t.length,h=i||0;h<n;h++)this.writeByte(t[h])},o.pageSize=4096,o);function o(){this.page=-1,this.pages=[],this.cursor=0,this.newPage()}var u,f,a=(Object.defineProperty(c.prototype,"bytes",{get:function(){return new Uint8Array(this.buffer)},enumerable:!1,configurable:!0}),Object.defineProperty(c.prototype,"byteLength",{get:function(){return this.data.byteLength},enumerable:!1,configurable:!0}),c.prototype.seek=function(t,i){switch(i){case 2:this.cursor=this.data.byteLength+t;break;case 1:this.cursor+=t;break;case 0:default:this.cursor=t}},c.prototype.readUint8=function(){var t=this.data.getUint8(this.cursor);return this.cursor+=1,t},c.prototype.writeUint8=function(t){this.data.setUint8(this.cursor,t),this.cursor+=1},c.prototype.readInt8=function(){var t=this.data.getInt8(this.cursor);return this.cursor+=1,t},c.prototype.writeInt8=function(t){this.data.setInt8(this.cursor,t),this.cursor+=1},c.prototype.readUint16=function(t){void 0===t&&(t=!0);var i=this.data.getUint16(this.cursor,t);return this.cursor+=2,i},c.prototype.writeUint16=function(t,i){void 0===i&&(i=!0),this.data.setUint16(this.cursor,t,i),this.cursor+=2},c.prototype.readInt16=function(t){void 0===t&&(t=!0);var i=this.data.getInt16(this.cursor,t);return this.cursor+=2,i},c.prototype.writeInt16=function(t,i){void 0===i&&(i=!0),this.data.setInt16(this.cursor,t,i),this.cursor+=2},c.prototype.readUint32=function(t){void 0===t&&(t=!0);var i=this.data.getUint32(this.cursor,t);return this.cursor+=4,i},c.prototype.writeUint32=function(t,i){void 0===i&&(i=!0),this.data.setUint32(this.cursor,t,i),this.cursor+=4},c.prototype.readInt32=function(t){void 0===t&&(t=!0);var i=this.data.getInt32(this.cursor,t);return this.cursor+=4,i},c.prototype.writeInt32=function(t,i){void 0===i&&(i=!0),this.data.setInt32(this.cursor,t,i),this.cursor+=4},c.prototype.readBytes=function(t){var i=new Uint8Array(this.data.buffer,this.cursor,t);return this.cursor+=i.byteLength,i},c.prototype.writeBytes=function(t){var i=this;t.forEach(function(t){return i.writeUint8(t)})},c.prototype.readHex=function(t,i){void 0===i&&(i=!1);for(var s=this.readBytes(t),n=[],h=0;h<s.length;h++)n.push(s[h].toString(16).padStart(2,"0"));return i&&n.reverse(),n.join("").toUpperCase()},c.prototype.readUtf8=function(t){for(var i=this.readBytes(t),s="",n=0;n<i.length;n++){var h=i[n];if(0===h)break;s+=String.fromCharCode(h)}return s},c.prototype.writeUtf8=function(t){for(var i=0;i<t.length;i++){var s=t.charCodeAt(i);this.writeUint8(s)}},c.prototype.readUtf16=function(t){for(var i=new Uint16Array(this.data.buffer,this.cursor,t),s="",n=0;n<i.length;n++){var h=i[n];if(0==h)break;s+=String.fromCharCode(h)}return this.cursor+=i.byteLength,s},c);function c(t){this.buffer=t,this.data=new DataView(t),this.cursor=0}(f=u=u||{})[f.BGM=0]="BGM",f[f.SE1=1]="SE1",f[f.SE2=2]="SE2",f[f.SE3=3]="SE3",f[f.SE4=4]="SE4";var v,l=(i(w,v=a),w.prototype.hasAudioTrack=function(t){return!!(this.soundMeta.hasOwnProperty(t)&&0<this.soundMeta[t].length)},w.prototype.getInt16AudioData=function(t){return this.decodeAudio(t)},w.prototype.getFloat32AudioData=function(t){for(var i=this.decodeAudio(t),s=new Float32Array(i.length),n=0;n<i.length;n++)s[n]=i[n]/32767;return s},w);function w(){return null!==v&&v.apply(this,arguments)||this}for(var d=new Int8Array([-1,2,-1,2]),y=new Int8Array([-1,-1,-1,-1,2,4,6,8,-1,-1,-1,-1,2,4,6,8]),m=new Int16Array([7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50,55,60,66,73,80,88,97,107,118,130,143,157,173,190,209,230,253,279,307,337,371,408,449,494,544,598,658,724,796,876,963,1060,1166,1282,1411,1552,1707,1878,2066,2272,2499,2749,3024,3327,3660,4026,4428,4871,5358,5894,6484,7132,7845,8630,9493,10442,11487,12635,13899,15289,16818,18500,20350,22385,24623,27086,29794,32767,0]),b=new Int16Array(360),g=0;g<4;g++)for(var A=0;A<90;A++){var _=(U=m[A])>>3;1&g&&(_+=U),2&g&&(_=-_),b[g+4*A]=_}for(var p=new Int16Array(1440),g=0;g<16;g++)for(A=0;A<90;A++){var U,_=(U=m[A])>>3;4&g&&(_+=U),2&g&&(_+=U>>1),1&g&&(_+=U>>2),8&g&&(_=-_),p[g+16*A]=_}var x,E=[null,.5,1,2,4,6,12,20,30],S={WHITE:[255,255,255],BLACK:[14,14,14],RED:[255,42,42],BLUE:[10,57,255]},F=(i(k,x=l),k.validateFSID=function(t){return/[0159]{1}[0-9A-F]{6}0[0-9A-F]{8}/.test(t)},k.validateFilename=function(t){return/[0-9A-F]{6}_[0-9A-F]{13}_[0-9]{3}/.test(t)},k.prototype.readFilename=function(){return[this.readHex(3),this.readUtf8(13),this.readUint16().toString().padStart(3,"0")].join("_")},k.prototype.readLineEncoding=function(){for(var t=new Uint8Array(k.height),i=0;i<48;i++)for(var s=this.readUint8(),n=0;n<8;n+=2)t[4*i+n/2]=s>>n&3;return t},k.prototype.decodeHeader=function(){this.seek(0),this.readUint32(),this.frameDataLength=this.readUint32(),this.soundDataLength=this.readUint32(),this.frameCount=this.readUint16()+1,this.version=this.readUint16()},k.prototype.decodeMeta=function(){this.seek(16);var t=this.readUint16(),i=this.readInt16(),s=this.readUtf16(11),n=this.readUtf16(11),h=this.readUtf16(11),r=this.readHex(8,!0),e=this.readHex(8,!0),o=this.readFilename(),u=this.readFilename(),f=this.readHex(8,!0);this.seek(154);var a=new Date(1e3*(this.readUint32()+946684800));this.seek(1702);var c=this.readUint16();this.thumbFrameIndex=i,this.meta={lock:1===t,loop:1==(c>>1&1),frame_count:this.frameCount,frame_speed:this.frameSpeed,bgm_speed:this.bgmSpeed,thumb_index:i,timestamp:a,spinoff:e!==r||e!==f,root:{filename:null,username:s,fsid:f},parent:{username:n,fsid:r,filename:o},current:{username:h,fsid:e,filename:u}}},k.prototype.decodeAnimationHeader=function(){var i=this;this.seek(1696);var s=this.readUint16();this.seek(1704),this.frameOffsets=new Uint32Array(s/4).map(function(t){return 1704+s+i.readUint32()})},k.prototype.decodeSoundHeader=function(){var t,i=1696+this.frameDataLength+this.frameCount;i%4!=0&&(i+=4-i%4),this.seek(i);var s=this.readUint32(),n=this.readUint32(),h=this.readUint32(),r=this.readUint32();this.frameSpeed=8-this.readUint8(),this.bgmSpeed=8-this.readUint8(),i+=32,this.framerate=E[this.frameSpeed],this.bgmrate=E[this.bgmSpeed],this.soundMeta=((t={})[u.BGM]={offset:i,length:s},t[u.SE1]={offset:i+=s,length:n},t[u.SE2]={offset:i+=n,length:h},t[u.SE3]={offset:i+=h,length:r},t)},k.prototype.isNewFrame=function(t){return this.seek(this.frameOffsets[t]),this.readUint8()>>7&1},k.prototype.getLayerOrder=function(t){return[0,1]},k.prototype.decodeFrame=function(t){0===t||this.prevDecodedFrame===t-1||this.isNewFrame(t)||this.decodeFrame(t-1),this.seek(this.frameOffsets[t]);var i=this.readUint8(),s=i>>7&1,n=i>>5&3,h=0,r=0;this.prevLayers[0].set(this.layers[0]),this.prevLayers[1].set(this.layers[1]),this.prevDecodedFrame=t,this.layers[0].fill(0),this.layers[1].fill(0),n&&(h=this.readInt8(),r=this.readInt8());for(var e=[this.readLineEncoding(),this.readLineEncoding()],o=0;o<2;o++)for(var u=this.layers[o],f=0;f<k.height;f++){var a=e[o][f],c=f*k.width;switch(a){case 0:break;case 1:case 2:var v=this.readUint32(!1);for(2==a&&u.fill(255,c,c+k.width);4294967295&v;){if(2147483648&v)for(var l=this.readUint8(),w=0;w<8;w++)u[c+w]=l>>w&1?255:0;c+=8,v<<=1}break;case 3:for(;c<(f+1)*k.width;){for(l=this.readUint8(),w=0;w<8;w++)u[c+w]=l>>w&1?255:0;c+=8}}}if(!s)for(var d=void 0,y=void 0,m=0;m<k.height;m++)if(!(m-r<0)){if(k.height<=m-r)break;for(var b=0;b<k.width;b++)if(!(b-h<0)){if(k.width<=b-h)break;y=(d=b+m*k.width)-(h+r*k.width),this.layers[0][d]^=this.prevLayers[0][y],this.layers[1][d]^=this.prevLayers[1][y]}}return this.layers},k.prototype.getFramePaletteIndices=function(t){this.seek(this.frameOffsets[t]);var i=this.readUint8(),s=1!=(1&i),n=[s?0:1,s?0:1,2,3];return[s?1:0,n[i>>1&3],n[i>>3&3]]},k.prototype.getFramePalette=function(t){var i=this;return this.getFramePaletteIndices(t).map(function(t){return i.globalPalette[t]})},k.prototype.getLayerPixels=function(t,i){this.prevDecodedFrame!==t&&this.decodeFrame(t);for(var s=this.getFramePaletteIndices(t),n=this.layers[i],h=new Uint8Array(k.width*k.height),r=s[i+1],e=0;e<h.length;e++)0!==n[e]&&(h[e]=r);return h},k.prototype.getFramePixels=function(t){var i=this.getFramePaletteIndices(t),s=this.decodeFrame(t),n=new Uint8Array(k.width*k.height);n.fill(i[0]);for(var h=0;h<n.length;h++){var r=s[0][h],e=s[1][h];0!==r?n[h]=i[1]:0!==e&&(n[h]=i[2])}return n},k.prototype.decodeAudio=function(t){for(var i,s,n,h=this.soundMeta[t],r=new Uint8Array(this.buffer,h.offset,h.length),e=new Int16Array(2*r.length),o=0,u=0,f=0,a=0;a<r.length;a++)for(var c=r[a],v=0;v<8;)s=u+p[(i=c>>v&15)+16*f],n=f+y[i],n=Math.max(0,Math.min(n,79)),s=Math.max(-32767,Math.min(s,32767)),e[o]=s,o+=1,f=n,u=s,v+=4;return e},k.prototype.decodeSoundFlags=function(){var s=this;return this.seek(1696+this.frameDataLength),new Array(this.frameCount).fill([]).map(function(t){var i=s.readUint8();return[1&i,i>>1&1,i>>2&1]})},k.type="PPM",k.width=256,k.height=192,k.sampleRate=8192,k.globalPalette=[S.WHITE,S.BLACK,S.RED,S.BLUE],k);function k(t){var i=x.call(this,t)||this;return i.type=k.type,i.width=k.width,i.height=k.height,i.globalPalette=k.globalPalette,i.sampleRate=k.sampleRate,i.prevDecodedFrame=null,i.decodeHeader(),i.decodeAnimationHeader(),i.decodeSoundHeader(),i.decodeMeta(),i.layers=[new Uint8Array(k.width*k.height),new Uint8Array(k.width*k.height)],i.prevLayers=[new Uint8Array(k.width*k.height),new Uint8Array(k.width*k.height)],i.prevDecodedFrame=null,i}for(var M=new Uint16Array(52488),I=[0,65280,255],O=0,j=0;j<3;j++)for(var L=0;L<3;L++)for(var B=0;B<3;B++)for(var P=0;P<3;P++)for(var W=0;W<3;W++)for(var R=0;R<3;R++)for(var z=0;z<3;z++)for(var D=0;D<3;D++)M.set([I[L],I[j],I[P],I[B],I[R],I[W],I[D],I[z]],O),O+=8;for(var G=new Uint16Array(52488),O=0,j=0;j<2187;j+=729)for(L=0;L<729;L+=243)for(B=0;B<243;B+=81)for(P=0;P<81;P+=27)for(W=0;W<27;W+=9)for(R=0;R<9;R+=3)for(z=0;z<3;z+=1)for(D=0;D<6561;D+=2187){var C=j+L+B+P+W+R+z+D,T=M.subarray(8*C,8*C+8);G.set(T,O),O+=8}var K=new Uint16Array(256);[0,3280,6560,729,2187,81,243,9,27,1,3,1458,4374,162,486,18,54,2,6,2916,2268,324,252,36,28,4,820,2460,1640,4920,4100,5740].forEach(function(t,i){var s=M.subarray(8*t,8*t+8);K.set(s,8*i)});var N=new Uint16Array(256);[0,3280,6560,3,729,2187,81,243,9,27,1,6,1458,4374,162,486,18,54,2,732,2916,2268,324,252,36,28,2460,820,4920,1640,5740,4100].forEach(function(t,i){var s=M.subarray(8*t,8*t+8);N.set(s,8*i)});var q,H=[.2,.5,1,2,4,6,8,12,20,24,30],Y={WHITE:[255,255,255],BLACK:[16,16,16],RED:[255,16,16],YELLOW:[255,231,0],GREEN:[0,134,49],BLUE:[0,56,206],NONE:[255,255,255]},V=(i(Z,q=l),Z.prototype.load=function(){this.seek(0),this.sections={},this.frameMeta=[];for(var t=this.byteLength-256,i=0,s=0;i<t&&s<6;){this.seek(i);var n=this.readUtf8(4).substring(0,3),h=this.readUint32();this.sections[n]={offset:i,length:h},i+=h+8,s+=1}this.decodeMeta(),this.decodeFrameMeta(),this.decodeSoundHeader()},Z.prototype.readBits=function(t){var i;16<this.bitIndex+t&&(i=this.readUint16(),this.bitValue|=i<<16-this.bitIndex,this.bitIndex-=16);var s=(1<<t)-1,n=this.bitValue&s;return this.bitValue>>=t,this.bitIndex+=t,n},Z.prototype.decodeMeta=function(){this.seek(this.sections.KFH.offset+12);var t=new Date(1e3*(this.readUint32()+946684800)),i=new Date(1e3*(this.readUint32()+946684800)),s=(this.readUint32(),this.readHex(10)),n=this.readHex(10),h=this.readHex(10),r=this.readUtf16(11),e=this.readUtf16(11),o=this.readUtf16(11),u=this.readUtf8(28),f=this.readUtf8(28),a=this.readUtf8(28),c=this.readUint16(),v=this.readUint16(),l=this.readUint16(),w=this.readUint8();this.readUint8(),this.frameCount=c,this.thumbFrameIndex=v,this.frameSpeed=w,this.framerate=H[w],this.meta={lock:1==(1&l),loop:1==(l>>1&1),frame_count:c,frame_speed:w,thumb_index:v,timestamp:i,creation_timestamp:t,root:{username:r,fsid:s,filename:u},parent:{username:e,fsid:n,filename:f},current:{username:o,fsid:h,filename:a}}},Z.prototype.decodeFrameMeta=function(){this.frameOffsets=new Uint32Array(this.frameCount),this.seek(this.sections.KMI.offset+8);for(var t=this.sections.KMC.offset+12,i=0;i<this.frameCount;i++){var s={flags:this.readUint32(),layerSize:[this.readUint16(),this.readUint16(),this.readUint16()],frameAuthor:this.readHex(10),layerDepth:[this.readUint8(),this.readUint8(),this.readUint8()],soundFlags:this.readUint8(),cameraFlag:this.readUint32()};this.frameMeta.push(s),this.frameOffsets[i]=t,t+=s.layerSize[0]+s.layerSize[1]+s.layerSize[2]}},Z.prototype.decodeSoundHeader=function(){var t,i,s,n;this.sections.hasOwnProperty("KSN")&&(i=this.sections.KSN.offset+8,this.seek(i),s=this.readUint32(),this.bgmSpeed=s,this.bgmrate=H[s],n=new Uint32Array(this.buffer,i+4,20),this.soundMeta=((t={})[u.BGM]={offset:i+=28,length:n[0]},t[u.SE1]={offset:i+=n[0],length:n[1]},t[u.SE2]={offset:i+=n[1],length:n[2]},t[u.SE3]={offset:i+=n[2],length:n[3]},t[u.SE4]={offset:i+=n[3],length:n[4]},t))},Z.prototype.getDiffingFlag=function(t){return 7&~(this.frameMeta[t].flags>>4)},Z.prototype.getLayerDepths=function(t){return this.frameMeta[t].layerDepth},Z.prototype.getLayerOrder=function(t){var s=this.getLayerDepths(t);return[2,1,0].sort(function(t,i){return s[i]-s[t]})},Z.prototype.decodeFrame=function(t,i,s){void 0===i&&(i=7),void 0===s&&(s=!1),s&&(i&=this.getDiffingFlag(t+1)),0!==t&&this.prevDecodedFrame!==t-1&&i&&this.decodeFrame(t-1,i,s=!0);for(var n=this.frameMeta[t],h=this.frameOffsets[t],r=0;r<3;r++){this.seek(h);var e=n.layerSize[r];if(h+=e,38!==e&&0!=(i>>r&1)){this.bitIndex=16;for(var o=this.bitValue=0,u=0;u<Z.height;u+=128)for(var f=0;f<Z.width;f+=128)for(var a=0;a<128;a+=8){var c=u+a;if(Z.height<=c)break;for(var v=0;v<128;v+=8){var l=f+v;if(Z.width<=l)break;if(o)--o;else{var w,d,y,m=c*Z.width+l,b=this.layers[r],g=this.readBits(3);if(0==g){var A=this.readBits(5),_=K.subarray(8*A,8*A+8);b.set(_,m),b.set(_,m+320),b.set(_,m+640),b.set(_,m+960),b.set(_,m+1280),b.set(_,m+1600),b.set(_,m+1920),b.set(_,m+2240)}else if(1==g)A=this.readBits(13),_=M.subarray(8*A,8*A+8),b.set(_,m),b.set(_,m+320),b.set(_,m+640),b.set(_,m+960),b.set(_,m+1280),b.set(_,m+1600),b.set(_,m+1920),b.set(_,m+2240);else if(2==g){var p=this.readBits(5),U=K.subarray(8*p,8*p+8),x=N.subarray(8*p,8*p+8);b.set(U,m),b.set(x,m+320),b.set(U,m+640),b.set(x,m+960),b.set(U,m+1280),b.set(x,m+1600),b.set(U,m+1920),b.set(x,m+2240)}else if(3==g){var p=this.readBits(13),U=M.subarray(8*p,8*p+8),x=G.subarray(8*p,8*p+8);b.set(U,m),b.set(x,m+320),b.set(U,m+640),b.set(x,m+960),b.set(U,m+1280),b.set(x,m+1600),b.set(U,m+1920),b.set(x,m+2240)}else if(4==g)for(var E=this.readBits(8),S=0;S<8;S++)_=E&1<<S?(A=this.readBits(5),K.subarray(8*A,8*A+8)):(A=this.readBits(13),M.subarray(8*A,8*A+8)),b.set(_,m+320*S);else{if(5==g){o=this.readBits(5);continue}7==g&&(w=this.readBits(2),x=U=void 0,this.readBits(1)?(d=this.readBits(5),y=this.readBits(5),U=K.subarray(8*d,8*d+8),x=K.subarray(8*y,8*y+8),w=(w+1)%4):(d=this.readBits(13),y=this.readBits(13),U=M.subarray(8*d,8*d+8),x=M.subarray(8*y,8*y+8)),0==w?(b.set(U,m),b.set(x,m+320),b.set(U,m+640),b.set(x,m+960),b.set(U,m+1280),b.set(x,m+1600),b.set(U,m+1920),b.set(x,m+2240)):1==w?(b.set(U,m),b.set(U,m+320),b.set(x,m+640),b.set(U,m+960),b.set(U,m+1280),b.set(x,m+1600),b.set(U,m+1920),b.set(U,m+2240)):2==w?(b.set(U,m),b.set(x,m+320),b.set(U,m+640),b.set(U,m+960),b.set(x,m+1280),b.set(U,m+1600),b.set(U,m+1920),b.set(x,m+2240)):3==w&&(b.set(U,m),b.set(x,m+320),b.set(x,m+640),b.set(U,m+960),b.set(x,m+1280),b.set(x,m+1600),b.set(U,m+1920),b.set(x,m+2240)))}}}}}}return this.prevDecodedFrame=t,[new Uint8Array(this.layers[0].buffer),new Uint8Array(this.layers[1].buffer),new Uint8Array(this.layers[2].buffer)]},Z.prototype.getFramePaletteIndices=function(t){var i=this.frameMeta[t].flags;return[15&i,i>>8&15,i>>12&15,i>>16&15,i>>20&15,i>>24&15,i>>28&15]},Z.prototype.getFramePalette=function(t){var i=this;return this.getFramePaletteIndices(t).map(function(t){return i.globalPalette[t]})},Z.prototype.getLayerPixels=function(t,i){this.prevDecodedFrame!==t&&this.decodeFrame(t);for(var s=this.getFramePaletteIndices(t),n=this.layers[i],h=new Uint8Array(Z.width*Z.height),r=2*i+1,e=0;e<n.length;e++){var o=n[e];65280&o?h[e]=s[r]:255&o&&(h[e]=s[1+r])}return h},Z.prototype.getFramePixels=function(h){var r=this,t=this.getFramePaletteIndices(h),e=new Uint8Array(Z.width*Z.height);return e.fill(t[0]),this.getLayerOrder(h).forEach(function(t){for(var i=r.getLayerPixels(h,t),s=0;s<i.length;s++){var n=i[s];0!==n&&(e[s]=n)}}),e},Z.prototype.decodeSoundFlags=function(){return this.frameMeta.map(function(t){var i=t.soundFlags;return[1&i,i>>1&1,i>>2&1,i>>3&1]})},Z.prototype.decodeAudio=function(t){for(var i,s,n,h=this.soundMeta[t],r=new Uint8Array(this.buffer,h.offset,h.length),e=new Int16Array(981840),o=0,u=0,f=40,a=0;a<r.length;a++)for(var c=r[a],v=0;v<8;)f<18||6==v?(s=u+b[(i=c>>v&3)+4*f],n=f+d[i],v+=2):(s=u+p[(i=c>>v&15)+16*f],n=f+y[i],v+=4),n=Math.max(0,Math.min(n,79)),s=Math.max(-2048,Math.min(s,2048)),e[o]=16*s,o+=1,f=n,u=s;return e.slice(0,o)},Z.type="KWZ",Z.width=320,Z.height=240,Z.sampleRate=16364,Z.globalPalette=[Y.WHITE,Y.BLACK,Y.RED,Y.YELLOW,Y.GREEN,Y.BLUE,Y.NONE],Z);function Z(t){var i=q.call(this,t)||this;return i.type=Z.type,i.width=Z.width,i.height=Z.height,i.globalPalette=Z.globalPalette,i.sampleRate=Z.sampleRate,i.prevDecodedFrame=null,i.bitIndex=0,i.bitValue=0,i.layers=[new Uint16Array(Z.width*Z.height),new Uint16Array(Z.width*Z.height),new Uint16Array(Z.width*Z.height)],i.bitIndex=0,i.bitValue=0,i.load(),i}function X(t){return n=t,new Promise(function(i,s){h.forEach(function(t){t.matches(n)&&t.load(n,i,s)})}).then(function(h){return new Promise(function(t,i){var s=new Uint8Array(h.slice(0,4)),n=s[0]<<24|s[1]<<16|s[2]<<8|s[3];1346458177==n?t(new F(h)):1262897152==(4294967040&n)?t(new V(h)):i()})});var n}var J=(Q.prototype.writeFrames=function(t){var i=this.header;i.seek(4),i.writeUint32(i.byteLength+t.byteLength),i.seek(40),i.writeUint32(t.byteLength),this.pcmData=t},Q.prototype.getBlob=function(){return new Blob([this.header.buffer,this.pcmData.buffer],{type:"audio/wav"})},Q);function Q(t,i,s){void 0===i&&(i=1),void 0===s&&(s=16),this.sampleRate=t,this.channels=i,this.bitsPerSample=s;var n=new ArrayBuffer(44),h=new a(n);h.writeUtf8("RIFF"),h.writeUint32(0),h.writeUtf8("WAVE"),h.writeUtf8("fmt "),h.writeUint32(16),h.writeUint16(1),h.writeUint16(this.channels),h.writeUint32(this.sampleRate),h.writeUint32(this.sampleRate*this.bitsPerSample*this.channels/8),h.writeUint16(this.bitsPerSample*this.channels/8),h.writeUint16(this.bitsPerSample),h.writeUtf8("data"),h.writeUint32(0),this.header=h,this.pcmData=null}var $=(tt.prototype.set=function(t,i){var s=new J(this.sampleRate*i,this.channelCount,this.bitsPerSample);s.writeFrames(t),this.url=window.URL.createObjectURL(s.getBlob()),this.audio.src=this.url,this.isActive=!0,this.playbackRate=i,this.length=t.length},Object.defineProperty(tt.prototype,"duration",{get:function(){return this.audio.duration},enumerable:!1,configurable:!0}),tt.prototype.unset=function(){this.isActive&&(window.URL.revokeObjectURL(this.url),this.audio.src="",this.audio.load(),this.isActive=!1,this.playbackRate=1,this.length=null)},tt.prototype.start=function(t){void 0===t&&(t=0),this.isActive&&(this.audio.currentTime=t,this.audio.play())},tt.prototype.stop=function(){this.isActive&&this.audio.pause()},tt);function tt(t){this.playbackRate=1,this.id=t,this.channelCount=1,this.bitsPerSample=16,this.sampleRate=0,this.audio=document.createElement("audio"),this.audio.preload="auto",this.isActive=!1}var it,st;(st=it=it||{})[st.Alpha=WebGLRenderingContext.ALPHA]="Alpha",st[st.LuminanceAlpha=WebGLRenderingContext.LUMINANCE_ALPHA]="LuminanceAlpha";var nt=(ht.prototype.createProgram=function(){var t=this.gl,i=t.createProgram();if(t.attachShader(i,this.createShader(t.VERTEX_SHADER,"#define GLSLIFY 1\nattribute vec4 a_position;varying vec2 v_texel;varying float v_scale;uniform vec2 u_textureSize;uniform vec2 u_screenSize;void main(){gl_Position=a_position;vec2 uv=a_position.xy*vec2(0.5,-0.5)+0.5;v_texel=uv*u_textureSize;v_scale=floor(u_screenSize.y/u_textureSize.y+0.01);}")),t.attachShader(i,this.createShader(t.FRAGMENT_SHADER,"precision highp float;\n#define GLSLIFY 1\nvarying vec2 v_texel;varying float v_scale;uniform vec4 u_color1;uniform vec4 u_color2;uniform sampler2D u_bitmap;uniform bool u_isSmooth;uniform vec2 u_textureSize;uniform vec2 u_screenSize;void main(){vec2 texel_floored=floor(v_texel);vec2 s=fract(v_texel);float region_range=0.5-0.5/v_scale;vec2 center_dist=s-0.5;vec2 f=(center_dist-clamp(center_dist,-region_range,region_range))*v_scale+0.5;vec2 mod_texel=texel_floored+f;vec2 coord=mod_texel.xy/u_textureSize.xy;vec2 colorWeights=texture2D(u_bitmap,coord).ra;gl_FragColor=vec4(u_color1.rgb,1.0)*colorWeights.y+vec4(u_color2.rgb,1.0)*colorWeights.x;}")),t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)){var s=t.getProgramInfoLog(i);throw t.deleteProgram(i),new Error(s)}t.useProgram(i);for(var n=t.getProgramParameter(i,t.ACTIVE_UNIFORMS),h=0;h<n;h++){var r=t.getActiveUniform(i,h).name;this.uniforms[r]=t.getUniformLocation(i,r)}this.program=i},ht.prototype.createScreenQuad=function(){var t=this.gl,i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,new Float32Array([1,1,-1,1,-1,-1,1,1,-1,-1,1,-1]),t.STATIC_DRAW),t.enableVertexAttribArray(0),t.vertexAttribPointer(0,2,t.FLOAT,!1,0,0),this.refs.buffers.push(i)},ht.prototype.createBitmapTexture=function(){var t=this.gl;t.activeTexture(t.TEXTURE0);var i=t.createTexture();t.bindTexture(t.TEXTURE_2D,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.uniform1i(this.uniforms.u_bitmap,0),this.refs.textures.push(i)},ht.prototype.createShader=function(t,i){var s=this.gl,n=s.createShader(t);if(s.shaderSource(n,i),s.compileShader(n),s.getShaderParameter(n,s.COMPILE_STATUS))return this.refs.shaders.push(n),n;var h=s.getShaderInfoLog(n);throw s.deleteShader(n),new Error(h)},ht.prototype.setInputSize=function(t,i){this.gl.uniform2f(this.uniforms.u_textureSize,t,i)},ht.prototype.setCanvasSize=function(t,i){this.gl.uniform2f(this.uniforms.u_screenSize,t,i),this.el.width=t,this.el.height=i,this.width=t,this.height=i,this.gl.viewport(0,0,t,i)},ht.prototype.setLayerType=function(t){this.textureType=t},ht.prototype.toImage=function(t){return this.el.toDataURL(t)},ht.prototype.setColor=function(t,i){this.gl.uniform4f(this.uniforms[t],i[0]/255,i[1]/255,i[2]/255,1)},ht.prototype.setPaperColor=function(t){this.gl.clearColor(t[0]/255,t[1]/255,t[2]/255,1)},ht.prototype.drawLayer=function(t,i,s,n,h){var r=this.gl;r.texImage2D(r.TEXTURE_2D,0,this.textureType,i,s,0,this.textureType,r.UNSIGNED_BYTE,t),this.setColor("u_color1",n),this.setColor("u_color2",h),r.drawArrays(r.TRIANGLES,0,6)},ht.prototype.resize=function(t,i){void 0===t&&(t=640),void 0===i&&(i=480),this.setCanvasSize(t,i)},ht.prototype.clear=function(){this.gl.clear(this.gl.COLOR_BUFFER_BIT)},ht.prototype.destroy=function(){var t=this.refs,i=this.gl;t.shaders.forEach(function(t){i.deleteShader(t)}),t.shaders=[],t.textures.forEach(function(t){i.deleteTexture(t)}),t.textures=[],t.buffers.forEach(function(t){i.deleteBuffer(t)}),t.buffers=[],i.deleteProgram(this.program),i.canvas.width=1,i.canvas.height=1},ht);function ht(t,i,s,n){void 0===i&&(i=640),void 0===s&&(s=480),void 0===n&&(n={antialias:!1,alpha:!1}),this.uniforms={},this.refs={shaders:[],textures:[],buffers:[]};var h=t.getContext("webgl",n);this.el=t,this.gl=h,this.width=t.width=i,this.height=t.height=s,this.createProgram(),this.createScreenQuad(),this.createBitmapTexture(),this.setCanvasSize(this.width,this.height),h.enable(h.BLEND),h.blendEquation(h.FUNC_ADD),h.blendFunc(h.ONE,h.ONE_MINUS_SRC_ALPHA)}var rt=(Object.defineProperty(et.prototype,"currentFrame",{get:function(){return this.t},set:function(t){this.setFrame(t)},enumerable:!1,configurable:!0}),Object.defineProperty(et.prototype,"currentTime",{get:function(){return this.isOpen?this.i:null},set:function(t){this.isOpen&&t<=this.duration&&0<=t&&(this.setFrame(Math.round(t/(1/this.framerate))),this.i=t,this.emit("progress",this.progress))},enumerable:!1,configurable:!0}),Object.defineProperty(et.prototype,"progress",{get:function(){return this.isOpen?this.currentTime/this.duration*100:0},set:function(t){this.currentTime=this.duration*(t/100)},enumerable:!1,configurable:!0}),Object.defineProperty(et.prototype,"volume",{get:function(){return this.audioTracks[3].audio.volume},set:function(t){for(var i=0;i<this.audioTracks.length;i++)this.audioTracks[i].audio.volume=t},enumerable:!1,configurable:!0}),Object.defineProperty(et.prototype,"muted",{get:function(){return this.audioTracks[3].audio.muted},set:function(t){for(var i=0;i<this.audioTracks.length;i++)this.audioTracks[i].audio.muted=t},enumerable:!1,configurable:!0}),Object.defineProperty(et.prototype,"framerate",{get:function(){return this.note.framerate},enumerable:!1,configurable:!0}),Object.defineProperty(et.prototype,"frameCount",{get:function(){return this.note.frameCount},enumerable:!1,configurable:!0}),Object.defineProperty(et.prototype,"frameSpeed",{get:function(){return this.note.frameSpeed},enumerable:!1,configurable:!0}),Object.defineProperty(et.prototype,"audiorate",{get:function(){return 1/this.note.bgmrate/(1/this.note.framerate)},enumerable:!1,configurable:!0}),et.prototype.open=function(s){return r(this,void 0,void 0,function(){var i=this;return e(this,function(t){return this.isOpen&&this.close(),[2,X(s).then(function(t){i.load(t)}).catch(function(t){i.emit("error",t),console.error("Error loading Flipnote:",t)})]})})},et.prototype.close=function(){this.pause(),this.note=null,this.isOpen=!1,this.paused=!0,this.loop=null,this.meta=null,this.t=null,this.i=null,this.duration=null,this.loop=null;for(var t=0;t<this.audioTracks.length;t++)this.audioTracks[t].unset();this.seFlags=null,this.hasPlaybackStarted=null,this.canvas.clear()},et.prototype.load=function(i){var n=this;this.note=i,this.meta=i.meta,this.type=i.type,this.loop=i.meta.loop,this.duration=this.note.frameCount*(1/this.note.framerate),this.paused=!0,this.isOpen=!0,this.audioTracks.forEach(function(t){t.sampleRate=i.sampleRate}),[u.SE1,u.SE2,u.SE3,u.SE4,u.BGM].forEach(function(t,i){var s=t===u.BGM?n.audiorate:1;n.note.hasAudioTrack(t)&&n.audioTracks[i].set(n.note.decodeAudio(t),s)}),this.seFlags=this.note.decodeSoundFlags(),this.hasPlaybackStarted=!1,this.layerVisibility={1:!0,2:!0,3:!0},this.canvas.setInputSize(i.width,i.height),this.canvas.setLayerType("PPM"===this.type?it.Alpha:it.LuminanceAlpha),this.setFrame(this.note.thumbFrameIndex),this.i=0,this.emit("load")},et.prototype.play=function(){var n=this;if(!this.isOpen||!this.paused)return null;this.hasPlaybackStarted&&(this.loop||this.currentFrame!=this.frameCount-1)||(this.i=0),this.paused=!1,this.playBgm();var h=performance.now()/1e3-this.currentTime,r=function(t){if(n.paused)return n.stopAudio(),null;var i=t/1e3,s=i-h;s>n.duration?n.loop?(n.currentTime=0,n.playBgm(),h=i,n.emit("playback:loop")):(n.pause(),n.emit("playback:end")):n.currentTime=s,requestAnimationFrame(r)};requestAnimationFrame(r),this.hasPlaybackStarted=!0,this.emit("playback:start")},et.prototype.pause=function(){if(!this.isOpen||this.paused)return null;this.paused=!0,this.stopAudio(),this.emit("playback:stop")},et.prototype.setFrame=function(t){this.isOpen&&t!==this.currentFrame&&(t=Math.max(0,Math.min(Math.floor(t),this.frameCount-1)),this.drawFrame(t),this.t=t,this.paused?(this.i=t*(1/this.framerate),this.emit("progress",this.progress)):this.playFrameSe(t),this.emit("frame:update",this.currentFrame))},et.prototype.nextFrame=function(){this.loop&&this.currentFrame>=this.frameCount-1?this.currentFrame=0:this.currentFrame+=1},et.prototype.prevFrame=function(){this.loop&&this.currentFrame<=0?this.currentFrame=this.frameCount-1:--this.currentFrame},et.prototype.lastFrame=function(){this.currentFrame=this.frameCount-1},et.prototype.firstFrame=function(){this.currentFrame=0},et.prototype.thumbnailFrame=function(){this.currentFrame=this.note.thumbFrameIndex},et.prototype.startSeek=function(){this.isSeeking||(this.wasPlaying=!this.paused,this.pause(),this.isSeeking=!0)},et.prototype.seek=function(t){this.isSeeking&&(this.progress=t)},et.prototype.endSeek=function(){this.isSeeking&&!0===this.wasPlaying&&this.play(),this.wasPlaying=!1,this.isSeeking=!1},et.prototype.drawFrame=function(t){var i=this,s=this.note.width,n=this.note.height,h=this.note.getFramePalette(t),r=this.note.decodeFrame(t);this.canvas.setPaperColor(h[0]),this.canvas.clear(),"PPM"===this.note.type?(this.layerVisibility[2]&&this.canvas.drawLayer(r[1],s,n,h[2],[0,0,0,0]),this.layerVisibility[1]&&this.canvas.drawLayer(r[0],s,n,h[1],[0,0,0,0])):"KWZ"===this.note.type&&this.note.getLayerOrder(t).forEach(function(t){i.layerVisibility[t+1]&&i.canvas.drawLayer(r[t],s,n,h[2*t+1],h[2*t+2])})},et.prototype.forceUpdate=function(){this.isOpen&&this.drawFrame(this.currentFrame)},et.prototype.playFrameSe=function(t){for(var i=this.seFlags[t],s=0;s<i.length;s++)i[s]&&this.audioTracks[s].isActive&&this.audioTracks[s].start()},et.prototype.playBgm=function(){this.audioTracks[4].start(this.currentTime)},et.prototype.stopAudio=function(){for(var t=0;t<this.audioTracks.length;t++)this.audioTracks[t].stop()},et.prototype.resize=function(t,i){this.canvas.resize(t,i),this.forceUpdate()},et.prototype.setLayerVisibility=function(t,i){this.layerVisibility[t]=i,this.forceUpdate()},et.prototype.on=function(t,i){var s=this.events;(s[t]||(s[t]=[])).push(i)},et.prototype.off=function(t,i){var s=this.events[t];s&&s.splice(s.indexOf(i),1)},et.prototype.emit=function(t){for(var i=[],s=1;s<arguments.length;s++)i[s-1]=arguments[s];for(var n=this.events[t]||[],h=0;h<n.length;h++)n[h].apply(null,i)},et.prototype.clearEvents=function(){this.events={}},et.prototype.destroy=function(){this.close(),this.canvas.destroy()},et);function et(t,i,s){this.loop=!1,this.paused=!0,this.duration=0,this.isOpen=!1,this.events={},this.t=-1,this.i=0,this.hasPlaybackStarted=!1,this.wasPlaying=!1,this.isSeeking=!1,t="string"==typeof t?document.querySelector(t):t,this.canvas=new nt(t,i,s),this.el=this.canvas.el,this.customPalette=null,this.audioTracks=[new $("se1"),new $("se2"),new $("se3"),new $("se4"),new $("bgm")]}var ot=5003,ut=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],ft=(at.prototype.char_out=function(t,i){this.accum[this.a_count++]=t,254<=this.a_count&&this.flush_char(i)},at.prototype.cl_block=function(t){this.cl_hash(ot),this.free_ent=this.ClearCode+2,this.clear_flg=!0,this.output(this.ClearCode,t)},at.prototype.cl_hash=function(t){for(var i=0;i<t;++i)this.htab[i]=-1},at.prototype.compress=function(t,i){var s,n,h,r,e,o;for(this.g_init_bits=t,this.clear_flg=!1,this.n_bits=this.g_init_bits,this.maxcode=this.get_maxcode(this.n_bits),this.ClearCode=1<<t-1,this.EOFCode=this.ClearCode+1,this.free_ent=this.ClearCode+2,this.a_count=0,r=this.nextPixel(),o=0,s=ot;s<65536;s*=2)++o;o=8-o,this.cl_hash(5003),this.output(this.ClearCode,i);t:for(;-1!=(n=this.nextPixel());)if(s=(n<<12)+r,h=n<<o^r,this.htab[h]!==s){if(0<=this.htab[h]){e=0===h?1:5003-h;do{if((h-=e)<0&&(h+=5003),this.htab[h]===s){r=this.codetab[h];continue t}}while(0<=this.htab[h])}this.output(r,i),r=n,this.free_ent<4096?(this.codetab[h]=this.free_ent++,this.htab[h]=s):this.cl_block(i)}else r=this.codetab[h];this.output(r,i),this.output(this.EOFCode,i)},at.prototype.encode=function(t){t.writeByte(this.initCodeSize),this.remaining=this.width*this.height,this.curPixel=0,this.compress(this.initCodeSize+1,t),t.writeByte(0)},at.prototype.flush_char=function(t){0<this.a_count&&(t.writeByte(this.a_count),t.writeBytes(this.accum,0,this.a_count),this.a_count=0)},at.prototype.get_maxcode=function(t){return(1<<t)-1},at.prototype.nextPixel=function(){return 0===this.remaining?-1:(--this.remaining,255&this.pixels[this.curPixel++])},at.prototype.output=function(t,i){for(this.cur_accum&=ut[this.cur_bits],0<this.cur_bits?this.cur_accum|=t<<this.cur_bits:this.cur_accum=t,this.cur_bits+=this.n_bits;8<=this.cur_bits;)this.char_out(255&this.cur_accum,i),this.cur_accum>>=8,this.cur_bits-=8;if((this.free_ent>this.maxcode||this.clear_flg)&&(this.clear_flg?(this.maxcode=this.get_maxcode(this.n_bits=this.g_init_bits),this.clear_flg=!1):(++this.n_bits,12==this.n_bits?this.maxcode=4096:this.maxcode=this.get_maxcode(this.n_bits))),t==this.EOFCode){for(;0<this.cur_bits;)this.char_out(255&this.cur_accum,i),this.cur_accum>>=8,this.cur_bits-=8;this.flush_char(i)}},at);function at(t,i,s,n){this.accum=new Uint8Array(256),this.htab=new Int32Array(ot),this.codetab=new Int32Array(ot),this.cur_accum=0,this.cur_bits=0,this.curPixel=0,this.free_ent=0,this.clear_flg=!1,this.g_init_bits=void 0,this.ClearCode=void 0,this.EOFCode=void 0,this.width=t,this.height=i,this.pixels=s,this.colorDepth=n,this.initCodeSize=Math.max(2,this.colorDepth),this.accum=new Uint8Array(256),this.htab=new Int32Array(ot),this.codetab=new Int32Array(ot),this.cur_accum=0,this.cur_bits=0,this.a_count,this.remaining,this.curPixel=0,this.free_ent=0,this.maxcode,this.clear_flg=!1,this.g_init_bits=void 0,this.ClearCode=void 0,this.EOFCode=void 0}var ct,vt,lt=(wt.fromFlipnote=function(t){var i=new wt(t.width,t.height);i.palette=t.globalPalette,i.delay=100/t.framerate,i.repeat=t.meta.loop?-1:0,i.init();for(var s=0;s<t.frameCount;s++)i.writeFrame(t.getFramePixels(s));return i},wt.fromFlipnoteFrame=function(t,i){var s=new wt(t.width,t.height);return s.palette=t.globalPalette,s.delay=100/t.framerate,s.repeat=t.meta.loop?-1:0,s.init(),s.writeFrame(t.getFramePixels(i)),s},wt.prototype.init=function(){for(var t=this.palette.length,i=1;1<<i<t;i+=1);this.colorDepth=i,this.writeHeader(),this.writeColorTable(),this.writeNetscapeExt()},wt.prototype.writeHeader=function(){var t=new a(new ArrayBuffer(13));t.writeUtf8("GIF89a"),t.writeUint16(this.width),t.writeUint16(this.height),t.writeUint8(128|this.colorDepth-1),t.writeUint8(0),t.writeUint8(0),this.data.writeBytes(new Uint8Array(t.buffer))},wt.prototype.writeColorTable=function(){for(var t=new Uint8Array(3*Math.pow(2,this.colorDepth)),i=0,s=0;i<this.palette.length;i+=1,s+=3)t.set(this.palette[i],s);this.data.writeBytes(t)},wt.prototype.writeGraphicsControlExt=function(){var t=new a(new ArrayBuffer(8));t.writeBytes([33,249,4,0]),t.writeUint16(this.delay),t.writeBytes([0,0]),this.data.writeBytes(new Uint8Array(t.buffer))},wt.prototype.writeNetscapeExt=function(){var t=new a(new ArrayBuffer(19));t.writeBytes([33,255,11]),t.writeUtf8("NETSCAPE2.0"),t.writeUint8(3),t.writeUint8(1),t.writeUint16(this.repeat),this.data.writeBytes(new Uint8Array(t.buffer))},wt.prototype.writeImageDesc=function(){var t=new a(new ArrayBuffer(10));t.writeUint8(44),t.writeUint16(0),t.writeUint16(0),t.writeUint16(this.width),t.writeUint16(this.height),t.writeUint8(0),this.data.writeBytes(new Uint8Array(t.buffer))},wt.prototype.writePixels=function(t){new ft(this.width,this.height,t,this.colorDepth).encode(this.data)},wt.prototype.writeFrame=function(t){this.writeGraphicsControlExt(),this.writeImageDesc(),this.writePixels(t)},wt.prototype.getBuffer=function(){return this.data.getBuffer()},wt.prototype.getBlob=function(){return new Blob([this.getBuffer()],{type:"image/gif"})},wt.prototype.getUrl=function(){return window.URL.createObjectURL(this.getBlob())},wt.prototype.getImage=function(){var t=new Image(this.width,this.height);return t.src=this.getUrl(),t},wt);function wt(t,i){this.delay=100,this.repeat=-1,this.colorDepth=8,this.palette=[],this.width=t,this.height=i,this.data=new s}(vt=ct=ct||{}).version="4.0.2",vt.player=rt,vt.parseSource=X,vt.kwzParser=V,vt.ppmParser=F,vt.gifEncoder=lt,vt.wavEncoder=J;var dt=rt,yt=X,mt=V,bt=F,gt=lt,At=J;t.default=ct,t.gifEncoder=gt,t.kwzParser=mt,t.parseSource=yt,t.player=dt,t.ppmParser=bt,t.version="4.0.2",t.wavEncoder=At,Object.defineProperty(t,"s",{value:!0})});
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports):"function"==typeof define&&define.amd?define(["exports"],i):i((t=t||self).flipnote={})}(this,(function(t){"use strict";var i=[{matches:function(t){return"string"==typeof t},load:function(t,i,n){var s=new XMLHttpRequest;s.open("GET",t,!0),s.responseType="arraybuffer",s.onreadystatechange=function(t){4===s.readyState&&(s.status>=200&&s.status<300?i(s.response):n({type:"httpError",status:s.status,statusText:s.statusText}))},s.send(null)}},{matches:function(t){return"undefined"!=typeof File&&t instanceof File},load:function(t,i,n){if("undefined"!=typeof FileReader){var s=new FileReader;s.onload=function(t){i(s.result)},s.onerror=function(t){n({type:"fileReadError"})},s.readAsArrayBuffer(t)}else n()}},{matches:function(t){return t instanceof ArrayBuffer},load:function(t,i,n){i(t)}}];var n=function(t,i){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var n in i)i.hasOwnProperty(n)&&(t[n]=i[n])})(t,i)};function s(t,i){function s(){this.constructor=t}n(t,i),t.prototype=null===i?Object.create(i):(s.prototype=i.prototype,new s)}function h(t,i,n,s){return new(n||(n=Promise))((function(h,r){function e(t){try{u(s.next(t))}catch(t){r(t)}}function o(t){try{u(s.throw(t))}catch(t){r(t)}}function u(t){var i;t.done?h(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(e,o)}u((s=s.apply(t,i||[])).next())}))}function r(t,i){var n,s,h,r,e={label:0,sent:function(){if(1&h[0])throw h[1];return h[1]},trys:[],ops:[]};return r={next:o(0),throw:o(1),return:o(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function o(r){return function(o){return function(r){if(n)throw new TypeError("Generator is already executing.");for(;e;)try{if(n=1,s&&(h=2&r[0]?s.return:r[0]?s.throw||((h=s.return)&&h.call(s),0):s.next)&&!(h=h.call(s,r[1])).done)return h;switch(s=0,h&&(r=[2&r[0],h.value]),r[0]){case 0:case 1:h=r;break;case 4:return e.label++,{value:r[1],done:!1};case 5:e.label++,s=r[1],r=[0];continue;case 7:r=e.ops.pop(),e.trys.pop();continue;default:if(!(h=e.trys,(h=h.length>0&&h[h.length-1])||6!==r[0]&&2!==r[0])){e=0;continue}if(3===r[0]&&(!h||r[1]>h[0]&&r[1]<h[3])){e.label=r[1];break}if(6===r[0]&&e.label<h[1]){e.label=h[1],h=r;break}if(h&&e.label<h[2]){e.label=h[2],e.ops.push(r);break}h[2]&&e.ops.pop(),e.trys.pop();continue}r=i.call(t,e)}catch(t){r=[6,t],s=0}finally{n=h=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,o])}}}var e,o=function(){function t(){this.page=-1,this.pages=[],this.cursor=0,this.newPage()}return t.prototype.newPage=function(){this.pages[++this.page]=new Uint8Array(t.pageSize),this.cursor=0},t.prototype.getData=function(){var i=this,n=new Uint8Array(this.page*t.pageSize+this.cursor);return this.pages.map((function(s,h){h===i.page?n.set(s.slice(0,i.cursor),h*t.pageSize):n.set(s,h*t.pageSize)})),n},t.prototype.getBuffer=function(){return this.getData().buffer},t.prototype.writeByte=function(i){this.cursor>=t.pageSize&&this.newPage(),this.pages[this.page][this.cursor++]=i},t.prototype.writeBytes=function(t,i,n){for(var s=n||t.length,h=i||0;h<s;h++)this.writeByte(t[h])},t.pageSize=4096,t}(),u=function(){function t(t){this.buffer=t,this.data=new DataView(t),this.cursor=0}return Object.defineProperty(t.prototype,"bytes",{get:function(){return new Uint8Array(this.buffer)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"byteLength",{get:function(){return this.data.byteLength},enumerable:!1,configurable:!0}),t.prototype.seek=function(t,i){switch(i){case 2:this.cursor=this.data.byteLength+t;break;case 1:this.cursor+=t;break;case 0:default:this.cursor=t}},t.prototype.readUint8=function(){var t=this.data.getUint8(this.cursor);return this.cursor+=1,t},t.prototype.writeUint8=function(t){this.data.setUint8(this.cursor,t),this.cursor+=1},t.prototype.readInt8=function(){var t=this.data.getInt8(this.cursor);return this.cursor+=1,t},t.prototype.writeInt8=function(t){this.data.setInt8(this.cursor,t),this.cursor+=1},t.prototype.readUint16=function(t){void 0===t&&(t=!0);var i=this.data.getUint16(this.cursor,t);return this.cursor+=2,i},t.prototype.writeUint16=function(t,i){void 0===i&&(i=!0),this.data.setUint16(this.cursor,t,i),this.cursor+=2},t.prototype.readInt16=function(t){void 0===t&&(t=!0);var i=this.data.getInt16(this.cursor,t);return this.cursor+=2,i},t.prototype.writeInt16=function(t,i){void 0===i&&(i=!0),this.data.setInt16(this.cursor,t,i),this.cursor+=2},t.prototype.readUint32=function(t){void 0===t&&(t=!0);var i=this.data.getUint32(this.cursor,t);return this.cursor+=4,i},t.prototype.writeUint32=function(t,i){void 0===i&&(i=!0),this.data.setUint32(this.cursor,t,i),this.cursor+=4},t.prototype.readInt32=function(t){void 0===t&&(t=!0);var i=this.data.getInt32(this.cursor,t);return this.cursor+=4,i},t.prototype.writeInt32=function(t,i){void 0===i&&(i=!0),this.data.setInt32(this.cursor,t,i),this.cursor+=4},t.prototype.readBytes=function(t){var i=new Uint8Array(this.data.buffer,this.cursor,t);return this.cursor+=i.byteLength,i},t.prototype.writeBytes=function(t){var i=this;t.forEach((function(t){return i.writeUint8(t)}))},t.prototype.readHex=function(t,i){void 0===i&&(i=!1);for(var n=this.readBytes(t),s=[],h=0;h<n.length;h++)s.push(n[h].toString(16).padStart(2,"0"));return i&&s.reverse(),s.join("").toUpperCase()},t.prototype.readUtf8=function(t){for(var i=this.readBytes(t),n="",s=0;s<i.length;s++){var h=i[s];if(0===h)break;n+=String.fromCharCode(h)}return n},t.prototype.writeUtf8=function(t){for(var i=0;i<t.length;i++){var n=t.charCodeAt(i);this.writeUint8(n)}},t.prototype.readUtf16=function(t){for(var i=new Uint16Array(this.data.buffer,this.cursor,t),n="",s=0;s<i.length;s++){var h=i[s];if(0==h)break;n+=String.fromCharCode(h)}return this.cursor+=i.byteLength,n},t}();!function(t){t[t.BGM=0]="BGM",t[t.SE1=1]="SE1",t[t.SE2=2]="SE2",t[t.SE3=3]="SE3",t[t.SE4=4]="SE4"}(e||(e={}));for(var f=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return s(i,t),i.prototype.hasAudioTrack=function(t){return!!(this.soundMeta.hasOwnProperty(t)&&this.soundMeta[t].length>0)},i.prototype.getInt16AudioData=function(t){return this.decodeAudio(t)},i.prototype.getFloat32AudioData=function(t){for(var i=this.decodeAudio(t),n=new Float32Array(i.length),s=0;s<i.length;s++)n[s]=i[s]/32767;return n},i}(u),a=new Int8Array([-1,2,-1,2]),c=new Int8Array([-1,-1,-1,-1,2,4,6,8,-1,-1,-1,-1,2,4,6,8]),v=new Int16Array([7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50,55,60,66,73,80,88,97,107,118,130,143,157,173,190,209,230,253,279,307,337,371,408,449,494,544,598,658,724,796,876,963,1060,1166,1282,1411,1552,1707,1878,2066,2272,2499,2749,3024,3327,3660,4026,4428,4871,5358,5894,6484,7132,7845,8630,9493,10442,11487,12635,13899,15289,16818,18500,20350,22385,24623,27086,29794,32767,0]),l=new Int16Array(360),w=0;w<4;w++)for(var d=0;d<90;d++){var y=(b=v[d])>>3;1&w&&(y+=b),2&w&&(y=-y),l[w+4*d]=y}var m=new Int16Array(1440);for(w=0;w<16;w++)for(d=0;d<90;d++){var b;y=(b=v[d])>>3;4&w&&(y+=b),2&w&&(y+=b>>1),1&w&&(y+=b>>2),8&w&&(y=-y),m[w+16*d]=y}for(var g=[null,.5,1,2,4,6,12,20,30],A={WHITE:[255,255,255],BLACK:[14,14,14],RED:[255,42,42],BLUE:[10,57,255]},p=function(t){function i(n){var s=t.call(this,n)||this;return s.type=i.type,s.width=i.width,s.height=i.height,s.globalPalette=i.globalPalette,s.sampleRate=i.sampleRate,s.prevDecodedFrame=null,s.decodeHeader(),s.decodeAnimationHeader(),s.decodeSoundHeader(),s.decodeMeta(),s.layers=[new Uint8Array(i.width*i.height),new Uint8Array(i.width*i.height)],s.prevLayers=[new Uint8Array(i.width*i.height),new Uint8Array(i.width*i.height)],s.prevDecodedFrame=null,s}return s(i,t),i.validateFSID=function(t){return/[0159]{1}[0-9A-F]{6}0[0-9A-F]{8}/.test(t)},i.validateFilename=function(t){return/[0-9A-F]{6}_[0-9A-F]{13}_[0-9]{3}/.test(t)},i.prototype.readFilename=function(){return[this.readHex(3),this.readUtf8(13),this.readUint16().toString().padStart(3,"0")].join("_")},i.prototype.readLineEncoding=function(){for(var t=new Uint8Array(i.height),n=0;n<48;n++)for(var s=this.readUint8(),h=0;h<8;h+=2)t[4*n+h/2]=s>>h&3;return t},i.prototype.decodeHeader=function(){this.seek(0);this.readUint32();this.frameDataLength=this.readUint32(),this.soundDataLength=this.readUint32(),this.frameCount=this.readUint16()+1,this.version=this.readUint16()},i.prototype.decodeMeta=function(){this.seek(16);var t=this.readUint16(),i=this.readInt16(),n=this.readUtf16(11),s=this.readUtf16(11),h=this.readUtf16(11),r=this.readHex(8,!0),e=this.readHex(8,!0),o=this.readFilename(),u=this.readFilename(),f=this.readHex(8,!0);this.seek(154);var a=new Date(1e3*(this.readUint32()+946684800));this.seek(1702);var c=this.readUint16();this.thumbFrameIndex=i,this.meta={lock:1===t,loop:1==(c>>1&1),frame_count:this.frameCount,frame_speed:this.frameSpeed,bgm_speed:this.bgmSpeed,thumb_index:i,timestamp:a,spinoff:e!==r||e!==f,root:{filename:null,username:n,fsid:f},parent:{username:s,fsid:r,filename:o},current:{username:h,fsid:e,filename:u}}},i.prototype.decodeAnimationHeader=function(){var t=this;this.seek(1696);var i=this.readUint16();this.seek(1704),this.frameOffsets=new Uint32Array(i/4).map((function(n){return 1704+i+t.readUint32()}))},i.prototype.decodeSoundHeader=function(){var t,i=1696+this.frameDataLength+this.frameCount;i%4!=0&&(i+=4-i%4),this.seek(i);var n=this.readUint32(),s=this.readUint32(),h=this.readUint32(),r=this.readUint32();this.frameSpeed=8-this.readUint8(),this.bgmSpeed=8-this.readUint8(),i+=32,this.framerate=g[this.frameSpeed],this.bgmrate=g[this.bgmSpeed],this.soundMeta=((t={})[e.BGM]={offset:i,length:n},t[e.SE1]={offset:i+=n,length:s},t[e.SE2]={offset:i+=s,length:h},t[e.SE3]={offset:i+=h,length:r},t)},i.prototype.isNewFrame=function(t){return this.seek(this.frameOffsets[t]),this.readUint8()>>7&1},i.prototype.getLayerOrder=function(t){return[0,1]},i.prototype.decodeFrame=function(t){0===t||this.prevDecodedFrame===t-1||this.isNewFrame(t)||this.decodeFrame(t-1),this.seek(this.frameOffsets[t]);var n=this.readUint8(),s=n>>7&1,h=n>>5&3,r=0,e=0;this.prevLayers[0].set(this.layers[0]),this.prevLayers[1].set(this.layers[1]),this.prevDecodedFrame=t,this.layers[0].fill(0),this.layers[1].fill(0),h&&(r=this.readInt8(),e=this.readInt8());for(var o=[this.readLineEncoding(),this.readLineEncoding()],u=0;u<2;u++)for(var f=this.layers[u],a=0;a<i.height;a++){var c=o[u][a],v=a*i.width;switch(c){case 0:break;case 1:case 2:var l=this.readUint32(!1);for(2==c&&f.fill(255,v,v+i.width);4294967295&l;){if(2147483648&l)for(var w=this.readUint8(),d=0;d<8;d++)f[v+d]=w>>d&1?255:0;v+=8,l<<=1}break;case 3:for(;v<(a+1)*i.width;){for(w=this.readUint8(),d=0;d<8;d++)f[v+d]=w>>d&1?255:0;v+=8}}}if(!s)for(var y=void 0,m=void 0,b=0;b<i.height;b++)if(!(b-e<0)){if(b-e>=i.height)break;for(var g=0;g<i.width;g++)if(!(g-r<0)){if(g-r>=i.width)break;m=(y=g+b*i.width)-(r+e*i.width),this.layers[0][y]^=this.prevLayers[0][m],this.layers[1][y]^=this.prevLayers[1][m]}}return this.layers},i.prototype.getFramePaletteIndices=function(t){this.seek(this.frameOffsets[t]);var i=this.readUint8(),n=1!=(1&i),s=[n?0:1,n?0:1,2,3];return[n?1:0,s[i>>1&3],s[i>>3&3]]},i.prototype.getFramePalette=function(t){var i=this;return this.getFramePaletteIndices(t).map((function(t){return i.globalPalette[t]}))},i.prototype.getLayerPixels=function(t,n){this.prevDecodedFrame!==t&&this.decodeFrame(t);for(var s=this.getFramePaletteIndices(t),h=this.layers[n],r=new Uint8Array(i.width*i.height),e=s[n+1],o=0;o<r.length;o++)0!==h[o]&&(r[o]=e);return r},i.prototype.getFramePixels=function(t){var n=this.getFramePaletteIndices(t),s=this.decodeFrame(t),h=new Uint8Array(i.width*i.height);h.fill(n[0]);for(var r=0;r<h.length;r++){var e=s[0][r],o=s[1][r];0!==e?h[r]=n[1]:0!==o&&(h[r]=n[2])}return h},i.prototype.decodeAudio=function(t){for(var i,n,s,h=this.soundMeta[t],r=new Uint8Array(this.buffer,h.offset,h.length),e=new Int16Array(2*r.length),o=0,u=0,f=0,a=0;a<r.length;a++)for(var v=r[a],l=0;l<8;)n=u+m[(i=v>>l&15)+16*f],s=f+c[i],s=Math.max(0,Math.min(s,79)),n=Math.max(-32767,Math.min(n,32767)),e[o]=n,o+=1,f=s,u=n,l+=4;return e},i.prototype.decodeSoundFlags=function(){var t=this;return this.seek(1696+this.frameDataLength),new Array(this.frameCount).fill([]).map((function(i){var n=t.readUint8();return[1&n,n>>1&1,n>>2&1]}))},i.type="PPM",i.width=256,i.height=192,i.sampleRate=8192,i.globalPalette=[A.WHITE,A.BLACK,A.RED,A.BLUE],i}(f),_=new Uint16Array(52488),U=[0,65280,255],x=0,E=0;E<3;E++)for(var F=0;F<3;F++)for(var S=0;S<3;S++)for(var k=0;k<3;k++)for(var M=0;M<3;M++)for(var I=0;I<3;I++)for(var O=0;O<3;O++)for(var j=0;j<3;j++)_.set([U[F],U[E],U[k],U[S],U[I],U[M],U[j],U[O]],x),x+=8;var L=new Uint16Array(52488);for(x=0,E=0;E<2187;E+=729)for(F=0;F<729;F+=243)for(S=0;S<243;S+=81)for(k=0;k<81;k+=27)for(M=0;M<27;M+=9)for(I=0;I<9;I+=3)for(O=0;O<3;O+=1)for(j=0;j<6561;j+=2187){var B=E+F+S+k+M+I+O+j,P=_.subarray(8*B,8*B+8);L.set(P,x),x+=8}var W=new Uint16Array(256);[0,3280,6560,729,2187,81,243,9,27,1,3,1458,4374,162,486,18,54,2,6,2916,2268,324,252,36,28,4,820,2460,1640,4920,4100,5740].forEach((function(t,i){var n=_.subarray(8*t,8*t+8);W.set(n,8*i)}));var R=new Uint16Array(256);[0,3280,6560,3,729,2187,81,243,9,27,1,6,1458,4374,162,486,18,54,2,732,2916,2268,324,252,36,28,2460,820,4920,1640,5740,4100].forEach((function(t,i){var n=_.subarray(8*t,8*t+8);R.set(n,8*i)}));var z=[.2,.5,1,2,4,6,8,12,20,24,30],D={WHITE:[255,255,255],BLACK:[16,16,16],RED:[255,16,16],YELLOW:[255,231,0],GREEN:[0,134,49],BLUE:[0,56,206],NONE:[255,255,255]},G=function(t){function i(n){var s=t.call(this,n)||this;return s.type=i.type,s.width=i.width,s.height=i.height,s.globalPalette=i.globalPalette,s.sampleRate=i.sampleRate,s.prevDecodedFrame=null,s.bitIndex=0,s.bitValue=0,s.layers=[new Uint16Array(i.width*i.height),new Uint16Array(i.width*i.height),new Uint16Array(i.width*i.height)],s.bitIndex=0,s.bitValue=0,s.load(),s}return s(i,t),i.prototype.load=function(){this.seek(0),this.sections={},this.frameMeta=[];for(var t=this.byteLength-256,i=0,n=0;i<t&&n<6;){this.seek(i);var s=this.readUtf8(4).substring(0,3),h=this.readUint32();this.sections[s]={offset:i,length:h},i+=h+8,n+=1}this.decodeMeta(),this.decodeFrameMeta(),this.decodeSoundHeader()},i.prototype.readBits=function(t){if(this.bitIndex+t>16){var i=this.readUint16();this.bitValue|=i<<16-this.bitIndex,this.bitIndex-=16}var n=(1<<t)-1,s=this.bitValue&n;return this.bitValue>>=t,this.bitIndex+=t,s},i.prototype.decodeMeta=function(){this.seek(this.sections.KFH.offset+12);var t=new Date(1e3*(this.readUint32()+946684800)),i=new Date(1e3*(this.readUint32()+946684800)),n=(this.readUint32(),this.readHex(10)),s=this.readHex(10),h=this.readHex(10),r=this.readUtf16(11),e=this.readUtf16(11),o=this.readUtf16(11),u=this.readUtf8(28),f=this.readUtf8(28),a=this.readUtf8(28),c=this.readUint16(),v=this.readUint16(),l=this.readUint16(),w=this.readUint8();this.readUint8();this.frameCount=c,this.thumbFrameIndex=v,this.frameSpeed=w,this.framerate=z[w],this.meta={lock:1==(1&l),loop:1==(l>>1&1),frame_count:c,frame_speed:w,thumb_index:v,timestamp:i,creation_timestamp:t,root:{username:r,fsid:n,filename:u},parent:{username:e,fsid:s,filename:f},current:{username:o,fsid:h,filename:a}}},i.prototype.decodeFrameMeta=function(){this.frameOffsets=new Uint32Array(this.frameCount),this.seek(this.sections.KMI.offset+8);for(var t=this.sections.KMC.offset+12,i=0;i<this.frameCount;i++){var n={flags:this.readUint32(),layerSize:[this.readUint16(),this.readUint16(),this.readUint16()],frameAuthor:this.readHex(10),layerDepth:[this.readUint8(),this.readUint8(),this.readUint8()],soundFlags:this.readUint8(),cameraFlag:this.readUint32()};this.frameMeta.push(n),this.frameOffsets[i]=t,t+=n.layerSize[0]+n.layerSize[1]+n.layerSize[2]}},i.prototype.decodeSoundHeader=function(){var t;if(this.sections.hasOwnProperty("KSN")){var i=this.sections.KSN.offset+8;this.seek(i);var n=this.readUint32();this.bgmSpeed=n,this.bgmrate=z[n];var s=new Uint32Array(this.buffer,i+4,20);this.soundMeta=((t={})[e.BGM]={offset:i+=28,length:s[0]},t[e.SE1]={offset:i+=s[0],length:s[1]},t[e.SE2]={offset:i+=s[1],length:s[2]},t[e.SE3]={offset:i+=s[2],length:s[3]},t[e.SE4]={offset:i+=s[3],length:s[4]},t)}},i.prototype.getDiffingFlag=function(t){return 7&~(this.frameMeta[t].flags>>4)},i.prototype.getLayerDepths=function(t){return this.frameMeta[t].layerDepth},i.prototype.getLayerOrder=function(t){var i=this.getLayerDepths(t);return[2,1,0].sort((function(t,n){return i[n]-i[t]}))},i.prototype.decodeFrame=function(t,n,s){void 0===n&&(n=7),void 0===s&&(s=!1),s&&(n&=this.getDiffingFlag(t+1)),0!==t&&this.prevDecodedFrame!==t-1&&n&&this.decodeFrame(t-1,n=n,s=!0);for(var h=this.frameMeta[t],r=this.frameOffsets[t],e=0;e<3;e++){this.seek(r);var o=h.layerSize[e];if(r+=o,38!==o&&0!=(n>>e&1)){this.bitIndex=16,this.bitValue=0;for(var u=0,f=0;f<i.height;f+=128)for(var a=0;a<i.width;a+=128)for(var c=0;c<128;c+=8){var v=f+c;if(v>=i.height)break;for(var l=0;l<128;l+=8){var w=a+l;if(w>=i.width)break;if(u)u-=1;else{var d=v*i.width+w,y=this.layers[e],m=this.readBits(3);if(0==m){var b=this.readBits(5),g=W.subarray(8*b,8*b+8);y.set(g,d),y.set(g,d+320),y.set(g,d+640),y.set(g,d+960),y.set(g,d+1280),y.set(g,d+1600),y.set(g,d+1920),y.set(g,d+2240)}else if(1==m){b=this.readBits(13),g=_.subarray(8*b,8*b+8);y.set(g,d),y.set(g,d+320),y.set(g,d+640),y.set(g,d+960),y.set(g,d+1280),y.set(g,d+1600),y.set(g,d+1920),y.set(g,d+2240)}else if(2==m){var A=this.readBits(5),p=W.subarray(8*A,8*A+8),U=R.subarray(8*A,8*A+8);y.set(p,d),y.set(U,d+320),y.set(p,d+640),y.set(U,d+960),y.set(p,d+1280),y.set(U,d+1600),y.set(p,d+1920),y.set(U,d+2240)}else if(3==m){A=this.readBits(13),p=_.subarray(8*A,8*A+8),U=L.subarray(8*A,8*A+8);y.set(p,d),y.set(U,d+320),y.set(p,d+640),y.set(U,d+960),y.set(p,d+1280),y.set(U,d+1600),y.set(p,d+1920),y.set(U,d+2240)}else if(4==m)for(var x=this.readBits(8),E=0;E<8;E++)if(x&1<<E){b=this.readBits(5),g=W.subarray(8*b,8*b+8);y.set(g,d+320*E)}else{b=this.readBits(13),g=_.subarray(8*b,8*b+8);y.set(g,d+320*E)}else{if(5==m){u=this.readBits(5);continue}if(7==m){var F=this.readBits(2);p=void 0,U=void 0;if(this.readBits(1)){var S=this.readBits(5),k=this.readBits(5);p=W.subarray(8*S,8*S+8),U=W.subarray(8*k,8*k+8),F=(F+1)%4}else{S=this.readBits(13),k=this.readBits(13);p=_.subarray(8*S,8*S+8),U=_.subarray(8*k,8*k+8)}0==F?(y.set(p,d),y.set(U,d+320),y.set(p,d+640),y.set(U,d+960),y.set(p,d+1280),y.set(U,d+1600),y.set(p,d+1920),y.set(U,d+2240)):1==F?(y.set(p,d),y.set(p,d+320),y.set(U,d+640),y.set(p,d+960),y.set(p,d+1280),y.set(U,d+1600),y.set(p,d+1920),y.set(p,d+2240)):2==F?(y.set(p,d),y.set(U,d+320),y.set(p,d+640),y.set(p,d+960),y.set(U,d+1280),y.set(p,d+1600),y.set(p,d+1920),y.set(U,d+2240)):3==F&&(y.set(p,d),y.set(U,d+320),y.set(U,d+640),y.set(p,d+960),y.set(U,d+1280),y.set(U,d+1600),y.set(p,d+1920),y.set(U,d+2240))}}}}}}}return this.prevDecodedFrame=t,[new Uint8Array(this.layers[0].buffer),new Uint8Array(this.layers[1].buffer),new Uint8Array(this.layers[2].buffer)]},i.prototype.getFramePaletteIndices=function(t){var i=this.frameMeta[t].flags;return[15&i,i>>8&15,i>>12&15,i>>16&15,i>>20&15,i>>24&15,i>>28&15]},i.prototype.getFramePalette=function(t){var i=this;return this.getFramePaletteIndices(t).map((function(t){return i.globalPalette[t]}))},i.prototype.getLayerPixels=function(t,n){this.prevDecodedFrame!==t&&this.decodeFrame(t);for(var s=this.getFramePaletteIndices(t),h=this.layers[n],r=new Uint8Array(i.width*i.height),e=2*n+1,o=0;o<h.length;o++){var u=h[o];65280&u?r[o]=s[e]:255&u&&(r[o]=s[e+1])}return r},i.prototype.getFramePixels=function(t){var n=this,s=this.getFramePaletteIndices(t),h=new Uint8Array(i.width*i.height);return h.fill(s[0]),this.getLayerOrder(t).forEach((function(i){for(var s=n.getLayerPixels(t,i),r=0;r<s.length;r++){var e=s[r];0!==e&&(h[r]=e)}})),h},i.prototype.decodeSoundFlags=function(){return this.frameMeta.map((function(t){var i=t.soundFlags;return[1&i,i>>1&1,i>>2&1,i>>3&1]}))},i.prototype.decodeAudio=function(t){for(var i,n,s,h=this.soundMeta[t],r=new Uint8Array(this.buffer,h.offset,h.length),e=new Int16Array(981840),o=0,u=0,f=40,v=0;v<r.length;v++)for(var w=r[v],d=0;d<8;)f<18||6==d?(n=u+l[(i=w>>d&3)+4*f],s=f+a[i],d+=2):(n=u+m[(i=w>>d&15)+16*f],s=f+c[i],d+=4),s=Math.max(0,Math.min(s,79)),n=Math.max(-2047,Math.min(n,2047)),e[o]=16*n,o+=1,f=s,u=n;return e.slice(0,o)},i.type="KWZ",i.width=320,i.height=240,i.sampleRate=16364,i.globalPalette=[D.WHITE,D.BLACK,D.RED,D.YELLOW,D.GREEN,D.BLUE,D.NONE],i}(f);function C(t){return function(t){return new Promise((function(n,s){i.forEach((function(i){i.matches(t)&&i.load(t,n,s)}))}))}(t).then((function(t){return new Promise((function(i,n){var s=new Uint8Array(t.slice(0,4)),h=s[0]<<24|s[1]<<16|s[2]<<8|s[3];1346458177===h?i(new p(t)):1262897152==(4294967040&h)?i(new G(t)):n()}))}))}var T,K=function(){function t(t,i,n){void 0===i&&(i=1),void 0===n&&(n=16),this.sampleRate=t,this.channels=i,this.bitsPerSample=n;var s=new ArrayBuffer(44),h=new u(s);h.writeUtf8("RIFF"),h.writeUint32(0),h.writeUtf8("WAVE"),h.writeUtf8("fmt "),h.writeUint32(16),h.writeUint16(1),h.writeUint16(this.channels),h.writeUint32(this.sampleRate),h.writeUint32(this.sampleRate*this.bitsPerSample*this.channels/8),h.writeUint16(this.bitsPerSample*this.channels/8),h.writeUint16(this.bitsPerSample),h.writeUtf8("data"),h.writeUint32(0),this.header=h,this.pcmData=null}return t.prototype.writeFrames=function(t){var i=this.header;i.seek(4),i.writeUint32(i.byteLength+t.byteLength),i.seek(40),i.writeUint32(t.byteLength),this.pcmData=t},t.prototype.getBlob=function(){return new Blob([this.header.buffer,this.pcmData.buffer],{type:"audio/wav"})},t}(),N=function(){function t(t){this.playbackRate=1,this.id=t,this.channelCount=1,this.bitsPerSample=16,this.sampleRate=0,this.audio=document.createElement("audio"),this.audio.preload="auto",this.isActive=!1}return t.prototype.set=function(t,i){var n=new K(this.sampleRate*i,this.channelCount,this.bitsPerSample);n.writeFrames(t),this.url=window.URL.createObjectURL(n.getBlob()),this.audio.src=this.url,this.isActive=!0,this.playbackRate=i,this.length=t.length},Object.defineProperty(t.prototype,"duration",{get:function(){return this.audio.duration},enumerable:!1,configurable:!0}),t.prototype.unset=function(){this.isActive&&(window.URL.revokeObjectURL(this.url),this.audio.src="",this.audio.load(),this.isActive=!1,this.playbackRate=1,this.length=null)},t.prototype.start=function(t){void 0===t&&(t=0),this.isActive&&(this.audio.currentTime=t,this.audio.play())},t.prototype.stop=function(){this.isActive&&this.audio.pause()},t}();!function(t){t[t.Alpha=WebGLRenderingContext.ALPHA]="Alpha",t[t.LuminanceAlpha=WebGLRenderingContext.LUMINANCE_ALPHA]="LuminanceAlpha"}(T||(T={}));var q,H=function(){function t(t,i,n,s){void 0===i&&(i=640),void 0===n&&(n=480),void 0===s&&(s={antialias:!1,alpha:!1}),this.uniforms={},this.refs={shaders:[],textures:[],buffers:[]};var h=t.getContext("webgl",s);this.el=t,this.gl=h,this.createProgram(),this.setCanvasSize(i,n),this.createScreenQuad(),this.createBitmapTexture(),h.enable(h.BLEND),h.blendEquation(h.FUNC_ADD),h.blendFunc(h.ONE,h.ONE_MINUS_SRC_ALPHA)}return t.prototype.createProgram=function(){var t=this.gl,i=t.createProgram();if(t.attachShader(i,this.createShader(t.VERTEX_SHADER,"#define GLSLIFY 1\nattribute vec4 a_position;varying vec2 v_texel;varying float v_scale;uniform vec2 u_textureSize;uniform vec2 u_screenSize;void main(){gl_Position=a_position;vec2 uv=a_position.xy*vec2(0.5,-0.5)+0.5;v_texel=uv*u_textureSize;v_scale=floor(u_screenSize.y/u_textureSize.y+0.01);}")),t.attachShader(i,this.createShader(t.FRAGMENT_SHADER,"precision highp float;\n#define GLSLIFY 1\nvarying vec2 v_texel;varying float v_scale;uniform vec4 u_color1;uniform vec4 u_color2;uniform sampler2D u_bitmap;uniform bool u_isSmooth;uniform vec2 u_textureSize;uniform vec2 u_screenSize;void main(){vec2 texel_floored=floor(v_texel);vec2 s=fract(v_texel);float region_range=0.5-0.5/v_scale;vec2 center_dist=s-0.5;vec2 f=(center_dist-clamp(center_dist,-region_range,region_range))*v_scale+0.5;vec2 mod_texel=texel_floored+f;vec2 coord=mod_texel.xy/u_textureSize.xy;vec2 colorWeights=texture2D(u_bitmap,coord).ra;gl_FragColor=vec4(u_color1.rgb,1.0)*colorWeights.y+vec4(u_color2.rgb,1.0)*colorWeights.x;}")),t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS)){var n=t.getProgramInfoLog(i);throw t.deleteProgram(i),new Error(n)}t.useProgram(i);for(var s=t.getProgramParameter(i,t.ACTIVE_UNIFORMS),h=0;h<s;h++){var r=t.getActiveUniform(i,h).name;this.uniforms[r]=t.getUniformLocation(i,r)}this.program=i},t.prototype.createScreenQuad=function(){var t=this.gl,i=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,i),t.bufferData(t.ARRAY_BUFFER,new Float32Array([1,1,-1,1,-1,-1,1,1,-1,-1,1,-1]),t.STATIC_DRAW),t.enableVertexAttribArray(0),t.vertexAttribPointer(0,2,t.FLOAT,!1,0,0),this.refs.buffers.push(i)},t.prototype.createBitmapTexture=function(){var t=this.gl;t.activeTexture(t.TEXTURE0);var i=t.createTexture();t.bindTexture(t.TEXTURE_2D,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.uniform1i(this.uniforms.u_bitmap,0),this.refs.textures.push(i)},t.prototype.createShader=function(t,i){var n=this.gl,s=n.createShader(t);if(n.shaderSource(s,i),n.compileShader(s),!n.getShaderParameter(s,n.COMPILE_STATUS)){var h=n.getShaderInfoLog(s);throw n.deleteShader(s),new Error(h)}return this.refs.shaders.push(s),s},t.prototype.setInputSize=function(t,i){this.gl.uniform2f(this.uniforms.u_textureSize,t,i)},t.prototype.setCanvasSize=function(t,i){var n=window.devicePixelRatio||1,s=t*n,h=i*n;this.el.width=s,this.el.height=h,this.width=s,this.height=h,this.gl.viewport(0,0,s,h),this.gl.uniform2f(this.uniforms.u_screenSize,s,h),this.el.style.width=t+"px",this.el.style.height=i+"px"},t.prototype.setLayerType=function(t){this.textureType=t},t.prototype.toImage=function(t){return this.el.toDataURL(t)},t.prototype.setColor=function(t,i){this.gl.uniform4f(this.uniforms[t],i[0]/255,i[1]/255,i[2]/255,1)},t.prototype.setPaperColor=function(t){this.gl.clearColor(t[0]/255,t[1]/255,t[2]/255,1)},t.prototype.drawLayer=function(t,i,n,s,h){var r=this.gl;r.texImage2D(r.TEXTURE_2D,0,this.textureType,i,n,0,this.textureType,r.UNSIGNED_BYTE,t),this.setColor("u_color1",s),this.setColor("u_color2",h),r.drawArrays(r.TRIANGLES,0,6)},t.prototype.resize=function(t,i){void 0===t&&(t=640),void 0===i&&(i=480),this.setCanvasSize(t,i)},t.prototype.clear=function(){this.gl.clear(this.gl.COLOR_BUFFER_BIT)},t.prototype.destroy=function(){var t=this.refs,i=this.gl;t.shaders.forEach((function(t){i.deleteShader(t)})),t.shaders=[],t.textures.forEach((function(t){i.deleteTexture(t)})),t.textures=[],t.buffers.forEach((function(t){i.deleteBuffer(t)})),t.buffers=[],i.deleteProgram(this.program),i.canvas.width=1,i.canvas.height=1},t}(),Y=function(){function t(t,i,n){this.loop=!1,this.paused=!0,this.duration=0,this.isOpen=!1,this.events={},this.t=-1,this.i=0,this.hasPlaybackStarted=!1,this.wasPlaying=!1,this.isSeeking=!1,t="string"==typeof t?document.querySelector(t):t,this.canvas=new H(t,i,n),this.el=this.canvas.el,this.customPalette=null,this.audioTracks=[new N("se1"),new N("se2"),new N("se3"),new N("se4"),new N("bgm")]}return Object.defineProperty(t.prototype,"currentFrame",{get:function(){return this.t},set:function(t){this.setFrame(t)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"currentTime",{get:function(){return this.isOpen?this.i:null},set:function(t){this.isOpen&&t<=this.duration&&t>=0&&(this.setFrame(Math.round(t/(1/this.framerate))),this.i=t,this.emit("progress",this.progress))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"progress",{get:function(){return this.isOpen?this.currentTime/this.duration*100:0},set:function(t){this.currentTime=this.duration*(t/100)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"volume",{get:function(){return this.audioTracks[3].audio.volume},set:function(t){for(var i=0;i<this.audioTracks.length;i++)this.audioTracks[i].audio.volume=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"muted",{get:function(){return this.audioTracks[3].audio.muted},set:function(t){for(var i=0;i<this.audioTracks.length;i++)this.audioTracks[i].audio.muted=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"framerate",{get:function(){return this.note.framerate},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"frameCount",{get:function(){return this.note.frameCount},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"frameSpeed",{get:function(){return this.note.frameSpeed},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"audiorate",{get:function(){return 1/this.note.bgmrate/(1/this.note.framerate)},enumerable:!1,configurable:!0}),t.prototype.open=function(t){return h(this,void 0,void 0,(function(){var i=this;return r(this,(function(n){return this.isOpen&&this.close(),[2,C(t).then((function(t){i.load(t)})).catch((function(t){throw i.emit("error",t),console.error("Error loading Flipnote:",t),"Error loading Flipnote"}))]}))}))},t.prototype.close=function(){this.pause(),this.note=null,this.isOpen=!1,this.paused=!0,this.loop=null,this.meta=null,this.t=null,this.i=null,this.duration=null,this.loop=null;for(var t=0;t<this.audioTracks.length;t++)this.audioTracks[t].unset();this.seFlags=null,this.hasPlaybackStarted=null,this.canvas.clear()},t.prototype.load=function(t){var i=this;this.note=t,this.meta=t.meta,this.type=t.type,this.loop=t.meta.loop,this.duration=this.note.frameCount*(1/this.note.framerate),this.paused=!0,this.isOpen=!0,this.audioTracks.forEach((function(i){i.sampleRate=t.sampleRate})),[e.SE1,e.SE2,e.SE3,e.SE4,e.BGM].forEach((function(t,n){var s=t===e.BGM?i.audiorate:1;i.note.hasAudioTrack(t)&&i.audioTracks[n].set(i.note.decodeAudio(t),s)})),this.seFlags=this.note.decodeSoundFlags(),this.hasPlaybackStarted=!1,this.layerVisibility={1:!0,2:!0,3:!0},this.canvas.setInputSize(t.width,t.height),this.canvas.setLayerType("PPM"===this.type?T.Alpha:T.LuminanceAlpha),this.setFrame(this.note.thumbFrameIndex),this.i=0,this.emit("load")},t.prototype.play=function(){var t=this;if(!this.isOpen||!this.paused)return null;this.hasPlaybackStarted&&(this.loop||this.currentFrame!=this.frameCount-1)||(this.i=0),this.paused=!1,this.playBgm();var i=performance.now()/1e3-this.currentTime,n=function(s){if(t.paused)return t.stopAudio(),null;var h=s/1e3,r=h-i;r>t.duration?t.loop?(t.currentTime=0,t.playBgm(),i=h,t.emit("playback:loop")):(t.pause(),t.emit("playback:end")):t.currentTime=r,requestAnimationFrame(n)};requestAnimationFrame(n),this.hasPlaybackStarted=!0,this.emit("playback:start")},t.prototype.pause=function(){if(!this.isOpen||this.paused)return null;this.paused=!0,this.stopAudio(),this.emit("playback:stop")},t.prototype.togglePlay=function(){this.paused?this.play():this.pause()},t.prototype.setFrame=function(t){this.isOpen&&t!==this.currentFrame&&(t=Math.max(0,Math.min(Math.floor(t),this.frameCount-1)),this.drawFrame(t),this.t=t,this.paused?(this.i=t*(1/this.framerate),this.emit("progress",this.progress)):this.playFrameSe(t),this.emit("frame:update",this.currentFrame))},t.prototype.nextFrame=function(){this.loop&&this.currentFrame>=this.frameCount-1?this.currentFrame=0:this.currentFrame+=1},t.prototype.prevFrame=function(){this.loop&&this.currentFrame<=0?this.currentFrame=this.frameCount-1:this.currentFrame-=1},t.prototype.lastFrame=function(){this.currentFrame=this.frameCount-1},t.prototype.firstFrame=function(){this.currentFrame=0},t.prototype.thumbnailFrame=function(){this.currentFrame=this.note.thumbFrameIndex},t.prototype.startSeek=function(){this.isSeeking||(this.wasPlaying=!this.paused,this.pause(),this.isSeeking=!0)},t.prototype.seek=function(t){this.isSeeking&&(this.progress=t)},t.prototype.endSeek=function(){this.isSeeking&&!0===this.wasPlaying&&this.play(),this.wasPlaying=!1,this.isSeeking=!1},t.prototype.drawFrame=function(t){var i=this,n=this.note.width,s=this.note.height,h=this.note.getFramePalette(t),r=this.note.decodeFrame(t);this.canvas.setPaperColor(h[0]),this.canvas.clear(),"PPM"===this.note.type?(this.layerVisibility[2]&&this.canvas.drawLayer(r[1],n,s,h[2],[0,0,0,0]),this.layerVisibility[1]&&this.canvas.drawLayer(r[0],n,s,h[1],[0,0,0,0])):"KWZ"===this.note.type&&this.note.getLayerOrder(t).forEach((function(t){i.layerVisibility[t+1]&&i.canvas.drawLayer(r[t],n,s,h[2*t+1],h[2*t+2])}))},t.prototype.forceUpdate=function(){this.isOpen&&this.drawFrame(this.currentFrame)},t.prototype.playFrameSe=function(t){for(var i=this.seFlags[t],n=0;n<i.length;n++)i[n]&&this.audioTracks[n].isActive&&this.audioTracks[n].start()},t.prototype.playBgm=function(){this.audioTracks[4].start(this.currentTime)},t.prototype.stopAudio=function(){for(var t=0;t<this.audioTracks.length;t++)this.audioTracks[t].stop()},t.prototype.resize=function(t,i){this.canvas.resize(t,i),this.forceUpdate()},t.prototype.setLayerVisibility=function(t,i){this.layerVisibility[t]=i,this.forceUpdate()},t.prototype.toggleLayerVisibility=function(t){this.setLayerVisibility(t,!this.layerVisibility[t])},t.prototype.on=function(t,i){var n=this.events;(n[t]||(n[t]=[])).push(i)},t.prototype.off=function(t,i){var n=this.events[t];n&&n.splice(n.indexOf(i),1)},t.prototype.emit=function(t){for(var i=[],n=1;n<arguments.length;n++)i[n-1]=arguments[n];for(var s=this.events[t]||[],h=0;h<s.length;h++)s[h].apply(null,i)},t.prototype.clearEvents=function(){this.events={}},t.prototype.destroy=function(){this.close(),this.canvas.destroy()},t}(),V=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],Z=function(){function t(t,i,n,s){this.accum=new Uint8Array(256),this.htab=new Int32Array(5003),this.codetab=new Int32Array(5003),this.cur_accum=0,this.cur_bits=0,this.curPixel=0,this.free_ent=0,this.clear_flg=!1,this.g_init_bits=void 0,this.ClearCode=void 0,this.EOFCode=void 0,this.width=t,this.height=i,this.pixels=n,this.colorDepth=s,this.initCodeSize=Math.max(2,this.colorDepth),this.accum=new Uint8Array(256),this.htab=new Int32Array(5003),this.codetab=new Int32Array(5003),this.cur_accum=0,this.cur_bits=0,this.a_count,this.remaining,this.curPixel=0,this.free_ent=0,this.maxcode,this.clear_flg=!1,this.g_init_bits=void 0,this.ClearCode=void 0,this.EOFCode=void 0}return t.prototype.char_out=function(t,i){this.accum[this.a_count++]=t,this.a_count>=254&&this.flush_char(i)},t.prototype.cl_block=function(t){this.cl_hash(5003),this.free_ent=this.ClearCode+2,this.clear_flg=!0,this.output(this.ClearCode,t)},t.prototype.cl_hash=function(t){for(var i=0;i<t;++i)this.htab[i]=-1},t.prototype.compress=function(t,i){var n,s,h,r,e,o;for(this.g_init_bits=t,this.clear_flg=!1,this.n_bits=this.g_init_bits,this.maxcode=this.get_maxcode(this.n_bits),this.ClearCode=1<<t-1,this.EOFCode=this.ClearCode+1,this.free_ent=this.ClearCode+2,this.a_count=0,r=this.nextPixel(),o=0,n=5003;n<65536;n*=2)++o;o=8-o,this.cl_hash(5003),this.output(this.ClearCode,i);t:for(;-1!=(s=this.nextPixel());)if(n=(s<<12)+r,h=s<<o^r,this.htab[h]!==n){if(this.htab[h]>=0){e=5003-h,0===h&&(e=1);do{if((h-=e)<0&&(h+=5003),this.htab[h]===n){r=this.codetab[h];continue t}}while(this.htab[h]>=0)}this.output(r,i),r=s,this.free_ent<4096?(this.codetab[h]=this.free_ent++,this.htab[h]=n):this.cl_block(i)}else r=this.codetab[h];this.output(r,i),this.output(this.EOFCode,i)},t.prototype.encode=function(t){t.writeByte(this.initCodeSize),this.remaining=this.width*this.height,this.curPixel=0,this.compress(this.initCodeSize+1,t),t.writeByte(0)},t.prototype.flush_char=function(t){this.a_count>0&&(t.writeByte(this.a_count),t.writeBytes(this.accum,0,this.a_count),this.a_count=0)},t.prototype.get_maxcode=function(t){return(1<<t)-1},t.prototype.nextPixel=function(){return 0===this.remaining?-1:(--this.remaining,255&this.pixels[this.curPixel++])},t.prototype.output=function(t,i){for(this.cur_accum&=V[this.cur_bits],this.cur_bits>0?this.cur_accum|=t<<this.cur_bits:this.cur_accum=t,this.cur_bits+=this.n_bits;this.cur_bits>=8;)this.char_out(255&this.cur_accum,i),this.cur_accum>>=8,this.cur_bits-=8;if((this.free_ent>this.maxcode||this.clear_flg)&&(this.clear_flg?(this.maxcode=this.get_maxcode(this.n_bits=this.g_init_bits),this.clear_flg=!1):(++this.n_bits,12==this.n_bits?this.maxcode=4096:this.maxcode=this.get_maxcode(this.n_bits))),t==this.EOFCode){for(;this.cur_bits>0;)this.char_out(255&this.cur_accum,i),this.cur_accum>>=8,this.cur_bits-=8;this.flush_char(i)}},t}(),X=function(){function t(t,i){this.delay=100,this.repeat=-1,this.colorDepth=8,this.palette=[],this.width=t,this.height=i,this.data=new o}return t.fromFlipnote=function(i){var n=new t(i.width,i.height);n.palette=i.globalPalette,n.delay=100/i.framerate,n.repeat=i.meta.loop?-1:0,n.init();for(var s=0;s<i.frameCount;s++)n.writeFrame(i.getFramePixels(s));return n},t.fromFlipnoteFrame=function(i,n){var s=new t(i.width,i.height);return s.palette=i.globalPalette,s.delay=100/i.framerate,s.repeat=i.meta.loop?-1:0,s.init(),s.writeFrame(i.getFramePixels(n)),s},t.prototype.init=function(){for(var t=this.palette.length,i=1;1<<i<t;i+=1);this.colorDepth=i,this.writeHeader(),this.writeColorTable(),this.writeNetscapeExt()},t.prototype.writeHeader=function(){var t=new u(new ArrayBuffer(13));t.writeUtf8("GIF89a"),t.writeUint16(this.width),t.writeUint16(this.height),t.writeUint8(128|this.colorDepth-1),t.writeUint8(0),t.writeUint8(0),this.data.writeBytes(new Uint8Array(t.buffer))},t.prototype.writeColorTable=function(){for(var t=new Uint8Array(3*Math.pow(2,this.colorDepth)),i=0,n=0;i<this.palette.length;i+=1,n+=3)t.set(this.palette[i],n);this.data.writeBytes(t)},t.prototype.writeGraphicsControlExt=function(){var t=new u(new ArrayBuffer(8));t.writeBytes([33,249,4,0]),t.writeUint16(this.delay),t.writeBytes([0,0]),this.data.writeBytes(new Uint8Array(t.buffer))},t.prototype.writeNetscapeExt=function(){var t=new u(new ArrayBuffer(19));t.writeBytes([33,255,11]),t.writeUtf8("NETSCAPE2.0"),t.writeUint8(3),t.writeUint8(1),t.writeUint16(this.repeat),this.data.writeBytes(new Uint8Array(t.buffer))},t.prototype.writeImageDesc=function(){var t=new u(new ArrayBuffer(10));t.writeUint8(44),t.writeUint16(0),t.writeUint16(0),t.writeUint16(this.width),t.writeUint16(this.height),t.writeUint8(0),this.data.writeBytes(new Uint8Array(t.buffer))},t.prototype.writePixels=function(t){new Z(this.width,this.height,t,this.colorDepth).encode(this.data)},t.prototype.writeFrame=function(t){this.writeGraphicsControlExt(),this.writeImageDesc(),this.writePixels(t)},t.prototype.getBuffer=function(){return this.data.getBuffer()},t.prototype.getBlob=function(){return new Blob([this.getBuffer()],{type:"image/gif"})},t.prototype.getUrl=function(){return window.URL.createObjectURL(this.getBlob())},t.prototype.getImage=function(){var t=new Image(this.width,this.height);return t.src=this.getUrl(),t},t}();!function(t){t.version="4.1.0",t.player=Y,t.parseSource=C,t.kwzParser=G,t.ppmParser=p,t.gifEncoder=X,t.wavEncoder=K}(q||(q={}));var J=q,Q=Y,$=C,tt=G,it=p,nt=X,st=K;t.default=J,t.gifEncoder=nt,t.kwzParser=tt,t.parseSource=$,t.player=Q,t.ppmParser=it,t.version="4.1.0",t.wavEncoder=st,Object.defineProperty(t,"s",{value:!0})}));

@@ -47,2 +47,3 @@ import { Flipnote, FlipnoteMeta } from '../parsers/index';

pause(): void;
togglePlay(): void;
setFrame(frameIndex: number): void;

@@ -64,2 +65,3 @@ nextFrame(): void;

setLayerVisibility(layerIndex: number, value: boolean): void;
toggleLayerVisibility(layerIndex: number): void;
on(eventType: string, callback: Function): void;

@@ -66,0 +68,0 @@ off(eventType: string, callback: Function): void;

@@ -9,5 +9,5 @@ export declare class ByteArray {

getData(): Uint8Array;
getBuffer(): ArrayBuffer | SharedArrayBuffer;
getBuffer(): ArrayBufferLike;
writeByte(val: number): void;
writeBytes(array: Uint8Array | number[], offset?: number, length?: number): void;
}
{
"name": "flipnote.js",
"version": "4.0.2",
"version": "4.1.0",
"description": "API for handling Flipnote Studio's animation formats, capable of real-time playback using webGL",

@@ -10,8 +10,9 @@ "module": "dist/flipnote.es.js",

"prepublishOnly": "npm run build",
"start": "rollup -c --watch --environment DEV_SERVER,BUILD:development",
"start": "rollup -c --watch --environment DEV_SERVER,TARGET:webcomponent,BUILD:development",
"dev": "rollup -c --environment BUILD:development",
"build": "npm run dev && npm run build:es && npm run build:min && npm run build:node",
"build:min": "rollup -c --environment BUILD:production",
"build:es": "rollup -c --environment ES_MODULE,BUILD:production",
"build:node": "rollup -c --environment ES_MODULE,TARGET:node"
"build": "npm run dev && npm run build:min && npm run build:es && npm run build:webcomponent && npm run build:node",
"build:min": "rollup -c --environment TARGET:web,BUILD:production",
"build:es": "rollup -c --environment TARGET:web,ES_MODULE,BUILD:production",
"build:webcomponent": "rollup -c --environment TARGET:webcomponent,BUILD:production",
"build:node": "rollup -c --environment TARGET:node,ES_MODULE"
},

@@ -39,3 +40,3 @@ "files": [

},
"author": "James Daniel <james@rakujira.jp>",
"author": "James Daniel <npm@jamesdaniel.dev>",
"license": "MIT",

@@ -46,3 +47,5 @@ "bugs": {

"devDependencies": {
"@pyoner/svelte-types": "^3.4.4-2",
"@rollup/plugin-alias": "^3.1.1",
"@rollup/plugin-commonjs": "^13.0.0",
"@rollup/plugin-node-resolve": "^8.0.1",

@@ -52,7 +55,13 @@ "@rollup/plugin-replace": "^2.3.3",

"rollup-plugin-bundle-size": "^1.0.3",
"rollup-plugin-copy": "^3.3.0",
"rollup-plugin-glslify": "^1.2.0",
"rollup-plugin-livereload": "^1.3.0",
"rollup-plugin-serve": "^1.0.1",
"rollup-plugin-svelte": "^5.2.3",
"rollup-plugin-svgo": "^1.1.0",
"rollup-plugin-terser": "^6.1.0",
"rollup-plugin-typescript2": "^0.27.1",
"rollup-plugin-uglify": "^6.0.4",
"svelte": "^3.24.0",
"svelte-preprocess": "^4.0.6",
"typescript": "^3.5.3"

@@ -59,0 +68,0 @@ },

@@ -54,3 +54,3 @@ # flipnote.js

## Player setup
## Manual Player Setup

@@ -298,2 +298,3 @@ To create a new player, we need to make a HTML [canvas](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial) element with a unique identifier (an `id` attribute works well!) to act as a display for the player.

* Identifying the PPM sound codec: Midmad from Hatena Haiku (no longer active) and WDLMaster from the [HCS forum](https://hcs64.com/mboard/forum.php).
* Further audio reverse-engineering: [SimonTime](https://github.com/simontime).
* [PBSDS](https://github.com/pbsds) for creating [Hatena Tools](https://github.com/pbsds/Hatenatools), and for giving me some notes regarding areas where the documentation fell short.

@@ -300,0 +301,0 @@ * Stichting Mathematisch Centrum for writing this [ADPCM to PCM converter in C](http://www.cs.columbia.edu/~gskc/Code/AdvancedInternetServices/SoundNoiseRatio/dvi_adpcm.c) which I semi-ported to JS to handle audio.

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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