!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).nextc4=e()}(this,(function(){"use strict";var t={readUInt32BE:function(t,e,r){if(e+(r=Math.min(r,4))>t.length)throw"Error: exceed the buffer boundary.";for(var n=0,o=0;o<r;++o)n|=t[e+o]<<8*(r-1-o);return n>>>0},writeUInt32BE:function(t,e,r,n){if(e+(n=Math.min(n,4))>t.length)throw"Error: exceed the buffer boundary.";for(var o=n-1;o>=0;o--)t[e+o]=255&r,r>>>=8},toString:function(t){if(!t)return null;for(var e=[],r=0,n=t.length;r<n;++r)e[r]=String.fromCodePoint(t[r]);return e.join("")},toBuffer:function(t){if(!t)return null;for(var e=t.length,r=new Uint32Array(e),n=0,o=0;o<e;++o){var i=t.codePointAt(o);r[n++]=i,i>65535&&o++}return r.slice(0,n)}},e={},r={},n=function(t){var e=typeof t;if("object"===e){if(!t)return"null";if(t instanceof Array)return"array";if(t instanceof Object)return e;var r=Object.prototype.toString.call(t);if("[object Window]"===r)return"object";if("[object Array]"===r||"number"==typeof t.length&&void 0!==t.splice&&void 0!==t.propertyIsEnumerable&&!t.propertyIsEnumerable("splice"))return"array";if("[object Function]"===r||void 0!==t.call&&void 0!==t.propertyIsEnumerable&&!t.propertyIsEnumerable("call"))return"function"}else if("function"===e&&void 0===t.call)return"object";return e},o=function(t){var e=typeof t;return"object"===e&&null!=t||"function"===e};r.abstractMethod=function(){throw Error("unimplemented abstract method")},r.nullFunction=function(){},r.inherits=function(t,e){function r(){}r.prototype=e.prototype,t.super_=e.prototype,t.prototype=new r,t.prototype.constructor=t},r.typeOf=n,r.isNull=function(t){return null===t},r.isDefAndNotNull=function(t){return null!=t},r.isArray=function(t){return"array"===n(t)},r.isArrayLike=function(t){var e=n(t);return"array"===e||"object"===e&&"number"==typeof t.length},r.isDateLike=function(t){return o(t)&&"function"==typeof t.getFullYear},r.isString=function(t){return"string"==typeof t},r.isBoolean=function(t){return"boolean"==typeof t},r.isNumber=function(t){return"number"==typeof t},r.isFunction=function(t){return"function"===n(t)},r.isObject=o;const i=r;var s=function(t,e,r){this.decoder_=t,this.encoder_=e,r&&(this.converters_=i.isArray(r)?r.slice():[r])};s.prototype.decoder_,s.prototype.encoder_,s.prototype.converters_,s.prototype.match=function(t){return this.decoder_.match(t)},s.prototype.process=function(t){var e=this.decoder_.decode(t);return e?(this.converters_&&this.converters_.forEach((function(t){e=t.convert(e)}),this),this.encoder_.encode(e)):null},e.Channel=s;var f={};var u=function(t,e){this.name_=t,this.type_=e};u.prototype.name_,u.prototype.type_,u.prototype.description_,u.prototype.version_,u.prototype.getName=function(){return this.name_},u.prototype.getType=function(){return this.type_},f.CharmapType={DECODER:"decoder",CONVERTER:"converter",ENCODER:"encoder"},f.Charmap=u;var a={},c=function(t){this.bytes_=t.length,this.ranges_=t};c.prototype.bytes_,c.prototype.ranges_,c.prototype.getBytes=function(){return this.bytes_},c.prototype.match=function(t){if(!this.bytes_)return!1;for(var e,r=this.bytes_-1;r>=0;--r){if((e=255&t)<this.ranges_[r].from||e>this.ranges_[r].to)return!1;t>>=8}return!0},c.prototype.getBlockSize=function(){if(!this.bytes_)return 0;var t=this.ranges_[this.bytes_-1];return t.to-t.from+1},c.prototype.getBlockCount=function(){if(!this.bytes_)return 0;for(var t=1,e=0;e<this.bytes_-1;++e)t*=this.ranges_[e].to-this.ranges_[e].from+1;return t},c.prototype.getIndexingOffset=function(t){if(!this.bytes_)return-1;for(var e,r=this.getCarries_(),n=0,o=this.bytes_-1;o>=0;--o){if((e=255&t)<this.ranges_[o].from||e>this.ranges_[o].to)return-1;n+=(e-this.ranges_[o].from)*r[o],t>>=8}return n},c.prototype.getCodePoint=function(t){if(!this.bytes_)return-1;for(var e=this.getCarries_(),r=0,n=0;n<this.bytes_;++n)t>=e[n]?(r|=Math.floor(t/e[n])+this.ranges_[n].from<<8*(this.bytes_-1-n),t%=e[n]):r|=this.ranges_[n].from<<8*(this.bytes_-1-n);return r>>>0},c.prototype.getCarries_=function(){if(!this.carries_){this.carries_=[],this.carries_[this.bytes_-1]=1;for(var t=this.bytes_-2;t>=0;--t)this.carries_[t]=this.carries_[t+1]*(this.ranges_[t+1].to-this.ranges_[t+1].from+1)}return this.carries_},c.prototype.consume=function(t,e){if(!this.bytes_)return!1;if(e+this.bytes_>t.length)return!1;for(var r=0;r<this.bytes_;++r)if(t[e+r]<this.ranges_[r].from||t[e+r]>this.ranges_[r].to)return!1;return!0},c.build=function(t){if(!t||!t.length)return null;var e=[];return t.forEach((function(t){var r=t.split("~");if(1===r.length){var n=+r[0];isNaN(n)||e.push({from:n,to:n})}else if(2===r.length){var o=+r[0],i=+r[1];!isNaN(o)&&!isNaN(i)&&o>=0&&o<=255&&i>=0&&i<=255&&e.push({from:Math.min(o,i),to:Math.max(o,i)})}})),e.length?new c(e):null},a.Condition=c;var h={UNICODE_UNKNOWN_CHAR:65533,UNICODE_BYTE_ORDER_MARK:65279};h.UTF8_BOM=new Uint8Array([239,187,191]),h.UTF16LE_BOM=new Uint8Array([255,254]),h.UTF16BE_BOM=new Uint8Array([254,255]),h.MBCS_UNKNOWN_CHAR=63,h.MBCS_WHITE_SPACE={GBK:41377,GB18030:41377},h.EMBEDDED_BASE64_PREFIX="data:application/octet-stream;base64,";var p={},_={};const{Condition:d}=a;var l=function(t){this.begin_=t.begin,this.end_=t.end,this.condition_=d.build(t.condition),this.reference_=t.reference,this.offset_=t.offset,this.characterset_=t.characterset};l.prototype.begin_,l.prototype.end_,l.prototype.condition_,l.prototype.reference_,l.prototype.offset_,l.prototype.characterset_,l.prototype.getBegin=function(){return this.begin_},l.prototype.getEnd=function(){return this.end_},l.prototype.getOffset=function(){return this.offset_},l.prototype.getReference=function(){return this.reference_},l.prototype.getCondition=function(){return this.condition_};var y=function(t){this.segments_=[],t&&t.forEach((function(t){t instanceof l||(t=new l(t)),this.segments_.push(t)}),this)};y.prototype.segments_,y.prototype.find=function(t){for(var e=0,r=this.segments_.length;e<r;++e)if(t>=this.segments_[e].begin_&&t<=this.segments_[e].end_&&(!this.segments_[e].condition_||this.segments_[e].condition_.match(t)))return this.segments_[e];return null},_.Reference={ASCII:"ascii",UNDEFINED:"undefined",BUFFER:"buffer",INDEXING_BUFFER:"indexing-buffer",SELF:"self",GB18030_UNICODE_SP_MAPPING:"gb18030-unicode-sp-mapping"},_.Segment=l,_.Segments=y;var g={};const E="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";g.encode=function(t){if(!t)return"";var e=t.length;if(!e)return"";for(var r=[],n=e%3,o=e-n,i=0,s=0,f=0;f<o;f+=3)i=t[f]<<16|t[f+1]<<8|t[f+2],r[s++]=E[i>>>18&63],r[s++]=E[i>>>12&63],r[s++]=E[i>>>6&63],r[s++]=E[63&i];return 1===n?(r[s++]=E[t[o]>>>2&63],r[s++]=E[t[o]<<4&48],r[s++]="=",r[s]="="):2===n&&(r[s++]=E[t[o]>>>2&63],r[s++]=E[t[o]<<4&48|t[o+1]>>>4&15],r[s++]=E[t[o+1]<<2&60],r[s]="="),r.join("")};const v=function(){for(var t={},e=0;e<64;++e)t[E[e]]=e;return t}();g.decode=function(t){if(!t)return new Uint8Array(0);var e=t.length;if(!e)return new Uint8Array(0);t.endsWith("==")?(t=t.substring(0,e-2),e-=2):t.endsWith("=")&&(t=t.substring(0,e-1),e-=1);var r=e%4,n=3*Math.floor(e/4);if(0!==r){if(1===r)throw"Invalid base64 string.";var o=v[t[e-1]];if(void 0===o)throw"Invalid base64 string.";if(2===r&&0!=(15&o))throw"Invalid base64 string.";if(3===r&&0!=(3&o))throw"Invalid base64 string.";n+=2===r?1:2}for(var i,s,f,u,a=new Uint8Array(n),c=e-r,h=0,p=0,_=0;_<c;_+=4){if(i=v[t[_]],s=v[t[_+1]],f=v[t[_+2]],u=v[t[_+3]],void 0===i||void 0===s||void 0===f||void 0===u)throw"Invalid base64 string.";h=i<<18|s<<12|f<<6|u,a[p++]=h>>>16&255,a[p++]=h>>>8&255,a[p++]=255&h}if(2===r){if(i=v[t[c]],s=v[t[c+1]],void 0===i)throw"Invalid base64 string.";a[p]=i<<2|s>>>4}else if(3===r){if(i=v[t[c]],s=v[t[c+1]],f=v[t[c+2]],void 0===i||void 0===s)throw"Invalid base64 string.";a[p++]=i<<2|s>>>4,a[p]=(15&s)<<4|f>>>2}return a};const{Charmap:m,CharmapType:B}=f,C=h,U=r,b=_,N=g;var w=function(t){if(!t||!t.name)throw"options should provide name property at least";if(m.call(this,t.name,B.CONVERTER),this.description_=t.description,this.version_=t.version,this.segments_=new b.Segments(t.segments),this.mappingBuffer_=null,t.buffer)if(t.buffer instanceof Uint16Array||t.buffer instanceof Uint32Array)this.mappingBuffer_=t.buffer;else if(U.isString(t.buffer)&&t.buffer.startsWith(C.EMBEDDED_BASE64_PREFIX)){var e=t.buffer.substring(C.EMBEDDED_BASE64_PREFIX.length),r=N.decode(e.trim());this.mappingBuffer_=2===t.byte?new Uint16Array(r.buffer):new Uint32Array(r.buffer)}};U.inherits(w,m),w.prototype.description_,w.prototype.version_,w.prototype.segments_,w.prototype.mappingBuffer_,w.prototype.getBytesOfCodepoint=function(){return this.mappingBuffer_?this.mappingBuffer_ instanceof Uint16Array?2:this.mappingBuffer_ instanceof Uint32Array?4:0:0},w.prototype.convert=function(t){if(!t)return null;for(var e=new Uint32Array(t.length),r=0,n=t.length;r<n;++r)e[r]=this.convertChar_(t[r]);return e},w.prototype.convertChar_=function(t){t>>>=0;var e=this.segments_.find(t);if(!e)return C.UNICODE_UNKNOWN_CHAR;switch(e.getReference()){case b.Reference.SELF:return t;case b.Reference.BUFFER:return this.mappingBuffer_?this.mappingBuffer_[t-e.getBegin()+e.getOffset()]:C.UNICODE_UNKNOWN_CHAR;default:return C.UNICODE_UNKNOWN_CHAR}},p.Converter=w;var O={},F={},R={};const{Condition:A}=a,T=h;var D=A.build(["0x90~0xE3","0x30~0x39","0x81~0xFE","0x30~0x39"]);R.convertGB18030ToUnicodeSP=function(t){if(t<2419097904||t>3811744309)return T.UNICODE_UNKNOWN_CHAR;var e=D.getIndexingOffset(t);return-1===e||e>1048575?T.UNICODE_UNKNOWN_CHAR:e+65536},R.convertUnicodeSPToGB18030=function(t){if(t<65536||t>1114111)return T.MBCS_WHITE_SPACE.GB18030;var e=t-65536;return D.getCodePoint(e)};const{Condition:I}=a,S=r,M=h,P=_,k=R;var x=function(){};x.prototype.decode=function(t,e){var r=this.test(t,e);if(-1===r)return null;for(var n,o=new Uint32Array(r),i=S.isNumber(e)?e:0,s=0,f=t.length;i<f;++s){if(0===(n=this.consume(t,i,o,s)))return null;i+=n}return o},x.prototype.parse=function(t,e){for(var r,n=[],o=0,i=S.isNumber(e)?e:0,s=t.length;i<s;){if(!(r=this.read(t,i)))return"";n[o++]=r.decoded,i+=r.consumed}return n.join("")},x.prototype.match=function(t,e){return-1!==this.test(t,e)},x.prototype.test=S.abstractMethod,x.prototype.consume=S.abstractMethod,x.prototype.read=S.abstractMethod;var L=function(){x.call(this)};S.inherits(L,x),L.prototype.test=function(t,e){var r=S.isNumber(e)?e:0;if(!t)return-1;if(0===t.length)return 0;var n=t.length-r;if(n<=0)return 0;if(!0&n)return-1;for(var o,i,s,f=0,u=r,a=t.length;u<a;){if(s=0,(o=t[u]|t[u+1]<<8)<=55295||o>=57344?(f+=1,s=2):o>=55296&&o<=56319&&u+3<a&&(i=t[u+2]|t[u+3]<<8)>=56320&&i<=57343&&(f+=1,s=4),!s)return-1;u+=s}return f},L.prototype.consume=function(t,e,r,n){var o=t[e]|t[e+1]<<8,i=2;o>=55296&&o<=56319&&(o=65536+((1023&o)<<10|1023&(t[e+2]|t[e+3]<<8)),i=4);return r[n]=o,i},L.prototype.read=function(t,e){var r=t.length;if(e+1>=r)return null;var n,o=t[e]|t[e+1]<<8,i=2;if(o>=55296&&o<=56319){if(e+3>=r)return null;if((n=t[e+2]|t[e+3]<<8)<56320||n>57343)return null;i=4}return{consumed:i,decoded:2===i?String.fromCharCode(o):String.fromCharCode(o)+String.fromCharCode(n)}};var K=function(){x.call(this)};S.inherits(K,x),K.prototype.test=function(t,e){var r=S.isNumber(e)?e:0;if(!t)return-1;if(0===t.length)return 0;var n=t.length-r;if(n<=0)return 0;if(!0&n)return-1;for(var o,i,s,f=0,u=r,a=t.length;u<a;){if(s=0,(o=t[u]<<8|t[u+1])<=55295||o>=57344?(f+=1,s=2):o>=55296&&o<=56319&&u+3<a&&(i=t[u+2]<<8|t[u+3])>=56320&&i<=57343&&(f+=1,s=4),!s)return-1;u+=s}return f},K.prototype.consume=function(t,e,r,n){var o=t[e]<<8|t[e+1],i=2;o>=55296&&o<=56319&&(o=65536+((1023&o)<<10|1023&(t[e+2]<<8|t[e+3])),i=4);return r[n]=o,i},K.prototype.read=function(t,e){var r=t.length;if(e+1>=r)return null;var n,o=t[e]<<8|t[e+1],i=2;if(o>=55296&&o<=56319){if(e+3>=r)return null;if((n=t[e+2]<<8|t[e+3])<56320||n>57343)return null;i=4}return{consumed:i,decoded:2===i?String.fromCharCode(o):String.fromCharCode(o)+String.fromCharCode(n)}};var W=function(){x.call(this)};S.inherits(W,x),W.prototype.test=function(t,e){var r=S.isNumber(e)?e:0;if(!t)return-1;if(0===t.length||t.length-r<=0)return 0;for(var n=0,o=r,i=t.length;o<i;)if(0==(128&t[o]))o++,n++;else if(o+1<i&&192==(224&t[o])&&128==(192&t[o+1]))o+=2,n++;else if(o+2<i&&224==(240&t[o])&&128==(192&t[o+1])&&128==(192&t[o+2]))o+=3,n++;else if(o+3<i&&240==(248&t[o])&&128==(192&t[o+1])&&128==(192&t[o+2])&&128==(192&t[o+3]))o+=4,n++;else if(o+4<i&&248==(252&t[o])&&128==(192&t[o+1])&&128==(192&t[o+2])&&128==(192&t[o+3])&&128==(192&t[o+4]))o+=5,n++;else{if(!(o+5<i&&252==(254&t[o])&&128==(192&t[o+1])&&128==(192&t[o+2])&&128==(192&t[o+3])&&128==(192&t[o+4])&&128==(192&t[o+5])))return-1;o+=6,n++}return n},W.prototype.consume=function(t,e,r,n){return 0==(128&t[e])?(r[n]=t[e],1):192==(224&t[e])?(r[n]=(63&t[e])<<6|63&t[e+1],2):224==(240&t[e])?(r[n]=(31&t[e])<<12|(63&t[e+1])<<6|63&t[e+2],3):240==(248&t[e])?(r[n]=(15&t[e])<<18|(63&t[e+1])<<12|(63&t[e+2])<<6|63&t[e+3],4):248==(252&t[e])?(r[n]=(7&t[e])<<24|(63&t[e+1])<<18|(63&t[e+2])<<12|(63&t[e+3])<<6|63&t[e+4],5):252==(254&t[e])?(r[n]=(3&t[e])<<30|(63&t[e+1])<<24|(63&t[e+2])<<18|(63&t[e+3])<<12|(63&t[e+4])<<6|63&t[e+5],6):0},W.prototype.read=function(t,e){var r,n=t.length;return 0==(128&t[e])?(r=t[e],{consumed:1,decoded:String.fromCharCode(r)}):e+1<n&&192==(224&t[e])&&128==(192&t[e+1])?(r=(63&t[e])<<6|63&t[e+1],{consumed:2,decoded:String.fromCharCode(r)}):e+2<n&&224==(240&t[e])&&128==(192&t[e+1])&&128==(192&t[e+2])?(r=(31&t[e])<<12|(63&t[e+1])<<6|63&t[e+2],{consumed:3,decoded:String.fromCharCode(r)}):e+3<n&&240==(248&t[e])&&128==(192&t[e+1])&&128==(192&t[e+2])&&128==(192&t[e+3])?(r=(15&t[e])<<18|(63&t[e+1])<<12|(63&t[e+2])<<6|63&t[e+3],{consumed:4,decoded:String.fromCodePoint(r)}):e+4<n&&248==(252&t[e])&&128==(192&t[e+1])&&128==(192&t[e+2])&&128==(192&t[e+3])&&128==(192&t[e+4])?(r=(7&t[e])<<24|(63&t[e+1])<<18|(63&t[e+2])<<12|(63&t[e+3])<<6|63&t[e+4],{consumed:5,decoded:String.fromCodePoint(r)}):e+5<n&&252==(254&t[e])&&128==(192&t[e+1])&&128==(192&t[e+2])&&128==(192&t[e+3])&&128==(192&t[e+4])&&128==(192&t[e+5])?(r=(3&t[e])<<30|(63&t[e+1])<<24|(63&t[e+2])<<18|(63&t[e+3])<<12|(63&t[e+4])<<6|63&t[e+5],{consumed:6,decoded:String.fromCodePoint(r)}):0};var G=function(t,e,r){x.call(this),this.conditions_=[],t&&S.isArray(t)&&t.forEach((function(t){var e=I.build(t.condition);e&&this.conditions_.push(e)}),this),this.segments_=new P.Segments(e),this.mappingBuffer_=r};S.inherits(G,x),G.prototype.conditions_,G.prototype.mappingBuffer_,G.prototype.segments_,G.prototype.getBytesOfCodepoint=function(){return this.mappingBuffer_?this.mappingBuffer_ instanceof Uint16Array?2:this.mappingBuffer_ instanceof Uint32Array?4:0:0},G.prototype.test=function(t,e){var r=S.isNumber(e)?e:0;if(!this.conditions_.length||!t)return-1;if(0===t.length||t.length-r<=0)return 0;for(var n,o=0,i=r,s=t.length;i<s;){if(!(n=this.find_(t,i)))return-1;i+=n.getBytes(),o++}return o},G.prototype.match=function(t,e){var r,n=S.isNumber(e)?e:0;if(!this.conditions_.length||!t)return!1;if(0===t.length||t.length-n<=0)return!0;for(var o=n,i=t.length;o<i;){if(!(r=this.find_(t,o)))return!1;var s=this.readUInt32BE_(t,o,r.getBytes());if(this.convertChar_(s)===M.UNICODE_UNKNOWN_CHAR)return!1;o+=r.getBytes()}return!0},G.prototype.find_=function(t,e){for(var r=0,n=this.conditions_.length;r<n;++r)if(this.conditions_[r].consume(t,e))return this.conditions_[r];return null},G.prototype.consume=function(t,e,r,n){var o=this.find_(t,e);if(!o)return 0;var i=o.getBytes(),s=this.readUInt32BE_(t,e,i);return r[n]=this.convertChar_(s),i},G.prototype.read=function(t,e){var r=this.find_(t,e);if(!r)return null;var n=r.getBytes(),o=this.readUInt32BE_(t,e,n),i=this.convertChar_(o);return{consumed:n,decoded:String.fromCodePoint(i)}},G.prototype.readUInt32BE_=function(t,e,r){for(var n=0,o=0;o<r;++o)n|=t[e+o]<<8*(r-1-o);return n>>>0},G.prototype.convertChar_=function(t){t>>>=0;var e=this.segments_.find(t);if(!e)return M.UNICODE_UNKNOWN_CHAR;switch(e.getReference()){case P.Reference.ASCII:return 127&t;case P.Reference.UNDEFINED:return M.UNICODE_UNKNOWN_CHAR;case P.Reference.BUFFER:return this.mappingBuffer_?this.mappingBuffer_[t-e.getBegin()+e.getOffset()]:M.UNICODE_UNKNOWN_CHAR;case P.Reference.INDEXING_BUFFER:if(!this.mappingBuffer_)return M.UNICODE_UNKNOWN_CHAR;var r=this.getIndexingBufferOffset_(e,t);return-1===r?M.UNICODE_UNKNOWN_CHAR:this.mappingBuffer_[r+e.getOffset()];case P.Reference.SELF:return t;case P.Reference.GB18030_UNICODE_SP_MAPPING:return k.convertGB18030ToUnicodeSP(t);default:return M.UNICODE_UNKNOWN_CHAR}},G.prototype.getIndexingBufferOffset_=function(t,e){var r=t.getCondition();return r?r.getIndexingOffset(e):-1},F.Multibyte=G,F.UTF16LE=new L,F.UTF16BE=new K,F.UTF8=new W;const{Charmap:j,CharmapType:H}=f,Y=h,X=F,$=r,V=g;var z=function(t){j.call(this,t,H.DECODER)};$.inherits(z,j),z.prototype.rule_,z.prototype.match=$.abstractMethod,z.prototype.decode=$.abstractMethod,z.prototype.parse=$.abstractMethod;var q=function(){z.call(this,"UTF-16LE"),this.rule_=X.UTF16LE};$.inherits(q,z),q.prototype.match=function(t,e){return this.rule_.match(t,e)},q.prototype.hasBom=function(t){return t&&t.length>=2&&t[0]===Y.UTF16LE_BOM[0]&&t[1]===Y.UTF16LE_BOM[1]},q.prototype.decode=function(t,e){return this.rule_.decode(t,e)},q.prototype.parse=function(t,e){var r=this.rule_.parse(t,e);return r&&r.charCodeAt(0)===Y.UNICODE_BYTE_ORDER_MARK?r.substring(1):r};var J=function(){z.call(this,"UTF-16BE"),this.rule_=X.UTF16BE};$.inherits(J,z),J.prototype.match=function(t,e){return this.rule_.match(t,e)},J.prototype.hasBom=function(t){return t&&t.length>=2&&t[0]===Y.UTF16BE_BOM[0]&&t[1]===Y.UTF16BE_BOM[1]},J.prototype.decode=function(t,e){return this.rule_.decode(t,e)},J.prototype.parse=function(t,e){var r=this.rule_.parse(t,e);return r&&r.charCodeAt(0)===Y.UNICODE_BYTE_ORDER_MARK?r.substring(1):r};var Q=function(){z.call(this,"UTF-8"),this.rule_=X.UTF8};$.inherits(Q,z),Q.prototype.match=function(t,e){return this.rule_.match(t,e)},Q.prototype.hasBom=function(t){return t&&t.length>=3&&t[0]===Y.UTF8_BOM[0]&&t[1]===Y.UTF8_BOM[1]&&t[2]===Y.UTF8_BOM[2]},Q.prototype.decode=function(t,e){return this.rule_.decode(t,e)},Q.prototype.parse=function(t,e){var r=this.rule_.parse(t,e);return r&&r.charCodeAt(0)===Y.UNICODE_BYTE_ORDER_MARK?r.substring(1):r};var Z=function(t){if(!t||!t.name)throw"options should provide name property at least";z.call(this,t.name),this.description_=t.description,this.version_=t.version;var e=null;if(t.buffer)if(t.buffer instanceof Uint16Array||t.buffer instanceof Uint32Array)e=t.buffer;else if($.isString(t.buffer)&&t.buffer.startsWith(Y.EMBEDDED_BASE64_PREFIX)){var r=t.buffer.substring(Y.EMBEDDED_BASE64_PREFIX.length),n=V.decode(r.trim());e=2===t.byte?new Uint16Array(n.buffer):new Uint32Array(n.buffer)}this.rule_=new X.Multibyte(t.rules,t.segments,e)};$.inherits(Z,z),Z.prototype.getBytesOfCodepoint=function(){return this.rule_.getBytesOfCodepoint()},Z.prototype.match=function(t,e){return this.rule_.match(t,e)},Z.prototype.decode=function(t,e){return this.rule_.decode(t,e)},Z.prototype.parse=function(t,e){return this.rule_.parse(t,e)},O.UTF16LE=new q,O.UTF16BE=new J,O.UTF8=new Q,O.Decoder=z,O.Multibyte=Z;var tt={},et={};const rt=r,nt=_,ot=R,it=t;var st=function(){};st.prototype.encode=function(t){var e=this.test(t);if(-1===e)return null;for(var r=new Uint8Array(e),n=0,o=0,i=t.length;o<i;++o)n+=this.consume(t,o,r,n);return r},st.prototype.unparse=function(t){var e=this.tell(t);if(-1===e)return null;for(var r=new Uint8Array(e),n=0,o=0,i=t.length;o<i;++o){var s=t.codePointAt(o);n+=this.write(s,r,n),s>65535&&o++}return r},st.prototype.test=rt.abstractMethod,st.prototype.consume=rt.abstractMethod,st.prototype.tell=rt.abstractMethod,st.prototype.write=rt.abstractMethod;var ft=function(){st.call(this)};rt.inherits(ft,st),ft.prototype.test=function(t){if(!t)return-1;if(0===t.length)return 0;for(var e,r=0,n=0,o=t.length;n<o;++n)(e=t[n]>>>0)<=55295?r+=2:e>=55296&&e<=57343||(e>=57344&&e<=65535?r+=2:e>=65536&&e<=1114111&&(r+=4));return r},ft.prototype.consume=function(t,e,r,n){var o,i=t[e]>>>0;if(i<=55295||i>=57344&&i<=65535)r[n]=255&i,r[n+1]=i>>8,o=2;else if(i>=55296&&i<=57343)o=0;else if(i>=65536&&i<=1114111){var s=56320+(1023&(i-=65536)),f=55296+(i>>10);r[n]=255&f,r[n+1]=f>>8,r[n+2]=255&s,r[n+3]=s>>8,o=4}else o=0;return o},ft.prototype.tell=function(t){return rt.isString(t)?2*t.length:-1},ft.prototype.write=function(t,e,r){var n;if(t<=55295||t>=57344&&t<=65535)e[r]=255&t,e[r+1]=t>>8,n=2;else if(t>=55296&&t<=57343)n=0;else if(t>=65536&&t<=1114111){var o=56320+(1023&(t-=65536)),i=55296+(t>>10);e[r]=255&i,e[r+1]=i>>8,e[r+2]=255&o,e[r+3]=o>>8,n=4}else n=0;return n};var ut=function(){st.call(this)};rt.inherits(ut,st),ut.prototype.test=function(t){if(!t)return-1;if(0===t.length)return 0;for(var e,r=0,n=0,o=t.length;n<o;++n)(e=t[n]>>>0)<=55295?r+=2:e>=55296&&e<=57343||(e>=57344&&e<=65535?r+=2:e>=65536&&e<=1114111&&(r+=4));return r},ut.prototype.consume=function(t,e,r,n){var o,i=t[e]>>>0;if(i<=55295||i>=57344&&i<=65535)r[n]=i>>8,r[n+1]=255&i,o=2;else if(i>=55296&&i<=57343)o=0;else if(i>=65536&&i<=1114111){var s=56320+(1023&(i-=65536)),f=55296+(i>>10);r[n]=f>>8,r[n+1]=255&f,r[n+2]=s>>8,r[n+3]=255&s,o=4}else o=0;return o},ut.prototype.tell=function(t){return rt.isString(t)?2*t.length:-1},ut.prototype.write=function(t,e,r){var n;if(t<=55295||t>=57344&&t<=65535)e[r]=t>>8,e[r+1]=255&t,n=2;else if(t>=55296&&t<=57343)n=0;else if(t>=65536&&t<=1114111){var o=56320+(1023&(t-=65536)),i=55296+(t>>10);e[r]=i>>8,e[r+1]=255&i,e[r+2]=o>>8,e[r+3]=255&o,n=4}else n=0;return n};var at=function(){st.call(this)};rt.inherits(at,st),at.prototype.test=function(t){if(!t)return-1;if(0===t.length)return 0;for(var e,r=0,n=0,o=t.length;n<o;++n)(e=t[n]>>>0)<=127?r+=1:e<=2047?r+=2:e<=55295?r+=3:e<=57343||(e<=65535?r+=3:e<=1114111&&(r+=4));return r},at.prototype.consume=function(t,e,r,n){var o,i=t[e]>>>0;return i<=127?(r[n]=i,o=1):i<=2047?(r[n]=192|i>>6,r[n+1]=128|63&i,o=2):i>=55296&&i<=57343?o=0:i<=65535?(r[n]=224|i>>12,r[n+1]=128|i>>6&63,r[n+2]=128|63&i,o=3):i<=1114111?(r[n]=240|i>>18,r[n+1]=128|i>>12&63,r[n+2]=128|i>>6&63,r[n+3]=128|63&i,o=4):o=0,o},at.prototype.tell=function(t){if(!rt.isString(t))return-1;for(var e,r=0,n=0,o=t.length;n<o;++n)(e=t.codePointAt(n))<=127?r+=1:e<=2047?r+=2:e<=55295?r+=3:e<=57343||(e<=65535?r+=3:e<=1114111&&(r+=4)),e>65535&&n++;return r},at.prototype.write=function(t,e,r){var n;return t<=127?(e[r]=t,n=1):t<=2047?(e[r]=192|t>>6,e[r+1]=128|63&t,n=2):t>=55296&&t<=57343?n=0:t<=65535?(e[r]=224|t>>12,e[r+1]=128|t>>6&63,e[r+2]=128|63&t,n=3):t<=1114111?(e[r]=240|t>>18,e[r+1]=128|t>>12&63,e[r+2]=128|t>>6&63,e[r+3]=128|63&t,n=4):n=0,n};var ct=function(t,e,r){st.call(this),this.segments_=new nt.Segments(t),this.mappingBuffer_=e,this.unknownChar_=r||63,this.unknownCharBytes_=this.getCharBytes_(this.unknownChar_)};rt.inherits(ct,st),ct.prototype.segments_,ct.prototype.mappingBuffer_,ct.prototype.unknownChar_,ct.prototype.getBytesOfCodepoint=function(){return this.mappingBuffer_?this.mappingBuffer_ instanceof Uint16Array?2:this.mappingBuffer_ instanceof Uint32Array?4:0:0},ct.prototype.test=function(t){if(!t)return-1;var e=t.length;if(0===e)return 0;for(var r,n,o=0,i=0;i<e;++i)if(r=t[i]>>>0,n=this.segments_.find(r))switch(n.getReference()){case nt.Reference.ASCII:o+=1;break;case nt.Reference.BUFFER:this.mappingBuffer_?o+=this.getCharBytes_(this.mappingBuffer_[r-n.getBegin()+n.getOffset()]):o+=this.unknownCharBytes_;break;case nt.Reference.GB18030_UNICODE_SP_MAPPING:o+=4}else o+=this.unknownCharBytes_;return o},ct.prototype.getCharBytes_=function(t){return(t>>>=0)<=255?1:t<=65535?2:4},ct.prototype.consume=function(t,e,r,n){var o,i=0,s=t[e]>>>0,f=this.segments_.find(s);if(!f)return it.writeUInt32BE(r,n,this.unknownChar_,this.unknownCharBytes_),this.unknownCharBytes_;switch(f.getReference()){case nt.Reference.ASCII:r[n]=s,i=1;break;case nt.Reference.BUFFER:if(!this.mappingBuffer_)return it.writeUInt32BE(r,n,this.unknownChar_,this.unknownCharBytes_),this.unknownCharBytes_;o=this.mappingBuffer_[s-f.getBegin()+f.getOffset()],i=this.getCharBytes_(o),it.writeUInt32BE(r,n,o,i);break;case nt.Reference.GB18030_UNICODE_SP_MAPPING:o=ot.convertUnicodeSPToGB18030(s),i=4,it.writeUInt32BE(r,n,o,i)}return i},ct.prototype.tell=function(t){if(!rt.isString(t))return-1;for(var e,r,n=0,o=0,i=t.length;o<i;++o)if((e=t.codePointAt(o))>65535&&o++,r=this.segments_.find(e))switch(r.getReference()){case nt.Reference.ASCII:n+=1;break;case nt.Reference.BUFFER:this.mappingBuffer_?n+=this.getCharBytes_(this.mappingBuffer_[e-r.getBegin()+r.getOffset()]):n+=this.unknownCharBytes_;break;case nt.Reference.GB18030_UNICODE_SP_MAPPING:n+=4}else n+=this.unknownCharBytes_;return n},ct.prototype.write=function(t,e,r){var n,o=0,i=this.segments_.find(t);if(!i)return it.writeUInt32BE(e,r,this.unknownChar_,this.unknownCharBytes_),this.unknownCharBytes_;switch(i.getReference()){case nt.Reference.ASCII:e[r]=t,o=1;break;case nt.Reference.BUFFER:if(!this.mappingBuffer_)return it.writeUInt32BE(e,r,this.unknownChar_,this.unknownCharBytes_),this.unknownCharBytes_;n=this.mappingBuffer_[t-i.getBegin()+i.getOffset()],o=this.getCharBytes_(n),it.writeUInt32BE(e,r,n,o);break;case nt.Reference.GB18030_UNICODE_SP_MAPPING:n=ot.convertUnicodeSPToGB18030(t),o=4,it.writeUInt32BE(e,r,n,o)}return o},et.UTF16LE=new ft,et.UTF16BE=new ut,et.UTF8=new at,et.Multibyte=ct;const{Charmap:ht,CharmapType:pt}=f,_t=h,dt=et,lt=r,yt=g;var gt=function(t){ht.call(this,t,pt.ENCODER)};lt.inherits(gt,ht),gt.prototype.rule_,gt.prototype.encode=lt.abstractMethod,gt.prototype.unparse=lt.abstractMethod;var Et=function(){gt.call(this,"UTF-16LE"),this.rule_=dt.UTF16LE};lt.inherits(Et,gt),Et.prototype.encode=function(t){return this.rule_.encode(t)},Et.prototype.unparse=function(t,e){if(!lt.isString(t))throw"Error: invalid type for str.";return e&&t.codePointAt(0)!==_t.UNICODE_BYTE_ORDER_MARK&&(t=String.fromCodePoint(_t.UNICODE_BYTE_ORDER_MARK)+t),this.rule_.unparse(t)};var vt=function(){gt.call(this,"UTF-16BE"),this.rule_=dt.UTF16BE};lt.inherits(vt,gt),vt.prototype.encode=function(t){return this.rule_.encode(t)},vt.prototype.unparse=function(t,e){if(!lt.isString(t))throw"Error: invalid type for str.";return e&&t.codePointAt(0)!==_t.UNICODE_BYTE_ORDER_MARK&&(t=String.fromCodePoint(_t.UNICODE_BYTE_ORDER_MARK)+t),this.rule_.unparse(t)};var mt=function(){gt.call(this,"UTF-8"),this.rule_=dt.UTF8};lt.inherits(mt,gt),mt.prototype.encode=function(t){return this.rule_.encode(t)},mt.prototype.unparse=function(t,e){if(!lt.isString(t))throw"Error: invalid type for str.";return e&&t.codePointAt(0)!==_t.UNICODE_BYTE_ORDER_MARK&&(t=String.fromCodePoint(_t.UNICODE_BYTE_ORDER_MARK)+t),this.rule_.unparse(t)};var Bt=function(t){if(!t||!t.name)throw"options should provide name property at least";gt.call(this,t.name),this.description_=t.description,this.version_=t.version;var e=null;if(t.buffer)if(t.buffer instanceof Uint16Array||t.buffer instanceof Uint32Array)e=t.buffer;else if(lt.isString(t.buffer)&&t.buffer.startsWith(_t.EMBEDDED_BASE64_PREFIX)){var r=t.buffer.substring(_t.EMBEDDED_BASE64_PREFIX.length),n=yt.decode(r.trim());e=2===t.byte?new Uint16Array(n.buffer):new Uint32Array(n.buffer)}this.rule_=new dt.Multibyte(t.segments,e,_t.MBCS_UNKNOWN_CHAR)};lt.inherits(Bt,gt),Bt.prototype.getBytesOfCodepoint=function(){return this.rule_.getBytesOfCodepoint()},Bt.prototype.encode=function(t){return this.rule_.encode(t)},Bt.prototype.unparse=function(t){if(!lt.isString(t))throw"Error: invalid type for str.";return this.rule_.unparse(t)},tt.UTF16LE=new Et,tt.UTF16BE=new vt,tt.UTF8=new mt,tt.Encoder=gt,tt.Multibyte=Bt;var Ct={};const{Channel:Ut}=e,{Converter:bt}=p,Nt=O,wt=tt,Ot=r;var Ft=function(t){this.reload(t)};Ft.prototype.encoders_,Ft.prototype.decoders_,Ft.prototype.converters_,Ft.prototype.channels_,Ft.prototype.detectionOrder_,Ft.prototype.reload=function(t){this.decoders_={},this.decoders_[Nt.UTF8.getName()]=Nt.UTF8,this.decoders_[Nt.UTF16LE.getName()]=Nt.UTF16LE,this.decoders_[Nt.UTF16BE.getName()]=Nt.UTF16BE,this.encoders_={},this.encoders_[wt.UTF8.getName()]=wt.UTF8,this.encoders_[wt.UTF16LE.getName()]=wt.UTF16LE,this.encoders_[wt.UTF16BE.getName()]=wt.UTF16BE,this.converters_={},this.detectionOrder_=[],this.channels_={},t&&(Ot.isArray(t.decoders)&&t.decoders.forEach((t=>{var e=new Nt.Multibyte(t);this.decoders_[e.getName()]=e}),this),Ot.isArray(t.detection_order)&&(this.detectionOrder_=t.detection_order.slice()),Ot.isArray(t.encoders)&&t.encoders.forEach((t=>{var e=new wt.Multibyte(t);this.encoders_[e.getName()]=e}),this),Ot.isArray(t.converters)&&t.converters.forEach((t=>{var e=new bt(t);this.converters_[e.getName()]=e}),this),Ot.isArray(t.channels)&&t.channels.forEach((t=>{this.newChannel(t.name,t.decoder,t.encoder,t.converters)}),this))},Ft.prototype.getDecoder=function(t){return this.decoders_[t]},Ft.prototype.getDecoderNames=function(){return Object.keys(this.decoders_)},Ft.prototype.getEncoder=function(t){return this.encoders_[t]},Ft.prototype.getEncoderNames=function(){return Object.keys(this.encoders_)},Ft.prototype.getConverter=function(t){return this.converters_[t]},Ft.prototype.getConverterNames=function(){return Object.keys(this.converters_)},Ft.prototype.getChannel=function(t){return this.channels_[t]},Ft.prototype.getChannelNames=function(){return Object.keys(this.channels_)},Ft.prototype.newChannel=function(t,e,r,n){if(!this.decoders_[e]||!this.encoders_[r])return null;var o=[];return n&&(Ot.isString(n)?this.converters_[n]&&o.push(this.converters_[n]):Ot.isArray(n)&&n.forEach((t=>{this.converters_[t]&&o.push(this.converters_[t])}),this)),this.channels_[t]=new Ut(this.decoders_[e],this.encoders_[r],o)},Ft.prototype.decode=function(t,e,r){var n=this.getDecoder(e);if(!n)throw`Error: decoder ${e} not found in the context.`;return n.decode(t,r)},Ft.prototype.encode=function(t,e){var r=this.getEncoder(e);if(!r)throw`Error: encoder ${e} not found in the context.`;return r.encode(t)},Ft.prototype.parse=function(t,e,r){var n=this.getDecoder(e);if(!n)throw`Error: decoder ${e} not found in the context.`;return n.parse(t,r)},Ft.prototype.unparse=function(t,e,r){var n=this.getEncoder(e);if(!n)throw`Error: encoder ${e} not found in the context.`;return n.unparse(t,r)},Ft.prototype.findPossibleEncoding=function(t){if(Nt.UTF8.match(t))return{encoding:Nt.UTF8.getName(),hasBom:Nt.UTF8.hasBom(t)};if(Nt.UTF16LE.hasBom(t)&&Nt.UTF16LE.match(t))return{encoding:Nt.UTF16LE.getName(),hasBom:!0};if(Nt.UTF16BE.hasBom(t)&&Nt.UTF16BE.match(t))return{encoding:Nt.UTF16BE.getName(),hasBom:!0};var e=this.detectionOrder_.find((e=>{var r=this.getDecoder(e);return r&&r.match(t)}),this);return e?{encoding:e,hasBom:!1}:null},Ct.Context=Ft;var Rt={};const{Context:At}=Ct,Tt=r,Dt=h;Rt.loadFromUrl=function(t){var e=fetch(t).then((t=>t.json())),r=function(t){return Tt.isString(t.buffer)&&!t.buffer.startsWith(Dt.EMBEDDED_BASE64_PREFIX)?fetch(t.buffer).then((t=>t.arrayBuffer())).then((e=>{t.buffer=2===t.byte?new Uint16Array(e):new Uint32Array(e)})):Promise.resolve()};return(e=e.then((t=>{var e=[];return Tt.isArray(t.decoders)&&t.decoders.forEach((t=>{e.push(r(t))})),Tt.isArray(t.encoders)&&t.encoders.forEach((t=>{e.push(r(t))})),Tt.isArray(t.converters)&&t.converters.forEach((t=>{e.push(r(t))})),Promise.all(e).then((()=>t))}))).then((t=>new At(t)))};const It=t,{Channel:St}=e,{CharmapType:Mt}=f,{Condition:Pt}=a,kt=h,{Converter:xt}=p,Lt=O,Kt=tt,{Reference:Wt}=_,{Context:Gt}=Ct,jt=g,{loadFromUrl:Ht}=Rt;return{Converter:xt,DecoderMultibyte:Lt.Multibyte,DECODER_UTF8:Lt.UTF8,DECODER_UTF16LE:Lt.UTF16LE,DECODER_UTF16BE:Lt.UTF16BE,EncoderMultibyte:Kt.Multibyte,ENCODER_UTF8:Kt.UTF8,ENCODER_UTF16LE:Kt.UTF16LE,ENCODER_UTF16BE:Kt.UTF16BE,Channel:St,Condition:Pt,CharmapType:Mt,SegmentReference:Wt,Context:Gt,Consts:kt,utils:It,base64:jt,loadFromUrl:Ht}}));
