UNPKG

pdfjs-dist

Version:

Generic build of Mozilla's PDF.js library.

29 lines • 61.4 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 = 6.0.227 * pdfjsBuild = 241dbabbf */ "object"!=typeof process||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&process.type,new Float32Array([1/0,1/0,-1/0,-1/0]);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(r){t>=e.INFOS&&console.info(`Info: ${r}`)}function warn(r){t>=e.WARNINGS&&console.warn(`Warning: ${r}`)}function unreachable(e){throw new Error(e)}function shadow(e,t,r,n=!1){Object.defineProperty(e,t,{value:r,enumerable:!n,configurable:!0,writable:!1});return r}const r=function BaseExceptionClosure(){function BaseException(e,t){this.message=e;this.name=t}BaseException.prototype=new Error;BaseException.constructor=BaseException;return BaseException}();class FormatError extends r{constructor(e){super(e,"FormatError")}}function bytesToString(e){"object"==typeof e&&void 0!==e?.length||unreachable("Invalid argument for bytesToString");const t=e.length,r=8192;if(t<r)return String.fromCharCode.apply(null,e);const n=[];for(let s=0;s<t;s+=r){const a=Math.min(s+r,t),i=e.subarray(s,a);n.push(String.fromCharCode.apply(null,i))}return n.join("")}class FeatureTest{static get isLittleEndian(){const e=new Uint8Array(4);e[0]=1;return shadow(this,"isLittleEndian",1===new Uint32Array(e.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: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")})}static get isCanvasFilterSupported(){let e;this.isOffscreenCanvasSupported?e=new OffscreenCanvas(1,1).getContext("2d"):"undefined"!=typeof document&&(e=document.createElement("canvas").getContext("2d"));return shadow(this,"isCanvasFilterSupported",void 0!==e?.filter)}static get isAlphaColorInputSupported(){if("undefined"==typeof document)return shadow(this,"isAlphaColorInputSupported",!1);const e=document.createElement("input");e.type="color";e.setAttribute("alpha","");e.value="#ff000080";return shadow(this,"isAlphaColorInputSupported","#ff0000"!==e.value)}}class Util{static get hexNums(){return shadow(this,"hexNums",Array.from(Array(256).keys(),e=>e.toString(16).padStart(2,"0")))}static makeHexColor(e,t,r){return`#${this.hexNums[e]}${this.hexNums[t]}${this.hexNums[r]}`}static transform(e,t){return[e[0]*t[0]+e[2]*t[1],e[1]*t[0]+e[3]*t[1],e[0]*t[2]+e[2]*t[3],e[1]*t[2]+e[3]*t[3],e[0]*t[4]+e[2]*t[5]+e[4],e[1]*t[4]+e[3]*t[5]+e[5]]}static multiplyByDOMMatrix(e,t){return[e[0]*t.a+e[2]*t.b,e[1]*t.a+e[3]*t.b,e[0]*t.c+e[2]*t.d,e[1]*t.c+e[3]*t.d,e[0]*t.e+e[2]*t.f+e[4],e[1]*t.e+e[3]*t.f+e[5]]}static applyTransform(e,t,r=0){const n=e[r],s=e[r+1];e[r]=n*t[0]+s*t[2]+t[4];e[r+1]=n*t[1]+s*t[3]+t[5]}static applyTransformToBezier(e,t,r=0){const n=t[0],s=t[1],a=t[2],i=t[3],o=t[4],c=t[5];for(let t=0;t<6;t+=2){const l=e[r+t],u=e[r+t+1];e[r+t]=l*n+u*a+o;e[r+t+1]=l*s+u*i+c}}static applyInverseTransform(e,t){const r=e[0],n=e[1],s=t[0]*t[3]-t[1]*t[2];e[0]=(r*t[3]-n*t[2]+t[2]*t[5]-t[4]*t[3])/s;e[1]=(-r*t[1]+n*t[0]+t[4]*t[1]-t[5]*t[0])/s}static axialAlignedBoundingBox(e,t,r){const n=t[0],s=t[1],a=t[2],i=t[3],o=t[4],c=t[5],l=e[0],u=e[1],f=e[2],h=e[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 e=s*l,t=s*f,r=a*u,n=a*h;m+=r;p+=r;d+=n;g+=n;b+=e;C+=e;w+=t;y+=t}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(e){const t=e[0]*e[3]-e[1]*e[2];return[e[3]/t,-e[1]/t,-e[2]/t,e[0]/t,(e[2]*e[5]-e[4]*e[3])/t,(e[4]*e[1]-e[5]*e[0])/t]}static singularValueDecompose2dScale(e,t){const r=e[0],n=e[1],s=e[2],a=e[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));t[0]=Math.sqrt(l+u||1);t[1]=Math.sqrt(l-u||1)}static normalizeRect(e){const t=e.slice(0);if(e[0]>e[2]){t[0]=e[2];t[2]=e[0]}if(e[1]>e[3]){t[1]=e[3];t[3]=e[1]}return t}static intersect(e,t){const r=Math.max(Math.min(e[0],e[2]),Math.min(t[0],t[2])),n=Math.min(Math.max(e[0],e[2]),Math.max(t[0],t[2]));if(r>n)return null;const s=Math.max(Math.min(e[1],e[3]),Math.min(t[1],t[3])),a=Math.min(Math.max(e[1],e[3]),Math.max(t[1],t[3]));return s>a?null:[r,s,n,a]}static pointBoundingBox(e,t,r){r[0]=Math.min(r[0],e);r[1]=Math.min(r[1],t);r[2]=Math.max(r[2],e);r[3]=Math.max(r[3],t)}static rectBoundingBox(e,t,r,n,s){s[0]=Math.min(s[0],e,r);s[1]=Math.min(s[1],t,n);s[2]=Math.max(s[2],e,r);s[3]=Math.max(s[3],t,n)}static#e(e,t,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*e+3*c*t)+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#t(e,t,r,n,s,a,i,o,c,l,u,f){if(Math.abs(c)<1e-12){Math.abs(l)>=1e-12&&this.#e(e,t,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.#e(e,t,r,n,s,a,i,o,(-l+m)/g,f);this.#e(e,t,r,n,s,a,i,o,(-l-m)/g,f)}static bezierBoundingBox(e,t,r,n,s,a,i,o,c){c[0]=Math.min(c[0],e,i);c[1]=Math.min(c[1],t,o);c[2]=Math.max(c[2],e,i);c[3]=Math.max(c[3],t,o);this.#t(e,r,s,i,t,n,a,o,3*(3*(r-s)-e+i),6*(e-2*r+s),3*(r-e),c);this.#t(e,r,s,i,t,n,a,o,3*(3*(n-a)-t+o),6*(t-2*n+a),3*(n-t),c)}}const n=async function JBig2(e={}){var t=e,quit_=(e,t)=>{throw t},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 e=h.buffer;i=new Int8Array(e);new Int16Array(e);o=new Uint8Array(e);new Uint16Array(e);new Int32Array(e);new Uint32Array(e);new Float32Array(e);new Float64Array(e);new BigInt64Array(e);new BigUint64Array(e)}class ExitStatus{name="ExitStatus";constructor(e){this.message=`Program terminated with exit(${e})`;this.status=e}}var f,h,callRuntimeCallbacks=e=>{for(;e.length>0;)e.shift()(t)},m=[],addOnPostRun=e=>m.push(e),g=[],addOnPreRun=e=>g.push(e),d=!0,p=0,b={},handleException=e=>{if(e instanceof ExitStatus||"unwind"==e)return n;quit_(0,e)},keepRuntimeAlive=()=>d||p>0,_proc_exit=e=>{n=e;if(!keepRuntimeAlive()){t.onExit?.(e);l=!0}quit_(0,new ExitStatus(e))},_exit=(e,t)=>{n=e;_proc_exit(e)},callUserCallback=e=>{if(!l)try{return e()}catch(e){handleException(e)}finally{(()=>{if(!keepRuntimeAlive())try{_exit(n)}catch(e){handleException(e)}})()}},alignMemory=(e,t)=>Math.ceil(e/t)*t,growMemory=e=>{var t=(e-h.buffer.byteLength+65535)/65536|0;try{h.grow(t);updateMemoryViews();return 1}catch(e){}};t.noExitRuntime&&(d=t.noExitRuntime);t.print&&t.print;t.printErr&&(c=t.printErr);t.wasmBinary&&t.wasmBinary;t.arguments&&t.arguments;t.thisProgram&&t.thisProgram;if(t.preInit){"function"==typeof t.preInit&&(t.preInit=[t.preInit]);for(;t.preInit.length>0;)t.preInit.shift()()}t.writeArrayToMemory=(e,t)=>{i.set(e,t)};var y,w={e:()=>function abort(e){t.onAbort?.(e);c(e="Aborted("+e+")");l=!0;e+=". Build with -sASSERTIONS for more info.";var r=new WebAssembly.RuntimeError(e);a?.(r);throw r}(""),b:()=>{d=!1;p=0},c:(e,t)=>{if(b[e]){clearTimeout(b[e].id);delete b[e]}if(!t)return 0;var r=setTimeout(()=>{delete b[e];callUserCallback(()=>f(e,performance.now()))},t);b[e]={id:r,timeout_ms:t};return 0},g:function _createImageData(e){t.imageData=new Uint8Array(e)},d:e=>{var t=o.length,r=2147483648;if((e>>>=0)>r)return!1;for(var n=1;n<=4;n*=2){var s=t*(1+.2/n);s=Math.min(s,e+100663296);var a=Math.min(r,alignMemory(Math.max(e,s),65536));if(growMemory(a))return!0}return!1},a:_proc_exit,h:function _setImageData(e,r,n,s){if(n===r){t.imageData=new Uint8ClampedArray(o.subarray(e,e+n*s));return}const a=r*s,i=t.imageData=new Uint8ClampedArray(a);for(let t=e,s=0;s<a;t+=n,s+=r)i.set(o.subarray(t,t+r),s)},f:function _setLineData(e,r,n){t.imageData.set(o.subarray(e,e+r),n)}};y=await async function createWasm(){function receiveInstance(e,r){!function assignWasmExports(e){t._malloc=e.k;t._free=e.l;t._jbig2_decode=e.m;t._ccitt_decode=e.n;f=e.o;h=e.i;e.__indirect_function_table}(y=e.exports);updateMemoryViews();return y}var e=function getWasmImports(){return{a:w}}();return new Promise((r,n)=>{t.instantiateWasm(e,(e,t)=>{r(receiveInstance(e))})})}();!function run(){!function preRun(){if(t.preRun){"function"==typeof t.preRun&&(t.preRun=[t.preRun]);for(;t.preRun.length;)addOnPreRun(t.preRun.shift())}callRuntimeCallbacks(g)}();function doRun(){t.calledRun=!0;if(!l){!function initRuntime(){u=!0;y.j()}();s?.(t);t.onRuntimeInitialized?.();!function postRun(){if(t.postRun){"function"==typeof t.postRun&&(t.postRun=[t.postRun]);for(;t.postRun.length;)addOnPostRun(t.postRun.shift())}callRuntimeCallbacks(m)}()}}if(t.setStatus){t.setStatus("Running...");setTimeout(()=>{setTimeout(()=>t.setStatus(""),1);doRun()},1)}else doRun()}();return u?t:new Promise((e,t)=>{s=e;a=t})};Symbol("CIRCULAR_REF"),Symbol("EOF");Object.create(null);let s=Object.create(null),a=Object.create(null);class Name{constructor(e){this.name=e}static get(e){return s[e]||=new Name(e)}}const i=function nonSerializableClosure(){return i};class Dict{__nonSerializable__=i;#r=new Map;objId=null;suppressEncryption=!1;xref;constructor(e=null){this.xref=e}assignXref(e){this.xref=e}get size(){return this.#r.size}#n(e,t,r,n){let s=this.#r.get(t);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?e?this.xref.fetchAsync(s,this.suppressEncryption):this.xref.fetch(s,this.suppressEncryption):s}get(e,t,r){return this.#n(!1,e,t,r)}async getAsync(e,t,r){return this.#n(!0,e,t,r)}getArray(e,t,r){let n=this.#n(!1,e,t,r);if(Array.isArray(n)){n=n.slice();for(let e=0,t=n.length;e<t;e++)n[e]instanceof Ref&&this.xref&&(n[e]=this.xref.fetch(n[e],this.suppressEncryption))}return n}getRaw(e){return this.#r.get(e)}getKeys(){return this.#r.keys()}getRawValues(){return this.#r.values()}getRawEntries(){return this.#r.entries()}set(e,t){this.#r.set(e,t)}setIfNotExists(e,t){this.has(e)||this.set(e,t)}setIfNumber(e,t){"number"==typeof t&&this.set(e,t)}setIfArray(e,t){(Array.isArray(t)||ArrayBuffer.isView(t))&&this.set(e,t)}setIfDefined(e,t){null!=t&&this.set(e,t)}setIfName(e,t){"string"==typeof t?this.set(e,Name.get(t)):t instanceof Name&&this.set(e,t)}setIfDict(e,t){t instanceof Dict&&this.set(e,t)}has(e){return this.#r.has(e)}*[Symbol.iterator](){for(const[e,t]of this.#r)yield[e,t instanceof Ref&&this.xref?this.xref.fetch(t,this.suppressEncryption):t]}static get empty(){const e=new 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:r=!1}){const n=new Dict(e),s=new Map;for(const e of t)if(e instanceof Dict)for(const[t,n]of e.getRawEntries()){let e=s.get(t);if(void 0===e){e=[];s.set(t,e)}else if(!(r&&n instanceof Dict))continue;e.push(n)}for(const[t,r]of s){if(1===r.length||!(r[0]instanceof Dict)){n.set(t,r[0]);continue}const s=new Dict(e);for(const e of r)for(const[t,r]of e.getRawEntries())s.setIfNotExists(t,r);s.size>0&&n.set(t,s)}s.clear();return n.size>0?n:Dict.empty}clone(){const e=new Dict(this.xref);for(const[t,r]of this.#r)e.set(t,r);return e}delete(e){this.#r.delete(e)}}class 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=a[e];if(t)return t;const r=/^(\d+)R(\d*)$/.exec(e);return r&&"0"!==r[1]?a[e]=new Ref(parseInt(r[1],10),r[2]?parseInt(r[2],10):0):null}static get(e,t){const r=0===t?`${e}R`:`${e}R${t}`;return a[r]||=new Ref(e,t)}}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(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 isImageStream(){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,r=null){unreachable("Abstract method `makeSubStream` called")}getBaseStreams(){return null}getOriginalStream(){return this.stream?.getOriginalStream()||this}}class MissingDataException extends r{constructor(e,t){super(`Missing data [${e}, ${t})`,"MissingDataException");this.begin=e;this.end=t}}class WasmImage{static#s=null;static#a=new Set;static#i=!0;static#o=!0;static#c=null;#l=null;#u=null;_filename=null;_noWasmFilename=null;static setOptions({handler:e,useWasm:t,useWorkerFetch:r,wasmUrl:n}){WasmImage.#i=t;WasmImage.#o=r;WasmImage.#c=n;r||(WasmImage.#s=e)}static get instance(){unreachable("Abstract getter `instance` accessed")}static cleanup(){for(const e of WasmImage.#a)e.#u=null}constructor(e=!1){e&&WasmImage.#a.add(this)}async#f(e){let t=null;try{t=(await import( /*webpackIgnore: true*/ /*@vite-ignore*/ `${WasmImage.#c}${this._noWasmFilename}`)).default()}catch(e){warn(`#getJsModule: ${e}`)}e(t)}async#h(e,t,r){try{this.#l||(WasmImage.#o?this.#l=await async function fetchBinaryData(e){const t=await fetch(e);if(!t.ok)throw new Error(`Failed to fetch file "${e}" with "${t.statusText}".`);return t.bytes()}(`${WasmImage.#c}${this._filename}`):this.#l=await WasmImage.#s.sendWithPromise("FetchBinaryData",{kind:"wasmUrl",filename:this._filename}));return r((await WebAssembly.instantiate(this.#l,t)).instance)}catch(t){warn(`#instantiateWasm: ${t}`);this.#f(e);return null}}_getModule(e){if(!this.#u){const{promise:t,resolve:r}=Promise.withResolvers(),n=[t];WasmImage.#i?n.push(e({warn,instantiateWasm:this.#h.bind(this,r)})):this.#f(r);this.#u=Promise.race(n)}return this.#u}async decode(e,t){unreachable("Abstract method `decode` called")}}class Jbig2Error extends r{constructor(e){super(e,"Jbig2Error")}}class JBig2CCITTFaxImage extends WasmImage{_filename="jbig2.wasm";_noWasmFilename="jbig2_nowasm_fallback.js";static get instance(){return shadow(this,"instance",new JBig2CCITTFaxImage(!0))}async decode(e,t,r,s,a){const i=await this._getModule(n);if(!i)throw new Jbig2Error("JBig2 failed to initialize");let o,c;try{const n=e.length;o=i._malloc(n);i.writeArrayToMemory(e,o);if(a)i._ccitt_decode(o,n,t,r,a.K,a.EndOfLine?1:0,a.EncodedByteAlign?1:0,a.BlackIs1?1:0,a.Columns,a.Rows);else{const e=s?s.length:0;if(e>0){c=i._malloc(e);i.writeArrayToMemory(s,c)}i._jbig2_decode(o,n,t,r,c,e)}if(!i.imageData)throw new Jbig2Error("Unknown error");const{imageData:l}=i;i.imageData=null;return l}finally{o&&i._free(o);c&&i._free(c)}}}function MathClamp(e,t,r){return Math.min(Math.max(e,t),r)}function isDefaultDecodeHelper(e,t){if(!Array.isArray(e))return!0;const r=e.length;if(r<t){warn("Decode map length is too short.");return!0}if(r>t){info("Truncating too long decode map.");e.length=t}return!1}class ColorSpace{static#m=new Uint8ClampedArray(3);constructor(e,t){this.name=e;this.numComps=t}getRgb(e,t,r=new Uint8ClampedArray(3)){this.getRgbItem(e,t,r,0);return r}getRgbHex(e,t){const r=this.getRgb(e,t,ColorSpace.#m);return Util.makeHexColor(r[0],r[1],r[2])}getRgbItem(e,t,r,n){unreachable("Should not call ColorSpace.getRgbItem")}getRgbBuffer(e,t,r,n,s,a,i){unreachable("Should not call ColorSpace.getRgbBuffer")}getOutputLength(e,t){unreachable("Should not call ColorSpace.getOutputLength")}isPassthrough(e){return!1}isDefaultDecode(e,t){return ColorSpace.isDefaultDecode(e,this.numComps)}fillRgb(e,t,r,n,s,a,i,o,c){const l=t*r;let u=null;const f=1<<i,h=r!==s||t!==n;if(this.isPassthrough(i))u=o;else if(1===this.numComps&&l>f&&"DeviceGray"!==this.name&&"DeviceRGB"!==this.name){const t=i<=8?new Uint8Array(f):new Uint16Array(f);for(let e=0;e<f;e++)t[e]=e;const r=new Uint8ClampedArray(3*f);this.getRgbBuffer(t,0,f,r,0,i,0);if(h){u=new Uint8Array(3*l);let e=0;for(let t=0;t<l;++t){const n=3*o[t];u[e++]=r[n];u[e++]=r[n+1];u[e++]=r[n+2]}}else{let t=0;for(let n=0;n<l;++n){const s=3*o[n];e[t++]=r[s];e[t++]=r[s+1];e[t++]=r[s+2];t+=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,e,0,i,c);if(u)if(h)!function resizeRgbImage(e,t,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 e=0;e<s;e++)f[e]=3*Math.floor(e*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];t[u++]=e[l++];t[u++]=e[l++];t[u++]=e[l++];u+=i}}}(u,e,t,r,n,s,c);else{let t=0,r=0;for(let s=0,i=n*a;s<i;s++){e[t++]=u[r++];e[t++]=u[r++];e[t++]=u[r++];t+=c}}}get usesZeroToOneRange(){return shadow(this,"usesZeroToOneRange",!0)}static isDefaultDecode(e,t){if(isDefaultDecodeHelper(e,2*t))return!0;for(let t=0,r=e.length;t<r;t+=2)if(0!==e[t]||1!==e[t+1])return!1;return!0}}class AlternateCS extends ColorSpace{constructor(e,t,r){super("Alternate",e);this.base=t;this.tintFn=r;this.tmpBuf=new Float32Array(t.numComps)}getRgbItem(e,t,r,n){const s=this.tmpBuf;this.tintFn(e,t,s,0);this.base.getRgbItem(s,0,r,n)}getRgbBuffer(e,t,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]=e[t++]*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(e,t){return this.base.getOutputLength(e*this.base.numComps/this.numComps,t)}}class PatternCS extends ColorSpace{constructor(e){super("Pattern",null);this.base=e}isDefaultDecode(e,t){unreachable("Should not call PatternCS.isDefaultDecode")}}class IndexedCS extends ColorSpace{constructor(e,t,r){super("Indexed",1);this.base=e;this.highVal=t;const n=e.numComps*(t+1);this.lookup=new Uint8Array(n);if(r instanceof BaseStream){const e=r.getBytes(n);this.lookup.set(e)}else{if("string"!=typeof r)throw new FormatError(`IndexedCS - unrecognized lookup table: ${r}`);for(let e=0;e<n;++e)this.lookup[e]=255&r.charCodeAt(e)}}getRgbItem(e,t,r,n){const{base:s,highVal:a,lookup:i}=this,o=MathClamp(Math.round(e[t]),0,a)*s.numComps;s.getRgbBuffer(i,o,1,r,n,8,0)}getRgbBuffer(e,t,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(e[t++]),0,c)*u;o.getRgbBuffer(l,r,1,n,s,8,i);s+=f}}getOutputLength(e,t){return this.base.getOutputLength(e*this.base.numComps,t)}isDefaultDecode(e,t){if(isDefaultDecodeHelper(e,2))return!0;if(!Number.isInteger(t)||t<1){warn("Bits per component is not correct");return!0}return 0===e[0]&&e[1]===(1<<t)-1}}class DeviceGrayCS extends ColorSpace{constructor(){super("DeviceGray",1)}getRgbItem(e,t,r,n){const s=255*e[t];r[n]=r[n+1]=r[n+2]=s}getRgbBuffer(e,t,r,n,s,a,i){const o=255/((1<<a)-1);let c=t,l=s;for(let t=0;t<r;++t){const t=o*e[c++];n[l++]=t;n[l++]=t;n[l++]=t;l+=i}}getOutputLength(e,t){return e*(3+t)}}class DeviceRgbCS extends ColorSpace{constructor(){super("DeviceRGB",3)}getRgbItem(e,t,r,n){r[n]=255*e[t];r[n+1]=255*e[t+1];r[n+2]=255*e[t+2]}getRgbBuffer(e,t,r,n,s,a,i){if(8===a&&0===i){n.set(e.subarray(t,t+3*r),s);return}const o=255/((1<<a)-1);let c=t,l=s;for(let t=0;t<r;++t){n[l++]=o*e[c++];n[l++]=o*e[c++];n[l++]=o*e[c++];l+=i}}getOutputLength(e,t){return e*(3+t)/3|0}isPassthrough(e){return 8===e}}class DeviceRgbaCS extends ColorSpace{constructor(){super("DeviceRGBA",4)}getOutputLength(e,t){return 4*e}isPassthrough(e){return 8===e}fillRgb(e,t,r,n,s,a,i,o,c){r!==s||t!==n?function resizeRgbaImage(e,t,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 e=0;e<s;e++)u[e]=Math.floor(e*o);const n=new Uint32Array(e.buffer),i=new Uint32Array(t.buffer),f=FeatureTest.isLittleEndian?16777215:4294967040;for(let e=0;e<a;e++){const t=n.subarray(Math.floor(e*c)*r);for(let e=0;e<s;e++)i[l++]|=t[u[e]]&f}}else{const n=4,i=r*n;for(let e=0;e<s;e++)u[e]=Math.floor(e*o)*n;for(let r=0;r<a;r++){const n=e.subarray(Math.floor(r*c)*i);for(let e=0;e<s;e++){const r=u[e];t[l++]=n[r];t[l++]=n[r+1];t[l++]=n[r+2]}}}}(o,e,t,r,n,s,c):function copyRgbaImage(e,t,r){if(1===r){const r=new Uint32Array(e.buffer),n=new Uint32Array(t.buffer),s=FeatureTest.isLittleEndian?16777215:4294967040;for(let e=0,t=r.length;e<t;e++)n[e]|=r[e]&s}else{let r=0;for(let n=0,s=e.length;n<s;n+=4){t[r++]=e[n];t[r++]=e[n+1];t[r++]=e[n+2]}}}(o,e,c)}}class DeviceCmykCS extends ColorSpace{constructor(){super("DeviceCMYK",4)}#g(e,t,r,n,s){const a=e[t]*r,i=e[t+1]*r,o=e[t+2]*r,c=e[t+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(e,t,r,n){this.#g(e,t,1,r,n)}getRgbBuffer(e,t,r,n,s,a,i){const o=1/((1<<a)-1);for(let a=0;a<r;a++){this.#g(e,t,o,n,s);t+=4;s+=3+i}}getOutputLength(e,t){return e/4*(3+t)|0}}class CalGrayCS extends ColorSpace{constructor(e,t,r){super("CalGray",1);if(!e)throw new FormatError("WhitePoint missing - required for color space CalGray");[this.XW,this.YW,this.ZW]=e;[this.XB,this.YB,this.ZB]=t||[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}}#g(e,t,r,n,s){const a=(e[t]*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(e,t,r,n){this.#g(e,t,r,n,1)}getRgbBuffer(e,t,r,n,s,a,i){const o=1/((1<<a)-1);for(let a=0;a<r;++a){this.#g(e,t,n,s,o);t+=1;s+=3+i}}getOutputLength(e,t){return e*(3+t)}}class CalRGBCS extends ColorSpace{static#d=new Float32Array([.8951,.2664,-.1614,-.7502,1.7135,.0367,.0389,-.0685,1.0296]);static#p=new Float32Array([.9869929,-.1470543,.1599627,.4323053,.5183603,.0492912,-.0085287,.0400428,.9684867]);static#b=new Float32Array([3.2404542,-1.5371385,-.4985314,-.969266,1.8760108,.041556,.0556434,-.2040259,1.0572252]);static#y=new Float32Array([1,1,1]);static#w=new Float32Array(3);static#C=new Float32Array(3);static#_=new Float32Array(3);static#R=(24/116)**3/8;constructor(e,t,r,n){super("CalRGB",3);if(!e)throw new FormatError("WhitePoint missing - required for color space CalRGB");const[s,a,i]=this.whitePoint=e,[o,c,l]=this.blackPoint=t||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}}#A(e,t,r){r[0]=e[0]*t[0]+e[1]*t[1]+e[2]*t[2];r[1]=e[3]*t[0]+e[4]*t[1]+e[5]*t[2];r[2]=e[6]*t[0]+e[7]*t[1]+e[8]*t[2]}#B(e,t,r){r[0]=1*t[0]/e[0];r[1]=1*t[1]/e[1];r[2]=1*t[2]/e[2]}#x(e,t,r){r[0]=.95047*t[0]/e[0];r[1]=1*t[1]/e[1];r[2]=1.08883*t[2]/e[2]}#S(e){return e<=.0031308?MathClamp(12.92*e,0,1):e>=.99554525?1:MathClamp(1.055*e**(1/2.4)-.055,0,1)}#v(e){return e<0?-this.#v(-e):e>8?((e+16)/116)**3:e*CalRGBCS.#R}#I(e,t,r){if(0===e[0]&&0===e[1]&&0===e[2]){r[0]=t[0];r[1]=t[1];r[2]=t[2];return}const n=this.#v(0),s=(1-n)/(1-this.#v(e[0])),a=1-s,i=(1-n)/(1-this.#v(e[1])),o=1-i,c=(1-n)/(1-this.#v(e[2])),l=1-c;r[0]=t[0]*s+a;r[1]=t[1]*i+o;r[2]=t[2]*c+l}#M(e,t,r){if(1===e[0]&&1===e[2]){r[0]=t[0];r[1]=t[1];r[2]=t[2];return}const n=r;this.#A(CalRGBCS.#d,t,n);const s=CalRGBCS.#w;this.#B(e,n,s);this.#A(CalRGBCS.#p,s,r)}#k(e,t,r){const n=r;this.#A(CalRGBCS.#d,t,n);const s=CalRGBCS.#w;this.#x(e,n,s);this.#A(CalRGBCS.#p,s,r)}#g(e,t,r,n,s){const a=MathClamp(e[t]*s,0,1),i=MathClamp(e[t+1]*s,0,1),o=MathClamp(e[t+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.#C;g[0]=f;g[1]=h;g[2]=m;const d=CalRGBCS.#_;this.#M(this.whitePoint,g,d);const p=CalRGBCS.#C;this.#I(this.blackPoint,d,p);const b=CalRGBCS.#_;this.#k(CalRGBCS.#y,p,b);const y=CalRGBCS.#C;this.#A(CalRGBCS.#b,b,y);r[n]=255*this.#S(y[0]);r[n+1]=255*this.#S(y[1]);r[n+2]=255*this.#S(y[2])}getRgbItem(e,t,r,n){this.#g(e,t,r,n,1)}getRgbBuffer(e,t,r,n,s,a,i){const o=1/((1<<a)-1);for(let a=0;a<r;++a){this.#g(e,t,n,s,o);t+=3;s+=3+i}}getOutputLength(e,t){return e*(3+t)/3|0}}class LabCS extends ColorSpace{constructor(e,t,r){super("Lab",3);if(!e)throw new FormatError("WhitePoint missing - required for color space Lab");[this.XW,this.YW,this.ZW]=e;[this.amin,this.amax,this.bmin,this.bmax]=r||[-100,100,-100,100];[this.XB,this.YB,this.ZB]=t||[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}}#D(e){return e>=6/29?e**3:108/841*(e-4/29)}#E(e,t,r,n){return r+e*(n-r)/t}#g(e,t,r,n,s){let a=e[t],i=e[t+1],o=e[t+2];if(!1!==r){a=this.#E(a,r,0,100);i=this.#E(i,r,this.amin,this.amax);o=this.#E(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.#D(l),h=this.YW*this.#D(c),m=this.ZW*this.#D(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(e,t,r,n){this.#g(e,t,!1,r,n)}getRgbBuffer(e,t,r,n,s,a,i){const o=(1<<a)-1;for(let a=0;a<r;a++){this.#g(e,t,o,n,s);t+=3;s+=3+i}}getOutputLength(e,t){return e*(3+t)/3|0}isDefaultDecode(e,t){return!0}get usesZeroToOneRange(){return shadow(this,"usesZeroToOneRange",!1)}}class QCMS{static#T=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 e=this.#T;return e?.byteLength?e:this.#T=new Uint8Array(this._memory.buffer)}}const o=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"}),c=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(e,t){throw new Error(function getStringFromWasm0(e,t){return function decodeText(e,t){h+=t;if(h>=f){u=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});u.decode();h=t}return u.decode(getUint8ArrayMemory0().subarray(e,e+t))}(e>>>=0,t)}(e,t))},__wbg_copy_result_0d15f3bf9d9012ae:function(e,t){!function copy_result(e,t){const{_mustAddAlpha:r,_destBuffer:n,_destOffset:s,_destLength:a,_memoryArray:i}=QCMS;if(t!==a)if(r)for(let r=e,a=e+t,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=e,a=e+t,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(e,e+t),s)}(e>>>0,t>>>0)},__wbg_copy_rgb_0106d9d9464fce43:function(e){!function copy_rgb(e){const{_destBuffer:t,_destOffset:r,_memoryArray:n}=QCMS;t[r]=n[e];t[r+1]=n[e+1];t[r+2]=n[e+2]}(e>>>0)},__wbg_make_cssRGB_8e24b34f71f5363e:function(e){!function make_cssRGB(e){const{_memoryArray:t}=QCMS;QCMS._cssColor=QCMS._makeHexColor(t[e],t[e+1],t[e+2])}(e>>>0)},__wbindgen_init_externref_table:function(){const e=g.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0);e.set(t+0,void 0);e.set(t+1,null);e.set(t+2,!0);e.set(t+3,!1)}}}}let l=null;function getUint8ArrayMemory0(){null!==l&&0!==l.byteLength||(l=new Uint8Array(g.memory.buffer));return l}function passArray8ToWasm0(e,t){const r=t(1*e.length,1)>>>0;getUint8ArrayMemory0().set(e,r/1);d=e.length;return r}let u=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});u.decode();const f=2146435072;let h=0;let m,g,d=0;function __wbg_finalize_init(e,t){g=e.exports;m=t;l=null;g.__wbindgen_start();return g}function fetchSync(e){const t=new XMLHttpRequest;t.open("GET",e,!1);t.responseType="arraybuffer";t.send(null);return t.response}class IccColorSpace extends ColorSpace{#P;#U;static#i=!0;static#c=null;static#F=null;constructor(e,t,r){if(!IccColorSpace.isUsable)throw new Error("No ICC color space support");super(t,r);let n;switch(r){case 1:n=o.Gray8;this.#U=(e,t,r)=>function qcms_convert_one(e,t,r){g.qcms_convert_one(e,t,r)}(this.#P,255*e[t],r);break;case 3:n=o.RGB8;this.#U=(e,t,r)=>function qcms_convert_three(e,t,r,n,s){g.qcms_convert_three(e,t,r,n,s)}(this.#P,255*e[t],255*e[t+1],255*e[t+2],r);break;case 4:n=o.CMYK;this.#U=(e,t,r)=>function qcms_convert_four(e,t,r,n,s,a){g.qcms_convert_four(e,t,r,n,s,a)}(this.#P,255*e[t],255*e[t+1],255*e[t+2],255*e[t+3],r);break;default:throw new Error(`Unsupported number of components: ${r}`)}this.#P=function qcms_transformer_from_memory(e,t,r){const n=passArray8ToWasm0(e,g.__wbindgen_malloc),s=d;return g.qcms_transformer_from_memory(n,s,t,r)>>>0}(e,n,c.Perceptual);if(!this.#P)throw new Error("Failed to create ICC color space");IccColorSpace.#F||=new FinalizationRegistry(e=>{!function qcms_drop_transformer(e){g.qcms_drop_transformer(e)}(e)});IccColorSpace.#F.register(this,this.#P)}getRgbHex(e,t){this.#U(e,t,!0);return QCMS._cssColor}getRgbItem(e,t,r,n){QCMS._destBuffer=r;QCMS._destOffset=n;QCMS._destLength=3;this.#U(e,t,!1);QCMS._destBuffer=null}getRgbBuffer(e,t,r,n,s,a,i){e=e.subarray(t,t+r*this.numComps);if(8!==a){const t=255/((1<<a)-1);for(let r=0,n=e.length;r<n;r++)e[r]*=t}QCMS._mustAddAlpha=i&&n.buffer===e.buffer;QCMS._destBuffer=n;QCMS._destOffset=s;QCMS._destLength=r*(3+i);!function qcms_convert_array(e,t){const r=passArray8ToWasm0(t,g.__wbindgen_malloc),n=d;g.qcms_convert_array(e,r,n)}(this.#P,e);QCMS._mustAddAlpha=!1;QCMS._destBuffer=null}getOutputLength(e,t){return e/this.numComps*(3+t)|0}static setOptions({useWasm:e,useWorkerFetch:t,wasmUrl:r}){if(t){this.#i=e;this.#c=r}else this.#i=!1}static get isUsable(){let e=!1;if(this.#i)if(this.#c)try{this._module=function initSync(e){if(void 0!==g)return g;void 0!==e&&(Object.getPrototypeOf(e)===Object.prototype?({module:e}=e):console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));const t=__wbg_get_imports();e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e));return __wbg_finalize_init(new WebAssembly.Instance(e,t),e)}({module:fetchSync(`${this.#c}qcms_bg.wasm`)});e=!!this._module;QCMS._memory=this._module.memory;QCMS._makeHexColor=Util.makeHexColor.bind(Util)}catch(e){warn(`ICCBased color space: "${e}".`)}else warn("No ICC color space support due to missing `wasmUrl` API option");return shadow(this,"isUsable",e)}}class CmykICCBasedCS extends IccColorSpace{static#G;constructor(){super(new Uint8Array(fetchSync(`${CmykICCBasedCS.#G}CGATS001Compat-v2-micro.icc`)),"DeviceCMYK",4)}static setOptions({iccUrl:e}){this.#G=e}static get isUsable(){let e=!1;IccColorSpace.isUsable&&(this.#G?e=!0:warn("No CMYK ICC profile support due to missing `iccUrl` API option"));return shadow(this,"isUsable",e)}}class ColorSpaceUtils{static parse({cs:e,xref:t,resources:r=null,pdfFunctionFactory:n,globalColorSpaceCache:s,localColorSpaceCache:a,asyncIfNotCached:i=!1}){const o={xref:t,resources:r,pdfFunctionFactory:n,globalColorSpaceCache:s,localColorSpaceCache:a};let c,l,u;if(e instanceof Ref){l=e;const r=s.getByRef(l)||a.getByRef(l);if(r)return r;e=t.fetch(e)}if(e instanceof Name){c=e.name;const t=a.getByName(c);if(t)return t}try{u=this.#L(e,o)}catch(e){if(i&&!(e instanceof MissingDataException))return Promise.reject(e);throw e}if(c||l){a.set(c,l,u);l&&s.set(null,l,u)}return i?Promise.resolve(u):u}static#O(e,t){const{globalColorSpaceCache:r}=t;let n;if(e instanceof Ref){n=e;const t=r.getByRef(n);if(t)return t}const s=this.#L(e,t);n&&r.set(null,n,s);return s}static#L(e,t){const{xref:r,resources:n,pdfFunctionFactory:s,globalColorSpaceCache:a}=t;if((e=r.fetchIfRef(e))instanceof Name)switch(e.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(e.name);if(n){if(n instanceof Name)return this.#L(n,t);e=n;break}}}warn(`Unrecognized ColorSpace: ${e.name}`);return this.gray}if(Array.isArray(e)){const n=r.fetchIfRef(e[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(e[1]);l=i.getArray("WhitePoint");u=i.getArray("BlackPoint");f=i.get("Gamma");return new CalGrayCS(l,u,f);case"CalRGB":i=r.fetchIfRef(e[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=e[1]instanceof Ref;if(m){const t=a.getByRef(e[1]);if(t)return t}const g=r.fetchIfRef(e[1]),d=g.dict;o=d.get("N");if(IccColorSpace.isUsable)try{const t=new IccColorSpace(g.getBytes(),"ICCBased",o);m&&a.set(null,e[1],t);return t}catch(t){if(t instanceof MissingDataException)throw t;warn(`ICCBased color space (${e[1]}): "${t}".`)}const p=d.getRaw("Alternate");if(p){const e=this.#O(p,t);if(e.numComps===o)return e;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=e[1]||null;c&&(c=this.#O(c,t));return new PatternCS(c);case"I":case"Indexed":c=this.#O(e[1],t);const b=MathClamp(r.fetchIfRef(e[2]),0,255),y=r.fetchIfRef(e[3]);return new IndexedCS(c,b,y);case"Separation":case"DeviceN":const w=r.fetchIfRef(e[1]);o=Array.isArray(w)?w.length:1;c=this.#O(e[2],t);const C=s.create(e[3]);return new AlternateCS(o,c,C);case"Lab":i=r.fetchIfRef(e[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: ${e}`);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 r{constructor(e){super(e,"JpegError")}}class DNLMarkerError extends r{constructor(e,t){super(e,"DNLMarkerError");this.scanLines=t}}class EOIMarkerError extends r{constructor(e){super(e,"EOIMarkerError")}}const p=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]),b=4017,y=799,w=3406,C=2276,_=1567,R=3784,A=5793,B=2896;function buildHuffmanTable(e,t){let r,n,s=0,a=16;for(;a>0&&!e[a-1];)a--;const i=[{children:[],index:0}];let o,c=i[0];for(r=0;r<a;r++){for(n=0;n<e[r];n++){c=i.pop();c.children[c.index]=t[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(e,t,r){return 64*((e.blocksPerLine+1)*t+r)}function decodeScan(e,t,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=e[r++];if(255===g){const s=e[r++];if(s){if(220===s&&u){r+=2;const e=t.getUint16(r);r+=2;if(e>0&&e!==n.scanLines)throw new DNLMarkerError("Found DNL marker (0xFFDC) while parsing scan data",e)}else if(217===s){if(u){const e=C*(8===n.precision?8:0);if(e>0&&Math.round(n.scanLines/e)>=5)throw new DNLMarkerError("Found EOI marker (0xFFD9) while parsing scan data, possibly caused by incorrect `scanLines` parameter",e)}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(e){let t=e;for(;;){t=t[readBit()];switch(typeof t){case"number":return t;case"object":continue}throw new JpegError("invalid huffman sequence")}}function receive(e){let t=0;for(;e>0;){t=t<<1|readBit();e--}return t}function receiveAndExtend(e){if(1===e)return 1===readBit()?1:-1;const t=receive(e);return t>=1<<e-1?t:t+(-1<<e)+1}let b=0;let y,w=0;let C=0;function decodeMcu(e,t,r,n,s){const a=r%f;C=(r/f|0)*e.v+n;const i=a*e.h+s;t(e,getBlockBufferOffset(e,C,i))}function decodeBlock(e,t,r){C=r/e.blocksPerLine|0;const n=r%e.blocksPerLine;t(e,getBlockBufferOffset(e,C,n))}const _=s.length;let R,A,B,x,S,v;v=h?0===i?0===c?function decodeDCFirst(e,t){const r=decodeHuffman(e.huffmanTableDC),n=0===r?0:receiveAndExtend(r)<<l;e.blockData[t]=e.pred+=n}:function decodeDCSuccessive(e,t){e.blockData[t]|=readBit()<<l}:0===c?function decodeACFirst(e,t){if(b>0){b--;return}let r=i;const n=o;for(;r<=n;){const n=decodeHuffman(e.huffmanTableAC),s=15&n,a=n>>4;if(0===s){if(a<15){b=receive(a)+(1<<a)-1;break}r+=16;continue}r+=a;const i=p[r];e.blockData[t+i]=receiveAndExtend(s)*(1<<l);r++}}:function decodeACSuccessive(e,t){let r=i;const n=o;let s,a,c=0;for(;r<=n;){const n=t+p[r],i=e.blockData[n]<0?-1:1;switch(w){case 0:a=decodeHuffman(e.huffmanTableAC);s=15&a;c=a>>4;if(0===s)if(c<15){b=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(e.blockData[n])e.blockData[n]+=i*(readBit()<<l);else{c--;0===c&&(w=2===w?3:0)}break;case 3:if(e.blockData[n])e.blockData[n]+=i*(readBit()<<l);else{e.blockData[n]=y<<l;w=0}break;case 4:e.blockData[n]&&(e.blockData[n]+=i*(readBit()<<l))}r++}if(4===w){b--;0===b&&(w=0)}}:function decodeBaseline(e,t){const r=decodeHuffman(e.huffmanTableDC),n=0===r?0:receiveAndExtend(r);e.blockData[t]=e.pred+=n;let s=1;for(;s<64;){const r=decodeHuffman(e.huffmanTableAC),n=15&r,a=r>>4;if(0===n){if(a<15)break;s+=16;continue}s+=a;const i=p[s];e.blockData[t+i]=receiveAndExtend(n);s++}};let I,M=0;const k=1===_?s[0].blocksPerLine*s[0].blocksPerColumn:f*n.mcusPerColumn;let D,E;for(;M<=k;){const n=a?Math.min(k-M,a):k;if(n>0){for(A=0;A<_;A++)s[A].pred=0;b=0;if(1===_){R=s[0];for(S=0;S<n;S++){decodeBlock(R,v,M);M++}}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,M,B,x)}M++}}d=0;I=findNextFileMarker(e,t,r);if(!I)break;if(I.invalid){warn(`decodeScan - ${n>0?"unexpected":"excessive"} MCU data, current marker is: ${I.invalid}`);r=I.offset}if(!(I.marker>=65488&&I.marker<=65495))break;r+=2}return r-m}function quantizeAndInverse(e,t,r){const n=e.quantizationTable,s=e.blockData;let a,i,o,c,l,u,f,h,m,g,d,p,x,S,v,I,M;if(!n)throw new JpegError("missing required Quantization Table.");for(let e=0;e<64;e+=8){m=s[t+e];g=s[t+e+1];d=s[t+e+2];p=s[t+e+3];x=s[t+e+4];S=s[t+e+5];v=s[t+e+6];I=s[t+e+7];m*=n[e];if(0!==(g|d|p|x|S|v|I)){g*=n[e+1];d*=n[e+2];p*=n[e+3];x*=n[e+4];S*=n[e+5];v*=n[e+6];I*=n[e+7];a=A*m+128>>8;i=A*x+128>>8;o=d;c=v;l=B*(g-I)+128>>8;h=B*(g+I)+128>>8;u=p<<4;f=S<<4;a=a+i+1>>1;i=a-i;M=o*R+c*_+128>>8;o=o*_-c*R+128>>8;c=M;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;M=l*C+h*w+2048>>12;l=l*w-h*C+2048>>12;h=M;M=u*y+f*b+2048>>12;u=u*b-f*y+2048>>12;f=M;r[e]=a+h;r[e+7]=a-h;r[e+1]=i+f;r[e+6]=i-f;r[e+2]=o+u;r[e+5]=o-u;r[e+3]=c+l;r[e+4]=c-l}else{M=A*m+512>>10;r[e]=M;r[e+1]=M;r[e+2]=M;r[e+3]=M;r[e+4]=M;r[e+5]=M;r[e+6]=M;r[e+7]=M}}for(let e=0;e<8;++e){m=r[e];g=r[e+8];d=r[e+16];p=r[e+24];x=r[e+32];S=r[e+40];v=r[e+48];I=r[e+56];if(0!==(g|d|p|x|S|v|I)){a=A*m+2048>>12;i=A*x+2048>>12;o=d;c=v;l=B*(g-I)+2048>>12;h=B*(g+I)+2048>>12;u=p;f=S;a=4112+(a+i+1>>1);i=a-i;M=o*R+c*_+2048>>12;o=o*_-c*R+2048>>12;c=M;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;M=l*C+h*w+2048>>12;l=l*w-h*C+2048>>12;h=M;M=u*y+f*b+2048>>12;u=u*b-f*y+2048>>12;f=M;m=a+h;I=a-h;g=i+f;v=i-f;d=o+u;S=o-u;p=c+l;x=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;x<16?x=0:x>=4080?x=255:x>>=4;S<16?S=0:S>=4080?S=255:S>>=4;v<16?v=0:v>=4080?v=255:v>>=4;I<16?I=0:I>=4080?I=255:I>>=4;s[t+e]=m;s[t+e+8]=g;s[t+e+16]=d;s[t+e+24]=p;s[t+e+32]=x;s[t+e+40]=S;s[t+e+48]=v;s[t+e+56]=I}else{M=A*m+8192>>14;M=M<-2040?0:M>=2024?255:M+2056>>4;s[t+e]=M;s[t+e+8]=M;s[t+e+16]=M;s[t+e+24]=M;s[t+e+32]=M;s[t+e+40]=M;s[t+e+48]=M;s[t+e+56]=M}}}function buildComponentData(e,t){const r=t.blocksPerLine,n=t.blocksPerColumn,s=new Int16Array(64);for(let e=0;e<n;e++)for(let n=0;n<r;n++){quantizeAndInverse(t,getBlockBufferOffset(t,e,n),s)}return t.blockData}function findNextFileMarker(e,t,r,n=r){const s=e.length-1;let a=n<r?n:r;if(r>=s)return null;const i=t.getUint16(r);if(i>=65472&&i<=65534)return{invalid:null,marker:i,offset:r};let o=t.getUint16(a);for(;!(o>=65472&&o<=65534);){if(++a>=s)return null;o=t.getUint16(a)}return{invalid:i.toString(16),marker:o,offset:a}}function prepareComponents(e){const t=Math.ceil(e.samplesPerLine/8/e.maxH),r=Math.ceil(e.scanLines/8/e.maxV);for(const n of e.components){const s=Math.ceil(Math.ceil(e.samplesPerLine/8)*n.h/e.maxH),a=Math.ceil(Math.ceil(e.scanLines/8)*n.v/e.maxV),i=t*n.h,o=64*(r*n.v)*(i+1);n.blockData=new Int16Array(o);n.blocksPerLine=s;n.blocksPerColumn=a}e.mcusPerLine=t;e.mcusPerColumn=r}function readDataBlock(e,t,r){const n=t.getUint16(r);let s=(r+=2)+n-2;const a=findNextFileMarker(e,t,s,r);if(a?.invalid){warn("readDataBlock - incorrect length, current marker is: "+a.invalid);s=a.offset}const i=e.subarray(r,s);return{appData:i,oldOffset:r,newOffset:r+i.length}}function skipData(e,t,r){const n=t.getUint16(r),s=(r+=2)+n-2,a=findNextFileMarker(e,t,s,r);return a?.invalid?a.offset:s}class JpegImage{constructor({decodeTransform:e=null,colorTransform:t=-1}={}){this._decodeTransform=e;this._colorTransform=t}static canUseImageDecoder(e,t=-1){const r=new DataView(e.buffer,e.byteOffset,e.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;e:for(;65497!==i;){switch(i){case 65505:const{appData:t,oldOffset:o,newOffset:c}=readDataBlock(e,r,s);s=c;if(69===t[0]&&120===t[1]&&105===t[2]&&102===t[3]&&0===t[4]&&0===t[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=e[s+7];break e;case 65535:255!==e[s]&&s--}s=skipData(e,r,s);i=r.getUint16(s);s+=2}return 4===a||3===a&&0===t?null:n||{}}parse(e,{dnlScanLines:t=null}={}){const r=new DataView(e.buffer,e.byteOffset,e.byteLength),n=e.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;e:for(;65497!==m;){let g,d,b;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(e,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 t=e[i++],n=new Uint16Array(64);if(t>>4){if(t>>4!=1)throw new JpegError("DQT - invalid table spec");for(d=0;d<64;d++){R=p[d];n[R]=r.getUint16(i);i+=2}}else for(d=0;d<64;d++){R=p[d];n[R]=e[i++]}u[15&t]=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=e[i++];const A=r.getUint16(i);i+=2;s.scanLines=t||A;s.samplesPerLine=r.getUint16(i);i+=2;s.components=[];s.componentIds={};const B=e[i++];let x=0,S=0;for(g=0;g<B;g++){const t=e[i],r=e[i+1]>>4,n=15&e[i+1];x<r&&(x=r);S<n&&(S=n);const a=e[i+2];b=s.components.push({h:r,v:n,quantizationId:a,quantizationTable:null});s.componentIds[t]=b-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 t=e[i++],r=new Uint8Array(16);let n=0;for(d=0;d<16;d++,i++)n+=r[d]=e[i];const s=new Uint8Array(n);for(d=0;d<n;d++,i++)s[d]=e[i];g+=17+n;(t>>4?f:h)[15&t]=buildHuffmanTable(r,s)}break;case 65501:i+=2;a=r.getUint16(i);i+=2;break;case 65498:const I=1===++l&&!t;i+=2;const M=e[i++],k=[];for(g=0;g<M;g++){const t=e[i++],r=s.componentIds[t],n=s.components[r];n.index=t;const a=e[i++];n.huffmanTableDC=h[a>>4];n.huffmanTableAC=f[15&a];k.push(n)}const D=e[i++],E=e[i++],T=e[i++];try{i+=decodeScan(e,r,i,s,k,a,D,E,T>>4,15&T,I)}catch(t){if(t instanceof DNLMarkerError){warn(`${t.message} -- attempting to re-parse the JPEG image.`);return this.parse(e,{dnlScanLines:t.scanLines})}if(t instanceof EOIMarkerError){warn(`${t.message} -- ignoring the rest of the image data.`);break e}throw t}break;case 65500:i+=4;break;case 65535:255!==e[i]&&i--;break;default:const P=findNextFileMarker(e,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 e}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 e of s.components){const t=u[e.quantizationId];t&&(e.quantizationTable=t);this.components.push({index:e.index,output:buildComponentData(0,e),scaleX:e.h/s.maxH,scaleY:e.v/s.maxV,blocksPerLine:e.blocksPerLine,blocksPerColumn:e.blocksPerColumn})}this.numComponents=this.components.length}_getLinearizedBlockData(e,t,r=!1){const n=this.width/e,s=this.height/t;let a,i,o,c,l,u,f,h,m,g,d,p=0;const b=this.components.length,y=e*t*b,w=new Uint8ClampedArray(y),C=new Uint32Array(e),_=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<e;l++){h=0|l*i;C[l]=(h&_)<<3|7&h}R=i}for(u=0;u<t;u++){h=0|u*o;g=c*(h&_)|(7&h)<<3;for(l=0;l<e;l++){w[p]=d[g+C[l]];p+=b}}}let A=this._decodeTransform;r||4!==b||A|