mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-14 11:05:41 +05:00
2 lines
580 KiB
JavaScript
2 lines
580 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["cryptpad-worker-min"]={})}(this,(function(e){"use strict";function t(e,t){return t.forEach((function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach((function(n){if("default"!==n&&!(n in e)){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}))})),Object.freeze(e)}var n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function o(e){if(e.__esModule)return e;var t=e.default;if("function"==typeof t){var n=function e(){return this instanceof e?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};n.prototype=t.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(e).forEach((function(t){var r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:function(){return e[t]}})})),n}var a,i={exports:{}},s={exports:{}},c={exports:{}};function u(){return a||(a=1,function(e){var t;t=function(){var e=function(){},t=function(){return(new Date).getTime()},n=function(e,t,n){e.timeouts.push(setTimeout(t,n))},r=function(t,r){t.ws&&(t.ws.onmessage=e,t.ws.onopen=e,t.ws.close(),r?t.ws.onclose({reason:"offline"}):n(t,(function(){t.ws&&t.ws.onclose({reason:"forced closed because websocket failed to close"})}),1e4))},o=function(e,t){return!!e.ws&&(e.ws.send(JSON.stringify(t)),!0)},a=function(e,t){return function(e,n){var r=t[e];if(!r)throw new Error("no such event "+e);r.push(n)}},i=function(e,t,n,r){var o=r[t];if(!o)throw new Error("no such event "+t);var a=o.indexOf(n);-1!==a&&o.splice(a,1)},s=function(e,n,r){if(e.channels[n])return new Promise((function(t){t(e.channels[n])}));var s=e.queues.p2;1===r?s=e.queues.p1:3===r&&(s=e.queues.p3);var c={queue:s,onMessage:[],onJoin:[],onLeave:[],members:[],jSeq:e.seq++},u={message:c.onMessage,join:c.onJoin,leave:c.onLeave},l={_:c,time:t(),id:n,members:c.members,bcast:function(n){return function(e,n,r){var a=e.channels[n],i=e.seq++,s=[i,"MSG",n,r];if(!a)return new Promise((function(e,t){t({type:"NO_SUCH_CHANNEL",message:JSON.stringify(s)})}));var c=o(e,s);return new Promise((function(n,r){c?e.requests[i]={reject:r,resolve:n,time:t()}:r({type:"DISCONNECTED",message:JSON.stringify(s)})}))}(e,l.id,n)},leave:function(n){return function(e,n,r){if(e.channels[n]){if(delete e.channels[n],e.ws&&1===e.ws.readyState){var a=e.seq++;o(e,[a,"LEAVE",n,r]);var i=function(){};e.requests[a]={reject:i,resolve:i,time:t()}}}else console.debug("no such channel",n)}(e,l.id,n)},on:a(0,u),off:function(e,t){i(0,e,t,u)}};e.requests[c.jSeq]=l;var f=[c.jSeq,"JOIN",n],d=o(e,f);return new Promise((function(e,t){d?(l._.resolve=e,l._.reject=t):t({type:"DISCONNECTED",message:JSON.stringify(f)})}))},c=function(n){var r={message:n.onMessage,disconnect:n.onDisconnect,reconnect:n.onReconnect},c={webChannels:n.channels,getLag:function(){return function(e){return e.ws?e.pingOutstanding?Math.max(t()-e.timeOfLastPingSent,e.lastObservedLag):e.lastObservedLag:null}(n)},sendto:function(e,r){return function(e,n,r){var a=e.seq++,i=[a,"MSG",n,r],s=o(e,i);return new Promise((function(n,r){s?e.requests[a]={reject:r,resolve:n,time:t()}:r({type:"DISCONNECTED",message:JSON.stringify(i)})}))}(n,e,r)},join:function(e,t){return s(n,e,t)},disconnect:function(){return function(t){if(t.ws){var n=t.ws.onclose;t.ws.onclose=e,t.ws.close(),n({reason:"network.disconnect() called"})}t.timeouts.forEach(clearTimeout),t.timeouts=[]}(n)},on:a(0,r),off:function(e,t){i(0,e,t,r)}};return c.__defineGetter__("webChannels",(function(){return Object.keys(n.channels).map((function(e){return n.channels[e]}))})),c},u=function(e,n){var a=void 0;try{a=JSON.parse(n.data)}catch(e){return void console.log(e.stack)}if(e.timeOfLastMsgReceived=t(),0===a[0]){if("IDENT"===a[2])return e.uid=a[3],e.ws._onident(),void(e.pingInterval=setInterval((function(){if(!(t()-e.timeOfLastPingReceived<15e3||(t()-e.timeOfLastMsgReceived>6e4&&r(e),e.pingOutstanding))){var n=e.seq++,a=t();e.timeOfLastPingSent=a,e.pingOutstanding++,e.requests[n]={time:a,ping:a},o(e,[n,"PING"])}}),5e3));if(e.uid){if("PING"===a[2])return a[2]="PONG",void o(e,a);if("MSG"===a[2]){var i=void 0,s=e.queues.p2;if(a[3]===e.uid)i=e.onMessage,"number"==typeof a[5]&&(1===a[5]&&(s=e.queues.p1),3===a[5]&&(s=e.queues.p3));else{var c=e.channels[a[3]];if(!c)return void console.log("message to non-existent chan "+JSON.stringify(a));i=c._.onMessage,c._.queue&&(s=c._.queue)}s.push({msg:a,h:i}),function(e){if(!e.queues.busy){var t=function(){var n=e.queues.p1.shift()||e.queues.p2.shift()||e.queues.p3.shift();if(n){e.queues.busy=!0;var r=n.h,o=n.msg;r.forEach((function(e){setTimeout((function(){try{e(o[4],o[1])}catch(e){console.error(e)}}))})),setTimeout((function(){t()}))}else e.queues.busy=!1};t()}}(e)}if("LEAVE"===a[2]){var u=e.channels[a[3]];if(!u)return void(a[1]!==e.uid&&console.log("leaving non-existent chan "+JSON.stringify(a)));var l=u._.members.indexOf(a[1]);-1!==l&&u._.members.splice(l,1),u._.onLeave.forEach((function(e){try{e(a[1],a[4])}catch(e){console.log(e.stack)}}))}if("JOIN"===a[2]){var f=e.channels[a[3]];if(!f)return void console.log("ERROR: join to non-existent chan "+JSON.stringify(a));if(-1!==f._.members.indexOf(a[1]))return;var d=-1!==f._.members.indexOf(e.uid);f._.members.push(a[1]),d||a[1]!==e.uid||(f.myID=e.uid,f._.resolve(f)),d&&f._.onJoin.forEach((function(e){try{e(a[1])}catch(e){console.log(e.stack)}}))}}}else{var h=e.requests[a[0]];if(!h)return void console.log("error: "+JSON.stringify(a));if(delete e.requests[a[0]],"ACK"===a[1]){if(h.ping)return e.lastObservedLag=t()-Number(h.ping),e.timeOfLastPingReceived=t(),void e.pingOutstanding--;h.resolve()}else if("JACK"===a[1]){if(h._){if(!a[2])throw new Error("wrong type of ACK for channel join");return h.id=a[2],void(e.channels[h.id]=h)}h.resolve()}else if("ERROR"===a[1])if("function"==typeof h.reject)h.reject({type:a[2],message:a[3]});else if(h._&&"function"==typeof h._.reject){if("EJOINED"===a[2]&&!e.channels[a[3]])return h.id=a[3],void(e.channels[h.id]=h);h._.reject({type:a[2],message:a[3]})}else console.error(a);else h.reject({type:"UNKNOWN",message:JSON.stringify(a)})}};return{connect:function(o,a){a=a||function(e){return new globalThis.WebSocket(e)};var i={ws:null,seq:1,uid:null,network:null,channels:{},onMessage:[],onDisconnect:[],onReconnect:[],timeouts:[],requests:{},pingInterval:null,queues:{p1:[],p2:[],p3:[]},timeOfLastPingSent:-1,timeOfLastPingReceived:-1,timeOfLastMsgReceived:-1,lastObservedLag:0,pingOutstanding:0};i.network=c(i);var s=e,l=e;"undefined"!=typeof window&&window.addEventListener("offline",(function(){-1===["localhost","127.0.0.1",""].indexOf(window.location.hostname)&&r(i,!0)}));var f=function(){var c=i.ws=a(o);i.timeOfLastPingSent=i.timeOfLastPingReceived=t(),i.timeOfLastMsgReceived=t(),c.onmessage=function(e){return u(i,e)},c.onclose=function(t){c.onclose=e,clearInterval(i.pingInterval),i.timeouts.forEach(clearTimeout),i.ws=null,i.uid&&(i.uid=null,i.onDisconnect.forEach((function(e){try{e(t.reason)}catch(e){console.log(e.stack)}}))),n(i,f,i.uid?0:7e3)},c.onopen=function(){n(i,(function(){i.uid||(l({type:"TIMEOUT",message:"waited 30000ms"}),s=l=e,r(i))}),3e4)},i.ws._onident=function(){i.timeOfLastPingReceived=t(),i.timeOfLastMsgReceived=t(),i.lastObservedLag=t()-i.timeOfLastPingSent,s!==e?(s(i.network),s=l=e):(i.channels={},i.requests={},i.pingOutstanding=0,i.onReconnect.forEach((function(e){try{e(i.uid)}catch(e){console.log(e.stack)}})))}};return new Promise((function(e,t){s=e,l=t,f()}))}}},e.exports?e.exports=t():window.netflux_websocket=t()}(c)),c.exports}function l(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var f,d={exports:{}};function h(){return f||(f=1,function(e){!function(e){var t=function(e){var t,n=new Float64Array(16);if(e)for(t=0;t<e.length;t++)n[t]=e[t];return n},n=function(){throw new Error("no PRNG")},r=new Uint8Array(16),o=new Uint8Array(32);o[0]=9;var a=t(),i=t([1]),s=t([56129,1]),c=t([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),u=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),f=t([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),d=t([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),h=t([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function p(e,t,n,r){e[t]=n>>24&255,e[t+1]=n>>16&255,e[t+2]=n>>8&255,e[t+3]=255&n,e[t+4]=r>>24&255,e[t+5]=r>>16&255,e[t+6]=r>>8&255,e[t+7]=255&r}function y(e,t,n,r,o){var a,i=0;for(a=0;a<o;a++)i|=e[t+a]^n[r+a];return(1&i-1>>>8)-1}function v(e,t,n,r){return y(e,t,n,r,16)}function m(e,t,n,r){return y(e,t,n,r,32)}function g(e,t,n,r){!function(e,t,n,r){for(var o,a=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,i=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,s=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,c=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,u=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,l=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,d=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,h=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,p=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,v=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,m=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,g=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,E=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,b=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,A=a,_=i,w=s,O=c,D=u,S=l,T=f,C=d,x=h,I=p,N=y,P=v,k=m,R=g,M=E,F=b,L=0;L<20;L+=2)A^=(o=(k^=(o=(x^=(o=(D^=(o=A+k|0)<<7|o>>>25)+A|0)<<9|o>>>23)+D|0)<<13|o>>>19)+x|0)<<18|o>>>14,S^=(o=(_^=(o=(R^=(o=(I^=(o=S+_|0)<<7|o>>>25)+S|0)<<9|o>>>23)+I|0)<<13|o>>>19)+R|0)<<18|o>>>14,N^=(o=(T^=(o=(w^=(o=(M^=(o=N+T|0)<<7|o>>>25)+N|0)<<9|o>>>23)+M|0)<<13|o>>>19)+w|0)<<18|o>>>14,F^=(o=(P^=(o=(C^=(o=(O^=(o=F+P|0)<<7|o>>>25)+F|0)<<9|o>>>23)+O|0)<<13|o>>>19)+C|0)<<18|o>>>14,A^=(o=(O^=(o=(w^=(o=(_^=(o=A+O|0)<<7|o>>>25)+A|0)<<9|o>>>23)+_|0)<<13|o>>>19)+w|0)<<18|o>>>14,S^=(o=(D^=(o=(C^=(o=(T^=(o=S+D|0)<<7|o>>>25)+S|0)<<9|o>>>23)+T|0)<<13|o>>>19)+C|0)<<18|o>>>14,N^=(o=(I^=(o=(x^=(o=(P^=(o=N+I|0)<<7|o>>>25)+N|0)<<9|o>>>23)+P|0)<<13|o>>>19)+x|0)<<18|o>>>14,F^=(o=(M^=(o=(R^=(o=(k^=(o=F+M|0)<<7|o>>>25)+F|0)<<9|o>>>23)+k|0)<<13|o>>>19)+R|0)<<18|o>>>14;A=A+a|0,_=_+i|0,w=w+s|0,O=O+c|0,D=D+u|0,S=S+l|0,T=T+f|0,C=C+d|0,x=x+h|0,I=I+p|0,N=N+y|0,P=P+v|0,k=k+m|0,R=R+g|0,M=M+E|0,F=F+b|0,e[0]=A>>>0&255,e[1]=A>>>8&255,e[2]=A>>>16&255,e[3]=A>>>24&255,e[4]=_>>>0&255,e[5]=_>>>8&255,e[6]=_>>>16&255,e[7]=_>>>24&255,e[8]=w>>>0&255,e[9]=w>>>8&255,e[10]=w>>>16&255,e[11]=w>>>24&255,e[12]=O>>>0&255,e[13]=O>>>8&255,e[14]=O>>>16&255,e[15]=O>>>24&255,e[16]=D>>>0&255,e[17]=D>>>8&255,e[18]=D>>>16&255,e[19]=D>>>24&255,e[20]=S>>>0&255,e[21]=S>>>8&255,e[22]=S>>>16&255,e[23]=S>>>24&255,e[24]=T>>>0&255,e[25]=T>>>8&255,e[26]=T>>>16&255,e[27]=T>>>24&255,e[28]=C>>>0&255,e[29]=C>>>8&255,e[30]=C>>>16&255,e[31]=C>>>24&255,e[32]=x>>>0&255,e[33]=x>>>8&255,e[34]=x>>>16&255,e[35]=x>>>24&255,e[36]=I>>>0&255,e[37]=I>>>8&255,e[38]=I>>>16&255,e[39]=I>>>24&255,e[40]=N>>>0&255,e[41]=N>>>8&255,e[42]=N>>>16&255,e[43]=N>>>24&255,e[44]=P>>>0&255,e[45]=P>>>8&255,e[46]=P>>>16&255,e[47]=P>>>24&255,e[48]=k>>>0&255,e[49]=k>>>8&255,e[50]=k>>>16&255,e[51]=k>>>24&255,e[52]=R>>>0&255,e[53]=R>>>8&255,e[54]=R>>>16&255,e[55]=R>>>24&255,e[56]=M>>>0&255,e[57]=M>>>8&255,e[58]=M>>>16&255,e[59]=M>>>24&255,e[60]=F>>>0&255,e[61]=F>>>8&255,e[62]=F>>>16&255,e[63]=F>>>24&255}(e,t,n,r)}function E(e,t,n,r){!function(e,t,n,r){for(var o,a=255&r[0]|(255&r[1])<<8|(255&r[2])<<16|(255&r[3])<<24,i=255&n[0]|(255&n[1])<<8|(255&n[2])<<16|(255&n[3])<<24,s=255&n[4]|(255&n[5])<<8|(255&n[6])<<16|(255&n[7])<<24,c=255&n[8]|(255&n[9])<<8|(255&n[10])<<16|(255&n[11])<<24,u=255&n[12]|(255&n[13])<<8|(255&n[14])<<16|(255&n[15])<<24,l=255&r[4]|(255&r[5])<<8|(255&r[6])<<16|(255&r[7])<<24,f=255&t[0]|(255&t[1])<<8|(255&t[2])<<16|(255&t[3])<<24,d=255&t[4]|(255&t[5])<<8|(255&t[6])<<16|(255&t[7])<<24,h=255&t[8]|(255&t[9])<<8|(255&t[10])<<16|(255&t[11])<<24,p=255&t[12]|(255&t[13])<<8|(255&t[14])<<16|(255&t[15])<<24,y=255&r[8]|(255&r[9])<<8|(255&r[10])<<16|(255&r[11])<<24,v=255&n[16]|(255&n[17])<<8|(255&n[18])<<16|(255&n[19])<<24,m=255&n[20]|(255&n[21])<<8|(255&n[22])<<16|(255&n[23])<<24,g=255&n[24]|(255&n[25])<<8|(255&n[26])<<16|(255&n[27])<<24,E=255&n[28]|(255&n[29])<<8|(255&n[30])<<16|(255&n[31])<<24,b=255&r[12]|(255&r[13])<<8|(255&r[14])<<16|(255&r[15])<<24,A=0;A<20;A+=2)a^=(o=(m^=(o=(h^=(o=(u^=(o=a+m|0)<<7|o>>>25)+a|0)<<9|o>>>23)+u|0)<<13|o>>>19)+h|0)<<18|o>>>14,l^=(o=(i^=(o=(g^=(o=(p^=(o=l+i|0)<<7|o>>>25)+l|0)<<9|o>>>23)+p|0)<<13|o>>>19)+g|0)<<18|o>>>14,y^=(o=(f^=(o=(s^=(o=(E^=(o=y+f|0)<<7|o>>>25)+y|0)<<9|o>>>23)+E|0)<<13|o>>>19)+s|0)<<18|o>>>14,b^=(o=(v^=(o=(d^=(o=(c^=(o=b+v|0)<<7|o>>>25)+b|0)<<9|o>>>23)+c|0)<<13|o>>>19)+d|0)<<18|o>>>14,a^=(o=(c^=(o=(s^=(o=(i^=(o=a+c|0)<<7|o>>>25)+a|0)<<9|o>>>23)+i|0)<<13|o>>>19)+s|0)<<18|o>>>14,l^=(o=(u^=(o=(d^=(o=(f^=(o=l+u|0)<<7|o>>>25)+l|0)<<9|o>>>23)+f|0)<<13|o>>>19)+d|0)<<18|o>>>14,y^=(o=(p^=(o=(h^=(o=(v^=(o=y+p|0)<<7|o>>>25)+y|0)<<9|o>>>23)+v|0)<<13|o>>>19)+h|0)<<18|o>>>14,b^=(o=(E^=(o=(g^=(o=(m^=(o=b+E|0)<<7|o>>>25)+b|0)<<9|o>>>23)+m|0)<<13|o>>>19)+g|0)<<18|o>>>14;e[0]=a>>>0&255,e[1]=a>>>8&255,e[2]=a>>>16&255,e[3]=a>>>24&255,e[4]=l>>>0&255,e[5]=l>>>8&255,e[6]=l>>>16&255,e[7]=l>>>24&255,e[8]=y>>>0&255,e[9]=y>>>8&255,e[10]=y>>>16&255,e[11]=y>>>24&255,e[12]=b>>>0&255,e[13]=b>>>8&255,e[14]=b>>>16&255,e[15]=b>>>24&255,e[16]=f>>>0&255,e[17]=f>>>8&255,e[18]=f>>>16&255,e[19]=f>>>24&255,e[20]=d>>>0&255,e[21]=d>>>8&255,e[22]=d>>>16&255,e[23]=d>>>24&255,e[24]=h>>>0&255,e[25]=h>>>8&255,e[26]=h>>>16&255,e[27]=h>>>24&255,e[28]=p>>>0&255,e[29]=p>>>8&255,e[30]=p>>>16&255,e[31]=p>>>24&255}(e,t,n,r)}var b=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function A(e,t,n,r,o,a,i){var s,c,u=new Uint8Array(16),l=new Uint8Array(64);for(c=0;c<16;c++)u[c]=0;for(c=0;c<8;c++)u[c]=a[c];for(;o>=64;){for(g(l,u,i,b),c=0;c<64;c++)e[t+c]=n[r+c]^l[c];for(s=1,c=8;c<16;c++)s=s+(255&u[c])|0,u[c]=255&s,s>>>=8;o-=64,t+=64,r+=64}if(o>0)for(g(l,u,i,b),c=0;c<o;c++)e[t+c]=n[r+c]^l[c];return 0}function _(e,t,n,r,o){var a,i,s=new Uint8Array(16),c=new Uint8Array(64);for(i=0;i<16;i++)s[i]=0;for(i=0;i<8;i++)s[i]=r[i];for(;n>=64;){for(g(c,s,o,b),i=0;i<64;i++)e[t+i]=c[i];for(a=1,i=8;i<16;i++)a=a+(255&s[i])|0,s[i]=255&a,a>>>=8;n-=64,t+=64}if(n>0)for(g(c,s,o,b),i=0;i<n;i++)e[t+i]=c[i];return 0}function w(e,t,n,r,o){var a=new Uint8Array(32);E(a,r,o,b);for(var i=new Uint8Array(8),s=0;s<8;s++)i[s]=r[s+16];return _(e,t,n,i,a)}function O(e,t,n,r,o,a,i){var s=new Uint8Array(32);E(s,a,i,b);for(var c=new Uint8Array(8),u=0;u<8;u++)c[u]=a[u+16];return A(e,t,n,r,o,c,s)}var D=function(e){var t,n,r,o,a,i,s,c;this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.leftover=0,this.fin=0,t=255&e[0]|(255&e[1])<<8,this.r[0]=8191&t,n=255&e[2]|(255&e[3])<<8,this.r[1]=8191&(t>>>13|n<<3),r=255&e[4]|(255&e[5])<<8,this.r[2]=7939&(n>>>10|r<<6),o=255&e[6]|(255&e[7])<<8,this.r[3]=8191&(r>>>7|o<<9),a=255&e[8]|(255&e[9])<<8,this.r[4]=255&(o>>>4|a<<12),this.r[5]=a>>>1&8190,i=255&e[10]|(255&e[11])<<8,this.r[6]=8191&(a>>>14|i<<2),s=255&e[12]|(255&e[13])<<8,this.r[7]=8065&(i>>>11|s<<5),c=255&e[14]|(255&e[15])<<8,this.r[8]=8191&(s>>>8|c<<8),this.r[9]=c>>>5&127,this.pad[0]=255&e[16]|(255&e[17])<<8,this.pad[1]=255&e[18]|(255&e[19])<<8,this.pad[2]=255&e[20]|(255&e[21])<<8,this.pad[3]=255&e[22]|(255&e[23])<<8,this.pad[4]=255&e[24]|(255&e[25])<<8,this.pad[5]=255&e[26]|(255&e[27])<<8,this.pad[6]=255&e[28]|(255&e[29])<<8,this.pad[7]=255&e[30]|(255&e[31])<<8};function S(e,t,n,r,o,a){var i=new D(a);return i.update(n,r,o),i.finish(e,t),0}function T(e,t,n,r,o,a){var i=new Uint8Array(16);return S(i,0,n,r,o,a),v(e,t,i,0)}function C(e,t,n,r,o){var a;if(n<32)return-1;for(O(e,0,t,0,n,r,o),S(e,16,e,32,n-32,e),a=0;a<16;a++)e[a]=0;return 0}function x(e,t,n,r,o){var a,i=new Uint8Array(32);if(n<32)return-1;if(w(i,0,32,r,o),0!==T(t,16,t,32,n-32,i))return-1;for(O(e,0,t,0,n,r,o),a=0;a<32;a++)e[a]=0;return 0}function I(e,t){var n;for(n=0;n<16;n++)e[n]=0|t[n]}function N(e){var t,n,r=1;for(t=0;t<16;t++)n=e[t]+r+65535,r=Math.floor(n/65536),e[t]=n-65536*r;e[0]+=r-1+37*(r-1)}function P(e,t,n){for(var r,o=~(n-1),a=0;a<16;a++)r=o&(e[a]^t[a]),e[a]^=r,t[a]^=r}function k(e,n){var r,o,a,i=t(),s=t();for(r=0;r<16;r++)s[r]=n[r];for(N(s),N(s),N(s),o=0;o<2;o++){for(i[0]=s[0]-65517,r=1;r<15;r++)i[r]=s[r]-65535-(i[r-1]>>16&1),i[r-1]&=65535;i[15]=s[15]-32767-(i[14]>>16&1),a=i[15]>>16&1,i[14]&=65535,P(s,i,1-a)}for(r=0;r<16;r++)e[2*r]=255&s[r],e[2*r+1]=s[r]>>8}function R(e,t){var n=new Uint8Array(32),r=new Uint8Array(32);return k(n,e),k(r,t),m(n,0,r,0)}function M(e){var t=new Uint8Array(32);return k(t,e),1&t[0]}function F(e,t){var n;for(n=0;n<16;n++)e[n]=t[2*n]+(t[2*n+1]<<8);e[15]&=32767}function L(e,t,n){for(var r=0;r<16;r++)e[r]=t[r]+n[r]}function H(e,t,n){for(var r=0;r<16;r++)e[r]=t[r]-n[r]}function K(e,t,n){var r,o,a=0,i=0,s=0,c=0,u=0,l=0,f=0,d=0,h=0,p=0,y=0,v=0,m=0,g=0,E=0,b=0,A=0,_=0,w=0,O=0,D=0,S=0,T=0,C=0,x=0,I=0,N=0,P=0,k=0,R=0,M=0,F=n[0],L=n[1],H=n[2],K=n[3],j=n[4],U=n[5],B=n[6],V=n[7],G=n[8],Y=n[9],J=n[10],q=n[11],W=n[12],Q=n[13],z=n[14],X=n[15];a+=(r=t[0])*F,i+=r*L,s+=r*H,c+=r*K,u+=r*j,l+=r*U,f+=r*B,d+=r*V,h+=r*G,p+=r*Y,y+=r*J,v+=r*q,m+=r*W,g+=r*Q,E+=r*z,b+=r*X,i+=(r=t[1])*F,s+=r*L,c+=r*H,u+=r*K,l+=r*j,f+=r*U,d+=r*B,h+=r*V,p+=r*G,y+=r*Y,v+=r*J,m+=r*q,g+=r*W,E+=r*Q,b+=r*z,A+=r*X,s+=(r=t[2])*F,c+=r*L,u+=r*H,l+=r*K,f+=r*j,d+=r*U,h+=r*B,p+=r*V,y+=r*G,v+=r*Y,m+=r*J,g+=r*q,E+=r*W,b+=r*Q,A+=r*z,_+=r*X,c+=(r=t[3])*F,u+=r*L,l+=r*H,f+=r*K,d+=r*j,h+=r*U,p+=r*B,y+=r*V,v+=r*G,m+=r*Y,g+=r*J,E+=r*q,b+=r*W,A+=r*Q,_+=r*z,w+=r*X,u+=(r=t[4])*F,l+=r*L,f+=r*H,d+=r*K,h+=r*j,p+=r*U,y+=r*B,v+=r*V,m+=r*G,g+=r*Y,E+=r*J,b+=r*q,A+=r*W,_+=r*Q,w+=r*z,O+=r*X,l+=(r=t[5])*F,f+=r*L,d+=r*H,h+=r*K,p+=r*j,y+=r*U,v+=r*B,m+=r*V,g+=r*G,E+=r*Y,b+=r*J,A+=r*q,_+=r*W,w+=r*Q,O+=r*z,D+=r*X,f+=(r=t[6])*F,d+=r*L,h+=r*H,p+=r*K,y+=r*j,v+=r*U,m+=r*B,g+=r*V,E+=r*G,b+=r*Y,A+=r*J,_+=r*q,w+=r*W,O+=r*Q,D+=r*z,S+=r*X,d+=(r=t[7])*F,h+=r*L,p+=r*H,y+=r*K,v+=r*j,m+=r*U,g+=r*B,E+=r*V,b+=r*G,A+=r*Y,_+=r*J,w+=r*q,O+=r*W,D+=r*Q,S+=r*z,T+=r*X,h+=(r=t[8])*F,p+=r*L,y+=r*H,v+=r*K,m+=r*j,g+=r*U,E+=r*B,b+=r*V,A+=r*G,_+=r*Y,w+=r*J,O+=r*q,D+=r*W,S+=r*Q,T+=r*z,C+=r*X,p+=(r=t[9])*F,y+=r*L,v+=r*H,m+=r*K,g+=r*j,E+=r*U,b+=r*B,A+=r*V,_+=r*G,w+=r*Y,O+=r*J,D+=r*q,S+=r*W,T+=r*Q,C+=r*z,x+=r*X,y+=(r=t[10])*F,v+=r*L,m+=r*H,g+=r*K,E+=r*j,b+=r*U,A+=r*B,_+=r*V,w+=r*G,O+=r*Y,D+=r*J,S+=r*q,T+=r*W,C+=r*Q,x+=r*z,I+=r*X,v+=(r=t[11])*F,m+=r*L,g+=r*H,E+=r*K,b+=r*j,A+=r*U,_+=r*B,w+=r*V,O+=r*G,D+=r*Y,S+=r*J,T+=r*q,C+=r*W,x+=r*Q,I+=r*z,N+=r*X,m+=(r=t[12])*F,g+=r*L,E+=r*H,b+=r*K,A+=r*j,_+=r*U,w+=r*B,O+=r*V,D+=r*G,S+=r*Y,T+=r*J,C+=r*q,x+=r*W,I+=r*Q,N+=r*z,P+=r*X,g+=(r=t[13])*F,E+=r*L,b+=r*H,A+=r*K,_+=r*j,w+=r*U,O+=r*B,D+=r*V,S+=r*G,T+=r*Y,C+=r*J,x+=r*q,I+=r*W,N+=r*Q,P+=r*z,k+=r*X,E+=(r=t[14])*F,b+=r*L,A+=r*H,_+=r*K,w+=r*j,O+=r*U,D+=r*B,S+=r*V,T+=r*G,C+=r*Y,x+=r*J,I+=r*q,N+=r*W,P+=r*Q,k+=r*z,R+=r*X,b+=(r=t[15])*F,i+=38*(_+=r*H),s+=38*(w+=r*K),c+=38*(O+=r*j),u+=38*(D+=r*U),l+=38*(S+=r*B),f+=38*(T+=r*V),d+=38*(C+=r*G),h+=38*(x+=r*Y),p+=38*(I+=r*J),y+=38*(N+=r*q),v+=38*(P+=r*W),m+=38*(k+=r*Q),g+=38*(R+=r*z),E+=38*(M+=r*X),a=(r=(a+=38*(A+=r*L))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),i=(r=i+o+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),E=(r=E+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),a=(r=(a+=o-1+37*(o-1))+(o=1)+65535)-65536*(o=Math.floor(r/65536)),i=(r=i+o+65535)-65536*(o=Math.floor(r/65536)),s=(r=s+o+65535)-65536*(o=Math.floor(r/65536)),c=(r=c+o+65535)-65536*(o=Math.floor(r/65536)),u=(r=u+o+65535)-65536*(o=Math.floor(r/65536)),l=(r=l+o+65535)-65536*(o=Math.floor(r/65536)),f=(r=f+o+65535)-65536*(o=Math.floor(r/65536)),d=(r=d+o+65535)-65536*(o=Math.floor(r/65536)),h=(r=h+o+65535)-65536*(o=Math.floor(r/65536)),p=(r=p+o+65535)-65536*(o=Math.floor(r/65536)),y=(r=y+o+65535)-65536*(o=Math.floor(r/65536)),v=(r=v+o+65535)-65536*(o=Math.floor(r/65536)),m=(r=m+o+65535)-65536*(o=Math.floor(r/65536)),g=(r=g+o+65535)-65536*(o=Math.floor(r/65536)),E=(r=E+o+65535)-65536*(o=Math.floor(r/65536)),b=(r=b+o+65535)-65536*(o=Math.floor(r/65536)),a+=o-1+37*(o-1),e[0]=a,e[1]=i,e[2]=s,e[3]=c,e[4]=u,e[5]=l,e[6]=f,e[7]=d,e[8]=h,e[9]=p,e[10]=y,e[11]=v,e[12]=m,e[13]=g,e[14]=E,e[15]=b}function j(e,t){K(e,t,t)}function U(e,n){var r,o=t();for(r=0;r<16;r++)o[r]=n[r];for(r=253;r>=0;r--)j(o,o),2!==r&&4!==r&&K(o,o,n);for(r=0;r<16;r++)e[r]=o[r]}function B(e,n){var r,o=t();for(r=0;r<16;r++)o[r]=n[r];for(r=250;r>=0;r--)j(o,o),1!==r&&K(o,o,n);for(r=0;r<16;r++)e[r]=o[r]}function V(e,n,r){var o,a,i=new Uint8Array(32),c=new Float64Array(80),u=t(),l=t(),f=t(),d=t(),h=t(),p=t();for(a=0;a<31;a++)i[a]=n[a];for(i[31]=127&n[31]|64,i[0]&=248,F(c,r),a=0;a<16;a++)l[a]=c[a],d[a]=u[a]=f[a]=0;for(u[0]=d[0]=1,a=254;a>=0;--a)P(u,l,o=i[a>>>3]>>>(7&a)&1),P(f,d,o),L(h,u,f),H(u,u,f),L(f,l,d),H(l,l,d),j(d,h),j(p,u),K(u,f,u),K(f,l,h),L(h,u,f),H(u,u,f),j(l,u),H(f,d,p),K(u,f,s),L(u,u,d),K(f,f,u),K(u,d,p),K(d,l,c),j(l,h),P(u,l,o),P(f,d,o);for(a=0;a<16;a++)c[a+16]=u[a],c[a+32]=f[a],c[a+48]=l[a],c[a+64]=d[a];var y=c.subarray(32),v=c.subarray(16);return U(y,y),K(v,v,y),k(e,v),0}function G(e,t){return V(e,t,o)}function Y(e,t){return n(t,32),G(e,t)}function J(e,t,n){var o=new Uint8Array(32);return V(o,n,t),E(e,r,o,b)}D.prototype.blocks=function(e,t,n){for(var r,o,a,i,s,c,u,l,f,d,h,p,y,v,m,g,E,b,A,_=this.fin?0:2048,w=this.h[0],O=this.h[1],D=this.h[2],S=this.h[3],T=this.h[4],C=this.h[5],x=this.h[6],I=this.h[7],N=this.h[8],P=this.h[9],k=this.r[0],R=this.r[1],M=this.r[2],F=this.r[3],L=this.r[4],H=this.r[5],K=this.r[6],j=this.r[7],U=this.r[8],B=this.r[9];n>=16;)d=f=0,d+=(w+=8191&(r=255&e[t+0]|(255&e[t+1])<<8))*k,d+=(O+=8191&(r>>>13|(o=255&e[t+2]|(255&e[t+3])<<8)<<3))*(5*B),d+=(D+=8191&(o>>>10|(a=255&e[t+4]|(255&e[t+5])<<8)<<6))*(5*U),d+=(S+=8191&(a>>>7|(i=255&e[t+6]|(255&e[t+7])<<8)<<9))*(5*j),f=(d+=(T+=8191&(i>>>4|(s=255&e[t+8]|(255&e[t+9])<<8)<<12))*(5*K))>>>13,d&=8191,d+=(C+=s>>>1&8191)*(5*H),d+=(x+=8191&(s>>>14|(c=255&e[t+10]|(255&e[t+11])<<8)<<2))*(5*L),d+=(I+=8191&(c>>>11|(u=255&e[t+12]|(255&e[t+13])<<8)<<5))*(5*F),d+=(N+=8191&(u>>>8|(l=255&e[t+14]|(255&e[t+15])<<8)<<8))*(5*M),h=f+=(d+=(P+=l>>>5|_)*(5*R))>>>13,h+=w*R,h+=O*k,h+=D*(5*B),h+=S*(5*U),f=(h+=T*(5*j))>>>13,h&=8191,h+=C*(5*K),h+=x*(5*H),h+=I*(5*L),h+=N*(5*F),f+=(h+=P*(5*M))>>>13,h&=8191,p=f,p+=w*M,p+=O*R,p+=D*k,p+=S*(5*B),f=(p+=T*(5*U))>>>13,p&=8191,p+=C*(5*j),p+=x*(5*K),p+=I*(5*H),p+=N*(5*L),y=f+=(p+=P*(5*F))>>>13,y+=w*F,y+=O*M,y+=D*R,y+=S*k,f=(y+=T*(5*B))>>>13,y&=8191,y+=C*(5*U),y+=x*(5*j),y+=I*(5*K),y+=N*(5*H),v=f+=(y+=P*(5*L))>>>13,v+=w*L,v+=O*F,v+=D*M,v+=S*R,f=(v+=T*k)>>>13,v&=8191,v+=C*(5*B),v+=x*(5*U),v+=I*(5*j),v+=N*(5*K),m=f+=(v+=P*(5*H))>>>13,m+=w*H,m+=O*L,m+=D*F,m+=S*M,f=(m+=T*R)>>>13,m&=8191,m+=C*k,m+=x*(5*B),m+=I*(5*U),m+=N*(5*j),g=f+=(m+=P*(5*K))>>>13,g+=w*K,g+=O*H,g+=D*L,g+=S*F,f=(g+=T*M)>>>13,g&=8191,g+=C*R,g+=x*k,g+=I*(5*B),g+=N*(5*U),E=f+=(g+=P*(5*j))>>>13,E+=w*j,E+=O*K,E+=D*H,E+=S*L,f=(E+=T*F)>>>13,E&=8191,E+=C*M,E+=x*R,E+=I*k,E+=N*(5*B),b=f+=(E+=P*(5*U))>>>13,b+=w*U,b+=O*j,b+=D*K,b+=S*H,f=(b+=T*L)>>>13,b&=8191,b+=C*F,b+=x*M,b+=I*R,b+=N*k,A=f+=(b+=P*(5*B))>>>13,A+=w*B,A+=O*U,A+=D*j,A+=S*K,f=(A+=T*H)>>>13,A&=8191,A+=C*L,A+=x*F,A+=I*M,A+=N*R,w=d=8191&(f=(f=((f+=(A+=P*k)>>>13)<<2)+f|0)+(d&=8191)|0),O=h+=f>>>=13,D=p&=8191,S=y&=8191,T=v&=8191,C=m&=8191,x=g&=8191,I=E&=8191,N=b&=8191,P=A&=8191,t+=16,n-=16;this.h[0]=w,this.h[1]=O,this.h[2]=D,this.h[3]=S,this.h[4]=T,this.h[5]=C,this.h[6]=x,this.h[7]=I,this.h[8]=N,this.h[9]=P},D.prototype.finish=function(e,t){var n,r,o,a,i=new Uint16Array(10);if(this.leftover){for(a=this.leftover,this.buffer[a++]=1;a<16;a++)this.buffer[a]=0;this.fin=1,this.blocks(this.buffer,0,16)}for(n=this.h[1]>>>13,this.h[1]&=8191,a=2;a<10;a++)this.h[a]+=n,n=this.h[a]>>>13,this.h[a]&=8191;for(this.h[0]+=5*n,n=this.h[0]>>>13,this.h[0]&=8191,this.h[1]+=n,n=this.h[1]>>>13,this.h[1]&=8191,this.h[2]+=n,i[0]=this.h[0]+5,n=i[0]>>>13,i[0]&=8191,a=1;a<10;a++)i[a]=this.h[a]+n,n=i[a]>>>13,i[a]&=8191;for(i[9]-=8192,r=(1^n)-1,a=0;a<10;a++)i[a]&=r;for(r=~r,a=0;a<10;a++)this.h[a]=this.h[a]&r|i[a];for(this.h[0]=65535&(this.h[0]|this.h[1]<<13),this.h[1]=65535&(this.h[1]>>>3|this.h[2]<<10),this.h[2]=65535&(this.h[2]>>>6|this.h[3]<<7),this.h[3]=65535&(this.h[3]>>>9|this.h[4]<<4),this.h[4]=65535&(this.h[4]>>>12|this.h[5]<<1|this.h[6]<<14),this.h[5]=65535&(this.h[6]>>>2|this.h[7]<<11),this.h[6]=65535&(this.h[7]>>>5|this.h[8]<<8),this.h[7]=65535&(this.h[8]>>>8|this.h[9]<<5),o=this.h[0]+this.pad[0],this.h[0]=65535&o,a=1;a<8;a++)o=(this.h[a]+this.pad[a]|0)+(o>>>16)|0,this.h[a]=65535&o;e[t+0]=this.h[0]>>>0&255,e[t+1]=this.h[0]>>>8&255,e[t+2]=this.h[1]>>>0&255,e[t+3]=this.h[1]>>>8&255,e[t+4]=this.h[2]>>>0&255,e[t+5]=this.h[2]>>>8&255,e[t+6]=this.h[3]>>>0&255,e[t+7]=this.h[3]>>>8&255,e[t+8]=this.h[4]>>>0&255,e[t+9]=this.h[4]>>>8&255,e[t+10]=this.h[5]>>>0&255,e[t+11]=this.h[5]>>>8&255,e[t+12]=this.h[6]>>>0&255,e[t+13]=this.h[6]>>>8&255,e[t+14]=this.h[7]>>>0&255,e[t+15]=this.h[7]>>>8&255},D.prototype.update=function(e,t,n){var r,o;if(this.leftover){for((o=16-this.leftover)>n&&(o=n),r=0;r<o;r++)this.buffer[this.leftover+r]=e[t+r];if(n-=o,t+=o,this.leftover+=o,this.leftover<16)return;this.blocks(this.buffer,0,16),this.leftover=0}if(n>=16&&(o=n-n%16,this.blocks(e,t,o),t+=o,n-=o),n){for(r=0;r<n;r++)this.buffer[this.leftover+r]=e[t+r];this.leftover+=n}};var q=C,W=x;var Q=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];function z(e,t,n,r){for(var o,a,i,s,c,u,l,f,d,h,p,y,v,m,g,E,b,A,_,w,O,D,S,T,C,x,I=new Int32Array(16),N=new Int32Array(16),P=e[0],k=e[1],R=e[2],M=e[3],F=e[4],L=e[5],H=e[6],K=e[7],j=t[0],U=t[1],B=t[2],V=t[3],G=t[4],Y=t[5],J=t[6],q=t[7],W=0;r>=128;){for(_=0;_<16;_++)w=8*_+W,I[_]=n[w+0]<<24|n[w+1]<<16|n[w+2]<<8|n[w+3],N[_]=n[w+4]<<24|n[w+5]<<16|n[w+6]<<8|n[w+7];for(_=0;_<80;_++)if(o=P,a=k,i=R,s=M,c=F,u=L,l=H,K,d=j,h=U,p=B,y=V,v=G,m=Y,g=J,q,S=65535&(D=q),T=D>>>16,C=65535&(O=K),x=O>>>16,S+=65535&(D=(G>>>14|F<<18)^(G>>>18|F<<14)^(F>>>9|G<<23)),T+=D>>>16,C+=65535&(O=(F>>>14|G<<18)^(F>>>18|G<<14)^(G>>>9|F<<23)),x+=O>>>16,S+=65535&(D=G&Y^~G&J),T+=D>>>16,C+=65535&(O=F&L^~F&H),x+=O>>>16,S+=65535&(D=Q[2*_+1]),T+=D>>>16,C+=65535&(O=Q[2*_]),x+=O>>>16,O=I[_%16],T+=(D=N[_%16])>>>16,C+=65535&O,x+=O>>>16,C+=(T+=(S+=65535&D)>>>16)>>>16,S=65535&(D=A=65535&S|T<<16),T=D>>>16,C=65535&(O=b=65535&C|(x+=C>>>16)<<16),x=O>>>16,S+=65535&(D=(j>>>28|P<<4)^(P>>>2|j<<30)^(P>>>7|j<<25)),T+=D>>>16,C+=65535&(O=(P>>>28|j<<4)^(j>>>2|P<<30)^(j>>>7|P<<25)),x+=O>>>16,T+=(D=j&U^j&B^U&B)>>>16,C+=65535&(O=P&k^P&R^k&R),x+=O>>>16,f=65535&(C+=(T+=(S+=65535&D)>>>16)>>>16)|(x+=C>>>16)<<16,E=65535&S|T<<16,S=65535&(D=y),T=D>>>16,C=65535&(O=s),x=O>>>16,T+=(D=A)>>>16,C+=65535&(O=b),x+=O>>>16,k=o,R=a,M=i,F=s=65535&(C+=(T+=(S+=65535&D)>>>16)>>>16)|(x+=C>>>16)<<16,L=c,H=u,K=l,P=f,U=d,B=h,V=p,G=y=65535&S|T<<16,Y=v,J=m,q=g,j=E,_%16==15)for(w=0;w<16;w++)O=I[w],S=65535&(D=N[w]),T=D>>>16,C=65535&O,x=O>>>16,O=I[(w+9)%16],S+=65535&(D=N[(w+9)%16]),T+=D>>>16,C+=65535&O,x+=O>>>16,b=I[(w+1)%16],S+=65535&(D=((A=N[(w+1)%16])>>>1|b<<31)^(A>>>8|b<<24)^(A>>>7|b<<25)),T+=D>>>16,C+=65535&(O=(b>>>1|A<<31)^(b>>>8|A<<24)^b>>>7),x+=O>>>16,b=I[(w+14)%16],T+=(D=((A=N[(w+14)%16])>>>19|b<<13)^(b>>>29|A<<3)^(A>>>6|b<<26))>>>16,C+=65535&(O=(b>>>19|A<<13)^(A>>>29|b<<3)^b>>>6),x+=O>>>16,x+=(C+=(T+=(S+=65535&D)>>>16)>>>16)>>>16,I[w]=65535&C|x<<16,N[w]=65535&S|T<<16;S=65535&(D=j),T=D>>>16,C=65535&(O=P),x=O>>>16,O=e[0],T+=(D=t[0])>>>16,C+=65535&O,x+=O>>>16,x+=(C+=(T+=(S+=65535&D)>>>16)>>>16)>>>16,e[0]=P=65535&C|x<<16,t[0]=j=65535&S|T<<16,S=65535&(D=U),T=D>>>16,C=65535&(O=k),x=O>>>16,O=e[1],T+=(D=t[1])>>>16,C+=65535&O,x+=O>>>16,x+=(C+=(T+=(S+=65535&D)>>>16)>>>16)>>>16,e[1]=k=65535&C|x<<16,t[1]=U=65535&S|T<<16,S=65535&(D=B),T=D>>>16,C=65535&(O=R),x=O>>>16,O=e[2],T+=(D=t[2])>>>16,C+=65535&O,x+=O>>>16,x+=(C+=(T+=(S+=65535&D)>>>16)>>>16)>>>16,e[2]=R=65535&C|x<<16,t[2]=B=65535&S|T<<16,S=65535&(D=V),T=D>>>16,C=65535&(O=M),x=O>>>16,O=e[3],T+=(D=t[3])>>>16,C+=65535&O,x+=O>>>16,x+=(C+=(T+=(S+=65535&D)>>>16)>>>16)>>>16,e[3]=M=65535&C|x<<16,t[3]=V=65535&S|T<<16,S=65535&(D=G),T=D>>>16,C=65535&(O=F),x=O>>>16,O=e[4],T+=(D=t[4])>>>16,C+=65535&O,x+=O>>>16,x+=(C+=(T+=(S+=65535&D)>>>16)>>>16)>>>16,e[4]=F=65535&C|x<<16,t[4]=G=65535&S|T<<16,S=65535&(D=Y),T=D>>>16,C=65535&(O=L),x=O>>>16,O=e[5],T+=(D=t[5])>>>16,C+=65535&O,x+=O>>>16,x+=(C+=(T+=(S+=65535&D)>>>16)>>>16)>>>16,e[5]=L=65535&C|x<<16,t[5]=Y=65535&S|T<<16,S=65535&(D=J),T=D>>>16,C=65535&(O=H),x=O>>>16,O=e[6],T+=(D=t[6])>>>16,C+=65535&O,x+=O>>>16,x+=(C+=(T+=(S+=65535&D)>>>16)>>>16)>>>16,e[6]=H=65535&C|x<<16,t[6]=J=65535&S|T<<16,S=65535&(D=q),T=D>>>16,C=65535&(O=K),x=O>>>16,O=e[7],T+=(D=t[7])>>>16,C+=65535&O,x+=O>>>16,x+=(C+=(T+=(S+=65535&D)>>>16)>>>16)>>>16,e[7]=K=65535&C|x<<16,t[7]=q=65535&S|T<<16,W+=128,r-=128}return r}function X(e,t,n){var r,o=new Int32Array(8),a=new Int32Array(8),i=new Uint8Array(256),s=n;for(o[0]=1779033703,o[1]=3144134277,o[2]=1013904242,o[3]=2773480762,o[4]=1359893119,o[5]=2600822924,o[6]=528734635,o[7]=1541459225,a[0]=4089235720,a[1]=2227873595,a[2]=4271175723,a[3]=1595750129,a[4]=2917565137,a[5]=725511199,a[6]=4215389547,a[7]=327033209,z(o,a,t,n),n%=128,r=0;r<n;r++)i[r]=t[s-n+r];for(i[n]=128,i[(n=256-128*(n<112?1:0))-9]=0,p(i,n-8,s/536870912|0,s<<3),z(o,a,i,n),r=0;r<8;r++)p(e,8*r,o[r],a[r]);return 0}function Z(e,n){var r=t(),o=t(),a=t(),i=t(),s=t(),c=t(),l=t(),f=t(),d=t();H(r,e[1],e[0]),H(d,n[1],n[0]),K(r,r,d),L(o,e[0],e[1]),L(d,n[0],n[1]),K(o,o,d),K(a,e[3],n[3]),K(a,a,u),K(i,e[2],n[2]),L(i,i,i),H(s,o,r),H(c,i,a),L(l,i,a),L(f,o,r),K(e[0],s,c),K(e[1],f,l),K(e[2],l,c),K(e[3],s,f)}function $(e,t,n){var r;for(r=0;r<4;r++)P(e[r],t[r],n)}function ee(e,n){var r=t(),o=t(),a=t();U(a,n[2]),K(r,n[0],a),K(o,n[1],a),k(e,o),e[31]^=M(r)<<7}function te(e,t,n){var r,o;for(I(e[0],a),I(e[1],i),I(e[2],i),I(e[3],a),o=255;o>=0;--o)$(e,t,r=n[o/8|0]>>(7&o)&1),Z(t,e),Z(e,e),$(e,t,r)}function ne(e,n){var r=[t(),t(),t(),t()];I(r[0],f),I(r[1],d),I(r[2],i),K(r[3],f,d),te(e,r,n)}function re(e,r,o){var a,i=new Uint8Array(64),s=[t(),t(),t(),t()];for(o||n(r,32),X(i,r,32),i[0]&=248,i[31]&=127,i[31]|=64,ne(s,i),ee(e,s),a=0;a<32;a++)r[a+32]=e[a];return 0}var oe=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function ae(e,t){var n,r,o,a;for(r=63;r>=32;--r){for(n=0,o=r-32,a=r-12;o<a;++o)t[o]+=n-16*t[r]*oe[o-(r-32)],n=Math.floor((t[o]+128)/256),t[o]-=256*n;t[o]+=n,t[r]=0}for(n=0,o=0;o<32;o++)t[o]+=n-(t[31]>>4)*oe[o],n=t[o]>>8,t[o]&=255;for(o=0;o<32;o++)t[o]-=n*oe[o];for(r=0;r<32;r++)t[r+1]+=t[r]>>8,e[r]=255&t[r]}function ie(e){var t,n=new Float64Array(64);for(t=0;t<64;t++)n[t]=e[t];for(t=0;t<64;t++)e[t]=0;ae(e,n)}function se(e,n,r,o){var a,i,s=new Uint8Array(64),c=new Uint8Array(64),u=new Uint8Array(64),l=new Float64Array(64),f=[t(),t(),t(),t()];X(s,o,32),s[0]&=248,s[31]&=127,s[31]|=64;var d=r+64;for(a=0;a<r;a++)e[64+a]=n[a];for(a=0;a<32;a++)e[32+a]=s[32+a];for(X(u,e.subarray(32),r+32),ie(u),ne(f,u),ee(e,f),a=32;a<64;a++)e[a]=o[a];for(X(c,e,r+64),ie(c),a=0;a<64;a++)l[a]=0;for(a=0;a<32;a++)l[a]=u[a];for(a=0;a<32;a++)for(i=0;i<32;i++)l[a+i]+=c[a]*s[i];return ae(e.subarray(32),l),d}function ce(e,n,r,o){var s,u=new Uint8Array(32),l=new Uint8Array(64),f=[t(),t(),t(),t()],d=[t(),t(),t(),t()];if(r<64)return-1;if(function(e,n){var r=t(),o=t(),s=t(),u=t(),l=t(),f=t(),d=t();return I(e[2],i),F(e[1],n),j(s,e[1]),K(u,s,c),H(s,s,e[2]),L(u,e[2],u),j(l,u),j(f,l),K(d,f,l),K(r,d,s),K(r,r,u),B(r,r),K(r,r,s),K(r,r,u),K(r,r,u),K(e[0],r,u),j(o,e[0]),K(o,o,u),R(o,s)&&K(e[0],e[0],h),j(o,e[0]),K(o,o,u),R(o,s)?-1:(M(e[0])===n[31]>>7&&H(e[0],a,e[0]),K(e[3],e[0],e[1]),0)}(d,o))return-1;for(s=0;s<r;s++)e[s]=n[s];for(s=0;s<32;s++)e[s+32]=o[s];if(X(l,e,r),ie(l),te(f,d,l),ne(d,n.subarray(32)),Z(f,d),ee(u,f),r-=64,m(n,0,u,0)){for(s=0;s<r;s++)e[s]=0;return-1}for(s=0;s<r;s++)e[s]=n[s+64];return r}var ue=16,le=64,fe=32,de=64;function he(e,t){if(32!==e.length)throw new Error("bad key size");if(24!==t.length)throw new Error("bad nonce size")}function pe(){for(var e=0;e<arguments.length;e++)if(!(arguments[e]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function ye(e){for(var t=0;t<e.length;t++)e[t]=0}e.lowlevel={crypto_core_hsalsa20:E,crypto_stream_xor:O,crypto_stream:w,crypto_stream_salsa20_xor:A,crypto_stream_salsa20:_,crypto_onetimeauth:S,crypto_onetimeauth_verify:T,crypto_verify_16:v,crypto_verify_32:m,crypto_secretbox:C,crypto_secretbox_open:x,crypto_scalarmult:V,crypto_scalarmult_base:G,crypto_box_beforenm:J,crypto_box_afternm:q,crypto_box:function(e,t,n,r,o,a){var i=new Uint8Array(32);return J(i,o,a),q(e,t,n,r,i)},crypto_box_open:function(e,t,n,r,o,a){var i=new Uint8Array(32);return J(i,o,a),W(e,t,n,r,i)},crypto_box_keypair:Y,crypto_hash:X,crypto_sign:se,crypto_sign_keypair:re,crypto_sign_open:ce,crypto_secretbox_KEYBYTES:32,crypto_secretbox_NONCEBYTES:24,crypto_secretbox_ZEROBYTES:32,crypto_secretbox_BOXZEROBYTES:ue,crypto_scalarmult_BYTES:32,crypto_scalarmult_SCALARBYTES:32,crypto_box_PUBLICKEYBYTES:32,crypto_box_SECRETKEYBYTES:32,crypto_box_BEFORENMBYTES:32,crypto_box_NONCEBYTES:24,crypto_box_ZEROBYTES:32,crypto_box_BOXZEROBYTES:16,crypto_sign_BYTES:le,crypto_sign_PUBLICKEYBYTES:fe,crypto_sign_SECRETKEYBYTES:de,crypto_sign_SEEDBYTES:32,crypto_hash_BYTES:64,gf:t,D:c,L:oe,pack25519:k,unpack25519:F,M:K,A:L,S:j,Z:H,pow2523:B,add:Z,set25519:I,modL:ae,scalarmult:te,scalarbase:ne},e.randomBytes=function(e){var t=new Uint8Array(e);return n(t,e),t},e.secretbox=function(e,t,n){pe(e,t,n),he(n,t);for(var r=new Uint8Array(32+e.length),o=new Uint8Array(r.length),a=0;a<e.length;a++)r[a+32]=e[a];return C(o,r,r.length,t,n),o.subarray(ue)},e.secretbox.open=function(e,t,n){pe(e,t,n),he(n,t);for(var r=new Uint8Array(ue+e.length),o=new Uint8Array(r.length),a=0;a<e.length;a++)r[a+ue]=e[a];return r.length<32||0!==x(o,r,r.length,t,n)?null:o.subarray(32)},e.secretbox.keyLength=32,e.secretbox.nonceLength=24,e.secretbox.overheadLength=ue,e.scalarMult=function(e,t){if(pe(e,t),32!==e.length)throw new Error("bad n size");if(32!==t.length)throw new Error("bad p size");var n=new Uint8Array(32);return V(n,e,t),n},e.scalarMult.base=function(e){if(pe(e),32!==e.length)throw new Error("bad n size");var t=new Uint8Array(32);return G(t,e),t},e.scalarMult.scalarLength=32,e.scalarMult.groupElementLength=32,e.box=function(t,n,r,o){var a=e.box.before(r,o);return e.secretbox(t,n,a)},e.box.before=function(e,t){pe(e,t),function(e,t){if(32!==e.length)throw new Error("bad public key size");if(32!==t.length)throw new Error("bad secret key size")}(e,t);var n=new Uint8Array(32);return J(n,e,t),n},e.box.after=e.secretbox,e.box.open=function(t,n,r,o){var a=e.box.before(r,o);return e.secretbox.open(t,n,a)},e.box.open.after=e.secretbox.open,e.box.keyPair=function(){var e=new Uint8Array(32),t=new Uint8Array(32);return Y(e,t),{publicKey:e,secretKey:t}},e.box.keyPair.fromSecretKey=function(e){if(pe(e),32!==e.length)throw new Error("bad secret key size");var t=new Uint8Array(32);return G(t,e),{publicKey:t,secretKey:new Uint8Array(e)}},e.box.publicKeyLength=32,e.box.secretKeyLength=32,e.box.sharedKeyLength=32,e.box.nonceLength=24,e.box.overheadLength=e.secretbox.overheadLength,e.sign=function(e,t){if(pe(e,t),t.length!==de)throw new Error("bad secret key size");var n=new Uint8Array(le+e.length);return se(n,e,e.length,t),n},e.sign.open=function(e,t){if(pe(e,t),t.length!==fe)throw new Error("bad public key size");var n=new Uint8Array(e.length),r=ce(n,e,e.length,t);if(r<0)return null;for(var o=new Uint8Array(r),a=0;a<o.length;a++)o[a]=n[a];return o},e.sign.detached=function(t,n){for(var r=e.sign(t,n),o=new Uint8Array(le),a=0;a<o.length;a++)o[a]=r[a];return o},e.sign.detached.verify=function(e,t,n){if(pe(e,t,n),t.length!==le)throw new Error("bad signature size");if(n.length!==fe)throw new Error("bad public key size");var r,o=new Uint8Array(le+e.length),a=new Uint8Array(le+e.length);for(r=0;r<le;r++)o[r]=t[r];for(r=0;r<e.length;r++)o[r+le]=e[r];return ce(a,o,o.length,n)>=0},e.sign.keyPair=function(){var e=new Uint8Array(fe),t=new Uint8Array(de);return re(e,t),{publicKey:e,secretKey:t}},e.sign.keyPair.fromSecretKey=function(e){if(pe(e),e.length!==de)throw new Error("bad secret key size");for(var t=new Uint8Array(fe),n=0;n<t.length;n++)t[n]=e[32+n];return{publicKey:t,secretKey:new Uint8Array(e)}},e.sign.keyPair.fromSeed=function(e){if(pe(e),32!==e.length)throw new Error("bad seed size");for(var t=new Uint8Array(fe),n=new Uint8Array(de),r=0;r<32;r++)n[r]=e[r];return re(t,n,!0),{publicKey:t,secretKey:n}},e.sign.publicKeyLength=fe,e.sign.secretKeyLength=de,e.sign.seedLength=32,e.sign.signatureLength=le,e.hash=function(e){pe(e);var t=new Uint8Array(64);return X(t,e,e.length),t},e.hash.hashLength=64,e.verify=function(e,t){return pe(e,t),0!==e.length&&0!==t.length&&(e.length===t.length&&0===y(e,0,t,0,e.length))},e.setPRNG=function(e){n=e},function(){var t="undefined"!=typeof self?self.crypto||self.msCrypto:null;if(t&&t.getRandomValues){e.setPRNG((function(e,n){var r,o=new Uint8Array(n);for(r=0;r<n;r+=65536)t.getRandomValues(o.subarray(r,r+Math.min(n-r,65536)));for(r=0;r<n;r++)e[r]=o[r];ye(o)}))}else void 0!==l&&(t=require("crypto"))&&t.randomBytes&&e.setPRNG((function(e,n){var r,o=t.randomBytes(n);for(r=0;r<n;r++)e[r]=o[r];ye(o)}))}()}(e.exports?e.exports:self.nacl=self.nacl||{})}(d)),d.exports}var p,y,v,m,g,E,b,A={exports:{}},_=A.exports;function w(){return p||(p=1,function(e){var t,n;t=_,n=function(){var e={};function t(e){if(!/^(?:[A-Za-z0-9+\/]{2}[A-Za-z0-9+\/]{2})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/.test(e))throw new TypeError("invalid encoding")}return e.decodeUTF8=function(e){if("string"!=typeof e)throw new TypeError("expected string");var t,n=unescape(encodeURIComponent(e)),r=new Uint8Array(n.length);for(t=0;t<n.length;t++)r[t]=n.charCodeAt(t);return r},e.encodeUTF8=function(e){var t,n=[];for(t=0;t<e.length;t++)n.push(String.fromCharCode(e[t]));return decodeURIComponent(escape(n.join("")))},"undefined"==typeof atob?void 0!==Buffer.from?(e.encodeBase64=function(e){return Buffer.from(e).toString("base64")},e.decodeBase64=function(e){return t(e),new Uint8Array(Array.prototype.slice.call(Buffer.from(e,"base64"),0))}):(e.encodeBase64=function(e){return new Buffer(e).toString("base64")},e.decodeBase64=function(e){return t(e),new Uint8Array(Array.prototype.slice.call(new Buffer(e,"base64"),0))}):(e.encodeBase64=function(e){var t,n=[],r=e.length;for(t=0;t<r;t++)n.push(String.fromCharCode(e[t]));return btoa(n.join(""))},e.decodeBase64=function(e){t(e);var n,r=atob(e),o=new Uint8Array(r.length);for(n=0;n<r.length;n++)o[n]=r.charCodeAt(n);return o}),e},e.exports?e.exports=n():(t.nacl||(t.nacl={}),t.nacl.util=n())}(A)),A.exports}function O(){return y||(y=1,function(e){var t,n,r,o,a,i;e.exports&&(e.exports=(t=u(),n=h(),r=w(),a=function(e){return e.replace(/^\d+:/,"")},i=(o={}).removeCp=function(e){return e.replace(/^cp\|([A-Za-z0-9+\/=]{0,20}\|)?/,"")},o.start=function(e){var o,s=(e=e||{}).network,c=e.websocketURL,u=e.userName,l=e.channel,f=e.crypto,d=e.readOnly||!1,h=!e.noChainPad&&(e.ChainPad||globalThis.ChainPad),p=void 0===e.useHistory||!!e.useHistory,y=!1,v=e.lastKnownHash,m={},g=[],E=e.priority||2,b=e.Cache,A=!1,_=Math.floor(1e6*Math.random()),w=e.metadata||{},O=w.validateKey=e.validateKey||w.validateKey;w.owners=e.owners||w.owners,w.expire=e.expire||w.expire;var D,S,T=!0,C=!1,x={setReadOnly:function(e,t){d=e,t&&(f=t)}},I=function(){},N=[],P={send:function(){}},k=function(){D&&"function"==typeof D.abort&&D.abort();var t=h.create({userName:u,initialState:e.initialState,transformFunction:e.transformFunction,patchTransformer:e.patchTransformer,validateContent:e.validateContent,avgSyncMilliseconds:e.avgSyncMilliseconds,logLevel:void 0!==e.logLevel?e.logLevel:1});return b&&Array.isArray(o)&&o.length&&(o.forEach((function(e){var n=e.patch;if(!/^\[/.test(n)){try{n=f.decrypt(n,O,!0)}catch(e){console.error(n,O,l),console.error(e)}n=a(n)}t.message(n)})),""===t.getUserDoc())?(t.abort(),o=[],b.clearChannel(l),k()):(t.onMessage((function(e,t,n){P.send(e,t,n)})),t.onPatch((function(n){e.onRemote&&e.onRemote({realtime:t,patch:n})})),t)},R={change:[],onChange:function(e){R.change.forEach((function(t){t(e)}))},users:[]},M=function(t){e.onJoin&&e.onJoin(t),32===t.length&&(-1===R.users.indexOf(t)&&R.users.push(t),R.onChange())},F=function(){},L=function(t){e.onLeave&&e.onLeave(t);var n=R.users.indexOf(t);-1!==n&&R.users.splice(n,1),R.onChange()},H=function(t,n){if(T){try{var r=D&&D.getUserDoc();if(A&&D&&(""===r||r===e.initialState))return void x.resetCache()}catch(e){console.error(e)}D&&D.start(),e.setMyID&&e.setMyID({myID:t.myID}),T=!1,e.onReady&&e.onReady({realtime:D,network:n,userList:R,myId:t.myID,leave:t.leave,metadata:w}),g.length&&(g.forEach((function(e){"function"==typeof e&&e()})),g=[])}},K=function(t,n){if(e.onChannelError&&e.onChannelError({channel:n.id,type:t.error,loaded:!T,error:t.error,message:t.message}),"EUNKNOWN"===t.error)return v=void 0,n&&n.leave(),b?(o=[],void b.clearChannel(l,(function(){h&&(x.realtime=D=k()),I(s,F)}))):void I(s,F);if("function"==typeof x.stop)try{x.stop()}catch(e){}},j=!0,U=function(e){b&&(o.length&&o[o.length-1].hash===e.hash||(!o.length&&j&&(e.isCheckpoint=!0,j=!1),(o.length||e.isCheckpoint)&&(o.push(e),b.storeCache(l,O,o,(function(e){if(e){b.clearChannel(l,(function(){console.warn("Cache cleared",l)}));var t=o;return o=[],void console.error(e,l,t,O)}})))))},B=function(t,n,r,o,s){var c=o.historyKeeper,u=t===c;if(!r||0!==n&&"0"!==n){if(!s||t===c){if(s){var d=JSON.parse(n);if(d.txid&&d.txid!==_)return;if(d.validateKey&&d.channel)return d.channel!==r.id||O||(O=d.validateKey),void(d.channel===r.id&&(w=d,e.onMetadataUpdate&&!T&&e.onMetadataUpdate(w)));if(d.state&&1===d.state&&d.channel)return void(d.channel===r.id&&(Object.keys(m).forEach((function(e){"function"==typeof m[e]&&m[e]("FAILED")})),m={},H(r,o)))}if(u){var h=JSON.parse(n);if(Array.isArray(h)&&h[0]&&h[0]!==_)return;if(h.channel===r.id&&h.error)return void K(h,r);if(n=h[4],h[3]!==r.id)return}if(v=n.slice(0,64),"function"==typeof m[v])return m[v](null,v),void delete m[v];var p,y=/^cp\|/.test(n);n=i(n);try{n=f.decrypt(n,O,u)}catch(e){console.error(n,O,l),console.error(e)}var E="string"==typeof n;!E&&n.content&&(p=n.author,n=n.content),T||e.onLocal&&e.onLocal(!0);var b=E?a(n):n,A=function(){try{if(D&&E&&D.message(b),e.onMessage){var n={time:h?h[5]:+new Date};e.onMessage(b,t,O,y,v,p,n)}var r=y;e.isCacheCheckpoint&&(r=e.isCacheCheckpoint(b,p)),U({patch:b,hash:v,isCheckpoint:r,author:p,time:h?h[5]:+new Date})}catch(e){console.error(e)}};T&&t!==c?g.push(A):A()}}else H(r,o)},V=function(t,a,s){P.wc=t,l=t.id,t.members.forEach(M);var c,u=function(e,n){B(n,e,t,a)};t.on("message",u),t.on("join",M),t.on("leave",L),P.stop=function(){t.off("message",u),t.off("join",M),t.off("leave",L),t.leave(),D&&D.abort()},s&&(P.send=function(t,o,s){var c=function(e,t){if(!d)try{var o=f.encrypt(e,t);if(0===e.indexOf("[4")){var a="";if(n&&r){var i=n.hash(r.decodeUTF8(e));a=r.encodeBase64(i.slice(0,8))+"|"}else console.log("Checkpoint sent without an ID. Nacl is missing.");o="cp|"+a+o}return o}catch(t){throw console.log(e),t}}(t,s);if(c){var u=c.slice(0,64),h=/^cp\|/.test(c);e.isCacheCheckpoint&&(h=e.isCacheCheckpoint(t,s)),m[u]=function(e,n){!e&&n&&U({patch:i(t),hash:u,isCheckpoint:h,author:s,time:+new Date}),o(e,n)},P.wc.bcast(c).then((function(){v=u,delete m[u],U({patch:i(t),hash:u,isCheckpoint:h,author:s,time:+new Date}),o(null,u)}),(function(e){if(console.error(e),!e||"enoent"!==e.type&&"ENOENT"!==e.type)delete m[u],o(e&&e.type||e);else{if(P.wc.leave(),y)return delete m[u],void o("STOPPED");T=!0,a.join(l,E).then((function(e){V(e,a,!1),P.send(t,o,s)}))}}))}},h&&!D&&(x.realtime=D=k()),e.onInit&&e.onInit({myID:t.myID,realtime:D,getLag:a.getLag,userList:R,network:a,channel:l})),e.onConnect&&e.onConnect(t,P.send),p?(t.members.forEach((function(e){16===e.length&&(c=e)})),S!==c&&(a.historyKeeper=c,S=c,N.forEach((function(e){e(c)}))),function(){var e={txid:_,priority:E,lastKnownHash:v,metadata:w};b&&Array.isArray(o)&&o.length&&(e.lastKnownHash=o[o.length-1].hash),g=[];var n=["GET_HISTORY",t.id,e];c&&a.sendto(c,JSON.stringify(n))}(),x.resetCache=function(){T=!0,o=[],b&&b.clearChannel(l),_=Math.floor(1e6*Math.random()),K({error:"EUNKNOWN",message:"Corrupted cache"},t)}):H(t,a)},G=!1;"undefined"!=typeof window&&window.addEventListener("beforeunload",(function(){G=!0}));var Y=function(e,t){var n;return e.some((function(e){if(e.id===t)return n=e,!0})),n},J=function(t){e.onError&&e.onError({type:t.type||t,message:t.message,error:t.type,loaded:!T})};I=function(n,r){var a;"string"==typeof n&&(a=t.connect(n));var i=function(){C=!1,"string"==typeof n?a.then(r,J):"function"==typeof n.then?n.then(r,J):r(n)};if(b&&!C)return b.getChannelCache(l,(function(t,n){O=n?n.k:void 0,(o=n?n.c:[]).length?(A=!0,e.onCacheStart&&e.onCacheStart(),h&&(x.realtime=D=k()),o.length?(e.onMessage&&o.forEach((function(t){var n={time:t.time};e.onMessage(t.patch,"cache",O,t.isCheckpoint,t.hash,t.author,n)})),e.onCacheReady&&e.onCacheReady({id:l,realtime:D,networkPromise:a}),i()):i()):i()})),void(x.resetCache=function(){b&&b.clearChannel(l),o=[]});i()};var q=!0;return F=function(t,n){y||t.join(l||null,E).then((function(e){if(y)try{e.leave()}catch(e){}else V(e,t,n)}),(function(r){r&&"ERESTRICTED"===r.type&&Array.isArray(r.message)&&e.onRejected?e.onRejected(r.message,(function(e){e?J(r):F(t,n)})):J(r)}))},x.stop=function(){y=!0},I(s||c,(function(t){if(s=t,q){if(q=!1,y)return;var n=function(t){G||"network.disconnect() called"!==t&&(e.onConnectionChange?e.onConnectionChange({state:!1}):e.onAbort&&e.onAbort({reason:t}))},r=function(t){if(e.onConnectionChange){e.onConnectionChange({state:!0,myId:t});var n=function(){T=!0,C=!0,R.users=[],I(s,F)};if(e.beforeReconnecting)return void e.beforeReconnecting((function(t,r){l=t,e.initialState=r,n()}));n()}},o=function(e,t){var n=Y(s.webChannels,l);n&&B(t,e,n,s,!0)};s.on("disconnect",n),s.on("reconnect",r),s.on("message",o),x.network=s,x.stop=function(){P&&P.stop&&P.stop();var e=Y(s.webChannels,l);if(e)try{e.leave("")}catch(e){}s.off("disconnect",n),s.off("reconnect",r),s.off("message",o),y=!0},s.onHistoryKeeperChange=function(e){N.push(e)}}F(s,!0)})),x},o))}(s)),s.exports}function D(){return E?g:(E=1,g=function(){if(m)return v;m=1;const e=t=>{if(Array.isArray(t))return t.map(e);if(t instanceof Object){let n=[],r=[];return Object.keys(t).forEach((e=>{/^(0|[1-9][0-9]*)$/.test(e)?n.push(+e):r.push(e)})),n.sort((function(e,t){return e-t})).concat(r.sort()).reduce(((n,r)=>(n[r]=e(t[r]),n)),{})}return t},t=JSON.stringify.bind(JSON);return v=(n,r,o)=>{let a=t(n,r,0);if(!a||"{"!==a[0]&&"["!==a[0])return a;let i=JSON.parse(a);return t(e(i),null,o)}}())}function S(){return b||(b=1,function(e){e.exports&&(e.exports=function(e,t){const n=globalThis;var r,o={},a=void 0===n.Proxy,i=o.DeepProxy=function(){var e={},r=e.isArray=Array.isArray||function(e){return"[object Array]"===Object.toString(e)},o=e.type=function(e){return null===e?"null":r(e)?"array":typeof e},i=e.isProxyable=function(e,t){return(void 0!==t||!a)&&-1!==["object","array"].indexOf(o(e))},s=e.set=function(t){return function(n,r,o){if("on"===r)throw new Error("'on' is a reserved attribute name for realtime lists and maps");return i(o)?n[r]=e.create(o,t):n[r]=o,t(),n[r]||!0}},c=e.pathMatches=function(e,t){return!t.some((function(t,n){return t!==e[n]}))},u=function(e,t){return t.pattern.length-e.pattern.length},l=function(e){return function(t,n,r){switch(t){case"change":n="array"===o(n)?n:[n],e.change.push({cb:function(e,t,o,a){if(c(o,n))return r(e,t,o,a)},pattern:n}),e.change.sort(u);break;case"remove":n="array"===o(n)?n:[n],e.remove.push({cb:function(e,t,o){if(c(t,n))return r(e,t,o)},pattern:n}),e.remove.sort(u);break;case"ready":e.ready.push({cb:function(e){n(e)}});break;case"cacheready":e.cacheready.push({cb:function(e){n(e)}});break;case"disconnect":e.disconnect.push({cb:function(e){n(e)}});break;case"reconnect":e.reconnect.push({cb:function(e){n(e)}});break;case"create":e.create.push({cb:function(e){n(e)}});break;case"error":e.error.push({cb:function(e){n(e)}})}return this}},f=e.get=function(){var e={cacheready:[],disconnect:[],reconnect:[],change:[],ready:[],remove:[],create:[],error:[]};return function(t,n){return"on"===n?l(e):"_isProxy"===n||("_events"===n?e:t[n])}},d=e.delete=function(e){return function(t,n){return void 0===t[n]||(delete t[n],e()),!0}},h=e.handlers=function(e,t){return t?{set:s(e),get:f(e),deleteProperty:d(e)}:{set:s(e),get:function(e,t){return"_isProxy"===t||e[t]},deleteProperty:d(e)}},p=e.remoteChangeFlag=!1,y=e.stringifyFakeProxy=function(e){var n=JSON.parse(t(e));return delete n._events,delete n._isProxy,t(n)};e.checkLocalChange=function(t,r){if(a&&!e.interval){var o=y(t);e.interval=n.setInterval((function(){var e=y(t);e!==o&&(o=e,p?p=!1:r())}),300)}};var v=e.create=function(e,t,r){var s="function"===o(t)?h(t,r):t;switch(o(e)){case"object":Object.keys(e).forEach((function(n){i(e[n])&&!e[n]._isProxy&&(e[n]=v(e[n],t))}));break;case"array":e.forEach((function(n,r){i(n)&&!n._isProxy&&(e[r]=v(e[r],t))}));break;default:throw new Error("attempted to make a proxy of an unproxyable object")}if(!a)return e._isProxy?e:new n.Proxy(e,s);var c=JSON.parse(JSON.stringify(e));if(r){var u={cacheready:[],disconnect:[],reconnect:[],change:[],ready:[],remove:[],create:[],error:[]};c.on=l(u),c._events=u}return c},m=function(e,t,n,r,o){var a=e.slice(0);a.push(t),n._events.change.some((function(e){return!1===e.cb(r,o,a,n)}))},g=e.find=function(e,t){for(var n=t.length,r=0;r<n;r++){if(void 0===e[t[r]])return;e=e[t[r]]}return e},E=function(e,t,n,r,a){var i=e.concat(t),s=g(n,i);switch(o(s)){case"array":a?m(e,t,n,r,void 0):n._events.remove.forEach((function(e){return e.cb(s,i,n)})),s.forEach((function(e,t){E(i,t,n)}));break;case"object":a?m(e,t,n,r,void 0):n._events.remove.forEach((function(e){return e.cb(s,i,n,r,!1)})),Object.keys(s).forEach((function(e){E(i,e,n,s[e],!1)}));break;default:n._events.remove.forEach((function(e){return e.cb(s,i,n)}))}},b=e.objects=function(t,n,r,a,i){var s=Object.keys(t),c=Object.keys(n);c.forEach((function(c){var u=o(n[c]),l=t[c];if(-1!==s.indexOf(c)){var f=o(t[c]);if(f===u)if(-1!==["array","object"].indexOf(f)){var d=a.slice(0).concat(c);"object"===f?b.call(i,t[c],n[c],r,d,i):e.arrays.call(i,t[c],n[c],r,d,i)}else t[c]!==n[c]&&(t[c]=n[c],m(a,c,i,l,n[c]));else{switch(console.log("type changed from [%s] to [%s]",f,u),u){case"undefined":throw new Error("first pass should never reveal undefined keys");case"array":case"object":t[c]=r(n[c]);break;default:t[c]=n[c]}m(a,c,i,l,n[c])}}else{switch(u){case"undefined":throw new Error("undefined type has key. this shouldn't happen?");case"array":case"object":t[c]=r(n[c]);break;default:t[c]=n[c]}m(a,c,i,l,n[c])}})),s.forEach((function(e){var r=t[e];"on"!==e&&"_events"!==e&&(-1!==c.indexOf(e)&&"undefined"!==o(n[e])||(E(a,e,i,r,!0),delete t[e]))}))},A=e.arrays=function(e,t,n,r,a){var i=e.length,s=t.length;if(i===s)e.forEach((function(i,s){var c=o(i),u=o(t[s]),l=i;if(c===u){var f=r.slice(0).concat(s);switch(u){case"undefined":throw new Error("existing key had type `undefined`. this should never happen");case"object":b.call(a,e[s],t[s],n,f,a)&&m(r,s,a,l,t[s]);break;case"array":A.call(a,e[s],t[s],n,f,a)&&m(r,s,a,l,t[s]);break;default:e[s]!==t[s]&&(e[s]=t[s],m(r,s,a,l,t[s]))}}else{switch(u){case"undefined":E(r,s,a,l,!0);break;case"object":case"array":e[s]=n(t[s]);break;default:e[s]=t[s]}m(r,s,a,l,t[s])}}));else{if(t.forEach((function(t,i){var s=o(e[i]),c=o(t),u=e[i];if(s!==c){switch(c){case"undefined":throw new Error("this should never happen");case"object":case"array":e[i]=n(t);break;default:e[i]=t}m(r,i,a,u,t)}else{var l=r.slice(0).concat(i);switch(c){case"object":b.call(a,e[i],t,n,l,a);break;case"array":A.call(a,e[i],t,n,l,a)&&m(r,i,a,u,t);break;default:t!==e[i]&&(e[i]=t,m(r,i,a,u,t))}}})),i>s)for(var c,u=s;u<=s;u++)c=e[u],E(r,u,a,c,!0);e.length=s}};return e.update=function(e,t,n){var r=o(e),a=o(t);if(r!==a)throw new Error("Proxy updates can't result in type changes");switch(a){case"array":A.call(e,e,t,(function(e){return v(e,n)}),[],e);break;case"object":b.call(e,e,t,(function(e){return v(e,n)}),[],e);break;default:throw new Error("unsupported realtime datatype:"+a)}},e}();return o.create=function(o){if(!i.isProxyable(o.data,!0))throw new Error("unsupported datatype: "+i.type(o.data));if("function"!=typeof(r=o.ChainPad||n.ChainPad).SmartJSONTransformer)throw new Error("Please update ChainPad");o.classic&&!o.crypto&&(console.error("[chainpad-listmap] no crypto module provided. messages will not be encrypted"),o.crypto={encrypt:function(e){return e},decrypt:function(e){return e}});var s=o.readOnly,c={initialState:t(o.data),patchTransformer:r.SmartJSONTransformer,validateContent:o.validateContent||function(e){try{return JSON.parse(e),!0}catch(t){return console.log(e),console.error("Failed to parse, rejecting patch"),!1}},readOnly:o.readOnly,userName:o.userName||"listmap",Cache:o.Cache,logLevel:void 0===o.logLevel?0:o.logLevel};o.classic&&(c.channel=o.channel,c.crypto=o.crypto,c.network=o.network,c.websocketURL=o.websocketURL,c.metadata=o.metadata||{validateKey:o.validateKey,owners:o.owners,expire:o.expire},c.onRejected=o.onRejected);var u,l,f,d={metadata:{}},h=!0,p=!1,y=a?i.stringifyFakeProxy:t,v=function(){var e=y(l);try{u.contentUpdate(e)}catch(e){l._events.error.forEach((function(t){t.cb({type:"CHAINPAD",error:e.message})}))}o.onLocal&&o.onLocal()},m=c.onLocal=function(e){h||s||(clearTimeout(f),e?v():f=setTimeout(v))},g=function(){i.remoteChangeFlag||m()};l=i.create(o.data,g,!0),c.onInit=function(e){l._events.create.forEach((function(t){t.cb(e)}))},c.onCacheReady=function(e){u&&u===e.realtime||(u=d.realtime=e.realtime);var t=u.getUserDoc(),n=JSON.parse(t);i.update(l,n,g),i.checkLocalChange(l,m),p||l._events.cacheready.forEach((function(t){t.cb(e)}))};var E=0;c.onReady=function(e){if(E=-1,p)return h=!1,c.onRemote(),void l._events.reconnect.forEach((function(t){t.cb(e)}));u&&u===e.realtime||(u=d.realtime=e.realtime),d.metadata=e.metadata;var t=u.getUserDoc(),n=JSON.parse(t);i.update(l,n,g),i.checkLocalChange(l,m),h=!1,p=!0,l._events.ready.forEach((function(t){t.cb(e)}))},c.onRemote=function(){if(!h){var e=u.getUserDoc(),t=JSON.parse(e);i.remoteChangeFlag=!0,i.update(l,t,g),i.remoteChangeFlag=!1}},c.onMessage=function(){-1!==E&&o.updateProgress&&o.updateProgress({progress:E++})},c.onAbort=function(e){l._events.disconnect.forEach((function(t){t.cb(e)}))},c.onConnectionChange=function(e){e.state?h=!0:l._events.disconnect.forEach((function(t){t.cb(e)}))},c.onMetadataUpdate=function(e){d.metadata=e,"function"==typeof o.onMetadataUpdate&&o.onMetadataUpdate(e)},c.onError=function(e){l._events.error.forEach((function(t){t.cb(e)}))},c.onChannelError=function(e){l._events.error.forEach((function(t){t.cb(e)}))},o.common&&"function"==typeof o.common.startRealtime?u=d.cpCnInner=o.common.startRealtime(c):d=e.start(c),d.proxy=l,d.realtime=u;var b=d.setReadOnly;return d.setReadOnly=function(e,t){s=e,b&&b(e,t)},d},o}(O(),D()))}(i)),i.exports}var T,C=S(),x={exports:{}};function I(){return T||(T=1,function(e){var t,r,o,a;a=function(){var e=l,t=function(n,r,o){r||(r=0);var a=t.resolve(n,r),i=t.m[r][a];if(!i&&e){if(i=e(a))return i}else if(i&&i.c&&(r=i.c,a=i.m,!(i=t.m[r][i.m])))throw new Error('failed to require "'+a+'" from '+r);if(!i)throw new Error('failed to require "'+n+'" from '+o);return i.exports||(i.exports={},i.call(i.exports,i,i.exports,t.relative(a,r))),i.exports};return t.resolve=function(e,n){var r=e,o=e+".js",a=e+"/index.js";return t.m[n][o]&&o?o:t.m[n][a]&&a?a:r},t.relative=function(e,n){return function(r){if("."!=r.charAt(0))return t(r,n,e);var o=e.split("/"),a=r.split("/");o.pop();for(var i=0;i<a.length;i++){var s=a[i];".."==s?o.pop():"."!=s&&o.push(s)}return t(o.join("/"),n,e)}},t}(),a.m=[],a.m[0]={"json.sortify":{c:1,m:"dist/JSON.sortify.js"},"fast-diff":{c:2,m:"diff.js"},"Diff.js":function(e,t,n){var r=n("fast-diff");e.exports.diff=function(e,t){return n=r(e,t),o=[],a=0,i=!0,s={offset:0,toInsert:"",toRemove:0,type:"Operation"},n.forEach((function(e,t){0===e[0]?(i||(o.push(s),a=s.offset+s.toRemove,s={offset:a,toInsert:"",toRemove:0,type:"Operation"}),a+=e[1].length,s.offset=a):1===e[0]?s.toInsert=e[1]:s.toRemove=e[1].length,t===n.length-1&&0!==e[0]&&o.push(s),i&&(i=!1)})),o;var n,o,a,i,s}},"Patch.js":function(e,t,n){var r=n("./Common"),o=n("./Operation"),a=n("./sha256"),i=e.exports,s=i.create=function(e,t){var n=Object.freeze({type:"Patch",operations:[],parentHash:e,isCheckpoint:!!t,mut:{inverseOf:void 0}});return t&&(n.mut.inverseOf=n),n},c=i.check=function(e,t){r.assert("Patch"===e.type),r.assert(Array.isArray(e.operations)),r.assert(/^[0-9a-f]{64}$/.test(e.parentHash));for(var n=e.operations.length-1;n>=0;n--)o.check(e.operations[n],t),n>0&&r.assert(!o.shouldMerge(e.operations[n],e.operations[n-1])),"number"==typeof t&&(t+=o.lengthChange(e.operations[n]));return e.isCheckpoint&&(r.assert(1===e.operations.length),r.assert(0===e.operations[0].offset),"number"==typeof t&&r.assert(!t||e.operations[0].toRemove===t)),e};i.toObj=function(e){r.PARANOIA&&c(e);var t,n=new Array(e.operations.length+1);for(t=0;t<e.operations.length;t++)n[t]=o.toObj(e.operations[t]);return n[t]=e.parentHash,n},i.fromObj=function(e,t){r.assert(Array.isArray(e)&&e.length>0);var n,i=s(a.check(e[e.length-1]),t);for(n=0;n<e.length-1;n++)i.operations[n]=o.fromObj(e[n]);return r.PARANOIA&&c(i),i};var u=function(e){return a.hex_sha256(e)},l=i.addOperation=function(e,t){r.PARANOIA&&(c(e),o.check(t));for(var n=0;n<e.operations.length;n++)if(o.shouldMerge(e.operations[n],t)){var a=o.merge(e.operations[n],t);if(e.operations.splice(n,1),null===a)return;t=a,n--}else{var i=o.rebase(e.operations[n],t);if(i===t)return void e.operations.splice(n,0,t);t=i}e.operations.push(t),r.PARANOIA&&c(e)};i.createCheckpoint=function(e,t,n){var a=o.create(0,e.length,t);r.PARANOIA&&n&&r.assert(n===u(e)),n=n||u(e);var i=s(n,!0);return i.operations[0]=a,i};var f=i.clone=function(e){r.PARANOIA&&c(e);for(var t=s(e.parentHash,e.isCheckpoint),n=0;n<e.operations.length;n++)t.operations[n]=e.operations[n];return t};i.merge=function(e,t){if(r.PARANOIA&&(c(e),c(t)),e.isCheckpoint)return r.assert(t.parentHash===e.parentHash),t.isCheckpoint?s(e.parentHash):f(t);if(t.isCheckpoint)return f(e);e=f(e);for(var n=t.operations.length-1;n>=0;n--)l(e,t.operations[n]);return e},i.apply=function(e,t){r.PARANOIA&&(c(e),r.assert("string"==typeof t),r.assert(a.hex_sha256(t)===e.parentHash));for(var n=t,i=e.operations.length-1;i>=0;i--)n=o.apply(e.operations[i],n);return n},i.lengthChange=function(e){r.PARANOIA&&c(e);for(var t=0,n=0;n<e.operations.length;n++)t+=o.lengthChange(e.operations[n]);return t},i.invert=function(e,t){r.PARANOIA&&(c(e),r.assert("string"==typeof t),r.assert(a.hex_sha256(t)===e.parentHash));for(var n=t,i=new Array(e.operations.length),u=e.operations.length-1;u>=0;u--)i[u]=o.invert(e.operations[u],n),n=o.apply(e.operations[u],n);var l=new Array(e.operations.length);!function(){for(var e=i.length-1;e>=0;e--){l[e]=i[e].offset;for(var t=e-1;t>=0;t--)l[e]+=i[t].toRemove-i[t].toInsert.length}}();var f=s(a.hex_sha256(n),e.isCheckpoint);f.operations.splice(0,f.operations.length);for(var d=0;d<i.length;d++)f.operations[d]=o.create(l[d],i[d].toRemove,i[d].toInsert);return r.PARANOIA&&c(f),f},i.simplify=function(e,t,n){r.PARANOIA&&(c(e),r.assert("string"==typeof t),r.assert(a.hex_sha256(t)===e.parentHash));for(var i=s(e.parentHash),u=t,l=[],f=0,d=e.operations.length-1;d>=0;d--){var h=n(e.operations[d],u,o.simplify);h&&(u=o.apply(h,u),l[f++]=h)}return Array.prototype.push.apply(i.operations,l.reverse()),i.operations[0]||i.operations.shift(),r.PARANOIA&&c(i),i},i.equals=function(e,t){if(e.operations.length!==t.operations.length)return!1;for(var n=0;n<e.operations.length;n++)if(!o.equals(e.operations[n],t.operations[n]))return!1;return!0};var d=function(e,t){return 0===e.offset&&e.toRemove===t.length&&e.toInsert===t};i.transform=function(e,t,n,o){if(r.PARANOIA&&(c(e,n.length),c(t,n.length),a.hex_sha256(n)!==e.parentHash))throw new Error("wrong hash");if(e.parentHash!==t.parentHash)throw new Error;var u=i.apply(t,n),l=s(t.mut.inverseOf?t.mut.inverseOf.parentHash:a.hex_sha256(u),e.isCheckpoint);if(0===t.operations.length)return f(e);if(0===e.operations.length){if(e.isCheckpoint)throw new Error;return l}if(e.isCheckpoint||1===e.operations.length&&d(e.operations[0],n))throw new Error("Attempting to transform a checkpoint, this should not happen");if(1===t.operations.length&&d(t.operations[0],n)){if(!t.isCheckpoint)throw new Error;return e}if(t.isCheckpoint)throw new Error;var h=o(e.operations,t.operations,n);return Array.prototype.push.apply(l.operations,h),r.PARANOIA&&c(l,u.length),l},i.random=function(e,t){r.assert("string"==typeof e),t=t||Math.floor(30*Math.random())+1;for(var n=s(a.hex_sha256(e)),i=e.length;t-- >0;){var u=o.random(i);i+=o.lengthChange(u),l(n,u)}return c(n),n},Object.freeze(e.exports)},"SHA256.js":function(e,t,n){!function(){function t(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function n(e,t){return e>>>t|e<<32-t}function r(e,t){return e>>>t}function o(e,t,n){return e&t^~e&n}function a(e,t,n){return e&t^e&n^t&n}function i(e){return n(e,2)^n(e,13)^n(e,22)}function s(e){return n(e,6)^n(e,11)^n(e,25)}function c(e){return n(e,7)^n(e,18)^r(e,3)}e.exports.hex_sha256=function(e){return function(e){for(var t="0123456789abcdef",n="",r=0;r<4*e.length;r++)n+=t.charAt(e[r>>2]>>8*(3-r%4)+4&15)+t.charAt(e[r>>2]>>8*(3-r%4)&15);return n}(function(e,u){var l,f,d,h,p,y,v,m,g,E,b,A=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],_=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],w=function(e){for(var t=[];e>0;e--)t.push(void 0);return t}(64);e[u>>5]|=128<<24-u%32,e[15+(u+64>>9<<4)]=u;for(var O=0;O<e.length;O+=16){l=_[0],f=_[1],d=_[2],h=_[3],p=_[4],y=_[5],v=_[6],m=_[7];for(var D=0;D<64;D++)w[D]=D<16?e[D+O]:t(t(t(n(b=w[D-2],17)^n(b,19)^r(b,10),w[D-7]),c(w[D-15])),w[D-16]),g=t(t(t(t(m,s(p)),o(p,y,v)),A[D]),w[D]),E=t(i(l),a(l,f,d)),m=v,v=y,y=p,p=t(h,g),h=d,d=f,f=l,l=t(g,E);_[0]=t(l,_[0]),_[1]=t(f,_[1]),_[2]=t(d,_[2]),_[3]=t(h,_[3]),_[4]=t(p,_[4]),_[5]=t(y,_[5]),_[6]=t(v,_[6]),_[7]=t(m,_[7])}return _}(function(e){for(var t=Array(),n=0;n<8*e.length;n+=8)t[n>>5]|=(255&e.charCodeAt(n/8))<<24-n%32;return t}(e),8*e.length))}}()},"Common.js":function(e,t,r){e.exports.global=function(){if("undefined"!=typeof self)return self;if(void 0!==n)return n;if("undefined"!=typeof window)return window;throw new Error("no self, nor global, nor window")}();var o=function(t){return"undefined"!=typeof localStorage&&localStorage[t]?localStorage[t]:e.exports.global[t]},a=e.exports.PARANOIA=o("ChainPad_PARANOIA");e.exports.VALIDATE_ENTIRE_CHAIN_EACH_MSG=o("ChainPad_VALIDATE_ENTIRE_CHAIN_EACH_MSG"),e.exports.TESTING=o("ChainPad_TESTING"),e.exports.assert=function(e){if(!e)throw new Error("Failed assertion")},e.exports.isUint=function(e){return"number"==typeof e&&Math.floor(e)===e&&e>=0},e.exports.randomASCII=function(e){for(var t=[],n=0;n<e;n++)t[n]=String.fromCharCode(Math.floor(256*Math.random())%57+65);return t.join("")},e.exports.strcmp=function(e,t){if(a&&"string"!=typeof e)throw new Error;if(a&&"string"!=typeof t)throw new Error;return e===t?0:e>t?1:-1},Object.freeze(e.exports)},"sha256.js":function(e,t,n){var r=n("./sha256/exports.js"),o=n("./SHA256.js"),a=n("./Common");e.exports.check=function(e){if("string"!=typeof e)throw new Error;if(!/[a-f0-9]{64}/.test(e))throw new Error;return e},e.exports.hex_sha256=function(e){e+="";var t=r.hex(function(e){for(var t=new Uint8Array(e.length),n=0;n<e.length;n++)t[n]=255&e.charCodeAt(n);return t}(e));if(a.PARANOIA){var n=o.hex_sha256(e);if(n!==t){try{throw new Error}catch(t){console.log({hashErr:t,badHash:e,asmHasher:r.hex,oldHasher:o.hex_sha256})}return n}}return t},Object.freeze(e.exports)},"Message.js":function(e,t,n){var r=n("./Common"),o=n("./Patch"),a=n("./sha256"),i=e.exports,s=i.PATCH=2,c=i.CHECKPOINT=4,u=i.check=function(e){return r.assert("Message"===e.type),r.assert(e.messageType===s||e.messageType===c),o.check(e.content),r.assert("string"==typeof e.lastMsgHash),e},l=i.create=function(e,t,n){var o={type:"Message",messageType:e,content:t,lastMsgHash:n,hashOf:"",mut:{parentCount:void 0,isInitialMessage:!1,isFromMe:!1,parent:void 0,time:void 0,author:void 0,serverHash:void 0}};return o.hashOf=d(o),r.PARANOIA&&u(o),Object.freeze(o)},f=i.toStr=i.toString=function(e){if(r.PARANOIA&&u(e),e.messageType===s||e.messageType===c){if(!e.content)throw new Error;return JSON.stringify([e.messageType,o.toObj(e.content),e.lastMsgHash])}throw new Error};i.fromString=function(e){var t={};"object"==typeof e&&(t=e,e=e.msg);var n=JSON.parse(e);if(n[0]!==c&&n[0]!==s)throw new Error("invalid message type "+n[0]);var r=l(n[0],o.fromObj(n[1],n[0]===c),n[2]);return r.mut.author=t.author,r.mut.time=t.time&&new Date(t.time),r.mut.serverHash=t.serverHash,Object.freeze(r)};var d=i.hashOf=function(e){return r.PARANOIA&&u(e),a.hex_sha256(f(e))};Object.freeze(e.exports)},"ChainPad.js":function(e,t,n){var r=e.exports.Common=n("./Common"),o=e.exports.Operation=n("./Operation"),a=e.exports.Patch=n("./Patch"),i=e.exports.Message=n("./Message"),s=e.exports.Sha=n("./sha256"),c=e.exports.Diff=n("./Diff"),u=e.exports.TextTransformer=n("./transform/TextTransformer");e.exports.NaiveJSONTransformer=n("./transform/NaiveJSONTransformer"),e.exports.SmartJSONTransformer=n("./transform/SmartJSONTransformer");var l=e.exports.EMPTY_STR_HASH="e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",f=function(e,t){e.logLevel>1&&console.log("["+e.userName+"] "+t)},d=function(e,t){e.logLevel>0&&console.error("["+e.userName+"] "+t)},h=function(e,t,n){if(!e.aborted){n||(n=Math.floor(2*Math.random()*e.config.avgSyncMilliseconds));var r=setTimeout((function(){e.schedules.splice(e.schedules.indexOf(r),1),t()}),n);return e.schedules.push(r),r}},p=function(e,t){var n=e.schedules.indexOf(t);n>-1&&e.schedules.splice(n,1),clearTimeout(t)},y=function(e,t,n,o){var a=i.toStr(t);if(function(e,t,n){e.messageHandlers.length||n("no onMessage() handler registered");try{e.messageHandlers.forEach((function(e){e(t,(function(){n.apply(null,arguments),n=function(){}}))}))}catch(e){n(e.stack)}}(e,a,(function(n){if(n)f(e,"Posting to server failed ["+n+"]"),e.pending=null,e.syncSchedule=h(e,(function(){g(e)}));else{var o=e.pending;if(e.pending=null,!o)throw new Error;r.assert(o.hash===t.hashOf),P(e,a,!0)?(e.timeOfLastSuccess=+new Date,e.lag=+new Date-o.timeSent):f(e,"Our message ["+t.hashOf+"] failed validation"),o.callback()}})),e.pending)throw new Error("there is already a pending message");-1===e.timeOfLastSuccess&&(e.timeOfLastSuccess=+new Date),e.pending={hash:t.hashOf,timeSent:+new Date,callback:function(){e.syncSchedule=h(e,(function(){g(e)}),0),n()}},r.PARANOIA&&_(e)},v=function(e){var t=e.onSettle;e.onSettle=[],t.forEach((function(t){try{t()}catch(t){d(e,"Error in onSettle handler ["+t.stack+"]")}}))},m=function(e){if(!e.mut.inverseOf)throw new Error;return e.mut.inverseOf},g=function(e,t){if(r.PARANOIA&&_(e),e.syncSchedule&&!e.pending){if(p(e,e.syncSchedule),e.syncSchedule=null,e.uncommitted=a.simplify(e.uncommitted,e.authDoc,e.config.operationSimplify),0===e.uncommitted.operations.length)return v(e),e.timeOfLastSuccess=+new Date,void(e.syncSchedule=h(e,(function(){g(e)})));var n=D(e,e.best)+1;if(n%e.config.checkpointInterval!=0){var o;o=e.setContentPatch?e.setContentPatch:i.create(i.PATCH,e.uncommitted,e.best.hashOf),y(e,o,(function(){e.setContentPatch&&(f(e,"initial Ack received ["+o.hashOf+"]"),e.setContentPatch=null)}))}else{var s=e.best;if(f(e,"Sending checkpoint (interval ["+e.config.checkpointInterval+"]) patch no ["+n+"]"),f(e,D(e,e.best)),!s||!s.content||!m(s.content))throw new Error;var c=a.createCheckpoint(e.authDoc,e.authDoc,m(s.content).parentHash),u=i.create(i.CHECKPOINT,c,s.hashOf);y(e,u,(function(){f(e,"Checkpoint sent and accepted")}))}}},E=function(e,t){r.assert(t.lastMsgHash),r.assert(t.hashOf),e.messages[t.hashOf]=t,(e.messagesByParent[t.lastMsgHash]=e.messagesByParent[t.lastMsgHash]||[]).push(t)},b=function(e,t){r.assert(t.lastMsgHash),r.assert(t.hashOf),delete e.messages[t.hashOf];var n=e.messagesByParent[t.lastMsgHash];r.assert(n.indexOf(t)>-1),n.splice(n.indexOf(t),1),0===n.length&&delete e.messagesByParent[t.lastMsgHash];var o=e.messagesByParent[t.hashOf];if(o)for(var a=0;a<o.length;a++)delete o[a].mut.parent},A=function(e,t){return t.mut.parent=t.mut.parent||e.messages[t.lastMsgHash]},_=function(e){r.assert("ChainPad"===e.type),r.assert("string"==typeof e.authDoc),a.check(e.uncommitted,e.authDoc.length);var t=a.apply(e.uncommitted,e.authDoc);if(r.assert(t.length===w(e)),""!==e.userInterfaceContent&&r.assert(t===e.userInterfaceContent),r.VALIDATE_ENTIRE_CHAIN_EACH_MSG){var n=e.authDoc,o=e.best;r.assert(m(o.content).parentHash===e.uncommitted.parentHash);var i=[];do{i.push(o),n=a.apply(m(o.content),n)}while(o=A(e,o));if(e.rootMessage.content.isCheckpoint){if(n!==e.rootMessage.content.operations[0].toInsert)throw new Error}else if(""!==n)throw new Error;for(;o=i.pop();)n=a.apply(o.content,n);r.assert(n===e.authDoc)}},w=function(e){return e.authDoc.length+a.lengthChange(e.uncommitted)},O=function(e,t,n){if(!t)return!1;for(;;){if(!n)return!1;if(t===n)return!0;n=A(e,n)}},D=function(e,t){if("number"==typeof t.mut.parentCount)return t.mut.parentCount;for(var n=[];"number"!=typeof t.mut.parentCount;t=A(e,t)){if(!t){if(t===e.rootMessage)throw new Error("root message does not have parent count");throw new Error("parentCount called on unlinked message")}n.unshift(t)}for(var r=t.mut.parentCount,o=0;o<n.length;o++)n[o].mut.parentCount=++r;return r},S=function(e,t,n){var o;if(r.assert(n),t)r.assert(n.parentHash===e.uncommitted.parentHash),e.uncommitted=a.merge(m(n),e.uncommitted);else if(e.uncommitted=a.transform(e.uncommitted,n,e.authDoc,e.config.patchTransformer),e.config.validateContent){o=a.apply(n,e.authDoc);var i=a.apply(e.uncommitted,o);e.config.validateContent(i)||(d(e,"Transformed patch is not valid"),e.uncommitted=a.create(s.hex_sha256(e.authDoc)))}r.assert(e.uncommitted.parentHash===m(n).parentHash),e.authDoc=o||a.apply(n,e.authDoc),r.PARANOIA&&(r.assert(e.uncommitted.parentHash===m(n).parentHash),r.assert(s.hex_sha256(e.authDoc)===e.uncommitted.parentHash),e.userInterfaceContent=a.apply(e.uncommitted,e.authDoc))},T=function(e,t){var n=t;return(e.messagesByParent[t.hashOf]||[]).forEach((function(o){r.assert(o.lastMsgHash===t.hashOf),o=T(e,o),D(e,o)>D(e,n)&&(n=o)})),n},C=function(e,t){t.operations.length&&(e.patchHandlers.forEach((function(e){e(t)})),e.changeHandlers.forEach((function(e){t.operations.forEach((function(t){e(t.offset,t.toRemove,t.toInsert)}))})))},x=function(e,t){try{return e.config.validateContent(t())}catch(t){d(e,"Error in content validator ["+t.stack+"]")}return!1},I=function(e,t,n){for(var r=A(e,t);r;r=A(e,r))if(!1===n(r))return},N=function(e,t){e.mut.inverseOf||((e.mut.inverseOf=a.invert(e,t)).mut.inverseOf=e)},P=function(e,t,n){r.PARANOIA&&_(e);var c=i.fromString(t);if(f(e,JSON.stringify([c.hashOf,c.content.operations])),e.messages[c.hashOf]){if(e.setContentPatch&&e.setContentPatch.hashOf===c.hashOf)e.setContentPatch=null;else{if(c.content.isCheckpoint)return f(e,"["+(n?"our":"their")+"] Checkpoint ["+c.hashOf+"] is already known"),!0;f(e,"Patch ["+c.hashOf+"] is already known")}r.PARANOIA&&_(e)}else if(!c.content.isCheckpoint||x(e,(function(){return c.content.operations[0].toInsert}))){if(E(e,c),!O(e,e.rootMessage,c)){if(c.content.isCheckpoint&&e.best.mut.isInitialMessage){f(e,"applying checkpoint ["+c.hashOf+"]");var u=a.apply(e.uncommitted,e.authDoc);r.assert(!r.PARANOIA||e.userInterfaceContent===u);var l=a.invert(e.uncommitted,e.authDoc);return a.addOperation(l,o.create(0,e.authDoc.length,c.content.operations[0].toInsert)),l=a.simplify(l,u,e.config.operationSimplify),c.mut.parentCount=0,e.rootMessage=e.best=c,e.authDoc=c.content.operations[0].toInsert,e.uncommitted=a.create(s.hex_sha256(e.authDoc)),C(e,l),r.PARANOIA&&(e.userInterfaceContent=e.authDoc),!0}return f(e,"Patch ["+c.hashOf+"] not connected to root (parent: ["+c.lastMsgHash+"])"),void(r.PARANOIA&&_(e))}(c=T(e,c)).mut.isFromMe=n;var d=c.content,h=[],p=e.best;if(!O(e,e.best,c)){var y=D(e,e.best),g=D(e,c);if(!(y<g||y===g&&r.strcmp(e.best.hashOf,c.hashOf)>0))return f(e,"Patch ["+c.hashOf+"] chain is ["+g+"] best chain is ["+y+"]"),r.PARANOIA&&_(e),!0;for(;p&&!O(e,p,c);)h.push(p),p=A(e,p);r.assert(p),f(e,"Patch ["+c.hashOf+"] better than best chain, switching")}var P=[],k=c;do{P.unshift(k),k=A(e,k),r.assert(k)}while(k!==p);var R=e.authDoc;h.forEach((function(e){R=a.apply(m(e.content),R)})),P.forEach((function(e,t){t!==P.length-1&&(N(e.content,R),R=a.apply(e.content,R))}));var M=e.best;if(P.length>1?(M=P[P.length-2],r.assert(M)):h.length&&(M=A(e,h[h.length-1]),r.assert(M)),r.assert(m(M.content).parentHash),r.assert(!r.PARANOIA||m(M.content).parentHash===s.hex_sha256(R)),m(M.content).parentHash===d.parentHash){if(d.isCheckpoint&&e.config.noPrune);else if(d.isCheckpoint){var F;if(I(e,c,(function(e){if(e.content.isCheckpoint){if(F)return F=e,!1;F=e}})),F&&F!==e.rootMessage){var L=D(e,F);if(e.config.strictCheckpointValidation&&L%e.config.checkpointInterval!=0){if(f(e,"checkpoint ["+c.hashOf+"] at invalid point ["+L+"]"),r.PARANOIA&&_(e),r.TESTING)throw new Error;return void b(e,c)}f(e,"checkpoint ["+c.hashOf+"]"),I(e,F,(function(t){f(e,"pruning ["+t.hashOf+"]"),b(e,t)})),e.rootMessage=F}}else{var H=a.simplify(d,R,e.config.operationSimplify);if(!a.equals(H,d)){if(f(e,"patch ["+c.hashOf+"] can be simplified"),r.PARANOIA&&_(e),r.TESTING)throw new Error;return void b(e,c)}if(!x(e,(function(){return a.apply(d,R)})))return void f(e,"Patch ["+c.hashOf+"] failed content validation")}N(d,R),e.uncommitted=a.simplify(e.uncommitted,e.authDoc,e.config.operationSimplify);var K=a.apply(e.uncommitted,e.authDoc);r.PARANOIA&&r.assert(K===e.userInterfaceContent);var j=a.invert(e.uncommitted,e.authDoc);if(h.forEach((function(t){f(e,"reverting ["+t.hashOf+"]"),t.mut.isFromMe&&f(e,"reverting patch 'from me' ["+JSON.stringify(t.content.operations)+"]"),j=a.merge(j,m(t.content)),function(e,t,n){S(e,t,m(n))}(e,t.mut.isFromMe,t.content)})),P.forEach((function(t){f(e,"applying ["+t.hashOf+"]"),j=a.merge(j,t.content),S(e,t.mut.isFromMe,t.content)})),j=a.merge(j,e.uncommitted),j=a.simplify(j,K,e.config.operationSimplify),e.best=c,r.PARANOIA){var U=a.apply(j,K);r.assert(e.userInterfaceContent.length===w(e)),r.assert(U===e.userInterfaceContent)}return C(e,j),e.uncommitted.operations.length||v(e),r.PARANOIA&&_(e),!0}if(f(e,"patch ["+c.hashOf+"] parentHash is not valid"),r.PARANOIA&&_(e),r.TESTING)throw new Error;b(e,c)}else f(e,"Checkpoint ["+c.hashOf+"] failed content validation")},k=function(e,t){return Object.freeze({type:"Block",hashOf:t.hashOf,lastMsgHash:t.lastMsgHash,isCheckpoint:!!t.content.isCheckpoint,isFromMe:t.mut&&t.mut.isFromMe,author:t.mut&&t.mut.author,serverHash:t.mut&&t.mut.serverHash,time:t.mut&&t.mut.time,getParent:function(){var n=A(e,t);if(n)return k(e,n)},getContent:function(){return function(e,t){for(var n=[t];n[0]!==e.rootMessage;){var o=A(e,n[0]);if(!o)return{error:"not connected to root",doc:void 0};n.unshift(o)}var i="";e.rootMessage.content.operations.length&&(r.assert(1===e.rootMessage.content.operations.length),i=e.rootMessage.content.operations[0].toInsert);for(var s=1;s<n.length;s++)i=a.apply(n[s].content,i);return{error:void 0,doc:i}}(e,t)},getPatch:function(){return a.clone(t.content)},getInversePatch:function(){return a.clone(m(t.content))},equals:function(e,n){return n?t===n:!(!e||"object"!=typeof e||"Block"!==e.type)&&e.equals(e,t)}})};e.exports.create=function(e){var t=function(e){var t=a.create(l);N(t,"");var n=i.create(i.PATCH,t,"0000000000000000000000000000000000000000000000000000000000000000");n.mut.parentCount=0,n.mut.isInitialMessage=!0;var r,s=n;if(""!==e.initialState){var c=a.create(l);a.addOperation(c,o.create(0,0,e.initialState)),N(c,""),(r=i.create(i.PATCH,c,n.hashOf)).mut.isInitialMessage=!0,s=r}var u={type:"ChainPad",authDoc:e.initialState,config:e,logLevel:e.logLevel,uncommitted:a.create(m(s.content).parentHash),patchHandlers:[],changeHandlers:[],messageHandlers:[],schedules:[],aborted:!1,syncSchedule:-2,userInterfaceContent:e.initialState,setContentPatch:r,pending:void 0,messages:{},messagesByParent:{},rootMessage:n,onSettle:[],userName:e.userName,best:s,lag:0,timeOfLastSuccess:-1};return E(u,n),r&&E(u,r),u}(function(e){if((e=e||{}).transformFunction)throw new Error("chainpad config transformFunction is nolonger used");return Object.freeze({initialState:e.initialState||"",checkpointInterval:e.checkpointInterval||50,avgSyncMilliseconds:e.avgSyncMilliseconds||300,strictCheckpointValidation:e.strictCheckpointValidation||!1,operationSimplify:e.operationSimplify||o.simplify,logLevel:"number"==typeof e.logLevel?e.logLevel:2,noPrune:e.noPrune,patchTransformer:e.patchTransformer||u,userName:e.userName||"anonymous",validateContent:e.validateContent||function(e){return!0},diffFunction:e.diffFunction||function(e,t){return c.diff(e,t)}})}(e)),n={onPatch:function(e){r.assert("function"==typeof e),t.patchHandlers.push(e)},patch:function(e,o,i){if("number"!=typeof e)!function(e,t){r.PARANOIA&&(_(e),r.assert(a.invert(e.uncommitted,e.authDoc).parentHash===t.parentHash),e.userInterfaceContent=a.apply(t,e.userInterfaceContent)),a.check(t,w(e)),e.uncommitted=a.merge(e.uncommitted,t)}(t,e);else{if("number"!=typeof o||"string"!=typeof i)throw new Error;n.change(e,o,i)}},onChange:function(e){r.assert("function"==typeof e),t.changeHandlers.push(e)},change:function(e,n,i){0===n&&""===i||function(e,t){r.PARANOIA&&(_(e),e.userInterfaceContent=o.apply(t,e.userInterfaceContent)),o.check(t,w(e)),a.addOperation(e.uncommitted,t)}(t,o.create(e,n,i))},contentUpdate:function(e){var n=t.config.diffFunction(t.authDoc,e),r=a.create(t.uncommitted.parentHash);Array.prototype.push.apply(r.operations,n),t.uncommitted=r},onMessage:function(e){r.assert("function"==typeof e),t.messageHandlers.push(e)},message:function(e){P(t,e,!1)},start:function(){t.aborted=!1,t.syncSchedule&&p(t,t.syncSchedule),t.pending=null,t.syncSchedule=h(t,(function(){g(t)}))},abort:function(){t.aborted=!0,t.schedules.forEach((function(e){clearTimeout(e)}))},sync:function(){g(t)},getAuthDoc:function(){return t.authDoc},getUserDoc:function(){return a.apply(t.uncommitted,t.authDoc)},getDepthOfState:function(e,n){return function(e,t,n){if(r.assert("string"==typeof e),0===(t=t||0)&&n.authDoc===e)return 0;var o=s.hex_sha256(e),a=n.best,i=0;do{if(i<t);else if(a.content.parentHash===o)return i+1;i++}while(a=A(n,a));return-1}(e,n,t)},onSettle:function(e){r.assert("function"==typeof e),t.onSettle.push(e)},getAuthBlock:function(){return k(t,t.best)},getBlockForHash:function(e){r.assert("string"==typeof e);var n=t.messages[e];if(n)return k(t,n)},getLag:function(){var e=!!t.pending,n=t.lag;return t.pending&&(n=+new Date-t.timeOfLastSuccess),{pending:e,lag:n,active:!t.aborted&&-2!==t.syncSchedule}},_:void 0};return n._=t,Object.freeze(n)},Object.freeze(e.exports)},"Operation.js":function(e,t,n){var r=n("./Common"),o=e.exports,a=o.check=function(e,t){if(r.assert("Operation"===e.type),!r.isUint(e.offset))throw new Error;if(!r.isUint(e.toRemove))throw new Error;if("string"!=typeof e.toInsert)throw new Error;if(e.toRemove<1&&e.toInsert.length<1)throw new Error;return r.assert("number"!=typeof t||e.offset+e.toRemove<=t),e},i=o.create=function(e,t,n){var o={type:"Operation",offset:e||0,toRemove:t||0,toInsert:n||""};return r.PARANOIA&&a(o),Object.freeze(o)};o.toObj=function(e){return r.PARANOIA&&a(e),[e.offset,e.toRemove,e.toInsert]},o.fromObj=function(e){return r.assert(Array.isArray(e)&&3===e.length),i(e[0],e[1],e[2])};var s=o.apply=function(e,t){return r.PARANOIA&&(r.assert("string"==typeof t),a(e,t.length)),t.substring(0,e.offset)+e.toInsert+t.substring(e.offset+e.toRemove)};o.applyMulti=function(e,t){for(var n=e.length-1;n>=0;n--)t=s(e[n],t);return t};var c=o.invert=function(e,t){return r.PARANOIA&&(a(e),r.assert("string"==typeof t),r.assert(e.offset+e.toRemove<=t.length)),i(e.offset,e.toInsert.length,(" "+t.substring(e.offset,e.offset+e.toRemove)).slice(1))},u=/[\uD800-\uDBFF]|[\uDC00-\uDFFF]/,l=o.hasSurrogate=function(e){return u.test(e)};o.simplify=function(e,t){r.PARANOIA&&(a(e),r.assert("string"==typeof t),r.assert(e.offset+e.toRemove<=t.length));for(var n=c(e,t),o=Math.min(e.toInsert.length,n.toInsert.length),s=0;s<o&&n.toInsert[s]===e.toInsert[s];){if(l(n.toInsert[s])||l(e.toInsert[s])){if(e.toInsert[s+1]!==n.toInsert[s+1])break;s++}s++}var u=e.offset+s,f=e.toRemove-s,d=e.toInsert.substring(s),h=n.toInsert.substring(s);if(h.length===d.length){for(s=h.length-1;s>=0&&h[s]===d[s];s--);d=d.substring(0,s+1),f=s+1}return 0===f&&0===d.length?null:i(u,f,d)},o.equals=function(e,t){return e.toRemove===t.toRemove&&e.toInsert===t.toInsert&&e.offset===t.offset},o.lengthChange=function(e){return r.PARANOIA&&a(e),e.toInsert.length-e.toRemove},o.merge=function(e,t){r.PARANOIA&&(a(t),a(e));var n=e.offset,o=e.toRemove,s=e.toInsert,c=t.offset,u=t.toRemove,l=t.toInsert,f=c-n;if(u>0){var d=s;s=s.substring(0,f)+s.substring(f+u),(u-=d.length-s.length)<0&&(u=0),o+=u,u=0}if(f<0)n+=f,s=l+s;else if(s.length===f)s+=l;else{if(!(s.length>f))throw new Error("should never happen\n"+JSON.stringify([e,t],null," "));s=s.substring(0,f)+l+s.substring(f)}return""===s&&0===o?null:i(n,o,s)},o.shouldMerge=function(e,t){return r.PARANOIA&&(a(e),a(t)),t.offset<e.offset?e.offset<=t.offset+t.toRemove:t.offset<=e.offset+e.toInsert.length},o.rebase=function(e,t){return r.PARANOIA&&(a(e),a(t)),t.offset<e.offset?t:i(t.offset+e.toRemove-e.toInsert.length,t.toRemove,t.toInsert)},o.random=function(e){r.assert(r.isUint(e));var t=Math.floor(1e8*Math.random()%e)||0,n=Math.floor(1e8*Math.random()%(e-t))||0,o="";do{o=r.randomASCII(Math.floor(20*Math.random()))}while(0===n&&""===o);return i(t,n,o)},Object.freeze(e.exports)},"sha256/hash.js":function(e,t,n){var r=n("./utils.js");e.exports.hash_reset=function(){return this.result=null,this.pos=0,this.len=0,this.asm.reset(),this},e.exports.hash_process=function(e){if(null!==this.result)throw new IllegalStateError("state must be reset before processing new data");if(r.is_string(e)&&(e=r.string_to_bytes(e)),r.is_buffer(e)&&(e=new Uint8Array(e)),!r.is_bytes(e))throw new TypeError("data isn't of expected type");for(var t=this.asm,n=this.heap,o=this.pos,a=this.len,i=0,s=e.length,c=0;s>0;)a+=c=r._heap_write(n,o+a,e,i,s),i+=c,s-=c,o+=c=t.process(o,a),(a-=c)||(o=0);return this.pos=o,this.len=a,this},e.exports.hash_finish=function(){if(null!==this.result)throw new IllegalStateError("state must be reset before processing new data");return this.asm.finish(this.pos,this.len,0),this.result=new Uint8Array(this.HASH_SIZE),this.result.set(this.heap.subarray(0,this.HASH_SIZE)),this.pos=0,this.len=0,this}},"sha256/utils.js":function(e,t,n){var r=e.exports.string_to_bytes=function(e,t){t=!!t;for(var n=e.length,r=new Uint8Array(t?4*n:n),o=0,a=0;o<n;o++){var i=e.charCodeAt(o);if(t&&55296<=i&&i<=56319){if(++o>=n)throw new Error("Malformed string, low surrogate expected at position "+o);i=(55296^i)<<10|65536|56320^e.charCodeAt(o)}else if(!t&&i>>>8)throw new Error("Wide characters are not allowed.");!t||i<=127?r[a++]=i:i<=2047?(r[a++]=192|i>>6,r[a++]=128|63&i):i<=65535?(r[a++]=224|i>>12,r[a++]=128|i>>6&63,r[a++]=128|63&i):(r[a++]=240|i>>18,r[a++]=128|i>>12&63,r[a++]=128|i>>6&63,r[a++]=128|63&i)}return r.subarray(0,a)};e.exports.hex_to_bytes=function(e){var t=e.length;1&t&&(e="0"+e,t++);for(var n=new Uint8Array(t>>1),r=0;r<t;r+=2)n[r>>1]=parseInt(e.substr(r,2),16);return n},e.exports.base64_to_bytes=function(e){return r(atob(e))};var o=e.exports.bytes_to_string=function(e,t){t=!!t;for(var n=e.length,r=new Array(n),o=0,a=0;o<n;o++){var i=e[o];if(!t||i<128)r[a++]=i;else if(i>=192&&i<224&&o+1<n)r[a++]=(31&i)<<6|63&e[++o];else if(i>=224&&i<240&&o+2<n)r[a++]=(15&i)<<12|(63&e[++o])<<6|63&e[++o];else{if(!(i>=240&&i<248&&o+3<n))throw new Error("Malformed UTF8 character at byte offset "+o);var s=(7&i)<<18|(63&e[++o])<<12|(63&e[++o])<<6|63&e[++o];s<=65535?r[a++]=s:(s^=65536,r[a++]=55296|s>>10,r[a++]=56320|1023&s)}}for(var c="",u=16384,l=0;l<a;l+=u)c+=String.fromCharCode.apply(String,r.slice(l,l+u<=a?l+u:a));return c};e.exports.bytes_to_hex=function(e){for(var t="",n=0;n<e.length;n++){var r=(255&e[n]).toString(16);r.length<2&&(t+="0"),t+=r}return t},e.exports.bytes_to_base64=function(e){return btoa(o(e))},e.exports.pow2_ceil=function(e){return e-=1,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e+=1},e.exports.is_number=function(e){return"number"==typeof e},e.exports.is_string=function(e){return"string"==typeof e},e.exports.is_buffer=function(e){return e instanceof ArrayBuffer},e.exports.is_bytes=function(e){return e instanceof Uint8Array},e.exports.is_typed_array=function(e){return e instanceof Int8Array||e instanceof Uint8Array||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array||e instanceof Float64Array},e.exports._heap_init=function(e,t){var n=t.heap,r=n?n.byteLength:t.heapSize||65536;if(4095&r||r<=0)throw new Error("heap size must be a positive integer and a multiple of 4096");return n=n||new e(new ArrayBuffer(r))},e.exports._heap_write=function(e,t,n,r,o){var a=e.length-t,i=a<o?a:o;return e.set(n.subarray(r,r+i),t),i}},"sha256/sha256.js":function(e,t,n){var r=n("./utils.js"),o=n("./hash.js"),a=n("./sha256.asm.js");function i(e){e=e||{},this.heap=r._heap_init(Uint8Array,e),this.asm=e.asm||a.sha256_asm({Uint8Array},null,this.heap.buffer),this.BLOCK_SIZE=64,this.HASH_SIZE=32,this.reset()}i.BLOCK_SIZE=64,i.HASH_SIZE=32;var s=i.prototype;s.reset=o.hash_reset,s.process=o.hash_process,s.finish=o.hash_finish;var c=null;e.exports.get_sha256_instance=function(){return null===c&&(c=new i({heapSize:1048576})),c},e.exports.sha256_constructor=i},"sha256/exports.js":function(e,t,n){var r=n("./sha256.js"),o=n("./utils.js");function a(e){if(void 0===e)throw new SyntaxError("data required");return r.get_sha256_instance().reset().process(e).finish().result}r.sha256_constructor.bytes=a,r.sha256_constructor.hex=function(e){var t=a(e);return o.bytes_to_hex(t)},r.sha256_constructor.base64=function(e){var t=a(e);return o.bytes_to_base64(t)},e.exports=r.sha256_constructor},"sha256/sha256.asm.js":function(e,t,n){e.exports.sha256_asm=function(e,t,n){"use asm";var r=0,o=0,a=0,i=0,s=0,c=0,u=0,l=0,f=0,d=0;var h=0,p=0,y=0,v=0,m=0,g=0,E=0,b=0,A=0,_=0,w=0,O=0,D=0,S=0,T=0,C=0;var x=new e.Uint8Array(n);function I(e,t,n,f,d,h,p,y,v,m,g,E,b,A,_,w){e=e|0;t=t|0;n=n|0;f=f|0;d=d|0;h=h|0;p=p|0;y=y|0;v=v|0;m=m|0;g=g|0;E=E|0;b=b|0;A=A|0;_=_|0;w=w|0;var O=0,D=0,S=0,T=0,C=0,x=0,I=0,N=0,P=0;O=r;D=o;S=a;T=i;C=s;x=c;I=u;N=l;P=e+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x428a2f98|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=t+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x71374491|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=n+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xb5c0fbcf|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=f+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xe9b5dba5|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=d+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x3956c25b|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=h+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x59f111f1|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=p+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x923f82a4|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=y+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xab1c5ed5|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=v+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xd807aa98|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=m+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x12835b01|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=g+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x243185be|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=E+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x550c7dc3|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=b+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x72be5d74|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=A+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x80deb1fe|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=_+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x9bdc06a7|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;P=w+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xc19bf174|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;e=P=(t>>>7^t>>>18^t>>>3^t<<25^t<<14)+(_>>>17^_>>>19^_>>>10^_<<15^_<<13)+e+m|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xe49b69c1|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;t=P=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(w>>>17^w>>>19^w>>>10^w<<15^w<<13)+t+g|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xefbe4786|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;n=P=(f>>>7^f>>>18^f>>>3^f<<25^f<<14)+(e>>>17^e>>>19^e>>>10^e<<15^e<<13)+n+E|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x0fc19dc6|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;f=P=(d>>>7^d>>>18^d>>>3^d<<25^d<<14)+(t>>>17^t>>>19^t>>>10^t<<15^t<<13)+f+b|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x240ca1cc|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;d=P=(h>>>7^h>>>18^h>>>3^h<<25^h<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+d+A|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x2de92c6f|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;h=P=(p>>>7^p>>>18^p>>>3^p<<25^p<<14)+(f>>>17^f>>>19^f>>>10^f<<15^f<<13)+h+_|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x4a7484aa|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;p=P=(y>>>7^y>>>18^y>>>3^y<<25^y<<14)+(d>>>17^d>>>19^d>>>10^d<<15^d<<13)+p+w|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x5cb0a9dc|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;y=P=(v>>>7^v>>>18^v>>>3^v<<25^v<<14)+(h>>>17^h>>>19^h>>>10^h<<15^h<<13)+y+e|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x76f988da|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;v=P=(m>>>7^m>>>18^m>>>3^m<<25^m<<14)+(p>>>17^p>>>19^p>>>10^p<<15^p<<13)+v+t|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x983e5152|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;m=P=(g>>>7^g>>>18^g>>>3^g<<25^g<<14)+(y>>>17^y>>>19^y>>>10^y<<15^y<<13)+m+n|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xa831c66d|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;g=P=(E>>>7^E>>>18^E>>>3^E<<25^E<<14)+(v>>>17^v>>>19^v>>>10^v<<15^v<<13)+g+f|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xb00327c8|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;E=P=(b>>>7^b>>>18^b>>>3^b<<25^b<<14)+(m>>>17^m>>>19^m>>>10^m<<15^m<<13)+E+d|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xbf597fc7|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;b=P=(A>>>7^A>>>18^A>>>3^A<<25^A<<14)+(g>>>17^g>>>19^g>>>10^g<<15^g<<13)+b+h|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xc6e00bf3|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;A=P=(_>>>7^_>>>18^_>>>3^_<<25^_<<14)+(E>>>17^E>>>19^E>>>10^E<<15^E<<13)+A+p|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xd5a79147|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;_=P=(w>>>7^w>>>18^w>>>3^w<<25^w<<14)+(b>>>17^b>>>19^b>>>10^b<<15^b<<13)+_+y|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x06ca6351|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;w=P=(e>>>7^e>>>18^e>>>3^e<<25^e<<14)+(A>>>17^A>>>19^A>>>10^A<<15^A<<13)+w+v|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x14292967|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;e=P=(t>>>7^t>>>18^t>>>3^t<<25^t<<14)+(_>>>17^_>>>19^_>>>10^_<<15^_<<13)+e+m|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x27b70a85|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;t=P=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(w>>>17^w>>>19^w>>>10^w<<15^w<<13)+t+g|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x2e1b2138|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;n=P=(f>>>7^f>>>18^f>>>3^f<<25^f<<14)+(e>>>17^e>>>19^e>>>10^e<<15^e<<13)+n+E|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x4d2c6dfc|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;f=P=(d>>>7^d>>>18^d>>>3^d<<25^d<<14)+(t>>>17^t>>>19^t>>>10^t<<15^t<<13)+f+b|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x53380d13|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;d=P=(h>>>7^h>>>18^h>>>3^h<<25^h<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+d+A|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x650a7354|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;h=P=(p>>>7^p>>>18^p>>>3^p<<25^p<<14)+(f>>>17^f>>>19^f>>>10^f<<15^f<<13)+h+_|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x766a0abb|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;p=P=(y>>>7^y>>>18^y>>>3^y<<25^y<<14)+(d>>>17^d>>>19^d>>>10^d<<15^d<<13)+p+w|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x81c2c92e|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;y=P=(v>>>7^v>>>18^v>>>3^v<<25^v<<14)+(h>>>17^h>>>19^h>>>10^h<<15^h<<13)+y+e|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x92722c85|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;v=P=(m>>>7^m>>>18^m>>>3^m<<25^m<<14)+(p>>>17^p>>>19^p>>>10^p<<15^p<<13)+v+t|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xa2bfe8a1|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;m=P=(g>>>7^g>>>18^g>>>3^g<<25^g<<14)+(y>>>17^y>>>19^y>>>10^y<<15^y<<13)+m+n|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xa81a664b|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;g=P=(E>>>7^E>>>18^E>>>3^E<<25^E<<14)+(v>>>17^v>>>19^v>>>10^v<<15^v<<13)+g+f|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xc24b8b70|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;E=P=(b>>>7^b>>>18^b>>>3^b<<25^b<<14)+(m>>>17^m>>>19^m>>>10^m<<15^m<<13)+E+d|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xc76c51a3|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;b=P=(A>>>7^A>>>18^A>>>3^A<<25^A<<14)+(g>>>17^g>>>19^g>>>10^g<<15^g<<13)+b+h|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xd192e819|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;A=P=(_>>>7^_>>>18^_>>>3^_<<25^_<<14)+(E>>>17^E>>>19^E>>>10^E<<15^E<<13)+A+p|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xd6990624|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;_=P=(w>>>7^w>>>18^w>>>3^w<<25^w<<14)+(b>>>17^b>>>19^b>>>10^b<<15^b<<13)+_+y|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xf40e3585|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;w=P=(e>>>7^e>>>18^e>>>3^e<<25^e<<14)+(A>>>17^A>>>19^A>>>10^A<<15^A<<13)+w+v|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x106aa070|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;e=P=(t>>>7^t>>>18^t>>>3^t<<25^t<<14)+(_>>>17^_>>>19^_>>>10^_<<15^_<<13)+e+m|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x19a4c116|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;t=P=(n>>>7^n>>>18^n>>>3^n<<25^n<<14)+(w>>>17^w>>>19^w>>>10^w<<15^w<<13)+t+g|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x1e376c08|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;n=P=(f>>>7^f>>>18^f>>>3^f<<25^f<<14)+(e>>>17^e>>>19^e>>>10^e<<15^e<<13)+n+E|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x2748774c|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;f=P=(d>>>7^d>>>18^d>>>3^d<<25^d<<14)+(t>>>17^t>>>19^t>>>10^t<<15^t<<13)+f+b|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x34b0bcb5|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;d=P=(h>>>7^h>>>18^h>>>3^h<<25^h<<14)+(n>>>17^n>>>19^n>>>10^n<<15^n<<13)+d+A|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x391c0cb3|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;h=P=(p>>>7^p>>>18^p>>>3^p<<25^p<<14)+(f>>>17^f>>>19^f>>>10^f<<15^f<<13)+h+_|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x4ed8aa4a|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;p=P=(y>>>7^y>>>18^y>>>3^y<<25^y<<14)+(d>>>17^d>>>19^d>>>10^d<<15^d<<13)+p+w|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x5b9cca4f|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;y=P=(v>>>7^v>>>18^v>>>3^v<<25^v<<14)+(h>>>17^h>>>19^h>>>10^h<<15^h<<13)+y+e|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x682e6ff3|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;v=P=(m>>>7^m>>>18^m>>>3^m<<25^m<<14)+(p>>>17^p>>>19^p>>>10^p<<15^p<<13)+v+t|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x748f82ee|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;m=P=(g>>>7^g>>>18^g>>>3^g<<25^g<<14)+(y>>>17^y>>>19^y>>>10^y<<15^y<<13)+m+n|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x78a5636f|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;g=P=(E>>>7^E>>>18^E>>>3^E<<25^E<<14)+(v>>>17^v>>>19^v>>>10^v<<15^v<<13)+g+f|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x84c87814|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;E=P=(b>>>7^b>>>18^b>>>3^b<<25^b<<14)+(m>>>17^m>>>19^m>>>10^m<<15^m<<13)+E+d|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x8cc70208|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;b=P=(A>>>7^A>>>18^A>>>3^A<<25^A<<14)+(g>>>17^g>>>19^g>>>10^g<<15^g<<13)+b+h|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0x90befffa|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;A=P=(_>>>7^_>>>18^_>>>3^_<<25^_<<14)+(E>>>17^E>>>19^E>>>10^E<<15^E<<13)+A+p|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xa4506ceb|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;_=P=(w>>>7^w>>>18^w>>>3^w<<25^w<<14)+(b>>>17^b>>>19^b>>>10^b<<15^b<<13)+_+y|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xbef9a3f7|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;w=P=(e>>>7^e>>>18^e>>>3^e<<25^e<<14)+(A>>>17^A>>>19^A>>>10^A<<15^A<<13)+w+v|0;P=P+N+(C>>>6^C>>>11^C>>>25^C<<26^C<<21^C<<7)+(I^C&(x^I))+0xc67178f2|0;N=I;I=x;x=C;C=T+P|0;T=S;S=D;D=O;O=P+(D&S^T&(D^S))+(D>>>2^D>>>13^D>>>22^D<<30^D<<19^D<<10)|0;r=r+O|0;o=o+D|0;a=a+S|0;i=i+T|0;s=s+C|0;c=c+x|0;u=u+I|0;l=l+N|0}function N(e){e=e|0;I(x[e|0]<<24|x[e|1]<<16|x[e|2]<<8|x[e|3],x[e|4]<<24|x[e|5]<<16|x[e|6]<<8|x[e|7],x[e|8]<<24|x[e|9]<<16|x[e|10]<<8|x[e|11],x[e|12]<<24|x[e|13]<<16|x[e|14]<<8|x[e|15],x[e|16]<<24|x[e|17]<<16|x[e|18]<<8|x[e|19],x[e|20]<<24|x[e|21]<<16|x[e|22]<<8|x[e|23],x[e|24]<<24|x[e|25]<<16|x[e|26]<<8|x[e|27],x[e|28]<<24|x[e|29]<<16|x[e|30]<<8|x[e|31],x[e|32]<<24|x[e|33]<<16|x[e|34]<<8|x[e|35],x[e|36]<<24|x[e|37]<<16|x[e|38]<<8|x[e|39],x[e|40]<<24|x[e|41]<<16|x[e|42]<<8|x[e|43],x[e|44]<<24|x[e|45]<<16|x[e|46]<<8|x[e|47],x[e|48]<<24|x[e|49]<<16|x[e|50]<<8|x[e|51],x[e|52]<<24|x[e|53]<<16|x[e|54]<<8|x[e|55],x[e|56]<<24|x[e|57]<<16|x[e|58]<<8|x[e|59],x[e|60]<<24|x[e|61]<<16|x[e|62]<<8|x[e|63])}function P(e){e=e|0;x[e|0]=r>>>24;x[e|1]=r>>>16&255;x[e|2]=r>>>8&255;x[e|3]=r&255;x[e|4]=o>>>24;x[e|5]=o>>>16&255;x[e|6]=o>>>8&255;x[e|7]=o&255;x[e|8]=a>>>24;x[e|9]=a>>>16&255;x[e|10]=a>>>8&255;x[e|11]=a&255;x[e|12]=i>>>24;x[e|13]=i>>>16&255;x[e|14]=i>>>8&255;x[e|15]=i&255;x[e|16]=s>>>24;x[e|17]=s>>>16&255;x[e|18]=s>>>8&255;x[e|19]=s&255;x[e|20]=c>>>24;x[e|21]=c>>>16&255;x[e|22]=c>>>8&255;x[e|23]=c&255;x[e|24]=u>>>24;x[e|25]=u>>>16&255;x[e|26]=u>>>8&255;x[e|27]=u&255;x[e|28]=l>>>24;x[e|29]=l>>>16&255;x[e|30]=l>>>8&255;x[e|31]=l&255}function k(){r=0x6a09e667;o=0xbb67ae85;a=0x3c6ef372;i=0xa54ff53a;s=0x510e527f;c=0x9b05688c;u=0x1f83d9ab;l=0x5be0cd19;f=d=0}function R(e,t,n,h,p,y,v,m,g,E){e=e|0;t=t|0;n=n|0;h=h|0;p=p|0;y=y|0;v=v|0;m=m|0;g=g|0;E=E|0;r=e;o=t;a=n;i=h;s=p;c=y;u=v;l=m;f=g;d=E}function M(e,t){e=e|0;t=t|0;var n=0;if(e&63)return-1;while((t|0)>=64){N(e);e=e+64|0;t=t-64|0;n=n+64|0}f=f+n|0;if(f>>>0<n>>>0)d=d+1|0;return n|0}function F(e,t,n){e=e|0;t=t|0;n=n|0;var r=0,o=0;if(e&63)return-1;if(~n)if(n&31)return-1;if((t|0)>=64){r=M(e,t)|0;if((r|0)==-1)return-1;e=e+r|0;t=t-r|0}r=r+t|0;f=f+t|0;if(f>>>0<t>>>0)d=d+1|0;x[e|t]=0x80;if((t|0)>=56){for(o=t+1|0;(o|0)<64;o=o+1|0)x[e|o]=0x00;N(e);t=0;x[e|0]=0}for(o=t+1|0;(o|0)<59;o=o+1|0)x[e|o]=0;x[e|56]=d>>>21&255;x[e|57]=d>>>13&255;x[e|58]=d>>>5&255;x[e|59]=d<<3&255|f>>>29;x[e|60]=f>>>21&255;x[e|61]=f>>>13&255;x[e|62]=f>>>5&255;x[e|63]=f<<3&255;N(e);if(~n)P(n);return r|0}function L(){r=h;o=p;a=y;i=v;s=m;c=g;u=E;l=b;f=64;d=0}function H(){r=A;o=_;a=w;i=O;s=D;c=S;u=T;l=C;f=64;d=0}function K(e,t,n,x,N,P,R,M,F,L,H,K,j,U,B,V){e=e|0;t=t|0;n=n|0;x=x|0;N=N|0;P=P|0;R=R|0;M=M|0;F=F|0;L=L|0;H=H|0;K=K|0;j=j|0;U=U|0;B=B|0;V=V|0;k();I(e^0x5c5c5c5c,t^0x5c5c5c5c,n^0x5c5c5c5c,x^0x5c5c5c5c,N^0x5c5c5c5c,P^0x5c5c5c5c,R^0x5c5c5c5c,M^0x5c5c5c5c,F^0x5c5c5c5c,L^0x5c5c5c5c,H^0x5c5c5c5c,K^0x5c5c5c5c,j^0x5c5c5c5c,U^0x5c5c5c5c,B^0x5c5c5c5c,V^0x5c5c5c5c);A=r;_=o;w=a;O=i;D=s;S=c;T=u;C=l;k();I(e^0x36363636,t^0x36363636,n^0x36363636,x^0x36363636,N^0x36363636,P^0x36363636,R^0x36363636,M^0x36363636,F^0x36363636,L^0x36363636,H^0x36363636,K^0x36363636,j^0x36363636,U^0x36363636,B^0x36363636,V^0x36363636);h=r;p=o;y=a;v=i;m=s;g=c;E=u;b=l;f=64;d=0}function j(e,t,n){e=e|0;t=t|0;n=n|0;var f=0,d=0,h=0,p=0,y=0,v=0,m=0,g=0,E=0;if(e&63)return-1;if(~n)if(n&31)return-1;E=F(e,t,-1)|0;f=r,d=o,h=a,p=i,y=s,v=c,m=u,g=l;H();I(f,d,h,p,y,v,m,g,0x80000000,0,0,0,0,0,0,768);if(~n)P(n);return E|0}function U(e,t,n,f,d){e=e|0;t=t|0;n=n|0;f=f|0;d=d|0;var h=0,p=0,y=0,v=0,m=0,g=0,E=0,b=0,A=0,_=0,w=0,O=0,D=0,S=0,T=0,C=0;if(e&63)return-1;if(~d)if(d&31)return-1;x[e+t|0]=n>>>24;x[e+t+1|0]=n>>>16&255;x[e+t+2|0]=n>>>8&255;x[e+t+3|0]=n&255;j(e,t+4|0,-1)|0;h=A=r,p=_=o,y=w=a,v=O=i,m=D=s,g=S=c,E=T=u,b=C=l;f=f-1|0;while((f|0)>0){L();I(A,_,w,O,D,S,T,C,0x80000000,0,0,0,0,0,0,768);A=r,_=o,w=a,O=i,D=s,S=c,T=u,C=l;H();I(A,_,w,O,D,S,T,C,0x80000000,0,0,0,0,0,0,768);A=r,_=o,w=a,O=i,D=s,S=c,T=u,C=l;h=h^r;p=p^o;y=y^a;v=v^i;m=m^s;g=g^c;E=E^u;b=b^l;f=f-1|0}r=h;o=p;a=y;i=v;s=m;c=g;u=E;l=b;if(~d)P(d);return 0}return{reset:k,init:R,process:M,finish:F,hmac_reset:L,hmac_init:K,hmac_finish:j,pbkdf2_generate_block:U}}},"transform/TextTransformer.js":function(e,t,n){var r=n("../Operation"),o=n("../Common"),a=function(e,t){o.PARANOIA&&(r.check(e),r.check(t));var n=function(e,t){if(e.offset>t.offset){if(e.offset>t.offset+t.toRemove)return r.create(e.offset-t.toRemove+t.toInsert.length,e.toRemove,e.toInsert);var n=e.toRemove-(t.offset+t.toRemove-e.offset);return n<0&&(n=0),0===n&&0===e.toInsert.length?null:r.create(t.offset+t.toInsert.length,n,e.toInsert)}if(e.offset+e.toRemove<t.offset)return e;var o=t.offset-e.offset;return 0===o&&0===e.toInsert.length?null:r.create(e.offset,o,e.toInsert)}(e,t);return o.PARANOIA&&n&&r.check(n),n};e.exports=function(e,t,n){var i,s=n;for(i=t.length-1;i>=0;i--)s=r.apply(t[i],s);var c=[];for(i=e.length-1;i>=0;i--){for(var u=e[i],l=t.length-1;l>=0;l--){try{u=a(u,t[l])}catch(e){return console.error("The pluggable transform function threw an error, failing operational transformation"),console.error(e.stack),[]}if(!u)break}u&&(o.PARANOIA&&r.check(u,s.length),c.unshift(u))}return c}},"transform/NaiveJSONTransformer.js":function(e,t,n){var r=n("./TextTransformer"),o=n("../Operation"),a=n("../Common");e.exports=function(e,t,n){var i,s,c,u=a.global.REALTIME_DEBUG=a.global.REALTIME_DEBUG||{};try{i=r(e,t,n),s=o.applyMulti(t,n),c=o.applyMulti(i,s);try{return JSON.parse(c),i}catch(r){console.error(r),u.ot_parseError={type:"resultParseError",resultOps:i,toTransform:e,transformBy:t,text1:n,text2:s,text3:c,error:r},console.log("Debugging info available at `window.REALTIME_DEBUG.ot_parseError`")}}catch(r){console.error(r),u.ot_applyError={type:"resultParseError",resultOps:i,toTransform:e,transformBy:t,text1:n,text2:s,text3:c,error:r},console.log("Debugging info available at `window.REALTIME_DEBUG.ot_applyError`")}return[]}},"transform/SmartJSONTransformer.js":function(e,t,n){var r,o,a,i=n("json.sortify"),s=n("../Diff"),c=n("../Operation"),u=n("./TextTransformer"),l=function(e){return null===e?"null":(t=e,"[object Array]"===Object.prototype.toString.call(t)?"array":typeof e);var t},f=function(e,t){for(var n=t.length,r=0;r<n;r++){if(void 0===e[t[r]])return;e=e[t[r]]}return e},d=function(e,t){var n=l(e);if(n!==l(t))return!1;if("object"===n){var r=Object.keys(e),o=Object.keys(t);return r.length===o.length&&!r.some((function(n){return!d(e[n],t[n])}))&&!o.some((function(t){return!(t in e)}))}return"array"===n?e.length===t.length&&!e.some((function(e,n){return!d(e,t[n])})):e===t},h=function(e,t,n,r,o){if("replace"===e)return{type:"replace",path:t,value:n,prev:r};if("splice"===e){if("number"!=typeof r)throw new Error;if("number"!=typeof o)throw new Error;return{type:"splice",path:t,value:n,offset:r,removals:o}}if("remove"!==e)throw new Error("expected a removal");return{type:"remove",path:t,value:n}},p=function(e,t,n,r){e.push(h("replace",t,n,r))},y=function(e,t,n,r,o){e.push(h("splice",t,n,r,o))},v=function(e,t){return!e.some((function(e,n){return e!==t[n]}))},m=(o={},a=1,(r=["replace","remove","splice"]).forEach((function(e){return o[e]={},r.forEach((function(t){o[e][t]=a++}))})),o),g=function(e,t,n){if("array"!==l(e)||"array"!==l(t))throw new Error("[resolve] expected two arrays");return t=t.filter((function(t){return!e.some((function(e){if("remove"===e.type&&v(e.path,t.path)&&t.path.length-e.path.length>1)return!0}))&&("splice"!==t.type||!e.some((function(e){if("splice"===e.type&&v(e.path,t.path)&&e.path.length-t.path.length<0){if(!e.removals)return;for(var n=e.offset,r=e.offset+e.removals;n<r;n++)if(n===t.path[e.path.length])return!0}})))&&(!e.some((function(e){return"remove"===t.type&&d(e.path,t.path)}))||void 0)})).filter((function(t){return!e.some((function(e){if("replace"===t.type&&"replace"===e.type&&d(e.path,t.path))return"string"!=typeof e.value||"string"!=typeof t.value||!n||e.prev!==t.prev||e.value===t.value||n(e,t,m.replace.replace)}))})).map((function(t){return e.forEach((function(e){if("splice"===e.type){if(d(e.path,t.path)){if("splice"===t.type){if(t.offset>e.offset+t.removals)return void(t.offset+=e.value.length-e.removals);if(t.offset<e.offset)return void(t.removals=Math.max(e.offset-t.offset,0));t.removals=Math.max(t.removals-(t.offset+e.removals-t.offset),0),t.offset+=e.value.length-e.removals}return}if(v(e.path,t.path)){var n=e.path.length;"number"==typeof t.path[n]&&e.offset<=t.path[n]&&(t.path[n]+=e.value.length-e.removals)}}})),t})),t},E=function(e,t,n,r){var o=Object.keys(e),a=Object.keys(t);a.forEach((function(a){var i=l(t[a]),s=e[a],c=n.concat(a);if(-1!==o.indexOf(a)){var u=l(s);if(u===i)"object"===u?E(e[a],t[a],c,r):"array"===u?b(e[a],t[a],c,r):e[a]!==t[a]&&p(r,c,t[a],s);else{if(console.log("type changed from [%s] to [%s]",u,i),"undefined"===i)throw new Error("first pass should never reveal undefined keys");p(r,c,t[a],s)}}else{if("undefined"===i)throw new Error("undefined type has key. this shouldn't happen?");if(s)throw new Error("no such key existed in b, so 'old' should be falsey");p(r,c,t[a],s)}})),o.forEach((function(o){-1!==a.indexOf(o)&&"undefined"!==l(t[o])||function(e,t,n){e.push(h("remove",t,n))}(r,n.concat(o),e[o])}))},b=function(e,t,n,r){var o=e.slice(0);if(0===o.length)y(r,n,t,0,0);else if(function(e,t){if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(l(e[n])!==l(t[n]))return!1;return!0}(o,t))o.forEach((function(e,o){var a=t[o];if(a!==e){var i=e,s=n.concat(o);switch(l(e)){case"undefined":throw new Error("existing key had type `undefined`. this should never happen");case"object":E(e,a,s,r);break;case"array":b(e,a,s,r);break;default:p(r,s,a,i)}}}));else{for(var a=0,i=0;a<o.length&&d(o[a],t[a]);)a++;for(;d(o[o.length-1-i],t[t.length-1-i])&&i+a<o.length&&i+a<t.length;)i++;var s=o.length-a-i,c=[];t.length!==a+i&&(c=t.slice(a,t.length-i)),y(r,n,c,a,s)}},A=function(e,t){var n=[],r=l(e),o=l(t);if(r!==o)throw new Error("Can't merge two objects of differing types");if("array"===o)b(e,t,[],n);else{if("object"!==o)throw new Error("unsupported datatype"+o);E(e,t,[],n)}return n},_=function(e,t){return t.forEach((function(t){!function(e,t){var n,r,o;switch(t.type){case"replace":r=t.path[t.path.length-1],n=t.path.slice(0,t.path.length-1);var a=f(e,n);if(!a)throw new Error("cannot apply change to non-existent element");a[r]=t.value;break;case"splice":var i=f(e,t.path);if(!i)throw console.error("[applyOp] expected path [%s] to exist in object",t.path.join(",")),new Error("Path did not exist");if("array"!==l(i))throw new Error("Can't splice non-array");Array.prototype.splice.apply(i,[t.offset,t.removals].concat(t.value));break;case"remove":r=t.path[t.path.length-1],n=t.path.slice(0,t.path.length-1),void 0!==(o=f(e,n))&&delete o[r];break;default:throw new Error("unsupported operation type")}}(e,t)})),e},w=function(e,t,n){if(e.prev!==t.prev)throw new Error("Parent values don't match!");if(n===m.splice.splice)return console.log(e),console.log(t),console.log("\n\n\n\n\n\n\n\n\n"),!0;var r=e.prev,o=s.diff(r,e.value),a=s.diff(r,t.value),i=u(a,o,r),l=c.applyMulti(o,r),f=c.applyMulti(i,l);t.value=f};e.exports=function(e,t,n){var r=JSON.parse(n),o=c.applyMulti(t,n),a=JSON.parse(o),u=c.applyMulti(e,n),l=JSON.parse(u);try{var f=A(r,l),d=A(r,a),h=g(d,f,w);_(r,d),_(r,h);var p=i(r);return s.diff(o,p)}catch(e){console.error(e)}return[]},e.exports._={clone:function(e){return JSON.parse(JSON.stringify(e))},pathOverlaps:v,deepEqual:d,diff:A,resolve:g,patch:_,arbiter:w}}},a.m[1]={"dist/JSON.sortify.js":function(e,t,n){var r;r=function(){var e=function e(t){if(Array.isArray(t))return t.map(e);if(t instanceof Object){var n=(r=[],o=[],Object.keys(t).forEach((function(e){/^(0|[1-9][0-9]*)$/.test(e)?r.push(+e):o.push(e)})),{v:r.sort((function(e,t){return e-t})).concat(o.sort()).reduce((function(n,r){return n[r]=e(t[r]),n}),{})});if("object"==typeof n)return n.v}var r,o;return t},t=JSON.stringify.bind(JSON);return function(n,r,o){var a=t(n,r,0);if(!a||"{"!==a[0]&&"["!==a[0])return a;var i=JSON.parse(a);return t(e(i),null,o)}},void 0!==e&&e.exports?e.exports=r():JSON.sortify=r()}},a.m[2]={"diff.js":function(e,t,n){var r=-1;function o(e,t,n,u){if(e===t)return e?[[0,e]]:[];if(null!=n){var l=function(e,t,n){var r="number"==typeof n?{index:n,length:0}:n.oldRange,o="number"==typeof n?null:n.newRange,a=e.length,i=t.length;if(0===r.length&&(null===o||0===o.length)){var s=r.index,c=e.slice(0,s),u=e.slice(s),l=o?o.index:null,f=s+i-a;if((null===l||l===f)&&!(f<0||f>i)){var d=t.slice(0,f);if((v=t.slice(f))===u){var p=Math.min(s,f);if((g=c.slice(0,p))===(b=d.slice(0,p)))return h(g,c.slice(p),d.slice(p),u)}}if(null===l||l===s){var y=s,v=(d=t.slice(0,y),t.slice(y));if(d===c){var m=Math.min(a-y,i-y);if((E=u.slice(u.length-m))===(A=v.slice(v.length-m)))return h(c,u.slice(0,u.length-m),v.slice(0,v.length-m),E)}}}if(r.length>0&&o&&0===o.length){var g=e.slice(0,r.index),E=e.slice(r.index+r.length);if(!(i<(p=g.length)+(m=E.length))){var b=t.slice(0,p),A=t.slice(i-m);if(g===b&&E===A)return h(g,e.slice(p,a-m),t.slice(p,i-m),E)}}return null}(e,t,n);if(l)return l}var f=i(e,t),d=e.substring(0,f);f=s(e=e.substring(f),t=t.substring(f));var p=e.substring(e.length-f),y=function(e,t){var n;if(!e)return[[1,t]];if(!t)return[[r,e]];var c=e.length>t.length?e:t,u=e.length>t.length?t:e,l=c.indexOf(u);if(-1!==l)return n=[[1,c.substring(0,l)],[0,u],[1,c.substring(l+u.length)]],e.length>t.length&&(n[0][0]=n[2][0]=r),n;if(1===u.length)return[[r,e],[1,t]];var f=function(e,t){var n=e.length>t.length?e:t,r=e.length>t.length?t:e;if(n.length<4||2*r.length<n.length)return null;function o(e,t,n){for(var r,o,a,c,u=e.substring(n,n+Math.floor(e.length/4)),l=-1,f="";-1!==(l=t.indexOf(u,l+1));){var d=i(e.substring(n),t.substring(l)),h=s(e.substring(0,n),t.substring(0,l));f.length<h+d&&(f=t.substring(l-h,l)+t.substring(l,l+d),r=e.substring(0,n-h),o=e.substring(n+d),a=t.substring(0,l-h),c=t.substring(l+d))}return 2*f.length>=e.length?[r,o,a,c,f]:null}var a,c,u,l,f,d=o(n,r,Math.ceil(n.length/4)),h=o(n,r,Math.ceil(n.length/2));if(!d&&!h)return null;a=h?d&&d[4].length>h[4].length?d:h:d,e.length>t.length?(c=a[0],u=a[1],l=a[2],f=a[3]):(l=a[0],f=a[1],c=a[2],u=a[3]);var p=a[4];return[c,u,l,f,p]}(e,t);if(f){var d=f[0],h=f[1],p=f[2],y=f[3],v=f[4],m=o(d,p),g=o(h,y);return m.concat([[0,v]],g)}return function(e,t){for(var n=e.length,o=t.length,i=Math.ceil((n+o)/2),s=i,c=2*i,u=new Array(c),l=new Array(c),f=0;f<c;f++)u[f]=-1,l[f]=-1;u[s+1]=0,l[s+1]=0;for(var d=n-o,h=d%2!=0,p=0,y=0,v=0,m=0,g=0;g<i;g++){for(var E=-g+p;E<=g-y;E+=2){for(var b=s+E,A=(S=E===-g||E!==g&&u[b-1]<u[b+1]?u[b+1]:u[b-1]+1)-E;S<n&&A<o&&e.charAt(S)===t.charAt(A);)S++,A++;if(u[b]=S,S>n)y+=2;else if(A>o)p+=2;else if(h&&(O=s+d-E)>=0&&O<c&&-1!==l[O]&&S>=(w=n-l[O]))return a(e,t,S,A)}for(var _=-g+v;_<=g-m;_+=2){for(var w,O=s+_,D=(w=_===-g||_!==g&&l[O-1]<l[O+1]?l[O+1]:l[O-1]+1)-_;w<n&&D<o&&e.charAt(n-w-1)===t.charAt(o-D-1);)w++,D++;if(l[O]=w,w>n)m+=2;else if(D>o)v+=2;else if(!h){var S;if((b=s+d-_)>=0&&b<c&&-1!==u[b])if(A=s+(S=u[b])-b,S>=(w=n-w))return a(e,t,S,A)}}}return[[r,e],[1,t]]}(e,t)}(e=e.substring(0,e.length-f),t=t.substring(0,t.length-f));return d&&y.unshift([0,d]),p&&y.push([0,p]),c(y,u),y}function a(e,t,n,r){var a=e.substring(0,n),i=t.substring(0,r),s=e.substring(n),c=t.substring(r),u=o(a,i),l=o(s,c);return u.concat(l)}function i(e,t){if(!e||!t||e.charAt(0)!==t.charAt(0))return 0;for(var n=0,r=Math.min(e.length,t.length),o=r,a=0;n<o;)e.substring(a,o)==t.substring(a,o)?a=n=o:r=o,o=Math.floor((r-n)/2+n);return u(e.charCodeAt(o-1))&&o--,o}function s(e,t){if(!e||!t||e.slice(-1)!==t.slice(-1))return 0;for(var n=0,r=Math.min(e.length,t.length),o=r,a=0;n<o;)e.substring(e.length-o,e.length-a)==t.substring(t.length-o,t.length-a)?a=n=o:r=o,o=Math.floor((r-n)/2+n);return l(e.charCodeAt(e.length-o))&&o--,o}function c(e,t){e.push([0,""]);for(var n,o=0,a=0,u=0,l="",h="";o<e.length;)if(o<e.length-1&&!e[o][1])e.splice(o,1);else switch(e[o][0]){case 1:u++,h+=e[o][1],o++;break;case r:a++,l+=e[o][1],o++;break;case 0:var p=o-u-a-1;if(t){if(p>=0&&d(e[p][1])){var y=e[p][1].slice(-1);if(e[p][1]=e[p][1].slice(0,-1),l=y+l,h=y+h,!e[p][1]){e.splice(p,1),o--;var v=p-1;e[v]&&1===e[v][0]&&(u++,h=e[v][1]+h,v--),e[v]&&e[v][0]===r&&(a++,l=e[v][1]+l,v--),p=v}}f(e[o][1])&&(y=e[o][1].charAt(0),e[o][1]=e[o][1].slice(1),l+=y,h+=y)}if(o<e.length-1&&!e[o][1]){e.splice(o,1);break}if(l.length>0||h.length>0){l.length>0&&h.length>0&&(0!==(n=i(h,l))&&(p>=0?e[p][1]+=h.substring(0,n):(e.splice(0,0,[0,h.substring(0,n)]),o++),h=h.substring(n),l=l.substring(n)),0!==(n=s(h,l))&&(e[o][1]=h.substring(h.length-n)+e[o][1],h=h.substring(0,h.length-n),l=l.substring(0,l.length-n)));var m=u+a;0===l.length&&0===h.length?(e.splice(o-m,m),o-=m):0===l.length?(e.splice(o-m,m,[1,h]),o=o-m+1):0===h.length?(e.splice(o-m,m,[r,l]),o=o-m+1):(e.splice(o-m,m,[r,l],[1,h]),o=o-m+2)}0!==o&&0===e[o-1][0]?(e[o-1][1]+=e[o][1],e.splice(o,1)):o++,u=0,a=0,l="",h=""}""===e[e.length-1][1]&&e.pop();var g=!1;for(o=1;o<e.length-1;)0===e[o-1][0]&&0===e[o+1][0]&&(e[o][1].substring(e[o][1].length-e[o-1][1].length)===e[o-1][1]?(e[o][1]=e[o-1][1]+e[o][1].substring(0,e[o][1].length-e[o-1][1].length),e[o+1][1]=e[o-1][1]+e[o+1][1],e.splice(o-1,1),g=!0):e[o][1].substring(0,e[o+1][1].length)==e[o+1][1]&&(e[o-1][1]+=e[o+1][1],e[o][1]=e[o][1].substring(e[o+1][1].length)+e[o+1][1],e.splice(o+1,1),g=!0)),o++;g&&c(e,t)}function u(e){return e>=55296&&e<=56319}function l(e){return e>=56320&&e<=57343}function f(e){return l(e.charCodeAt(0))}function d(e){return u(e.charCodeAt(e.length-1))}function h(e,t,n,o){return d(e)||f(o)?null:function(e){for(var t=[],n=0;n<e.length;n++)e[n][1].length>0&&t.push(e[n]);return t}([[0,e],[r,t],[1,n],[0,o]])}function p(e,t,n){return o(e,t,n,!0)}p.INSERT=1,p.DELETE=r,p.EQUAL=0,e.exports=p}},t=a("ChainPad.js"),r="ChainPad",e.exports=t,"undefined"!=typeof window?o=window:void 0!==n?o=n:"undefined"!=typeof self&&(o=self),o[r]=t}(x)),x.exports}var N,P=I(),k=t({__proto__:null,default:r(P)},[P]),R={exports:{}},M={},F={},L={};function H(){if(N)return L;N=1,Object.defineProperty(L,"__esModule",{value:!0}),L.toBig=L.shrSL=L.shrSH=L.rotrSL=L.rotrSH=L.rotrBL=L.rotrBH=L.rotr32L=L.rotr32H=L.rotlSL=L.rotlSH=L.rotlBL=L.rotlBH=L.add5L=L.add5H=L.add4L=L.add4H=L.add3L=L.add3H=void 0,L.add=m,L.fromBig=n,L.split=r;const e=BigInt(2**32-1),t=BigInt(32);function n(n,r=!1){return r?{h:Number(n&e),l:Number(n>>t&e)}:{h:0|Number(n>>t&e),l:0|Number(n&e)}}function r(e,t=!1){const r=e.length;let o=new Uint32Array(r),a=new Uint32Array(r);for(let i=0;i<r;i++){const{h:r,l:s}=n(e[i],t);[o[i],a[i]]=[r,s]}return[o,a]}const o=(e,n)=>BigInt(e>>>0)<<t|BigInt(n>>>0);L.toBig=o;const a=(e,t,n)=>e>>>n;L.shrSH=a;const i=(e,t,n)=>e<<32-n|t>>>n;L.shrSL=i;const s=(e,t,n)=>e>>>n|t<<32-n;L.rotrSH=s;const c=(e,t,n)=>e<<32-n|t>>>n;L.rotrSL=c;const u=(e,t,n)=>e<<64-n|t>>>n-32;L.rotrBH=u;const l=(e,t,n)=>e>>>n-32|t<<64-n;L.rotrBL=l;const f=(e,t)=>t;L.rotr32H=f;const d=(e,t)=>e;L.rotr32L=d;const h=(e,t,n)=>e<<n|t>>>32-n;L.rotlSH=h;const p=(e,t,n)=>t<<n|e>>>32-n;L.rotlSL=p;const y=(e,t,n)=>t<<n-32|e>>>64-n;L.rotlBH=y;const v=(e,t,n)=>e<<n-32|t>>>64-n;function m(e,t,n,r){const o=(t>>>0)+(r>>>0);return{h:e+n+(o/2**32|0)|0,l:0|o}}L.rotlBL=v;const g=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0);L.add3L=g;const E=(e,t,n,r)=>t+n+r+(e/2**32|0)|0;L.add3H=E;const b=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0);L.add4L=b;const A=(e,t,n,r,o)=>t+n+r+o+(e/2**32|0)|0;L.add4H=A;const _=(e,t,n,r,o)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(o>>>0);L.add5L=_;const w=(e,t,n,r,o,a)=>t+n+r+o+a+(e/2**32|0)|0;L.add5H=w;const O={fromBig:n,split:r,toBig:o,shrSH:a,shrSL:i,rotrSH:s,rotrSL:c,rotrBH:u,rotrBL:l,rotr32H:f,rotr32L:d,rotlSH:h,rotlSL:p,rotlBH:y,rotlBL:v,add:m,add3L:g,add3H:E,add4L:b,add4H:A,add5H:w,add5L:_};return L.default=O,L}var K,j,U,B={},V={};function G(){return j||(j=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.wrapXOFConstructorWithOpts=e.wrapConstructorWithOpts=e.wrapConstructor=e.Hash=e.nextTick=e.swap32IfBE=e.byteSwapIfBE=e.swap8IfBE=e.isLE=void 0,e.isBytes=n,e.anumber=r,e.abytes=o,e.ahash=function(e){if("function"!=typeof e||"function"!=typeof e.create)throw new Error("Hash should be wrapped by utils.createHasher");r(e.outputLen),r(e.blockLen)},e.aexists=function(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")},e.aoutput=function(e,t){o(e);const n=t.outputLen;if(e.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)},e.u8=function(e){return new Uint8Array(e.buffer,e.byteOffset,e.byteLength)},e.u32=function(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))},e.clean=function(...e){for(let t=0;t<e.length;t++)e[t].fill(0)},e.createView=function(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)},e.rotr=function(e,t){return e<<32-t|e>>>t},e.rotl=function(e,t){return e<<t|e>>>32-t>>>0},e.byteSwap=a,e.byteSwap32=i,e.bytesToHex=function(e){if(o(e),s)return e.toHex();let t="";for(let n=0;n<e.length;n++)t+=c[e[n]];return t},e.hexToBytes=function(e){if("string"!=typeof e)throw new Error("hex string expected, got "+typeof e);if(s)return Uint8Array.fromHex(e);const t=e.length,n=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);const r=new Uint8Array(n);for(let t=0,o=0;t<n;t++,o+=2){const n=l(e.charCodeAt(o)),a=l(e.charCodeAt(o+1));if(void 0===n||void 0===a){const t=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+t+'" at index '+o)}r[t]=16*n+a}return r},e.asyncLoop=async function(t,n,r){let o=Date.now();for(let a=0;a<t;a++){r(a);const t=Date.now()-o;t>=0&&t<n||(await(0,e.nextTick)(),o+=t)}},e.utf8ToBytes=f,e.bytesToUtf8=function(e){return(new TextDecoder).decode(e)},e.toBytes=d,e.kdfInputToBytes=function(e){"string"==typeof e&&(e=f(e));return o(e),e},e.concatBytes=function(...e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];o(r),t+=r.length}const n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){const o=e[t];n.set(o,r),r+=o.length}return n},e.checkOpts=function(e,t){if(void 0!==t&&"[object Object]"!=={}.toString.call(t))throw new Error("options should be object or undefined");return Object.assign(e,t)},e.createHasher=h,e.createOptHasher=p,e.createXOFer=y,e.randomBytes=function(e=32){if(t.crypto&&"function"==typeof t.crypto.getRandomValues)return t.crypto.getRandomValues(new Uint8Array(e));if(t.crypto&&"function"==typeof t.crypto.randomBytes)return Uint8Array.from(t.crypto.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")};const t=(K||(K=1,Object.defineProperty(V,"__esModule",{value:!0}),V.crypto=void 0,V.crypto="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0),V);function n(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&"Uint8Array"===e.constructor.name}function r(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function o(e,...t){if(!n(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function a(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function i(e){for(let t=0;t<e.length;t++)e[t]=a(e[t]);return e}e.isLE=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0],e.swap8IfBE=e.isLE?e=>e:e=>a(e),e.byteSwapIfBE=e.swap8IfBE,e.swap32IfBE=e.isLE?e=>e:i;const s=(()=>"function"==typeof Uint8Array.from([]).toHex&&"function"==typeof Uint8Array.fromHex)(),c=Array.from({length:256},((e,t)=>t.toString(16).padStart(2,"0")));const u={_0:48,_9:57,A:65,F:70,a:97,f:102};function l(e){return e>=u._0&&e<=u._9?e-u._0:e>=u.A&&e<=u.F?e-(u.A-10):e>=u.a&&e<=u.f?e-(u.a-10):void 0}function f(e){if("string"!=typeof e)throw new Error("string expected");return new Uint8Array((new TextEncoder).encode(e))}function d(e){return"string"==typeof e&&(e=f(e)),o(e),e}e.nextTick=async()=>{};function h(e){const t=t=>e().update(d(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}function p(e){const t=(t,n)=>e(n).update(d(t)).digest(),n=e({});return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=t=>e(t),t}function y(e){const t=(t,n)=>e(n).update(d(t)).digest(),n=e({});return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=t=>e(t),t}e.Hash=class{},e.wrapConstructor=h,e.wrapConstructorWithOpts=p,e.wrapXOFConstructorWithOpts=y}(B)),B}function Y(){if(U)return F;U=1,Object.defineProperty(F,"__esModule",{value:!0}),F.shake256=F.shake128=F.keccak_512=F.keccak_384=F.keccak_256=F.keccak_224=F.sha3_512=F.sha3_384=F.sha3_256=F.sha3_224=F.Keccak=void 0,F.keccakP=v;const e=H(),t=G(),n=BigInt(0),r=BigInt(1),o=BigInt(2),a=BigInt(7),i=BigInt(256),s=BigInt(113),c=[],u=[],l=[];for(let e=0,t=r,f=1,d=0;e<24;e++){[f,d]=[d,(2*f+3*d)%5],c.push(2*(5*d+f)),u.push((e+1)*(e+2)/2%64);let h=n;for(let e=0;e<7;e++)t=(t<<r^(t>>a)*s)%i,t&o&&(h^=r<<(r<<BigInt(e))-r);l.push(h)}const f=(0,e.split)(l,!0),d=f[0],h=f[1],p=(t,n,r)=>r>32?(0,e.rotlBH)(t,n,r):(0,e.rotlSH)(t,n,r),y=(t,n,r)=>r>32?(0,e.rotlBL)(t,n,r):(0,e.rotlSL)(t,n,r);function v(e,n=24){const r=new Uint32Array(10);for(let t=24-n;t<24;t++){for(let t=0;t<10;t++)r[t]=e[t]^e[t+10]^e[t+20]^e[t+30]^e[t+40];for(let t=0;t<10;t+=2){const n=(t+8)%10,o=(t+2)%10,a=r[o],i=r[o+1],s=p(a,i,1)^r[n],c=y(a,i,1)^r[n+1];for(let n=0;n<50;n+=10)e[t+n]^=s,e[t+n+1]^=c}let n=e[2],o=e[3];for(let t=0;t<24;t++){const r=u[t],a=p(n,o,r),i=y(n,o,r),s=c[t];n=e[s],o=e[s+1],e[s]=a,e[s+1]=i}for(let t=0;t<50;t+=10){for(let n=0;n<10;n++)r[n]=e[t+n];for(let n=0;n<10;n++)e[t+n]^=~r[(n+2)%10]&r[(n+4)%10]}e[0]^=d[t],e[1]^=h[t]}(0,t.clean)(r)}class m extends t.Hash{constructor(e,n,r,o=!1,a=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=o,this.rounds=a,(0,t.anumber)(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=(0,t.u32)(this.state)}clone(){return this._cloneInto()}keccak(){(0,t.swap32IfBE)(this.state32),v(this.state32,this.rounds),(0,t.swap32IfBE)(this.state32),this.posOut=0,this.pos=0}update(e){(0,t.aexists)(this),e=(0,t.toBytes)(e),(0,t.abytes)(e);const{blockLen:n,state:r}=this,o=e.length;for(let t=0;t<o;){const a=Math.min(n-this.pos,o-t);for(let n=0;n<a;n++)r[this.pos++]^=e[t++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:t,pos:n,blockLen:r}=this;e[n]^=t,128&t&&n===r-1&&this.keccak(),e[r-1]^=128,this.keccak()}writeInto(e){(0,t.aexists)(this,!1),(0,t.abytes)(e),this.finish();const n=this.state,{blockLen:r}=this;for(let t=0,o=e.length;t<o;){this.posOut>=r&&this.keccak();const a=Math.min(r-this.posOut,o-t);e.set(n.subarray(this.posOut,this.posOut+a),t),this.posOut+=a,t+=a}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return(0,t.anumber)(e),this.xofInto(new Uint8Array(e))}digestInto(e){if((0,t.aoutput)(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,(0,t.clean)(this.state)}_cloneInto(e){const{blockLen:t,suffix:n,outputLen:r,rounds:o,enableXOF:a}=this;return e||(e=new m(t,n,r,a,o)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=o,e.suffix=n,e.outputLen=r,e.enableXOF=a,e.destroyed=this.destroyed,e}}F.Keccak=m;const g=(e,n,r)=>(0,t.createHasher)((()=>new m(n,e,r)));F.sha3_224=g(6,144,28),F.sha3_256=g(6,136,32),F.sha3_384=g(6,104,48),F.sha3_512=g(6,72,64),F.keccak_224=g(1,144,28),F.keccak_256=g(1,136,32),F.keccak_384=g(1,104,48),F.keccak_512=g(1,72,64);const E=(e,n,r)=>(0,t.createXOFer)(((t={})=>new m(n,e,void 0===t.dkLen?r:t.dkLen,!0)));return F.shake128=E(31,168,16),F.shake256=E(31,136,32),F}var J,q,W,Q,z,X={},Z={},$={},ee={};function te(){if(J)return ee;J=1,Object.defineProperty(ee,"__esModule",{value:!0}),ee.SHA512_IV=ee.SHA384_IV=ee.SHA224_IV=ee.SHA256_IV=ee.HashMD=void 0,ee.setBigUint64=t,ee.Chi=function(e,t,n){return e&t^~e&n},ee.Maj=function(e,t,n){return e&t^e&n^t&n};const e=G();function t(e,t,n,r){if("function"==typeof e.setBigUint64)return e.setBigUint64(t,n,r);const o=BigInt(32),a=BigInt(4294967295),i=Number(n>>o&a),s=Number(n&a),c=r?4:0,u=r?0:4;e.setUint32(t+c,i,r),e.setUint32(t+u,s,r)}class n extends e.Hash{constructor(t,n,r,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=n,this.padOffset=r,this.isLE=o,this.buffer=new Uint8Array(t),this.view=(0,e.createView)(this.buffer)}update(t){(0,e.aexists)(this),t=(0,e.toBytes)(t),(0,e.abytes)(t);const{view:n,buffer:r,blockLen:o}=this,a=t.length;for(let i=0;i<a;){const s=Math.min(o-this.pos,a-i);if(s!==o)r.set(t.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===o&&(this.process(n,0),this.pos=0);else{const n=(0,e.createView)(t);for(;o<=a-i;i+=o)this.process(n,i)}}return this.length+=t.length,this.roundClean(),this}digestInto(n){(0,e.aexists)(this),(0,e.aoutput)(n,this),this.finished=!0;const{buffer:r,view:o,blockLen:a,isLE:i}=this;let{pos:s}=this;r[s++]=128,(0,e.clean)(this.buffer.subarray(s)),this.padOffset>a-s&&(this.process(o,0),s=0);for(let e=s;e<a;e++)r[e]=0;t(o,a-8,BigInt(8*this.length),i),this.process(o,0);const c=(0,e.createView)(n),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=u/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let e=0;e<l;e++)c.setUint32(4*e,f[e],i)}digest(){const{buffer:e,outputLen:t}=this;this.digestInto(e);const n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:t,buffer:n,length:r,finished:o,destroyed:a,pos:i}=this;return e.destroyed=a,e.finished=o,e.length=r,e.pos=i,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}}return ee.HashMD=n,ee.SHA256_IV=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ee.SHA224_IV=Uint32Array.from([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]),ee.SHA384_IV=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),ee.SHA512_IV=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),ee}function ne(){if(q)return $;q=1,Object.defineProperty($,"__esModule",{value:!0}),$.sha512_224=$.sha512_256=$.sha384=$.sha512=$.sha224=$.sha256=$.SHA512_256=$.SHA512_224=$.SHA384=$.SHA512=$.SHA224=$.SHA256=void 0;const e=te(),t=H(),n=G(),r=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),o=new Uint32Array(64);class a extends e.HashMD{constructor(t=32){super(64,t,8,!1),this.A=0|e.SHA256_IV[0],this.B=0|e.SHA256_IV[1],this.C=0|e.SHA256_IV[2],this.D=0|e.SHA256_IV[3],this.E=0|e.SHA256_IV[4],this.F=0|e.SHA256_IV[5],this.G=0|e.SHA256_IV[6],this.H=0|e.SHA256_IV[7]}get(){const{A:e,B:t,C:n,D:r,E:o,F:a,G:i,H:s}=this;return[e,t,n,r,o,a,i,s]}set(e,t,n,r,o,a,i,s){this.A=0|e,this.B=0|t,this.C=0|n,this.D=0|r,this.E=0|o,this.F=0|a,this.G=0|i,this.H=0|s}process(t,a){for(let e=0;e<16;e++,a+=4)o[e]=t.getUint32(a,!1);for(let e=16;e<64;e++){const t=o[e-15],r=o[e-2],a=(0,n.rotr)(t,7)^(0,n.rotr)(t,18)^t>>>3,i=(0,n.rotr)(r,17)^(0,n.rotr)(r,19)^r>>>10;o[e]=i+o[e-7]+a+o[e-16]|0}let{A:i,B:s,C:c,D:u,E:l,F:f,G:d,H:h}=this;for(let t=0;t<64;t++){const a=h+((0,n.rotr)(l,6)^(0,n.rotr)(l,11)^(0,n.rotr)(l,25))+(0,e.Chi)(l,f,d)+r[t]+o[t]|0,p=((0,n.rotr)(i,2)^(0,n.rotr)(i,13)^(0,n.rotr)(i,22))+(0,e.Maj)(i,s,c)|0;h=d,d=f,f=l,l=u+a|0,u=c,c=s,s=i,i=a+p|0}i=i+this.A|0,s=s+this.B|0,c=c+this.C|0,u=u+this.D|0,l=l+this.E|0,f=f+this.F|0,d=d+this.G|0,h=h+this.H|0,this.set(i,s,c,u,l,f,d,h)}roundClean(){(0,n.clean)(o)}destroy(){this.set(0,0,0,0,0,0,0,0),(0,n.clean)(this.buffer)}}$.SHA256=a;class i extends a{constructor(){super(28),this.A=0|e.SHA224_IV[0],this.B=0|e.SHA224_IV[1],this.C=0|e.SHA224_IV[2],this.D=0|e.SHA224_IV[3],this.E=0|e.SHA224_IV[4],this.F=0|e.SHA224_IV[5],this.G=0|e.SHA224_IV[6],this.H=0|e.SHA224_IV[7]}}$.SHA224=i;const s=(()=>t.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map((e=>BigInt(e)))))(),c=(()=>s[0])(),u=(()=>s[1])(),l=new Uint32Array(80),f=new Uint32Array(80);class d extends e.HashMD{constructor(t=64){super(128,t,16,!1),this.Ah=0|e.SHA512_IV[0],this.Al=0|e.SHA512_IV[1],this.Bh=0|e.SHA512_IV[2],this.Bl=0|e.SHA512_IV[3],this.Ch=0|e.SHA512_IV[4],this.Cl=0|e.SHA512_IV[5],this.Dh=0|e.SHA512_IV[6],this.Dl=0|e.SHA512_IV[7],this.Eh=0|e.SHA512_IV[8],this.El=0|e.SHA512_IV[9],this.Fh=0|e.SHA512_IV[10],this.Fl=0|e.SHA512_IV[11],this.Gh=0|e.SHA512_IV[12],this.Gl=0|e.SHA512_IV[13],this.Hh=0|e.SHA512_IV[14],this.Hl=0|e.SHA512_IV[15]}get(){const{Ah:e,Al:t,Bh:n,Bl:r,Ch:o,Cl:a,Dh:i,Dl:s,Eh:c,El:u,Fh:l,Fl:f,Gh:d,Gl:h,Hh:p,Hl:y}=this;return[e,t,n,r,o,a,i,s,c,u,l,f,d,h,p,y]}set(e,t,n,r,o,a,i,s,c,u,l,f,d,h,p,y){this.Ah=0|e,this.Al=0|t,this.Bh=0|n,this.Bl=0|r,this.Ch=0|o,this.Cl=0|a,this.Dh=0|i,this.Dl=0|s,this.Eh=0|c,this.El=0|u,this.Fh=0|l,this.Fl=0|f,this.Gh=0|d,this.Gl=0|h,this.Hh=0|p,this.Hl=0|y}process(e,n){for(let t=0;t<16;t++,n+=4)l[t]=e.getUint32(n),f[t]=e.getUint32(n+=4);for(let e=16;e<80;e++){const n=0|l[e-15],r=0|f[e-15],o=t.rotrSH(n,r,1)^t.rotrSH(n,r,8)^t.shrSH(n,r,7),a=t.rotrSL(n,r,1)^t.rotrSL(n,r,8)^t.shrSL(n,r,7),i=0|l[e-2],s=0|f[e-2],c=t.rotrSH(i,s,19)^t.rotrBH(i,s,61)^t.shrSH(i,s,6),u=t.rotrSL(i,s,19)^t.rotrBL(i,s,61)^t.shrSL(i,s,6),d=t.add4L(a,u,f[e-7],f[e-16]),h=t.add4H(d,o,c,l[e-7],l[e-16]);l[e]=0|h,f[e]=0|d}let{Ah:r,Al:o,Bh:a,Bl:i,Ch:s,Cl:d,Dh:h,Dl:p,Eh:y,El:v,Fh:m,Fl:g,Gh:E,Gl:b,Hh:A,Hl:_}=this;for(let e=0;e<80;e++){const n=t.rotrSH(y,v,14)^t.rotrSH(y,v,18)^t.rotrBH(y,v,41),w=t.rotrSL(y,v,14)^t.rotrSL(y,v,18)^t.rotrBL(y,v,41),O=y&m^~y&E,D=v&g^~v&b,S=t.add5L(_,w,D,u[e],f[e]),T=t.add5H(S,A,n,O,c[e],l[e]),C=0|S,x=t.rotrSH(r,o,28)^t.rotrBH(r,o,34)^t.rotrBH(r,o,39),I=t.rotrSL(r,o,28)^t.rotrBL(r,o,34)^t.rotrBL(r,o,39),N=r&a^r&s^a&s,P=o&i^o&d^i&d;A=0|E,_=0|b,E=0|m,b=0|g,m=0|y,g=0|v,({h:y,l:v}=t.add(0|h,0|p,0|T,0|C)),h=0|s,p=0|d,s=0|a,d=0|i,a=0|r,i=0|o;const k=t.add3L(C,I,P);r=t.add3H(k,T,x,N),o=0|k}({h:r,l:o}=t.add(0|this.Ah,0|this.Al,0|r,0|o)),({h:a,l:i}=t.add(0|this.Bh,0|this.Bl,0|a,0|i)),({h:s,l:d}=t.add(0|this.Ch,0|this.Cl,0|s,0|d)),({h,l:p}=t.add(0|this.Dh,0|this.Dl,0|h,0|p)),({h:y,l:v}=t.add(0|this.Eh,0|this.El,0|y,0|v)),({h:m,l:g}=t.add(0|this.Fh,0|this.Fl,0|m,0|g)),({h:E,l:b}=t.add(0|this.Gh,0|this.Gl,0|E,0|b)),({h:A,l:_}=t.add(0|this.Hh,0|this.Hl,0|A,0|_)),this.set(r,o,a,i,s,d,h,p,y,v,m,g,E,b,A,_)}roundClean(){(0,n.clean)(l,f)}destroy(){(0,n.clean)(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}$.SHA512=d;class h extends d{constructor(){super(48),this.Ah=0|e.SHA384_IV[0],this.Al=0|e.SHA384_IV[1],this.Bh=0|e.SHA384_IV[2],this.Bl=0|e.SHA384_IV[3],this.Ch=0|e.SHA384_IV[4],this.Cl=0|e.SHA384_IV[5],this.Dh=0|e.SHA384_IV[6],this.Dl=0|e.SHA384_IV[7],this.Eh=0|e.SHA384_IV[8],this.El=0|e.SHA384_IV[9],this.Fh=0|e.SHA384_IV[10],this.Fl=0|e.SHA384_IV[11],this.Gh=0|e.SHA384_IV[12],this.Gl=0|e.SHA384_IV[13],this.Hh=0|e.SHA384_IV[14],this.Hl=0|e.SHA384_IV[15]}}$.SHA384=h;const p=Uint32Array.from([2352822216,424955298,1944164710,2312950998,502970286,855612546,1738396948,1479516111,258812777,2077511080,2011393907,79989058,1067287976,1780299464,286451373,2446758561]),y=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class v extends d{constructor(){super(28),this.Ah=0|p[0],this.Al=0|p[1],this.Bh=0|p[2],this.Bl=0|p[3],this.Ch=0|p[4],this.Cl=0|p[5],this.Dh=0|p[6],this.Dl=0|p[7],this.Eh=0|p[8],this.El=0|p[9],this.Fh=0|p[10],this.Fl=0|p[11],this.Gh=0|p[12],this.Gl=0|p[13],this.Hh=0|p[14],this.Hl=0|p[15]}}$.SHA512_224=v;class m extends d{constructor(){super(32),this.Ah=0|y[0],this.Al=0|y[1],this.Bh=0|y[2],this.Bl=0|y[3],this.Ch=0|y[4],this.Cl=0|y[5],this.Dh=0|y[6],this.Dl=0|y[7],this.Eh=0|y[8],this.El=0|y[9],this.Fh=0|y[10],this.Fl=0|y[11],this.Gh=0|y[12],this.Gl=0|y[13],this.Hh=0|y[14],this.Hl=0|y[15]}}return $.SHA512_256=m,$.sha256=(0,n.createHasher)((()=>new a)),$.sha224=(0,n.createHasher)((()=>new i)),$.sha512=(0,n.createHasher)((()=>new d)),$.sha384=(0,n.createHasher)((()=>new h)),$.sha512_256=(0,n.createHasher)((()=>new m)),$.sha512_224=(0,n.createHasher)((()=>new v)),$}function re(){return W||(W=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.EMPTY=e.utf8ToBytes=e.concatBytes=e.randomBytes=e.ensureBytes=void 0,e.equalBytes=function(e,t){if(e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return 0===n},e.splitCoder=function(...t){const n=e=>"number"==typeof e?e:e.bytesLen,r=t.reduce(((e,t)=>e+n(t)),0);return{bytesLen:r,encode:o=>{const a=new Uint8Array(r);for(let r=0,i=0;r<t.length;r++){const s=t[r],c=n(s),u="number"==typeof s?o[r]:s.encode(o[r]);(0,e.ensureBytes)(u,c),a.set(u,i),"number"!=typeof s&&u.fill(0),i+=c}return a},decode:o=>{(0,e.ensureBytes)(o,r);const a=[];for(const e of t){const t=n(e),r=o.subarray(0,t);a.push("number"==typeof e?r:e.decode(r)),o=o.subarray(t)}return a}}},e.vecCoder=function(t,n){const r=n*t.bytesLen;return{bytesLen:r,encode:e=>{if(e.length!==n)throw new Error(`vecCoder.encode: wrong length=${e.length}. Expected: ${n}`);const o=new Uint8Array(r);for(let n=0,r=0;n<e.length;n++){const a=t.encode(e[n]);o.set(a,r),a.fill(0),r+=a.length}return o},decode:n=>{(0,e.ensureBytes)(n,r);const o=[];for(let e=0;e<n.length;e+=t.bytesLen)o.push(t.decode(n.subarray(e,e+t.bytesLen)));return o}}},e.cleanBytes=function(...e){for(const t of e)if(Array.isArray(t))for(const e of t)e.fill(0);else t.fill(0)},e.getMask=function(e){return(1<<e)-1},e.getMessage=function(t,n=e.EMPTY){if((0,e.ensureBytes)(t),(0,e.ensureBytes)(n),n.length>255)throw new Error("context should be less than 255 bytes");return(0,r.concatBytes)(new Uint8Array([0,n.length]),n,t)},e.getMessagePrehash=function(t,n,a=e.EMPTY){if((0,e.ensureBytes)(n),(0,e.ensureBytes)(a),a.length>255)throw new Error("context should be less than 255 bytes");if(!o[t])throw new Error("unknown hash: "+t);const{oid:i,hash:s}=o[t],c=s(n);return(0,r.concatBytes)(new Uint8Array([1,a.length]),a,i,c)};const t=ne(),n=Y(),r=G();Object.defineProperty(e,"concatBytes",{enumerable:!0,get:function(){return r.concatBytes}}),Object.defineProperty(e,"utf8ToBytes",{enumerable:!0,get:function(){return r.utf8ToBytes}}),e.ensureBytes=r.abytes,e.randomBytes=r.randomBytes,e.EMPTY=new Uint8Array(0);const o={"SHA2-256":{oid:(0,r.hexToBytes)("0609608648016503040201"),hash:t.sha256},"SHA2-384":{oid:(0,r.hexToBytes)("0609608648016503040202"),hash:t.sha384},"SHA2-512":{oid:(0,r.hexToBytes)("0609608648016503040203"),hash:t.sha512},"SHA2-224":{oid:(0,r.hexToBytes)("0609608648016503040204"),hash:t.sha224},"SHA2-512/224":{oid:(0,r.hexToBytes)("0609608648016503040205"),hash:t.sha512_224},"SHA2-512/256":{oid:(0,r.hexToBytes)("0609608648016503040206"),hash:t.sha512_256},"SHA3-224":{oid:(0,r.hexToBytes)("0609608648016503040207"),hash:n.sha3_224},"SHA3-256":{oid:(0,r.hexToBytes)("0609608648016503040208"),hash:n.sha3_256},"SHA3-384":{oid:(0,r.hexToBytes)("0609608648016503040209"),hash:n.sha3_384},"SHA3-512":{oid:(0,r.hexToBytes)("060960864801650304020A"),hash:n.sha3_512},"SHAKE-128":{oid:(0,r.hexToBytes)("060960864801650304020B"),hash:e=>(0,n.shake128)(e,{dkLen:32})},"SHAKE-256":{oid:(0,r.hexToBytes)("060960864801650304020C"),hash:e=>(0,n.shake256)(e,{dkLen:64})}}}(Z)),Z}function oe(){if(Q)return X;Q=1,Object.defineProperty(X,"__esModule",{value:!0}),X.XOF256=X.XOF128=X.genCrystals=void 0;const e=Y(),t=re();function n(e,t=8){const n=e.toString(2).padStart(8,"0").slice(-t).padStart(7,"0").split("").reverse().join("");return Number.parseInt(n,2)}X.genCrystals=e=>{const{newPoly:r,N:o,Q:a,F:i,ROOT_OF_UNITY:s,brvBits:c,isKyber:u}=e,l=(e,t=a)=>{const n=e%t|0;return 0|(n>=0?n:t+n)};const f=function(){const e=r(o);for(let t=0;t<o;t++){const r=n(t,c),o=BigInt(s)**BigInt(r)%BigInt(a);e[t]=0|Number(o)}return e}(),d=u?128:o,h=u?1:0,p={encode:e=>{for(let t=1,n=128;n>h;n>>=1)for(let r=0;r<o;r+=2*n){const o=f[t++];for(let t=r;t<r+n;t++){const r=l(o*e[t+n]);e[t+n]=0|l(e[t]-r),e[t]=0|l(e[t]+r)}}return e},decode:e=>{for(let t=d-1,n=1+h;n<d+h;n<<=1)for(let r=0;r<o;r+=2*n){const o=f[t--];for(let t=r;t<r+n;t++){const r=e[t];e[t]=l(r+e[t+n]),e[t+n]=l(o*(e[t+n]-r))}}for(let t=0;t<e.length;t++)e[t]=l(i*e[t]);return e}};return{mod:l,smod:(e,t=a)=>{const n=0|l(e,t);return 0|(n>t>>1?n-t:n)},nttZetas:f,NTT:p,bitsCoder:(e,n)=>{const a=(0,t.getMask)(e),i=e*(o/8);return{bytesLen:i,encode:r=>{const o=new Uint8Array(i);for(let i=0,s=0,c=0,u=0;i<r.length;i++)for(s|=(n.encode(r[i])&a)<<c,c+=e;c>=8;c-=8,s>>=8)o[u++]=s&(0,t.getMask)(c);return o},decode:t=>{const i=r(o);for(let r=0,o=0,s=0,c=0;r<t.length;r++)for(o|=t[r]<<s,s+=8;s>=e;s-=e,o>>=e)i[c++]=n.decode(o&a);return i}}}}};const r=e=>(t,n)=>{n||(n=e.blockLen);const r=new Uint8Array(t.length+2);r.set(t);const o=t.length,a=new Uint8Array(n);let i=e.create({}),s=0,c=0;return{stats:()=>({calls:s,xofs:c}),get:(t,n)=>(r[o+0]=t,r[o+1]=n,i.destroy(),i=e.create({}).update(r),s++,()=>(c++,i.xofInto(a))),clean:()=>{i.destroy(),a.fill(0),r.fill(0)}}};return X.XOF128=r(e.shake128),X.XOF256=r(e.shake256),X}function ae(){return z||(z=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.ml_kem1024=e.ml_kem768=e.ml_kem512=e.PARAMS=void 0;const t=Y(),n=G(),r=oe(),o=re(),a=256,i=3329,{mod:s,nttZetas:c,NTT:u,bitsCoder:l}=(0,r.genCrystals)({N:a,Q:i,F:3303,ROOT_OF_UNITY:17,newPoly:e=>new Uint16Array(e),brvBits:7,isKyber:!0});e.PARAMS={512:{N:a,Q:i,K:2,ETA1:3,ETA2:2,du:10,dv:4,RBGstrength:128},768:{N:a,Q:i,K:3,ETA1:2,ETA2:2,du:10,dv:4,RBGstrength:192},1024:{N:a,Q:i,K:4,ETA1:2,ETA2:2,du:11,dv:5,RBGstrength:256}};const f=e=>l(e,(e=>{if(e>=12)return{encode:e=>e,decode:e=>e};const t=2**(e-1);return{encode:t=>((t<<e)+i/2)/i,decode:n=>n*i+t>>>e}})(e));function d(e,t){for(let n=0;n<a;n++)e[n]=s(e[n]+t[n])}function h(e,t){for(let i=0;i<128;i++){let u=c[64+(i>>1)];1&i&&(u=-u);const{c0:l,c1:f}=(n=e[2*i+0],r=e[2*i+1],o=t[2*i+0],a=t[2*i+1],{c0:s(r*a*u+n*o),c1:s(n*a+r*o)});e[2*i+0]=l,e[2*i+1]=f}var n,r,o,a;return e}function p(e){const t=new Uint16Array(a);for(let n=0;n<a;){const r=e();if(r.length%3)throw new Error("SampleNTT: unaligned block");for(let e=0;n<a&&e+3<=r.length;e+=3){const o=4095&(r[e+0]|r[e+1]<<8),s=4095&(r[e+1]>>4|r[e+2]<<4);o<i&&(t[n++]=o),n<a&&s<i&&(t[n++]=s)}}return t}function y(e,t,r,o){const i=e(o*a/4,t,r),c=new Uint16Array(a),u=(0,n.u32)(i);let l=0;for(let e=0,t=0,n=0,r=0;e<u.length;e++){let a=u[e];for(let e=0;e<32;e++)n+=1&a,a>>=1,l+=1,l===o?(r=n,n=0):l===2*o&&(c[t++]=s(r-n),n=0,l=0)}if(l)throw new Error(`sampleCBD: leftover bits: ${l}`);return c}const v=e=>{const{K:t,PRF:n,XOF:r,HASH512:i,ETA1:c,ETA2:l,du:v,dv:m}=e,g=f(1),E=f(m),b=f(v),A=(0,o.splitCoder)((0,o.vecCoder)(f(12),t),32),_=(0,o.vecCoder)(f(12),t),w=(0,o.splitCoder)((0,o.vecCoder)(b,t),E),O=(0,o.splitCoder)(32,32);return{secretCoder:_,secretKeyLen:_.bytesLen,publicKeyLen:A.bytesLen,cipherTextLen:w.bytesLen,keygen:e=>{(0,o.ensureBytes)(e,32);const a=new Uint8Array(33);a.set(e),a[32]=t;const s=i(a),[l,f]=O.decode(s),v=[],m=[];for(let e=0;e<t;e++)v.push(u.encode(y(n,f,e,c)));const g=r(l);for(let e=0;e<t;e++){const r=u.encode(y(n,f,t+e,c));for(let n=0;n<t;n++){d(r,h(p(g.get(n,e)),v[n]))}m.push(r)}g.clean();const E={publicKey:A.encode([m,l]),secretKey:_.encode(v)};return(0,o.cleanBytes)(l,f,v,m,a,s),E},encrypt:(e,i,s)=>{const[f,v]=A.decode(e),m=[];for(let e=0;e<t;e++)m.push(u.encode(y(n,s,e,c)));const E=r(v),b=new Uint16Array(a),_=[];for(let e=0;e<t;e++){const r=y(n,s,t+e,l),o=new Uint16Array(a);for(let n=0;n<t;n++){d(o,h(p(E.get(e,n)),m[n]))}d(r,u.decode(o)),_.push(r),d(b,h(f[e],m[e])),o.fill(0)}E.clean();const O=y(n,s,2*t,l);d(O,u.decode(b));const D=g.decode(i);return d(D,O),(0,o.cleanBytes)(f,m,b,O),w.encode([_,D])},decrypt:(e,n)=>{const[r,i]=w.decode(e),c=_.decode(n),l=new Uint16Array(a);for(let e=0;e<t;e++)d(l,h(c[e],u.encode(r[e])));return function(e,t){for(let n=0;n<a;n++)e[n]=s(e[n]-t[n])}(i,u.decode(l)),(0,o.cleanBytes)(l,c,r),g.encode(i)}}};function m(e){const t=v(e),{HASH256:n,HASH512:r,KDF:a}=e,{secretCoder:i,cipherTextLen:s}=t,c=t.publicKeyLen,u=(0,o.splitCoder)(t.secretKeyLen,t.publicKeyLen,32,32),l=u.bytesLen;return{publicKeyLen:c,msgLen:32,keygen:(e=(0,o.randomBytes)(64))=>{(0,o.ensureBytes)(e,64);const{publicKey:r,secretKey:a}=t.keygen(e.subarray(0,32)),i=n(r),s=u.encode([a,r,i,e.subarray(32)]);return(0,o.cleanBytes)(a,i),{publicKey:r,secretKey:s}},encapsulate:(a,s=(0,o.randomBytes)(32))=>{(0,o.ensureBytes)(a,c),(0,o.ensureBytes)(s,32);const u=a.subarray(0,384*e.K),l=i.encode(i.decode(u.slice()));if(!(0,o.equalBytes)(l,u))throw(0,o.cleanBytes)(l),new Error("ML-KEM.encapsulate: wrong publicKey modulus");(0,o.cleanBytes)(l);const f=r.create().update(s).update(n(a)).digest(),d=t.encrypt(a,s,f.subarray(32,64));return f.subarray(32).fill(0),{cipherText:d,sharedSecret:f.subarray(0,32)}},decapsulate:(e,n)=>{(0,o.ensureBytes)(n,l),(0,o.ensureBytes)(e,s);const[i,c,f,d]=u.decode(n),h=t.decrypt(e,i),p=r.create().update(h).update(f).digest(),y=p.subarray(0,32),v=t.encrypt(c,h,p.subarray(32,64)),m=(0,o.equalBytes)(e,v),g=a.create({dkLen:32}).update(d).update(e).digest();return(0,o.cleanBytes)(h,v,m?g:y),m?y:g}}}const g={HASH256:t.sha3_256,HASH512:t.sha3_512,KDF:t.shake256,XOF:r.XOF128,PRF:function(e,n,r){return t.shake256.create({dkLen:e}).update(n).update(new Uint8Array([r])).digest()}};e.ml_kem512=m({...g,...e.PARAMS[512]}),e.ml_kem768=m({...g,...e.PARAMS[768]}),e.ml_kem1024=m({...g,...e.PARAMS[1024]})}(M)),M}var ie,se,ce,ue={};function le(){return ie||(ie=1,function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.ml_dsa87=e.ml_dsa65=e.ml_dsa44=e.PARAMS=void 0;const t=Y(),n=oe(),r=re(),o=256,a=8380417,i=13,s=0|Math.floor(95232),c=0|Math.floor(261888);e.PARAMS={2:{K:4,L:4,D:i,GAMMA1:2**17,GAMMA2:s,TAU:39,ETA:2,OMEGA:80},3:{K:6,L:5,D:i,GAMMA1:2**19,GAMMA2:c,TAU:49,ETA:4,OMEGA:55},5:{K:8,L:7,D:i,GAMMA1:2**19,GAMMA2:c,TAU:60,ETA:2,OMEGA:75}};const u=e=>new Int32Array(e),{mod:l,smod:f,NTT:d,bitsCoder:h}=(0,n.genCrystals)({N:o,Q:a,F:8347681,ROOT_OF_UNITY:1753,newPoly:u,isKyber:!1,brvBits:8}),p=e=>e,y=(e,t=p,n=p)=>h(e,{encode:e=>t(n(e)),decode:e=>n(t(e))}),v=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=l(e[n]+t[n]);return e},m=(e,t)=>{for(let n=0;n<e.length;n++)e[n]=l(e[n]-t[n]);return e},g=e=>{for(let t=0;t<o;t++)e[t]<<=i;return e},E=(e,t)=>{for(let n=0;n<o;n++)if(Math.abs(f(e[n]))>=t)return!0;return!1},b=(e,t)=>{const n=u(o);for(let r=0;r<e.length;r++)n[r]=l(e[r]*t[r]);return n};function A(e){const t=u(o);for(let n=0;n<o;){const r=e();if(r.length%3)throw new Error("RejNTTPoly: unaligned block");for(let e=0;n<o&&e<=r.length-3;e+=3){const o=8388607&(r[e+0]|r[e+1]<<8|r[e+2]<<16);o<a&&(t[n++]=o)}}return t}function _(e){const{K:n,L:i,GAMMA1:h,GAMMA2:p,TAU:_,ETA:w,OMEGA:O}=e,{CRH_BYTES:D,TR_BYTES:S,C_TILDE_BYTES:T,XOF128:C,XOF256:x}=e;if(![2,4].includes(w))throw new Error("Wrong ETA");if(![1<<17,1<<19].includes(h))throw new Error("Wrong GAMMA1");if(![s,c].includes(p))throw new Error("Wrong GAMMA2");const I=_*w,N=e=>{const t=l(e),n=0|f(t,2*p);if(t-n==a-1)return{r1:0,r0:n-1|0};return{r1:0|Math.floor((t-n)/(2*p)),r0:n}},P=e=>N(e).r1,k=e=>N(e).r0,R=(e,t)=>{const n=Math.floor((a-1)/(2*p)),{r1:r,r0:o}=N(t);return 1===e?o>0?0|l(r+1,n):0|l(r-1,n):0|r},M=e=>{const t=l(e),n=0|f(t,8192);return{r1:0|Math.floor((t-n)/8192),r0:n}},F={bytesLen:O+n,encode:e=>{if(!1===e)throw new Error("hint.encode: hint is false");const t=new Uint8Array(O+n);for(let r=0,a=0;r<n;r++){for(let n=0;n<o;n++)0!==e[r][n]&&(t[a++]=n);t[O+r]=a}return t},decode:e=>{const t=[];let r=0;for(let a=0;a<n;a++){const n=u(o);if(e[O+a]<r||e[O+a]>O)return!1;for(let t=r;t<e[O+a];t++){if(t>r&&e[t]<=e[t-1])return!1;n[e[t]]=1}r=e[O+a],t.push(n)}for(let t=r;t<O;t++)if(0!==e[t])return!1;return t}},L=y(2===w?3:4,(e=>w-e),(e=>{if(!(-w<=e&&e<=w))throw new Error(`malformed key s1/s3 ${e} outside of ETA range [${-w}, ${w}]`);return e})),H=y(13,(e=>4096-e)),K=y(10),j=y(h===1<<17?18:20,(e=>f(h-e))),U=y(p===s?6:4),B=(0,r.vecCoder)(U,n),V=(0,r.splitCoder)(32,(0,r.vecCoder)(K,n)),G=(0,r.splitCoder)(32,32,S,(0,r.vecCoder)(L,i),(0,r.vecCoder)(L,n),(0,r.vecCoder)(H,n)),Y=(0,r.splitCoder)(T,(0,r.vecCoder)(j,i),F),J=2===w?e=>e<15&&2-e%5:e=>e<9&&4-e;function q(e){const t=u(o);for(let n=0;n<o;){const r=e();for(let e=0;n<o&&e<r.length;e+=1){const a=J(15&r[e]),i=J(r[e]>>4&15);!1!==a&&(t[n++]=a),n<o&&!1!==i&&(t[n++]=i)}}return t}const W=e=>{const n=u(o),r=t.shake256.create({}).update(e),a=new Uint8Array(t.shake256.blockLen);r.xofInto(a);const i=a.slice(0,8);for(let e=o-_,s=8,c=0,u=0;e<o;e++){let o=e+1;for(;o>e;)o=a[s++],s<t.shake256.blockLen||(r.xofInto(a),s=0);n[e]=n[o],n[o]=1-((i[c]>>u++&1)<<1),u>=8&&(c++,u=0)}return n},Q=e=>{const t=u(o),n=u(o);for(let r=0;r<e.length;r++){const{r0:o,r1:a}=M(e[r]);t[r]=o,n[r]=a}return{r0:t,r1:n}},z=(e,t)=>{for(let n=0;n<o;n++)e[n]=R(t[n],e[n]);return e},X=(e,t)=>{const n=u(o);let r=0;for(let c=0;c<o;c++){const o=(i=e[c],s=t[c],i<=p||i>a-p||i===a-p&&0===s?0:1);n[c]=o,r+=o}var i,s;return{v:n,cnt:r}},Z=(0,r.splitCoder)(32,64,32),$={signRandBytes:32,keygen:e=>{const a=new Uint8Array(34),s=void 0===e;s&&(e=(0,r.randomBytes)(32)),(0,r.ensureBytes)(e,32),a.set(e),s&&e.fill(0),a[32]=n,a[33]=i;const[c,l,f]=Z.decode((0,t.shake256)(a,{dkLen:Z.bytesLen})),h=x(l),p=[];for(let e=0;e<i;e++)p.push(q(h.get(255&e,e>>8&255)));const y=[];for(let e=i;e<i+n;e++)y.push(q(h.get(255&e,e>>8&255)));const m=p.map((e=>d.encode(e.slice()))),g=[],E=[],_=C(c),w=u(o);for(let e=0;e<n;e++){w.fill(0);for(let t=0;t<i;t++){const n=A(_.get(t,e));v(w,b(n,m[t]))}d.decode(w);const{r0:t,r1:n}=Q(v(w,y[e]));g.push(t),E.push(n)}const O=V.encode([c,E]),D=(0,t.shake256)(O,{dkLen:S}),T=G.encode([c,f,D,p,y,g]);return _.clean(),h.clean(),(0,r.cleanBytes)(c,l,f,p,y,m,w,g,E,D,a),{publicKey:O,secretKey:T}},sign:(e,a,s,c=!1)=>{const[l,f,y,g,_,w]=G.decode(e),S=[],N=C(l);for(let e=0;e<n;e++){const t=[];for(let n=0;n<i;n++)t.push(A(N.get(n,e)));S.push(t)}N.clean();for(let e=0;e<i;e++)d.encode(g[e]);for(let e=0;e<n;e++)d.encode(_[e]),d.encode(w[e]);const R=c?a:t.shake256.create({dkLen:D}).update(y).update(a).digest(),M=s||new Uint8Array(32);(0,r.ensureBytes)(M);const F=t.shake256.create({dkLen:D}).update(f).update(M).update(R).digest();(0,r.ensureBytes)(F,D);const L=x(F,j.bytesLen);e:for(let e=0;;){const a=[];for(let t=0;t<i;t++,e++)a.push(j.decode(L.get(255&e,e>>8)()));const s=a.map((e=>d.encode(e.slice()))),c=[];for(let e=0;e<n;e++){const t=u(o);for(let n=0;n<i;n++)v(t,b(S[e][n],s[n]));d.decode(t),c.push(t)}const l=c.map((e=>e.map(P))),f=t.shake256.create({dkLen:T}).update(R).update(B.encode(l)).digest(),y=d.encode(W(f)),A=g.map((e=>b(e,y)));for(let e=0;e<i;e++)if(v(d.decode(A[e]),a[e]),E(A[e],h-I))continue e;let D=0;const C=[];for(let e=0;e<n;e++){const t=d.decode(b(_[e],y)),n=m(c[e],t).map(k);if(E(n,p-I))continue e;const r=d.decode(b(w[e],y));if(E(r,p))continue e;v(n,r);const o=X(n,l[e]);C.push(o.v),D+=o.cnt}if(D>O)continue;L.clean();const x=Y.encode([f,A,C]);return(0,r.cleanBytes)(f,A,C,y,l,c,s,a,F,R,g,_,w,...S),x}throw new Error("Unreachable code path reached, report this error")},verify:(e,a,s,c=!1)=>{const[l,f]=V.decode(e),p=(0,t.shake256)(e,{dkLen:S});if(s.length!==Y.bytesLen)return!1;const[y,_,w]=Y.decode(s);if(!1===w)return!1;for(let e=0;e<i;e++)if(E(_[e],h-I))return!1;const x=c?a:t.shake256.create({dkLen:D}).update(p).update(a).digest(),N=d.encode(W(y)),P=_.map((e=>e.slice()));for(let e=0;e<i;e++)d.encode(P[e]);const k=[],R=C(l);for(let e=0;e<n;e++){const t=b(d.encode(g(f[e])),N),n=u(o);for(let t=0;t<i;t++){const r=A(R.get(t,e));v(n,b(r,P[t]))}const r=d.decode(m(n,t));k.push(z(r,w[e]))}R.clean();const M=t.shake256.create({dkLen:T}).update(x).update(B.encode(k)).digest();for(const e of w){if(!(e.reduce(((e,t)=>e+t),0)<=O))return!1}for(const e of _)if(E(e,h-I))return!1;return(0,r.equalBytes)(y,M)}};return{internal:$,keygen:$.keygen,signRandBytes:$.signRandBytes,sign:(e,t,n=r.EMPTY,o)=>{const a=(0,r.getMessage)(t,n),i=$.sign(e,a,o);return a.fill(0),i},verify:(e,t,n,o=r.EMPTY)=>$.verify(e,(0,r.getMessage)(t,o),n),prehash:e=>({sign:(t,n,o=r.EMPTY,a)=>{const i=(0,r.getMessagePrehash)(e,n,o),s=$.sign(t,i,a);return i.fill(0),s},verify:(t,n,o,a=r.EMPTY)=>$.verify(t,(0,r.getMessagePrehash)(e,n,a),o)})}}e.ml_dsa44=_({...e.PARAMS[2],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:32,XOF128:n.XOF128,XOF256:n.XOF256}),e.ml_dsa65=_({...e.PARAMS[3],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:48,XOF128:n.XOF128,XOF256:n.XOF256}),e.ml_dsa87=_({...e.PARAMS[5],CRH_BYTES:64,TR_BYTES:64,C_TILDE_BYTES:64,XOF128:n.XOF128,XOF256:n.XOF256})}(ue)),ue}var fe,de,he={exports:{}};function pe(){return fe||(fe=1,function(e){e.exports=function(e,t,n,r,o,a,i,s){function c(e){var t=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],n=1779033703,r=3144134277,o=1013904242,a=2773480762,i=1359893119,s=2600822924,c=528734635,u=1541459225,l=new Array(64);function f(e){for(var f=0,d=e.length;d>=64;){var h,p,y,v,m,g=n,E=r,b=o,A=a,_=i,w=s,O=c,D=u;for(p=0;p<16;p++)y=f+4*p,l[p]=(255&e[y])<<24|(255&e[y+1])<<16|(255&e[y+2])<<8|255&e[y+3];for(p=16;p<64;p++)v=((h=l[p-2])>>>17|h<<15)^(h>>>19|h<<13)^h>>>10,m=((h=l[p-15])>>>7|h<<25)^(h>>>18|h<<14)^h>>>3,l[p]=(v+l[p-7]|0)+(m+l[p-16]|0)|0;for(p=0;p<64;p++)v=(((_>>>6|_<<26)^(_>>>11|_<<21)^(_>>>25|_<<7))+(_&w^~_&O)|0)+(D+(t[p]+l[p]|0)|0)|0,m=((g>>>2|g<<30)^(g>>>13|g<<19)^(g>>>22|g<<10))+(g&E^g&b^E&b)|0,D=O,O=w,w=_,_=A+v|0,A=b,b=E,E=g,g=v+m|0;n=n+g|0,r=r+E|0,o=o+b|0,a=a+A|0,i=i+_|0,s=s+w|0,c=c+O|0,u=u+D|0,f+=64,d-=64}}f(e);var d,h=e.length%64,p=e.length/536870912|0,y=e.length<<3,v=h<56?56:120,m=e.slice(e.length-h,e.length);for(m.push(128),d=h+1;d<v;d++)m.push(0);return m.push(p>>>24&255),m.push(p>>>16&255),m.push(p>>>8&255),m.push(p>>>0&255),m.push(y>>>24&255),m.push(y>>>16&255),m.push(y>>>8&255),m.push(y>>>0&255),f(m),[n>>>24&255,n>>>16&255,n>>>8&255,n>>>0&255,r>>>24&255,r>>>16&255,r>>>8&255,r>>>0&255,o>>>24&255,o>>>16&255,o>>>8&255,o>>>0&255,a>>>24&255,a>>>16&255,a>>>8&255,a>>>0&255,i>>>24&255,i>>>16&255,i>>>8&255,i>>>0&255,s>>>24&255,s>>>16&255,s>>>8&255,s>>>0&255,c>>>24&255,c>>>16&255,c>>>8&255,c>>>0&255,u>>>24&255,u>>>16&255,u>>>8&255,u>>>0&255]}function u(e,t,n){e=e.length<=64?e:c(e);var r,o=64+t.length+4,a=new Array(o),i=new Array(64),s=[];for(r=0;r<64;r++)a[r]=54;for(r=0;r<e.length;r++)a[r]^=e[r];for(r=0;r<t.length;r++)a[64+r]=t[r];for(r=o-4;r<o;r++)a[r]=0;for(r=0;r<64;r++)i[r]=92;for(r=0;r<e.length;r++)i[r]^=e[r];function u(){for(var e=o-1;e>=o-4;e--){if(a[e]++,a[e]<=255)return;a[e]=0}}for(;n>=32;)u(),s=s.concat(c(i.concat(c(a)))),n-=32;return n>0&&(u(),s=s.concat(c(i.concat(c(a))).slice(0,n))),s}function l(e,t,n,r){var o,a,i=e[0]^t[n++],s=e[1]^t[n++],c=e[2]^t[n++],u=e[3]^t[n++],l=e[4]^t[n++],f=e[5]^t[n++],d=e[6]^t[n++],h=e[7]^t[n++],p=e[8]^t[n++],y=e[9]^t[n++],v=e[10]^t[n++],m=e[11]^t[n++],g=e[12]^t[n++],E=e[13]^t[n++],b=e[14]^t[n++],A=e[15]^t[n++],_=i,w=s,O=c,D=u,S=l,T=f,C=d,x=h,I=p,N=y,P=v,k=m,R=g,M=E,F=b,L=A;for(a=0;a<8;a+=2)_^=(o=(R^=(o=(I^=(o=(S^=(o=_+R)<<7|o>>>25)+_)<<9|o>>>23)+S)<<13|o>>>19)+I)<<18|o>>>14,T^=(o=(w^=(o=(M^=(o=(N^=(o=T+w)<<7|o>>>25)+T)<<9|o>>>23)+N)<<13|o>>>19)+M)<<18|o>>>14,P^=(o=(C^=(o=(O^=(o=(F^=(o=P+C)<<7|o>>>25)+P)<<9|o>>>23)+F)<<13|o>>>19)+O)<<18|o>>>14,L^=(o=(k^=(o=(x^=(o=(D^=(o=L+k)<<7|o>>>25)+L)<<9|o>>>23)+D)<<13|o>>>19)+x)<<18|o>>>14,_^=(o=(D^=(o=(O^=(o=(w^=(o=_+D)<<7|o>>>25)+_)<<9|o>>>23)+w)<<13|o>>>19)+O)<<18|o>>>14,T^=(o=(S^=(o=(x^=(o=(C^=(o=T+S)<<7|o>>>25)+T)<<9|o>>>23)+C)<<13|o>>>19)+x)<<18|o>>>14,P^=(o=(N^=(o=(I^=(o=(k^=(o=P+N)<<7|o>>>25)+P)<<9|o>>>23)+k)<<13|o>>>19)+I)<<18|o>>>14,L^=(o=(F^=(o=(M^=(o=(R^=(o=L+F)<<7|o>>>25)+L)<<9|o>>>23)+R)<<13|o>>>19)+M)<<18|o>>>14;t[r++]=e[0]=_+i|0,t[r++]=e[1]=w+s|0,t[r++]=e[2]=O+c|0,t[r++]=e[3]=D+u|0,t[r++]=e[4]=S+l|0,t[r++]=e[5]=T+f|0,t[r++]=e[6]=C+d|0,t[r++]=e[7]=x+h|0,t[r++]=e[8]=I+p|0,t[r++]=e[9]=N+y|0,t[r++]=e[10]=P+v|0,t[r++]=e[11]=k+m|0,t[r++]=e[12]=R+g|0,t[r++]=e[13]=M+E|0,t[r++]=e[14]=F+b|0,t[r++]=e[15]=L+A|0}function f(e,t,n,r,o){for(;o--;)e[t++]=n[r++]}function d(e,t,n,r,o){for(;o--;)e[t++]^=n[r++]}function h(e,t,n,r,o){f(e,0,t,n+16*(2*o-1),16);for(var a=0;a<2*o;a+=2)l(e,t,n+16*a,r+8*a),l(e,t,n+16*a+16,r+8*a+16*o)}function p(e,t,n){return e[t+16*(2*n-1)]}function y(e){for(var t=[],n=0;n<e.length;n++){var r=e.charCodeAt(n);r<128?t.push(r):r>127&&r<2048?(t.push(r>>6|192),t.push(63&r|128)):(t.push(r>>12|224),t.push(r>>6&63|128),t.push(63&r|128))}return t}if(n<1||n>31)throw new Error("scrypt: logN not be between 1 and 31");var v,m,g,E,b=1<<n>>>0;if(1*r>=1<<30||r>16777216||r>8388608||b>16777216/r)throw new Error("scrypt: parameters are too large");"string"==typeof e&&(e=y(e)),"string"==typeof t&&(t=y(t)),"undefined"!=typeof Int32Array?(v=new Int32Array(64*r),m=new Int32Array(32*b*r),E=new Int32Array(16)):(v=[],m=[],E=new Array(16)),g=u(e,t,128*r);var A=32*r;function _(){for(var e=0;e<32*r;e++){var t=4*e;v[0+e]=(255&g[t+3])<<24|(255&g[t+2])<<16|(255&g[t+1])<<8|255&g[t+0]}}function w(e,t){for(var n=e;n<t;n+=2)f(m,n*(32*r),v,0,32*r),h(E,v,0,A,r),f(m,(n+1)*(32*r),v,A,32*r),h(E,v,A,0,r)}function O(e,t){for(var n=e;n<t;n+=2){var o=p(v,0,r)&b-1;d(v,0,m,o*(32*r),32*r),h(E,v,0,A,r),o=p(v,A,r)&b-1,d(v,A,m,o*(32*r),32*r),h(E,v,A,0,r)}}function D(){for(var e=0;e<32*r;e++){var t=v[0+e];g[4*e+0]=t>>>0&255,g[4*e+1]=t>>>8&255,g[4*e+2]=t>>>16&255,g[4*e+3]=t>>>24&255}}var S="undefined"!=typeof setImmediate?setImmediate:setTimeout;function T(e,t,n,r,o){!function a(){S((function(){r(e,e+n<t?e+n:t),(e+=n)<t?a():o()}))}()}function C(t){var n=u(e,g,o);return"base64"===t?function(e){for(var t,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(""),r=e.length,o=[],a=0;a<r;)t=((a<r?e[a++]:0)<<16)+((a<r?e[a++]:0)<<8)+(a<r?e[a++]:0),o.push(n[t>>>18&63]),o.push(n[t>>>12&63]),o.push(n[t>>>6&63]),o.push(n[t>>>0&63]);return r%3>0&&(o[o.length-1]="=",r%3==1&&(o[o.length-2]="=")),o.join("")}(n):"hex"===t?function(e){for(var t="0123456789abcdef".split(""),n=e.length,r=[],o=0;o<n;o++)r.push(t[e[o]>>>4&15]),r.push(t[e[o]>>>0&15]);return r.join("")}(n):n}"function"==typeof a&&(s=i,i=a,a=1e3),a<=0?(_(),w(0,b),O(0,b),D(),i(C(s))):(_(),T(0,b,2*a,w,(function(){T(0,b,2*a,O,(function(){D(),i(C(s))}))})))}}(he)),he.exports}function ye(){return de||(de=1,function(e){var t;t=function(e,t,n,r){var o={Nacl:e,PQC:n},a=t.encodeBase64,i=e=>{let n;return(n=e.length%4)&&(e+="=".repeat(4-n)),t.decodeBase64(e)},s=t.decodeUTF8,c=t.encodeUTF8,u=function(e){for(var t="",n=0;n<e.length;n++)e[n]<16&&(t+="0"),t+=e[n].toString(16);return t},l=function(e,t){if(!e||!t)throw new Error("Both NaCl and KEM keys required for key derivation");var n=new Uint8Array(32);return r(Array.from(f([e,t])),Array.from(s("CryptPad.mailbox.pqc.salt")),8,1024,128,200,(function(e){for(var t=0;t<e.length;t++)n[t]=e[t]}),"binary"),n},f=function(e){var t=0;e.forEach((function(e){t+=e.length}));var n=new Uint8Array(t),r=0;return e.forEach((function(e){n.set(e,r),r+=e.length})),n},d=function(e,t,n){return new Uint8Array(Array.prototype.slice.call(e,t,n))},h=function(t,n){if(!o.PQC||!o.PQC.ml_kem||!o.PQC.ml_kem.ml_kem512)return null;try{var r;r=t?64===t.length?t:e.hash(t).subarray(0,64):e.randomBytes(64);var a=o.PQC.ml_kem.ml_kem512.keygen(r);return{publicKey:a.publicKey,secretKey:a.secretKey}}catch(e){return console.error("[chainpad-crypto."+n+"] failed to generate PQC KEM keys",e),null}},p=function(t,n){if(!o.PQC||!o.PQC.ml_dsa||!o.PQC.ml_dsa.ml_dsa44)return null;try{var r;r=t?32===t.length?t:e.hash(t).subarray(0,32):e.randomBytes(32);var a=o.PQC.ml_dsa.ml_dsa44.internal.keygen(r);return{publicKey:a.publicKey,secretKey:a.secretKey}}catch(e){return console.error("[chainpad-crypto."+n+"] failed to generate PQC DSA keys",e),null}},y=function(e,t,n,r){return t&&(e[n||"kemPublic"]=a(t.publicKey),e[r||"kemPrivate"]=a(t.secretKey)),e},v=function(e,t,n,r){return t&&(e[n||"dsaPublic"]=a(t.publicKey),e[r||"dsaPrivate"]=a(t.secretKey)),e},m=function(e,t){if(!o.PQC||!o.PQC.ml_kem||!o.PQC.ml_kem.ml_kem512)return null;try{var n=e,r=o.PQC.ml_kem.ml_kem512.encapsulate(n);return{sharedSecret:r.sharedSecret,cipherText:r.cipherText}}catch(e){return console.error("[chainpad-crypto."+(t||"kemEncapsulate")+"] failed to encapsulate with KEM",e),null}},g=function(e,t,n){if(!o.PQC||!o.PQC.ml_kem||!o.PQC.ml_kem.ml_kem512)return null;try{var r=e,a=t;return o.PQC.ml_kem.ml_kem512.decapsulate(r,a)}catch(e){return console.error("[chainpad-crypto."+(n||"kemDecapsulate")+"] failed to decapsulate KEM",e),null}},E=function(e,t,n){if(!o.PQC||!o.PQC.ml_dsa||!o.PQC.ml_dsa.ml_dsa44)return null;try{var r=t,a=e;return o.PQC.ml_dsa.ml_dsa44.sign(a,r)}catch(e){return console.error("[chainpad-crypto."+(n||"dsaSign")+"] failed to sign with DSA",e),null}},b=function(e,t,n,r){if(!o.PQC||!o.PQC.ml_dsa||!o.PQC.ml_dsa.ml_dsa44)return!1;try{var a=e,i=t,s=n;return o.PQC.ml_dsa.ml_dsa44.verify(a,i,s)}catch(e){return console.error("[chainpad-crypto."+(r||"dsaVerify")+"] failed to verify DSA signature",e),!1}},A=o.CryptoAgility={};A.decodeBase64=i,A.encodeBase64=a,A.decodeUTF8=s,A.encodeUTF8=c,A.generateKemKeypair=h,A.generateDsaKeypair=p,A.addKemKeysToResult=y,A.addDsaKeysToResult=v,A.kemDecapsulate=g,A.kemEncapsulate=m,A.dsaSign=E,A.dsaVerify=b,A.signKeyPairFromSeed=function(t){return e.sign.keyPair.fromSeed(t)},A.signKeyPairFromSecretKey=function(t){return e.sign.keyPair.fromSecretKey(t)},A.signKeyPair=function(){return e.sign.keyPair()},A.sign=function(t,n){return e.sign(t,n)},A.signOpen=function(t,n){return e.sign.open(t,n)},A.signDetached=function(t,n){return e.sign.detached(t,n)},A.verifyDetached=function(t,n,r){return e.sign.detached.verify(n,t,r)},A.curveKeyPair=function(){return e.box.keyPair()},A.box=function(t,n,r,o){return e.box(t,n,r,o)},A.boxOpen=function(t,n,r,o){return e.box.open(t,n,r,o)},A.boxKeyPairFromSecretKey=function(t){return e.box.keyPair.fromSecretKey(t)},A.secretbox=function(t,n,r){return e.secretbox(t,n,r)},A.secretboxOpen=function(t,n,r){return e.secretbox.open(t,n,r)},A.createHash=function(t){return e.hash(t)},A.bytes=function(t){return e.randomBytes(t)},A.boxNonceLength=function(){return e.box.nonceLength},A.signSeedLength=function(){return e.sign.seedLength},A.boxKeyLength=function(){return e.box.publicKeyLength},A.secretboxKeyLength=function(){return e.secretbox.keyLength},A.secretboxNonceLength=function(){return e.secretbox.nonceLength},A.signKeyLength=function(){return e.sign.publicKeyLength};var _=o.Box={};_.encrypt=function(t,n,r,o){return e.box(t,n,r,o)},_.decrypt=function(t,n,r,o){return e.box.open(t,n,r,o)},_.encryptAfter=function(t,n,r){return e.box.after(t,n,r)},_.decryptAfter=function(t,n,r){return e.box.open.after(t,n,r)},_.getSharedSecret=function(t,n){return e.box.before(t,n)};var w=o.SecretBox={};w.encrypt=function(t,n,r){return e.secretbox(t,n,r)},w.decrypt=function(t,n,r){return e.secretbox.open(t,n,r)};var O=o.Sign={};O.sign=function(t,n){return e.sign(t,n)},O.verify=function(t,n){return e.sign.open(t,n)},O.detached=function(t,n){return e.sign.detached(t,n)},O.verifyDetached=function(t,n,r){return e.sign.detached.verify(n,t,r)};var D=o.encrypt=function(e,t){return function(e,t){var n=s(e),r=A.bytes(24),o=w.encrypt(n,r,t);if(!o)throw new Error;return a(r)+"|"+a(o)}(e,t)},S=o.decrypt=function(e,t){return function(e,t){var n=e.split("|");if(2!==n.length)throw new Error;var r=i(n[0]),o=i(n[1]),a=w.decrypt(o,r,t);if(!a)throw new Error;return c(a)}(e,t)},T=o.parseKey=function(e){try{var t=i(e),n=A.createHash(t),r=n.subarray(32);return{lookupKey:r,cryptKey:n.subarray(0,32),channel:a(r).substring(0,10)}}catch(e){throw console.error("[chainpad-crypto.parseKey] invalid string supplied"),e}},C=o.rand64=function(e){return a(A.bytes(e))};o.genKey=function(){return C(18)};var x=function(e){return a(e).replace(/\//g,"-").replace(/=+$/g,"")},I=function(e){return i(e.replace(/\-/g,"/"))};o.b64RemoveSlashes=function(e){return e.replace(/\//g,"-")},o.b64AddSlashes=function(e){return e.replace(/\-/g,"/")},o.createEncryptor=function(t){var n;if("object"==typeof t){var r={};if(!(n=t.cryptKey))throw new Error("NO_DECRYPTION_KEY_PROVIDED");if(t.signKey){var u=i(t.signKey),l=t.dsaPrivate?i(t.dsaPrivate):null,d=t.dsaPublic?i(t.dsaPublic):null,h=o.PQC?.ml_dsa?.ml_dsa44,p=2484;r.encrypt=function(t){var r=s(D(t,n));if(l&&h)try{var i=o.CryptoAgility.dsaSign(l,r),c=e.sign(r,u);return a(f([c.subarray(0,64),i,r]))}catch(e){console.warn("PQC signature failed, using classical:",e)}return a(e.sign(r,u))}}return r.decrypt=function(t,r,a){if(!r&&!a)throw new Error("UNSUPPORTED_DECRYPTION_CONFIGURATION");var s,u=i(t),l=u.length>=p&&d&&h;if(a||"string"!=typeof r)s=u.subarray(l?p:64);else if(l)try{var y=u.subarray(0,64),v=u.subarray(64,p),m=u.subarray(p);if(!o.CryptoAgility.dsaVerify(d,m,v))return null;s=e.sign.open(f([y,m]),i(r))}catch(e){return null}else s=e.sign.open(u,i(r));return s?S(c(s),n):null},r}return n=T(t).cryptKey,{encrypt:function(e){return D(e,n)},decrypt:function(e){return S(e,n)}}},o.createEditCryptor=function(t,n){try{if(!t){if(n&&18!==n.length)throw new Error("expected supplied seed to have length of 18");n||(n=e.randomBytes(18)),t=a(n)}var r=e.hash(i(t)),o=e.sign.keyPair.fromSeed(r.subarray(0,32)),s=r.subarray(32,64),c={editKeyStr:t,signKey:a(o.secretKey),validateKey:a(o.publicKey),cryptKey:s,viewKeyStr:x(s)},u=h(r,"createEditCryptor");c=y(c,u);var l=p(o.secretKey,"createEditCryptor");return c=v(c,l)}catch(e){throw console.error("[chainpad-crypto.createEditCryptor] invalid string supplied"),e}},o.createViewCryptor=function(e){try{if(!e)throw new Error("Cannot open a new pad in read-only mode!");var t=i(e),n={cryptKey:t,viewKeyStr:e},r=h(t,"createViewCryptor");return n=y(n,r)}catch(e){throw console.error("[chainpad-crypto.createViewCryptor] invalid string supplied"),e}};var N=o.createViewCryptor2=function(t,n){try{if(!t)throw new Error("Cannot open a new pad in read-only mode!");var r=I(t),o=r;if(n){var i=s(n);(o=new Uint8Array(r.length+i.length)).set(i),o.set(r,i.length)}var c=e.hash(o),u=c.subarray(0,16),l=c.subarray(16,48),d=e.sign.keyPair.fromSeed(c.subarray(32,64)),m={viewKeyStr:t,cryptKey:l,chanId:x(u),secondarySignKey:a(d.secretKey),secondaryValidateKey:a(d.publicKey)},g=h(f([c,o]),"createViewCryptor2");m=y(m,g);var E=p(f([c.subarray(32,64),o]),"createViewCryptor2");return m=v(m,E)}catch(e){throw console.error("[chainpad-crypto.createViewCryptor2] invalid string supplied"),e}};o.createEditCryptor2=function(t,n,r){try{if(!t){if(n&&18!==n.length)throw new Error("expected supplied seed to have length of 18");n||(n=e.randomBytes(18)),t=x(n)}n||(n=I(t));var o=n;if(r){var i=s(r);(o=new Uint8Array(n.length+i.length)).set(i),o.set(n,i.length)}var c=e.hash(o),u=e.sign.keyPair.fromSeed(c.subarray(0,32)),l=e.hash(u.secretKey).subarray(0,e.secretbox.keyLength),f=c.subarray(32,64),d=x(f),h=N(d,r),y={editKeyStr:t,viewKeyStr:d,signKey:a(u.secretKey),validateKey:a(u.publicKey),cryptKey:h.cryptKey,secondaryKey:a(l),chanId:h.chanId,secondarySignKey:h.secondarySignKey,secondaryValidateKey:h.secondaryValidateKey};h.kemPublic&&(y.kemPublic=h.kemPublic,y.kemPrivate=h.kemPrivate),h.secondaryDsaKey&&(y.secondaryDsaKey=h.secondaryDsaKey,y.secondaryDsaValidateKey=h.secondaryDsaValidateKey);var m=p(c.subarray(0,32),"createEditCryptor2");return y=v(y,m)}catch(e){throw console.error("[chainpad-crypto.createEditCryptor2] invalid string supplied"),e}},o.createFileCryptor2=function(t,n){try{var r;t||(r=e.randomBytes(18),t=x(r)),r||(r=I(t));var o=r;if(n){var a=s(n);(o=new Uint8Array(r.length+a.length)).set(a),o.set(r,a.length)}var i=e.hash(o),c=i.subarray(0,24),u={fileKeyStr:t,cryptKey:i.subarray(24,56),chanId:x(c)},l=h(f([i,o]),"createFileCryptor2");u=y(u,l);var d=p(f([i.subarray(56,64),o]),"createFileCryptor2");return u=v(u,d)}catch(e){throw console.error("[chainpad-crypto.createFileCryptor2] invalid string supplied"),e}};var P=o.Curve={};P.encrypt=function(t,n){var r=s(t),o=e.randomBytes(24),i=e.box.after(r,o,n);return a(o)+"|"+a(i)},P.decrypt=function(t,n){var r=t.split("|"),o=i(r[0]),a=i(r[1]),s=e.box.open.after(a,o,n);return s?c(s):null},P.signAndEncrypt=function(t,n,r,i){var c=P.encrypt(t,n),u=s(c);if(i&&o.PQC&&o.PQC.ml_dsa&&o.PQC.ml_dsa.ml_dsa44)try{var l=e.sign(u,r),d=E(i,u),h=f([l,d]);return a(h)}catch(e){console.warn("ML-DSA signing failed, using only NaCl:",e)}return a(e.sign(u,r))},P.openSigned=function(t,n,r,a){var s=i(t),u=2420;if(s.length>=2484&&a&&o.PQC&&o.PQC.ml_dsa&&o.PQC.ml_dsa.ml_dsa44)try{var l=d(s,0,64+s.length-64-u),f=d(s,s.length-u),h=d(s,64,s.length-u);return e.sign.open(l,r)&&b(a,h,f)?P.decrypt(c(h),n):null}catch(e){return console.error("PQC signature verification failed:",e),null}var p=s.subarray(64);return P.decrypt(c(p),n)},P.deriveKeys=function(t,n,r,c){try{const u=i(t),l=i(n),d=e.box.before(u,l);let h=d;if(r&&c&&o.PQC?.ml_kem?.ml_kem512)try{const t=i(r),n=i(c),o=e.hash(f([d,u,l.subarray(0,32),t,n.subarray(0,32)])),a=e.hash(o).subarray(0,32);h=f([d,a])}catch(e){console.warn("PQC key exchange failed, using classical-only:",e)}const y=s("CryptPad.signingKeyGenerationSalt"),v=e.hash(f([y,h])),m=e.sign.keyPair.fromSeed(v.subarray(0,32)),g=v.subarray(32,64),E={cryptKey:a(g),signKey:a(m.secretKey),validateKey:a(m.publicKey)};if(o.PQC?.ml_dsa?.ml_dsa44)try{const t=s("CryptPad.curve.pqcSalt"),n=e.hash(f([h,t])).subarray(0,32),r=p(n,"deriveKeys");r&&(E.dsaPrivate=a(r.secretKey),E.dsaPublic=a(r.publicKey))}catch(e){console.error("Failed to generate PQC signature keys:",e)}return E}catch(e){return console.error("Failed to derive keys:",e),null}},P.createEncryptor=function(e){if(!e||"object"!=typeof e)return console.error("invalid input for createEncryptor"),{encrypt:function(){throw new Error("Invalid encryptor: keys missing or malformed")},decrypt:function(){throw new Error("Invalid encryptor: keys missing or malformed")}};var t,n,r,o,a;try{t=i(e.cryptKey),n=i(e.signKey),r=i(e.validateKey),o=e.dsaPrivate?i(e.dsaPrivate):void 0,a=e.dsaPublic?i(e.dsaPublic):void 0}catch(e){return console.error("Failed to decode keys for createEncryptor:",e),{encrypt:function(){throw new Error("Invalid encryptor: failed to decode keys")},decrypt:function(){throw new Error("Invalid encryptor: failed to decode keys")}}}return{encrypt:function(e){return P.signAndEncrypt(e,t,n,o)},decrypt:function(e){return P.openSigned(e,t,r,a)}}};var k=o.Mailbox={},R=function(t,n){var r=e.randomBytes(e.box.nonceLength),a=e.box(t,r,n.their_public,n.my_private),i=f([r,n.my_public,a]);if(n.their_kem_public&&o.PQC&&o.PQC.ml_kem&&o.PQC.ml_kem.ml_kem512)try{const t=m(n.their_kem_public,"pqc_asymmetric_encrypt");if(!t||!t.sharedSecret||!t.cipherText)throw new Error("[PQC] Encapsulate failed: result is undefined or incomplete");var s=t.sharedSecret,c=t.cipherText;if(!s||32!==s.length)throw new Error("[PQC] Internal encapsulate failed to return sharedSecret");var u=e.box.before(n.their_public,n.my_private),d=l(u,s),h=e.randomBytes(e.secretbox.nonceLength),p=e.secretbox(i,h,d);i=f([new Uint8Array([1]),c,h,p])}catch(e){console.warn("[PQC] Encryption failed, falling back to traditional:",e),i=f([new Uint8Array([0]),i])}else i=f([new Uint8Array([0]),i]);var y=new Uint8Array(i);return y.content=y,y.author=n.my_public,y.author_kem=n.my_kem_public,y},M=function(t,n){var r=t[0],a=d(t,1);if(1===r&&n.my_kem_private&&o.PQC&&o.PQC.ml_kem&&o.PQC.ml_kem.ml_kem512)try{var i=d(a,0,768),s=d(a,768,768+e.secretbox.nonceLength),c=d(a,768+e.secretbox.nonceLength),u=g(i,n.my_kem_private,"pqc_asymmetric_decrypt"),f=e.box.before(n.their_public,n.my_private),h=l(f,u),p=e.secretbox.open(c,s,h);if(!p)throw new Error("Failed to decrypt PQC layer");a=p}catch(e){throw new Error("E_PQC_DECRYPTION_FAILURE")}var y=d(a,0,e.box.nonceLength),v=d(a,e.box.nonceLength,e.box.nonceLength+e.box.publicKeyLength),m=d(a,e.box.nonceLength+e.box.publicKeyLength),E=e.box.open(m,y,v,n.my_private);if(!E)throw new Error("E_DECRYPTION_FAILURE");var b=new Uint8Array(E);return b.content=b,b.author=v,b.author_kem=n.my_kem_public,b},F=function(t,n){var r=2420;if(t.length>=2484&&n.dsaPublic&&o.PQC&&o.PQC.ml_dsa&&o.PQC.ml_dsa.ml_dsa44)try{var a=d(t,0,64+t.length-64-r),i=d(t,t.length-r),s=d(t,64,t.length-r);return e.sign.open(a,n.validateKey)&&b(n.dsaPublic,s,i,"pqc_verify_signature")?s:null}catch(e){return console.error("PQC signature verification failed:",e),null}return e.sign.open(t,n.validateKey)},L=k.sealSecretLetter=function(t,n){var r=s(t),i=R(r,{their_public:n.their_public,their_kem_public:n.their_kem_public,my_private:n.my_private,my_public:n.my_public,my_kem_private:n.my_kem_private,my_kem_public:n.my_kem_public}),c=n.ephemeral_keypair||e.box.keyPair(),u=n.ephemeral_kem_keypair||h(),l=R(i,{their_public:n.their_public,their_kem_public:n.their_kem_public,my_private:c.secretKey,my_public:c.publicKey,my_kem_private:u.secretKey,my_kem_public:u.publicKey});return n.signingKey&&(l=function(t,n){var r=e.sign(t,n.signingKey);if(n.dsaPrivate&&o.PQC&&o.PQC.ml_dsa&&o.PQC.ml_dsa.ml_dsa44)try{var a=E(n.dsaPrivate,t,"pqc_sign_message");if(a)return f([r,a])}catch(e){console.warn("ML-DSA signing failed, using only NaCl:",e)}return r}(l,{signingKey:n.signingKey,dsaPrivate:n.dsaPrivate})),a(l)};k.openOwnSecretLetter=function(e,t){var n=i(e);if(t.validateKey&&!(n=F(n,{validateKey:t.validateKey,dsaPublic:t.dsaPublic})))throw new Error("E_SIGNATURE_VERIFICATION_FAILED");var r=M(n,{my_private:t.ephemeral_private,my_kem_private:t.ephemeral_kem_private,their_public:t.their_public}),o=M(r.content,{my_private:t.my_private,my_kem_private:t.my_kem_private,their_public:t.their_public});return{content:c(o.content),author:a(o.author)}};var H=k.openSecretLetter=function(e,t){var n=i(e);if(t.validateKey&&!(n=F(n,{validateKey:t.validateKey,dsaPublic:t.dsaPublic})))throw new Error("E_SIGNATURE_VERIFICATION_FAILED");var r=M(n,{my_private:t.my_private,my_kem_private:t.my_kem_private,their_public:t.their_public}),o=M(r.content,{my_private:t.my_private,my_kem_private:t.my_kem_private,their_public:t.their_public});return{content:c(o.content),author:a(o.author)}};k.createEncryptor=function(e){if(e&&"object"==typeof e){["curvePublic","curvePrivate"].forEach((function(t){if("string"!=typeof e[t])throw console.log(t),new Error("Expected key was not present")}));var t=i(e.curvePrivate),n=i(e.curvePublic),r=e.kemPrivate?i(e.kemPrivate):void 0,o=e.kemPublic?i(e.kemPublic):void 0,a=e.signingKey?i(e.signingKey):void 0,s=e.validateKey?i(e.validateKey):void 0,c=e.dsaPrivate?i(e.dsaPrivate):void 0,u=e.dsaPublic?i(e.dsaPublic):void 0;return{encrypt:function(s,u,l){var f=i(u),d=l?i(l):void 0;try{return L(s,{signingKey:a,dsaPrivate:c,ephemeral_keypair:e.ephemeral_keypair,ephemeral_kem_keypair:e.ephemeral_kem_keypair,their_public:f,their_kem_public:d,my_private:t,my_kem_private:r,my_public:n,my_kem_public:o})}catch(e){return console.error(e),null}},decrypt:function(e){try{return H(e,{validateKey:s,dsaPublic:u,my_private:t,my_kem_private:r})}catch(e){return console.error(e),null}}}}console.error("invalid Mailbox.createEncryptor keys")};var K=o.Team={},j=function(t,n){var r=s(t),i=R(r,{their_public:n.team_curve_public,their_kem_public:n.team_kem_public,my_private:n.my_curve_private,my_public:n.my_curve_public,my_kem_private:n.my_kem_private,my_kem_public:n.my_kem_public}),c=e.box.keyPair(),u=null;if(o.PQC&&o.PQC.ml_kem&&o.PQC.ml_kem.ml_kem512)try{u=h()}catch(e){console.error("[PQC] Failed to generate ephemeral KEM keypair:",e)}var l,d=R(i,{their_public:n.team_curve_public,their_kem_public:n.team_kem_public,my_private:c.secretKey,my_public:c.publicKey,my_kem_private:u?.secretKey,my_kem_public:u?.publicKey});if(u?.publicKey&&"object"==typeof d&&d.author instanceof Uint8Array&&(d={content:d.content,author:d.author,author_kem:u.publicKey}),n.team_dsa_private&&o.PQC&&o.PQC.ml_dsa&&o.PQC.ml_dsa.ml_dsa44)try{const t=(l=d)instanceof Uint8Array?l:l.u8_bundle||l.content||new Uint8Array(l),r=e.sign(t,n.team_ed_private),o=E(n.team_dsa_private,t);return a(f([r,o]))}catch(t){return console.error("[PQC] Failed to create hybrid team signature, falling back to classical:",t),a(e.sign(d,n.team_ed_private))}return a(e.sign(d,n.team_ed_private))},U={teamCurvePublic:"team_curve_public",teamCurvePrivate:"team_curve_private",teamKemPrivate:"team_kem_private",teamKemPublic:"team_kem_public",myCurvePublic:"my_curve_public",myCurvePrivate:"my_curve_private",myKemPublic:"my_kem_public",myKemPrivate:"my_kem_private",teamEdPublic:"team_ed_public",teamEdPrivate:"team_ed_private",teamDsaPublic:"team_dsa_public",teamDsaPrivate:"team_dsa_private"},B=function(t){var n=e.hash(t);return[d(n,0,32),d(n,32)]},V=function(t){var n=B(t),r=e.box.keyPair.fromSecretKey(n[0]),i=d(n[1],0,16),s=null;if(o.PQC&&o.PQC.ml_kem&&o.PQC.ml_kem.ml_kem512)try{var c=e.hash(f([n[0],t]));s=h(c)}catch(e){console.error("Failed to generate post-quantum KEM keys for team:",e),s=null}var l={channel:u(i),teamCurvePublic:a(r.publicKey),teamCurvePrivate:a(r.secretKey),viewKeyStr:o.b64RemoveSlashes(a(t))};return s&&(l.teamKemPublic=a(s.publicKey),l.teamKemPrivate=a(s.secretKey)),l};K.deriveGuestKeys=function(e){var t=performance?.now?.()||Date.now(),n=V(i(o.b64AddSlashes(e)));return J(t,"Team.deriveGuestKeys"),n},K.createSeed=function(){var t=performance?.now?.()||Date.now(),n=o.b64AddSlashes(a(e.randomBytes(18)));return J(t,"Team.createSeed"),n},K.deriveMemberKeys=function(t,n){var r,s,c=performance?.now?.()||Date.now();try{if((r=i(o.b64AddSlashes(t))).length<18)throw new Error("INVALID_SEED")}catch(e){throw e}if(s=n,!Boolean(s.curvePublic&&i(s.curvePublic).length===e.box.publicKeyLength&&s.curvePrivate&&i(s.curvePrivate).length===e.box.secretKeyLength&&(!s.kemPublic||800===i(s.kemPublic).length)&&(!s.kemPrivate||1632===i(s.kemPrivate).length)))throw new Error("INVALID_OWN_KEYS");var u=B(r),l=e.sign.keyPair.fromSeed(u[0]),d=null;if(o.PQC&&o.PQC.ml_dsa&&o.PQC.ml_dsa.ml_dsa44)try{var h=e.hash(f([u[0],r])).subarray(0,32);d=p(h)}catch(e){console.error("Failed to generate post-quantum DSA keys for team:",e),d=null}var y,v,m,g=V(u[1]),E=(y={myCurvePublic:n.curvePublic,myCurvePrivate:n.curvePrivate,teamEdPrivate:a(l.secretKey),teamEdPublic:a(l.publicKey),myKemPublic:n.kemPublic,myKemPrivate:n.kemPrivate,teamDsaPrivate:a(d?.secretKey),teamDsaPublic:a(d?.publicKey)},v=g,m=JSON.parse(JSON.stringify(y)),Object.keys(v).forEach((function(e){m[e]=v[e]})),m);return J(c,"Team.deriveMemberKeys"),E},K.createEncryptor=function(t){var n=performance?.now?.()||Date.now(),r={};Object.keys(U).forEach((function(e){if(t[e])try{r[U[e]]=i(t[e])}catch(t){throw console.log(e),new Error("INVALID_KEY_SUPPLIED")}}));var s,u={};if(s=r,Boolean(s.my_curve_private&&s.my_curve_private.length===e.box.secretKeyLength&&s.my_curve_public&&s.my_curve_public.length===e.box.publicKeyLength&&s.team_curve_public&&s.team_curve_public.length===e.box.publicKeyLength&&(!o.PQC||!o.PQC.ml_kem||!o.PQC.ml_kem.ml_kem512||s.my_kem_private&&1632===s.my_kem_private.length&&s.my_kem_public&&800===s.my_kem_public.length&&s.team_kem_public&&800===s.team_kem_public.length)&&s.team_ed_private&&s.team_ed_private.length===e.sign.secretKeyLength&&(!o.PQC||!o.PQC.ml_dsa||!o.PQC.ml_dsa.ml_dsa44||s.team_dsa_private&&2560===s.team_dsa_private.length))&&(u.encrypt=function(e){var t=performance?.now?.()||Date.now();try{var n=j(e,r);return J(t,"Team.createEncryptor.encrypt"),n}catch(e){return console.error(e),J(t,"Team.createEncryptor.encrypt"),null}}),function(t){return Boolean(t.team_curve_private&&t.team_curve_private.length===e.box.secretKeyLength&&(!o.PQC||!o.PQC.ml_kem||!o.PQC.ml_kem.ml_kem512||t.team_kem_private&&1632===t.team_kem_private.length)&&t.team_ed_public&&t.team_ed_public.length===e.sign.publicKeyLength)}(r)&&(u.decrypt=function(t,n){var s=performance?.now?.()||Date.now();try{var u=function(t,n,r){var s,u=i(t),l=2420,f=u.length>2484&&n.team_dsa_public&&o.PQC&&o.PQC.ml_dsa&&o.PQC.ml_dsa.ml_dsa44;if(!0===r)s=d(u,64);else if(f)try{var h=d(u,0,u.length-l);if(!(s=e.sign.open(h,n.team_ed_public)))throw new Error("Classical signature verification failed");var p=d(u,u.length-l);if(!b(n.team_dsa_public,s,p))throw new Error("Post-quantum signature verification failed")}catch(t){if(console.error("Hybrid signature verification failed:",t),null===(s=e.sign.open(u,n.team_ed_public)))throw new Error("E_VALIDATION_FAILURE")}else if(null===(s=e.sign.open(u,n.team_ed_public)))throw new Error("E_VALIDATION_FAILURE");var y=M(s,{my_private:n.team_curve_private,my_kem_private:n.team_kem_private,their_public:n.team_curve_public,sender_public:n.team_kem_public}),v=M(y.content,{my_private:n.team_curve_private,my_kem_private:n.team_kem_private,their_public:y.author,sender_public:y.author_kem});return{content:c(v.content),author:a(v.author)}}(t,r,n);return J(s,"Team.createEncryptor.decrypt"),u}catch(e){return console.error(e),J(s,"Team.createEncryptor.decrypt"),null}}),0===Object.keys(u).length)throw new Error("INVALID_TEAM_CONFIGURATION");return J(n,"Team.createEncryptor"),u};var G=[],Y=0;function J(e,t){const n=(performance?.now?.()||Date.now())-e;Y+=n,G.push({fnName:t,deltaMs:n});const r=(n/1e3).toFixed(4),o=(Y/1e3).toFixed(4);console.log(`[Team timing] ${t}: +${r}s, cumulative: ${o}s`),console.log("[Team timing] Operation times:",G)}return o},e.exports?e.exports=t(h(),w(),ce?se:(ce=1,se={ml_kem:ae(),ml_dsa:le(),utils:re()}),pe()):window.chainpad_crypto=t(window.nacl,window.PostQuantum,window.scrypt)}(R)),R.exports}var ve,me=ye(),ge={exports:{}};function Ee(){return ve||(ve=1,function(e){e.exports&&(e.exports=((e={})=>{var t={setCustomize:t=>{e=t.ApiConfig},getWebsocketURL:function(t){var n=e.websocketPath||"/cryptpad_websocket";if(/^ws{1,2}:\/\//.test(n))return n;var r=new URL(t||globalThis?.location?.href||e.httpUnsafeOrigin);return t&&(r.href=t),r.protocol.replace(/http/,"ws")+"//"+r.host+n}};return t})())}(ge)),ge.exports}var be,Ae=Ee(),_e=t({__proto__:null,default:r(Ae)},[Ae]),we={exports:{}};function Oe(){return be||(be=1,function(e){e.exports&&(e.exports=function(e={}){return{setCustomize:t=>{e=t.AppConfig},userHashKey:"User_hash",userNameKey:"User_name",blockHashKey:"Block_hash",fileHashKey:"FS_hash",sessionJWT:"Session_JWT",ssoSeed:"SSO_seed",displayNameKey:"cryptpad.username",oldStorageKey:"CryptPad_RECENTPADS",storageKey:"filesData",tokenKey:"loginToken",prefersDriveRedirectKey:"prefersDriveRedirect",isPremiumKey:"isPremiumUser",displayPadCreationScreen:"displayPadCreationScreen",deprecatedKey:"deprecated",MAX_TEAMS_SLOTS:e.maxTeamsSlots||5,MAX_TEAMS_OWNED:e.maxOwnedTeams||5,MAX_PREMIUM_TEAMS_SLOTS:Math.max(e.maxTeamsSlots||0,e.maxPremiumTeamsSlots||0)||5,MAX_PREMIUM_TEAMS_OWNED:Math.max(e.maxOwnedTeams||0,e.maxPremiumTeamsOwned||0)||5,criticalApps:["profile","settings","debug","admin","support","notifications","calendar","moderation","oldadmin"],earlyAccessApps:[]}}(void 0))}(we)),we.exports}var De,Se=Oe(),Te=t({__proto__:null,default:r(Se)},[Se]),Ce={exports:{}},xe={exports:{}},Ie=xe.exports;function Ne(){return De||(De=1,function(e){!function(t){const n=e=>{var n=t.CryptPad_Util={};t.atob=t.atob||function(e){return Buffer.from(e,"base64").toString("binary")},t.btoa=t.btoa||function(e){return Buffer.from(e,"binary").toString("base64")},n.encodeBase64=e.CryptoAgility.encodeBase64,n.decodeBase64=e.CryptoAgility.decodeBase64,n.encodeUTF8=e.CryptoAgility.encodeUTF8,n.decodeUTF8=e.CryptoAgility.decodeUTF8,n.slice=function(e,t,n){return Array.prototype.slice.call(e,t,n)},n.u8ToBase64=(e,t)=>{const n=new FileReader;n.onload=()=>{let e=n.result,r=e.slice(e.indexOf(",")+1);t(r)},n.readAsDataURL(new Blob([e]))},n.shuffleArray=function(e){for(var t=e.length-1;t>0;t--){var n=Math.floor(Math.random()*(t+1)),r=e[t];e[t]=e[n],e[n]=r}},n.bake=function(e,t){return void 0===t&&(t=[]),Array.isArray(t)||(t=[t]),function(){return e.apply(null,t)}},n.both=function(e,t){if("function"!=typeof e)throw new Error("INVALID_USAGE");return"function"!=typeof t&&(t=function(e){return e}),function(){return e.apply(null,arguments),t.apply(null,arguments)}},n.clone=function(e){return null==e?e:JSON.parse(JSON.stringify(e))},n.serializeError=function(e){if(!(e instanceof Error))return e;var t={};return Object.getOwnPropertyNames(e).forEach((function(n){t[n]=e[n]})),t},n.tryParse=function(e){try{return JSON.parse(e)}catch(e){return}},n.mkAsync=function(e,t){if("function"!=typeof e)throw new Error("EXPECTED_FUNCTION");return function(){var n=Array.prototype.slice.call(arguments);setTimeout((function(){e.apply(null,n)}),t)}},n.mkEvent=function(e){var t=[],n=!1;let r;return{reg:function(r){e&&n?setTimeout(r):t.push(r)},unreg:function(e){-1!==t.indexOf(e)?t.splice(t.indexOf(e),1):console.log("event handler was already unregistered")},fire:function(){if(!e||!n){var o=Array.prototype.slice.call(arguments);n||r.apply(null,o),n=!0,t.forEach((function(e){e.apply(null,o)}))}},promise:new Promise((e=>{r=e}))}},n.mkTimeout=function(e,t){t=t||0;var r=n.once(e),o=setTimeout((function(){r("TIMEOUT")}),t);return n.both(r,(function(){clearTimeout(o)}))},n.onClickEnter=function(e,t,n){e.on("click keydown",(function(e){var r="click"===e.type,o="keydown"===e.type&&13===e.which,a="keydown"===e.type&&32===e.which&&n&&n.space;(r||o||a)&&("keydown"===e.type&&e.preventDefault(),t(e))}))},n.response=function(e){var t={},n={};"function"!=typeof e&&(e=function(e){throw new Error(e)});var r=function(e){clearTimeout(n[e]),delete n[e],delete t[e]};return{clear:r,expected:function(e){return Boolean(t[e])},expectation:function(e){return t[e]},expect:function(o,a,i){"string"!=typeof o&&e("EXPECTED_STRING"),"function"!=typeof a&&e("EXPECTED_CALLBACK"),t[o]=a,"number"==typeof i&&i&&(n[o]=setTimeout((function(){"function"==typeof t[o]&&t[o]("TIMEOUT"),r(o)}),i))},handle:function(n,o){var a=t[n];if("function"==typeof a){try{a.apply(null,Array.isArray(o)?o:[o])}catch(t){e("HANDLER_ERROR",{error:t,id:n,args:o})}r(n)}else e("MISSING_CALLBACK",{id:n,args:o})},_pending:t}},n.inc=function(e,t,n){e[t]=(e[t]||0)+("number"==typeof n?n:1)},n.values=function(e){return Object.keys(e).map((function(t){return e[t]}))},n.find=function(e,t){for(var n=t.length,r=0;r<n;r++){if(void 0===e[t[r]])return;e=e[t[r]]}return e},n.uid=function(){return Number(Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)).toString(32).replace(/\./g,"")},n.guid=function(e){var t=n.uid();return void 0===e[t]?t:n.guid(e)},n.fixHTML=function(e){return e?e.replace(/[<>&"']/g,(function(e){return{"<":"<",">":">","&":"&",'"':""","'":"'"}[e]})):""},n.hexToBase64=function(e){var n=e.replace(/\r|\n/g,"").replace(/([\da-fA-F]{2}) ?/g,"0x$1 ").replace(/ +$/,"").split(" "),r=String.fromCharCode.apply(null,n);return t.btoa(r).replace(/\//g,"-").replace(/=+$/,"")},n.base64ToHex=function(e){var n=[];return t.atob(e.replace(/-/g,"/")).split("").forEach((function(e){var t=e.charCodeAt(0).toString(16);1===t.length&&(t="0"+t),n.push(t)})),n.join("")},n.uint8ArrayToHex=function(e){for(var t="",n=0;n<e.length;n++)e[n]<16&&(t+="0"),t+=e[n].toString(16);return t},n.hexToUint8Array=function(e){for(var t=new Uint8Array(Math.ceil(e.length/2)),n=0;n<t.length;n++)t[n]=parseInt(e.substr(2*n,2),16);return t},n.uint8ArrayJoin=function(e){for(var t=0,n=0;n<e.length;n++)t+=e[n].length;var r=new Uint8Array(t);n=0;for(var o=0;n<e.length;n++)r.set(e[n],o),o+=e[n].length;return r},n.escapeKeyCharacters=function(e){return e&&e.replace&&e.replace(/\//g,"-")},n.unescapeKeyCharacters=function(e){return e.replace(/\-/g,"/")},n.deduplicateString=function(e){for(var t=e.slice(),n=0;n<t.length;n++)for(var r=n+1;r<t.length;r++)t[n]===t[r]&&t.splice(r--,1);return t},n.fixFileName=function(e){return e.replace(/ /g,"-").replace(/[\/\?]/g,"_").replace(/_+/g,"_")};var r=1048576,o=1073741824;n.bytesToGigabytes=function(e){return Math.ceil(e/o*100)/100},n.bytesToMegabytes=function(e){return Math.ceil(e/r*100)/100},n.bytesToKilobytes=function(e){return Math.ceil(e/1024*100)/100},n.magnitudeOfBytes=function(e){return e>=o?"GB":e>=r?"MB":"KB"};n.getBlock=function(e,t,r){var o=n.once(n.mkAsync(r)),a={};"string"==typeof t.bearer&&t.bearer&&(a.authorization=`Bearer ${t.bearer}`),fetch(e,{method:"GET",credentials:"include",headers:a}).then((e=>{e.ok?o(void 0,e):401!==e.status&&404!==e.status?o(e.status,e):e.json().then((t=>{o(e.status,t)})).catch((()=>{o(e.status)}))})).catch((e=>{o(e)}))},n.fetchApi=function(e,t,n,r){const o=new URL(e);o.pathname=`api/${t}`;let a=o.href+(n?"?"+ +new Date:"");if("undefined"!=typeof self&&self.crypto)fetch(a).then((e=>{if(!e.ok)throw new Error(`Fetch error: ${e.status}`);return e.text()})).then((e=>{r(JSON.parse(e.slice(27,-5)))})).catch((e=>{console.error(e.message),r({})}));else if(void 0!==l){("http:"===o.protocol?require("node:http"):require("node:https")).get(o.href,(e=>{let t="";e.on("data",(e=>{t+=e})),e.on("end",(()=>{try{r(JSON.parse(t.slice(27,-5)))}catch(e){console.error(e),r({})}}))}))}},n.fetch=function(e,t,r,o){var a,i=n.once(n.mkAsync(t)),s=function(e){var t=e.replace(/(\/)*$/,""),n=t.lastIndexOf("/"),r=t.slice(n+1);return/^[a-f0-9]{48}$/.test(r)||(r=void 0),r}(e),c=function(){(a=new XMLHttpRequest).open("GET",e,!0),r&&a.addEventListener("progress",(function(e){if(e.lengthComputable){var t=e.loaded/e.total;r(t)}}),!1),a.responseType="arraybuffer",a.onerror=function(e){i(e)},a.onload=function(){if(/^4/.test(""+this.status))return i("XHR_ERROR");var e=a.response;if(e){var t=new Uint8Array(e);return s?void function(e,t,n){o&&"function"==typeof o.setBlobCache?o.setBlobCache(e,t,n):n("EINVAL")}(s,t,(function(){i(null,t)})):void i(void 0,t)}i("ENOENT")},a.send(null)};if(s)return function(e,t){o&&"function"==typeof o.getBlobCache?o.getBlobCache(e,t):t("EINVAL")}(s,(function(e,t){!e&&t?i(void 0,t):c()})),{cancel:function(){a&&a.abort&&a.abort()}};c()},n.dataURIToBlob=function(e){for(var t=atob(e.split(",")[1]),n=e.split(",")[0].split(":")[1].split(";")[0],r=new ArrayBuffer(t.length),o=new Uint8Array(r),a=0;a<t.length;a++)o[a]=t.charCodeAt(a);return new Blob([r],{type:n})},n.throttle=function(e,t){var r,o,a=0,i=function(n){r=setTimeout((function(){r=void 0;var n=+new Date-a;n<t?i(t-n):e.apply(null,o)}),n)},s=function(){a=+new Date,o=n.slice(arguments),r||i(t)};return s.clear=function(){clearTimeout(r),r=void 0},s},n.notAgainForAnother=function(e,t){if("function"!=typeof e||"number"!=typeof t)throw new Error("invalid inputs");var r=null;return function(){var o=+new Date;return r&&o<=r+t?t-(o-r):(r=o,e.apply(null,n.slice(arguments)),null)}},n.createRandomInteger=function(){return Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)},n.noop=function(){},n.once=function(e,t){return function(){e&&(e.apply(this,Array.prototype.slice.call(arguments)),e=t)}},n.blobToImage=function(e,t){var n=new FileReader;n.onloadend=function(){t(n.result)},n.readAsDataURL(e)},n.blobURLToImage=function(e,t){var n=new XMLHttpRequest;n.onload=function(){var e=new FileReader;e.onloadend=function(){t(e.result)},e.readAsDataURL(n.response)},n.open("GET",e),n.responseType="blob",n.send()},n.isObject=function(e){return"object"==typeof e&&"[object Object]"===Object.prototype.toString.call(e)},n.isCircular=function(e){try{return JSON.stringify(e),!1}catch(e){return!0}},n.extend=function(e,t){if(n.isObject(e)&&n.isObject(t))if(n.isCircular(t))console.log("Extend doesn't accept circular objects");else for(var r in t)n.isObject(t[r])?(e[r]=n.isObject(e[r])?e[r]:{},n.extend(e[r],t[r])):Array.isArray(t[r])?e[r]=t[r].slice():e[r]=t[r];else console.log("Extend only works with 2 objects")},n.isChecked=function(e){return!!e&&(void 0!==e.tagName?Boolean(e.checked):"function"==typeof e.prop&&Boolean(e.prop("checked")))},n.hexToRGB=function(e){var t=e.replace(/^#/,"");return[parseInt(t.slice(0,2),16),parseInt(t.slice(2,4),16),parseInt(t.slice(4,6),16)]},n.rgbToHex=function(e){return`#${e.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/).slice(1).map((e=>parseInt(e,10).toString(16).padStart(2,"0"))).join("")}`},n.isSmallScreen=function(){return t.innerHeight<800||t.innerWidth<800},n.stripTags=function(e){var t=document.createElement("div");return t.innerHTML=e,t.innerText},n.parseFilename=function(e){if(!e||!e.trim())return{};var t=/^(\.?.+?)(\.[^.]+)?$/.exec(e)||[];return{name:t[1],ext:t[2]}},n.isPlainTextFile=function(e,t){if(e&&0===e.indexOf("text/"))return!0;var r=n.parseFilename(t);return!(e||!t||r.ext)||("application/x-javascript"===e||"application/xml"===e)},n.isSpreadsheet=function(e,t){return e&&("application/vnd.oasis.opendocument.spreadsheet"===e||"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"===e)||t&&(t.endsWith(".xlsx")||t.endsWith(".ods"))},n.isOfficeDoc=function(e,t){return e&&("application/vnd.oasis.opendocument.text"===e||"application/vnd.openxmlformats-officedocument.wordprocessingml.document"===e)||t&&(t.endsWith(".docx")||t.endsWith(".odt"))},n.isPresentation=function(e,t){return e&&("application/vnd.oasis.opendocument.presentation"===e||"application/vnd.openxmlformats-officedocument.presentationml.presentation"===e)||t&&(t.endsWith(".pptx")||t.endsWith(".odp"))},n.isValidURL=function(e){return!!new RegExp("^(https?:\\/\\/)((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?").test(e)};var a=/([\uD800-\uDBFF][\uDC00-\uDFFF])/;n.getFirstCharacter=function(e){if(!e||!e.trim())return"?";var t=function(e){for(var t=e.split(a),n=[],r=0;r<t.length;r++){var o=t[r];""!==o&&n.push(o)}return n}(e);return function(e){return a.test(e)}(t[0])?t[0]:e[0]},n.getRandomColor=function(e){var t=function(){return e?Math.floor(156*Math.random())+70:Math.floor(200*Math.random())+25};return"#"+t().toString(16)+t().toString(16)+t().toString(16)},n.checkRestrictedApp=function(e,t,n,r,o){if(Array.isArray(n)&&n.includes(e)&&!t.enableEarlyAccess)return-2;var a=t.premiumTypes;return Array.isArray(a)&&a.includes(e)?o?r?1:0:-1:2};return n.supportsWasm=function(){return!("undefined"==typeof Atomics||!function(){try{return"[object SharedArrayBuffer]"===Object.prototype.toString.call(new t.WebAssembly.Memory({shared:!0,initial:0,maximum:0}).buffer)}catch(e){console.error(e)}return!1}()||"undefined"==typeof WebAssembly)},n.getKeysArray=function(e){return[...Array(e).keys()]},n.getVersionFromUrlArgs=e=>{let t=/ver=([0-9.]+)(-[0-9]*)?/.exec(e);return Array.isArray(t)&&t[1]||void 0},n.Saferphore={create:e=>{var t,n=[];return t=function(){if(e<0)throw new Error("(resourceCount < 0) should never happen");var r;0!==e&&0!==n.length&&(e--,n.shift()((r=0,function(n){if(r++)throw new Error("returnAfter() called multiple times");var o=0;return function(){if(o++)throw new Error("returnAfter wrapped callback called multiple times");n&&n.apply(null,arguments),e++,t()}})))},{take:function(e){n.push(e),t()}}}},n};e.exports&&(e.exports=n(ye()))}("undefined"!=typeof self?self:Ie)}(xe)),xe.exports}var Pe,ke,Re={exports:{}};function Me(){return Pe||(Pe=1,function(e){e.exports&&(e.exports=function(){var e={},t=function(e){return e.replace(/-/g,"/")};return e.parseUser=function(e){var n,r,o,a=function(e){if(/^\[.*?@.*\]$/.test(e)){var n,r=e.slice(1,-1);if(r=r.replace(/\/([a-zA-Z0-9+-]{43}=)$/,(function(e,r){return n=t(r),""})),n){var o=r.lastIndexOf("@");if(!(o<1))return{domain:r.slice(o+1),user:r.slice(0,o),pubkey:n}}}}(e);if(function(e){if(e&&e.domain&&e.user&&e.pubkey)return!0}(a))return a;if(e.replace(/^https*:\/\/([^\/]+)\/user\/#\/1\/([^\/]+)\/([a-zA-Z0-9+-]{43}=)$/,(function(e,a,i,s){return n=a,r=i,o=t(s),""})),!n)throw new Error("Could not parse user id ["+e+"]");return{domain:n,user:r,pubkey:o}},e.serialize=function(e,t,n){return"["+t+"@"+e.replace(/https*:\/\//,"")+"/"+n.replace(/\//g,"-")+"]"},e.canonicalize=function(n){if("string"==typeof n){if(44===n.length)return t(n);try{return e.parseUser(n).pubkey}catch(e){return}}},e}())}(Re)),Re.exports}function Fe(){return ke||(ke=1,function(e){!function(t){e.exports&&(e.exports=function(e,n,r){var o=t.CryptPad_Hash={},a=e.uint8ArrayToHex,i=e.hexToBase64,s=e.base64ToHex;o.encodeBase64=e.encodeBase64,o.decodeBase64=e.decodeBase64,o.hashChannelList=function(t){return e.encodeBase64(n.CryptoAgility.createHash(e.decodeUTF8(JSON.stringify(t))))},o.generateSignPair=function(){var e=n.CryptoAgility.signKeyPair(),t=function(e){return n.b64RemoveSlashes(e).replace(/=+$/g,"")},r={validateKey:o.encodeBase64(e.publicKey),signKey:o.encodeBase64(e.secretKey),safeValidateKey:t(o.encodeBase64(e.publicKey)),safeSignKey:t(o.encodeBase64(e.secretKey))};if(n.PQC&&n.PQC.ml_dsa&&n.PQC.ml_dsa.ml_dsa44)try{var a=n.Nacl.hash(e.secretKey).subarray(0,32),i=n.CryptoAgility.generateDsaKeypair(a);r.dsaPublic=o.encodeBase64(i.publicKey),r.dsaPrivate=o.encodeBase64(i.secretKey),r.safeDsaPublic=t(o.encodeBase64(i.publicKey)),r.safeDsaPrivate=t(o.encodeBase64(i.secretKey))}catch(e){console.error("Failed to generate post-quantum DSA keys:",e)}return r},o.getSignPublicFromPrivate=function(t){var r=n.b64AddSlashes(t),o=e.decodeBase64(r),a=n.CryptoAgility.signKeyPairFromSecretKey(o);return e.encodeBase64(a.publicKey)},o.getCurvePublicFromPrivate=function(t){var r=n.b64AddSlashes(t),o=e.decodeBase64(r),a=n.CryptoAgility.boxKeyPairFromSecretKey(o);return e.encodeBase64(a.publicKey)};var c=o.getEditHashFromKeys=function(e){var t=e.version,r=e.keys;if(0===t)return e.channel+e.key;if(1===t){if(!r.editKeyStr)return;return"/1/edit/"+i(e.channel)+"/"+n.b64RemoveSlashes(r.editKeyStr)+"/"}if(2===t){if(!r.editKeyStr)return;var o=e.password?"p/":"";return"/2/"+e.type+"/edit/"+n.b64RemoveSlashes(r.editKeyStr)+"/"+o}},u=o.getViewHashFromKeys=function(e){var t=e.version,r=e.keys;if(0!==t){if(1===t){if(!r.viewKeyStr)return;return"/1/view/"+i(e.channel)+"/"+n.b64RemoveSlashes(r.viewKeyStr)+"/"}if(2===t){if(!r.viewKeyStr)return;var o=e.password?"p/":"";return"/2/"+e.type+"/view/"+n.b64RemoveSlashes(r.viewKeyStr)+"/"+o}}};o.getHiddenHashFromKeys=function(e,t,n){n=n||{};var r=t.keys&&t.keys.editKeyStr||t.key,a=!n.view&&r?"edit/":"view/",i=t.password?"p/":"";t.keys&&t.keys.fileKeyStr&&(a="");var s="/3/"+e+"/"+a+t.channel+"/"+i,c=o.parseTypeHash(e,s);return c&&c.getHash?c.getHash(n||{}):s};var l=o.getFileHashFromKeys=function(e){var t=e.version,r=e.keys;if(0!==t){if(1===t)return"/1/"+i(e.channel)+"/"+n.b64RemoveSlashes(r.fileKeyStr)+"/";if(2===t){if(!r.fileKeyStr)return;var o=e.password?"p/":"";return"/2/"+e.type+"/"+n.b64RemoveSlashes(r.fileKeyStr)+"/"+o}}};o.getPublicSigningKeyString=r.serialize,o.ephemeralChannelLength=34,o.createChannelId=function(e){var t=a(n.CryptoAgility.bytes(e?17:16));if(-1===[32,34].indexOf(t.length)||/[^a-f0-9]/.test(t))throw new Error("channel ids must consist of 32 hex characters");return t},o.getChannelIdFromKey=function(e){if(e)return a(o.decodeBase64(e).subarray(0,16))},o.getBoxPublicFromSecret=function(e){if(e){var t=o.decodeBase64(e),r=n.CryptoAgility.boxKeyPairFromSecretKey(t);return o.encodeBase64(r.publicKey)}},o.checkBoxKeyPair=function(e,t){if(!t||!e)return!1;var r=o.decodeBase64(e),a=n.CryptoAgility.boxKeyPairFromSecretKey(r);return t===o.encodeBase64(a.publicKey)},o.createRandomHash=function(e,t){var r;return"file"===e?(r=n.createFileCryptor2(void 0,t),l({password:Boolean(t),version:2,type:e,keys:r})):(r=n.createEditCryptor2(void 0,void 0,t),c({password:Boolean(t),version:2,type:e,keys:r}))};var f=o.parseTypeHash=function(e,t){if(t){var r,o=[],a={},i=(r=t,r.replace(/\/+/g,"/")).split("/"),s=function(){a.password=-1!==o.indexOf("p"),a.present=-1!==o.indexOf("present"),a.embed=-1!==o.indexOf("embed"),a.versionHash=function(e){var t;return e.some((function(e){if(/^hash=/.test(e))return t=e.slice(5),!0})),t?n.b64AddSlashes(t):""}(o),a.auditorKey=function(e){var t;return e.some((function(e){if(/^auditor=/.test(e))return t=e.slice(8),!0})),t?n.b64AddSlashes(t):""}(o),a.newPadOpts=function(e){var t;return e.some((function(e){if(/^newpad=/.test(e))return t=e.slice(7),!0})),t||""}(o),a.loginOpts=function(e){var t;return e.some((function(e){if(/^login=/.test(e))return t=e.slice(6),!0})),t||""}(o),a.ownerKey=function(e){var t;return e.some((function(e){if(86===e.length)return t=e,!0})),t}(o)};return i[1]&&"4"===i[1]?(a.getHash=function(t){if(!t||!Object.keys(t).length)return"";var n="/4/"+e+"/";return t.newPadOpts&&(n+="newpad="+t.newPadOpts+"/"),t.loginOpts&&(n+="login="+t.loginOpts+"/"),n},a.getOptions=function(){var e={};return a.newPadOpts&&(e.newPadOpts=a.newPadOpts),a.loginOpts&&(e.loginOpts=a.loginOpts),e},a.version=4,a.app=i[2],o=i.slice(3),s(),a):-1===["media","file","user","invite"].indexOf(e)?(a.type="pad",a.getHash=function(){return t},a.getOptions=function(){return{embed:a.embed,present:a.present,ownerKey:a.ownerKey,versionHash:a.versionHash,auditorKey:a.auditorKey,newPadOpts:a.newPadOpts,loginOpts:a.loginOpts,password:a.password}},"/"!==t.slice(0,1)&&t.length>=56?(a.channel=t.slice(0,32),a.key=t.slice(32,56),a.version=0,a):(a.getHash=function(e){var t=i.slice(0,5).join("/")+"/",r=void 0!==e.ownerKey?e.ownerKey:a.ownerKey;r&&(t+=r+"/"),(a.password||e.password)&&(t+="p/"),e.embed&&(t+="embed/"),e.present&&(t+="present/");var o=void 0!==e.versionHash?e.versionHash:a.versionHash;o&&(t+="hash="+n.b64RemoveSlashes(o)+"/");var s=void 0!==e.auditorKey?e.auditorKey:a.auditorKey;return s&&(t+="auditor="+n.b64RemoveSlashes(s)+"/"),e.newPadOpts&&(t+="newpad="+e.newPadOpts+"/"),e.loginOpts&&(t+="login="+e.loginOpts+"/"),t},i[1]&&"1"===i[1]?(a.version=1,a.mode=i[2],a.channel=i[3],a.key=n.b64AddSlashes(i[4]),o=i.slice(5),s(),a):i[1]&&"2"===i[1]?(a.version=2,a.app=i[2],a.mode=i[3],a.key=i[4],o=i.slice(5),s(),a):i[1]&&"3"===i[1]?(a.version=3,a.app=i[2],a.mode=i[3],a.channel=i[4],o=i.slice(5),s(),a):a)):(a.getHash=function(){return i.join("/")},-1!==["media","file"].indexOf(e)?(a.type="file",a.getOptions=function(){return{embed:a.embed,present:a.present,ownerKey:a.ownerKey,newPadOpts:a.newPadOpts,loginOpts:a.loginOpts,password:a.password}},a.getHash=function(e){var t=i.slice(0,4).join("/")+"/",n=void 0!==e.ownerKey?e.ownerKey:a.ownerKey;return n&&(t+=n+"/"),(a.password||e.password)&&(t+="p/"),e.embed&&(t+="embed/"),e.present&&(t+="present/"),e.newPadOpts&&(t+="newpad="+e.newPadOpts+"/"),e.loginOpts&&(t+="login="+e.loginOpts+"/"),t},i[1]&&"1"===i[1]?(a.version=1,a.channel=i[2].replace(/-/g,"/"),a.key=i[3].replace(/-/g,"/"),o=i.slice(4),s(),a):i[1]&&"2"===i[1]?(a.version=2,a.app=i[2],a.key=i[3],o=i.slice(4),s(),a):i[1]&&"3"===i[1]?(a.version=3,a.app=i[2],a.channel=i[3],o=i.slice(4),s(),a):a):-1!==["user"].indexOf(e)?(a.type="user",i[1]&&"1"===i[1]?(a.version=1,a.user=i[2],a.pubkey=i[3].replace(/-/g,"/"),a):a):-1!==["invite"].indexOf(e)?(a.type="invite",i[1]&&"2"===i[1]?(a.version=2,a.app=i[2],a.mode=i[3],a.key=i[4],o=i.slice(5),a.password=-1!==o.indexOf("p"),a):a):void 0)}},d=o.parsePadUrl=function(e){var t,n={};return e?("/"!==e.slice(-1)&&"#"!==e.slice(-1)&&(e+="/"),e=e.replace(/\/\?[^#]+#/,"/#"),n.getUrl=function(e){e=e||{};var t="/";return n.type?(t+=n.type+"/",!n.hashData&&e&&Object.keys(e).length?t+"#"+function(e){if(!e||!Object.keys(e).length)return"";var t="/4/"+n.type+"/";return e.newPadOpts&&(t+="newpad="+e.newPadOpts+"/"),e.loginOpts&&(t+="login="+e.loginOpts+"/"),t}(e):n.hashData?t+="#"+n.hashData.getHash(e):t):t},n.getOptions=function(){return n.hashData&&n.hashData.getOptions?n.hashData.getOptions():{}},/^https*:\/\//.test(e)?(e.replace(/^https*:\/\/([^\/]*)\/(.*?)\//i,(function(e,t,r){return n.domain=t,n.type=r,""})),-1===(t=e.indexOf("/#"))||(n.hash=e.slice(t+2),n.hashData=f(n.type,n.hash)),n):/^\/($|[^\/])/.test(e)?(t=e.indexOf("/#"),n.type=e.slice(1,t),-1===t||(n.hash=e.slice(t+2),n.hashData=f(n.type,n.hash)),n):n):n};return o.hashToHref=function(e,t){return"/"+t+"/#"+e},o.hrefToHash=function(e){return o.parsePadUrl(e).hash},o.getRelativeHref=function(e){if(e&&-1!==e.indexOf("#")){var t=d(e);return"/"+t.type+"/#"+t.hash}},o.getSecrets=function(t,r,o){var a,i,c={},u=function(){c.keys=n.createEditCryptor2(void 0,void 0,o),c.channel=s(c.keys.chanId),c.version=2,c.type=t};if(!r)return u(),c;if(r){if(!t)throw new Error("getSecrets with a hash requires a type parameter");a=f(t,r),i=r}if(0===i.length)return u(),c;if(0===a.version)c.channel=a.channel,c.key=a.key,c.version=0;else if(1===a.version){if(c.version=1,"pad"===a.type){if(c.channel=s(a.channel),"edit"===a.mode){if(c.keys=n.createEditCryptor(a.key),c.key=c.keys.editKeyStr,32!==c.channel.length||24!==c.key.length)throw new Error("The channel key and/or the encryption key is invalid")}else if("view"===a.mode&&(c.keys=n.createViewCryptor(a.key),32!==c.channel.length))throw new Error("The channel key is invalid")}else if("file"===a.type)c.channel=s(a.channel),c.keys={fileKeyStr:a.key,cryptKey:e.decodeBase64(a.key)};else if("user"===a.type)throw new Error("User hashes can't be opened (yet)")}else if(2===a.version)if(c.version=2,c.type=t,c.password=o,"pad"===a.type){if("edit"===a.mode){if(c.keys=n.createEditCryptor2(a.key,void 0,o),c.channel=s(c.keys.chanId),c.key=c.keys.editKeyStr,32!==c.channel.length||24!==c.key.length)throw new Error("The channel key and/or the encryption key is invalid")}else if("view"===a.mode&&(c.keys=n.createViewCryptor2(a.key,o),c.channel=s(c.keys.chanId),32!==c.channel.length))throw new Error("The channel key is invalid")}else if("file"===a.type){if(c.keys=n.createFileCryptor2(a.key,o),c.channel=s(c.keys.chanId),c.key=c.keys.fileKeyStr,48!==c.channel.length||24!==c.key.length)throw new Error("The channel key and/or the encryption key is invalid")}else if("user"===a.type)throw new Error("User hashes can't be opened (yet)");return c},o.getHashes=function(e){var t={};return(e=JSON.parse(JSON.stringify(e))).keys||e.key?(e.keys||(e.keys={}),(e.keys.editKeyStr||0===e.version&&e.key)&&(t.editHash=c(e)),e.keys.viewKeyStr&&(t.viewHash=u(e)),e.keys.fileKeyStr&&(t.fileHash=l(e)),t):t},o.getFormData=function(t,r,a){var i=(t=t||o.getSecrets("form",r,a))&&t.keys,s=i&&i.secondaryKey;if(s){var c=n.CryptoAgility.boxKeyPairFromSecretKey(e.decodeUTF8(s).slice(0,32)),u={};u.form_public=e.encodeBase64(c.publicKey);var l=u.form_private=e.encodeBase64(c.secretKey),f=o.getViewHashFromKeys({version:1,channel:t.channel,keys:{viewKeyStr:e.encodeBase64(i.cryptKey)}}),d=o.parseTypeHash("pad",f);return u.form_auditorHash=d.getHash({auditorKey:l}),u}},o.hrefToHexChannelId=function(e,t){var n=o.parsePadUrl(e);if(n&&n.hash)return o.getSecrets(n.type,n.hash,t).channel},o.getBlobPathFromHex=function(e){return"/blob/"+e.slice(0,2)+"/"+e},o.serializeHash=function(e){return e&&"/"!==e.slice(-1)&&(e+="/"),e},o.createInviteUrl=function(e,n){return n=n||o.createChannelId(),t.location.origin+"/invite/#/1/"+n+"/"+e.replace(/\//g,"-")+"/"},o.isValidChannel=function(e){return/^[a-zA-Z0-9]{32,48}$/.test(e)},o.isValidHref=function(e){if(e){var t=o.parsePadUrl(e);if(t&&t.type){if(t.hash){if(!t.hashData)return;if(void 0===t.hashData.version)return;if("pad"===t.hashData.type||"file"===t.hashData.type){if(!t.hashData.key&&!t.hashData.channel)return;if(t.hashData.key&&!/^[a-zA-Z0-9+-/=]+$/.test(t.hashData.key))return}}return t}}},o.decodeDataOptions=function(t){var n=decodeURIComponent(t),r=e.encodeUTF8(e.decodeBase64(n));return e.tryParse(r)||{}},o.encodeDataOptions=function(t){var n=JSON.stringify(t),r=e.encodeBase64(e.decodeUTF8(n));return encodeURIComponent(r)},o.getNewPadURL=function(e,t){var n=o.parsePadUrl(e),r=n.getOptions();return r.newPadOpts=o.encodeDataOptions(t),n.getUrl(r)},o.getLoginURL=function(e,t){var n=o.parsePadUrl(e),r=n.getOptions();return r.loginOpts=o.encodeDataOptions(t),n.getUrl(r)},o}(Ne(),ye(),Me(),h()))}("undefined"!=typeof window?window:{})}(Ce)),Ce.exports}var Le,He,Ke=Fe(),je=Ne(),Ue={exports:{}},Be={exports:{}};function Ve(){return Le||(Le=1,function(e){e.exports=function e(t,n,r){function o(i,s){if(!n[i]){if(!t[i]){if(!s&&l)return l(i);if(a)return a(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var u=n[i]={exports:{}};t[i][0].call(u.exports,(function(e){var n=t[i][1][e];return o(n||e)}),u,u.exports,e,t,n,r)}return n[i].exports}for(var a=l,i=0;i<r.length;i++)o(r[i]);return o}({1:[function(e,t,r){(function(e){var n,r,o=e.MutationObserver||e.WebKitMutationObserver;if(o){var a=0,i=new o(l),s=e.document.createTextNode("");i.observe(s,{characterData:!0}),n=function(){s.data=a=++a%2}}else if(e.setImmediate||void 0===e.MessageChannel)n="document"in e&&"onreadystatechange"in e.document.createElement("script")?function(){var t=e.document.createElement("script");t.onreadystatechange=function(){l(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null},e.document.documentElement.appendChild(t)}:function(){setTimeout(l,0)};else{var c=new e.MessageChannel;c.port1.onmessage=l,n=function(){c.port2.postMessage(0)}}var u=[];function l(){var e,t;r=!0;for(var n=u.length;n;){for(t=u,u=[],e=-1;++e<n;)t[e]();n=u.length}r=!1}function f(e){1!==u.push(e)||r||n()}t.exports=f}).call(this,void 0!==n?n:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(e,t,n){var r=e(1);function o(){}var a={},i=["REJECTED"],s=["FULFILLED"],c=["PENDING"];function u(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=c,this.queue=[],this.outcome=void 0,e!==o&&h(this,e)}function l(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}function f(e,t,n){r((function(){var r;try{r=t(n)}catch(t){return a.reject(e,t)}r===e?a.reject(e,new TypeError("Cannot resolve promise with itself")):a.resolve(e,r)}))}function d(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments)}}function h(e,t){var n=!1;function r(t){n||(n=!0,a.reject(e,t))}function o(t){n||(n=!0,a.resolve(e,t))}function i(){t(o,r)}var s=p(i);"error"===s.status&&r(s.value)}function p(e,t){var n={};try{n.value=e(t),n.status="success"}catch(e){n.status="error",n.value=e}return n}function y(e){return e instanceof this?e:a.resolve(new this(o),e)}function v(e){var t=new this(o);return a.reject(t,e)}function m(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n=e.length,r=!1;if(!n)return this.resolve([]);for(var i=new Array(n),s=0,c=-1,u=new this(o);++c<n;)l(e[c],c);return u;function l(e,o){function c(e){i[o]=e,++s!==n||r||(r=!0,a.resolve(u,i))}t.resolve(e).then(c,(function(e){r||(r=!0,a.reject(u,e))}))}}function g(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n=e.length,r=!1;if(!n)return this.resolve([]);for(var i=-1,s=new this(o);++i<n;)c(e[i]);return s;function c(e){t.resolve(e).then((function(e){r||(r=!0,a.resolve(s,e))}),(function(e){r||(r=!0,a.reject(s,e))}))}}t.exports=u,u.prototype.catch=function(e){return this.then(null,e)},u.prototype.then=function(e,t){if("function"!=typeof e&&this.state===s||"function"!=typeof t&&this.state===i)return this;var n=new this.constructor(o);return this.state!==c?f(n,this.state===s?e:t,this.outcome):this.queue.push(new l(n,e,t)),n},l.prototype.callFulfilled=function(e){a.resolve(this.promise,e)},l.prototype.otherCallFulfilled=function(e){f(this.promise,this.onFulfilled,e)},l.prototype.callRejected=function(e){a.reject(this.promise,e)},l.prototype.otherCallRejected=function(e){f(this.promise,this.onRejected,e)},a.resolve=function(e,t){var n=p(d,t);if("error"===n.status)return a.reject(e,n.value);var r=n.value;if(r)h(e,r);else{e.state=s,e.outcome=t;for(var o=-1,i=e.queue.length;++o<i;)e.queue[o].callFulfilled(t)}return e},a.reject=function(e,t){e.state=i,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e},u.resolve=y,u.reject=v,u.all=m,u.race=g},{1:1}],3:[function(e,t,r){(function(t){"function"!=typeof t.Promise&&(t.Promise=e(2))}).call(this,void 0!==n?n:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{2:2}],4:[function(e,t,n){var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(){try{if("undefined"!=typeof indexedDB)return indexedDB;if("undefined"!=typeof webkitIndexedDB)return webkitIndexedDB;if("undefined"!=typeof mozIndexedDB)return mozIndexedDB;if("undefined"!=typeof OIndexedDB)return OIndexedDB;if("undefined"!=typeof msIndexedDB)return msIndexedDB}catch(e){return}}var i=a();function s(){try{if(!i||!i.open)return!1;var e="undefined"!=typeof openDatabase&&/(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&!/BlackBerry/.test(navigator.platform),t="function"==typeof fetch&&-1!==fetch.toString().indexOf("[native code");return(!e||t)&&"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange}catch(e){return!1}}function c(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(o){if("TypeError"!==o.name)throw o;for(var n=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),r=0;r<e.length;r+=1)n.append(e[r]);return n.getBlob(t.type)}}"undefined"==typeof Promise&&e(3);var u=Promise;function l(e,t){t&&e.then((function(e){t(null,e)}),(function(e){t(e)}))}function f(e,t,n){"function"==typeof t&&e.then(t),"function"==typeof n&&e.catch(n)}function d(e){return"string"!=typeof e&&(console.warn(e+" used as a key, but it is not a string."),e=String(e)),e}function h(){if(arguments.length&&"function"==typeof arguments[arguments.length-1])return arguments[arguments.length-1]}var p="local-forage-detect-blob-support",y=void 0,v={},m=Object.prototype.toString,g="readonly",E="readwrite";function b(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),o=0;o<t;o++)r[o]=e.charCodeAt(o);return n}function A(e){return new u((function(t){var n=e.transaction(p,E),r=c([""]);n.objectStore(p).put(r,"key"),n.onabort=function(e){e.preventDefault(),e.stopPropagation(),t(!1)},n.oncomplete=function(){var e=navigator.userAgent.match(/Chrome\/(\d+)/),n=navigator.userAgent.match(/Edge\//);t(n||!e||parseInt(e[1],10)>=43)}})).catch((function(){return!1}))}function _(e){return"boolean"==typeof y?u.resolve(y):A(e).then((function(e){return y=e}))}function w(e){var t=v[e.name],n={};n.promise=new u((function(e,t){n.resolve=e,n.reject=t})),t.deferredOperations.push(n),t.dbReady?t.dbReady=t.dbReady.then((function(){return n.promise})):t.dbReady=n.promise}function O(e){var t=v[e.name].deferredOperations.pop();if(t)return t.resolve(),t.promise}function D(e,t){var n=v[e.name].deferredOperations.pop();if(n)return n.reject(t),n.promise}function S(e,t){return new u((function(n,r){if(v[e.name]=v[e.name]||F(),e.db){if(!t)return n(e.db);w(e),e.db.close()}var o=[e.name];t&&o.push(e.version);var a=i.open.apply(i,o);t&&(a.onupgradeneeded=function(t){var n=a.result;try{n.createObjectStore(e.storeName),t.oldVersion<=1&&n.createObjectStore(p)}catch(n){if("ConstraintError"!==n.name)throw n;console.warn('The database "'+e.name+'" has been upgraded from version '+t.oldVersion+" to version "+t.newVersion+', but the storage "'+e.storeName+'" already exists.')}}),a.onerror=function(e){e.preventDefault(),r(a.error)},a.onsuccess=function(){var t=a.result;t.onversionchange=function(e){e.target.close()},n(t),O(e)}}))}function T(e){return S(e,!1)}function C(e){return S(e,!0)}function x(e,t){if(!e.db)return!0;var n=!e.db.objectStoreNames.contains(e.storeName),r=e.version<e.db.version,o=e.version>e.db.version;if(r&&(e.version!==t&&console.warn('The database "'+e.name+"\" can't be downgraded from version "+e.db.version+" to version "+e.version+"."),e.version=e.db.version),o||n){if(n){var a=e.db.version+1;a>e.version&&(e.version=a)}return!0}return!1}function I(e){return new u((function(t,n){var r=new FileReader;r.onerror=n,r.onloadend=function(n){var r=btoa(n.target.result||"");t({__local_forage_encoded_blob:!0,data:r,type:e.type})},r.readAsBinaryString(e)}))}function N(e){return c([b(atob(e.data))],{type:e.type})}function P(e){return e&&e.__local_forage_encoded_blob}function k(e){var t=this,n=t._initReady().then((function(){var e=v[t._dbInfo.name];if(e&&e.dbReady)return e.dbReady}));return f(n,e,e),n}function R(e){w(e);for(var t=v[e.name],n=t.forages,r=0;r<n.length;r++){var o=n[r];o._dbInfo.db&&(o._dbInfo.db.close(),o._dbInfo.db=null)}return e.db=null,T(e).then((function(t){return e.db=t,x(e)?C(e):t})).then((function(r){e.db=t.db=r;for(var o=0;o<n.length;o++)n[o]._dbInfo.db=r})).catch((function(t){throw D(e,t),t}))}function M(e,t,n,r){void 0===r&&(r=1);try{var o=e.db.transaction(e.storeName,t);n(null,o)}catch(o){if(r>0&&(!e.db||"InvalidStateError"===o.name||"NotFoundError"===o.name))return u.resolve().then((function(){if(!e.db||"NotFoundError"===o.name&&!e.db.objectStoreNames.contains(e.storeName)&&e.version<=e.db.version)return e.db&&(e.version=e.db.version+1),C(e)})).then((function(){return R(e).then((function(){M(e,t,n,r-1)}))})).catch(n);n(o)}}function F(){return{forages:[],db:null,dbReady:null,deferredOperations:[]}}function L(e){var t=this,n={db:null};if(e)for(var r in e)n[r]=e[r];var o=v[n.name];o||(o=F(),v[n.name]=o),o.forages.push(t),t._initReady||(t._initReady=t.ready,t.ready=k);var a=[];function i(){return u.resolve()}for(var s=0;s<o.forages.length;s++){var c=o.forages[s];c!==t&&a.push(c._initReady().catch(i))}var l=o.forages.slice(0);return u.all(a).then((function(){return n.db=o.db,T(n)})).then((function(e){return n.db=e,x(n,t._defaultConfig.version)?C(n):e})).then((function(e){n.db=o.db=e,t._dbInfo=n;for(var r=0;r<l.length;r++){var a=l[r];a!==t&&(a._dbInfo.db=n.db,a._dbInfo.version=n.version)}}))}function H(e,t){var n=this;e=d(e);var r=new u((function(t,r){n.ready().then((function(){M(n._dbInfo,g,(function(o,a){if(o)return r(o);try{var i=a.objectStore(n._dbInfo.storeName).get(e);i.onsuccess=function(){var e=i.result;void 0===e&&(e=null),P(e)&&(e=N(e)),t(e)},i.onerror=function(){r(i.error)}}catch(e){r(e)}}))})).catch(r)}));return l(r,t),r}function K(e,t){var n=this,r=new u((function(t,r){n.ready().then((function(){M(n._dbInfo,g,(function(o,a){if(o)return r(o);try{var i=a.objectStore(n._dbInfo.storeName).openCursor(),s=1;i.onsuccess=function(){var n=i.result;if(n){var r=n.value;P(r)&&(r=N(r));var o=e(r,n.key,s++);void 0!==o?t(o):n.continue()}else t()},i.onerror=function(){r(i.error)}}catch(e){r(e)}}))})).catch(r)}));return l(r,t),r}function j(e,t,n){var r=this;e=d(e);var o=new u((function(n,o){var a;r.ready().then((function(){return a=r._dbInfo,"[object Blob]"===m.call(t)?_(a.db).then((function(e){return e?t:I(t)})):t})).then((function(t){M(r._dbInfo,E,(function(a,i){if(a)return o(a);try{var s=i.objectStore(r._dbInfo.storeName);null===t&&(t=void 0);var c=s.put(t,e);i.oncomplete=function(){void 0===t&&(t=null),n(t)},i.onabort=i.onerror=function(){var e=c.error?c.error:c.transaction.error;o(e)}}catch(e){o(e)}}))})).catch(o)}));return l(o,n),o}function U(e,t){var n=this;e=d(e);var r=new u((function(t,r){n.ready().then((function(){M(n._dbInfo,E,(function(o,a){if(o)return r(o);try{var i=a.objectStore(n._dbInfo.storeName).delete(e);a.oncomplete=function(){t()},a.onerror=function(){r(i.error)},a.onabort=function(){var e=i.error?i.error:i.transaction.error;r(e)}}catch(e){r(e)}}))})).catch(r)}));return l(r,t),r}function B(e){var t=this,n=new u((function(e,n){t.ready().then((function(){M(t._dbInfo,E,(function(r,o){if(r)return n(r);try{var a=o.objectStore(t._dbInfo.storeName).clear();o.oncomplete=function(){e()},o.onabort=o.onerror=function(){var e=a.error?a.error:a.transaction.error;n(e)}}catch(e){n(e)}}))})).catch(n)}));return l(n,e),n}function V(e){var t=this,n=new u((function(e,n){t.ready().then((function(){M(t._dbInfo,g,(function(r,o){if(r)return n(r);try{var a=o.objectStore(t._dbInfo.storeName).count();a.onsuccess=function(){e(a.result)},a.onerror=function(){n(a.error)}}catch(e){n(e)}}))})).catch(n)}));return l(n,e),n}function G(e,t){var n=this,r=new u((function(t,r){e<0?t(null):n.ready().then((function(){M(n._dbInfo,g,(function(o,a){if(o)return r(o);try{var i=a.objectStore(n._dbInfo.storeName),s=!1,c=i.openKeyCursor();c.onsuccess=function(){var n=c.result;n?0===e||s?t(n.key):(s=!0,n.advance(e)):t(null)},c.onerror=function(){r(c.error)}}catch(e){r(e)}}))})).catch(r)}));return l(r,t),r}function Y(e){var t=this,n=new u((function(e,n){t.ready().then((function(){M(t._dbInfo,g,(function(r,o){if(r)return n(r);try{var a=o.objectStore(t._dbInfo.storeName).openKeyCursor(),i=[];a.onsuccess=function(){var t=a.result;t?(i.push(t.key),t.continue()):e(i)},a.onerror=function(){n(a.error)}}catch(e){n(e)}}))})).catch(n)}));return l(n,e),n}function J(e,t){t=h.apply(this,arguments);var n=this.config();(e="function"!=typeof e&&e||{}).name||(e.name=e.name||n.name,e.storeName=e.storeName||n.storeName);var r,o=this;if(e.name){var a=e.name===n.name&&o._dbInfo.db?u.resolve(o._dbInfo.db):T(e).then((function(t){var n=v[e.name],r=n.forages;n.db=t;for(var o=0;o<r.length;o++)r[o]._dbInfo.db=t;return t}));r=e.storeName?a.then((function(t){if(t.objectStoreNames.contains(e.storeName)){var n=t.version+1;w(e);var r=v[e.name],o=r.forages;t.close();for(var a=0;a<o.length;a++){var s=o[a];s._dbInfo.db=null,s._dbInfo.version=n}var c=new u((function(t,r){var o=i.open(e.name,n);o.onerror=function(e){o.result.close(),r(e)},o.onupgradeneeded=function(){o.result.deleteObjectStore(e.storeName)},o.onsuccess=function(){var e=o.result;e.close(),t(e)}}));return c.then((function(e){r.db=e;for(var t=0;t<o.length;t++){var n=o[t];n._dbInfo.db=e,O(n._dbInfo)}})).catch((function(t){throw(D(e,t)||u.resolve()).catch((function(){})),t}))}})):a.then((function(t){w(e);var n=v[e.name],r=n.forages;t.close();for(var o=0;o<r.length;o++)r[o]._dbInfo.db=null;var a=new u((function(t,n){var r=i.deleteDatabase(e.name);r.onerror=function(){var e=r.result;e&&e.close(),n(r.error)},r.onblocked=function(){console.warn('dropInstance blocked for database "'+e.name+'" until all open connections are closed')},r.onsuccess=function(){var e=r.result;e&&e.close(),t(e)}}));return a.then((function(e){n.db=e;for(var t=0;t<r.length;t++)O(r[t]._dbInfo)})).catch((function(t){throw(D(e,t)||u.resolve()).catch((function(){})),t}))}))}else r=u.reject("Invalid arguments");return l(r,t),r}var q={_driver:"asyncStorage",_initStorage:L,_support:s(),iterate:K,getItem:H,setItem:j,removeItem:U,clear:B,length:V,key:G,keys:Y,dropInstance:J};function W(){return"function"==typeof openDatabase}var Q="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",z="~~local_forage_type~",X=/^~~local_forage_type~([^~]+)~/,Z="__lfsc__:",$=Z.length,ee="arbf",te="blob",ne="si08",re="ui08",oe="uic8",ae="si16",ie="si32",se="ur16",ce="ui32",ue="fl32",le="fl64",fe=$+ee.length,de=Object.prototype.toString;function he(e){var t,n,r,o,a,i=.75*e.length,s=e.length,c=0;"="===e[e.length-1]&&(i--,"="===e[e.length-2]&&i--);var u=new ArrayBuffer(i),l=new Uint8Array(u);for(t=0;t<s;t+=4)n=Q.indexOf(e[t]),r=Q.indexOf(e[t+1]),o=Q.indexOf(e[t+2]),a=Q.indexOf(e[t+3]),l[c++]=n<<2|r>>4,l[c++]=(15&r)<<4|o>>2,l[c++]=(3&o)<<6|63&a;return u}function pe(e){var t,n=new Uint8Array(e),r="";for(t=0;t<n.length;t+=3)r+=Q[n[t]>>2],r+=Q[(3&n[t])<<4|n[t+1]>>4],r+=Q[(15&n[t+1])<<2|n[t+2]>>6],r+=Q[63&n[t+2]];return n.length%3==2?r=r.substring(0,r.length-1)+"=":n.length%3==1&&(r=r.substring(0,r.length-2)+"=="),r}function ye(e,t){var n="";if(e&&(n=de.call(e)),e&&("[object ArrayBuffer]"===n||e.buffer&&"[object ArrayBuffer]"===de.call(e.buffer))){var r,o=Z;e instanceof ArrayBuffer?(r=e,o+=ee):(r=e.buffer,"[object Int8Array]"===n?o+=ne:"[object Uint8Array]"===n?o+=re:"[object Uint8ClampedArray]"===n?o+=oe:"[object Int16Array]"===n?o+=ae:"[object Uint16Array]"===n?o+=se:"[object Int32Array]"===n?o+=ie:"[object Uint32Array]"===n?o+=ce:"[object Float32Array]"===n?o+=ue:"[object Float64Array]"===n?o+=le:t(new Error("Failed to get type for BinaryArray"))),t(o+pe(r))}else if("[object Blob]"===n){var a=new FileReader;a.onload=function(){var n=z+e.type+"~"+pe(this.result);t(Z+te+n)},a.readAsArrayBuffer(e)}else try{t(JSON.stringify(e))}catch(n){console.error("Couldn't convert value into a JSON string: ",e),t(null,n)}}function ve(e){if(e.substring(0,$)!==Z)return JSON.parse(e);var t,n=e.substring(fe),r=e.substring($,fe);if(r===te&&X.test(n)){var o=n.match(X);t=o[1],n=n.substring(o[0].length)}var a=he(n);switch(r){case ee:return a;case te:return c([a],{type:t});case ne:return new Int8Array(a);case re:return new Uint8Array(a);case oe:return new Uint8ClampedArray(a);case ae:return new Int16Array(a);case se:return new Uint16Array(a);case ie:return new Int32Array(a);case ce:return new Uint32Array(a);case ue:return new Float32Array(a);case le:return new Float64Array(a);default:throw new Error("Unkown type: "+r)}}var me={serialize:ye,deserialize:ve,stringToBuffer:he,bufferToString:pe};function ge(e,t,n,r){e.executeSql("CREATE TABLE IF NOT EXISTS "+t.storeName+" (id INTEGER PRIMARY KEY, key unique, value)",[],n,r)}function Ee(e){var t=this,n={db:null};if(e)for(var r in e)n[r]="string"!=typeof e[r]?e[r].toString():e[r];var o=new u((function(e,r){try{n.db=openDatabase(n.name,String(n.version),n.description,n.size)}catch(e){return r(e)}n.db.transaction((function(o){ge(o,n,(function(){t._dbInfo=n,e()}),(function(e,t){r(t)}))}),r)}));return n.serializer=me,o}function be(e,t,n,r,o,a){e.executeSql(n,r,o,(function(e,i){i.code===i.SYNTAX_ERR?e.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name = ?",[t.storeName],(function(e,s){s.rows.length?a(e,i):ge(e,t,(function(){e.executeSql(n,r,o,a)}),a)}),a):a(e,i)}),a)}function Ae(e,t){var n=this;e=d(e);var r=new u((function(t,r){n.ready().then((function(){var o=n._dbInfo;o.db.transaction((function(n){be(n,o,"SELECT * FROM "+o.storeName+" WHERE key = ? LIMIT 1",[e],(function(e,n){var r=n.rows.length?n.rows.item(0).value:null;r&&(r=o.serializer.deserialize(r)),t(r)}),(function(e,t){r(t)}))}))})).catch(r)}));return l(r,t),r}function _e(e,t){var n=this,r=new u((function(t,r){n.ready().then((function(){var o=n._dbInfo;o.db.transaction((function(n){be(n,o,"SELECT * FROM "+o.storeName,[],(function(n,r){for(var a=r.rows,i=a.length,s=0;s<i;s++){var c=a.item(s),u=c.value;if(u&&(u=o.serializer.deserialize(u)),void 0!==(u=e(u,c.key,s+1)))return void t(u)}t()}),(function(e,t){r(t)}))}))})).catch(r)}));return l(r,t),r}function we(e,t,n,r){var o=this;e=d(e);var a=new u((function(a,i){o.ready().then((function(){void 0===t&&(t=null);var s=t,c=o._dbInfo;c.serializer.serialize(t,(function(t,u){u?i(u):c.db.transaction((function(n){be(n,c,"INSERT OR REPLACE INTO "+c.storeName+" (key, value) VALUES (?, ?)",[e,t],(function(){a(s)}),(function(e,t){i(t)}))}),(function(t){if(t.code===t.QUOTA_ERR){if(r>0)return void a(we.apply(o,[e,s,n,r-1]));i(t)}}))}))})).catch(i)}));return l(a,n),a}function Oe(e,t,n){return we.apply(this,[e,t,n,1])}function De(e,t){var n=this;e=d(e);var r=new u((function(t,r){n.ready().then((function(){var o=n._dbInfo;o.db.transaction((function(n){be(n,o,"DELETE FROM "+o.storeName+" WHERE key = ?",[e],(function(){t()}),(function(e,t){r(t)}))}))})).catch(r)}));return l(r,t),r}function Se(e){var t=this,n=new u((function(e,n){t.ready().then((function(){var r=t._dbInfo;r.db.transaction((function(t){be(t,r,"DELETE FROM "+r.storeName,[],(function(){e()}),(function(e,t){n(t)}))}))})).catch(n)}));return l(n,e),n}function Te(e){var t=this,n=new u((function(e,n){t.ready().then((function(){var r=t._dbInfo;r.db.transaction((function(t){be(t,r,"SELECT COUNT(key) as c FROM "+r.storeName,[],(function(t,n){var r=n.rows.item(0).c;e(r)}),(function(e,t){n(t)}))}))})).catch(n)}));return l(n,e),n}function Ce(e,t){var n=this,r=new u((function(t,r){n.ready().then((function(){var o=n._dbInfo;o.db.transaction((function(n){be(n,o,"SELECT key FROM "+o.storeName+" WHERE id = ? LIMIT 1",[e+1],(function(e,n){var r=n.rows.length?n.rows.item(0).key:null;t(r)}),(function(e,t){r(t)}))}))})).catch(r)}));return l(r,t),r}function xe(e){var t=this,n=new u((function(e,n){t.ready().then((function(){var r=t._dbInfo;r.db.transaction((function(t){be(t,r,"SELECT key FROM "+r.storeName,[],(function(t,n){for(var r=[],o=0;o<n.rows.length;o++)r.push(n.rows.item(o).key);e(r)}),(function(e,t){n(t)}))}))})).catch(n)}));return l(n,e),n}function Ie(e){return new u((function(t,n){e.transaction((function(r){r.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'",[],(function(n,r){for(var o=[],a=0;a<r.rows.length;a++)o.push(r.rows.item(a).name);t({db:e,storeNames:o})}),(function(e,t){n(t)}))}),(function(e){n(e)}))}))}function Ne(e,t){t=h.apply(this,arguments);var n=this.config();(e="function"!=typeof e&&e||{}).name||(e.name=e.name||n.name,e.storeName=e.storeName||n.storeName);var r,o=this;return l(r=e.name?new u((function(t){var r;r=e.name===n.name?o._dbInfo.db:openDatabase(e.name,"","",0),e.storeName?t({db:r,storeNames:[e.storeName]}):t(Ie(r))})).then((function(e){return new u((function(t,n){e.db.transaction((function(r){function o(e){return new u((function(t,n){r.executeSql("DROP TABLE IF EXISTS "+e,[],(function(){t()}),(function(e,t){n(t)}))}))}for(var a=[],i=0,s=e.storeNames.length;i<s;i++)a.push(o(e.storeNames[i]));u.all(a).then((function(){t()})).catch((function(e){n(e)}))}),(function(e){n(e)}))}))})):u.reject("Invalid arguments"),t),r}var Pe={_driver:"webSQLStorage",_initStorage:Ee,_support:W(),iterate:_e,getItem:Ae,setItem:Oe,removeItem:De,clear:Se,length:Te,key:Ce,keys:xe,dropInstance:Ne};function ke(){try{return"undefined"!=typeof localStorage&&"setItem"in localStorage&&!!localStorage.setItem}catch(e){return!1}}function Re(e,t){var n=e.name+"/";return e.storeName!==t.storeName&&(n+=e.storeName+"/"),n}function Me(){var e="_localforage_support_test";try{return localStorage.setItem(e,!0),localStorage.removeItem(e),!1}catch(e){return!0}}function Fe(){return!Me()||localStorage.length>0}function Le(e){var t=this,n={};if(e)for(var r in e)n[r]=e[r];return n.keyPrefix=Re(e,t._defaultConfig),Fe()?(t._dbInfo=n,n.serializer=me,u.resolve()):u.reject()}function He(e){var t=this,n=t.ready().then((function(){for(var e=t._dbInfo.keyPrefix,n=localStorage.length-1;n>=0;n--){var r=localStorage.key(n);0===r.indexOf(e)&&localStorage.removeItem(r)}}));return l(n,e),n}function Ke(e,t){var n=this;e=d(e);var r=n.ready().then((function(){var t=n._dbInfo,r=localStorage.getItem(t.keyPrefix+e);return r&&(r=t.serializer.deserialize(r)),r}));return l(r,t),r}function je(e,t){var n=this,r=n.ready().then((function(){for(var t=n._dbInfo,r=t.keyPrefix,o=r.length,a=localStorage.length,i=1,s=0;s<a;s++){var c=localStorage.key(s);if(0===c.indexOf(r)){var u=localStorage.getItem(c);if(u&&(u=t.serializer.deserialize(u)),void 0!==(u=e(u,c.substring(o),i++)))return u}}}));return l(r,t),r}function Ue(e,t){var n=this,r=n.ready().then((function(){var t,r=n._dbInfo;try{t=localStorage.key(e)}catch(e){t=null}return t&&(t=t.substring(r.keyPrefix.length)),t}));return l(r,t),r}function Be(e){var t=this,n=t.ready().then((function(){for(var e=t._dbInfo,n=localStorage.length,r=[],o=0;o<n;o++){var a=localStorage.key(o);0===a.indexOf(e.keyPrefix)&&r.push(a.substring(e.keyPrefix.length))}return r}));return l(n,e),n}function Ve(e){var t=this.keys().then((function(e){return e.length}));return l(t,e),t}function Ge(e,t){var n=this;e=d(e);var r=n.ready().then((function(){var t=n._dbInfo;localStorage.removeItem(t.keyPrefix+e)}));return l(r,t),r}function Ye(e,t,n){var r=this;e=d(e);var o=r.ready().then((function(){void 0===t&&(t=null);var n=t;return new u((function(o,a){var i=r._dbInfo;i.serializer.serialize(t,(function(t,r){if(r)a(r);else try{localStorage.setItem(i.keyPrefix+e,t),o(n)}catch(e){"QuotaExceededError"!==e.name&&"NS_ERROR_DOM_QUOTA_REACHED"!==e.name||a(e),a(e)}}))}))}));return l(o,n),o}function Je(e,t){if(t=h.apply(this,arguments),!(e="function"!=typeof e&&e||{}).name){var n=this.config();e.name=e.name||n.name,e.storeName=e.storeName||n.storeName}var r,o=this;return r=e.name?new u((function(t){e.storeName?t(Re(e,o._defaultConfig)):t(e.name+"/")})).then((function(e){for(var t=localStorage.length-1;t>=0;t--){var n=localStorage.key(t);0===n.indexOf(e)&&localStorage.removeItem(n)}})):u.reject("Invalid arguments"),l(r,t),r}var qe={_driver:"localStorageWrapper",_initStorage:Le,_support:ke(),iterate:je,getItem:Ke,setItem:Ye,removeItem:Ge,clear:He,length:Ve,key:Ue,keys:Be,dropInstance:Je},We=function(e,t){return e===t||"number"==typeof e&&"number"==typeof t&&isNaN(e)&&isNaN(t)},Qe=function(e,t){for(var n=e.length,r=0;r<n;){if(We(e[r],t))return!0;r++}return!1},ze=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},Xe={},Ze={},$e={INDEXEDDB:q,WEBSQL:Pe,LOCALSTORAGE:qe},et=[$e.INDEXEDDB._driver,$e.WEBSQL._driver,$e.LOCALSTORAGE._driver],tt=["dropInstance"],nt=["clear","getItem","iterate","key","keys","length","removeItem","setItem"].concat(tt),rt={description:"",driver:et.slice(),name:"localforage",size:4980736,storeName:"keyvaluepairs",version:1};function ot(e,t){e[t]=function(){var n=arguments;return e.ready().then((function(){return e[t].apply(e,n)}))}}function at(){for(var e=1;e<arguments.length;e++){var t=arguments[e];if(t)for(var n in t)t.hasOwnProperty(n)&&(ze(t[n])?arguments[0][n]=t[n].slice():arguments[0][n]=t[n])}return arguments[0]}var it=function(){function e(t){for(var n in o(this,e),$e)if($e.hasOwnProperty(n)){var r=$e[n],a=r._driver;this[n]=a,Xe[a]||this.defineDriver(r)}this._defaultConfig=at({},rt),this._config=at({},this._defaultConfig,t),this._driverSet=null,this._initDriver=null,this._ready=!1,this._dbInfo=null,this._wrapLibraryMethodsWithReady(),this.setDriver(this._config.driver).catch((function(){}))}return e.prototype.config=function(e){if("object"===(void 0===e?"undefined":r(e))){if(this._ready)return new Error("Can't call config() after localforage has been used.");for(var t in e){if("storeName"===t&&(e[t]=e[t].replace(/\W/g,"_")),"version"===t&&"number"!=typeof e[t])return new Error("Database version must be a number.");this._config[t]=e[t]}return!("driver"in e)||!e.driver||this.setDriver(this._config.driver)}return"string"==typeof e?this._config[e]:this._config},e.prototype.defineDriver=function(e,t,n){var r=new u((function(t,n){try{var r=e._driver,o=new Error("Custom driver not compliant; see https://mozilla.github.io/localForage/#definedriver");if(!e._driver)return void n(o);for(var a=nt.concat("_initStorage"),i=0,s=a.length;i<s;i++){var c=a[i];if((!Qe(tt,c)||e[c])&&"function"!=typeof e[c])return void n(o)}var f=function(){for(var t=function(e){return function(){var t=new Error("Method "+e+" is not implemented by the current driver"),n=u.reject(t);return l(n,arguments[arguments.length-1]),n}},n=0,r=tt.length;n<r;n++){var o=tt[n];e[o]||(e[o]=t(o))}};f();var d=function(n){Xe[r]&&console.info("Redefining LocalForage driver: "+r),Xe[r]=e,Ze[r]=n,t()};"_support"in e?e._support&&"function"==typeof e._support?e._support().then(d,n):d(!!e._support):d(!0)}catch(e){n(e)}}));return f(r,t,n),r},e.prototype.driver=function(){return this._driver||null},e.prototype.getDriver=function(e,t,n){var r=Xe[e]?u.resolve(Xe[e]):u.reject(new Error("Driver not found."));return f(r,t,n),r},e.prototype.getSerializer=function(e){var t=u.resolve(me);return f(t,e),t},e.prototype.ready=function(e){var t=this,n=t._driverSet.then((function(){return null===t._ready&&(t._ready=t._initDriver()),t._ready}));return f(n,e,e),n},e.prototype.setDriver=function(e,t,n){var r=this;ze(e)||(e=[e]);var o=this._getSupportedDrivers(e);function a(){r._config.driver=r.driver()}function i(e){return r._extend(e),a(),r._ready=r._initStorage(r._config),r._ready}function s(e){return function(){var t=0;function n(){for(;t<e.length;){var o=e[t];return t++,r._dbInfo=null,r._ready=null,r.getDriver(o).then(i).catch(n)}a();var s=new Error("No available storage method found.");return r._driverSet=u.reject(s),r._driverSet}return n()}}var c=null!==this._driverSet?this._driverSet.catch((function(){return u.resolve()})):u.resolve();return this._driverSet=c.then((function(){var e=o[0];return r._dbInfo=null,r._ready=null,r.getDriver(e).then((function(e){r._driver=e._driver,a(),r._wrapLibraryMethodsWithReady(),r._initDriver=s(o)}))})).catch((function(){a();var e=new Error("No available storage method found.");return r._driverSet=u.reject(e),r._driverSet})),f(this._driverSet,t,n),this._driverSet},e.prototype.supports=function(e){return!!Ze[e]},e.prototype._extend=function(e){at(this,e)},e.prototype._getSupportedDrivers=function(e){for(var t=[],n=0,r=e.length;n<r;n++){var o=e[n];this.supports(o)&&t.push(o)}return t},e.prototype._wrapLibraryMethodsWithReady=function(){for(var e=0,t=nt.length;e<t;e++)ot(this,nt[e])},e.prototype.createInstance=function(t){return new e(t)},e}(),st=new it;t.exports=st},{3:3}]},{},[4])(4)}(Be)),Be.exports}function Ge(){return He||(He=1,function(e){(()=>{const t=(e,t)=>{let n=globalThis,r=globalThis;var o=n.CryptPad_Cache={},a=e.mkEvent(!0),i=!1,s=!1,c=!1;try{var u=n.indexedDB.open("test_db",1);u.onsuccess=function(){i=(c=!0)&&!s,a.fire()},u.onerror=function(){a.fire()}}catch(e){a.fire()}o.enable=function(){s=!1,i=c&&!s},o.disable=function(){s=!0,i=c&&!s},o.isEnabled=()=>i;var l=t.createInstance({driver:t.INDEXEDDB,name:"cp_cache"});o.getBlobCache=function(t,n){n=e.once(e.mkAsync(n||function(){})),a.reg((function(){i?l.getItem(t,(function(r,o){!r&&o&&o.c?(n(null,o.c),o.t=+new Date,l.setItem(t,o,(function(e){e&&console.error(e)}))):n(e.serializeError(r||"EINVAL"))})):n("NOCACHE")}))},o.setBlobCache=function(t,n,r){r=e.once(e.mkAsync(r||function(){})),a.reg((function(){i?n?l.setItem(t,{c:n,t:+new Date},(function(t){r(e.serializeError(t))})):r("EINVAL"):r("NOCACHE")}))},o.getChannelCache=function(t,n){n=e.once(e.mkAsync(n||function(){})),a.reg((function(){i?l.getItem(t,(function(r,o){!r&&o&&Array.isArray(o.c)?(n(null,o),o.t=+new Date,l.setItem(t,o,(function(e){e&&console.error(e)}))):n(e.serializeError(r||"EINVAL"))})):n("NOCACHE")}))};var f={};return o.storeCache=function(t,n,r,o){o=e.once(e.mkAsync(o||function(){})),a.reg((function(){f[t]=f[t]||e.throttle((function(n,r,o){var a,s;i?Array.isArray(r)&&n?(a=r,Array.isArray(a)&&(a.length>100&&a.splice(0,a.length-100),a.some((function(e,t){if(e.isCheckpoint)return s=t,!0})),a.splice(0,s)),l.setItem(t,{k:n,c:r,t:+new Date},(function(t){t&&o(e.serializeError(t))}))):o("EINVAL"):o("NOCACHE")}),50),f[t](n,r,o)}))},o.leaveChannel=function(e){delete f[e]},o.clearChannel=function(t,n){n=e.once(e.mkAsync(n||function(){})),a.reg((function(){i?l.removeItem(t,(function(){n()})):n("NOCACHE")}))},o.clear=function(t){t=e.once(e.mkAsync(t||function(){})),a.reg((function(){i?l.clear(t):t("NOCACHE")}))},o.getKeys=function(t){t=e.once(e.mkAsync(t||function(){})),a.reg((function(){i?l.keys().then((function(e){t(null,e)})).catch((function(e){t(e)})):t("NOCACHE")}))},o.getTime=function(t,n){n=e.once(e.mkAsync(n||function(){})),a.reg((function(){i?l.getItem(t,(function(t,r){!t&&r&&r.c?n(null,r.t):n(e.serializeError(t||"EINVAL"))})):n("NOCACHE")}))},r.CryptPad_clearIndexedDB=o.clear,o};e.exports&&(e.exports=t(Ne(),Ve()))})()}(Ue)),Ue.exports}var Ye=Ge(),Je=t({__proto__:null,default:r(Ye)},[Ye]);const qe=je.mkEvent(!0),We=je.mkEvent(!0),Qe=je.mkEvent(),ze=je.mkEvent();let Xe={};const Ze={setCustomize:e=>{Xe=e.ApiConfig},init:e=>{var t,n,r;const{broadcast:o,userHash:a,anonHash:i}=e,s=a||i||Ke.createRandomHash("drive"),c=e.store,u=Ke.getSecrets("drive",s),l=(null===(t=e.store)||void 0===t?void 0:t.network)||(null===(n=e.store)||void 0===n?void 0:n.networkPromise),f={data:{},websocketURL:Ae.getWebsocketURL(),network:l,channel:u.channel,readOnly:!1,validateKey:(null===(r=u.keys)||void 0===r?void 0:r.validateKey)||void 0,crypto:me.createEncryptor(u.keys),Cache:Je,userName:"fs",logLevel:1,ChainPad:k,updateProgress:function(e){e.type="drive",o([],"LOADING_DRIVE",e)},classic:!0},d=globalThis.CP_account_rt=C.create(f);c.driveSecret=u,c.proxy=d.proxy,c.onRpcReadyEvt=je.mkEvent(!0),c.loggedIn=void 0!==e.userHash;const h={loggedIn:c.loggedIn};return d.proxy.on("create",(function(e){c.realtime=e.realtime,c.network=e.network,c.loggedIn||(h.anonHash=Ke.getEditHashFromKeys(u))})).on("cacheready",(function(t){c.realtime=t.realtime,c.offline=!0;const n=!!c.networkPromise;if(c.networkPromise||(c.networkPromise=t.networkPromise),c.cacheReturned=h,c.networkPromise&&c.networkPromise.then&&!n){const e=setTimeout((function(){c.networkTimeout=!0,o([],"LOADING_DRIVE",{type:"offline"})}),5e3);c.networkPromise.then((function(t){c.network||(c.network=t),clearTimeout(e)}),(function(t){console.error(t),clearTimeout(e)}))}e.cache&&(h.edPublic=d.proxy.edPublic,qe.fire(h))})).on("ready",(function(t){delete c.networkTimeout,c.ready||(c.driveMetadata=t.metadata,d.proxy.drive||(d.proxy.drive={}),!d.proxy[Se.displayNameKey]&&c.noDriveName&&(d.proxy[Se.displayNameKey]=c.noDriveName),!d.proxy.uid&&c.noDriveUid&&(d.proxy.uid=c.noDriveUid),!d.proxy.form_seed&&e.form_seed&&(d.proxy.form_seed=e.form_seed),d.proxy.edPublic&&Array.isArray(Xe.adminKeys)&&-1!==Xe.adminKeys.indexOf(d.proxy.edPublic)&&(c.isAdmin=!0),h.edPublic=d.proxy.edPublic,We.fire(h))})).on("error",(function(e){"EDELETED"===e.error&&(c.ownDeletion||(c.isDeleted=!0,o([],"DRIVE_DELETED",e.message)))})).on("disconnect",(function(){c.offline=!0,Qe.fire(),o([],"UPDATE_METADATA")})).on("reconnect",(function(){c.offline=!1,ze.fire(),o([],"UPDATE_METADATA")})),{channel:u.channel,onAccountCacheReady:qe.reg,onAccountReady:We.reg,onDisconnect:Qe.reg,onReconnect:ze.reg}}};var $e,et=Object.freeze({__proto__:null,Account:Ze}),tt={exports:{}};function nt(){return $e||($e=1,function(e){(()=>{const t=(e={},t={})=>{var n={setCustomize:n=>{t=n.Messages,e=n.AppConfig},init:function(e){n.state=e}};return n.send=function(t,r,o){("function"!=typeof o&&(o=function(){}),e.disableFeedback)?o():t&&(!0===r||n.state)?function(e,t){var n=new XMLHttpRequest;n.open("HEAD",e),n.onreadystatechange=function(){this.readyState===this.DONE&&t&&t()},n.send()}("/common/feedback.html?"+t+"="+Math.random().toString(16).replace(/0./,""),o):o()},n.reportAppUsage=function(){var e=window.location.pathname.split("/").filter((function(e){return e})).join(".");/^#\/1\/view\//.test(window.location.hash)?n.send(e+"_VIEW"):n.send(e)},n.reportScreenDimensions=function(){var e=window.innerHeight,t=window.innerWidth;n.send("DIMENSIONS:"+e+"x"+t)},n.reportLanguage=function(){t&&n.send("LANG_"+t._languageUsed)},n};e.exports&&(e.exports=t(void 0,void 0))})()}(tt)),tt.exports}var rt,ot=nt(),at=t({__proto__:null,default:r(ot)},[ot]),it={exports:{}};function st(){return rt||(rt=1,function(e){e.exports&&(e.exports=function(e={},t){var n={setCustomize:t=>{e=t.AppConfig}};n.MINIMUM_PASSWORD_LENGTH="number"==typeof e.minimumPasswordLength?e.minimumPasswordLength:8,n.MINIMUM_NAME_LENGTH=1,n.MAXIMUM_NAME_LENGTH=64,n.isEmail=function(e){return/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(String(e).toLowerCase())},n.isLongEnoughPassword=function(e){return e.length>=n.MINIMUM_PASSWORD_LENGTH};var r=n.isString=function(e){return"string"==typeof e};return n.isValidUsername=function(e){return!!(r(e)&&e.length>=n.MINIMUM_NAME_LENGTH)},n.isValidPassword=function(e){return!(!e||!r(e))},n.passwordsMatch=function(e,t){return r(e)&&r(t)&&e===t},n.customSalt=function(){return"string"==typeof e.loginSalt?e.loginSalt:""},n.deriveFromPassphrase=function(e,r,o,a){t(r,e+n.customSalt(),8,1024,o||128,200,a,void 0)},n.dispenser=function(e){var t={used:0};return function(n){if(t.used+n>e.length)throw new Error("exceeded available entropy");if("number"!=typeof n)throw new Error("expected a number");if(n<=0)throw new Error("expected to consume a positive number of bytes");var r;return r=e.slice?e.slice(t.used,t.used+n):e.subarray(t.used,t.used+n),t.used+=n,r}},n}(void 0,pe()))}(it)),it.exports}var ct,ut,lt,ft=st(),dt=t({__proto__:null,default:r(ft)},[ft]),ht={exports:{}},pt={exports:{}},yt={exports:{}},vt={exports:{}};function mt(){return ct||(ct=1,function(e){e.exports&&(e.exports={whenRealtimeSyncs:function(e,t){"function"==typeof e.getAuthDoc?setTimeout((function(){e.getAuthDoc()!==e.getUserDoc()?e.onSettle(t):t()}),0):console.error("improper use of this function")}})}(vt)),vt.exports}function gt(){return ut||(ut=1,function(e){(()=>{const t=(e,t,n)=>{let r=globalThis;var o={setCustomize:()=>{}},a=function(e){try{return JSON.parse(JSON.stringify(e))}catch(e){return}};return o.init=function(o,i,s){var c=o.loggedIn,u=o.sharedFolder,l=o.readOnly,f=o.Messages||{},d=i.ROOT,h=i.FILES_DATA,p=i.STATIC_DATA,y=i.OLD_FILES_DATA,v=i.UNSORTED,m=i.TRASH,g=i.TEMPLATE,E=i.SHARED_FOLDERS,b=i.SHARED_FOLDERS_TEMP,A=i.debug;i._setReadOnly=function(e){(l=e)||i.fixFiles()},i.setHref=function(e,n,r){(n||e)&&(l||(n?[n]:i.findChannels([e])).forEach((function(e){var n=i.getFileData(e,!0);if(i.getHref(n)===r)return;n.href=i.cryptor.encrypt(r);const o=t.parsePadUrl(r);if("form"!==o.type)return;const a=t.getSecrets(o.type,o.hash,n.password);n.roHref="/"+o.type+"/#"+t.getViewHashFromKeys(a)})))},i.setPadAttribute=function(e,t,n,r){if(r=r||function(){},l)r("EFORBIDDEN");else{var o=i.getIdFromHref(e);if(o)if(t&&t.trim()){var s=i.getFileData(o,!0);"href"===t?i.setHref(null,o,n):s[t]=a(n),r(null)}else r("E_INVAL_ATTR");else r("E_INVAL_HREF")}},i.getPadAttribute=function(e,t,n){n=n||function(){};var r=i.getIdFromHref(e);if(r){var o=i.getFileData(r);n(null,a(o[t]))}else n(null,void 0)},i.pushData=function(t,n){if("function"!=typeof n&&(n=function(){}),l)n("EFORBIDDEN");else{var r=e.createRandomInteger(),o=a(t);o.href&&-1!==o.href.indexOf("#")&&(o.href=i.cryptor.encrypt(o.href)),s[h][r]=o,n(null,r)}},i.pushLink=function(t,n){if("function"!=typeof n&&(n=function(){}),l)n("EFORBIDDEN");else{var r=e.createRandomInteger(),o=a(t);s[p][r]=o,n(null,r)}},i.pushSharedFolder=function(t,n){if("function"!=typeof n&&(n=function(){}),l)n("EFORBIDDEN");else{var r,u=a(t);if(Object.keys(s[E]).some((function(e){if(s[E][e].channel===u.channel)return u.href&&!s[E][e].href&&(s[E][e].href=u.href),r=e,!0})))n("EEXISTS",r);else if(c&&!o.testMode){var f=e.createRandomInteger();u.href&&-1!==u.href.indexOf("#")&&(u.href=i.cryptor.encrypt(u.href)),s[E][f]=u,n(null,f)}else n("EAUTH")}},i.deprecateSharedFolder=function(e,t){if(!l){var n=s[E][e];if(n){if(!(!n.href||-1===i.cryptor.decrypt(n.href).indexOf("#")))(s[b][e]=JSON.parse(JSON.stringify(n))).legacy="PASSWORD_CHANGE"!==t;var r=i.findFile(Number(e));i.delete(r,null,!0),delete s[E][e]}}};var _=function(e){l||delete s[h][e]};i.checkDeletedFiles=function(e){if(c||o.testMode)if(l)e("EFORBIDDEN");else{var n=i.getFiles([d,"hrefArray",m]),r=[];i.getFiles([h,E,p]).forEach((function(e){if(-1===n.indexOf(e)){var a=i.isSharedFolder(e)?s[E][e]:i.getFileData(e),c=a.channel;a.lastVersion&&r.push(t.hrefToHexChannelId(a.lastVersion)),a.rtChannel&&r.push(a.rtChannel),c&&r.push(c),i.isSharedFolder(e)?(delete s[E][e],o.removeProxy&&o.removeProxy(e)):s[p][e]?delete s[p][e]:_(e)}})),r.length?e(null,r):e()}else e()};i.deleteMultiplePermanently=function(e,t,n){if(l)n("EFORBIDDEN");else{var r=e.filter((function(e){return i.isPathIn(e,[h])}));if(!c&&!o.testMode)return r.forEach((function(e){var t=e[1];t&&_(t)})),void n();var a=e.filter((function(e){return i.isPathIn(e,["hrefArray"])})),u=e.filter((function(e){return i.isPathIn(e,[d])})),f=e.filter((function(e){return i.isPathIn(e,[m])})),p=[];a.forEach((function(e){var t=i.find(e);p.push({root:e[0],id:t})})),function(e){l||e.forEach((function(e){var t=s[e.root].indexOf(e.id);s[e.root].splice(t,1)}))}(p),u.forEach((function(e){var t=e.slice(),n=t.pop();delete i.find(t)[n]}));var y,v=[];f.forEach((function(e){var t=e.slice(),n=t.pop(),r=i.find(t);4!==e.length?delete r[n]:v.push({name:e[1],el:r})})),y=v,l||y.forEach((function(e){var t=s[m][e.name].indexOf(e.el);s[m][e.name].splice(t,1)})),t?n():i.checkDeletedFiles(n)}},i.copyFromOtherDrive=function(e,n,r,o){if(!l){var a=[];if(Object.keys(r).forEach((function(e){e=Number(e);var t=r[e];if(t.static)return delete t.static,void(s[p][e]=t);t.href&&(t.href=i.cryptor.encrypt(t.href));var n=!1;for(var o in s[h])if(s[h][o].channel===t.channel){s[h][o].href||(s[h][o].href=t.href),n=!0;break}n?a.push(e):s[h][e]=t})),i.isFile(n)&&-1!==a.indexOf(n))i.log(f.sharedFolders_duplicate);else{if(i.isFolder(n)){var c=function(e){for(var t in e)i.isFile(e[t])?-1!==a.indexOf(e[t])&&(i.log(f.sharedFolders_duplicate),delete e[t]):i.isFolder(e[t])&&c(e[t])};c(n)}var u=i.find(e),d=i.isFile(n)?t.createChannelId():o,y=i.getAvailableName(u,d);Array.isArray(u)?u.push(n):u[y]=n}}};i.copyElement=function(e,n){if(!l&&!i.comparePath(e,n)){var r=i.find(e),o=i.find(n);if(i.isPathIn(n,[m])){if(!e||e.length<2||e[0]===m)return void A("Can't move an element from the trash to the trash: ",e);var a=e[e.length-1],c=i.isPathIn(e,["hrefArray"])?i.getTitle(r):a,u=e.slice();return u.pop(),function(e,t,n){if(!l){var r=s[m];void 0===r[e]&&(r[e]=[]);var o={element:t,path:n};r[e].push(o)}}(c,r,u),!0}if(i.isPathIn(n,["hrefArray"])){if(i.isFolder(r))return void i.log(f.fo_moveUnsortedError);if(e[0]===n[0])return;var d=n[0];return-1===s[d].indexOf(r)&&s[d].push(r),!0}var h=i.isFile(r)?i.getAvailableName(o,t.createChannelId()):i.isInTrashRoot(e)?e[1]:e.pop();if(void 0===o[h])return o[h]=r,!0;i.log(f.fo_unavailableName)}},i.forget=function(e){if(!l){var t=i.getIdFromHref(e);if(t){if(!c&&!o.testMode)return _(t),!0;var n=i.findFile(t);return i.move(n,[m]),!0}}},i.restoreHref=function(e){if(!l){var t=i.getIdFromHref(e);if(t&&i.isFile(t)){var n=i.findFile(t),r=!0;n.forEach((function(e){e[0]!==m?r=!1:i.delete(e,null,!0)})),r&&i.add(t)}}},i.add=function(e,n){if(!l&&(c||o.testMode)){e=Number(e);var r=s[h][e]||s[p][e]||s[E][e];if(r&&"object"==typeof r){var a,u=n;if(n&&!Array.isArray(n)&&(u=decodeURIComponent(n).split(",")),n&&i.isPathIn(u,["hrefArray"]))(a=i.find(u)).push(e);else if(-1!==i.getFiles([d,m,"hrefArray"]).indexOf(e)||u||(u=[d]),n&&i.isPathIn(u,[d])){if(a=i.find(u)){var f=i.getAvailableName(a,t.createChannelId());return void(a[f]=e)}a=i.find([d]),u.slice(1).forEach((function(e){a=a[e]=a[e]||{}})),a[t.createChannelId()]=e}}}},i.setFolderData=function(e,n,r,o){if(!l){var a=i.find(e);if(i.isFolder(a)&&!i.isSharedFolder(a)){if(!i.hasFolderData(a))a["000"+t.createChannelId().slice(0,-3)]={metadata:!0};i.getFolderData(a)[n]=r,o()}}};var w=function(e){i.rt?(i.rt.sync(),n.whenRealtimeSyncs(i.rt,e)):r.setTimeout(e,1e3)};return i.migrateReadOnly=function(e){if(!l&&o.editKey)if(s.version>=2)e();else{s.migrateRo=1;w((function(){var t=JSON.parse(JSON.stringify(s));i.reencrypt(o.editKey,o.editKey,t),setTimeout((function(){s.version>=2?e():(Object.keys(t).forEach((function(e){s[e]=t[e]})),s.version=2,delete s.migrateRo,w(e))}),1e3)}))}else e({error:"EFORBIDDEN"})},i.migrate=function(n){if(l)n();else{!function(){if(s[v]&&s[y]){A("UNSORTED still exists in the object, removing it...");var e=s[v];0!==e.length?(e.forEach((function(e){"string"==typeof e&&(0===s[y].filter((function(t){return t.href===e})).length&&s[y].push({href:e}))})),delete s[v]):delete s[v]}}(),function(n){if(s[y])try{A("Migrating file system..."),s.migrate=1;w((function(){var r=s[y].slice();s[h]||(s[h]={});var o=s[h];r.forEach((function(n){if(n&&n.href){var r=n.href,a=e.createRandomInteger(),s=i.findFile(r),c=n,u=t.createChannelId();o[a]=c||{href:r},s.forEach((function(e){var t=e.slice(),n=t.pop(),r=i.find(t);if(i.isInTrashRoot(e))return r.element=a,void(o[a].filename=e[1]);i.isPathIn(e,["hrefArray"])?r[n]=a:(r[u]=a,o[a].filename=n,delete r[n])}))}})),delete s[y],delete s.migrate,n()}))}catch(e){console.error(e),n()}else n()}(n)}},i.fixFiles=function(n){if(!l){n&&(A=function(){});var r=+new Date;A("Cleaning file system...");var a=JSON.stringify(s),f=function(n){"object"!=typeof s[d]&&(A("ROOT was not an object"),s[d]={});var r=n||s[d];if(!r)return console.error("Invalid element in root");var o,a=0,c=s[p],u=s[h];for(var l in r)if(null!==(o=r[l]))if(i.isFolderData(o))0!==a&&(A("Multiple metadata files in folder"),delete r[l]),a++;else if(i.isFile(o,!0)||i.isFolder(o))if(i.isFolder(o))f(o);else{if("string"==typeof o){var y=e.createRandomInteger(),v=t.createChannelId();u[y]={href:i.cryptor.encrypt(o),filename:l},r[v]=y,delete r[l]}if("number"==typeof o)u[o]||c[o]||(A("An element in ROOT doesn't have associated data",o,l),delete r[l])}else A("An element in ROOT was not a folder nor a file. ",o),delete r[l];else console.error("element[%s] is null",l),delete r[l]};e.isObject(s[p])||(A("STATIC_DATA was not an object"),s[p]={}),f(),function(){if(!u){"object"!=typeof s[m]&&(A("TRASH was not an object"),s[m]={});var t,n=s[m],r=function(n,r,o){if("object"==typeof n){if(!i.isSharedFolder(n.element))if(i.isFile(n.element,!0)||i.isFolder(n.element))if(Array.isArray(n.path)){if("string"==typeof n.element){var a=e.createRandomInteger();s[h][a]={href:i.cryptor.encrypt(n.element),filename:o},n.element=a}if(i.isFolder(n.element)&&f(n.element),"number"==typeof n.element)s[h][n.element]||s[p][n.element]||(A("An element in TRASH doesn't have associated data",n.element,o),t.push(r))}else t.push(r);else t.push(r)}else t.push(r)};for(var o in n)if(Array.isArray(n[o]))if(0===n[o].length)A("Empty array in TRASH root. ",n[o]),delete n[o];else{t=[];for(var a=0;a<n[o].length;a++)r(n[o][a],a,o);for(var c=t.length-1;c>=0;c--)n[o].splice(t[c],1)}else A("An element in TRASH root is not an array. ",n[o]),delete n[o]}}(),function(){if(!u){Array.isArray(s[g])||(A("TEMPLATE was not an array"),s[g]=[]);var t=e.deduplicateString(s[g]);t.length!==s[g].length&&(s[g]=t);var n=s[g],r=i.getFiles([d]),o=[];n.forEach((function(t,a){if(i.isFile(t,!0)&&-1===r.indexOf(t)){if("string"==typeof t){var c=e.createRandomInteger();return s[h][c]={href:i.cryptor.encrypt(t)},void(n[a]=c)}if("number"==typeof t)s[h][t]||(A("An element in TEMPLATE doesn't have associated data",t),o.push(t))}else o.push(t)})),o.forEach((function(e){var t=n.indexOf(e);-1!==t&&n.splice(t,1)}))}}(),function(){"object"!=typeof s[h]&&(A("FILES_DATA was not an object"),s[h]={});var e=s[h],n=i.getFiles([d,m,"hrefArray"]),r=i.find([d]),a=[];for(var u in e)if(String(u)===String(Number(u))){var f=e[u=Number(u)];if(f&&"object"==typeof f)if(f.href||f.roHref){var y;try{y=f.href&&(-1!==f.href.indexOf("#")?f.href:i.cryptor.decrypt(f.href))}catch(e){}if(!y||-1!==y.indexOf("#")){var v,g=t.parsePadUrl(y||f.roHref);if(g.hash)if(g.type){if(y&&"pad"===g.hashData.type&&g.hashData.version)if("view"===g.hashData.mode)f.roHref=y,delete f.href;else if(f.roHref){var E=t.parsePadUrl(f.roHref);E.hash&&E.type||(v=t.getSecrets(g.type,g.hash,f.password),f.roHref="/"+g.type+"/#"+t.getViewHashFromKeys(v))}else v=t.getSecrets(g.type,g.hash,f.password),f.roHref="/"+g.type+"/#"+t.getViewHashFromKeys(v);if(0===g.hashData.version&&delete f.roHref,y&&"/"!==y.slice(0,1)&&(f.href=i.cryptor.encrypt(t.getRelativeHref(y))),f.ctime||(f.ctime=f.atime),f.title||(f.title=i.getDefaultName(g)),!f.channel)try{v||(v=t.getSecrets(g.type,g.hash,f.password)),f.channel=v.channel,console.log(f),A("Adding missing channel in filesData ",f.channel)}catch(e){console.error(e)}if(t.isValidChannel(f.channel)||console.error("Remove invalid channel",f.channel,f),!c&&!o.testMode||-1!==n.indexOf(u));else A("An element in filesData was not in ROOT, TEMPLATE or TRASH.",u,f),r[t.createChannelId()]=u}else A("Removing an element in filesData with a invalid type.",f),a.push(u);else A("Removing an element in filesData with a invalid href.",f),a.push(u)}}else A("Removing an element in filesData with a missing href.",f),a.push(u);else A("An element in filesData was not an object.",f),a.push(u)}else A("Invalid file ID in filesData.",u),a.push(u);a.forEach((function(e){_(e)}));var b=s[p],w=[];for(var O in b){var D=b[O=Number(O)];D&&"object"==typeof D&&D.href?!c&&!o.testMode||-1!==n.indexOf(O)||w.push(O):w.push(O)}w.forEach((function(e){l||delete s[p][e]}))}(),Object.keys(s).forEach((function(e){"/"===e.slice(0,1)&&delete s[e]})),function(){if(!u){"object"!=typeof s[E]&&(A("SHARED_FOLDER was not an object"),s[E]={});var e,n,r=s[E],o=i.getFiles([d,m]),a=i.find([d]);for(var c in r){var l;n=r[c],c=Number(c);try{l=n.href&&(-1!==n.href.indexOf("#")?n.href:i.cryptor.decrypt(n.href))}catch(e){}if((e=t.parsePadUrl(l||n.roHref))&&e.hash&&"undefined"!==e.hash){if(-1===o.indexOf(c))console.log("missing"+c),a[t.createChannelId()]=c}else delete r[c]}}}(),function(){if(!u){"object"!=typeof s[b]&&(A("SHARED_FOLDER_TEMP was not an object"),s[b]={});var e=s[b],t=s[E];for(var n in e)t[n]&&delete e[n]}}();var y=+new Date-r+"ms";JSON.stringify(s)===a?A("File system was clean.",y):A("Your file system was corrupted. It has been cleaned so that the pads you visit can be stored safely.",y)}},i},o};e.exports&&(e.exports=t(Ne(),Fe(),mt()))})()}(yt)),yt.exports}function Et(){return lt||(lt=1,function(e){(()=>{const t=(e,t,n,r,o,a={})=>{let i=globalThis;var s={setCustomize:e=>{a=e.Messages,r.setCustomize(e)}},c=s.ROOT="root",u=s.UNSORTED="unsorted",l=s.TRASH="trash",f=s.TEMPLATE="template",d=s.SHARED_FOLDERS="sharedFolders",h=s.SHARED_FOLDERS_TEMP="sharedFoldersTemp",p=s.FILES_DATA=n.storageKey,y=s.OLD_FILES_DATA=n.oldStorageKey,v=s.STATIC_DATA="static";s.getDefaultName=function(e){var t=e.type;return a.type[t]+" - "+function(){if(i.Intl&&i.Intl.DateTimeFormat)return new i.Intl.DateTimeFormat(void 0,{weekday:"short",year:"numeric",month:"long",day:"numeric"}).format(new Date);return(new Date).toString().split(" ").slice(0,4).join(" ")}()};var m=s.createCryptor=function(e){var t={};if(!e)return t.encrypt=function(e){return e},t.decrypt=function(e){return e},t;try{var n=o.createEncryptor(e);t.encrypt=function(e){try{return"/file/#"===e.slice(0,7)?e:n.encrypt(e)}catch(e){return}},t.decrypt=function(e){try{return n.decrypt(e)}catch(e){return}}}catch(e){console.error(e)}return t};return s.getHref=function(e,t){if(e.href&&-1!==e.href.indexOf("#"))return e.href;if(e.href&&t){var n=t.decrypt(e.href);if(n&&-1!==n.indexOf("#"))return n}return e.roHref},s.reencrypt=function(e,t,n){if(n){var r=m(e),o=m(t);Object.keys(n[p]).forEach((function(e){var t=n[p][e]||{};if(t.href&&t.roHref&&!t.fileType){var a=t.href&&-1===t.href.indexOf("#")?r.decrypt(t.href):t.href;if(!a)return;t.href=o.encrypt(a)}})),Object.keys(n[d]||{}).forEach((function(e){var t=n[d][e]||{};if(t.href){var a=t.href&&-1===t.href.indexOf("#")?r.decrypt(t.href):t.href;if(!a)return;t.href=o.encrypt(a)}})),Object.keys(n[h]||{}).forEach((function(e){var t=n[h][e]||{};if(t.href){var a=t.href&&-1===t.href.indexOf("#")?r.decrypt(t.href):t.href;if(!a)return;t.href=o.encrypt(a)}}))}else console.error("Nothing to reencrypt")},s.init=function(n,o){var i={};i.cryptor=m(o.editKey),i.setReadOnly=function(e,t){o.editKey=t,i.cryptor=m(t),i.cryptor.k=Math.random(),i.readOnly=e,i._setReadOnly&&i._setReadOnly(e)},i.readOnly=o.readOnly,i.reencrypt=s.reencrypt,i.getDefaultName=s.getDefaultName;var g=o.sframeChan,E=a.fm_newFolder||"New folder",b=a.fm_newFile||"New file";i.ROOT=c,i.STATIC_DATA=v,i.UNSORTED=u,i.TRASH=l,i.TEMPLATE=f,i.SHARED_FOLDERS=d,i.SHARED_FOLDERS_TEMP=h,i.FILES_DATA=p,i.OLD_FILES_DATA=y;var A=i.sharedFolder=o.sharedFolder;i.id=o.id;var _=function(){console.debug.apply(console,arguments)},w=i.log=o.log||_,O=o.logError||_,D=i.debug=o.debug||_;i.fixFiles=function(){};var S=i.error=function(){g?g.query("Q_DRIVE_USEROBJECT",{cmd:"fixFiles",data:{}},(function(){})):("function"==typeof i.fixFiles&&i.fixFiles(),console.error.apply(console,arguments),i.fixFiles())};o.outer&&r.init(o,i,n),i.getStructure=function(){var e={};return e[c]={},e[l]={},e[p]={},e[f]=[],e[d]={},e};var T=i.getHref=function(e){return s.getHref(e,i.cryptor)},C=function(e){return null===e?"null":Array.isArray(e)?"array":typeof e};i.isValidDrive=function(e){var t=i.getStructure();return"object"==typeof e&&Object.keys(t).every((function(n){return e[n]&&C(t[n])===C(e[n])}))};var x=function(){return[f]},I=function(e,t){return e===t},N=i.isSharedFolder=function(e){return!A&&Boolean(n[d]&&n[d][e])},P=i.isFile=function(e,t){return!N(e)&&("number"==typeof e||(void 0!==n[y]||t)&&"string"==typeof e)},k=i.isFolderData=function(e){return"object"==typeof e&&!0===e.metadata};i.isReadOnlyFile=function(e){if(!P(e))return!1;var t=i.getFileData(e);return t.roHref?Boolean(t.roHref&&!t.href):void 0},i.isStaticFile=function(e){return Boolean(n[v]&&n[v][e])};var R=i.isFolder=function(e){return!k(e)&&("object"==typeof e&&!e.channel||N(e))};i.isFolderEmpty=function(e){return!!R(e)&&(0===Object.keys(e).length||!(1!==Object.keys(e).length||!k(e[Object.keys(e)[0]])))},i.hasSubfolder=function(e,t){if(!R(e))return!1;var n=0,r=function(e){n+=R(e.element)?1:0};for(var o in e)t?Array.isArray(e[o])&&e[o].forEach(r):n+=R(e[o])?1:0;return n},i.hasFile=function(e,t){if(!R(e))return!1;var n=0,r=function(e){n+=P(e.element)?1:0};for(var o in e)t?Array.isArray(e[o])&&e[o].forEach(r):n+=P(e[o])?1:0;return n},i.hasFolderData=function(e){for(var t in e)if(k(e[t]))return!0};var M=i.hasSubSharedFolder=function(e){for(var t in e){if(N(e[t]))return!0;if(R(e[t])&&M(e[t]))return!0}return!1},F=i.getFileData=function(t,r){if(t){var a,s;try{a=(n[v]||{})[t]}catch(e){console.error(e)}if(a){var c=r?a:e.clone(a);return r||(c.static=!0),c}try{s=n[p][t]||{}}catch(e){console.error(e),s={}}if(!r&&(s=JSON.parse(JSON.stringify(s))).href&&-1===s.href.indexOf("#"))if(o.editKey)try{s.href=i.cryptor.decrypt(s.href)}catch(e){delete s.href}else delete s.href;return s}};i.getFolderData=function(e){for(var t in e)if(k(e[t]))return e[t];return{}};var L=i.getTitle=function(e,t){if(N(e))return"??";var n=F(e);if(n){if(n.static)return n.name;if(e&&(n.href||n.roHref))return"title"===t?n.title:"name"===t?n.filename:n.filename||n.title||b;S("getTitle called with a non-existing file id: ",e,n)}else S("unable to retrieve data about the requested file: ",e,n)},H=i.comparePath=function(e,t){if(!(e&&t&&Array.isArray(e)&&Array.isArray(t)))return!1;if(e.length!==t.length)return!1;for(var n=!0,r=e.length-1;n&&r>=0;)n=e[r]===t[r],r--;return n},K=i.isSubpath=function(e,t){var n=t.slice(),r=e.slice(0,n.length);return H(n,r)},j=i.isPathIn=function(e,t){if(t){var n=t.indexOf("hrefArray");return-1!==n&&(t.splice(n,1),t=t.concat(x())),t.some((function(t){return Array.isArray(e)&&e[0]===t}))}},U=i.isInTrashRoot=function(e){return e[0]===l&&4===e.length},B=function(e,t){if(t){if(0===t.length)return e;var n=t.slice(),r=n.shift();if(void 0!==e[r])return B(e[r],n);D("Unable to find the key '"+r+"' in the root object provided:",e)}else S("Invalid path:\n",t,"\nin root\n",e)},V=i.find=function(e){return B(n,e)},G=i.getFilesRecursively=function(e,t){for(var n in t=t||[],e)P(e[n])||N(e[n])?-1===t.indexOf(e[n])&&t.push(e[n]):k(e[n])||G(e[n],t);return t},Y={array:function(e){return n[e]||(n[e]=[]),n[e].slice()}};x().forEach((function(e){Y[e]=function(){return Y.array(e)}})),Y.hrefArray=function(){var t=[];return A?t:(x().forEach((function(e){t=t.concat(Y[e]())})),e.deduplicateString(t))},Y[c]=function(){var e=[];return G(n[c],e),e},Y[l]=function(){var e=n[l],t=[],r=function(e){P(e.element)||N(e.element)?-1===t.indexOf(e.element)&&t.push(e.element):G(e.element,t)};for(var o in e){if(!Array.isArray(e[o]))return void S("Trash contains a non-array element");e[o].forEach(r)}return t},Y[y]=function(){var e=[];return n[y]?(n[y].forEach((function(t){t.href&&-1===e.indexOf(t.href)&&e.push(t.href)})),e):e},Y[v]=function(){return n[v]?Object.keys(n[v]).map(Number).filter(Boolean):[]},Y[p]=function(){return n[p]?Object.keys(n[p]).map(Number).filter(Boolean):[]},Y[d]=function(){return n[d]?Object.keys(n[d]).map(Number).filter(Boolean):[]};var J=i.getFiles=function(t){var n=[];return t&&t.length||(t=[c,"hrefArray",l,y,p,d]),t.forEach((function(e){"function"==typeof Y[e]&&(n=n.concat(Y[e]()))})),e.deduplicateString(n)},q=i.getIdFromHref=function(e){var r,o=function(e){if(e)return t.parsePadUrl(e).getUrl().replace(/\/p\/?/,"/")},a=o(e);return J([p]).some((function(e){if(o(T(n[p][e]))===a||o(n[p][e].roHref)===a)return r=e,!0})),r};i.getSFIdFromHref=function(e){var r,o=function(e){if(e)return t.parsePadUrl(e).getUrl().replace(/\/p\/?/,"/")},a=o(e);return J([d]).some((function(e){if(o(T(n[d][e]))===a||o(n[d][e].roHref)===a)return r=e,!0})),r};var W=function(e,t){if(!j(e,[c,l]))return[];t=Array.isArray(t)?t:[t];var n={},r=V(e),o=function(e){Object.keys(e).forEach((t=>{n[t]||=[],Array.prototype.push.apply(n[t],e[t])}))};if(P(r)||N(r))return t.some((t=>{I(t,r)&&(n[t]||=[],n[t].push(e))})),n;if(R(r))for(var a in r){let n=e.slice();n.push(a),o(W(n,t))}return n},Q=function(e,t){if(A)return{};if(!n[e])return{};var r=n[e].slice(),o={},a=-1;return t.forEach((t=>{for(;-1!==(a=r.indexOf(t,a+1));)o[t]||=[],o[t].push([e,a])})),o},z=function(e,t){if(A)return[];var n=V(e),r={},o=function(e){Object.keys(e).forEach((t=>{r[t]||=[],Array.prototype.push.apply(r[t],e[t])}))};if(1===e.length&&"object"==typeof n&&Object.keys(n).forEach((function(r){var a=n[r];if(Array.isArray(a)){var i=e.slice();i.push(r),o(z(i,t))}})),2===e.length){if(!Array.isArray(n))return[];n.forEach((function(n,a){var i=e.slice();i.push(a),i.push("element"),P(n.element)?t.some((e=>{I(e,n.element)&&(r[e]||=[],r[e].push(i))})):o(z(i,t))}))}return e.length>=4&&o(W(e,t)),r},X=i.findFiles=function(e){var t=W([c],e),n=Q(f,e),r=z([l],e);let o={};return e.forEach((e=>{o[e]=[]})),[t,n,r].forEach((e=>{Object.keys(e).forEach((t=>{o[t]||=[],Array.prototype.push.apply(o[t],e[t])}))})),o},Z=i.findFile=function(e){return X([e])[e]||[]};i.findChannels=function(e,t){var r=n[p],o=n[d],a=[p];return t&&a.push(d),J(a).filter((function(t){var n=r[t]||o[t]||{};return-1!==e.indexOf(n.channel)}))},i.search=function(r){if("string"!=typeof r)return[];r=r.trim();var o,a=[],s=n[p],u=n[d],l=r.toLowerCase();/^#/.test(l)&&(o=[l.slice(1).trim()]);J([p,d]).forEach((function(e){var t=s[e]||u[e];if(t)if(Array.isArray(t.tags)&&(n=t.tags,o&&n.length&&(n=n.map((function(e){return e.toLowerCase()})),o.some((function(e){return n.some((function(t){return t===e}))})))))a.push(e);else{var n,r=t.title||t.lastTitle;(r&&-1!==r.toLowerCase().indexOf(l)||t.filename&&-1!==t.filename.toLowerCase().indexOf(l))&&a.push(e)}}));var f=t.getRelativeHref(r);if(f){var h=q(f);h&&a.push(h)}a=e.deduplicateString(a);var y=[];a.forEach((function(e){y.push({id:e,paths:Z(e),data:i.getFileData(e)})}));var v=[],m=function(e,t){for(var n in e)R(e[n])&&!N(e[n])&&(-1!==n.toLowerCase().indexOf(l)&&v.push({id:null,paths:[t.concat(n)],data:{title:n}}),m(e[n],t.concat(n)))};return m(n[c],[c]),v=v.sort((function(e,t){return e.data.title.toLowerCase()>t.data.title.toLowerCase()})),y=v.concat(y)},i.getRecentPads=function(){var e=n[p];return Object.keys(e).filter((function(t){return e[t]})).sort((function(t,n){return e[n].atime-e[t].atime})).map((function(e){return Number(e)}))},i.getOwnedPads=function(e){var t=n[p];return Object.keys(t).filter((function(n){return t[n].owners&&-1!==t[n].owners.indexOf(e)})).map((function(e){return Number(e)}))};var $=i.getAvailableName=function(e,t){if(void 0===e[t])return t;for(var n=t,r=1;void 0!==e[n];)n=t+"_"+r,r++;return n},ee=i.move=function(e,t,n){if(g)g.query("Q_DRIVE_USEROBJECT",{cmd:"move",data:{paths:e,newPath:t}},n);else{var r=[];e.forEach((function(e){var n=e.slice();n.pop(),H(n,t)||(K(t,e)?w(a.fo_moveFolderToChildError):i.copyElement(e.slice(),t)&&r.push(e))})),i.delete(r,n)}};return i.restore=function(e,t){if(g)g.query("Q_DRIVE_USEROBJECT",{cmd:"restore",data:{path:e}},t);else if(U(e)){var n=e.slice();n.pop();var r=V(n).path;ee([e],r,t)}},i.addFolder=function(e,t,n){if(g)g.query("Q_DRIVE_USEROBJECT",{cmd:"addFolder",data:{path:e,name:t}},n);else{var r=V(e),o=$(r,t||E);r[o]={};var a=e.slice();a.push(o),n({newPath:a})}},i.delete=function(e,t,n){g?g.query("Q_DRIVE_USEROBJECT",{cmd:"delete",data:{paths:e,nocheck:n}},t):(t=t||function(){},i.deleteMultiplePermanently(e,n,t))},i.emptyTrash=function(e){e=e||function(){},g?g.query("Q_DRIVE_USEROBJECT",{cmd:"emptyTrash"},e):(n[l]={},i.checkDeletedFiles(e))},i.ownedInTrash=function(e){return J([l]).map((function(t){var r=N(t)?n[d][t]:i.getFileData(t);if(r)return e(r.owners)?r.channel:void 0})).filter(Boolean)},i.rename=function(e,t,r){if(r=r||function(){},g)g.query("Q_DRIVE_USEROBJECT",{cmd:"rename",data:{path:e,newName:t}},r);else if(e.length<=1)O("Renaming `root` is forbidden");else{var o,i=V(e);if(R(i)&&!N(i)){var s=e.slice(),c=s.pop();if(!t||!t.trim()||c===t)return;var u=V(s);return void 0!==u[t]?void w(a.fo_existingNameError):(u[t]=i,delete u[c],void("function"==typeof r&&r()))}if(o=N(i)?n[d][i]:n[p][i]||n[v][i])return n[v][i]?t&&t.trim()?(o.name=t,void r()):void r():t&&""!==t.trim()?void(L(i,"name")!==t&&(o.filename=t,"function"==typeof r&&r())):(delete o.filename,void("function"==typeof r&&r()))}},i.getTagsList=function(){var e,t={},r=function(e){t[e]=t[e]?++t[e]:1};for(var o in n[p])(e=n[p][o]).tags&&Array.isArray(e.tags)&&e.tags.forEach(r);return t},i},s};e.exports&&(e.exports=t(Ne(),Fe(),Oe(),gt(),ye(),void 0))})()}(pt)),pt.exports}var bt,At,_t,wt,Ot={exports:{}};function Dt(){return bt||(bt=1,function(e){e.exports=function(e){var t,n=[],r=[],o=0,a=function(e){return o++,function(){for(e&&e.apply(null,arguments),o=(o||1)-1;!o&&n.length&&!t;)n.shift()(a)}};a.abort=function(){r.forEach(clearTimeout),t=1};var i={nThen:function(e){return t||(o?n.push(e):e(a)),i},orTimeout:function(e,s){if(t)return i;if(!s)throw Error("Must specify milliseconds to orTimeout()");var c,u=setTimeout((function(){for(;n.shift()!==c;);for(e(a),o=(o||1)-1;!o&&n.length;)n.shift()(a)}),s);return n.push(c=function(){var e=r.indexOf(u);if(e>-1)return r.splice(e,1),void clearTimeout(u);throw new Error("timeout not listed in array")}),r.push(u),i}};return i.nThen(e)}}(Ot)),Ot.exports}function St(){if(_t)return At;_t=1;return At=((e,t,n,r,o,a,i,s)=>{var c={},u={};return c.checkMigration=function(e,n,r,o){var a=t.once(t.mkAsync(o));if(n)if(e)if(n.version>=2)a();else if(n.migrateRo){var i,s=!1,c=setInterval((function(){if(n.version>=2)return s=!0,clearTimeout(i),clearInterval(c),void a()}),100);i=setTimeout((function(){clearInterval(c),r.migrateReadOnly((function(){s=!0,a()}))}),2e4);n.on("change",["version"],(function(){s||n.version>=2&&(s=!0,clearTimeout(i),clearInterval(c),a())}))}else r.migrateReadOnly(a);else a();else a()},c.migrate=function(e){var n=u[e];if(n){var r=n.teams;if(Array.isArray(r)&&r.length){var o=r[0];if(o.secondaryKey){var a=t.find(o,["store","manager","folders",o.id]);a&&a.proxy&&!a.proxy.version&&a.userObject.migrateReadOnly((function(){r.forEach((function(e){t.find(e,["store","manager","folders",e.id,"userObject"]).setReadOnly(!1,e.secondarykey)}))}))}}}},c.load=function(n,l,f,d){var h=t.once(t.mkAsync(d)),p=n.network,y=n.store,v=n.isNew,m=n.isNewChannel,g=y.id,E=y.handleSharedFolder,b=y.manager.user.userObject.getHref(f),A=e.parsePadUrl(b),_=e.getSecrets("drive",A.hash,f.password);if(!_.keys)return y.manager.deprecateProxy(l),void h(null);var w=_.keys.secondaryKey;o((function(e){n.cache&&r.getChannelCache(_.channel,e((function(t){if("EINVAL"===t)return e.abort(),y.manager.restrictedProxy(l,_.channel),void h(null)})))})).nThen((function(e){m(null,{channel:_.channel},e((function(t){if(t.isNew&&!v)return y.manager.deprecateProxy(l,_.channel,t.reason),e.abort(),void h(null)})))})).nThen((function(){var e=u[_.channel];if(e&&e.readOnly&&w&&c.upgrade(_.channel,_),e&&e.ready&&e.rt)return setTimeout((function(){y.manager.addProxy(l,e.rt,(function(){c.leave(_.channel,g)}),w),h(e.rt)})),e.teams.push({cb:h,store:y,id:l}),void(E&&E(l,e.rt));if(e&&!e.ready&&e.rt)return e.teams.push({cb:h,store:y,secondaryKey:w,id:l}),void(E&&E(l,e.rt));e=u[_.channel]={teams:[{cb:h,store:y,secondaryKey:w,id:l}],readOnly:!Boolean(w)};var t=f.owners,o={data:{},channel:_.channel,readOnly:!Boolean(w),crypto:a.createEncryptor(_.keys),userName:"sharedFolder",logLevel:1,ChainPad:s,classic:!0,network:p,Cache:r,metadata:{validateKey:_.keys.validateKey||void 0,owners:t},onRejected:n.Store&&n.Store.onRejected},d=e.rt=i.create(o);d.proxy.on("cacheready",(function(){e.teams&&(e.teams.forEach((function(t){d.cache=!0,t.store.manager.addProxy(t.id,d,(function(){c.leave(_.channel,t.store.id)}),t.secondaryKey,n.updatePassword),n.updatePassword=!1,t.cb(e.rt)})),e.ready=!0)})),d.proxy.on("ready",(function(){v&&!Object.keys(d.proxy).length&&(d.proxy.version=2),e.teams&&(e.teams.forEach((function(t){d.cache=!1,t.store.manager.addProxy(t.id,d,(function(){c.leave(_.channel,t.store.id)}),t.secondaryKey,n.updatePassword),t.cb(e.rt)})),e.ready=!0)})),d.proxy.on("error",(function(t){if(t&&t.error){if("EDELETED"===t.error){try{e.teams.forEach((function(e){e.store.manager.deprecateProxy(e.id,_.channel,t.message),e.store.handleSharedFolder&&e.store.handleSharedFolder(e.id,null),e.cb()}))}catch(e){}return delete u[_.channel],void h()}if("ERESTRICTED"===t.error)return e.teams.forEach((function(e){e.store.manager.restrictedProxy(e.id,_.channel),e.cb()})),delete u[_.channel],void h()}})),E&&E(l,d)}))},c.upgrade=function(e,t){var n=u[e];if(n&&n.readOnly&&n.rt.setReadOnly&&t.keys&&t.keys.editKeyStr){var r=a.createEncryptor(t.keys);n.readOnly=!1,n.rt.setReadOnly(!1,r)}},c.leave=function(e,t){var n=u[e];if(n){var r,o=n.teams;if(Array.isArray(o))o.some((function(e,n){if(e.store.id===t)return e.store.handleSharedFolder&&e.store.handleSharedFolder(e.id,null),r=n,!0})),void 0!==r&&(o.splice(r,1),o.length||n.rt&&n.rt.stop&&n.rt.stop())}},c.updatePassword=function(r,a,i,s){var l=a.oldChannel,f=a.href,d=a.password,h=e.parsePadUrl(f),p=e.getSecrets(h.type,h.hash,d),y=u[l];if(y){if(y.rt&&y.rt.stop)try{y.rt.stop()}catch(e){}var v=o;y.teams.forEach((function(e){v=v((function(o){var a=e.store,s=e.id,u=t.find(a.proxy,["drive",n.SHARED_FOLDERS])||{};if(s&&u[s]){var f=JSON.parse(JSON.stringify(u[s]));f.password=d,c.load({network:i,store:a,updatePassword:!0,Store:r,isNewChannel:r.isNewChannel},s,f,o()),a.rpc&&(a.rpc.unpin([l],o()),a.rpc.pin([p.channel],o()))}})).nThen})),v((function(){s()}))}else s({error:"ENOTFOUND"})},c.loadSharedFolders=function(e,t,r,a,i,s,u,l){var f=a[n.SHARED_FOLDERS]||{},d=Object.keys(f).length,h=1,p=s();u=u||function(){},o((function(n){Object.keys(f).forEach((function(o){var a=f[o];c.load({network:t,store:r,Store:e,cache:l,isNewChannel:e.isNewChannel},o,a,n((function(){u({progress:h,max:d}),h++})))}))})).nThen((function(){setTimeout(p)}))},c.isSharedFolderChannel=function(e){return Object.keys(u).includes(e)},c})(Fe(),Ne(),Et(),Ge(),Dt(),ye(),S(),I()),At}function Tt(){return wt||(wt=1,function(e){(()=>{const t=(e,t,n,r={},o,a,i={})=>{var s=function(t,n,r,o,a,i){if(!t.folders[n]||i||t.folders[n].restricted){var s=function(e){var t={};for(var n in e.cfg)t[n]=e.cfg[n];return t}(t);s.sharedFolder=!0,s.id=n,s.editKey=a,s.rt=r.realtime,s.readOnly=Boolean(!a);var c=e.init(r.proxy,s);c.fixFiles&&c.fixFiles();var u=r.proxy;if(u.metadata&&u.metadata.title){var l=t.user.proxy[e.SHARED_FOLDERS][n];l&&(l.lastTitle=u.metadata.title)}return t.folders[n]={proxy:r.proxy,userObject:c,leave:o,restricted:u.restricted,offline:Boolean(r.cache)},u.on&&(u.on("disconnect",(function(){t.folders[n].offline=!0})),u.on("reconnect",(function(){t.folders[n].offline=!1}))),c}t.folders[n].offline&&!r.cache&&t.Store&&(t.folders[n].offline=!1,t.folders[n].userObject.fixFiles&&t.folders[n].userObject.fixFiles(),t.Store.refreshDriveUI())},c=function(e,t){var n=e.folders[t];n&&(n.leave(),delete e.folders[t])},u=function(n,r,o,a){if(!n.folders[r]||!n.folders[r].deleting){if(n.user.userObject.readOnly){return c(n,r),s(n,r,{proxy:{deprecated:!0}},(function(){})),void n.Store.refreshDriveUI()}if(o&&n.unpinPads([o],(function(){})),a&&"PASSWORD_CHANGE"!==a){let o=t.find(n,["user","proxy",e.SHARED_FOLDERS]),a=o[r]&&o[r].lastTitle;return a&&((e,t,n)=>{var r=e.store.mailbox;if(r){var o,a=e.cfg.teamId;o=a?e.store.modules.team.getTeamsData()[a]:e.Store.getMetadata(null,null,(()=>{})).user,r.sendTo("SF_DELETED",{sfId:t,team:a,title:n},{curvePublic:o.curvePublic,channel:o.notifications},(e=>{console.error(e)}))}})(n,r,a),delete o[r],void(n.Store&&n.Store.refreshDriveUI&&n.Store.refreshDriveUI())}n.user.userObject.deprecateSharedFolder(r,a),c(n,r),n.Store&&n.Store.refreshDriveUI&&n.Store.refreshDriveUI()}},l=function(e,t){c(e,t),s(e,t,{proxy:{restricted:!0,root:{},filesData:{}}},(function(){})),e.Store.refreshDriveUI()},f=function(e,t){return Array.isArray(t)&&-1!==t.indexOf(e.edPublic)},d=function(e){var t=[e.user.userObject],n=Object.keys(e.folders).map((function(t){return e.folders[t].userObject}));return Array.prototype.push.apply(t,n),t},h=function(e,t){var n=d(e),r=e.user.userObject;return n.some((function(e){if(Object.keys(e.getFileData(t)).length)return r=e,!0})),r},p=function(e,t){var n=Number(t.id);if(n)return e.user.userObject.findFile(n)[0]},y=function(t,n,r){var o=[];return t.user.userObject.findChannels([n],!0).forEach((function(n){var a=t.user.proxy[e.SHARED_FOLDERS][n];a&&!r&&(a=JSON.parse(JSON.stringify(a))),a||(a=t.user.userObject.getFileData(n,r)),o.push({id:n,data:a,userObject:t.user.userObject})})),Object.keys(t.folders).forEach((function(e){t.folders[e].userObject.findChannels([n]).forEach((function(n){o.push({id:n,fId:e,data:t.folders[e].userObject.getFileData(n,r),userObject:t.folders[e].userObject})}))})),o},v=function(e,t){var n=[],r=e.user.userObject.getIdFromHref(t);return r&&n.push({data:e.user.userObject.getFileData(r),userObject:e.user.userObject}),Object.keys(e.folders).forEach((function(r){var o=e.folders[r].userObject.getIdFromHref(t);o&&n.push({fId:r,data:e.folders[r].userObject.getFileData(o),userObject:e.folders[r].userObject})})),n},m=function(e,t){var n=[],r=d(e);let o={};return r.forEach((function(e){var a=Number(e.id);let i;if(a){i=e.findFile(t);let n=(o[a]||[])[0];if(!n)return;i.forEach((function(e){Array.prototype.unshift.apply(e,n)}))}else{let n=[t],a=r.map((e=>+e.id)).filter(Boolean);Array.prototype.push.apply(n,a),o=e.findFiles(n),i=o[t]}Array.prototype.push.apply(n,i)})),n},g=function(e,t){var n={},r=d(e);let o={};return r.forEach((function(e){var a=Number(e.id);if(!e.id){let e=r.map((e=>+e.id)).filter(Boolean);Array.prototype.push.apply(t,e)}var i=e.findFiles(t);if(e.id||(o=i),a){let e=(o[a]||[])[0];if(!e)return;Object.keys(i).forEach((t=>{i[t].forEach((t=>{Array.prototype.unshift.apply(t,e)}))}))}Object.keys(i).forEach((e=>{n[e]||=[],Array.prototype.push.apply(n[e],i[e])}))})),n},E=function(e,n,r){if(r)return e.user.userObject.findChannels(n);var o=[];return d(e).forEach((function(e){var t=e.findChannels(n);Array.prototype.push.apply(o,t)})),o=t.deduplicateString(o)},b=function(e,t,n){var r=d(e),o={};return r.some((function(e){if((o=e.getFileData(t,n))&&Object.keys(o).length)return!0})),o},A=function(n,r){var o;if(n.isHistoryMode&&!n.folders[r])o=!0;else if(!n.folders[r])return{};var a=o?{}:n.folders[r].proxy;Object.keys(a.metadata||{}).length>1&&(a.metadata={title:a.metadata.title});var i=t.clone(a.metadata||{});for(var s in n.user.proxy[e.SHARED_FOLDERS][r]||{})if(void 0!==n.user.proxy[e.SHARED_FOLDERS][r][s]){var c=t.clone(n.user.proxy[e.SHARED_FOLDERS][r][s]);if("href"===s&&-1===c.indexOf("#"))try{c=n.user.userObject.cryptor.decrypt(c)}catch(e){}"href"===s&&-1===c.indexOf("#")&&(c=void 0),i[s]=c}return i},_=function(e,t){var n,r={id:null,userObject:e.user.userObject,path:t};if(!Array.isArray(t)||t.length<=1)return r;for(var o=e.user.userObject,a=2;a<t.length;a++)if(n=o.find(t.slice(0,a)),o.isSharedFolder(n)){r={id:n,userObject:e.folders[n]?.userObject,path:t.slice(a)};break}return r},w=function(e,t){var n=[],r={};return t.forEach((function(t){var o=_(e,t);o.id?r[o.id]?r[o.id].push(o.path):r[o.id]=[o.path]:n.push(o.path)})),{main:n,folders:r}},O=function(e,t){var n=_(e,t);return"number"==typeof n.id&&n.id},D=function(e,t,n){if(!t||!O(e,t)){var r=b(e,n||e.user.userObject.find(t));if(r&&f(e,r.owners)){var o=r.channel;if(o)return Object.keys(e.folders).map((function(t){return e.folders[t].userObject})).some((function(e){return e.findChannels([o]).length}))}}},S=function(e,n,o){var a=[],i=[];return n.forEach((function(n,s){var c=o.find(n),u=[],l=n[n.length-1];if(o.isFile(c))u.push(c);else if(o.isSharedFolder(c)){u.push(c);var f=e.folders[c].proxy.metadata||{};f&&(l=f.title)}else{try{c=JSON.parse(JSON.stringify(c))}catch(e){return}o.getFilesRecursively(c,u)}if(u.some((function(e){return o.isSharedFolder(e)})))return e.cfg&&e.cfg.log&&e.cfg.log(r._getKey("fm_moveNestedSF",[l])),void i.unshift(s);u=t.deduplicateString(u);var d={};u.forEach((function(e){d[e]=o.getFileData(e)})),a.push({el:c,data:d,key:l})})),i.forEach((function(e){n.splice(e,1)})),a},T=function(e,t){var r;return y(e,t).some((function(e){if(e&&e.data&&e.data.href){var t=n.parsePadUrl(e.data.href),o=t.hashData;if(o&&"view"!==o.mode)return r=t.hash,!0}})),r},C=function(e,t,n){var r=w(e,t.paths),o=_(e,t.newPath),i=t.copy;o.userObject.isFolder(o.path)?a((function(t){if(r.main.length)if(o.id){var n=S(e,r.main,e.user.userObject),a=o.userObject;if(n.forEach((function(e){a.copyFromOtherDrive(o.path,e.el,e.data,e.key)})),i)return;r.main.length&&e.user.userObject.delete(r.main,t())}else e.user.userObject.move(r.main,o.path,t());var s=Object.keys(r.folders);s.length&&s.forEach((function(n){var a=Number(n),s=r.folders[a];if(o.id===a)o.userObject.move(s,o.path,t());else{var c=e.folders[a].userObject,u=o.userObject;if(S(e,s,c).forEach((function(e){u.copyFromOtherDrive(o.path,e.el,e.data,e.key)})),i)return;c.delete(s,t())}}))})).nThen((function(){n()})):n()},x=function(t,o,s){var c=_(t,(o=o||{}).path);if(c&&c.userObject)if(c.id)s({error:"EINVAL"});else if(t.pinPads){var u,l=o.folderData||{};a((function(){if(!o.folderData){var e=n.createRandomHash("drive",o.password),r=n.getSecrets("drive",e,o.password),a=n.getHashes(r);l={href:"/drive/#"+a.editHash,roHref:"/drive/#"+a.viewHash,channel:r.channel,lastTitle:o.name,ctime:+new Date},o.password&&(l.password=o.password),o.owned&&(l.owners=[t.edPublic])}})).nThen((function(e){t.Store.pad.getMetadata(null,{channel:l.channel},e((function(t){if(t&&(t.error||t.rejected))return e.abort(),void s({error:t.error||"ERESTRICTED"})})))})).nThen((function(e){t.pinPads([l.channel],e())})).nThen((function(e){t.user.userObject.pushSharedFolder(l,e((function(r,o){if("EEXISTS"===r&&l.href&&o){var a=n.parsePadUrl(l.href),c=n.getSecrets("drive",a.hash,l.password);return i.upgrade(c.channel,c),t.folders[o]&&t.folders[o].userObject.setReadOnly(!1,c.keys.secondaryKey),e.abort(),void s(o)}return"EEXISTS"===r&&o?(e.abort(),void s(o)):r?(e.abort(),void s(r)):void(u=o)})))})).nThen((function(n){t.user.userObject.add(u,c.path),t.loadSharedFolder(u,l,n((function(a){if(!a)return n.abort(),void s({error:"EDELETED"});a.proxy.metadata||(a.proxy.metadata={title:o.name||r.fm_newFolder}),o.folderData&&t.Store.pad.getMetadata(null,{channel:l.channel},(function(n){var r=t.user.proxy[e.SHARED_FOLDERS][u];n.owners&&(r.owners=n.owners),n.expire&&(r.expire=+n.expire)}))})),!Boolean(o.folderData))})).nThen((function(){t.onSync((function(){s(u)}))}))}else s({error:"EAUTH"});else s({error:"E_NOTFOUND"})},I=function(r,o,i){var s=(o=o||{}).resolved||w(r,o.paths);if(s.main.length||Object.keys(s.folders).length){if(o.paths&&1===o.paths.length&&o.paths[0][0]===e.SHARED_FOLDERS_TEMP)return delete t.find(r,["user","proxy",e.SHARED_FOLDERS_TEMP])[o.paths[0][1]],void r.onSync(i);var c=[];a((function(n){if(s.main.length){var o=r.user.userObject;t.find(r.settings,["drive","hideDuplicate"])&&s.main.forEach((function(t){var n=o.find(t);if(t[0]!==e.FILES_DATA&&!o.isFile(n)&&!o.isSharedFolder(n)){var a=[];o.getFilesRecursively(n,a),a.forEach((function(t){D(r,null,t)&&r.user.userObject.add(Number(t),[e.ROOT])}))}})),o.delete(s.main,n((function(e,t){r.unpinPads&&t&&Array.prototype.push.apply(c,t)})))}})).nThen((function(e){Object.keys(s.folders).forEach((function(t){r.folders[t].userObject.delete(s.folders[t],e((function(e,t){r.unpinPads&&t&&Array.prototype.push.apply(c,t)})))}))})).nThen((function(e){if(r.unpinPads){c=t.deduplicateString(c);var o=[];E(r,c).forEach((function(e){var t=b(r,e),a=[t.channel];t.answersChannel&&a.push(t.answersChannel),t.rtChannel&&a.push(t.rtChannel),t.lastVersion&&a.push(n.hrefToHexChannelId(t.lastVersion)),Array.prototype.push.apply(o,a)}));var a=[];c.forEach((function(e){-1===o.indexOf(e)&&(a.push(e),r.Store.checkDeletedPad(e))})),r.unpinPads(a,e((function(e){if(e&&e.error)return console.error(e.error)})))}})).nThen((function(){i()}))}else i({error:"E_NOTFOUND"})},N=function(n,r,i){var s=w(n,(r=r||{}).paths||[]);if(r.channel||s.main.length||Object.keys(s.folders).length){var c={main:[],folders:{}},u=function(r,a,i,s){var u,l=t.once(t.mkAsync(s)),f=r;if(!f&&a){var d=a.find(i);if(!a.isFile(d)&&!a.isSharedFolder(d))return;var h=a.isFile(d)?a.getFileData(d):A(n,d);f=h.channel}Object.keys(n.user.proxy[e.SHARED_FOLDERS]||{}).some((function(t){if((n.user.proxy[e.SHARED_FOLDERS][t]||{}).channel===f)return u=Number(t),n.folders[t].deleting=!0,!0})),n.removeOwnedChannel(f,(function(e){if(e&&e.error&&"ENOENT"!==e.error)return u&&n.folders[u]&&n.folders[u].deleting&&delete n.folders[u].deleting,o.send("ERROR_DELETING_OWNED_PAD="+f+"|"+e.error,!0),void l();var t=E(n,[f]);if(u&&t.push(u),!t.length)return c=void 0,void l();t.forEach((function(e){var t=m(n,e),r=w(n,t);Array.prototype.push.apply(c.main,r.main),Object.keys(r.folders).forEach((function(e){c.folders[e]?Array.prototype.push.apply(c.folders[e],r.folders[e]):c.folders[e]=r.folders[e]}))})),l()}))};a((function(e){r.channel&&u(r.channel,null,null,e()),s.main.forEach((function(t){u(null,n.user.userObject,t,e())})),Object.keys(s.folders).forEach((function(t){var r=n.folders[t].userObject;s.folders[t].forEach((function(t){u(null,r,t,e())}))}))})).nThen((function(){c?I(n,{resolved:c},i):i(),r.channel&&n.Store.refreshDriveUI()}))}else i({error:"E_NOTFOUND"})},P={move:C,restore:function(e,t,n){t=t||{},e.user.userObject.restore(t.path,n)},addFolder:function(e,t,n){var r=_(e,(t=t||{}).path);r&&r.userObject?r.userObject.addFolder(r.path,t.name,(function(t){if(t.newPath&&r.id){var o=p(e,r.userObject);o&&Array.prototype.unshift.apply(t.newPath,o)}n(t)})):n({error:"E_NOTFOUND"})},addSharedFolder:x,addLink:function(e,t,n){var r=_(e,(t=t||{}).path);if(r&&r.userObject){var o=r.userObject,a=+new Date;o.pushLink({name:t.name,href:t.href,atime:a,ctime:a},(function(t,a){t?n({error:t}):(o.add(a,r.path),e.onSync(n))}))}else n({error:"E_NOTFOUND"})},restoreSharedFolder:function(r,o,i){var s=o.id,c=o.password,u=t.find(r,["user","proxy",e.SHARED_FOLDERS_TEMP]),l=u&&u[s];if(l)if(r.Store){var f=r.user.userObject.getHref?r.user.userObject.getHref(l):l.href,d=!1;a((function(e){r.Store.isNewChannel(null,{href:f,password:c},e((function(e){d=!(!e||e.error)&&e.isNew})))})).nThen((function(){if(d)i({error:"ENOTFOUND"});else{var e=t.clone(l),o=n.parsePadUrl(f),a=n.getSecrets(o.type,o.hash,c);e.password=c,e.channel=a.channel,a.keys.editKeyStr&&(e.href="/drive/#"+n.getEditHashFromKeys(a)),e.roHref="/drive/#"+n.getViewHashFromKeys(a),delete e.legacy,x(r,{path:["root"],folderData:e},(function(){delete u[s],r.onSync(i)}))}}))}else i({error:"ESTORE"});else i({error:"EINVAL"})},convertFolderToSharedFolder:function(t,n,r){var o=n.path,i=t.user.userObject.find(o);if(o.length<=1||o[0]!==e.ROOT)r({error:"E_INVAL_PATH"});else if(O(t,o))r({error:"E_INVAL_NESTING"});else if(t.user.userObject.hasSubSharedFolder(i))r({error:"E_INVAL_NESTING"});else{var s,c=o.slice(0,-1),u=t.user.userObject.find(c),l=o[o.length-1];a((function(e){x(t,{path:c,name:l,owned:n.owned,password:n.password||""},e((function(t){if("object"==typeof t&&t&&t.error)return e.abort(),void r(t);s=t})))})).nThen((function(n){if(!s)return n.abort(),void r({error:"E_NO_ID"});var a,l=[];for(var f in i)(t.user.userObject.isFolder(i[f])||t.user.userObject.isFile(i[f]))&&l.push(o.concat(f));if(Object.keys(u).some((function(e){if(u[e]===s)return a=e,!0})),!a)return n.abort(),void r({error:"E_NO_KEY"});var d=c.concat(a).concat(e.ROOT);C(t,{paths:l,newPath:d,copy:!1},n())})).nThen((function(n){var r=[];Object.keys(i).forEach((function(e){if(t.user.userObject.isFile(i[e])){var n=t.user.userObject.getFileData(i[e]);n&&f(t,n.owners)&&r.push(o.concat(e))}})),C(t,{paths:r,newPath:[e.ROOT],copy:!1},n())})).nThen((function(){var n=t.user.proxy[e.SHARED_FOLDERS][s],a=t.user.userObject.getFolderData(i);for(var c in a)"metadata"!==c&&(n[c]=a[c]);t.user.userObject.delete([o],(function(){r({fId:s})}))}))}},delete:I,deleteOwned:N,emptyTrash:function(e,n,r){a((function(r){if(n&&n.deleteOwned){var i=e.user.userObject.ownedInTrash((function(t){return f(e,t)})),s=a;i.forEach((function(t){s=s((function(n){e.removeOwnedChannel(t,n((function(e){setTimeout(n(),50),e&&e.error&&"ENOENT"!==e.error&&(console.error(e.error,t),o.send("ERROR_EMPTYTRASH_OWNED="+t+"|"+e.error,!0)),console.warn("DELETED",t)})))})).nThen})),s(r())}e.user.userObject.emptyTrash(r((function(n,o){var i=a;setTimeout(r((function(){if(Array.isArray(o)){var n=r(),a=t.deduplicateString(o),s=[];a.forEach((function(t){i=i((function(n){y(e,t,!0).length||s.push(t),e.Store.checkDeletedPad(t,n())})).nThen})),i((function(){e.unpinPads(s,(function(){n()}))}))}})))})))})).nThen(r)},rename:function(t,n,o){var a=_(t,(n=n||{}).path);if(a&&a.userObject){if(!a.id){var i=t.user.userObject.find(a.path);if(t.user.userObject.isSharedFolder(i)&&t.folders[i])return t.folders[i].proxy.metadata.title=n.newName||r.fm_folder,t.user.proxy[e.SHARED_FOLDERS][i].lastTitle=n.newName||r.fm_folder,void o()}a.userObject.rename(a.path,n.newName,o)}else o({error:"E_NOTFOUND"})},setFolderData:function(t,n,r){var o=_(t,(n=n||{}).path);if(o&&o.userObject){if(!o.id){var a=t.user.userObject.find(o.path);if(t.user.userObject.isSharedFolder(a)&&t.folders[a])return t.user.proxy[e.SHARED_FOLDERS][a][n.key]=n.value,void t.onSync(r)}o.userObject.setFolderData(o.path,n.key,n.value,(function(){t.onSync(r)}))}else r({error:"E_NOTFOUND"})},updateStaticAccess:function(e,t,n){h(e,t).getFileData(t,!0).atime=+new Date,e.onSync(n)}},k=function(e,t,n){var r=t.cmd,o=t.data||{},a=P[r];"function"!=typeof a?n():a(e,o,n)},R=function(t,n,r){if(r=r||function(){},n.attr&&n.attr.trim()){var o=t.user.userObject.getSFIdFromHref(n.href);o&&("href"===n.attr&&(n.value=t.user.userObject.cryptor.encrypt(n.value)),t.user.proxy[e.SHARED_FOLDERS][o][n.attr]=n.value);var i=v(t,n.href),s=a;i.forEach((function(e){s=s((function(t){e.userObject.setPadAttribute(n.href,n.attr,n.value,t())})).nThen})),s((function(){r()}))}else r("E_INVAL_ATTR")},M=function(e,t,n){n=n||function(){};var r=e.user.userObject.getSFIdFromHref(t.href);if(r){var o=A(e,r),a=t.attr?o[t.attr]:JSON.parse(JSON.stringify(o));setTimeout((function(){n(null,{value:a,atime:1})}))}else{var i=v(e,t.href),s={};i.forEach((function(e){var n=e.data.atime,r=t.attr?e.data[t.attr]:JSON.parse(JSON.stringify(e.data));(!s.value||s.atime<n)&&(s.atime=n,s.value=r)})),setTimeout((function(){n(null,s)}))}},F=function(e){var t={};return d(e).forEach((function(e){var n=e.getTagsList();Object.keys(n).forEach((function(e){t[e]=t[e]?t[e]+n[e]:n[e]}))})),t},L=function(e,t){var n=d(e),r=[],o=[];return n.forEach((function(e){var n=e.getFiles(t).map((function(t){return{id:t,data:e.getFileData(t)}})).filter((function(e){if(-1===o.indexOf(e.data.channel||e.id))return o.push(e.data.channel||e.id),!0}));Array.prototype.push.apply(r,n)})),r},H=function(e){return e.filter((function(e){if("string"==typeof e)return-1!==[32,48].indexOf(e.length)}))},K=function(t,r){var o=[],a=function(e){return"expirable"===r?function(n){var r=e.getFileData(n);r&&-1===o.indexOf(r.channel)&&(function(e,t){return Array.isArray(t)&&t.length&&(!e.edPublic||-1===t.indexOf(e.edPublic))}(t,r.owners)||r.expire&&r.expire<+new Date)&&o.push(r.channel)}:"owned"===r?function(n){var r=e.getFileData(n);r&&-1===o.indexOf(r.channel)&&f(t,r.owners)&&o.push(r.channel)}:"pin"===r?function(t){var r=e.getFileData(t);if(r){if(r.lastVersion){var a=n.hrefToHexChannelId(r.lastVersion);-1===o.indexOf(a)&&o.push(a)}r.answersChannel&&-1===o.indexOf(r.answersChannel)&&o.push(r.answersChannel),r.rtChannel&&-1===o.indexOf(r.rtChannel)&&o.push(r.rtChannel),r.ooImages&&Array.isArray(r.ooImages)&&Array.prototype.push.apply(o,r.ooImages),-1===o.indexOf(r.channel)&&o.push(r.channel)}}:void 0};if("owned"===r&&!t.edPublic)return H(o);if("pin"===r&&!t.edPublic)return H(o);if(d(t).forEach((function(t){t.getFiles([e.FILES_DATA]).forEach(a(t))})),"owned"===r){var i=Object.keys(t.user.proxy[e.SHARED_FOLDERS]).filter((function(n){var r=t.user.proxy[e.SHARED_FOLDERS][n].owners;if(f(t,r))return!0})).map((function(n){return t.user.proxy[e.SHARED_FOLDERS][n].channel}));Array.prototype.push.apply(o,i)}if("pin"===r){var s=Object.keys(t.folders).map((function(n){try{return t.user.proxy[e.SHARED_FOLDERS][n].channel}catch(e){console.error(e)}})).filter(Boolean);Array.prototype.push.apply(o,s)}return H(o)},j=function(e,t,n,r){var o=e.user.userObject,i=["root"];if(t){var s=_(e,t);o=s.userObject,i=s.path}var c=function(){var e;a((function(t){o.pushData(n,t((function(t,n){t?e=t:o.add(n,i)})))})).nThen((function(){r(e)}))};e.pinPads?e.pinPads([n.channel],(function(e){e&&e.error?r(e.error):c()})):c()},U=function(e,t,n,r){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"rename",data:{path:t,newName:n}},r)},B=function(e,t,n,r,o){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"move",data:{paths:t,newPath:n,copy:o}},r)},V=function(e,t,n){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"emptyTrash",data:{deleteOwned:t}},n)},G=function(e,t,n,r){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"addFolder",data:{path:t,name:n}},r)},Y=function(e,t,n,r){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"addSharedFolder",data:{path:t,name:n.name,owned:n.owned,password:n.password}},r)},J=function(e,t,n,r){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"addLink",data:{path:t,name:n.name,href:n.url}},r)},q=function(e,t,n,r){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"restoreSharedFolder",data:{id:t,password:n}},r)},W=function(e,t,n,r,o){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"convertFolderToSharedFolder",data:{path:t,owned:n,password:r}},o)},Q=function(e,t,n){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"delete",data:{paths:t}},n)},z=function(e,t,n){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"deleteOwned",data:{paths:t}},n)},X=function(e,t,n){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"restore",data:{path:t}},n)},Z=function(e,t,n){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"setFolderData",data:t},n)},$=function(e,t,n){e.sframeChan.query("Q_DRIVE_USEROBJECT",{cmd:"updateStaticAccess",data:t},n)},ee=E,te=b,ne=p,re=function(e,t,n){if(n)return e.folders[n].userObject.find(t);var r=_(e,t);return r.userObject.find(r.path)},oe=function(e,t,n){var r=h(e,t);return String(r.getTitle(t,n))},ae=function(e,t){return h(e,t).isStaticFile(t)},ie=function(e,t){return h(e,t).isReadOnlyFile(t)},se=function(e,n){var r=[];return d(e).forEach((function(e){Array.prototype.push.apply(r,e.getFiles(n))})),r=t.deduplicateString(r)},ce=function(e,t){var n=[];return d(e).forEach((function(r){var o=p(e,r),a=r.search(t);a.length&&(o&&a.forEach((function(e){e.inSharedFolder=!0,e.paths.forEach((function(e){Array.prototype.unshift.apply(e,o)}))})),Array.prototype.push.apply(n,a))})),n},ue=function(t){var n=[];return d(t).forEach((function(t){var r=t.getFiles([e.FILES_DATA,e.STATIC_DATA]).map((function(e){return[Number(e),t.getFileData(e)]}));Array.prototype.push.apply(n,r)})),n.filter((function(e){return e[1].atime})).sort((function(e,t){return t[1].atime-e[1].atime}))},le=function(e){return e.user.userObject.getOwnedPads(e.edPublic)},fe=function(e,t){e.isHistoryMode=Boolean(t)},de=function(e,t){var n=_(e,t);if(!n||!n.userObject)return{};if(!n.id){var r=e.user.userObject.find(n.path);if(e.user.userObject.isSharedFolder(r))return A(e,r)}var o=n.userObject.find(n.path);return n.userObject.getFolderData(o)},he=O,pe=function(e,t){return e.user.userObject.isValidDrive(t)},ye=function(e,t,n){return e.user.userObject.isFile(t,n)},ve=function(e,t){return e.user.userObject.isFolder(t)},me=function(e,t){return e.user.userObject.isSharedFolder(t)},ge=function(e,t){if(e.folders[t]){var n=e.folders[t].userObject;return n.isFolderEmpty(n.find[n.ROOT])}return e.user.userObject.isFolderEmpty(t)},Ee=function(e,t,n){return e.user.userObject.isPathIn(t,n)},be=function(e,t,n){return e.user.userObject.isSubpath(t,n)},Ae=function(e,t){return e.user.userObject.isInTrashRoot(t)},_e=function(e,t,n){return e.user.userObject.comparePath(t,n)},we=function(e,t,n){if(e.folders[t]){var r=e.folders[t].userObject;return r.hasSubfolder(r.find[r.ROOT])}return e.user.userObject.hasSubfolder(t,n)},Oe=function(e,t){return e.user.userObject.hasSubSharedFolder(t)},De=function(e,t,n){if(e.folders[t]){var r=e.folders[t].userObject;return r.hasFile(r.find[r.ROOT])}return e.user.userObject.hasFile(t,n)},Se=function(e){return e.user.userObject.ownedInTrash((function(t){return f(e,t)}))},Te=D;return{setCustomize:t=>{r=t.Messages,e.setCustomize(t)},create:function(t,n,r){var o={pinPads:n.pin,unpinPads:n.unpin,onSync:n.onSync,Store:n.Store,store:n.store,removeOwnedChannel:n.removeOwnedChannel,loadSharedFolder:n.loadSharedFolder,cfg:r,edPublic:n.edPublic,settings:n.settings,user:{proxy:t},folders:{}};r.removeProxy=function(e){c(o,e)},o.user.userObject=e.init(t,r);var a=function(e){return function(){return[].unshift.call(arguments,o),e.apply(null,arguments)}};return{addProxy:a(s),removeProxy:a(c),deprecateProxy:a(u),restrictedProxy:a(l),addSharedFolder:a(x),addPin:function(e,t){o.pinPads=e,o.unpinPads=t},removePin:function(){delete o.pinPads,delete o.unpinPads},command:a(k),getPadAttribute:a(M),setPadAttribute:a(R),getTagsList:a(F),getSecureFilesList:a(L),getSharedFolderData:a(A),getChannelsList:a(K),addPad:a(j),delete:a(I),deleteOwned:a(N),findChannel:a(y),findHref:a(v),findFile:a(m),getEditHash:a(T),user:o.user,folders:o.folders}},createInner:function(t,n,r,o){var a={cfg:o,sframeChan:n,edPublic:r,user:{proxy:t,userObject:e.init(t,o)},folders:{}},i=function(e){return function(){return[].unshift.call(arguments,a),e.apply(null,arguments)}};return{addProxy:i(s),removeProxy:i(c),setHistoryMode:i(fe),rename:i(U),move:i(B),emptyTrash:i(V),addFolder:i(G),addSharedFolder:i(Y),addLink:i(J),restoreSharedFolder:i(q),convertFolderToSharedFolder:i(W),delete:i(Q),deleteOwned:i(z),restore:i(X),setFolderData:i(Z),updateStaticAccess:i($),getFileData:i(te),find:i(re),getTitle:i(oe),isReadOnlyFile:i(ie),isStaticFile:i(ae),getFiles:i(se),search:i(ce),getRecentPads:i(ue),getOwnedPads:i(le),getTagsList:i(F),findFile:i(m),findFiles:i(g),findChannels:i(ee),getSharedFolderData:i(A),getFolderData:i(de),isInSharedFolder:i(he),getUserObjectPath:i(ne),isDuplicateOwned:i(Te),ownedInTrash:i(Se),isValidDrive:i(pe),isFile:i(ye),isFolder:i(ve),isSharedFolder:i(me),isFolderEmpty:i(ge),isPathIn:i(Ee),isSubpath:i(be),isInTrashRoot:i(Ae),comparePath:i(_e),hasSubfolder:i(we),hasSubSharedFolder:i(Oe),hasFile:i(De),user:a.user,folders:a.folders}}}};e.exports&&(e.exports=t(Et(),Ne(),Fe(),void 0,nt(),Dt(),St()))})()}(ht)),ht.exports}var Ct,xt,It=Tt(),Nt=t({__proto__:null,default:r(It)},[It]),Pt=Et(),kt=t({__proto__:null,default:r(Pt)},[Pt]),Rt={exports:{}},Mt={exports:{}};function Ft(){return xt||(xt=1,function(e){e.exports&&(e.exports=((e={},t={},n)=>{let r=[];const o=["sheet","doc","presentation"],a=a=>{e=a.AppConfig;const i=(t=a.ApiConfig).onlyOffice&&t.onlyOffice.availableVersions.includes(n.currentVersion);r=e.availablePadTypes.filter((e=>i||!o.includes(e)))};Object.keys(e).length&&a({AppConfig:e,ApiConfig:t});const i={OO_APPS:o,setCustomize:a};return i.__defineGetter__("availableTypes",(function(){return t.appsToDisable?r.filter((e=>!t.appsToDisable.includes(e))):r})),i.__defineGetter__("appsToSelect",(function(){return r.filter((e=>!["drive","teams","file","contacts","convert"].includes(e)))})),i.isAvailable=e=>Array.isArray(i.availableTypes)&&i.availableTypes.includes(e),i})(void 0,void 0,(Ct||(Ct=1,function(e){e.exports&&(e.exports={currentVersionNumber:8,currentVersion:"v8"})}(Mt)),Mt.exports)))}(Rt)),Rt.exports}var Lt,Ht,Kt=Ft(),jt=t({__proto__:null,default:r(Kt)},[Kt]),Ut={exports:{}},Bt={exports:{}};function Vt(){return Lt||(Lt=1,function(e){(()=>{const t=(e,t,n={},r,o)=>{const a=function(){if(Object.keys(n).length){var e,t=new URL(n.httpUnsafeOrigin);try{return(e=new URL(n.websocketPath,n.httpUnsafeOrigin)).protocol=t.protocol,e.origin}catch(e){return console.error(e),n.httpUnsafeOrigin}}};var i=a();var s=e=>JSON.parse(JSON.stringify(e)),c=function(e,n,r){var o=t.once(t.mkAsync(r));fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}).then((e=>{e.ok?e.text().then((e=>{o(void 0,t.tryParse(e))})):e.json().then().then((t=>{o(e.status,t)}))})).catch((e=>{o(e)}))},u=function(n,r,a){var u=s(r);u.publicKey=t.encodeBase64(n.publicKey),u.nonce=t.encodeBase64(o.CryptoAgility.bytes(24));var l,f,d=new URL("/api/auth/",i);e((function(e){c(d,u,e(((t,n)=>t?(e.abort(),console.error(t),n&&console.error(n),void a(t)):n.date&&n.txid?(l=n.txid,void(f=n.date)):(e.abort(),void a("REQUEST_REJECTED")))))})).nThen((function(e){var r=s(u);r.txid=l,r.date=f;var i=t.decodeUTF8(JSON.stringify(r)),h=o.CryptoAgility.signDetached(i,n.secretKey),p=t.encodeBase64(h);c(d,{sig:p,txid:l},e(((t,n)=>{if(t)return e.abort(),console.error(t),n&&console.error(n),void a("RESPONSE_REJECTED",n);a(void 0,n)})))}))};return u.setCustomize=e=>{n=e.ApiConfig,i=a()},u};e.exports&&(e.exports=t(Dt(),Ne(),void 0,h(),ye()))})()}(Bt)),Bt.exports}function Gt(){return Ht||(Ht=1,function(e){e.exports&&(e.exports=((e,t={},n,r,o)=>{var a={setCustomize:e=>{t=e.ApiConfig,n.setCustomize(e)}};a.join=e.uint8ArrayJoin,a.seed=function(){return o.CryptoAgility.createHash(e.decodeUTF8("pewpewpew"))},a.genkeys=function(e){if(!(e instanceof Uint8Array))throw new Error("INVALID_SEED_FORMAT");if(!e||"number"!=typeof e.length||e.length<64)throw new Error("INVALID_SEED_LENGTH");var t=e.subarray(0,o.CryptoAgility.signSeedLength()),n=e.subarray(o.CryptoAgility.signSeedLength(),o.CryptoAgility.signSeedLength()+o.CryptoAgility.secretboxKeyLength()),a=o.CryptoAgility.signKeyPairFromSeed(t),i=null;if(o.PQC&&o.PQC.ml_dsa)try{var s=r.hash(e).subarray(0,32);i=o.CryptoAgility.generateDsaKeypair(s)}catch(e){console.error("Failed to generate post-quantum keys:",e),i=null}return{sign:a,pqSignPair:i,symmetric:n,hasPQ:null!==i}},a.keysToRPCFormat=function(t){try{var n=t.sign,r=t.pqSignPair;return{edPrivate:e.encodeBase64(n.secretKey),edPublic:e.encodeBase64(n.publicKey),dsaPrivate:e.encodeBase64(r.secretKey),dsaPublic:e.encodeBase64(r.publicKey)}}catch(e){return void console.error(e)}},a.encrypt=function(t,n,r){var i=e.decodeUTF8(n),s=o.CryptoAgility.bytes(o.CryptoAgility.secretboxNonceLength());return a.join([[0],s,o.CryptoAgility.secretbox(i,s,r.symmetric)])},a.decrypt=function(t,n){var r=o.CryptoAgility.secretboxNonceLength(),a=t.subarray(1,1+r),i=t.subarray(1+r),s=o.CryptoAgility.secretboxOpen(i,a,n.symmetric);try{return JSON.parse(e.encodeUTF8(s))}catch(e){return void console.error(e)}},a.sign=function(e,t){var n=o.CryptoAgility.createHash(e);if(t.hasPQ&&t.pqSignPair)try{var r=o.CryptoAgility.signDetached(n,t.sign.secretKey),a=o.PQC.ml_dsa.ml_dsa44.internal.sign(t.pqSignPair.secretKey,n);console.log("Hybrid signature created successfully:");var i=new Uint8Array(1+r.length+4+a.length);return i[0]=1,i.set(r,1),new DataView(i.buffer).setUint32(1+r.length,a.length,!1),i.set(a,1+r.length+4),i}catch(e){console.error("PQ signing failed, falling back to classical:",e)}r=o.CryptoAgility.signDetached(n,t.sign.secretKey);var s=new Uint8Array(r.length+1);return s[0]=0,s.set(r,1),s},a.serialize=function(t,n){var r=a.encrypt(0,t,n),o=a.sign(r,n);return{publicKey:e.encodeBase64(n.sign.publicKey),pqPublicKey:e.encodeBase64(n.pqSignPair.publicKey),signature:e.encodeBase64(o),ciphertext:e.encodeBase64(r)}},a.proveAncestor=function(t){var n=e.find(t,["sign","publicKey"]);try{let r=[n,a.sign(n,t)].map(e.encodeBase64);return t.pqSignPair&&t.pqSignPair.publicKey&&r.push(e.encodeBase64(t.pqSignPair.publicKey)),JSON.stringify(r)}catch(e){return void console.error(e)}};var i=function(t){return e.encodeBase64(t).replace(/\//g,"-")};a.getBlockUrl=function(e){var n=i(e.sign.publicKey);return(t.fileHost||t.httpUnsafeOrigin||window.location.origin)+"/block/"+n.slice(0,2)+"/"+n},a.getBlockHash=function(e){return a.getBlockUrl(e)+"#"+i(e.symmetric)};var s=function(t){try{return e.decodeBase64(t.replace(/\-/g,"/"))}catch(e){return void console.error(e)}};return a.parseBlockHash=function(e){if("string"==typeof e){var t=e.split("#");if(2===t.length)try{return{href:t[0],keys:{symmetric:s(t[1])}}}catch(e){return void console.error(e)}}},a.checkRights=function(t,r){const o=e.mkAsync(r),{blockKeys:a,auth:i}=t;var s="MFA_CHECK";i&&i.type&&(s=`${i.type.toUpperCase()}_`+s),n(a.sign,{command:s,auth:i&&i.data},o)},a.writeLoginBlock=function(e,t){const{content:r,blockKeys:o,oldBlockKeys:i,auth:s,pw:c,session:u,token:l,userData:f}=e;var d="WRITE_BLOCK";s&&s.type&&(d=`${s.type.toUpperCase()}_`+d);var h=a.serialize(JSON.stringify(r),o);h.auth=s&&s.data,h.hasPassword=c,h.registrationProof=i&&a.proveAncestor(i),l&&(h.inviteToken=l),f&&(h.userData=f),n(o.sign,{command:d,content:h,session:u},t)},a.removeLoginBlock=function(e,t){const{reason:r,blockKeys:o,auth:a,edPublic:i}=e;var s="REMOVE_BLOCK";a&&a.type&&(s=`${a.type.toUpperCase()}_`+s),n(o.sign,{command:s,auth:a&&a.data,edPublic:i,reason:r},t)},a.updateSSOBlock=function(e,t){const{blockKeys:r,oldBlockKeys:o}=e;var i=o&&a.proveAncestor(o);n(r.sign,{command:"SSO_UPDATE_BLOCK",ancestorProof:i},t)},a})(Ne(),void 0,Vt(),h(),ye()))}(Ut)),Ut.exports}var Yt,Jt,qt,Wt=Gt(),Qt=t({__proto__:null,default:r(Wt)},[Wt]),zt={exports:{}};function Xt(){return Yt||(Yt=1,function(e){var t;t=function(){var e=function(t){if(Array.isArray(t))return t.map(e);if(t instanceof Object){var n=[],r=[];return Object.keys(t).forEach((function(e){/^(0|[1-9][0-9]*)$/.test(e)?n.push(+e):r.push(e)})),n.sort((function(e,t){return e-t})).concat(r.sort()).reduce((function(n,r){return n[r]=e(t[r]),n}),{})}return t},t=JSON.stringify.bind(JSON);return function(n,r,o){var a=t(n,r,0);if(!a||"{"!==a[0]&&"["!==a[0])return a;var i=JSON.parse(a);return t(e(i),null,o)}},e.exports?e.exports=t():JSON.sortify=t()}(zt)),zt.exports}function Zt(){if(qt)return Jt;qt=1;var e,t,n,r,o,a,i,s;return ye(),e=Fe(),t=Ne(),Oe(),n=mt(),o=(r={}).createData=function(n,r){var o={channel:r||e.createChannelId(),displayName:n["cryptpad.username"],profile:n.profile&&n.profile.view,edPublic:n.edPublic,curvePublic:n.curvePublic,dsaPublic:n.dsaPublic,kemPublic:n.kemPublic,notifications:t.find(n,["mailboxes","notifications","channel"]),avatar:n.profile&&n.profile.avatar,badge:n.profile&&n.profile.badge,uid:n.uid};return!1===r&&delete o.channel,o},a=r.getFriend=function(e,t){if(t){if(t===e.curvePublic){var n=o(e);return delete n.channel,n}return e.friends?e.friends[t]:void 0}},i=r.getFriendList=function(e){return e.friends||(e.friends={}),e.friends},s=function(e,t){Object.keys(e).forEach((function(n){"me"!==n&&t(e[n],n,e)}))},r.getFriendChannelsList=function(e){var t=[];return s(e.friends,(function(e){t.push(e.channel)})),t},r.declineFriendRequest=function(e,t,n){e.mailbox.sendTo("DECLINE_FRIEND_REQUEST",{},{channel:t.notifications,curvePublic:t.curvePublic},(function(e){n(e)}))},r.acceptFriendRequest=function(e,t,n){var r=a(e.proxy,t.curvePublic)||{},i=o(e.proxy,r.channel||t.channel);e.mailbox.sendTo("ACCEPT_FRIEND_REQUEST",{user:i},{channel:t.notifications,curvePublic:t.curvePublic},(function(e){n(e)}))},r.addToFriendList=function(e,t,r){var o=e.proxy,a=i(o),s=t.curvePublic;s!==o.curvePublic?(a[s]=t,n.whenRealtimeSyncs(e.realtime,(function(){r(),e.pinPads([t.channel],(function(e){e.error&&console.error(e.error)}))}))):r("E_MYKEY")},r.updateMyData=function(e,n){var r=o(e.proxy,!1);e.proxy.friends&&(e.proxy.friends.me=t.clone(r),delete e.proxy.friends.me.channel),e.modules.team&&e.modules.team.updateMyData(r);var i=function(t){t&&t.notifications&&(delete t.user,r.channel=t.channel,e.mailbox.sendTo("UPDATE_DATA",r,{channel:t.notifications,curvePublic:t.curvePublic},(function(e){e&&e.error&&console.error(e)})))};n?i(a(e.proxy,n)):s(e.proxy.friends||{},i)},r.removeFriend=function(e,t,r){var o=e.proxy,a=o.friends[t];a?a.notifications?e.mailbox.sendTo("UNFRIEND",{curvePublic:o.curvePublic},{channel:a.notifications,curvePublic:a.curvePublic},(function(i){i&&i.error?r(i):(e.messenger.onFriendRemoved(t,a.channel),delete o.friends[t],n.whenRealtimeSyncs(e.realtime,(function(){r(i)})))})):r({error:"EINVAL"}):r({error:"ENOENT"})},Jt=r}var $t,en,tn,nn={exports:{}},rn={exports:{}},on={exports:{}};function an(){return $t||($t=1,function(e){var t,n,r,o,a,i,s,c,u,l,f,d;e.exports&&(e.exports=(t=Ne(),h(),n=ye(),r=t.uid,o=t.tryParse,a=function(e,r){var o=t.decodeUTF8(JSON.stringify(e));return t.encodeBase64(n.CryptoAgility.signDetached(o,r))},i=function(e,t,n){if("function"!=typeof n)throw new Error("expected callback");var o=e.network,a=o.historyKeeper;if("string"==typeof a){var i=r(),s=e.pending[i]=function(e,t){n(e,t)};return s.data=t,s.called=0,o.sendto(a,JSON.stringify([i,t]))}n("NO_HISTORY_KEEPER")},s=[],c=[],u=function(e){var t={network:e,connected:!0,anon:void 0,authenticated:[]};return s.push(e),c.push(t),e.on("message",(function(n,r){r===e.historyKeeper&&function(e,t){"string"!=typeof t&&console.error("received non-string message [%s]",t);var n=o(t);if(n){if(Array.isArray(n)&&!/(FULL_HISTORY|HISTORY_RANGE)/.test(n[0])){var r=n[0];"string"==typeof r&&(function(e,t){return!!e.anon&&"function"==typeof e.anon.pending[t]}(e,r)?function(e,t,n){var r=e.pending[t];"ERROR"===n[0]?r(n[1]):r(void 0,n.slice(1)),delete e.pending[t]}(e.anon,r,n.slice(1)):e.authenticated.some((function(e){var t=e.pending[r];return"function"==typeof t&&("ERROR"!==n[1]?(/\|/.test(n[1])&&e.cookie!==n[1]&&(e.cookie=n[1]),t(void 0,n.slice(2)),delete e.pending[r],!0):"NO_COOKIE"===n[2]?(e.send("COOKIE","",(function(n){if(n)return console.error(n),void t(n);e.resend(r)&&delete e.pending[r]})),!0):(t(n[2]),delete e.pending[r],!0))}))||console.error("UNHANDLED RPC MESSAGE",t))}}else console.error(new Error("could not parse message: %s",t))}(t,n)})),e.on("disconnect",(function(){t.connected=!1,t.anon&&(t.anon.connected=!1),t.authenticated.forEach((function(e){e.connected=!1}))})),e.on("reconnect",(function(){t.anon&&(t.anon.connected=!0),t.authenticated.forEach((function(e){e.connected=!0}))})),t},l=function(e){var t;return s.some((function(n,r){return e===n&&(t=r,!0)})),c[t]?c[t]:u(e)},f=function(e,n){if(!e)throw new Error("expected network context");var o,s=n.publicKeyString;return e.authenticated.some((function(e,t){return e.publicKey===s&&(o=t,!0)})),e.authenticated[o]?e.authenticated[o]:function(e,n){var o={network:e.network,publicKey:n.publicKeyString,timeouts:{},pending:{},cookie:null,connected:!0},s=o.send=function(e,r,s){var c=t.mkAsync(s);if(o.connected||"COOKIE"===e){var u=[e,r];o.cookie&&o.cookie.join?u.unshift(o.cookie.join("|")):u.unshift(o.cookie);var l=a(u,n.signKey);return u.unshift(n.publicKeyString),u.unshift(l),i(o,u,c)}c("DISCONNECTED")};return o.resend=function(e){var t=o.pending[e];if(t.called)return console.error("[%s] called too many times",e),!0;t.called++,t.data[2]=o.cookie,t.data[0]=a(t.data.slice(2),n.signKey);var i=r();o.pending[i]=t,delete o.pending[e];try{return o.network.sendto(o.network.historyKeeper,JSON.stringify([i,t.data]))}catch(e){console.log("failed to resend"),console.error(e)}},s.unauthenticated=function(e,r,a){var s=t.mkAsync(a);if(o.connected){var c=[null,n.publicKeyString,null,e,r];return o.cookie&&o.cookie.join?c[2]=o.cookie.join("|"):c[2]=o.cookie,i(o,c,s)}s("DISCONNECTED")},o.destroy=function(){Object.keys(o.timeouts).forEach((function(e){clearTimeout(e)})),o.send("DESTROY","",(function(){}));var t=e.authenticated.indexOf(o);-1!==t&&e.authenticated.splice(t,1)},e.authenticated.push(o),o}(e,n)},d=function(e){return e.anon||function(e){var n={network:e.network,timeouts:{},pending:{},connected:!0};return e.anon=n,n.send=function(e,r,o){var a=t.mkAsync(o);if(n.connected)return i(n,[e,r],a);a("DISCONNECTED")},n.resend=function(e){var t=n.pending[e];if(t.called)return console.error("[%s] called too many times",e),!0;t.called++;try{return n.network.sendto(n.network.historyKeeper,JSON.stringify([e,t.data]))}catch(e){console.log("failed to resend"),console.error(e)}},n.destroy=function(){Object.keys(n.timeouts).forEach((function(e){clearTimeout(e)})),e.anon=void 0},n}(e)},{create:function(e,n,r,o){if("function"!=typeof o)throw new Error("expected callback");var a,i=t.mkAsync(o);try{if(64!==(a=t.decodeBase64(n)).length)throw new Error("private key did not match expected length of 64")}catch(e){return void i(e)}try{if(32!==t.decodeBase64(r).length)return void i("expected public key to be 32 uint")}catch(e){return void i(e)}if(e){var s=l(e),c=f(s,{publicKeyString:r,signKey:a});c.send("COOKIE","",(function(e){e?i(e):i(void 0,{send:c.send,destroy:c.destroy})}))}else i("NO_NETWORK")},createAnonymous:function(e,n){var r=t.mkAsync(n);if("function"!=typeof r)throw new Error("expected callback");if(e){var o=d(l(e));r(void 0,{send:o.send,destroy:o.destroy})}else r("NO_NETWORK")}}))}(on)),on.exports}function sn(){return en||(en=1,function(e){var t,n;e.exports&&(e.exports=(t=Ne(),n=an(),{create:function(e,r,o,a){if("function"!=typeof o)throw new Error("Expected callback");var i=t.once(t.mkAsync(o));if(e)if(r){var s=r.edPrivate,c=r.edPublic;s&&c?n.create(e,s,c,(function(e,n){if(e)i(e);else{var r={};r.destroy=n.destroy,r.publicKey=c,r.send=n.send,r.pin=function(e,r){var o=t.once(t.mkAsync(r));Array.isArray(e)?n.send("PIN",e,o):o("[TypeError] pin expects an array")},r.unpin=function(e,r){var o=t.once(t.mkAsync(r));Array.isArray(e)?n.send("UNPIN",e,o):o("[TypeError] pin expects an array")},r.adminRpc=function(e,t){if(e.cmd){var r=[e.cmd,e.data];n.send("ADMIN",r,t)}else setTimeout((function(){t("[TypeError] admin rpc expects a command")}))},r.getServerHash=function(e){n.send("GET_HASH",c,(function(t,n){n&&n[0]?e(t,Array.isArray(n)&&n[0]||void 0):e("NO_HASH_RETURNED")}))},r.reset=function(e,r){var o=t.once(t.mkAsync(r));Array.isArray(e)?n.send("RESET",e,o):o("[TypeError] pin expects an array")},r.getFileListSize=function(e){n.send("GET_TOTAL_SIZE",void 0,(function(t,n){t?e(t):n&&n.length&&"number"==typeof n[0]?e(void 0,n[0]):e("INVALID_RESPONSE")}))},r.updatePinLimits=function(e){n.send("UPDATE_LIMITS",void 0,(function(t,n){t?e(t):n&&n.length&&"number"==typeof n[0]?e(void 0,n[0],n[1],n[2]):e("INVALID_RESPONSE")}))},r.getLimit=function(e){n.send("GET_LIMIT",void 0,(function(t,n){t?e(t):n&&n.length&&"number"==typeof n[0]?e(void 0,n[0],n[1],n[2]):e("INVALID_RESPONSE")}))},r.trimHistory=function(e,r){var o=t.once(t.mkAsync(r));"object"==typeof e&&e.channel&&e.hash?n.send("TRIM_HISTORY",e,(function(e){if(e)return o(e);o()})):o("INVALID_ARGUMENTS")},r.clearOwnedChannel=function(e,t){"string"==typeof e&&32===e.length?n.send("CLEAR_OWNED_CHANNEL",e,(function(e){if(e)return t(e);t()})):t("INVALID_ARGUMENTS")},r.removeOwnedChannel=function(e,t,r){if("string"!=typeof e||-1===[32,48].indexOf(e.length))return console.error("invalid channel to remove",e),void t("INVALID_ARGUMENTS");n.send("REMOVE_OWNED_CHANNEL",{channel:e,reason:r},(function(n,r){n?t(n):r&&r.length&&"OK"===r[0]?(t(),a&&a.clearChannel&&a.clearChannel(e)):t("INVALID_RESPONSE")}))},r.removePins=function(e){n.send("REMOVE_PINS",void 0,(function(t,n){t?e(t):n&&n.length&&"OK"===n[0]?e():e("INVALID_RESPONSE")}))},r.uploadComplete=function(e,t){n.send("UPLOAD_COMPLETE",e,(function(e,n){if(e)t(e);else{var r=n[0];"string"==typeof r?t(void 0,r):t("INVALID_ID")}}))},r.ownedUploadComplete=function(e,t){n.send("OWNED_UPLOAD_COMPLETE",e,(function(e,n){if(e)t(e);else{var r=n[0];"string"==typeof r?t(void 0,r):t("INVALID_ID")}}))},r.uploadStatus=function(e,t){"number"==typeof e?n.send("UPLOAD_STATUS",e,(function(e,n){if(e)t(e);else{var r=n[0];"boolean"==typeof r?t(void 0,r):t("INVALID_RESPONSE")}})):setTimeout((function(){t("INVALID_SIZE")}))},r.uploadCancel=function(e,t){n.send("UPLOAD_CANCEL",e,(function(e){e?t(e):t()}))},r.setMetadata=function(e,t){n.send("SET_METADATA",{channel:e.channel,command:e.command,value:e.value},t)},i(e,r)}})):i("INVALID_KEYS")}else i("INVALID_PROXY");else i("INVALID_NETWORK")}}))}(rn)),rn.exports}function cn(){return tn||(tn=1,function(e){(()=>{const t=(e,t,n,r,o,a,i,s,c,u)=>{var l=function(e,t,n){if(!e.done){if(e.cb(t&&t.error,n,t),e.done=!0,!e.hasNetwork){var o=r.find(e,["network","disconnect"]);"function"==typeof o&&o()}if(e.realtime&&e.realtime.stop)try{e.realtime.stop()}catch(e){console.error(e)}var a=r.find(e,["session","realtime","abort"]);"function"==typeof a&&(e.session.realtime.sync(),a())}},f=function(e,r){u((function(t){var o,a;e.hasNetwork||(o=t((function(e,t){e||(r.network=t)})),a=i.getWebsocketURL(),n.connect(a).then((function(e){o(null,e)}),(function(e){o(e)})))})).nThen((function(){e.realtime=t.start(r)}))},d=function(e,t,n,r){Array.isArray(n)&&n.length&&16===n[0].length&&Array.isArray(t.accessKeys)?(e.network.historyKeeper=n[0],u((function(n){t.accessKeys.forEach((function(t){c.create(e.network,t,n((function(e){console.log("done",t),e&&console.error(e)})))}))})).nThen((function(){r()}))):r(!0)},h=function(t,n){var r;return"string"==typeof t?r=o.getSecrets("pad",t,n.password):"object"==typeof t&&(r=t),r.keys||(r.keys=r.key),{websocketURL:i.getWebsocketURL(n.origin),channel:r.channel,validateKey:r.keys.validateKey||void 0,crypto:e.createEncryptor(r.keys),logLevel:0,initialState:n.initialState,Cache:s}},p=function(e){return"object"==typeof e},y=function(e,t){p(e)&&p(t)&&Object.keys(t).forEach((function(n){e[n]=t[n]}))};return{get:function(e,t,n,r){if("function"!=typeof t)throw new Error("Cryptget expects a callback");r=r||function(){};var o=h(e,n=n||{}),a={cb:t,accessKeys:n.accessKeys,hasNetwork:Boolean(n.network)};o.onRejected=function(e,t){d(o,a,e,t)},o.onReady=function(e){var t=a.session=e.realtime;a.network=e.network,r(1),l(a,void 0,t.getUserDoc())},o.onError=function(e){console.warn(e),l(a,e)},o.onChannelError=function(e){console.error(e),l(a,e)},o.onCacheReady=n.onCacheReady;var i=0;o.onMessage=function(){i++,r(Math.min(.99,i/100))},y(o,n),f(a,o)},put:function(e,t,n,r){if("function"!=typeof n)throw new Error("Cryptput expects a callback");var o=h(e,r=r||{}),i={cb:n,accessKeys:r.accessKeys,hasNetwork:Boolean(r.network)};o.onRejected=function(e,t){d(o,i,e,t)},o.onReady=function(e){var r=i.session=e.realtime;i.network=e.network,r.contentUpdate(t);var o=setTimeout((function(){n(new Error("Timeout"))}),15e3);a.whenRealtimeSyncs(r,(function(){clearTimeout(o);var e=r.getAuthDoc();r.abort(),l(i,void 0,e)}))},o.onChannelError=function(e){l(i,e)},y(o,r),f(i,o)}}};e.exports&&(e.exports=t(ye(),O(),u(),Ne(),Fe(),mt(),Ee(),Ge(),sn(),Dt(),I()))})()}(nn)),nn.exports}var un,ln,fn,dn,hn,pn,yn,vn={exports:{}};function mn(){if(hn)return dn;hn=1;return dn=((e,t,n,r,o,a,i,s)=>{const c={};let u={};c.setCustomize=e=>{u=e.Broadcast};var l=["notifications","supportteam","broadcast"],f=[],d="000000000000000000000000000000000",h=function(e,t,n,r,o){e.emit("MESSAGE",{type:t,content:n},r?[r]:e.clients,o)},p=function(e,t,n,r){e.emit("VIEWED",{type:t,hash:n},r||e.clients)},y=function(e){var t=e.store&&e.store.proxy;if(t.curvePrivate&&t.curvePublic&&t.kemPublic&&t.kemPrivate)return{curvePrivate:t.curvePrivate,curvePublic:t.curvePublic,kemPrivate:t.kemPrivate,kemPublic:t.kemPublic}},v=c.sendTo=function(t,n,o,a,i){a=a||{};var c=i||function(e){e&&e.error&&console.error(e.error)};if(s.Mailbox){var u=e.find(t,["store","anon_rpc"]);if(u){var l={encrypt:function(e){return e}},f=d,h={uid:e.uid(),type:n,content:o};if(!/^BROADCAST/.test(n)){var p=y(t);if(!p)return void c({error:"missing asymmetric encryption keys"});if(!a||!a.channel||!a.curvePublic)return void c({error:"no notification channel"});if(f=a.channel,l=s.Mailbox.createEncryptor(p),"object"==typeof o&&!o.user){var v=r.createData(t.store.proxy,!1);o.user=v}h={type:n,content:o}}var m=JSON.stringify(h),g=l.encrypt(m,a.curvePublic,a.kemPublic);if(a.viewed){var E=e.find(t,["store","proxy","teams",a.viewed]);if(E){var b=g.slice(0,64),A=e.find(E,["keys","mailbox","viewed"]);Array.isArray(A)&&A.push(b)}}u.send("WRITE_PRIVATE_MESSAGE",[f,g],(function(e){c(e?{error:e}:{hash:g.slice(0,64)})}))}else c({error:"anonymous rpc session not ready"})}else c({error:"chainpad-crypto is outdated and doesn't support mailboxes."})};c.sendToAnon=function(t,n,r,o,a){var i,c,u=s.CryptoAgility.bytes(32),l=s.CryptoAgility.boxKeyPairFromSecretKey(new Uint8Array(u)),f=e.encodeBase64(l.secretKey),d=e.encodeBase64(l.publicKey);if(s.PQC&&s.PQC.ml_kem&&s.PQC.ml_kem.ml_kem512)try{var h=s.CryptoAgility.bytes(64),p=s.PQC.ml_kem.ml_kem512.keygen(new Uint8Array(h));i=e.encodeBase64(p.secretKey),c=e.encodeBase64(p.publicKey)}catch(e){console.warn("Failed to generate ephemeral PQC keys:",e)}v({store:{anon_rpc:t,proxy:{curvePrivate:f,curvePublic:d,kemPrivate:i,kemPublic:c}}},n,r,o,a)};var m=function(t,r,o,i){var s=r.type,c=r.hash;if(/^REMINDER\|/.test(c)){i(),delete t.boxes.reminders.content[c],p(t,s,c,t.clients.filter((function(e){return e!==o})));var u=c.slice(9).split("-")[0],l=e.find(t,["store","proxy","hideReminders",u]);if(!l){var f=t.store.proxy.hideReminders=t.store.proxy.hideReminders||{};l=f[u]=f[u]||[]}var d=c.split("-")[1];d&&!l.includes(d)&&l.push(Number(d))}else{var h=t.boxes[s];if(h){var y,v,m=h.data||{},g=h.history.indexOf(c);-1!==g&&(0===g?(m.lastKnownHash=c,h.history.shift()):-1===m.viewed.indexOf(c)&&m.viewed.push(c));var E=[];h.history.some((function(e,t){if(-1===m.viewed.indexOf(e))return!0;y=t+1,E.push(e),v=e})),m.viewed=m.viewed.filter((function(e){return-1===E.indexOf(e)})),y&&(h.history=h.history.slice(y),m.lastKnownHash=v),Object.keys(h.content).forEach((function(e){-1!==h.history.indexOf(e)&&-1===m.viewed.indexOf(e)||(a.remove(t,h,h.content[e],e),delete h.content[e])})),n.whenRealtimeSyncs(t.store.realtime,(function(){i(),p(t,s,c,t.clients.filter((function(e){return e!==o})))}))}else i({error:"NOT_LOADED"})}},g=function(e,t,n,c,u){u=u||{};var l=e.boxes[t]={channel:n.channel,type:t,queue:[],history:[],content:{},sendMessage:function(t){if("object"==typeof t&&!t.user){var n=r.createData(e.store.proxy,!1);t.user=n}try{t=JSON.stringify(t)}catch(e){console.error(e)}l.queue.push(t)},data:n};if(s.Mailbox){var f=n.keys||y(e);if(f||n.decrypted){var d=n.decrypted?{encrypt:function(e){return e},decrypt:function(e){return e}}:s.Mailbox.createEncryptor(f);l.encryptor=d;var v,g={network:e.store.network,channel:n.channel,noChainPad:!0,crypto:d,owners:"broadcast"===t?[]:u.owners||[e.store.proxy.edPublic],lastKnownHash:n.lastKnownHash};g.onConnectionChange=function(){},g.onConnect=function(n,r){l.sendMessage=function(n,o){var a;o=o||function(){};try{a=JSON.stringify(n)}catch(e){console.error(e)}r(a,(function(r,a){r?console.error(r):(l.history.push(a),n.ctime=+new Date,l.content[a]=n,h(e,t,{msg:n,hash:a}),o(a))}),f.curvePublic)},l.queue.forEach((function(e){l.sendMessage(e)})),l.queue=[]},l.onMessage=g.onMessage=function(r,i,s,c,f,d,p){if(f!==n.lastKnownHash&&f!==v){var y=p&&p.time;v=f;try{r=JSON.parse(r)}catch(e){console.error(e)}if(d&&(r.author=d),l.history.push(f),function(e,t){return-1===(t.viewed||[]).indexOf(e)&&e!==t.lastKnownHash}(f,n)){var g={msg:r,hash:f,time:y},E=l.ready;a.add(e,l,g,(function(n,a,i){a&&m(e,a,"",(function(){console.log("Notification handled automatically")})),i||n?m(e,{type:t,hash:f},"",(function(){console.log("Notification handled automatically")})):(r.ctime=y||0,l.content[f]=r,u.dump||h(e,t,g,null,(function(e){e&&e.msg&&E&&o.system(void 0,e.msg)})))}))}else if(0===Object.keys(l.content).length){n.lastKnownHash=f,l.history=[];var b=n.viewed.indexOf(f);-1!==b&&n.viewed.splice(b,1)}}},g.onReady=function(){var r=[];n.viewed.forEach((function(e,t){-1===l.history.indexOf(e)&&r.push(t)}));for(var o=r.length-1;o>=0;o--)n.viewed.splice(r[o],1);var i=function(n){a.remove(e,l,l.content[n],n),delete l.content[n],p(e,t,n)};e.store.proxy.on("change",["mailboxes",t],(function(e,t,n){var r;"lastKnownHash"===n[2]&&(l.history.some((function(e,n){if(r=n+1,i(e),e===t)return!0})),l.history=l.history.slice(r));"viewed"===n[2]&&i(t)})),l.ready=!0,c(l.content)},l.cpNf=i.start(g)}else console.error("missing asymmetric encryption keys")}else console.error("chainpad-crypto is outdated and doesn't support mailboxes.")};return c.init=function(n,r,i){var s={},c=n.store,y=c.proxy.mailboxes=c.proxy.mailboxes||{},E={Store:n.Store,store:c,pinPads:n.pinPads,updateMetadata:n.updateMetadata,updateDrive:n.updateDrive,mailboxes:y,emit:i,clients:[],boxes:{},req:{},loggedIn:c.loggedIn&&c.proxy.edPublic};return function(e,n){!n.notifications&&e.loggedIn&&(n.notifications={channel:t.createChannelId(),lastKnownHash:"",viewed:[]},e.pinPads([n.notifications.channel],(function(e){e.error&&console.error(e)}))),n.support&&delete n.support,n.broadcast||(n.broadcast={channel:d,lastKnownHash:u.lastBroadcastHash,decrypted:!0,viewed:[]})}(E,y),E.loggedIn&&function(t){var n=t.store.network;n.on("message",(function(r,o){if(o===n.historyKeeper){var a=JSON.parse(r);if(/HISTORY_RANGE/.test(a[0])){var i=a[1],s=t.req[i];if(s){var c=a[0],u=a[2],l=s.box;if("HISTORY_RANGE"===c){if(!Array.isArray(u))return;var f;if("broadcast"===s.box.type)f=e.tryParse(u[4]);else try{var d=l.encryptor.decrypt(u[4]);(f=JSON.parse(d.content)).author=d.author}catch(e){console.log(e)}var h=u[4].slice(0,64);t.emit("HISTORY",{txid:i,time:u[5],message:f,hash:h},[s.cId])}else"HISTORY_RANGE_END"===c&&(t.emit("HISTORY",{txid:i,complete:!0},[s.cId]),delete t.req[i])}}}}))}(E),E.boxes.reminders={content:{}},Object.keys(y).forEach((function(e){if(-1!==l.indexOf(e)){var t=y[e];-1===f.indexOf(e)?g(E,e,t,(function(){})):g(E,e,t,r((function(){})))}})),E.loggedIn&&Object.keys(c.proxy.teams||{}).forEach((function(t){var n=c.proxy.teams[t];if(n){var r=n.keys.mailbox||{};if(r.channel){var o={owners:[e.find(n,["keys","drive","edPublic"])]};g(E,"team-"+t,r,(function(){}),o)}}})),s.post=function(e,t,n){var r=E.boxes[e];r&&r.sendMessage({type:t,content:n,sender:c.proxy.curvePublic})},s.hideMessage=function(e,t){p(E,e,t.hash,E.clients)},s.showMessage=function(e,t,n,r){"reminders"===e&&t&&(E.boxes.reminders.content[t.hash]=t.msg,E.clients.length||(E.boxes.reminders.content[t.hash].requiresNotif=!0),p(E,e,t.hash,E.clients)),h(E,e,t,n,(function(e){o.system(void 0,e.msg),r&&r()}))},s.open=function(e,t,n,r,o){(-1!==l.indexOf(e)||r)&&g(E,e,t,n,o)},s.close=function(e,t){!function(e,t,n){n=n||function(){};var r=e.boxes[t];r?r.cpNf&&"function"==typeof r.cpNf.stop?(r.cpNf.stop(),Object.keys(r.content).forEach((function(n){a.remove(e,r,r.content[n],n),p(e,t,n,e.clients)})),delete e.boxes[t]):n("EINVAL"):n()}(E,e,t)},s.dismiss=function(e,t){m(E,e,"",t)},s.sendTo=function(e,t,n,r){E.loggedIn?v(E,e,t,n,r):r({error:"NOT_LOGGED_IN"})},s.removeClient=function(e){!function(e,t){var n=e.clients.indexOf(t);e.clients.splice(n,1)}(E,e)},s.execCommand=function(e,t,n){var r=t.cmd,a=t.data;"SUBSCRIBE"!==r?"DISMISS"!==r?"SENDTO"!==r?"LOAD_HISTORY"!==r||function(e,t,n,r){var o=e.boxes[n.type];if(o){var a=["GET_HISTORY_RANGE",o.channel,{from:n.lastKnownHash,count:n.count,txid:n.txid}];"broadcast"===n.type&&(a=["GET_HISTORY_RANGE",o.channel,{to:n.lastKnownHash,txid:n.txid}]),e.req[n.txid]={cId:t,box:o};var i=e.store.network;i.sendto(i.historyKeeper,JSON.stringify(a)).then((function(){}),(function(e){console.error(e)}))}else r({error:"ENOENT"})}(E,e,a,n):v(E,a.type,a.msg,a.user,n):m(E,a,e,n):function(e,t,n,r){Object.keys(e.boxes).forEach((function(t){Object.keys(e.boxes[t].content).forEach((function(r){var a={msg:e.boxes[t].content[r],hash:r};h(e,t,a,n,(function(e){e.error||a.msg&&a.msg.requiresNotif&&(o.system(void 0,e.msg),delete a.msg.requiresNotif)}))}))})),-1===e.clients.indexOf(n)&&e.clients.push(n),r()}(E,0,e,n)},s},c})(Ne(),Fe(),mt(),Zt(),(un||(un=1,function(e){(()=>{const t=(e={})=>{let t=globalThis;var n={};e.requireConf=e.requireConf||{},n.setCustomize=t=>{e=t.ApiConfig};var r=t.location&&t.location.pathname.slice(1,-1),o=-1!==["code","slide","pad","kanban","whiteboard","diagram","sheet","poll","teams","form","doc","presentation"].indexOf(r)?"-"+r:"",a="/customize/favicon/main-favicon"+o+".png?"+e.requireConf.urlArgs,i="/customize/favicon/alt-favicon"+o+".png?"+e.requireConf.urlArgs,s="/customize/favicon/main-favicon"+o+".ico?"+e.requireConf.urlArgs,c="/customize/favicon/alt-favicon"+o+".ico?"+e.requireConf.urlArgs,u=t.document,l=n.isSupported=function(){return"function"==typeof t.Notification&&t.isSecureContext},f=n.hasPermission=function(){return"granted"===Notification.permission},d=n.getPermission=function(e){e=e||function(){},Notification&&"function"==typeof Notification.requestPermission?Notification.requestPermission((function(t){e("granted"===t)})):e(!1)},h=n.create=function(e,n,r){u&&!r?r=u.getElementById("favicon").getAttribute("data-main-favicon")||i:r||(r=i);var o=new Notification(n,{icon:r,body:e});return o.onclick=function(){if(u)try{parent.focus(),t.focus(),this.close()}catch(e){}},o};return n.system=function(e,t,n){if(l())return f()?h(e,t,n):void("denied"!==Notification.permission&&d((function(r){r&&h(e,t,n)})))},u&&!u.getElementById("favicon")&&function(){if(u){console.debug("creating favicon");var e={id:"favicon",type:"image/png",rel:"icon","data-main-favicon":a,"data-alt-favicon":i,href:a};if(!u.getElementById("favicon")){var t=u.createElement("link");Object.keys(e).forEach((function(n){t.setAttribute(n,e[n])})),u.head.appendChild(t)}if(!u.getElementById("favicon-ico")){var n=u.createElement("link");e.href=e.href.replace(/\.png/g,".ico"),e.id="favicon-ico",e.type="image/x-icon",Object.keys(e).forEach((function(t){n.setAttribute(t,e[t])})),u.head.appendChild(n)}}else console.error("document is not available in this context")}(),n.tab=function(e,r){if(u){var o="_pendingTabNotification",l=u.getElementById("favicon"),f=u.getElementById("favicon-ico"),d=a,h=i,p=s,y=c;l&&(d=l.getAttribute("data-main-favicon")||a,h=l.getAttribute("data-alt-favicon")||i,l.setAttribute("href",d)),f&&(p=f.getAttribute("data-main-favicon")||s,y=f.getAttribute("data-alt-favicon")||c,f.setAttribute("href",p));var v=function(e){return!!n[o]&&(t.clearInterval(n[o]),l&&l.setAttribute("href",e?h:d),f&&f.setAttribute("href",e?y:p),!0)};v();var m=function(){l&&l.setAttribute("href",l.getAttribute("href")===d?h:d),f&&f.setAttribute("href",f.getAttribute("href")===p?y:p),--r};return n[o]=t.setInterval((function(){if(r>0)return m();v(!0)}),e),m(),{cancel:v}}console.error("document is not available in this context")},n};e.exports&&(e.exports=t(void 0))})()}(vn)),vn.exports),(fn||(fn=1,ln=((e,t,n,r,o)=>{var a=function(e){var t=e.store.realtime.getLag().lag||0;return 20*(Math.max(0,t)+300)*(.5+Math.random())},i={},s={},c=function(e,t){var r=e.store.proxy.mutedUsers||{},o=n.find(t,["msg","author"]);return!!o&&Boolean(r[o])},u={};i.FRIEND_REQUEST=function(t,n,r,o){var a=r.msg.content.user||r.msg.content;if(c(t,r))o(!0);else if(u[r.msg.author])o(!0);else{if(u[r.msg.author]={type:n.type,hash:r.hash},e.getFriend(t.store.proxy,r.msg.author)||t.store.proxy.friends_pending[r.msg.author])return delete t.store.proxy.friends_pending[r.msg.author],void e.acceptFriendRequest(t.store,a,(function(n){n&&n.error?o():e.addToFriendList({proxy:t.store.proxy,realtime:t.store.realtime,pinPads:t.pinPads},a,(function(e){if(e)return console.error(e),void o(!0);t.store.messenger&&t.store.messenger.onFriendAdded(a),t.updateMetadata(),o(!0)}))}));o()}},s.FRIEND_REQUEST=function(e,t,n){var r=n.content.user||n.content;u[r.curvePublic]&&delete u[r.curvePublic]};var l={},f={};i.DECLINE_FRIEND_REQUEST=function(e,t,n,r){var o=n.msg.content.user||n.msg.content;o.curvePublic||(o.curvePublic=n.msg.author),setTimeout((function(){r(!0),e.store.proxy.friends_pending[n.msg.author]&&(delete e.store.proxy.friends_pending[n.msg.author],e.updateMetadata(),l[n.msg.author]||t.sendMessage({type:"FRIEND_REQUEST_DECLINED",content:{user:o}},(function(e){l[n.msg.author]={type:t.type,hash:e}})))}),a(e))},i.FRIEND_REQUEST_DECLINED=function(e,t,n,r){e.updateMetadata();var o=n.msg.content.user.curvePublic||n.msg.content.user,a=f[o];delete f[o],l[o]?r(!0,a):(l[o]={type:t.type,hash:n.hash},r(!1,a))},s.FRIEND_REQUEST_DECLINED=function(e,t,n){var r=n.content.user.curvePublic||n.content.user;l[r]&&delete l[r]},i.ACCEPT_FRIEND_REQUEST=function(t,n,r,o){var i=r.msg.content.user||r.msg.content;setTimeout((function(){o(!0),t.store.proxy.friends_pending[r.msg.author]&&(delete t.store.proxy.friends_pending[r.msg.author],e.addToFriendList({proxy:t.store.proxy,realtime:t.store.realtime,pinPads:t.pinPads},i,(function(e){e?console.error(e):(t.store.messenger&&t.store.messenger.onFriendAdded(i),t.updateMetadata(),t.store.modules.profile&&t.store.modules.profile.update(),f[r.msg.author]||n.sendMessage({type:"FRIEND_REQUEST_ACCEPTED",content:{user:i}},(function(e){f[r.msg.author]={type:n.type,hash:e}})))})))}),a(t))},i.FRIEND_REQUEST_ACCEPTED=function(e,t,n,r){e.updateMetadata();var o=n.msg.content.user.curvePublic||n.msg.content.user,a=l[o];delete l[o],f[o]?r(!0,a):(f[o]={type:t.type,hash:n.hash},r(!1,a))},s.FRIEND_REQUEST_ACCEPTED=function(e,t,n){var r=n.content.user.curvePublic||n.content.user;f[r]&&delete f[r]},i.CANCEL_FRIEND_REQUEST=function(e,t,n,r){var o=u[n.msg.author];o?r(!0,o):r(!0)},i.UNFRIEND=function(t,n,r,o){var a=r.msg.author,i=e.getFriend(t.store.proxy,a);i?(delete t.store.proxy.friends[a],delete t.store.proxy.friends_pending[a],t.store.messenger&&t.store.messenger.onFriendRemoved(a,i.channel),t.updateMetadata(),o(!0)):o(!0)},i.UPDATE_DATA=function(e,t,n,r){var o=n.msg,a=o.author,i=e.store.proxy.friends&&e.store.proxy.friends[a];if(!i||"object"!=typeof o.content)return void r(!0);const s=o.content.edPublic,c=()=>{Object.keys(o.content).forEach((function(e){i[e]=o.content[e]})),e.store.messenger&&e.store.messenger.onFriendUpdate(a),e.updateMetadata(),r(!0)};if(o.content.badge&&e.store.modules.badge)return e.store.modules.badge.listBadges({edPublic:s},(e=>{e.includes(o.content.badge)||delete o.content.badge,c()}));c()};var d=function(e,t){let n=e.store.data.blockHash,a=o.parseBlockHash(n).keys.symmetric;return r.encrypt(t,a)},h={};i.SHARE_PAD=function(e,n,r,o){var a=r.msg,i=r.hash,s=a.content;if(c(e,r))o(!0);else{var u,l=s.isStatic?s.href:t.hrefToHexChannelId(s.href,s.password),f=t.parsePadUrl(s.href),p=f.hashData&&f.hashData.mode||"n/a",y=h[l];if(y){if("edit"===y.mode&&"view"===p)return void o(!0);u=y.data}s.password&&(s.password=d(e,s.password)),h[l]={mode:p,data:{type:n.type,hash:i}},o(!1,u)}},s.SHARE_PAD=function(e,n,r,o){var a=r.content,i=t.hrefToHexChannelId(a.href,a.password),s=h[i];s&&s.data&&s.data.hash===o&&delete h[i]};var p=!1;i.SUPPORT_MESSAGE=function(e,t,n,r){p?r(!0):(p=!0,r())},s.SUPPORT_MESSAGE=function(){p=!1},i.REQUEST_PAD_ACCESS=function(e,t,n,r){var o=n.msg.content;if(c(e,n))r(!0);else{var a=o.channel,i=e.store.manager.findChannel(a);if(i.length){var s,u,l=e.store.proxy.edPublic;i.some((function(e){if(e.data&&Array.isArray(e.data.owners)&&-1!==e.data.owners.indexOf(l)&&e.data.href)return u=e.data.href,s=e.data.filename||e.data.title,!0}))?(o.title=s,o.href=u,r(!1)):r(!0)}else r(!0)}},i.GIVE_PAD_ACCESS=function(e,t,n,r){var o,a=n.msg.content,i=a.channel;e.store.manager.findChannel(i,!0).forEach((function(e){e.data&&!e.data.href&&(o||(o=e.data.filename||e.data.title),e.userObject.setHref(i,null,a.href))})),a.title=o||a.title,r(!1)},i.ADD_TO_ACCESS_LIST=function(e,t,n,r){var o=n.msg.content.channel;e.Store.getAllStores().forEach((function(t){var n=t.manager.findChannel(o);if(n.length){var r=n[0].data,a=n[0].id,i=t.id;e.Store.loadSharedFolder(i,a,r,(function(){}),!1)}})),r(!0)};var y={};i.ADD_OWNER=function(e,t,n,r){var o=n.msg.content;if(c(e,n))r(!0);else{if(!(o.teamChannel||o.href&&o.title&&o.channel))return console.log("Remove invalid notification"),void r(!0);var a=o.channel||o.teamChannel;o.password&&(o.pw=o.password,o.password=d(e,o.password)),y[a]?r(!0):(y[a]={type:t.type,hash:n.hash},r(!1))}},s.ADD_OWNER=function(e,t,n){var r=n.content.channel||n.content.teamChannel;y[r]&&delete y[r]},i.RM_OWNER=function(e,t,n,r){var o=n.msg.content;if(!o.channel&&!o.teamChannel)return console.log("Remove invalid notification"),void r(!0);var a=o.channel||o.teamChannel;if(o.teamChannel){var i=e.store.proxy.teams||{};Object.keys(i).some((function(e){if(i[e].channel===a)return i[e].owner=!1,!0}))}y[a]&&o.pending?r(!1,y[a]):r(!1)};var v={};i.INVITE_TO_TEAM=function(e,t,r,o){var a=r.msg.content;if(c(e,r))o(!0);else{if(!a.team)return console.log("Remove invalid notification"),void o(!0);var i=v[a.team.channel];if(i)return console.log("removing old invitation"),o(!1,i),void(v[a.team.channel]={type:t.type,hash:r.hash});var s=n.find(e,["store","proxy","teams"])||{};Object.keys(s).some((function(e){return s[e].channel===a.team.channel}))?o(!0):(v[a.team.channel]={type:t.type,hash:r.hash},o(!1))}},s.INVITE_TO_TEAM=function(e,t,r){var o=n.find(r,["content","team","channel"]);delete v[o]},i.KICKED_FROM_TEAM=function(e,t,n,r){var o=n.msg.content;if(!o.teamChannel)return console.log("Remove invalid notification"),void r(!0);v[o.teamChannel]&&o.pending?r(!0,v[o.teamChannel]):r(!1)},i.INVITE_TO_TEAM_ANSWER=function(e,t,r,o){var a=r.msg,i=a.content;if(!i.teamChannel)return console.log("Remove invalid notification"),void o(!0);var s,c,u=n.find(e,["store","proxy","teams"])||{};if(Object.keys(u).some((function(e){var t=u[e];if(t.channel===i.teamChannel)return s=e,c=t,!0})),s){if(i.team=c,!i.answer)try{e.store.modules.team.removeFromTeam(s,a.author,!0)}catch(e){console.error(e)}var l=i.user||i;t.sendMessage({type:"INVITE_TO_TEAM_ANSWERED",content:{user:l,team:c,answer:i.answer}},(function(){})),o(!0)}else o(!0)},i.TEAM_EDIT_RIGHTS=function(e,t,r,o){var a=r.msg.content;if(!a.teamData)return console.log("Remove invalid notification"),void o(!0);var i,s=n.find(e,["store","proxy","teams"])||{};if(Object.keys(s).some((function(e){if(s[e].channel===a.teamData.channel)return i=e,!0})),i)try{e.store.modules.team.changeMyRights(i,a.state,a.teamData,(function(e){e||console.error("Can't update team rights"),o(!0)}))}catch(e){console.error(e)}else o(!0)},i.OWNED_PAD_REMOVED=function(e,t,n,r){var o=n.msg.content;if(!o.channel)return console.log("Remove invalid notification"),void r(!0);var a=o.channel;e.store.manager.findChannel(a).forEach((function(t){var n=e.store.manager.findFile(t.id);e.store.manager.delete({paths:n},(function(){e.updateDrive()}))})),r(!0)},i.MOVE_TODO=function(e,t,n,r){var o=e.store.proxy.curvePublic;n.msg.author===o?r():r(!0)},i.SAFE_LINKS_DEFAULT=function(e,t,n,r){var o=e.store.proxy.curvePublic;n.msg.author===o?r():r(!0)};var m={};i.FORM_RESPONSE=function(e,t,n,r){var o,a,i=n.msg,s=n.hash,c=i.content,u=c.channel;if(u)if(function(e,t){return(e.store.proxy.mutedChannels||[]).includes(t)}(e,u))r(!0);else if(e.Store.getAllStores().some((function(e){return e.manager.findChannel(u).some((function(e){if(e.data&&(!a||e.data.href))return a=e.data.href||e.data.roHref,o=e.data.filename||e.data.title,!!e.data.href||void 0}))})),a){c.href=a,c.title=o;var l=m[u],f=l?l.data:void 0;m[u]={data:{type:t.type,hash:s}},r(!1,f)}else r(!0);else r(!0)},s.FORM_RESPONSE=function(e,t,n,r){var o=n.content.channel,a=m[o];a&&a.data&&a.data.hash===r&&delete m[o]};var g={};i.COMMENT_REPLY=function(e,t,r,o){var a=r.msg,i=r.hash,s=a.content;if(n.find(e.store.proxy,["settings","pad","disableNotif"]))o(!0);else{var c,u,l=s.channel;if(l)if(e.Store.getAllStores().some((function(e){return e.manager.findChannel(l).some((function(e){if(e.data&&(!u||e.data.href))return u=e.data.href||e.data.roHref,c=e.data.filename||e.data.title,!!e.data.href||void 0}))})),u){s.href=u,s.title=c;var f=g[l],d=f?f.data:void 0;g[l]={data:{type:t.type,hash:i}},o(!1,d)}else o(!0);else o(!0)}},s.COMMENT_REPLY=function(e,t,n,r){var o=n.content.channel,a=g[o];a&&a.data&&a.data.hash===r&&delete g[o]};var E,b,A={};i.MENTION=function(e,t,n,r){var o=n.msg,a=n.hash,i=o.content;if(c(e,n))r(!0);else{var s=i.channel;if(s){var u,l;e.Store.getAllStores().some((function(e){return e.manager.findChannel(s).some((function(e){if(e.data&&(!l||e.data.href))return l=e.data.href||e.data.roHref,u=e.data.filename||e.data.title,!!e.data.href||void 0}))})),i.href=l,i.title=u;var f=A[s],d=f?f.data:void 0;A[s]={data:{type:t.type,hash:a}},r(!1,d)}else r(!0)}},s.MENTION=function(e,t,n,r){var o=n.content.channel,a=A[o];a&&a.data&&a.data.hash===r&&delete A[o]},i.BROADCAST_MAINTENANCE=function(e,t,n,r){var o=n.msg.uid;e.Store.onMaintenanceUpdate(o),r(!0)},i.BROADCAST_SURVEY=function(e,t,n,r){var o=n.msg,a=o.content,i=o.uid,s=E;E={type:t.type,hash:n.hash},e.Store.onSurveyUpdate(i),r(!a.url,s)},i.BROADCAST_CUSTOM=function(e,t,n,r){var o=n.msg.uid,a=b;b={uid:o,type:t.type,hash:n.hash},r(!1,a)},i.BROADCAST_DELETE=function(e,t,n,r){var o=n.msg.content.uid;if(b&&b.uid===o)return r(!0,b),void(b=void 0);r(!0)};var _,w,O={};return i.SF_DELETED=function(e,t,n,r){var o=n.msg.content,a=o.team,i=o.sfId;if(O[i])r(!0);else if(O[i]=1,a){var s=e.store.proxy.teams[a];o.teamName=s.metadata&&s.metadata.name,r(!1)}else r(!1)},s.SF_DELETED=function(e,t,n){var r=n.content.sfId;delete O[r]},i.NEW_TICKET=function(e,t,r,o){var a=r.msg.content;a.time||(a.time=r.time);var i=n.find(e,["store","modules","support"]);a.isAdmin&&i.addUserTicket(a,o),i.addAdminTicket(a,o)},i.NOTIF_TICKET=function(e,t,r,o){var a=r.msg.content;a.time||(a.time=r.time);var i=n.find(e,["store","modules","support"]);if(a.isAdmin)return n.find(e,["store","proxy","support",a.channel])?(i.updateUserTicket(a),_?void o(!1,_):(_={channel:a.channel,type:t.type,hash:r.hash},void o(!1))):void o(!0);i.checkAdminTicket(a,(s=>{s?(i.updateAdminTicket(a),n.find(e.store.proxy,["settings","general","disableSupportNotif"])?o(!0):w?o(!1,w):(w={channel:a.channel,type:t.type,hash:r.hash},o(!1))):o(!0)}))},s.NOTIF_TICKET=function(e,t,n){var r=n.content.channel;_&&_.channel===r&&(_=void 0),w&&w.channel===r&&(w=void 0)},i.ADD_MODERATOR=function(e,t,r,o){var a=r.msg.content;n.find(e,["store","modules","support"]).updateAdminKey(a,o)},i.MODERATOR_NEW_KEY=function(e,t,r,o){var a=r.msg.content;n.find(e,["store","modules","support"]).updateAdminKey(a,(function(){o(!0)}))},{add:function(e,t,r,o){if(r.msg){var a=n.find(e,["store","proxy","curvePublic"]),s=n.find(r,["msg","content","user","curvePublic"])||n.find(r,["msg","content","curvePublic"]);if(s&&r.msg.author!==s&&r.msg.author!==a)return console.error("blocked"),void o(null,null,!0);var c=r.msg.type;if(i[c])try{i[c](e,t,r,o)}catch(e){console.error(e),o()}else o()}else o(null,null,!0)},remove:function(e,t,n,r){if(n){var o=n.type;if(s[o])try{s[o](e,t,n,r)}catch(e){console.error(e)}}}}})(Zt(),Fe(),Ne(),ye(),Gt())),ln),O(),ye()),dn}function gn(){if(yn)return pn;yn=1;return pn=((e,t,n,r,o,a,i,s,c)=>{let u={};let l=function(l,f,d,h){var p=l.version||0;s((function(){})).nThen((function(){var t,n,r,o,a;p<2&&(t="cryptpad.userlist-drawer",n="cryptpad.hide_poll_text",r="cryptpad.indentUnit",o="cryptpad.indentWithTabs",a=l.settings=l.settings||{},void 0!==l[r]&&(a.codemirror=a.codemirror||{},a.codemirror.indentUnit=l[r],delete l[r]),void 0!==l[o]&&(a.codemirror=a.codemirror||{},a.codemirror.indentWithTabs=l[o],delete l[o]),void 0!==l[t]&&(a.toolbar=a.toolbar||{},a.toolbar["userlist-drawer"]=l[t],delete l[t]),void 0!==l[n]&&(a.poll=a.poll||{},a.poll["hide-text"]=l[n],delete l[n]),e.send("Migrate-2",!0),l.version=p=2)})).nThen((function(){p<3&&(!function(){if(localStorage.CRYPTPAD_LANG){var e=localStorage.CRYPTPAD_LANG;l.settings.language=e}}(),e.send("Migrate-3",!0),l.version=p=3)})).nThen((function(){var t;p<4&&(t=l.settings=l.settings||{},void 0!==l.allowUserFeedback&&(t.general=t.general||{},t.general.allowUserFeedback=l.allowUserFeedback,delete l.allowUserFeedback),e.send("Migrate-4",!0),l.version=p=4)})).nThen((function(){p<5&&(!function(){var e=l.drive&&l.drive.filesData;if(e)for(var t in e)"number"!=typeof e[t].ctime&&(e[t].ctime=+new Date(e[t].ctime)),"number"!=typeof e[t].atime&&(e[t].atime=+new Date(e[t].atime))}(),e.send("Migrate-5",!0),l.version=p=5)})).nThen((function(n){var r,o,a,i,c;p<6&&(a=l.drive.filesData||{},i=s((function(){})),c=Object.keys(a).length,Object.keys(a).forEach((function(e,n){i=i.nThen((function(i){setTimeout(i((function(){if(r=a[e],o=t.parsePadUrl(r.href),r.href&&!r.channel){var i=t.getSecrets(o.type,o.hash,r.password);r.channel=i.channel,d(6,Math.round(100*n/c)),console.log("Adding missing channel in filesData ",r.channel)}})))}))})),i.nThen(n((function(){e.send("Migrate-6",!0),l.version=p=6}))))})).nThen((function(n){var r,o,a,i,c;p<7&&(a=l.drive.filesData,i=s((function(){})),c=Object.keys(a).length,Object.keys(a).forEach((function(e,n){i=i.nThen((function(i){setTimeout(i((function(){if((r=a[e]).href)if(-1!==r.href.indexOf("#"))if("pad"===(o=t.parsePadUrl(r.href)).hashData.type){if("view"===o.hashData.mode)r.roHref=r.href,delete r.href,console.log("Move href to roHref in filesData ",r.roHref);else{var i=t.getSecrets(o.type,o.hash,r.password),s=t.getViewHashFromKeys(i);s&&(r.roHref="/"+o.type+"/#"+s,console.log("Adding missing roHref in filesData ",r.href))}d(6,Math.round(100*n/c))}else d(7,Math.round(100*n/c));else d(7,Math.round(100*n/c));else d(7,Math.round(100*n/c))})))}))})),i.nThen(n((function(){e.send("Migrate-7",!0),l.version=p=7}))))})).nThen((function(){p<8&&(l.FS_hashes=n.deduplicateString(l.FS_hashes||[]),e.send("Migrate-8",!0),l.version=p=8)})).nThen((function(){p<9&&(!function(){var e=h.network,t={},n={store:h},o=r.createData(l),i=function(e){var n=t[e];if(n){try{n.wc.leave()}catch(e){}delete t[e]}};e.on("message",(function(r,s){try{!function(r,s){if(s===e.historyKeeper){var c=JSON.parse(r);if(!c.validateKey&&!c.owners||!c.channel){if(c.channel&&t[c.channel]){if(c.error&&"EINVAL"===c.error){var u=["GET_HISTORY",c.channel,{}];return void e.sendto(e.historyKeeper,JSON.stringify(u)).then((function(){}),(function(){}))}if(c.state&&1===c.state){o.channel=c.channel;var l=["UPDATE",o.curvePublic,+new Date,o],f=t[c.channel].encrypt(JSON.stringify(l));return t[c.channel].wc.bcast(f).then((function(){}),(function(e){console.error("Can't migrate this friend",t[c.channel].friend,e)})),void i(c.channel)}}else if(c.channel)return;var d=c[3];if(d&&t[d]){var h=t[d],p=h.decrypt(c[4]),y=JSON.parse(p);if("UPDATE"===y[0]){if(y[1]===o.curvePublic)return;var v=y[3];if(!v.notifications)return;h.friend.notifications=v.notifications,o.channel=d,a.sendTo(n,"UPDATE_DATA",o,{channel:v.notifications,curvePublic:v.curvePublic},(function(e){e&&e.error?console.error(e):console.log("friend migrated",h.friend)})),i(d)}}}}}(r,s)}catch(e){console.error(e)}}));var s=l.friends||{};Object.keys(s).forEach((function(n){if(44===n.length){var r=s[n];r.notifications||e.join(r.channel).then((function(n){var o=c.Curve.deriveKeys(r.curvePublic,l.curvePrivate,r.kemPublic,l.kemPublic),a=c.Curve.createEncryptor(o);t[r.channel]={wc:n,friend:r,decrypt:a.decrypt,encrypt:a.encrypt};var i={lastKnownHash:r.lastKnownHash},s=["GET_HISTORY",r.channel,i];e.sendto(e.historyKeeper,JSON.stringify(s)).then((function(){}),(function(e){console.error("Can't migrate this friend",r,e)}))}),(function(e){console.error("Can't migrate this friend",r,e)}))}}))}(),e.send("Migrate-9",!0),l.version=p=9)})).nThen((function(n){p<10&&function(){var i=h.proxy.todo;if(i){var c,f=n((function(){e.send("Migrate-10",!0),l.version=p=10})),d={network:h.network,initialState:"{}",metadata:{owners:h.proxy.edPublic?[h.proxy.edPublic]:[]}};s((function(e){o.get(i,e((function(t,n){if(t||!n)return e.abort(),void f();try{c=JSON.parse(n)}catch(e){}})),d)})).nThen((function(e){if(!c||"object"!=typeof c)return e.abort(),void f();var n={content:{data:{1:{id:"1",color:"color6",item:[],title:u.kanban_todo},2:{id:"2",color:"color3",item:[],title:u.kanban_working},3:{id:"3",color:"color5",item:[],title:u.kanban_done}},items:{},list:[1,2,3]},metadata:{title:u.type.todo,defaultTitle:u.type.todo,type:"kanban"}},s=4,p=!1;if((c.order||[]).forEach((function(e){var t=c.data[e];if(t&&t.task){p=!0;var r=t.state?"3":"1";n.content.data[r].item.push(s),n.content.items[s]={id:s,title:t.task},s++}})),!p)return e.abort(),void f();var y=t.createRandomHash("kanban"),v=t.getSecrets("kanban",y),m=t.getSecrets("todo",i);o.put(y,JSON.stringify(n),e((function(n){if(n)return e.abort(),void f();h.rpc&&(h.rpc.pin([v.channel],(function(){})),h.rpc.unpin([m.channel],(function(){})));var o=t.hashToHref(y,"kanban");h.manager.addPad(["root"],{title:u.type.todo,owners:d.metadata.owners,channel:v.channel,href:o,roHref:t.hashToHref(t.getViewHashFromKeys(v),"kanban"),atime:+new Date,ctime:+new Date},e((function(e){if(e)console.error(e);else{delete h.proxy.todo;var t=r.createData(l),n={store:h};a.sendTo(n,"MOVE_TODO",{user:t,href:o},{channel:t.notifications,curvePublic:t.curvePublic},(function(e){e&&e.error&&console.error(e)}))}})))})),d)})).nThen((function(){f()}))}}()})).nThen((function(t){if(!(p>=11)){var o=function(){e.send("Migrate-11",!0),l.version=p=11};if(void 0===n.find(l,["settings","security","unsafeLinks"])){var i={store:h},s=r.createData(l);s.curvePublic?a.sendTo(i,"SAFE_LINKS_DEFAULT",{user:s},{channel:s.notifications,curvePublic:s.curvePublic},t((function(e){e&&e.error?console.error(e):o()}))):o()}else o()}})).nThen((function(){i.whenRealtimeSyncs(h.realtime,n.mkAsync(n.bake(f)))}))};return l.setCustomize=e=>{u=e.Messages},l})(nt(),Fe(),Ne(),Zt(),cn(),mn(),mt(),Dt(),ye()),pn}var En,bn,An=o(et);var _n,wn,On,Dn,Sn=bn?En:(bn=1,_n=cn(),wn=Et(),Fe(),On=mt(),Dn={anonDriveIntoUser:function(e,t,n){t&&e.loggedIn||"function"!=typeof n?_n.get(t,(function(r,o){var a;if(r)console.error("Cannot migrate recent pads",r);else if(o){try{a=JSON.parse(o)}catch(e){return"function"==typeof n&&n(),void console.error("Cannot parsed recent pads",e)}if(a){var i=e.proxy,s=wn.init(a.drive,{readOnly:!1,loggedIn:!0,outer:!0}),c=function(){s.fixFiles(!0);var r=e.manager;s.getFiles([s.FILES_DATA]).forEach((function(e){var t=s.getFileData(e),n=t.channel,o=r.findChannel(n);if(0===o.length)t&&r.addPad(null,t,(function(e){e&&console.error("Cannot import file:",t,e)}));else{if(!t.href)return;o.forEach((function(e){e.data&&!e.data.href&&e.userObject.setHref(n,null,t.href)}))}})),i.FS_hashes&&Array.isArray(i.FS_hashes)||(i.FS_hashes=[]),-1===i.FS_hashes.indexOf(t)&&i.FS_hashes.push(t),"function"==typeof n&&On.whenRealtimeSyncs(e.realtime,n)};s&&"function"==typeof s.migrate?s.migrate(c):(console.log("oldFo.migrate is not a function"),c())}else"function"==typeof n&&n()}else"function"==typeof n&&n()})):n()}},En=Dn);const Tn=je.mkEvent(!0),Cn=je.mkEvent(!0),xn=je.mkEvent(),In=je.mkEvent(),Nn=(e,t)=>{var n,r;const o=e.store,a=e.Store;let i;if(t){const e=a.getStore(t);i=null===(r=null==e?void 0:e.proxy)||void 0===r?void 0:r.drive}else i=null===(n=o.drive)||void 0===n?void 0:n.proxy;return i},Pn={init:e=>{var t;const{broadcast:n,store:r,Store:o,account:a}=e,i=r.drive||(r.drive={});let s=null===(t=r.proxy)||void 0===t?void 0:t.drive;if((null==s?void 0:s.hash)||Ke.createRandomHash("drive"),!s.hash)return i.proxy=s,a.onAccountCacheReady((()=>{Tn.fire()})),a.onAccountReady((()=>{Cn.fire()})),{channel:"",onDriveCacheReady:Tn.reg,onDriveReady:Cn.reg,onDisconnect:xn.reg,onReconnect:In.reg};throw new Error("NOT IMPLEMENTED")},initAPI:e=>{const{broadcast:t,store:n,Store:r,account:o}=e,a={store:n,Store:r};return{exists:(e,t,r)=>{r({state:Boolean(n.proxy)})},get:(e,t,n)=>{let r=Nn(a,t.teamId);n(r?{drive:r}:{error:"ENOTFOUND"})},set:(e,t,n)=>{let o=Nn(a,t.teamId);var i,s;o?(i=o,s=t.value,Object.keys(i).forEach((e=>{delete i[e]})),Object.keys(s).forEach((e=>{i[e]=je.clone(s[e])})),r.onSync(t.teamId,n)):n({error:"ENOTFOUND"})},migrateAnon:(e,t,r)=>{Sn.anonDriveIntoUser(n,t.anonHash,r)}}}};var kn=o(Object.freeze({__proto__:null,Drive:Pn})),Rn=O(),Mn=r(Dt()),Fn=r(Xt()),Ln=St();const Hn=je.mkEvent(!0),Kn=je.mkEvent(!0),jn=(e,t,n,r)=>{const o=je.once(je.mkAsync(r)),{store:a,Store:i}=e;!a.offline&&a.anon_rpc?n.channel?32===n.channel.length&&Ke.isValidChannel(n.channel)?a.anon_rpc.send("GET_METADATA",n.channel,((e,t)=>{if(e)return void o({error:e});const r=t&&t[0]||{};o(r),r.rejected||i.getAllStores().forEach((e=>{const t=e.manager.findChannel(n.channel,!0);let o=!1;(t.forEach((e=>{Fn(e.data.owners)!==Fn(r.owners)&&(o=!0),e.data.owners=r.owners,e.data.atime=+new Date,r.expire&&(e.data.expire=+r.expire)})),o)&&(e.sendEvent||a.sendDriveEvent)("DRIVE_CHANGE",{path:["drive",Pt.FILES_DATA]})}))})):o({error:"EINVAL"}):o({error:"ENOTFOUND"}):o({error:"OFFLINE"})},Un=(e,t,n)=>{if(n.versionHash)return((e,t,n)=>{let r;const{Store:o,store:a,postMessage:i}=e,s=n.channel,c=n.versionHash,u=Ke.createChannelId();Mn((n=>{jn(e,0,{channel:s},n((e=>{if(e&&e.rejected)return i(t,"PAD_ERROR",{type:"ERESTRICTED"}),void n.abort();r=e.validateKey})))})).nThen((()=>{o.getHistoryRange(t,{cpCount:1,channel:s,lastKnownHash:c},(e=>{var n,o;if(e&&e.error)return i(t,"PAD_ERROR",e.error);const l=e.messages||[];if((null===(n=l[l.length-1])||void 0===n?void 0:n.serverHash)!==c)return i(t,"PAD_ERROR",{type:"HASH_NOT_FOUND"});i(t,"PAD_CONNECT",{myID:u,id:s,members:[u]}),(e.messages||[]).forEach((e=>{i(t,"PAD_MESSAGE",{msg:e.msg,time:e.time,user:u.slice(0,16)})})),r&&(null===(o=null==a?void 0:a.messenger)||void 0===o||o.storeValidateKey(s,r)),i(t,"PAD_READY")}))}))})(e,t,n);const{channels:r,store:o,Store:a,myDeletions:i,postMessage:s}=e,c=n.channel;if(!Ke.isValidChannel(c))return s(t,"PAD_ERROR","INVALID_CHAN");const u=void 0===r[c],l=r[c]||(r[c]={queue:[],data:{},clients:[],bcast:(e,t,n)=>{l.clients.forEach((function(r){r!==n&&s(r,e,t)}))},history:[],pushHistory:(e,t)=>{if(t){let t;for(l.history.push("cp|"+e),t=l.history.length-101;t>0&&!/^cp\|/.test(l.history[t]);t--);l.history=l.history.slice(t)}else l.history.push(e)}});if(-1===l.clients.indexOf(t)&&l.clients.push(t),!u&&l.wc)return s(t,"PAD_CONNECT",{myID:l.wc.myID,id:l.wc.id,members:l.wc.members}),l.wc.members.forEach((e=>{s(t,"PAD_JOIN",e)})),l.history.forEach((e=>{s(t,"PAD_MESSAGE",{msg:Rn.removeCp(e),user:l.wc.myID,validateKey:l.data.validateKey})})),void s(t,"PAD_READY");const f=t=>{const r=null==t?void 0:t.type;"EDELETED"===r&&i[c]&&(delete i[c],t.ownDeletion=!0),l.bcast("PAD_ERROR",t),"EDELETED"===r&&(null==Je?void 0:Ye.clearChannel)&&Ye.clearChannel(c),["EDELETED","EEXPIRED","ERESTRICTED"].includes(r)&&e.leavePad(null,n,(function(){}))},d={Cache:o.neverCache?void 0:Je,priority:1,onCacheStart:()=>{s(t,"PAD_CACHE")},onCacheReady:()=>{s(t,"PAD_CACHE_READY"),Kn.fire()},onReady:e=>{const n=e.metadata||{};l.data=n,(null==n?void 0:n.validateKey)&&o.messenger&&o.messenger.storeValidateKey(c,n.validateKey),s(t,"PAD_READY",e.noCache)},onMessage:function(e,t,n,r,o){l.lastHash=o,l.pushHistory(e,r),l.bcast("PAD_MESSAGE",{user:t,msg:e,validateKey:n})},onJoin:function(e){l.bcast("PAD_JOIN",e)},onLeave:function(e){l.bcast("PAD_LEAVE",e)},onError:f,onChannelError:f,onRejected:a.onRejected,onConnectionChange:e=>{e.state||l.bcast("PAD_DISCONNECT")},onMetadataUpdate:e=>{l.data=e||{},a.getAllStores().forEach((t=>{t.manager.findChannel(c,!0).forEach((t=>{t.data.owners=e.owners,t.data.atime=+new Date,e.expire&&(t.data.expire=+e.expire)}));(t.sendEvent||o.sendDriveEvent)("DRIVE_CHANGE",{path:["drive",Pt.FILES_DATA]})})),l.bcast("PAD_METADATA",e)},crypto:{encrypt:function(e){return e},decrypt:function(e){return e}},noChainPad:!0,channel:c,metadata:n.metadata,network:o.network||o.networkPromise,websocketURL:Ae.getWebsocketURL(),onInit:function(){Hn.fire()},onConnect:(e,n)=>{l.sendMessage=(t,r,o)=>{n(t,(n=>{n?o({error:n}):(l.lastHash=t.slice(0,64),l.pushHistory(Rn.removeCp(t),/^cp\|/.test(t)),l.bcast("PAD_MESSAGE",{user:e.myID,msg:Rn.removeCp(t),validateKey:l.data.validateKey},r),o())}))},l.wc=e,l.queue.forEach((function(e){l.sendMessage(e.message,t)})),l.queue=[],l.bcast("PAD_CONNECT",{myID:e.myID,id:e.id,members:e.members})}};l.cpNf=Rn.start(d)},Bn=(e,t)=>{var n,r,o,a,i,s;const c=e.store;if(null===(r=null===(n=c.messenger)||void 0===n?void 0:n.leavePad)||void 0===r||r.call(n,t),null===(a=null===(o=c.onlyoffice)||void 0===o?void 0:o.leavePad)||void 0===a||a.call(o,t),Object.keys(c.modules).forEach((e=>{var n,r;null===(r=null===(n=c.modules[e])||void 0===n?void 0:n.leavePad)||void 0===r||r.call(n,t)})),!((e,t)=>{const{store:n}=e;if(!n)return!1;if(n.driveChannel===t)return!0;if(Ln.isSharedFolderChannel(t))return!0;if(je.find(n,["proxy","teams"])){var r=je.find(n,["proxy","teams"])||{};return Object.keys(r).some((e=>r[e].channel===t))}if(je.find(n,["proxy","profile","href"])){let e=je.find(n,["proxy","profile","href"]);return Ke.hrefToHexChannelId(e)===t}})(e,t)){try{Ye.leaveChannel(t)}catch(e){console.error(e)}null===(s=null===(i=e.channels[t])||void 0===i?void 0:i.cpNf)||void 0===s||s.stop()}delete e.channels[t]},Vn={init:e=>{const{broadcast:t,postMessage:n,store:r,Store:o}=e,a={channels:[],postMessage:n,store:r,Store:o,myDeletions:[],leavePad:(e,t,n)=>{}},i=(e,t,n)=>{const r=a.channels[t.channel];(null==r?void 0:r.cpNf)?(Bn(a,t.channel),n()):n({error:"EINVAL"})};a.leavePad=i;return{join:(e,t,n)=>{Un(a,e,t)},destroy:(e,t,n)=>{((e,t,n,r)=>{const{store:o,Store:a,channels:i,myDeletions:s}=e;let c,u,l=n,f=!1;if(n&&"object"==typeof n&&({channel:l,force:f,teamId:c,reason:u}=n),l===o.driveChannel&&!f)return void r({error:"User drive removal blocked!"});const d=a.getStore(c);d?d.rpc?(i[l]&&(s[l]=!0),d.rpc.removeOwnedChannel(l,(e=>{e&&delete s[l],r({error:e})}),u)):r({error:"RPC_NOT_READY"}):r({error:"ENOTFOUND"})})(a,0,t,n)},clear:(e,t,n)=>{((e,t,n,r)=>{const{Store:o}=e,a=o.getStore(n&&n.teamId);a.rpc?a.rpc.clearOwnedChannel(n.channel,(e=>{r({error:e})})):r({error:"RPC_NOT_READY"})})(a,0,t,n)},setMetadata:(e,t,n)=>{((e,t,n,r)=>{if(!n.channel)return void r({error:"ENOTFOUND"});if(!n.command)return void r({error:"EINVAL"});const{Store:o}=e,a=o.getStore(n.teamId);if(!a)return void r({error:"ENOTFOUND"});const i=n.channels;delete n.channels,a.rpc.setMetadata(n,((e,t)=>{e?r({error:e}):Array.isArray(t)&&t.length?r(t[0]):r({})})),Array.isArray(i)&&i.forEach((e=>{var r=je.clone(n);r.channel=e,o.setPadMetadata(t,r,(()=>{}))}))})(a,e,t,n)},getMetadata:(e,t,n)=>{jn(a,0,t,n)},sendMessage:(e,t,n)=>{((e,t,n,r)=>{var o=n.msg,a=e.channels[n.channel];if(a)a.wc?a.sendMessage(o,t,r):(a.queue.push(o),r())})(a,e,t,n)},onCorruptedCache:(e,t,n)=>{((e,t,n)=>{var r=e.channels[n];r&&r.cpNf&&(Ye.clearChannel(n),r.cpNf.resetCache&&r.cpNf.resetCache())})(a,0,t)},getLastHash:(e,t,n)=>{((e,t,n,r)=>{var o=e.channels[n.channel];o?o.lastHash?r({hash:o.lastHash}):r({error:"EINVAL"}):r({error:"ENOCHAN"})})(a,0,t,n)},leave:i,removeClient:e=>{Object.keys(a.channels).forEach((t=>{let n=a.channels[t].clients.indexOf(e);-1!==n&&a.channels[t].clients.splice(n,1),0===a.channels[t].clients.length&&Bn(a,t)}))},onJoined:Hn.reg,onCacheReady:Kn.reg,getChannels:()=>a.channels}}};var Gn,Yn,Jn,qn,Wn,Qn,zn,Xn,Zn,$n,er,tr,nr,rr,or,ar,ir,sr,cr,ur,lr=o(Object.freeze({__proto__:null,Pad:Vn}));function fr(){if(Yn)return Gn;Yn=1;return Gn=((e,t,n)=>{const r={};let o={},a={};r.setCustomize=e=>{o=e.Messages,a=e.AppConfig};var i=function(e,t){t.degraded||t.clients.forEach((function(n){var r=e.clients[n];if(r){var o={id:r.id,cursor:r.cursor};t.sendMsg(JSON.stringify(o))}}))},s=function(e,t,n){var r=t.members,o=a.degradedLimit||8;n.degraded=r.length-1>=o,e.emit("DEGRADED",{degraded:n.degraded},n.clients)},c=function(e,t,r,o){var a=t.channel,c=t.secret;c.keys.cryptKey&&(c.keys.cryptKey=function(e){for(var t=Object.keys(e).length,n=new Uint8Array(t),r=0;r<t;r++)n[r]=e[r];return n}(c.keys.cryptKey));var u=c.channel,l=e.store.network,f=!0,d=e.clients[r];if(d)o();else{d=e.clients[r]={channel:a,cursor:{}};var h=e.channels[a];if(h)return d.id||(d.id=h.wc.myID+"-"+r),h.clients.forEach((function(t){var n=e.clients[t];h.degraded||n&&e.emit("MESSAGE",{id:n.id,cursor:n.cursor},[r])})),h.sendMsg(JSON.stringify({join:!0,id:d.id})),h.clients.push(r),s(e,h.wc,h),void o();var p=function(t){e.channels[a]=e.channels[a]||{};var l=e.channels[a];l.padChan=u,d.id||(d.id=t.myID+"-"+r),l.clients&&l.clients.forEach((function(n){e.clients[n]&&!e.clients[n].id&&(e.clients[n].id=t.myID+"-"+n)})),l.encryptor||(l.encryptor=n.createEncryptor(c.keys)),t.on("join",(function(){i(e,l),s(e,t,l)})),t.on("leave",(function(n){e.emit("MESSAGE",{leave:!0,id:n},l.clients),s(e,t,l)})),t.on("message",(function(t){if(!l.degraded){var n,r=l.encryptor.decrypt(t,c.keys&&c.keys.validateKey);try{if((n=JSON.parse(r))&&n.join)return void i(e,l);e.emit("MESSAGE",n,l.clients)}catch(e){console.error(e)}}})),l.wc=t,l.sendMsg=function(e,n){n=n||function(){};var r=l.encryptor.encrypt(e);t.bcast(r).then((function(){n()}),(function(e){n({error:e})}))},f&&(l.clients=[r],f=!1,o(),s(e,t,l))};l.join(a).then(p,(function(e){o({error:e})}));var y=function(){e.channels[a]?l.join(a).then(p,(function(e){console.error(e)})):console.log("cant reconnect",a)};e.channels[a]=e.channels[a]||{},e.channels[a].onReconnect=y,l.on("reconnect",y)}},u=function(n,r,a,i){var s=n.clients[a];if(s){var c=n.store.proxy||{};r.color=e.find(c,["settings","general","cursor","color"]),r.name=c[t.displayNameKey]||n.store.noDriveName||o.anonymous,r.avatar=e.find(c,["profile","avatar"]),r.uid=e.find(c,["uid"])||n.store.noDriveUid,s.cursor=r,function(e,t){var n=e.clients[t];if(n&&n.cursor){var r=e.channels[n.channel];if(r&&!r.degraded&&r.sendMsg){var o={id:n.id,cursor:n.cursor};r.sendMsg(JSON.stringify(o)),e.emit("MESSAGE",o,r.clients.filter((function(e){return e!==t})))}}}(n,a),i()}else i({error:"NO_CLIENT"})};return r.init=function(e,t,n){var r={};if(e.store&&e.store.modules&&e.store.modules.cursor)return e.store.modules.cursor;var o={store:e.store,emit:n,channels:{},clients:{}};return r.removeClient=function(e){!function(e,t){var n,r=function(e){return e!==t};for(var o in e.channels)(n=e.channels[o]).clients=n.clients.filter(r),0===n.clients.length&&(n.wc&&n.wc.leave(),n.onReconnect&&e.store.network.off("reconnect",n.onReconnect),delete e.channels[o]);if(e.clients[t]){var a={leave:!0,id:e.clients[t].id};(n=e.channels[e.clients[t].channel])&&(n.sendMsg(JSON.stringify(a)),e.emit("MESSAGE",a,n.clients))}delete e.clients[t]}(o,e)},r.leavePad=function(e){!function(e,t){Object.keys(e.channels).some((function(n){var r=e.channels[n];if(r.padChan===t)return r.wc&&r.wc.leave(),r.onReconnect&&e.store.network.off("reconnect",r.onReconnect),delete e.channels[n],!0}))}(o,e)},r.execCommand=function(e,t,n){var r=t.cmd,a=t.data;"INIT_CURSOR"!==r?"UPDATE"!==r||u(o,a,e,n):c(o,a,e,n)},r},r})(Ne(),Oe(),ye()),Gn}function dr(){if(qn)return Jn;qn=1;return Jn=((e,t,n,r,o,a,i,s,c,u)=>{const l={};let f={};l.setCustomize=e=>{f=e.ApiConfig};var d=function(e,t,n,r){let o=Object.keys(e.clients).filter((n=>Boolean(e.clients[n].admin)===t));o.length&&e.emit(n,{channel:r},[o])},h=function(t,n,r,o){var a=e.mkAsync(o);if(n&&!t.adminRdyEvt)return void a("EFORBIDDEN");let i=f.httpUnsafeOrigin;e.fetchApi(i,"config",!0,(o=>{t.moderatorKeys=o.moderatorKeys,t.adminKeys=o.adminKeys;var i=o.supportMailboxKey;if(i)if(n&&e.find(t.store.proxy,["mailboxes","supportteam","keys","curvePublic"])!==i)a("EFORBIDDEN");else{var s=o.supportMailboxKemKey;if(n)return t.adminRdyEvt.reg((()=>{a(null,{supportKey:i,supportKemKey:s,myCurve:r.adminCurvePrivate||e.find(t.store.proxy,["mailboxes","supportteam","keys","curvePrivate"]),theirPublic:r.curvePublic,myKem:t.store.proxy.kemPrivate,theirKem:r.kemPublic,notifKey:r.curvePublic})}));a(null,{supportKey:i,supportKemKey:s,myCurve:t.store.proxy.curvePrivate,theirPublic:r.curvePublic||i,myKem:t.store.proxy.kemPrivate,theirKem:r.kemPublic||s,notifKey:i})}else a("E_NOT_INIT")}))},p=function(t,n,r,o){var s,c,l,f,d=e.once(e.mkAsync(o));a((e=>{h(t,r,n,e(((t,n)=>{if(t)return e.abort(),void d({error:t});s=n.theirPublic,c=n.myCurve,l=n.theirKem,f=n.myKem})))})).nThen((()=>{var r,o=i.Curve.deriveKeys(s,c,l,f),a=i.Curve.createEncryptor(o),h={network:t.store.network,channel:n.channel,noChainPad:!0,crypto:a,owners:[]},p=[];d=e.both((function(){r&&"function"==typeof r.stop&&r.stop()}),d),h.onMessage=function(e,t,n,r,o,a,i){var s=i&&i.time;try{e=JSON.parse(e)}catch(e){return void console.error(e)}e.time=s,a&&(e.author=a),p.push(e)},h.onError=d,h.onChannelError=d,h.onReady=function(){d(null,p)},r=u.start(h)}))},y=function(n,r,o,s){var c=e.find(n,["store","mailbox"]),u=e.find(n,["store","anon_rpc"]);if(c)if(u){var l,f,d,p,y,v=r.channel,m=r.title,g=r.ticket,E=+new Date;a((e=>{h(n,o,r,e(((t,n)=>{if(t)return e.abort(),void s({error:t});l=n.supportKey,f=n.theirPublic,p=n.theirKem,y=n.myKem,d=n.myCurve})))})).nThen((e=>{var t=i.Curve.deriveKeys(f,d,p,y),n=i.Curve.createEncryptor(t),r=JSON.stringify(g),o=n.encrypt(r);u.send("WRITE_PRIVATE_MESSAGE",[v,o],e(((t,n)=>{if(t)return e.abort(),void s({error:t});E=n&&n[0]})))})).nThen((e=>{if(o){var t=n.adminDoc.proxy.tickets.active;if(t[v])return e.abort(),void s({error:"EEXISTS"});t[v]={title:g.title,restored:g.legacy,premium:!1,time:E,author:r.name,supportKey:l,lastAdmin:!0,authorKey:r.curvePublic,notifications:r.notifications}}})).nThen((e=>{o||(n.supportData[v]={time:+new Date,title:m,curvePublic:l},n.Store.onSync(null,e()))})).nThen((()=>{var a=o?r.notifications:t.getChannelIdFromKey(l);c.sendTo("NEW_TICKET",{title:m,channel:v,time:E,isAdmin:o,supportKey:l,premium:o?"":e.find(n,["store","account","plan"]),user:e.find(r.ticket,["sender","curvePublic"])?void 0:{supportTeam:!0}},{channel:a,curvePublic:f},(e=>{console.error(e),e&&e.error&&delete n.supportData[v],s(e)})),c.sendTo("NOTIF_TICKET",{title:m,channel:v,time:E,isAdmin:o,isNewTicket:!0,user:e.find(r.ticket,["sender","curvePublic"])?void 0:{supportTeam:!0}},{channel:a,curvePublic:f},(()=>{}))}))}else s({error:"anonymous rpc session not ready"});else s({error:"E_NOT_READY"})},v=function(n,r,o,s){var c,u,l,f,d,p,y=e.find(n,["store","mailbox"]),v=e.find(n,["store","anon_rpc"]);y?v?r?.ticket?a((e=>{h(n,o,r,e(((t,n)=>{if(t)return e.abort(),void s(t);c=n.theirPublic,u=n.myCurve,d=n.theirKem,f=n.myKem,l=n.notifKey})))})).nThen((e=>{var t=i.Curve.deriveKeys(c,u,d,f),n=i.Curve.createEncryptor(t),o=JSON.stringify(r.ticket),a=n.encrypt(o);v.send("WRITE_PRIVATE_MESSAGE",[r.channel,a],e(((t,n)=>{if(t)return e.abort(),void s(t);p=n&&n[0],s(void 0,p)})))})).nThen((()=>{var n=o?r.notifChannel:t.getChannelIdFromKey(l);n&&y.sendTo("NOTIF_TICKET",{isAdmin:o,title:r.ticket.title,isClose:r.ticket.close,channel:r.channel,time:p,user:e.find(r.ticket,["sender","curvePublic"])?void 0:{supportTeam:!0}},{channel:n,curvePublic:l},(()=>{}))})):s("E_NO_DATA"):s("anonymous rpc session not ready"):s("E_NOT_READY")},m=function(n,r,o){var a=t.getSecrets("support",r),u={data:{},channel:a.channel,crypto:i.createEncryptor(a.keys),userName:"support",ChainPad:c,classic:!0,network:n.store.network,metadata:{validateKey:a.keys.validateKey||void 0}},l=n.adminDoc=s.create(u);l.proxy.on("ready",(function(){var r=l.proxy;if(r.tickets=r.tickets||{},r.tickets.active=r.tickets.active||{},r.tickets.closed=r.tickets.closed||{},r.tickets.pending=r.tickets.pending||{},n.adminRdyEvt.fire(),o(),!n.supportRpc)return;let a=function(t){if(!t.adminDoc||!t.supportRpc)return;let n=t.adminDoc.metadata&&t.adminDoc.metadata.channel,r=t.adminDoc.proxy.tickets,o=[n,...Object.keys(r.active),...Object.keys(r.pending),...Object.keys(r.closed)];return e.deduplicateString(o).sort()}(n),i=t.hashChannelList(a);n.supportRpc.getServerHash((function(e,t){e?console.warn(e):t!==i&&n.supportRpc.reset(a,(function(e){e&&console.warn(e)}))}))})),l.proxy.on("change",["recorded"],(function(){d(n,!0,"RECORDED_CHANGE","")})),l.proxy.on("remove",["recorded"],(function(){d(n,!0,"RECORDED_CHANGE","")}))},g=function(n,o,s){let c=s(),u=n.store.proxy,l=e.find(u,["mailboxes","supportteam","keys","curvePublic"]),f=e.find(u,["mailboxes","supportteam","keys","curvePrivate"]);o||(n.adminRdyEvt=e.mkEvent(!0)),a((e=>{h(n,!1,{},e(((t,r)=>{if(setTimeout(c),t)e.abort();else if(r.theirPublic!==l){try{delete u.mailboxes.supportteam,n.store.mailbox.close("supportteam")}catch(e){}return delete n.adminRdyEvt,void e.abort()}})))})).nThen((t=>{!function(t,n){let o,a,s=e.mkAsync(n),c=t.store.proxy,u=e.find(c,["mailboxes","supportteam","keys","curvePrivate"]);if(u){try{let t=i.CryptoAgility.signKeyPairFromSeed(e.decodeBase64(u));o=e.encodeBase64(t.secretKey),a=e.encodeBase64(t.publicKey)}catch(e){return void s(e)}r.create(t.store.network,{edPublic:a,edPrivate:o},((e,n)=>{e?s(e):(console.log("Support RPC ready, public key is ",a),t.supportRpc=n,s())}))}else s("EFORBIDDEN")}(n,t((e=>{e&&console.error("Support RPC not ready",e)})))})).nThen((e=>{let r=f.slice(0,24),o=t.getEditHashFromKeys({version:2,type:"support",keys:{editKeyStr:r}});m(n,o,e())})).nThen((()=>{console.log("Support admin loaded")}))};var E=function(t,n,r,o){let a=t.store.proxy,i=e.find(a,["mailboxes","supportadmin"]);i?t.store.mailbox.open("supportadmin",i,(function(n){t.store.mailbox.close("supportadmin",(function(){}));let r=e.clone(n||{}),a=[];Object.keys(r).forEach((e=>{let n=r[e];if("CLOSE"===n.type)return void(a.includes(n.content.id)||a.push(n.content.id));let o=n.author,i=n.content&&n.content.title;((e,t,n)=>{let r=e.adminDoc.proxy;return["active","pending","closed"].some((e=>{let o=r.tickets[e];return Object.keys(o).some((e=>{let r=o[e];return r.authorKey===t&&r.title===n&&r.restored}))}))})(t,o,i)&&(a.includes(n.content.id)||a.push(n.content.id))})),Object.keys(r).forEach((e=>{let t=r[e];t.content&&a.includes(t.content.id)&&delete r[e]})),o(r)}),!0,{dump:!0}):o({error:"ENOENT"})};let b=(t,n,r,o,a)=>{let s;try{let t=i.CryptoAgility.signKeyPairFromSeed(e.decodeBase64(r));s=e.encodeBase64(t.publicKey)}catch(e){return void a(e)}t.Store.adminRpc(null,{cmd:"ADMIN_DECREE",data:["SET_SUPPORT_KEYS",[n,s,o]]},a)},A=(e,t,n,r)=>{e.Store.adminRpc(null,{cmd:"GET_MODERATORS",data:{}},r)};return l.init=function(r,s,c){var u={};if(r.store&&r.store.modules&&r.store.modules.support)return r.store.modules.support;var l=r.store,m=l.proxy.support=l.proxy.support||{},_={moderatorKeys:f.moderatorKeys,adminKeys:f.adminKeys,supportData:m,store:r.store,Store:r.Store,emit:c,clients:{}};return e.find(l,["proxy","mailboxes","supportteam"])&&g(_,!1,s),u.ctx=_,u.removeClient=function(e){delete _.clients[e]},u.leavePad=function(){},u.addAdminTicket=function(e,t){!function(e,t,r){e.adminRdyEvt?e.adminRdyEvt.reg((()=>{let o;a((n=>{h(e,!0,t,n(((e,t)=>{if(e)return n.abort(),void r(!0);o=t.supportKey})))})).nThen((()=>{var a=Math.floor(2e3*Math.random());setTimeout((()=>{var a=e.adminDoc.proxy;a.tickets.active[t.channel]||a.tickets.closed[t.channel]||a.tickets.pending[t.channel]?r(!0):(a.tickets.active[t.channel]={title:t.title,premium:t.premium,time:t.time,author:t.user&&t.user.displayName,supportKey:t.supportKey||o,authorKey:t.user&&t.user.curvePublic},n.whenRealtimeSyncs(e.adminDoc.realtime,(function(){r(!0)})),d(e,!0,"NEW_TICKET",t.channel),e.supportRpc&&e.supportRpc.pin([t.channel],(()=>{})))}),a)}))})):r(!0)}(_,e,t)},u.updateAdminTicket=function(e){!function(e,t){e.adminRdyEvt&&e.adminRdyEvt.reg((()=>{var n=Math.floor(2e3*Math.random());setTimeout((()=>{var n=e.adminDoc.proxy;let r=n.tickets.active[t.channel]||n.tickets.pending[t.channel];r&&(t.time<=r.time||(t.isClose&&(n.tickets.closed[t.channel]=r,delete n.tickets.active[t.channel],delete n.tickets.pending[t.channel]),r.time=t.time,r.lastAdmin=!1,d(e,!0,"UPDATE_TICKET",t.channel)))}),n)}))}(_,e)},u.updateAdminKey=function(n,r){((n,r,o)=>{let i=r.supportKey,s=t.getBoxPublicFromSecret(i),c=n.store.proxy;const u=e.find(c,["mailboxes","supportteam","keys","curvePrivate"]),l=e.find(c,["mailboxes","supportteam","keys","curvePublic"]);h(n,!1,{},((t,r)=>{if(t)return void o(!0);if(s!==r.theirPublic)return void o(!0);if(u===i||l===s)return void o(!0);let c=e.find(n,["store","mailbox"]);try{n.adminDoc&&n.adminDoc.stop(),c&&c.close("supportteam"),n.supportRpc&&n.supportRpc.destroy(),n.adminRdyEvt=e.mkEvent(!0)}catch(e){console.error(e)}n.Store.addAdminMailbox(null,{version:2,priv:i},(e=>{e&&e.error?o(!0):a((e=>{g(n,!0,e),n.adminRdyEvt.reg((()=>{d(n,!0,"UPDATE_RIGHTS"),o(!1)}))}))}))}))})(_,n,r)},u.checkAdminTicket=function(e,t){!function(e,t,n){e.adminRdyEvt?e.adminRdyEvt.reg((()=>{let r=e.adminDoc.proxy,o=r.tickets.active[t.channel]||r.tickets.pending[t.channel];n(o)})):n(!0)}(_,e,t)},u.addUserTicket=function(e,t){!function(e,t,n){if(!e.supportData)return void n(!0);let r=t.channel;e.supportData[r]={time:t.time,title:t.title,curvePublic:t.supportKey},e.Store.onSync(null,(function(){n(!0)}))}(_,e,t)},u.updateUserTicket=function(e){!function(e,t){if(d(e,!1,"UPDATE_TICKET",t.channel),t.isClose){let n=e.supportData[t.channel];if(!n)return;n.closed=!0}}(_,e)},u.execCommand=function(r,s,c){var u=s.cmd,l=s.data;"MAKE_TICKET"!==u?"GET_MY_TICKETS"!==u?"REPLY_TICKET"!==u?"CLOSE_TICKET"!==u?"DELETE_TICKET"!==u?"MAKE_TICKET_ADMIN"!==u?"LIST_TICKETS_ADMIN"!==u?"LOAD_TICKET_ADMIN"!==u?"REPLY_TICKET_ADMIN"!==u?"CLOSE_TICKET_ADMIN"!==u?"MOVE_TICKET_ADMIN"!==u?"GET_RECORDED"!==u?"SET_RECORDED"!==u?"USE_RECORDED"!==u?"SEARCH_ADMIN"!==u?"FILTER_TAGS_ADMIN"!==u?"SET_TAGS_ADMIN"!==u?"GET_LEGACY"!==u?"DUMP_LEGACY"!==u?"CLEAR_LEGACY"!==u?"RESTORE_LEGACY"!==u?"GET_PRIVATE_KEY"!==u?"DISABLE_SUPPORT"!==u?"ROTATE_KEYS"!==u?"ADD_MODERATOR"!==u?c({error:"NOT_SUPPORTED"}):function(t,n,r,o){let a=t.store.proxy;var i=e.find(t,["store","mailbox"]);let s=e.find(a,["mailboxes","supportteam","keys","curvePublic"]),c=e.find(a,["mailboxes","supportteam","keys","curvePrivate"]),u=e.find(a,["mailboxes","supportteam","lastKnownHash"]),l=a.edPublic;h(t,!1,{},((e,r)=>{e?o({error:e}):r.theirPublic===s&&t.moderatorKeys.includes(l)?i.sendTo("ADD_MODERATOR",{supportKey:c,lastKnownHash:u},{channel:n.mailbox,curvePublic:n.curvePublic},(()=>{o()})):o({error:"EFORBIDDEN"})}))}(_,l,0,c):function(n,r,s,c){let u,l=e.once(e.mkAsync(c)),f=n.store.proxy,d=f.edPublic;const p=i.CryptoAgility.curveKeyPair(),y=i.CryptoAgility.generateKemKeypair(),v=e.encodeBase64(p.publicKey),m=e.encodeBase64(p.secretKey),E=e.encodeBase64(y.publicKey),_=e.find(f,["mailboxes","supportteam","keys","curvePrivate"]),w=e.find(f,["mailboxes","supportteam","keys","curvePublic"]),O=e.find(f,["mailboxes","supportteam","keys","kemPublic"]);if(!m||!v)return void l({error:"INVALID_KEY"});let D;a((e=>{h(n,!1,{},e(((t,n)=>{if("E_NOT_INIT"!==t)return t?(l({error:t}),void e.abort()):void(u=n.theirPublic)})))})).nThen((e=>{if(!n.adminKeys.includes(d))return e.abort(),void l({error:"EFORBIDDEN"})})).nThen((e=>{if(u)return n.moderatorKeys.includes(d)?w!==u?(e.abort(),void l({error:"EFORBIDDEN"})):void 0:(e.abort(),void l({error:"EINVAL"}))})).nThen((e=>{u&&n.adminRdyEvt.reg((()=>{let r=n.adminDoc.proxy;D=n.adminDoc.metadata&&n.adminDoc.metadata.channel;let a=m.slice(0,24),i=t.getEditHashFromKeys({version:2,type:"support",keys:{editKeyStr:a}}),s={network:n.store.network,initialState:"{}"};(r.oldKeys=r.oldKeys||{})[w]={curvePrivate:_,rotatedOn:+new Date,rotatedBy:d},o.put(i,JSON.stringify(r),e((t=>{if(t)return e.abort(),void l({error:t})})),s)}))})).nThen((e=>{b(n,v,m,E,e((t=>{if(t&&t.error)return e.abort(),void l(t)})))})).nThen((()=>{if(!u)return;n.adminDoc&&n.adminDoc.stop();let t=e.find(n,["store","mailbox"]);t&&t.close("supportteam"),n.supportRpc&&n.supportRpc.destroy(),n.adminRdyEvt=e.mkEvent(!0)})).nThen((e=>{n.Store.addAdminMailbox(null,{version:2,priv:m},e((t=>{if(t&&t.error)return e.abort(),u?b(n,w,_,O,(()=>{l(t)})):void l(t)})))})).nThen((t=>{if(!u)return;let r=e.find(n,["store","mailbox"]);A(n,0,0,t((e=>{if(e&&e.error)return void l({success:!0,noNotify:!0});let t=e&&e[0];Object.keys(t||{}).forEach((e=>{let n=t[e];r.sendTo("MODERATOR_NEW_KEY",{supportKey:m},{channel:n.mailbox,curvePublic:n.curvePublic},(()=>{}))}))})))})).nThen((e=>{g(n,!0,e)})).nThen((e=>{D&&n.Store.adminRpc(null,{cmd:"ARCHIVE_DOCUMENT",data:{id:D,reason:"Deprecated support pad"}},e())})).nThen((()=>{l({success:!0})}))}(_,0,0,c):function(t,n,r,o){let i,s=e.once(e.mkAsync(o)),c=t.store.proxy.edPublic;a((e=>{h(t,!1,{},e((t=>{if(t)return s({error:t}),void e.abort()})))})).nThen((e=>{if(!t.adminKeys.includes(c))return e.abort(),void s({error:"EFORBIDDEN"})})).nThen((e=>{t.Store.adminRpc(null,{cmd:"ARCHIVE_SUPPORT",data:{}},e((t=>{if(t&&t.error)return e.abort(),void s(t)})))})).nThen((e=>{t.Store.adminRpc(null,{cmd:"ADMIN_DECREE",data:["SET_SUPPORT_KEYS",["","",""]]},e((function(t){if(t&&t.error)return e.abort(),void s(t)})))})).nThen((e=>{A(t,0,0,e((t=>{if(!t||t.error)return e.abort(),void s();i=t[0]||{}})))})).nThen((()=>{let e=a;Object.keys(i).forEach((n=>{e=e((e=>{t.Store.adminRpc(null,{cmd:"REMOVE_MODERATOR",data:n},e((e=>{e&&e.error&&console.error("Error removing moderator data",n,e.error)})))})).nThen})),e((()=>{s()}))}))}(_,0,0,c):function(t,n,r,o){let a=t.store.proxy,i=e.find(a,["mailboxes","supportteam","keys","curvePublic"]),s=e.find(a,["mailboxes","supportteam","keys","curvePrivate"]);h(t,!1,{},((e,t)=>{e?o({error:e}):(i&&t.theirPublic!==i&&(s=void 0),o({curvePrivate:s,curvePublic:t.theirPublic}))}))}(_,0,0,c):function(n,r,o,a){let i=n.store.proxy,s=e.find(i,["mailboxes","supportadmin"]);if(!s)return void a({error:"ENOENT"});if(!n.adminRdyEvt)return void a({error:"EFORBIDDEN"});let c=r.messages,u=r.hashes,l=c[0],f=c[c.length-1];l?n.adminRdyEvt.reg((()=>{let r={name:e.find(l,["sender","name"]),notifications:e.find(l,["sender","notifications"]),curvePublic:e.find(l,["sender","curvePublic"]),kemPublic:e.find(l,["sender","kemPublic"]),channel:t.createChannelId(),title:l.title,time:f.time,ticket:{legacy:!0,title:l.title,sender:l.sender,messages:c}};y(n,r,!0,(e=>{e&&e.error?a(e):(u.forEach((e=>{s.viewed.push(e)})),n.Store.onSync(null,(function(){a({done:!0})})))}))})):a({error:"EINVAL"})}(_,l,0,c):function(e,t,n,r){let o=e.store.proxy;e.store.mailbox.close("supportadmin",(function(){delete o.mailboxes.supportadmin,e.Store.onSync(null,(function(){r({done:!0})}))}))}(_,0,0,c):function(t,n,r,o){let a=t.store.proxy,i=e.find(a,["mailboxes","supportadmin"]);if(!i)return void o({error:"ENOENT"});let s=e.clone(i);s.lastKnownHash=void 0,s.viewed=[],t.store.mailbox.open("supportadmin",s,(function(e){t.store.mailbox.close("supportadmin",(function(){})),o(e)}),!0,{dump:!0})}(_,0,0,c):E(_,0,0,c):((e,t,r,o)=>{e.adminRdyEvt?e.adminRdyEvt.reg((()=>{let r=e.adminDoc.proxy.tickets,a=t.channel;(r.active[a]||r.pending[a]||r.closed[a]).tags=t.tags||[],n.whenRealtimeSyncs(e.adminDoc.realtime,(function(){let e=[];["active","pending","closed"].forEach((t=>{let n=r[t];Object.keys(n).forEach((t=>{(n[t].tags||[]).forEach((t=>{e.includes(t)||e.push(t)}))}))})),o({done:!0,allTags:e})}))})):o({error:"EFORBIDDEN"})})(_,l,0,c):((e,t,n,r)=>{if(!e.adminRdyEvt)return void r({error:"EFORBIDDEN"});let o=t.tags||[];e.adminRdyEvt.reg((()=>{let t=e.adminDoc.proxy.tickets;if(!o.length)return void r({all:!0});let n=[];["active","pending","closed"].forEach((e=>{let r=t[e];Object.keys(r).forEach((e=>{(r[e].tags||[]).some((e=>o.includes(e)))||n.push(e)}))})),r({tickets:n})}))})(_,l,0,c):((t,n,r,o)=>{if(!t.adminRdyEvt)return void o({error:"EFORBIDDEN"});let a=n.tags||[],i=(n.text||"").toLowerCase();t.adminRdyEvt.reg((()=>{let n=t.adminDoc.proxy.tickets,r={},s=(t,n,o)=>{let a=e.clone(n);a.category=o,r[t]=a};["active","pending","closed"].some((t=>{let o=n[t];return Object.keys(o).some((n=>{let c=o[n];if(a.length&&!(c.tags||[]).some((e=>a.includes(e))))return;let u=e.hexToBase64(n).slice(0,10);if(i===u)return r={},s(n,c,t),!0;(!i||c.title.toLowerCase().includes(i))&&s(n,c,t)}))})),o({tickets:r})}))})(_,l,0,c):function(e,t,n,r){if(!e.adminRdyEvt)return void r({error:"EFORBIDDEN"});let o=t.id;e.adminRdyEvt.reg((()=>{let t=e.adminDoc.proxy,n=(t.recorded=t.recorded||{})[o];n&&(n.count=(n.count||0)+1),r()}))}(_,l,0,c):function(e,t,r,o){if(!e.adminRdyEvt)return void o({error:"EFORBIDDEN"});let a=t.id,i=t.content,s=Boolean(t.remove);e.adminRdyEvt.reg((()=>{let t=e.adminDoc.proxy,r=t.recorded=t.recorded||{};s?delete r[a]:r[a]={content:i,count:0},n.whenRealtimeSyncs(e.adminDoc.realtime,(function(){o({done:!0})}))}))}(_,l,0,c):function(t,n,r,o){t.adminRdyEvt?t.adminRdyEvt.reg((()=>{let n=t.adminDoc.proxy,r=n.recorded=n.recorded||{};o({messages:e.clone(r)})})):o({error:"EFORBIDDEN"})}(_,0,0,c):function(e,t,r,o){if(!e.adminRdyEvt)return void o({error:"EFORBIDDEN"});let a=t.channel,i=t.from,s=t.to;e.adminRdyEvt.reg((()=>{let t=e.adminDoc.proxy,r=t.tickets[i],c=t.tickets[s];if(!i||!s)return void o({error:"EINVAL"});let u=r[a];u&&!c[a]?(c[a]=u,delete r[a],n.whenRealtimeSyncs(e.adminDoc.realtime,(function(){o({moved:!0})}))):o({error:"CANT_MOVE"})}))}(_,l,0,c):function(e,t,r,o){if(!e.adminRdyEvt)return void o({error:"EFORBIDDEN"});let a=t.supportKey;e.adminRdyEvt.reg((()=>{let r=e.adminDoc.proxy;r.oldKeys&&r.oldKeys[a]&&(t.adminCurvePrivate=r.oldKeys[a].curvePrivate),v(e,t,!0,(r=>{if(r)o({error:r});else{var a=e.adminDoc.proxy,i=a.tickets.active[t.channel]||a.tickets.pending[t.channel];i.time=+new Date,i.lastAdmin=!0,a.tickets.closed[t.channel]=i,delete a.tickets.active[t.channel],delete a.tickets.pending[t.channel],n.whenRealtimeSyncs(e.adminDoc.realtime,(function(){o({closed:!0})}))}}))}))}(_,l,0,c):function(e,t,n,r){if(!e.adminRdyEvt)return void r({error:"EFORBIDDEN"});let o=t.supportKey;e.adminRdyEvt.reg((()=>{let n=e.adminDoc.proxy;n.oldKeys&&n.oldKeys[o]&&(t.adminCurvePrivate=n.oldKeys[o].curvePrivate),v(e,t,!0,((n,o)=>{if(n)r({error:n});else{var a=e.adminDoc.proxy,i=a.tickets.active[t.channel]||a.tickets.pending[t.channel];i.time=o,i.lastAdmin=!0,r({sent:!0})}}))}))}(_,l,0,c):function(t,n,r,o){let a=n.supportKey;t.adminRdyEvt.reg((()=>{let r=t.adminDoc.proxy;r.oldKeys&&r.oldKeys[a]&&(n.adminCurvePrivate=r.oldKeys[a].curvePrivate),p(t,n,!0,(function(r,a){if(r)return void o({error:r});var i=t.adminDoc.proxy;if(!Array.isArray(a)||!a.length)return void o(a);a.sort(((e,t)=>e.time-t.time));let s=a[a.length-1],c=a.some((t=>{let r=e.find(t,["sender","curvePublic"]);if(n.curvePublic===r)return e.find(t,["sender","quota","plan"])}));var u=i.tickets.active[n.channel];u&&(s.legacy&&(s=Array.isArray(s.messages)&&s.messages[s.messages.length-1]),u.time=s.time,u.premium=c,s.sender&&(u.lastAdmin=!s.sender.blockLocation),s.close&&(i.tickets.closed[n.channel]=u,delete i.tickets.active[n.channel],d(t,!0,"UPDATE_TICKET",n.channel))),o(a)}))}))}(_,l,0,c):function(t,n,r,o){t.adminRdyEvt?(t.clients[r]||(t.clients[r]={admin:!0}),t.adminRdyEvt.reg((()=>{var r=t.adminDoc.proxy;return"pending"===n.type?o(e.clone(r.tickets.pending)):"closed"===n.type?o(e.clone(r.tickets.closed)):void o(e.clone(r.tickets.active))}))):o({error:"EFORBIDDEN"})}(_,l,r,c):function(e,t,n,r){e.adminRdyEvt?e.adminRdyEvt.reg((()=>{y(e,t,!0,r)})):r({error:"EFORBIDDEN"})}(_,l,0,c):function(e,t,n,r){let o=e.supportData,a=t.channel;o[a]&&o[a].closed?(delete o[a],r({deleted:!0})):r({error:"ENOTCLOSED"})}(_,l,0,c):function(e,t,n,r){v(e,t,!1,(e=>{r(e?{error:e}:{closed:!0})}))}(_,l,0,c):function(e,t,n,r){v(e,t,!1,(e=>{r(e?{error:e}:{sent:!0})}))}(_,l,0,c):function(t,n,r,o){var i=[],s=a;t.clients[r]||(t.clients[r]={admin:!1}),Object.keys(t.supportData).forEach((function(n){s=s((r=>{var o=e.clone(t.supportData[n]);p(t,{channel:n,curvePublic:o.curvePublic,kemPublic:o.kemPublic},!1,r(((e,r)=>{if(e){if("EDELETED"===e.type)return void delete t.supportData[n];o.error=e}else o.messages=r,r.length&&r[r.length-1].close&&(t.supportData[n].closed=!0,o.closed=!0);o.id=n,i.push(o)})))})).nThen})),s((()=>{i.sort(((e,t)=>e.closed&&t.closed?e.time-t.time:e.closed?1:t.closed?-1:e.time-t.time)),o({tickets:i})}))}(_,0,r,c):function(e,t,n,r){y(e,t,!1,r)}(_,l,0,c)},u},l})(Ne(),Fe(),mt(),sn(),cn(),Dt(),ye(),S(),I(),O()),Jn}function hr(){if(Qn)return Wn;Qn=1;var e,t,n;return e=ye(),n=function(t,n,r,o){var a=n.channel,i=n.secret;i.keys.cryptKey&&(i.keys.cryptKey=function(e){for(var t=Object.keys(e).length,n=new Uint8Array(t),r=0;r<t;r++)n[r]=e[r];return n}(i.keys.cryptKey));var s=i.channel,c=t.store.network,u=!0,l=t.clients[r];if(l)o();else{l=t.clients[r]={channel:a};var f=t.channels[a];if(f)return l.id||(l.id=f.wc.myID+"-"+r),f.clients.push(r),void o();var d=function(n){t.channels[a]=t.channels[a]||{};var c=t.channels[a];c.padChan=s,l.id||(l.id=n.myID+"-"+r),c.clients&&c.clients.forEach((function(e){t.clients[e]&&!t.clients[e].id&&(t.clients[e].id=n.myID+"-"+e)})),c.encryptor||(c.encryptor=e.createEncryptor(i.keys)),n.on("message",(function(e){var n,r=c.encryptor.decrypt(e,i.keys&&i.keys.validateKey);try{"ISAVE"===(n=JSON.parse(r)).msg&&delete t.pending[n.uid],t.emit("MESSAGE",n,c.clients)}catch(e){console.error(e)}})),c.wc=n,c.sendMsg=function(e,t){t=t||function(){};var r=c.encryptor.encrypt(e);n.bcast(r).then((function(){t()}),(function(e){t({error:e})}))},u&&(c.clients=[r],u=!1,o())};c.join(a).then(d,(function(e){o({error:e})}));var h=function(){t.channels[a]?c.join(a).then(d,(function(e){console.error(e)})):console.log("cant reconnect",a)};t.channels[a]=t.channels[a]||{},t.channels[a].onReconnect=h,c.on("reconnect",h)}},(t={}).init=function(e,t,r){var o={};if(e.store&&e.store.modules&&e.store.modules.integration)return e.store.modules.integration;var a={store:e.store,emit:r,channels:{},pending:{},clients:{}};return o.removeClient=function(e){!function(e,t){var n,r=function(e){return e!==t};for(var o in e.channels)(n=e.channels[o]).clients=n.clients.filter(r),0===n.clients.length&&(n.wc&&n.wc.leave(),n.onReconnect&&e.store.network.off("reconnect",n.onReconnect),delete e.channels[o]);delete e.clients[t]}(a,e)},o.leavePad=function(e){!function(e,t){Object.keys(e.channels).some((function(n){var r=e.channels[n];if(r.padChan===t)return r.wc&&r.wc.leave(),r.onReconnect&&e.store.network.off("reconnect",r.onReconnect),delete e.channels[n],!0}))}(a,e)},o.execCommand=function(e,t,r){var o=t.cmd,i=t.data;"INIT"!==o?"SEND"!==o||function(e,t,n,r){var o=e.clients[n];if(o){var a=e.channels[o.channel];if(a){var i={id:n,msg:t.msg,uid:t.uid};"ISAVE"===i.msg&&(e.pending[t.uid]=!0),a.sendMsg(JSON.stringify(i),(n=>{e.pending[t.uid]?(delete e.pending[t.uid],r(n)):setTimeout(r,1e3)})),e.emit("MESSAGE",i,a.clients.filter((function(e){return e!==n})))}else r({error:"NO_CHAN"})}else r({error:"NO_CLIENT"})}(a,i,e,r):n(a,i,e,r)},o},Wn=t}function pr(){if(Xn)return zn;Xn=1;var e,t;return t=function(e,t,n){var r=e.clients[t];if(r){var o=e.channels[r.channel];o?(n(),o.history.forEach((function(n){e.emit("MESSAGE",{msg:n,validateKey:o.validateKey},[t])})),e.emit("HISTORY_SYNCED",{},[t])):n({error:"ENOCHAN"})}else n({error:"ENOENT"})},(e={}).init=function(e,n){var r={},o={store:e,emit:n,channels:{},clients:{}};return r.removeClient=function(e){!function(e,t){var n,r=function(e){return e!==t};for(var o in e.channels)(n=e.channels[o]).clients=n.clients.filter(r),0===n.clients.length&&(n.wc&&n.wc.leave(),delete e.channels[o]);if(e.clients[t]){var a=e.clients[t].channel,i=e.channels[a];i&&e.emit("LEAVE",{id:t},[i.clients[0]]),delete e.clients[t]}}(o,e)},r.leavePad=function(e){!function(e,t){Object.keys(e.channels).some((function(n){var r=e.channels[n];if(r.padChan===t)return r.wc&&r.wc.leave(),delete e.channels[n],!0}))}(o,e)},r.execCommand=function(e,n,r){var a=n.cmd,i=n.data;"SEND_MESSAGE"!==a?"UPDATE_HASH"!==a?"OPEN_CHANNEL"!==a?"GET_HISTORY"!==a?"REENCRYPT"!==a||function(e,t,n,r){var o=t.channel,a=e.store.network,i=function(e){var n=a.historyKeeper,o={metadata:t.metadata},i=["GET_HISTORY",e.id,o];a.sendto(n,JSON.stringify(i)),t.msgs.forEach((function(t){e.bcast(t)})),e.leave(),r()};e.store.anon_rpc.send("IS_NEW_CHANNEL",o,(function(e,t){var n;e?r({error:e}):(t&&t.length&&"object"==typeof t[0]?n=t[0].isNew:r({error:"INVALID_RESPONSE"}),n?a.join(o).then(i,(function(e){r({error:e})})):r({error:"EEXISTS"}))}))}(o,i,0,r):t(o,e,r):function(e,n,r,o){var a=n.channel,i=n.padChan,s=e.store.network,c=!0,u=e.clients[r];if(u)o();else{u=e.clients[r]={channel:a};var l=e.channels[a];if(l)return u.id||(u.id=l.wc.myID+"-"+r),t(e,r,(function(){e.emit("READY",l.clients,[r])})),l.clients.push(r),void o();var f=Math.floor(1e6*Math.random()),d=function(t){e.channels[a]=e.channels[a]||{history:[],validateKey:n.validateKey},(l=e.channels[a]).padChan=i,u.id||(u.id=t.myID+"-"+r),l.clients&&l.clients.forEach((function(n){e.clients[n]&&(e.clients[n].id=t.myID+"-"+n)})),t.on("join",(function(){})),t.on("leave",(function(){})),t.on("message",(function(t){l.history.push(t),e.emit("MESSAGE",{msg:t,validateKey:l.validateKey},l.clients)})),l.wc=t,l.sendMsg=function(e,n){n=n||function(){};var r=e.slice(0,64);t.bcast(e).then((function(){l.history.push(e),l.lastKnownHash=r,n()}),(function(e){n({error:e})}))},c&&(l.clients=[r],l.lastCpHash=n.lastCpHash,c=!1,o());var d=s.historyKeeper,h={txid:f,lastKnownHash:l.lastKnownHash||l.lastCpHash,metadata:{forcePlaceholder:!0,validateKey:n.validateKey,owners:n.owners,expire:n.expire}},p=["GET_HISTORY",t.id,h];d&&s.sendto(d,JSON.stringify(p)).then((function(){}),(function(e){console.error(e)}))};s.on("message",(function(t,n){if(e.channels[a]&&n===s.historyKeeper){var r;try{r=JSON.parse(t)}catch(e){}if(r&&!(r.txid&&r.txid!==f||r.channel&&r.channel!==a))if(r.validateKey&&r.channel)l.validateKey||(l.validateKey=r.validateKey);else if(r.state&&1===r.state&&r.channel)e.emit("READY",l.clients,l.clients);else if(r.error&&r.channel)e.emit("READY",l.clients,l.clients);else if(!(Array.isArray(r)&&r[0]&&r[0]!==f||(t=r[4],r[3]!==a))){var o=t.slice(0,64);o!==l.lastKnownHash&&o!==l.lastCpHash&&(l.lastKnownHash=o,e.emit("MESSAGE",{msg:t},l.clients),l.history.push(t))}}})),s.join(a).then(d,(function(e){o({error:e})})),s.on("reconnect",(function(){e.channels[a]&&s.join(a).then(d,(function(e){console.error(e)}))}))}}(o,i,e,r):function(e,t,n,r){var o=e.clients[n];if(o){var a=e.channels[o.channel];if(a){var i=t,s=-1;a.history.some((function(e,t){if(e.slice(0,64)===i)return s=t+1,!0})),-1!==s&&(a.history=a.history.slice(s)),r()}else r({error:"INVALID_CHANNEL"})}else r({error:"NOT_IN_CHANNEL"})}(o,i,e,r):function(e,t,n,r){var o=e.clients[n];if(o){var a=e.channels[o.channel];if(a){var i=function(o){o&&o.error?r(o):(e.emit("MESSAGE",{msg:t.msg},a.clients.filter((function(e){return e!==n}))),r())};t.isCp?a.sendMsg(t.isCp,i):a.sendMsg(t.msg,i)}else r({error:"INVALID_CHANNEL"})}else r({error:"NOT_IN_CHANNEL"})}(o,i,e,r)},r},zn=e}function yr(){if($n)return Zn;$n=1;return Zn=((e,t,n,r,o,a,i,s)=>{var c={};const u=e.mkEvent(!0);return c.init=function(c,l,f){var d={},h=c.store;if(h.loggedIn&&h.proxy.edPublic){var p={Store:c.Store,store:h,pinPads:c.pinPads,updateMetadata:c.updateMetadata,emit:f,onReadyHandlers:[],clients:[]};return p.profile=h.proxy.profile=h.proxy.profile||{},function(e,n){var r=e.profile;if(r.edit&&r.view)setTimeout(n);else{var o=t.createRandomHash("profile"),a=t.getSecrets("profile",o);e.pinPads([a.channel],(function(e){e.error?n(e.error):(r.edit=t.getEditHashFromKeys(a),r.view=t.getViewHashFromKeys(a),setTimeout(n))}))}}(p,l((function(r){r||function(r){var o=r.profile,c=t.getSecrets("profile",o.edit),l=i.createEncryptor(c.keys),f={data:{},network:r.store.network,channel:c.channel,crypto:l,owners:[r.store.proxy.edPublic],ChainPad:s,validateKey:c.keys.validateKey||void 0,userName:"profile",classic:!0},d=a.create(f);d.proxy.on("create",(function(){})).on("ready",(function(){if(d.proxy.name=r.store.proxy[n.displayNameKey]||"",r.listmap=d,d.proxy.curvePublic||(d.proxy.curvePublic=r.store.proxy.curvePublic),d.proxy.notifications||(d.proxy.notifications=e.find(r.store.proxy,["mailboxes","notifications","channel"])),d.proxy.edPublic||(d.proxy.edPublic=r.store.proxy.edPublic),!d.proxy.proof){let t=c.channel,n=e.decodeUTF8(t),o=e.decodeBase64(r.store.proxy.edPrivate),a=i.Nacl.sign(n,o),s=e.encodeBase64(a);d.proxy.proof=s}r.onReadyHandlers.length&&(r.onReadyHandlers.forEach((function(e){try{e(d.proxy)}catch(e){console.error(e)}})),r.onReadyHandlers=[]),u.fire()})).on("change",[],(function(){r.emit("UPDATE",d.proxy,r.clients)}))}(p)}))),d.setName=function(e){!function(e,t){e.listmap.proxy.name=t,r.whenRealtimeSyncs(e.listmap.realtime,(function(){e.listmap&&e.emit("UPDATE",e.listmap.proxy,e.clients)}))}(p,e)},d.removeClient=function(e){!function(e,t){var n=e.clients.indexOf(t);-1!==n&&e.clients.splice(n,1)}(p,e)},d.update=function(){p.listmap&&p.emit("UPDATE",p.listmap.proxy,p.clients)},d.execCommand=function(e,t,n){console.log(t);var a=t.cmd,i=t.data;"SUBSCRIBE"!==a?"SET"!==a||function(e,t,n,a){u.reg((()=>{var i=t.key,s=t.value;i&&(e.listmap.proxy[i]=s,r.whenRealtimeSyncs(e.listmap.realtime,(function(){e.emit("UPDATE",e.listmap.proxy,e.clients.filter((function(e){return e!==n}))),"badge"===i&&e.Store.set(null,{key:["profile","badge"],value:s||void 0},(()=>{o.updateMyData(e.store),e.updateMetadata()})),a(e.listmap.proxy)})))}))}(p,i,e,n):function(e,t,n,r){-1===e.clients.indexOf(n)&&e.clients.push(n),e.listmap?r(e.listmap.proxy):e.onReadyHandlers.push((function(e){r(e)}))}(p,0,e,n)},d}},c})(Ne(),Fe(),Oe(),mt(),Zt(),S(),ye(),I()),Zn}function vr(){if(tr)return er;tr=1;return er=function(e,t,n,r,o,a){var i={},s=function(e){return Boolean(e&&"object"==typeof e&&!Array.isArray(e))},c=function(e){return e.slice(0,64)},u=function(t,n){var r=e.find(n,[t,"role"]);return-1!==["OWNER","ADMIN"].indexOf(r)},l=function(t,n,r){var o=e.find(r,[t,"role"]);return!!o&&(!!function(e){return-1!==["OWNER","ADMIN","MEMBER","VIEWER"].indexOf(e)}(n)&&("OWNER"===o||"ADMIN"===o&&-1!==["ADMIN","MEMBER","VIEWER"].indexOf(n)))},f=function(e){return"string"==typeof e&&44===e.length},d=i.commands={};d.ADD=function(e,t,n){if(!s(e))throw new Error("INVALID ARGS");if(!n.internal.initialized)throw new Error("UNITIALIZED");if(void 0===n.state.members)throw new Error("CANNOT_ADD_TO_UNITIALIZED_ROSTER");var r=n.state.members;Object.keys(e).forEach((function(n){if(!f(n))throw console.log(n,n.length),new Error("INVALID_CURVE_KEY");if(!s(e[n]))throw new Error("INVALID_CONTENT");if(r[n])throw new Error("ALREADY_PRESENT");var o=e[n];if("string"!=typeof o.role&&(o.role="MEMBER"),!l(t,o.role,r))throw new Error("INSUFFICIENT_PERMISSIONS");if("string"!=typeof o.displayName)throw new Error("DISPLAYNAME_REQUIRED");if("string"!=typeof o.notifications)throw new Error("NOTIFICATIONS_REQUIRED")}));var o=!1;return Object.keys(e).forEach((function(t){o=!0,r[t]=e[t]})),o},d.RM=function(t,n,r){if(!Array.isArray(t))throw new Error("INVALID_ARGS");if(void 0===r.state.members)throw new Error("CANNOT_RM_FROM_UNITIALIZED_ROSTER");var o=r.state.members;t.forEach((function(t){if(!f(t))throw new Error("INVALID_CURVE_KEY");if(t!==n){var r=o[t].role;if(!function(t,n,r){var o=e.find(r,[t,"role"]);return!!o&&("OWNER"===o||"ADMIN"===o&&-1!==["ADMIN","MEMBER","VIEWER"].indexOf(n))}(n,r,o))throw new Error("INSUFFICIENT_PERMISSIONS")}}));var a=!1;return t.forEach((function(e){o[e]&&(a=!0,delete o[e])})),a},d.DESCRIBE=function(t,n,o){if(!t||"object"!=typeof t||Array.isArray(t))throw new Error("INVALID_ARGUMENTS");if(void 0===o.state.members)throw new Error("NOT_READY");var a=o.state.members;Object.keys(t).forEach((function(r){if(!f(r))throw new Error("INVALID_ID");if(!a[r])throw new Error("NOT_PRESENT");if(!function(t,n,r){if(!r[n])return!1;if(t===n&&r[n])return!0;var o=e.find(r,[t,"role"]),a=e.find(r,[n,"role"]);return!!o&&("OWNER"===o||"ADMIN"===o&&"OWNER"!==a)}(n,r,a))throw new Error("INSUFFICIENT_PERMISSIONS");var o=t[r];if(!s(o))throw new Error("INVALID_ARGUMENTS");var i=e.clone(a[r]);if("string"==typeof o.role&&!function(t,n,r,o){return!(t!==n||!o[n])&&("MEMBER"===e.find(o,[t,"role"])?"VIEWER"===r:void 0)}(n,r,o.role,a)&&!l(n,o.role,a))throw new Error("INSUFFICIENT_PERMISSIONS");if("string"!=typeof i.displayName&&"string"!=typeof o.displayName)throw new Error("DISPLAYNAME_REQUIRED");if(-1===["undefined","string"].indexOf(typeof o.displayName))throw new Error("INVALID_DISPLAYNAME");if("string"!=typeof i.notifications&&"string"!=typeof o.notifications)throw new Error("NOTIFICATIONS_REQUIRED");if(-1===["undefined","string"].indexOf(typeof o.notifications))throw new Error("INVALID_NOTIFICATIONS")}));var i=!1;return Object.keys(t).forEach((function(n){var o=e.clone(a[n]),s=t[n];Object.keys(s).forEach((function(e){void 0===o[e]||null!==s[e]?o[e]=s[e]:delete o[e]})),r(o)!==r(a[n])&&(i=!0,a[n]=o)})),i},d.CHECKPOINT=function(e,t,n){if(!s(e))throw new Error("INVALID_CHECKPOINT_STATE");if(!n.internal.initialized){n.state=e;var o=n.state.metadata=n.state.metadata||{};return o.topic=o.topic||"",o.name=o.name||"",o.avatar=o.avatar||"",n.internal.initialized=!0,!0}if(r(e)!==r(n.state))throw new Error("CHECKPOINT_DOES_NOT_MATCH_PREVIOUS_STATE");if(!u(t,n.state.members))throw new Error("INSUFFICIENT_PERMISSIONS");return n.state=e,!0};var h=["avatar","name","topic"];d.METADATA=function(t,n,r){if(!s(t))throw new Error("INVALID_ARGS");if(!function(t,n){var r=e.find(n,[t,"role"]);return Boolean(r&&-1!==["OWNER","ADMIN"].indexOf(r))}(n,r.state.members))throw new Error("INSUFFICIENT_PERMISSIONS");Object.keys(t).forEach((function(e){if(null===t[e]){if(-1===h.indexOf(e))return;throw new Error("CANNOT_REMOVE_MANDATORY_METADATA")}if("string"!=typeof t[e])throw new Error("INVALID_ARGUMENTS")}));var o=!1;return Object.keys(t).forEach((function(e){void 0!==r.state.metadata[e]&&null===t[e]&&(o=!0,delete r.state.metadata[e]),t[e]!==r.state.metadata[e]&&(o=!0,r.state.metadata[e]=t[e])})),o},d.INVITE=function(e,t,n){if(!s(e))throw new Error("INVALID_ARGS");if(!n.internal.initialized)throw new Error("UNINITIALIED");if(void 0===n.state.members)throw new Error("CANNOT+INVITE_TO_UNINITIALIED_ROSTER");var r=n.state.members;Object.keys(e).forEach((function(n){if(!f(n))throw console.log(n,n.length),new Error("INVALID_CURVE_KEY");if(!s(e[n]))throw new Error("INVALID_CONTENT");if(r[n])throw new Error("ARLEADY_PRESENT");var o=e[n];if("string"!=typeof o.role&&(o.role="VIEWER"),void 0===o.pending&&(o.pending=!0),!l(t,o.role,r))throw new Error("INSUFFICIENT_PERMISSIONS");if("string"!=typeof o.displayName||!o.displayName)throw new Error("DISPLAYNAME_REQUIRED")}));var o=!1;return Object.keys(e).forEach((function(t){o=!0,r[t]=e[t]})),o},d.ACCEPT=function(t,n,r){if(!r.internal.initialized)throw new Error("UNINITIALIED");if(void 0===r.state.members)throw new Error("CANNOT_ADD_TO_UNINITIALIED_ROSTER");var o=r.state.members;if(!s(o[n]))throw new Error("INSUFFICIENT_PERMISSIONS");if(!o[n].pending)throw new Error("ALREADY_PRESENT");if("string"!=typeof t)throw new Error("INVALID_ARGS");if(!f(t))throw new Error("INVALID_CURVE_KEY");var a=t;if(void 0!==o[a])throw new Error("MEMBER_ALREADY_PRESENT");var i=e.clone(o[n]);delete i.remaining,delete i.totalUses,delete i.inviteChannel,delete i.previewChannel,o[a]=i;var c=o[n].remaining||1;return-1===c||(c>1?o[n].remaining=c-1:delete o[n]),!0};var p=function(e,t,n){if(!Array.isArray(e)||"string"!=typeof t)throw new Error("INVALID ARGUMENTS");var r=e[0];if("function"!=typeof d[r])throw new Error("INVALID_COMMAND");return d[r](e[1],t,n)},y=function(t,n,r){return p(t,n,e.clone(r))};return i.create=function(t,i){if("function"!=typeof i)throw new Error("EXPECTED_CALLBACK");var l=e.once(e.mkAsync(i));if(t.network)if(t.channel&&"string"==typeof t.channel&&32===t.channel.length)if(t.keys&&"object"==typeof t.keys)if(t.store){var d=e.response((function(e,t){console.error("ROSTER_RESPONSE__"+e,t)})),h=t.store,v=t.keys,m=v.myCurvePublic,g=t.channel,E=t.lastKnownHash||-1;t.newTeam&&(E=void 0);var b={state:{members:{},metadata:{}},internal:{initialized:!1,sinceLastCheckpoint:0,lastCheckpointHash:E}},A={},_={change:e.mkEvent(),checkpoint:e.mkEvent()};A.on=function(e,t){if("object"!=typeof _[e])throw new Error("unsupported event");return _[e].reg(t),A},A.off=function(e,t){if("object"!=typeof _[e])throw new Error("unsupported event");return _[e].unreg(t),A},A.once=function(e,t){if("object"!=typeof _[e])throw new Error("unsupported event");var n=function(){t.apply(null,Array.prototype.slice.call(arguments)),_[e].unreg(n)};return _[e].reg(n),A},A.getState=function(){return e.clone(b.state)},A.getLastCheckpointHash=function(){return b.internal.lastCheckpointHash||-1};var w=function(){b.internal.pendingCheckpointId&&(d.clear(b.internal.pendingCheckpointId),delete b.internal.pendingCheckpointId),clearTimeout(b.internal.checkpointTimeout),delete b.internal.checkpointTimeout};A.stop=function(){b.internal.cpNetflux&&"function"==typeof b.internal.cpNetflux.stop?(b.internal.cpNetflux.stop(),w()):console.log("FAILED TO LEAVE")};var O,D,S,T=!1,C=function(){if(t.onCacheReady){var e=b.state;if(Object.keys(e.members||{}).length)t.onCacheReady(A);else{try{b.internal.cpNetflux.resetCache()}catch(e){console.error(e)}t.onCacheReady({error:"CORRUPTED"})}}},x=function(){T=!0,l(void 0,A)},I=function(e){e&&"EUNKNOWN"===e.type||(T?console.error("CHANNEL_ERROR",e):l(e))},N=function(e){e.state||(T=!1)},P=function(){console.log("ROSTER CONNECTED")},k=function(){return Boolean(T&&m)},R=function(t,n,r,o,a,i){O!==a&&b.internal.sinceLastCheckpoint++,O=a;var s=e.tryParse(t);if(s){var l,f;try{l=p(s,i,b)}catch(e){f=e.message}var h=c(a);if(d.expected(h)){if(f)return void d.handle(h,[f]);try{l?d.handle(h,[void 0,A.getState()]):(d.handle(h,["NO_CHANGE"]),console.log(t))}catch(e){console.log("CAUGHT",e)}}if("CHECKPOINT"===s[0]&&l?(k()&&_.checkpoint.fire(a),b.internal.sinceLastCheckpoint=0,b.internal.lastCheckpointHash=a):l&&k()&&_.change.fire(),w(),k()&&function(e,t){if(!u(e,t.state.members))return!1;var n=t.internal.sinceLastCheckpoint;return!(!n||"number"!=typeof n||n<25)}(m,b)){var y=1e3*Math.floor(20*Math.random())+5e3;b.internal.checkpointTimeout=setTimeout((function(){b.internal.pendingCheckpointId=A.checkpoint((function(e){e&&console.error(e)}))}),y)}}else console.error("could not parse")},M=function(t,n){var r=e.tryParse(t);return"CHECKPOINT"===r[0]&&y(r,n,b)},F=function(e,t){if(k()){var n=h.anon_rpc;if(n){var o=!1;try{o=y(e,v.myCurvePublic,b)}catch(e){return void t(e.message)}if(o){var a=S.encrypt(r(e)),i=c(a);return d.expect(i,(function(e,n){e?t(e):t(void 0,n,i)}),3e4),n.send("WRITE_PRIVATE_MESSAGE",[g,a],(function(e){if(e)return d.handle(i,[e.message||e])})),i}t("NO_CHANGE")}else t("ANON_RPC_NOT_READY")}else t("NOT_READY")};A.init=function(t,n){var r=e.once(e.mkAsync(n));if(b.internal.initialized)r("ALREADY_INITIALIZED");else if(s(t)){var o=e.clone(t);o.role="OWNER";var a={};a[m]=o,F(["CHECKPOINT",{members:a}],r)}else r("INVALID_ARGUMENTS")},A.checkpoint=function(t){var n=e.once(e.mkAsync(t));F(["CHECKPOINT",e.clone(b.state)],n)},A.add=function(t,n){var r=e.once(e.mkAsync(n));if(!b.internal.initialized)return r("UNINITIALIZED");if(s(t)){var o=e.clone(t);Object.keys(o).forEach((function(e){if(!f(e)||s(b.state.members[e]))return delete o[e]})),F(["ADD",o],r)}else r("INVALID_ARGUMENTS")},A.remove=function(t,n){var r=e.once(e.mkAsync(n)),o=b.state;if(!o)return r("UNINITIALIZED");if(Array.isArray(t)){var a=e.clone(t),i=[],s=Object.keys(o.members);a.forEach((function(e){-1!==s.indexOf(e)&&i.push(e)})),F(["RM",i],r)}else r("INVALID_ARGUMENTS")},A.describe=function(t,n){var r=e.once(e.mkAsync(n)),o=b.state;if(!o)return r("UNINITIALIZED");if(s(t)){var a=e.clone(t);Object.keys(a).some((function(e){var t=a[e];if(s(t)||delete a[e],!s(o.members[e]))return!0;Object.keys(t).forEach((function(n){t[n]===o.members[e][n]&&delete t[n]}))}))?r("INVALID_ARGUMENTS"):F(["DESCRIBE",a],r)}else r("INVALID_ARGUMENTS")},A.metadata=function(t,n){var r=e.once(e.mkAsync(n)),o=b.state.metadata;if(s(t)){var a=e.clone(t);Object.keys(a).forEach((function(e){a[e]===o[e]&&delete a[e]})),F(["METADATA",a],r)}else r("INVALID_ARGUMENTS")},A.invite=function(t,n){var r=e.once(e.mkAsync(n));if(!b.state)return r("UNINITIALIZED");if(!b.internal.initialized)return r("UNINITIALIZED");if(s(t)){var o=e.clone(t);Object.keys(o).forEach((function(e){if(!f(e)||s(b.state.members[e]))return delete o[e]})),F(["INVITE",o],r)}else r("INVALID_ARGUMENTS")},A.accept=function(t,n){var r=e.once(e.mkAsync(n));"string"==typeof t&&f(t)?F(["ACCEPT",t],r):r("INVALID_ARGUMENTS")},o((function(e){h.anon_rpc&&h.anon_rpc.send("GET_METADATA",g,(function(t,n){if(t)return e.abort(),void console.error(t);D=b.internal.metadata=n&&n[0]||void 0}))})).nThen((function(e){if(!t.keys.teamEdPublic&&D&&D.validateKey&&(t.keys.teamEdPublic=D.validateKey),!t.keys.teamEdPublic)return e.abort(),void l("NO_VALIDATE_KEY");if(!t.keys.teamKemPublic&&D.kemPublic&&(t.keys.teamKemPublic=D.kemPublic),!t.keys.teamDsaPublic&&D.dsaPublic&&(t.keys.teamDsaPublic=D.dsaPublic),!t.keys.teamKemPublic&&!t.keys.teamDsaPublic)return e.abort(),void l("NO_PQC_KEYS");try{S=a.Team.createEncryptor(t.keys)}catch(t){return e.abort(),void l(t)}})).nThen((function(){"string"==typeof E&&console.log("Synchronizing from checkpoint"),b.internal.cpNetflux=n.start({lastKnownHash:E,network:t.network,channel:t.channel,crypto:S,validateKey:t.keys.teamEdPublic,dsaValidateKey:t.keys.teamDsaPublic,owners:t.owners,Cache:t.Cache,isCacheCheckpoint:M,onCacheReady:C,onChannelError:I,onReady:x,onConnect:P,onConnectionChange:N,onMessage:R,noChainPad:!0})}))}else l("EXPECTED_STORE");else l("EXPECTED_CRYPTO_KEYS");else l("EXPECTED_CHANNEL");else l("EXPECTED_NETWORK")},i}(Ne(),Fe(),O(),Xt(),Dt(),ye()),er}function mr(){if(ar)return or;ar=1;return or=((e,t,n,r,o,a,i,s,c,u,l,f,d,h,p,y,v,m,g)=>{const E={};var b=e.mkEvent(!0),A=function(){},_=function(e,n,r,o){n&&(o||(r.on("change",["drive",a.SHARED_FOLDERS],(function(o,s,c){if(c.length>3&&"password"===c[3]){var u=c[2],l=r.drive[a.SHARED_FOLDERS][u],f=n.manager.user.userObject.getHref?n.manager.user.userObject.getHref(l):l.href,d=t.parsePadUrl(f),h=t.getSecrets(d.type,d.hash,o);return setTimeout((function(){i.updatePassword(e.Store,{oldChannel:h.channel,password:s,href:f},e.store.network,(function(){console.log("Shared folder password changed")}))})),!1}})),r.on("disconnect",(function(){n.offline=!0,n.sendEvent("NETWORK_DISCONNECT",n.id)})),r.on("reconnect",(function(){n.offline=!1,n.sendEvent("NETWORK_RECONNECT",n.id)}))),r.on("change",[],(function(t,r,i){if(o){if(i[0]===a.FILES_DATA&&"object"==typeof r&&r.channel&&!r.owners){var s=[r.channel];r.rtChannel&&s.push(r.rtChannel),r.lastVersion&&s.push(r.lastVersion),n.pin(s,(function(e){e&&e.error&&console.error(e.error)}))}if(i[0]===a.FILES_DATA&&"object"==typeof t&&t.channel&&!r){var c=[t.channel];n.manager.findChannel(t.channel).some((function(e){return e.fId!==o}))||(t.rtChannel&&c.push(t.rtChannel),t.lastVersion&&c.push(t.lastVersion),n.unpin(c,(function(e){e&&e.error&&console.error(e)})))}}t&&!r&&Array.isArray(i)&&(i[0]===a.FILES_DATA||"drive"===i[0]&&i[1]===a.FILES_DATA)&&setTimeout((function(){e.Store.checkDeletedPad(t&&t.channel)})),n.sendEvent("DRIVE_CHANGE",{id:o,old:t,new:r,path:i})})),r.on("remove",[],(function(e,t){n.sendEvent("DRIVE_REMOVE",{id:o,old:e,path:t})})))},w=function(e,t){var n=e.teams[t];if(n){try{n.listmap.stop()}catch(e){}try{n.roster.stop()}catch(e){}n.proxy={},n.stopped=!0,n?.rpc?.destroy(),delete e.teams[t],delete e.cache[t],delete e.store.proxy.teams[t],e.emit("LEAVE_TEAM",t,n.clients),e.updateMetadata(),e.store.calendar&&e.store.calendar.closeTeam(t),e.store.mailbox&&e.store.mailbox.close("team-"+t,(function(){}))}},O=function(e,t,n,r){t.rpc?r():n.edPrivate&&n.edPublic?h.create(e.store.network,n,(function(e,n){e?r(e):(t.rpc=n,t&&t.onRpcReadyEvt&&t.onRpcReadyEvt.fire(),r())}),d):r("EFORBIDDEN")},D=function(n,r,a,s,c,u,l){var f=e.once(e.mkAsync(l));if(n.cache[r])f();else{var d=a.proxy,h={id:r,proxy:d,listmap:a,clients:[],realtime:a.realtime,handleSharedFolder:function(e,t){!function(e,t,n,r){var o=e.teams[t];o&&(r?(o.sharedFolders[n]=r,_(e,o,r.proxy,n)):delete o.sharedFolders[n])}(n,r,e,t)},sharedFolders:{},roster:s,onRpcReadyEvt:e.mkEvent(!0),offline:!0};n.cache[r]=h,u&&h.clients.push(u),s.on("change",(function(){var t=s.getState(),o=e.find(n,["store","proxy","curvePublic"]);if(t.members&&Object.keys(t.members).length)if(t.members[o]){var a=e.find(n,["store","proxy","teams",r]);a&&(a.metadata=t.metadata),n.updateMetadata(),n.emit("ROSTER_CHANGE",r,h.clients)}else w(n,r);else console.error(JSON.stringify(t))})),s.on("checkpoint",(function(t){e.find(n,["store","proxy","teams",r,"keys","roster"]).lastKnownHash=t})),h.sendEvent=function(e,t,r){n.emit(e,t,h.clients.filter((function(e){return e!==r})))},h.getChatData=function(){var e=c.chat||{},n=e.edit||e.view;if(!n)return{};var o=t.getSecrets("chat",n);return{teamId:r,channel:o.channel,secret:o,validateKey:e.validateKey}},h.pin=function(e,t){c.drive.edPrivate?h.rpc?("function"!=typeof t&&console.error("expected a callback"),h.rpc.pin(e,(function(e,n){t(e?{error:e}:{hash:n})}))):t({error:"TEAM_RPC_NOT_READY"}):t({error:"EFORBIDDEN"})},h.unpin=function(e,t){c.drive.edPrivate?h.rpc?("function"!=typeof t&&console.error("expected a callback"),h.rpc.unpin(e,(function(e,n){t(e?{error:e}:{hash:n})}))):t({error:"TEAM_RPC_NOT_READY"}):t({error:"EFORBIDDEN"})};var p=n.store.proxy.teams[h.id],y=p.hash||p.roHash,v=t.getSecrets("team",y,p.password),m=h.manager=o.create(d.drive,{onSync:function(e){n.Store.onSync(r,e)},edPublic:c.drive.edPublic,pin:h.pin,unpin:h.unpin,loadSharedFolder:function(e,t,r,o){i.load({isNew:o,network:n.store.network||n.store.networkPromise,store:h,isNewChannel:n.Store.isNewChannel,Store:n.Store},e,t,r)},settings:{drive:e.find(n.store,["proxy","settings","drive"])},removeOwnedChannel:function(e,t){var o;"object"==typeof e?(e.teamId=r,o=e):o={channel:e,teamId:r},n.Store.pad.destroy("",o,t)},Store:n.Store,store:n.store},{teamId:h.id,outer:!0,edPublic:c.drive.edPublic,loggedIn:!0,log:function(e){h.sendEvent("DRIVE_LOG",e)},rt:h.realtime,editKey:v.keys.secondaryKey,readOnly:Boolean(!v.keys.secondaryKey)});h.secondaryKey=v&&v.keys.secondaryKey,h.userObject=m.user.userObject,g((function(e){n.teams[r]=h,_(n,h,d);var t=n.store.network||n.store.networkPromise;i.loadSharedFolders(n.Store,t,h,h.proxy.drive,h.userObject,e,(function(e){n.progress+=70/(n.numberOfTeams*e.max),n.updateProgress({progress:n.progress})}),!0)})).nThen((function(){n.store.modules.calendar&&n.store.modules.calendar.openTeam(r),f()}))}},S=function(n,r,o,a,s,c,u){var l,f=a.getState(),d=e.find(n,["store","proxy","teams",r]);d&&(d.metadata=f.metadata),delete n.nocache[r],n.store.proxy.teams[r]&&g((function(e){D(n,r,o,a,s,c,e()),l=n.teams[r]||n.cache[r],s.drive.edPrivate&&O(n,l,s.drive,e((function(){})))})).nThen((function(e){l.userObject.fixFiles(),i.checkMigration(l.secondaryKey,l.proxy?.drive,l.userObject,e()),i.loadSharedFolders(n.Store,n.store.network,l,l.proxy?.drive,l.userObject,e,(function(e){n.progress+=70/(n.numberOfTeams*e.max),n.updateProgress({progress:n.progress})}))})).nThen((function(){if(l.rpc){var o=function(t,n){var r=t.teams[n];if(!r)return null;var o=r.manager.getChannelsList("pin"),a=t.store.proxy.teams[n];o.push(`${a.channel}#drive`);var i=e.find(a,["keys","chat","channel"]),s=e.find(a,["keys","roster","channel"]),c=e.find(a,["keys","mailbox","channel"]);if(i&&o.push(i),s&&o.push(s),c&&o.push(c),r.proxy.calendars){var u=Object.keys(r.proxy.calendars).map((function(e){return r.proxy.calendars[e].channel}));o=o.concat(u)}var l=r.roster.getState();return l.members&&Object.keys(l.members).forEach((function(e){var t=l.members[e];t.inviteChannel&&t.pending&&o.push(t.inviteChannel),t.previewChannel&&t.pending&&o.push(t.previewChannel)})),o.sort(),o}(n,r),a=t.hashChannelList(o);l.rpc.getServerHash((function(e,t){e?console.warn(e):t!==a&&l.rpc.reset(o,(function(e){e&&console.warn(e)}))}))}})).nThen((function(){l.offline=!1,n.onReadyHandlers[r]&&n.onReadyHandlers[r].forEach((function(e){("function"==typeof e.cb&&e.cb(),e.cId)&&(-1===l.clients.indexOf(e.cId)&&l.clients.push(e.cId))})),delete n.onReadyHandlers[r],n.store.modules.calendar&&n.store.modules.calendar.openTeam(r),u()}))},T=function(e,t,n,r,o,a){var i=function(){(e.cache[t]||e.teams[t])&&w(e,t),delete e.store.proxy.teams[t],delete e.onReadyHandlers[t],o.abort(),a({error:"ENOENT"})};n&&e.store.anon_rpc.send("IS_NEW_CHANNEL",n,o((function(e,t){t&&t.length&&"object"==typeof t[0]&&t[0].isNew&&i()}))),r&&e.store.anon_rpc.send("IS_NEW_CHANNEL",r,o((function(e,t){t&&t.length&&"object"==typeof t[0]&&t[0].isNew&&i()})))},C=function(n,r,o,a,i){var l=e.once(e.mkAsync(a)),f=r.hash||r.roHash,h=t.getSecrets("team",f,r.password),v=y.createEncryptor(h.keys);r.roHash||(r.roHash=t.getViewHashFromKeys(h));var E,A,_=r.keys;if(!_.chat.validateKey&&_.chat.edit){var O=t.getSecrets("chat",_.chat.edit);_.chat.validateKey=O.keys.validateKey}var C={curvePublic:n.store.proxy.curvePublic,curvePrivate:n.store.proxy.curvePrivate,kemPublic:n.store.proxy.kemPublic,kemPrivate:n.store.proxy.kemPrivate},x=_.roster||{},I=x.edit?y.Team.deriveMemberKeys(x.edit,C):y.Team.deriveGuestKeys(x.view||"");g((function(e){if(i)return d.getChannelCache(h.channel,e((function(t,n){n&&n.c||(e.abort(),l({error:"NOCACHE"}))}))),void d.getChannelCache(I.channel,e((function(t,n){var r=n&&n.c,o=n&&n.k;o&&!I.teamEdPublic&&(I.teamEdPublic=o);var a=n&&n.dsaPublic;a&&!I.teamDsaPublic&&(I.teamDsaPublic=a),r||(e.abort(),l({error:"NOCACHE"}))})));n.Store.onReadyEvt.reg((()=>{T(n,o,h.channel,I.channel,e,l)}))})).nThen((function(t){var a={lm:!1,roster:!1,check:function(){this.lm&&this.roster&&i&&(n.progress+=30/n.numberOfTeams,n.updateProgress({progress:n.progress}),D(n,o,A,E,_,null,t(l)),this.check=function(){})}},u={data:{},readOnly:!Boolean(h.keys.signKey),network:n.store.network||n.store.networkPromise,channel:h.channel,crypto:v,ChainPad:m,Cache:d,metadata:{validateKey:h.keys.validateKey||void 0},userName:"team",classic:!0,onMetadataUpdate:function(){var e=n.teams[o];e&&n.emit("ROSTER_CHANGE",o,e.clients)}};(A=p.create(u)).proxy.on("cacheready",(function(){a.lm=!0,a.check()})),A.proxy.on("ready",t()),A.proxy.on("error",(function(e){e&&void 0!==e.loaded&&!e.loaded&&l({error:"ECONNECT"}),e&&e.error&&"EDELETED"===e.error&&w(n,o)})),s.create({network:n.store.network||n.store.networkPromise,channel:I.channel,keys:I,store:n.store,lastKnownHash:x.lastKnownHash,onCacheReady:function(e){if(i){if(e&&"CORRUPTED"===e.error)return console.error("Corrupted roster cache, cant load this team offline",r),A&&"function"==typeof A.stop&&A.stop(),t.abort(),void l({error:"CACHE_CORRUPTED_ROSTER"});E=e,a.roster=!0,a.check()}},Cache:d},t((function(r,o){if(r)return t.abort(),console.error(r),void l({error:"ROSTER_ERROR"});E=o,x.lastKnownHash=E.getLastCheckpointHash();var a=E.getState(),i=e.find(n,["store","proxy","curvePublic"]);a.members[i]&&b.reg((function(){if(x.edit){var e={},t=c.createData(n.store.proxy,!1);t.pending=!1,e[n.store.proxy.curvePublic]=t,E.describe(e,(function(e){e&&"NO_CHANGE"!==e&&console.error(e)}))}}))})))})).nThen((function(t){var a=E.getState(),i=e.find(n,["store","proxy","curvePublic"]);if(!a.members||!Object.keys(a.members).length)return A.stop(),E.stop(),A.proxy={},l({error:"EINVAL"}),t.abort(),console.error(JSON.stringify(a)),void u.send("ROSTER_CORRUPTED");if(!a.members[i])return A.stop(),E.stop(),A.proxy={},delete n.store.proxy.teams[o],n.updateMetadata(),l({error:"EFORBIDDEN"}),void t.abort();var s=a.members[i],c=e.find(r,["keys","drive","edPrivate"]);if(r.hash&&c||-1===["ADMIN","MEMBER"].indexOf(s.role))r.hash&&c||"OWNER"!==s.role||u.send("TEAM_RIGHTS_OWNER");else{console.warn("Missing edit rights: demote to viewer");var f={};f[n.store.proxy.curvePublic]={role:"VIEWER"},E.describe(f,(function(e){u.send("TEAM_RIGHTS_FIXED"),delete r.hash,delete r.keys.drive.edPrivate,delete r.keys.chat.edit,e&&"NO_CHANGE"!==e&&console.error(e)}))}})).nThen((function(){i||(n.progress+=30/n.numberOfTeams,n.updateProgress({progress:n.progress})),S(n,o,A,E,_,null,l)}))},x=function(t,n,r,o){var a=n.team;if(!((a.hash||a.roHash)&&a.channel&&a.password&&a.keys&&a.metadata))return void o({error:"EINVAL"});let i=t.store.proxy.teams;if(Object.values(i).some((e=>e.channel===a.channel)))o({error:"EEXISTS"});else{var s=e.createRandomInteger();t.store.proxy.teams[s]=a,t.onReadyHandlers[s]=[],C(t,a,s,(function(e){e&&e.error||console.debug("Team joined:"+s);var n=t.store.proxy.teams[s];t.store.mailbox.open("team-"+s,n.keys.mailbox,(function(){}),!0,{owners:n.keys.drive.edPublic}),t.updateMetadata(),o(e)}))}},I=function(t,n,r){var o=e.find(t,["store","proxy","teams",n]);if(!o)return{};var a=e.clone(o);return r||(delete a.hash,delete a.keys.drive.edPrivate,delete a.keys.chat.edit),delete a.owner,a},N=function(n,r,o){if(!r)return!0;var a=e.find(n,["store","proxy","teams",r]);if(!a)return!0;var s=n.teams[r];if(!s)return!0;var c=t.getSecrets("team",o||a.roHash,a.password);if(i.upgrade(a.channel,c),s.userObject&&s.userObject.setReadOnly(!c.keys.secondaryKey,c.keys.secondaryKey),c.keys.secondaryKey)try{n.store.modules.calendar.upgradeTeam(r)}catch(e){console.error(e)}!c.keys.secondaryKey&&s.rpc&&s.rpc.destroy();var u=e.find(s,["proxy","drive","sharedFolders"]);Object.keys(u||{}).forEach((function(n){var r=s.manager.getSharedFolderData(n),o=t.parsePadUrl(r.href||r.roHref),a=t.getSecrets(o.type,o.hash,r.password);i.upgrade(a.channel,a);var c=e.find(s,["manager","folders",n,"userObject"]);c&&c.setReadOnly(!a.keys.secondaryKey,a.keys.secondaryKey)})),n.updateMetadata(),n.emit("ROSTER_CHANGE_RIGHTS",r,s.clients)},P=function(n,r,o,a,i){if(r){var s=e.find(n,["store","proxy","teams",r]);if(s){var c=n.onReadyHandlers[r],u=n.teams[r];if(s.channel===a.channel&&s.password===a.password)if(o?(s.hash=a.hash,s.keys.drive.edPrivate=a.keys.drive.edPrivate,s.keys.chat.edit=a.keys.chat.edit):(delete s.hash,delete s.keys.drive.edPrivate,delete s.keys.chat.edit),u||!Array.isArray(c))if(u){if(o){O(n,u,s.keys.drive,(function(){u.manager.addPin(u.pin,u.unpin)}));var l=t.getSecrets("team",a.hash,s.password);u.secondaryKey=l&&l.keys.secondaryKey;var f=y.createEncryptor(l.keys);u.listmap.setReadOnly(!1,f)}else delete u.secondaryKey,u.rpc&&u.rpc.destroy&&u.rpc.destroy(),u.manager.removePin(),u.listmap.setReadOnly(!0);N(n,r,a.hash),i(!0)}else i(!1);else c.push({cb:function(){P(n,r,o,a,i)}});else i(!1)}else i(!1)}else i(!1)},k=function(t,n,r,o,a){n?e.find(t,["store","proxy","teams",n])&&t.teams[n]?t.store.mailbox.sendTo("TEAM_EDIT_RIGHTS",{state:o,teamData:I(t,n,o)},{channel:r.notifications,curvePublic:r.curvePublic},a):a({error:"ENOENT"}):a({error:"EINVAL"})},R=function(t,n,r,o){var a=n.teamId;if(a){var i=e.find(t,["store","proxy","teams",a]),s=t.teams[a];if(i&&s)if(s.roster)if(n.curvePublic&&n.data){var c,u=s.roster.getState().members[n.curvePublic];g((function(e){t.Store.pad.getMetadata(null,{channel:i.channel},e((function(e){c=e&&e.error?s.listmap.metadata||{}:e})))})).nThen((function(){if(u.pendingOwner=Array.isArray(c.pending_owners)&&-1!==c.pending_owners.indexOf(u.edPublic),"OWNER"!==u.role||"OWNER"===n.data.role){"VIEWER"===u.role&&"VIEWER"!==n.data.role&&k(t,a,u,!0,(function(e){o(e)})),"VIEWER"!==u.role&&"VIEWER"===n.data.role&&k(t,a,u,!1,(function(e){o(e)}));var r={};r[n.curvePublic]=n.data,s.roster.describe(r,(function(e){e?o({error:e}):o()}))}else!function(t,n,r,o){var a=e.once(o);if(n){var i=e.find(t,["store","proxy","teams",n]);if(i){var s=t.teams[n];if(s){var c=r.pendingOwner;g((function(n){var o=c?"RM_PENDING_OWNERS":"RM_OWNERS",s=function(e){var t=e&&e.error;if(t)return console.error(t),n.abort(),void a(t)},u=function(e){t.Store.pad.setMetadata(null,{channel:e,command:o,value:[r.edPublic]},n(s))};u(i.channel),u(e.find(i,["keys","roster","channel"])),u(e.find(i,["keys","chat","channel"]))})).nThen((function(e){var t={};t[r.curvePublic]={role:"ADMIN",pendingOwner:!1},s.roster.describe(t,e((function(e){e&&console.error(e)})))})).nThen((function(e){t.store.mailbox.sendTo("RM_OWNER",{teamChannel:i.channel,title:i.metadata.name,pending:c},{channel:r.notifications,curvePublic:r.curvePublic},e())})).nThen((function(){a()}))}else a({error:"ENOENT"})}else a({error:"ENOENT"})}else a({error:"EINVAL"})}(t,a,u,(function(e){e?(console.error(e),o({error:e})):o()}))}))}else o({error:"MISSING_DATA"});else o({error:"NO_ROSTER"});else o({error:"ENOENT"})}else o({error:"EINVAL"})},M=function(e,t){Object.keys(e.onReadyHandlers).forEach((function(n){var r=-1;e.onReadyHandlers[n].some((function(e,n){if(e.cId===t)return r=n,!0})),-1!==r&&e.onReadyHandlers[n].splice(r,1)})),Object.keys(e.teams).forEach((function(n){var r=e.teams[n].clients,o=r.indexOf(t);-1!==o&&r.splice(o,1)}))},F=function(t,n,r,o){var a,i=n.seeds;try{a=l.derivePreviewKeys(i.preview)}catch(e){return void o({error:"INVALID_SEEDS"})}f.get({channel:a.channel,type:"pad",version:2,keys:{cryptKey:a.cryptKey}},(function(t,n){if(t)o({error:t});else if(n){var r=e.tryParse(n);o(r||{error:"parseError"})}else o({error:"DELETED"})}),{network:t.store.network,initialState:"{}"})},L=function(t,n,r,o){var a,i;g((function(r){!function(t,n,r,o){var a,i=n.bytes64;try{a=l.deriveInviteKeys(i)}catch(e){return void o({error:"INVALID_SEEDS"})}f.get({channel:a.channel,type:"pad",version:2,keys:{cryptKey:a.cryptKey}},(function(t,n){if(t)o({error:t});else if(n){var r=e.tryParse(n);o(r||{error:"parseError"})}else o({error:"DELETED"})}),{network:t.store.network,initialState:"{}"})}(t,n,0,r((function(e){if(e&&e.error)return r.abort(),void o(e);a=e})))})).nThen((function(n){var r=e.find(a,["teamData","channel"]),u=t.store.proxy.teams||{};if(Object.keys(u).some((function(e){return u[e].channel===r})))return n.abort(),void o({error:"ALREADY_MEMBER"});var l=e.find(a,["teamData","keys","roster"]),f=a.ephemeral;if(!l||!f)return n.abort(),void o({error:"INVALID_INVITE_CONTENT"});var h=y.Team.deriveMemberKeys(l.edit,f);s.create({network:t.store.network||t.store.networkPromise,channel:l.channel,keys:h,store:t.store,Cache:d},n((function(e,r){if(e)return n.abort(),console.error(e),void o({error:"ROSTER_ERROR"});var a=c.createData(t.store.proxy,!1),s=r.getState();i=s.members[f.curvePublic],r.accept(a.curvePublic,n((function(e){if(r.stop(),e)return n.abort(),console.error(e),void o({error:"ACCEPT_ERROR"})})))})))})).nThen((function(){var e={};i.remaining&&1!==i.remaining||O(t,e,a.ephemeral,(function(t){if(!t){var n=e.rpc;i.inviteChannel&&n.removeOwnedChannel(i.inviteChannel,(function(e){e&&console.error(e)})),i.previewChannel&&n.removeOwnedChannel(i.previewChannel,(function(e){e&&console.error(e)}))}})),x(t,{team:a.teamData},0,o)}))},H=function(t){if(t){if(t.keys&&t.keys.mailbox)return t.keys.mailbox;var n=e.find(t,["keys","roster","edit"]);if(n){var r=y.CryptoAgility.createHash(e.decodeUTF8(n)),o=r.slice(0,32),a=e.uint8ArrayToHex(r.slice(32,48)),i=y.CryptoAgility.boxKeyPairFromSecretKey(o);return{channel:a,viewed:[],keys:{curvePrivate:e.encodeBase64(i.secretKey),curvePublic:e.encodeBase64(i.publicKey)}}}}};return E.init=function(n,r,o){var a={},i=n.store;if(i.loggedIn&&i.proxy.edPublic&&!i.modules?.team){var h={store:i,Store:n.Store,pinPads:n.pinPads,emit:o,onReadyHandlers:{},teams:{},cache:{},nocache:{},updateMetadata:n.updateMetadata,updateProgress:n.updateLoadingProgress,progress:0};i.proxy.teams||(i.proxy.teams={});var E=i.proxy.teams;h.numberOfTeams=Object.keys(E).length,h.store.proxy.on("change",["teams"],(function(e,t,n){"hash"===n[2]&&N(h,n[1],t)})),h.store.proxy.on("remove",["teams"],(function(e,t){"hash"===t[2]&&N(h,t[1])}));var _=function(t,n){if(!t||!n)return!0;try{var r=e.decodeBase64(t),o=y.CryptoAgility.signKeyPairFromSecretKey(r);return e.encodeBase64(o.publicKey)===n}catch(e){return!1}};Object.keys(E).forEach((function(t){h.onReadyHandlers[t]=[],e.find(E,[t,"keys","mailbox"])||(E[t].keys.mailbox=H(E[t])),C(h,E[t],t,r((function(e){if(e){delete h.onReadyHandlers[t],delete h.cache[t],"NOCACHE"===e?.error&&(h.nocache[t]=!0);var n="string"==typeof e?e:e.type||e.message;return u.send("TEAM_LOADING_ERROR="+n),void console.error(e)}console.debug("Team "+t+" cache ready")})),d.isEnabled())})),a.onReady=function(n){var r;r={},Object.keys(E).forEach((function(n){try{var o=E[n],a=r[o.channel],i=e.find(o,["keys","drive","edPrivate"]),s=e.find(o,["keys","drive","edPublic"]);if(s?i&&s&&!_(i,s)&&(u.send("TEAM_CORRUPTED_EDPRIVATE"),delete E[n].keys.drive.edPrivate,i=void 0):u.send("TEAM_CORRUPTED_EDPUBLIC"),o.hash&&2===t.parseTypeHash("drive",o.hash).version&&40!==o.hash.length&&u.send("TEAM_CORRUPTED_HASH"),!a)return void(r[o.channel]=n);var c=E[a],l=e.find(c,["keys","drive","edPrivate"]),f=e.find(c,["keys","chat","edit"]),d=e.find(o,["keys","chat","edit"]);!c.hash&&o.hash&&(c.hash=o.hash),!l&&i&&(c.keys.drive.edPrivate=i),!f&&d&&(c.keys.chat.edit=d),h.store.proxy.duplicateTeams=h.store.proxy.duplicateTeams||{},h.store.proxy.duplicateTeams[n]=E[n],delete E[n]}catch(e){console.error(e)}}));var o=function(e){return!E[e]&&(w(h,e),delete h.onReadyHandlers[e],!0)};Object.keys(h.teams).forEach(o),Object.keys(h.onReadyHandlers).forEach((function(t){if(!o(t)){var r=h.store.proxy.teams[t],a=e.find(r,["keys","roster","channel"]),i=e.once(e.mkAsync(n()));g((function(e){T(h,t,r.channel,a,e,i)})),h.onReadyHandlers[t].push({cb:i})}})),Object.keys(E).forEach((function(t){h.onReadyHandlers[t]||h.teams[t]||(h.onReadyHandlers[t]=[],e.find(E,[t,"keys","mailbox"])||(E[t].keys.mailbox=H(E[t])),C(h,E[t],t,n((function(e){if(e){var n="string"==typeof e?e:e.type||e.message;return u.send("TEAM_LOADING_ERROR="+n),void console.error(e)}console.debug("Team "+t+" ready")}))))})),A(),b.fire()},a.getTeam=function(e){return h.teams[e]},a.getTeamsData=function(t){var n={},r=!1;return-1!==["drive","teams","settings"].indexOf(t)&&(r=!0),Object.keys(E).forEach((function(t){if(h.teams[t]){var o=h.teams[t].proxy||{},a=o.drive&&Object.keys(o.drive.filesData||{}).length,i=o.drive&&Object.keys(o.drive.sharedFolders||{}).length;n[t]={owner:E[t].owner,name:E[t].metadata.name,channel:E[t].channel,numberPads:a,numberSf:i,roster:e.find(E[t],["keys","roster","channel"]),edPublic:e.find(E[t],["keys","drive","edPublic"]),avatar:e.find(E[t],["metadata","avatar"]),viewer:!e.find(E[t],["keys","drive","edPrivate"]),notifications:e.find(E[t],["keys","mailbox","channel"]),curvePublic:e.find(E[t],["keys","mailbox","keys","curvePublic"]),validKeys:_(e.find(E[t],["keys","drive","edPrivate"]),e.find(E[t],["keys","drive","edPublic"]))},r&&h.teams[t]&&(n[t].secondaryKey=h.teams[t].secondaryKey),h.teams[t]&&(n[t].hasSecondaryKey=Boolean(h.teams[t].secondaryKey))}})),n},a.getTeams=function(){return Object.keys(h.teams)};a.removeFromTeam=function(e,t,n){if(E[e]&&(!n||function(e,t){var n=h.teams[e];if(n){var r=n.roster&&n.roster.getState();if(r.members)return(r.members[t]||{}).pending}}(e,t)))if(h.onReadyHandlers[e])h.onReadyHandlers[e].push({cb:function(){h.teams[e].roster.remove([t],(function(e){e&&"NO_CHANGE"!==e&&console.error(e)}))}});else{var r=h.teams[e];r?r.roster.remove([t],(function(e){e&&"NO_CHANGE"!==e&&console.error(e)})):console.error("TEAM MODULE ERROR")}},a.changeMyRights=function(e,t,n,r){P(h,e,t,n,r)},a.updateMyData=function(e){Object.keys(h.teams).forEach((function(t){var n=h.teams[t];if(n.roster){var r={};r[e.curvePublic]=e,n.roster.describe(r,(function(e){e&&console.error(e)}))}}))},a.removeClient=function(e){M(h,e)};return a.execCommand=function(n,r,o){var a=r.cmd,i=r.data;if("SUBSCRIBE"!==a)if("LIST_TEAMS"!==a)if("OPEN_TEAM_CHAT"!==a)if("GET_TEAM_ROSTER"!==a)if("GET_TEAM_METADATA"!==a)if("SET_TEAM_METADATA"!==a){if("OFFER_OWNERSHIP"===a)return h.store.offline?void o({error:"OFFLINE"}):void function(t,n,r,o){var a=e.once(o),i=n.teamId;if(i){var s=e.find(t,["store","proxy","teams",i]);if(s){var c=t.teams[i];if(c)if(c.roster)if(n.curvePublic){var u=c.roster.getState().members[n.curvePublic];g((function(n){var r=function(e){var t=e&&e.error;if(t)return console.error(t),n.abort(),void a({error:t})},o=function(e){t.Store.pad.setMetadata(null,{channel:e,command:"ADD_PENDING_OWNERS",value:[u.edPublic]},n(r))};o(s.channel),o(e.find(s,["keys","roster","channel"])),o(e.find(s,["keys","chat","channel"]))})).nThen((function(e){var t={};t[u.curvePublic]={role:"OWNER"},c.roster.describe(t,e((function(e){e&&console.error(e)})))})).nThen((function(n){t.store.mailbox.sendTo("ADD_OWNER",{teamChannel:s.channel,chatChannel:e.find(s,["keys","chat","channel"]),rosterChannel:e.find(s,["keys","roster","channel"]),title:s.metadata.name},{channel:u.notifications,curvePublic:u.curvePublic},n())})).nThen((function(){a()}))}else a({error:"MISSING_DATA"});else a({error:"NO_ROSTER"});else a({error:"ENOENT"})}else a({error:"ENOENT"})}else a({error:"EINVAL"})}(h,i,0,o);if("ANSWER_OWNERSHIP"===a)return h.store.offline?void o({error:"OFFLINE"}):void function(t,n,r,o){var a,i=t.store.proxy.teams;if(Object.keys(i).forEach((function(e){if(i[e].channel===n.teamChannel)return a=e,!0})),a){var s=e.find(t,["store","proxy","teams",a]);if(s){var c=t.teams[a];if(c)if(c.roster){var u={};n.answer?s.owner=!0:(u[t.store.proxy.curvePublic]={role:"ADMIN"},c.roster.describe(u,(function(e){e?o({error:e}):o()})))}else o({error:"NO_ROSTER"});else o({error:"ENOENT"})}else o({error:"ENOENT"})}else o({error:"EINVAL"})}(h,i,0,o);if("DESCRIBE_USER"!==a){if("INVITE_TO_TEAM"===a)return h.store.offline?void o({error:"OFFLINE"}):void function(e,t,n,r){var o=t.teamId;if(o){var a=e.teams[o];if(a)if(a.roster){var i=t.user;if(i&&i.curvePublic&&i.notifications){delete i.channel,delete i.lastKnownHash,i.pending=!0;var s={};s[i.curvePublic]=i,s[i.curvePublic].role="VIEWER",a.roster.add(s,(function(t){t&&"NO_CHANGE"!==t?r({error:t}):e.store.mailbox.sendTo("INVITE_TO_TEAM",{team:I(e,o)},{channel:i.notifications,curvePublic:i.curvePublic},(function(e){r(e)}))}))}else r({error:"MISSING_DATA"})}else r({error:"NO_ROSTER"});else r({error:"ENOENT"})}else r({error:"EINVAL"})}(h,i,0,o);if("LEAVE_TEAM"!==a){if("JOIN_TEAM"===a)return h.store.offline?void o({error:"OFFLINE"}):void x(h,i,0,o);if("REMOVE_USER"!==a){if("DELETE_TEAM"===a)return h.store.offline?void o({error:"OFFLINE"}):void function(t,n,r,o){var a=n.teamId;if(a){var i=t.teams[a],s=e.find(t,["store","proxy","teams",a]);if(i&&s){var c=i.roster.getState(),l=e.find(t,["store","proxy","curvePublic"]),f=c.members[l];if(!f||"OWNER"!==f.role)return o({error:"EFORBIDDEN"});var d=e.find(t,["store","proxy","edPublic"]),h=e.find(s,["keys","drive","edPublic"]);g((function(e){t.Store.anonRpcMsg(null,{msg:"GET_METADATA",data:s.channel},e((function(t){if(t&&t.error)return e.abort(),o({error:t.error});var n=t[0];n&&Array.isArray(n.owners)&&-1!==n.owners.indexOf(d)||(e.abort(),o({error:"EFORBIDDEN"}))})))})).nThen((function(n){i.proxy.delete=!0;var r=i.manager.getChannelsList("owned"),o=e.Saferphore.create(10);r.forEach((function(e){var r=n();o.take((function(n){var o=!1;g((function(r){32===e.length&&t.Store.anonRpcMsg(null,{msg:"GET_METADATA",data:e},r((function(e){if(e&&e.error)return n(),void r.abort();var t=e[0];if(!t||!Array.isArray(t.owners)||-1===t.owners.indexOf(h))return n(),void r.abort();o=t.owners.some((function(e){return e!==h}))})))})).nThen((function(n){o?t.Store.pad.setMetadata(null,{channel:e,command:"RM_OWNERS",value:[h]},n()):i.rpc.removeOwnedChannel(e,n((function(e){e&&console.error(e)})))})).nThen((function(){n(),r()}))}))}))})).nThen((function(n){i.rpc.removePins(n((function(e){e&&console.error(e)})));var r=e.find(s,["keys","mailbox","channel"]);i.rpc.removeOwnedChannel(r,n((function(e){e&&console.error(e)})));var o=e.find(s,["keys","roster","channel"]);t.store.rpc.removeOwnedChannel(o,n((function(e){e&&console.error(e)})));var a=e.find(s,["keys","chat","channel"]);t.store.rpc.removeOwnedChannel(a,n((function(e){e&&console.error(e)}))),t.store.rpc.removeOwnedChannel(s.channel,n((function(e){e&&console.error(e)})))})).nThen((function(){u.send("TEAM_DELETION"),w(t,a),o()}))}else o({error:"ENOENT"})}else o({error:"EINVAL"})}(h,i,0,o);if("CREATE_TEAM"===a)return h.store.offline?void o({error:"OFFLINE"}):void function(n,r,o,a){var i,l=e.once(a),f=t.createChannelId(),h=t.createRandomHash("team",f),E=t.getSecrets("team",h,f),b=t.getViewHashFromKeys(E),A=y.CryptoAgility.signKeyPair(),_=y.CryptoAgility.curveKeyPair(),O=y.CryptoAgility.generateKemKeypair(),D=y.CryptoAgility.generateKemKeypair(),T=y.Team.createSeed(),C=y.Team.deriveMemberKeys(T,{curvePublic:n.store.proxy.curvePublic,curvePrivate:n.store.proxy.curvePrivate,kemPublic:n.store.proxy.kemPublic,kemPrivate:n.store.proxy.kemPrivate}),x=t.getSecrets("chat"),I=t.getHashes(x),N={network:n.store.network,channel:E.channel,data:{},validateKey:E.keys.validateKey,crypto:y.createEncryptor(E.keys),logLevel:1,classic:!0,ChainPad:m,Cache:d,owners:[n.store.proxy.edPublic]};g((function(e){s.create({network:n.store.network||n.store.networkPromise,channel:C.channel,owners:[n.store.proxy.edPublic],keys:C,store:n.store,lastKnownHash:void 0,newTeam:!0,Cache:d},e((function(t,r){if(t)return e.abort(),void l({error:"ROSTER_ERROR"});i=r;var o=c.createData(n.store.proxy);delete o.channel,i.init(o,e((function(t){if(t)return e.abort(),void l({error:"ROSTER_INIT_ERROR"})})))})));var t,r=y.createEncryptor(x.keys),o={network:n.store.network,channel:x.channel,noChainPad:!0,crypto:r,metadata:{validateKey:x.keys.validateKey,owners:[n.store.proxy.edPublic]}},a=e();o.onReady=function(){t&&t.stop(),a()},o.onError=function(){e.abort(),l({error:"CHAT_INIT_ERROR"})},t=v.start(o)})).nThen((function(e){i.metadata({name:r.name},e((function(t){if(t)return e.abort(),void l({error:"ROSTER_INIT_ERROR"})})))})).nThen((function(){var a=e.createRandomInteger();N.onMetadataUpdate=function(){var e=n.teams[a];e&&n.emit("ROSTER_CHANGE",a,e.clients)};var s=p.create(N),c=s.proxy;c.version=2,c.on("ready",(function(){var d={mailbox:{channel:t.createChannelId(),viewed:[],keys:{curvePrivate:e.encodeBase64(_.secretKey),curvePublic:e.encodeBase64(_.publicKey),kemPrivate:e.encodeBase64(O.secretKey),kemPublic:e.encodeBase64(O.publicKey)}},drive:{edPrivate:e.encodeBase64(A.secretKey),edPublic:e.encodeBase64(A.publicKey),dsaPrivate:e.encodeBase64(D.secretKey),dsaPublic:e.encodeBase64(D.publicKey)},chat:{edit:I.editHash,view:I.viewHash,validateKey:x.keys.validateKey,channel:x.channel},roster:{channel:C.channel,edit:T,view:C.viewKeyStr}},p=n.store.proxy.teams[a]={owner:!0,channel:E.channel,hash:h,roHash:b,password:f,keys:d,metadata:{name:r.name}};c.drive={},S(n,a,s,i,d,o,(function(){u.send("TEAM_CREATION"),n.store.mailbox.open("team-"+a,p.keys.mailbox,(function(){}),!0,{owners:p.keys.drive.edPublic}),n.updateMetadata(),l()}))})).on("error",(function(e){e&&void 0!==e.loaded&&!e.loaded&&l({error:"ECONNECT"}),e&&"EDELETED"===e.error&&w(n,a)}))}))}(h,i,n,o);if("GET_EDITABLE_FOLDERS"!==a)if("CREATE_INVITE_LINK"!==a){if("GET_PREVIEW_CONTENT"!==a)return"ACCEPT_LINK_INVITATION"===a?h.store.offline?void o({error:"OFFLINE"}):void L(h,i,0,o):void 0;F(h,i,0,o)}else!function(t,n,r,o){var a=e.mkAsync(e.once(o)),i=n.teamId,s=t.teams[n.teamId],u=n.seeds,d=n.bytes64;if(i&&s){var h,p=s.roster;try{h=p.getState().metadata.name}catch(e){return void a({error:"TEAM_NAME_ERR"})}var y=n.message,v=n.name,m=n.hash,E=e.find(t,["store","proxy","teams",i]);try{var b=l.encryptHash(m,E.hash)}catch(e){console.error(e)}var A=l.derivePreviewKeys(u.preview),_=l.deriveInviteKeys(d),w=l.generateKeys(),O=n.role||"VIEWER",D=n.uses||1;g((function(e){!function(){var n=l.generateSignPair(),r={initialState:"{}",network:t.store.network,metadata:{owners:[t.store.proxy.edPublic,w.edPublic]}};r.metadata.validateKey=n.validateKey;var o={teamName:h,message:y,author:c.createData(t.store.proxy,!1),displayName:v},i={channel:A.channel,type:"pad",version:2,keys:{cryptKey:A.cryptKey,validateKey:n.validateKey,signKey:n.signKey}};f.put(i,JSON.stringify(o),e((function(t){if(t)return console.error("CRYPTPUT_ERR",t),e.abort(),void a({error:"SET_PREVIEW_CONTENT"})})),r)}(),function(){var n=l.generateSignPair(),r={initialState:"{}",network:t.store.network,metadata:{owners:[t.store.proxy.edPublic,w.edPublic]}};r.metadata.validateKey=n.validateKey;var o={teamData:I(t,i,"MEMBER"===O),ephemeral:{edPublic:w.edPublic,edPrivate:w.edPrivate,curvePublic:w.curvePublic,curvePrivate:w.curvePrivate,kemPublic:w.kemPublic,kemPrivate:w.kemPrivate,dsaPublic:w.dsaPublic,dsaPrivate:w.dsaPrivate}},s={channel:_.channel,type:"pad",version:2,keys:{cryptKey:_.cryptKey,validateKey:n.validateKey,signKey:n.signKey}};f.put(s,JSON.stringify(o),e((function(t){if(t)return console.error("CRYPTPUT_ERR",t),e.abort(),void a({error:"SET_PREVIEW_CONTENT"})})),r)}()})).nThen((function(e){s.pin([_.channel,A.channel],(function(e){e&&e.error&&console.error(e.error)})),l.createRosterEntry(s.roster,{curvePublic:w.curvePublic,content:{curvePublic:w.curvePublic,displayName:n.name,pending:!0,remaining:D,totalUses:D,role:O,hash:b,inviteChannel:_.channel,previewChannel:A.channel}},e((function(t){t&&(e.abort(),a(t))})))})).nThen((function(){a()}))}else a({error:"EINVAL"})}(h,i,0,o);else!function(t,n,r,o){var a=n.teamId;if(a){var i=t.teams[a];if(i){var s=i.manager.folders||{};o(Object.keys(s).filter((function(e){return!s[e].proxy.version})).map((function(t){var n=e.find(i,["user","userObject"]);return{name:e.find(s,[t,"proxy","metadata","title"]),path:n?n.findFile(t)[0]:[]}})))}else o({error:"ENOENT"})}else o({error:"EINVAL"})}(h,i,0,o)}else!function(e,t,n,r){var o=t.teamId;if(o){var a=e.teams[o];if(a)if(a.roster)if(t.curvePublic){var i=a.roster.getState().members[t.curvePublic];a.roster.remove([t.curvePublic],(function(n){if(!n)return i&&i.notifications?void e.store.mailbox.sendTo("KICKED_FROM_TEAM",{pending:t.pending,teamChannel:I(e,o).channel,teamName:I(e,o).metadata.name},{channel:i.notifications,curvePublic:i.curvePublic},(function(e){r(e)})):r();r({error:n})}))}else r({error:"MISSING_DATA"});else r({error:"NO_ROSTER"});else r({error:"ENOENT"})}else r({error:"EINVAL"})}(h,i,0,o)}else!function(e,t,n,r){var o=t.teamId;if(o){var a=e.teams[o];if(a)if(a.roster){var i=e.store.proxy.curvePublic;a.roster.remove([i],(function(t){t?r({error:t}):(w(e,o),r())}))}else r({error:"NO_ROSTER"});else r({error:"ENOENT"})}else r({error:"EINVAL"})}(h,i,0,o)}else R(h,i,0,o)}else!function(e,t,n,r){var o=t.teamId;if(o){var a=e.teams[o];a?a.offline?r({error:"OFFLINE"}):a.roster?(t.metadata&&delete t.metadata.offline,a.roster.metadata(t.metadata,(function(n){if(n)r({error:n});else{var a=e.store.proxy.teams[o];a&&(a.metadata=t.metadata),r()}}))):r({error:"NO_ROSTER"}):r({error:"ENOENT"})}else r({error:"EINVAL"})}(h,i,0,o);else!function(e,t,n,r){var o=t.teamId;if(o){var a=e.teams[o];if(a)if(a.roster){var i=(a.roster.getState()||{}).metadata||{};i.offline=a.offline,r(i)}else r({error:"NO_ROSTER"});else r({error:"ENOENT"})}else r({error:"EINVAL"})}(h,i,0,o);else!function(t,n,r,o){var a=n.teamId;if(a){var i=e.find(t,["store","proxy","teams",a]);if(i){var s=t.teams[a];if(s)if(s.roster){var c,u=(s.roster.getState()||{}).members||{};g((function(e){t.Store.pad.getMetadata(null,{channel:i.channel},e((function(e){c=e&&e.error?s.listmap.metadata||{}:e})))})).nThen((function(){if(t.pending_owners=c.pending_owners,Array.isArray(c.pending_owners)&&c.pending_owners.forEach((function(n){var r;if(Object.keys(u).some((function(e){if(u[e].edPublic===n)return r=u[e],!0})),!r&&i.owner){var o=function(e){t.Store.pad.setMetadata(null,{channel:e,command:"RM_PENDING_OWNERS",value:[n]},(function(){}))};return o(i.channel),o(e.find(i,["keys","roster","channel"])),void o(e.find(i,["keys","chat","channel"]))}r.pendingOwner=!0})),t.store.messenger){var n=s.getChatData();(t.store.messenger.getOnlineList(n.channel)||[]).forEach((function(e){u[e]&&(u[e].online=!0)}))}Object.keys(u).forEach((function(e){var t=u[e];if(t.inviteChannel&&t.hash)if(i.hash)try{t.hash=l.decryptHash(t.hash,i.hash)}catch(e){console.error(e)}else delete t.hash})),o(u)}))}else o({error:"NO_ROSTER"});else o({error:"ENOENT"})}else o({error:"ENOENT"})}else o({error:"EINVAL"})}(h,i,0,o);else!function(e,t,n,r){var o=e.teams[t.teamId];if(o){var a=function(){e.emit("ROSTER_CHANGE",t.teamId,o.clients)};e.store.messenger?e.store.messenger.openTeamChat(o.getChatData(),a,n,r):A=function(){e.store.messenger.openTeamChat(o.getChatData(),a,n,r)}}else r({error:"ENOENT"})}(h,i,n,o);else!function(t){var n=e.clone(E);Object.keys(n).forEach((function(e){h.teams[e]?n[e].offline=h.teams[e].offline:(n[e].error=!0,h.nocache[e]&&(n[e].offline=!0))})),t(n)}(o);else!function(e,t,n,r){M(e,n);try{e.store.messenger.removeClient(n)}catch(e){}if(A=function(){},t)if(!e.onReadyHandlers[t]||e.teams[t])if(e.teams[t]){var o=e.teams[t].clients;-1===o.indexOf(n)&&o.push(n),r()}else r({error:"EINVAL"});else-1===e.onReadyHandlers[t].indexOf(n)&&e.onReadyHandlers[t].push({cId:n,cb:r});else r()}(h,i,n,o)},a}},E.anonGetPreviewContent=function(e,t,n){F(e,t,0,n)},E})(Ne(),Fe(),Oe(),mt(),Tt(),Et(),St(),vr(),Zt(),nt(),(rr||(rr=1,nr=function(e,t,n,r){var o={},a=e.encodeBase64,i=e.decodeBase64;o.generateKeys=function(){var e=r.CryptoAgility.signKeyPair(),t=r.CryptoAgility.curveKeyPair(),n=r.CryptoAgility.generateKemKeypair(),o=r.CryptoAgility.generateDsaKeypair();return{edPublic:a(e.publicKey),edPrivate:a(e.secretKey),curvePublic:a(t.publicKey),curvePrivate:a(t.secretKey),kemPublic:a(n.publicKey),kemPrivate:a(n.secretKey),dsaPublic:a(o.publicKey),dsaPrivate:a(o.secretKey)}},o.generateSignPair=function(){var e=r.CryptoAgility.signKeyPair(),t=r.CryptoAgility.generateKemKeypair();return{validateKey:a(e.publicKey),signKey:a(e.secretKey),dsaPublic:a(t.publicKey),dsaPrivate:a(t.secretKey)}};var s=function(n){var o=t.dispenser(i(n));return{channel:e.uint8ArrayToHex(o(16)),cryptKey:o(r.CryptoAgility.secretboxKeyLength())}};o.deriveInviteKeys=s,o.derivePreviewKeys=s,o.createRosterEntry=function(e,t,n){var r={};r[t.curvePublic]=t.content,e.invite(r,n)};var c=e.decodeUTF8;return o.encryptHash=function(e,t){var n=c(t),o=r.CryptoAgility.createHash(n).subarray(0,32);return r.encrypt(e,o)},o.decryptHash=function(e,t){var n=c(t),o=r.CryptoAgility.createHash(n).subarray(0,32);return r.decrypt(e,o)},o}(Ne(),st(),h(),ye())),nr),cn(),Ge(),sn(),S(),ye(),O(),I(),Dt(),h()),or}function gr(){if(sr)return ir;sr=1;return ir=((e,t,n,r,o,a,i,s)=>{var c=e.Curve;const u={};let l={};u.setCustomize=e=>{l=e.Messages};var f="MSG",d="UNFRIEND",h="MAP_ID",p="MAP_ID_ACK",y=function(e){return JSON.parse(JSON.stringify(e))},v=function(e){for(var t=Object.keys(e).length,n=new Uint8Array(t),r=0;r<t;r++)n[r]=e[r];return n},m=o.createData,g=function(e,t){if(t===e.curvePublic){var n=m(e);return delete n.channel,n}return e.friends?e.friends[t]:void 0},E=u.getFriendList=function(e){return e.friends||(e.friends={}),e.friends},b=function(e,t){return e.messages.some((function(e){return e.sig===t}))},A=function(e,t){var n,r=e.store.proxy,o=E(r);for(var a in o)if(o[a].channel===t){n=o[a];break}return n},_=function(e,t,n,r){e.range_requests||(e.range_requests={}),e.range_requests[t]={messages:[],cb:r,chanId:n}},w=function(e,t){delete e.range_requests[t]},O=function(e,t,r,o){var a=e.store.network;if(console.log("Fetching [%s] messages since [%s]",t.id,r.lastKnownHash||""),t.isPadChat||t.isTeamChat){var i=n.uid();_(e,i,t.id,void 0);var s=["GET_HISTORY_RANGE",t.id,{count:10,txid:i}];a.sendto(a.historyKeeper,JSON.stringify(s)).then((function(){}),(function(e){console.error(e)}))}else{var c=e.store.proxy,u=A(e,t.id)||{},l={metadata:{validateKey:o?o.validateKey:void 0,owners:[c.edPublic,u.edPublic]},lastKnownHash:r.lastKnownHash},f=["GET_HISTORY",t.id,l];a.sendto(a.historyKeeper,JSON.stringify(f)).then((function(){}),(function(e){console.error(e)}))}},D=function(e,t,n,r){var o=e.channels[t];if(o.isFriendChat){var a=A(e,t);if(!a)return void r({error:"NO_SUCH_FRIEND"});a.lastKnownHash=n}else if(o.isPadChat);else if(!o.isTeamChat)return void r({error:"NOT_IMPLEMENTED"});r()},S=function(e,t){var n=e.channels[t];n&&(n.ready=!0,n.onReady.fire())},T=function(e,t,n){var o=e.store.proxy.friends;o&&(delete o[t],r.whenRealtimeSyncs(e.store.realtime,(function(){e.updateMetadata(),n()})))},C=function(e,t,n){var r=n.slice(0,64);if(!b(t,r)){var o,a=t.decrypt(n),i=JSON.parse(a);if(i[0]===f){var s={type:i[0],sig:r,author:i[1],time:i[2],text:i[3],channel:t.id,name:i[4]};return t.messages.push(s),t.ready&&e.emit("MESSAGE",s,t.clients),!0}var c=e.store.proxy;if(i[0]!==d);else{if((o=i[1])===c.curvePublic)return;T(e,o,(function(){t.wc.leave(d);var n=e.store.network;t.onReconnect&&n.off("reconnect",t.onReconnect),delete e.channels[t.id],e.emit("UNFRIEND",{curvePublic:o,fromMe:!1},t.clients)}))}}},x=function(e,t,r){if(r===e.store.network.historyKeeper){var o,a=JSON.parse(t);if(!a.validateKey&&!a.owners||!a.channel)if(/HISTORY_RANGE/.test(a[0])){var i=a[1],s=function(e,t){return e.range_requests[t]}(e,i),c=a[0];if(!s)return;if(!(o=e.channels[s.chanId]))return;if(!s.cb){if("HISTORY_RANGE"===c){if(!Array.isArray(a[2]))return;C(e,o,a[2][4])}else if("HISTORY_RANGE_END"===c)return S(e,s.chanId),w(e,i);return}if("HISTORY_RANGE"===c)s.messages.push(a[2]);else{if("HISTORY_RANGE_END"===c){var u=s.messages.map((function(e){if("MSG"===e[2])try{return{d:JSON.parse(o.decrypt(e[4])),sig:e[4].slice(0,64)}}catch(e){return void console.log("failed to decrypt")}})).filter((function(e){if(e&&e.d&&e.d[0]===f&&!b(o,e.sig))return e})).map((function(e){return{type:e.d[0],sig:e.sig,author:e.d[1],time:e.d[2],text:e.d[3],channel:s.chanId,name:e.d[4]}}));return function(e,t){var n=e.messages;t.reverse().forEach((function(e){n.unshift(e)}))}(o,u),s.cb(u),w(e,i)}console.log(a)}}else{if(a.channel&&e.channels[a.channel]){if(o=e.channels[a.channel],"ECLEARED"===a.error)return D(e,a.channel,"",(function(){})),o.messages=[],void e.emit("CLEAR_CHANNEL",a.channel,o.clients);if(a.error&&("EINVAL"===a.error||"EUNKNOWN"===a.error))return void D(e,a.channel,"",(function(){O(e,o,{},{})}));if(a.state&&1===a.state&&a.channel)return void S(e,a.channel)}(o=e.channels[a[3]])&&C(e,o,a[4])}}else!function(e,t,r){var o,a;try{if(a=JSON.parse(t),!(o=e.channels[a.channel])||-1===o.wc.members.indexOf(r))return}catch(e){return void console.error(e,t)}var i=o.decrypt(a.msg);if(i){var s=n.tryParse(i);if(s){if((s[0]===h||s[0]===p)&&s[2]===r&&s[1]&&(o.mapId[r]=s[1],e.emit("JOIN",{info:s[1],id:o.id},o.clients),!o.readOnly&&s[0]===h)){var c=e.store.proxy||{},u=m(c);delete u.channel;var l=[p,u,o.wc.myID],f=JSON.stringify(l),d=o.encrypt(f),y={channel:o.id,msg:d};e.store.network.sendto(r,JSON.stringify(y))}}else console.error(i)}else console.error("Failed to decrypt message")}(e,t,r)},I=function(e,t,n){var r=e.channels[n];if(r){r.wc&&r.wc.leave(d);var o=e.store.network;r.onReconnect&&o.off("reconnect",r.onReconnect),delete e.channels[r.id],e.emit("UNFRIEND",{curvePublic:t,fromMe:!0},e.friendsClients)}},N=function(e){var t=[];return Array.prototype.push.apply(t,e.friendsClients),Object.keys(e.channels).forEach((function(n){Array.prototype.push.apply(t,e.channels[n].clients)})),n.deduplicateString(t)},P=function(e,t){var r=e.store.proxy,o=e.store.network,a=o.historyKeeper,i=t.keys,s=t.encryptor||c.createEncryptor(i),u={id:t.channel,isFriendChat:t.isFriendChat,isPadChat:t.isPadChat,isTeamChat:t.isTeamChat,padChan:t.padChan,readOnly:t.readOnly,ready:!1,onReady:n.mkEvent(!0),sending:!1,messages:[],clients:t.clients||[],onUserlistUpdate:t.onUserlistUpdate||function(){},mapId:{}};t.onReady&&u.onReady.reg(t.onReady),u.encrypt=function(e){if(!u.readOnly)return s.encrypt(e)},u.decrypt=t.decrypt||function(e){return s.decrypt(e)};var l=function(e){if(e!==a&&!u.readOnly&&!u.isPadChat){var t=m(r);delete t.channel;var n=[h,t,u.wc.myID],i=JSON.stringify(n),s=u.encrypt(i),c={channel:u.id,msg:s};o.sendto(e,JSON.stringify(c))}},f=function(t){if(t!==a){var n=u.mapId[t];n&&(u.wc.members.some((function(e){return u.mapId[e]&&u.mapId[e].curvePublic===n.curvePublic}))||e.emit("LEAVE",{info:n,id:u.id},u.clients))}},d=function(n){u.wc=n,e.channels[t.channel]=u,n.on("message",(function(t,r){!function(e,t,n,r){var o=e.channels[r.id];o&&C(e,o,t)}(e,t,0,n)})),n.on("join",l),n.on("leave",f),O(e,u,t,i)};o.join(t.channel).then(d,(function(e){console.error(e)})),u.onReconnect=function(){u&&u.stopped||e.channels[t.channel]&&o.join(t.channel).then(d,(function(e){console.error(e)}))},o.on("reconnect",u.onReconnect)},k=function(e,t,r,o){var a=n.once(n.mkAsync(o)),i=r.channel,s=e.channels[i];if(s)s.onReady.reg((function(){-1===s.clients.indexOf(t)&&s.clients.push(t),a()}));else{var u=e.store.proxy,l={keys:c.deriveKeys(r.curvePublic,u.curvePrivate,r.kemPublic,u.kemPublic),channel:r.channel,lastKnownHash:r.lastKnownHash,owners:[u.edPublic,r.edPublic],isFriendChat:!0,clients:t?[t]:e.friendsClients,onReady:a};P(e,l)}};return u.init=function(t,r,c){var u={},h=t.store;if(h.messenger)return h.messenger.addListener(),h.messenger;if(!i.isAvailable("contacts"))return;var p={store:h,Store:t.Store,updateMetadata:t.updateMetadata,pinPads:t.pinPads,emit:c,friendsClients:[],channels:{},validateKeys:{},range_requests:{}};u.addListener=function(){h.proxy&&h.proxy.on("change",["mutedUsers"],(function(){p.emit("UPDATE_MUTED",null,N(p))}))},u.addListener();let b=n.once((e=>{const t=p.store.network||e;t.on("message",(function(e,t){x(p,e,t)})),t.on("disconnect",(function(){p.emit("DISCONNECT",null,N(p))})),t.on("reconnect",(function(){p.emit("RECONNECT",null,N(p))}))}));return h.networkPromise?.then(b),p.store.network&&b(),u.onFriendUpdate=function(e){var t=g(h.proxy,e);if(t&&t.channel){var n=p.channels[t.channel];n&&p.emit("UPDATE_DATA",{info:y(t),channel:t.channel},n.clients)}},u.onFriendAdded=function(e){if(p.friendsClients.length){var t=g(p.store.proxy,e.curvePublic);if("object"==typeof t)if(t.channel){var n=t.channel;p.channels[n]||k(p,null,t,(function(){c("FRIEND",{curvePublic:t.curvePublic},p.friendsClients)}))}}},u.onFriendRemoved=function(e,t){I(p,e,t)},u.getOnlineList=function(e){return function(e,t){var n=e.channels[t];if(n){var r=[],o=m(e.store.proxy,!1);return r.push(o.curvePublic),n.wc.members.forEach((function(t){if(t!==e.store.network.historyKeeper){var o=n.mapId[t]||{};o.curvePublic&&-1===r.indexOf(o.curvePublic)&&r.push(o.curvePublic)}})),r}}(p,e)},u.storeValidateKey=function(e,t){p.validateKeys[e]=t},u.leavePad=function(e){delete p.validateKeys[e],Object.keys(p.channels).some((function(t){var n=p.channels[t];if(n.padChan===e){n.wc&&n.wc.leave();var r=p.store.network;return n.onReconnect&&r.off("reconnect",n.onReconnect),n.stopped=!0,delete p.channels[t],!0}}))},u.openTeamChat=function(t,r,o,a){!function(t,r,o,a,i){var s=o,c=s.channel,u=s.secret;if(c&&u){var l=n.once(n.mkAsync((function(){t.emit("TEAMCHAT_READY",c,[r]),i({readOnly:"object"==typeof u.keys&&!u.keys.validateKey,channel:c})}))),f=t.channels[c];if(f)f.onReady.reg((function(){-1===f.clients.indexOf(r)&&f.clients.push(r),l()}));else{u.keys.cryptKey&&(u.keys.cryptKey=v(u.keys.cryptKey));var d=e.createEncryptor(u.keys),h=u.keys&&u.keys.validateKey||s.validateKey,p={teamId:o.teamId,readOnly:"object"==typeof u.keys&&!u.keys.validateKey,encryptor:d,channel:c,isTeamChat:!0,decrypt:function(e){return d.decrypt(e,h)},clients:[r],onUserlistUpdate:a,onReady:l};P(t,p)}}else i({error:"EINVAL"})}(p,o,t,r,a)},u.removeClient=function(e){!function(e,t){var n=e.friendsClients.indexOf(t);-1!==n&&e.friendsClients.splice(n,1),Object.keys(e.channels).forEach((function(n){var r=e.channels[n],o=r.clients,a=o.indexOf(t);if(-1!==a&&o.splice(a,1),0===o.length){r.wc&&r.wc.leave();var i=e.store.network;return r.onReconnect&&i.off("reconnect",r.onReconnect),r.stopped=!0,delete e.channels[n],!0}}))}(p,e)},u.execCommand=function(t,r,i){var c=r.cmd,u=r.data;"INIT_FRIENDS"!==c?"GET_ROOMS"!==c?"GET_MUTED_USERS"!==c?"GET_USERLIST"!==c?"OPEN_PAD_CHAT"!==c?"GET_MY_INFO"!==c?"REMOVE_FRIEND"!==c?"CANCEL_FRIEND"!==c?"MUTE_USER"!==c?"UNMUTE_USER"!==c?"GET_STATUS"!==c?"GET_MORE_HISTORY"!==c?"SEND_MESSAGE"!==c?"SET_CHANNEL_HEAD"!==c?"CLEAR_OWNED_CHANNEL"!==c||function(e,t,n){var r=e.channels[t];r?e.store.rpc?e.store.rpc.clearOwnedChannel(t,(function(o){n({error:o}),o||(r.messages=[],e.emit("CLEAR_CHANNEL",t,r.clients))})):n({error:"RPC_NOT_READY"}):n({error:"NO_CHANNEL"})}(p,u,i):D(p,u.id,u.sig,i):function(e,t,n,r){var o=e.channels[t];if(o)if(o.readOnly)r({error:"FORBIDDEN"});else if(e.store.network.webChannels.some((function(e){if(e.id===o.wc.id)return!0}))){var i=e.store.proxy||{},s=[f,i.curvePublic,+new Date,n];if(!o.isFriendChat){var c=i[a.displayNameKey]||l.anonymous+"#"+(i.uid||e.store.noDriveUid).slice(0,5);s.push(c)}var u=JSON.stringify(s),d=o.encrypt(u);o.wc.bcast(d).then((function(){C(e,o,d),r()}),(function(e){r({error:e})}))}else r({error:"NO_SUCH_CHANNEL"});else r({error:"NO_CHANNEL"})}(p,u.id,u.content,i):function(e,t,r,o,a){if("function"==typeof a)if("string"==typeof r){var i=e.channels[t];if(void 0!==i){var s=n.uid();_(e,s,t,a);var c=["GET_HISTORY_RANGE",i.id,{from:r,count:o,txid:s}],u=e.store.network;u.sendto(u.historyKeeper,JSON.stringify(c)).then((function(){}),(function(e){console.error(e)}))}else console.error("chan is undefined. we're going to have a problem here")}else a([])}(p,u.id,u.sig,u.count,i):function(e,t,n){var r=e.channels[t];if(r){r.onUserlistUpdate&&r.onUserlistUpdate();var o=e.store.proxy||{};n(r.wc.members.some((function(t){if(t!==e.store.network.historyKeeper){var n=r.mapId[t]||void 0;return!!n&&n.curvePublic!==o.curvePublic}})))}else n("NO_SUCH_CHANNEL")}(p,u,i):function(e,t,r){var o=n.once(n.mkAsync(r)),a=e.store.proxy,i=a.mutedUsers=a.mutedUsers||{};delete i[t],e.emit("UPDATE_MUTED",null,N(e)),o(Object.keys(i).length)}(p,u,i):function(e,t,r){var o=n.once(n.mkAsync(r)),a=e.store.proxy,i=a.mutedUsers=a.mutedUsers||{};i[t.curvePublic]||(i[t.curvePublic]=t,e.emit("UPDATE_MUTED",null,N(e))),o()}(p,u,i):function(e,t,r){var o=n.once(r);"function"==typeof o?e.Store.cancelFriendRequest(t,o):console.error("NO_CALLBACK")}(p,u,i):function(e,t,r){var a=n.once(r);if("function"==typeof a){var i=e.store.proxy,s=g(i,t);if(!s)return console.error("friend is not valid"),void a({error:"INVALID_FRIEND"});var c=e.channels[s.channel];if(e.store.mailbox&&s.curvePublic&&s.notifications)o.removeFriend(e.store,t,(function(t){t&&t.error?a({error:t.error}):(e.updateMetadata(),a(t))}));else if(c)try{var u=[d,i.curvePublic,+new Date],l=JSON.stringify(u),f=c.encrypt(l);c.wc.bcast(f).then((function(){I(e,t,s.channel),T(e,t,(function(){a()}))}),(function(n){n?a({error:n}):(I(e,t,s.channel),T(e,t,(function(){a()})))}))}catch(e){a({error:e})}else a({error:"NO_SUCH_CHANNEL"})}else console.error("NO_CALLBACK")}(p,u,i):function(e,t){var n=e.store.proxy||{};t({curvePublic:n.curvePublic,displayName:n[a.displayNameKey]})}(p,i):function(t,r,o,a){var i=o.channel,s=n.once(n.mkAsync((function(){t.emit("PADCHAT_READY",i,[r]),a()}))),c=t.channels[i];if(c)c.onReady.reg((function(){-1===c.clients.indexOf(r)&&c.clients.push(r),s()}));else{var u=o.secret;u.keys.cryptKey&&(u.keys.cryptKey=v(u.keys.cryptKey));var l=e.createEncryptor(u.keys),f=u.keys&&u.keys.validateKey||t.validateKeys[u.channel],d={padChan:o.secret&&o.secret.channel,readOnly:"object"==typeof u.keys&&!u.keys.validateKey,encryptor:l,channel:o.channel,isPadChat:!0,decrypt:function(e){return l.decrypt(e,f)},clients:[r],onReady:s};P(t,d)}}(p,t,u,i):function(e,t,n){var r=e.channels[t.id];if(r)if(r.isFriendChat){var o=A(e,t.id);if(!o)return void n({error:"NO_SUCH_FRIEND"});n([o])}else n([]);else n({error:"NO_SUCH_CHANNEL"})}(p,u,i):function(e,t){var n=e.store.proxy;if(!t)return n.mutedUsers||{};t(n.mutedUsers||{})}(p,i):function(e,t,n){var r=e.store.proxy;if(t&&t.curvePublic){var o=t.curvePublic,a=g(r,o);if(!a)return void n({error:"NO_SUCH_FRIEND"});var i=e.channels[a.channel];return i?void n([{id:i.id,isFriendChat:!0,name:a.displayName,lastKnownHash:a.lastKnownHash,curvePublic:a.curvePublic,messages:i.messages}]):void n({error:"NO_SUCH_CHANNEL"})}if(t&&t.padChat){var s=e.channels[t.padChat];return s?void n([{id:s.id,isPadChat:!0,messages:s.messages}]):void n({error:"NO_SUCH_CHANNEL"})}if(t&&t.teamChat){var c=e.channels[t.teamChat];return c?void n([{id:c.id,isTeamChat:!0,messages:c.messages}]):void n({error:"NO_SUCH_CHANNEL"})}var u=Object.keys(e.channels).map((function(t){var n,r,o,a=e.channels[t];if(a.isFriendChat){var i=A(e,t);if(!i)return null;n=i.displayName,r=i.lastKnownHash,o=i.curvePublic}else{if(a.isPadChat)return;if(a.isTeamChat)return}return{id:a.id,isFriendChat:a.isFriendChat,name:n,lastKnownHash:r,curvePublic:o,messages:a.messages}})).filter((function(e){return e}));n(u)}(p,u,i):function(e,t,n){var r=E(e.store.proxy);s((function(n){Object.keys(r).forEach((function(o){if("me"!==o){var a=y(r[o]);"object"==typeof a&&a.channel&&k(e,t,a,n())}else delete r.me.channel}))})).nThen((function(){-1===e.friendsClients.indexOf(t)&&e.friendsClients.push(t),n()}))}(p,t,i)},u},u})(ye(),Fe(),Ne(),mt(),Zt(),Oe(),Ft(),Dt()),ir}function Er(){if(ur)return cr;ur=1;return cr=((e,t,n,r)=>{const o={},a={};var i=function(t,n,o,a,i){var s,c=e.once(e.mkAsync(i)),u=function(t,n){if(!n)return e.find(t.store,["proxy","edPublic"]);var r=e.find(t,["store","proxy","teams",n]);return e.find(r,["keys","drive","edPublic"])}(t,a),l=t.Store,f=0,d=0,h=0;r((function(e){l.getFileSize(null,{channel:n},e((function(t){return t&&t.error?(e.abort(),void c(t)):void 0===t.size?(e.abort(),void c({error:"ENOENT"})):void(f=t.size)}))),l.getHistory(null,{channel:n,lastKnownHash:o},e((function(t){if(t&&t.error)return e.abort(),void c(t);if(!Array.isArray(t))return e.abort(),void c({error:"EINVAL"});if(t.length){s=t[0].hash;var n=t.map((function(e){return e.msg}));d=n.join("\n").length}})),!0),l.pad.getMetadata(null,{channel:n},e((function(t){if((!t||!t.error)&&t&&"object"==typeof t)return h=JSON.stringify(t).length,t&&Array.isArray(t.owners)&&-1!==t.owners.indexOf(u)?void 0:(e.abort(),void c({error:"INSUFFICIENT_PERMISSIONS"}))})))})).nThen((function(){c({size:f-h-d,hash:s})}))};return a.GET_HISTORY_SIZE=function(o,a,s,c){if(o.store.loggedIn&&o.store.rpc){var u=a.channels;if(Array.isArray(u)){var l=[];a.account?u=function(r){var o=[],a=e.find(r.store,["proxy","edPublic"]);-1!==(e.find(r.store,["driveMetadata","owners"])||[]).indexOf(a)&&o.push(r.store.driveChannel);var i=r.store.proxy.profile;if(i){var s=i.edit?t.hrefToHexChannelId("/profile/#"+i.edit,null):null;s&&o.push(s)}r.store.proxy.todo&&o.push(t.hrefToHexChannelId("/todo/#"+r.store.proxy.todo,null));var c=r.store.proxy.mailboxes;if(c){var u=Object.keys(c).map((function(e){return{lastKnownHash:c[e].lastKnownHash,channel:c[e].channel}}));Array.prototype.push.apply(o,u)}var l=r.store.proxy[n.SHARED_FOLDERS];if(l){var f=Object.keys(l).map((function(e){var t=l[e];if(t&&t.owners&&Array.isArray(t.owners)&&-1!==t.owners.indexOf(a))return t.channel})).filter(Boolean);Array.prototype.push.apply(o,f)}return o}(o):a.team&&(u=function(t,n){let r=e.find(t.store,["proxy","teams",n]);if(!r)return[];let o=[r.channel],a=r.keys.roster;return o.push({channel:a.channel,lastKnownHash:a.lastKnownHash}),o}(o,a.team));var f=0,d=[];r((function(e){u.forEach((function(t){var n,r=t;"object"==typeof t&&t.channel&&(r=t.channel,n=t.lastKnownHash),i(o,r,n,a.teamId,e((function(e){e&&e.error?l.push(e.error):(f+=e.size,e.hash&&d.push({channel:r,hash:e.hash}))})))}))})).nThen((function(){c({warning:l.length?l:void 0,channels:d,size:f})}))}else c({error:"EINVAL"})}else c({error:"INSUFFICIENT_PERMISSIONS"})},a.TRIM_HISTORY=function(e,t,n,o){if(e.store.loggedIn&&e.store.rpc){var a=t.channels;if(Array.isArray(a)){var i=function(e,t){if(!t)return e.store.rpc;var n=e.store.modules.team;if(n){var r=n.getTeam(t);if(r)return r.rpc}}(e,t.teamId);if(i){var s=[];r((function(e){a.forEach((function(t){i.trimHistory(t,e((function(e){e&&s.push(e)})))}))})).nThen((function(){1===a.length&&s.length?o({error:s[0]}):o({warning:s.length?s:void 0})}))}else o({error:"ENORPC"})}else o({error:"EINVAL"})}else o({error:"INSUFFICIENT_PERMISSIONS"})},o.init=function(e,t,n){var r={};if(e.store){var o={store:e.store,Store:e.Store,pinPads:e.pinPads,updateMetadata:e.updateMetadata,emit:n};return r.execCommand=function(e,t,n){var r=t.cmd,i=t.data;try{a[r](o,i,e,n)}catch(e){console.error(e)}},r}},o})(Ne(),Fe(),Et(),Dt()),cr}var br,Ar={exports:{}};function _r(){return br||(br=1,function(e){(()=>{const t=e=>{var t={};const n=globalThis;var r=function(){},o=t.getWeekNo=function(e,t){"number"!=typeof t&&(t=1);var n=new Date(e.getFullYear(),0,1),r=n.getDay()-t;r=r>=0?r:r+7;var o,a=Math.floor((e.getTime()-n.getTime())/864e5)+1;if(r<4){if((o=Math.floor((a+r-1)/7)+1)>52){var i=new Date(e.getFullYear()+1,0,1).getDay()-t;o=(i=i>=0?i:i+7)<4?1:53}}else o=Math.floor((a+r-1)/7);return o},a=function(e){var t=new Date(e.getFullYear(),0,0),n=e-t+60*(t.getTimezoneOffset()-e.getTimezoneOffset())*1e3;return Math.floor(n/864e5)},i=t.DAYORDER=["SU","MO","TU","WE","TH","FR","SA"],s=function(e){var t=Number(e.slice(0,-2)),n=i.indexOf(e.slice(-2));return t?[t,n]:n},c=function(e,t){var n=e.getDay();n>=(t="number"==typeof t?t:1)?e.setDate(e.getDate()-(n-t)):e.setDate(e.getDate()-(7+n-t))},u=function(e){return e.getFullYear()+"-"+(e.getMonth()+1)+"-"+e.getDate()},l={daily:function(e,t){e.setDate(e.getDate()+t)},weekly:function(e,t){e.setDate(e.getDate()+7*t)},monthly:function(e,t){e.setMonth(e.getMonth()+t)},yearly:function(e,t){e.setFullYear(e.getFullYear()+t)}},f={month:function(e,t,n){var r=new Date(t.start),o=(n-(e.getMonth()+1)+12)%12,a=e.getMonth()+o;if(e.setMonth(a),e.setDate(r.getDate()),e.getMonth()===a)return!0},weekno:function(e,t,n,r){var a=r&&r.wkst;"number"!=typeof a&&(a=1);var i=new Date(t.start),s=new Date(e.getFullYear(),11,31),u=o(s,a),l=1===u;1===u&&(u=52);var f=o(e,a);if(!n||n>u)return!1;n<0&&(n=u+n+1);var d=n-f,h=new Date(+e);h.setDate(h.getDate()+7*d),c(h,a);var p="aaaaaaa".split("").map((function(t,n){var r=new Date(+h);if(r.setDate(r.getDate()+n),r.getFullYear()===e.getFullYear())return r.toLocaleDateString()!==i.toLocaleDateString()&&r})).filter(Boolean);return 1===n&&l&&(c(s,a),"aaaaaaa".split("").some((function(t,n){var r=new Date(+s);if(r.setDate(r.getDate()+n),r.toLocaleDateString()!==i.toLocaleDateString())return r.getFullYear()>e.getFullYear()||void p.push(r)}))),p.length?p:void 0}};f.yearday=function(e,t,n){var r=e.getFullYear();if(function(e,t){if(!("number"!=typeof t||Math.abs(t)<1||Math.abs(t)>366))return t<0&&(t=a(new Date(e.getFullYear(),11,31))+t+1),e.setMonth(0),e.setDate(t),!0}(e,n)&&e.getFullYear()===r)return!0},f.monthday=function(e,t,n,r){if("number"!=typeof n||Math.abs(n)<1||Math.abs(n)>31)return!1;var o=function(e,t){var n=e.getMonth();t<0&&(t=new Date(e.getFullYear(),e.getMonth()+1,0).getDate()+t+1);return e.setDate(t),e.getMonth()===n};if("monthly"===r.freq)return o(e,n);var a="aaaaaaaaaaaa".split("").map((function(t,r){var a=new Date(e.getFullYear(),r,1);return o(a,n)?a:void 0})).filter(Boolean);return a.length?a:void 0},f.day=function(e,t,n,r){var o,a=s(n);Array.isArray(a)&&(o=a[0],a=a[1]);var i=[];if(![0,1,2,3,4,5,6].includes(a))return!1;var c,u=function(e){if(o){var t=[];"aaaaaaaaaaaa".split("").some((function(n,r){if(void 0===e||r===e){var a,s=i.filter((function(e){return e.getMonth()===r}));return a=o<0?s.length+o:o-1,t.push(s[a]),void 0!==e&&r===e}})),i=t.filter(Boolean)}};if("yearly"===r.freq){c=new Date(+e);for(var l=e.getFullYear();c.getDay()!==a;)c.setDate(c.getDate()+1);for(;c.getFullYear()===l;)i.push(new Date(+c)),c.setDate(c.getDate()+7);return u(),i}if("monthly"===r.freq){c=new Date(+e);for(var f=e.getMonth();c.getDay()!==a;)c.setDate(c.getDate()+1);for(;c.getMonth()===f;)i.push(new Date(+c)),c.setDate(c.getDate()+7);return u(f),i}if("weekly"===r.freq)for(;e.getDay()!==a;)e.setDate(e.getDate()+1);return!0};var d={month:function(e,t){return e.filter((function(e){return t.includes(e.getMonth()+1)}))},weekno:function(e,t,n){return e.filter((function(e){var r=n&&n.wkst;"number"!=typeof r&&(r=1);var a=new Date(e.getFullYear(),11,31),i=o(a,r);1===i&&(i=52);var s=o(e,r);return t.some((function(e){return e>0?e===s:s===i+e+1}))}))},yearday:function(e,t){return e.filter((function(e){var n=a(e),r=a(new Date(e.getFullYear(),11,31));return t.some((function(e){return e>0?e===n:n===r+e+1}))}))},monthday:function(t,n){return t.filter((function(t){var r=e.clone(n);return(r=r.map((function(e){e<0&&(e=new Date(t.getFullYear(),t.getMonth()+1,0).getDate()+e+1);return e}))).includes(t.getDate())}))},day:function(e,t,n){return e.filter((function(e){var r=e.toLocaleDateString(),o="yearly";return("monthly"===n.freq||"yearly"===n.freq&&n.by&&n.by.month)&&(o="monthly"),t.some((function(t){var n,a=s(t);if(Array.isArray(a)&&(n=a[0],a=a[1]),!n)return e.getDay()===a;var i=new Date(e.getFullYear(),e.getMonth(),1);return"yearly"===o&&i.setMonth(0),f.day(i,{},t,{freq:o}).some((function(e){return e.toLocaleDateString()===r}))}))}))},setpos:function(t,n){var r=t.slice(),o=e.deduplicateString(n.slice().map((function(e){return e>0?e-1:0!==e?r.length+e:void 0})));return t.filter((function(e){var t=r.indexOf(e);return o.includes(t)}))}},h=["month","weekno","yearday","monthday","day"],p=["month","monthday","day"];t.getMonthId=function(e){return e.getFullYear()+"-"+e.getMonth()};var y=n.CP_calendar_cache={},v={};t.resetCache=function(){y=n.CP_calendar_cache={},v={}};var m=function(t){if(!t.recUpdate)return[];var n={},r=t.recUpdate.from;return Object.keys(r||{}).forEach((function(e){var t=r[e];t.recurrenceRule&&(n[e]=t.recurrenceRule)})),Object.keys(n).sort((function(e,t){return Number(e)-Number(t)})).map((function(t){var r=e.clone(n[t]);if(l[r.freq]&&!(r.interval&&r.interval<1))return r._start=Number(t),r})).filter(Boolean)};t.getRecurring=function(o,i){n.CP_DEV_MODE&&(r=console.warn);var s=[];return o.forEach((function(n){var o=n.split("-"),g=new Date(o[0],o[1]),E=new Date(+g);E.setMonth(E.getMonth()+1),E.setMilliseconds(-1),r("Compute month",g.toLocaleDateString()),(i||[]).forEach((function(n){var o=new Date(n.start),i=new Date(n.end),b=n,A=n.recurrenceRule;if(A){var _=m(n),w=_.shift();if(!(o>=E)){for(var O=A.until,D=_.slice(),S=w;S&&S._start&&S._start<g;)O=w.until,S=D.shift();if(!(O<g)){var T=function(e,t){if(!(e>t)){var n;if(t.getFullYear()===e.getFullYear())n=a(t)-a(e);else{var r=new Date(e.getFullYear(),11,31);for(n=a(r)-a(e)+a(t);r.getFullYear()+1<t.getFullYear();)r.setFullYear(r.getFullYear()+1),n+=a(r)}return{h:t.getHours(),m:t.getMinutes(),days:n}}console.error("Wrong data")}(o,i);if(!(A.interval&&A.interval<1)&&l[A.freq]){r("Iterate over",n.title,n),r("Use rule",A);var C=A.count,x=1,I=function(a){var i=new Date(+a);if(!(C&&x>=C)){r("Start iteration",i.toLocaleDateString());var m=function(t,n,o){var a=e.clone(n),i=new Date(a.start),s=a.id.split("|")[0],u=o.toLocaleDateString();y[s]=y[s]||{};var v=t.interval||1,m=t.freq,g=[],E=function(e,n){g=d[e](g,n,t)},b=function(e){return function(n){var r=new Date(+o);"yearly"===t.freq?(r.setMonth(0),r.setDate(1)):"monthly"===t.freq?r.setDate(1):"weekly"===t.freq?c(r,t.wkst):t.freq;var s=f[e](r,a,n,t);if(s)if(Array.isArray(s))s=s.filter((function(e){return e.toLocaleDateString()!==i.toLocaleDateString()})),Array.prototype.push.apply(g,s);else{if(r.toLocaleDateString()===i.toLocaleDateString())return;g.push(r)}}},A=e.once((function(){l[m](o,v)})),_=function(){"monthly"===m?o.setDate(15):"yearly"===m&&1===i.getMonth()&&29===i.getDate()&&o.setDate(28),A();var e=new Date(+o);if("monthly"===m||"yearly"===m){if(e.setDate(i.getDate()),e.getDate()!==i.getDate())return;if("yearly"===m&&e.getMonth()!==i.getMonth())return}g.push(e)};if(Array.isArray(y[s][u]))return r("Get cache",s,u),"monthly"===m?o.setDate(15):"yearly"===m&&1===i.getMonth()&&29===i.getDate()&&o.setDate(28),A(),y[s][u];if(t.by&&"yearly"===m){var w=h.slice(),O=!1;(t.by.weekno||t.by.yearday||t.by.monthday||t.by.day)&&(w.shift(),O=!0);var D=!0;w.forEach((function(e){var n=t.by[e];n&&(D?(n.forEach(b(e)),D=!1):"day"===e?t.by.yearday||t.by.monthday||t.by.weekno?E("day",t.by.day):t.by.day.forEach(b("day")):E(e,n))})),t.by.month&&O&&E("month",t.by.month)}t.by&&"monthly"===m&&(t.by.monthday||t.by.day?t.by.monthday?t.by.monthday.forEach(b("monthday")):t.by.day&&t.by.day.forEach(b("day")):_(),t.by.month&&E("month",t.by.month),t.by.day&&t.by.monthday&&E("day",t.by.day)),t.by&&"weekly"===m&&(t.by.day?t.by.day.forEach(b("day")):_(),t.by.month&&E("month",t.by.month)),t.by&&"daily"===m&&(_(),p.forEach((function(e){var n=t.by[e];n&&E(e,n)}))),g.sort((function(e,t){return e-t})),t.by&&t.by.setpos&&E("setpos",t.by.setpos),t.by&&Object.keys(t.by).length?A():_();var S=[];return g=g.filter((function(e){var t=new Date(+e).toLocaleDateString();return!S.includes(t)&&(S.push(t),!0)})),r("Set cache",s,u),y[s][u]=g,g}(A,n,i);if(r("Iteration results",JSON.stringify(m.map((function(e){return new Date(e).toLocaleDateString()})))),!m.length)return i.getFullYear()<g.getFullYear()||i<E?void I(i):void 0;var O=!1,D=!1;m.some((function(a){var c=e.clone(n);c.id=b.id+"|"+ +a;var l,f,d,h=new Date(+a),p=new Date(+a);l=h,d=T,(f=p).setTime(+l),d&&(f.setHours(d.h),f.setMinutes(d.m),f.setSeconds(0),f.setDate(l.getDate()+d.days)),c.start=+h,c.end=+p,c._count=x,t.applyUpdates([c]),h=new Date(c.start),p=new Date(c.end),c.isAllDay&&c.startDay&&(c.startDay=u(h)),c.isAllDay&&c.endDay&&(c.endDay=u(p)),w&&c.start===w._start&&(D=!0);var y=function(){D&&(r("Use new rule",w),c._count=x,C=w.count,x=1,i=+h,n=c,A=w,w=_.shift())};if(x>=C)return r(h.toLocaleDateString(),"count"),O=!0,!0;if(h>=E)return r(h.toLocaleDateString(),"endMonth"),O=!0,!0;if(A.until&&h>A.until)return r(h.toLocaleDateString(),"until"),O=!0,!0;if(!(h<o)){if(x++,p<g)return r(h.toLocaleDateString(),"startMonth"),void(D&&y());if(h<E&&p>=E||h<g&&p>=g){if(v[c.id]&&v[c.id].includes(c.start))return;v[c.id]=v[c.id]||[],v[c.id].push(c.start)}if(b.timeZone&&!c.isAllDay){var m=function(e,t,n){var r=function(e,t){let n=e.toLocaleString("en-CA",{timeZone:t,hour12:!1}).replace(", ","T");return n+="."+e.getMilliseconds().toString().padStart(3,"0"),-(new Date(n+"Z")-e)},o=Intl.DateTimeFormat().resolvedOptions().timeZone,a=r(t,e)-r(n,e);return r(t,o)-r(n,o)-a}(b.timeZone,o,h);c.start+=m,c.end+=m}return s.push(c),D?(y(),!0):void 0}r(h.toLocaleDateString(),"start")})),O||I(i)}};I(o),r("Added this month (all events)",s.map((function(e){return new Date(e.start).toLocaleDateString()})))}}}}}))})),s},t.getAllOccurrences=function(e){if(!e.recurrenceRule)return[e.start];var n=e.recurrenceRule;if(!n.until&&!n.count)return!1;var r=[e.start],o=new Date(e.start);o.setDate(15);for(var a=[],i=0;(a=t.getRecurring([t.getMonthId(o)],[e]))&&(n.count?r.length<n.count:+o<=n.until)&&i<12*n.count;)Array.prototype.push.apply(r,a.map((function(e){return e.start}))),o.setMonth(o.getMonth()+1),i++;return r},t.diffDate=function(e,t){for(var n=new Date(t),r=new Date(e),o=0,a=n<r?-1:1;n.toLocaleDateString()!==r.toLocaleDateString()||a>=1e4;)n.setDate(n.getDate()-a),o++;return{d:o*=a,h:(n=new Date(t)).getHours()-r.getHours(),m:n.getMinutes()-r.getMinutes()}};return t.applyUpdates=function(e){return e.forEach((function(e){if(e.raw={start:e.start,end:e.end},e.recUpdate){var t,n=e.recUpdate.from||{},r=e.recUpdate.one||{},o=e.start,a=m(e).filter((function(e){return e._start>o})).shift(),i=function(t,n){var r=t[n],o=new Date(e.raw[n]);o.setDate(o.getDate()+r.d),o.setHours(o.getHours()+r.h),o.setMinutes(o.getMinutes()+r.m),e[n]=+o};(t=n,Object.keys(t).sort((function(e,t){return Number(e)-Number(t)}))).forEach((function(t){o<Number(t)||Object.keys(n[t]).forEach((function(r){"start"!==r&&"end"!==r?("recurrenceRule"!==r||n[t][r])&&(e[r]=n[t][r]):i(n[t],r)}))})),Object.keys(r[o]||{}).forEach((function(t){"start"!==t&&"end"!==t?("recurrenceRule"!==t||r[o][t])&&(e[t]=r[o][t]):i(r[o],t)})),e.deleted&&Object.keys(e).forEach((function(t){delete e[t]})),a&&e.recurrenceRule&&(e.recurrenceRule._next=a._start-1),e.reminders&&(e.raw.reminders=e.reminders)}})),e},t};e.exports&&(e.exports=t(Ne()))})()}(Ar)),Ar.exports}var wr,Or,Dr,Sr={exports:{}};function Tr(){return wr||(wr=1,function(e){e.exports=function(){var e=function(){return(e=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function t(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var a=arguments[t],i=0,s=a.length;i<s;i++,o++)r[o]=a[i];return r}var n=["onChange","onClose","onDayCreate","onDestroy","onKeyDown","onMonthChange","onOpen","onParseConfig","onReady","onValueUpdate","onYearChange","onPreCalendarPosition"],r={_disable:[],allowInput:!1,allowInvalidPreload:!1,altFormat:"F j, Y",altInput:!1,altInputClass:"form-control input",animate:"object"==typeof window&&-1===window.navigator.userAgent.indexOf("MSIE"),ariaDateFormat:"F j, Y",autoFillDefaultTime:!0,clickOpens:!0,closeOnSelect:!0,conjunction:", ",dateFormat:"Y-m-d",defaultHour:12,defaultMinute:0,defaultSeconds:0,disable:[],disableMobile:!1,enableSeconds:!1,enableTime:!1,errorHandler:function(e){return"undefined"!=typeof console&&console.warn(e)},getWeek:function(e){var t=new Date(e.getTime());t.setHours(0,0,0,0),t.setDate(t.getDate()+3-(t.getDay()+6)%7);var n=new Date(t.getFullYear(),0,4);return 1+Math.round(((t.getTime()-n.getTime())/864e5-3+(n.getDay()+6)%7)/7)},hourIncrement:1,ignoredFocusElements:[],inline:!1,locale:"default",minuteIncrement:5,mode:"single",monthSelectorType:"dropdown",nextArrow:"<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 17 17'><g></g><path d='M13.207 8.472l-7.854 7.854-0.707-0.707 7.146-7.146-7.146-7.148 0.707-0.707 7.854 7.854z' /></svg>",noCalendar:!1,now:new Date,onChange:[],onClose:[],onDayCreate:[],onDestroy:[],onKeyDown:[],onMonthChange:[],onOpen:[],onParseConfig:[],onReady:[],onValueUpdate:[],onYearChange:[],onPreCalendarPosition:[],plugins:[],position:"auto",positionElement:void 0,prevArrow:"<svg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 17 17'><g></g><path d='M5.207 8.471l7.146 7.147-0.707 0.707-7.853-7.854 7.854-7.853 0.707 0.707-7.147 7.146z' /></svg>",shorthandCurrentMonth:!1,showMonths:1,static:!1,time_24hr:!1,weekNumbers:!1,wrap:!1},o={weekdays:{shorthand:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],longhand:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},months:{shorthand:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],longhand:["January","February","March","April","May","June","July","August","September","October","November","December"]},daysInMonth:[31,28,31,30,31,30,31,31,30,31,30,31],firstDayOfWeek:0,ordinal:function(e){var t=e%100;if(t>3&&t<21)return"th";switch(t%10){case 1:return"st";case 2:return"nd";case 3:return"rd";default:return"th"}},rangeSeparator:" to ",weekAbbreviation:"Wk",scrollTitle:"Scroll to increment",toggleTitle:"Click to toggle",amPM:["AM","PM"],yearAriaLabel:"Year",monthAriaLabel:"Month",hourAriaLabel:"Hour",minuteAriaLabel:"Minute",time_24hr:!1},a=function(e,t){return void 0===t&&(t=2),("000"+e).slice(-1*t)},i=function(e){return!0===e?1:0};function s(e,t){var n;return function(){var r=this;clearTimeout(n),n=setTimeout((function(){return e.apply(r,arguments)}),t)}}var c=function(e){return e instanceof Array?e:[e]};function u(e,t,n){if(!0===n)return e.classList.add(t);e.classList.remove(t)}function l(e,t,n){var r=window.document.createElement(e);return t=t||"",n=n||"",r.className=t,void 0!==n&&(r.textContent=n),r}function f(e){for(;e.firstChild;)e.removeChild(e.firstChild)}function d(e,t){return t(e)?e:e.parentNode?d(e.parentNode,t):void 0}function h(e,t){var n=l("div","numInputWrapper"),r=l("input","numInput "+e),o=l("span","arrowUp"),a=l("span","arrowDown");if(-1===navigator.userAgent.indexOf("MSIE 9.0")?r.type="number":(r.type="text",r.pattern="\\d*"),void 0!==t)for(var i in t)r.setAttribute(i,t[i]);return n.appendChild(r),n.appendChild(o),n.appendChild(a),n}function p(e){try{return"function"==typeof e.composedPath?e.composedPath()[0]:e.target}catch(t){return e.target}}var y=function(){},v=function(e,t,n){return n.months[t?"shorthand":"longhand"][e]},m={D:y,F:function(e,t,n){e.setMonth(n.months.longhand.indexOf(t))},G:function(e,t){e.setHours(parseFloat(t))},H:function(e,t){e.setHours(parseFloat(t))},J:function(e,t){e.setDate(parseFloat(t))},K:function(e,t,n){e.setHours(e.getHours()%12+12*i(new RegExp(n.amPM[1],"i").test(t)))},M:function(e,t,n){e.setMonth(n.months.shorthand.indexOf(t))},S:function(e,t){e.setSeconds(parseFloat(t))},U:function(e,t){return new Date(1e3*parseFloat(t))},W:function(e,t,n){var r=parseInt(t),o=new Date(e.getFullYear(),0,2+7*(r-1),0,0,0,0);return o.setDate(o.getDate()-o.getDay()+n.firstDayOfWeek),o},Y:function(e,t){e.setFullYear(parseFloat(t))},Z:function(e,t){return new Date(t)},d:function(e,t){e.setDate(parseFloat(t))},h:function(e,t){e.setHours(parseFloat(t))},i:function(e,t){e.setMinutes(parseFloat(t))},j:function(e,t){e.setDate(parseFloat(t))},l:y,m:function(e,t){e.setMonth(parseFloat(t)-1)},n:function(e,t){e.setMonth(parseFloat(t)-1)},s:function(e,t){e.setSeconds(parseFloat(t))},u:function(e,t){return new Date(parseFloat(t))},w:y,y:function(e,t){e.setFullYear(2e3+parseFloat(t))}},g={D:"(\\w+)",F:"(\\w+)",G:"(\\d\\d|\\d)",H:"(\\d\\d|\\d)",J:"(\\d\\d|\\d)\\w+",K:"",M:"(\\w+)",S:"(\\d\\d|\\d)",U:"(.+)",W:"(\\d\\d|\\d)",Y:"(\\d{4})",Z:"(.+)",d:"(\\d\\d|\\d)",h:"(\\d\\d|\\d)",i:"(\\d\\d|\\d)",j:"(\\d\\d|\\d)",l:"(\\w+)",m:"(\\d\\d|\\d)",n:"(\\d\\d|\\d)",s:"(\\d\\d|\\d)",u:"(.+)",w:"(\\d\\d|\\d)",y:"(\\d{2})"},E={Z:function(e){return e.toISOString()},D:function(e,t,n){return t.weekdays.shorthand[E.w(e,t,n)]},F:function(e,t,n){return v(E.n(e,t,n)-1,!1,t)},G:function(e,t,n){return a(E.h(e,t,n))},H:function(e){return a(e.getHours())},J:function(e,t){return void 0!==t.ordinal?e.getDate()+t.ordinal(e.getDate()):e.getDate()},K:function(e,t){return t.amPM[i(e.getHours()>11)]},M:function(e,t){return v(e.getMonth(),!0,t)},S:function(e){return a(e.getSeconds())},U:function(e){return e.getTime()/1e3},W:function(e,t,n){return n.getWeek(e)},Y:function(e){return a(e.getFullYear(),4)},d:function(e){return a(e.getDate())},h:function(e){return e.getHours()%12?e.getHours()%12:12},i:function(e){return a(e.getMinutes())},j:function(e){return e.getDate()},l:function(e,t){return t.weekdays.longhand[e.getDay()]},m:function(e){return a(e.getMonth()+1)},n:function(e){return e.getMonth()+1},s:function(e){return e.getSeconds()},u:function(e){return e.getTime()},w:function(e){return e.getDay()},y:function(e){return String(e.getFullYear()).substring(2)}},b=function(e){var t=e.config,n=void 0===t?r:t,a=e.l10n,i=void 0===a?o:a,s=e.isMobile,c=void 0!==s&&s;return function(e,t,r){var o=r||i;return void 0===n.formatDate||c?t.split("").map((function(t,r,a){return E[t]&&"\\"!==a[r-1]?E[t](e,o,n):"\\"!==t?t:""})).join(""):n.formatDate(e,t,o)}},A=function(e){var t=e.config,n=void 0===t?r:t,a=e.l10n,i=void 0===a?o:a;return function(e,t,o,a){if(0===e||e){var s,c=a||i,u=e;if(e instanceof Date)s=new Date(e.getTime());else if("string"!=typeof e&&void 0!==e.toFixed)s=new Date(e);else if("string"==typeof e){var l=t||(n||r).dateFormat,f=String(e).trim();if("today"===f)s=new Date,o=!0;else if(/Z$/.test(f)||/GMT$/.test(f))s=new Date(e);else if(n&&n.parseDate)s=n.parseDate(e,l);else{s=n&&n.noCalendar?new Date((new Date).setHours(0,0,0,0)):new Date((new Date).getFullYear(),0,1,0,0,0,0);for(var d=void 0,h=[],p=0,y=0,v="";p<l.length;p++){var E=l[p],b="\\"===E,A="\\"===l[p-1]||b;if(g[E]&&!A){v+=g[E];var _=new RegExp(v).exec(e);_&&(d=!0)&&h["Y"!==E?"push":"unshift"]({fn:m[E],val:_[++y]})}else b||(v+=".");h.forEach((function(e){var t=e.fn,n=e.val;return s=t(s,n,c)||s}))}s=d?s:void 0}}if(s instanceof Date&&!isNaN(s.getTime()))return!0===o&&s.setHours(0,0,0,0),s;n.errorHandler(new Error("Invalid date provided: "+u))}}};function _(e,t,n){return void 0===n&&(n=!0),!1!==n?new Date(e.getTime()).setHours(0,0,0,0)-new Date(t.getTime()).setHours(0,0,0,0):e.getTime()-t.getTime()}var w=864e5;function O(e){var t=e.defaultHour,n=e.defaultMinute,r=e.defaultSeconds;if(void 0!==e.minDate){var o=e.minDate.getHours(),a=e.minDate.getMinutes(),i=e.minDate.getSeconds();t<o&&(t=o),t===o&&n<a&&(n=a),t===o&&n===a&&r<i&&(r=e.minDate.getSeconds())}if(void 0!==e.maxDate){var s=e.maxDate.getHours(),c=e.maxDate.getMinutes();(t=Math.min(t,s))===s&&(n=Math.min(c,n)),t===s&&n===c&&(r=e.maxDate.getSeconds())}return{hours:t,minutes:n,seconds:r}}function D(y,m){var E={config:e(e({},r),T.defaultConfig),l10n:o};function D(e){return e.bind(E)}function S(){var e=E.config;!1===e.weekNumbers&&1===e.showMonths||!0!==e.noCalendar&&window.requestAnimationFrame((function(){if(void 0!==E.calendarContainer&&(E.calendarContainer.style.visibility="hidden",E.calendarContainer.style.display="block"),void 0!==E.daysContainer){var t=(E.days.offsetWidth+1)*e.showMonths;E.daysContainer.style.width=t+"px",E.calendarContainer.style.width=t+(void 0!==E.weekWrapper?E.weekWrapper.offsetWidth:0)+"px",E.calendarContainer.style.removeProperty("visibility"),E.calendarContainer.style.removeProperty("display")}}))}function C(e){if(0===E.selectedDates.length){var t=void 0===E.config.minDate||_(new Date,E.config.minDate)>=0?new Date:new Date(E.config.minDate.getTime()),n=O(E.config);t.setHours(n.hours,n.minutes,n.seconds,t.getMilliseconds()),E.selectedDates=[t],E.latestSelectedDateObj=t}void 0!==e&&"blur"!==e.type&&function(e){e.preventDefault();var t="keydown"===e.type,n=p(e),r=n;void 0!==E.amPM&&n===E.amPM&&(E.amPM.textContent=E.l10n.amPM[i(E.amPM.textContent===E.l10n.amPM[0])]);var o=parseFloat(r.getAttribute("min")),s=parseFloat(r.getAttribute("max")),c=parseFloat(r.getAttribute("step")),u=parseInt(r.value,10),l=u+c*(e.delta||(t?38===e.which?1:-1:0));if(void 0!==r.value&&2===r.value.length){var f=r===E.hourElement,d=r===E.minuteElement;l<o?(l=s+l+i(!f)+(i(f)&&i(!E.amPM)),d&&L(void 0,-1,E.hourElement)):l>s&&(l=r===E.hourElement?l-s-i(!E.amPM):o,d&&L(void 0,1,E.hourElement)),E.amPM&&f&&(1===c?l+u===23:Math.abs(l-u)>c)&&(E.amPM.textContent=E.l10n.amPM[i(E.amPM.textContent===E.l10n.amPM[0])]),r.value=a(l)}}(e);var r=E._input.value;x(),be(),E._input.value!==r&&E._debouncedChange()}function x(){if(void 0!==E.hourElement&&void 0!==E.minuteElement){var e,t,n=(parseInt(E.hourElement.value.slice(-2),10)||0)%24,r=(parseInt(E.minuteElement.value,10)||0)%60,o=void 0!==E.secondElement?(parseInt(E.secondElement.value,10)||0)%60:0;void 0!==E.amPM&&(e=n,t=E.amPM.textContent,n=e%12+12*i(t===E.l10n.amPM[1]));var a=void 0!==E.config.minTime||E.config.minDate&&E.minDateHasTime&&E.latestSelectedDateObj&&0===_(E.latestSelectedDateObj,E.config.minDate,!0);if(void 0!==E.config.maxTime||E.config.maxDate&&E.maxDateHasTime&&E.latestSelectedDateObj&&0===_(E.latestSelectedDateObj,E.config.maxDate,!0)){var s=void 0!==E.config.maxTime?E.config.maxTime:E.config.maxDate;(n=Math.min(n,s.getHours()))===s.getHours()&&(r=Math.min(r,s.getMinutes())),r===s.getMinutes()&&(o=Math.min(o,s.getSeconds()))}if(a){var c=void 0!==E.config.minTime?E.config.minTime:E.config.minDate;(n=Math.max(n,c.getHours()))===c.getHours()&&r<c.getMinutes()&&(r=c.getMinutes()),r===c.getMinutes()&&(o=Math.max(o,c.getSeconds()))}N(n,r,o)}}function I(e){var t=e||E.latestSelectedDateObj;t&&N(t.getHours(),t.getMinutes(),t.getSeconds())}function N(e,t,n){void 0!==E.latestSelectedDateObj&&E.latestSelectedDateObj.setHours(e%24,t,n||0,0),E.hourElement&&E.minuteElement&&!E.isMobile&&(E.hourElement.value=a(E.config.time_24hr?e:(12+e)%12+12*i(e%12==0)),E.minuteElement.value=a(t),void 0!==E.amPM&&(E.amPM.textContent=E.l10n.amPM[i(e>=12)]),void 0!==E.secondElement&&(E.secondElement.value=a(n)))}function P(e){var t=p(e),n=parseInt(t.value)+(e.delta||0);(n/1e3>1||"Enter"===e.key&&!/[^\d]/.test(n.toString()))&&Z(n)}function k(e,t,n,r){return t instanceof Array?t.forEach((function(t){return k(e,t,n,r)})):e instanceof Array?e.forEach((function(e){return k(e,t,n,r)})):(e.addEventListener(t,n,r),void E._handlers.push({remove:function(){return e.removeEventListener(t,n)}}))}function R(){ye("onChange")}function M(e,t){var n=void 0!==e?E.parseDate(e):E.latestSelectedDateObj||(E.config.minDate&&E.config.minDate>E.now?E.config.minDate:E.config.maxDate&&E.config.maxDate<E.now?E.config.maxDate:E.now),r=E.currentYear,o=E.currentMonth;try{void 0!==n&&(E.currentYear=n.getFullYear(),E.currentMonth=n.getMonth())}catch(e){e.message="Invalid date supplied: "+n,E.config.errorHandler(e)}t&&E.currentYear!==r&&(ye("onYearChange"),G()),!t||E.currentYear===r&&E.currentMonth===o||ye("onMonthChange"),E.redraw()}function F(e){var t=p(e);~t.className.indexOf("arrow")&&L(e,t.classList.contains("arrowUp")?1:-1)}function L(e,t,n){var r=e&&p(e),o=n||r&&r.parentNode&&r.parentNode.firstChild,a=ve("increment");a.delta=t,o&&o.dispatchEvent(a)}function H(e,t,n,r){var o=$(t,!0),a=l("span","flatpickr-day "+e,t.getDate().toString());return a.dateObj=t,a.$i=r,a.setAttribute("aria-label",E.formatDate(t,E.config.ariaDateFormat)),-1===e.indexOf("hidden")&&0===_(t,E.now)&&(E.todayDateElem=a,a.classList.add("today"),a.setAttribute("aria-current","date")),o?(a.tabIndex=-1,me(t)&&(a.classList.add("selected"),E.selectedDateElem=a,"range"===E.config.mode&&(u(a,"startRange",E.selectedDates[0]&&0===_(t,E.selectedDates[0],!0)),u(a,"endRange",E.selectedDates[1]&&0===_(t,E.selectedDates[1],!0)),"nextMonthDay"===e&&a.classList.add("inRange")))):a.classList.add("flatpickr-disabled"),"range"===E.config.mode&&function(e){return!("range"!==E.config.mode||E.selectedDates.length<2)&&_(e,E.selectedDates[0])>=0&&_(e,E.selectedDates[1])<=0}(t)&&!me(t)&&a.classList.add("inRange"),E.weekNumbers&&1===E.config.showMonths&&"prevMonthDay"!==e&&n%7==1&&E.weekNumbers.insertAdjacentHTML("beforeend","<span class='flatpickr-day'>"+E.config.getWeek(t)+"</span>"),ye("onDayCreate",a),a}function K(e){e.focus(),"range"===E.config.mode&&re(e)}function j(e){for(var t=e>0?0:E.config.showMonths-1,n=e>0?E.config.showMonths:-1,r=t;r!=n;r+=e)for(var o=E.daysContainer.children[r],a=e>0?0:o.children.length-1,i=e>0?o.children.length:-1,s=a;s!=i;s+=e){var c=o.children[s];if(-1===c.className.indexOf("hidden")&&$(c.dateObj))return c}}function U(e,t){var n=ee(document.activeElement||document.body),r=void 0!==e?e:n?document.activeElement:void 0!==E.selectedDateElem&&ee(E.selectedDateElem)?E.selectedDateElem:void 0!==E.todayDateElem&&ee(E.todayDateElem)?E.todayDateElem:j(t>0?1:-1);void 0===r?E._input.focus():n?function(e,t){for(var n=-1===e.className.indexOf("Month")?e.dateObj.getMonth():E.currentMonth,r=t>0?E.config.showMonths:-1,o=t>0?1:-1,a=n-E.currentMonth;a!=r;a+=o)for(var i=E.daysContainer.children[a],s=n-E.currentMonth===a?e.$i+t:t<0?i.children.length-1:0,c=i.children.length,u=s;u>=0&&u<c&&u!=(t>0?c:-1);u+=o){var l=i.children[u];if(-1===l.className.indexOf("hidden")&&$(l.dateObj)&&Math.abs(e.$i-u)>=Math.abs(t))return K(l)}E.changeMonth(o),U(j(o),0)}(r,t):K(r)}function B(e,t){for(var n=(new Date(e,t,1).getDay()-E.l10n.firstDayOfWeek+7)%7,r=E.utils.getDaysInMonth((t-1+12)%12,e),o=E.utils.getDaysInMonth(t,e),a=window.document.createDocumentFragment(),i=E.config.showMonths>1,s=i?"prevMonthDay hidden":"prevMonthDay",c=i?"nextMonthDay hidden":"nextMonthDay",u=r+1-n,f=0;u<=r;u++,f++)a.appendChild(H(s,new Date(e,t-1,u),u,f));for(u=1;u<=o;u++,f++)a.appendChild(H("",new Date(e,t,u),u,f));for(var d=o+1;d<=42-n&&(1===E.config.showMonths||f%7!=0);d++,f++)a.appendChild(H(c,new Date(e,t+1,d%o),d,f));var h=l("div","dayContainer");return h.appendChild(a),h}function V(){if(void 0!==E.daysContainer){f(E.daysContainer),E.weekNumbers&&f(E.weekNumbers);for(var e=document.createDocumentFragment(),t=0;t<E.config.showMonths;t++){var n=new Date(E.currentYear,E.currentMonth,1);n.setMonth(E.currentMonth+t),e.appendChild(B(n.getFullYear(),n.getMonth()))}E.daysContainer.appendChild(e),E.days=E.daysContainer.firstChild,"range"===E.config.mode&&1===E.selectedDates.length&&re()}}function G(){if(!(E.config.showMonths>1||"dropdown"!==E.config.monthSelectorType)){var e=function(e){return!(void 0!==E.config.minDate&&E.currentYear===E.config.minDate.getFullYear()&&e<E.config.minDate.getMonth()||void 0!==E.config.maxDate&&E.currentYear===E.config.maxDate.getFullYear()&&e>E.config.maxDate.getMonth())};E.monthsDropdownContainer.tabIndex=-1,E.monthsDropdownContainer.innerHTML="";for(var t=0;t<12;t++)if(e(t)){var n=l("option","flatpickr-monthDropdown-month");n.value=new Date(E.currentYear,t).getMonth().toString(),n.textContent=v(t,E.config.shorthandCurrentMonth,E.l10n),n.tabIndex=-1,E.currentMonth===t&&(n.selected=!0),E.monthsDropdownContainer.appendChild(n)}}}function Y(){var e,t=l("div","flatpickr-month"),n=window.document.createDocumentFragment();E.config.showMonths>1||"static"===E.config.monthSelectorType?e=l("span","cur-month"):(E.monthsDropdownContainer=l("select","flatpickr-monthDropdown-months"),E.monthsDropdownContainer.setAttribute("aria-label",E.l10n.monthAriaLabel),k(E.monthsDropdownContainer,"change",(function(e){var t=p(e),n=parseInt(t.value,10);E.changeMonth(n-E.currentMonth),ye("onMonthChange")})),G(),e=E.monthsDropdownContainer);var r=h("cur-year",{tabindex:"-1"}),o=r.getElementsByTagName("input")[0];o.setAttribute("aria-label",E.l10n.yearAriaLabel),E.config.minDate&&o.setAttribute("min",E.config.minDate.getFullYear().toString()),E.config.maxDate&&(o.setAttribute("max",E.config.maxDate.getFullYear().toString()),o.disabled=!!E.config.minDate&&E.config.minDate.getFullYear()===E.config.maxDate.getFullYear());var a=l("div","flatpickr-current-month");return a.appendChild(e),a.appendChild(r),n.appendChild(a),t.appendChild(n),{container:t,yearElement:o,monthElement:e}}function J(){f(E.monthNav),E.monthNav.appendChild(E.prevMonthNav),E.config.showMonths&&(E.yearElements=[],E.monthElements=[]);for(var e=E.config.showMonths;e--;){var t=Y();E.yearElements.push(t.yearElement),E.monthElements.push(t.monthElement),E.monthNav.appendChild(t.container)}E.monthNav.appendChild(E.nextMonthNav)}function q(){E.weekdayContainer?f(E.weekdayContainer):E.weekdayContainer=l("div","flatpickr-weekdays");for(var e=E.config.showMonths;e--;){var t=l("div","flatpickr-weekdaycontainer");E.weekdayContainer.appendChild(t)}return W(),E.weekdayContainer}function W(){if(E.weekdayContainer){var e=E.l10n.firstDayOfWeek,n=t(E.l10n.weekdays.shorthand);e>0&&e<n.length&&(n=t(n.splice(e,n.length),n.splice(0,e)));for(var r=E.config.showMonths;r--;)E.weekdayContainer.children[r].innerHTML="\n <span class='flatpickr-weekday'>\n "+n.join("</span><span class='flatpickr-weekday'>")+"\n </span>\n "}}function Q(e,t){void 0===t&&(t=!0);var n=t?e:e-E.currentMonth;n<0&&!0===E._hidePrevMonthArrow||n>0&&!0===E._hideNextMonthArrow||(E.currentMonth+=n,(E.currentMonth<0||E.currentMonth>11)&&(E.currentYear+=E.currentMonth>11?1:-1,E.currentMonth=(E.currentMonth+12)%12,ye("onYearChange"),G()),V(),ye("onMonthChange"),ge())}function z(e){return!(!E.config.appendTo||!E.config.appendTo.contains(e))||E.calendarContainer.contains(e)}function X(e){if(E.isOpen&&!E.config.inline){var t=p(e),n=z(t),r=t===E.input||t===E.altInput||E.element.contains(t)||e.path&&e.path.indexOf&&(~e.path.indexOf(E.input)||~e.path.indexOf(E.altInput)),o="blur"===e.type?r&&e.relatedTarget&&!z(e.relatedTarget):!r&&!n&&!z(e.relatedTarget),a=!E.config.ignoredFocusElements.some((function(e){return e.contains(t)}));o&&a&&(void 0!==E.timeContainer&&void 0!==E.minuteElement&&void 0!==E.hourElement&&""!==E.input.value&&void 0!==E.input.value&&C(),E.close(),E.config&&"range"===E.config.mode&&1===E.selectedDates.length&&(E.clear(!1),E.redraw()))}}function Z(e){if(!(!e||E.config.minDate&&e<E.config.minDate.getFullYear()||E.config.maxDate&&e>E.config.maxDate.getFullYear())){var t=e,n=E.currentYear!==t;E.currentYear=t||E.currentYear,E.config.maxDate&&E.currentYear===E.config.maxDate.getFullYear()?E.currentMonth=Math.min(E.config.maxDate.getMonth(),E.currentMonth):E.config.minDate&&E.currentYear===E.config.minDate.getFullYear()&&(E.currentMonth=Math.max(E.config.minDate.getMonth(),E.currentMonth)),n&&(E.redraw(),ye("onYearChange"),G())}}function $(e,t){var n;void 0===t&&(t=!0);var r=E.parseDate(e,void 0,t);if(E.config.minDate&&r&&_(r,E.config.minDate,void 0!==t?t:!E.minDateHasTime)<0||E.config.maxDate&&r&&_(r,E.config.maxDate,void 0!==t?t:!E.maxDateHasTime)>0)return!1;if(!E.config.enable&&0===E.config.disable.length)return!0;if(void 0===r)return!1;for(var o=!!E.config.enable,a=null!==(n=E.config.enable)&&void 0!==n?n:E.config.disable,i=0,s=void 0;i<a.length;i++){if("function"==typeof(s=a[i])&&s(r))return o;if(s instanceof Date&&void 0!==r&&s.getTime()===r.getTime())return o;if("string"==typeof s){var c=E.parseDate(s,void 0,!0);return c&&c.getTime()===r.getTime()?o:!o}if("object"==typeof s&&void 0!==r&&s.from&&s.to&&r.getTime()>=s.from.getTime()&&r.getTime()<=s.to.getTime())return o}return!o}function ee(e){return void 0!==E.daysContainer&&-1===e.className.indexOf("hidden")&&-1===e.className.indexOf("flatpickr-disabled")&&E.daysContainer.contains(e)}function te(e){e.target!==E._input||!(E.selectedDates.length>0||E._input.value.length>0)||e.relatedTarget&&z(e.relatedTarget)||E.setDate(E._input.value,!0,e.target===E.altInput?E.config.altFormat:E.config.dateFormat)}function ne(e){var t=p(e),n=E.config.wrap?y.contains(t):t===E._input,r=E.config.allowInput,o=E.isOpen&&(!r||!n),a=E.config.inline&&n&&!r;if(13===e.keyCode&&n){if(r)return E.setDate(E._input.value,!0,t===E.altInput?E.config.altFormat:E.config.dateFormat),t.blur();E.open()}else if(z(t)||o||a){var i=!!E.timeContainer&&E.timeContainer.contains(t);switch(e.keyCode){case 13:i?(e.preventDefault(),C(),le()):fe(e);break;case 27:e.preventDefault(),le();break;case 8:case 46:n&&!E.config.allowInput&&(e.preventDefault(),E.clear());break;case 37:case 39:if(i||n)E.hourElement&&E.hourElement.focus();else if(e.preventDefault(),void 0!==E.daysContainer&&(!1===r||document.activeElement&&ee(document.activeElement))){var s=39===e.keyCode?1:-1;e.ctrlKey?(e.stopPropagation(),Q(s),U(j(1),0)):U(void 0,s)}break;case 38:case 40:e.preventDefault();var c=40===e.keyCode?1:-1;E.daysContainer&&void 0!==t.$i||t===E.input||t===E.altInput?e.ctrlKey?(e.stopPropagation(),Z(E.currentYear-c),U(j(1),0)):i||U(void 0,7*c):t===E.currentYearElement?Z(E.currentYear-c):E.config.enableTime&&(!i&&E.hourElement&&E.hourElement.focus(),C(e),E._debouncedChange());break;case 9:if(i){var u=[E.hourElement,E.minuteElement,E.secondElement,E.amPM].concat(E.pluginElements).filter((function(e){return e})),l=u.indexOf(t);if(-1!==l){var f=u[l+(e.shiftKey?-1:1)];e.preventDefault(),(f||E._input).focus()}}else!E.config.noCalendar&&E.daysContainer&&E.daysContainer.contains(t)&&e.shiftKey&&(e.preventDefault(),E._input.focus())}}if(void 0!==E.amPM&&t===E.amPM)switch(e.key){case E.l10n.amPM[0].charAt(0):case E.l10n.amPM[0].charAt(0).toLowerCase():E.amPM.textContent=E.l10n.amPM[0],x(),be();break;case E.l10n.amPM[1].charAt(0):case E.l10n.amPM[1].charAt(0).toLowerCase():E.amPM.textContent=E.l10n.amPM[1],x(),be()}(n||z(t))&&ye("onKeyDown",e)}function re(e){if(1===E.selectedDates.length&&(!e||e.classList.contains("flatpickr-day")&&!e.classList.contains("flatpickr-disabled"))){for(var t=e?e.dateObj.getTime():E.days.firstElementChild.dateObj.getTime(),n=E.parseDate(E.selectedDates[0],void 0,!0).getTime(),r=Math.min(t,E.selectedDates[0].getTime()),o=Math.max(t,E.selectedDates[0].getTime()),a=!1,i=0,s=0,c=r;c<o;c+=w)$(new Date(c),!0)||(a=a||c>r&&c<o,c<n&&(!i||c>i)?i=c:c>n&&(!s||c<s)&&(s=c));for(var u=0;u<E.config.showMonths;u++)for(var l=E.daysContainer.children[u],f=function(r,o){var c,u,f,d=l.children[r],h=d.dateObj.getTime(),p=i>0&&h<i||s>0&&h>s;return p?(d.classList.add("notAllowed"),["inRange","startRange","endRange"].forEach((function(e){d.classList.remove(e)})),"continue"):a&&!p?"continue":(["startRange","inRange","endRange","notAllowed"].forEach((function(e){d.classList.remove(e)})),void(void 0!==e&&(e.classList.add(t<=E.selectedDates[0].getTime()?"startRange":"endRange"),n<t&&h===n?d.classList.add("startRange"):n>t&&h===n&&d.classList.add("endRange"),h>=i&&(0===s||h<=s)&&(u=n,f=t,(c=h)>Math.min(u,f)&&c<Math.max(u,f))&&d.classList.add("inRange"))))},d=0,h=l.children.length;d<h;d++)f(d)}}function oe(){!E.isOpen||E.config.static||E.config.inline||ce()}function ae(e){return function(t){var n=E.config["_"+e+"Date"]=E.parseDate(t,E.config.dateFormat),r=E.config["_"+("min"===e?"max":"min")+"Date"];void 0!==n&&(E["min"===e?"minDateHasTime":"maxDateHasTime"]=n.getHours()>0||n.getMinutes()>0||n.getSeconds()>0),E.selectedDates&&(E.selectedDates=E.selectedDates.filter((function(e){return $(e)})),E.selectedDates.length||"min"!==e||I(n),be()),E.daysContainer&&(ue(),void 0!==n?E.currentYearElement[e]=n.getFullYear().toString():E.currentYearElement.removeAttribute(e),E.currentYearElement.disabled=!!r&&void 0!==n&&r.getFullYear()===n.getFullYear())}}function ie(){return E.config.wrap?y.querySelector("[data-input]"):y}function se(){"object"!=typeof E.config.locale&&void 0===T.l10ns[E.config.locale]&&E.config.errorHandler(new Error("flatpickr: invalid locale "+E.config.locale)),E.l10n=e(e({},T.l10ns.default),"object"==typeof E.config.locale?E.config.locale:"default"!==E.config.locale?T.l10ns[E.config.locale]:void 0),g.K="("+E.l10n.amPM[0]+"|"+E.l10n.amPM[1]+"|"+E.l10n.amPM[0].toLowerCase()+"|"+E.l10n.amPM[1].toLowerCase()+")",void 0===e(e({},m),JSON.parse(JSON.stringify(y.dataset||{}))).time_24hr&&void 0===T.defaultConfig.time_24hr&&(E.config.time_24hr=E.l10n.time_24hr),E.formatDate=b(E),E.parseDate=A({config:E.config,l10n:E.l10n})}function ce(e){if("function"!=typeof E.config.position){if(void 0!==E.calendarContainer){ye("onPreCalendarPosition");var t=e||E._positionElement,n=Array.prototype.reduce.call(E.calendarContainer.children,(function(e,t){return e+t.offsetHeight}),0),r=E.calendarContainer.offsetWidth,o=E.config.position.split(" "),a=o[0],i=o.length>1?o[1]:null,s=t.getBoundingClientRect(),c=window.innerHeight-s.bottom,l="above"===a||"below"!==a&&c<n&&s.top>n,f=window.pageYOffset+s.top+(l?-n-2:t.offsetHeight+2);if(u(E.calendarContainer,"arrowTop",!l),u(E.calendarContainer,"arrowBottom",l),!E.config.inline){var d=window.pageXOffset+s.left,h=!1,p=!1;"center"===i?(d-=(r-s.width)/2,h=!0):"right"===i&&(d-=r-s.width,p=!0),u(E.calendarContainer,"arrowLeft",!h&&!p),u(E.calendarContainer,"arrowCenter",h),u(E.calendarContainer,"arrowRight",p);var y=window.document.body.offsetWidth-(window.pageXOffset+s.right),v=d+r>window.document.body.offsetWidth,m=y+r>window.document.body.offsetWidth;if(u(E.calendarContainer,"rightMost",v),!E.config.static)if(E.calendarContainer.style.top=f+"px",v)if(m){var g=function(){for(var e=null,t=0;t<document.styleSheets.length;t++){var n=document.styleSheets[t];try{n.cssRules}catch(e){continue}e=n;break}return null!=e?e:(r=document.createElement("style"),document.head.appendChild(r),r.sheet);var r}();if(void 0===g)return;var b=window.document.body.offsetWidth,A=Math.max(0,b/2-r/2),_=g.cssRules.length,w="{left:"+s.left+"px;right:auto;}";u(E.calendarContainer,"rightMost",!1),u(E.calendarContainer,"centerMost",!0),g.insertRule(".flatpickr-calendar.centerMost:before,.flatpickr-calendar.centerMost:after"+w,_),E.calendarContainer.style.left=A+"px",E.calendarContainer.style.right="auto"}else E.calendarContainer.style.left="auto",E.calendarContainer.style.right=y+"px";else E.calendarContainer.style.left=d+"px",E.calendarContainer.style.right="auto"}}}else E.config.position(E,e)}function ue(){E.config.noCalendar||E.isMobile||(G(),ge(),V())}function le(){E._input.focus(),-1!==window.navigator.userAgent.indexOf("MSIE")||void 0!==navigator.msMaxTouchPoints?setTimeout(E.close,0):E.close()}function fe(e){e.preventDefault(),e.stopPropagation();var t=d(p(e),(function(e){return e.classList&&e.classList.contains("flatpickr-day")&&!e.classList.contains("flatpickr-disabled")&&!e.classList.contains("notAllowed")}));if(void 0!==t){var n=t,r=E.latestSelectedDateObj=new Date(n.dateObj.getTime()),o=(r.getMonth()<E.currentMonth||r.getMonth()>E.currentMonth+E.config.showMonths-1)&&"range"!==E.config.mode;if(E.selectedDateElem=n,"single"===E.config.mode)E.selectedDates=[r];else if("multiple"===E.config.mode){var a=me(r);a?E.selectedDates.splice(parseInt(a),1):E.selectedDates.push(r)}else"range"===E.config.mode&&(2===E.selectedDates.length&&E.clear(!1,!1),E.latestSelectedDateObj=r,E.selectedDates.push(r),0!==_(r,E.selectedDates[0],!0)&&E.selectedDates.sort((function(e,t){return e.getTime()-t.getTime()})));if(x(),o){var i=E.currentYear!==r.getFullYear();E.currentYear=r.getFullYear(),E.currentMonth=r.getMonth(),i&&(ye("onYearChange"),G()),ye("onMonthChange")}if(ge(),V(),be(),o||"range"===E.config.mode||1!==E.config.showMonths?void 0!==E.selectedDateElem&&void 0===E.hourElement&&E.selectedDateElem&&E.selectedDateElem.focus():K(n),void 0!==E.hourElement&&void 0!==E.hourElement&&E.hourElement.focus(),E.config.closeOnSelect){var s="single"===E.config.mode&&!E.config.enableTime,c="range"===E.config.mode&&2===E.selectedDates.length&&!E.config.enableTime;(s||c)&&le()}R()}}E.parseDate=A({config:E.config,l10n:E.l10n}),E._handlers=[],E.pluginElements=[],E.loadedPlugins=[],E._bind=k,E._setHoursFromDate=I,E._positionCalendar=ce,E.changeMonth=Q,E.changeYear=Z,E.clear=function(e,t){if(void 0===e&&(e=!0),void 0===t&&(t=!0),E.input.value="",void 0!==E.altInput&&(E.altInput.value=""),void 0!==E.mobileInput&&(E.mobileInput.value=""),E.selectedDates=[],E.latestSelectedDateObj=void 0,!0===t&&(E.currentYear=E._initialDate.getFullYear(),E.currentMonth=E._initialDate.getMonth()),!0===E.config.enableTime){var n=O(E.config);N(n.hours,n.minutes,n.seconds)}E.redraw(),e&&ye("onChange")},E.close=function(){E.isOpen=!1,E.isMobile||(void 0!==E.calendarContainer&&E.calendarContainer.classList.remove("open"),void 0!==E._input&&E._input.classList.remove("active")),ye("onClose")},E._createElement=l,E.destroy=function(){void 0!==E.config&&ye("onDestroy");for(var e=E._handlers.length;e--;)E._handlers[e].remove();if(E._handlers=[],E.mobileInput)E.mobileInput.parentNode&&E.mobileInput.parentNode.removeChild(E.mobileInput),E.mobileInput=void 0;else if(E.calendarContainer&&E.calendarContainer.parentNode)if(E.config.static&&E.calendarContainer.parentNode){var t=E.calendarContainer.parentNode;if(t.lastChild&&t.removeChild(t.lastChild),t.parentNode){for(;t.firstChild;)t.parentNode.insertBefore(t.firstChild,t);t.parentNode.removeChild(t)}}else E.calendarContainer.parentNode.removeChild(E.calendarContainer);E.altInput&&(E.input.type="text",E.altInput.parentNode&&E.altInput.parentNode.removeChild(E.altInput),delete E.altInput),E.input&&(E.input.type=E.input._type,E.input.classList.remove("flatpickr-input"),E.input.removeAttribute("readonly")),["_showTimeInput","latestSelectedDateObj","_hideNextMonthArrow","_hidePrevMonthArrow","__hideNextMonthArrow","__hidePrevMonthArrow","isMobile","isOpen","selectedDateElem","minDateHasTime","maxDateHasTime","days","daysContainer","_input","_positionElement","innerContainer","rContainer","monthNav","todayDateElem","calendarContainer","weekdayContainer","prevMonthNav","nextMonthNav","monthsDropdownContainer","currentMonthElement","currentYearElement","navigationCurrentMonth","selectedDateElem","config"].forEach((function(e){try{delete E[e]}catch(e){}}))},E.isEnabled=$,E.jumpToDate=M,E.open=function(e,t){if(void 0===t&&(t=E._positionElement),!0===E.isMobile){if(e){e.preventDefault();var n=p(e);n&&n.blur()}return void 0!==E.mobileInput&&(E.mobileInput.focus(),E.mobileInput.click()),void ye("onOpen")}if(!E._input.disabled&&!E.config.inline){var r=E.isOpen;E.isOpen=!0,r||(E.calendarContainer.classList.add("open"),E._input.classList.add("active"),ye("onOpen"),ce(t)),!0===E.config.enableTime&&!0===E.config.noCalendar&&(!1!==E.config.allowInput||void 0!==e&&E.timeContainer.contains(e.relatedTarget)||setTimeout((function(){return E.hourElement.select()}),50))}},E.redraw=ue,E.set=function(e,t){if(null!==e&&"object"==typeof e)for(var r in Object.assign(E.config,e),e)void 0!==de[r]&&de[r].forEach((function(e){return e()}));else E.config[e]=t,void 0!==de[e]?de[e].forEach((function(e){return e()})):n.indexOf(e)>-1&&(E.config[e]=c(t));E.redraw(),be(!0)},E.setDate=function(e,t,n){if(void 0===t&&(t=!1),void 0===n&&(n=E.config.dateFormat),0!==e&&!e||e instanceof Array&&0===e.length)return E.clear(t);he(e,n),E.latestSelectedDateObj=E.selectedDates[E.selectedDates.length-1],E.redraw(),M(void 0,t),I(),0===E.selectedDates.length&&E.clear(!1),be(t),t&&ye("onChange")},E.toggle=function(e){if(!0===E.isOpen)return E.close();E.open(e)};var de={locale:[se,W],showMonths:[J,S,q],minDate:[M],maxDate:[M],clickOpens:[function(){!0===E.config.clickOpens?(k(E._input,"focus",E.open),k(E._input,"click",E.open)):(E._input.removeEventListener("focus",E.open),E._input.removeEventListener("click",E.open))}]};function he(e,t){var n=[];if(e instanceof Array)n=e.map((function(e){return E.parseDate(e,t)}));else if(e instanceof Date||"number"==typeof e)n=[E.parseDate(e,t)];else if("string"==typeof e)switch(E.config.mode){case"single":case"time":n=[E.parseDate(e,t)];break;case"multiple":n=e.split(E.config.conjunction).map((function(e){return E.parseDate(e,t)}));break;case"range":n=e.split(E.l10n.rangeSeparator).map((function(e){return E.parseDate(e,t)}))}else E.config.errorHandler(new Error("Invalid date supplied: "+JSON.stringify(e)));E.selectedDates=E.config.allowInvalidPreload?n:n.filter((function(e){return e instanceof Date&&$(e,!1)})),"range"===E.config.mode&&E.selectedDates.sort((function(e,t){return e.getTime()-t.getTime()}))}function pe(e){return e.slice().map((function(e){return"string"==typeof e||"number"==typeof e||e instanceof Date?E.parseDate(e,void 0,!0):e&&"object"==typeof e&&e.from&&e.to?{from:E.parseDate(e.from,void 0),to:E.parseDate(e.to,void 0)}:e})).filter((function(e){return e}))}function ye(e,t){if(void 0!==E.config){var n=E.config[e];if(void 0!==n&&n.length>0)for(var r=0;n[r]&&r<n.length;r++)n[r](E.selectedDates,E.input.value,E,t);"onChange"===e&&(E.input.dispatchEvent(ve("change")),E.input.dispatchEvent(ve("input")))}}function ve(e){var t=document.createEvent("Event");return t.initEvent(e,!0,!0),t}function me(e){for(var t=0;t<E.selectedDates.length;t++)if(0===_(E.selectedDates[t],e))return""+t;return!1}function ge(){E.config.noCalendar||E.isMobile||!E.monthNav||(E.yearElements.forEach((function(e,t){var n=new Date(E.currentYear,E.currentMonth,1);n.setMonth(E.currentMonth+t),E.config.showMonths>1||"static"===E.config.monthSelectorType?E.monthElements[t].textContent=v(n.getMonth(),E.config.shorthandCurrentMonth,E.l10n)+" ":E.monthsDropdownContainer.value=n.getMonth().toString(),e.value=n.getFullYear().toString()})),E._hidePrevMonthArrow=void 0!==E.config.minDate&&(E.currentYear===E.config.minDate.getFullYear()?E.currentMonth<=E.config.minDate.getMonth():E.currentYear<E.config.minDate.getFullYear()),E._hideNextMonthArrow=void 0!==E.config.maxDate&&(E.currentYear===E.config.maxDate.getFullYear()?E.currentMonth+1>E.config.maxDate.getMonth():E.currentYear>E.config.maxDate.getFullYear()))}function Ee(e){return E.selectedDates.map((function(t){return E.formatDate(t,e)})).filter((function(e,t,n){return"range"!==E.config.mode||E.config.enableTime||n.indexOf(e)===t})).join("range"!==E.config.mode?E.config.conjunction:E.l10n.rangeSeparator)}function be(e){void 0===e&&(e=!0),void 0!==E.mobileInput&&E.mobileFormatStr&&(E.mobileInput.value=void 0!==E.latestSelectedDateObj?E.formatDate(E.latestSelectedDateObj,E.mobileFormatStr):""),E.input.value=Ee(E.config.dateFormat),void 0!==E.altInput&&(E.altInput.value=Ee(E.config.altFormat)),!1!==e&&ye("onValueUpdate")}function Ae(e){var t=p(e),n=E.prevMonthNav.contains(t),r=E.nextMonthNav.contains(t);n||r?Q(n?-1:1):E.yearElements.indexOf(t)>=0?t.select():t.classList.contains("arrowUp")?E.changeYear(E.currentYear+1):t.classList.contains("arrowDown")&&E.changeYear(E.currentYear-1)}return function(){E.element=E.input=y,E.isOpen=!1,function(){var t=["wrap","weekNumbers","allowInput","allowInvalidPreload","clickOpens","time_24hr","enableTime","noCalendar","altInput","shorthandCurrentMonth","inline","static","enableSeconds","disableMobile"],o=e(e({},JSON.parse(JSON.stringify(y.dataset||{}))),m),a={};E.config.parseDate=o.parseDate,E.config.formatDate=o.formatDate,Object.defineProperty(E.config,"enable",{get:function(){return E.config._enable},set:function(e){E.config._enable=pe(e)}}),Object.defineProperty(E.config,"disable",{get:function(){return E.config._disable},set:function(e){E.config._disable=pe(e)}});var i="time"===o.mode;if(!o.dateFormat&&(o.enableTime||i)){var s=T.defaultConfig.dateFormat||r.dateFormat;a.dateFormat=o.noCalendar||i?"H:i"+(o.enableSeconds?":S":""):s+" H:i"+(o.enableSeconds?":S":"")}if(o.altInput&&(o.enableTime||i)&&!o.altFormat){var u=T.defaultConfig.altFormat||r.altFormat;a.altFormat=o.noCalendar||i?"h:i"+(o.enableSeconds?":S K":" K"):u+" h:i"+(o.enableSeconds?":S":"")+" K"}Object.defineProperty(E.config,"minDate",{get:function(){return E.config._minDate},set:ae("min")}),Object.defineProperty(E.config,"maxDate",{get:function(){return E.config._maxDate},set:ae("max")});var l=function(e){return function(t){E.config["min"===e?"_minTime":"_maxTime"]=E.parseDate(t,"H:i:S")}};Object.defineProperty(E.config,"minTime",{get:function(){return E.config._minTime},set:l("min")}),Object.defineProperty(E.config,"maxTime",{get:function(){return E.config._maxTime},set:l("max")}),"time"===o.mode&&(E.config.noCalendar=!0,E.config.enableTime=!0),Object.assign(E.config,a,o);for(var f=0;f<t.length;f++)E.config[t[f]]=!0===E.config[t[f]]||"true"===E.config[t[f]];for(n.filter((function(e){return void 0!==E.config[e]})).forEach((function(e){E.config[e]=c(E.config[e]||[]).map(D)})),E.isMobile=!E.config.disableMobile&&!E.config.inline&&"single"===E.config.mode&&!E.config.disable.length&&!E.config.enable&&!E.config.weekNumbers&&/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),f=0;f<E.config.plugins.length;f++){var d=E.config.plugins[f](E)||{};for(var h in d)n.indexOf(h)>-1?E.config[h]=c(d[h]).map(D).concat(E.config[h]):void 0===o[h]&&(E.config[h]=d[h])}o.altInputClass||(E.config.altInputClass=ie().className+" "+E.config.altInputClass),ye("onParseConfig")}(),se(),E.input=ie(),E.input?(E.input._type=E.input.type,E.input.type="text",E.input.classList.add("flatpickr-input"),E._input=E.input,E.config.altInput&&(E.altInput=l(E.input.nodeName,E.config.altInputClass),E._input=E.altInput,E.altInput.placeholder=E.input.placeholder,E.altInput.disabled=E.input.disabled,E.altInput.required=E.input.required,E.altInput.tabIndex=E.input.tabIndex,E.altInput.type="text",E.input.setAttribute("type","hidden"),!E.config.static&&E.input.parentNode&&E.input.parentNode.insertBefore(E.altInput,E.input.nextSibling)),E.config.allowInput||E._input.setAttribute("readonly","readonly"),E._positionElement=E.config.positionElement||E._input):E.config.errorHandler(new Error("Invalid input element specified")),function(){E.selectedDates=[],E.now=E.parseDate(E.config.now)||new Date;var e=E.config.defaultDate||("INPUT"!==E.input.nodeName&&"TEXTAREA"!==E.input.nodeName||!E.input.placeholder||E.input.value!==E.input.placeholder?E.input.value:null);e&&he(e,E.config.dateFormat),E._initialDate=E.selectedDates.length>0?E.selectedDates[0]:E.config.minDate&&E.config.minDate.getTime()>E.now.getTime()?E.config.minDate:E.config.maxDate&&E.config.maxDate.getTime()<E.now.getTime()?E.config.maxDate:E.now,E.currentYear=E._initialDate.getFullYear(),E.currentMonth=E._initialDate.getMonth(),E.selectedDates.length>0&&(E.latestSelectedDateObj=E.selectedDates[0]),void 0!==E.config.minTime&&(E.config.minTime=E.parseDate(E.config.minTime,"H:i")),void 0!==E.config.maxTime&&(E.config.maxTime=E.parseDate(E.config.maxTime,"H:i")),E.minDateHasTime=!!E.config.minDate&&(E.config.minDate.getHours()>0||E.config.minDate.getMinutes()>0||E.config.minDate.getSeconds()>0),E.maxDateHasTime=!!E.config.maxDate&&(E.config.maxDate.getHours()>0||E.config.maxDate.getMinutes()>0||E.config.maxDate.getSeconds()>0)}(),E.utils={getDaysInMonth:function(e,t){return void 0===e&&(e=E.currentMonth),void 0===t&&(t=E.currentYear),1===e&&(t%4==0&&t%100!=0||t%400==0)?29:E.l10n.daysInMonth[e]}},E.isMobile||function(){var e=window.document.createDocumentFragment();if(E.calendarContainer=l("div","flatpickr-calendar"),E.calendarContainer.tabIndex=-1,!E.config.noCalendar){if(e.appendChild((E.monthNav=l("div","flatpickr-months"),E.yearElements=[],E.monthElements=[],E.prevMonthNav=l("span","flatpickr-prev-month"),E.prevMonthNav.innerHTML=E.config.prevArrow,E.nextMonthNav=l("span","flatpickr-next-month"),E.nextMonthNav.innerHTML=E.config.nextArrow,J(),Object.defineProperty(E,"_hidePrevMonthArrow",{get:function(){return E.__hidePrevMonthArrow},set:function(e){E.__hidePrevMonthArrow!==e&&(u(E.prevMonthNav,"flatpickr-disabled",e),E.__hidePrevMonthArrow=e)}}),Object.defineProperty(E,"_hideNextMonthArrow",{get:function(){return E.__hideNextMonthArrow},set:function(e){E.__hideNextMonthArrow!==e&&(u(E.nextMonthNav,"flatpickr-disabled",e),E.__hideNextMonthArrow=e)}}),E.currentYearElement=E.yearElements[0],ge(),E.monthNav)),E.innerContainer=l("div","flatpickr-innerContainer"),E.config.weekNumbers){var t=function(){E.calendarContainer.classList.add("hasWeeks");var e=l("div","flatpickr-weekwrapper");e.appendChild(l("span","flatpickr-weekday",E.l10n.weekAbbreviation));var t=l("div","flatpickr-weeks");return e.appendChild(t),{weekWrapper:e,weekNumbers:t}}(),n=t.weekWrapper,r=t.weekNumbers;E.innerContainer.appendChild(n),E.weekNumbers=r,E.weekWrapper=n}E.rContainer=l("div","flatpickr-rContainer"),E.rContainer.appendChild(q()),E.daysContainer||(E.daysContainer=l("div","flatpickr-days"),E.daysContainer.tabIndex=-1),V(),E.rContainer.appendChild(E.daysContainer),E.innerContainer.appendChild(E.rContainer),e.appendChild(E.innerContainer)}E.config.enableTime&&e.appendChild(function(){E.calendarContainer.classList.add("hasTime"),E.config.noCalendar&&E.calendarContainer.classList.add("noCalendar");var e=O(E.config);E.timeContainer=l("div","flatpickr-time"),E.timeContainer.tabIndex=-1;var t=l("span","flatpickr-time-separator",":"),n=h("flatpickr-hour",{"aria-label":E.l10n.hourAriaLabel});E.hourElement=n.getElementsByTagName("input")[0];var r=h("flatpickr-minute",{"aria-label":E.l10n.minuteAriaLabel});if(E.minuteElement=r.getElementsByTagName("input")[0],E.hourElement.tabIndex=E.minuteElement.tabIndex=-1,E.hourElement.value=a(E.latestSelectedDateObj?E.latestSelectedDateObj.getHours():E.config.time_24hr?e.hours:function(e){switch(e%24){case 0:case 12:return 12;default:return e%12}}(e.hours)),E.minuteElement.value=a(E.latestSelectedDateObj?E.latestSelectedDateObj.getMinutes():e.minutes),E.hourElement.setAttribute("step",E.config.hourIncrement.toString()),E.minuteElement.setAttribute("step",E.config.minuteIncrement.toString()),E.hourElement.setAttribute("min",E.config.time_24hr?"0":"1"),E.hourElement.setAttribute("max",E.config.time_24hr?"23":"12"),E.hourElement.setAttribute("maxlength","2"),E.minuteElement.setAttribute("min","0"),E.minuteElement.setAttribute("max","59"),E.minuteElement.setAttribute("maxlength","2"),E.timeContainer.appendChild(n),E.timeContainer.appendChild(t),E.timeContainer.appendChild(r),E.config.time_24hr&&E.timeContainer.classList.add("time24hr"),E.config.enableSeconds){E.timeContainer.classList.add("hasSeconds");var o=h("flatpickr-second");E.secondElement=o.getElementsByTagName("input")[0],E.secondElement.value=a(E.latestSelectedDateObj?E.latestSelectedDateObj.getSeconds():e.seconds),E.secondElement.setAttribute("step",E.minuteElement.getAttribute("step")),E.secondElement.setAttribute("min","0"),E.secondElement.setAttribute("max","59"),E.secondElement.setAttribute("maxlength","2"),E.timeContainer.appendChild(l("span","flatpickr-time-separator",":")),E.timeContainer.appendChild(o)}return E.config.time_24hr||(E.amPM=l("span","flatpickr-am-pm",E.l10n.amPM[i((E.latestSelectedDateObj?E.hourElement.value:E.config.defaultHour)>11)]),E.amPM.title=E.l10n.toggleTitle,E.amPM.tabIndex=-1,E.timeContainer.appendChild(E.amPM)),E.timeContainer}()),u(E.calendarContainer,"rangeMode","range"===E.config.mode),u(E.calendarContainer,"animate",!0===E.config.animate),u(E.calendarContainer,"multiMonth",E.config.showMonths>1),E.calendarContainer.appendChild(e);var o=void 0!==E.config.appendTo&&void 0!==E.config.appendTo.nodeType;if((E.config.inline||E.config.static)&&(E.calendarContainer.classList.add(E.config.inline?"inline":"static"),E.config.inline&&(!o&&E.element.parentNode?E.element.parentNode.insertBefore(E.calendarContainer,E._input.nextSibling):void 0!==E.config.appendTo&&E.config.appendTo.appendChild(E.calendarContainer)),E.config.static)){var s=l("div","flatpickr-wrapper");E.element.parentNode&&E.element.parentNode.insertBefore(s,E.element),s.appendChild(E.element),E.altInput&&s.appendChild(E.altInput),s.appendChild(E.calendarContainer)}E.config.static||E.config.inline||(void 0!==E.config.appendTo?E.config.appendTo:window.document.body).appendChild(E.calendarContainer)}(),function(){if(E.config.wrap&&["open","close","toggle","clear"].forEach((function(e){Array.prototype.forEach.call(E.element.querySelectorAll("[data-"+e+"]"),(function(t){return k(t,"click",E[e])}))})),E.isMobile)!function(){var e=E.config.enableTime?E.config.noCalendar?"time":"datetime-local":"date";E.mobileInput=l("input",E.input.className+" flatpickr-mobile"),E.mobileInput.tabIndex=1,E.mobileInput.type=e,E.mobileInput.disabled=E.input.disabled,E.mobileInput.required=E.input.required,E.mobileInput.placeholder=E.input.placeholder,E.mobileFormatStr="datetime-local"===e?"Y-m-d\\TH:i:S":"date"===e?"Y-m-d":"H:i:S",E.selectedDates.length>0&&(E.mobileInput.defaultValue=E.mobileInput.value=E.formatDate(E.selectedDates[0],E.mobileFormatStr)),E.config.minDate&&(E.mobileInput.min=E.formatDate(E.config.minDate,"Y-m-d")),E.config.maxDate&&(E.mobileInput.max=E.formatDate(E.config.maxDate,"Y-m-d")),E.input.getAttribute("step")&&(E.mobileInput.step=String(E.input.getAttribute("step"))),E.input.type="hidden",void 0!==E.altInput&&(E.altInput.type="hidden");try{E.input.parentNode&&E.input.parentNode.insertBefore(E.mobileInput,E.input.nextSibling)}catch(e){}k(E.mobileInput,"change",(function(e){E.setDate(p(e).value,!1,E.mobileFormatStr),ye("onChange"),ye("onClose")}))}();else{var e=s(oe,50);if(E._debouncedChange=s(R,300),E.daysContainer&&!/iPhone|iPad|iPod/i.test(navigator.userAgent)&&k(E.daysContainer,"mouseover",(function(e){"range"===E.config.mode&&re(p(e))})),k(window.document.body,"keydown",ne),E.config.inline||E.config.static||k(window,"resize",e),void 0!==window.ontouchstart?k(window.document,"touchstart",X):k(window.document,"mousedown",X),k(window.document,"focus",X,{capture:!0}),!0===E.config.clickOpens&&(k(E._input,"focus",E.open),k(E._input,"click",E.open)),void 0!==E.daysContainer&&(k(E.monthNav,"click",Ae),k(E.monthNav,["keyup","increment"],P),k(E.daysContainer,"click",fe)),void 0!==E.timeContainer&&void 0!==E.minuteElement&&void 0!==E.hourElement){var t=function(e){return p(e).select()};k(E.timeContainer,["increment"],C),k(E.timeContainer,"blur",C,{capture:!0}),k(E.timeContainer,"click",F),k([E.hourElement,E.minuteElement],["focus","click"],t),void 0!==E.secondElement&&k(E.secondElement,"focus",(function(){return E.secondElement&&E.secondElement.select()})),void 0!==E.amPM&&k(E.amPM,"click",(function(e){C(e),R()}))}E.config.allowInput&&k(E._input,"blur",te)}}(),(E.selectedDates.length||E.config.noCalendar)&&(E.config.enableTime&&I(E.config.noCalendar?E.latestSelectedDateObj:void 0),be(!1)),S();var t=/^((?!chrome|android).)*safari/i.test(navigator.userAgent);!E.isMobile&&t&&ce(),ye("onReady")}(),E}function S(e,t){for(var n=Array.prototype.slice.call(e).filter((function(e){return e instanceof HTMLElement})),r=[],o=0;o<n.length;o++){var a=n[o];try{if(null!==a.getAttribute("data-fp-omit"))continue;void 0!==a._flatpickr&&(a._flatpickr.destroy(),a._flatpickr=void 0),a._flatpickr=D(a,t||{}),r.push(a._flatpickr)}catch(e){console.error(e)}}return 1===r.length?r[0]:r}"function"!=typeof Object.assign&&(Object.assign=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(!e)throw TypeError("Cannot convert undefined or null to object");for(var r=function(t){t&&Object.keys(t).forEach((function(n){return e[n]=t[n]}))},o=0,a=t;o<a.length;o++)r(a[o]);return e}),"undefined"!=typeof HTMLElement&&"undefined"!=typeof HTMLCollection&&"undefined"!=typeof NodeList&&(HTMLCollection.prototype.flatpickr=NodeList.prototype.flatpickr=function(e){return S(this,e)},HTMLElement.prototype.flatpickr=function(e){return S([this],e)});var T=function(e,t){return"string"==typeof e?S(window.document.querySelectorAll(e),t):e instanceof Node?S([e],t):S(e,t)};return T.defaultConfig={},T.l10ns={en:e({},o),default:e({},o)},T.localize=function(t){T.l10ns.default=e(e({},T.l10ns.default),t)},T.setDefaults=function(t){T.defaultConfig=e(e({},T.defaultConfig),t)},T.parseDate=A({}),T.formatDate=b({}),T.compareDates=_,"undefined"!=typeof jQuery&&void 0!==jQuery.fn&&(jQuery.fn.flatpickr=function(e){return S(this,e)}),Date.prototype.fp_incr=function(e){return new Date(this.getFullYear(),this.getMonth(),this.getDate()+("string"==typeof e?parseInt(e,10):e))},"undefined"!=typeof window&&(window.flatpickr=T),T}()}(Sr)),Sr.exports}function Cr(){if(Dr)return Or;Dr=1;return Or=((e,t,n,r,o,a,i,s,c,u,l)=>{var f={setCustomize:()=>{}},d=function(e,t){if(!t||1===t)return e.store;var n=e.store.modules&&e.store.modules.team;return n?n.getTeam(t):void 0},h=function(t,n){t.emit("UPDATE",{teams:n.stores,roTeams:n.roStores,id:n.channel,loading:!n.ready&&!n.cacheready,readOnly:n.readOnly||!n.ready&&n.cacheready||n.offline,offline:n.offline,deleted:!n.stores.length,restricted:n.restricted,owned:t.Store.isOwned(n.owners),content:e.clone(n.proxy),hashes:n.hashes},t.clients)},p=function(e,t){var n=e.calendars[t];n&&n.reminders&&Object.keys(n.reminders).forEach((function(e){Array.isArray(n.reminders[e])&&n.reminders[e].forEach((function(e){clearTimeout(e)}))}))},y=function(e,t){var n=e.calendars[t];n&&(n.stores.length||(n.lm.stop(),p(e,t),delete e.calendars[t]))},v=function(e,t,n){t.stores.forEach((function(r){var o=d(e,r);if(o&&o.proxy&&o.rpc&&o.proxy.calendars){var a=o.proxy.calendars[t.channel];a&&(a.color!==n.color&&(a.color=n.color),a.title!==n.title&&(a.title=n.title))}}))},m=function(t,n,r,o){var a=+new Date,i=e.clone(r),s=i.id;if(Array.isArray(n[s])&&n[s].forEach((function(e){clearTimeout(e)})),n[s]=[],!r.deleted){var u=e.find(t,["store","proxy","hideReminders",s])||[],l=t.store.data.lastVisit;if(i.isAllDay&&(i.startDay&&(i.start=+c.parseDate(i.startDay)),i.endDay)){var f=c.parseDate(i.endDay);f.setHours(23),f.setMinutes(59),f.setSeconds(59),i.end=+f}var d=a-6048e5,h=o&&i.start>l&&i.end<=a&&i.end>d;if(i.end<=a&&!h)return delete n[s],void function(t,n){var r=e.find(t,["store","proxy","hideReminders"])||{};Object.keys(r).filter((function(e){return e===n})).forEach((function(e){delete r[e]}))}(t,s);var p=!1,y=function(n){p=!0,t.Store.onReadyEvt.reg((function(){!function(n){if(!e.find(t,["store","proxy","settings","general","calendar","hideNotif"])){var r=i.start<=a?i.start:+new Date;t.store.mailbox.showMessage("reminders",{msg:{ctime:r,type:"REMINDER",missed:Boolean(h),content:i},hash:"REMINDER|"+s+"-"+n},null,(function(){}))}}(n)}))},v=i.reminders||[];v.sort((function(e,t){return e-t})),v.some((function(e){var t=a+6e4*e;if(!u.some((function(t){return e>=t})))return i.start-t>=2147483647||(i.start<=t?(y(e),!0):void n[s].push(setTimeout((function(){y(e)}),i.start-t)))})),p||t.Store.onReadyEvt.reg((function(){t.store.mailbox.hideMessage("reminders",{hash:"REMINDER|"+s},null,(function(){}))}))}},g=function(t,n,r,o){var i=function(e){var t=new Date,n=new Date(t.getFullYear(),t.getMonth()-1,15),r=new Date(t.getFullYear(),t.getMonth()+1,15),o=a.getMonthId(n),i=a.getMonthId(t),s=a.getMonthId(r),c=a.getRecurring([o,i,s],[e]),u=[e];return Array.prototype.push.apply(u,c),u}(e.clone(r));i.forEach((function(e){m(t,n,e,o)}))},E=function(e,t,n){var r=e.calendars[t];n&&r&&r.reminders&&(1===r.stores.length&&0===r.stores[0]||g(e,r.reminders,n))},b=function(t,n,r){var o=t.calendars[n];if(o&&o.reminders&&!Object.keys(o.reminders).length&&(1!==o.stores.length||0!==o.stores[0])){var a=e.find(o,["proxy","content"]);a&&Object.keys(a).forEach((function(e){g(t,o.reminders,a[e],r)}))}},A=function(n,r,a){var c=e.once(e.mkAsync(a||function(){})),f=r.storeId,y=r.data,m=y.channel;if(m){var g=n.calendars[m],A=function(){h(n,g)};if(g){if(g.readOnly&&y.href){var _=t.parsePadUrl(y.href),w=t.getSecrets("calendar",_.hash,y.password),O=u.createEncryptor(w.keys);g.hashes.editHash=t.getEditHashFromKeys(w),g.lm.setReadOnly(!1,O),g.readOnly=!1}else if(0===f)return 1===g.stores.length&&0===g.stores[0]&&g.tempId.length&&r.cId&&g.tempId.push(r.cId),void c();return-1!==g.roStores.indexOf(f)&&y.href&&(g.roStores.splice(g.roStores.indexOf(f),1),-1!==g.stores.indexOf(0)&&g.stores.splice(g.stores.indexOf(0),1),A()),g.stores&&-1!==g.stores.indexOf(f)?void c():(-1!==g.stores.indexOf(0)&&(g.stores.splice(g.stores.indexOf(0),1),g.tempId=[]),g.stores.push(f),y.href||g.roStores.push(f),A(),void c())}g=n.calendars[m]={ready:!1,channel:m,readOnly:!y.href,tempId:[],stores:[f],roStores:y.href?[]:[f],reminders:{},hashes:{}},0===f&&g.tempId.push(r.cId);var D=t.parsePadUrl(y.href||y.roHref),S=t.getSecrets("calendar",D.hash,y.password),T=u.createEncryptor(S.keys);g.hashes.viewHash=t.getViewHashFromKeys(S),y.href&&(g.hashes.editHash=t.getEditHashFromKeys(S)),g.proxy={metadata:{color:y.color,title:y.title}},A();var C=function(){g.stores.forEach((function(e){var t=d(n,e);t&&t.rpc&&t.proxy.calendars&&(delete t.proxy.calendars[m],(t.unpin||n.unpinPads)([m],(function(e){e&&e.error&&console.error(e.error)})))})),g.lm&&g.lm.stop(),g.stores=[],h(n,g),p(n,m),delete n.calendars[m]};i((function(e){n.store.network&&!r.isNew&&n.Store.isNewChannel(null,m,e((function(t){if(!t||!t.error)return t&&"boolean"==typeof t.isNew&&t.isNew?(C(),c({error:"EDELETED"}),void e.abort()):void 0})))})).nThen((function(){var e;if(1!==f&&f){var t=n.store.modules.team&&n.store.modules.team.getTeamsData(),a=t&&t[f];e=a?a.edPublic:void 0}else e=n.store.proxy.edPublic;var i={data:{},network:n.store.network||n.store.networkPromise,channel:S.channel,crypto:T,owners:[e],ChainPad:l,validateKey:S.keys.validateKey||void 0,userName:"calendar",Cache:o,classic:!0,onRejected:n.Store&&n.Store.onRejected},u=s.create(i);g.lm=u;var d=g.proxy=u.proxy,h=!1,p=function(){h||(h=!0,setTimeout((function(){h=!1,A()})))};u.proxy.on("cacheready",(function(){d.metadata&&(g.cacheready=!0,p(),c&&c(null,u.proxy),b(n,m,r.lastVisitNotif))})).on("ready",(function(e){var t=e.metadata;if(g.owners=t.owners||[],g.ready=!0,!d.metadata){if(!r.isNew)return void C();d.metadata={color:y.color,title:y.title}}p(),c&&c(null,u.proxy),b(n,m,r.lastVisitNotif)})).on("change",[],(function(){g.ready&&p()})).on("change",["content"],(function(e,t,r){2!==r.length||!t||e?2!==r.length||t||!e?(r.length>=3&&["start","reminders","isAllDay"].includes(r[2])||r.length>=6&&["start","reminders","isAllDay"].includes(r[5]))&&setTimeout((function(){E(n,m,d.content[r[1]])})):E(n,m,{id:r[1],start:0}):E(n,m,t)})).on("remove",["content"],(function(e,t){p(),(t.length>=3&&"reminders"===t[2]||t.length>=6&&"reminders"===t[5])&&setTimeout((function(){E(n,m,d.content[t[1]])}))})).on("change",["metadata"],(function(){var e=d.metadata;e&&e.title&&e.color&&v(n,g,e)})).on("disconnect",(function(){g.offline=!0,p()})).on("reconnect",(function(){g.offline=!1,p()})).on("error",(function(e){e&&e.error&&("EDELETED"!==e.error?("ERESTRICTED"===e.error&&(g.restricted=!0,p()),c(e)):C())}))}))}},_=function(e,t){if(t.href&&-1===t.href.indexOf("#"))if(e.secondaryKey)try{t.href=e.userObject.cryptor.decrypt(t.href)}catch(e){console.error(e),delete t.href}else delete t.href},w=function(t,n){var r=n.proxy.calendars,o=n.id||1;n.proxy.on("change",["calendars"],(function(r,a,i){i.length<2||(r&&!a&&function(){var e=i[1],n=t.calendars[e];if(n){var r=n.stores.indexOf(o);if(-1!==r){n.stores.splice(r,1);var a=n.roStores.indexOf(o);-1!==a&&n.roStores.splice(a,1),y(t,e),h(t,n)}}}(),!r&&a&&function(){var r=i[1],a=n.proxy.calendars[r];if(a){var s=e.clone(a);_(n,s),A(t,{storeId:o,data:s})}}())})),Object.keys(r||{}).forEach((function(a){var i=e.clone(r[a]);_(n,i),A(t,{storeId:o,lastVisitNotif:!0,data:i})}))},O=function(e,n,o,a){var i=d(e,n.teamId);if(i)if(i.rpc){var s,c,u,l=i.proxy.calendars=i.proxy.calendars||{},f=(s=t.createRandomHash("calendar"),c=t.getSecrets("calendar",s),u=t.getViewHashFromKeys(c),{href:t.hashToHref(s,"calendar"),roHref:t.hashToHref(u,"calendar"),channel:c.channel});f.color=n.color,f.title=n.title,A(e,{storeId:i.id||1,data:f,isNew:!0},(function(t){if(t)return console.error(t),void a({error:t.error});var n=e.calendars[f.channel];r.whenRealtimeSyncs(n.lm.realtime,(function(){l[f.channel]=f,(i.pin||e.pinPads)([f.channel],(function(e){e&&e.error&&console.error(e.error)})),e.Store.onSync(i.id,a)}))}))}else a({error:"EFORBIDDEN"});else a({error:"NO_STORE"})};return f.init=function(n,o,a){var s={},c=n.store,u={loggedIn:c.loggedIn&&c.proxy.edPublic,store:c,Store:n.Store,pinPads:n.pinPads,unpinPads:n.unpinPads,updateMetadata:n.updateMetadata,emit:a,onReady:e.mkEvent(!0),calendars:{},clients:[]};return function(e,t){var n=e.store.proxy;n.calendars=n.calendars||{},setTimeout(t)}(u,o((function(e){e||function(e){w(e,e.store);var t=e.store.modules.team&&e.store.modules.team.getTeamsData();t&&Object.keys(t).forEach((function(t){var n=d(e,t);w(e,n)}))}(u)}))),u.store.proxy.on("change",["hideReminders"],(function(e,t,n){var r=n[1].split("|")[0];Object.keys(u.calendars).some((function(e){var t=u.calendars[e];if(t&&t.proxy&&t.proxy.content)return t.proxy.content[r]?(setTimeout((function(){E(u,e,t.proxy.content[r])})),!0):void 0}))})),s.closeTeam=function(e){Object.keys(u.calendars).forEach((function(t){var n=u.calendars[t],r=n.stores.indexOf(e);if(-1!==r){n.stores.splice(r,1);var o=n.roStores.indexOf(e);-1!==o&&n.roStores.splice(o,1),y(u,t),h(u,n)}}))},s.openTeam=function(e){var t=d(u,e);t&&w(u,t)},s.upgradeTeam=function(t){if(t){var n=d(u,t);n&&Object.keys(u.calendars).forEach((function(r){var o=u.calendars[r];if(-1!==o.stores.indexOf(t)){var a=n.proxy.calendars[r],i=e.clone(a);_(n,i),A(u,{storeId:t,data:i}),h(u,o)}}))}},s.removeClient=function(e){!function(e,t){var n=e.clients.indexOf(t);-1!==n&&e.clients.splice(n,1),Object.keys(e.calendars).forEach((function(n){var r=e.calendars[n];if(1===r.stores.length&&0===r.stores[0]&&r.tempId.length){var o=r.tempId.indexOf(t);-1!==o&&r.tempId.splice(o,1),r.tempId.length||(r.stores=[],y(e,n))}}))}(u,e)},s.execCommand=function(n,o,a){var s=o.cmd,c=o.data;if("SUBSCRIBE"!==s){if("OPEN"!==s)return"IMPORT"===s?u.store.offline?void a({error:"OFFLINE"}):u.loggedIn?void function(n,r,o,a){var i=r.id,s=n.calendars[i];if(s)if(Array.isArray(s.stores)&&-1!==s.stores.indexOf(r.teamId)){var c=n.store,u=c.proxy.calendars=c.proxy.calendars||{},l=s.hashes.editHash,f=s.hashes.viewHash;u[i]={href:l&&t.hashToHref(l,"calendar"),roHref:f&&t.hashToHref(f,"calendar"),channel:i,color:e.find(s,["proxy","metadata","color"])||e.getRandomColor(),title:e.find(s,["proxy","metadata","title"])||"..."},n.Store.onSync(null,a),A(n,{storeId:1,data:{href:u[i].href,toHref:u[i].roHref,channel:i}})}else a({error:"EINVAL"});else a({error:"ENOENT"})}(u,c,0,a):void a({error:"NOT_LOGGED_IN"}):"IMPORT_ICS"===s?u.store.offline?void a({error:"OFFLINE"}):void function(e,t,n,o){var a=t.id,i=e.calendars[a];if(i&&i.proxy){var s=t.json;i.proxy.content=i.proxy.content||{},Object.keys(s).forEach((function(t){i.proxy.content[t]=s[t],E(e,a,s[t])})),r.whenRealtimeSyncs(i.lm.realtime,(function(){h(e,i),o()}))}else o({error:"ENOENT"})}(u,c,0,a):"ADD"===s?u.store.offline?void a({error:"OFFLINE"}):u.loggedIn?void function(n,r,o,a){var i=d(n,r.teamId);if(i)if(i.rpc){var s=i.proxy.calendars=i.proxy.calendars||{},c=t.parsePadUrl(r.href),u=t.getSecrets(c.type,c.hash,r.password);if(u.channel===r.channel){var l=t.getEditHashFromKeys(u),f=t.getViewHashFromKeys(u),h=l&&t.hashToHref(l,"calendar"),p={href:h,roHref:f&&t.hashToHref(f,"calendar"),color:r.color,title:r.title,channel:r.channel};!s[r.channel]||!s[r.channel].href&&p.href?(p.color=r.color,p.title=r.title,A(n,{storeId:i.id||1,data:e.clone(p)},(function(e){if(e)return console.error(e),void a({error:e.error});if(h&&i.id&&i.secondaryKey)try{p.href=i.userObject.cryptor.encrypt(h)}catch(e){console.error(e)}s[p.channel]=p,(i.pin||n.pinPads)([p.channel],(function(e){e&&e.error&&console.error(e.error)})),n.Store.onSync(i.id,a)}))):a()}else a({error:"EINVAL"})}else a({error:"EFORBIDDEN"});else a({error:"NO_STORE"})}(u,c,0,a):void a({error:"NOT_LOGGED_IN"}):"CREATE"===s?u.loggedIn?c.initialCalendar?void u.Store.onReadyEvt.reg((function(){O(u,c,0,a)})):u.store.offline?void a({error:"OFFLINE"}):void O(u,c,0,a):void a({error:"NOT_LOGGED_IN"}):"UPDATE"===s?u.store.offline?void a({error:"OFFLINE"}):void function(t,n,o,a){var i=n.id,s=t.calendars[i];if(s){var c=e.find(s,["proxy","metadata"]);c?(c.title=n.title,c.color=n.color,r.whenRealtimeSyncs(s.lm.realtime,a),h(t,s),v(t,s,n)):a({error:"EINVAL"})}else a({error:"ENOENT"})}(u,c,0,a):"DELETE"===s?u.store.offline?void a({error:"OFFLINE"}):u.loggedIn?void function(e,t,n,r){var o=d(e,t.teamId);if(o)if(o.rpc){if(o.proxy.calendars){var a=t.id;if(o.proxy.calendars[a]){delete o.proxy.calendars[a],(o.unpin||e.unpinPads)([a],(function(e){e&&e.error&&console.error(e.error)}));var i=e.calendars[a],s=i.stores.indexOf(o.id||1);i.stores.splice(s,1),y(e,a),e.Store.onSync(o.id,(function(){h(e,i),r()}))}else r()}}else r({error:"EFORBIDDEN"});else r({error:"NO_STORE"})}(u,c,0,a):void a({error:"NOT_LOGGED_IN"}):"CREATE_EVENT"===s?u.store.offline?void a({error:"OFFLINE"}):void function(e,t,n,o){var a=t.calendarId,i=e.calendars[a];if(i){var s=new Date(t.start),c=new Date(t.end);t.isAllDay?(t.startDay=s.getFullYear()+"-"+(s.getMonth()+1)+"-"+s.getDate(),t.endDay=c.getFullYear()+"-"+(c.getMonth()+1)+"-"+c.getDate()):(delete t.startDay,delete t.endDay),i.proxy.content=i.proxy.content||{},i.proxy.content[t.id]=t,r.whenRealtimeSyncs(i.lm.realtime,(function(){E(e,a,t),h(e,i),o()}))}else o({error:"ENOENT"})}(u,c,0,a):"UPDATE_EVENT"===s?u.store.offline?void a({error:"OFFLINE"}):void function(t,n,o,a){if(n&&n.ev){var s=n.ev.calendarId,c=t.calendars[s];if(c&&c.proxy&&c.proxy.content){var u=c.proxy.content[n.ev.id];if(u){n.rawData=n.rawData||{};var l,f=n.changes||{},d=n.type||{};if(f.calendarId){if(!(l=t.calendars[f.calendarId])||!l.proxy)return void a({error:"ENOENT"});l.proxy.content=l.proxy.content||{}}var p={one:{},from:{}};["one","from","all"].includes(d.which)&&(u.recUpdate=u.recUpdate||p,u.recUpdate.one||(u.recUpdate.one={}),u.recUpdate.from||(u.recUpdate.from={}));var y=u.recUpdate,v=["calendarId"],m=Object.keys(f).filter((function(e){return!v.includes(e)})),g=function(e){[y.from,y.one].forEach((function(t){Object.keys(t).forEach((function(n){Number(n)<e||delete t[n]}))}))},b=function(e,t){Object.keys(e).forEach((function(n){t&&Number(n)<t||m.forEach((function(t){delete e[n][t]}))}))};if(void 0!==f.recurrenceRule&&("all"===d.which&&f.recurrenceRule.until?g(f.recurrenceRule.until):["one","from"].includes(d.which)&&!n.rawData.isOrigin?g(d.when+1):y=u.recUpdate=p),"one"===d.which?y.one[d.when]=y.one[d.when]||{}:"from"===d.which?(y.from[d.when]=y.from[d.when]||{},b(y.from,d.when),b(y.one,d.when)):"all"===d.which&&(b(y.from),b(y.one)),f.start&&y&&(!d.which||"all"===d.which)){var A=f.start-u.start,_={},w={};Object.keys(y.one||{}).forEach((function(e){_[Number(e)+A]=y.one[e]})),Object.keys(y.from||{}).forEach((function(e){w[Number(e)+A]=y.from[e]})),y.one=_,y.from=w}var O=e.find(t,["store","proxy","hideReminders"])||{};f.reminders&&("one"===d.which?d.when&&d.when!==u.start?delete O[n.ev.id+"|"+d.when]:delete O[n.ev.id]:"from"===d.which?Object.keys(O).filter((function(e){return 0===e.indexOf(n.ev.id)})).forEach((function(e){var t=Number(e.split("|")[1]);t&&(t<d.when||delete O[e])})):Object.keys(O).filter((function(e){return 0===e.indexOf(n.ev.id)})).forEach((function(e){delete O[e]}))),Object.keys(f).forEach((function(e){if(!v.includes(e)&&"one"===d.which)return"recurrenceRule"===e?n.rawData&&n.rawData.isOrigin?u[e]=f[e]:(y.from[d.when]=y.from[d.when]||{},y.from[d.when][e]=f[e]):void(y.one[d.when][e]=f[e]);v.includes(e)||"from"!==d.which?u[e]=f[e]:y.from[d.when][e]=f[e]}));var D=new Date(u.start),S=new Date(u.end);u.isAllDay?(u.startDay=D.getFullYear()+"-"+(D.getMonth()+1)+"-"+D.getDate(),u.endDay=S.getFullYear()+"-"+(S.getMonth()+1)+"-"+S.getDate()):(delete u.startDay,delete u.endDay),f.calendarId&&l&&(l.proxy.content[n.ev.id]=e.clone(u),delete c.proxy.content[n.ev.id]),i((function(e){r.whenRealtimeSyncs(c.lm.realtime,e()),l&&r.whenRealtimeSyncs(l.lm.realtime,e())})).nThen((function(){l?(E(t,s,{id:u.id,start:0}),E(t,u.calendarId,u)):(f.start||f.reminders||f.isAllDay)&&E(t,s,u),h(t,c),l&&h(t,l),a()}))}else a({error:"EINVAL"})}else a({error:"ENOENT"})}else a({error:"EINVAL"})}(u,c,0,a):"DELETE_EVENT"===s?u.store.offline?void a({error:"OFFLINE"}):void function(e,t,n,o){var a=t.calendarId,i=e.calendars[a];if(i){i.proxy.content=i.proxy.content||{};var s=t.id.split("|")[0];if(t.id===s)delete i.proxy.content[t.id];else{var c=i.proxy.content[s],u=t.raw&&t.raw.start;u&&(c.recUpdate=c.recUpdate||{one:{},from:{}},c.recUpdate.one[u]={deleted:!0})}r.whenRealtimeSyncs(i.lm.realtime,(function(){E(e,a,{id:t.id,start:0}),h(e,i),o()}))}else o({error:"ENOENT"})}(u,c,0,a):void 0;u.Store.onReadyEvt.reg((function(){!function(n,r,o,a){var i=t.getSecrets("calendar",r.hash,r.password),s=t.getEditHashFromKeys(i),c=t.getViewHashFromKeys(i),u={href:s&&t.hashToHref(s,"calendar"),roHref:c&&t.hashToHref(c,"calendar"),channel:i.channel,color:e.getRandomColor(),title:"..."};A(n,{cId:o,storeId:0,data:u},a)}(u,c,n,a)}))}else!function(e,t,n,r){-1===e.clients.indexOf(n)&&e.clients.push(n),r({length:Object.keys(e.calendars).length}),Object.keys(e.calendars).forEach((function(t){var n=e.calendars[t]||{};h(e,n)}))}(u,0,n,a)},s},f})(Ne(),Fe(),Oe(),mt(),Ge(),_r(),Dt(),S(),Tr(),ye(),I()),Or}var xr=r(h());let Ir={};const Nr=(e,t,n)=>{const r=[],o=null==Ir?void 0:Ir.httpUnsafeOrigin;je.fetchApi(o,"config",!0,(e=>{var o,a;(null===(o=null==e?void 0:e.adminKeys)||void 0===o?void 0:o.includes(t))&&r.push("admin");(null===(a=null==e?void 0:e.moderatorKeys)||void 0===a?void 0:a.includes(t))&&r.push("moderator"),n(r)}))},Pr=(e,t,n)=>{e.Store.anonRpcMsg("",{msg:"IS_PREMIUM",data:t},(e=>{let t=Array.isArray(e)&&e[0];n(t?["premium"]:[])}))},kr=(e,t,n,r)=>{var o,a;const i=[];null==Ir||Ir.httpUnsafeOrigin;const s=t.edPublic||(null===(a=null===(o=e.store)||void 0===o?void 0:o.proxy)||void 0===a?void 0:a.edPublic);Mn((e=>{Nr(0,s,e((e=>{Array.prototype.push.apply(i,e)})))})).nThen((t=>{Pr(e,s,t((e=>{Array.prototype.push.apply(i,e)})))})).nThen((()=>{r(i)}))},Rr={admin:Nr,moderator:Nr,premium:Pr},Mr={init:(e,t,n)=>{const r={store:e.store,Store:e.Store,updateMetadata:e.updateMetadata},o=r.Store;return o.onReadyEvt.reg((()=>{var e;const t=o.getMetadata(void 0,"drive",(()=>{})),n=(null===(e=null==t?void 0:t.user)||void 0===e?void 0:e.badge)||"";n&&kr(r,{},0,(e=>{var t,o;if(!e.includes(n)){const e=null===(o=null===(t=null==r?void 0:r.store)||void 0===t?void 0:t.modules)||void 0===o?void 0:o.profile;null==e||e.execCommand(void 0,{cmd:"SET",data:{key:"badge",value:""}},(()=>{}))}}))})),{listBadges:(e,t)=>{kr(r,e,0,t)},removeClient:()=>{},execCommand:(e,t,n)=>{const o=t.cmd,a=t.data;"LIST_BADGES"!==o?"CHECK_BADGE"!==o?n():((e,t,n,r)=>{const{badge:o,ed:a,sig:i,nid:s}=t,c=je.decodeBase64(a),u=je.decodeBase64(i),l=xr.sign.open(u,c);if(!l)return void r({verified:!1});if(je.encodeUTF8(l)!==s)return void r({verified:!1});let f=Rr[o];f?f(e,a,(e=>{r({verified:e.includes(o),badge:o})})):r({verified:!1,error:"EINVAL"})})(r,a,0,n):kr(r,a,0,n)}}},setCustomize:e=>{Ir=null==e?void 0:e.ApiConfig}};var Fr,Lr,Hr=o(Object.freeze({__proto__:null,Badge:Mr}));function Kr(){if(Lr)return Fr;Lr=1;return Fr=((e,t,n,r,o,a,i,s,c,u,l,f,d,h,p,y,v,m,g,E,b,A,_,w,O,D,S,T,C,x,I,N,P,k,R,M)=>{const F=p.Account,L=y.Drive,H=v.Pad,K=T.Badge,j=globalThis;globalThis.nacl=globalThis.nacl||I.Nacl;let U={},B={};const V=a.Saferphore;var G=a.mkEvent(!0),Y=a.mkEvent(!0),J=a.mkEvent(!0),q=a.mkEvent(!0);var W={drive:{hideDuplicate:!0},pad:{width:!0,spellcheck:!0},security:{unsafeLinks:!1},general:{allowUserFeedback:!0}};return{setCustomize:e=>{U=e.ApiConfig,B=e.AppConfig},create:function(p){var y=j.Cryptpad_Store={};let v=p.query||function(){},T=p.broadcast||function(){};var N=j.CryptPad_AsyncStore={modules:{}};y.onReadyEvt=G,y.pad=H.init({Store:y,store:N,postMessage:v,broadcast:T}),y.drive=L.initAPI({Store:y,store:N,postMessage:v,broadcast:T});var P=[],k=N.sendDriveEvent=function(e,t,n){P.forEach((function(r){r!==n&&v(r,e,t)}))},Q=y.getStore=function(e){if(!e)return N;try{var t=N.modules.team.getTeam(e);return t||void console.error("Team not found",e)}catch(t){return console.error(t),void console.error("Team not found",e)}},z=y.onSync=function(e,t){var n=Q(e);n?M((function(e){if(n.realtime&&c.whenRealtimeSyncs(n.realtime,e()),!n.id&&n.drive?.realtime&&c.whenRealtimeSyncs(n.drive.realtime,e()),n.sharedFolders&&"object"==typeof n.sharedFolders)for(var t in n.sharedFolders)n.sharedFolders[t].realtime&&c.whenRealtimeSyncs(n.sharedFolders[t].realtime,e())})).nThen((function(){t()})):t({error:"ENOTFOUND"})};y.get=function(e,t,n){var r=Q(t.teamId);r?r.proxy?n(a.find(r.proxy,t.key)):n({error:"ENODRIVE"}):n({error:"ENOTFOUND"})},y.set=function(e,t,n){var r=Q(t.teamId);if(r)if(r.proxy){var o=t.key.slice(),i=o.pop(),s=a.find(r.proxy,o);s&&"object"==typeof s?(void 0===t.value?delete s[i]:s[i]=t.value,t.teamId||(T([e],"UPDATE_METADATA"),Array.isArray(o)&&"profile"===o[0]&&N.messenger&&u.updateMyData(N)),z(t.teamId,n)):n({error:"INVALID_PATH"})}else n({error:"ENODRIVE"});else n({error:"ENOTFOUND"})},y.getSharedFolder=function(e,n,r){var o,i=Q(n.teamId),s=n.id;if(i&&i.manager){if(i.manager.folders[s])return(o=a.clone(i.manager.folders[s].proxy)).offline=Boolean(i.manager.folders[s].offline),void r(o);var c=a.find(i.proxy,["drive",t.SHARED_FOLDERS])||{};c[s]?y.loadSharedFolder(n.teamId,s,c[s],(function(){r(i.manager.folders[s].proxy)})):r({})}else r({error:"ENOTFOUND"})},y.restoreSharedFolder=function(e,t,n){if(t.sfId&&t.drive){var r=Q(t.teamId);r.sharedFolders[t.sfId]&&(Object.keys(t.drive).forEach((function(e){r.sharedFolders[t.sfId].proxy[e]=t.drive[e]})),Object.keys(r.sharedFolders[t.sfId].proxy).forEach((function(e){t.drive[e]||delete r.sharedFolders[t.sfId].proxy[e]}))),z(t.teamId,n)}else n({error:"EINVAL"})},y.hasSigningKeys=function(){if(N.proxy)return"string"==typeof N.proxy.edPrivate&&"string"==typeof N.proxy.edPublic},y.hasCurveKeys=function(){if(N.proxy)return"string"==typeof N.proxy.curvePrivate&&"string"==typeof N.proxy.curvePublic},y.isOwned=function(e){var t=N.proxy.edPublic;if(!t)return!1;if(!Array.isArray(e)||!e.length)return!1;if(-1!==e.indexOf(t))return!0;var n=N.proxy.teams;return!!n&&Object.keys(n).some((function(t){var r=a.find(n[t],["keys","drive","edPublic"]);return r&&-1!==e.indexOf(r)}))};var X=function(e){var t=e?N.manager.getChannelsList("expirable"):function(){var e=`${N.driveChannel}#drive`;if(!e)return null;var t=N.manager.getChannelsList("pin"),n=N.proxy.profile;if(n){var r=n.edit?o.hrefToHexChannelId("/profile/#"+n.edit,null):null;r&&t.push(r);var a=n.avatar?o.hrefToHexChannelId(n.avatar,null):null;a&&t.push(a)}if(N.proxy.todo&&t.push(o.hrefToHexChannelId("/todo/#"+N.proxy.todo,null)),N.proxy.friends){var i=u.getFriendChannelsList(N.proxy);t=t.concat(i)}if(N.proxy.mailboxes){var s=Object.keys(N.proxy.mailboxes).map((function(e){if("broadcast"!==e||N.isAdmin)return N.proxy.mailboxes[e].channel})).filter(Boolean);t=t.concat(s)}if(N.proxy.calendars){var c=Object.keys(N.proxy.calendars).map((function(e){return N.proxy.calendars[e].channel}));t=t.concat(c)}return t.push(e),N.data&&N.data.blockId&&t.push(`${N.data.blockId}#block`),t.sort(),t}();return a.deduplicateString(t).sort()};y.pinPads=function(e,t,n){if(t){var r=Q(t&&t.teamId);if(r.rpc){"function"!=typeof n&&(console.error("expected a callback"),n=function(){});var o=t.pads||t;r.rpc.pin(o,(function(e){n(e?{error:e}:{})}))}else n({error:"RPC_NOT_READY"})}else n({error:"EINVAL"})},y.unpinPads=function(e,t,n){if(t){var r=Q(t&&t.teamId);if(r.rpc){var o=t.pads||t;r.rpc.unpin(o,(function(e){n(e?{error:e}:{})}))}else n({error:"RPC_NOT_READY"})}else n({error:"EINVAL"})};var Z=N.account={};y.getPinnedUsage=function(e,t,n){var r=Q(t&&t.teamId);r&&r.rpc?r.rpc.getFileListSize((function(e,t){r.id||"number"!=typeof t||(Z.usage=t),n({bytes:t})})):n({error:"RPC_NOT_READY"})},y.getPinLimit=function(e,t,n){var r=Q(t&&t.teamId);r.rpc?r.rpc.getLimit((function(e,t,o,a){if(e)n({error:e});else{var i=r.id?{}:Z;i.limit=t,i.plan=o,i.note=a,n(i)}})):n({error:"RPC_NOT_READY"})};y.uploadComplete=function(e,t,n){var r=Q(t.teamId);r?r.rpc?t.owned?r.rpc.ownedUploadComplete(t.id,(function(e,t){n(e?{error:e}:t)})):r.rpc.uploadComplete(t.id,(function(e,t){n(e?{error:e}:t)})):n({error:"RPC_NOT_READY"}):n({error:"ENOTFOUND"})},y.uploadStatus=function(e,t,n){var r=Q(t.teamId);r?r.rpc?r.rpc.uploadStatus(t.size,(function(e,t){n(e?{error:e}:t)})):n({error:"RPC_NOT_READY"}):n({error:"ENOTFOUND"})},y.uploadCancel=function(e,t,n){var r=Q(t.teamId);r?r.rpc?r.rpc.uploadCancel(t.size,(function(e,t){n(e?{error:e}:t)})):n({error:"RPC_NOT_READY"}):n({error:"ENOTFOUND"})},y.uploadChunk=function(e,t,n){var r=Q(t.teamId);r?r.rpc?r.rpc.send.unauthenticated("UPLOAD",t.chunk,(function(e,t){n({error:e,msg:t})})):n({error:"RPC_NOT_READY"}):n({error:"ENOTFOUND"})};y.anonRpcMsg=function(e,t,n){N.anon_rpc?N.anon_rpc.send(t.msg,t.data,(function(e,t){n(e?{error:e}:t)})):n({error:"ANON_RPC_NOT_READY"})},y.getFileSize=function(e,t,n){var r=a.once(a.mkAsync(n));if(N.anon_rpc){var i=t.channel||o.hrefToHexChannelId(t.href,t.password);N.anon_rpc.send("GET_FILE_SIZE",i,(function(e,t){if(!e)return t&&t.length&&"number"==typeof t[0]?(0===t[0]&&d.clearChannel(i),void r({size:t[0]})):void r({error:"INVALID_RESPONSE"});r({error:e})}))}else r({error:"ANON_RPC_NOT_READY"})},y.isNewChannel=function(e,t,n){if(N.anon_rpc){var r=t.channel||o.hrefToHexChannelId(t.href,t.password);N.anon_rpc.send("IS_NEW_CHANNEL",r,(function(e,t){if(!e)return t&&t.length&&"object"==typeof t[0]?(t[0].isNew&&d.clearChannel(r),void n(t[0])):void n({error:"INVALID_RESPONSE"});n({error:e})}))}else n({error:"ANON_RPC_NOT_READY"})},y.getMultipleFileSize=function(e,t,n){N.anon_rpc?Array.isArray(t.files)?N.anon_rpc.send("GET_MULTIPLE_FILE_SIZE",t.files,(function(e,t){e?n({error:e}):t&&t.length&&"object"==typeof t[0]?n({size:t[0]}):n({error:"UNEXPECTED_RESPONSE"})})):n({error:"INVALID_FILE_LIST"}):n({error:"ANON_RPC_NOT_READY"})},y.getDeletedPads=function(e,t,n){if(N.anon_rpc){var r=t&&t.list||X(!0);Array.isArray(r)?N.anon_rpc.send("GET_DELETED_PADS",r,(function(e,t){e?n({error:e}):t&&t.length&&Array.isArray(t[0])?n(t[0]):n({error:"UNEXPECTED_RESPONSE"})})):n({error:"INVALID_FILE_LIST"})}else n({error:"ANON_RPC_NOT_READY"})};var $=function(e,t,n){N.anon_rpc?n():f.createAnonymous(N.network,(function(e,t){e?n({error:e}):(N.anon_rpc=t,n())}))},ee=y.getAllStores=function(){if(!N.proxy||!N.manager)return[];var e=[N],t=N.modules.team;if(t){var n=t.getTeams().map((function(e){return t.getTeam(e)}));Array.prototype.push.apply(e,n)}return e};y.getUserColor=function(){var e=a.find(N,["proxy","settings","general","cursor","color"]);return e||(e=a.getRandomColor(!0),y.setAttribute(null,{attr:["general","cursor","color"],value:e},(function(){}))),e},y.getMetadata=function(e,t,n){var r=N.proxy||{},s=a.find(r,["settings","general","disableThumbnails"]),c=N.modules.team&&N.modules.team.getTeamsData(t)||{};r.uid||(N.noDriveUid=N.noDriveUid||o.createChannelId());var u={user:{name:r[i.displayNameKey]||N.noDriveName||"",uid:r.uid||N.noDriveUid,avatar:a.find(r,["profile","avatar"]),profile:a.find(r,["profile","view"]),color:y.getUserColor(),notifications:a.find(r,["mailboxes","notifications","channel"]),curvePublic:r.curvePublic,kemPublic:r.kemPublic,edPublic:r.edPublic,dsaPublic:r.dsaPublic,netfluxId:N?.network?.webChannels?.[0]?.myID,badge:a.find(r,["profile","badge"])},priv:{clientId:e,edPublic:r.edPublic,edPrivate:r.edPrivate,dsaPublic:r.dsaPublic,dsaPrivate:r.dsaPrivate,friends:r.friends||{},settings:r.settings||W,thumbnails:!1===s,isDriveOwned:Boolean(a.find(N,["driveMetadata","owners"])),driveChannel:N.driveChannel,pendingFriends:r.friends_pending||{},supportPrivateKey:a.find(r,["mailboxes","supportadmin","keys","curvePrivate"]),accountName:r.login_name||"",offline:N.proxy&&N.offline,teams:c,plan:N.ready?Z.plan||"":void 0,mutedChannels:r.mutedChannels}};return n(JSON.parse(JSON.stringify(u))),u},y.onMaintenanceUpdate=function(){let e=U.httpUnsafeOrigin;a.fetchApi(e,"broadcast",!0,(e=>{e&&T([],"UNIVERSAL_EVENT",{type:"broadcast",data:{ev:"MAINTENANCE",data:e.maintenance}})}))},y.onSurveyUpdate=function(){let e=U.httpUnsafeOrigin;a.fetchApi(e,"broadcast",!0,(e=>{T([],"UNIVERSAL_EVENT",{type:"broadcast",data:{ev:"SURVEY",data:e.surveyURL}})}))};y.addPad=function(e,n,r){if(n.href||n.roHref){var a;if(!n.roHref){var i=o.parsePadUrl(n.href);"pad"===i.hashData.type&&(a=o.getSecrets(i.type,i.hash,n.password),n.roHref="/"+i.type+"/#"+o.getViewHashFromKeys(a))}var s,c,u,l,f=(s=n.href,c=n.roHref,u=n.title,l=+new Date,{href:s,roHref:c,atime:l,ctime:l,title:u||t.getDefaultName(o.parsePadUrl(s))});n.owners&&(f.owners=n.owners),n.expire&&(f.expire=n.expire),n.password&&(f.password=n.password),(n.channel||a)&&(f.channel=n.channel||a.channel),n.readme&&(f.readme=1),Object.keys(n.attributes||{}).forEach((e=>{n.attributes[e]&&(f[e]=n.attributes[e])})),-1===n.teamId&&(n.teamId=void 0);var d=Q(n.teamId);d&&d.manager?d.manager.addPad(n.path,f,(function(o){o?r({error:o}):(ee().forEach((function(n){(n.id?n.sendEvent:k)("DRIVE_CHANGE",{path:["drive",t.FILES_DATA]},e)})),z(n.teamId,r))})):r({error:"ENOTFOUND"})}else r({error:"NO_HREF"})};var te=function(e,t){var n=a.find(N,["proxy","edPublic"]),r=function(e){var t=[];return e?(N.proxy.todo&&t.push(o.hrefToHexChannelId("/todo/#"+N.proxy.todo,null)),N.proxy.profile&&N.proxy.profile.edit&&t.push(o.hrefToHexChannelId("/profile/#"+N.proxy.profile.edit,null)),N.proxy.mailboxes&&Object.keys(N.proxy.mailboxes||{}).forEach((function(e){if("supportadmin"!==e){var n=N.proxy.mailboxes[e];t.push(n.channel)}}))):t=N.manager.getChannelsList("owned"),t.filter((function(e){if("string"==typeof e)return-1!==[32,48].indexOf(e.length)}))}(e),i=V.create(10),s=function(t){e||N.manager.findChannel(t).forEach((function(e){var t=N.manager.findFile(e.id);N.manager.delete({paths:t})}))};r.forEach((function(e){var r=t();i.take((function(t){var o=!1;M((function(a){32===e.length&&y.anonRpcMsg(null,{msg:"GET_METADATA",data:e},a((function(i){if(i&&i.error)return t(),r(),void a.abort();var c=i[0];return Object.keys(c||{}).length?c&&Array.isArray(c.owners)&&-1!==c.owners.indexOf(n)?void(o=c.owners.some((function(e){return e!==n}))):(t(),r(),void a.abort()):(s(e),t(),r(),void a.abort())})))})).nThen((function(t){o?y.pad.setMetadata(null,{channel:e,command:"RM_OWNERS",value:[n]},t()):N.rpc.removeOwnedChannel(e,t((function(t){t?console.error(t):s(e)})))})).nThen((function(){t(),r()}))}))}))};y.removeOwnedPads=function(e,t,n){N.proxy.edPublic?M((function(e){te(!1,e)})).nThen(n):n({error:"NOT_LOGGED_IN"})},y.deleteAccount=function(t,n,r){var o=N.proxy.edPublic,s=n&&n.keys,c=n&&n.auth;y.anonRpcMsg(t,{msg:"GET_METADATA",data:N.driveChannel},(function(n){var u=n[0];if(u&&u.owners&&1===u.owners.length&&-1!==u.owners.indexOf(o))M((function(e){C.checkRights({auth:c,blockKeys:s},e((function(t){if(t)return e.abort(),console.error(t),void r({error:"INVALID_CODE"})})))})).nThen((function(e){globalThis.accountDeletion=t,N.proxy[i.tokenKey]="DELETED",z(null,e())})).nThen((function(e){N.rpc.removePins(e((function(e){e&&console.error(e)})))})).nThen((function(e){N.ownDeletion=!0,y.pad.destroy(t,{channel:N.driveChannel,force:!0},e())})).nThen((function(e){s&&C.removeLoginBlock({reason:"ARCHIVE_OWNED",auth:c,edPublic:o,blockKeys:s},e((function(e){e&&console.error(e)})))})).nThen((function(e){te(!0,e)})).nThen((function(){T([t],"DRIVE_DELETED","ARCHIVE_OWNED"),v(t,"DELETE_ACCOUNT","DELETED",(function(){})),N.network.disconnect(),r({state:!0})}));else{var l={intent:"Please delete my account."};l.drive=N.driveChannel,l.edPublic=o;var f=a.decodeBase64(N.proxy.edPrivate),d=I.CryptoAgility.signDetached(a.decodeUTF8(e(l)),f);I.Nacl.sign.detached.verify(a.decodeUTF8(e(l)),d,a.decodeBase64(o))||console.error("signed message failed verification");var h=a.encodeBase64(d);r({proof:h,toSign:JSON.parse(e(l))})}}))},y.setDisplayName=function(e,t,n){if(!N.proxy)return N.noDriveName=t,T([e],"UPDATE_METADATA"),void n();N.modules.profile&&N.modules.profile.setName(t),N.proxy[i.displayNameKey]=t,T([e],"UPDATE_METADATA"),u.updateMyData(N),z(null,n)},y.resetDrive=function(e,t,n){M((function(e){te(e)})).nThen((function(){N.proxy.drive=N.userObject.getStructure(),k("DRIVE_CHANGE",{path:["drive","filesData"]},e),z(null,n)}))},y.setPadAttribute=function(e,n,r){M((function(r){ee().forEach((function(o){o.manager.setPadAttribute(n,r((function(){(o.id?o.sendEvent:k)("DRIVE_CHANGE",{path:["drive",t.FILES_DATA]},e),z(o.id,r())})))}))})).nThen(r)},y.getPadAttribute=function(e,t,n){var r={};M((function(e){ee().forEach((function(n){n.manager.getPadAttribute(t,e((function(e,t){e||(t&&"object"==typeof t?(!r.value||r.atime<t.atime)&&(r.atime=t.atime,r.value=t.value):console.error("Not an object!"))})))}))})).nThen((function(){n(r.value)}))};var ne=function(e){if("string"==typeof e)return console.error("DEPRECATED: use setAttribute with an array, not a string"),{path:["settings"],obj:N.proxy?.settings,key:e};if(Array.isArray(e))if(0!==e.length){var t=N.proxy?.settings;if(t)return e.forEach((function(n,r){if(r!==e.length-1){if(t[n]){if("object"!=typeof t[n])return void console.error("Wrong attribute")}else t[n]={};t=t[n]}})),{path:["settings"].concat(e),obj:t,key:e[e.length-1]}}else console.error("Attribute can't be empty");else console.error("Attribute must be string or array")};y.setAttribute=function(e,t,n){try{var r=ne(t.attr);r.obj[r.key]=t.value}catch(e){return void n({error:e})}z(null,(function(){n(),T([],"UPDATE_METADATA")}))},y.getAttribute=function(e,t,n){var r;try{r=ne(t.attr)}catch(e){return void n({error:e})}n(r?.obj[r.key])},y.listAllTags=function(e,t,n){var r={};ee().forEach((function(e){var t=e.manager.getTagsList();Object.keys(t).forEach((function(e){r[e]=(r[e]||0)+t[e]}))})),n(r)},y.getTemplates=function(e,t,n){var r=[],o=[];ee().forEach((function(e){e.userObject.getFiles(["template"]).forEach((function(t){var n=e.userObject.getFileData(t);-1===o.indexOf(n.channel)&&(o.push(n.channel),r.push(JSON.parse(JSON.stringify(n))))}))})),n(r)},y.incrementTemplateUse=function(e,t){ee().forEach((function(e){e.userObject.getPadAttribute(t,"used",(function(n,r){if(!n){var o="number"==typeof r?++r:1;e.userObject.setPadAttribute(t,"used",o)}}))}))},y.isOnlyInSharedFolder=function(e,t,n){var r=!1,o=function(e){return!e.fId};return ee().some((function(e){var n=e.manager.findChannel(t);if(n.length)return n.some(o)?(r=!1,!0):void(r=!0)})),n(r)},y.moveToTrash=function(e,n,r){var a=o.getRelativeHref(n.href),i=!0;M((function(n){ee().forEach((function(r){r.userObject.forget(a)&&(i=!1,(r.id?r.sendEvent:k)("DRIVE_CHANGE",{path:["drive",t.FILES_DATA]},e),z(r.id,n()))}))})).nThen((function(){r({error:i?"FORBIDDEN":void 0})}))},y.setPadTitle=function(e,n,r){G.reg((function(){var i=n.title,c=n.href,u=n.channel,l=o.parsePadUrl(c),f=l.hashData;if(""===i.trim()&&(i=t.getDefaultName(l)),!B.disableAnonymousStore||N.loggedIn)if("debug"!==l.type){var d,h,p=y.pad.getChannels()[u];p&&p.wc&&u===p.wc.id&&(d=p.data.owners||void 0),n.owners&&(d=n.owners),p&&p.wc&&u===p.wc.id&&(h=+p.data.expire||void 0),n.expire&&(h=n.expire),n.teamId&&(n.teamId=Number(n.teamId));var m,g,E=[],b=[];ee().forEach((function(e){if("edit"!==f.mode||!e.id||e.secondaryKey){var t=e.manager.findChannel(u,!0);t.length&&b.push(e.id),(e.id||n.teamId&&-1!==n.teamId)&&Number(e.id)!==n.teamId||m||(m=t.length),e.id||(g=t.length),Array.prototype.push.apply(E,t)}}));var A=0!==E.length;if(!N.offline||A)if(N.offline)r();else{if(E.forEach((function(e){var t=e.data;t.atime=+new Date,t.title=i,(d||"file"!==f.type)&&(t.owners=d),t.expire=h,t.readme&&(delete t.readme,s.send("OPEN_README")),"view"!==f.mode&&(t.href||e.userObject.restoreHref(c),e.userObject.setHref(u,null,c))})),!A||n.forceSave&&!m){var _,w=a.find(N.proxy,["settings","general","autostore"]);return 1===w||n.forceSave||n.path?("view"===f.mode&&(_=c,c=void 0),y.addPad(e,{teamId:n.teamId,href:c,roHref:_,channel:u,title:i,owners:d,expire:h,password:n.password,path:n.path,attributes:n.attributes},r),void v(e,"AUTOSTORE_DISPLAY_POPUP",{stored:!0,inMyDrive:g||!A&&!n.teamId})):(v(e,"AUTOSTORE_DISPLAY_POPUP",{autoStore:w}),void r({notStored:!0}))}b.forEach((function(n){(n?Q(n).sendEvent:k)("DRIVE_CHANGE",{path:["drive",t.FILES_DATA]},e)})),v(e,"AUTOSTORE_DISPLAY_POPUP",{stored:!0,inMyDrive:g}),M((function(e){b.forEach((function(t){z(t,e())}))})).nThen(r)}else r({error:"OFFLINE"})}else r({notStored:!0});else r({notStored:!0})}))},y.getSecureFilesList=function(e,t,n){var r={},a=t.types,i=t.where,s=t.filter||{},c=[];ee().forEach((function(e){e.manager.getSecureFilesList(i).forEach((function(e){var t=e.data;if(-1===c.indexOf(t.channel||t.id)){var n=e.id;if(t.channel&&c.push(t.channel||t.id),t.static)-1!==a.indexOf("link")&&(r[n]=t);else{var i=o.parsePadUrl(t.href||t.roHref);a&&0!==a.length&&-1===a.indexOf(i.type)||function(e,t){var n,r=s.fileType||[];if("file"===e&&r.length){if(!t.fileType)return!0;n=!r.some((function(e){return 0===t.fileType.indexOf(e)}))}return n}(i.type,t)||(r[n]=t)}}}))})),n(r)},y.getPadData=function(e,t,n){var r={};ee().some((function(e){var n=e.userObject.getFileData(t);if(n.roHref||n.href)return r=n,!0})),n(r)},y.getPadDataFromChannel=function(e,t,n){var r,o,a=t.channel,i=t.edit,s=t.file;ee().some((function(e){var t=e.manager.findChannel(a);if(Array.isArray(t))return t.some((function(e){if(e&&e.data){var t=e.data;if(i&&t.href||!i&&t.roHref||s)return r=t,!0;i&&!o&&t.roHref&&(o=t)}}))}));var c=r||o;c||!N.offline?n(c||{}):G.reg((function(){y.getPadDataFromChannel(e,t,n)}))},y.checkDeletedPad=function(e,t){e&&y.getPadDataFromChannel(null,{channel:e,isFile:!0},(function(n){"function"==typeof t&&setTimeout(t),Object.keys(n).length||T([],"CHANNEL_DELETED",e)}))},y.answerFriendRequest=function(e,t,n){var r=t.value,o=t.data;if("notifications"===o.type){var a=o.content.hash,i=o.content.msg,s=function(e){e=e||function(){},N.mailbox.dismiss({hash:a,type:"notifications"},e)};r?u.acceptFriendRequest(N,i.content.user,(function(e){e&&e.error?n(e):u.addToFriendList({proxy:N.proxy,realtime:N.realtime,pinPads:function(e,t){y.pinPads(null,e,t)}},i.content.user,(function(e){N.messenger&&N.messenger.onFriendAdded(i.content.user),T([],"UPDATE_METADATA"),e?n({error:e}):s(n)}))})):(u.declineFriendRequest(N,i.content.user,(function(e){T([],"UPDATE_METADATA"),n(e)})),s())}else n({error:"EINVAL"})},y.sendFriendRequest=function(e,t,n){u.getFriend(N.proxy,t.curvePublic)?n({error:"ALREADY_FRIEND"}):t.notifications&&t.curvePublic?(N.proxy.friends_pending=N.proxy.friends_pending||{},N.proxy.friends_pending[t.curvePublic]?n({error:"ALREADY_SENT"}):(N.proxy.friends_pending[t.curvePublic]={time:+new Date,channel:t.notifications,curvePublic:t.curvePublic},T([],"UPDATE_METADATA"),N.mailbox.sendTo("FRIEND_REQUEST",{user:u.createData(N.proxy)},{channel:t.notifications,curvePublic:t.curvePublic},(function(e){n(e)})))):n({error:"INVALID_USER"})},y.cancelFriendRequest=function(e,t){if(e.curvePublic&&e.notifications){var n=N.proxy;if(u.getFriend(n,e.curvePublic))return console.error("You can't cancel an accepted friend request"),void t({error:"ALREADY_FRIEND"});a.find(N,["proxy","friends_pending"])||{}?N.mailbox.sendTo("CANCEL_FRIEND_REQUEST",{user:u.createData(N.proxy)},{channel:e.notifications,curvePublic:e.curvePublic},(function(n){n&&n.error?t(n):(delete N.proxy.friends_pending[e.curvePublic],T([],"UPDATE_METADATA"),z(null,(function(){t(n)})))})):t()}else t({error:"EINVAL"})},y.anonGetPreviewContent=function(e,t,n){w.anonGetPreviewContent({store:N},t,n)},y.getStrongerHash=function(e,t,n){var r=a.once(n);ee().some((function(e){var n=e.manager.getEditHash(t.channel);if(n)return r(n),!0}))||r()},y.universal={execCommand:function(e,t,n){var r=function(){var r=t.type,o=t.data;N.modules[r]?N.modules[r].execCommand(e,o,n):n({error:r+" is disabled"})};-1===["team","calendar"].indexOf(t.type)&&N.proxy?G.reg(r):r()}};var re=function(e,t,n,r){N.modules[t]||(N.modules[t]=e.init({Store:y,store:N,updateLoadingProgress:function(e){e.type="team",v(r,"LOADING_DRIVE",e)},updateMetadata:function(){T([],"UPDATE_METADATA")},pinPads:function(e,t){y.pinPads(null,e,t)},unpinPads:function(e,t){y.unpinPads(null,e,t)}},n,(function(e,n,r){r.forEach((function(r){v(r,"UNIVERSAL_EVENT",{type:t,data:{ev:e,data:n}})}))})))};y.onlyoffice={execCommand:function(e,t,n){N.onlyoffice?N.onlyoffice.execCommand(e,t,n):n({error:"OnlyOffice is disabled"})}},y.mailbox={execCommand:function(e,t,n){G.reg((function(){N.mailbox?N.mailbox.execCommand(e,t,n):n({error:"Mailbox is disabled"})}))}},y.adminRpc=function(e,t,n){N.rpc.adminRpc(t,(function(e,t){n(e?{error:e}:t)}))},y.addAdminMailbox=function(e,t,n){var r=t&&t.priv,a=o.getBoxPublicFromSecret(r),i=t&&2===t.version;if(r&&a){var s=o.getChannelIdFromKey(a),c=i?"supportteam":"supportadmin",u=(N.proxy.mailboxes=N.proxy.mailboxes||{})[c]={channel:s,viewed:[],lastKnownHash:t.lastKnownHash||"",keys:{curvePublic:a,curvePrivate:r}};y.pinPads(null,[s],(function(){})),N.mailbox.open(c,u,(function(){console.log("ready")})),z(null,n)}else n({error:"EINVAL"})},y.getSnapshot=function(e,t,n){y.getHistoryRange(e,{cpCount:1,channel:t.channel,lastKnownHash:t.hash},n)},y.onRejected=function(e,t){var n=a.once(a.mkAsync(t));Array.isArray(e)?(q.fire(),J.reg((()=>{if(N.loggedIn&&N.proxy.edPublic){var t,r=N.modules.team,o=r&&r.getTeams()||[];-1!==e.indexOf(N.proxy.edPublic)?t=N:o.some((function(n){var o=a.find(N,["proxy","teams",n,"keys","drive","edPublic"]),i=a.find(N,["proxy","teams",n,"keys","drive","edPrivate"]);if(-1===e.indexOf(o))return!1;if(!i)return!1;var s=r.getTeam(n);return t=s,!0}));var i=function(){if(t){var e=t.rpc;e?e.send("COOKIE","",(function(e){n(e)})):n("ERESTRICTED")}else n("ERESTRICTED")};t&&t.onRpcReadyEvt?t.onRpcReadyEvt.reg((function(){i()})):i()}else n("ERESTRICTED")}))):n("ERESTRICTED")},y.changePadPasswordPin=function(e,t,n){var r=t.oldChannel,o=t.channel;M((function(e){ee().forEach((function(t){t.manager.findChannel(o).length&&(t.rpc.unpin([r],e()),t.rpc.pin([o],e()))}))})).nThen(n)},y.contactPadOwner=function(e,t,n){var r=t.owners;if(!Array.isArray(r)||!r.length)return n({state:!1});t.send?M((function(e){r.forEach((function(n){!function(e,n,r,o){if(N.mailbox&&!t.anon)return N.mailbox.sendTo(e,n,r,o);A.sendToAnon(N.anon_rpc,e,n,r,o)}(t.query,{channel:t.channel,data:t.msgData},{channel:n.notifications,curvePublic:n.curvePublic},e())}))})).nThen((function(){n({state:!0})})):n({state:!0})},y.givePadAccess=function(e,t,n){var r,o,a=N.proxy.edPublic,i=t.channel,s=N.manager.findChannel(i);t.user&&t.user.notifications&&t.user.curvePublic?s.some((function(e){if(e.data&&Array.isArray(e.data.owners)&&-1!==e.data.owners.indexOf(a)&&e.data.href)return r=e.data.href,o=e.data.title,!0}))?(N.mailbox.sendTo("GIVE_PAD_ACCESS",{channel:i,href:r,title:o},{channel:t.user.notifications,curvePublic:t.user.curvePublic}),n()):n({error:"ENOTFOUND"}):n({error:"EINVAL"})};y.burnPad=function(e,t){var n=t.channel,r=I.b64AddSlashes(t.ownerKey||"");if(n&&r)try{var a=o.decodeBase64(r),i=I.CryptoAgility.signKeyPairFromSecretKey(a);l.create(N.network,{edPublic:o.encodeBase64(i.publicKey),edPrivate:o.encodeBase64(i.secretKey)},(function(e,r){e?console.error(e):y.pad.getMetadata(null,{channel:n},(function(e){r.removeOwnedChannel(n,(function(n){n?console.error(n):function(e,t){var n=e.channel,r=e.href,a=o.parsePadUrl(r),i=o.getSecrets(a.type,a.hash,e.password);if((!t||!t.error)&&t.mailbox){var s,c=I.createEncryptor(i.keys),u=[];try{"string"==typeof t.mailbox?u.push(c.decrypt(t.mailbox,!0,!0)):Object.keys(t.mailbox).forEach((function(e){u.push(c.decrypt(t.mailbox[e],!0,!0))}))}catch(e){console.error(e)}try{s=N.proxy.curvePublic}catch(e){return void console.error(e)}u.forEach((function(e){var t=JSON.parse(e);t.curvePublic!==s&&N.mailbox.sendTo("OWNED_PAD_REMOVED",{channel:n},{channel:t.notifications,curvePublic:t.curvePublic},(function(){}))}))}}(t,e)}))}))}))}catch(e){console.error(e)}else console.error("Can't delete BAR pad")},y.deleteMailboxMessage=function(e,t,n){N.anon_rpc?N.anon_rpc.send("DELETE_MAILBOX_MESSAGE",t,(function(e){n({error:e})})):n({error:"RPC_NOT_READY"})},y.getFullHistory=function(e,t,n){var r=N.network,o=r.historyKeeper,a=[],i=!1,s=function(e){if(!i){var o=function(e){try{return JSON.parse(e)}catch(e){return null}}(e);if(o)return"FULL_HISTORY_END"===o[0]?(n(a),r.off("message",s),void(i=!0)):void("FULL_HISTORY"===o[0]&&(o[1]&&o[1].validateKey||o[1][3]===t.channel&&(e=o[1][4])&&(e=e.replace(/cp\|(([A-Za-z0-9+\/=]+)\|)?/,""),t.debug?a.push({serverHash:e.slice(0,64),msg:e,author:o[1][1],time:o[1][5]}):a.push(e))))}};r.on("message",s),r.sendto(o,JSON.stringify(["GET_FULL_HISTORY",t.channel,t.validateKey]))},y.getHistory=function(e,t,n,r){var o=a.once(a.mkAsync(n)),i=N.network,s=i.historyKeeper,c=Math.floor(1e6*Math.random()),u=[],l=!1,f=function(e,n){if(!l&&n===s){var a=function(e){try{return JSON.parse(e)}catch(e){return null}}(e);if(a&&!(a.txid&&a.txid!==c||a.validateKey&&a.channel))if(a.error&&a.channel)a.channel===t.channel&&(i.off("message",f),l=!0,o({error:a.error}));else{if(1===a.state&&a.channel){if(a.channel!==t.channel)return;return o(u),i.off("message",f),void(l=!0)}Array.isArray(a)&&a[0]&&a[0]!==c||a[3]===t.channel&&(a[4]&&r?u.push({msg:e,hash:a[4].slice(0,64)}):(e=a[4])&&(e=e.replace(/cp\|(([A-Za-z0-9+\/=]+)\|)?/,""),u.push(e)))}}};i.on("message",f);var d={txid:c,lastKnownHash:t.lastKnownHash},h=["GET_HISTORY",t.channel,d];i.sendto(s,JSON.stringify(h))},y.getHistoryRange=function(e,t,n){var r,o=N.network,i=o.historyKeeper,s=[],c=!0,u=!1,l=!1,f=a.uid();o.on("message",(function(e){if(!l){var o=function(e){try{return JSON.parse(e)}catch(e){return null}}(e);if(o[1]===f){if("HISTORY_RANGE_ERROR"===o[0]){let e=o[2];return"ENOENT"===e?.code?(l=!0,void n({messages:s,isFull:!0})):void n({error:o[2]})}if("HISTORY_RANGE_END"===o[0])return n({messages:s,isFull:u,lastKnownHash:r}),void(l=!0);"HISTORY_RANGE"===o[0]&&(o[2]&&o[1].validateKey||o[2][3]===t.channel&&(e=o[2][4])&&(c&&(/^cp\|/.test(e)||t.toHash||(u=!0),r=e.slice(0,64),c=!1),e=e.replace(/cp\|(([A-Za-z0-9+\/=]+)\|)?/,""),s.push({serverHash:e.slice(0,64),msg:e,author:o[2][1],time:o[2][5]})))}else console.log("bad txid")}})),o.sendto(i,JSON.stringify(["GET_HISTORY_RANGE",t.channel,{from:t.lastKnownHash,to:t.toHash,cpCount:t.cpCount||2,txid:f}]))};var oe=function(e,n){e&&(e.deprecated||e.restricted||(n||e.on("change",["drive",t.SHARED_FOLDERS],(function(n,r,a){if(a.length>3&&"password"===a[3]){var i=a[2],s=e.drive[t.SHARED_FOLDERS][i],c=N.manager.user.userObject.getHref?N.manager.user.userObject.getHref(s):s.href,u=o.parsePadUrl(c),l=o.getSecrets(u.type,u.hash,n);return h.updatePassword(y,{oldChannel:l.channel,password:r,href:c},N.network,(function(){console.log("Shared folder password changed")})),!1}})),e.on("change",[],(function(e,r,o){if(n){if(o[0]===t.FILES_DATA&&"object"==typeof r&&r.channel&&!r.owners){var a=[r.channel];r.rtChannel&&a.push(r.rtChannel),r.lastVersion&&a.push(r.lastVersion),y.pinPads(null,a,(function(e){console.error(e)}))}if(o[0]===t.FILES_DATA&&"object"==typeof e&&e.channel&&!r){var i=[e.channel];N.manager.findChannel(e.channel).some((function(e){return e.fId!==n}))||(e.rtChannel&&i.push(e.rtChannel),e.lastVersion&&i.push(e.lastVersion),y.unpinPads(null,i,(function(e){console.error(e)})))}}e&&!r&&Array.isArray(o)&&(o[0]===t.FILES_DATA||"drive"===o[0]&&o[1]===t.FILES_DATA)&&setTimeout((function(){y.checkDeletedPad(e&&e.channel)})),k("DRIVE_CHANGE",{id:n,old:e,new:r,path:o})})),e.on("remove",[],(function(e,t){k("DRIVE_REMOVE",{id:n,old:e,path:t})}))))};y.loadSharedFolder=function(e,t,n,r,a){var i=Q(e);if(i){var s=o.parsePadUrl(n.href||n.roHref);s||s.hashData?h.load({isNew:a,network:N.network||N.networkPromise,store:i,Store:y,isNewChannel:y.isNewChannel},t,n,r):r({error:"EINVAL"})}else r({error:"ENOTFOUND"})};var ae=function(e,t,n,r){y.loadSharedFolder(null,e,t,n,r)};y.loadSharedFolderAnon=function(e,t,n){y.loadSharedFolder(null,t.id,t.data,(function(e){n({error:e?void 0:"EDELETED"})}))},y.addSharedFolder=function(e,n,r){G.reg((function(){var o=Q(n.teamId);o.manager.addSharedFolder(n,(function(a){a&&"object"==typeof a&&a.error?r(a):((n.teamId?o.sendEvent:k)("DRIVE_CHANGE",{path:["drive",t.FILES_DATA]},e),r(a))}))}))},y.updateSharedFolderPassword=function(e,t,n){h.updatePassword(y,t,N.network,n)},y.userObjectCommand=function(e,n,r){if(n&&n.cmd){var o=Q(n.teamId);if(o.offline)return(o.id?o.sendEvent:k)("NETWORK_DISCONNECT"),void r({error:"OFFLINE"});o.manager.command(n,(function(o){ee().forEach((function(n){(n.id?n.sendEvent:k)("DRIVE_CHANGE",{path:["drive",t.FILES_DATA]},e)})),z(n.teamId,(function(){r(o)}))}))}},y._removeClient=function(e){var t=P.indexOf(e);-1!==t&&P.splice(t,1),N.onlyoffice?.removeClient?.(e),N.mailbox?.removeClient?.(e),Object.keys(N.modules).forEach((function(t){N.modules[t]?.removeClient?.(e)})),y.pad?.removeClient?.(e)};y.refreshDriveUI=function(){ee().forEach((function(e){(e.id?e.sendEvent:k)("DRIVE_CHANGE",{path:["drive",t.FILES_DATA]})}))};var ie=function(e,t){const r=a.mkAsync(t);var o=N.proxy,i=N.drive;if(N.manager)r();else{var s=N.manager=n.create(i.proxy,{onSync:function(e){z(null,e)},edPublic:o.edPublic,pin:function(e,t){N.loggedIn?y.pinPads(null,e,t):t()},unpin:function(e,t){N.loggedIn?y.unpinPads(null,e,t):t()},loadSharedFolder:ae,settings:o.settings,removeOwnedChannel:function(e,t){y.pad.destroy("",e,t)},store:N,Store:y},{outer:!0,edPublic:N.proxy.edPublic,loggedIn:N.loggedIn,log:function(e){k("DRIVE_LOG",e)},rt:i.realtime}),c=N.userObject=s.user.userObject;M((function(e){N.sharedFolders={},N.handleSharedFolder=function(e,t){t?(N.sharedFolders[e]=t,N.driveEvents&&oe(t.proxy,e)):delete N.sharedFolders[e]},c.migrate(e())})).nThen((function(t){var n=N.network||N.networkPromise;h.loadSharedFolders(y,n,N,i.proxy,c,t,(t=>{var n={type:"sf",progress:100*t.progress/t.max};v(e,"LOADING_DRIVE",n)}),!0)})).nThen((function(t){re(w,"team",t,e)})).nThen((function(e){re(S,"calendar",e)})).nThen((function(){r()}))}};const se=(e=function(){})=>{re(m,"cursor",e),re(E,"integration",e),re(O,"messenger",e),re(D,"history",e),re(K,"badge",e),N.onlyoffice||(N.onlyoffice=b.init(N,(function(e,t,n){n.forEach((function(n){v(n,"OO_EVENT",{ev:e,data:t})}))}))),N&&(N.messenger=N.modules.messenger)},ce=(e,t,n)=>{const r=a.mkAsync(n);ie(e,(function(){Y.fire(),r(t)}))};var ue=function(e,t,n){N.ready=!0;var c=N.proxy,u=N.manager,f=N.userObject;M((function(n){c.settings||(c.settings=W),c.forms||(c.forms={}),c.friends_pending||(c.friends_pending={}),c.form_seed||(c.form_seed=o.createChannelId()),u||(ce(e,t,n()),u=N.manager,f=N.userObject),$(0,0,n()),function(e,t,n){if(!N.loggedIn)return n();N.rpc?n(Z):l.create(N.network,N.proxy,(function(e,t){e?n({error:e}):(N.rpc=t,N.onRpcReadyEvt.fire(),y.getPinLimit(null,null,(function(e){e.error&&console.error(e.error),Z.limit=e.limit,Z.plan=e.plan,Z.note=e.note,n(e)})))}),d)}(0,0,n()),v(e,"LOADING_DRIVE",{type:"migrate",progress:0})})).nThen((function(t){void 0===c.version&&(c.version=11),r(c,t(),(function(t,n){v(e,"LOADING_DRIVE",{type:"migrate",progress:n})}),N)})).nThen((function(t){v(e,"LOADING_DRIVE",{type:"sf",progress:0}),f.fixFiles(),h.loadSharedFolders(y,N.network,N,N.drive.proxy,f,t,(t=>{var n={type:"sf",progress:100*t.progress/t.max};v(e,"LOADING_DRIVE",n)})),se(t),re(_,"profile",t),re(S,"calendar",t),re(g,"support",t),M((e=>{N.modules.team&&N.modules.team.onReady(e)}))})).nThen((function(){var e,r=function(){T([],"REQUEST_LOGIN")};N.loggedIn&&(function(e){if(N.rpc){var t=X(!1),n=o.hashChannelList(t);N.rpc.getServerHash((function(t,r){t?e(t):e(null,r===n)}))}else e({error:"RPC_NOT_READY"})}((function(e,t){t||function(e){if(N.rpc){var t=X(!1);N.rpc.reset(t,(function(t){e(t||null)}))}else e({error:"RPC_NOT_READY"})}((function(e){if(e)return console.error(e);console.log("RESET DONE")}))})),"number"!=typeof c.loginToken&&(c[i.tokenKey]=N.data.localToken||Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)),t[i.tokenKey]=c[i.tokenKey],N.data.localToken&&N.data.localToken!==c[i.tokenKey])?r():(t.feedback=a.find(c,["settings","general","allowUserFeedback"]),s.init(t.feedback),N.returned=t,"function"==typeof n&&n(t),N.offline=!1,k("NETWORK_RECONNECT"),T([],"UPDATE_METADATA"),T([],"STORE_READY",t),"string"==typeof c.uid&&32===c.uid.length||(console.log("generating a persistent identifier"),c.uid=o.createChannelId()),!N.loggedIn||y.hasSigningKeys()&&y.hasCurveKeys()?(c.on("change",[i.displayNameKey],(function(e,t){"string"==typeof t&&T([],"UPDATE_METADATA")})),c.on("change",["profile"],(function(){T([],"UPDATE_METADATA")})),c.on("change",["friends"],(function(e,t,n){if(T([],"UPDATE_METADATA"),N.messenger&&void 0===e){var r=n.slice(-1)[0],o=c.friends&&c.friends[r];N.messenger.onFriendAdded(o)}})),c.on("remove",["friends"],(function(e,t){if(T([],"UPDATE_METADATA"),N.messenger){var n=t[1];n&&"channel"===t[2]&&N.messenger.onFriendRemoved(n,e)}})),c.on("change",["friends_pending"],(function(){T([],"UPDATE_METADATA")})),c.on("remove",["friends_pending"],(function(){T([],"UPDATE_METADATA")})),c.on("change",["settings"],(function(){T([],"UPDATE_METADATA")})),c.on("change",[i.tokenKey],(function(){N.isDeleted||"DELETED"===c[i.tokenKey]||T([],"UPDATE_TOKEN",{token:c[i.tokenKey]})})),N.mailbox=A.init({Store:y,store:N,updateMetadata:function(){T([],"UPDATE_METADATA")},updateDrive:function(){k("DRIVE_CHANGE",{path:["drive","filesData"]})},pinPads:function(e,t){y.pinPads(null,e,t)}},e,(function(e,t,n,r){var o=a.once(r||function(){});n.forEach((function(n){v(n,"MAILBOX_EVENT",{ev:e,data:t},o)}))})),G.fire()):r())}))};const le=(e,t,n,r)=>{if(N.accountModule)return N.accountModule;const o=F.init({userHash:t.userHash,anonHash:t.anonHash,cache:t.cache,form_seed:t.form_seed,store:N,broadcast:T,postMessage:v});N.accountModule=o;const{channel:i,onAccountReady:s,onAccountCacheReady:c,onDisconnect:u,onReconnect:l}=o;N.driveChannel=i,c((e=>{N.cacheReturned||=e,n(e)})),s((e=>{N.returned||=e,r(e)})),u((()=>{k("NETWORK_DISCONNECT")})),l((()=>{k("NETWORK_RECONNECT")}));return setInterval((function(){var e=[];const t=y.pad.getChannels();Object.keys(t).forEach((function(n){var r=t[n].clients;Array.prototype.push.apply(e,r)})),(e=a.deduplicateString(e)).forEach((function(e){var t=0,n=function(){if(t>=2)return y._removeClient(e),v(e,"TIMEOUT"),void console.error("TIMEOUT",e);t++;var r=setTimeout(n,3e4);v(e,"PING",null,(function(e){e&&console.error(e),clearTimeout(r)}))};n()}))}),12e4),o},fe=(e,t,n,r)=>{const o=a.once((e=>{const t=L.init({account:e,store:N,broadcast:T,postMessage:v}),{onDriveReady:o,onDriveCacheReady:a,onDisconnect:i,onReconnect:s}=t;a((()=>{n(N.cacheReturned||N.returned)})),o((()=>{J.fire(),r(N.returned)})),i((()=>{})),s((()=>{}))})),i=()=>{},s=le(0,t,i,i);s.onAccountCacheReady((()=>{o(s)})),s.onAccountReady((()=>{o(s)}))};y.disableCache=function(e,t,n){t?d.disable():d.enable(),n()};var de=!1;const he=e=>{if(N?.network?.historyKeeper)return setTimeout(e);const t=t=>{N.network||=t;t.join("0000000000000000000000000000000000").then((function(n){let r;n.members.forEach((e=>{16===e.length&&(r=e)})),t.historyKeeper=r,n.leave(),e()}),(function(t){console.error(t),e({error:"GET_HK"})}))};if(N.network)return t(N.network);N.networkPromise?.then(t)};var pe=function(e,t,n){const r=a.once(t);var o=function(){se();let e=()=>{$(0,0,(function(){s.send("NO_DRIVE",!0),r({})}))};he((t=>{if(!t)return n?((e,t)=>{if(N.rpc)t(N.rpc);else{var n=I.CryptoAgility.signKeyPair(),r={edPublic:a.encodeBase64(n.publicKey),edPrivate:a.encodeBase64(n.secretKey)};l.create(N.network,r,(function(e,n){e?t({error:e}):(N.rpc=n,t(n))}))}})(0,e):void e()})),N.network||n||r({})};if(!N.network){var i=x.getWebsocketURL();return N.networkPromise=R.connect(i),o(),N.networkPromise.then((e=>{N.network!==e&&(N.network?(e.disconnect(),e=N.network):N.network=e)}),(function(e){console.error(e),r({error:"OFFLINE"})}))}o()};const ye=(e,t,n)=>{N.manager?Y.reg((function(){he((r=>{N.network||=r,ue(e,t,(()=>{n(t)}))}))})):ue(e,t,(()=>{n(t)}))};return y.init=function(e,t,n){var r=a.once((function(r){t.driveEvents&&function(e){Y.reg((()=>{-1===P.indexOf(e)&&P.push(e),N.driveEvents||(N.driveEvents=!0,oe(N.proxy),Object.keys(N.manager.folders).forEach((function(e){var t=N.manager.folders[e].proxy;oe(t,e)})))}))}(e),n(r)}));if(de&&!N.returned&&t.cache)Y.reg((function(){r({state:"ALREADY_INIT",returned:N.cacheReturned})}));else{if(de)return N.networkTimeout&&v(e,"LOADING_DRIVE",{type:"offline"}),void G.reg((function(){r({state:"ALREADY_INIT",returned:N.returned})}));t.disableCache&&d.disable(),t.noDrive&&!t.requires&&(t.requires="pad"),((e,t,n)=>{if(t.neverDrive||t.noDrive&&!t.userHash&&!t.anonHash)return t.neverDrive&&(N.neverCache=!0),void pe(0,(e=>{e?.error&&s.send("NO_DRIVE_ERROR",!0),t.neverDrive&&(e.tempKeys=N?.tempKeys),n(e)}),!!t.neverDrive);const r=t.requires,o=!t.noDrive;de=!0,N.data=t;let c=e=>{1===Object.keys(N.proxy).length&&s.send("FIRST_APP_USE",!0),e&&e.error&&(de=!1)};if("pad"===r&&!o)return void pe(0,(function(r){if(r&&r.error)return;n(r);let o=a.once((()=>{fe(0,t,(t=>{ce(e,t,c)}),(t=>{ye(e,t,c)}))}));y.pad.onCacheReady((()=>{N.network||o()})),y.pad.onJoined(o),q.reg(o)}));if("file"===r&&!o)return void pe(0,(function(r){r&&r.error||(n(r),fe(0,t,(t=>{ce(e,t,c)}),(t=>{ye(e,t,c)})))}));if("team"===r){let r=!1;const o=o=>a=>{r||(r=!0,M((e=>{o||$(0,0,e())})).nThen((t=>{re(w,"team",t,e)})).nThen((e=>{!o&&N.modules.team&&N.modules.team.onReady(e)})).nThen((()=>{n(a),fe(0,t,(t=>{ce(e,t,c)}),(t=>{ye(e,t,c)}))})))};return void le(0,t,o(!0),o(!1))}if("drive"===r)return void fe(0,t,(t=>{n(t),ce(e,t,c)}),(t=>{n(t),ye(e,t,c)}));let u=e=>{c(e);const t=i.prefersDriveRedirectKey,r=a.find(N,["proxy","settings","general",t]);e[t]=r,n(e)};fe(0,t,(t=>{ce(e,t,u)}),(t=>{ye(e,t,u)}))})(e,t,a.once((e=>{"GET_HK"!==e.error?r(e):r({error:"ERROR"})})))}},G.reg((function(){var e=+new Date-7776e6;d.getKeys((function(t,n){if(t)console.error(t);else{var r=function(){if(n.length){var t=n.pop();d.getTime(t,(function(n,o){n?r():!o||o<e?d.clearChannel(t,r()):r()}))}};r()}}))})),y.disconnect=function(){globalThis.accountDeletion||N.network&&N.network.disconnect()},y}}})(Xt(),Et(),Tt(),gn(),Fe(),Ne(),Oe(),nt(),mt(),Zt(),sn(),an(),Ge(),St(),An,kn,lr,fr(),dr(),hr(),pr(),mn(),yr(),mr(),gr(),Er(),Cr(),Hr,Gt(),Ee(),ye(),I(),O(),S(),u(),Dt()),Fr}var jr,Ur,Br=Kr(),Vr=t({__proto__:null,default:r(Br)},[Br]);var Gr,Yr,Jr,qr,Wr,Qr={exports:{}};function zr(){return Gr||(Gr=1,function(e){(()=>{const t=(e,t={})=>({create:function(n,r,o){var a,i=[],s=e.mkEvent(!0);n.reg((function(e){if(!a){var t=e.data;if("_READY"===t)return r("_READY"),a=!0,s.fire(),void i.forEach((function(e){n.fire(e)}));i.push(t)}}));var c={},u={},l={},f=[],d={},h={};h.query=function(e,t,n,o){var a,i=Math.random().toString(16).replace("0.","")+Math.random().toString(16).replace("0.",""),c=(o=o||{}).timeout||3e4;c>0&&(a=setTimeout((function(){delete u[i],n("TIMEOUT")}),c)),l[i]=function(e){clearTimeout(a),delete l[i],e&&(delete u[i],n("UNHANDLED"))},u[i]=function(e,t){delete u[i],n(void 0,e.content,t)},s.reg((function(){var n={txid:i,content:t,q:e,raw:o.raw};r(o.raw?n:JSON.stringify(n))}))};var p=h.event=function(e,t,n){n=n||{},s.reg((function(){var o={content:t,q:e,raw:n.raw};r(n.raw?o:JSON.stringify(o))}))};h.on=function(e,t,n){var o=function(e,n,o){t(e.content,(function(t){var n={txid:e.txid,content:t};r(o?n:JSON.stringify(n))}),n)};return(c[e]=c[e]||[]).push(o),n||p("EV_REGISTER_HANDLER",e),{stop:function(){var t=c[e].indexOf(o);-1!==t&&c[e].splice(t,1)}}},h.whenReg=function(e,t,n){var r=n;f.indexOf(e)>-1?t():r=!0,r&&(d[e]=d[e]||[]).push(t)},h.onReg=function(e,t){h.whenReg(e,t,!0)},h.on("EV_REGISTER_HANDLER",(function(e){d[e]&&(d[e].forEach((function(e){e()})),delete d[e]),f.push(e)}));var y=!1;h.onReady=function(e){y?e():"function"==typeof e&&h.on("EV_RPC_READY",(function(){y=!0,e()}))},h.ready=function(){h.whenReg("EV_RPC_READY",(function(){h.event("EV_RPC_READY")}))};var v=[""];t.httpUnsafeOrigin?(v.push(t.httpUnsafeOrigin),v.push(t.httpSafeOrigin)):globalThis.location&&v.push(globalThis.location.origin),n.reg((function(e){if(a&&e.data&&"_READY"!==e.data&&v.includes(e.origin)){var t;try{t="object"==typeof e.data?e.data:JSON.parse(e.data)}catch(e){return void console.warn(e)}void 0!==t.ack?l[t.txid]&&l[t.txid](!t.ack):"string"==typeof t.q?c[t.q]?(t.txid&&r(JSON.stringify({txid:t.txid,ack:!0})),c[t.q].forEach((function(n){n(t||JSON.parse(e.data),e,t&&t.raw),t=void 0}))):t.txid&&r(JSON.stringify({txid:t.txid,ack:!1})):void 0===t.q&&u[t.txid]&&u[t.txid](t,e)}})),r("_READY"),o(h)}});e.exports&&(e.exports=t(Ne()))})()}(Qr)),Qr.exports}function Xr(){if(Jr)return Yr;Jr=1;var e;return Yr=((e,t,n)=>{const r={};let o,a,i={},s=()=>{};return r.init=t=>{if(a)return;a=e.create({query:(e,t,n,r)=>{r=r||function(){},i[e].chan.query(t,n,(function(e,t){r(e?{error:e}:t)}))},broadcast:(e,t,n,r)=>{r=r||function(){},Object.keys(i).forEach((o=>{-1===e.indexOf(+o)&&i[o].chan.query(t,n,((e,t)=>{r(e?{error:e}:t)}))}))}}),s=t},r.initClient=(e,r)=>{if(!a)return console.error("Not initialized"),void r("NOT_INIT");const{postMsg:c}=e,u=n.mkEvent(),l=Number(Math.floor(Math.random()*Number.MAX_SAFE_INTEGER)),f=()=>{a._removeClient(l)};t.create(u,c,(function(e){let t=i[l]={chan:e};console.debug("SharedW Channel created"),Object.keys(a.queries).forEach((function(n){"CONNECT"!==n&&"JOIN_PAD"!==n&&"SEND_PAD_MSG"!==n&&"STOPWORKER"!==n&&e.on(n,(function(e,r){try{a.queries[n](l,e,r)}catch(t){console.error("Error in webworker when executing query "+n),console.error(t),console.log(e)}"DISCONNECT"===n&&(f(),globalThis.accountDeletion&&globalThis.accountDeletion===t.id&&(a=void 0,o=void 0))}))})),e.on("STOPWORKER",(function(e,t){s(),a.queries.DISCONNECT(l,e,t)})),e.on("CONNECT",(function(e,t){console.debug("Connecting to store..."),a.queries.CONNECT(l,e,(function(e){if(e&&"ALREADY_INIT"===e.state)return console.debug("Store already exists!"),o=o||e.returned,void t(e);o=e,t(e)}))})),e.on("JOIN_PAD",(function(e,n){t.channelId=e.channel;try{a.queries.JOIN_PAD(l,e,n)}catch(t){console.error("Error in webworker when executing query JOIN_PAD"),console.error(t),console.log(e)}})),e.on("SEND_PAD_MSG",(function(e,n){var r={msg:e,channel:t.channelId};try{a.queries.SEND_PAD_MSG(l,r,n)}catch(e){console.error("Error in webworker when executing query SEND_PAD_MSG"),console.error(e),console.log(r)}})),r(u,f)}),!0)},r})((Ur||(Ur=1,e=Kr(),jr={create:function(t){var n=e.create(t),r={},o=r.queries={CONNECT:n.init,DISCONNECT:n.disconnect,PING:function(e,t,n){n()},CACHE_DISABLE:n.disableCache,GET_PIN_LIMIT:n.getPinLimit,PIN_PADS:n.pinPads,UNPIN_PADS:n.unpinPads,GET_PINNED_USAGE:n.getPinnedUsage,GET_DELETED_PADS:n.getDeletedPads,UPLOAD_CHUNK:n.uploadChunk,UPLOAD_COMPLETE:n.uploadComplete,UPLOAD_STATUS:n.uploadStatus,UPLOAD_CANCEL:n.uploadCancel,ANON_RPC_MESSAGE:n.anonRpcMsg,GET_FILE_SIZE:n.getFileSize,GET_MULTIPLE_FILE_SIZE:n.getMultipleFileSize,GET:n.get,SET:n.set,ADD_PAD:n.addPad,SET_PAD_TITLE:n.setPadTitle,MOVE_TO_TRASH:n.moveToTrash,RESET_DRIVE:n.resetDrive,GET_METADATA:n.getMetadata,IS_ONLY_IN_SHARED_FOLDER:n.isOnlyInSharedFolder,SET_DISPLAY_NAME:n.setDisplayName,SET_PAD_ATTRIBUTE:n.setPadAttribute,GET_PAD_ATTRIBUTE:n.getPadAttribute,SET_ATTRIBUTE:n.setAttribute,GET_ATTRIBUTE:n.getAttribute,LIST_ALL_TAGS:n.listAllTags,GET_TEMPLATES:n.getTemplates,GET_SECURE_FILES_LIST:n.getSecureFilesList,GET_PAD_DATA:n.getPadData,GET_PAD_DATA_FROM_CHANNEL:n.getPadDataFromChannel,GET_STRONGER_HASH:n.getStrongerHash,INCREMENT_TEMPLATE_USE:n.incrementTemplateUse,GET_SHARED_FOLDER:n.getSharedFolder,ADD_SHARED_FOLDER:n.addSharedFolder,LOAD_SHARED_FOLDER:n.loadSharedFolderAnon,RESTORE_SHARED_FOLDER:n.restoreSharedFolder,UPDATE_SHARED_FOLDER_PASSWORD:n.updateSharedFolderPassword,ANSWER_FRIEND_REQUEST:n.answerFriendRequest,SEND_FRIEND_REQUEST:n.sendFriendRequest,ANON_GET_PREVIEW_CONTENT:n.anonGetPreviewContent,OO_COMMAND:n.onlyoffice.execCommand,MAILBOX_COMMAND:n.mailbox.execCommand,UNIVERSAL_COMMAND:n.universal.execCommand,SEND_PAD_MSG:n.pad.sendMessage,JOIN_PAD:n.pad.join,LEAVE_PAD:n.pad.leave,REMOVE_OWNED_CHANNEL:n.pad.destroy,CLEAR_OWNED_CHANNEL:n.pad.clear,CORRUPTED_CACHE:n.pad.onCorruptedCache,GET_LAST_HASH:n.pad.getLastHash,GET_FULL_HISTORY:n.getFullHistory,GET_HISTORY:n.getHistory,GET_HISTORY_RANGE:n.getHistoryRange,IS_NEW_CHANNEL:n.isNewChannel,CONTACT_PAD_OWNER:n.contactPadOwner,GIVE_PAD_ACCESS:n.givePadAccess,BURN_PAD:n.burnPad,GET_PAD_METADATA:n.pad?.getMetadata,SET_PAD_METADATA:n.pad?.setMetadata,CHANGE_PAD_PASSWORD_PIN:n.changePadPasswordPin,GET_SNAPSHOT:n.getSnapshot,DELETE_MAILBOX_MESSAGE:n.deleteMailboxMessage,DRIVE_USEROBJECT:n.userObjectCommand,GET_DRIVE:n.drive.get,SET_DRIVE:n.drive.set,MIGRATE_ANON_DRIVE:n.drive.migrateAnon,HAS_DRIVE:n.drive.exists,DELETE_ACCOUNT:n.deleteAccount,REMOVE_OWNED_PADS:n.removeOwnedPads,ADMIN_RPC:n.adminRpc,ADMIN_ADD_MAILBOX:n.addAdminMailbox};return r.query=function(e,t,n){o[e]?o[e]("0",t,n):console.error("UNHANDLED_STORE_RPC")},r._removeClient=n._removeClient,r}}),jr),zr(),Ne()),Yr}var Zr,$r,eo=function(){if(Wr)return qr;Wr=1;const e=Xr();return qr={start:t=>{let n=!1,r=()=>{globalThis.close()};globalThis.window=globalThis,addEventListener("connect",(o=>{console.debug("New SharedWorker client");const a=o.ports[0],i=e=>{a.postMessage(e)};let s,c=!1,u=()=>{};a.onmessage=function(o){if("INIT"===o.data?.type){if((o=>{n||(t(o),e.init(r),n=!0)})(o.data.cfg),c)return;c=!0,e.initClient({postMsg:i},(function(e,t){s=e,u=t,i("SW_READY")}))}else"CLOSE"===o.data?(console.debug("leave"),u()):s&&s.fire(o)}}))}}}();var to,no,ro=function(){if($r)return Zr;$r=1;const e=Xr();return Zr={start:t=>{let n,r=!1;const o=()=>{globalThis.close()},a=e=>{postMessage(e)};globalThis.window=globalThis,onmessage=function(i){if("INIT"===i.data?.type){let s=i.data.cfg;if(r)return;return t(s),e.init(o),r=!0,void e.initClient({postMsg:a},(function(e){n=e,a("WW_READY")}))}n&&n.fire(i)}}}}();var oo=function(){if(no)return to;no=1;const e=Xr(),t=Ne();return to={start:n=>{let r,o=!1,a=!1;const i=t.mkEvent(),s=()=>{a=!0},c=e=>{a||i.fire(e)};return{init:t=>{o||(n(t),e.init(s),o=!0,e.initClient({postMsg:c},(function(e){r=e,c("STORE_READY")})))},onMessage:e=>{i.reg((t=>{setTimeout((()=>{e(t)}))}))},query:e=>{r&&!a&&r.fire({data:e,origin:""})}}}}}(),ao=gn(),io=t({__proto__:null,default:r(ao)},[ao]),so=mn(),co=t({__proto__:null,default:r(so)},[so]),uo=fr(),lo=t({__proto__:null,default:r(uo)},[uo]),fo=dr(),ho=t({__proto__:null,default:r(fo)},[fo]),po=gr(),yo=t({__proto__:null,default:r(po)},[po]),vo=Cr(),mo=t({__proto__:null,default:r(vo)},[vo]);let go=e=>{[at,kt,Te,Nt,_e,io,Qt,jt,dt,lo,ho,mo,Vr,Ze,co,yo,Mr].forEach((t=>{"function"==typeof t.setCustomize&&t.setCustomize(e)}))},Eo="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope,bo="undefined"!=typeof SharedWorkerGlobalScope&&self instanceof SharedWorkerGlobalScope;e.store={},bo?eo.start(go):Eo?ro.start(go):("undefined"!=typeof module&&module.exports,e.store=oo.start(go)),e.start=go}));
|