flipnote.js
Advanced tools
Comparing version 4.1.1 to 4.1.2
@@ -6,3 +6,3 @@ import { parseSource as _parseSource, Flipnote as _Flipnote, FlipnoteMeta as _FlipnoteMeta, FlipnoteAudioTrack as _FlipnoteAudioTrack, KwzParser, PpmParser } from './parsers/index'; | ||
const version: string; | ||
type Flipnpte = _Flipnote; | ||
type Flipnote = _Flipnote; | ||
type FlipnoteMeta = _FlipnoteMeta; | ||
@@ -19,3 +19,3 @@ type FlipnoteAudioTrack = _FlipnoteAudioTrack; | ||
export declare const version: string; | ||
export declare type Flipnpte = _Flipnote; | ||
export declare type Flipnote = _Flipnote; | ||
export declare type FlipnoteMeta = _FlipnoteMeta; | ||
@@ -22,0 +22,0 @@ export declare type FlipnoteAudioTrack = _FlipnoteAudioTrack; |
/*!! | ||
flipnote.js v4.1.1 (web version) | ||
flipnote.js v4.1.2 (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 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.1",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.1",t.wavEncoder=st,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.2",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.2",t.wavEncoder=st,Object.defineProperty(t,"s",{value:!0})})); |
/*!! | ||
flipnote.js v4.1.1 (webcomponent version) | ||
flipnote.js v4.1.2 (webcomponent 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";function i(){}function n(t){return t()}function s(){return Object.create(null)}function r(t){t.forEach(n)}function e(t){return"function"==typeof t}function o(t,i){return t!=t?i==i:t!==i||t&&"object"==typeof t||"function"==typeof t}function h(t,i){t.appendChild(i)}function a(t,i,n){t.insertBefore(i,n||null)}function u(t){t.parentNode.removeChild(t)}function l(t){return document.createElement(t)}function c(t){return document.createTextNode(t)}function f(){return c(" ")}function v(t,i,n,s){return t.addEventListener(i,n,s),()=>t.removeEventListener(i,n,s)}function p(t,i,n){null==n?t.removeAttribute(i):t.getAttribute(i)!==n&&t.setAttribute(i,n)}function d(t,i,n){i in t?t[i]=n:p(t,i,n)}function y(t,i,n,s){t.style.setProperty(i,n,s?"important":"")}let m;function w(t){m=t}function g(){if(!m)throw new Error("Function called outside component initialization");return m}function _(){const t=g();return(i,n)=>{const s=t.$$.callbacks[i];if(s){const r=function(t,i){const n=document.createEvent("CustomEvent");return n.initCustomEvent(t,!1,!1,i),n}(i,n);s.slice().forEach(i=>{i.call(t,r)})}}}const b=[],A=[],F=[],x=[],P=Promise.resolve();let C=!1;function k(t){F.push(t)}let U=!1;const M=new Set;function S(){if(!U){U=!0;do{for(let t=0;t<b.length;t+=1){const i=b[t];w(i),E(i.$$)}for(b.length=0;A.length;)A.pop()();for(let t=0;t<F.length;t+=1){const i=F[t];M.has(i)||(M.add(i),i())}F.length=0}while(b.length);for(;x.length;)x.pop()();C=!1,U=!1,M.clear()}}function E(t){if(null!==t.fragment){t.update(),r(t.before_update);const i=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,i),t.after_update.forEach(k)}}const B=new Set;let z,I;function L(t,i){t&&t.i&&(B.delete(t),t.i(i))}function O(t,i){const n=i.token={};function s(t,s,e,o){if(i.token!==n)return;i.resolved=o;let h=i.ctx;void 0!==e&&(h=h.slice(),h[e]=o);const a=t&&(i.current=t)(h);let u=!1;i.block&&(i.blocks?i.blocks.forEach((t,n)=>{n!==s&&t&&(z={r:0,c:[],p:z},function(t,i,n,s){if(t&&t.o){if(B.has(t))return;B.add(t),z.c.push(()=>{B.delete(t),s&&(n&&t.d(1),s())}),t.o(i)}}(t,1,1,()=>{i.blocks[n]=null}),z.r||r(z.c),z=z.p)}):i.block.d(1),a.c(),L(a,1),a.m(i.mount(),i.anchor),u=!0),i.block=a,i.blocks&&(i.blocks[s]=a),u&&S()}if((e=t)&&"object"==typeof e&&"function"==typeof e.then){const n=g();if(t.then(t=>{w(n),s(i.then,1,i.value,t),w(null)},t=>{w(n),s(i.catch,2,i.error,t),w(null)}),i.current!==i.pending)return s(i.pending,0),!0}else{if(i.current!==i.then)return s(i.then,1,i.value,t),!0;i.resolved=t}var e}function j(t,i){-1===t.$$.dirty[0]&&(b.push(t),C||(C=!0,P.then(S)),t.$$.dirty.fill(0)),t.$$.dirty[i/31|0]|=1<<i%31}function D(t,o,h,a,l,c,f=[-1]){const v=m;w(t);const p=o.props||{},d=t.$$={fragment:null,ctx:null,props:c,update:i,not_equal:l,bound:s(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(v?v.$$.context:[]),callbacks:s(),dirty:f};let y=!1;if(d.ctx=h?h(t,p,(i,n,...s)=>{const r=s.length?s[0]:n;return d.ctx&&l(d.ctx[i],d.ctx[i]=r)&&(d.bound[i]&&d.bound[i](r),y&&j(t,i)),n}):[],d.update(),y=!0,r(d.before_update),d.fragment=!!a&&a(d.ctx),o.target){if(o.hydrate){const t=function(t){return Array.from(t.childNodes)}(o.target);d.fragment&&d.fragment.l(t),t.forEach(u)}else d.fragment&&d.fragment.c();o.intro&&L(t.$$.fragment),function(t,i,s){const{fragment:o,on_mount:h,on_destroy:a,after_update:u}=t.$$;o&&o.m(i,s),k(()=>{const i=h.map(n).filter(e);a?a.push(...i):r(i),t.$$.on_mount=[]}),u.forEach(k)}(t,o.target,o.anchor),S()}w(v)}"function"==typeof HTMLElement&&(I=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}connectedCallback(){for(const t in this.$$.slotted)this.appendChild(this.$$.slotted[t])}attributeChangedCallback(t,i,n){this[t]=n}$destroy(){!function(t,i){const n=t.$$;null!==n.fragment&&(r(n.on_destroy),n.fragment&&n.fragment.d(i),n.on_destroy=n.fragment=null,n.ctx=[])}(this,1),this.$destroy=i}$on(t,i){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(i),()=>{const t=n.indexOf(i);-1!==t&&n.splice(t,1)}}$set(){}});var R=function(t,i){return(R=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 W(t,i){function n(){this.constructor=t}R(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}function G(t,i,n,s){return new(n||(n=Promise))((function(r,e){function o(t){try{a(s.next(t))}catch(t){e(t)}}function h(t){try{a(s.throw(t))}catch(t){e(t)}}function a(t){var i;t.done?r(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(o,h)}a((s=s.apply(t,i||[])).next())}))}function T(t,i){var n,s,r,e,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return e={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function h(e){return function(h){return function(e){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,s&&(r=2&e[0]?s.return:e[0]?s.throw||((r=s.return)&&r.call(s),0):s.next)&&!(r=r.call(s,e[1])).done)return r;switch(s=0,r&&(e=[2&e[0],r.value]),e[0]){case 0:case 1:r=e;break;case 4:return o.label++,{value:e[1],done:!1};case 5:o.label++,s=e[1],e=[0];continue;case 7:e=o.ops.pop(),o.trys.pop();continue;default:if(!(r=o.trys,(r=r.length>0&&r[r.length-1])||6!==e[0]&&2!==e[0])){o=0;continue}if(3===e[0]&&(!r||e[1]>r[0]&&e[1]<r[3])){o.label=e[1];break}if(6===e[0]&&o.label<r[1]){o.label=r[1],r=e;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(e);break}r[2]&&o.ops.pop(),o.trys.pop();continue}e=i.call(t,o)}catch(t){e=[6,t],s=0}finally{n=r=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,h])}}}var H=[{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 $,K=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,r){r===i.page?n.set(s.slice(0,i.cursor),r*t.pageSize):n.set(s,r*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,r=i||0;r<s;r++)this.writeByte(t[r])},t.pageSize=4096,t}(),N=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=[],r=0;r<n.length;r++)s.push(n[r].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 r=i[s];if(0===r)break;n+=String.fromCharCode(r)}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 r=i[s];if(0==r)break;n+=String.fromCharCode(r)}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"}($||($={}));for(var V=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return W(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}(N),q=new Int8Array([-1,2,-1,2]),Z=new Int8Array([-1,-1,-1,-1,2,4,6,8,-1,-1,-1,-1,2,4,6,8]),Y=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]),X=new Int16Array(360),J=0;J<4;J++)for(var Q=0;Q<90;Q++){var tt=(nt=Y[Q])>>3;1&J&&(tt+=nt),2&J&&(tt=-tt),X[J+4*Q]=tt}var it=new Int16Array(1440);for(J=0;J<16;J++)for(Q=0;Q<90;Q++){var nt;tt=(nt=Y[Q])>>3;4&J&&(tt+=nt),2&J&&(tt+=nt>>1),1&J&&(tt+=nt>>2),8&J&&(tt=-tt),it[J+16*Q]=tt}for(var st=[null,.5,1,2,4,6,12,20,30],rt={WHITE:[255,255,255],BLACK:[14,14,14],RED:[255,42,42],BLUE:[10,57,255]},et=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 W(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(),r=0;r<8;r+=2)t[4*n+r/2]=s>>r&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),r=this.readUtf16(11),e=this.readHex(8,!0),o=this.readHex(8,!0),h=this.readFilename(),a=this.readFilename(),u=this.readHex(8,!0);this.seek(154);var l=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:l,spinoff:o!==e||o!==u,root:{filename:null,username:n,fsid:u},parent:{username:s,fsid:e,filename:h},current:{username:r,fsid:o,filename:a}}},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(),r=this.readUint32(),e=this.readUint32();this.frameSpeed=8-this.readUint8(),this.bgmSpeed=8-this.readUint8(),i+=32,this.framerate=st[this.frameSpeed],this.bgmrate=st[this.bgmSpeed],this.soundMeta=((t={})[$.BGM]={offset:i,length:n},t[$.SE1]={offset:i+=n,length:s},t[$.SE2]={offset:i+=s,length:r},t[$.SE3]={offset:i+=r,length:e},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,r=n>>5&3,e=0,o=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),r&&(e=this.readInt8(),o=this.readInt8());for(var h=[this.readLineEncoding(),this.readLineEncoding()],a=0;a<2;a++)for(var u=this.layers[a],l=0;l<i.height;l++){var c=h[a][l],f=l*i.width;switch(c){case 0:break;case 1:case 2:var v=this.readUint32(!1);for(2==c&&u.fill(255,f,f+i.width);4294967295&v;){if(2147483648&v)for(var p=this.readUint8(),d=0;d<8;d++)u[f+d]=p>>d&1?255:0;f+=8,v<<=1}break;case 3:for(;f<(l+1)*i.width;){for(p=this.readUint8(),d=0;d<8;d++)u[f+d]=p>>d&1?255:0;f+=8}}}if(!s)for(var y=void 0,m=void 0,w=0;w<i.height;w++)if(!(w-o<0)){if(w-o>=i.height)break;for(var g=0;g<i.width;g++)if(!(g-e<0)){if(g-e>=i.width)break;m=(y=g+w*i.width)-(e+o*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),r=this.layers[n],e=new Uint8Array(i.width*i.height),o=s[n+1],h=0;h<e.length;h++)0!==r[h]&&(e[h]=o);return e},i.prototype.getFramePixels=function(t){var n=this.getFramePaletteIndices(t),s=this.decodeFrame(t),r=new Uint8Array(i.width*i.height);r.fill(n[0]);for(var e=0;e<r.length;e++){var o=s[0][e],h=s[1][e];0!==o?r[e]=n[1]:0!==h&&(r[e]=n[2])}return r},i.prototype.decodeAudio=function(t){for(var i,n,s,r=this.soundMeta[t],e=new Uint8Array(this.buffer,r.offset,r.length),o=new Int16Array(2*e.length),h=0,a=0,u=0,l=0;l<e.length;l++)for(var c=e[l],f=0;f<8;)n=a+it[(i=c>>f&15)+16*u],s=u+Z[i],s=Math.max(0,Math.min(s,79)),n=Math.max(-32767,Math.min(n,32767)),o[h]=n,h+=1,u=s,a=n,f+=4;return o},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=[rt.WHITE,rt.BLACK,rt.RED,rt.BLUE],i}(V),ot=new Uint16Array(52488),ht=[0,65280,255],at=0,ut=0;ut<3;ut++)for(var lt=0;lt<3;lt++)for(var ct=0;ct<3;ct++)for(var ft=0;ft<3;ft++)for(var vt=0;vt<3;vt++)for(var pt=0;pt<3;pt++)for(var dt=0;dt<3;dt++)for(var yt=0;yt<3;yt++)ot.set([ht[lt],ht[ut],ht[ft],ht[ct],ht[pt],ht[vt],ht[yt],ht[dt]],at),at+=8;var mt=new Uint16Array(52488);for(at=0,ut=0;ut<2187;ut+=729)for(lt=0;lt<729;lt+=243)for(ct=0;ct<243;ct+=81)for(ft=0;ft<81;ft+=27)for(vt=0;vt<27;vt+=9)for(pt=0;pt<9;pt+=3)for(dt=0;dt<3;dt+=1)for(yt=0;yt<6561;yt+=2187){var wt=ut+lt+ct+ft+vt+pt+dt+yt,gt=ot.subarray(8*wt,8*wt+8);mt.set(gt,at),at+=8}var _t=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=ot.subarray(8*t,8*t+8);_t.set(n,8*i)}));var bt=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=ot.subarray(8*t,8*t+8);bt.set(n,8*i)}));var At=[.2,.5,1,2,4,6,8,12,20,24,30],Ft={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]},xt=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 W(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),r=this.readUint32();this.sections[s]={offset:i,length:r},i+=r+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),r=this.readHex(10),e=this.readUtf16(11),o=this.readUtf16(11),h=this.readUtf16(11),a=this.readUtf8(28),u=this.readUtf8(28),l=this.readUtf8(28),c=this.readUint16(),f=this.readUint16(),v=this.readUint16(),p=this.readUint8();this.readUint8();this.frameCount=c,this.thumbFrameIndex=f,this.frameSpeed=p,this.framerate=At[p],this.meta={lock:1==(1&v),loop:1==(v>>1&1),frame_count:c,frame_speed:p,thumb_index:f,timestamp:i,creation_timestamp:t,root:{username:e,fsid:n,filename:a},parent:{username:o,fsid:s,filename:u},current:{username:h,fsid:r,filename:l}}},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=At[n];var s=new Uint32Array(this.buffer,i+4,20);this.soundMeta=((t={})[$.BGM]={offset:i+=28,length:s[0]},t[$.SE1]={offset:i+=s[0],length:s[1]},t[$.SE2]={offset:i+=s[1],length:s[2]},t[$.SE3]={offset:i+=s[2],length:s[3]},t[$.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 r=this.frameMeta[t],e=this.frameOffsets[t],o=0;o<3;o++){this.seek(e);var h=r.layerSize[o];if(e+=h,38!==h&&0!=(n>>o&1)){this.bitIndex=16,this.bitValue=0;for(var a=0,u=0;u<i.height;u+=128)for(var l=0;l<i.width;l+=128)for(var c=0;c<128;c+=8){var f=u+c;if(f>=i.height)break;for(var v=0;v<128;v+=8){var p=l+v;if(p>=i.width)break;if(a)a-=1;else{var d=f*i.width+p,y=this.layers[o],m=this.readBits(3);if(0==m){var w=this.readBits(5),g=_t.subarray(8*w,8*w+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){w=this.readBits(13),g=ot.subarray(8*w,8*w+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 _=this.readBits(5),b=_t.subarray(8*_,8*_+8),A=bt.subarray(8*_,8*_+8);y.set(b,d),y.set(A,d+320),y.set(b,d+640),y.set(A,d+960),y.set(b,d+1280),y.set(A,d+1600),y.set(b,d+1920),y.set(A,d+2240)}else if(3==m){_=this.readBits(13),b=ot.subarray(8*_,8*_+8),A=mt.subarray(8*_,8*_+8);y.set(b,d),y.set(A,d+320),y.set(b,d+640),y.set(A,d+960),y.set(b,d+1280),y.set(A,d+1600),y.set(b,d+1920),y.set(A,d+2240)}else if(4==m)for(var F=this.readBits(8),x=0;x<8;x++)if(F&1<<x){w=this.readBits(5),g=_t.subarray(8*w,8*w+8);y.set(g,d+320*x)}else{w=this.readBits(13),g=ot.subarray(8*w,8*w+8);y.set(g,d+320*x)}else{if(5==m){a=this.readBits(5);continue}if(7==m){var P=this.readBits(2);b=void 0,A=void 0;if(this.readBits(1)){var C=this.readBits(5),k=this.readBits(5);b=_t.subarray(8*C,8*C+8),A=_t.subarray(8*k,8*k+8),P=(P+1)%4}else{C=this.readBits(13),k=this.readBits(13);b=ot.subarray(8*C,8*C+8),A=ot.subarray(8*k,8*k+8)}0==P?(y.set(b,d),y.set(A,d+320),y.set(b,d+640),y.set(A,d+960),y.set(b,d+1280),y.set(A,d+1600),y.set(b,d+1920),y.set(A,d+2240)):1==P?(y.set(b,d),y.set(b,d+320),y.set(A,d+640),y.set(b,d+960),y.set(b,d+1280),y.set(A,d+1600),y.set(b,d+1920),y.set(b,d+2240)):2==P?(y.set(b,d),y.set(A,d+320),y.set(b,d+640),y.set(b,d+960),y.set(A,d+1280),y.set(b,d+1600),y.set(b,d+1920),y.set(A,d+2240)):3==P&&(y.set(b,d),y.set(A,d+320),y.set(A,d+640),y.set(b,d+960),y.set(A,d+1280),y.set(A,d+1600),y.set(b,d+1920),y.set(A,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),r=this.layers[n],e=new Uint8Array(i.width*i.height),o=2*n+1,h=0;h<r.length;h++){var a=r[h];65280&a?e[h]=s[o]:255&a&&(e[h]=s[o+1])}return e},i.prototype.getFramePixels=function(t){var n=this,s=this.getFramePaletteIndices(t),r=new Uint8Array(i.width*i.height);return r.fill(s[0]),this.getLayerOrder(t).forEach((function(i){for(var s=n.getLayerPixels(t,i),e=0;e<s.length;e++){var o=s[e];0!==o&&(r[e]=o)}})),r},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,r=this.soundMeta[t],e=new Uint8Array(this.buffer,r.offset,r.length),o=new Int16Array(981840),h=0,a=0,u=40,l=0;l<e.length;l++)for(var c=e[l],f=0;f<8;)u<18||6==f?(n=a+X[(i=c>>f&3)+4*u],s=u+q[i],f+=2):(n=a+it[(i=c>>f&15)+16*u],s=u+Z[i],f+=4),s=Math.max(0,Math.min(s,79)),n=Math.max(-2047,Math.min(n,2047)),o[h]=16*n,h+=1,u=s,a=n;return o.slice(0,h)},i.type="KWZ",i.width=320,i.height=240,i.sampleRate=16364,i.globalPalette=[Ft.WHITE,Ft.BLACK,Ft.RED,Ft.YELLOW,Ft.GREEN,Ft.BLUE,Ft.NONE],i}(V);function Pt(t){return function(t){return new Promise((function(i,n){H.forEach((function(s){s.matches(t)&&s.load(t,i,n)}))}))}(t).then((function(t){return new Promise((function(i,n){var s=new Uint8Array(t.slice(0,4)),r=s[0]<<24|s[1]<<16|s[2]<<8|s[3];1346458177===r?i(new et(t)):1262897152==(4294967040&r)?i(new xt(t)):n()}))}))}var Ct,kt=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),r=new N(s);r.writeUtf8("RIFF"),r.writeUint32(0),r.writeUtf8("WAVE"),r.writeUtf8("fmt "),r.writeUint32(16),r.writeUint16(1),r.writeUint16(this.channels),r.writeUint32(this.sampleRate),r.writeUint32(this.sampleRate*this.bitsPerSample*this.channels/8),r.writeUint16(this.bitsPerSample*this.channels/8),r.writeUint16(this.bitsPerSample),r.writeUtf8("data"),r.writeUint32(0),this.header=r,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}(),Ut=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 kt(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"}(Ct||(Ct={}));var Mt=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 r=t.getContext("webgl",s);this.el=t,this.gl=r,this.createProgram(),this.setCanvasSize(i,n),this.createScreenQuad(),this.createBitmapTexture(),r.enable(r.BLEND),r.blendEquation(r.FUNC_ADD),r.blendFunc(r.ONE,r.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),r=0;r<s;r++){var e=t.getActiveUniform(i,r).name;this.uniforms[e]=t.getUniformLocation(i,e)}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 r=n.getShaderInfoLog(s);throw n.deleteShader(s),new Error(r)}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,r=i*n;this.el.width=s,this.el.height=r,this.width=s,this.height=r,this.gl.viewport(0,0,s,r),this.gl.uniform2f(this.uniforms.u_screenSize,s,r),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,r){var e=this.gl;e.texImage2D(e.TEXTURE_2D,0,this.textureType,i,n,0,this.textureType,e.UNSIGNED_BYTE,t),this.setColor("u_color1",s),this.setColor("u_color2",r),e.drawArrays(e.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}(),St=function(){function t(t,i,n){this.loop=!1,this.paused=!0,this.duration=0,this.isOpen=!1,this.events={},this.t=-1,this.s=0,this.hasPlaybackStarted=!1,this.wasPlaying=!1,this.isSeeking=!1,t="string"==typeof t?document.querySelector(t):t,this.canvas=new Mt(t,i,n),this.el=this.canvas.el,this.customPalette=null,this.audioTracks=[new Ut("se1"),new Ut("se2"),new Ut("se3"),new Ut("se4"),new Ut("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.s:null},set:function(t){this.isOpen&&t<=this.duration&&t>=0&&(this.setFrame(Math.round(t/(1/this.framerate))),this.s=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 G(this,void 0,void 0,(function(){var i=this;return T(this,(function(n){return this.isOpen&&this.close(),[2,Pt(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.s=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})),[$.SE1,$.SE2,$.SE3,$.SE4,$.BGM].forEach((function(t,n){var s=t===$.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?Ct.Alpha:Ct.LuminanceAlpha),this.setFrame(this.note.thumbFrameIndex),this.s=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.s=0),this.paused=!1,this.playBgm();var i=performance.now()/1e3-this.currentTime,n=function(s){if(t.paused)return t.stopAudio(),null;var r=s/1e3,e=r-i;e>t.duration?t.loop?(t.currentTime=0,t.playBgm(),i=r,t.emit("playback:loop")):(t.pause(),t.emit("playback:end")):t.currentTime=e,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.s=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,r=this.note.getFramePalette(t),e=this.note.decodeFrame(t);this.canvas.setPaperColor(r[0]),this.canvas.clear(),"PPM"===this.note.type?(this.layerVisibility[2]&&this.canvas.drawLayer(e[1],n,s,r[2],[0,0,0,0]),this.layerVisibility[1]&&this.canvas.drawLayer(e[0],n,s,r[1],[0,0,0,0])):"KWZ"===this.note.type&&this.note.getLayerOrder(t).forEach((function(t){i.layerVisibility[t+1]&&i.canvas.drawLayer(e[t],n,s,r[2*t+1],r[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]||[],r=0;r<s.length;r++)s[r].apply(null,i)},t.prototype.clearEvents=function(){this.events={}},t.prototype.destroy=function(){this.close(),this.canvas.destroy()},t}();function Et(t,i){return t.toString().padStart(i,"0")}function Bt(t){return Math.floor(t%3600/60)+":"+Et(Math.round(t%60),2)}function zt(t,i){return t.replace(/<svg ([^>]*)>/,(function(t,n){return"<svg "+n+' style="'+i+'">'}))}function It(t){let n,s,o,c,d,m,w;return{c(){n=l("div"),s=l("div"),o=l("div"),c=f(),d=l("div"),this.c=i,p(o,"class","PlayerSlider__level"),y(o,"width",100*t[0]+"%"),p(d,"class","PlayerSlider__handle"),y(d,"left",100*t[0]+"%"),p(s,"class","PlayerSlider__track"),p(n,"class","PlayerSlider")},m(i,r){a(i,n,r),h(n,s),h(s,o),h(s,c),h(s,d),t[6](s),m||(w=[v(window,"mousemove",(function(){e(t[2]?t[5]:null)&&(t[2]?t[5]:null).apply(this,arguments)})),v(window,"mouseup",(function(){e(t[2]?t[4]:null)&&(t[2]?t[4]:null).apply(this,arguments)})),v(n,"mousedown",t[3])],m=!0)},p(i,[n]){t=i,1&n&&y(o,"width",100*t[0]+"%"),1&n&&y(d,"left",100*t[0]+"%")},i:i,o:i,d(i){i&&u(n),t[6](null),m=!1,r(w)}}}function Lt(t,i,n){let s,{value:r=0}=i,e=!1;const o=(h=g(),a=_(),function(t,i){a(t,i),h.dispatchEvent&&h.dispatchEvent(new CustomEvent(t,{detail:i}))});var h,a;function u(t){t.preventDefault();const i=s.getBoundingClientRect(),n=i.height/2,e=i.width-2*n,h=t.pageX-i.left-n,a=Math.max(0,Math.min(1,h/e));r!==a&&o("change",{value:a})}return t.$set=t=>{"value"in t&&n(0,r=t.value)},[r,s,e,function(t){t.preventDefault(),n(2,e=!0),u(t),o("inputstart")},function(t){t.preventDefault(),n(2,e=!1),u(t),o("inputend")},u,function(t){A[t?"unshift":"push"](()=>{s=t,n(1,s)})}]}customElements.define("flipnote-player-slider-bar",class extends I{constructor(t){super(),this.shadowRoot.innerHTML="<style>.PlayerSlider{padding:4px 0;cursor:pointer}.PlayerSlider__track{position:relative;flex:1;height:4px;border-radius:3px;margin:6px 0;background:var(--flipnote-player-slider-track, #FFD3A6)}.PlayerSlider__level{position:absolute;width:100%;height:6px;margin:-1px;border-radius:8px;background:var(--flipnote-player-slider-level, #F36A2D)}.PlayerSlider__handle{display:none;position:absolute;top:0;height:10px;width:6px;margin-left:-3px;margin-top:-3px;border-radius:2px;background:var(--flipnote-player-slider-handle, #F36A2D)}.PlayerSlider:hover .PlayerSlider__handle{display:block}</style>",D(this,{target:this.shadowRoot},Lt,It,o,{value:0}),t&&(t.target&&a(t.target,this,t.anchor),t.props&&(this.$set(t.props),S()))}static get observedAttributes(){return["value"]}get value(){return this.$$.ctx[0]}set value(t){this.$set({value:t}),S()}});function Ot(t){let n,s=t[1][t[0]]+"";return{c(){n=l("div"),this.c=i,p(n,"class","PlayerIcon")},m(t,i){a(t,n,i),n.innerHTML=s},p(t,[i]){1&i&&s!==(s=t[1][t[0]]+"")&&(n.innerHTML=s)},i:i,o:i,d(t){t&&u(n)}}}const jt="fill:currentColor";function Dt(t,i,n){let{icon:s="play"}=i;const r={play:zt('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 241 240"><path fill-rule="evenodd" d="M74.137 48h8.985a4 4 0 012.129.614l91.994 57.84c7.48 4.704 9.732 14.582 5.028 22.062a16 16 0 01-5.028 5.03l-91.994 57.84a4 4 0 01-2.13.614h-8.984C68.54 192 64 187.461 64 181.863V58.137C64 52.54 68.539 48 74.137 48z"/></svg>',jt),pause:zt('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240"><path fill-rule="evenodd" d="M64 48h24c8.837 0 16 7.163 16 16v112c0 8.837-7.163 16-16 16H64c-8.837 0-16-7.163-16-16V64c0-8.837 7.163-16 16-16zm88 0h24c8.837 0 16 7.163 16 16v112c0 8.837-7.163 16-16 16h-24c-8.837 0-16-7.163-16-16V64c0-8.837 7.163-16 16-16z"/></svg>',jt),loader:zt('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240"><path fill-rule="evenodd" d="M120 176c8.837 0 16 7.163 16 16s-7.163 16-16 16-16-7.163-16-16 7.163-16 16-16zm48.497-28c4.419-7.653 14.204-10.275 21.857-5.856 7.653 4.418 10.275 14.203 5.856 21.856-4.418 7.653-14.203 10.275-21.856 5.856-7.653-4.418-10.275-14.203-5.857-21.856zm-118.85-5.856c7.652-4.419 17.437-1.797 21.856 5.856 4.418 7.653 1.796 17.438-5.857 21.856-7.653 4.419-17.438 1.797-21.856-5.856-4.419-7.653-1.797-17.438 5.856-21.856zm124.707-72c7.653-4.419 17.438-1.797 21.856 5.856 4.419 7.653 1.797 17.438-5.856 21.856-7.653 4.419-17.438 1.797-21.857-5.856-4.418-7.653-1.796-17.438 5.857-21.856zM43.79 76c4.418-7.653 14.203-10.275 21.856-5.856C73.3 74.562 75.921 84.347 71.503 92c-4.419 7.653-14.204 10.275-21.857 5.856C41.993 93.438 39.371 83.653 43.79 76zM120 32c8.837 0 16 7.163 16 16s-7.163 16-16 16-16-7.163-16-16 7.163-16 16-16z"/></svg>',jt),volumeOn:zt('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240"><path d="M113.3 42.022a10 10 0 0110-1.2 10 10 0 015.7 9v140a10 10 0 01-5.7 9 9.116 9.116 0 01-4.3 1.001 10.009 10.009 0 01-6.2-2.2l-47.3-37.8H29c-5.523 0-10-4.478-10-10v-60c0-5.524 4.477-10 10-10h36.5zm82.986 17.298c17.008 16.234 25.715 36.022 25.715 58.68 0 22.37-8.465 43.147-24.992 61.928-4.378 4.975-11.96 5.459-16.936 1.08-4.975-4.378-5.46-11.96-1.08-16.936C191.798 149.52 198 134.297 198 118c0-16.009-5.96-29.554-18.286-41.32-4.794-4.576-4.97-12.172-.395-16.966 4.577-4.794 12.172-4.97 16.966-.394zM165.201 87.4c10.904 8.178 16.8 18.987 16.8 31.6 0 12.433-5.712 23.38-16.318 32.219-5.091 4.242-12.658 3.555-16.9-1.537-4.174-5.008-3.577-12.41 1.289-16.69l.246-.21c5.395-4.496 7.683-8.881 7.683-13.782 0-4.613-2.01-8.403-6.857-12.14l-.343-.26c-5.302-3.976-6.377-11.498-2.4-16.8 3.976-5.302 11.498-6.376 16.8-2.4z"/></svg>',jt),volumeOff:zt('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240"><path d="M123.3 40.822a10 10 0 00-10 1.2l-47.8 37.8H29c-5.523 0-10 4.477-10 10v60c0 5.523 4.477 10 10 10h36.5l47.3 37.8a10.009 10.009 0 006.2 2.201 9.116 9.116 0 004.3-1 10 10 0 005.7-9v-140a10 10 0 00-5.7-9zm70.451 50.462c4.702-4.454 12.126-4.377 16.734.23 4.608 4.609 4.685 12.033.23 16.735l-.23.236L198.971 120l11.514 11.515c4.687 4.686 4.687 12.284 0 16.97-4.608 4.608-12.032 4.685-16.734.23l-.236-.23L182 136.971l-11.515 11.514-.236.23c-4.702 4.455-12.126 4.378-16.734-.23-4.608-4.608-4.685-12.032-.23-16.734l.23-.236L165.029 120l-11.514-11.515c-4.687-4.686-4.687-12.284 0-16.97 4.608-4.608 12.032-4.685 16.734-.23l.236.23L182 103.029l11.515-11.514.236-.23z"/></svg>',jt)};return t.$set=t=>{"icon"in t&&n(0,s=t.icon)},[s,r]}function Rt(t){let i;return{c(){i=l("div"),i.textContent="Error",p(i,"class","FlipnotePlayer__overlay")},m(t,n){a(t,i,n)},d(t){t&&u(i)}}}function Wt(t){return{c:i,m:i,d:i}}function Gt(t){let i;return{c(){i=l("div"),i.innerHTML='<flipnote-player-icon icon="loader" class="FlipnotePlayer__loaderIcon"></flipnote-player-icon>',p(i,"class","FlipnotePlayer__overlay")},m(t,n){a(t,i,n)},d(t){t&&u(i)}}}function Tt(t){let n;return{c(){n=l("div"),n.textContent="todo :)",p(n,"class","FlipnotePlayerControls FlipnotePlayerControls--full")},m(t,i){a(t,n,i)},p:i,d(t){t&&u(n)}}}function Ht(t){let i,n,s,e,o,y,m,w,g,_,b,A,F,x,P,C,k,U,M,S,E;return{c(){i=l("div"),n=l("flipnote-player-slider-bar"),e=f(),o=l("div"),y=l("div"),m=l("button"),w=l("flipnote-player-icon"),_=f(),b=l("span"),A=c(t[6]),F=f(),x=l("div"),P=l("flipnote-player-icon"),k=f(),U=l("flipnote-player-slider-bar"),d(n,"class","FlipnotePlayerControls__progressBar"),d(n,"value",s=t[3]/100),d(w,"icon",g=t[4]?"pause":"play"),p(m,"class","Button FlipnotePlayerControls__playButton"),p(b,"class","FlipnotePlayerControls__frameCounter"),p(y,"class","FlipnotePlayerControls__groupLeft"),d(P,"class","FlipnotePlayerControls__muteIcon"),d(P,"icon",C=t[0]||0===t[5]?"volumeOff":"volumeOn"),d(U,"class","FlipnotePlayerControls__volumeBar"),d(U,"value",M=t[0]?0:t[5]),p(x,"class","FlipnotePlayerControls__groupRight"),p(o,"class","FlipnotePlayerControls__row"),p(i,"class","FlipnotePlayerControls FlipnotePlayerControls--default")},m(s,r){a(s,i,r),h(i,n),h(i,e),h(i,o),h(o,y),h(y,m),h(m,w),h(y,_),h(y,b),h(b,A),h(o,F),h(o,x),h(x,P),h(x,k),h(x,U),S||(E=[v(n,"change",t[9]),v(n,"inputstart",t[8]),v(n,"inputend",t[10]),v(m,"click",t[12]),v(P,"click",t[13]),v(U,"change",t[11])],S=!0)},p(t,i){8&i&&s!==(s=t[3]/100)&&d(n,"value",s),16&i&&g!==(g=t[4]?"pause":"play")&&d(w,"icon",g),64&i&&function(t,i){i=""+i,t.wholeText!==i&&(t.data=i)}(A,t[6]),33&i&&C!==(C=t[0]||0===t[5]?"volumeOff":"volumeOn")&&d(P,"icon",C),33&i&&M!==(M=t[0]?0:t[5])&&d(U,"value",M)},d(t){t&&u(i),S=!1,r(E)}}}function $t(t){let i,n,s,e,o,c,y,m,w;return{c(){i=l("div"),n=l("button"),s=l("flipnote-player-icon"),o=f(),c=l("flipnote-player-slider-bar"),d(s,"icon",e=t[4]?"pause":"play"),p(n,"class","Button FlipnotePlayerControls__playButton"),d(c,"class","FlipnotePlayerControls__progressBar"),d(c,"value",y=t[3]/100),p(i,"class","FlipnotePlayerControls FlipnotePlayerControls--compact FlipnotePlayerControls__row")},m(r,e){a(r,i,e),h(i,n),h(n,s),h(i,o),h(i,c),m||(w=[v(n,"click",t[12]),v(c,"change",t[9]),v(c,"inputstart",t[8]),v(c,"inputend",t[10])],m=!0)},p(t,i){16&i&&e!==(e=t[4]?"pause":"play")&&d(s,"icon",e),8&i&&y!==(y=t[3]/100)&&d(c,"value",y)},d(t){t&&u(i),m=!1,r(w)}}}function Kt(t){let n,s,r,e,o,c,d,y,m={ctx:t,current:null,token:null,pending:Gt,then:Wt,catch:Rt,error:23};function w(t,i){return"compact"===t[1]?$t:"default"===t[1]?Ht:"full"===t[1]?Tt:void 0}O(o=t[7],m);let g=w(t),_=g&&g(t);return{c(){n=l("div"),s=l("div"),r=l("canvas"),e=f(),m.block.c(),c=f(),_&&_.c(),this.c=i,p(r,"class","FlipnotePlayer__canvas"),p(s,"class","FlipnotePlayer__canvasArea"),p(n,"class","FlipnotePlayer")},m(i,o){a(i,n,o),h(n,s),h(s,r),t[16](r),h(s,e),m.block.m(s,m.anchor=null),m.mount=()=>s,m.anchor=null,h(n,c),_&&_.m(n,null),d||(y=v(r,"click",t[12]),d=!0)},p(i,[s]){t=i,m.ctx=t,128&s&&o!==(o=t[7])&&O(o,m),g===(g=w(t))&&_?_.p(t,s):(_&&_.d(1),_=g&&g(t),_&&(_.c(),_.m(n,null)))},i:i,o:i,d(i){i&&u(n),t[16](null),m.block.d(),m.token=null,m=null,_&&_.d(),d=!1,y()}}}function Nt(t,i,n){let s,r,{src:e=null}=i,{controls:o="default"}=i,{timeformat:h="frames"}=i,{muted:a=!1}=i,u=0,l=0,c=0,f=0,v=0,p=!1,d=1,y="";var m;m=()=>{n(17,s=new St(r,256,192)),s.on("load",()=>{n(19,c=s.frameCount),n(21,v=s.duration),n(5,d=s.volume),n(17,s.muted=a,s),s.resize(s.note.width,s.note.height)}),s.on("progress",t=>{n(3,u=t),n(20,f=s.currentTime)}),s.on("playback:start",()=>{n(4,p=!0)}),s.on("playback:stop",()=>{n(4,p=!1)}),s.on("frame:update",()=>{n(18,l=s.currentFrame+1)})},g().$$.on_mount.push(m);let w=new Promise((t,i)=>i());return t.$set=t=>{"src"in t&&n(14,e=t.src),"controls"in t&&n(1,o=t.controls),"timeformat"in t&&n(15,h=t.timeformat),"muted"in t&&n(0,a=t.muted)},t.$$.update=()=>{16384&t.$$.dirty&&e&&n(7,w=async function(t){await s.open(t)}(e)),131073&t.$$.dirty&&s&&n(17,s.muted=a,s),3964928&t.$$.dirty&&n(6,y="time"===h?`${Bt(f)} / ${Bt(v)}`:`${Et(l,3)} / ${Et(c,3)}`)},[a,o,r,u,p,d,y,w,function(t){s&&s.startSeek()},function(t){const{value:i}=t.detail;s&&s.seek(100*i)},function(t){s&&s.endSeek()},function(t){const{value:i}=t.detail;s&&(n(17,s.volume=i,s),n(5,d=i),d>0&&a&&n(0,a=!1))},function(){s&&s.togglePlay()},function(){n(0,a=!a)},e,h,function(t){A[t?"unshift":"push"](()=>{r=t,n(2,r)})}]}customElements.define("flipnote-player-icon",class extends I{constructor(t){super(),this.shadowRoot.innerHTML="<style>.PlayerIcon{width:100%;height:100%;color:var(--flipnote-player-icon-color, #F36A2D)}</style>",D(this,{target:this.shadowRoot},Dt,Ot,o,{icon:0}),t&&(t.target&&a(t.target,this,t.anchor),t.props&&(this.$set(t.props),S()))}static get observedAttributes(){return["icon"]}get icon(){return this.$$.ctx[0]}set icon(t){this.$set({icon:t}),S()}});class Vt extends I{constructor(t){super(),this.shadowRoot.innerHTML="<style>.Button{border:0;padding:0;outline:0;-webkit-appearance:none;display:block;font-family:inherit;font-size:inherit;text-align:center;cursor:pointer;background:var(--flipnote-player-button-background, #FFD3A6);color:var(--flipnote-player-button-color, #F36A2D);border-radius:4px}.Button flipnote-player-icon{display:block}.FlipnotePlayer{display:inline-block;position:relative;font-family:var(--flipnote-player-font-family, sans-serif)}.FlipnotePlayer__canvasArea{position:relative}.FlipnotePlayer__canvas{position:relative;display:block}.FlipnotePlayer__overlay{position:absolute;top:0;left:0;background:#e5e5e9;color:#4b4c53;width:100%;height:100%;display:flex;justify-content:center;align-items:center}@keyframes spin{from{transform:rotateZ(0)}to{transform:rotateZ(360deg)}}.FlipnotePlayer__loaderIcon{animation:spin infinite 1.2s linear}.FlipnotePlayerControls{background:var(--flipnote-player-controls-background, none)}.FlipnotePlayerControls__muteIcon{width:28px;height:28px}.FlipnotePlayerControls__row,.FlipnotePlayerControls__groupLeft,.FlipnotePlayerControls__groupRight{display:flex;align-items:center}.FlipnotePlayerControls__groupLeft{margin-right:auto}.FlipnotePlayerControls__groupRight{margin-left:auto}.FlipnotePlayerControls__playButton{height:32px;width:32px;padding:2px}.FlipnotePlayerControls__frameCounter{font-variant-numeric:tabular-nums}.FlipnotePlayerControls--compact .FlipnotePlayerControls__playButton{margin-right:12px}.FlipnotePlayerControls--compact .FlipnotePlayerControls__progressBar{flex:1}.FlipnotePlayerControls--default .FlipnotePlayerControls__playButton{margin-right:8px}.FlipnotePlayerControls--default .FlipnotePlayerControls__volumeBar{width:70px;margin-left:8px}</style>",D(this,{target:this.shadowRoot},Nt,Kt,o,{src:14,controls:1,timeformat:15,muted:0}),t&&(t.target&&a(t.target,this,t.anchor),t.props&&(this.$set(t.props),S()))}static get observedAttributes(){return["src","controls","timeformat","muted"]}get src(){return this.$$.ctx[14]}set src(t){this.$set({src:t}),S()}get controls(){return this.$$.ctx[1]}set controls(t){this.$set({controls:t}),S()}get timeformat(){return this.$$.ctx[15]}set timeformat(t){this.$set({timeformat:t}),S()}get muted(){return this.$$.ctx[0]}set muted(t){this.$set({muted:t}),S()}}var qt,Zt=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],Yt=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,r,e,o,h;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,e=this.nextPixel(),h=0,n=5003;n<65536;n*=2)++h;h=8-h,this.cl_hash(5003),this.output(this.ClearCode,i);t:for(;-1!=(s=this.nextPixel());)if(n=(s<<12)+e,r=s<<h^e,this.htab[r]!==n){if(this.htab[r]>=0){o=5003-r,0===r&&(o=1);do{if((r-=o)<0&&(r+=5003),this.htab[r]===n){e=this.codetab[r];continue t}}while(this.htab[r]>=0)}this.output(e,i),e=s,this.free_ent<4096?(this.codetab[r]=this.free_ent++,this.htab[r]=n):this.cl_block(i)}else e=this.codetab[r];this.output(e,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&=Zt[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}(),Xt=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 K}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 N(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 N(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 N(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 N(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 Yt(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.1",t.player=St,t.parseSource=Pt,t.kwzParser=xt,t.ppmParser=et,t.gifEncoder=Xt,t.wavEncoder=kt}(qt||(qt={}));var Jt=St,Qt=Pt,ti=xt,ii=et,ni=Xt,si=kt;customElements.define("flipnote-player",Vt);var ri=Vt;t.gifEncoder=ni,t.kwzParser=ti,t.parseSource=Qt,t.player=Jt,t.playerComponent=ri,t.ppmParser=ii,t.version="4.1.1",t.wavEncoder=si,Object.defineProperty(t,"h",{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";function i(){}function n(t){return t()}function s(){return Object.create(null)}function r(t){t.forEach(n)}function e(t){return"function"==typeof t}function o(t,i){return t!=t?i==i:t!==i||t&&"object"==typeof t||"function"==typeof t}function h(t,i){t.appendChild(i)}function a(t,i,n){t.insertBefore(i,n||null)}function u(t){t.parentNode.removeChild(t)}function l(t){return document.createElement(t)}function c(t){return document.createTextNode(t)}function f(){return c(" ")}function v(t,i,n,s){return t.addEventListener(i,n,s),()=>t.removeEventListener(i,n,s)}function p(t,i,n){null==n?t.removeAttribute(i):t.getAttribute(i)!==n&&t.setAttribute(i,n)}function d(t,i,n){i in t?t[i]=n:p(t,i,n)}function y(t,i,n,s){t.style.setProperty(i,n,s?"important":"")}let m;function w(t){m=t}function g(){if(!m)throw new Error("Function called outside component initialization");return m}function _(){const t=g();return(i,n)=>{const s=t.$$.callbacks[i];if(s){const r=function(t,i){const n=document.createEvent("CustomEvent");return n.initCustomEvent(t,!1,!1,i),n}(i,n);s.slice().forEach(i=>{i.call(t,r)})}}}const b=[],A=[],F=[],x=[],P=Promise.resolve();let C=!1;function k(t){F.push(t)}let U=!1;const M=new Set;function S(){if(!U){U=!0;do{for(let t=0;t<b.length;t+=1){const i=b[t];w(i),E(i.$$)}for(b.length=0;A.length;)A.pop()();for(let t=0;t<F.length;t+=1){const i=F[t];M.has(i)||(M.add(i),i())}F.length=0}while(b.length);for(;x.length;)x.pop()();C=!1,U=!1,M.clear()}}function E(t){if(null!==t.fragment){t.update(),r(t.before_update);const i=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,i),t.after_update.forEach(k)}}const B=new Set;let z,I;function L(t,i){t&&t.i&&(B.delete(t),t.i(i))}function O(t,i){const n=i.token={};function s(t,s,e,o){if(i.token!==n)return;i.resolved=o;let h=i.ctx;void 0!==e&&(h=h.slice(),h[e]=o);const a=t&&(i.current=t)(h);let u=!1;i.block&&(i.blocks?i.blocks.forEach((t,n)=>{n!==s&&t&&(z={r:0,c:[],p:z},function(t,i,n,s){if(t&&t.o){if(B.has(t))return;B.add(t),z.c.push(()=>{B.delete(t),s&&(n&&t.d(1),s())}),t.o(i)}}(t,1,1,()=>{i.blocks[n]=null}),z.r||r(z.c),z=z.p)}):i.block.d(1),a.c(),L(a,1),a.m(i.mount(),i.anchor),u=!0),i.block=a,i.blocks&&(i.blocks[s]=a),u&&S()}if((e=t)&&"object"==typeof e&&"function"==typeof e.then){const n=g();if(t.then(t=>{w(n),s(i.then,1,i.value,t),w(null)},t=>{w(n),s(i.catch,2,i.error,t),w(null)}),i.current!==i.pending)return s(i.pending,0),!0}else{if(i.current!==i.then)return s(i.then,1,i.value,t),!0;i.resolved=t}var e}function j(t,i){-1===t.$$.dirty[0]&&(b.push(t),C||(C=!0,P.then(S)),t.$$.dirty.fill(0)),t.$$.dirty[i/31|0]|=1<<i%31}function D(t,o,h,a,l,c,f=[-1]){const v=m;w(t);const p=o.props||{},d=t.$$={fragment:null,ctx:null,props:c,update:i,not_equal:l,bound:s(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(v?v.$$.context:[]),callbacks:s(),dirty:f};let y=!1;if(d.ctx=h?h(t,p,(i,n,...s)=>{const r=s.length?s[0]:n;return d.ctx&&l(d.ctx[i],d.ctx[i]=r)&&(d.bound[i]&&d.bound[i](r),y&&j(t,i)),n}):[],d.update(),y=!0,r(d.before_update),d.fragment=!!a&&a(d.ctx),o.target){if(o.hydrate){const t=function(t){return Array.from(t.childNodes)}(o.target);d.fragment&&d.fragment.l(t),t.forEach(u)}else d.fragment&&d.fragment.c();o.intro&&L(t.$$.fragment),function(t,i,s){const{fragment:o,on_mount:h,on_destroy:a,after_update:u}=t.$$;o&&o.m(i,s),k(()=>{const i=h.map(n).filter(e);a?a.push(...i):r(i),t.$$.on_mount=[]}),u.forEach(k)}(t,o.target,o.anchor),S()}w(v)}"function"==typeof HTMLElement&&(I=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"})}connectedCallback(){for(const t in this.$$.slotted)this.appendChild(this.$$.slotted[t])}attributeChangedCallback(t,i,n){this[t]=n}$destroy(){!function(t,i){const n=t.$$;null!==n.fragment&&(r(n.on_destroy),n.fragment&&n.fragment.d(i),n.on_destroy=n.fragment=null,n.ctx=[])}(this,1),this.$destroy=i}$on(t,i){const n=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return n.push(i),()=>{const t=n.indexOf(i);-1!==t&&n.splice(t,1)}}$set(){}});var R=function(t,i){return(R=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 W(t,i){function n(){this.constructor=t}R(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}function G(t,i,n,s){return new(n||(n=Promise))((function(r,e){function o(t){try{a(s.next(t))}catch(t){e(t)}}function h(t){try{a(s.throw(t))}catch(t){e(t)}}function a(t){var i;t.done?r(t.value):(i=t.value,i instanceof n?i:new n((function(t){t(i)}))).then(o,h)}a((s=s.apply(t,i||[])).next())}))}function T(t,i){var n,s,r,e,o={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return e={next:h(0),throw:h(1),return:h(2)},"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function h(e){return function(h){return function(e){if(n)throw new TypeError("Generator is already executing.");for(;o;)try{if(n=1,s&&(r=2&e[0]?s.return:e[0]?s.throw||((r=s.return)&&r.call(s),0):s.next)&&!(r=r.call(s,e[1])).done)return r;switch(s=0,r&&(e=[2&e[0],r.value]),e[0]){case 0:case 1:r=e;break;case 4:return o.label++,{value:e[1],done:!1};case 5:o.label++,s=e[1],e=[0];continue;case 7:e=o.ops.pop(),o.trys.pop();continue;default:if(!(r=o.trys,(r=r.length>0&&r[r.length-1])||6!==e[0]&&2!==e[0])){o=0;continue}if(3===e[0]&&(!r||e[1]>r[0]&&e[1]<r[3])){o.label=e[1];break}if(6===e[0]&&o.label<r[1]){o.label=r[1],r=e;break}if(r&&o.label<r[2]){o.label=r[2],o.ops.push(e);break}r[2]&&o.ops.pop(),o.trys.pop();continue}e=i.call(t,o)}catch(t){e=[6,t],s=0}finally{n=r=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,h])}}}var H=[{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 $,K=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,r){r===i.page?n.set(s.slice(0,i.cursor),r*t.pageSize):n.set(s,r*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,r=i||0;r<s;r++)this.writeByte(t[r])},t.pageSize=4096,t}(),N=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=[],r=0;r<n.length;r++)s.push(n[r].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 r=i[s];if(0===r)break;n+=String.fromCharCode(r)}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 r=i[s];if(0==r)break;n+=String.fromCharCode(r)}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"}($||($={}));for(var V=function(t){function i(){return null!==t&&t.apply(this,arguments)||this}return W(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}(N),q=new Int8Array([-1,2,-1,2]),Z=new Int8Array([-1,-1,-1,-1,2,4,6,8,-1,-1,-1,-1,2,4,6,8]),Y=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]),X=new Int16Array(360),J=0;J<4;J++)for(var Q=0;Q<90;Q++){var tt=(nt=Y[Q])>>3;1&J&&(tt+=nt),2&J&&(tt=-tt),X[J+4*Q]=tt}var it=new Int16Array(1440);for(J=0;J<16;J++)for(Q=0;Q<90;Q++){var nt;tt=(nt=Y[Q])>>3;4&J&&(tt+=nt),2&J&&(tt+=nt>>1),1&J&&(tt+=nt>>2),8&J&&(tt=-tt),it[J+16*Q]=tt}for(var st=[null,.5,1,2,4,6,12,20,30],rt={WHITE:[255,255,255],BLACK:[14,14,14],RED:[255,42,42],BLUE:[10,57,255]},et=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 W(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(),r=0;r<8;r+=2)t[4*n+r/2]=s>>r&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),r=this.readUtf16(11),e=this.readHex(8,!0),o=this.readHex(8,!0),h=this.readFilename(),a=this.readFilename(),u=this.readHex(8,!0);this.seek(154);var l=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:l,spinoff:o!==e||o!==u,root:{filename:null,username:n,fsid:u},parent:{username:s,fsid:e,filename:h},current:{username:r,fsid:o,filename:a}}},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(),r=this.readUint32(),e=this.readUint32();this.frameSpeed=8-this.readUint8(),this.bgmSpeed=8-this.readUint8(),i+=32,this.framerate=st[this.frameSpeed],this.bgmrate=st[this.bgmSpeed],this.soundMeta=((t={})[$.BGM]={offset:i,length:n},t[$.SE1]={offset:i+=n,length:s},t[$.SE2]={offset:i+=s,length:r},t[$.SE3]={offset:i+=r,length:e},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,r=n>>5&3,e=0,o=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),r&&(e=this.readInt8(),o=this.readInt8());for(var h=[this.readLineEncoding(),this.readLineEncoding()],a=0;a<2;a++)for(var u=this.layers[a],l=0;l<i.height;l++){var c=h[a][l],f=l*i.width;switch(c){case 0:break;case 1:case 2:var v=this.readUint32(!1);for(2==c&&u.fill(255,f,f+i.width);4294967295&v;){if(2147483648&v)for(var p=this.readUint8(),d=0;d<8;d++)u[f+d]=p>>d&1?255:0;f+=8,v<<=1}break;case 3:for(;f<(l+1)*i.width;){for(p=this.readUint8(),d=0;d<8;d++)u[f+d]=p>>d&1?255:0;f+=8}}}if(!s)for(var y=void 0,m=void 0,w=0;w<i.height;w++)if(!(w-o<0)){if(w-o>=i.height)break;for(var g=0;g<i.width;g++)if(!(g-e<0)){if(g-e>=i.width)break;m=(y=g+w*i.width)-(e+o*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),r=this.layers[n],e=new Uint8Array(i.width*i.height),o=s[n+1],h=0;h<e.length;h++)0!==r[h]&&(e[h]=o);return e},i.prototype.getFramePixels=function(t){var n=this.getFramePaletteIndices(t),s=this.decodeFrame(t),r=new Uint8Array(i.width*i.height);r.fill(n[0]);for(var e=0;e<r.length;e++){var o=s[0][e],h=s[1][e];0!==o?r[e]=n[1]:0!==h&&(r[e]=n[2])}return r},i.prototype.decodeAudio=function(t){for(var i,n,s,r=this.soundMeta[t],e=new Uint8Array(this.buffer,r.offset,r.length),o=new Int16Array(2*e.length),h=0,a=0,u=0,l=0;l<e.length;l++)for(var c=e[l],f=0;f<8;)n=a+it[(i=c>>f&15)+16*u],s=u+Z[i],s=Math.max(0,Math.min(s,79)),n=Math.max(-32767,Math.min(n,32767)),o[h]=n,h+=1,u=s,a=n,f+=4;return o},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=[rt.WHITE,rt.BLACK,rt.RED,rt.BLUE],i}(V),ot=new Uint16Array(52488),ht=[0,65280,255],at=0,ut=0;ut<3;ut++)for(var lt=0;lt<3;lt++)for(var ct=0;ct<3;ct++)for(var ft=0;ft<3;ft++)for(var vt=0;vt<3;vt++)for(var pt=0;pt<3;pt++)for(var dt=0;dt<3;dt++)for(var yt=0;yt<3;yt++)ot.set([ht[lt],ht[ut],ht[ft],ht[ct],ht[pt],ht[vt],ht[yt],ht[dt]],at),at+=8;var mt=new Uint16Array(52488);for(at=0,ut=0;ut<2187;ut+=729)for(lt=0;lt<729;lt+=243)for(ct=0;ct<243;ct+=81)for(ft=0;ft<81;ft+=27)for(vt=0;vt<27;vt+=9)for(pt=0;pt<9;pt+=3)for(dt=0;dt<3;dt+=1)for(yt=0;yt<6561;yt+=2187){var wt=ut+lt+ct+ft+vt+pt+dt+yt,gt=ot.subarray(8*wt,8*wt+8);mt.set(gt,at),at+=8}var _t=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=ot.subarray(8*t,8*t+8);_t.set(n,8*i)}));var bt=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=ot.subarray(8*t,8*t+8);bt.set(n,8*i)}));var At=[.2,.5,1,2,4,6,8,12,20,24,30],Ft={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]},xt=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 W(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),r=this.readUint32();this.sections[s]={offset:i,length:r},i+=r+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),r=this.readHex(10),e=this.readUtf16(11),o=this.readUtf16(11),h=this.readUtf16(11),a=this.readUtf8(28),u=this.readUtf8(28),l=this.readUtf8(28),c=this.readUint16(),f=this.readUint16(),v=this.readUint16(),p=this.readUint8();this.readUint8();this.frameCount=c,this.thumbFrameIndex=f,this.frameSpeed=p,this.framerate=At[p],this.meta={lock:1==(1&v),loop:1==(v>>1&1),frame_count:c,frame_speed:p,thumb_index:f,timestamp:i,creation_timestamp:t,root:{username:e,fsid:n,filename:a},parent:{username:o,fsid:s,filename:u},current:{username:h,fsid:r,filename:l}}},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=At[n];var s=new Uint32Array(this.buffer,i+4,20);this.soundMeta=((t={})[$.BGM]={offset:i+=28,length:s[0]},t[$.SE1]={offset:i+=s[0],length:s[1]},t[$.SE2]={offset:i+=s[1],length:s[2]},t[$.SE3]={offset:i+=s[2],length:s[3]},t[$.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 r=this.frameMeta[t],e=this.frameOffsets[t],o=0;o<3;o++){this.seek(e);var h=r.layerSize[o];if(e+=h,38!==h&&0!=(n>>o&1)){this.bitIndex=16,this.bitValue=0;for(var a=0,u=0;u<i.height;u+=128)for(var l=0;l<i.width;l+=128)for(var c=0;c<128;c+=8){var f=u+c;if(f>=i.height)break;for(var v=0;v<128;v+=8){var p=l+v;if(p>=i.width)break;if(a)a-=1;else{var d=f*i.width+p,y=this.layers[o],m=this.readBits(3);if(0==m){var w=this.readBits(5),g=_t.subarray(8*w,8*w+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){w=this.readBits(13),g=ot.subarray(8*w,8*w+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 _=this.readBits(5),b=_t.subarray(8*_,8*_+8),A=bt.subarray(8*_,8*_+8);y.set(b,d),y.set(A,d+320),y.set(b,d+640),y.set(A,d+960),y.set(b,d+1280),y.set(A,d+1600),y.set(b,d+1920),y.set(A,d+2240)}else if(3==m){_=this.readBits(13),b=ot.subarray(8*_,8*_+8),A=mt.subarray(8*_,8*_+8);y.set(b,d),y.set(A,d+320),y.set(b,d+640),y.set(A,d+960),y.set(b,d+1280),y.set(A,d+1600),y.set(b,d+1920),y.set(A,d+2240)}else if(4==m)for(var F=this.readBits(8),x=0;x<8;x++)if(F&1<<x){w=this.readBits(5),g=_t.subarray(8*w,8*w+8);y.set(g,d+320*x)}else{w=this.readBits(13),g=ot.subarray(8*w,8*w+8);y.set(g,d+320*x)}else{if(5==m){a=this.readBits(5);continue}if(7==m){var P=this.readBits(2);b=void 0,A=void 0;if(this.readBits(1)){var C=this.readBits(5),k=this.readBits(5);b=_t.subarray(8*C,8*C+8),A=_t.subarray(8*k,8*k+8),P=(P+1)%4}else{C=this.readBits(13),k=this.readBits(13);b=ot.subarray(8*C,8*C+8),A=ot.subarray(8*k,8*k+8)}0==P?(y.set(b,d),y.set(A,d+320),y.set(b,d+640),y.set(A,d+960),y.set(b,d+1280),y.set(A,d+1600),y.set(b,d+1920),y.set(A,d+2240)):1==P?(y.set(b,d),y.set(b,d+320),y.set(A,d+640),y.set(b,d+960),y.set(b,d+1280),y.set(A,d+1600),y.set(b,d+1920),y.set(b,d+2240)):2==P?(y.set(b,d),y.set(A,d+320),y.set(b,d+640),y.set(b,d+960),y.set(A,d+1280),y.set(b,d+1600),y.set(b,d+1920),y.set(A,d+2240)):3==P&&(y.set(b,d),y.set(A,d+320),y.set(A,d+640),y.set(b,d+960),y.set(A,d+1280),y.set(A,d+1600),y.set(b,d+1920),y.set(A,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),r=this.layers[n],e=new Uint8Array(i.width*i.height),o=2*n+1,h=0;h<r.length;h++){var a=r[h];65280&a?e[h]=s[o]:255&a&&(e[h]=s[o+1])}return e},i.prototype.getFramePixels=function(t){var n=this,s=this.getFramePaletteIndices(t),r=new Uint8Array(i.width*i.height);return r.fill(s[0]),this.getLayerOrder(t).forEach((function(i){for(var s=n.getLayerPixels(t,i),e=0;e<s.length;e++){var o=s[e];0!==o&&(r[e]=o)}})),r},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,r=this.soundMeta[t],e=new Uint8Array(this.buffer,r.offset,r.length),o=new Int16Array(981840),h=0,a=0,u=40,l=0;l<e.length;l++)for(var c=e[l],f=0;f<8;)u<18||6==f?(n=a+X[(i=c>>f&3)+4*u],s=u+q[i],f+=2):(n=a+it[(i=c>>f&15)+16*u],s=u+Z[i],f+=4),s=Math.max(0,Math.min(s,79)),n=Math.max(-2047,Math.min(n,2047)),o[h]=16*n,h+=1,u=s,a=n;return o.slice(0,h)},i.type="KWZ",i.width=320,i.height=240,i.sampleRate=16364,i.globalPalette=[Ft.WHITE,Ft.BLACK,Ft.RED,Ft.YELLOW,Ft.GREEN,Ft.BLUE,Ft.NONE],i}(V);function Pt(t){return function(t){return new Promise((function(i,n){H.forEach((function(s){s.matches(t)&&s.load(t,i,n)}))}))}(t).then((function(t){return new Promise((function(i,n){var s=new Uint8Array(t.slice(0,4)),r=s[0]<<24|s[1]<<16|s[2]<<8|s[3];1346458177===r?i(new et(t)):1262897152==(4294967040&r)?i(new xt(t)):n()}))}))}var Ct,kt=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),r=new N(s);r.writeUtf8("RIFF"),r.writeUint32(0),r.writeUtf8("WAVE"),r.writeUtf8("fmt "),r.writeUint32(16),r.writeUint16(1),r.writeUint16(this.channels),r.writeUint32(this.sampleRate),r.writeUint32(this.sampleRate*this.bitsPerSample*this.channels/8),r.writeUint16(this.bitsPerSample*this.channels/8),r.writeUint16(this.bitsPerSample),r.writeUtf8("data"),r.writeUint32(0),this.header=r,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}(),Ut=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 kt(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"}(Ct||(Ct={}));var Mt=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 r=t.getContext("webgl",s);this.el=t,this.gl=r,this.createProgram(),this.setCanvasSize(i,n),this.createScreenQuad(),this.createBitmapTexture(),r.enable(r.BLEND),r.blendEquation(r.FUNC_ADD),r.blendFunc(r.ONE,r.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),r=0;r<s;r++){var e=t.getActiveUniform(i,r).name;this.uniforms[e]=t.getUniformLocation(i,e)}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 r=n.getShaderInfoLog(s);throw n.deleteShader(s),new Error(r)}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,r=i*n;this.el.width=s,this.el.height=r,this.width=s,this.height=r,this.gl.viewport(0,0,s,r),this.gl.uniform2f(this.uniforms.u_screenSize,s,r),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,r){var e=this.gl;e.texImage2D(e.TEXTURE_2D,0,this.textureType,i,n,0,this.textureType,e.UNSIGNED_BYTE,t),this.setColor("u_color1",s),this.setColor("u_color2",r),e.drawArrays(e.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}(),St=function(){function t(t,i,n){this.loop=!1,this.paused=!0,this.duration=0,this.isOpen=!1,this.events={},this.t=-1,this.s=0,this.hasPlaybackStarted=!1,this.wasPlaying=!1,this.isSeeking=!1,t="string"==typeof t?document.querySelector(t):t,this.canvas=new Mt(t,i,n),this.el=this.canvas.el,this.customPalette=null,this.audioTracks=[new Ut("se1"),new Ut("se2"),new Ut("se3"),new Ut("se4"),new Ut("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.s:null},set:function(t){this.isOpen&&t<=this.duration&&t>=0&&(this.setFrame(Math.round(t/(1/this.framerate))),this.s=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 G(this,void 0,void 0,(function(){var i=this;return T(this,(function(n){return this.isOpen&&this.close(),[2,Pt(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.s=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})),[$.SE1,$.SE2,$.SE3,$.SE4,$.BGM].forEach((function(t,n){var s=t===$.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?Ct.Alpha:Ct.LuminanceAlpha),this.setFrame(this.note.thumbFrameIndex),this.s=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.s=0),this.paused=!1,this.playBgm();var i=performance.now()/1e3-this.currentTime,n=function(s){if(t.paused)return t.stopAudio(),null;var r=s/1e3,e=r-i;e>t.duration?t.loop?(t.currentTime=0,t.playBgm(),i=r,t.emit("playback:loop")):(t.pause(),t.emit("playback:end")):t.currentTime=e,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.s=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,r=this.note.getFramePalette(t),e=this.note.decodeFrame(t);this.canvas.setPaperColor(r[0]),this.canvas.clear(),"PPM"===this.note.type?(this.layerVisibility[2]&&this.canvas.drawLayer(e[1],n,s,r[2],[0,0,0,0]),this.layerVisibility[1]&&this.canvas.drawLayer(e[0],n,s,r[1],[0,0,0,0])):"KWZ"===this.note.type&&this.note.getLayerOrder(t).forEach((function(t){i.layerVisibility[t+1]&&i.canvas.drawLayer(e[t],n,s,r[2*t+1],r[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]||[],r=0;r<s.length;r++)s[r].apply(null,i)},t.prototype.clearEvents=function(){this.events={}},t.prototype.destroy=function(){this.close(),this.canvas.destroy()},t}();function Et(t,i){return t.toString().padStart(i,"0")}function Bt(t){return Math.floor(t%3600/60)+":"+Et(Math.round(t%60),2)}function zt(t,i){return t.replace(/<svg ([^>]*)>/,(function(t,n){return"<svg "+n+' style="'+i+'">'}))}function It(t){let n,s,o,c,d,m,w;return{c(){n=l("div"),s=l("div"),o=l("div"),c=f(),d=l("div"),this.c=i,p(o,"class","PlayerSlider__level"),y(o,"width",100*t[0]+"%"),p(d,"class","PlayerSlider__handle"),y(d,"left",100*t[0]+"%"),p(s,"class","PlayerSlider__track"),p(n,"class","PlayerSlider")},m(i,r){a(i,n,r),h(n,s),h(s,o),h(s,c),h(s,d),t[6](s),m||(w=[v(window,"mousemove",(function(){e(t[2]?t[5]:null)&&(t[2]?t[5]:null).apply(this,arguments)})),v(window,"mouseup",(function(){e(t[2]?t[4]:null)&&(t[2]?t[4]:null).apply(this,arguments)})),v(n,"mousedown",t[3])],m=!0)},p(i,[n]){t=i,1&n&&y(o,"width",100*t[0]+"%"),1&n&&y(d,"left",100*t[0]+"%")},i:i,o:i,d(i){i&&u(n),t[6](null),m=!1,r(w)}}}function Lt(t,i,n){let s,{value:r=0}=i,e=!1;const o=(h=g(),a=_(),function(t,i){a(t,i),h.dispatchEvent&&h.dispatchEvent(new CustomEvent(t,{detail:i}))});var h,a;function u(t){t.preventDefault();const i=s.getBoundingClientRect(),n=i.height/2,e=i.width-2*n,h=t.pageX-i.left-n,a=Math.max(0,Math.min(1,h/e));r!==a&&o("change",{value:a})}return t.$set=t=>{"value"in t&&n(0,r=t.value)},[r,s,e,function(t){t.preventDefault(),n(2,e=!0),u(t),o("inputstart")},function(t){t.preventDefault(),n(2,e=!1),u(t),o("inputend")},u,function(t){A[t?"unshift":"push"](()=>{s=t,n(1,s)})}]}customElements.define("flipnote-player-slider-bar",class extends I{constructor(t){super(),this.shadowRoot.innerHTML="<style>.PlayerSlider{padding:4px 0;cursor:pointer}.PlayerSlider__track{position:relative;flex:1;height:4px;border-radius:3px;margin:6px 0;background:var(--flipnote-player-slider-track, #FFD3A6)}.PlayerSlider__level{position:absolute;width:100%;height:6px;margin:-1px;border-radius:8px;background:var(--flipnote-player-slider-level, #F36A2D)}.PlayerSlider__handle{display:none;position:absolute;top:0;height:10px;width:6px;margin-left:-3px;margin-top:-3px;border-radius:2px;background:var(--flipnote-player-slider-handle, #F36A2D)}.PlayerSlider:hover .PlayerSlider__handle{display:block}</style>",D(this,{target:this.shadowRoot},Lt,It,o,{value:0}),t&&(t.target&&a(t.target,this,t.anchor),t.props&&(this.$set(t.props),S()))}static get observedAttributes(){return["value"]}get value(){return this.$$.ctx[0]}set value(t){this.$set({value:t}),S()}});function Ot(t){let n,s=t[1][t[0]]+"";return{c(){n=l("div"),this.c=i,p(n,"class","PlayerIcon")},m(t,i){a(t,n,i),n.innerHTML=s},p(t,[i]){1&i&&s!==(s=t[1][t[0]]+"")&&(n.innerHTML=s)},i:i,o:i,d(t){t&&u(n)}}}const jt="fill:currentColor";function Dt(t,i,n){let{icon:s="play"}=i;const r={play:zt('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 241 240"><path fill-rule="evenodd" d="M74.137 48h8.985a4 4 0 012.129.614l91.994 57.84c7.48 4.704 9.732 14.582 5.028 22.062a16 16 0 01-5.028 5.03l-91.994 57.84a4 4 0 01-2.13.614h-8.984C68.54 192 64 187.461 64 181.863V58.137C64 52.54 68.539 48 74.137 48z"/></svg>',jt),pause:zt('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240"><path fill-rule="evenodd" d="M64 48h24c8.837 0 16 7.163 16 16v112c0 8.837-7.163 16-16 16H64c-8.837 0-16-7.163-16-16V64c0-8.837 7.163-16 16-16zm88 0h24c8.837 0 16 7.163 16 16v112c0 8.837-7.163 16-16 16h-24c-8.837 0-16-7.163-16-16V64c0-8.837 7.163-16 16-16z"/></svg>',jt),loader:zt('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240"><path fill-rule="evenodd" d="M120 176c8.837 0 16 7.163 16 16s-7.163 16-16 16-16-7.163-16-16 7.163-16 16-16zm48.497-28c4.419-7.653 14.204-10.275 21.857-5.856 7.653 4.418 10.275 14.203 5.856 21.856-4.418 7.653-14.203 10.275-21.856 5.856-7.653-4.418-10.275-14.203-5.857-21.856zm-118.85-5.856c7.652-4.419 17.437-1.797 21.856 5.856 4.418 7.653 1.796 17.438-5.857 21.856-7.653 4.419-17.438 1.797-21.856-5.856-4.419-7.653-1.797-17.438 5.856-21.856zm124.707-72c7.653-4.419 17.438-1.797 21.856 5.856 4.419 7.653 1.797 17.438-5.856 21.856-7.653 4.419-17.438 1.797-21.857-5.856-4.418-7.653-1.796-17.438 5.857-21.856zM43.79 76c4.418-7.653 14.203-10.275 21.856-5.856C73.3 74.562 75.921 84.347 71.503 92c-4.419 7.653-14.204 10.275-21.857 5.856C41.993 93.438 39.371 83.653 43.79 76zM120 32c8.837 0 16 7.163 16 16s-7.163 16-16 16-16-7.163-16-16 7.163-16 16-16z"/></svg>',jt),volumeOn:zt('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240"><path d="M113.3 42.022a10 10 0 0110-1.2 10 10 0 015.7 9v140a10 10 0 01-5.7 9 9.116 9.116 0 01-4.3 1.001 10.009 10.009 0 01-6.2-2.2l-47.3-37.8H29c-5.523 0-10-4.478-10-10v-60c0-5.524 4.477-10 10-10h36.5zm82.986 17.298c17.008 16.234 25.715 36.022 25.715 58.68 0 22.37-8.465 43.147-24.992 61.928-4.378 4.975-11.96 5.459-16.936 1.08-4.975-4.378-5.46-11.96-1.08-16.936C191.798 149.52 198 134.297 198 118c0-16.009-5.96-29.554-18.286-41.32-4.794-4.576-4.97-12.172-.395-16.966 4.577-4.794 12.172-4.97 16.966-.394zM165.201 87.4c10.904 8.178 16.8 18.987 16.8 31.6 0 12.433-5.712 23.38-16.318 32.219-5.091 4.242-12.658 3.555-16.9-1.537-4.174-5.008-3.577-12.41 1.289-16.69l.246-.21c5.395-4.496 7.683-8.881 7.683-13.782 0-4.613-2.01-8.403-6.857-12.14l-.343-.26c-5.302-3.976-6.377-11.498-2.4-16.8 3.976-5.302 11.498-6.376 16.8-2.4z"/></svg>',jt),volumeOff:zt('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240"><path d="M123.3 40.822a10 10 0 00-10 1.2l-47.8 37.8H29c-5.523 0-10 4.477-10 10v60c0 5.523 4.477 10 10 10h36.5l47.3 37.8a10.009 10.009 0 006.2 2.201 9.116 9.116 0 004.3-1 10 10 0 005.7-9v-140a10 10 0 00-5.7-9zm70.451 50.462c4.702-4.454 12.126-4.377 16.734.23 4.608 4.609 4.685 12.033.23 16.735l-.23.236L198.971 120l11.514 11.515c4.687 4.686 4.687 12.284 0 16.97-4.608 4.608-12.032 4.685-16.734.23l-.236-.23L182 136.971l-11.515 11.514-.236.23c-4.702 4.455-12.126 4.378-16.734-.23-4.608-4.608-4.685-12.032-.23-16.734l.23-.236L165.029 120l-11.514-11.515c-4.687-4.686-4.687-12.284 0-16.97 4.608-4.608 12.032-4.685 16.734-.23l.236.23L182 103.029l11.515-11.514.236-.23z"/></svg>',jt)};return t.$set=t=>{"icon"in t&&n(0,s=t.icon)},[s,r]}function Rt(t){let i;return{c(){i=l("div"),i.textContent="Error",p(i,"class","FlipnotePlayer__overlay")},m(t,n){a(t,i,n)},d(t){t&&u(i)}}}function Wt(t){return{c:i,m:i,d:i}}function Gt(t){let i;return{c(){i=l("div"),i.innerHTML='<flipnote-player-icon icon="loader" class="FlipnotePlayer__loaderIcon"></flipnote-player-icon>',p(i,"class","FlipnotePlayer__overlay")},m(t,n){a(t,i,n)},d(t){t&&u(i)}}}function Tt(t){let n;return{c(){n=l("div"),n.textContent="todo :)",p(n,"class","FlipnotePlayerControls FlipnotePlayerControls--full")},m(t,i){a(t,n,i)},p:i,d(t){t&&u(n)}}}function Ht(t){let i,n,s,e,o,y,m,w,g,_,b,A,F,x,P,C,k,U,M,S,E;return{c(){i=l("div"),n=l("flipnote-player-slider-bar"),e=f(),o=l("div"),y=l("div"),m=l("button"),w=l("flipnote-player-icon"),_=f(),b=l("span"),A=c(t[6]),F=f(),x=l("div"),P=l("flipnote-player-icon"),k=f(),U=l("flipnote-player-slider-bar"),d(n,"class","FlipnotePlayerControls__progressBar"),d(n,"value",s=t[3]/100),d(w,"icon",g=t[4]?"pause":"play"),p(m,"class","Button FlipnotePlayerControls__playButton"),p(b,"class","FlipnotePlayerControls__frameCounter"),p(y,"class","FlipnotePlayerControls__groupLeft"),d(P,"class","FlipnotePlayerControls__muteIcon"),d(P,"icon",C=t[0]||0===t[5]?"volumeOff":"volumeOn"),d(U,"class","FlipnotePlayerControls__volumeBar"),d(U,"value",M=t[0]?0:t[5]),p(x,"class","FlipnotePlayerControls__groupRight"),p(o,"class","FlipnotePlayerControls__row"),p(i,"class","FlipnotePlayerControls FlipnotePlayerControls--default")},m(s,r){a(s,i,r),h(i,n),h(i,e),h(i,o),h(o,y),h(y,m),h(m,w),h(y,_),h(y,b),h(b,A),h(o,F),h(o,x),h(x,P),h(x,k),h(x,U),S||(E=[v(n,"change",t[9]),v(n,"inputstart",t[8]),v(n,"inputend",t[10]),v(m,"click",t[12]),v(P,"click",t[13]),v(U,"change",t[11])],S=!0)},p(t,i){8&i&&s!==(s=t[3]/100)&&d(n,"value",s),16&i&&g!==(g=t[4]?"pause":"play")&&d(w,"icon",g),64&i&&function(t,i){i=""+i,t.wholeText!==i&&(t.data=i)}(A,t[6]),33&i&&C!==(C=t[0]||0===t[5]?"volumeOff":"volumeOn")&&d(P,"icon",C),33&i&&M!==(M=t[0]?0:t[5])&&d(U,"value",M)},d(t){t&&u(i),S=!1,r(E)}}}function $t(t){let i,n,s,e,o,c,y,m,w;return{c(){i=l("div"),n=l("button"),s=l("flipnote-player-icon"),o=f(),c=l("flipnote-player-slider-bar"),d(s,"icon",e=t[4]?"pause":"play"),p(n,"class","Button FlipnotePlayerControls__playButton"),d(c,"class","FlipnotePlayerControls__progressBar"),d(c,"value",y=t[3]/100),p(i,"class","FlipnotePlayerControls FlipnotePlayerControls--compact FlipnotePlayerControls__row")},m(r,e){a(r,i,e),h(i,n),h(n,s),h(i,o),h(i,c),m||(w=[v(n,"click",t[12]),v(c,"change",t[9]),v(c,"inputstart",t[8]),v(c,"inputend",t[10])],m=!0)},p(t,i){16&i&&e!==(e=t[4]?"pause":"play")&&d(s,"icon",e),8&i&&y!==(y=t[3]/100)&&d(c,"value",y)},d(t){t&&u(i),m=!1,r(w)}}}function Kt(t){let n,s,r,e,o,c,d,y,m={ctx:t,current:null,token:null,pending:Gt,then:Wt,catch:Rt,error:23};function w(t,i){return"compact"===t[1]?$t:"default"===t[1]?Ht:"full"===t[1]?Tt:void 0}O(o=t[7],m);let g=w(t),_=g&&g(t);return{c(){n=l("div"),s=l("div"),r=l("canvas"),e=f(),m.block.c(),c=f(),_&&_.c(),this.c=i,p(r,"class","FlipnotePlayer__canvas"),p(s,"class","FlipnotePlayer__canvasArea"),p(n,"class","FlipnotePlayer")},m(i,o){a(i,n,o),h(n,s),h(s,r),t[16](r),h(s,e),m.block.m(s,m.anchor=null),m.mount=()=>s,m.anchor=null,h(n,c),_&&_.m(n,null),d||(y=v(r,"click",t[12]),d=!0)},p(i,[s]){t=i,m.ctx=t,128&s&&o!==(o=t[7])&&O(o,m),g===(g=w(t))&&_?_.p(t,s):(_&&_.d(1),_=g&&g(t),_&&(_.c(),_.m(n,null)))},i:i,o:i,d(i){i&&u(n),t[16](null),m.block.d(),m.token=null,m=null,_&&_.d(),d=!1,y()}}}function Nt(t,i,n){let s,r,{src:e=null}=i,{controls:o="default"}=i,{timeformat:h="frames"}=i,{muted:a=!1}=i,u=0,l=0,c=0,f=0,v=0,p=!1,d=1,y="";var m;m=()=>{n(17,s=new St(r,256,192)),s.on("load",()=>{n(19,c=s.frameCount),n(21,v=s.duration),n(5,d=s.volume),n(17,s.muted=a,s),s.resize(s.note.width,s.note.height)}),s.on("progress",t=>{n(3,u=t),n(20,f=s.currentTime)}),s.on("playback:start",()=>{n(4,p=!0)}),s.on("playback:stop",()=>{n(4,p=!1)}),s.on("frame:update",()=>{n(18,l=s.currentFrame+1)})},g().$$.on_mount.push(m);let w=new Promise((t,i)=>i());return t.$set=t=>{"src"in t&&n(14,e=t.src),"controls"in t&&n(1,o=t.controls),"timeformat"in t&&n(15,h=t.timeformat),"muted"in t&&n(0,a=t.muted)},t.$$.update=()=>{16384&t.$$.dirty&&e&&n(7,w=async function(t){await s.open(t)}(e)),131073&t.$$.dirty&&s&&n(17,s.muted=a,s),3964928&t.$$.dirty&&n(6,y="time"===h?`${Bt(f)} / ${Bt(v)}`:`${Et(l,3)} / ${Et(c,3)}`)},[a,o,r,u,p,d,y,w,function(t){s&&s.startSeek()},function(t){const{value:i}=t.detail;s&&s.seek(100*i)},function(t){s&&s.endSeek()},function(t){const{value:i}=t.detail;s&&(n(17,s.volume=i,s),n(5,d=i),d>0&&a&&n(0,a=!1))},function(){s&&s.togglePlay()},function(){n(0,a=!a)},e,h,function(t){A[t?"unshift":"push"](()=>{r=t,n(2,r)})}]}customElements.define("flipnote-player-icon",class extends I{constructor(t){super(),this.shadowRoot.innerHTML="<style>.PlayerIcon{width:100%;height:100%;color:var(--flipnote-player-icon-color, #F36A2D)}</style>",D(this,{target:this.shadowRoot},Dt,Ot,o,{icon:0}),t&&(t.target&&a(t.target,this,t.anchor),t.props&&(this.$set(t.props),S()))}static get observedAttributes(){return["icon"]}get icon(){return this.$$.ctx[0]}set icon(t){this.$set({icon:t}),S()}});class Vt extends I{constructor(t){super(),this.shadowRoot.innerHTML="<style>.Button{border:0;padding:0;outline:0;-webkit-appearance:none;display:block;font-family:inherit;font-size:inherit;text-align:center;cursor:pointer;background:var(--flipnote-player-button-background, #FFD3A6);color:var(--flipnote-player-button-color, #F36A2D);border-radius:4px}.Button flipnote-player-icon{display:block}.FlipnotePlayer{display:inline-block;position:relative;font-family:var(--flipnote-player-font-family, sans-serif)}.FlipnotePlayer__canvasArea{position:relative}.FlipnotePlayer__canvas{position:relative;display:block}.FlipnotePlayer__overlay{position:absolute;top:0;left:0;background:#e5e5e9;color:#4b4c53;width:100%;height:100%;display:flex;justify-content:center;align-items:center}@keyframes spin{from{transform:rotateZ(0)}to{transform:rotateZ(360deg)}}.FlipnotePlayer__loaderIcon{animation:spin infinite 1.2s linear}.FlipnotePlayerControls{background:var(--flipnote-player-controls-background, none)}.FlipnotePlayerControls__muteIcon{width:28px;height:28px}.FlipnotePlayerControls__row,.FlipnotePlayerControls__groupLeft,.FlipnotePlayerControls__groupRight{display:flex;align-items:center}.FlipnotePlayerControls__groupLeft{margin-right:auto}.FlipnotePlayerControls__groupRight{margin-left:auto}.FlipnotePlayerControls__playButton{height:32px;width:32px;padding:2px}.FlipnotePlayerControls__frameCounter{font-variant-numeric:tabular-nums}.FlipnotePlayerControls--compact .FlipnotePlayerControls__playButton{margin-right:12px}.FlipnotePlayerControls--compact .FlipnotePlayerControls__progressBar{flex:1}.FlipnotePlayerControls--default .FlipnotePlayerControls__playButton{margin-right:8px}.FlipnotePlayerControls--default .FlipnotePlayerControls__volumeBar{width:70px;margin-left:8px}</style>",D(this,{target:this.shadowRoot},Nt,Kt,o,{src:14,controls:1,timeformat:15,muted:0}),t&&(t.target&&a(t.target,this,t.anchor),t.props&&(this.$set(t.props),S()))}static get observedAttributes(){return["src","controls","timeformat","muted"]}get src(){return this.$$.ctx[14]}set src(t){this.$set({src:t}),S()}get controls(){return this.$$.ctx[1]}set controls(t){this.$set({controls:t}),S()}get timeformat(){return this.$$.ctx[15]}set timeformat(t){this.$set({timeformat:t}),S()}get muted(){return this.$$.ctx[0]}set muted(t){this.$set({muted:t}),S()}}var qt,Zt=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535],Yt=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,r,e,o,h;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,e=this.nextPixel(),h=0,n=5003;n<65536;n*=2)++h;h=8-h,this.cl_hash(5003),this.output(this.ClearCode,i);t:for(;-1!=(s=this.nextPixel());)if(n=(s<<12)+e,r=s<<h^e,this.htab[r]!==n){if(this.htab[r]>=0){o=5003-r,0===r&&(o=1);do{if((r-=o)<0&&(r+=5003),this.htab[r]===n){e=this.codetab[r];continue t}}while(this.htab[r]>=0)}this.output(e,i),e=s,this.free_ent<4096?(this.codetab[r]=this.free_ent++,this.htab[r]=n):this.cl_block(i)}else e=this.codetab[r];this.output(e,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&=Zt[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}(),Xt=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 K}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 N(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 N(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 N(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 N(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 Yt(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.2",t.player=St,t.parseSource=Pt,t.kwzParser=xt,t.ppmParser=et,t.gifEncoder=Xt,t.wavEncoder=kt}(qt||(qt={}));var Jt=St,Qt=Pt,ti=xt,ii=et,ni=Xt,si=kt;customElements.define("flipnote-player",Vt);var ri=Vt;t.gifEncoder=ni,t.kwzParser=ti,t.parseSource=Qt,t.player=Jt,t.playerComponent=ri,t.ppmParser=ii,t.version="4.1.2",t.wavEncoder=si,Object.defineProperty(t,"h",{value:!0})})); |
import { parseSource as _parseSource, Flipnote as _Flipnote, FlipnoteMeta as _FlipnoteMeta, FlipnoteAudioTrack as _FlipnoteAudioTrack, KwzParser, PpmParser } from './parsers/index'; | ||
import { GifEncoder, WavEncoder } from './encoders/index'; | ||
declare namespace api { | ||
const version = "4.1.1"; | ||
type Flipnpte = _Flipnote; | ||
const version = "4.1.2"; | ||
type Flipnote = _Flipnote; | ||
type FlipnoteMeta = _FlipnoteMeta; | ||
@@ -15,4 +15,4 @@ type FlipnoteAudioTrack = _FlipnoteAudioTrack; | ||
export default api; | ||
export declare const version = "4.1.1"; | ||
export declare type Flipnpte = _Flipnote; | ||
export declare const version = "4.1.2"; | ||
export declare type Flipnote = _Flipnote; | ||
export declare type FlipnoteMeta = _FlipnoteMeta; | ||
@@ -19,0 +19,0 @@ export declare type FlipnoteAudioTrack = _FlipnoteAudioTrack; |
{ | ||
"name": "flipnote.js", | ||
"version": "4.1.1", | ||
"version": "4.1.2", | ||
"description": "API for handling Flipnote Studio's animation formats, capable of real-time playback using webGL", | ||
@@ -5,0 +5,0 @@ "module": "dist/flipnote.es.js", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package