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

flipnote.js

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

flipnote.js - npm Package Compare versions

Comparing version 4.0.0 to 4.0.2

37

dist/flipnote.d.ts

@@ -1,15 +0,26 @@

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

@@ -46,7 +46,7 @@ import { FlipnoteAudioTrack, FlipnoteParserBase } from './parserBase';

static sampleRate: number;
static globalPalette: [number, number, number][];
static globalPalette: import("./parserBase").PaletteColor[];
type: string;
width: number;
height: number;
globalPalette: [number, number, number][];
globalPalette: import("./parserBase").PaletteColor[];
sampleRate: number;

@@ -72,3 +72,3 @@ meta: KwzMeta;

getFramePaletteIndices(frameIndex: number): number[];
getFramePalette(frameIndex: number): [number, number, number][];
getFramePalette(frameIndex: number): import("./parserBase").PaletteColor[];
getLayerPixels(frameIndex: number, layerIndex: number): Uint8Array;

@@ -75,0 +75,0 @@ getFramePixels(frameIndex: number): Uint8Array;

@@ -55,7 +55,7 @@ /**

static sampleRate: number;
static globalPalette: [number, number, number][];
static globalPalette: import("./parserBase").PaletteColor[];
type: string;
width: number;
height: number;
globalPalette: [number, number, number][];
globalPalette: import("./parserBase").PaletteColor[];
sampleRate: number;

@@ -83,3 +83,3 @@ meta: PpmMeta;

getFramePaletteIndices(frameIndex: number): number[];
getFramePalette(frameIndex: number): [number, number, number][];
getFramePalette(frameIndex: number): import("./parserBase").PaletteColor[];
getLayerPixels(frameIndex: number, layerIndex: number): Uint8Array;

@@ -86,0 +86,0 @@ getFramePixels(frameIndex: number): Uint8Array;

@@ -13,3 +13,3 @@ export declare class AudioTrack {

set(pcmData: Int16Array, playbackRate: number): void;
readonly duration: number;
get duration(): number;
unset(): void;

@@ -16,0 +16,0 @@ start(offset?: number): void;

@@ -28,11 +28,16 @@ import { Flipnote, FlipnoteMeta } from '../parsers/index';

constructor(el: string | HTMLCanvasElement, width: number, height: number);
currentFrame: number;
currentTime: number;
progress: number;
volume: number;
muted: boolean;
readonly framerate: number;
readonly frameCount: number;
readonly frameSpeed: number;
readonly audiorate: number;
get currentFrame(): number;
set currentFrame(frameIndex: number);
get currentTime(): number;
set currentTime(value: number);
get progress(): number;
set progress(value: number);
get volume(): number;
set volume(value: number);
get muted(): boolean;
set muted(value: boolean);
get framerate(): number;
get frameCount(): number;
get frameSpeed(): number;
get audiorate(): number;
open(source: any): Promise<void>;

@@ -39,0 +44,0 @@ close(): void;

@@ -12,4 +12,4 @@ /** datastream serves as a wrapper around the DataView API to help keep track of the offset into the stream */

constructor(arrayBuffer: ArrayBuffer);
readonly bytes: Uint8Array;
readonly byteLength: number;
get bytes(): Uint8Array;
get byteLength(): number;
seek(offset: number, whence?: SeekOrigin): void;

@@ -16,0 +16,0 @@ readUint8(): number;

{
"name": "flipnote.js",
"version": "4.0.0",
"version": "4.0.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",

@@ -13,2 +13,3 @@ # flipnote.js

* Crisp upscaling/downscaling using sharp-bilinear shaders
* Built-in GIF and WAV converters
* Zero dependencies, only ~12kB when minified & gzipped :^)

@@ -15,0 +16,0 @@

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 not supported yet

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc