UNPKG

pdfjs-dist

Version:

Generic build of Mozilla's PDF.js library.

22 lines • 96.9 kB
/** * @licstart The following is the entire license notice for the * JavaScript code in this page * * Copyright 2024 Mozilla Foundation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @licend The above is the entire license notice for the * JavaScript code in this page */ "object"!=typeof process||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&process.type;const e={ERRORS:0,WARNINGS:1,INFOS:5};let t=e.WARNINGS;function setVerbosityLevel(e){Number.isInteger(e)&&(t=e)}function getVerbosityLevel(){return t}function info(n){t>=e.INFOS&&console.log(`Info: ${n}`)}function util_warn(n){t>=e.WARNINGS&&console.log(`Warning: ${n}`)}function unreachable(e){throw new Error(e)}function shadow(e,t,n,r=!1){Object.defineProperty(e,t,{value:n,enumerable:!r,configurable:!0,writable:!1});return n}const n=function BaseExceptionClosure(){function BaseException(e,t){this.message=e;this.name=t}BaseException.prototype=new Error;BaseException.constructor=BaseException;return BaseException}();class FormatError extends n{constructor(e){super(e,"FormatError")}}function bytesToString(e){"object"==typeof e&&void 0!==e?.length||unreachable("Invalid argument for bytesToString");const t=e.length,n=8192;if(t<n)return String.fromCharCode.apply(null,e);const r=[];for(let i=0;i<t;i+=n){const s=Math.min(i+n,t),o=e.subarray(i,s);r.push(String.fromCharCode.apply(null,o))}return r.join("")}class util_FeatureTest{static get isLittleEndian(){return shadow(this,"isLittleEndian",function isLittleEndian(){const e=new Uint8Array(4);e[0]=1;return 1===new Uint32Array(e.buffer,0,1)[0]}())}static get isEvalSupported(){return shadow(this,"isEvalSupported",function isEvalSupported(){try{new Function("");return!0}catch{return!1}}())}static get isOffscreenCanvasSupported(){return shadow(this,"isOffscreenCanvasSupported","undefined"!=typeof OffscreenCanvas)}static get isImageDecoderSupported(){return shadow(this,"isImageDecoderSupported","undefined"!=typeof ImageDecoder)}static get platform(){if("undefined"!=typeof navigator&&"string"==typeof navigator?.platform&&"string"==typeof navigator?.userAgent){const{platform:e,userAgent:t}=navigator;return shadow(this,"platform",{isAndroid:t.includes("Android"),isLinux:e.includes("Linux"),isMac:e.includes("Mac"),isWindows:e.includes("Win"),isFirefox:t.includes("Firefox")})}return shadow(this,"platform",{isAndroid:!1,isLinux:!1,isMac:!1,isWindows:!1,isFirefox:!1})}static get isCSSRoundSupported(){return shadow(this,"isCSSRoundSupported",globalThis.CSS?.supports?.("width: round(1.5px, 1px)"))}}Array.from(Array(256).keys(),(e=>e.toString(16).padStart(2,"0")));function MathClamp(e,t,n){return Math.min(Math.max(e,t),n)}"function"!=typeof Promise.try&&(Promise.try=function(e,...t){return new Promise((n=>{n(e(...t))}))});"function"!=typeof Math.sumPrecise&&(Math.sumPrecise=function(e){return e.reduce(((e,t)=>e+t),0)});Symbol("CIRCULAR_REF"),Symbol("EOF");Object.create(null);let r=Object.create(null),i=Object.create(null);class Name{constructor(e){this.name=e}static get(e){return r[e]||=new Name(e)}}const s=function nonSerializableClosure(){return s};class primitives_Dict{constructor(e=null){this._map=new Map;this.xref=e;this.objId=null;this.suppressEncryption=!1;this.__nonSerializable__=s}assignXref(e){this.xref=e}get size(){return this._map.size}get(e,t,n){let r=this._map.get(e);if(void 0===r&&void 0!==t){r=this._map.get(t);void 0===r&&void 0!==n&&(r=this._map.get(n))}return r instanceof primitives_Ref&&this.xref?this.xref.fetch(r,this.suppressEncryption):r}async getAsync(e,t,n){let r=this._map.get(e);if(void 0===r&&void 0!==t){r=this._map.get(t);void 0===r&&void 0!==n&&(r=this._map.get(n))}return r instanceof primitives_Ref&&this.xref?this.xref.fetchAsync(r,this.suppressEncryption):r}getArray(e,t,n){let r=this._map.get(e);if(void 0===r&&void 0!==t){r=this._map.get(t);void 0===r&&void 0!==n&&(r=this._map.get(n))}r instanceof primitives_Ref&&this.xref&&(r=this.xref.fetch(r,this.suppressEncryption));if(Array.isArray(r)){r=r.slice();for(let e=0,t=r.length;e<t;e++)r[e]instanceof primitives_Ref&&this.xref&&(r[e]=this.xref.fetch(r[e],this.suppressEncryption))}return r}getRaw(e){return this._map.get(e)}getKeys(){return[...this._map.keys()]}getRawValues(){return[...this._map.values()]}set(e,t){this._map.set(e,t)}has(e){return this._map.has(e)}*[Symbol.iterator](){for(const[e,t]of this._map)yield[e,t instanceof primitives_Ref&&this.xref?this.xref.fetch(t,this.suppressEncryption):t]}static get empty(){const e=new primitives_Dict(null);e.set=(e,t)=>{unreachable("Should not call `set` on the empty dictionary.")};return shadow(this,"empty",e)}static merge({xref:e,dictArray:t,mergeSubDicts:n=!1}){const r=new primitives_Dict(e),i=new Map;for(const e of t)if(e instanceof primitives_Dict)for(const[t,r]of e._map){let e=i.get(t);if(void 0===e){e=[];i.set(t,e)}else if(!(n&&r instanceof primitives_Dict))continue;e.push(r)}for(const[t,n]of i){if(1===n.length||!(n[0]instanceof primitives_Dict)){r._map.set(t,n[0]);continue}const i=new primitives_Dict(e);for(const e of n)for(const[t,n]of e._map)i._map.has(t)||i._map.set(t,n);i.size>0&&r._map.set(t,i)}i.clear();return r.size>0?r:primitives_Dict.empty}clone(){const e=new primitives_Dict(this.xref);for(const t of this.getKeys())e.set(t,this.getRaw(t));return e}delete(e){delete this._map[e]}}class primitives_Ref{constructor(e,t){this.num=e;this.gen=t}toString(){return 0===this.gen?`${this.num}R`:`${this.num}R${this.gen}`}static fromString(e){const t=i[e];if(t)return t;const n=/^(\d+)R(\d*)$/.exec(e);return n&&"0"!==n[1]?i[e]=new primitives_Ref(parseInt(n[1]),n[2]?parseInt(n[2]):0):null}static get(e,t){const n=0===t?`${e}R`:`${e}R${t}`;return i[n]||=new primitives_Ref(e,t)}}Symbol.iterator;Symbol.iterator;class base_stream_BaseStream{get length(){unreachable("Abstract getter `length` accessed")}get isEmpty(){unreachable("Abstract getter `isEmpty` accessed")}get isDataLoaded(){return shadow(this,"isDataLoaded",!0)}getByte(){unreachable("Abstract method `getByte` called")}getBytes(e){unreachable("Abstract method `getBytes` called")}async getImageData(e,t){return this.getBytes(e,t)}async asyncGetBytes(){unreachable("Abstract method `asyncGetBytes` called")}get isAsync(){return!1}get isAsyncDecoder(){return!1}get canAsyncDecodeImageFromBuffer(){return!1}async getTransferableImage(){return null}peekByte(){const e=this.getByte();-1!==e&&this.pos--;return e}peekBytes(e){const t=this.getBytes(e);this.pos-=t.length;return t}getUint16(){const e=this.getByte(),t=this.getByte();return-1===e||-1===t?-1:(e<<8)+t}getInt32(){return(this.getByte()<<24)+(this.getByte()<<16)+(this.getByte()<<8)+this.getByte()}getByteRange(e,t){unreachable("Abstract method `getByteRange` called")}getString(e){return bytesToString(this.getBytes(e))}skip(e){this.pos+=e||1}reset(){unreachable("Abstract method `reset` called")}moveStart(){unreachable("Abstract method `moveStart` called")}makeSubStream(e,t,n=null){unreachable("Abstract method `makeSubStream` called")}getBaseStreams(){return null}}class MissingDataException extends n{constructor(e,t){super(`Missing data [${e}, ${t})`,"MissingDataException");this.begin=e;this.end=t}}function log2(e){return e>0?Math.ceil(Math.log2(e)):0}function readInt8(e,t){return e[t]<<24>>24}function readUint16(e,t){return e[t]<<8|e[t+1]}function readUint32(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}const o=[{qe:22017,nmps:1,nlps:1,switchFlag:1},{qe:13313,nmps:2,nlps:6,switchFlag:0},{qe:6145,nmps:3,nlps:9,switchFlag:0},{qe:2753,nmps:4,nlps:12,switchFlag:0},{qe:1313,nmps:5,nlps:29,switchFlag:0},{qe:545,nmps:38,nlps:33,switchFlag:0},{qe:22017,nmps:7,nlps:6,switchFlag:1},{qe:21505,nmps:8,nlps:14,switchFlag:0},{qe:18433,nmps:9,nlps:14,switchFlag:0},{qe:14337,nmps:10,nlps:14,switchFlag:0},{qe:12289,nmps:11,nlps:17,switchFlag:0},{qe:9217,nmps:12,nlps:18,switchFlag:0},{qe:7169,nmps:13,nlps:20,switchFlag:0},{qe:5633,nmps:29,nlps:21,switchFlag:0},{qe:22017,nmps:15,nlps:14,switchFlag:1},{qe:21505,nmps:16,nlps:14,switchFlag:0},{qe:20737,nmps:17,nlps:15,switchFlag:0},{qe:18433,nmps:18,nlps:16,switchFlag:0},{qe:14337,nmps:19,nlps:17,switchFlag:0},{qe:13313,nmps:20,nlps:18,switchFlag:0},{qe:12289,nmps:21,nlps:19,switchFlag:0},{qe:10241,nmps:22,nlps:19,switchFlag:0},{qe:9217,nmps:23,nlps:20,switchFlag:0},{qe:8705,nmps:24,nlps:21,switchFlag:0},{qe:7169,nmps:25,nlps:22,switchFlag:0},{qe:6145,nmps:26,nlps:23,switchFlag:0},{qe:5633,nmps:27,nlps:24,switchFlag:0},{qe:5121,nmps:28,nlps:25,switchFlag:0},{qe:4609,nmps:29,nlps:26,switchFlag:0},{qe:4353,nmps:30,nlps:27,switchFlag:0},{qe:2753,nmps:31,nlps:28,switchFlag:0},{qe:2497,nmps:32,nlps:29,switchFlag:0},{qe:2209,nmps:33,nlps:30,switchFlag:0},{qe:1313,nmps:34,nlps:31,switchFlag:0},{qe:1089,nmps:35,nlps:32,switchFlag:0},{qe:673,nmps:36,nlps:33,switchFlag:0},{qe:545,nmps:37,nlps:34,switchFlag:0},{qe:321,nmps:38,nlps:35,switchFlag:0},{qe:273,nmps:39,nlps:36,switchFlag:0},{qe:133,nmps:40,nlps:37,switchFlag:0},{qe:73,nmps:41,nlps:38,switchFlag:0},{qe:37,nmps:42,nlps:39,switchFlag:0},{qe:21,nmps:43,nlps:40,switchFlag:0},{qe:9,nmps:44,nlps:41,switchFlag:0},{qe:5,nmps:45,nlps:42,switchFlag:0},{qe:1,nmps:45,nlps:43,switchFlag:0},{qe:22017,nmps:46,nlps:46,switchFlag:0}];class ArithmeticDecoder{constructor(e,t,n){this.data=e;this.bp=t;this.dataEnd=n;this.chigh=e[t];this.clow=0;this.byteIn();this.chigh=this.chigh<<7&65535|this.clow>>9&127;this.clow=this.clow<<7&65535;this.ct-=7;this.a=32768}byteIn(){const e=this.data;let t=this.bp;if(255===e[t])if(e[t+1]>143){this.clow+=65280;this.ct=8}else{t++;this.clow+=e[t]<<9;this.ct=7;this.bp=t}else{t++;this.clow+=t<this.dataEnd?e[t]<<8:65280;this.ct=8;this.bp=t}if(this.clow>65535){this.chigh+=this.clow>>16;this.clow&=65535}}readBit(e,t){let n=e[t]>>1,r=1&e[t];const i=o[n],s=i.qe;let a,c=this.a-s;if(this.chigh<s)if(c<s){c=s;a=r;n=i.nmps}else{c=s;a=1^r;1===i.switchFlag&&(r=a);n=i.nlps}else{this.chigh-=s;if(32768&c){this.a=c;return r}if(c<s){a=1^r;1===i.switchFlag&&(r=a);n=i.nlps}else{a=r;n=i.nmps}}do{0===this.ct&&this.byteIn();c<<=1;this.chigh=this.chigh<<1&65535|this.clow>>15&1;this.clow=this.clow<<1&65535;this.ct--}while(!(32768&c));this.a=c;e[t]=n<<1|r;return a}}const a=-1,c=[[-1,-1],[-1,-1],[7,8],[7,7],[6,6],[6,6],[6,5],[6,5],[4,0],[4,0],[4,0],[4,0],[4,0],[4,0],[4,0],[4,0],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[3,3],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2],[1,2]],l=[[-1,-1],[12,-2],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[11,1792],[11,1792],[12,1984],[12,2048],[12,2112],[12,2176],[12,2240],[12,2304],[11,1856],[11,1856],[11,1920],[11,1920],[12,2368],[12,2432],[12,2496],[12,2560]],f=[[-1,-1],[-1,-1],[-1,-1],[-1,-1],[8,29],[8,29],[8,30],[8,30],[8,45],[8,45],[8,46],[8,46],[7,22],[7,22],[7,22],[7,22],[7,23],[7,23],[7,23],[7,23],[8,47],[8,47],[8,48],[8,48],[6,13],[6,13],[6,13],[6,13],[6,13],[6,13],[6,13],[6,13],[7,20],[7,20],[7,20],[7,20],[8,33],[8,33],[8,34],[8,34],[8,35],[8,35],[8,36],[8,36],[8,37],[8,37],[8,38],[8,38],[7,19],[7,19],[7,19],[7,19],[8,31],[8,31],[8,32],[8,32],[6,1],[6,1],[6,1],[6,1],[6,1],[6,1],[6,1],[6,1],[6,12],[6,12],[6,12],[6,12],[6,12],[6,12],[6,12],[6,12],[8,53],[8,53],[8,54],[8,54],[7,26],[7,26],[7,26],[7,26],[8,39],[8,39],[8,40],[8,40],[8,41],[8,41],[8,42],[8,42],[8,43],[8,43],[8,44],[8,44],[7,21],[7,21],[7,21],[7,21],[7,28],[7,28],[7,28],[7,28],[8,61],[8,61],[8,62],[8,62],[8,63],[8,63],[8,0],[8,0],[8,320],[8,320],[8,384],[8,384],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,10],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[5,11],[7,27],[7,27],[7,27],[7,27],[8,59],[8,59],[8,60],[8,60],[9,1472],[9,1536],[9,1600],[9,1728],[7,18],[7,18],[7,18],[7,18],[7,24],[7,24],[7,24],[7,24],[8,49],[8,49],[8,50],[8,50],[8,51],[8,51],[8,52],[8,52],[7,25],[7,25],[7,25],[7,25],[8,55],[8,55],[8,56],[8,56],[8,57],[8,57],[8,58],[8,58],[6,192],[6,192],[6,192],[6,192],[6,192],[6,192],[6,192],[6,192],[6,1664],[6,1664],[6,1664],[6,1664],[6,1664],[6,1664],[6,1664],[6,1664],[8,448],[8,448],[8,512],[8,512],[9,704],[9,768],[8,640],[8,640],[8,576],[8,576],[9,832],[9,896],[9,960],[9,1024],[9,1088],[9,1152],[9,1216],[9,1280],[9,1344],[9,1408],[7,256],[7,256],[7,256],[7,256],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,2],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[4,3],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,128],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,8],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[5,9],[6,16],[6,16],[6,16],[6,16],[6,16],[6,16],[6,16],[6,16],[6,17],[6,17],[6,17],[6,17],[6,17],[6,17],[6,17],[6,17],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,4],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[4,5],[6,14],[6,14],[6,14],[6,14],[6,14],[6,14],[6,14],[6,14],[6,15],[6,15],[6,15],[6,15],[6,15],[6,15],[6,15],[6,15],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[5,64],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,6],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7],[4,7]],h=[[-1,-1],[-1,-1],[12,-2],[12,-2],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[-1,-1],[11,1792],[11,1792],[11,1792],[11,1792],[12,1984],[12,1984],[12,2048],[12,2048],[12,2112],[12,2112],[12,2176],[12,2176],[12,2240],[12,2240],[12,2304],[12,2304],[11,1856],[11,1856],[11,1856],[11,1856],[11,1920],[11,1920],[11,1920],[11,1920],[12,2368],[12,2368],[12,2432],[12,2432],[12,2496],[12,2496],[12,2560],[12,2560],[10,18],[10,18],[10,18],[10,18],[10,18],[10,18],[10,18],[10,18],[12,52],[12,52],[13,640],[13,704],[13,768],[13,832],[12,55],[12,55],[12,56],[12,56],[13,1280],[13,1344],[13,1408],[13,1472],[12,59],[12,59],[12,60],[12,60],[13,1536],[13,1600],[11,24],[11,24],[11,24],[11,24],[11,25],[11,25],[11,25],[11,25],[13,1664],[13,1728],[12,320],[12,320],[12,384],[12,384],[12,448],[12,448],[13,512],[13,576],[12,53],[12,53],[12,54],[12,54],[13,896],[13,960],[13,1024],[13,1088],[13,1152],[13,1216],[10,64],[10,64],[10,64],[10,64],[10,64],[10,64],[10,64],[10,64]],u=[[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[8,13],[11,23],[11,23],[12,50],[12,51],[12,44],[12,45],[12,46],[12,47],[12,57],[12,58],[12,61],[12,256],[10,16],[10,16],[10,16],[10,16],[10,17],[10,17],[10,17],[10,17],[12,48],[12,49],[12,62],[12,63],[12,30],[12,31],[12,32],[12,33],[12,40],[12,41],[11,22],[11,22],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[8,14],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,10],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[7,11],[9,15],[9,15],[9,15],[9,15],[9,15],[9,15],[9,15],[9,15],[12,128],[12,192],[12,26],[12,27],[12,28],[12,29],[11,19],[11,19],[11,20],[11,20],[12,34],[12,35],[12,36],[12,37],[12,38],[12,39],[11,21],[11,21],[12,42],[12,43],[10,0],[10,0],[10,0],[10,0],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12],[7,12]],d=[[-1,-1],[-1,-1],[-1,-1],[-1,-1],[6,9],[6,8],[5,7],[5,7],[4,6],[4,6],[4,6],[4,6],[4,5],[4,5],[4,5],[4,5],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,1],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[3,4],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,3],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2],[2,2]];class CCITTFaxDecoder{constructor(e,t={}){if("function"!=typeof e?.next)throw new Error('CCITTFaxDecoder - invalid "source" parameter.');this.source=e;this.eof=!1;this.encoding=t.K||0;this.eoline=t.EndOfLine||!1;this.byteAlign=t.EncodedByteAlign||!1;this.columns=t.Columns||1728;this.rows=t.Rows||0;this.eoblock=t.EndOfBlock??!0;this.black=t.BlackIs1||!1;this.codingLine=new Uint32Array(this.columns+1);this.refLine=new Uint32Array(this.columns+2);this.codingLine[0]=this.columns;this.codingPos=0;this.row=0;this.nextLine2D=this.encoding<0;this.inputBits=0;this.inputBuf=0;this.outputBits=0;this.rowsDone=!1;let n;for(;0===(n=this._lookBits(12));)this._eatBits(1);1===n&&this._eatBits(12);if(this.encoding>0){this.nextLine2D=!this._lookBits(1);this._eatBits(1)}}readNextChar(){if(this.eof)return-1;const e=this.refLine,t=this.codingLine,n=this.columns;let r,i,s,o,c;if(0===this.outputBits){this.rowsDone&&(this.eof=!0);if(this.eof)return-1;this.err=!1;let s,c,l;if(this.nextLine2D){for(o=0;t[o]<n;++o)e[o]=t[o];e[o++]=n;e[o]=n;t[0]=0;this.codingPos=0;r=0;i=0;for(;t[this.codingPos]<n;){s=this._getTwoDimCode();switch(s){case 0:this._addPixels(e[r+1],i);e[r+1]<n&&(r+=2);break;case 1:s=c=0;if(i){do{s+=l=this._getBlackCode()}while(l>=64);do{c+=l=this._getWhiteCode()}while(l>=64)}else{do{s+=l=this._getWhiteCode()}while(l>=64);do{c+=l=this._getBlackCode()}while(l>=64)}this._addPixels(t[this.codingPos]+s,i);t[this.codingPos]<n&&this._addPixels(t[this.codingPos]+c,1^i);for(;e[r]<=t[this.codingPos]&&e[r]<n;)r+=2;break;case 7:this._addPixels(e[r]+3,i);i^=1;if(t[this.codingPos]<n){++r;for(;e[r]<=t[this.codingPos]&&e[r]<n;)r+=2}break;case 5:this._addPixels(e[r]+2,i);i^=1;if(t[this.codingPos]<n){++r;for(;e[r]<=t[this.codingPos]&&e[r]<n;)r+=2}break;case 3:this._addPixels(e[r]+1,i);i^=1;if(t[this.codingPos]<n){++r;for(;e[r]<=t[this.codingPos]&&e[r]<n;)r+=2}break;case 2:this._addPixels(e[r],i);i^=1;if(t[this.codingPos]<n){++r;for(;e[r]<=t[this.codingPos]&&e[r]<n;)r+=2}break;case 8:this._addPixelsNeg(e[r]-3,i);i^=1;if(t[this.codingPos]<n){r>0?--r:++r;for(;e[r]<=t[this.codingPos]&&e[r]<n;)r+=2}break;case 6:this._addPixelsNeg(e[r]-2,i);i^=1;if(t[this.codingPos]<n){r>0?--r:++r;for(;e[r]<=t[this.codingPos]&&e[r]<n;)r+=2}break;case 4:this._addPixelsNeg(e[r]-1,i);i^=1;if(t[this.codingPos]<n){r>0?--r:++r;for(;e[r]<=t[this.codingPos]&&e[r]<n;)r+=2}break;case a:this._addPixels(n,0);this.eof=!0;break;default:info("bad 2d code");this._addPixels(n,0);this.err=!0}}}else{t[0]=0;this.codingPos=0;i=0;for(;t[this.codingPos]<n;){s=0;if(i)do{s+=l=this._getBlackCode()}while(l>=64);else do{s+=l=this._getWhiteCode()}while(l>=64);this._addPixels(t[this.codingPos]+s,i);i^=1}}let f=!1;this.byteAlign&&(this.inputBits&=-8);if(this.eoblock||this.row!==this.rows-1){s=this._lookBits(12);if(this.eoline)for(;s!==a&&1!==s;){this._eatBits(1);s=this._lookBits(12)}else for(;0===s;){this._eatBits(1);s=this._lookBits(12)}if(1===s){this._eatBits(12);f=!0}else s===a&&(this.eof=!0)}else this.rowsDone=!0;if(!this.eof&&this.encoding>0&&!this.rowsDone){this.nextLine2D=!this._lookBits(1);this._eatBits(1)}if(this.eoblock&&f&&this.byteAlign){s=this._lookBits(12);if(1===s){this._eatBits(12);if(this.encoding>0){this._lookBits(1);this._eatBits(1)}if(this.encoding>=0)for(o=0;o<4;++o){s=this._lookBits(12);1!==s&&info("bad rtc code: "+s);this._eatBits(12);if(this.encoding>0){this._lookBits(1);this._eatBits(1)}}this.eof=!0}}else if(this.err&&this.eoline){for(;;){s=this._lookBits(13);if(s===a){this.eof=!0;return-1}if(s>>1==1)break;this._eatBits(1)}this._eatBits(12);if(this.encoding>0){this._eatBits(1);this.nextLine2D=!(1&s)}}this.outputBits=t[0]>0?t[this.codingPos=0]:t[this.codingPos=1];this.row++}if(this.outputBits>=8){c=1&this.codingPos?0:255;this.outputBits-=8;if(0===this.outputBits&&t[this.codingPos]<n){this.codingPos++;this.outputBits=t[this.codingPos]-t[this.codingPos-1]}}else{s=8;c=0;do{if("number"!=typeof this.outputBits)throw new FormatError('Invalid /CCITTFaxDecode data, "outputBits" must be a number.');if(this.outputBits>s){c<<=s;1&this.codingPos||(c|=255>>8-s);this.outputBits-=s;s=0}else{c<<=this.outputBits;1&this.codingPos||(c|=255>>8-this.outputBits);s-=this.outputBits;this.outputBits=0;if(t[this.codingPos]<n){this.codingPos++;this.outputBits=t[this.codingPos]-t[this.codingPos-1]}else if(s>0){c<<=s;s=0}}}while(s)}this.black&&(c^=255);return c}_addPixels(e,t){const n=this.codingLine;let r=this.codingPos;if(e>n[r]){if(e>this.columns){info("row is wrong length");this.err=!0;e=this.columns}1&r^t&&++r;n[r]=e}this.codingPos=r}_addPixelsNeg(e,t){const n=this.codingLine;let r=this.codingPos;if(e>n[r]){if(e>this.columns){info("row is wrong length");this.err=!0;e=this.columns}1&r^t&&++r;n[r]=e}else if(e<n[r]){if(e<0){info("invalid code");this.err=!0;e=0}for(;r>0&&e<n[r-1];)--r;n[r]=e}this.codingPos=r}_findTableCode(e,t,n,r){const i=r||0;for(let r=e;r<=t;++r){let e=this._lookBits(r);if(e===a)return[!0,1,!1];r<t&&(e<<=t-r);if(!i||e>=i){const t=n[e-i];if(t[0]===r){this._eatBits(r);return[!0,t[1],!0]}}}return[!1,0,!1]}_getTwoDimCode(){let e,t=0;if(this.eoblock){t=this._lookBits(7);e=c[t];if(e?.[0]>0){this._eatBits(e[0]);return e[1]}}else{const e=this._findTableCode(1,7,c);if(e[0]&&e[2])return e[1]}info("Bad two dim code");return a}_getWhiteCode(){let e,t=0;if(this.eoblock){t=this._lookBits(12);if(t===a)return 1;e=t>>5?f[t>>3]:l[t];if(e[0]>0){this._eatBits(e[0]);return e[1]}}else{let e=this._findTableCode(1,9,f);if(e[0])return e[1];e=this._findTableCode(11,12,l);if(e[0])return e[1]}info("bad white code");this._eatBits(1);return 1}_getBlackCode(){let e,t;if(this.eoblock){e=this._lookBits(13);if(e===a)return 1;t=e>>7?!(e>>9)&&e>>7?u[(e>>1)-64]:d[e>>7]:h[e];if(t[0]>0){this._eatBits(t[0]);return t[1]}}else{let e=this._findTableCode(2,6,d);if(e[0])return e[1];e=this._findTableCode(7,12,u,64);if(e[0])return e[1];e=this._findTableCode(10,13,h);if(e[0])return e[1]}info("bad black code");this._eatBits(1);return 1}_lookBits(e){let t;for(;this.inputBits<e;){if(-1===(t=this.source.next()))return 0===this.inputBits?a:this.inputBuf<<e-this.inputBits&65535>>16-e;this.inputBuf=this.inputBuf<<8|t;this.inputBits+=8}return this.inputBuf>>this.inputBits-e&65535>>16-e}_eatBits(e){(this.inputBits-=e)<0&&(this.inputBits=0)}}class Jbig2Error extends n{constructor(e){super(e,"Jbig2Error")}}class ContextCache{getContexts(e){return e in this?this[e]:this[e]=new Int8Array(65536)}}class DecodingContext{constructor(e,t,n){this.data=e;this.start=t;this.end=n}get decoder(){return shadow(this,"decoder",new ArithmeticDecoder(this.data,this.start,this.end))}get contextCache(){return shadow(this,"contextCache",new ContextCache)}}function decodeInteger(e,t,n){const r=e.getContexts(t);let i=1;function readBits(e){let t=0;for(let s=0;s<e;s++){const e=n.readBit(r,i);i=i<256?i<<1|e:511&(i<<1|e)|256;t=t<<1|e}return t>>>0}const s=readBits(1),o=readBits(1)?readBits(1)?readBits(1)?readBits(1)?readBits(1)?readBits(32)+4436:readBits(12)+340:readBits(8)+84:readBits(6)+20:readBits(4)+4:readBits(2);let a;0===s?a=o:o>0&&(a=-o);return a>=-2147483648&&a<=2147483647?a:null}function decodeIAID(e,t,n){const r=e.getContexts("IAID");let i=1;for(let e=0;e<n;e++){i=i<<1|t.readBit(r,i)}return n<31?i&(1<<n)-1:2147483647&i}const m=["SymbolDictionary",null,null,null,"IntermediateTextRegion",null,"ImmediateTextRegion","ImmediateLosslessTextRegion",null,null,null,null,null,null,null,null,"PatternDictionary",null,null,null,"IntermediateHalftoneRegion",null,"ImmediateHalftoneRegion","ImmediateLosslessHalftoneRegion",null,null,null,null,null,null,null,null,null,null,null,null,"IntermediateGenericRegion",null,"ImmediateGenericRegion","ImmediateLosslessGenericRegion","IntermediateGenericRefinementRegion",null,"ImmediateGenericRefinementRegion","ImmediateLosslessGenericRefinementRegion",null,null,null,null,"PageInformation","EndOfPage","EndOfStripe","EndOfFile","Profiles","Tables",null,null,null,null,null,null,null,null,"Extension"],g=[[{x:-1,y:-2},{x:0,y:-2},{x:1,y:-2},{x:-2,y:-1},{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:2,y:-1},{x:-4,y:0},{x:-3,y:0},{x:-2,y:0},{x:-1,y:0}],[{x:-1,y:-2},{x:0,y:-2},{x:1,y:-2},{x:2,y:-2},{x:-2,y:-1},{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:2,y:-1},{x:-3,y:0},{x:-2,y:0},{x:-1,y:0}],[{x:-1,y:-2},{x:0,y:-2},{x:1,y:-2},{x:-2,y:-1},{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:-2,y:0},{x:-1,y:0}],[{x:-3,y:-1},{x:-2,y:-1},{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:-4,y:0},{x:-3,y:0},{x:-2,y:0},{x:-1,y:0}]],p=[{coding:[{x:0,y:-1},{x:1,y:-1},{x:-1,y:0}],reference:[{x:0,y:-1},{x:1,y:-1},{x:-1,y:0},{x:0,y:0},{x:1,y:0},{x:-1,y:1},{x:0,y:1},{x:1,y:1}]},{coding:[{x:-1,y:-1},{x:0,y:-1},{x:1,y:-1},{x:-1,y:0}],reference:[{x:0,y:-1},{x:-1,y:0},{x:0,y:0},{x:1,y:0},{x:0,y:1},{x:1,y:1}]}],b=[39717,1941,229,405],w=[32,8];function decodeBitmap(e,t,n,r,i,s,o,a){if(e){return decodeMMRBitmap(new Reader(a.data,a.start,a.end),t,n,!1)}if(0===r&&!s&&!i&&4===o.length&&3===o[0].x&&-1===o[0].y&&-3===o[1].x&&-1===o[1].y&&2===o[2].x&&-2===o[2].y&&-2===o[3].x&&-2===o[3].y)return function decodeBitmapTemplate0(e,t,n){const r=n.decoder,i=n.contextCache.getContexts("GB"),s=[];let o,a,c,l,f,h,u;for(a=0;a<t;a++){f=s[a]=new Uint8Array(e);h=a<1?f:s[a-1];u=a<2?f:s[a-2];o=u[0]<<13|u[1]<<12|u[2]<<11|h[0]<<7|h[1]<<6|h[2]<<5|h[3]<<4;for(c=0;c<e;c++){f[c]=l=r.readBit(i,o);o=(31735&o)<<1|(c+3<e?u[c+3]<<11:0)|(c+4<e?h[c+4]<<4:0)|l}}return s}(t,n,a);const c=!!s,l=g[r].concat(o);l.sort(((e,t)=>e.y-t.y||e.x-t.x));const f=l.length,h=new Int8Array(f),u=new Int8Array(f),d=[];let m,p,w=0,y=0,C=0,x=0;for(p=0;p<f;p++){h[p]=l[p].x;u[p]=l[p].y;y=Math.min(y,l[p].x);C=Math.max(C,l[p].x);x=Math.min(x,l[p].y);p<f-1&&l[p].y===l[p+1].y&&l[p].x===l[p+1].x-1?w|=1<<f-1-p:d.push(p)}const _=d.length,B=new Int8Array(_),R=new Int8Array(_),A=new Uint16Array(_);for(m=0;m<_;m++){p=d[m];B[m]=l[p].x;R[m]=l[p].y;A[m]=1<<f-1-p}const S=-y,I=-x,k=t-C,v=b[r];let D=new Uint8Array(t);const P=[],E=a.decoder,T=a.contextCache.getContexts("GB");let U,M,F,L,O,G=0,W=0;for(let e=0;e<n;e++){if(i){G^=E.readBit(T,v);if(G){P.push(D);continue}}D=new Uint8Array(D);P.push(D);for(U=0;U<t;U++){if(c&&s[e][U]){D[U]=0;continue}if(U>=S&&U<k&&e>=I){W=W<<1&w;for(p=0;p<_;p++){M=e+R[p];F=U+B[p];L=P[M][F];if(L){L=A[p];W|=L}}}else{W=0;O=f-1;for(p=0;p<f;p++,O--){F=U+h[p];if(F>=0&&F<t){M=e+u[p];if(M>=0){L=P[M][F];L&&(W|=L<<O)}}}}const n=E.readBit(T,W);D[U]=n}}return P}function decodeRefinement(e,t,n,r,i,s,o,a,c){let l=p[n].coding;0===n&&(l=l.concat([a[0]]));const f=l.length,h=new Int32Array(f),u=new Int32Array(f);let d;for(d=0;d<f;d++){h[d]=l[d].x;u[d]=l[d].y}let m=p[n].reference;0===n&&(m=m.concat([a[1]]));const g=m.length,b=new Int32Array(g),y=new Int32Array(g);for(d=0;d<g;d++){b[d]=m[d].x;y[d]=m[d].y}const C=r[0].length,x=r.length,_=w[n],B=[],R=c.decoder,A=c.contextCache.getContexts("GR");let S=0;for(let n=0;n<t;n++){if(o){S^=R.readBit(A,_);if(S)throw new Jbig2Error("prediction is not supported")}const t=new Uint8Array(e);B.push(t);for(let o=0;o<e;o++){let a,c,l=0;for(d=0;d<f;d++){a=n+u[d];c=o+h[d];a<0||c<0||c>=e?l<<=1:l=l<<1|B[a][c]}for(d=0;d<g;d++){a=n+y[d]-s;c=o+b[d]-i;a<0||a>=x||c<0||c>=C?l<<=1:l=l<<1|r[a][c]}const m=R.readBit(A,l);t[o]=m}}return B}function decodeTextRegion(e,t,n,r,i,s,o,a,c,l,f,h,u,d,m,g,p,b,w){if(e&&t)throw new Jbig2Error("refinement with Huffman is not supported");const y=[];let C,x;for(C=0;C<r;C++){x=new Uint8Array(n);i&&x.fill(i);y.push(x)}const _=p.decoder,B=p.contextCache;let R=e?-d.tableDeltaT.decode(w):-decodeInteger(B,"IADT",_),A=0;C=0;for(;C<s;){R+=e?d.tableDeltaT.decode(w):decodeInteger(B,"IADT",_);A+=e?d.tableFirstS.decode(w):decodeInteger(B,"IAFS",_);let r=A;for(;;){let i=0;o>1&&(i=e?w.readBits(b):decodeInteger(B,"IAIT",_));const s=o*R+i,A=e?d.symbolIDTable.decode(w):decodeIAID(B,_,c),S=t&&(e?w.readBit():decodeInteger(B,"IARI",_));let I=a[A],k=I[0].length,v=I.length;if(S){const e=decodeInteger(B,"IARDW",_),t=decodeInteger(B,"IARDH",_);k+=e;v+=t;I=decodeRefinement(k,v,m,I,(e>>1)+decodeInteger(B,"IARDX",_),(t>>1)+decodeInteger(B,"IARDY",_),!1,g,p)}let D=0;l?1&h?D=v-1:r+=v-1:h>1?r+=k-1:D=k-1;const P=s-(1&h?0:v-1),E=r-(2&h?k-1:0);let T,U,M;if(l)for(T=0;T<v;T++){x=y[E+T];if(!x)continue;M=I[T];const e=Math.min(n-P,k);switch(u){case 0:for(U=0;U<e;U++)x[P+U]|=M[U];break;case 2:for(U=0;U<e;U++)x[P+U]^=M[U];break;default:throw new Jbig2Error(`operator ${u} is not supported`)}}else for(U=0;U<v;U++){x=y[P+U];if(x){M=I[U];switch(u){case 0:for(T=0;T<k;T++)x[E+T]|=M[T];break;case 2:for(T=0;T<k;T++)x[E+T]^=M[T];break;default:throw new Jbig2Error(`operator ${u} is not supported`)}}}C++;const F=e?d.tableDeltaS.decode(w):decodeInteger(B,"IADS",_);if(null===F)break;r+=D+F+f}}return y}function readSegmentHeader(e,t){const n={};n.number=readUint32(e,t);const r=e[t+4],i=63&r;if(!m[i])throw new Jbig2Error("invalid segment type: "+i);n.type=i;n.typeName=m[i];n.deferredNonRetain=!!(128&r);const s=!!(64&r),o=e[t+5];let a=o>>5&7;const c=[31&o];let l=t+6;if(7===o){a=536870911&readUint32(e,l-1);l+=3;let t=a+7>>3;c[0]=e[l++];for(;--t>0;)c.push(e[l++])}else if(5===o||6===o)throw new Jbig2Error("invalid referred-to flags");n.retainBits=c;let f=4;n.number<=256?f=1:n.number<=65536&&(f=2);const h=[];let u,d;for(u=0;u<a;u++){let t;t=1===f?e[l]:2===f?readUint16(e,l):readUint32(e,l);h.push(t);l+=f}n.referredTo=h;if(s){n.pageAssociation=readUint32(e,l);l+=4}else n.pageAssociation=e[l++];n.length=readUint32(e,l);l+=4;if(4294967295===n.length){if(38!==i)throw new Jbig2Error("invalid unknown segment length");{const t=readRegionSegmentInformation(e,l),r=!!(1&e[l+y]),i=6,s=new Uint8Array(i);if(!r){s[0]=255;s[1]=172}s[2]=t.height>>>24&255;s[3]=t.height>>16&255;s[4]=t.height>>8&255;s[5]=255&t.height;for(u=l,d=e.length;u<d;u++){let t=0;for(;t<i&&s[t]===e[u+t];)t++;if(t===i){n.length=u+i;break}}if(4294967295===n.length)throw new Jbig2Error("segment end was not found")}}n.headerEnd=l;return n}function readSegments(e,t,n,r){const i=[];let s=n;for(;s<r;){const n=readSegmentHeader(t,s);s=n.headerEnd;const r={header:n,data:t};if(!e.randomAccess){r.start=s;s+=n.length;r.end=s}i.push(r);if(51===n.type)break}if(e.randomAccess)for(let e=0,t=i.length;e<t;e++){i[e].start=s;s+=i[e].header.length;i[e].end=s}return i}function readRegionSegmentInformation(e,t){return{width:readUint32(e,t),height:readUint32(e,t+4),x:readUint32(e,t+8),y:readUint32(e,t+12),combinationOperator:7&e[t+16]}}const y=17;function processSegment(e,t){const n=e.header,r=e.data,i=e.end;let s,o,a,c,l=e.start;switch(n.type){case 0:const e={},t=readUint16(r,l);e.huffman=!!(1&t);e.refinement=!!(2&t);e.huffmanDHSelector=t>>2&3;e.huffmanDWSelector=t>>4&3;e.bitmapSizeSelector=t>>6&1;e.aggregationInstancesSelector=t>>7&1;e.bitmapCodingContextUsed=!!(256&t);e.bitmapCodingContextRetained=!!(512&t);e.template=t>>10&3;e.refinementTemplate=t>>12&1;l+=2;if(!e.huffman){c=0===e.template?4:1;o=[];for(a=0;a<c;a++){o.push({x:readInt8(r,l),y:readInt8(r,l+1)});l+=2}e.at=o}if(e.refinement&&!e.refinementTemplate){o=[];for(a=0;a<2;a++){o.push({x:readInt8(r,l),y:readInt8(r,l+1)});l+=2}e.refinementAt=o}e.numberOfExportedSymbols=readUint32(r,l);l+=4;e.numberOfNewSymbols=readUint32(r,l);l+=4;s=[e,n.number,n.referredTo,r,l,i];break;case 6:case 7:const f={};f.info=readRegionSegmentInformation(r,l);l+=y;const h=readUint16(r,l);l+=2;f.huffman=!!(1&h);f.refinement=!!(2&h);f.logStripSize=h>>2&3;f.stripSize=1<<f.logStripSize;f.referenceCorner=h>>4&3;f.transposed=!!(64&h);f.combinationOperator=h>>7&3;f.defaultPixelValue=h>>9&1;f.dsOffset=h<<17>>27;f.refinementTemplate=h>>15&1;if(f.huffman){const e=readUint16(r,l);l+=2;f.huffmanFS=3&e;f.huffmanDS=e>>2&3;f.huffmanDT=e>>4&3;f.huffmanRefinementDW=e>>6&3;f.huffmanRefinementDH=e>>8&3;f.huffmanRefinementDX=e>>10&3;f.huffmanRefinementDY=e>>12&3;f.huffmanRefinementSizeSelector=!!(16384&e)}if(f.refinement&&!f.refinementTemplate){o=[];for(a=0;a<2;a++){o.push({x:readInt8(r,l),y:readInt8(r,l+1)});l+=2}f.refinementAt=o}f.numberOfSymbolInstances=readUint32(r,l);l+=4;s=[f,n.referredTo,r,l,i];break;case 16:const u={},d=r[l++];u.mmr=!!(1&d);u.template=d>>1&3;u.patternWidth=r[l++];u.patternHeight=r[l++];u.maxPatternIndex=readUint32(r,l);l+=4;s=[u,n.number,r,l,i];break;case 22:case 23:const m={};m.info=readRegionSegmentInformation(r,l);l+=y;const g=r[l++];m.mmr=!!(1&g);m.template=g>>1&3;m.enableSkip=!!(8&g);m.combinationOperator=g>>4&7;m.defaultPixelValue=g>>7&1;m.gridWidth=readUint32(r,l);l+=4;m.gridHeight=readUint32(r,l);l+=4;m.gridOffsetX=4294967295&readUint32(r,l);l+=4;m.gridOffsetY=4294967295&readUint32(r,l);l+=4;m.gridVectorX=readUint16(r,l);l+=2;m.gridVectorY=readUint16(r,l);l+=2;s=[m,n.referredTo,r,l,i];break;case 38:case 39:const p={};p.info=readRegionSegmentInformation(r,l);l+=y;const b=r[l++];p.mmr=!!(1&b);p.template=b>>1&3;p.prediction=!!(8&b);if(!p.mmr){c=0===p.template?4:1;o=[];for(a=0;a<c;a++){o.push({x:readInt8(r,l),y:readInt8(r,l+1)});l+=2}p.at=o}s=[p,r,l,i];break;case 48:const w={width:readUint32(r,l),height:readUint32(r,l+4),resolutionX:readUint32(r,l+8),resolutionY:readUint32(r,l+12)};4294967295===w.height&&delete w.height;const C=r[l+16];readUint16(r,l+17);w.lossless=!!(1&C);w.refinement=!!(2&C);w.defaultPixelValue=C>>2&1;w.combinationOperator=C>>3&3;w.requiresBuffer=!!(32&C);w.combinationOperatorOverride=!!(64&C);s=[w];break;case 49:case 50:case 51:case 62:break;case 53:s=[n.number,r,l,i];break;default:throw new Jbig2Error(`segment type ${n.typeName}(${n.type}) is not implemented`)}const f="on"+n.typeName;f in t&&t[f].apply(t,s)}function processSegments(e,t){for(let n=0,r=e.length;n<r;n++)processSegment(e[n],t)}class SimpleSegmentVisitor{onPageInformation(e){this.currentPageInfo=e;const t=e.width+7>>3,n=new Uint8ClampedArray(t*e.height);e.defaultPixelValue&&n.fill(255);this.buffer=n}drawBitmap(e,t){const n=this.currentPageInfo,r=e.width,i=e.height,s=n.width+7>>3,o=n.combinationOperatorOverride?e.combinationOperator:n.combinationOperator,a=this.buffer,c=128>>(7&e.x);let l,f,h,u,d=e.y*s+(e.x>>3);switch(o){case 0:for(l=0;l<i;l++){h=c;u=d;for(f=0;f<r;f++){t[l][f]&&(a[u]|=h);h>>=1;if(!h){h=128;u++}}d+=s}break;case 2:for(l=0;l<i;l++){h=c;u=d;for(f=0;f<r;f++){t[l][f]&&(a[u]^=h);h>>=1;if(!h){h=128;u++}}d+=s}break;default:throw new Jbig2Error(`operator ${o} is not supported`)}}onImmediateGenericRegion(e,t,n,r){const i=e.info,s=new DecodingContext(t,n,r),o=decodeBitmap(e.mmr,i.width,i.height,e.template,e.prediction,null,e.at,s);this.drawBitmap(i,o)}onImmediateLosslessGenericRegion(){this.onImmediateGenericRegion(...arguments)}onSymbolDictionary(e,t,n,r,i,s){let o,a;if(e.huffman){o=function getSymbolDictionaryHuffmanTables(e,t,n){let r,i,s,o,a=0;switch(e.huffmanDHSelector){case 0:case 1:r=getStandardTable(e.huffmanDHSelector+4);break;case 3:r=getCustomHuffmanTable(a,t,n);a++;break;default:throw new Jbig2Error("invalid Huffman DH selector")}switch(e.huffmanDWSelector){case 0:case 1:i=getStandardTable(e.huffmanDWSelector+2);break;case 3:i=getCustomHuffmanTable(a,t,n);a++;break;default:throw new Jbig2Error("invalid Huffman DW selector")}if(e.bitmapSizeSelector){s=getCustomHuffmanTable(a,t,n);a++}else s=getStandardTable(1);o=e.aggregationInstancesSelector?getCustomHuffmanTable(a,t,n):getStandardTable(1);return{tableDeltaHeight:r,tableDeltaWidth:i,tableBitmapSize:s,tableAggregateInstances:o}}(e,n,this.customTables);a=new Reader(r,i,s)}let c=this.symbols;c||(this.symbols=c={});const l=[];for(const e of n){const t=c[e];t&&l.push(...t)}const f=new DecodingContext(r,i,s);c[t]=function decodeSymbolDictionary(e,t,n,r,i,s,o,a,c,l,f,h){if(e&&t)throw new Jbig2Error("symbol refinement with Huffman is not supported");const u=[];let d=0,m=log2(n.length+r);const g=f.decoder,p=f.contextCache;let b,w;if(e){b=getStandardTable(1);w=[];m=Math.max(m,1)}for(;u.length<r;){d+=e?s.tableDeltaHeight.decode(h):decodeInteger(p,"IADH",g);let r=0,i=0;const b=e?w.length:0;for(;;){const b=e?s.tableDeltaWidth.decode(h):decodeInteger(p,"IADW",g);if(null===b)break;r+=b;i+=r;let y;if(t){const i=decodeInteger(p,"IAAI",g);if(i>1)y=decodeTextRegion(e,t,r,d,0,i,1,n.concat(u),m,0,0,1,0,s,c,l,f,0,h);else{const e=decodeIAID(p,g,m),t=decodeInteger(p,"IARDX",g),i=decodeInteger(p,"IARDY",g);y=decodeRefinement(r,d,c,e<n.length?n[e]:u[e-n.length],t,i,!1,l,f)}u.push(y)}else if(e)w.push(r);else{y=decodeBitmap(!1,r,d,o,!1,null,a,f);u.push(y)}}if(e&&!t){const e=s.tableBitmapSize.decode(h);h.byteAlign();let t;if(0===e)t=readUncompressedBitmap(h,i,d);else{const n=h.end,r=h.position+e;h.end=r;t=decodeMMRBitmap(h,i,d,!1);h.end=n;h.position=r}const n=w.length;if(b===n-1)u.push(t);else{let e,r,i,s,o,a=0;for(e=b;e<n;e++){s=w[e];i=a+s;o=[];for(r=0;r<d;r++)o.push(t[r].subarray(a,i));u.push(o);a=i}}}}const y=[],C=[];let x,_,B=!1;const R=n.length+r;for(;C.length<R;){let t=e?b.decode(h):decodeInteger(p,"IAEX",g);for(;t--;)C.push(B);B=!B}for(x=0,_=n.length;x<_;x++)C[x]&&y.push(n[x]);for(let e=0;e<r;x++,e++)C[x]&&y.push(u[e]);return y}(e.huffman,e.refinement,l,e.numberOfNewSymbols,e.numberOfExportedSymbols,o,e.template,e.at,e.refinementTemplate,e.refinementAt,f,a)}onImmediateTextRegion(e,t,n,r,i){const s=e.info;let o,a;const c=this.symbols,l=[];for(const e of t){const t=c[e];t&&l.push(...t)}const f=log2(l.length);if(e.huffman){a=new Reader(n,r,i);o=function getTextRegionHuffmanTables(e,t,n,r,i){const s=[];for(let e=0;e<=34;e++){const t=i.readBits(4);s.push(new HuffmanLine([e,t,0,0]))}const o=new HuffmanTable(s,!1);s.length=0;for(let e=0;e<r;){const t=o.decode(i);if(t>=32){let n,r,o;switch(t){case 32:if(0===e)throw new Jbig2Error("no previous value in symbol ID table");r=i.readBits(2)+3;n=s[e-1].prefixLength;break;case 33:r=i.readBits(3)+3;n=0;break;case 34:r=i.readBits(7)+11;n=0;break;default:throw new Jbig2Error("invalid code length in symbol ID table")}for(o=0;o<r;o++){s.push(new HuffmanLine([e,n,0,0]));e++}}else{s.push(new HuffmanLine([e,t,0,0]));e++}}i.byteAlign();const a=new HuffmanTable(s,!1);let c,l,f,h=0;switch(e.huffmanFS){case 0:case 1:c=getStandardTable(e.huffmanFS+6);break;case 3:c=getCustomHuffmanTable(h,t,n);h++;break;default:throw new Jbig2Error("invalid Huffman FS selector")}switch(e.huffmanDS){case 0:case 1:case 2:l=getStandardTable(e.huffmanDS+8);break;case 3:l=getCustomHuffmanTable(h,t,n);h++;break;default:throw new Jbig2Error("invalid Huffman DS selector")}switch(e.huffmanDT){case 0:case 1:case 2:f=getStandardTable(e.huffmanDT+11);break;case 3:f=getCustomHuffmanTable(h,t,n);h++;break;default:throw new Jbig2Error("invalid Huffman DT selector")}if(e.refinement)throw new Jbig2Error("refinement with Huffman is not supported");return{symbolIDTable:a,tableFirstS:c,tableDeltaS:l,tableDeltaT:f}}(e,t,this.customTables,l.length,a)}const h=new DecodingContext(n,r,i),u=decodeTextRegion(e.huffman,e.refinement,s.width,s.height,e.defaultPixelValue,e.numberOfSymbolInstances,e.stripSize,l,f,e.transposed,e.dsOffset,e.referenceCorner,e.combinationOperator,o,e.refinementTemplate,e.refinementAt,h,e.logStripSize,a);this.drawBitmap(s,u)}onImmediateLosslessTextRegion(){this.onImmediateTextRegion(...arguments)}onPatternDictionary(e,t,n,r,i){let s=this.patterns;s||(this.patterns=s={});const o=new DecodingContext(n,r,i);s[t]=function decodePatternDictionary(e,t,n,r,i,s){const o=[];if(!e){o.push({x:-t,y:0});0===i&&o.push({x:-3,y:-1},{x:2,y:-2},{x:-2,y:-2})}const a=decodeBitmap(e,(r+1)*t,n,i,!1,null,o,s),c=[];for(let e=0;e<=r;e++){const r=[],i=t*e,s=i+t;for(let e=0;e<n;e++)r.push(a[e].subarray(i,s));c.push(r)}return c}(e.mmr,e.patternWidth,e.patternHeight,e.maxPatternIndex,e.template,o)}onImmediateHalftoneRegion(e,t,n,r,i){const s=this.patterns[t[0]],o=e.info,a=new DecodingContext(n,r,i),c=function decodeHalftoneRegion(e,t,n,r,i,s,o,a,c,l,f,h,u,d,m){if(o)throw new Jbig2Error("skip is not supported");if(0!==a)throw new Jbig2Error(`operator "${a}" is not supported in halftone region`);const g=[];let p,b,w;for(p=0;p<i;p++){w=new Uint8Array(r);s&&w.fill(s);g.push(w)}const y=t.length,C=t[0],x=C[0].length,_=C.length,B=log2(y),R=[];if(!e){R.push({x:n<=1?3:2,y:-1});0===n&&R.push({x:-3,y:-1},{x:2,y:-2},{x:-2,y:-2})}const A=[];let S,I,k,v,D,P,E,T,U,M,F;e&&(S=new Reader(m.data,m.start,m.end));for(p=B-1;p>=0;p--){I=e?decodeMMRBitmap(S,c,l,!0):decodeBitmap(!1,c,l,n,!1,null,R,m);A[p]=I}for(k=0;k<l;k++)for(v=0;v<c;v++){D=0;P=0;for(b=B-1;b>=0;b--){D^=A[b][k][v];P|=D<<b}E=t[P];T=f+k*d+v*u>>8;U=h+k*u-v*d>>8;if(T>=0&&T+x<=r&&U>=0&&U+_<=i)for(p=0;p<_;p++){F=g[U+p];M=E[p];for(b=0;b<x;b++)F[T+b]|=M[b]}else{let e,t;for(p=0;p<_;p++){t=U+p;if(!(t<0||t>=i)){F=g[t];M=E[p];for(b=0;b<x;b++){e=T+b;e>=0&&e<r&&(F[e]|=M[b])}}}}}return g}(e.mmr,s,e.template,o.width,o.height,e.defaultPixelValue,e.enableSkip,e.combinationOperator,e.gridWidth,e.gridHeight,e.gridOffsetX,e.gridOffsetY,e.gridVectorX,e.gridVectorY,a);this.drawBitmap(o,c)}onImmediateLosslessHalftoneRegion(){this.onImmediateHalftoneRegion(...arguments)}onTables(e,t,n,r){let i=this.customTables;i||(this.customTables=i={});i[e]=function decodeTablesSegment(e,t,n){const r=e[t],i=4294967295&readUint32(e,t+1),s=4294967295&readUint32(e,t+5),o=new Reader(e,t+9,n),a=1+(r>>1&7),c=1+(r>>4&7),l=[];let f,h,u=i;do{f=o.readBits(a);h=o.readBits(c);l.push(new HuffmanLine([u,f,h,0]));u+=1<<h}while(u<s);f=o.readBits(a);l.push(new HuffmanLine([i-1,f,32,0,"lower"]));f=o.readBits(a);l.push(new HuffmanLine([s,f,32,0]));if(1&r){f=o.readBits(a);l.push(new HuffmanLine([f,0]))}return new HuffmanTable(l,!1)}(t,n,r)}}class HuffmanLine{constructor(e){if(2===e.length){this.isOOB=!0;this.rangeLow=0;this.prefixLength=e[0];this.rangeLength=0;this.prefixCode=e[1];this.isLowerRange=!1}else{this.isOOB=!1;this.rangeLow=e[0];this.prefixLength=e[1];this.rangeLength=e[2];this.prefixCode=e[3];this.isLowerRange="lower"===e[4]}}}class HuffmanTreeNode{constructor(e){this.children=[];if(e){this.isLeaf=!0;this.rangeLength=e.rangeLength;this.rangeLow=e.rangeLow;this.isLowerRange=e.isLowerRange;this.isOOB=e.isOOB}else this.isLeaf=!1}buildTree(e,t){const n=e.prefixCode>>t&1;if(t<=0)this.children[n]=new HuffmanTreeNode(e);else{let r=this.children[n];r||(this.children[n]=r=new HuffmanTreeNode(null));r.buildTree(e,t-1)}}decodeNode(e){if(this.isLeaf){if(this.isOOB)return null;const t=e.readBits(this.rangeLength);return this.rangeLow+(this.isLowerRange?-t:t)}const t=this.children[e.readBit()];if(!t)throw new Jbig2Error("invalid Huffman data");return t.decodeNode(e)}}class HuffmanTable{constructor(e,t){t||this.assignPrefixCodes(e);this.rootNode=new HuffmanTreeNode(null);for(let t=0,n=e.length;t<n;t++){const n=e[t];n.prefixLength>0&&this.rootNode.buildTree(n,n.prefixLength-1)}}decode(e){return this.rootNode.decodeNode(e)}assignPrefixCodes(e){const t=e.length;let n=0;for(let r=0;r<t;r++)n=Math.max(n,e[r].prefixLength);const r=new Uint32Array(n+1);for(let n=0;n<t;n++)r[e[n].prefixLength]++;let i,s,o,a=1,c=0;r[0]=0;for(;a<=n;){c=c+r[a-1]<<1;i=c;s=0;for(;s<t;){o=e[s];if(o.prefixLength===a){o.prefixCode=i;i++}s++}a++}}}const C={};function getStandardTable(e){let t,n=C[e];if(n)return n;switch(e){case 1:t=[[0,1,4,0],[16,2,8,2],[272,3,16,6],[65808,3,32,7]];break;case 2:t=[[0,1,0,0],[1,2,0,2],[2,3,0,6],[3,4,3,14],[11,5,6,30],[75,6,32,62],[6,63]];break;case 3:t=[[-256,8,8,254],[0,1,0,0],[1,2,0,2],[2,3,0,6],[3,4,3,14],[11,5,6,30],[-257,8,32,255,"lower"],[75,7,32,126],[6,62]];break;case 4:t=[[1,1,0,0],[2,2,0,2],[3,3,0,6],[4,4,3,14],[12,5,6,30],[76,5,32,31]];break;case 5:t=[[-255,7,8,126],[1,1,0,0],[2,2,0,2],[3,3,0,6],[4,4,3,14],[12,5,6,30],[-256,7,32,127,"lower"],[76,6,32,62]];break;case 6:t=[[-2048,5,10,28],[-1024,4,9,8],[-512,4,8,9],[-256,4,7,10],[-128,5,6,29],[-64,5,5,30],[-32,4,5,11],[0,2,7,0],[128,3,7,2],[256,3,8,3],[512,4,9,12],[1024,4,10,13],[-2049,6,32,62,"lower"],[2048,6,32,63]];break;case 7:t=[[-1024,4,9,8],[-512,3,8,0],[-256,4,7,9],[-128,5,6,26],[-64,5,5,27],[-32,4,5,10],[0,4,5,11],[32,5,5,28],[64,5,6,29],[128,4,7,12],[256,3,8,1],[512,3,9,2],[1024,3,10,3],[-1025,5,32,30,"lower"],[2048,5,32,31]];break;case 8:t=[[-15,8,3,252],[-7,9,1,508],[-5,8,1,253],[-3,9,0,509],[-2,7,0,124],[-1,4,0,10],[0,2,1,0],[2,5,0,26],[3,6,0,58],[4,3,4,4],[20,6,1,59],[22,4,4,11],[38,4,5,12],[70,5,6,27],[134,5,7,28],[262,6,7,60],[390,7,8,125],[646,6,10,61],[-16,9,32,510,"lower"],[1670,9,32,511],[2,1]];break;case 9:t=[[-31,8,4,252],[-15,9,2,508],[-11,8,2,253],[-7,9,1,509],[-5,7,1,124],[-3,4,1,10],[-1,3,1,2],[1,3,1,3],[3,5,1,26],[5,6,1,58],[7,3,5,4],[39,6,2,59],[43,4,5,11],[75,4,6,12],[139,5,7,27],[267,5,8,28],[523,6,8,60],[779,7,9,125],[1291,6,11,61],[-32,9,32,510,"lower"],[3339,9,32,511],[2,0]];break;case 10:t=[[-21,7,4,122],[-5,8,0,252],[-4,7,0,123],[-3,5,0,24],[-2,2,2,0],[2,5,0,25],[3,6,0,54],[4,7,0,124],[5,8,0,253],[6,2,6,1],[70,5,5,26],[102,6,5,55],[134,6,6,56],[198,6,7,57],[326,6,8,58],[582,6,9,59],[1094,6,10,60],[2118,7,11,125],[-22,8,32,254,"lower"],[4166,8,32,255],[2,2]];break;case 11:t=[[1,1,0,0],[2,2,1,2],[4,4,0,12],[5,4,1,13],[7,5,1,28],[9,5,2,29],[13,6,2,60],[17,7,2,122],[21,7,3,123],[29,7,4,124],[45,7,5,125],[77,7,6,126],[141,7,32,127]];break;case 12:t=[[1,1,0,0],[2,2,0,2],[3,3,1,6],[5,5,0,28],[6,5,1,29],[8,6,1,60],[10,7,0,122],[11,7,1,123],[13,7,2,124],[17,7,3,125],[25,7,4,126],[41,8,5,254],[73,8,32,255]];break;case 13:t=[[1,1,0,0],[2,3,0,4],[3,4,0,12],[4,5,0,28],[5,4,1,13],[7,3,3,5],[15,6,1,58],[17,6,2,59],[21,6,3,60],[29,6,4,61],[45,6,5,62],[77,7,6,126],[141,7,32,127]];break;case 14:t=[[-2,3,0,4],[-1,3,0,5],[0,1,0,0],[1,3,0,6],[2,3,0,7]];break;case 15:t=[[-24,7,4,124],[-8,6,2,60],[-4,5,1,28],[-2,4,0,12],[-1,3,0,4],[0,1,0,0],[1,3,0,5],[2,4,0,13],[3,5,1,29],[5,6,2,61],[9,7,4,125],[-25,7,32,126,"lower"],[25,7,32,127]];break;default:throw new Jbig2Error(`standard table B.${e} does not exist`)}for(let e=0,n=t.length;e<n;e++)t[e]=new HuffmanLine(t[e]);n=new HuffmanTable(t,!0);C[e]=n;return n}class Reader{constructor(e,t,n){this.data=e;this.start=t;this.end=n;this.position=t;this.shift=-1;this.currentByte=0}readBit(){if(this.shift<0){if(this.position>=this.end)throw new Jbig2Error("end of data while reading bit");this.currentByte=this.data[this.position++];this.shift=7}const e=this.currentByte>>this.shift&1;this.shift--;return e}readBits(e){let t,n=0;for(t=e-1;t>=0;t--)n|=this.readBit()<<t;return n}byteAlign(){this.shift=-1}next(){return this.position>=this.end?-1:this.data[this.position++]}}function getCustomHuffmanTable(e,t,n){let r=0;for(let i=0,s=t.length;i<s;i++){const s=n[t[i]];if(s){if(e===r)return s;r++}}throw new Jbig2Error("can't find custom Huffman table")}function readUncompressedBitmap(e,t,n){const r=[];for(let i=0;i<n;i++){const n=new Uint8Array(t);r.push(n);for(let r=0;r<t;r++)n[r]=e.readBit();e.byteAlign()}return r}function decodeMMRBitmap(e,t,n,r){const i=new CCITTFaxDecoder(e,{K:-1,Columns:t,Rows:n,BlackIs1:!0,EndOfBlock:r}),s=[];let o,a=!1;for(let e=0;e<n;e++){const e=new Uint8Array(t);s.push(e);let n=-1;for(let r=0;r<t;r++){if(n<0){o=i.readNextChar();if(-1===o){o=0;a=!0}n=7}e[r]=o>>n&1;n--}}if(r&&!a){const e=5;for(let t=0;t<e&&-1!==i.readNextChar();t++);}return s}class Jbig2Image{parseChunks(e){return function parseJbig2Chunks(e){const t=new SimpleSegmentVisitor;for(let n=0,r=e.length;n<r;n++){const r=e[n];processSegments(readSegments({},r.data,r.start,r.end),t)}return t.buffer}(e)}parse(e){const{imgData:t,width:n,height:r}=function parseJbig2(e){const t=e.length;let n=0;if(151!==e[n]||74!==e[n+1]||66!==e[n+2]||50!==e[n+3]||13!==e[n+4]||10!==e[n+5]||26!==e[n+6]||10!==e[n+7])throw new Jbig2Error("parseJbig2 - invalid header.");const r=Object.create(null);n+=8;const i=e[n++];r.randomAccess=!(1&i);if(!(2&i)){r.numberOfPages=readUint32(e,n);n+=4}const s=readSegments(r,e,n,t),o=new SimpleSegmentVisitor;processSegments(s,o);const{width:a,height:c}=o.currentPageInfo,l=o.buffer,f=new Uint8ClampedArray(a*c);let h=0,u=0;for(let e=0;e<c;e++){let e,t=0;for(let n=0;n<a;n++){if(!t){t=128;e=l[u++]}f[h++]=e&t?0:255;t>>=1}}return{imgData:f,width:a,height:c}}(e);this.width=n;this.height=r;return t}}class ColorSpace{constructor(e,t){this.name=e;this.numComps=t}getRgb(e,t){const n=new Uint8ClampedArray(3);this.getRgbItem(e,t,n,0);return n}getRgbItem(e,t,n,r){unreachable("Should not