UNPKG

pdfjs-dist

Version:

Generic build of Mozilla's PDF.js library.

28 lines • 62.1 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 */ /** * pdfjsVersion = 5.7.284 * pdfjsBuild = 7e5b36c2d */"object"!=typeof process||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&process.type;const t=[1/0,1/0,-1/0,-1/0],e=(new Float32Array(t),{ERRORS:0,WARNINGS:1,INFOS:5});let r=e.WARNINGS;function setVerbosityLevel(t){Number.isInteger(t)&&(r=t)}function getVerbosityLevel(){return r}function info(t){r>=e.INFOS&&console.info(`Info: ${t}`)}function warn(t){r>=e.WARNINGS&&console.warn(`Warning: ${t}`)}function unreachable(t){throw new Error(t)}function shadow(t,e,r,n=!1){Object.defineProperty(t,e,{value:r,enumerable:!n,configurable:!0,writable:!1});return r}const n=function BaseExceptionClosure(){function BaseException(t,e){this.message=t;this.name=e}BaseException.prototype=new Error;BaseException.constructor=BaseException;return BaseException}();class FormatError extends n{constructor(t){super(t,"FormatError")}}function bytesToString(t){"object"==typeof t&&void 0!==t?.length||unreachable("Invalid argument for bytesToString");const e=t.length,r=8192;if(e<r)return String.fromCharCode.apply(null,t);const n=[];for(let s=0;s<e;s+=r){const a=Math.min(s+r,e),i=t.subarray(s,a);n.push(String.fromCharCode.apply(null,i))}return n.join("")}class FeatureTest{static get isLittleEndian(){return shadow(this,"isLittleEndian",function isLittleEndian(){const t=new Uint8Array(4);t[0]=1;return 1===new Uint32Array(t.buffer,0,1)[0]}())}static get isOffscreenCanvasSupported(){return shadow(this,"isOffscreenCanvasSupported","undefined"!=typeof OffscreenCanvas)}static get isImageDecoderSupported(){return shadow(this,"isImageDecoderSupported","undefined"!=typeof ImageDecoder)}static get isFloat16ArraySupported(){return shadow(this,"isFloat16ArraySupported","undefined"!=typeof Float16Array)}static get isSanitizerSupported(){return shadow(this,"isSanitizerSupported","undefined"!=typeof Sanitizer)}static get platform(){const{platform:t,userAgent:e}=navigator;return shadow(this,"platform",{isAndroid:e.includes("Android"),isLinux:t.includes("Linux"),isMac:t.includes("Mac"),isWindows:t.includes("Win"),isFirefox:e.includes("Firefox")})}static get isCSSRoundSupported(){return shadow(this,"isCSSRoundSupported",globalThis.CSS?.supports?.("width: round(1.5px, 1px)"))}static get isAlphaColorInputSupported(){return shadow(this,"isAlphaColorInputSupported",(()=>{if("undefined"==typeof document)return!1;const t=document.createElement("input");t.type="color";t.setAttribute("alpha","");t.value="#ff000080";return"#ff0000"!==t.value})())}}class Util{static get hexNums(){return shadow(this,"hexNums",Array.from(Array(256).keys(),t=>t.toString(16).padStart(2,"0")))}static makeHexColor(t,e,r){return`#${this.hexNums[t]}${this.hexNums[e]}${this.hexNums[r]}`}static domMatrixToTransform(t){return[t.a,t.b,t.c,t.d,t.e,t.f]}static scaleMinMax(t,e){let r;if(t[0]){if(t[0]<0){r=e[0];e[0]=e[2];e[2]=r}e[0]*=t[0];e[2]*=t[0];if(t[3]<0){r=e[1];e[1]=e[3];e[3]=r}e[1]*=t[3];e[3]*=t[3]}else{r=e[0];e[0]=e[1];e[1]=r;r=e[2];e[2]=e[3];e[3]=r;if(t[1]<0){r=e[1];e[1]=e[3];e[3]=r}e[1]*=t[1];e[3]*=t[1];if(t[2]<0){r=e[0];e[0]=e[2];e[2]=r}e[0]*=t[2];e[2]*=t[2]}e[0]+=t[4];e[1]+=t[5];e[2]+=t[4];e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static multiplyByDOMMatrix(t,e){return[t[0]*e.a+t[2]*e.b,t[1]*e.a+t[3]*e.b,t[0]*e.c+t[2]*e.d,t[1]*e.c+t[3]*e.d,t[0]*e.e+t[2]*e.f+t[4],t[1]*e.e+t[3]*e.f+t[5]]}static applyTransform(t,e,r=0){const n=t[r],s=t[r+1];t[r]=n*e[0]+s*e[2]+e[4];t[r+1]=n*e[1]+s*e[3]+e[5]}static applyTransformToBezier(t,e,r=0){const n=e[0],s=e[1],a=e[2],i=e[3],o=e[4],c=e[5];for(let e=0;e<6;e+=2){const l=t[r+e],u=t[r+e+1];t[r+e]=l*n+u*a+o;t[r+e+1]=l*s+u*i+c}}static applyInverseTransform(t,e){const r=t[0],n=t[1],s=e[0]*e[3]-e[1]*e[2];t[0]=(r*e[3]-n*e[2]+e[2]*e[5]-e[4]*e[3])/s;t[1]=(-r*e[1]+n*e[0]+e[4]*e[1]-e[5]*e[0])/s}static axialAlignedBoundingBox(t,e,r){const n=e[0],s=e[1],a=e[2],i=e[3],o=e[4],c=e[5],l=t[0],u=t[1],f=t[2],h=t[3];let m=n*l+o,g=m,d=n*f+o,p=d,b=i*u+c,y=b,w=i*h+c,C=w;if(0!==s||0!==a){const t=s*l,e=s*f,r=a*u,n=a*h;m+=r;p+=r;d+=n;g+=n;b+=t;C+=t;w+=e;y+=e}r[0]=Math.min(r[0],m,d,g,p);r[1]=Math.min(r[1],b,w,y,C);r[2]=Math.max(r[2],m,d,g,p);r[3]=Math.max(r[3],b,w,y,C)}static inverseTransform(t){const e=t[0]*t[3]-t[1]*t[2];return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[4]*t[3])/e,(t[4]*t[1]-t[5]*t[0])/e]}static singularValueDecompose2dScale(t,e){const r=t[0],n=t[1],s=t[2],a=t[3],i=r**2+n**2,o=r*s+n*a,c=s**2+a**2,l=(i+c)/2,u=Math.sqrt(l**2-(i*c-o**2));e[0]=Math.sqrt(l+u||1);e[1]=Math.sqrt(l-u||1)}static normalizeRect(t){const e=t.slice(0);if(t[0]>t[2]){e[0]=t[2];e[2]=t[0]}if(t[1]>t[3]){e[1]=t[3];e[3]=t[1]}return e}static intersect(t,e){const r=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),n=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(r>n)return null;const s=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),a=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return s>a?null:[r,s,n,a]}static pointBoundingBox(t,e,r){r[0]=Math.min(r[0],t);r[1]=Math.min(r[1],e);r[2]=Math.max(r[2],t);r[3]=Math.max(r[3],e)}static rectBoundingBox(t,e,r,n,s){s[0]=Math.min(s[0],t,r);s[1]=Math.min(s[1],e,n);s[2]=Math.max(s[2],t,r);s[3]=Math.max(s[3],e,n)}static#t(t,e,r,n,s,a,i,o,c,l){if(c<=0||c>=1)return;const u=1-c,f=c*c,h=f*c,m=u*(u*(u*t+3*c*e)+3*f*r)+h*n,g=u*(u*(u*s+3*c*a)+3*f*i)+h*o;l[0]=Math.min(l[0],m);l[1]=Math.min(l[1],g);l[2]=Math.max(l[2],m);l[3]=Math.max(l[3],g)}static#e(t,e,r,n,s,a,i,o,c,l,u,f){if(Math.abs(c)<1e-12){Math.abs(l)>=1e-12&&this.#t(t,e,r,n,s,a,i,o,-u/l,f);return}const h=l**2-4*u*c;if(h<0)return;const m=Math.sqrt(h),g=2*c;this.#t(t,e,r,n,s,a,i,o,(-l+m)/g,f);this.#t(t,e,r,n,s,a,i,o,(-l-m)/g,f)}static bezierBoundingBox(t,e,r,n,s,a,i,o,c){c[0]=Math.min(c[0],t,i);c[1]=Math.min(c[1],e,o);c[2]=Math.max(c[2],t,i);c[3]=Math.max(c[3],e,o);this.#e(t,r,s,i,e,n,a,o,3*(3*(r-s)-t+i),6*(t-2*r+s),3*(r-t),c);this.#e(t,r,s,i,e,n,a,o,3*(3*(n-a)-e+o),6*(e-2*n+a),3*(n-e),c)}}Symbol("CIRCULAR_REF"),Symbol("EOF");Object.create(null);let s=Object.create(null),a=Object.create(null);class Name{constructor(t){this.name=t}static get(t){return s[t]||=new Name(t)}}const i=function nonSerializableClosure(){return i};class Dict{__nonSerializable__=i;#r=new Map;objId=null;suppressEncryption=!1;xref;constructor(t=null){this.xref=t}assignXref(t){this.xref=t}get size(){return this.#r.size}#n(t,e,r,n){let s=this.#r.get(e);if(void 0===s&&void 0!==r){s=this.#r.get(r);void 0===s&&void 0!==n&&(s=this.#r.get(n))}return s instanceof Ref&&this.xref?t?this.xref.fetchAsync(s,this.suppressEncryption):this.xref.fetch(s,this.suppressEncryption):s}get(t,e,r){return this.#n(!1,t,e,r)}async getAsync(t,e,r){return this.#n(!0,t,e,r)}getArray(t,e,r){let n=this.#n(!1,t,e,r);if(Array.isArray(n)){n=n.slice();for(let t=0,e=n.length;t<e;t++)n[t]instanceof Ref&&this.xref&&(n[t]=this.xref.fetch(n[t],this.suppressEncryption))}return n}getRaw(t){return this.#r.get(t)}getKeys(){return this.#r.keys()}getRawValues(){return this.#r.values()}getRawEntries(){return this.#r.entries()}set(t,e){this.#r.set(t,e)}setIfNotExists(t,e){this.has(t)||this.set(t,e)}setIfNumber(t,e){"number"==typeof e&&this.set(t,e)}setIfArray(t,e){(Array.isArray(e)||ArrayBuffer.isView(e))&&this.set(t,e)}setIfDefined(t,e){null!=e&&this.set(t,e)}setIfName(t,e){"string"==typeof e?this.set(t,Name.get(e)):e instanceof Name&&this.set(t,e)}setIfDict(t,e){e instanceof Dict&&this.set(t,e)}has(t){return this.#r.has(t)}*[Symbol.iterator](){for(const[t,e]of this.#r)yield[t,e instanceof Ref&&this.xref?this.xref.fetch(e,this.suppressEncryption):e]}static get empty(){const t=new Dict(null);t.set=(t,e)=>{unreachable("Should not call `set` on the empty dictionary.")};return shadow(this,"empty",t)}static merge({xref:t,dictArray:e,mergeSubDicts:r=!1}){const n=new Dict(t),s=new Map;for(const t of e)if(t instanceof Dict)for(const[e,n]of t.getRawEntries()){let t=s.get(e);if(void 0===t){t=[];s.set(e,t)}else if(!(r&&n instanceof Dict))continue;t.push(n)}for(const[e,r]of s){if(1===r.length||!(r[0]instanceof Dict)){n.set(e,r[0]);continue}const s=new Dict(t);for(const t of r)for(const[e,r]of t.getRawEntries())s.setIfNotExists(e,r);s.size>0&&n.set(e,s)}s.clear();return n.size>0?n:Dict.empty}clone(){const t=new Dict(this.xref);for(const[e,r]of this.#r)t.set(e,r);return t}delete(t){this.#r.delete(t)}}class Ref{constructor(t,e){this.num=t;this.gen=e}toString(){return 0===this.gen?`${this.num}R`:`${this.num}R${this.gen}`}static fromString(t){const e=a[t];if(e)return e;const r=/^(\d+)R(\d*)$/.exec(t);return r&&"0"!==r[1]?a[t]=new Ref(parseInt(r[1],10),r[2]?parseInt(r[2],10):0):null}static get(t,e){const r=0===e?`${t}R`:`${t}R${e}`;return a[r]||=new Ref(t,e)}}Symbol.iterator;Symbol.iterator;class 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(t){unreachable("Abstract method `getBytes` called")}async getImageData(t,e){return this.getBytes(t,e)}async asyncGetBytes(){unreachable("Abstract method `asyncGetBytes` called")}get isAsync(){return!1}get isAsyncDecoder(){return!1}get isImageStream(){return!1}get canAsyncDecodeImageFromBuffer(){return!1}async getTransferableImage(){return null}peekByte(){const t=this.getByte();-1!==t&&this.pos--;return t}peekBytes(t){const e=this.getBytes(t);this.pos-=e.length;return e}getUint16(){const t=this.getByte(),e=this.getByte();return-1===t||-1===e?-1:(t<<8)+e}getInt32(){return(this.getByte()<<24)+(this.getByte()<<16)+(this.getByte()<<8)+this.getByte()}getByteRange(t,e){unreachable("Abstract method `getByteRange` called")}getString(t){return bytesToString(this.getBytes(t))}skip(t){this.pos+=t||1}reset(){unreachable("Abstract method `reset` called")}moveStart(){unreachable("Abstract method `moveStart` called")}makeSubStream(t,e,r=null){unreachable("Abstract method `makeSubStream` called")}getBaseStreams(){return null}getOriginalStream(){return this.stream?.getOriginalStream()||this}}class MissingDataException extends n{constructor(t,e){super(`Missing data [${t}, ${e})`,"MissingDataException");this.begin=t;this.end=e}}async function fetchBinaryData(t){const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch file "${t}" with "${e.statusText}".`);return e.bytes()}const o=async function JBig2(t={}){var e=t,quit_=(t,e)=>{throw e},r=import.meta.url;try{new URL(".",r).href}catch{}0;console.log.bind(console);var n,s,a,i,o,c=console.error.bind(console),l=!1,u=!1;function updateMemoryViews(){var t=h.buffer;i=new Int8Array(t);new Int16Array(t);o=new Uint8Array(t);new Uint16Array(t);new Int32Array(t);new Uint32Array(t);new Float32Array(t);new Float64Array(t);new BigInt64Array(t);new BigUint64Array(t)}class ExitStatus{name="ExitStatus";constructor(t){this.message=`Program terminated with exit(${t})`;this.status=t}}var f,h,callRuntimeCallbacks=t=>{for(;t.length>0;)t.shift()(e)},m=[],addOnPostRun=t=>m.push(t),g=[],addOnPreRun=t=>g.push(t),d=!0,p=0,b={},handleException=t=>{if(t instanceof ExitStatus||"unwind"==t)return n;quit_(0,t)},keepRuntimeAlive=()=>d||p>0,_proc_exit=t=>{n=t;if(!keepRuntimeAlive()){e.onExit?.(t);l=!0}quit_(0,new ExitStatus(t))},_exit=(t,e)=>{n=t;_proc_exit(t)},callUserCallback=t=>{if(!l)try{return t()}catch(t){handleException(t)}finally{(()=>{if(!keepRuntimeAlive())try{_exit(n)}catch(t){handleException(t)}})()}},alignMemory=(t,e)=>Math.ceil(t/e)*e,growMemory=t=>{var e=(t-h.buffer.byteLength+65535)/65536|0;try{h.grow(e);updateMemoryViews();return 1}catch(t){}};e.noExitRuntime&&(d=e.noExitRuntime);e.print&&e.print;e.printErr&&(c=e.printErr);e.wasmBinary&&e.wasmBinary;e.arguments&&e.arguments;e.thisProgram&&e.thisProgram;if(e.preInit){"function"==typeof e.preInit&&(e.preInit=[e.preInit]);for(;e.preInit.length>0;)e.preInit.shift()()}e.writeArrayToMemory=(t,e)=>{i.set(t,e)};var y,w={e:()=>function abort(t){e.onAbort?.(t);c(t="Aborted("+t+")");l=!0;t+=". Build with -sASSERTIONS for more info.";var r=new WebAssembly.RuntimeError(t);a?.(r);throw r}(""),b:()=>{d=!1;p=0},c:(t,e)=>{if(b[t]){clearTimeout(b[t].id);delete b[t]}if(!e)return 0;var r=setTimeout(()=>{delete b[t];callUserCallback(()=>f(t,performance.now()))},e);b[t]={id:r,timeout_ms:e};return 0},g:function _createImageData(t){e.imageData=new Uint8Array(t)},d:t=>{var e=o.length,r=2147483648;if((t>>>=0)>r)return!1;for(var n=1;n<=4;n*=2){var s=e*(1+.2/n);s=Math.min(s,t+100663296);var a=Math.min(r,alignMemory(Math.max(t,s),65536));if(growMemory(a))return!0}return!1},a:_proc_exit,h:function _setImageData(t,r,n,s){if(n===r){e.imageData=new Uint8ClampedArray(o.subarray(t,t+n*s));return}const a=r*s,i=e.imageData=new Uint8ClampedArray(a);for(let e=t,s=0;s<a;e+=n,s+=r)i.set(o.subarray(e,e+r),s)},f:function _setLineData(t,r,n){e.imageData.set(o.subarray(t,t+r),n)}};y=await async function createWasm(){function receiveInstance(t,r){!function assignWasmExports(t){e._malloc=t.k;e._free=t.l;e._jbig2_decode=t.m;e._ccitt_decode=t.n;f=t.o;h=t.i;t.__indirect_function_table}(y=t.exports);updateMemoryViews();return y}var t=function getWasmImports(){return{a:w}}();return new Promise((r,n)=>{e.instantiateWasm(t,(t,e)=>{r(receiveInstance(t))})})}();!function run(){!function preRun(){if(e.preRun){"function"==typeof e.preRun&&(e.preRun=[e.preRun]);for(;e.preRun.length;)addOnPreRun(e.preRun.shift())}callRuntimeCallbacks(g)}();function doRun(){e.calledRun=!0;if(!l){!function initRuntime(){u=!0;y.j()}();s?.(e);e.onRuntimeInitialized?.();!function postRun(){if(e.postRun){"function"==typeof e.postRun&&(e.postRun=[e.postRun]);for(;e.postRun.length;)addOnPostRun(e.postRun.shift())}callRuntimeCallbacks(m)}()}}if(e.setStatus){e.setStatus("Running...");setTimeout(()=>{setTimeout(()=>e.setStatus(""),1);doRun()},1)}else doRun()}();return u?e:new Promise((t,e)=>{s=t;a=e})};class Jbig2Error extends n{constructor(t){super(t,"Jbig2Error")}}class JBig2CCITTFaxImage{static#s=null;static#a=null;static#i=null;static#o=!0;static#c=!0;static#l=null;static setOptions({handler:t,useWasm:e,useWorkerFetch:r,wasmUrl:n}){this.#o=e;this.#c=r;this.#l=n;r||(this.#a=t)}static async#u(t){const e=`${this.#l}jbig2_nowasm_fallback.js`;let r=null;try{r=(await import( /*webpackIgnore: true*/ /*@vite-ignore*/ e)).default()}catch(t){warn(`JBig2CCITTFaxImage#getJsModule: ${t}`)}t(r)}static async#f(t,e,r){const n="jbig2.wasm";try{this.#s||(this.#c?this.#s=await fetchBinaryData(`${this.#l}${n}`):this.#s=await this.#a.sendWithPromise("FetchBinaryData",{kind:"wasmUrl",filename:n}));return r((await WebAssembly.instantiate(this.#s,e)).instance)}catch(e){warn(`JBig2CCITTFaxImage#instantiateWasm: ${e}`);this.#u(t);return null}finally{this.#a=null}}static async decode(t,e,r,n,s){if(!this.#i){const{promise:t,resolve:e}=Promise.withResolvers(),r=[t];this.#o?r.push(o({warn,instantiateWasm:this.#f.bind(this,e)})):this.#u(e);this.#i=Promise.race(r)}const a=await this.#i;if(!a)throw new Jbig2Error("JBig2 failed to initialize");let i,c;try{const o=t.length;i=a._malloc(o);a.writeArrayToMemory(t,i);if(s)a._ccitt_decode(i,o,e,r,s.K,s.EndOfLine?1:0,s.EncodedByteAlign?1:0,s.BlackIs1?1:0,s.Columns,s.Rows);else{const t=n?n.length:0;if(t>0){c=a._malloc(t);a.writeArrayToMemory(n,c)}a._jbig2_decode(i,o,e,r,c,t)}if(!a.imageData)throw new Jbig2Error("Unknown error");const{imageData:l}=a;a.imageData=null;return l}finally{i&&a._free(i);c&&a._free(c)}}static cleanup(){this.#i=null}}function MathClamp(t,e,r){return Math.min(Math.max(t,e),r)}function isDefaultDecodeHelper(t,e){if(!Array.isArray(t))return!0;const r=t.length;if(r<e){warn("Decode map length is too short.");return!0}if(r>e){info("Truncating too long decode map.");t.length=e}return!1}class ColorSpace{static#h=new Uint8ClampedArray(3);constructor(t,e){this.name=t;this.numComps=e}getRgb(t,e,r=new Uint8ClampedArray(3)){this.getRgbItem(t,e,r,0);return r}getRgbHex(t,e){const r=this.getRgb(t,e,ColorSpace.#h);return Util.makeHexColor(r[0],r[1],r[2])}getRgbItem(t,e,r,n){unreachable("Should not call ColorSpace.getRgbItem")}getRgbBuffer(t,e,r,n,s,a,i){unreachable("Should not call ColorSpace.getRgbBuffer")}getOutputLength(t,e){unreachable("Should not call ColorSpace.getOutputLength")}isPassthrough(t){return!1}isDefaultDecode(t,e){return ColorSpace.isDefaultDecode(t,this.numComps)}fillRgb(t,e,r,n,s,a,i,o,c){const l=e*r;let u=null;const f=1<<i,h=r!==s||e!==n;if(this.isPassthrough(i))u=o;else if(1===this.numComps&&l>f&&"DeviceGray"!==this.name&&"DeviceRGB"!==this.name){const e=i<=8?new Uint8Array(f):new Uint16Array(f);for(let t=0;t<f;t++)e[t]=t;const r=new Uint8ClampedArray(3*f);this.getRgbBuffer(e,0,f,r,0,i,0);if(h){u=new Uint8Array(3*l);let t=0;for(let e=0;e<l;++e){const n=3*o[e];u[t++]=r[n];u[t++]=r[n+1];u[t++]=r[n+2]}}else{let e=0;for(let n=0;n<l;++n){const s=3*o[n];t[e++]=r[s];t[e++]=r[s+1];t[e++]=r[s+2];e+=c}}}else if(h){u=new Uint8ClampedArray(3*l);this.getRgbBuffer(o,0,l,u,0,i,0)}else this.getRgbBuffer(o,0,n*a,t,0,i,c);if(u)if(h)!function resizeRgbImage(t,e,r,n,s,a,i){i=1!==i?0:i;const o=r/s,c=n/a;let l,u=0;const f=new Uint16Array(s),h=3*r;for(let t=0;t<s;t++)f[t]=3*Math.floor(t*o);for(let r=0;r<a;r++){const n=Math.floor(r*c)*h;for(let r=0;r<s;r++){l=n+f[r];e[u++]=t[l++];e[u++]=t[l++];e[u++]=t[l++];u+=i}}}(u,t,e,r,n,s,c);else{let e=0,r=0;for(let s=0,i=n*a;s<i;s++){t[e++]=u[r++];t[e++]=u[r++];t[e++]=u[r++];e+=c}}}get usesZeroToOneRange(){return shadow(this,"usesZeroToOneRange",!0)}static isDefaultDecode(t,e){if(isDefaultDecodeHelper(t,2*e))return!0;for(let e=0,r=t.length;e<r;e+=2)if(0!==t[e]||1!==t[e+1])return!1;return!0}}class AlternateCS extends ColorSpace{constructor(t,e,r){super("Alternate",t);this.base=e;this.tintFn=r;this.tmpBuf=new Float32Array(e.numComps)}getRgbItem(t,e,r,n){const s=this.tmpBuf;this.tintFn(t,e,s,0);this.base.getRgbItem(s,0,r,n)}getRgbBuffer(t,e,r,n,s,a,i){const o=this.tintFn,c=this.base,l=1/((1<<a)-1),u=c.numComps,f=c.usesZeroToOneRange,h=(c.isPassthrough(8)||!f)&&0===i;let m=h?s:0;const g=h?n:new Uint8ClampedArray(u*r),d=this.numComps,p=new Float32Array(d),b=new Float32Array(u);let y,w;for(y=0;y<r;y++){for(w=0;w<d;w++)p[w]=t[e++]*l;o(p,0,b,0);if(f)for(w=0;w<u;w++)g[m++]=255*b[w];else{c.getRgbItem(b,0,g,m);m+=u}}h||c.getRgbBuffer(g,0,r,n,s,8,i)}getOutputLength(t,e){return this.base.getOutputLength(t*this.base.numComps/this.numComps,e)}}class PatternCS extends ColorSpace{constructor(t){super("Pattern",null);this.base=t}isDefaultDecode(t,e){unreachable("Should not call PatternCS.isDefaultDecode")}}class IndexedCS extends ColorSpace{constructor(t,e,r){super("Indexed",1);this.base=t;this.highVal=e;const n=t.numComps*(e+1);this.lookup=new Uint8Array(n);if(r instanceof BaseStream){const t=r.getBytes(n);this.lookup.set(t)}else{if("string"!=typeof r)throw new FormatError(`IndexedCS - unrecognized lookup table: ${r}`);for(let t=0;t<n;++t)this.lookup[t]=255&r.charCodeAt(t)}}getRgbItem(t,e,r,n){const{base:s,highVal:a,lookup:i}=this,o=MathClamp(Math.round(t[e]),0,a)*s.numComps;s.getRgbBuffer(i,o,1,r,n,8,0)}getRgbBuffer(t,e,r,n,s,a,i){const{base:o,highVal:c,lookup:l}=this,{numComps:u}=o,f=o.getOutputLength(u,i);for(let a=0;a<r;++a){const r=MathClamp(Math.round(t[e++]),0,c)*u;o.getRgbBuffer(l,r,1,n,s,8,i);s+=f}}getOutputLength(t,e){return this.base.getOutputLength(t*this.base.numComps,e)}isDefaultDecode(t,e){if(isDefaultDecodeHelper(t,2))return!0;if(!Number.isInteger(e)||e<1){warn("Bits per component is not correct");return!0}return 0===t[0]&&t[1]===(1<<e)-1}}class DeviceGrayCS extends ColorSpace{constructor(){super("DeviceGray",1)}getRgbItem(t,e,r,n){const s=255*t[e];r[n]=r[n+1]=r[n+2]=s}getRgbBuffer(t,e,r,n,s,a,i){const o=255/((1<<a)-1);let c=e,l=s;for(let e=0;e<r;++e){const e=o*t[c++];n[l++]=e;n[l++]=e;n[l++]=e;l+=i}}getOutputLength(t,e){return t*(3+e)}}class DeviceRgbCS extends ColorSpace{constructor(){super("DeviceRGB",3)}getRgbItem(t,e,r,n){r[n]=255*t[e];r[n+1]=255*t[e+1];r[n+2]=255*t[e+2]}getRgbBuffer(t,e,r,n,s,a,i){if(8===a&&0===i){n.set(t.subarray(e,e+3*r),s);return}const o=255/((1<<a)-1);let c=e,l=s;for(let e=0;e<r;++e){n[l++]=o*t[c++];n[l++]=o*t[c++];n[l++]=o*t[c++];l+=i}}getOutputLength(t,e){return t*(3+e)/3|0}isPassthrough(t){return 8===t}}class DeviceRgbaCS extends ColorSpace{constructor(){super("DeviceRGBA",4)}getOutputLength(t,e){return 4*t}isPassthrough(t){return 8===t}fillRgb(t,e,r,n,s,a,i,o,c){r!==s||e!==n?function resizeRgbaImage(t,e,r,n,s,a,i){const o=r/s,c=n/a;let l=0;const u=new Uint16Array(s);if(1===i){for(let t=0;t<s;t++)u[t]=Math.floor(t*o);const n=new Uint32Array(t.buffer),i=new Uint32Array(e.buffer),f=FeatureTest.isLittleEndian?16777215:4294967040;for(let t=0;t<a;t++){const e=n.subarray(Math.floor(t*c)*r);for(let t=0;t<s;t++)i[l++]|=e[u[t]]&f}}else{const n=4,i=r*n;for(let t=0;t<s;t++)u[t]=Math.floor(t*o)*n;for(let r=0;r<a;r++){const n=t.subarray(Math.floor(r*c)*i);for(let t=0;t<s;t++){const r=u[t];e[l++]=n[r];e[l++]=n[r+1];e[l++]=n[r+2]}}}}(o,t,e,r,n,s,c):function copyRgbaImage(t,e,r){if(1===r){const r=new Uint32Array(t.buffer),n=new Uint32Array(e.buffer),s=FeatureTest.isLittleEndian?16777215:4294967040;for(let t=0,e=r.length;t<e;t++)n[t]|=r[t]&s}else{let r=0;for(let n=0,s=t.length;n<s;n+=4){e[r++]=t[n];e[r++]=t[n+1];e[r++]=t[n+2]}}}(o,t,c)}}class DeviceCmykCS extends ColorSpace{constructor(){super("DeviceCMYK",4)}#m(t,e,r,n,s){const a=t[e]*r,i=t[e+1]*r,o=t[e+2]*r,c=t[e+3]*r;n[s]=255+a*(-4.387332384609988*a+54.48615194189176*i+18.82290502165302*o+212.25662451639585*c-285.2331026137004)+i*(1.7149763477362134*i-5.6096736904047315*o+-17.873870861415444*c-5.497006427196366)+o*(-2.5217340131683033*o-21.248923337353073*c+17.5119270841813)+c*(-21.86122147463605*c-189.48180835922747);n[s+1]=255+a*(8.841041422036149*a+60.118027045597366*i+6.871425592049007*o+31.159100130055922*c-79.2970844816548)+i*(-15.310361306967817*i+17.575251261109482*o+131.35250912493976*c-190.9453302588951)+o*(4.444339102852739*o+9.8632861493405*c-24.86741582555878)+c*(-20.737325471181034*c-187.80453709719578);n[s+2]=255+a*(.8842522430003296*a+8.078677503112928*i+30.89978309703729*o-.23883238689178934*c-14.183576799673286)+i*(10.49593273432072*i+63.02378494754052*o+50.606957656360734*c-112.23884253719248)+o*(.03296041114873217*o+115.60384449646641*c-193.58209356861505)+c*(-22.33816807309886*c-180.12613974708367)}getRgbItem(t,e,r,n){this.#m(t,e,1,r,n)}getRgbBuffer(t,e,r,n,s,a,i){const o=1/((1<<a)-1);for(let a=0;a<r;a++){this.#m(t,e,o,n,s);e+=4;s+=3+i}}getOutputLength(t,e){return t/4*(3+e)|0}}class CalGrayCS extends ColorSpace{constructor(t,e,r){super("CalGray",1);if(!t)throw new FormatError("WhitePoint missing - required for color space CalGray");[this.XW,this.YW,this.ZW]=t;[this.XB,this.YB,this.ZB]=e||[0,0,0];this.G=r||1;if(this.XW<0||this.ZW<0||1!==this.YW)throw new FormatError(`Invalid WhitePoint components for ${this.name}, no fallback available`);if(this.XB<0||this.YB<0||this.ZB<0){info(`Invalid BlackPoint for ${this.name}, falling back to default.`);this.XB=this.YB=this.ZB=0}0===this.XB&&0===this.YB&&0===this.ZB||warn(`${this.name}, BlackPoint: XB: ${this.XB}, YB: ${this.YB}, ZB: ${this.ZB}, only default values are supported.`);if(this.G<1){info(`Invalid Gamma: ${this.G} for ${this.name}, falling back to default.`);this.G=1}}#m(t,e,r,n,s){const a=(t[e]*s)**this.G,i=this.YW*a,o=Math.max(295.8*i**.3333333333333333-40.8,0);r[n]=o;r[n+1]=o;r[n+2]=o}getRgbItem(t,e,r,n){this.#m(t,e,r,n,1)}getRgbBuffer(t,e,r,n,s,a,i){const o=1/((1<<a)-1);for(let a=0;a<r;++a){this.#m(t,e,n,s,o);e+=1;s+=3+i}}getOutputLength(t,e){return t*(3+e)}}class CalRGBCS extends ColorSpace{static#g=new Float32Array([.8951,.2664,-.1614,-.7502,1.7135,.0367,.0389,-.0685,1.0296]);static#d=new Float32Array([.9869929,-.1470543,.1599627,.4323053,.5183603,.0492912,-.0085287,.0400428,.9684867]);static#p=new Float32Array([3.2404542,-1.5371385,-.4985314,-.969266,1.8760108,.041556,.0556434,-.2040259,1.0572252]);static#b=new Float32Array([1,1,1]);static#y=new Float32Array(3);static#w=new Float32Array(3);static#C=new Float32Array(3);static#_=(24/116)**3/8;constructor(t,e,r,n){super("CalRGB",3);if(!t)throw new FormatError("WhitePoint missing - required for color space CalRGB");const[s,a,i]=this.whitePoint=t,[o,c,l]=this.blackPoint=e||new Float32Array(3);[this.GR,this.GG,this.GB]=r||new Float32Array([1,1,1]);[this.MXA,this.MYA,this.MZA,this.MXB,this.MYB,this.MZB,this.MXC,this.MYC,this.MZC]=n||new Float32Array([1,0,0,0,1,0,0,0,1]);if(s<0||i<0||1!==a)throw new FormatError(`Invalid WhitePoint components for ${this.name}, no fallback available`);if(o<0||c<0||l<0){info(`Invalid BlackPoint for ${this.name} [${o}, ${c}, ${l}], falling back to default.`);this.blackPoint=new Float32Array(3)}if(this.GR<0||this.GG<0||this.GB<0){info(`Invalid Gamma [${this.GR}, ${this.GG}, ${this.GB}] for ${this.name}, falling back to default.`);this.GR=this.GG=this.GB=1}}#R(t,e,r){r[0]=t[0]*e[0]+t[1]*e[1]+t[2]*e[2];r[1]=t[3]*e[0]+t[4]*e[1]+t[5]*e[2];r[2]=t[6]*e[0]+t[7]*e[1]+t[8]*e[2]}#A(t,e,r){r[0]=1*e[0]/t[0];r[1]=1*e[1]/t[1];r[2]=1*e[2]/t[2]}#B(t,e,r){r[0]=.95047*e[0]/t[0];r[1]=1*e[1]/t[1];r[2]=1.08883*e[2]/t[2]}#x(t){return t<=.0031308?MathClamp(12.92*t,0,1):t>=.99554525?1:MathClamp(1.055*t**(1/2.4)-.055,0,1)}#S(t){return t<0?-this.#S(-t):t>8?((t+16)/116)**3:t*CalRGBCS.#_}#v(t,e,r){if(0===t[0]&&0===t[1]&&0===t[2]){r[0]=e[0];r[1]=e[1];r[2]=e[2];return}const n=this.#S(0),s=(1-n)/(1-this.#S(t[0])),a=1-s,i=(1-n)/(1-this.#S(t[1])),o=1-i,c=(1-n)/(1-this.#S(t[2])),l=1-c;r[0]=e[0]*s+a;r[1]=e[1]*i+o;r[2]=e[2]*c+l}#M(t,e,r){if(1===t[0]&&1===t[2]){r[0]=e[0];r[1]=e[1];r[2]=e[2];return}const n=r;this.#R(CalRGBCS.#g,e,n);const s=CalRGBCS.#y;this.#A(t,n,s);this.#R(CalRGBCS.#d,s,r)}#I(t,e,r){const n=r;this.#R(CalRGBCS.#g,e,n);const s=CalRGBCS.#y;this.#B(t,n,s);this.#R(CalRGBCS.#d,s,r)}#m(t,e,r,n,s){const a=MathClamp(t[e]*s,0,1),i=MathClamp(t[e+1]*s,0,1),o=MathClamp(t[e+2]*s,0,1),c=1===a?1:a**this.GR,l=1===i?1:i**this.GG,u=1===o?1:o**this.GB,f=this.MXA*c+this.MXB*l+this.MXC*u,h=this.MYA*c+this.MYB*l+this.MYC*u,m=this.MZA*c+this.MZB*l+this.MZC*u,g=CalRGBCS.#w;g[0]=f;g[1]=h;g[2]=m;const d=CalRGBCS.#C;this.#M(this.whitePoint,g,d);const p=CalRGBCS.#w;this.#v(this.blackPoint,d,p);const b=CalRGBCS.#C;this.#I(CalRGBCS.#b,p,b);const y=CalRGBCS.#w;this.#R(CalRGBCS.#p,b,y);r[n]=255*this.#x(y[0]);r[n+1]=255*this.#x(y[1]);r[n+2]=255*this.#x(y[2])}getRgbItem(t,e,r,n){this.#m(t,e,r,n,1)}getRgbBuffer(t,e,r,n,s,a,i){const o=1/((1<<a)-1);for(let a=0;a<r;++a){this.#m(t,e,n,s,o);e+=3;s+=3+i}}getOutputLength(t,e){return t*(3+e)/3|0}}class LabCS extends ColorSpace{constructor(t,e,r){super("Lab",3);if(!t)throw new FormatError("WhitePoint missing - required for color space Lab");[this.XW,this.YW,this.ZW]=t;[this.amin,this.amax,this.bmin,this.bmax]=r||[-100,100,-100,100];[this.XB,this.YB,this.ZB]=e||[0,0,0];if(this.XW<0||this.ZW<0||1!==this.YW)throw new FormatError("Invalid WhitePoint components, no fallback available");if(this.XB<0||this.YB<0||this.ZB<0){info("Invalid BlackPoint, falling back to default");this.XB=this.YB=this.ZB=0}if(this.amin>this.amax||this.bmin>this.bmax){info("Invalid Range, falling back to defaults");this.amin=-100;this.amax=100;this.bmin=-100;this.bmax=100}}#k(t){return t>=6/29?t**3:108/841*(t-4/29)}#D(t,e,r,n){return r+t*(n-r)/e}#m(t,e,r,n,s){let a=t[e],i=t[e+1],o=t[e+2];if(!1!==r){a=this.#D(a,r,0,100);i=this.#D(i,r,this.amin,this.amax);o=this.#D(o,r,this.bmin,this.bmax)}i>this.amax?i=this.amax:i<this.amin&&(i=this.amin);o>this.bmax?o=this.bmax:o<this.bmin&&(o=this.bmin);const c=(a+16)/116,l=c+i/500,u=c-o/200,f=this.XW*this.#k(l),h=this.YW*this.#k(c),m=this.ZW*this.#k(u);let g,d,p;if(this.ZW<1){g=3.1339*f+-1.617*h+-.4906*m;d=-.9785*f+1.916*h+.0333*m;p=.072*f+-.229*h+1.4057*m}else{g=3.2406*f+-1.5372*h+-.4986*m;d=-.9689*f+1.8758*h+.0415*m;p=.0557*f+-.204*h+1.057*m}n[s]=255*Math.sqrt(g);n[s+1]=255*Math.sqrt(d);n[s+2]=255*Math.sqrt(p)}getRgbItem(t,e,r,n){this.#m(t,e,!1,r,n)}getRgbBuffer(t,e,r,n,s,a,i){const o=(1<<a)-1;for(let a=0;a<r;a++){this.#m(t,e,o,n,s);e+=3;s+=3+i}}getOutputLength(t,e){return t*(3+e)/3|0}isDefaultDecode(t,e){return!0}get usesZeroToOneRange(){return shadow(this,"usesZeroToOneRange",!1)}}class QCMS{static#E=null;static _memory=null;static _mustAddAlpha=!1;static _destBuffer=null;static _destOffset=0;static _destLength=0;static _cssColor="";static _makeHexColor=null;static get _memoryArray(){const t=this.#E;return t?.byteLength?t:this.#E=new Uint8Array(this._memory.buffer)}}const c=Object.freeze({RGB8:0,0:"RGB8",RGBA8:1,1:"RGBA8",BGRA8:2,2:"BGRA8",Gray8:3,3:"Gray8",GrayA8:4,4:"GrayA8",CMYK:5,5:"CMYK"}),l=Object.freeze({Perceptual:0,0:"Perceptual",RelativeColorimetric:1,1:"RelativeColorimetric",Saturation:2,2:"Saturation",AbsoluteColorimetric:3,3:"AbsoluteColorimetric"});function __wbg_get_imports(){return{__proto__:null,"./qcms_bg.js":{__proto__:null,__wbg___wbindgen_throw_6b64449b9b9ed33c:function(t,e){throw new Error(function getStringFromWasm0(t,e){return function decodeText(t,e){m+=e;if(m>=h){f=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});f.decode();m=e}return f.decode(getUint8ArrayMemory0().subarray(t,t+e))}(t>>>=0,e)}(t,e))},__wbg_copy_result_0d15f3bf9d9012ae:function(t,e){!function copy_result(t,e){const{_mustAddAlpha:r,_destBuffer:n,_destOffset:s,_destLength:a,_memoryArray:i}=QCMS;if(e!==a)if(r)for(let r=t,a=t+e,o=s;r<a;r+=3,o+=4){n[o]=i[r];n[o+1]=i[r+1];n[o+2]=i[r+2];n[o+3]=255}else for(let r=t,a=t+e,o=s;r<a;r+=3,o+=4){n[o]=i[r];n[o+1]=i[r+1];n[o+2]=i[r+2]}else n.set(i.subarray(t,t+e),s)}(t>>>0,e>>>0)},__wbg_copy_rgb_0106d9d9464fce43:function(t){!function copy_rgb(t){const{_destBuffer:e,_destOffset:r,_memoryArray:n}=QCMS;e[r]=n[t];e[r+1]=n[t+1];e[r+2]=n[t+2]}(t>>>0)},__wbg_make_cssRGB_8e24b34f71f5363e:function(t){!function make_cssRGB(t){const{_memoryArray:e}=QCMS;QCMS._cssColor=QCMS._makeHexColor(e[t],e[t+1],e[t+2])}(t>>>0)},__wbindgen_init_externref_table:function(){const t=d.__wbindgen_externrefs,e=t.grow(4);t.set(0,void 0);t.set(e+0,void 0);t.set(e+1,null);t.set(e+2,!0);t.set(e+3,!1)}}}}let u=null;function getUint8ArrayMemory0(){null!==u&&0!==u.byteLength||(u=new Uint8Array(d.memory.buffer));return u}function passArray8ToWasm0(t,e){const r=e(1*t.length,1)>>>0;getUint8ArrayMemory0().set(t,r/1);p=t.length;return r}let f=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});f.decode();const h=2146435072;let m=0;let g,d,p=0;function __wbg_finalize_init(t,e){d=t.exports;g=e;u=null;d.__wbindgen_start();return d}function fetchSync(t){const e=new XMLHttpRequest;e.open("GET",t,!1);e.responseType="arraybuffer";e.send(null);return e.response}class IccColorSpace extends ColorSpace{#T;#P;static#o=!0;static#l=null;static#U=null;constructor(t,e,r){if(!IccColorSpace.isUsable)throw new Error("No ICC color space support");super(e,r);let n;switch(r){case 1:n=c.Gray8;this.#P=(t,e,r)=>function qcms_convert_one(t,e,r){d.qcms_convert_one(t,e,r)}(this.#T,255*t[e],r);break;case 3:n=c.RGB8;this.#P=(t,e,r)=>function qcms_convert_three(t,e,r,n,s){d.qcms_convert_three(t,e,r,n,s)}(this.#T,255*t[e],255*t[e+1],255*t[e+2],r);break;case 4:n=c.CMYK;this.#P=(t,e,r)=>function qcms_convert_four(t,e,r,n,s,a){d.qcms_convert_four(t,e,r,n,s,a)}(this.#T,255*t[e],255*t[e+1],255*t[e+2],255*t[e+3],r);break;default:throw new Error(`Unsupported number of components: ${r}`)}this.#T=function qcms_transformer_from_memory(t,e,r){const n=passArray8ToWasm0(t,d.__wbindgen_malloc),s=p;return d.qcms_transformer_from_memory(n,s,e,r)>>>0}(t,n,l.Perceptual);if(!this.#T)throw new Error("Failed to create ICC color space");IccColorSpace.#U||=new FinalizationRegistry(t=>{!function qcms_drop_transformer(t){d.qcms_drop_transformer(t)}(t)});IccColorSpace.#U.register(this,this.#T)}getRgbHex(t,e){this.#P(t,e,!0);return QCMS._cssColor}getRgbItem(t,e,r,n){QCMS._destBuffer=r;QCMS._destOffset=n;QCMS._destLength=3;this.#P(t,e,!1);QCMS._destBuffer=null}getRgbBuffer(t,e,r,n,s,a,i){t=t.subarray(e,e+r*this.numComps);if(8!==a){const e=255/((1<<a)-1);for(let r=0,n=t.length;r<n;r++)t[r]*=e}QCMS._mustAddAlpha=i&&n.buffer===t.buffer;QCMS._destBuffer=n;QCMS._destOffset=s;QCMS._destLength=r*(3+i);!function qcms_convert_array(t,e){const r=passArray8ToWasm0(e,d.__wbindgen_malloc),n=p;d.qcms_convert_array(t,r,n)}(this.#T,t);QCMS._mustAddAlpha=!1;QCMS._destBuffer=null}getOutputLength(t,e){return t/this.numComps*(3+e)|0}static setOptions({useWasm:t,useWorkerFetch:e,wasmUrl:r}){if(e){this.#o=t;this.#l=r}else this.#o=!1}static get isUsable(){let t=!1;if(this.#o)if(this.#l)try{this._module=function initSync(t){if(void 0!==d)return d;void 0!==t&&(Object.getPrototypeOf(t)===Object.prototype?({module:t}=t):console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));const e=__wbg_get_imports();t instanceof WebAssembly.Module||(t=new WebAssembly.Module(t));return __wbg_finalize_init(new WebAssembly.Instance(t,e),t)}({module:fetchSync(`${this.#l}qcms_bg.wasm`)});t=!!this._module;QCMS._memory=this._module.memory;QCMS._makeHexColor=Util.makeHexColor.bind(Util)}catch(t){warn(`ICCBased color space: "${t}".`)}else warn("No ICC color space support due to missing `wasmUrl` API option");return shadow(this,"isUsable",t)}}class CmykICCBasedCS extends IccColorSpace{static#F;constructor(){super(new Uint8Array(fetchSync(`${CmykICCBasedCS.#F}CGATS001Compat-v2-micro.icc`)),"DeviceCMYK",4)}static setOptions({iccUrl:t}){this.#F=t}static get isUsable(){let t=!1;IccColorSpace.isUsable&&(this.#F?t=!0:warn("No CMYK ICC profile support due to missing `iccUrl` API option"));return shadow(this,"isUsable",t)}}class ColorSpaceUtils{static parse({cs:t,xref:e,resources:r=null,pdfFunctionFactory:n,globalColorSpaceCache:s,localColorSpaceCache:a,asyncIfNotCached:i=!1}){const o={xref:e,resources:r,pdfFunctionFactory:n,globalColorSpaceCache:s,localColorSpaceCache:a};let c,l,u;if(t instanceof Ref){l=t;const r=s.getByRef(l)||a.getByRef(l);if(r)return r;t=e.fetch(t)}if(t instanceof Name){c=t.name;const e=a.getByName(c);if(e)return e}try{u=this.#G(t,o)}catch(t){if(i&&!(t instanceof MissingDataException))return Promise.reject(t);throw t}if(c||l){a.set(c,l,u);l&&s.set(null,l,u)}return i?Promise.resolve(u):u}static#L(t,e){const{globalColorSpaceCache:r}=e;let n;if(t instanceof Ref){n=t;const e=r.getByRef(n);if(e)return e}const s=this.#G(t,e);n&&r.set(null,n,s);return s}static#G(t,e){const{xref:r,resources:n,pdfFunctionFactory:s,globalColorSpaceCache:a}=e;if((t=r.fetchIfRef(t))instanceof Name)switch(t.name){case"G":case"DeviceGray":return this.gray;case"RGB":case"DeviceRGB":return this.rgb;case"DeviceRGBA":return this.rgba;case"CMYK":case"DeviceCMYK":return this.cmyk;case"Pattern":return new PatternCS(null);default:if(n instanceof Dict){const r=n.get("ColorSpace");if(r instanceof Dict){const n=r.get(t.name);if(n){if(n instanceof Name)return this.#G(n,e);t=n;break}}}warn(`Unrecognized ColorSpace: ${t.name}`);return this.gray}if(Array.isArray(t)){const n=r.fetchIfRef(t[0]).name;let i,o,c,l,u,f;switch(n){case"G":case"DeviceGray":return this.gray;case"RGB":case"DeviceRGB":return this.rgb;case"CMYK":case"DeviceCMYK":return this.cmyk;case"CalGray":i=r.fetchIfRef(t[1]);l=i.getArray("WhitePoint");u=i.getArray("BlackPoint");f=i.get("Gamma");return new CalGrayCS(l,u,f);case"CalRGB":i=r.fetchIfRef(t[1]);l=i.getArray("WhitePoint");u=i.getArray("BlackPoint");f=i.getArray("Gamma");const h=i.getArray("Matrix");return new CalRGBCS(l,u,f,h);case"ICCBased":const m=t[1]instanceof Ref;if(m){const e=a.getByRef(t[1]);if(e)return e}const g=r.fetchIfRef(t[1]),d=g.dict;o=d.get("N");if(IccColorSpace.isUsable)try{const e=new IccColorSpace(g.getBytes(),"ICCBased",o);m&&a.set(null,t[1],e);return e}catch(e){if(e instanceof MissingDataException)throw e;warn(`ICCBased color space (${t[1]}): "${e}".`)}const p=d.getRaw("Alternate");if(p){const t=this.#L(p,e);if(t.numComps===o)return t;warn("ICCBased color space: Ignoring incorrect /Alternate entry.")}if(1===o)return this.gray;if(3===o)return this.rgb;if(4===o)return this.cmyk;break;case"Pattern":c=t[1]||null;c&&(c=this.#L(c,e));return new PatternCS(c);case"I":case"Indexed":c=this.#L(t[1],e);const b=MathClamp(r.fetchIfRef(t[2]),0,255),y=r.fetchIfRef(t[3]);return new IndexedCS(c,b,y);case"Separation":case"DeviceN":const w=r.fetchIfRef(t[1]);o=Array.isArray(w)?w.length:1;c=this.#L(t[2],e);const C=s.create(t[3]);return new AlternateCS(o,c,C);case"Lab":i=r.fetchIfRef(t[1]);l=i.getArray("WhitePoint");u=i.getArray("BlackPoint");const _=i.getArray("Range");return new LabCS(l,u,_);default:warn(`Unimplemented ColorSpace object: ${n}`);return this.gray}}warn(`Unrecognized ColorSpace object: ${t}`);return this.gray}static get gray(){return shadow(this,"gray",new DeviceGrayCS)}static get rgb(){return shadow(this,"rgb",new DeviceRgbCS)}static get rgba(){return shadow(this,"rgba",new DeviceRgbaCS)}static get cmyk(){if(CmykICCBasedCS.isUsable)try{return shadow(this,"cmyk",new CmykICCBasedCS)}catch{warn("CMYK fallback: DeviceCMYK")}return shadow(this,"cmyk",new DeviceCmykCS)}}class JpegError extends n{constructor(t){super(t,"JpegError")}}class DNLMarkerError extends n{constructor(t,e){super(t,"DNLMarkerError");this.scanLines=e}}class EOIMarkerError extends n{constructor(t){super(t,"EOIMarkerError")}}const b=new Uint8Array([0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63]),y=4017,w=799,C=3406,_=2276,R=1567,A=3784,B=5793,x=2896;function buildHuffmanTable(t,e){let r,n,s=0,a=16;for(;a>0&&!t[a-1];)a--;const i=[{children:[],index:0}];let o,c=i[0];for(r=0;r<a;r++){for(n=0;n<t[r];n++){c=i.pop();c.children[c.index]=e[s];for(;c.index>0;)c=i.pop();c.index++;i.push(c);for(;i.length<=r;){i.push(o={children:[],index:0});c.children[c.index]=o.children;c=o}s++}if(r+1<a){i.push(o={children:[],index:0});c.children[c.index]=o.children;c=o}}return i[0].children}function getBlockBufferOffset(t,e,r){return 64*((t.blocksPerLine+1)*e+r)}function decodeScan(t,e,r,n,s,a,i,o,c,l,u=!1){const f=n.mcusPerLine,h=n.progressive,m=r;let g=0,d=0;function readBit(){if(d>0){d--;return g>>d&1}g=t[r++];if(255===g){const s=t[r++];if(s){if(220===s&&u){r+=2;const t=e.getUint16(r);r+=2;if(t>0&&t!==n.scanLines)throw new DNLMarkerError("Found DNL marker (0xFFDC) while parsing scan data",t)}else if(217===s){if(u){const t=C*(8===n.precision?8:0);if(t>0&&Math.round(n.scanLines/t)>=5)throw new DNLMarkerError("Found EOI marker (0xFFD9) while parsing scan data, possibly caused by incorrect `scanLines` parameter",t)}throw new EOIMarkerError("Found EOI marker (0xFFD9) while parsing scan data")}throw new JpegError(`unexpected marker ${(g<<8|s).toString(16)}`)}}d=7;return g>>>7}function decodeHuffman(t){let e=t;for(;;){e=e[readBit()];switch(typeof e){case"number":return e;case"object":continue}throw new JpegError("invalid huffman sequence")}}function receive(t){let e=0;for(;t>0;){e=e<<1|readBit();t--}return e}function receiveAndExtend(t){if(1===t)return 1===readBit()?1:-1;const e=receive(t);return e>=1<<t-1?e:e+(-1<<t)+1}let p=0;let y,w=0;let C=0;function decodeMcu(t,e,r,n,s){const a=r%f;C=(r/f|0)*t.v+n;const i=a*t.h+s;e(t,getBlockBufferOffset(t,C,i))}function decodeBlock(t,e,r){C=r/t.blocksPerLine|0;const n=r%t.blocksPerLine;e(t,getBlockBufferOffset(t,C,n))}const _=s.length;let R,A,B,x,S,v;v=h?0===i?0===c?function decodeDCFirst(t,e){const r=decodeHuffman(t.huffmanTableDC),n=0===r?0:receiveAndExtend(r)<<l;t.blockData[e]=t.pred+=n}:function decodeDCSuccessive(t,e){t.blockData[e]|=readBit()<<l}:0===c?function decodeACFirst(t,e){if(p>0){p--;return}let r=i;const n=o;for(;r<=n;){const n=decodeHuffman(t.huffmanTableAC),s=15&n,a=n>>4;if(0===s){if(a<15){p=receive(a)+(1<<a)-1;break}r+=16;continue}r+=a;const i=b[r];t.blockData[e+i]=receiveAndExtend(s)*(1<<l);r++}}:function decodeACSuccessive(t,e){let r=i;const n=o;let s,a,c=0;for(;r<=n;){const n=e+b[r],i=t.blockData[n]<0?-1:1;switch(w){case 0:a=decodeHuffman(t.huffmanTableAC);s=15&a;c=a>>4;if(0===s)if(c<15){p=receive(c)+(1<<c);w=4}else{c=16;w=1}else{if(1!==s)throw new JpegError("invalid ACn encoding");y=receiveAndExtend(s);w=c?2:3}continue;case 1:case 2:if(t.blockData[n])t.blockData[n]+=i*(readBit()<<l);else{c--;0===c&&(w=2===w?3:0)}break;case 3:if(t.blockData[n])t.blockData[n]+=i*(readBit()<<l);else{t.blockData[n]=y<<l;w=0}break;case 4:t.blockData[n]&&(t.blockData[n]+=i*(readBit()<<l))}r++}if(4===w){p--;0===p&&(w=0)}}:function decodeBaseline(t,e){const r=decodeHuffman(t.huffmanTableDC),n=0===r?0:receiveAndExtend(r);t.blockData[e]=t.pred+=n;let s=1;for(;s<64;){const r=decodeHuffman(t.huffmanTableAC),n=15&r,a=r>>4;if(0===n){if(a<15)break;s+=16;continue}s+=a;const i=b[s];t.blockData[e+i]=receiveAndExtend(n);s++}};let M,I=0;const k=1===_?s[0].blocksPerLine*s[0].blocksPerColumn:f*n.mcusPerColumn;let D,E;for(;I<=k;){const n=a?Math.min(k-I,a):k;if(n>0){for(A=0;A<_;A++)s[A].pred=0;p=0;if(1===_){R=s[0];for(S=0;S<n;S++){decodeBlock(R,v,I);I++}}else for(S=0;S<n;S++){for(A=0;A<_;A++){R=s[A];D=R.h;E=R.v;for(B=0;B<E;B++)for(x=0;x<D;x++)decodeMcu(R,v,I,B,x)}I++}}d=0;M=findNextFileMarker(t,e,r);if(!M)break;if(M.invalid){warn(`decodeScan - ${n>0?"unexpected":"excessive"} MCU data, current marker is: ${M.invalid}`);r=M.offset}if(!(M.marker>=65488&&M.marker<=65495))break;r+=2}return r-m}function quantizeAndInverse(t,e,r){const n=t.quantizationTable,s=t.blockData;let a,i,o,c,l,u,f,h,m,g,d,p,b,S,v,M,I;if(!n)throw new JpegError("missing required Quantization Table.");for(let t=0;t<64;t+=8){m=s[e+t];g=s[e+t+1];d=s[e+t+2];p=s[e+t+3];b=s[e+t+4];S=s[e+t+5];v=s[e+t+6];M=s[e+t+7];m*=n[t];if(0!==(g|d|p|b|S|v|M)){g*=n[t+1];d*=n[t+2];p*=n[t+3];b*=n[t+4];S*=n[t+5];v*=n[t+6];M*=n[t+7];a=B*m+128>>8;i=B*b+128>>8;o=d;c=v;l=x*(g-M)+128>>8;h=x*(g+M)+128>>8;u=p<<4;f=S<<4;a=a+i+1>>1;i=a-i;I=o*A+c*R+128>>8;o=o*R-c*A+128>>8;c=I;l=l+f+1>>1;f=l-f;h=h+u+1>>1;u=h-u;a=a+c+1>>1;c=a-c;i=i+o+1>>1;o=i-o;I=l*_+h*C+2048>>12;l=l*C-h*_+2048>>12;h=I;I=u*w+f*y+2048>>12;u=u*y-f*w+2048>>12;f=I;r[t]=a+h;r[t+7]=a-h;r[t+1]=i+f;r[t+6]=i-f;r[t+2]=o+u;r[t+5]=o-u;r[t+3]=c+l;r[t+4]=c-l}else{I=B*m+512>>10;r[t]=I;r[t+1]=I;r[t+2]=I;r[t+3]=I;r[t+4]=I;r[t+5]=I;r[t+6]=I;r[t+7]=I}}for(let t=0;t<8;++t){m=r[t];g=r[t+8];d=r[t+16];p=r[t+24];b=r[t+32];S=r[t+40];v=r[t+48];M=r[t+56];if(0!==(g|d|p|b|S|v|M)){a=B*m+2048>>12;i=B*b+2048>>12;o=d;c=v;l=x*(g-M)+2048>>12;h=x*(g+M)+2048>>12;u=p;f=S;a=4112+(a+i+1>>1);i=a-i;I=o*A+c*R+2048>>12;o=o*R-c*A+2048>>12;c=I;l=l+f+1>>1;f=l-f;h=h+u+1>>1;u=h-u;a=a+c+1>>1;c=a-c;i=i+o+1>>1;o=i-o;I=l*_+h*C+2048>>12;l=l*C-h*_+2048>>12;h=I;I=u*w+f*y+2048>>12;u=u*y-f*w+2048>>12;f=I;m=a+h;M=a-h;g=i+f;v=i-f;d=o+u;S=o-u;p=c+l;b=c-l;m<16?m=0:m>=4080?m=255:m>>=4;g<16?g=0:g>=4080?g=255:g>>=4;d<16?d=0:d>=4080?d=255:d>>=4;p<16?p=0:p>=4080?p=255:p>>=4;b<16?b=0:b>=4080?b=255:b>>=4;S<16?S=0:S>=4080?S=255:S>>=4;v<16?v=0:v>=4080?v=255:v>>=4;M<16?M=0:M>=4080?M=255:M>>=4;s[e+t]=m;s[e+t+8]=g;s[e+t+16]=d;s[e+t+24]=p;s[e+t+32]=b;s[e+t+40]=S;s[e+t+48]=v;s[e+t+56]=M}else{I=B*m+8192>>14;I=I<-2040?0:I>=2024?255:I+2056>>4;s[e+t]=I;s[e+t+8]=I;s[e+t+16]=I;s[e+t+24]=I;s[e+t+32]=I;s[e+t+40]=I;s[e+t+48]=I;s[e+t+56]=I}}}function buildComponentData(t,e){const r=e.blocksPerLine,n=e.blocksPerColumn,s=new Int16Array(64);for(let t=0;t<n;t++)for(let n=0;n<r;n++){quantizeAndInverse(e,getBlockBufferOffset(e,t,n),s)}return e.blockData}function findNextFileMarker(t,e,r,n=r){const s=t.length-1;let a=n<r?n:r;if(r>=s)return null;const i=e.getUint16(r);if(i>=65472&&i<=65534)return{invalid:null,marker:i,offset:r};let o=e.getUint16(a);for(;!(o>=65472&&o<=65534);){if(++a>=s)return null;o=e.getUint16(a)}return{invalid:i.toString(16),marker:o,offset:a}}function prepareComponents(t){const e=Math.ceil(t.samplesPerLine/8/t.maxH),r=Math.ceil(t.scanLines/8/t.maxV);for(const n of t.components){const s=Math.ceil(Math.ceil(t.samplesPerLine/8)*n.h/t.maxH),a=Math.ceil(Math.ceil(t.scanLines/8)*n.v/t.maxV),i=e*n.h,o=64*(r*n.v)*(i+1);n.blockData=new Int16Array(o);n.blocksPerLine=s;n.blocksPerColumn=a}t.mcusPerLine=e;t.mcusPerColumn=r}function readDataBlock(t,e,r){const n=e.getUint16(r);let s=(r+=2)+n-2;const a=findNextFileMarker(t,e,s,r);if(a?.invalid){warn("readDataBlock - incorrect length, current marker is: "+a.invalid);s=a.offset}const i=t.subarray(r,s);return{appData:i,oldOffset:r,newOffset:r+i.length}}function skipData(t,e,r){const n=e.getUint16(r),s=(r+=2)+n-2,a=findNextFileMarker(t,e,s,r);return a?.invalid?a.offset:s}class JpegImage{constructor({decodeTransform:t=null,colorTransform:e=-1}={}){this._decodeTransform=t;this._colorTransform=e}static canUseImageDecoder(t,e=-1){const r=new DataView(t.buffer,t.byteOffset,t.byteLength);let n=null,s=0,a=null,i=r.getUint16(s);s+=2;if(65496!==i)throw new JpegError("SOI not found");i=r.getUint16(s);s+=2;t:for(;65497!==i;){switch(i){case 65505:const{appData:e,oldOffset:o,newOffset:c}=readDataBlock(t,r,s);s=c;if(69===e[0]&&120===e[1]&&105===e[2]&&102===e[3]&&0===e[4]&&0===e[5]){if(n)throw new JpegError("Duplicate EXIF-blocks found.");n={exifStart:o+6,exifEnd:c}}i=r.getUint16(s);s+=2;continue;case 65472:case 65473:case 65474:a=t[s+7];break t;case 65535:255!==t[s]&&s--}s=skipData(t,r,s);i=r.getUint16(s);s+=2}return 4===a||3===a&&0===e?null:n||{}}parse(t,{dnlScanLines:e=null}={}){const r=new DataView(t.buffer,t.byteOffset,t.byteLength),n=t.length-1;let s,a,i=0,o=null,c=null,l=0;const u=[],f=[],h=[];let m=r.getUint16(i);i+=2;if(65496!==m)throw new JpegError("SOI not found");m=r.getUint16(i);i+=2;t:for(;65497!==m;){let g,d,p;switch(m){case 65504:case 65505:case 65506:case 65507:case 65508:case 65509:case 65510:case 65511:case 65512:case 65513:case 65514:case 65515:case 65516:case 65517:case 65518:case 65519:case 65534:const{appData:y,newOffset:w}=readDataBlock(t,r,i);i=w;65504===m&&74===y[0]&&70===y[1]&&73===y[2]&&70===y[3]&&0===y[4]&&(o={version:{major:y[5],minor:y[6]},densityUnits:y[7],xDensity:y[8]<<8|y[9],yDensity:y[10]<<8|y[11],thumbWidth:y[12],thumbHeight:y[13],thumbData:y.subarray(14,14+3*y[12]*y[13])});65518===m&&65===y[0]&&100===y[1]&&111===y[2]&&98===y[3]&&101===y[4]&&(c={version:y[5]<<8|y[6],flags0:y[7]<<8|y[8],flags1:y[9]<<8|y[10],transformCode:y[11]});break;case 65499:const C=r.getUint16(i);i+=2;const _=C+i-2;let R;for(;i<_;){const e=t[i++],n=new Uint16Array(64);if(e>>4){if(e>>4!=1)throw new JpegError("DQT - invalid table spec");for(d=0;d<64;d++){R=b[d];n[R]=r.getUint16(i);i+=2}}else for(d=0;d<64;d++){R=b[d];n[R]=t[i++]}u[15&e]=n}break;case 65472:case 65473:case 65474:if(s)throw new JpegError("Only single frame JPEGs supported");i+=2;s={};s.extended=65473===m;s.progressive=65474===m;s.precision=t[i++];const A=r.getUint16(i);i+=2;s.scanLines=e||A;s.samplesPerLine=r.getUint16(i);i+=2;s.components=[];s.componentIds={};const B=t[i++];let x=0,S=0;for(g=0;g<B;g++){const e=t[i],r=t[i+1]>>4,n=15&t[i+1];x<r&&(x=r);S<n&&(S=n);const a=t[i+2];p=s.components.push({h:r,v:n,quantizationId:a,quantizationTable:null});s.componentIds[e]=p-1;i+=3}s.maxH=x;s.maxV=S;prepareComponents(s);break;case 65476:const v=r.getUint16(i);i+=2;for(g=2;g<v;){const e=t[i++],r=new Uint8Array(16);let n=0;for(d=0;d<16;d++,i++)n+=r[d]=t[i];const s=new Uint8Array(n);for(d=0;d<n;d++,i++)s[d]=t[i];g+=17+n;(e>>4?f:h)[15&e]=buildHuffmanTable(r,s)}break;case 65501:i+=2;a=r.getUint16(i);i+=2;break;case 65498:const M=1===++l&&!e;i+=2;const I=t[i++],k=[];for(g=0;g<I;g++){const e=t[i++],r=s.componentIds[e],n=s.components[r];n.index=e;const a=t[i++];n.huffmanTableDC=h[a>>4];n.huffmanTableAC=f[15&a];k.push(n)}const D=t[i++],E=t[i++],T=t[i++];try{i+=decodeScan(t,r,i,s,k,a,D,E,T>>4,15&T,M)}catch(e){if(e instanceof DNLMarkerError){warn(`${e.message} -- attempting to re-parse the JPEG image.`);return this.parse(t,{dnlScanLines:e.scanLines})}if(e instanceof EOIMarkerError){warn(`${e.message} -- ignoring the rest of the image data.`);break t}throw e}break;case 65500:i+=4;break;case 65535:255!==t[i]&&i--;break;default:const P=findNextFileMarker(t,r,i-2,i-3);if(P?.invalid){warn("JpegImage.parse - unexpected data, current marker is: "+P.invalid);i=P.offset;break}if(!P||i>=n){warn("JpegImage.parse - reached the end of the image data without finding an EOI marker (0xFFD9).");break t}throw new JpegError("JpegImage.parse - unknown marker: "+m.toString(16))}if(i<n){m=r.getUint16(i);i+=2}else m=0}if(!s)throw new JpegError("JpegImage.parse - no frame data found.");this.width=s.samplesPerLine;this.height=s.scanLines;this.jfif=o;this.adobe=c;this.components=[];for(const t of s.components){const e=u[t.quantizationId];e&&(t.quantizationTable=e);this.components.push({index:t.index,output:buildComponentData(0,t),scaleX:t.h/s.maxH,scaleY:t.v/s.maxV,blocksPerLine:t.blocksPerLine,blocksPerColumn:t.blocksPerColumn})}this.numComponents=this.components.length}_getLinearizedBlockData(t,e,r=!1){const n=this.width/t,s=this.height/e;let a,i,o,c,l,u,f,h,m,g,d,p=0;const b=this.components.length,y=t*e*b,w=new Uint8ClampedArray(y),C=new Uint32Array(t),_=4294967288;let R;for(f=0;f<b;f++){a=this.components[f];i=a.scaleX*n;o=a.scaleY*s;p=f;d=a.output;c=a.blocksPerLine+1<<3;if(i!==R){for(l=0;l<t;l++){h=0|l*i;C[l]=(h&_)<<3|7&h}R=i}for(u=0;u<e;u++){h=0|u*o;g=c*(h&_)|(7&h)<<3;for(l=0;l<t;l++){w[p]=d[g+C[l]];p+=b}}}let A=this._decodeTransform;r||4!==b||A||(A=new Int32Array([-256,255,-256,255,-256,255,-256,255]));if(A)for(f=0;f<y;)for(h=0,m=0;h<b;h++,f++,m+=2)w[f]=(