UNPKG

pdfjs-dist

Version:

Generic build of Mozilla's PDF.js library.

27 lines • 538 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.5.438
 * pdfjsBuild = 0a4153349
 */var t={463(t){var e=TypeError;t.exports=function(t){if("string"==typeof t)return t;throw new e("Argument is not a string")}},804(t){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",i=e+"+/",n=e+"-_",inverse=function(t){for(var e={},i=0;i<64;i++)e[t.charAt(i)]=i;return e};t.exports={i2c:i,c2i:inverse(i),i2cUrl:n,c2iUrl:inverse(n)}},529(t){t.exports=function(t,e){return{value:t,done:e}}},837(t){var e=TypeError;t.exports=function(t){if(t>9007199254740991)throw new e("Maximum allowed index exceeded");return t}},2(t){t.exports={IndexSizeError:{s:"INDEX_SIZE_ERR",c:1,m:1},DOMStringSizeError:{s:"DOMSTRING_SIZE_ERR",c:2,m:0},HierarchyRequestError:{s:"HIERARCHY_REQUEST_ERR",c:3,m:1},WrongDocumentError:{s:"WRONG_DOCUMENT_ERR",c:4,m:1},InvalidCharacterError:{s:"INVALID_CHARACTER_ERR",c:5,m:1},NoDataAllowedError:{s:"NO_DATA_ALLOWED_ERR",c:6,m:0},NoModificationAllowedError:{s:"NO_MODIFICATION_ALLOWED_ERR",c:7,m:1},NotFoundError:{s:"NOT_FOUND_ERR",c:8,m:1},NotSupportedError:{s:"NOT_SUPPORTED_ERR",c:9,m:1},InUseAttributeError:{s:"INUSE_ATTRIBUTE_ERR",c:10,m:1},InvalidStateError:{s:"INVALID_STATE_ERR",c:11,m:1},SyntaxError:{s:"SYNTAX_ERR",c:12,m:1},InvalidModificationError:{s:"INVALID_MODIFICATION_ERR",c:13,m:1},NamespaceError:{s:"NAMESPACE_ERR",c:14,m:1},InvalidAccessError:{s:"INVALID_ACCESS_ERR",c:15,m:1},ValidationError:{s:"VALIDATION_ERR",c:16,m:0},TypeMismatchError:{s:"TYPE_MISMATCH_ERR",c:17,m:1},SecurityError:{s:"SECURITY_ERR",c:18,m:1},NetworkError:{s:"NETWORK_ERR",c:19,m:1},AbortError:{s:"ABORT_ERR",c:20,m:1},URLMismatchError:{s:"URL_MISMATCH_ERR",c:21,m:1},QuotaExceededError:{s:"QUOTA_EXCEEDED_ERR",c:22,m:1},TimeoutError:{s:"TIMEOUT_ERR",c:23,m:1},InvalidNodeTypeError:{s:"INVALID_NODE_TYPE_ERR",c:24,m:1},DataCloneError:{s:"DATA_CLONE_ERR",c:25,m:1}}},944(t){var e=TypeError;t.exports=function(t){var i=t&&t.alphabet;if(void 0===i||"base64"===i||"base64url"===i)return i||"base64";throw new e("Incorrect `alphabet` option")}},767(t){t.exports=function(t){return{iterator:t,next:t.next,done:!1}}},117(t){t.exports=function(t){return null==t}},859(t){t.exports=function(t){t.iterator=t.next=t.nextHandler=t.mapper=t.predicate=t.inner=t.iterables=t.iters=t.openIters=t.padding=t.finishResults=t.buffer=null}},684(t){t.exports=function(t,e){var i="function"==typeof Iterator&&Iterator.prototype[t];if(i)try{i.call({next:null},e).next()}catch(t){return!0}}},269(t){t.exports=Object.create?Object.create(null):{}},741(t){var e=Math.ceil,i=Math.floor;t.exports=Math.trunc||function trunc(t){var n=+t;return(n>0?i:e)(n)}},149(t){var e=RangeError;t.exports=function(t){if(t==t)return t;throw new e("NaN is not allowed")}},717(t,e){e.f=Object.getOwnPropertySymbols},103(t){t.exports=function(t){try{return{error:!1,value:t()}}catch(t){return{error:!0,value:t}}}},750(t,e,i){var n=i(117),r=TypeError;t.exports=function(t){if(n(t))throw new r("Can't call method on "+t);return t}},835(t){t.exports=function(t){try{var e=new Set,i={size:0,has:function(){return!0},keys:function(){return Object.defineProperty({},"next",{get:function(){e.clear();e.add(4);return function(){return{done:!0}}}})}},n=e[t](i);return 1===n.size&&4===n.values().next().value}catch(t){return!1}}},291(t,e,i){var n=i(741);t.exports=function(t){var e=+t;return e!=e||0===e?0:n(e)}},14(t,e,i){var n=i(291),r=Math.min;t.exports=function(t){var e=n(t);return e>0?r(e,9007199254740991):0}},981(t,e,i){var n=i(750),r=Object;t.exports=function(t){return r(n(t))}},590(t,e,i){var n=i(291),r=RangeError;t.exports=function(t){var e=n(t);if(e<0)throw new r("The argument can't be less than 0");return e}},812(t){var e=TypeError;t.exports=function(t,i){if(t<i)throw new e("Not enough arguments");return t}}};const e={};function __webpack_require__(i){const n=e[i];if(void 0!==n)return n.exports;const r=e[i]={exports:{}};t[i](r,r.exports,__webpack_require__);return r.exports}__webpack_require__.cw=t=>{var e;return()=>{if(t){var i=t;t=0;e={exports:{}};i.call(e.exports,e,e.exports)}return e.exports}};__webpack_require__.d=(t,e)=>{for(var i in e)__webpack_require__.o(e,i)&&!__webpack_require__.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})};__webpack_require__.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var i=__webpack_require__.cw(t=>{var e=mt(),i=ve(),n=TypeError;t.exports=function(t){if(e(t))return t;throw new n(i(t)+" is not a function")}}),n=__webpack_require__.cw(t=>{var e=yt(),i=String,n=TypeError;t.exports=function(t){if(e(t))return t;throw new n("Can't set "+i(t)+" as a prototype")}}),r=__webpack_require__.cw(t=>{var e=Qt().has;t.exports=function(t){e(t);return t}}),a_string_namespaceFn=()=>__webpack_require__(463),s=__webpack_require__.cw(t=>{var e=ke(),i=new e.WeakMap,n=e.set,r=e.remove;t.exports=function(t){n(i,t,1);r(i,t);return t}}),a=__webpack_require__.cw(t=>{var e=ke().has;t.exports=function(t){e(t);return t}}),o=__webpack_require__.cw(t=>{var e=Pe(),i=Rt(),n=Lt().f,r=e("unscopables"),s=Array.prototype;void 0===s[r]&&n(s,r,{configurable:!0,value:i(null)});t.exports=function(t){s[r][t]=!0}}),l=__webpack_require__.cw(t=>{var e=zt(),i=TypeError;t.exports=function(t,n){if(e(n,t))return t;throw new i("Incorrect invocation")}}),c=__webpack_require__.cw(t=>{var e=bt(),i=String,n=TypeError;t.exports=function(t){if(void 0===t||e(t))return t;throw new n(i(t)+" is not an object or undefined")}}),h=__webpack_require__.cw(t=>{var e=bt(),i=String,n=TypeError;t.exports=function(t){if(e(t))return t;throw new n(i(t)+" is not an object")}}),d=__webpack_require__.cw(t=>{var e=x(),i=TypeError;t.exports=function(t){if("Uint8Array"===e(t))return t;throw new i("Argument is not an Uint8Array")}}),u=__webpack_require__.cw(t=>{t.exports="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView}),p=__webpack_require__.cw(t=>{var e=it(),i=$(),n=A(),r=e.ArrayBuffer,s=e.TypeError;t.exports=r&&i(r.prototype,"byteLength","get")||function(t){if("ArrayBuffer"!==n(t))throw new s("ArrayBuffer expected");return t.byteLength}}),g=__webpack_require__.cw(t=>{var e=it(),i=u(),n=p(),r=e.DataView;t.exports=function(t){if(!i||0!==n(t))return!1;try{new r(t);return!1}catch(t){return!0}}}),m=__webpack_require__.cw(t=>{var e=g(),i=TypeError;t.exports=function(t){if(e(t))throw new i("ArrayBuffer is detached");return t}}),f=__webpack_require__.cw(t=>{var e,i,n,r=u(),s=O(),a=it(),o=mt(),l=bt(),c=nt(),h=x(),d=ve(),p=S(),g=M(),m=P(),f=zt(),b=Ht(),y=Vt(),w=Pe(),v=_e(),_=dt(),A=_.enforce,C=_.get,E=a.Int8Array,T=E&&E.prototype,k=a.Uint8ClampedArray,D=k&&k.prototype,I=E&&b(E),R=T&&b(T),B=Object.prototype,L=a.TypeError,N=w("toStringTag"),U=v("TYPED_ARRAY_TAG"),H="TypedArrayConstructor",z=r&&!!y&&"Opera"!==h(a.opera),G=!1,W={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},j={BigInt64Array:8,BigUint64Array:8},getTypedArrayConstructor=function(t){var e=b(t);if(l(e)){var i=C(e);return i&&c(i,H)?i[H]:getTypedArrayConstructor(e)}},isTypedArray=function(t){if(!l(t))return!1;var e=h(t);return c(W,e)||c(j,e)};for(e in W)(n=(i=a[e])&&i.prototype)?A(n)[H]=i:z=!1;for(e in j)(n=(i=a[e])&&i.prototype)&&(A(n)[H]=i);if(!z||!o(I)||I===Function.prototype){I=function TypedArray(){throw new L("Incorrect invocation")};if(z)for(e in W)a[e]&&y(a[e],I)}if(!z||!R||R===B){R=I.prototype;if(z)for(e in W)a[e]&&y(a[e].prototype,R)}z&&b(D)!==R&&y(D,R);if(s&&!c(R,N)){G=!0;m(R,N,{configurable:!0,get:function(){return l(this)?this[U]:void 0}});for(e in W)a[e]&&p(a[e].prototype,U,e)}t.exports={NATIVE_ARRAY_BUFFER_VIEWS:z,TYPED_ARRAY_TAG:G&&U,aTypedArray:function(t){if(isTypedArray(t))return t;throw new L("Target is not a typed array")},aTypedArrayConstructor:function(t){if(o(t)&&(!y||f(I,t)))return t;throw new L(d(t)+" is not a typed array constructor")},exportTypedArrayMethod:function(t,e,i,n){if(s){if(i)for(var r in W){var o=a[r];if(o&&c(o.prototype,t))try{delete o.prototype[t]}catch(i){try{o.prototype[t]=e}catch(t){}}}R[t]&&!i||g(R,t,i?e:z&&T[t]||e,n)}},exportTypedArrayStaticMethod:function(t,e,i){var n,r;if(s){if(y){if(i)for(n in W)if((r=a[n])&&c(r,t))try{delete r[t]}catch(t){}if(I[t]&&!i)return;try{return g(I,t,i?e:z&&I[t]||e)}catch(t){}}for(n in W)!(r=a[n])||r[t]&&!i||g(r,t,e)}},getTypedArrayConstructor,isView:function isView(t){if(!l(t))return!1;var e=h(t);return"DataView"===e||c(W,e)||c(j,e)},isTypedArray,TypedArray:I,TypedArrayPrototype:R}}),b=__webpack_require__.cw(t=>{var e=Pt();t.exports=function(t,i,n){for(var r=0,s=arguments.length>2?n:e(i),a=new t(s);s>r;)a[r]=i[r++];return a}}),y=__webpack_require__.cw(t=>{var e=me(),i=pe(),n=Pt(),createMethod=function(t){return function(r,s,a){var o=e(r),l=n(o);if(0===l)return!t&&-1;var c,h=i(a,l);if(t&&s!=s){for(;l>h;)if((c=o[h++])!=c)return!0}else for(;l>h;h++)if((t||h in o)&&o[h]===s)return t||h||0;return!t&&-1}};t.exports={includes:createMethod(!0),indexOf:createMethod(!1)}}),w=__webpack_require__.cw(t=>{var e=O(),i=pt(),n=TypeError,r=Object.getOwnPropertyDescriptor,s=e&&!function(){if(void 0!==this)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(t){return t instanceof TypeError}}();t.exports=s?function(t,e){if(i(t)&&!r(t,"length").writable)throw new n("Cannot set read only .length");return t.length=e}:function(t,e){return t.length=e}}),v=__webpack_require__.cw(t=>{var e=K();t.exports=e([].slice)}),base64_map_namespaceFn=()=>__webpack_require__(804),_=__webpack_require__.cw(t=>{var e=h(),i=Et();t.exports=function(t,n,r,s){try{return s?n(e(r)[0],r[1]):n(r)}catch(e){i(t,"throw",e)}}}),A=__webpack_require__.cw(t=>{var e=K(),i=e({}.toString),n=e("".slice);t.exports=function(t){return n(i(t),8,-1)}}),x=__webpack_require__.cw(t=>{var e=ye(),i=mt(),n=A(),r=Pe()("toStringTag"),s=Object,a="Arguments"===n(function(){return arguments}());t.exports=e?n:function(t){var e,o,l;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(o=function(t,e){try{return t[e]}catch(t){}}(e=s(t),r))?o:a?n(e):"Object"===(l=n(e))&&i(e.callee)?"Arguments":l}}),C=__webpack_require__.cw(t=>{var e=nt(),i=$t(),n=Nt(),r=Lt();t.exports=function(t,s,a){for(var o=i(s),l=r.f,c=n.f,h=0;h<o.length;h++){var d=o[h];e(t,d)||a&&e(a,d)||l(t,d,c(s,d))}}}),E=__webpack_require__.cw(t=>{var e=z();t.exports=!e(function(){function F(){}F.prototype.constructor=null;return Object.getPrototypeOf(new F)!==F.prototype})}),S=__webpack_require__.cw(t=>{var e=O(),i=Lt(),n=T();t.exports=e?function(t,e,r){return i.f(t,e,n(1,r))}:function(t,e,i){t[e]=i;return t}}),T=__webpack_require__.cw(t=>{t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}}),k=__webpack_require__.cw(t=>{var e=O(),i=Lt(),n=T();t.exports=function(t,r,s){e?i.f(t,r,n(0,s)):t[r]=s}}),P=__webpack_require__.cw(t=>{var e=Mt(),i=Lt();t.exports=function(t,n,r){r.get&&e(r.get,n,{getter:!0});r.set&&e(r.set,n,{setter:!0});return i.f(t,n,r)}}),M=__webpack_require__.cw(t=>{var e=mt(),i=Lt(),n=Mt(),r=I();t.exports=function(t,s,a,o){o||(o={});var l=o.enumerable,c=void 0!==o.name?o.name:s;e(a)&&n(a,c,o);if(o.global)l?t[s]=a:r(s,a);else{try{o.unsafe?t[s]&&(l=!0):delete t[s]}catch(t){}l?t[s]=a:i.f(t,s,{value:a,enumerable:!1,configurable:!o.nonConfigurable,writable:!o.nonWritable})}return t}}),D=__webpack_require__.cw(t=>{var e=M();t.exports=function(t,i,n){for(var r in i)e(t,r,i[r],n);return t}}),I=__webpack_require__.cw(t=>{var e=it(),i=Object.defineProperty;t.exports=function(t,n){try{i(e,t,{value:n,configurable:!0,writable:!0})}catch(i){e[t]=n}return n}}),O=__webpack_require__.cw(t=>{var e=z();t.exports=!e(function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]})}),R=__webpack_require__.cw(t=>{var e=it(),i=bt(),n=e.document,r=i(n)&&i(n.createElement);t.exports=function(t){return r?n.createElement(t):{}}}),B=__webpack_require__.cw(t=>{t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]}),L=__webpack_require__.cw(t=>{var e=it().navigator,i=e&&e.userAgent;t.exports=i?String(i):""}),N=__webpack_require__.cw(t=>{var e,i,n=it(),r=L(),s=n.process,a=n.Deno,o=s&&s.versions||a&&a.version,l=o&&o.v8;l&&(i=(e=l.split("."))[0]>0&&e[0]<4?1:+(e[0]+e[1]));!i&&r&&(!(e=r.match(/Edge\/(\d+)/))||e[1]>=74)&&(e=r.match(/Chrome\/(\d+)/))&&(i=+e[1]);t.exports=i}),U=__webpack_require__.cw(t=>{var e=K(),i=Error,n=e("".replace),r=String(new i("zxcasd").stack),s=/\n\s*at [^:]*:[^\n]*/,a=s.test(r);t.exports=function(t,e){if(a&&"string"==typeof t&&!i.prepareStackTrace)for(;e--;)t=n(t,s,"");return t}}),H=__webpack_require__.cw(t=>{var e=it(),i=Nt().f,n=S(),r=M(),s=I(),a=C(),o=ft();t.exports=function(t,l){var c,h,d,u,p,g=t.target,m=t.global,f=t.stat;if(c=m?e:f?e[g]||s(g,{}):e[g]&&e[g].prototype)for(h in l){u=l[h];d=t.dontCallGetSet?(p=i(c,h))&&p.value:c[h];if(!o(m?h:g+(f?".":"#")+h,t.forced)&&void 0!==d){if(typeof u==typeof d)continue;a(u,d)}(t.sham||d&&d.sham)&&n(u,"sham",!0);r(c,h,u,t)}}}),z=__webpack_require__.cw(t=>{t.exports=function(t){try{return!!t()}catch(t){return!0}}}),G=__webpack_require__.cw(t=>{var e=j(),i=Function.prototype,n=i.apply,r=i.call;t.exports="object"==typeof Reflect&&Reflect.apply||(e?r.bind(n):function(){return r.apply(n,arguments)})}),W=__webpack_require__.cw(t=>{var e=X(),n=i(),r=j(),s=e(e.bind);t.exports=function(t,e){n(t);return void 0===e?t:r?s(t,e):function(){return t.apply(e,arguments)}}}),j=__webpack_require__.cw(t=>{var e=z();t.exports=!e(function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})}),V=__webpack_require__.cw(t=>{var e=j(),i=Function.prototype.call;t.exports=e?i.bind(i):function(){return i.apply(i,arguments)}}),q=__webpack_require__.cw(t=>{var e=O(),i=nt(),n=Function.prototype,r=e&&Object.getOwnPropertyDescriptor,s=i(n,"name"),a=s&&(!e||e&&r(n,"name").configurable);t.exports={CONFIGURABLE:a}}),$=__webpack_require__.cw(t=>{var e=K(),n=i();t.exports=function(t,i,r){try{return e(n(Object.getOwnPropertyDescriptor(t,i)[r]))}catch(t){}}}),X=__webpack_require__.cw(t=>{var e=A(),i=K();t.exports=function(t){if("Function"===e(t))return i(t)}}),K=__webpack_require__.cw(t=>{var e=j(),i=Function.prototype,n=i.call,r=e&&i.bind.bind(n,n);t.exports=e?r:function(t){return function(){return n.apply(t,arguments)}}}),get_alphabet_option_namespaceFn=()=>__webpack_require__(944),Y=__webpack_require__.cw(t=>{var e=it(),i=mt();t.exports=function(t,n){return arguments.length<2?(r=e[t],i(r)?r:void 0):e[t]&&e[t][n];var r}}),get_iterator_direct_namespaceFn=()=>__webpack_require__(767),J=__webpack_require__.cw(t=>{var e=V(),i=h(),n=get_iterator_direct_namespaceFn(),r=Z();t.exports=function(t,s){s&&"string"==typeof t||i(t);var a=r(t);return n(i(void 0!==a?e(a,t):t))}}),Q=__webpack_require__.cw(t=>{var e=V(),i=mt(),n=h(),r=ve(),s=Z(),a=TypeError;t.exports=function(t,o){var l=arguments.length<2?s(t):o;if(i(l))return n(e(l,t));throw new a(r(t)+" is not iterable")}}),Z=__webpack_require__.cw(t=>{var e=A(),i=is_null_or_undefined_namespaceFn(),n=tt(),r=Pe()("iterator"),s=Array.prototype;t.exports=function(t){if(!i(t))return n(t,r)||n(t,"@@iterator")||("Arguments"===e(t)?s[r]:void 0)}}),tt=__webpack_require__.cw(t=>{var e=i(),n=is_null_or_undefined_namespaceFn();t.exports=function(t,i){var r=t[i];return n(r)?void 0:e(r)}}),et=__webpack_require__.cw(t=>{var e=i(),n=h(),r=V(),s=to_integer_or_infinity_namespaceFn(),a=get_iterator_direct_namespaceFn(),o="Invalid size",l=RangeError,c=TypeError,d=Math.max,SetRecord=function(t,i){this.set=t;this.size=d(i,0);this.has=e(t.has);this.keys=e(t.keys)};SetRecord.prototype={getIterator:function(){return a(n(r(this.keys,this.set)))},includes:function(t){return r(this.has,this.set,t)}};t.exports=function(t){n(t);var e=+t.size;if(e!=e)throw new c(o);var i=s(e);if(i<0)throw new l(o);return new SetRecord(t,i)}}),it=__webpack_require__.cw(function(t){var check=function(t){return t&&t.Math===Math&&t};t.exports=check("object"==typeof globalThis&&globalThis)||check("object"==typeof window&&window)||check("object"==typeof self&&self)||check("object"==typeof global&&global)||check("object"==typeof this&&this)||function(){return this}()||Function("return this")()}),nt=__webpack_require__.cw(t=>{var e=K(),i=to_object_namespaceFn(),n=e({}.hasOwnProperty);t.exports=Object.hasOwn||function hasOwn(t,e){return n(i(t),e)}}),rt=__webpack_require__.cw(t=>{t.exports={}}),st=__webpack_require__.cw(t=>{var e=Y();t.exports=e("document","documentElement")}),ot=__webpack_require__.cw(t=>{var e=O(),i=z(),n=R();t.exports=!e&&!i(function(){return 7!==Object.defineProperty(n("div"),"a",{get:function(){return 7}}).a})}),lt=__webpack_require__.cw(t=>{var e=K(),i=z(),n=A(),r=Object,s=e("".split);t.exports=i(function(){return!r("z").propertyIsEnumerable(0)})?function(t){return"String"===n(t)?s(t,""):r(t)}:r}),ct=__webpack_require__.cw(t=>{var e=mt(),i=bt(),n=Vt();t.exports=function(t,r,s){var a,o;n&&e(a=r.constructor)&&a!==s&&i(o=a.prototype)&&o!==s.prototype&&n(t,o);return t}}),ht=__webpack_require__.cw(t=>{var e=K(),i=mt(),n=ce(),r=e(Function.toString);i(n.inspectSource)||(n.inspectSource=function(t){return r(t)});t.exports=n.inspectSource}),dt=__webpack_require__.cw(t=>{var e,i,n,r=Te(),s=it(),a=bt(),o=S(),l=nt(),c=ce(),h=le(),d=rt(),u="Object already initialized",p=s.TypeError,g=s.WeakMap;if(r||c.state){var m=c.state||(c.state=new g);m.get=m.get;m.has=m.has;m.set=m.set;e=function(t,e){if(m.has(t))throw new p(u);e.facade=t;m.set(t,e);return e};i=function(t){return m.get(t)||{}};n=function(t){return m.has(t)}}else{var f=h("state");d[f]=!0;e=function(t,e){if(l(t,f))throw new p(u);e.facade=t;o(t,f,e);return e};i=function(t){return l(t,f)?t[f]:{}};n=function(t){return l(t,f)}}t.exports={set:e,get:i,has:n,enforce:function(t){return n(t)?i(t):e(t,{})},getterFor:function(t){return function(e){var n;if(!a(e)||(n=i(e)).type!==t)throw new p("Incompatible receiver, "+t+" required");return n}}}}),ut=__webpack_require__.cw(t=>{var e=Pe(),i=iterators_namespaceFn(),n=e("iterator"),r=Array.prototype;t.exports=function(t){return void 0!==t&&(i.Array===t||r[n]===t)}}),pt=__webpack_require__.cw(t=>{var e=A();t.exports=Array.isArray||function isArray(t){return"Array"===e(t)}}),gt=__webpack_require__.cw(t=>{var e=x();t.exports=function(t){var i=e(t);return"BigInt64Array"===i||"BigUint64Array"===i}}),mt=__webpack_require__.cw(t=>{var e="object"==typeof document&&document.all;t.exports=void 0===e&&void 0!==e?function(t){return"function"==typeof t||t===e}:function(t){return"function"==typeof t}}),ft=__webpack_require__.cw(t=>{var e=z(),i=mt(),n=/#|\.prototype\./,isForced=function(t,n){var l=s[r(t)];return l===o||l!==a&&(i(n)?e(n):!!n)},r=isForced.normalize=function(t){return String(t).replace(n,".").toLowerCase()},s=isForced.data={},a=isForced.NATIVE="N",o=isForced.POLYFILL="P";t.exports=isForced}),is_null_or_undefined_namespaceFn=()=>__webpack_require__(117),bt=__webpack_require__.cw(t=>{var e=mt();t.exports=function(t){return"object"==typeof t?null!==t:e(t)}}),yt=__webpack_require__.cw(t=>{var e=bt();t.exports=function(t){return e(t)||null===t}}),wt=__webpack_require__.cw(t=>{t.exports=!1}),vt=__webpack_require__.cw(t=>{var e=bt(),i=dt().get;t.exports=function isRawJSON(t){if(!e(t))return!1;var n=i(t);return!!n&&"RawJSON"===n.type}}),_t=__webpack_require__.cw(t=>{var e=Y(),i=mt(),n=zt(),r=Ee(),s=Object;t.exports=r?function(t){return"symbol"==typeof t}:function(t){var r=e("Symbol");return i(r)&&n(r.prototype,s(t))}}),At=__webpack_require__.cw(t=>{var e=V();t.exports=function(t,i,n){for(var r,s,a=n?t:t.iterator,o=t.next;!(r=e(o,a)).done;)if(void 0!==(s=i(r.value)))return s}}),xt=__webpack_require__.cw(t=>{var e=W(),i=V(),n=h(),r=ve(),s=ut(),a=Pt(),o=zt(),l=Q(),c=Z(),d=Et(),u=TypeError,Result=function(t,e){this.stopped=t;this.result=e},p=Result.prototype;t.exports=function(t,h,g){var m,f,b,y,w,v,_,A=g&&g.that,x=!(!g||!g.AS_ENTRIES),C=!(!g||!g.IS_RECORD),E=!(!g||!g.IS_ITERATOR),S=!(!g||!g.INTERRUPTED),T=e(h,A),stop=function(t){var e=m;m=void 0;e&&d(e,"normal");return new Result(!0,t)},callFn=function(t){if(x){n(t);return S?T(t[0],t[1],stop):T(t[0],t[1])}return S?T(t,stop):T(t)};if(C)m=t.iterator;else if(E)m=t;else{if(!(f=c(t)))throw new u(r(t)+" is not iterable");if(s(f)){for(b=0,y=a(t);y>b;b++)if((w=callFn(t[b]))&&o(p,w))return w;return new Result(!1)}m=l(t,f)}v=C?t.next:m.next;for(;!(_=i(v,m)).done;){var k=_.value;try{w=callFn(k)}catch(t){if(!m)throw t;d(m,"throw",t)}if("object"==typeof w&&w&&o(p,w))return w}return new Result(!1)}}),Ct=__webpack_require__.cw(t=>{var e=Et();t.exports=function(t,i,n){for(var r=t.length-1;r>=0;r--)if(void 0!==t[r])try{n=e(t[r].iterator,i,n)}catch(t){i="throw";n=t}if("throw"===i)throw n;return n}}),Et=__webpack_require__.cw(t=>{var e=V(),i=h(),n=tt();t.exports=function(t,r,s){var a,o;i(t);try{if(!(a=n(t,"return"))){if("throw"===r)throw s;return s}a=e(a,t)}catch(t){o=!0;a=t}if("throw"===r)throw s;if(o)throw a;i(a);return s}}),St=__webpack_require__.cw(t=>{var e=V(),i=Rt(),n=S(),r=D(),s=Pe(),a=dt(),o=tt(),l=kt().IteratorPrototype,c=__webpack_require__(529),h=Et(),d=Ct(),u=__webpack_require__(859),p=s("toStringTag"),g="IteratorHelper",m="WrapForValidIterator",f="normal",b="throw",y=a.set,createIteratorProxyPrototype=function(t){var n=a.getterFor(t?m:g);return r(i(l),{next:function next(){var e=n(this);if(t)return e.nextHandler();if(e.done)return c(void 0,!0);try{var i=e.nextHandler();e.done&&u(e);return e.returnHandlerResult?i:c(i,e.done)}catch(t){e.done=!0;u(e);throw t}},return:function(){var i=n(this),r=i.iterator,s=i.inner,a=i.openIters,l=i.done;i.done=!0;if(t){var p=o(r,"return");return p?e(p,r):c(void 0,!0)}u(i);if(l)return c(void 0,!0);if(s)try{h(s.iterator,f)}catch(t){return h(r,b,t)}if(a)try{d(a,f)}catch(t){if(r)return h(r,b,t);throw t}r&&h(r,f);return c(void 0,!0)}})},w=createIteratorProxyPrototype(!0),v=createIteratorProxyPrototype(!1);n(v,p,"Iterator Helper");t.exports=function(t,e,i){var n=function Iterator(n,r){if(r){r.iterator=n.iterator;r.next=n.next}else r=n;r.type=e?m:g;r.returnHandlerResult=!!i;r.nextHandler=t;r.counter=0;r.done=!1;y(this,r)};n.prototype=e?w:v;return n}}),iterator_helper_throws_on_invalid_iterator_namespaceFn=()=>__webpack_require__(684),Tt=__webpack_require__.cw(t=>{var e=it();t.exports=function(t,i){var n=e.Iterator,r=n&&n.prototype,s=r&&r[t],a=!1;if(s)try{s.call({next:function(){return{done:!0}},return:function(){a=!0}},-1)}catch(t){t instanceof i||(a=!1)}if(!a)return s}}),kt=__webpack_require__.cw(t=>{var e,i,n,r=z(),s=mt(),a=bt(),o=Rt(),l=Ht(),c=M(),h=Pe(),d=wt(),u=h("iterator");[].keys&&("next"in(n=[].keys())?(i=l(l(n)))!==Object.prototype&&(e=i):!0);!a(e)||r(function(){var t={};return e[u].call(t)!==t})?e={}:d&&(e=o(e));s(e[u])||c(e,u,function(){return this});t.exports={IteratorPrototype:e}}),iterators_namespaceFn=()=>__webpack_require__(269),Pt=__webpack_require__.cw(t=>{var e=to_length_namespaceFn();t.exports=function(t){return e(t.length)}}),Mt=__webpack_require__.cw(t=>{var e=K(),i=z(),n=mt(),r=nt(),s=O(),a=q().CONFIGURABLE,o=ht(),l=dt(),c=l.enforce,h=l.get,d=String,u=Object.defineProperty,p=e("".slice),g=e("".replace),m=e([].join),f=s&&!i(function(){return 8!==u(function(){},"length",{value:8}).length}),b=String(String).split("String"),y=t.exports=function(t,e,i){"Symbol("===p(d(e),0,7)&&(e="["+g(d(e),/^Symbol\(([^)]*)\).*$/,"$1")+"]");i&&i.getter&&(e="get "+e);i&&i.setter&&(e="set "+e);(!r(t,"name")||a&&t.name!==e)&&(s?u(t,"name",{value:e,configurable:!0}):t.name=e);f&&i&&r(i,"arity")&&t.length!==i.arity&&u(t,"length",{value:i.arity});try{i&&r(i,"constructor")&&i.constructor?s&&u(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch(t){}var n=c(t);r(n,"source")||(n.source=m(b,"string"==typeof e?e:""));return t};Function.prototype.toString=y(function toString(){return n(this)&&h(this).source||o(this)},"toString")}),Dt=__webpack_require__.cw(t=>{var e=K(),i=Map.prototype;t.exports={Map,set:e(i.set),get:e(i.get),has:e(i.has),remove:e(i.delete),proto:i}}),It=__webpack_require__.cw(t=>{var e=z();t.exports=!e(function(){var t="9007199254740993",e=JSON.rawJSON(t);return!JSON.isRawJSON(e)||JSON.stringify(e)!==t})}),Ft=__webpack_require__.cw(t=>{var e=i(),n=TypeError,PromiseCapability=function(t){var i,r;this.promise=new t(function(t,e){if(void 0!==i||void 0!==r)throw new n("Bad Promise constructor");i=t;r=e});this.resolve=e(i);this.reject=e(r)};t.exports.f=function(t){return new PromiseCapability(t)}}),Ot=__webpack_require__.cw(t=>{var e=we();t.exports=function(t,i){return void 0===t?arguments.length<2?"":i:e(t)}}),not_a_nan_namespaceFn=()=>__webpack_require__(149),Rt=__webpack_require__.cw(t=>{var e,i=h(),n=Bt(),r=B(),s=rt(),a=st(),o=R(),l=le(),c="prototype",d="script",u=l("IE_PROTO"),EmptyConstructor=function(){},scriptTag=function(t){return"<"+d+">"+t+"</"+d+">"},NullProtoObjectViaActiveX=function(t){t.write(scriptTag(""));t.close();var e=t.parentWindow.Object;t=null;return e},NullProtoObject=function(){try{e=new ActiveXObject("htmlfile")}catch(t){}NullProtoObject="undefined"!=typeof document?document.domain&&e?NullProtoObjectViaActiveX(e):function(){var t,e=o("iframe"),i="java"+d+":";e.style.display="none";a.appendChild(e);e.src=String(i);(t=e.contentWindow.document).open();t.write(scriptTag("document.F=Object"));t.close();return t.F}():NullProtoObjectViaActiveX(e);for(var t=r.length;t--;)delete NullProtoObject[c][r[t]];return NullProtoObject()};s[u]=!0;t.exports=Object.create||function create(t,e){var r;if(null!==t){EmptyConstructor[c]=i(t);r=new EmptyConstructor;EmptyConstructor[c]=null;r[u]=t}else r=NullProtoObject();return void 0===e?r:n.f(r,e)}}),Bt=__webpack_require__.cw((t,e)=>{var i=O(),n=Se(),r=Lt(),s=h(),a=me(),o=Wt();e.f=i&&!n?Object.defineProperties:function defineProperties(t,e){s(t);for(var i,n=a(e),l=o(e),c=l.length,h=0;c>h;)r.f(t,i=l[h++],n[i]);return t}}),Lt=__webpack_require__.cw((t,e)=>{var i=O(),n=ot(),r=Se(),s=h(),a=be(),o=TypeError,l=Object.defineProperty,c=Object.getOwnPropertyDescriptor,d="enumerable",u="configurable",p="writable";e.f=i?r?function defineProperty(t,e,i){s(t);e=a(e);s(i);if("function"==typeof t&&"prototype"===e&&"value"in i&&p in i&&!i[p]){var n=c(t,e);if(n&&n[p]){t[e]=i.value;i={configurable:u in i?i[u]:n[u],enumerable:d in i?i[d]:n[d],writable:!1}}}return l(t,e,i)}:l:function defineProperty(t,e,i){s(t);e=a(e);s(i);if(n)try{return l(t,e,i)}catch(t){}if("get"in i||"set"in i)throw new o("Accessors not supported");"value"in i&&(t[e]=i.value);return t}}),Nt=__webpack_require__.cw((t,e)=>{var i=O(),n=V(),r=jt(),s=T(),a=me(),o=be(),l=nt(),c=ot(),h=Object.getOwnPropertyDescriptor;e.f=i?h:function getOwnPropertyDescriptor(t,e){t=a(t);e=o(e);if(c)try{return h(t,e)}catch(t){}if(l(t,e))return s(!n(r.f,t,e),t[e])}}),Ut=__webpack_require__.cw((t,e)=>{var i=Gt(),n=B().concat("length","prototype");e.f=Object.getOwnPropertyNames||function getOwnPropertyNames(t){return i(t,n)}}),Ht=__webpack_require__.cw(t=>{var e=nt(),i=mt(),n=to_object_namespaceFn(),r=le(),s=E(),a=r("IE_PROTO"),o=Object,l=o.prototype;t.exports=s?o.getPrototypeOf:function(t){var r=n(t);if(e(r,a))return r[a];var s=r.constructor;return i(s)&&r instanceof s?s.prototype:r instanceof o?l:null}}),zt=__webpack_require__.cw(t=>{var e=K();t.exports=e({}.isPrototypeOf)}),Gt=__webpack_require__.cw(t=>{var e=K(),i=nt(),n=me(),r=y().indexOf,s=rt(),a=e([].push);t.exports=function(t,e){var o,l=n(t),c=0,h=[];for(o in l)!i(s,o)&&i(l,o)&&a(h,o);for(;e.length>c;)i(l,o=e[c++])&&(~r(h,o)||a(h,o));return h}}),Wt=__webpack_require__.cw(t=>{var e=Gt(),i=B();t.exports=Object.keys||function keys(t){return e(t,i)}}),jt=__webpack_require__.cw((t,e)=>{var i={}.propertyIsEnumerable,n=Object.getOwnPropertyDescriptor,r=n&&!i.call({1:2},1);e.f=r?function propertyIsEnumerable(t){var e=n(this,t);return!!e&&e.enumerable}:i}),Vt=__webpack_require__.cw(t=>{var e=$(),i=bt(),r=require_object_coercible_namespaceFn(),s=n();t.exports=Object.setPrototypeOf||("__proto__"in{}?function(){var t,n=!1,a={};try{(t=e(Object.prototype,"__proto__","set"))(a,[]);n=a instanceof Array}catch(t){}return function setPrototypeOf(e,a){r(e);s(a);if(!i(e))return e;n?t(e,a):e.__proto__=a;return e}}():void 0)}),qt=__webpack_require__.cw(t=>{var e=V(),i=mt(),n=bt(),r=TypeError;t.exports=function(t,s){var a,o;if("string"===s&&i(a=t.toString)&&!n(o=e(a,t)))return o;if(i(a=t.valueOf)&&!n(o=e(a,t)))return o;if("string"!==s&&i(a=t.toString)&&!n(o=e(a,t)))return o;throw new r("Can't convert object to primitive value")}}),$t=__webpack_require__.cw(t=>{var e=Y(),i=K(),n=Ut(),r=__webpack_require__(717),s=h(),a=i([].concat);t.exports=e("Reflect","ownKeys")||function ownKeys(t){var e=n.f(s(t)),i=r.f;return i?a(e,i(t)):e}}),Xt=__webpack_require__.cw(t=>{var e=K(),i=nt(),n=SyntaxError,r=parseInt,s=String.fromCharCode,a=e("".charAt),o=e("".slice),l=e(/./.exec),c={'\\"':'"',"\\\\":"\\","\\/":"/","\\b":"\b","\\f":"\f","\\n":"\n","\\r":"\r","\\t":"\t"},h=/^[\da-f]{4}$/i,d=/^[\u0000-\u001F]$/;t.exports=function(t,e){for(var u=!0,p="";e<t.length;){var g=a(t,e);if("\\"===g){var m=o(t,e,e+2);if(i(c,m)){p+=c[m];e+=2}else{if("\\u"!==m)throw new n('Unknown escape sequence: "'+m+'"');var f=o(t,e+=2,e+4);if(!l(h,f))throw new n("Bad Unicode escape at: "+e);p+=s(r(f,16));e+=4}}else{if('"'===g){u=!1;e++;break}if(l(d,g))throw new n("Bad control character in string literal at: "+e);p+=g;e++}}if(u)throw new n("Unterminated string at: "+e);return{value:p,end:e}}}),Kt=__webpack_require__.cw(t=>{var e=h(),i=bt(),n=Ft();t.exports=function(t,r){e(t);if(i(r)&&r.constructor===t)return r;var s=n.f(t);(0,s.resolve)(r);return s.promise}}),require_object_coercible_namespaceFn=()=>__webpack_require__(750),Yt=__webpack_require__.cw(t=>{var e=Qt(),i=ne(),n=e.Set,r=e.add;t.exports=function(t){var e=new n;i(t,function(t){r(e,t)});return e}}),Jt=__webpack_require__.cw(t=>{var e=r(),i=Qt(),n=Yt(),s=se(),a=et(),o=ne(),l=At(),c=i.has,h=i.remove;t.exports=function difference(t){var i=e(this),r=a(t),d=n(i);s(d)<=r.size?o(d,function(t){r.includes(t)&&h(d,t)}):l(r.getIterator(),function(t){c(d,t)&&h(d,t)});return d}}),Qt=__webpack_require__.cw(t=>{var e=K(),i=Set.prototype;t.exports={Set,add:e(i.add),has:e(i.has),remove:e(i.delete),proto:i}}),Zt=__webpack_require__.cw(t=>{var e=r(),i=Qt(),n=se(),s=et(),a=ne(),o=At(),l=i.Set,c=i.add,h=i.has;t.exports=function intersection(t){var i=e(this),r=s(t),d=new l;n(i)>r.size?o(r.getIterator(),function(t){h(i,t)&&c(d,t)}):a(i,function(t){r.includes(t)&&c(d,t)});return d}}),te=__webpack_require__.cw(t=>{var e=r(),i=Qt().has,n=se(),s=et(),a=ne(),o=At(),l=Et();t.exports=function isDisjointFrom(t){var r=e(this),c=s(t);if(n(r)<=c.size)return!1!==a(r,function(t){if(c.includes(t))return!1},!0);var h=c.getIterator();return!1!==o(h,function(t){if(i(r,t))return l(h.iterator,"normal",!1)})}}),ee=__webpack_require__.cw(t=>{var e=r(),i=se(),n=ne(),s=et();t.exports=function isSubsetOf(t){var r=e(this),a=s(t);return!(i(r)>a.size)&&!1!==n(r,function(t){if(!a.includes(t))return!1},!0)}}),ie=__webpack_require__.cw(t=>{var e=r(),i=Qt().has,n=se(),s=et(),a=At(),o=Et();t.exports=function isSupersetOf(t){var r=e(this),l=s(t);if(n(r)<l.size)return!1;var c=l.getIterator();return!1!==a(c,function(t){if(!i(r,t))return o(c.iterator,"normal",!1)})}}),ne=__webpack_require__.cw(t=>{var e=K(),i=At(),n=Qt(),r=n.Set,s=n.proto,a=e(s.forEach),o=e(s.keys),l=o(new r).next;t.exports=function(t,e,n){return n?i({iterator:o(t),next:l},e):a(t,e)}}),re=__webpack_require__.cw(t=>{var e=Y(),createSetLike=function(t){return{size:t,has:function(){return!1},keys:function(){return{next:function(){return{done:!0}}}}}},createSetLikeWithInfinitySize=function(t){return{size:t,has:function(){return!0},keys:function(){throw new Error("e")}}};t.exports=function(t,i){var n=e("Set");try{(new n)[t](createSetLike(0));try{(new n)[t](createSetLike(-1));return!1}catch(e){if(!i)return!0;try{(new n)[t](createSetLikeWithInfinitySize(-1/0));return!1}catch(e){return i(new n([1,2])[t](createSetLikeWithInfinitySize(1/0)))}}}catch(t){return!1}}}),set_method_get_keys_before_cloning_detection_namespaceFn=()=>__webpack_require__(835),se=__webpack_require__.cw(t=>{var e=$(),i=Qt();t.exports=e(i.proto,"size","get")||function(t){return t.size}}),ae=__webpack_require__.cw(t=>{var e=r(),i=Qt(),n=Yt(),s=et(),a=At(),o=i.add,l=i.has,c=i.remove;t.exports=function symmetricDifference(t){var i=e(this),r=s(t).getIterator(),h=n(i);a(r,function(t){l(i,t)?c(h,t):o(h,t)});return h}}),oe=__webpack_require__.cw(t=>{var e=r(),i=Qt().add,n=Yt(),s=et(),a=At();t.exports=function union(t){var r=e(this),o=s(t).getIterator(),l=n(r);a(o,function(t){i(l,t)});return l}}),le=__webpack_require__.cw(t=>{var e=he(),i=_e(),n=e("keys");t.exports=function(t){return n[t]||(n[t]=i(t))}}),ce=__webpack_require__.cw(t=>{var e=wt(),i=it(),n=I(),r="__core-js_shared__",s=t.exports=i[r]||n(r,{});(s.versions||(s.versions=[])).push({version:"3.51.0",mode:e?"pure":"global",copyright:"© 2013–2025 Denis Pushkarev (zloirock.ru), 2025–2026 CoreJS Company (core-js.io). All rights reserved.",license:"https://github.com/zloirock/core-js/blob/v3.51.0/LICENSE",source:"https://github.com/zloirock/core-js"})}),he=__webpack_require__.cw(t=>{var e=ce(),i=Object.create||Object;t.exports=function(t,n){return e[t]||(e[t]=n||i(null))}}),de=__webpack_require__.cw(t=>{var e=N(),i=z(),n=it().String;t.exports=!!Object.getOwnPropertySymbols&&!i(function(){var t=Symbol("symbol detection");return!n(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&e&&e<41})}),ue=__webpack_require__.cw(t=>{var e=K();t.exports=e(1.1.valueOf)}),pe=__webpack_require__.cw(t=>{var e=to_integer_or_infinity_namespaceFn(),i=Math.max,n=Math.min;t.exports=function(t,r){var s=e(t);return s<0?i(s+r,0):n(s,r)}}),ge=__webpack_require__.cw(t=>{var e=fe(),i=TypeError;t.exports=function(t){var n=e(t,"number");if("number"==typeof n)throw new i("Can't convert number to bigint");return BigInt(n)}}),me=__webpack_require__.cw(t=>{var e=lt(),i=require_object_coercible_namespaceFn();t.exports=function(t){return e(i(t))}}),to_integer_or_infinity_namespaceFn=()=>__webpack_require__(291),to_length_namespaceFn=()=>__webpack_require__(14),to_object_namespaceFn=()=>__webpack_require__(981),to_positive_integer_namespaceFn=()=>__webpack_require__(590),fe=__webpack_require__.cw(t=>{var e=V(),i=bt(),n=_t(),r=tt(),s=qt(),a=Pe(),o=TypeError,l=a("toPrimitive");t.exports=function(t,a){if(!i(t)||n(t))return t;var c,h=r(t,l);if(h){void 0===a&&(a="default");c=e(h,t,a);if(!i(c)||n(c))return c;throw new o("Can't convert object to primitive value")}void 0===a&&(a="number");return s(t,a)}}),be=__webpack_require__.cw(t=>{var e=fe(),i=_t();t.exports=function(t){var n=e(t,"string");return i(n)?n:n+""}}),ye=__webpack_require__.cw(t=>{var e={};e[Pe()("toStringTag")]="z";t.exports="[object z]"===String(e)}),we=__webpack_require__.cw(t=>{var e=x(),i=String;t.exports=function(t){if("Symbol"===e(t))throw new TypeError("Cannot convert a Symbol value to a string");return i(t)}}),ve=__webpack_require__.cw(t=>{var e=String;t.exports=function(t){try{return e(t)}catch(t){return"Object"}}}),_e=__webpack_require__.cw(t=>{var e=K(),i=0,n=Math.random(),r=e(1.1.toString);t.exports=function(t){return"Symbol("+(void 0===t?"":t)+")_"+r(++i+n,36)}}),Ae=__webpack_require__.cw(t=>{var e=it(),i=K(),n=c(),r=a_string_namespaceFn(),s=nt(),a=base64_map_namespaceFn(),o=get_alphabet_option_namespaceFn(),l=m(),h=a.c2i,d=a.c2iUrl,u=e.SyntaxError,p=e.TypeError,g=e.Array,f=i("".charAt),b=Math.floor,skipAsciiWhitespace=function(t,e){for(var i=t.length;e<i;e++){var n=f(t,e);if(" "!==n&&"\t"!==n&&"\n"!==n&&"\f"!==n&&"\r"!==n)break}return e},decodeBase64Chunk=function(t,e,i){var n=t.length;n<4&&(t+=2===n?"AA":"A");var r=(e[f(t,0)]<<18)+(e[f(t,1)]<<12)+(e[f(t,2)]<<6)+e[f(t,3)],s=[r>>16&255,r>>8&255,255&r];if(2===n){if(i&&0!==s[1])throw new u("Extra bits");return[s[0]]}if(3===n){if(i&&0!==s[2])throw new u("Extra bits");return[s[0],s[1]]}return s},writeBytes=function(t,e,i){for(var n=e.length,r=0;r<n;r++)t[i+r]=e[r];return i+n};t.exports=function(t,e,i,a){r(t);n(e);var c="base64"===o(e)?h:d,m=e?e.lastChunkHandling:void 0;void 0===m&&(m="loose");if("loose"!==m&&"strict"!==m&&"stop-before-partial"!==m)throw new p("Incorrect `lastChunkHandling` option");i&&l(i.buffer);var y=t.length,w=i||g(b(3*y/4)),v=0,_=0,A="",x=0;if(a)for(;;){if((x=skipAsciiWhitespace(t,x))===y){if(A.length>0){if("stop-before-partial"===m)break;if("loose"!==m)throw new u("Missing padding");if(1===A.length)throw new u("Malformed padding: exactly one additional character");v=writeBytes(w,decodeBase64Chunk(A,c,!1),v)}_=y;break}var C=f(t,x);++x;if("="===C){if(A.length<2)throw new u("Padding is too early");x=skipAsciiWhitespace(t,x);if(2===A.length){if(x===y){if("stop-before-partial"===m)break;throw new u("Malformed padding: only one =")}if("="===f(t,x)){++x;x=skipAsciiWhitespace(t,x)}}if(x<y)throw new u("Unexpected character after padding");v=writeBytes(w,decodeBase64Chunk(A,c,"strict"===m),v);_=y;break}if(!s(c,C))throw new u("Unexpected character");var E=a-v;if(1===E&&2===A.length||2===E&&3===A.length)break;if(4===(A+=C).length){v=writeBytes(w,decodeBase64Chunk(A,c,!1),v);A="";_=x;if(v===a)break}}i||(w.length=v);return{bytes:w,read:_,written:v}}}),xe=__webpack_require__.cw(t=>{var e=it(),i=K(),n=e.Uint8Array,r=e.SyntaxError,s=Math.min,a=i("".match);t.exports=function(t,e){var i=t.length;if(i%2!=0)throw new r("String should be an even number of characters");for(var o=e?s(e.length,i/2):i/2,l=e||new n(o),c=a(t,/[\S\s]{2}/g),h=0;h<o;h++){var d=+("0x"+c[h]+"0");if(d!=d)throw new r("String should only contain hex characters");l[h]=d>>4}return{bytes:l,read:h<<1}}}),Ce=__webpack_require__.cw(t=>{var e=z(),i=Pe(),n=O(),r=wt(),s=i("iterator");t.exports=!e(function(){var t=new URL("b?a=1&b=2&c=3","https://a"),e=t.searchParams,i=new URLSearchParams("a=1&a=2&b=3"),a="";t.pathname="c%20d";e.forEach(function(t,i){e.delete("b");a+=i+t});i.delete("a",2);i.delete("b",void 0);return r&&(!t.toJSON||!i.has("a",1)||i.has("a",2)||!i.has("a",void 0)||i.has("b"))||!e.size&&(r||!n)||!e.sort||"https://a/c%20d?a=1&c=3"!==t.href||"3"!==e.get("c")||"a=1"!==String(new URLSearchParams("?a=1"))||!e[s]||"a"!==new URL("https://a@b").username||"b"!==new URLSearchParams(new URLSearchParams("a=b")).get("a")||"xn--e1aybc"!==new URL("https://тест").host||"#%D0%B1"!==new URL("https://a#б").hash||"a1c3"!==a||"x"!==new URL("https://x",void 0).host})}),Ee=__webpack_require__.cw(t=>{var e=de();t.exports=e&&!Symbol.sham&&"symbol"==typeof Symbol.iterator}),Se=__webpack_require__.cw(t=>{var e=O(),i=z();t.exports=e&&i(function(){return 42!==Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype})}),Te=__webpack_require__.cw(t=>{var e=it(),i=mt(),n=e.WeakMap;t.exports=i(n)&&/native code/.test(String(n))}),ke=__webpack_require__.cw(t=>{var e=K(),i=WeakMap.prototype;t.exports={WeakMap,set:e(i.set),get:e(i.get),has:e(i.has),remove:e(i.delete)}}),Pe=__webpack_require__.cw(t=>{var e=it(),i=he(),n=nt(),r=_e(),s=de(),a=Ee(),o=e.Symbol,l=i("wks"),c=a?o.for||o:o&&o.withoutSetter||r;t.exports=function(t){n(l,t)||(l[t]=s&&n(o,t)?o[t]:c("Symbol."+t));return l[t]}}),Me=__webpack_require__.cw(()=>{var t=H(),e=y().includes,i=z(),n=o(),r=i(function(){return!Array(1).includes()}),s=i(function(){return[,1].includes(void 0,1)});t({target:"Array",proto:!0,forced:r||s},{includes:function includes(t){return e(this,t,arguments.length>1?arguments[1]:void 0)}});n("includes")}),De=__webpack_require__.cw(()=>{var t=H(),e=to_object_namespaceFn(),i=Pt(),n=w(),r=__webpack_require__(837);t({target:"Array",proto:!0,arity:1,forced:z()(function(){return 4294967297!==[].push.call({length:4294967296},1)})||!function(){try{Object.defineProperty([],"length",{writable:!1}).push()}catch(t){return t instanceof TypeError}}()},{push:function push(t){var s=e(this),a=i(s),o=arguments.length;r(a+o);for(var l=0;l<o;l++){s[a]=arguments[l];a++}n(s,a);return a}})}),Ie=__webpack_require__.cw(()=>{var t=H(),e=it(),i=l(),n=h(),r=mt(),s=Ht(),a=P(),o=k(),c=z(),d=nt(),u=Pe(),p=kt().IteratorPrototype,g=O(),m=wt(),f="constructor",b="Iterator",y=u("toStringTag"),w=TypeError,v=e[b],_=m||!r(v)||v.prototype!==p||!c(function(){v({})}),A=function Iterator(){i(this,p);if(s(this)===p)throw new w("Abstract class Iterator not directly constructable")},defineIteratorPrototypeAccessor=function(t,e){g?a(p,t,{configurable:!0,get:function(){return e},set:function(e){n(this);if(this===p)throw new w("You can't redefine this property");d(this,t)?this[t]=e:o(this,t,e)}}):p[t]=e};d(p,y)||defineIteratorPrototypeAccessor(y,b);!_&&d(p,f)&&p[f]!==Object||defineIteratorPrototypeAccessor(f,A);A.prototype=p;t({global:!0,constructor:!0,forced:_},{Iterator:A})}),Fe=__webpack_require__.cw(()=>{var t=H(),e=V(),i=h(),n=get_iterator_direct_namespaceFn(),r=not_a_nan_namespaceFn(),s=to_positive_integer_namespaceFn(),a=Et(),o=St(),l=iterator_helper_throws_on_invalid_iterator_namespaceFn(),c=Tt(),d=wt(),u=RangeError,p=1/0,g=!d&&!l("drop",0),m=!d&&!g&&c("drop",RangeError),f=d||g||m||!function(){try{Iterator.prototype.drop.call({next:function(){return{done:!0}}},9007199254740992)}catch(t){return t instanceof u}}(),b=o(function(){for(var t,n=this.iterator,r=this.next;this.remaining;){this.remaining--;t=i(e(r,n));if(this.done=!!t.done)return}t=i(e(r,n));if(!(this.done=!!t.done))return t.value});t({target:"Iterator",proto:!0,real:!0,forced:f},{drop:function drop(t){i(this);var o;try{if((o=s(r(+t)))>9007199254740991&&o!==p)throw new u("The argument should be a safe integer")}catch(t){a(this,"throw",t)}return m?e(m,this,o):new b(n(this),{remaining:o})}})}),Oe=__webpack_require__.cw(()=>{var t=H(),e=V(),n=xt(),r=i(),s=h(),a=get_iterator_direct_namespaceFn(),o=Et(),l=Tt()("every",TypeError);t({target:"Iterator",proto:!0,real:!0,forced:l},{every:function every(t){s(this);try{r(t)}catch(t){o(this,"throw",t)}if(l)return e(l,this,t);var i=a(this),c=0;return!n(i,function(e,i){if(!t(e,c++))return i()},{IS_RECORD:!0,INTERRUPTED:!0}).stopped}})}),Re=__webpack_require__.cw(()=>{var t=H(),e=V(),n=i(),r=h(),s=get_iterator_direct_namespaceFn(),a=St(),o=_(),l=wt(),c=Et(),d=iterator_helper_throws_on_invalid_iterator_namespaceFn(),u=Tt(),p=!l&&!d("filter",function(){}),g=!l&&!p&&u("filter",TypeError),m=l||p||g,f=a(function(){for(var t,i,n=this.iterator,s=this.predicate,a=this.next;;){t=r(e(a,n));if(this.done=!!t.done)return;i=t.value;if(o(n,s,[i,this.counter++],!0))return i}});t({target:"Iterator",proto:!0,real:!0,forced:m},{filter:function filter(t){r(this);try{n(t)}catch(t){c(this,"throw",t)}return g?e(g,this,t):new f(s(this),{predicate:t})}})}),Be=__webpack_require__.cw(()=>{var t=H(),e=V(),n=xt(),r=i(),s=h(),a=get_iterator_direct_namespaceFn(),o=Et(),l=Tt()("find",TypeError);t({target:"Iterator",proto:!0,real:!0,forced:l},{find:function find(t){s(this);try{r(t)}catch(t){o(this,"throw",t)}if(l)return e(l,this,t);var i=a(this),c=0;return n(i,function(e,i){if(t(e,c++))return i(e)},{IS_RECORD:!0,INTERRUPTED:!0}).result}})}),Le=__webpack_require__.cw(()=>{var t=H(),e=V(),n=i(),r=h(),s=get_iterator_direct_namespaceFn(),a=J(),o=St(),l=Et(),c=z(),d=wt(),u=iterator_helper_throws_on_invalid_iterator_namespaceFn(),p=Tt(),g=!d&&c(function(){return 1!==[1].values().flatMap(function(){return[1]}).find(function(){return!0})}),m=!d&&!g&&!u("flatMap",function(){}),f=!d&&!g&&!m&&p("flatMap",TypeError),b=d||g||m||f,y=o(function(){for(var t,i,n=this.iterator,s=this.mapper;;){if(i=this.inner)try{if(!(t=r(e(i.next,i.iterator))).done)return t.value;this.inner=null}catch(t){l(n,"throw",t)}t=r(e(this.next,n));if(this.done=!!t.done)return;try{this.inner=a(s(t.value,this.counter++),!1)}catch(t){l(n,"throw",t)}}});t({target:"Iterator",proto:!0,real:!0,forced:b},{flatMap:function flatMap(t){r(this);try{n(t)}catch(t){l(this,"throw",t)}return f?e(f,this,t):new y(s(this),{mapper:t,inner:null})}})}),Ne=__webpack_require__.cw(()=>{var t=H(),e=V(),n=xt(),r=i(),s=h(),a=get_iterator_direct_namespaceFn(),o=Et(),l=Tt()("forEach",TypeError);t({target:"Iterator",proto:!0,real:!0,forced:l},{forEach:function forEach(t){s(this);try{r(t)}catch(t){o(this,"throw",t)}if(l)return e(l,this,t);var i=a(this),c=0;n(i,function(e){t(e,c++)},{IS_RECORD:!0})}})}),Ue=__webpack_require__.cw(()=>{var t=H(),e=V(),n=i(),r=h(),s=get_iterator_direct_namespaceFn(),a=St(),o=_(),l=Et(),c=iterator_helper_throws_on_invalid_iterator_namespaceFn(),d=Tt(),u=wt(),p=!u&&!c("map",function(){}),g=!u&&!p&&d("map",TypeError),m=u||p||g,f=a(function(){var t=this.iterator,i=r(e(this.next,t));if(!(this.done=!!i.done))return o(t,this.mapper,[i.value,this.counter++],!0)});t({target:"Iterator",proto:!0,real:!0,forced:m},{map:function map(t){r(this);try{n(t)}catch(t){l(this,"throw",t)}return g?e(g,this,t):new f(s(this),{mapper:t})}})}),He=__webpack_require__.cw(()=>{var t=H(),e=V(),n=xt(),r=i(),s=h(),a=get_iterator_direct_namespaceFn(),o=Et(),l=Tt()("some",TypeError);t({target:"Iterator",proto:!0,real:!0,forced:l},{some:function some(t){s(this);try{r(t)}catch(t){o(this,"throw",t)}if(l)return e(l,this,t);var i=a(this),c=0;return n(i,function(e,i){if(t(e,c++))return i()},{IS_RECORD:!0,INTERRUPTED:!0}).stopped}})}),ze=__webpack_require__.cw(()=>{var t=H(),e=V(),i=h(),n=get_iterator_direct_namespaceFn(),r=not_a_nan_namespaceFn(),s=to_positive_integer_namespaceFn(),a=St(),o=Et(),l=iterator_helper_throws_on_invalid_iterator_namespaceFn(),c=Tt(),d=wt(),u=RangeError,p=1/0,g=!d&&!l("take",1),m=!d&&!g&&c("take",RangeError),f=d||g||m||!function(){try{Iterator.prototype.take.call({next:function(){return{done:!0}}},9007199254740992)}catch(t){return t instanceof u}}(),b=a(function(){var t=this.iterator;if(!this.remaining--){this.done=!0;return o(t,"normal",void 0)}var n=i(e(this.next,t));if(!(this.done=!!n.done))return n.value});t({target:"Iterator",proto:!0,real:!0,forced:f},{take:function take(t){i(this);var a;try{if((a=s(r(+t)))>9007199254740991&&a!==p)throw new u("The argument should be a safe integer")}catch(t){o(this,"throw",t)}return m?e(m,this,a):new b(n(this),{remaining:a})}})}),Ge=__webpack_require__.cw(()=>{var t=H(),e=h(),i=k(),n=xt(),r=get_iterator_direct_namespaceFn();t({target:"Iterator",proto:!0,real:!0},{toArray:function toArray(){var t=[],s=0;n(r(e(this)),function(e){i(t,s++,e)},{IS_RECORD:!0});return t}})}),We=__webpack_require__.cw(()=>{var t=H(),e=O(),i=it(),n=Y(),r=K(),s=V(),a=mt(),o=bt(),l=pt(),c=nt(),h=we(),d=Pt(),u=k(),p=z(),g=Xt(),m=de(),f=i.JSON,b=i.Number,y=i.SyntaxError,w=f&&f.parse,v=n("Object","keys"),_=Object.getOwnPropertyDescriptor,A=r("".charAt),x=r("".slice),C=r(/./.exec),E=r([].push),S=/^\d$/,T=/^[1-9]$/,P=/^[\d-]$/,M=/^[\t\n\r ]$/,internalize=function(t,e,i,n){var r,a,h,u,p,g=t[e],m=n&&g===n.value,f=m&&"string"==typeof n.source?{source:n.source}:{};if(o(g)){var b=l(g),y=m?n.nodes:b?[]:{};if(b){r=y.length;h=d(g);for(u=0;u<h;u++)internalizeProperty(g,u,internalize(g,""+u,i,u<r?y[u]:void 0))}else{a=v(g);h=d(a);for(u=0;u<h;u++){p=a[u];internalizeProperty(g,p,internalize(g,p,i,c(y,p)?y[p]:void 0))}}}return s(i,t,e,g,f)},internalizeProperty=function(t,i,n){if(e){var r=_(t,i);if(r&&!r.configurable)return}void 0===n?delete t[i]:u(t,i,n)},Node=function(t,e,i,n){this.value=t;this.end=e;this.source=i;this.nodes=n},Context=function(t,e){this.source=t;this.index=e};Context.prototype={fork:function(t){return new Context(this.source,t)},parse:function(){var t=this.source,e=this.skip(M,this.index),i=this.fork(e),n=A(t,e);if(C(P,n))return i.number();switch(n){case"{":return i.object();case"[":return i.array();case'"':return i.string();case"t":return i.keyword(!0);case"f":return i.keyword(!1);case"n":return i.keyword(null)}throw new y('Unexpected character: "'+n+'" at: '+e)},node:function(t,e,i,n,r){return new Node(e,n,t?null:x(this.source,i,n),r)},object:function(){for(var t=this.source,e=this.index+1,i=!1,n={},r={},s=!1;e<t.length;){e=this.until(['"',"}"],e);if("}"===A(t,e)&&!i){e++;s=!0;break}var a=this.fork(e).string(),o=a.value;e=a.end;e=this.until([":"],e)+1;e=this.skip(M,e);a=this.fork(e).parse();u(r,o,a);u(n,o,a.value);e=this.until([",","}"],a.end);var l=A(t,e);if(","===l){i=!0;e++}else if("}"===l){e++;s=!0;break}}if(!s)throw new y("Unterminated object at: "+e);return this.node(1,n,this.index,e,r)},array:function(){for(var t=this.source,e=this.index+1,i=!1,n=[],r=[],s=!1;e<t.length;){e=this.skip(M,e);if("]"===A(t,e)&&!i){e++;s=!0;break}var a=this.fork(e).parse();E(r,a);E(n,a.value);e=this.until([",","]"],a.end);if(","===A(t,e)){i=!0;e++}else if("]"===A(t,e)){e++;s=!0;break}}if(!s)throw new y("Unterminated array at: "+e);return this.node(1,n,this.index,e,r)},string:function(){var t=this.index,e=g(this.source,this.index+1);return this.node(0,e.value,t,e.end)},number:function(){var t=this.source,e=this.index,i=e;"-"===A(t,i)&&i++;if("0"===A(t,i))i++;else{if(!C(T,A(t,i)))throw new y("Failed to parse number at: "+i);i=this.skip(S,i+1)}if("."===A(t,i)){var n=i+1;if(n===(i=this.skip(S,n)))throw new y("Failed to parse number's fraction at: "+i)}if("e"===A(t,i)||"E"===A(t,i)){i++;"+"!==A(t,i)&&"-"!==A(t,i)||i++;if(i===(i=this.skip(S,i)))throw new y("Failed to parse number's exponent value at: "+i)}return this.node(0,b(x(t,e,i)),e,i)},keyword:function(t){var e=""+t,i=this.index,n=i+e.length;if(x(this.source,i,n)!==e)throw new y("Failed to parse value at: "+i);return this.node(0,t,i,n)},skip:function(t,e){for(var i=this.source;e<i.length&&C(t,A(i,e));e++);return e},until:function(t,e){e=this.skip(M,e);for(var i=A(this.source,e),n=0;n<t.length;n++)if(t[n]===i)return e;throw new y('Unexpected character: "'+i+'" at: '+e)}};var D=p(function(){var t,e="9007199254740993";w(e,function(e,i,n){t=n.source});return t!==e}),I=m&&!p(function(){return 1/w("-0 \t")!=-1/0});t({target:"JSON",stat:!0,forced:D},{parse:function parse(t,e){return I&&!a(e)?w(t):function(t,e){t=h(t);var i=new Context(t,0),n=i.parse(),r=n.value,s=i.skip(M,n.end);if(s<t.length)throw new y('Unexpected extra character: "'+A(t,s)+'" after the parsed data at: '+s);return a(e)?internalize({"":r},"",e,n):r}(t,e)}})}),je=__webpack_require__.cw(()=>{var t=H(),e=Y(),i=V(),n=K(),r=z(),s=pt(),a=mt(),o=bt(),l=Rt(),c=vt(),h=_t(),d=A(),u=ue(),p=y().includes,g=nt(),m=we(),f=Xt(),b=_e(),w=de(),v=It(),_=String,x=TypeError,C=e("JSON","stringify"),E=e("BigInt"),S=n("".valueOf),T=n((!0).valueOf),k=E&&n(E.prototype.valueOf),P=n(/./.exec),M=n("".charAt),D=n("".charCodeAt),I=n("".replace),O=n("".slice),R=n([].push),B=n([].pop),L=n(1.1.toString),N=/[\uD800-\uDFFF]/g,U=/^[\uD800-\uDBFF]$/,G=/^[\uDC00-\uDFFF]$/,W=/^\d+$/,j=b(),q=b(),$=b(),X=j.length,J=q.length,Q=!w||r(function(){var t=e("Symbol")("stringify detection");return"[null]"!==C([t])||"{}"!==C({a:t})||"{}"!==C(Object(t))}),Z=r(function(){return'"\\udf06\\ud834"'!==C("\udf06\ud834")||'"\\udead"'!==C("\udead")}),tt=v?e("JSON","isRawJSON"):c,et=Q?function(t,e,n){return C(t,function(t,n){var r=i(e,this,t,n);if(!h(r))return r},n)}:C,fixIllFormedJSON=function(t,e,i){var n=M(i,e-1),r=M(i,e+1);return P(U,t)&&!P(G,r)||P(G,t)&&!P(U,n)?"\\u"+L(D(t,0),16):t},hasInternalSlot=function(t,e){try{t(e);return!0}catch(t){return!1}},isSerializedAsObject=function(t){if(!o(t)||a(t)||s(t))return!1;try{return!function(t){var e=d(t);return"Number"===e&&hasInternalSlot(u,t)||"String"===e&&hasInternalSlot(S,t)||"Boolean"===e&&hasInternalSlot(T,t)||!!k&&"BigInt"===e&&hasInternalSlot(k,t)}(t)}catch(t){return!0}},createElementHolder=function(t,e){return{toJSON:function(){var n=t[e];if(o(n)||"bigint"==typeof n){var r=n.toJSON;a(r)&&(n=i(r,n,e))}return n}}};C&&t({target:"JSON",stat:!0,arity:3,forced:Q||Z||!v},{stringify:function stringify(t,e,n){var r,o=a(e)?e:void 0,c=o?void 0:function(t){if(s(t)){for(var e=t.length,i=[],n=l(null),r=0;r<e;r++){var a,o=t[r];if("string"==typeof o)a=o;else{if("number"!=typeof o&&"Number"!==d(o)&&"String"!==d(o))continue;a=m(o)}if(!g(n,a)){n[a]=!0;R(i,a)}}return i}}(e),h=c&&function(t){for(var e=0,i=t.length;e<i;e++)if(P(W,t[e]))return q;return""}(c),u=[],b=[],y=[],w=!1,A=!0,C=et(t,function(t,e){t=_(t);if(c){if(t===$){B(b);r=B(y);return}if(A)A=!1;else if(this!==r&&!s(this)&&!p(c,t))return}else o&&(e=i(o,this,t,e));if(tt(e)){if(v)return e;w=!0;return j+(R(u,e.rawJSON)-1)}if(c&&isSerializedAsObject(e)){if(p(b,e))throw new x("Converting circular structure to JSON");var n=function(t,e,i){for(var n=l(null),r=0,s=e.length;r<s;r++){var a=e[r];n[i+a]=createElementHolder(t,a)}n[$]=null;return n}(e,c,h);R(b,e);R(y,r);r=n;h&&(w=!0);return n}return e},n);if("string"!=typeof C)return C;Z&&(C=I(C,N,fixIllFormedJSON));if(!w)return C;for(var E="",S=C.length,T=0;T<S;T++){var k=M(C,T);if('"'===k){var D=f(C,++T).end-1,L=O(C,T,D);O(L,0,X)===j?E+=u[O(L,X)]:O(L,0,J)===q?E+='"'+O(L,J)+'"':E+='"'+L+'"';T=D}else E+=k}return E}})}),Ve=__webpack_require__.cw(()=>{var t=H(),e=i(),n=Dt(),r=wt(),s=n.get,a=n.has,o=n.set;t({target:"Map",proto:!0,real:!0,forced:r},{getOrInsertComputed:function getOrInsertComputed(t,i){var n=a(this,t);e(i);if(n)return s(this,t);0===t&&1/t==-1/0&&(t=0);var r=i(t);o(this,t,r);return r}})}),qe=__webpack_require__.cw(()=>{var t=H(),e=Dt(),i=wt(),n=e.get,r=e.has,s=e.set;t({target:"Map",proto:!0,real:!0,forced:i},{getOrInsert:function getOrInsert(t,e){if(r(this,t))return n(this,t);s(this,t,e);return e}})}),$e=__webpack_require__.cw(()=>{var t=H(),e=K(),i=xt(),n=z(),r=Q(),s=Vt(),a=Pe(),o=RangeError,l=TypeError,c=1/0,h=Math.sumPrecise,d=Math.abs,u=Math.pow,p=e([].push),g=a("iterator"),m=u(2,1023),f=u(2,53)-1,b=Number.MAX_VALUE,y=u(2,971),w={},v={},_={},A={},x={},C=n(function(){if(-1!==h([-1])||h([-b])!==-b)return!0;if(!s)return!1;try{h(s([1],{}));return!0}catch(t){}try{var t={};t[g]=function(){return this};h(s(r([1]),t));return!0}catch(t){}}),twosum=function(t,e){var i=t+e;return{hi:i,lo:e-(i-t)}};t({target:"Math",stat:!0,forced:C},{sumPrecise:function sumPrecise(t){var e=[],n=0,r=A;i(t,function(t){if(++n>f)throw new o("Maximum allowed index exceeded");if("number"!=typeof t)throw new l("Value is not a number");if(r!==w)if(t!=t)r=w;else if(t===c)r=r===v?w:_;else if(t===-1/0)r=r===_?w:v;else if(!(0===t&&1/t!==c||r!==A&&r!==x)){r=x;p(e,t)}});switch(r){case w:return NaN;case v:return-1/0;case _:return c;case A:return-0}for(var s,a,h,u,g,C,E=[],S=0,T=0;T<e.length;T++){s=e[T];for(var k=0,P=0;P<E.length;P++){a=E[P];if(d(s)<d(a)){C=s;s=a;a=C}u=(h=twosum(s,a)).hi;g=h.lo;if(d(u)===c){var M=u===c?1:-1;S+=M;if(d(s=s-M*m-M*m)<d(a)){C=s;s=a;a=C}u=(h=twosum(s,a)).hi;g=h.lo}0!==g&&(E[k++]=g);s=u}E.length=k;0!==s&&p(E,s)}var D=E.length-1;u=0;g=0;if(0!==S){var I=D>=0?E[D]:0;D--;if(d(S)>1||S>0&&I>0||S<0&&I<0)return S>0?c:-1/0;u=(h=twosum(S*m,I/2)).hi;g=h.lo;g*=2;if(d(2*u)===c)return u>0?u===m&&g===-y/2&&D>=0&&E[D]<0?b:c:u===-m&&g===y/2&&D>=0&&E[D]>0?-b:-1/0;if(0!==g){E[++D]=g;g=0}u*=2}for(;D>=0;){u=(h=twosum(u,E[D--])).hi;if(0!==(g=h.lo))break}D>=0&&(g<0&&E[D]<0||g>0&&E[D]>0)&&(a=2*g)===(s=u+a)-u&&(u=s);return u}})}),Xe=__webpack_require__.cw(()=>{var t=H(),e=it(),n=G(),r=v(),s=Kt(),a=Ft(),o=i(),l=__webpack_require__(103),c=z(),h=e.Promise,d=!1;t({target:"Promise",stat:!0,forced:!h||!h.try||c(function(){var t=h.resolve();return h.try(function(e){d=8===e;return t},8)!==t})||!d},{try:function(t){var e=arguments.length>1?r(arguments,1):[],i=l(function(){return n(o(t),void 0,e)});if(!i.error)return s(this,i.value);var c=a.f(this);(0,c.reject)(i.value);return c.promise}})}),Ke=__webpack_require__.cw(()=>{var t=H(),e=Jt(),i=z();t({target:"Set",proto:!0,real:!0,forced:!re()("difference",function(t){return 0===t.size})||i(function(){var t={size:1,has:function(){return!0},keys:function(){var t=0;return{next:function(){var i=t++>1;e.has(1)&&e.clear();return{done:i,value:2}}}}},e=new Set([1,2,3,4]);return 3!==e.difference(t).size})},{difference:e})}),Ye=__webpack_require__.cw(()=>{var t=H(),e=z(),i=Zt();t({target:"Set",proto:!0,real:!0,forced:!re()("intersection",function(t){return 2===t.size&&t.has(1)&&t.has(2)})||e(function(){return"3,2"!==String(Array.from(new Set([1,2,3]).intersection(new Set([3,2]))))})},{intersection:i})}),Je=__webpack_require__.cw(()=>{var t=H(),e=te();t({target:"Set",proto:!0,real:!0,forced:!re()("isDisjointFrom",function(t){return!t})},{isDisjointFrom:e})}),Qe=__webpack_require__.cw(()=>{var t=H(),e=ee();t({target:"Set",proto:!0,real:!0,forced:!re()("isSubsetOf",function(t){return t})},{isSubsetOf:e})}),Ze=__webpack_require__.cw(()=>{var t=H(),e=ie();t({target:"Set",proto:!0,real:!0,forced:!re()("isSupersetOf",function(t){return!t})},{isSupersetOf:e})}),ti=__webpack_require__.cw(()=>{var t=H(),e=ae(),i=set_method_get_keys_before_cloning_detection_namespaceFn();t({target:"Set",proto:!0,real:!0,forced:!re()("symmetricDifference")||!i("symmetricDifference")},{symmetricDifference:e})}),ei=__webpack_require__.cw(()=>{var t=H(),e=oe(),i=set_method_get_keys_before_cloning_detection_namespaceFn();t({target:"Set",proto:!0,real:!0,forced:!re()("union")||!i("union")},{union:e})}),ii=__webpack_require__.cw(()=>{var t=f(),e=gt(),i=Pt(),n=to_integer_or_infinity_namespaceFn(),r=ge(),s=t.aTypedArray,a=t.getTypedArrayConstructor,o=t.exportTypedArrayMethod,l=RangeError,c=function(){try{new Int8Array(1).with(2,{valueOf:function(){throw 8}})}catch(t){return 8===t}}(),h=c&&function(){try{new Int8Array(1).with(-.5,1)}catch(t){return!0}}();o("with",{with:function(t,o){var c=s(this),h=i(c),d=n(t),u=d<0?h+d:d,p=e(c)?r(o):+o;if(u>=h||u<0)throw new l("Incorrect index");for(var g=new(a(c))(h),m=0;m<h;m++)g[m]=m===u?p:c[m];return g}}.with,!c||h)}),ni=__webpack_require__.cw(()=>{var t=H(),e=it(),i=b(),n=Ae(),r=e.Uint8Array,s=!r||!r.fromBase64||!function(){try{r.fromBase64("a");return}catch(t){}try{r.fromBase64("",null)}catch(t){return!0}}();r&&t({target:"Uint8Array",stat:!0,forced:s},{fromBase64:function fromBase64(t){var e=n(t,arguments.length>1?arguments[1]:void 0,null,9007199254740991);return i(r,e.bytes)}})}),ri=__webpack_require__.cw(()=>{var t=H(),e=it(),i=Ae(),n=d(),r=e.Uint8Array,s=!r||!r.prototype.setFromBase64||!function(){var t=new r([255,255,255,255,255]);try{t.setFromBase64("",null);return}catch(t){}try{t.setFromBase64("a");return}catch(t){}try{t.setFromBase64("MjYyZg===")}catch(e){return 50===t[0]&&54===t[1]&&50===t[2]&&255===t[3]&&255===t[4]}}();r&&t({target:"Uint8Array",proto:!0,forced:s},{setFromBase64:function setFromBase64(t){n(this);var e=i(t,arguments.length>1?arguments[1]:void 0,this,this.length);return{read:e.read,written:e.written}}})}),si=__webpack_require__.cw(()=>{var t=H(),e=it(),i=a_string_namespaceFn(),n=d(),r=m(),s=xe();e.Uint8Array&&t({target:"Uint8Array",proto:!0,forced:function throwsOnLengthTrackingView(){try{var t=new ArrayBuffer(16,{maxByteLength:1024});new Uint8Array(t).setFromHex("cafed00d")}catch(t){return!0}}()},{setFromHex:function setFromHex(t){n(this);i(t);r(this.buffer);var e=s(t,this).read;return{read:e,written:e/2}}})}),ai=__webpack_require__.cw(()=>{var t=H(),e=it(),i=K(),n=c(),r=d(),s=m(),a=base64_map_namespaceFn(),o=get_alphabet_option_namespaceFn(),l=a.i2c,h=a.i2cUrl,u=Math.floor,p=Math.ceil,g=i("".charAt),f=e.Uint8Array,b=e.Array,y=i([].join),w=!f||!f.prototype.toBase64||!function(){try{(new f).toBase64(null)}catch(t){return!0}}();f&&t({target:"Uint8Array",proto:!0,forced:w},{toBase64:function toBase64(){var t=r(this),e=arguments.length?n(arguments[0]):void 0,i="base64"===o(e)?l:h,a=!!e&&!!e.omitPadding;s(this.buffer);for(var c,d=0,m=t.length,f=b(a?4*u(m/3)+(m%3?m%3+1:0):4*p(m/3)),w=0,at=function(t){return g(i,c>>6*t&63)};d+2<m;d+=3){c=(t[d]<<16)+(t[d+1]<<8)+t[d+2];f[w++]=at(3);f[w++]=at(2);f[w++]=at(1);f[w++]=at(0)}if(d+2===m){c=(t[d]<<16)+(t[d+1]<<8);f[w++]=at(3);f[w++]=at(2);f[w++]=at(1);a||(f[w++]="=")}else if(d+1===m){c=t[d]<<16;f[w++]=at(3);f[w++]=at(2);if(!a){f[w++]="=";f[w++]="="}}return y(f,"")}})}),oi=__webpack_require__.cw(()=>{var t=H(),e=it(),i=K(),n=d(),r=m(),s=i(1.1.toString),a=i([].join),o=Array,l=e.Uint8Array,c=!l||!l.prototype.toHex||!function(){try{return"ffffffffffffffff"===new l([255,255,255,255,255,255,255,255]).toHex()}catch(t){return!1}}();l&&t({target:"Uint8Array",proto:!0,forced:c},{toHex:function toHex(){n(this);r(this.buffer);for(var t=o(this.length),e=0,i=this.length;e<i;e++){var l=s(this[e],16);t[e]=1===l.length?"0"+l:l}return a(t,"")}})}),li=__webpack_require__.cw(()=>{var t=H(),e=i(),n=a(),r=s(),o=ke(),l=wt(),c=o.get,h=o.has,d=o.set;t({target:"WeakMap",proto:!0,real:!0,forced:l||!function(){try{WeakMap.prototype.getOrInsertComputed&&(new WeakMap).getOrInsertComputed(1,function(){throw 1})}catch(t){return t instanceof TypeError}}()},{getOrInsertComputed:function getOrInsertComputed(t,i){l||n(this);r(t);e(i);if(h(this,t))return c(this,t);var s=i(t);d(this,t,s);return s}})}),ci=__webpack_require__.cw(()=>{var t=H(),e=ke(),i=wt(),n=e.get,r=e.has,s=e.set;t({target:"WeakMap",proto:!0,real:!0,forced:i},{getOrInsert:function getOrInsert(t,e){if(r(this,t))return n(this,t);s(this,t,e);return e}})}),hi=__webpack_require__.cw(()=>{var t=H(),e=it(),i=Y(),n=T(),r=Lt().f,s=nt(),a=l(),o=ct(),c=Ot(),h=__webpack_require__(2),d=U(),u=O(),p=wt(),g="DOMException",m=i("Error"),f=i(g),b=function DOMException(){a(this,y);var t=arguments.length,e=c(t<1?void 0:arguments[0]),i=c(t<2?void 0:arguments[1],"Error"),s=new f(e,i),l=new m(e);l.name=g;r(s,"stack",n(1,d(l.stack,1)));o(s,this,b);return s},y=b.prototype=f.prototype,w="stack"in new m(g),v="stack"in new f(1,2),_=f&&u&&Object.getOwnPropertyDescriptor(e,g),A=!(!_||_.writable&&_.configurable),x=w&&!A&&!v;t({global:!0,constructor:!0,forced:p||x},{DOMException:x?b:f});var C=i(g),E=C.prototype;if(E.constructor!==C){p||r(E,"constructor",n(1,C));for(var S in h)if(s(h,S)){var k=h[S],P=k.s;s(C,P)||r(C,P,n(6,k.c))}}}),di=__webpack_require__.cw(()=>{var t=H(),e=Y(),i=__webpack_require__(812),n=we(),r=Ce(),s=e("URL");t({target:"URL",stat:!0,forced:!r},{parse:function parse(t){var e=i(arguments.length,1),r=n(t),a=e<2||void 0===arguments[1]?void 0:n(arguments[1]);try{return new s(r,a)}catch(t){return null}}})});Me();De();Ie();Re();qe();Ve();Ke();Ye();Je();Qe();Ze();ti();ei();ii();ri();si();ai();oi();di();const ui=!("object"!=typeof process||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&"browser"!==process.type),pi=[1/0,1/0,-1/0,-1/0],gi=new Float32Array(pi),mi=[.001,0,0,.001,0,0],fi="http://www.w3.org/2000/svg",bi=1,yi=2,wi=4,vi=16,_i=32,Ai=64,xi=128,Ci=256,Ei={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},Si="pdfjs_internal_id_",Ti="pdfjs_internal_editor_",ki={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101,COMMENT:102},Pi={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,INK_COLOR_AND_OPACITY:24,HIGHLIGHT_COLOR:31,HIGHLIGHT_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},Mi={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},Di=0,Ii=1,Fi=2,Oi=3,Ri=3,Bi=4,Li={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},Ni={TEXT:1,LINK:2,FREETEXT:3,LINE:4,SQUARE:5,CIRCLE:6,POLYGON:7,POLYLINE:8,HIGHLIGHT:9,UNDERLINE:10,SQUIGGLY:11,STRIKEOUT:12,STAMP:13,CARET:14,INK:15,POPUP:16,FILEATTACHMENT:17,SOUND:18,MOVIE:19,WIDGET:20,SCREEN:21,PRINTERMARK:22,TRAPNET:23,WATERMARK:24,THREED:25,REDACT:26,RICHMEDIA:27},Ui=1,Hi=2,zi=3,Gi=4,Wi=5,ji={ERRORS:0,WARNINGS:1,INFOS:5},Vi={dependency:1,setLineWidth:2,setLineCap:3,setLineJoin:4,setMiterLimit:5,setDash:6,setRenderingIntent:7,setFlatness:8,setGState:9,save:10,restore:11,transform:12,moveTo:13,lineTo:14,curveTo:15,curveTo2:16,curveTo3:17,closePath:18,rectangle:19,stroke:20,closeStroke:21,fill:22,eoFill:23,fillStroke:24,eoFillStroke:25,closeFillStroke:26,closeEOFillStroke:27,endPath:28,clip:29,eoClip:30,beginText:31,endText:32,setCharSpacing:33,setWordSpacing:34,setHScale:35,setLeading:36,setFont:37,setTextRenderingMode:38,setTextRise:39,moveText:40,setLeadingMoveText:41,setTextMatrix:42,nextLine:43,showText:44,showSpacedText:45,nextLineShowText:46,nextLineSetSpacingShowText:47,setCharWidth:48,setCharWidthAndBounds:49,setStrokeColorSpace:50,setFillColorSpace:51,setStrokeColor:52,setStrokeColorN:53,setFillColor:54,setFillColorN:55,setStrokeGray:56,setFillGray:57,setStrokeRGBColor:58,setFillRGBColor:59,setStrokeCMYKColor:60,setFillCMYKColor:61,shadingFill:62,beginInlineImage:63,beginImageData:64,endInlineImage:65,paintXObject:66,markPoint:67,markPointProps:68,beginMarkedContent:69,beginMarkedContentProps:70,endMarkedContent:71,beginCompat:72,endCompat:73,paintFormXObjectBegin:74,paintFormXObjectEnd:75,beginGroup:76,endGroup:77,beginAnnotation:80,endAnnotation:81,paintImageMaskXObject:83,paintImageMaskXObjectGroup:84,paintImageXObject:85,paintInlineImageXObject:86,paintInlineImageXObjectGroup:87,paintImageXObjectRepeat:88,paintImageMaskXObjectRepeat:89,paintSolidColorImageMask:90,constructPath:91,setStrokeTransparent:92,setFillTransparent:93,rawFillPath:94},qi=0,$i=1,Xi=2,Ki=3,Yi=4,Ji={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let Qi=ji.WARNINGS;function setVerbosityLevel(t){Number.isInteger(t)&&(Qi=t)}function getVerbosityLevel(){return Qi}function info(t){Qi>=ji.INFOS&&console.info(`Info: ${t}`)}function warn(t){Qi>=ji.WARNINGS&&console.warn(`Warning: ${t}`)}function unreachable(t){throw new Error(t)}function util_assert(t,e){t||unreachable(e)}function createValidAbsoluteUrl(t,e=null,i=null){if(!t)return null;if(i&&"string"==typeof t){if(i.addDefaultProtocol&&t.startsWith("www.")){const e=t.match(/\./g);e?.length>=2&&(t=`http://${t}`)}if(i.tryConvertEncoding)try{t=function stringToUTF8String(t){return decodeURIComponent(escape(t))}(t)}catch{}}const n=e?URL.parse(t,e):URL.parse(t);return function _isValidProtocol(t){switch(t?.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}(n)?n:null}function updateUrlHash(t,e,i=!1){const n=URL.parse(t);if(n){n.hash=e;return n.href}return i&&createValidAbsoluteUrl(t,"http://example.com")?t.split("#",1)[0]+""+(e?`#${e}`:""):""}function stripPath(t){return t.substring(t.lastIndexOf("/")+1)}function util_shadow(t,e,i,n=!1){Object.defineProperty(t,e,{value:i,enumerable:!n,configurable:!0,writable:!1});return i}const Zi=function BaseExceptionClosure(){function BaseException(t,e){this.message=t;this.name=e}BaseException.prototype=new Error;BaseException.constructor=BaseException;return BaseException}();class PasswordException extends Zi{constructor(t,e){super(t,"PasswordException");this.code=e}}class UnknownErrorException extends Zi{constructor(t,e){super(t,"UnknownErrorException");this.details=e}}class InvalidPDFException extends Zi{constructor(t){super(t,"InvalidPDFException")}}class ResponseException extends Zi{constructor(t,e,i){super(t,"ResponseException");this.status=e;this.missing=i}}class FormatError extends Zi{constructor(t){super(t,"FormatError")}}class AbortException extends Zi{constructor(t){super(t,"AbortException")}}function stringToBytes(t){"string"!=typeof t&&unreachable("Invalid argument for stringToBytes");const e=t.length,i=new Uint8Array(e);for(let n=0;n<e;++n)i[n]=255&t.charCodeAt(n);return i}class FeatureTest{static get isLittleEndian(){const t=new Uint8Array(4);t[0]=1;return util_shadow(this,"isLittleEndian",1===new Uint32Array(t.buffer,0,1)[0])}static get isOffscreenCanvasSupported(){return util_shadow(this,"isOffscreenCanvasSupported","undefined"!=typeof OffscreenCanvas)}static get isImageDecoderSupported(){return util_shadow(this,"isImageDecoderSupported","undefined"!=typeof ImageDecoder)}static get isVideoFrameSupported(){return util_shadow(this,"isVideoFrameSupported","undefined"!=typeof VideoFrame)}static get isFloat16ArraySupported(){return util_shadow(this,"isFloat16ArraySupported","undefined"!=typeof Float16Array)}static get isSanitizerSupported(){return util_shadow(this,"isSanitizerSupported","undefined"!=typeof Sanitizer)}static get platform(){const{platform:t,userAgent:e}=navigator;return util_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 isCanvasFilterSupported(){let t;this.isOffscreenCanvasSupported?t=new OffscreenCanvas(1,1).getContext("2d"):"undefined"!=typeof document&&(t=document.createElement("canvas").getContext("2d"));return util_shadow(this,"isCanvasFilterSupported",void 0!==t?.filter)}static get isAlphaColorInputSupported(){if("undefined"==typeof document)return util_shadow(this,"isAlphaColorInputSupported",!1);const t=document.createElement("input");t.type="color";t.setAttribute("alpha","");t.value="#ff000080";return util_shadow(this,"isAlphaColorInputSupported","#ff0000"!==t.value)}static get isBackdropFilterSupported(){return util_shadow(this,"isBackdropFilterSupported","undefined"!=typeof CSS&&CSS.supports("backdrop-filter","blur(1px)"))}}class Util{static get hexNums(){return util_shadow(this,"hexNums",Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0")))}static makeHexColor(t,e,i){return`#${this.hexNums[t]}${this.hexNums[e]}${this.hexNums[i]}`}static get identity0to256Map(){return util_shadow(this,"identity0to256Map",Uint8Array.from({length:256},(t,e)=>e))}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,i=0){const n=t[i],r=t[i+1];t[i]=n*e[0]+r*e[2]+e[4];t[i+1]=n*e[1]+r*e[3]+e[5]}static applyTransformToBezier(t,e,i=0){const n=e[0],r=e[1],s=e[2],a=e[3],o=e[4],l=e[5];for(let e=0;e<6;e+=2){const c=t[i+e],h=t[i+e+1];t[i+e]=c*n+h*s+o;t[i+e+1]=c*r+h*a+l}}static applyInverseTransform(t,e){const i=t[0],n=t[1],r=e[0]*e[3]-e[1]*e[2];t[0]=(i*e[3]-n*e[2]+e[2]*e[5]-e[4]*e[3])/r;t[1]=(-i*e[1]+n*e[0]+e[4]*e[1]-e[5]*e[0])/r}static axialAlignedBoundingBox(t,e,i){const n=e[0],r=e[1],s=e[2],a=e[3],o=e[4],l=e[5],c=t[0],h=t[1],d=t[2],u=t[3];let p=n*c+o,g=p,m=n*d+o,f=m,b=a*h+l,y=b,w=a*u+l,v=w;if(0!==r||0!==s){const t=r*c,e=r*d,i=s*h,n=s*u;p+=i;f+=i;m+=n;g+=n;b+=t;v+=t;w+=e;y+=e}i[0]=Math.min(i[0],p,m,Math.min(g,f));i[1]=Math.min(i[1],b,w,Math.min(y,v));i[2]=Math.max(i[2],p,m,Math.max(g,f));i[3]=Math.max(i[3],b,w,Math.max(y,v))}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 i=t[0],n=t[1],r=t[2],s=t[3],a=i**2+n**2,o=i*r+n*s,l=r**2+s**2,c=(a+l)/2,h=Math.sqrt(c**2-(a*l-o**2));e[0]=Math.sqrt(c+h||1);e[1]=Math.sqrt(c-h||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 i=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(i>n)return null;const r=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),s=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return r>s?null:[i,r,n,s]}static pointBoundingBox(t,e,i){i[0]=Math.min(i[0],t);i[1]=Math.min(i[1],e);i[2]=Math.max(i[2],t);i[3]=Math.max(i[3],e)}static rectBoundingBox(t,e,i,n,r){r[0]=Math.min(r[0],t,i);r[1]=Math.min(r[1],e,n);r[2]=Math.max(r[2],t,i);r[3]=Math.max(r[3],e,n)}static#t(t,e,i,n,r,s,a,o,l,c){if(l<=0||l>=1)return;const h=1-l,d=l*l,u=d*l,p=h*(h*(h*t+3*l*e)+3*d*i)+u*n,g=h*(h*(h*r+3*l*s)+3*d*a)+u*o;c[0]=Math.min(c[0],p);c[1]=Math.min(c[1],g);c[2]=Math.max(c[2],p);c[3]=Math.max(c[3],g)}static#e(t,e,i,n,r,s,a,o,l,c,h,d){if(Math.abs(l)<1e-12){Math.abs(c)>=1e-12&&this.#t(t,e,i,n,r,s,a,o,-h/c,d);return}const u=c**2-4*h*l;if(u<0)return;const p=Math.sqrt(u),g=2*l;this.#t(t,e,i,n,r,s,a,o,(-c+p)/g,d);this.#t(t,e,i,n,r,s,a,o,(-c-p)/g,d)}static bezierBoundingBox(t,e,i,n,r,s,a,o,l){l[0]=Math.min(l[0],t,a);l[1]=Math.min(l[1],e,o);l[2]=Math.max(l[2],t,a);l[3]=Math.max(l[3],e,o);this.#e(t,i,r,a,e,n,s,o,3*(3*(i-r)-t+a),6*(t-2*i+r),3*(i-t),l);this.#e(t,i,r,a,e,n,s,o,3*(3*(n-s)-e+o),6*(e-2*n+s),3*(n-e),l)}}let tn=null,en=null;function normalizeUnicode(t){if(!tn){tn=/([\u00a0\u00b5\u037e\u0eb3\u2000-\u200a\u202f\u2126\ufb00-\ufb04\ufb06\ufb20-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufba1\ufba4-\ufba9\ufbae-\ufbb1\ufbd3-\ufbdc\ufbde-\ufbe7\ufbea-\ufbf8\ufbfc\ufbfd\ufc00-\ufc5d\ufc64-\ufcf1\ufcf5-\ufd3d\ufd88\ufdf4\ufdfa\ufdfb\ufe71\ufe77\ufe79\ufe7b\ufe7d]+)|(\ufb05+)/gu;en=new Map([["ſt","ſt"]])}return t.replaceAll(tn,(t,e,i)=>e?e.normalize("NFKC"):en.get(i))}function getUuid(){if("function"==typeof crypto.randomUUID)return crypto.randomUUID();const t=new Uint8Array(32);crypto.getRandomValues(t);return function bytesToString(t){"object"==typeof t&&void 0!==t?.length||unreachable("Invalid argument for bytesToString");const e=t.length,i=8192;if(e<i)return String.fromCharCode.apply(null,t);const n=[];for(let r=0;r<e;r+=i){const s=Math.min(r+i,e),a=t.subarray(r,s);n.push(String.fromCharCode.apply(null,a))}return n.join("")}(t)}const makeArr=()=>[],makeMap=()=>new Map,makeObj=()=>Object.create(null),makeSet=()=>new Set;"function"!=typeof Blob.prototype.bytes&&(Blob.prototype.bytes=async function(){return new Uint8Array(await this.arrayBuffer())});"function"!=typeof Response.prototype.bytes&&(Response.prototype.bytes=async function(){return new Uint8Array(await this.arrayBuffer())});"function"!=typeof Iterator.prototype.join&&(Iterator.prototype.join=function(t){return[...this].join(t)});Ue();function MathClamp(t,e,i){return Math.min(Math.max(t,e),i)}class PixelsPerInch{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}class RenderingCancelledException extends Zi{constructor(t,e=0){super(t,"RenderingCancelledException");this.extraDelay=e}}function getRGBA(t){if(t.startsWith("#")){const e=t.slice(1);return[parseInt(e.slice(0,2),16),parseInt(e.slice(2,4),16),parseInt(e.slice(4,6),16),e.length>=8?parseInt(e.slice(6,8),16)/255:1]}if(t.startsWith("rgb(")){const[e,i,n]=t.slice(4,-1).split(",").map(t=>parseInt(t,10));return[e,i,n,1]}if(t.startsWith("rgba(")){const e=t.slice(5,-1).split(",");return[parseInt(e[0],10),parseInt(e[1],10),parseInt(e[2],10),parseFloat(e[3])]}const e=t.match(/^color\(srgb\s+([\d.]+)\s+([\d.]+)\s+([\d.]+)(?:\s*\/\s*([\d.]+|none))?\)$/);return e?[Math.round(255*parseFloat(e[1])),Math.round(255*parseFloat(e[2])),Math.round(255*parseFloat(e[3])),void 0!==e[4]&&"none"!==e[4]?parseFloat(e[4]):1]:null}function getRGB(t){const e=getRGBA(t);if(!e){warn(`Not a valid color format: "${t}"`);return[0,0,0]}return e.slice(0,3)}function getCurrentTransform(t){const{a:e,b:i,c:n,d:r,e:s,f:a}=t.getTransform();return[e,i,n,r,s,a]}function getCurrentTransformInverse(t){const{a:e,b:i,c:n,d:r,e:s,f:a}=t.getTransform().invertSelf();return[e,i,n,r,s,a]}class OutputScale{constructor(){const{pixelRatio:t}=OutputScale;this.sx=t;this.sy=t}get scaled(){return 1!==this.sx||1!==this.sy}get symmetric(){return this.sx===this.sy}limitCanvas(t,e,i,n,r=-1){let s=1/0,a=1/0,o=1/0;(i=OutputScale.capPixels(i,r))>0&&(s=Math.sqrt(i/(t*e)));if(-1!==n){a=n/t;o=n/e}const l=Math.min(s,a,o);if(this.sx>l||this.sy>l){this.sx=l;this.sy=l;return!0}return!1}static get pixelRatio(){return globalThis.devicePixelRatio||1}static capPixels(t,e){if(e>=0){const i=Math.ceil(window.screen.availWidth*window.screen.availHeight*this.pixelRatio**2*(1+e/100));return t>0?Math.min(t,i):i}return t}}function applyOpacity(t,e){const i=255*(1-(e=MathClamp(e??1,0,1)));return t.map(t=>Math.round(t*e+i))}function RGBToHSL(t,e){const i=t[0]/255,n=t[1]/255,r=t[2]/255,s=Math.max(i,n,r),a=Math.min(i,n,r),o=(s+a)/2;if(s===a)e[0]=e[1]=0;else{const t=s-a;e[1]=o<.5?t/(s+a):t/(2-s-a);switch(s){case i:e[0]=60*((n-r)/t+(n<r?6:0));break;case n:e[0]=60*((r-i)/t+2);break;case r:e[0]=60*((i-n)/t+4)}}e[2]=o}function HSLToRGB(t,e){const i=t[0],n=t[1],r=t[2],s=(1-Math.abs(2*r-1))*n,a=s*(1-Math.abs(i/60%2-1)),o=r-s/2;switch(Math.floor(i/60)){case 0:e[0]=s+o;e[1]=a+o;e[2]=o;break;case 1:e[0]=a+o;e[1]=s+o;e[2]=o;break;case 2:e[0]=o;e[1]=s+o;e[2]=a+o;break;case 3:e[0]=o;e[1]=a+o;e[2]=s+o;break;case 4:e[0]=a+o;e[1]=o;e[2]=s+o;break;case 5:case 6:e[0]=s+o;e[1]=o;e[2]=a+o}}function computeLuminance(t){return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function contrastRatio(t,e,i){HSLToRGB(t,i);i.map(computeLuminance);const n=.2126*i[0]+.7152*i[1]+.0722*i[2];HSLToRGB(e,i);i.map(computeLuminance);const r=.2126*i[0]+.7152*i[1]+.0722*i[2];return n>r?(n+.05)/(r+.05):(r+.05)/(n+.05)}const nn=new Map;function findContrastColor(t,e){const i=t[0]+256*t[1]+65536*t[2]+16777216*e[0]+4294967296*e[1]+1099511627776*e[2];let n=nn.get(i);if(n)return n;const r=new Float32Array(9),s=r.subarray(0,3),a=r.subarray(3,6);RGBToHSL(t,a);const o=r.subarray(6,9);RGBToHSL(e,o);const l=o[2]<.5,c=l?12:4.5;a[2]=l?Math.sqrt(a[2]):1-Math.sqrt(1-a[2]);if(contrastRatio(a,o,s)<c){let t,e;if(l){t=a[2];e=1}else{t=0;e=a[2]}const i=.005;for(;e-t>i;){const i=a[2]=(t+e)/2;l===contrastRatio(a,o,s)<c?t=i:e=i}a[2]=l?e:t}HSLToRGB(a,s);n=Util.makeHexColor(Math.round(255*s[0]),Math.round(255*s[1]),Math.round(255*s[2]));nn.set(i,n);return n}function makePathFromDrawOPS(t){const e=new Path2D;if(!t)return e;for(let i=0,n=t.length;i<n;)switch(t[i++]){case qi:e.moveTo(t[i++],t[i++]);break;case $i:e.lineTo(t[i++],t[i++]);break;case Xi:e.bezierCurveTo(t[i++],t[i++],t[i++],t[i++],t[i++],t[i++]);break;case Ki:e.quadraticCurveTo(t[i++],t[i++],t[i++],t[i++]);break;case Yi:e.closePath();break;default:warn(`Unrecognized drawing path operator: ${t[i-1]}`)}return e}ze();ci();li();He();je();hi();Fe();Oe();Be();We();class PageViewport{constructor({viewBox:t,userUnit:e,scale:i,rotation:n,offsetX:r=0,offsetY:s=0,dontFlip:a=!1}){this.viewBox=t;this.userUnit=e;this.scale=i;this.rotation=n;this.offsetX=r;this.offsetY=s;i*=e;const o=(t[2]+t[0])/2,l=(t[3]+t[1])/2;let c,h,d,u,p,g,m,f;(n%=360)<0&&(n+=360);switch(n){case 180:c=-1;h=0;d=0;u=1;break;case 90:c=0;h=1;d=1;u=0;break;case 270:c=0;h=-1;d=-1;u=0;break;case 0:c=1;h=0;d=0;u=-1;break;default:throw new Error("PageViewport: Invalid rotation, must be a multiple of 90 degrees.")}if(a){d=-d;u=-u}if(0===c){p=Math.abs(l-t[1])*i+r;g=Math.abs(o-t[0])*i+s;m=(t[3]-t[1])*i;f=(t[2]-t[0])*i}else{p=Math.abs(o-t[0])*i+r;g=Math.abs(l-t[1])*i+s;m=(t[2]-t[0])*i;f=(t[3]-t[1])*i}this.transform=[c*i,h*i,d*i,u*i,p-c*i*o-d*i*l,g-h*i*o-u*i*l];this.width=m;this.height=f}get rawDims(){const t=this.viewBox;return util_shadow(this,"rawDims",{pageWidth:t[2]-t[0],pageHeight:t[3]-t[1],pageX:t[0],pageY:t[1]})}clone({scale:t=this.scale,rotation:e=this.rotation,offsetX:i=this.offsetX,offsetY:n=this.offsetY,dontFlip:r=!1}={}){return new PageViewport({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:i,offsetY:n,dontFlip:r})}convertToViewportPoint(t,e){const i=[t,e];Util.applyTransform(i,this.transform);return i}convertToPdfPoint(t,e){const i=[t,e];Util.applyInverseTransform(i,this.transform);return i}}class XfaText{static textContent(t){const e=[],i={items:e,styles:Object.create(null)};!function walk(t){if(!t)return;let i=null;const n=t.name;if("#text"===n)i=t.value;else{if(!XfaText.shouldBuildText(n))return;t?.attributes?.textContent?i=t.attributes.textContent:t.value&&(i=t.value)}null!==i&&e.push({str:i});if(t.children)for(const e of t.children)walk(e)}(t);return i}static shouldBuildText(t){return!("textarea"===t||"input"===t||"option"===t||"select"===t)}}const rn=/url\(|image-set\(/i,sn=/^on/i;class XfaLayer{static get _allowedHtmlElements(){return util_shadow(this,"_allowedHtmlElements",new Set(["a","b","br","button","div","i","img","input","label","li","ol","option","p","select","span","sub","sup","textarea","ul"]))}static get _allowedSvgElements(){return util_shadow(this,"_allowedSvgElements",new Set(["ellipse","line","path","rect","svg"]))}static get _allowedRichTextElements(){return util_shadow(this,"_allowedRichTextElements",new Set(["a","b","br","div","i","li","ol","p","span","sub","sup","ul"]))}static get _allowedRichTextAttributes(){return util_shadow(this,"_allowedRichTextAttributes",new Set(["class","dir","style"]))}static get _allowedRichTextStyles(){return util_shadow(this,"_allowedRichTextStyles",new Set(["color","font","fontFamily","fontSize","fontStretch","fontStyle","fontWeight","kerningMode","letterSpacing","lineHeight","margin","marginBottom","marginLeft","marginRight","marginTop","orphans","paddingLeft","paddingRight","breakAfter","breakBefore","breakInside","tabInterval","tabStop","textAlign","textDecoration","textIndent","transform","verticalAlign","widows"]))}static setupStorage(t,e,i,n,r){const s=n.getValue(e,{value:null});switch(i.name){case"textarea":null!==s.value&&(t.textContent=s.value);if("print"===r)break;t.addEventListener("input",t=>{n.setValue(e,{value:t.target.value})});break;case"input":if("radio"===i.attributes.type||"checkbox"===i.attributes.type){s.value===i.attributes.xfaOn?t.setAttribute("checked",!0):s.value===i.attributes.xfaOff&&t.removeAttribute("checked");if("print"===r)break;t.addEventListener("change",t=>{n.setValue(e,{value:t.target.checked?t.target.getAttribute("xfaOn"):t.target.getAttribute("xfaOff")})})}else{null!==s.value&&t.setAttribute("value",s.value);if("print"===r)break;t.addEventListener("input",t=>{n.setValue(e,{value:t.target.value})})}break;case"select":if(null!==s.value){t.setAttribute("value",s.value);for(const t of i.children)t.attributes.value===s.value?t.attributes.selected=!0:Object.hasOwn(t.attributes,"selected")&&delete t.attributes.selected}t.addEventListener("input",t=>{const i=t.target.options,r=-1===i.selectedIndex?"":i[i.selectedIndex].value;n.setValue(e,{value:r})})}}static setAttributes({html:t,element:e,storage:i=null,intent:n,linkService:r}){const{attributes:s}=e,a=t instanceof HTMLAnchorElement;"radio"===s.type&&(s.name=`${s.name}-${n}`);for(const[e,i]of Object.entries(s))if(null!=i&&!sn.test(e)&&("richText"!==n||this._allowedRichTextAttributes.has(e)))switch(e){case"class":i.length&&t.setAttribute(e,i.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",i);break;case"style":if("richText"===n){const e=this._allowedRichTextStyles;for(const[n,r]of Object.entries(i))e.has(n)&&!rn.test(r)&&(t.style[n]=r)}else Object.assign(t.style,i);break;case"textContent":t.textContent=i;break;default:(!a||"href"!==e&&"newWindow"!==e)&&t.setAttribute(e,i)}a&&r?.addLinkAttributes(t,s.href,s.newWindow);i&&s.dataId&&this.setupStorage(t,s.dataId,e,i)}static#i(t,e,i){return"richText"===i?!e&&this._allowedRichTextElements.has(t)?document.createElement(t):null:e?e===fi&&this._allowedSvgElements.has(t)?document.createElementNS(fi,t):null:this._allowedHtmlElements.has(t)?document.createElement(t):null}static render(t){const e=t.annotationStorage,i=t.linkService,n=t.xfaHtml,r=t.intent||"display",s=this.#i(n.name,n.attributes?.xmlns,r)??document.createElement("div");n.attributes&&this.setAttributes({html:s,element:n,intent:r,linkService:i});const a="richText"!==r,o=t.div;o.append(s);if(t.viewport){const e=`matrix(${t.viewport.transform.join(",")})`;o.style.transform=e}a&&o.setAttribute("class","xfaLayer xfaFont");const l=[];if(0===n.children.length){if(n.value){const t=document.createTextNode(n.value);s.append(t);a&&XfaText.shouldBuildText(n.name)&&l.push(t)}return{textDivs:l}}const c=[[n,-1,s]];for(;c.length>0;){const[t,n,s]=c.at(-1);if(n+1===t.children.length){c.pop();continue}const o=t.children[++c.at(-1)[1]];if(null===o)continue;const{name:h}=o;if("#text"===h){const t=document.createTextNode(o.value);l.push(t);s.append(t);continue}const d=this.#i(h,o.attributes?.xmlns,r);if(d){s.append(d);o.attributes&&this.setAttributes({html:d,element:o,storage:e,intent:r,linkService:i});if(o.children?.length>0)c.push([o,-1,d]);else if(o.value){const t=document.createTextNode(o.value);a&&XfaText.shouldBuildText(h)&&l.push(t);d.append(t)}}}for(const t of o.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))t.setAttribute("readOnly",!0);return{textDivs:l}}static update(t){const e=`matrix(${t.viewport.transform.join(",")})`;t.div.style.transform=e;t.div.hidden=!1}static getPageViewport(t,{scale:e=1,rotation:i=0}){const{width:n,height:r}=t.attributes.style;return new PageViewport({viewBox:[0,0,parseInt(n,10),parseInt(r,10)],userUnit:1,scale:e,rotation:i})}}async function fetchData(t,e="text"){if(isValidFetchUrl(t,document.baseURI)){const i=await fetch(t);if(!i.ok)throw new Error(i.statusText);switch(e){case"blob":return i.blob();case"bytes":return i.bytes();case"json":return i.json()}return i.text()}return new Promise((i,n)=>{const r=new XMLHttpRequest;r.open("GET",t,!0);r.responseType="bytes"===e?"arraybuffer":e;r.onreadystatechange=()=>{if(r.readyState===XMLHttpRequest.DONE)if(200!==r.status&&0!==r.status)n(new Error(r.statusText));else{switch(e){case"bytes":i(new Uint8Array(r.response));return;case"blob":case"json":i(r.response);return}i(r.responseText)}};r.send(null)})}function isDataScheme(t){const e=t.length;let i=0;for(;i<e&&""===t[i].trim();)i++;return"data:"===t.substring(i,i+5).toLowerCase()}function isPdfFile(t){return"string"==typeof t&&/\.pdf$/i.test(t)}function getFilenameFromUrl(t){[t]=t.split(/[#?]/,1);return stripPath(t)}function getPdfFilenameFromUrl(t,e="document.pdf"){if("string"!=typeof t)return e;if(isDataScheme(t)){warn('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.');return e}const i=(t=>{try{return new URL(t)}catch{}try{return new URL(decodeURIComponent(t))}catch{}try{return new URL(t,"https://foo.bar")}catch{}try{return new URL(decodeURIComponent(t),"https://foo.bar")}catch{}return null})(t);if(!i)return e;const decode=t=>{try{let e=decodeURIComponent(t);if(e.includes("/")){e=stripPath(e);if(4===e.length&&n.test(e))return t}return e}catch{return t}},n=/\.pdf$/i,r=stripPath(i.pathname);if(n.test(r))return decode(r);if(i.searchParams.size>0){const getLast=t=>[...t].findLast(t=>n.test(t)),t=getLast(i.searchParams.values())??getLast(i.searchParams.keys());if(t)return decode(t)}if(i.hash){const{hash:t}=i;let e=-1;for(const{index:i}of t.matchAll(/\.pdf\b/gi))e=i;if(e>0){let i=e;for(;i>0&&!"/?#=".includes(t[i-1]);)i--;if(i<e)return decode(t.slice(i,e+4))}}return e}function isValidFetchUrl(t,e){const i=e?URL.parse(t,e):URL.parse(t);return/https?:/.test(i?.protocol??"")}function noContextMenu(t){t.preventDefault()}function stopEvent(t){t.preventDefault();t.stopPropagation()}class PDFDateString{static#n;static toDateObject(t){if(t instanceof Date)return t;if(!t||"string"!=typeof t)return null;this.#n||=new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+\\-])?(\\d{2})?'?(\\d{2})?'?");const e=this.#n.exec(t);if(!e)return null;const i=parseInt(e[1],10);let n=parseInt(e[2],10);n=n>=1&&n<=12?n-1:0;let r=parseInt(e[3],10);r=r>=1&&r<=31?r:1;let s=parseInt(e[4],10);s=s>=0&&s<=23?s:0;let a=parseInt(e[5],10);a=a>=0&&a<=59?a:0;let o=parseInt(e[6],10);o=o>=0&&o<=59?o:0;const l=e[7]||"Z";let c=parseInt(e[8],10);c=c>=0&&c<=23?c:0;let h=parseInt(e[9],10)||0;h=h>=0&&h<=59?h:0;if("-"===l){s+=c;a+=h}else if("+"===l){s-=c;a-=h}return new Date(Date.UTC(i,n,r,s,a,o))}}function setLayerDimensions(t,e,i=!1,n=!0){if(e instanceof PageViewport){const{pageWidth:n,pageHeight:r}=e.rawDims,{style:s}=t,a=`round(down, var(--total-scale-factor) * ${n}px, var(--scale-round-x))`,o=`round(down, var(--total-scale-factor) * ${r}px, var(--scale-round-y))`;if(i&&e.rotation%180!=0){s.width=o;s.height=a}else{s.width=a;s.height=o}}n&&t.setAttribute("data-main-rotation",e.rotation)}const an=new Set(["image/apng","image/avif","image/bmp","image/gif","image/jpeg","image/png","image/svg+xml","image/webp","image/x-icon"]);class ColorScheme{static get isDarkMode(){return util_shadow(this,"isDarkMode",!!window?.matchMedia?.("(prefers-color-scheme: dark)").matches)}}class CSSConstants{static get commentForegroundColor(){const t=document.createElement("span");t.classList.add("comment","sidebar");const{style:e}=t;e.width=e.height="0";e.display="none";e.color="var(--comment-fg-color)";document.body.append(t);const{color:i}=window.getComputedStyle(t);t.remove();return util_shadow(this,"commentForegroundColor",getRGB(i))}}function renderRichText({html:t,dir:e,className:i},n){const r=document.createDocumentFragment();if("string"==typeof t){const i=document.createElement("p");i.dir=e||"auto";const n=t.split(/\r\n?|\n/);for(let t=0,e=n.length;t<e;++t){const r=n[t];i.append(document.createTextNode(r));t<e-1&&i.append(document.createElement("br"))}r.append(i)}else XfaLayer.render({xfaHtml:t,div:r,intent:"richText"});r.firstElementChild.classList.add("richText",i);n.append(r)}class EditorToolbar{#r=null;#s=null;#a;#o=null;#l=null;#c=null;#h=null;#d=null;static#u=null;constructor(t){this.#a=t;EditorToolbar.#u||=Object.freeze({freetext:"pdfjs-editor-remove-freetext-button",highlight:"pdfjs-editor-remove-highlight-button",ink:"pdfjs-editor-remove-ink-button",stamp:"pdfjs-editor-remove-stamp-button",signature:"pdfjs-editor-remove-signature-button"})}render(){const t=this.#r=document.createElement("div");t.classList.add("editToolbar","hidden");t.setAttribute("role","toolbar");const e=this.#a._uiManager._signal;if(e instanceof AbortSignal&&!e.aborted){t.addEventListener("contextmenu",noContextMenu,{signal:e});t.addEventListener("pointerdown",EditorToolbar.#p,{signal:e})}const i=this.#o=document.createElement("div");i.className="buttons";t.append(i);const n=this.#a.toolbarPosition;if(n){const{style:e}=t,i="ltr"===this.#a._uiManager.direction?1-n[0]:n[0];e.insetInlineEnd=100*i+"%";e.top=`calc(${100*n[1]}% + var(--editor-toolbar-vert-offset))`}return t}get div(){return this.#r}static#p(t){t.stopPropagation()}#g(t){this.#a._focusEventsAllowed=!1;stopEvent(t)}#m(t){this.#a._focusEventsAllowed=!0;stopEvent(t)}#f(t){const e=this.#a._uiManager._signal;if(!(e instanceof AbortSignal)||e.aborted)return!1;t.addEventListener("focusin",this.#g.bind(this),{capture:!0,signal:e});t.addEventListener("focusout",this.#m.bind(this),{capture:!0,signal:e});t.addEventListener("contextmenu",noContextMenu,{signal:e});return!0}hide(){this.#r.classList.add("hidden");this.#s?.hideDropdown()}show(){this.#r.classList.remove("hidden");this.#l?.shown();this.#c?.shown()}addDeleteButton(){const{editorType:t,_uiManager:e}=this.#a,i=document.createElement("button");i.classList.add("basic","deleteButton");i.tabIndex=0;i.setAttribute("data-l10n-id",EditorToolbar.#u[t]);this.#f(i)&&i.addEventListener("click",t=>{e.delete()},{signal:e._signal});this.#o.append(i)}get#b(){const t=document.createElement("div");t.className="divider";return t}async addAltText(t){const e=await t.render();this.#f(e);this.#o.append(e,this.#b);this.#l=t}addComment(t,e=null){if(this.#c)return;const i=t.renderForToolbar();if(!i)return;this.#f(i);const n=this.#h=this.#b;if(e){this.#o.insertBefore(i,e);this.#o.insertBefore(n,e)}else this.#o.append(i,n);this.#c=t;t.toolbar=this}addColorPicker(t){if(this.#s)return;this.#s=t;const e=t.renderButton();this.#f(e);this.#o.append(e,this.#b)}async addEditSignatureButton(t){const e=this.#d=await t.renderEditButton(this.#a);if(e){this.#f(e);this.#o.append(e,this.#b)}}removeButton(t){if("comment"===t){this.#c?.removeToolbarCommentButton();this.#c=null;this.#h?.remove();this.#h=null}}async addButton(t,e){switch(t){case"colorPicker":e&&this.addColorPicker(e);break;case"altText":e&&await this.addAltText(e);break;case"editSignature":e&&await this.addEditSignatureButton(e);break;case"delete":this.addDeleteButton();break;case"comment":e&&this.addComment(e)}}async addButtonBefore(t,e,i){if(!e&&"comment"===t)return;const n=this.#o.querySelector(i);n&&"comment"===t&&this.addComment(e,n)}updateEditSignatureButton(t){this.#d&&(this.#d.title=t)}remove(){this.#r.remove();this.#s?.destroy();this.#s=null}}class FloatingToolbar{#o=null;#r=null;#y;constructor(t){this.#y=t}#w(){const t=this.#r=document.createElement("div");t.className="editToolbar";t.setAttribute("role","toolbar");t.dir=this.#y.direction;const e=this.#y._signal;e instanceof AbortSignal&&!e.aborted&&t.addEventListener("contextmenu",noContextMenu,{signal:e});const i=this.#o=document.createElement("div");i.className="buttons";t.append(i);this.#y.hasCommentManager()&&this.#v("commentButton","pdfjs-comment-floating-button","pdfjs-comment-floating-button-label",()=>{this.#y.commentSelection("floating_button")});this.#v("highlightButton","pdfjs-highlight-floating-button1","pdfjs-highlight-floating-button-label",()=>{this.#y.highlightSelection("floating_button")});return t}#_(t,e){let i=0,n=0;for(const r of t){const t=r.y+r.height;if(t<i)continue;const s=r.x+(e?r.width:0);if(t>i){n=s;i=t}else e?s>n&&(n=s):s<n&&(n=s)}return[e?1-n:n,i]}show(t,e,i){const[n,r]=this.#_(e,i),{style:s}=this.#r||=this.#w();t.append(this.#r);s.insetInlineEnd=100*n+"%";s.top=`calc(${100*r}% + var(--editor-toolbar-vert-offset))`}hide(){this.#r.remove()}#v(t,e,i,n){const r=document.createElement("button");r.classList.add("basic",t);r.tabIndex=0;r.setAttribute("data-l10n-id",e);const s=document.createElement("span");r.append(s);s.className="visuallyHidden";s.setAttribute("data-l10n-id",i);const a=this.#y._signal;if(a instanceof AbortSignal&&!a.aborted){r.addEventListener("contextmenu",noContextMenu,{signal:a});r.addEventListener("click",n,{signal:a})}this.#o.append(r)}}const on=Object.freeze({internal:"0a475cb6-573c-46ed-869d-fa7c5839d995"});function bindEvents(t,e,i){for(const n of i)e.addEventListener(n,t[n].bind(t))}class CurrentPointers{static#A=NaN;static#x=null;static#C=NaN;static#E=null;static initializeAndAddPointerId(t){(CurrentPointers.#x||=new Set).add(t)}static setPointer(t,e){CurrentPointers.#A||=e;CurrentPointers.#E??=t}static setTimeStamp(t){CurrentPointers.#C=t}static isSamePointerId(t){return CurrentPointers.#A===t}static isSamePointerIdOrRemove(t){if(CurrentPointers.#A===t)return!0;CurrentPointers.#x?.delete(t);return!1}static isSamePointerType(t){return CurrentPointers.#E===t}static isInitializedAndDifferentPointerType(t){return null!==CurrentPointers.#E&&!CurrentPointers.isSamePointerType(t)}static isSameTimeStamp(t){return CurrentPointers.#C===t}static isUsingMultiplePointers(){return CurrentPointers.#x?.size>=1}static clearPointerType(){CurrentPointers.#E=null}static clearPointerIds(){CurrentPointers.#A=NaN;CurrentPointers.#x=null}static clearTimeStamp(){CurrentPointers.#C=NaN}}class IdManager{#S=0;get id(){return`${Ti}${this.#S++}`}}class ImageManager{#T=getUuid();#S=0;#k=null;static get _isSVGFittingCanvas(){const t=`data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="${fi}"><rect width="1" height="1" style="fill:red;"/></svg>`,e=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),i=new Image;i.src=t;return util_shadow(this,"_isSVGFittingCanvas",i.decode().then(()=>{e.drawImage(i,0,0,1,1,0,0,1,3);return 0===new Uint32Array(e.getImageData(0,0,1,1).data.buffer)[0]}))}async#P(t,e){this.#k||=new Map;let i=this.#k.get(t);if(null===i)return null;if(i?.bitmap){i.refCounter+=1;return i}try{i||={bitmap:null,id:`image_${this.#T}_${this.#S++}`,refCounter:0,isSvg:!1};let t;if("string"==typeof e){i.url=e;t=await fetchData(e,"blob")}else e instanceof File?t=i.file=e:e instanceof Blob&&(t=e);if("image/svg+xml"===t.type){const e=ImageManager._isSVGFittingCanvas,n=new FileReader,r=new Image,s=new Promise((t,s)=>{r.onload=()=>{i.bitmap=r;i.isSvg=!0;t()};n.onload=async()=>{const t=i.svgUrl=n.result;r.src=await e?`${t}#svgView(preserveAspectRatio(none))`:t};r.onerror=n.onerror=s});n.readAsDataURL(t);await s}else i.bitmap=await createImageBitmap(t);i.refCounter=1}catch(t){warn(t);i=null}this.#k.set(t,i);i&&this.#k.set(i.id,i);return i}async getFromFile(t){const{lastModified:e,name:i,size:n,type:r}=t;return this.#P(`${e}_${i}_${n}_${r}`,t)}async getFromUrl(t){return this.#P(t,t)}async getFromBlob(t,e){const i=await e;return this.#P(t,i)}async getFromId(t){this.#k||=new Map;const e=this.#k.get(t);if(!e)return null;if(e.bitmap){e.refCounter+=1;return e}if(e.file)return this.getFromFile(e.file);if(e.blobPromise){const{blobPromise:t}=e;delete e.blobPromise;return this.getFromBlob(e.id,t)}return this.getFromUrl(e.url)}getFromCanvas(t,e){this.#k||=new Map;let i=this.#k.get(t);if(i?.bitmap){i.refCounter+=1;return i}const n=new OffscreenCanvas(e.width,e.height);n.getContext("2d").drawImage(e,0,0);i={bitmap:n.transferToImageBitmap(),id:`image_${this.#T}_${this.#S++}`,refCounter:1,isSvg:!1};this.#k.set(t,i);this.#k.set(i.id,i);return i}getSvgUrl(t){const e=this.#k.get(t);return e?.isSvg?e.svgUrl:null}deleteId(t){this.#k||=new Map;const e=this.#k.get(t);if(!e)return;e.refCounter-=1;if(0!==e.refCounter)return;const{bitmap:i}=e;if(!e.url&&!e.file){const t=new OffscreenCanvas(i.width,i.height);t.getContext("bitmaprenderer").transferFromImageBitmap(i);e.blobPromise=t.convertToBlob()}i.close?.();e.bitmap=null}isValidId(t){return t.startsWith(`image_${this.#T}_`)}}class CommandManager{#M=[];#D=!1;#I;#F=-1;constructor(t=128){this.#I=t}add({cmd:t,undo:e,post:i,mustExec:n,type:r=NaN,overwriteIfSameType:s=!1,keepUndo:a=!1}){n&&t();if(this.#D)return;const o={cmd:t,undo:e,post:i,type:r};if(-1===this.#F){this.#M.length>0&&(this.#M.length=0);this.#F=0;this.#M.push(o);return}if(s&&this.#M[this.#F].type===r){a&&(o.undo=this.#M[this.#F].undo);this.#M[this.#F]=o;return}const l=this.#F+1;if(l===this.#I)this.#M.splice(0,1);else{this.#F=l;l<this.#M.length&&this.#M.splice(l)}this.#M.push(o)}undo(){if(-1===this.#F)return;this.#D=!0;const{undo:t,post:e}=this.#M[this.#F];t();e?.();this.#D=!1;this.#F-=1}redo(){if(this.#F<this.#M.length-1){this.#F+=1;this.#D=!0;const{cmd:t,post:e}=this.#M[this.#F];t();e?.();this.#D=!1}}hasSomethingToUndo(){return-1!==this.#F}hasSomethingToRedo(){return this.#F<this.#M.length-1}cleanType(t){if(-1!==this.#F){for(let e=this.#F;e>=0;e--)if(this.#M[e].type!==t){this.#M.splice(e+1,this.#F-e);this.#F=e;return}this.#M.length=0;this.#F=-1}}destroy(){this.#M=null}}class KeyboardManager{static ALT=1;static CTRL=2;static META=4;static SHIFT=8;constructor(t){this.callbacks=new Map;const{isMac:e}=FeatureTest.platform;for(const[i,n,r={}]of t){const t=i.some(t=>t.startsWith("mac+"));for(const s of i){let i=s;if(t){const t=s.startsWith("mac+");if(e!==t)continue;t&&(i=s.slice(4))}const[a,o]=KeyboardManager.#O(i);null!==a&&this.callbacks.getOrInsertComputed(a,makeArr).push({callback:n,options:r,modifiers:o})}}}static#O(t){let e=null,i=0;for(let n of t.split("+")){n=n.trim();if(!n)continue;const r=n.toUpperCase(),s=KeyboardManager[r];if(s)i|=s;else{if(null!==e){warn(`KeyboardManager: multiple keys in shortcut "${t}"`);break}e="SPACE"===r?" ":n}}null===e&&warn(`KeyboardManager: no key found in shortcut "${t}"`);return[e,i]}static#R(t){const e=/^(?:Key([A-Z])|(?:Digit|Numpad)(\d))$/.exec(t);return e?e[1]?.toLowerCase()??e[2]:null}exec(t,e){let i=this.callbacks.get(e.key);if(!i){if(/^[a-z]$/i.test(e.key))return;const t=KeyboardManager.#R(e.code);if(null===t||t===e.key)return;i=this.callbacks.get(t);if(!i)return}const n=(e.altKey?KeyboardManager.ALT:0)|(e.ctrlKey?KeyboardManager.CTRL:0)|(e.metaKey?KeyboardManager.META:0)|(e.shiftKey?KeyboardManager.SHIFT:0),r=i.find(t=>t.modifiers===n);if(!r)return;const{callback:s,options:{bubbles:a=!1,args:o=[],checker:l=null}}=r;if(!l||l(t,e)){s.bind(t,...o,e)();a||stopEvent(e)}}}class ColorManager{static _colorsMapping=new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]);get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);!function getColorValues(t){const e=document.createElement("span");e.style.visibility="hidden";e.style.colorScheme="only light";document.body.append(e);for(const i of t.keys()){e.style.color=i;const n=window.getComputedStyle(e).color;t.set(i,getRGB(n))}e.remove()}(t);return util_shadow(this,"_colors",t)}convert(t){const e=getRGB(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(const[t,i]of this._colors)if(i.every((t,i)=>t===e[i]))return ColorManager._colorsMapping.get(t);return e}getHexCode(t){const e=this._colors.get(t);return e?Util.makeHexColor(...e):t}}class AnnotationEditorUIManager{#B=new AbortController;#L=null;#N=null;#U=new Map;#H=new Map;#z=null;#G=null;#W=null;#j=null;#V=null;#q=new CommandManager;#$=null;#X=null;#K=null;#Y=0;#J=new Set;#Q=null;#Z=null;#tt=new Set;_editorUndoBar=null;#et=!1;#it=!1;#nt=!1;#rt=null;#st=null;#at=null;#ot=null;#lt=!1;#ct=null;#ht=new IdManager;#dt=!1;#ut=!1;#pt=!1;#gt=null;#mt=null;#ft=null;#bt=null;#yt=null;#wt=ki.NONE;#vt=new Set;#_t=null;#At=null;#xt=null;#Ct=null;#Et=null;#St={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#Tt=[0,0];#kt=null;#Pt=null;#Mt=null;#Dt=null;#It=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){const t=AnnotationEditorUIManager.prototype,arrowChecker=t=>t.#Pt.contains(document.activeElement)&&"BUTTON"!==document.activeElement.tagName&&t.hasSomethingToControl(),textInputChecker=(t,{target:e})=>{if(e instanceof HTMLInputElement){const{type:t}=e;return"text"!==t&&"number"!==t}return!0},e=this.TRANSLATE_SMALL,i=this.TRANSLATE_BIG;return util_shadow(this,"_keyboardManager",new KeyboardManager([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:textInputChecker}],[["ctrl+z","mac+meta+z"],t.undo,{checker:textInputChecker}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.redo,{checker:textInputChecker}],[["Backspace","alt+Backspace","ctrl+Backspace","shift+Backspace","mac+Backspace","mac+alt+Backspace","mac+ctrl+Backspace","Delete","ctrl+Delete","shift+Delete","mac+Delete"],t.delete,{checker:textInputChecker}],[["Enter"],t.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#Pt.contains(e)&&!t.isEnterHandled}],[["Space"],t.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#Pt.contains(document.activeElement)}],[["Escape"],t.unselectAll],[["ArrowLeft"],t.translateSelectedEditors,{args:[-e,0],checker:arrowChecker}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-i,0],checker:arrowChecker}],[["ArrowRight"],t.translateSelectedEditors,{args:[e,0],checker:arrowChecker}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[i,0],checker:arrowChecker}],[["ArrowUp"],t.translateSelectedEditors,{args:[0,-e],checker:arrowChecker}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-i],checker:arrowChecker}],[["ArrowDown"],t.translateSelectedEditors,{args:[0,e],checker:arrowChecker}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,i],checker:arrowChecker}]]))}constructor(t,e,i,n,r,s,a,o,l,c,h,d,u,p,g,m,f){const b=this._signal=this.#B.signal;this.#Pt=t;this.#Mt=e;this.#Dt=i;this.#W=n;this.#$=r;this.#At=s;this.#Et=o;this._eventBus=a;const y={signal:b,...on};a.on("editingaction",this.onEditingAction.bind(this),y);a.on("pagechanging",this.onPageChanging.bind(this),y);a.on("scalechanging",this.onScaleChanging.bind(this),y);a.on("rotationchanging",this.onRotationChanging.bind(this),y);a.on("setpreference",this.onSetPreference.bind(this),y);a.on("switchannotationeditorparams",t=>this.updateParams(t.type,t.value),y);window.addEventListener("pointerdown",()=>{this.#ut=!0},{capture:!0,signal:b});window.addEventListener("pointerup",()=>{this.#ut=!1},{capture:!0,signal:b});window.addEventListener("beforeunload",this.endCurrentEditing.bind(this),{capture:!0,signal:b});this.#Ft();this.#Ot();this.#Rt();this.#j=o.annotationStorage;this.#rt=o.filterFactory;this.#xt=l;this.#ot=c||null;this.#et=h;this.#it=d;this.#nt=u;this.#yt=p||null;this.viewParameters={realScale:PixelsPerInch.PDF_TO_CSS_UNITS,rotation:0};this.isShiftKeyDown=!1;this._editorUndoBar=g||null;this._supportsPinchToZoom=!1!==m;this._keepToolbarInPage=!0===f;r?.setSidebarUiManager(this)}destroy(){this.#It?.resolve();this.#It=null;this.#B?.abort();this.#B=null;this._signal=null;for(const t of this.#H.values())t.destroy();this.#H.clear();this.#U.clear();this.#tt.clear();this.#bt?.clear();this.#L=null;this.#vt.clear();this.#q.destroy();this.#W?.destroy();this.#$?.destroy();this.#At?.destroy();this.#ct?.hide();this.#ct=null;this.#ft?.destroy();this.#ft=null;this.#N=null;if(this.#st){clearTimeout(this.#st);this.#st=null}if(this.#kt){clearTimeout(this.#kt);this.#kt=null}this._editorUndoBar?.destroy();this.#Et=null}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return this.#yt}get useNewAltTextFlow(){return this.#it}get useNewAltTextWhenAddingImage(){return this.#nt}get hcmFilter(){return util_shadow(this,"hcmFilter",this.#xt?this.#rt.addHCMFilter(this.#xt.foreground,this.#xt.background):"none")}get direction(){return util_shadow(this,"direction",getComputedStyle(this.#Pt).direction)}get _highlightColors(){return util_shadow(this,"_highlightColors",this.#ot?new Map(this.#ot.split(",").map(t=>{(t=t.split("=").map(t=>t.trim()))[1]=t[1].toUpperCase();return t})):null)}get highlightColors(){const{_highlightColors:t}=this;if(!t)return util_shadow(this,"highlightColors",null);const e=new Map,i=!!this.#xt;for(const[n,r]of t){const t=n.endsWith("_HCM");i&&t?e.set(n.replace("_HCM",""),r):i||t||e.set(n,r)}return util_shadow(this,"highlightColors",e)}get highlightColorNames(){return util_shadow(this,"highlightColorNames",this.highlightColors?new Map(Array.from(this.highlightColors,t=>t.reverse())):null)}getNonHCMColor(t){if(!this._highlightColors)return t;const e=this.highlightColorNames.get(t);return this._highlightColors.get(e)||t}getNonHCMColorName(t){return this.highlightColorNames.get(t)||t}setCurrentDrawingSession(t){if(t){this.unselectAll();this.disableUserSelect(!0)}else this.disableUserSelect(!1);this.#K=t}setMainHighlightColorPicker(t){this.#ft=t}editAltText(t,e=!1){this.#W?.editAltText(this,t,e)}hasCommentManager(){return!!this.#$}editComment(t,e,i,n){this.#$?.showDialog(this,t,e,i,n)}selectComment(t,e){const i=this.#H.get(t),n=i?.getEditorByUID(e);n?.toggleComment(!0,!0)}updateComment(t){this.#$?.updateComment(t.getData())}updatePopupColor(t){this.#$?.updatePopupColor(t)}removeComment(t){this.#$?.removeComments([t.uid])}deleteComment(t,e){const undo=()=>{t.comment=e};this.addCommands({cmd:()=>{this._editorUndoBar?.show(undo,"comment");this.toggleComment(null);t.comment=null},undo,mustExec:!0})}toggleComment(t,e,i=void 0){this.#$?.toggleCommentPopup(t,e,i)}makeCommentColor(t,e){return t&&this.#$?.makeCommentColor(t,e)||null}getCommentDialogElement(){return this.#$?.dialogElement||null}async waitForEditorsRendered(t){if(this.#H.has(t-1))return;const{resolve:e,promise:i}=Promise.withResolvers(),onEditorsRendered=i=>{if(i.pageNumber===t){this._eventBus.off("editorsrendered",onEditorsRendered);e()}};this._eventBus.on("editorsrendered",onEditorsRendered,on);await i}getSignature(t){this.#At?.getSignature({uiManager:this,editor:t})}get signatureManager(){return this.#At}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal,...on});this._eventBus.dispatch("showannotationeditorui",{source:this,mode:t})}setPreference(t,e){this._eventBus.dispatch("setpreference",{source:this,name:t,value:e})}onSetPreference({name:t,value:e}){if("enableNewAltTextWhenAddingImage"===t)this.#nt=e}onPageChanging({pageNumber:t}){this.#Y=t-1}deletePage(t){for(const e of this.getEditors(t))e.remove();this.#H.delete(t);this.#Y===t&&(this.#Y=0)}focusMainContainer(){this.#Pt.focus()}findParent(t,e){for(const i of this.#H.values()){const{x:n,y:r,width:s,height:a}=i.div.getBoundingClientRect();if(t>=n&&t<=n+s&&e>=r&&e<=r+a)return i}return null}disableUserSelect(t=!1){this.#Mt.classList.toggle("noUserSelect",t)}addShouldRescale(t){this.#tt.add(t)}removeShouldRescale(t){this.#tt.delete(t)}onScaleChanging({scale:t}){this.commitOrRemove();this.viewParameters.realScale=t*PixelsPerInch.PDF_TO_CSS_UNITS;for(const t of this.#tt)t.onScaleChanging();this.#K?.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove();this.viewParameters.rotation=t}#Bt({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t}#Lt(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const e of this.#H.values())if(e.hasTextLayer(t))return e;return null}highlightSelection(t="",e=!1){const i=document.getSelection();if(!i||i.isCollapsed)return;const{anchorNode:n,anchorOffset:r,focusNode:s,focusOffset:a}=i,o=i.toString(),l=this.#Bt(i).closest(".textLayer"),c=this.getSelectionBoxes(l);if(!c)return;i.empty();const h=this.#Lt(l),d=this.#wt===ki.NONE,callback=()=>{const i=h?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:c,anchorNode:n,anchorOffset:r,focusNode:s,focusOffset:a,text:o});d&&this.showAllEditors("highlight",!0,!0);e&&i?.editComment()};d?this.switchToMode(ki.HIGHLIGHT,callback):callback()}commentSelection(t=""){this.highlightSelection(t,!0)}endCurrentEditing(){this.commitOrRemove();this.currentLayer?.endDrawingSession(!1)}#Nt(){const t=document.getSelection();if(!t||t.isCollapsed)return;const e=this.#Bt(t).closest(".textLayer"),i=this.getSelectionBoxes(e);if(i){this.#ct||=new FloatingToolbar(this);this.#ct.show(e,i,"ltr"===this.direction)}}getAndRemoveDataFromAnnotationStorage(t){if(!this.#j)return null;const e=`${Ti}${t}`,i=this.#j.getRawValue(e);i&&this.#j.remove(e);return i}addToAnnotationStorage(t){t.isEmpty()||!this.#j||this.#j.has(t.id)||this.#j.setValue(t.id,t)}a11yAlert(t,e=null){const i=this.#Dt;if(i){i.setAttribute("data-l10n-id",t);e?i.setAttribute("data-l10n-args",JSON.stringify(e)):i.removeAttribute("data-l10n-args")}}#Ut(){const t=document.getSelection();if(!t||t.isCollapsed){if(this.#_t){this.#ct?.hide();this.#_t=null;this.#Ht({hasSelectedText:!1})}return}const{anchorNode:e}=t;if(e===this.#_t)return;const i=this.#Bt(t).closest(".textLayer");if(i){this.#ct?.hide();this.#_t=e;this.#Ht({hasSelectedText:!0});if(this.#wt===ki.HIGHLIGHT||this.#wt===ki.NONE){this.#wt===ki.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0);this.#lt=this.isShiftKeyDown;if(!this.isShiftKeyDown){const t=this.#wt===ki.HIGHLIGHT?this.#Lt(i):null;t?.toggleDrawing();if(this.#ut){const e=new AbortController,i=this.combinedSignal(e),pointerup=i=>{if("pointerup"!==i.type||0===i.button){e.abort();t?.toggleDrawing(!0);"pointerup"===i.type&&this.#zt("main_toolbar")}};window.addEventListener("pointerup",pointerup,{signal:i});window.addEventListener("blur",pointerup,{signal:i})}else{t?.toggleDrawing(!0);this.#zt("main_toolbar")}}}}else if(this.#_t){this.#ct?.hide();this.#_t=null;this.#Ht({hasSelectedText:!1})}}#zt(t=""){this.#wt===ki.HIGHLIGHT?this.highlightSelection(t):this.#et&&this.#Nt()}#Ft(){document.addEventListener("selectionchange",this.#Ut.bind(this),{signal:this._signal})}#Gt(){if(this.#at)return;this.#at=new AbortController;const t=this.combinedSignal(this.#at);window.addEventListener("focus",this.focus.bind(this),{signal:t});window.addEventListener("blur",this.blur.bind(this),{signal:t})}#Wt(){this.#at?.abort();this.#at=null}blur(){this.isShiftKeyDown=!1;if(this.#lt){this.#lt=!1;this.#zt("main_toolbar")}if(!this.hasSelection)return;const{activeElement:t}=document;for(const e of this.#vt)if(e.div.contains(t)){this.#mt=[e,t];e._focusEventsAllowed=!1;break}}focus(){if(!this.#mt)return;const[t,e]=this.#mt;this.#mt=null;e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal});e.focus()}#Rt(){if(this.#gt)return;this.#gt=new AbortController;const t=this.combinedSignal(this.#gt);window.addEventListener("keydown",this.keydown.bind(this),{signal:t});window.addEventListener("keyup",this.keyup.bind(this),{signal:t})}#jt(){this.#gt?.abort();this.#gt=null}#Vt(){if(this.#X)return;this.#X=new AbortController;const t=this.combinedSignal(this.#X);document.addEventListener("copy",this.copy.bind(this),{signal:t});document.addEventListener("cut",this.cut.bind(this),{signal:t});document.addEventListener("paste",this.paste.bind(this),{signal:t})}#qt(){this.#X?.abort();this.#X=null}#Ot(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t});document.addEventListener("drop",this.drop.bind(this),{signal:t})}addEditListeners(){this.#Rt();this.setEditingState(!0)}removeEditListeners(){this.#jt();this.setEditingState(!1)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const i of this.#Z)if(i.isHandlingMimeForPasting(e)){t.dataTransfer.dropEffect="copy";t.preventDefault();return}}drop(t){for(const e of t.dataTransfer.items)for(const i of this.#Z)if(i.isHandlingMimeForPasting(e.type)){i.paste(e,this.currentLayer);t.preventDefault();return}}copy(t){t.preventDefault();this.#L?.commitOrRemove();if(!this.hasSelection)return;const e=[];for(const t of this.#vt){const i=t.serialize(!0);i&&e.push(i)}0!==e.length&&t.clipboardData.setData("application/pdfjs",JSON.stringify(e))}cut(t){this.copy(t);this.delete()}async paste(t){t.preventDefault();const{clipboardData:e}=t;for(const t of e.items)for(const e of this.#Z)if(e.isHandlingMimeForPasting(t.type)){e.paste(t,this.currentLayer);return}let i=e.getData("application/pdfjs");if(!i)return;try{i=JSON.parse(i)}catch(t){warn(`paste: "${t.message}".`);return}if(!Array.isArray(i))return;this.unselectAll();const n=this.currentLayer;try{const t=[];for(const e of i){const i=await n.deserialize(e);if(!i)return;t.push(i)}const cmd=()=>{for(const e of t)this.#$t(e);this.#Xt(t)},undo=()=>{for(const e of t)e.remove()};this.addCommands({cmd,undo,mustExec:!0})}catch(t){warn(`paste: "${t.message}".`)}}keydown(t){this.isShiftKeyDown||"Shift"!==t.key||(this.isShiftKeyDown=!0);this.#wt===ki.NONE||this.isEditorHandlingKeyboard||AnnotationEditorUIManager._keyboardManager.exec(this,t)}keyup(t){if(this.isShiftKeyDown&&"Shift"===t.key){this.isShiftKeyDown=!1;if(this.#lt){this.#lt=!1;this.#zt("main_toolbar")}}}onEditingAction({name:t}){switch(t){case"undo":case"redo":case"delete":case"selectAll":this[t]();break;case"highlightSelection":this.highlightSelection("context_menu");break;case"commentSelection":this.commentSelection("context_menu")}}updatePageIndex(t,e){for(const i of this.#G.get(t)||[])i.pageIndex=e;const i=this.#z.get(t);if(i){i.pageIndex=e;this.#H.set(e,i);this.#dt?i.enable():i.disable()}}startUpdatePages(){this.#z=new Map(this.#H);this.#H.clear();const t=this.#G=new Map,saveEditor=e=>{t.getOrInsertComputed(e.pageIndex,makeArr).push(e)};for(const t of this.#U.values())saveEditor(t);for(const[t,e]of this.#j)t.startsWith(Ti)&&!this.#U.has(t)&&Number.isInteger(e?.pageIndex)&&saveEditor(e)}endUpdatePages(){this.#z=null;this.#G=null}clonePage(t,e){for(const i of this.getEditors(t)){const t=i.serialize(i.mode!==ki.HIGHLIGHT);if(t){t.pageIndex=e;t.id=this.getId();t.isClone=!0;delete t.popupRef;this.#j.setValue(t.id,t)}}}findClonesForPage(t){const e=[],{pageIndex:i}=t;for(const[n,r]of this.#j)if(r.pageIndex===i&&r.isClone){this.#j.remove(n);e.push(t.deserialize(r).then(e=>{if(e){e.isClone=!0;t.addOrRebuild(e)}}))}return Promise.all(e)}#Ht(t){if(Object.entries(t).some(([t,e])=>this.#St[t]!==e)){this._eventBus.dispatch("editingstateschanged",{source:this,details:Object.assign(this.#St,t)});this.#wt===ki.HIGHLIGHT&&!1===t.hasSelectedEditor&&this.#Kt([[Pi.HIGHLIGHT_FREE,!0]])}}#Kt(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})}setEditingState(t){if(t){this.#Gt();this.#Vt();this.#Ht({isEditing:this.#wt!==ki.NONE,isEmpty:this.#Yt(),hasSomethingToUndo:this.#q.hasSomethingToUndo(),hasSomethingToRedo:this.#q.hasSomethingToRedo(),hasSelectedEditor:!1})}else{this.#Wt();this.#qt();this.#Ht({isEditing:!1});this.disableUserSelect(!1)}}registerEditorTypes(t){if(!this.#Z){this.#Z=t;for(const t of this.#Z)this.#Kt(t.defaultPropertiesToUpdate)}}getId(){return this.#ht.id}get currentLayer(){return this.#H.get(this.#Y)}getLayer(t){return this.#H.get(t)}get currentPageIndex(){return this.#Y}addLayer(t){this.#H.set(t.pageIndex,t);this.#dt?t.enable():t.disable()}removeLayer(t){this.#H.delete(t.pageIndex)}async updateMode(t,e=null,i=!1,n=!1,r=!1,s=!1){if(this.#wt!==t){if(this.#It){await this.#It.promise;if(!this.#It)return}this.#It=Promise.withResolvers();this.#K?.commitOrRemove();this.#wt===ki.POPUP&&this.#$?.hideSidebar();this.#$?.destroyPopup();this.#wt=t;if(t!==ki.NONE){for(const t of this.#U.values())t.addStandaloneCommentButton();t===ki.SIGNATURE&&await(this.#At?.loadSignatures());i&&CurrentPointers.clearPointerType();this.setEditingState(!0);await this.#Jt();this.unselectAll();for(const e of this.#H.values())e.updateMode(t);if(t===ki.POPUP){this.#N||=await this.#Et.getAnnotationsByType(new Set(this.#Z.map(t=>t._editorType)));const t=new Set,e=[];for(const i of this.#U.values()){const{annotationElementId:n,hasComment:r,deleted:s}=i;n&&t.add(n);r&&!s&&e.push(i.getData())}for(const i of this.#N){const{id:n,popupRef:r,contentsObj:s}=i;r&&s?.str&&!t.has(n)&&!this.#J.has(n)&&e.push(i)}this.#$?.showSidebar(e)}if(e){for(const t of this.#U.values())if(t.uid===e){this.setSelected(t);s?t.editComment():r?t.enterInEditMode():t.focus()}else t.unselect();this.#It.resolve()}else{n&&this.addNewEditorFromKeyboard();this.#It.resolve()}}else{this.setEditingState(!1);this.#Qt();for(const t of this.#U.values())t.hideStandaloneCommentButton();this._editorUndoBar?.hide();this.toggleComment(null);this.#It.resolve()}}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t.mode!==this.#wt&&this._eventBus.dispatch("switchannotationeditormode",{source:this,...t})}updateParams(t,e){if(this.#Z){switch(t){case Pi.CREATE:this.currentLayer.addNewEditor(e);return;case Pi.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}});(this.#Ct||=new Map).set(t,e);this.showAllEditors("highlight",e)}if(this.hasSelection)for(const i of this.#vt)i.updateParams(t,e);else for(const i of this.#Z)i.updateDefaultParams(t,e)}}showAllEditors(t,e,i=!1){for(const i of this.#U.values())i.editorType===t&&i.show(e);(this.#Ct?.get(Pi.HIGHLIGHT_SHOW_ALL)??!0)!==e&&this.#Kt([[Pi.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(this.#pt!==t){this.#pt=t;for(const e of this.#H.values()){t?e.disableClick():e.enableClick();e.div.classList.toggle("waiting",t)}}}async#Jt(){if(!this.#dt){this.#dt=!0;const t=[];for(const e of this.#H.values())t.push(e.enable());await Promise.all(t);for(const t of this.#U.values())t.enable()}}#Qt(){this.unselectAll();if(this.#dt){this.#dt=!1;for(const t of this.#H.values())t.disable();for(const t of this.#U.values())t.disable()}}*getEditors(t){for(const e of this.#U.values())e.pageIndex===t&&(yield e)}getEditor(t){return this.#U.get(t)}addEditor(t){this.#U.set(t.id,t)}removeEditor(t){if(t.div.contains(document.activeElement)){this.#st&&clearTimeout(this.#st);this.#st=setTimeout(()=>{this.focusMainContainer();this.#st=null},0)}this.#U.delete(t.id);t.annotationElementId&&this.#bt?.delete(t.annotationElementId);this.unselect(t);t.annotationElementId&&this.#J.has(t.annotationElementId)||this.#j?.remove(t.id)}addDeletedAnnotationElement(t){this.#J.add(t.annotationElementId);this.addChangedExistingAnnotation(t);t.deleted=!0}isDeletedAnnotationElement(t){return this.#J.has(t)}removeDeletedAnnotationElement(t){this.#J.delete(t.annotationElementId);this.removeChangedExistingAnnotation(t);t.deleted=!1}#$t(t){const e=this.#H.get(t.pageIndex);if(e)e.addOrRebuild(t);else{this.addEditor(t);this.addToAnnotationStorage(t)}}setActiveEditor(t){if(this.#L!==t){this.#L=t;t&&this.#Kt(t.propertiesToUpdate)}}get#Zt(){let t=null;for(t of this.#vt);return t}updateUI(t){this.#Zt===t&&this.#Kt(t.propertiesToUpdate)}updateUIForDefaultProperties(t){this.#Kt(t.defaultPropertiesToUpdate)}toggleSelected(t){if(this.#vt.has(t)){this.#vt.delete(t);t.unselect();this.#Ht({hasSelectedEditor:this.hasSelection})}else{this.#vt.add(t);t.select();this.#Kt(t.propertiesToUpdate);this.#Ht({hasSelectedEditor:!0})}}setSelected(t){this.updateToolbar({mode:t.mode,editId:t.uid});this.#K?.commitOrRemove();for(const e of this.#vt)e!==t&&e.unselect();this.#$?.destroyPopup();this.#vt.clear();this.#vt.add(t);t.select();this.#Kt(t.propertiesToUpdate);this.#Ht({hasSelectedEditor:!0})}get firstSelectedEditor(){return this.#vt.values().next().value}unselect(t){t.unselect();this.#vt.delete(t);this.#Ht({hasSelectedEditor:this.hasSelection})}get hasSelection(){return 0!==this.#vt.size}get isEnterHandled(){return 1===this.#vt.size&&this.firstSelectedEditor.isEnterHandled}undo(){this.#q.undo();this.#Ht({hasSomethingToUndo:this.#q.hasSomethingToUndo(),hasSomethingToRedo:this.#q.hasSomethingToRedo(),isEmpty:this.#Yt()});this._editorUndoBar?.hide()}redo(){this.#q.redo();this.#Ht({hasSomethingToUndo:this.#q.hasSomethingToUndo(),hasSomethingToRedo:this.#q.hasSomethingToRedo(),isEmpty:this.#Yt()})}addCommands(t){this.#q.add(t);this.#Ht({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#Yt()})}cleanUndoStack(t){this.#q.cleanType(t)}#Yt(){if(0===this.#U.size)return!0;if(1===this.#U.size)for(const t of this.#U.values())return t.isEmpty();return!1}delete(){this.commitOrRemove();const t=this.currentLayer?.endDrawingSession(!0);if(!this.hasSelection&&!t)return;const e=t?[t]:[...this.#vt],undo=()=>{for(const t of e)this.#$t(t)};this.addCommands({cmd:()=>{this._editorUndoBar?.show(undo,1===e.length?e[0].editorType:e.length);for(const t of e)t.remove()},undo,mustExec:!0})}commitOrRemove(){this.#L?.commitOrRemove()}hasSomethingToControl(){return this.#L||this.hasSelection}#Xt(t){for(const t of this.#vt)t.unselect();this.#vt.clear();for(const e of t)if(!e.isEmpty()){this.#vt.add(e);e.select()}this.#Ht({hasSelectedEditor:this.hasSelection})}selectAll(){for(const t of this.#vt)t.commit();this.#Xt(this.#U.values())}unselectAll(){if(this.#L){this.#L.commitOrRemove();if(this.#wt!==ki.NONE)return}if(!this.#K?.commitOrRemove()){this.#$?.destroyPopup();if(this.hasSelection){for(const t of this.#vt)t.unselect();this.#vt.clear();this.#Ht({hasSelectedEditor:!1})}}}translateSelectedEditors(t,e,i=!1){i||this.commitOrRemove();if(!this.hasSelection)return;this.#Tt[0]+=t;this.#Tt[1]+=e;const[n,r]=this.#Tt,s=[...this.#vt];this.#kt&&clearTimeout(this.#kt);this.#kt=setTimeout(()=>{this.#kt=null;this.#Tt[0]=this.#Tt[1]=0;this.addCommands({cmd:()=>{for(const t of s)if(this.#U.has(t.id)){t.translateInPage(n,r);t.translationDone()}},undo:()=>{for(const t of s)if(this.#U.has(t.id)){t.translateInPage(-n,-r);t.translationDone()}},mustExec:!1})},1e3);for(const i of s){i.translateInPage(t,e);i.translationDone()}}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0);this.#Q=new Map;for(const t of this.#vt)this.#Q.set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#Q)return!1;this.disableUserSelect(!1);const t=this.#Q;this.#Q=null;let e=!1;for(const[{x:i,y:n,pageIndex:r},s]of t){s.newX=i;s.newY=n;s.newPageIndex=r;e||=i!==s.savedX||n!==s.savedY||r!==s.savedPageIndex}if(!e)return!1;const move=(t,e,i,n)=>{if(this.#U.has(t.id)){const r=this.#H.get(n);if(r)t._setParentAndPosition(r,e,i);else{t.pageIndex=n;t.x=e;t.y=i}}};this.addCommands({cmd:()=>{for(const[e,{newX:i,newY:n,newPageIndex:r}]of t)move(e,i,n,r)},undo:()=>{for(const[e,{savedX:i,savedY:n,savedPageIndex:r}]of t)move(e,i,n,r)},mustExec:!0});return!0}dragSelectedEditors(t,e){if(this.#Q)for(const i of this.#Q.keys())i.drag(t,e)}rebuild(t){if(null===t.parent){const e=this.getLayer(t.pageIndex);if(e){e.changeParent(t);e.addOrRebuild(t)}else{this.addEditor(t);this.addToAnnotationStorage(t);t.rebuild()}}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){return this.getActive()?.shouldGetKeyboardEvents()||1===this.#vt.size&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return this.#L===t}getActive(){return this.#L}getMode(){return this.#wt}isEditingMode(){return this.#wt!==ki.NONE}get imageManager(){return util_shadow(this,"imageManager",new ImageManager)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let i=0,n=e.rangeCount;i<n;i++)if(!t.contains(e.getRangeAt(i).commonAncestorContainer))return null;const{x:i,y:n,width:r,height:s}=t.getBoundingClientRect();let a;switch(t.getAttribute("data-main-rotation")){case"90":a=(t,e,a,o)=>({x:(e-n)/s,y:1-(t+a-i)/r,width:o/s,height:a/r});break;case"180":a=(t,e,a,o)=>({x:1-(t+a-i)/r,y:1-(e+o-n)/s,width:a/r,height:o/s});break;case"270":a=(t,e,a,o)=>({x:1-(e+o-n)/s,y:(t-i)/r,width:o/s,height:a/r});break;default:a=(t,e,a,o)=>({x:(t-i)/r,y:(e-n)/s,width:a/r,height:o/s})}const o=[];for(let t=0,i=e.rangeCount;t<i;t++){const i=e.getRangeAt(t);if(!i.collapsed)for(const{x:t,y:e,width:n,height:r}of i.getClientRects())0!==n&&0!==r&&o.push(a(t,e,n,r))}return 0===o.length?null:o}addChangedExistingAnnotation({annotationElementId:t,id:e}){(this.#V||=new Map).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){this.#V?.delete(t)}renderAnnotationElement(t){const e=this.#V?.get(t.data.id);if(!e)return;const i=this.#j.getRawValue(e);i&&(this.#wt!==ki.NONE||i.hasBeenModified)&&i.renderAnnotationElement(t)}setMissingCanvas(t,e,i){const n=this.#bt?.get(t);if(n){n.setCanvas(e,i);this.#bt.delete(t)}}addMissingCanvas(t,e){(this.#bt||=new Map).set(t,e)}}class AltText{#l=null;#te=!1;#ee=null;#ie=null;#ne=null;#re=null;#se=!1;#ae=null;#a=null;#oe=null;#le=null;#ce=!1;static#he=null;static _l10n=null;constructor(t){this.#a=t;this.#ce=t._uiManager.useNewAltTextFlow;AltText.#he||=Object.freeze({added:"pdfjs-editor-new-alt-text-added-button","added-label":"pdfjs-editor-new-alt-text-added-button-label",missing:"pdfjs-editor-new-alt-text-missing-button","missing-label":"pdfjs-editor-new-alt-text-missing-button-label",review:"pdfjs-editor-new-alt-text-to-review-button","review-label":"pdfjs-editor-new-alt-text-to-review-button-label"})}static initialize(t){AltText._l10n??=t}async render(){const t=this.#ee=document.createElement("button");t.className="altText";t.tabIndex="0";const e=this.#ie=document.createElement("span");t.append(e);if(this.#ce){t.classList.add("new");t.setAttribute("data-l10n-id",AltText.#he.missing);e.setAttribute("data-l10n-id",AltText.#he["missing-label"])}else{t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button");e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label")}const i=this.#a._uiManager._signal;t.addEventListener("contextmenu",noContextMenu,{signal:i});t.addEventListener("pointerdown",t=>t.stopPropagation(),{signal:i});const onClick=t=>{t.preventDefault();this.#a._uiManager.editAltText(this.#a);this.#ce&&this.#a._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:this.#de}})};t.addEventListener("click",onClick,{capture:!0,signal:i});t.addEventListener("keydown",e=>{if(e.target===t&&"Enter"===e.key){this.#se=!0;onClick(e)}},{signal:i});await this.#ue();return t}get#de(){return(this.#l?"added":null===this.#l&&this.guessedText&&"review")||"missing"}finish(){if(this.#ee){this.#ee.focus({focusVisible:this.#se});this.#se=!1}}isEmpty(){return this.#ce?null===this.#l:!this.#l&&!this.#te}hasData(){return this.#ce?null!==this.#l||!!this.#oe:this.isEmpty()}get guessedText(){return this.#oe}async setGuessedText(t){if(null===this.#l){this.#oe=t;this.#le=await AltText._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t});this.#ue()}}toggleAltTextBadge(t=!1){if(this.#ce&&!this.#l){if(!this.#ae){const t=this.#ae=document.createElement("div");t.className="noAltTextBadge";this.#a.div.append(t)}this.#ae.classList.toggle("hidden",!t)}else{this.#ae?.remove();this.#ae=null}}serialize(t){let e=this.#l;t||this.#oe!==e||(e=this.#le);return{altText:e,decorative:this.#te,guessedText:this.#oe,textWithDisclaimer:this.#le}}get data(){return{altText:this.#l,decorative:this.#te}}set data({altText:t,decorative:e,guessedText:i,textWithDisclaimer:n,cancel:r=!1}){if(i){this.#oe=i;this.#le=n}if(this.#l!==t||this.#te!==e){if(!r){this.#l=t;this.#te=e}this.#ue()}}toggle(t=!1){if(this.#ee){if(!t&&this.#re){clearTimeout(this.#re);this.#re=null}this.#ee.disabled=!t}}shown(){this.#a._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:this.#de}})}destroy(){this.#ee?.remove();this.#ee=null;this.#ie=null;this.#ne=null;this.#ae?.remove();this.#ae=null}async#ue(){const t=this.#ee;if(!t)return;if(this.#ce){t.classList.toggle("done",!!this.#l);t.setAttribute("data-l10n-id",AltText.#he[this.#de]);this.#ie?.setAttribute("data-l10n-id",AltText.#he[`${this.#de}-label`]);if(!this.#l){this.#ne?.remove();return}}else{if(!this.#l&&!this.#te){t.classList.remove("done");this.#ne?.remove();return}t.classList.add("done");t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=this.#ne;if(!e){this.#ne=e=document.createElement("span");e.className="tooltip";e.setAttribute("role","tooltip");e.id=`alt-text-tooltip-${this.#a.id}`;const i=100,n=this.#a._uiManager._signal;n.addEventListener("abort",()=>{clearTimeout(this.#re);this.#re=null},{once:!0});t.addEventListener("mouseenter",()=>{this.#re=setTimeout(()=>{this.#re=null;this.#ne.classList.add("show");this.#a._reportTelemetry({action:"alt_text_tooltip"})},i)},{signal:n});t.addEventListener("mouseleave",()=>{if(this.#re){clearTimeout(this.#re);this.#re=null}this.#ne?.classList.remove("show")},{signal:n})}if(this.#te)e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip");else{e.removeAttribute("data-l10n-id");e.textContent=this.#l}e.parentNode||t.append(e);const i=this.#a.getElementForAltText();i?.setAttribute("aria-describedby",e.id)}}class Comment{#pe=null;#ge=null;#me=!1;#a=null;#fe=null;#be=null;#ye=null;#we=null;#ve=!1;#_e=null;constructor(t){this.#a=t}renderForToolbar(){const t=this.#ge=document.createElement("button");t.className="comment";return this.#w(t,!1)}renderForStandalone(){const t=this.#pe=document.createElement("button");t.className="annotationCommentButton";const e=this.#a.commentButtonPosition;if(e){const{style:i}=t;i.insetInlineEnd=`calc(${100*("ltr"===this.#a._uiManager.direction?1-e[0]:e[0])}% - var(--comment-button-dim))`;i.top=`calc(${100*e[1]}% - var(--comment-button-dim))`;const n=this.#a.commentButtonColor;n&&(i.backgroundColor=n)}return this.#w(t,!0)}focusButton(){setTimeout(()=>{(this.#pe??this.#ge)?.focus()},0)}onUpdatedColor(){if(!this.#pe)return;const t=this.#a.commentButtonColor;t&&(this.#pe.style.backgroundColor=t);this.#a._uiManager.updatePopupColor(this.#a)}get commentButtonWidth(){return(this.#pe?.getBoundingClientRect().width??0)/this.#a.parent.boundingClientRect.width}get commentPopupPositionInLayer(){if(this.#_e)return this.#_e;if(!this.#pe)return null;const{x:t,y:e,height:i}=this.#pe.getBoundingClientRect(),{x:n,y:r,width:s,height:a}=this.#a.parent.boundingClientRect;return[(t-n)/s,(e+i-r)/a]}set commentPopupPositionInLayer(t){this.#_e=t}hasDefaultPopupPosition(){return null===this.#_e}removeStandaloneCommentButton(){this.#pe?.remove();this.#pe=null}removeToolbarCommentButton(){this.#ge?.remove();this.#ge=null}setCommentButtonStates({selected:t,hasPopup:e}){if(this.#pe){this.#pe.classList.toggle("selected",t);this.#pe.ariaExpanded=e}}#w(t,e){if(!this.#a._uiManager.hasCommentManager())return null;t.tabIndex="0";t.ariaHasPopup="dialog";if(e){t.ariaControls="commentPopup";t.setAttribute("data-l10n-id","pdfjs-show-comment-button")}else{t.ariaControlsElements=[this.#a._uiManager.getCommentDialogElement()];t.setAttribute("data-l10n-id","pdfjs-editor-add-comment-button")}const i=this.#a._uiManager._signal;if(!(i instanceof AbortSignal)||i.aborted)return t;t.addEventListener("contextmenu",noContextMenu,{signal:i});if(e){t.addEventListener("focusin",t=>{this.#a._focusEventsAllowed=!1;stopEvent(t)},{capture:!0,signal:i});t.addEventListener("focusout",t=>{this.#a._focusEventsAllowed=!0;stopEvent(t)},{capture:!0,signal:i})}t.addEventListener("pointerdown",t=>t.stopPropagation(),{signal:i});const onClick=e=>{e.preventDefault();t===this.#ge?this.edit():this.#a.toggleComment(!0)};t.addEventListener("click",onClick,{capture:!0,signal:i});t.addEventListener("keydown",e=>{if(e.target===t&&"Enter"===e.key){this.#me=!0;onClick(e)}},{signal:i});t.addEventListener("pointerenter",()=>{this.#a.toggleComment(!1,!0)},{signal:i});t.addEventListener("pointerleave",()=>{this.#a.toggleComment(!1,!1)},{signal:i});return t}edit(t){const e=this.commentPopupPositionInLayer;let i,n;if(e)[i,n]=e;else{[i,n]=this.#a.commentButtonPosition;const{width:t,height:e,x:r,y:s}=this.#a;i=r+i*t;n=s+n*e}const r=this.#a.parent.boundingClientRect,{x:s,y:a,width:o,height:l}=r;this.#a._uiManager.editComment(this.#a,s+i*o,a+n*l,{...t,parentDimensions:r})}finish(){if(this.#ge){this.#ge.focus({focusVisible:this.#me});this.#me=!1}}isDeleted(){return this.#ve||""===this.#ye}isEmpty(){return null===this.#ye}hasBeenEdited(){return this.isDeleted()||this.#ye!==this.#fe}serialize(){return this.data}get data(){return{text:this.#ye,richText:this.#be,date:this.#we,deleted:this.isDeleted()}}set data(t){t!==this.#ye&&(this.#be=null);if(null!==t){this.#ye=t;this.#we=new Date;this.#ve=!1}else{this.#ye="";this.#ve=!0}}restoreData({text:t,richText:e,date:i}){this.#ye=t;this.#be=e;this.#we=i;this.#ve=!1}setInitialText(t,e=null){this.#fe=t;this.data=t;this.#we=null;this.#be=e}shown(){}destroy(){this.#ge?.remove();this.#ge=null;this.#pe?.remove();this.#pe=null;this.#ye="";this.#be=null;this.#we=null;this.#a=null;this.#me=!1;this.#ve=!1}}function preventDefault(t){t.preventDefault()}const ln=1e-4;function stopTouchEvent(t){if(t.cancelable){stopEvent(t);return!0}t.stopPropagation();return!1}class TouchManager{#Pt;#Ae=!1;#xe=null;#Ce;#Ee;#Se;#Te;#ke;#Pe=!1;#Me=null;#De;#Ie=new Set;#Fe=null;#Oe;#Re=null;#Be=0;constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:i=null,onPinchStart:n=null,onPinching:r=null,onPinchEnd:s=null,onPanning:a=null,signal:o}){this.#Pt=t;this.#xe=i;this.#Ce=e;this.#Ee=n;this.#Se=r;this.#Te=s;this.#ke=a;this.#Oe=new AbortController;this.#De=AbortSignal.any([o,this.#Oe.signal]);t.addEventListener("touchstart",this.#Le.bind(this),{passive:!1,signal:this.#De})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return 35/OutputScale.pixelRatio}get MIN_TOUCH_DISTANCE_TO_SCALE(){return 4/OutputScale.pixelRatio}#Le(t){if(this.#Ce?.())return;this.#Ne(t);const e=this.#Ie;for(const{identifier:i}of t.changedTouches)e.add(i);if(1!==e.size){if(!this.#Re){this.#Re=new AbortController;const t=AbortSignal.any([this.#De,this.#Re.signal]),e=this.#Pt,i={signal:t,capture:!1,passive:!1};e.addEventListener("touchmove",this.#Ue.bind(this),i);const n=this.#He.bind(this);e.addEventListener("touchend",n,i);e.addEventListener("touchcancel",n,i);i.capture=!0;e.addEventListener("pointerdown",stopEvent,i);e.addEventListener("pointermove",stopEvent,i);e.addEventListener("pointercancel",preventDefault,i);e.addEventListener("pointerup",preventDefault,i);this.#Ee?.()}this.#Pe=stopTouchEvent(t);this.#ze(t)}else this.#Ge()}#Ge(){if(this.#Me)return;const t=this.#Me=new AbortController,e=AbortSignal.any([this.#De,t.signal]),i=this.#Pt,n={capture:!0,signal:e,passive:!1},cancelPointerDown=t=>{if("touch"===t.pointerType){this.#Me?.abort();this.#Me=null}};i.addEventListener("pointerdown",t=>{if("touch"===t.pointerType){stopEvent(t);cancelPointerDown(t)}},n);i.addEventListener("pointerup",cancelPointerDown,n);i.addEventListener("pointercancel",cancelPointerDown,n)}#Ne(t){const e=this.#Ie;if(0===e.size)return;const i=this.#Ie=new Set;for(const{identifier:n}of t.touches)e.has(n)&&i.add(n)}#We(t){const e=this.#Ie,i=[];for(const n of t.touches)e.has(n.identifier)&&i.push(n);return i}#ze(t){const e=this.#We(t);if(2!==e.length||this.#xe?.()){this.#Fe=null;return}const[i,n]=e;this.#Fe={touch0X:i.screenX,touch0Y:i.screenY,touch1X:n.screenX,touch1Y:n.screenY,panX:(i.clientX+n.clientX)/2,panY:(i.clientY+n.clientY)/2,screenPanX:(i.screenX+n.screenX)/2,screenPanY:(i.screenY+n.screenY)/2}}#Ue(t){if(!this.#Fe)return;const e=this.#We(t);if(2!==e.length)return;const i=this.#Pe;this.#Pe=stopTouchEvent(t);if(!this.#Pe)return;if(!i){this.#ze(t);return}const[n,r]=e,{screenX:s,screenY:a}=n,{screenX:o,screenY:l}=r,c=this.#Fe,{touch0X:h,touch0Y:d,touch1X:u,touch1Y:p,panX:g,panY:m}=c,f=u-h,b=p-d,y=o-s,w=l-a,v=(n.clientX+r.clientX)/2,_=(n.clientY+r.clientY)/2;c.panX=v;c.panY=_;const A=v-g,x=_-m,C=(s+o)/2,E=(a+l)/2,S=Math.hypot(C-c.screenPanX,E-c.screenPanY);c.screenPanX=C;c.screenPanY=E;const T=Math.hypot(y,w),k=Math.hypot(f,b),P=this.#Ae?this.MIN_TOUCH_DISTANCE_TO_SCALE:this.MIN_TOUCH_DISTANCE_TO_PINCH+2*S;if(T<ln||k<ln||Math.abs(k-T)<=P){(A||x)&&this.#ke?.(A,x);return}c.touch0X=s;c.touch0Y=a;c.touch1X=o;c.touch1Y=l;const M=Math.sign(T-k);if(this.#Ae){if(this.#Be){const t=this.#Be;this.#Be=0;if(M!==t&&Math.abs(T-k)<=2*S){this.#Ae=!1;(A||x)&&this.#ke?.(A,x);return}}this.#Se?.([g,m],k,T,A,x)}else{this.#Ae=!0;this.#Be=M;(A||x)&&this.#ke?.(A,x)}}#He(t){this.#Ne(t);if(this.#Ie.size>=2){this.#ze(t);return}const e=!!this.#Fe;this.#je();1===this.#Ie.size&&this.#Ge();e&&stopTouchEvent(t)}#je(){this.#Fe=null;this.#Ae=!1;this.#Be=0;this.#Pe=!1;if(this.#Re){this.#Re.abort();this.#Re=null;this.#Te?.()}}destroy(){this.#je();this.#Ie.clear();this.#Oe?.abort();this.#Oe=null;this.#Me?.abort();this.#Me=null}}class AnnotationEditor{#Ve=null;#qe=null;#l=null;#c=null;#pe=null;#$e=!1;#Xe=null;#Ke="";#Ye=null;#Je=null;#Qe=null;#Ze=null;#ti=null;#ei="";#ii=!1;#ni=null;#ri=!1;#si=!1;#ai=!1;#oi=null;#li=0;#ci=0;#hi=null;#di=null;isSelected=!1;_isCopy=!1;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_isVisible=!0;_uiManager=null;_focusEventsAllowed=!0;static _l10n=null;static _l10nAlert=null;static _l10nResizer=null;#ui=!1;#pi=AnnotationEditor._zIndex++;static _borderLineWidth=-1;static _colorManager=new ColorManager;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){const t=AnnotationEditor.prototype._resizeWithKeyboard,e=AnnotationEditorUIManager.TRANSLATE_SMALL,i=AnnotationEditorUIManager.TRANSLATE_BIG;return util_shadow(this,"_resizerKeyboardManager",new KeyboardManager([[["ArrowLeft"],t,{args:[-e,0]}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t,{args:[-i,0]}],[["ArrowRight"],t,{args:[e,0]}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t,{args:[i,0]}],[["ArrowUp"],t,{args:[0,-e]}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t,{args:[0,-i]}],[["ArrowDown"],t,{args:[0,e]}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t,{args:[0,i]}],[["Escape"],AnnotationEditor.prototype._stopResizingWithKeyboard]]))}constructor(t){this.parent=t.parent;this.id=t.id;this.width=this.height=null;this.pageIndex=t.parent.pageIndex;this.name=t.name;this.div=null;this._uiManager=t.uiManager;this.annotationElementId=null;this._willKeepAspectRatio=!1;this._initialOptions.isCentered=t.isCentered;this._structTreeParentId=null;this.annotationElementId=t.annotationElementId||null;this.creationDate=t.creationDate||new Date;this.modificationDate=t.modificationDate||null;this.canAddComment=!0;const{rotation:e,rawDims:{pageWidth:i,pageHeight:n,pageX:r,pageY:s}}=this.parent.viewport;this.rotation=e;this.pageRotation=(360+e-this._uiManager.viewParameters.rotation)%360;this.pageDimensions=[i,n];this.pageTranslation=[r,s];const[a,o]=this.parentDimensions;this.x=t.x/a;this.y=t.y/o;this.isAttachedToDOM=!1;this.deleted=!1}updatePageIndex(t){this.pageIndex=t}get editorType(){return Object.getPrototypeOf(this).constructor._type}get mode(){return Object.getPrototypeOf(this).constructor._editorType}static get isDrawer(){return!1}static get _defaultLineColor(){return util_shadow(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new FakeEditor({id:t._uiManager.getId(),parent:t.parent,uiManager:t._uiManager});e.annotationElementId=t.annotationElementId;e.deleted=!0;e._uiManager.addToAnnotationStorage(e)}static initialize(t,e){AnnotationEditor._l10n??=t;AnnotationEditor._l10nAlert??=Object.freeze({highlight:"pdfjs-editor-highlight-added-alert",freetext:"pdfjs-editor-freetext-added-alert",ink:"pdfjs-editor-ink-added-alert",stamp:"pdfjs-editor-stamp-added-alert",signature:"pdfjs-editor-signature-added-alert"});AnnotationEditor._l10nResizer??=Object.freeze({topLeft:"pdfjs-editor-resizer-top-left",topMiddle:"pdfjs-editor-resizer-top-middle",topRight:"pdfjs-editor-resizer-top-right",middleRight:"pdfjs-editor-resizer-middle-right",bottomRight:"pdfjs-editor-resizer-bottom-right",bottomMiddle:"pdfjs-editor-resizer-bottom-middle",bottomLeft:"pdfjs-editor-resizer-bottom-left",middleLeft:"pdfjs-editor-resizer-middle-left"});if(-1!==AnnotationEditor._borderLineWidth)return;const i=getComputedStyle(document.documentElement);AnnotationEditor._borderLineWidth=parseFloat(i.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){unreachable("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#ui}set _isDraggable(t){this.#ui=t;this.div?.classList.toggle("draggable",t)}get uid(){return this.annotationElementId||this.id}get isEnterHandled(){return!0}center(){const[t,e]=this.pageDimensions;switch(this.parentRotation){case 90:this.x-=this.height*e/(2*t);this.y+=this.width*t/(2*e);break;case 180:this.x+=this.width/2;this.y+=this.height/2;break;case 270:this.x+=this.height*e/(2*t);this.y-=this.width*t/(2*e);break;default:this.x-=this.width/2;this.y-=this.height/2}this.fixAndSetPosition()}addCommands(t){this._uiManager.addCommands(t)}get currentLayer(){return this._uiManager.currentLayer}setInBackground(){this.div.style.zIndex=0}setInForeground(){this.div.style.zIndex=this.#pi}setParent(t){if(null!==t){this.pageIndex=t.pageIndex;this.pageDimensions=t.pageDimensions}else{this.#gi();this.#Ze?.remove();this.#Ze=null}this.parent=t}focusin(t){this._focusEventsAllowed&&(this.#ii?this.#ii=!1:this.parent.setSelected(this))}focusout(t){if(!this._focusEventsAllowed||!this.isAttachedToDOM)return;const e=t.relatedTarget;if(!e?.closest(`#${this.id}`)){t.preventDefault();this.parent?.isMultipleSelection||this.commitOrRemove()}}commitOrRemove(){this.isEmpty()?this.remove():this.commit()}commit(){this.isInEditMode()&&this.addToAnnotationStorage()}addToAnnotationStorage(){this._uiManager.addToAnnotationStorage(this)}setAt(t,e,i,n){const[r,s]=this.parentDimensions;[i,n]=this.screenToPageTranslation(i,n);this.x=(t+i)/r;this.y=(e+n)/s;this.fixAndSetPosition()}_moveAfterPaste(t,e){if(this.isClone){delete this.isClone;return}const[i,n]=this.parentDimensions;this.setAt(t*i,e*n,this.width*i,this.height*n);this._onTranslated()}#mi([t,e],i,n){[i,n]=this.screenToPageTranslation(i,n);this.x+=i/t;this.y+=n/e;this._onTranslating(this.x,this.y);this.fixAndSetPosition()}translate(t,e){this.#mi(this.parentDimensions,t,e)}translateInPage(t,e){this.#ni||=[this.x,this.y,this.width,this.height];this.#mi(this.pageDimensions,t,e);this.div.scrollIntoView({block:"nearest"})}translationDone(){this._onTranslated(this.x,this.y)}drag(t,e){this.#ni||=[this.x,this.y,this.width,this.height];const{div:i,parentDimensions:[n,r]}=this;this.x+=t/n;this.y+=e/r;if(this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:t,y:e}=this.div.getBoundingClientRect();if(this.parent.findNewParent(this,t,e)){this.x-=Math.floor(this.x);this.y-=Math.floor(this.y)}}let{x:s,y:a}=this;const[o,l]=this.getBaseTranslation();s+=o;a+=l;const{style:c}=i;c.left=`${(100*s).toFixed(2)}%`;c.top=`${(100*a).toFixed(2)}%`;this._onTranslating(s,a)}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!this.#ni&&(this.#ni[0]!==this.x||this.#ni[1]!==this.y)}get _hasBeenResized(){return!!this.#ni&&(this.#ni[2]!==this.width||this.#ni[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:i}=AnnotationEditor,n=i/t,r=i/e;switch(this.rotation){case 90:return[-n,r];case 180:return[n,r];case 270:return[n,-r];default:return[-n,-r]}}get _mustFixPosition(){return!0}fixAndSetPosition(t=this.rotation){const{div:{style:e},pageDimensions:[i,n]}=this;let{x:r,y:s,width:a,height:o}=this;a*=i;o*=n;r*=i;s*=n;let l=0,c=0;const h=this._uiManager._keepToolbarInPage&&this._editToolbar?.div;if(h?.offsetParent){const e=this.parentScale,d=h.offsetLeft+this.div.clientLeft,u=h.offsetTop+this.div.clientTop,p=Math.min(0,d)/e,g=Math.min(0,u)/e,m=a-p+Math.max(0,d+h.offsetWidth-this.div.offsetWidth)/e,f=o-g+Math.max(0,u+h.offsetHeight-this.div.offsetHeight)/e;if(m<=(t%180?n:i)){a=m;l=p}if(f<=(t%180?i:n)){o=f;c=g}[l,c]=AnnotationEditor.#fi(l,c,t);r+=l;s+=c}if(this._mustFixPosition)switch(t){case 0:r=MathClamp(r,0,i-a);s=MathClamp(s,0,n-o);break;case 90:r=MathClamp(r,0,i-o);s=MathClamp(s,a,n);break;case 180:r=MathClamp(r,a,i);s=MathClamp(s,o,n);break;case 270:r=MathClamp(r,o,i);s=MathClamp(s,0,n-a)}this.x=r=(r-l)/i;this.y=s=(s-c)/n;const[d,u]=this.getBaseTranslation();r+=d;s+=u;e.left=`${(100*r).toFixed(2)}%`;e.top=`${(100*s).toFixed(2)}%`;this.moveInDOM()}static#fi(t,e,i){switch(i){case 90:return[e,-t];case 180:return[-t,-e];case 270:return[-e,t];default:return[t,e]}}screenToPageTranslation(t,e){return AnnotationEditor.#fi(t,e,this.parentRotation)}pageTranslationToScreen(t,e){return AnnotationEditor.#fi(t,e,360-this.parentRotation)}#bi(t){switch(t){case 90:{const[t,e]=this.pageDimensions;return[0,-t/e,e/t,0]}case 180:return[-1,0,0,-1];case 270:{const[t,e]=this.pageDimensions;return[0,t/e,-e/t,0]}default:return[1,0,0,1]}}get parentScale(){return this._uiManager.viewParameters.realScale}get parentRotation(){return(this._uiManager.viewParameters.rotation+this.pageRotation)%360}get parentDimensions(){const{parentScale:t,pageDimensions:[e,i]}=this;return[e*t,i*t]}setDims(){const{div:{style:t},width:e,height:i}=this;t.width=`${(100*e).toFixed(2)}%`;t.height=`${(100*i).toFixed(2)}%`}getInitialTranslation(){return[0,0]}#yi(){if(this.#Ye)return;this.#Ye=document.createElement("div");this.#Ye.classList.add("resizers");const t=this._willKeepAspectRatio?["topLeft","topRight","bottomRight","bottomLeft"]:["topLeft","topMiddle","topRight","middleRight","bottomRight","bottomMiddle","bottomLeft","middleLeft"],e=this._uiManager._signal;for(const i of t){const t=document.createElement("div");this.#Ye.append(t);t.classList.add("resizer",i);t.setAttribute("data-resizer-name",i);t.addEventListener("pointerdown",this.#wi.bind(this,i),{signal:e});t.addEventListener("contextmenu",noContextMenu,{signal:e});t.tabIndex=-1}this.div.prepend(this.#Ye)}#wi(t,e){e.preventDefault();const{isMac:i}=FeatureTest.platform;if(0!==e.button||e.ctrlKey&&i)return;this.#l?.toggle(!1);const n=this._isDraggable;this._isDraggable=!1;this.#Je=[e.screenX,e.screenY];const r=new AbortController,s=this._uiManager.combinedSignal(r);this.parent.togglePointerEvents(!1);window.addEventListener("pointermove",this.#vi.bind(this,t),{passive:!0,capture:!0,signal:s});window.addEventListener("touchmove",stopEvent,{passive:!1,signal:s});window.addEventListener("contextmenu",noContextMenu,{signal:s});this.#Qe={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};const a=this.parent.div.style.cursor,o=this.div.style.cursor;this.div.style.cursor=this.parent.div.style.cursor=window.getComputedStyle(e.target).cursor;const pointerUpCallback=()=>{r.abort();this.parent.togglePointerEvents(!0);this.#l?.toggle(!0);this._isDraggable=n;this.parent.div.style.cursor=a;this.div.style.cursor=o;this.#_i()};window.addEventListener("pointerup",pointerUpCallback,{signal:s});window.addEventListener("blur",pointerUpCallback,{signal:s})}#Ai(t,e,i,n){this.width=i;this.height=n;this.x=t;this.y=e;this.setDims();this.fixAndSetPosition();this._onResized()}_onResized(){}#_i(){if(!this.#Qe)return;const{savedX:t,savedY:e,savedWidth:i,savedHeight:n}=this.#Qe;this.#Qe=null;const r=this.x,s=this.y,a=this.width,o=this.height;r===t&&s===e&&a===i&&o===n||this.addCommands({cmd:this.#Ai.bind(this,r,s,a,o),undo:this.#Ai.bind(this,t,e,i,n),mustExec:!0})}static _round(t){return Math.round(1e4*t)/1e4}#vi(t,e){const[i,n]=this.parentDimensions,r=this.x,s=this.y,a=this.width,o=this.height,l=AnnotationEditor.MIN_SIZE/i,c=AnnotationEditor.MIN_SIZE/n,h=this.#bi(this.rotation),transf=(t,e)=>[h[0]*t+h[2]*e,h[1]*t+h[3]*e],d=this.#bi(360-this.rotation);let u,p,g=!1,m=!1;switch(t){case"topLeft":g=!0;u=(t,e)=>[0,0];p=(t,e)=>[t,e];break;case"topMiddle":u=(t,e)=>[t/2,0];p=(t,e)=>[t/2,e];break;case"topRight":g=!0;u=(t,e)=>[t,0];p=(t,e)=>[0,e];break;case"middleRight":m=!0;u=(t,e)=>[t,e/2];p=(t,e)=>[0,e/2];break;case"bottomRight":g=!0;u=(t,e)=>[t,e];p=(t,e)=>[0,0];break;case"bottomMiddle":u=(t,e)=>[t/2,e];p=(t,e)=>[t/2,0];break;case"bottomLeft":g=!0;u=(t,e)=>[0,e];p=(t,e)=>[t,0];break;case"middleLeft":m=!0;u=(t,e)=>[0,e/2];p=(t,e)=>[t,e/2]}const f=u(a,o),b=p(a,o);let y=transf(...b);const w=AnnotationEditor._round(r+y[0]),v=AnnotationEditor._round(s+y[1]);let _,A,x=1,C=1;if(e.fromKeyboard)({deltaX:_,deltaY:A}=e);else{const{screenX:t,screenY:i}=e,[n,r]=this.#Je;[_,A]=this.screenToPageTranslation(t-n,i-r);this.#Je[0]=t;this.#Je[1]=i}[_,A]=(E=_/i,S=A/n,[d[0]*E+d[2]*S,d[1]*E+d[3]*S]);var E,S;if(g){const t=Math.hypot(a,o);x=C=Math.max(Math.min(Math.hypot(b[0]-f[0]-_,b[1]-f[1]-A)/t,1/a,1/o),l/a,c/o)}else m?x=MathClamp(Math.abs(b[0]-f[0]-_),l,1)/a:C=MathClamp(Math.abs(b[1]-f[1]-A),c,1)/o;const T=AnnotationEditor._round(a*x),k=AnnotationEditor._round(o*C);y=transf(...p(T,k));const P=w-y[0],M=v-y[1];this.#ni||=[this.x,this.y,this.width,this.height];this.width=T;this.height=k;this.x=P;this.y=M;this.setDims();this.fixAndSetPosition();this._onResizing()}_onResizing(){}altTextFinish(){this.#l?.finish()}get toolbarButtons(){return null}async addEditToolbar(){if(this._editToolbar||this.#si)return this._editToolbar;this._editToolbar=new EditorToolbar(this);this.div.append(this._editToolbar.render());const{toolbarButtons:t}=this;if(t)for(const[e,i]of t)await this._editToolbar.addButton(e,i);this.hasComment||this._editToolbar.addButton("comment",this.addCommentButton());this._editToolbar.addButton("delete");return this._editToolbar}addCommentButtonInToolbar(){this._editToolbar?.addButtonBefore("comment",this.addCommentButton(),".deleteButton")}removeCommentButtonFromToolbar(){this._editToolbar?.removeButton("comment")}removeEditToolbar(){this._editToolbar?.remove();this._editToolbar=null;this.#l?.destroy()}addContainer(t){const e=this._editToolbar?.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}createAltText(){if(!this.#l){AltText.initialize(AnnotationEditor._l10n);this.#l=new AltText(this);if(this.#Ve){this.#l.data=this.#Ve;this.#Ve=null}}return this.#l}get altTextData(){return this.#l?.data}set altTextData(t){this.#l&&(this.#l.data=t)}get guessedAltText(){return this.#l?.guessedText}async setGuessedAltText(t){await(this.#l?.setGuessedText(t))}serializeAltText(t){return this.#l?.serialize(t)}hasAltText(){return!!this.#l&&!this.#l.isEmpty()}hasAltTextData(){return this.#l?.hasData()??!1}focusCommentButton(){this.#c?.focusButton()}addCommentButton(){return this.canAddComment?this.#c||=new Comment(this):null}addStandaloneCommentButton(){if(this._uiManager.hasCommentManager())if(this.#pe)this._uiManager.isEditingMode()&&this.#pe.classList.remove("hidden");else if(this.hasComment){this.#pe=this.#c.renderForStandalone();this.div.append(this.#pe)}}removeStandaloneCommentButton(){this.#c.removeStandaloneCommentButton();this.#pe=null}hideStandaloneCommentButton(){this.#pe?.classList.add("hidden")}get comment(){if(!this.#c)return null;const{data:{richText:t,text:e,date:i,deleted:n}}=this.#c;return{text:e,richText:t,date:i,deleted:n,color:this.getNonHCMColor(),opacity:this.opacity??1}}set comment(t){this.#c||=new Comment(this);"object"==typeof t&&null!==t?this.#c.restoreData(t):this.#c.data=t;if(this.hasComment){this.removeCommentButtonFromToolbar();this.addStandaloneCommentButton();this._uiManager.updateComment(this)}else{this.addCommentButtonInToolbar();this.removeStandaloneCommentButton();this._uiManager.removeComment(this)}}setCommentData({comment:t,popupRef:e,richText:i}){if(!e)return;this.#c||=new Comment(this);this.#c.setInitialText(t,i);if(!this.annotationElementId)return;const n=this._uiManager.getAndRemoveDataFromAnnotationStorage(this.annotationElementId);n&&this.updateFromAnnotationLayer(n)}get hasEditedComment(){return this.#c?.hasBeenEdited()}get hasDeletedComment(){return this.#c?.isDeleted()}get hasComment(){return!!this.#c&&!this.#c.isEmpty()&&!this.#c.isDeleted()}async editComment(t){this.#c||=new Comment(this);this.#c.edit(t)}toggleComment(t,e=void 0){this.hasComment&&this._uiManager.toggleComment(this,t,e)}setSelectedCommentButton(t){this.#c.setSelectedButton(t)}addComment(t){if(this.hasEditedComment){const e=180,i=100,[,,,n]=t.rect,[r]=this.pageDimensions,[s]=this.pageTranslation,a=s+r+1,o=n-i,l=a+e;t.popup={contents:this.comment.text,deleted:this.comment.deleted,rect:[a,o,l,n]}}}updateFromAnnotationLayer({popup:{contents:t,deleted:e}}){this.#c.data=e?null:t}get parentBoundingClientRect(){return this.parent.boundingClientRect}render(){const t=this.div=document.createElement("div");t.setAttribute("data-editor-rotation",(360-this.rotation)%360);t.className=this.name;t.setAttribute("id",this.id);t.tabIndex=this.#$e?-1:0;t.setAttribute("role","application");this.defaultL10nId&&t.setAttribute("data-l10n-id",this.defaultL10nId);this._isVisible||t.classList.add("hidden");this.setInForeground();this.#xi();const[e,i]=this.parentDimensions;if(this.parentRotation%180!=0){t.style.maxWidth=`${(100*i/e).toFixed(2)}%`;t.style.maxHeight=`${(100*e/i).toFixed(2)}%`}const[n,r]=this.getInitialTranslation();this.translate(n,r);bindEvents(this,t,["keydown","pointerdown","dblclick"]);this.#Ci();this.addStandaloneCommentButton();this._uiManager._editorUndoBar?.hide();return t}#Ei(){this.#Qe={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};this.#l?.toggle(!1);this.parent.togglePointerEvents(!1)}#Si(t,e,i){let n=i/e*.7+1-.7;if(1===n)return;const r=this.#bi(this.rotation),transf=(t,e)=>[r[0]*t+r[2]*e,r[1]*t+r[3]*e],[s,a]=this.parentDimensions,o=this.x,l=this.y,c=this.width,h=this.height,d=AnnotationEditor.MIN_SIZE/s,u=AnnotationEditor.MIN_SIZE/a;n=Math.max(Math.min(n,1/c,1/h),d/c,u/h);const p=AnnotationEditor._round(c*n),g=AnnotationEditor._round(h*n);if(p===c&&g===h)return;this.#ni||=[o,l,c,h];const m=transf(c/2,h/2),f=AnnotationEditor._round(o+m[0]),b=AnnotationEditor._round(l+m[1]),y=transf(p/2,g/2);this.x=f-y[0];this.y=b-y[1];this.width=p;this.height=g;this.setDims();this.fixAndSetPosition();this._onResizing()}#Ti(){this.#l?.toggle(!0);this.parent.togglePointerEvents(!0);this.#_i()}pointerdown(t){const{isMac:e}=FeatureTest.platform;if(0!==t.button||t.ctrlKey&&e)t.preventDefault();else{this.#ii=!0;this._isDraggable?this.#ki(t):this.#Pi(t)}}#Pi(t){const{isMac:e}=FeatureTest.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)}#ki(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();let i=!1;const n=new AbortController,r=this._uiManager.combinedSignal(n),s={capture:!0,passive:!1,signal:r},cancelDrag=t=>{n.abort();this.#Xe=null;this.#ii=!1;this._uiManager.endDragSession()||this.#Pi(t);i&&this._onStopDragging()};if(e){this.#li=t.clientX;this.#ci=t.clientY;this.#Xe=t.pointerId;this.#Ke=t.pointerType;window.addEventListener("pointermove",t=>{if(!i){i=!0;this._uiManager.toggleComment(this,!0,!1);this._onStartDragging()}const{clientX:e,clientY:n,pointerId:r}=t;if(r!==this.#Xe){stopEvent(t);return}const[s,a]=this.screenToPageTranslation(e-this.#li,n-this.#ci);this.#li=e;this.#ci=n;this._uiManager.dragSelectedEditors(s,a);this.div.scrollIntoView({block:"nearest"})},s);window.addEventListener("touchmove",stopEvent,s);window.addEventListener("pointerdown",t=>{t.pointerType===this.#Ke&&(this.#di||t.isPrimary)&&cancelDrag(t);stopEvent(t)},s)}const pointerUpCallback=t=>{this.#Xe&&this.#Xe!==t.pointerId?stopEvent(t):cancelDrag(t)};window.addEventListener("pointerup",pointerUpCallback,{signal:r});window.addEventListener("blur",pointerUpCallback,{signal:r})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#oi&&clearTimeout(this.#oi);this.#oi=setTimeout(()=>{this.#oi=null;this.parent?.moveEditorInDOM(this)},0)}_setParentAndPosition(t,e,i){t.changeParent(this);this.x=e;this.y=i;this.fixAndSetPosition();this._onTranslated()}getRect(t,e,i=this.rotation){const n=this.parentScale,[r,s]=this.pageDimensions,[a,o]=this.pageTranslation,l=t/n,c=e/n,h=this.x*r,d=this.y*s,u=this.width*r,p=this.height*s;switch(i){case 0:return[h+l+a,s-d-c-p+o,h+l+u+a,s-d-c+o];case 90:return[h+c+a,s-d+l+o,h+c+p+a,s-d+l+u+o];case 180:return[h-l-u+a,s-d+c+o,h-l+a,s-d+c+p+o];case 270:return[h-c-p+a,s-d-l-u+o,h-c+a,s-d-l+o];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[i,n,r,s]=t,a=r-i,o=s-n;switch(this.rotation){case 0:return[i,e-s,a,o];case 90:return[i,e-n,o,a];case 180:return[r,e-n,a,o];case 270:return[r,e-s,o,a];default:throw new Error("Invalid rotation")}}getPDFRect(){return this.getRect(0,0)}getNonHCMColor(){return this.color&&AnnotationEditor._colorManager.convert(this._uiManager.getNonHCMColor(this.color))}onUpdatedColor(){this.#c?.onUpdatedColor()}getData(){const{comment:{text:t,color:e,date:i,opacity:n,deleted:r,richText:s},uid:a,pageIndex:o,creationDate:l,modificationDate:c}=this;return{id:a,pageIndex:o,rect:this.getPDFRect(),richText:s,contentsObj:{str:t},creationDate:l,modificationDate:i||c,popupRef:!r,color:e,opacity:n}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){if(this.isInEditMode())return!1;this.parent.setEditingState(!1);this.#si=!0;return!0}disableEditMode(){if(!this.isInEditMode())return!1;this.parent.setEditingState(!0);this.#si=!1;return!0}isInEditMode(){return this.#si}shouldGetKeyboardEvents(){return this.#ai}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){const{top:t,left:e,bottom:i,right:n}=this.getClientDimensions(),{innerHeight:r,innerWidth:s}=window;return e<s&&n>0&&t<r&&i>0}#xi(){if(this.#ti||!this.div)return;this.#ti=new AbortController;const t=this._uiManager.combinedSignal(this.#ti);this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t});this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})}#Ci(){!this.#di&&this.div&&this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#di=new TouchManager({container:this.div,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#Ei.bind(this),onPinching:this.#Si.bind(this),onPinchEnd:this.#Ti.bind(this),signal:this._uiManager._signal}))}rebuild(){this.#xi();this.#Ci()}rotate(t){}resize(){}serializeDeleted(){return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:this._initialData?.popupRef||""}}serialize(t=!1,e=null){return{annotationType:this.mode,pageIndex:this.pageIndex,rect:this.getPDFRect(),rotation:this.rotation,structTreeParentId:this._structTreeParentId,popupRef:this._initialData?.popupRef||""}}static async deserialize(t,e,i){const n=new this.prototype.constructor({parent:e,id:i.getId(),uiManager:i,annotationElementId:t.annotationElementId,creationDate:t.creationDate,modificationDate:t.modificationDate});n.rotation=t.rotation;n.#Ve=t.accessibilityData;n._isCopy=t.isCopy||!1;const[r,s]=n.pageDimensions,[a,o,l,c]=n.getRectInCurrentCoords(t.rect,s);n.x=a/r;n.y=o/s;n.width=l/r;n.height=c/s;return n}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||null!==this.serialize())}remove(){this.#ti?.abort();this.#ti=null;this.isEmpty()||this.commit();this.#di?.destroy();this.#di=null;this.parent?this.parent.remove(this):this._uiManager.removeEditor(this);this.hideCommentPopup();if(this.#oi){clearTimeout(this.#oi);this.#oi=null}this.#gi();this.removeEditToolbar();if(this.#hi){for(const t of this.#hi.values())clearTimeout(t);this.#hi=null}this.parent=null;this.#Ze?.remove();this.#Ze=null}get isResizable(){return!1}makeResizable(){if(this.isResizable){this.#yi();this.#Ye.classList.remove("hidden")}}get toolbarPosition(){return null}get commentButtonPosition(){return"ltr"===this._uiManager.direction?[1,0]:[0,0]}get commentButtonPositionInPage(){const{commentButtonPosition:[t,e]}=this,[i,n,r,s]=this.getPDFRect();return[AnnotationEditor._round(i+(r-i)*t),AnnotationEditor._round(n+(s-n)*(1-e))]}get commentButtonColor(){return this._uiManager.makeCommentColor(this.getNonHCMColor(),this.opacity)}get commentPopupPosition(){return this.#c.commentPopupPositionInLayer}set commentPopupPosition(t){this.#c.commentPopupPositionInLayer=t}hasDefaultPopupPosition(){return this.#c.hasDefaultPopupPosition()}get commentButtonWidth(){return this.#c.commentButtonWidth}get elementBeforePopup(){return this.div}setCommentButtonStates(t){this.#c?.setCommentButtonStates(t)}keydown(t){if(!this.isResizable||t.target!==this.div||"Enter"!==t.key)return;this._uiManager.setSelected(this);this.#Qe={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};const e=this.#Ye.children;if(!this.#qe){this.#qe=Array.from(e);const t=this.#Mi.bind(this),i=this.#Di.bind(this),n=this._uiManager._signal;for(const e of this.#qe){const r=e.getAttribute("data-resizer-name");e.setAttribute("role","spinbutton");e.addEventListener("keydown",t,{signal:n});e.addEventListener("blur",i,{signal:n});e.addEventListener("focus",this.#Ii.bind(this,r),{signal:n});e.setAttribute("data-l10n-id",AnnotationEditor._l10nResizer[r])}}const i=this.#qe[0];let n=0;for(const t of e){if(t===i)break;n++}const r=(360-this.rotation+this.parentRotation)%360/90*(this.#qe.length/4);if(r!==n){if(r<n)for(let t=0;t<n-r;t++)this.#Ye.append(this.#Ye.firstElementChild);else if(r>n)for(let t=0;t<r-n;t++)this.#Ye.firstElementChild.before(this.#Ye.lastElementChild);let t=0;for(const i of e){const e=this.#qe[t++].getAttribute("data-resizer-name");i.setAttribute("data-l10n-id",AnnotationEditor._l10nResizer[e])}}this.#Fi(0);this.#ai=!0;this.#Ye.firstElementChild.focus({focusVisible:!0});t.preventDefault();t.stopImmediatePropagation()}#Mi(t){AnnotationEditor._resizerKeyboardManager.exec(this,t)}#Di(t){this.#ai&&t.relatedTarget?.parentNode!==this.#Ye&&this.#gi()}#Ii(t){this.#ei=this.#ai?t:""}#Fi(t){if(this.#qe)for(const e of this.#qe)e.tabIndex=t}_resizeWithKeyboard(t,e){this.#ai&&this.#vi(this.#ei,{deltaX:t,deltaY:e,fromKeyboard:!0})}#gi(){this.#ai=!1;this.#Fi(-1);this.#_i()}_stopResizingWithKeyboard(){this.#gi();this.div.focus()}select(){if(this.isSelected&&this._editToolbar)this._editToolbar.show();else{this.isSelected=!0;this.makeResizable();this.div?.classList.add("selectedEditor");if(this._editToolbar){this.#Oi();this.#l?.toggleAltTextBadge(!1)}else this.addEditToolbar().then(()=>{this.div?.classList.contains("selectedEditor")&&this.#Oi()})}}#Oi(){this._editToolbar?.show();if(this._uiManager._keepToolbarInPage){this.fixAndSetPosition();this._onTranslated()}}focus(){this.div&&!this.div.contains(document.activeElement)&&setTimeout(()=>this.div?.focus({preventScroll:!0}),0)}unselect(){if(this.isSelected){this.isSelected=!1;this.#Ye?.classList.add("hidden");this.div?.classList.remove("selectedEditor");this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0});this._editToolbar?.hide();this.#l?.toggleAltTextBadge(!0);this.hideCommentPopup()}}hideCommentPopup(){this.hasComment&&this._uiManager.toggleComment(null)}updateParams(t,e){}disableEditing(){}enableEditing(){}get canChangeContent(){return!1}enterInEditMode(){if(this.canChangeContent){this.enableEditMode();this.div.focus()}}dblclick(t){if("BUTTON"!==t.target.nodeName){this.enterInEditMode();this.parent.updateToolbar({mode:this.constructor._editorType,editId:this.uid})}}getElementForAltText(){return this.div}get contentDiv(){return this.div}get isEditing(){return this.#ri}set isEditing(t){this.#ri=t;if(this.parent)if(t){this.parent.setSelected(this);this.parent.setActiveEditor(this)}else this.parent.setActiveEditor(null)}static get MIN_SIZE(){return 16}static canCreateNewEmptyEditor(){return!0}get telemetryInitialData(){return{action:"added"}}get telemetryFinalData(){return null}_reportTelemetry(t,e=!1){if(e){this.#hi||=new Map;const{action:e}=t;let i=this.#hi.get(e);i&&clearTimeout(i);i=setTimeout(()=>{this._reportTelemetry(t);this.#hi.delete(e);0===this.#hi.size&&(this.#hi=null)},AnnotationEditor._telemetryTimeout);this.#hi.set(e,i);return}t.type||=this.editorType;this._uiManager._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:t}})}show(t=this._isVisible){this.div.classList.toggle("hidden",!t);this._isVisible=t}enable(){this.div&&(this.div.tabIndex=0);this.#$e=!1}disable(){this.div&&(this.div.tabIndex=-1);this.#$e=!0}updateFakeAnnotationElement(t){if(this.#Ze||this.deleted)if(this.deleted){this.#Ze.remove();this.#Ze=null}else(this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized)&&this.#Ze.updateEdited({rect:this.getPDFRect(),popup:this.comment});else this.#Ze=t.addFakeAnnotation(this)}renderAnnotationElement(t){if(this.deleted){t.hide();return null}let e=t.container.querySelector(".annotationContent");if(e){if("CANVAS"===e.nodeName){const t=e;e=document.createElement("div");e.classList.add("annotationContent",this.editorType);t.before(e)}}else{e=document.createElement("div");e.classList.add("annotationContent",this.editorType);t.container.prepend(e)}return e}resetAnnotationElement(t){const{firstElementChild:e}=t.container;"DIV"===e?.nodeName&&e.classList.contains("annotationContent")&&e.remove()}}class FakeEditor extends AnnotationEditor{constructor(t){super(t);this.annotationElementId=t.annotationElementId;this.deleted=!0}serialize(){return this.serializeDeleted()}}const cn=3285377520,hn=4294901760,dn=65535;class MurmurHash3_64{constructor(t){this.h1=t?4294967295&t:cn;this.h2=t?4294967295&t:cn}update(t){let e,i;if("string"==typeof t){e=new Uint8Array(2*t.length);i=0;for(let n=0,r=t.length;n<r;n++){const r=t.charCodeAt(n);if(r<=255)e[i++]=r;else{e[i++]=r>>>8;e[i++]=255&r}}}else{if(!ArrayBuffer.isView(t))throw new Error("Invalid data format, must be a string or TypedArray.");e=t.slice();i=e.byteLength}const n=i>>2,r=i-4*n,s=new Uint32Array(e.buffer,0,n);let a=0,o=0,l=this.h1,c=this.h2;const h=3432918353,d=461845907,u=11601,p=13715;for(let t=0;t<n;t++)if(1&t){a=s[t];a=a*h&hn|a*u&dn;a=a<<15|a>>>17;a=a*d&hn|a*p&dn;l^=a;l=l<<13|l>>>19;l=5*l+3864292196}else{o=s[t];o=o*h&hn|o*u&dn;o=o<<15|o>>>17;o=o*d&hn|o*p&dn;c^=o;c=c<<13|c>>>19;c=5*c+3864292196}a=0;switch(r){case 3:a^=e[4*n+2]<<16;case 2:a^=e[4*n+1]<<8;case 1:a^=e[4*n];a=a*h&hn|a*u&dn;a=a<<15|a>>>17;a=a*d&hn|a*p&dn;1&n?l^=a:c^=a}this.h1=l;this.h2=c}hexdigest(){let t=this.h1,e=this.h2;t^=e>>>1;t=3981806797*t&hn|36045*t&dn;e=4283543511*e&hn|(2950163797*(e<<16|t>>>16)&hn)>>>16;t^=e>>>1;t=444984403*t&hn|60499*t&dn;e=3301882366*e&hn|(3120437893*(e<<16|t>>>16)&hn)>>>16;t^=e>>>1;return(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const un=Object.freeze({map:null,hash:"",transfer:void 0});class AnnotationStorage{#Ri=!1;#Bi=null;#Li=null;#Ni=new Map;onSetModified=null;onResetModified=null;onAnnotationEditor=null;getValue(t,e){const i=this.#Ni.get(t);return void 0===i?e:Object.assign(e,i)}getRawValue(t){return this.#Ni.get(t)}remove(t){const e=this.#Ni.get(t);if(void 0!==e){e instanceof AnnotationEditor&&this.#Li.delete(e.annotationElementId);this.#Ni.delete(t);0===this.#Ni.size&&this.resetModified();this.#Ni.values().some(t=>t instanceof AnnotationEditor)||this.onAnnotationEditor?.(null)}}setValue(t,e){const i=this.#Ni.get(t);let n=!1;if(void 0!==i){for(const[t,r]of Object.entries(e))if(i[t]!==r){n=!0;i[t]=r}}else{n=!0;this.#Ni.set(t,e)}n&&this.#Ui();if(e instanceof AnnotationEditor){(this.#Li||=new Map).set(e.annotationElementId,e);this.onAnnotationEditor?.(e.constructor._type)}}has(t){return this.#Ni.has(t)}get size(){return this.#Ni.size}#Ui(){if(!this.#Ri){this.#Ri=!0;this.onSetModified?.()}}resetModified(){if(this.#Ri){this.#Ri=!1;this.onResetModified?.()}}get print(){return new PrintAnnotationStorage(this)}get serializable(){if(0===this.#Ni.size)return un;const t=new Map,e=new MurmurHash3_64,i=[],n=Object.create(null);let r=!1;for(const[i,s]of this.#Ni){const a=s instanceof AnnotationEditor?s.serialize(!1,n):s;if(s.page){s.pageIndex=s.page._pageIndex;delete s.page}if(a){t.set(i,a);e.update(`${i}:${JSON.stringify(a)}`);r||=!!a.bitmap}}if(r)for(const e of t.values())e.bitmap&&i.push(e.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:i}:un}get editorStats(){let t=null;const e=new Map;let i=0,n=0;for(const r of this.#Ni.values()){if(!(r instanceof AnnotationEditor)){r.popup&&(r.popup.deleted?n+=1:i+=1);continue}r.isCommentDeleted?n+=1:r.hasEditedComment&&(i+=1);const s=r.telemetryFinalData;if(!s)continue;const{type:a}=s;e.getOrInsertComputed(a,()=>Object.getPrototypeOf(r).constructor);t||=Object.create(null);const o=t[a]||=new Map;for(const[t,e]of Object.entries(s)){if("type"===t)continue;const i=o.getOrInsertComputed(t,makeMap);i.set(e,(i.get(e)??0)+1)}}if(n>0||i>0){t||=Object.create(null);t.comments={deleted:n,edited:i}}if(!t)return null;for(const[i,n]of e)t[i]=n.computeTelemetryFinalData(t[i]);return t}resetModifiedIds(){this.#Bi=null}updateEditor(t,e){const i=this.#Li?.get(t);if(i){i.updateFromAnnotationLayer(e);return!0}return!1}getEditor(t){return this.#Li?.get(t)||null}get modifiedIds(){if(this.#Bi)return this.#Bi;const t=[];if(this.#Li)for(const e of this.#Li.values())e.serialize()&&t.push(e.annotationElementId);let e="";if(t.length){const i=new MurmurHash3_64;i.update(t.join(","));e=i.hexdigest()}return this.#Bi={ids:new Set(t),hash:e}}[Symbol.iterator](){return this.#Ni.entries()}}class PrintAnnotationStorage extends AnnotationStorage{#Hi=un;constructor(t){super();const{serializable:e}=t;if(e===un)return;const{map:i,hash:n,transfer:r}=e,s=structuredClone(i,r?{transfer:r}:null);this.#Hi={map:s,hash:n,transfer:[]}}get print(){unreachable("Should not call PrintAnnotationStorage.print")}get serializable(){return this.#Hi}get modifiedIds(){return util_shadow(this,"modifiedIds",{ids:new Set,hash:""})}}function getFactoryUrlProp(t){if("string"!=typeof t)return null;if(t.endsWith("/"))return t;throw new Error(`Invalid factory url: "${t}" must include trailing slash.`)}const isRefProxy=t=>"object"==typeof t&&Number.isInteger(t?.num)&&t.num>=0&&Number.isInteger(t?.gen)&&t.gen>=0,pn=function _isValidExplicitDest(t,e,i){if(!Array.isArray(i)||i.length<2)return!1;const[n,r,...s]=i;if(!t(n)&&!Number.isInteger(n))return!1;if(!e(r))return!1;const a=s.length;let o=!0;switch(r.name){case"XYZ":if(a<2||a>3)return!1;break;case"Fit":case"FitB":return 0===a;case"FitH":case"FitBH":case"FitV":case"FitBV":if(a>1)return!1;break;case"FitR":if(4!==a)return!1;o=!1;break;default:return!1}for(const t of s)if(!("number"==typeof t||o&&null===t))return!1;return!0}.bind(null,isRefProxy,t=>"object"==typeof t&&"string"==typeof t?.name);function getWorkerSrc(t){if(!function isSameOrigin(t,e){const i=URL.parse(t);if(!i?.origin||"null"===i.origin)return!1;const n=new URL(e,i);return i.origin===n.origin}(window.location,t)){const e=`await import("${new URL(t,window.location).href}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))}return t}class LoopbackPort{#zi=new Map;#Gi=Promise.resolve();postMessage(t,e){const i={data:structuredClone(t,e?{transfer:e}:null)};this.#Gi.then(()=>{for(const[t]of this.#zi)t.call(this,i)})}addEventListener(t,e,i=null){let n=null;if(i?.signal instanceof AbortSignal){const{signal:r}=i;if(r.aborted){warn("LoopbackPort - cannot use an `aborted` signal.");return}const onAbort=()=>this.removeEventListener(t,e);n=()=>r.removeEventListener("abort",onAbort);r.addEventListener("abort",onAbort)}this.#zi.set(e,n)}removeEventListener(t,e){const i=this.#zi.get(e);i?.();this.#zi.delete(e)}terminate(){for(const[,t]of this.#zi)t?.();this.#zi.clear()}}class StatTimer{#Wi=new Map;times=[];time(t){this.#Wi.has(t)&&warn(`Timer is already running for ${t}`);this.#Wi.set(t,Date.now())}timeEnd(t){this.#Wi.has(t)||warn(`Timer has not been started for ${t}`);this.times.push({name:t,start:this.#Wi.get(t),end:Date.now()});this.#Wi.delete(t)}toString(){const t=Math.max(...this.times.map(t=>t.name.length));return this.times.map(e=>`${e.name.padEnd(t)} ${e.end-e.start}ms\n`).join("")}}const gn=new class WebGPU{#ji=null;#Vi=null;#qi=null;#$i=null;async#Xi(){if(!globalThis.navigator?.gpu)return!1;try{const t=await navigator.gpu.requestAdapter();if(!t)return!1;this.#$i=navigator.gpu.getPreferredCanvasFormat();this.#Vi=await t.requestDevice();return!0}catch{return!1}}init(){return this.#ji||=this.#Xi()}get isReady(){return null!==this.#Vi}loadMeshShader(){if(!this.#Vi||this.#qi)return;const t=this.#Vi.createShaderModule({code:"\nstruct Uniforms {\n  offsetX      : f32,\n  offsetY      : f32,\n  scaleX       : f32,\n  scaleY       : f32,\n  paddedWidth  : f32,\n  paddedHeight : f32,\n  borderSize   : f32,\n  _pad         : f32,\n};\n\n@group(0) @binding(0) var<uniform> u : Uniforms;\n\nstruct VertexInput {\n  @location(0) position : vec2<f32>,\n  @location(1) color    : vec4<f32>,\n};\n\nstruct VertexOutput {\n  @builtin(position) position : vec4<f32>,\n  @location(0)       color    : vec3<f32>,\n};\n\n@vertex\nfn vs_main(in : VertexInput) -> VertexOutput {\n  var out : VertexOutput;\n  let cx = (in.position.x + u.offsetX) * u.scaleX;\n  let cy = (in.position.y + u.offsetY) * u.scaleY;\n  out.position = vec4<f32>(\n    ((cx + u.borderSize) / u.paddedWidth) * 2.0 - 1.0,\n    1.0 - ((cy + u.borderSize) / u.paddedHeight) * 2.0,\n    0.0,\n    1.0\n  );\n  out.color = in.color.rgb;\n  return out;\n}\n\n@fragment\nfn fs_main(in : VertexOutput) -> @location(0) vec4<f32> {\n  return vec4<f32>(in.color, 1.0);\n}\n"});this.#qi=this.#Vi.createRenderPipeline({layout:"auto",vertex:{module:t,entryPoint:"vs_main",buffers:[{arrayStride:8,attributes:[{shaderLocation:0,offset:0,format:"float32x2"}]},{arrayStride:4,attributes:[{shaderLocation:1,offset:0,format:"unorm8x4"}]}]},fragment:{module:t,entryPoint:"fs_main",targets:[{format:this.#$i}]},primitive:{topology:"triangle-list"}})}draw(t,e,i,n,r,s,a,o){this.loadMeshShader();const l=this.#Vi,{offsetX:c,offsetY:h,scaleX:d,scaleY:u}=n,p=l.createBuffer({size:Math.max(t.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});t.byteLength>0&&l.queue.writeBuffer(p,0,t);const g=l.createBuffer({size:Math.max(e.byteLength,4),usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST});e.byteLength>0&&l.queue.writeBuffer(g,0,e);const m=l.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});l.queue.writeBuffer(m,0,new Float32Array([c,h,d,u,s,a,o,0]));const f=l.createBindGroup({layout:this.#qi.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:m}}]}),b=new OffscreenCanvas(s,a),y=b.getContext("webgpu");y.configure({device:l,format:this.#$i,alphaMode:r?"opaque":"premultiplied"});const w=r?{r:r[0]/255,g:r[1]/255,b:r[2]/255,a:1}:{r:0,g:0,b:0,a:0},v=l.createCommandEncoder(),_=v.beginRenderPass({colorAttachments:[{view:y.getCurrentTexture().createView(),clearValue:w,loadOp:"clear",storeOp:"store"}]});if(i>0){_.setPipeline(this.#qi);_.setBindGroup(0,f);_.setVertexBuffer(0,p);_.setVertexBuffer(1,g);_.draw(i)}_.end();l.queue.submit([v.finish()]);p.destroy();g.destroy();m.destroy();return b.transferToImageBitmap()}};function initGPU(){return gn.init()}function isGPUReady(){return gn.isReady}Xe();const mn=1,fn=2,bn=1,yn=2,wn=3,vn=4,_n=5,An=6,xn=7,Cn=8;function onFn(){}function wrapReason(t){if(t instanceof AbortException||t instanceof InvalidPDFException||t instanceof PasswordException||t instanceof ResponseException||t instanceof UnknownErrorException)return t;if("object"!=typeof t||null===t)return new UnknownErrorException(String(t),String(t));switch(t.name){case"AbortException":return new AbortException(t.message);case"InvalidPDFException":return new InvalidPDFException(t.message);case"PasswordException":return new PasswordException(t.message,t.code);case"ResponseException":return new ResponseException(t.message,t.status,t.missing);case"UnknownErrorException":return new UnknownErrorException(t.message,t.details)}return new UnknownErrorException(t.message,t.toString())}class MessageHandler{#Ki=new Map;#Yi=new Map;#Ji=1;#Qi;#Zi=new AbortController;#tn;#en=new Map;#in=1;#nn=new Map;#rn;constructor(t,e,i){this.#tn=t;this.#rn=e;this.#Qi=i;i.addEventListener("message",this.#sn.bind(this),{signal:this.#Zi.signal})}#sn({data:t}){if(t.targetName!==this.#tn)return;if(t.stream){this.#an(t);return}if(t.callback){const{callbackId:e,callback:i}=t,n=this.#Yi.get(e);if(!n)throw new Error(`Cannot resolve callback ${e}`);this.#Yi.delete(e);if(i===mn)n.resolve(t.data);else{if(i!==fn)throw new Error("Unexpected callback case");n.reject(wrapReason(t.reason))}return}const e=this.#Ki.get(t.action);if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const i=this.#tn,n=t.sourceName,r=this.#Qi;Promise.try(e,t.data).then(e=>{r.postMessage({sourceName:i,targetName:n,callback:mn,callbackId:t.callbackId,data:e})}).catch(e=>{r.postMessage({sourceName:i,targetName:n,callback:fn,callbackId:t.callbackId,reason:wrapReason(e)})});return}t.streamId?this.#on(t):e(t.data)}on(t,e){const i=this.#Ki;if(i.has(t))throw new Error(`There is already a "${t}" handler.`);i.set(t,e)}send(t,e,i){this.#Qi.postMessage({sourceName:this.#tn,targetName:this.#rn,action:t,data:e},i)}sendWithPromise(t,e,i){const n=this.#Ji++,r=Promise.withResolvers();this.#Yi.set(n,r);try{this.#Qi.postMessage({sourceName:this.#tn,targetName:this.#rn,action:t,callbackId:n,data:e},i)}catch(t){r.reject(t)}return r.promise}sendWithStream(t,e,i,n){const r=this.#in++,s=this.#tn,a=this.#rn,o=this.#Qi;return new ReadableStream({start:i=>{const l=Promise.withResolvers();this.#en.set(r,{controller:i,startCall:l,pullCall:null,cancelCall:null,isClosed:!1});o.postMessage({sourceName:s,targetName:a,action:t,streamId:r,data:e,desiredSize:i.desiredSize},n);return l.promise},pull:t=>{const e=Promise.withResolvers();this.#en.get(r).pullCall=e;o.postMessage({sourceName:s,targetName:a,stream:An,streamId:r,desiredSize:t.desiredSize});return e.promise},cancel:t=>{util_assert(t instanceof Error,"cancel must have a valid reason");const e=Promise.withResolvers();this.#en.get(r).cancelCall=e;this.#en.get(r).isClosed=!0;o.postMessage({sourceName:s,targetName:a,stream:bn,streamId:r,reason:wrapReason(t)});return e.promise}},i)}#on(t){const e=t.streamId,i=this.#tn,n=t.sourceName,r=this.#Qi,s=this.#nn,a=this.#Ki.get(t.action),o={enqueue(t,s=1,a){if(this.isCancelled)return;const o=this.desiredSize;this.desiredSize-=s;if(o>0&&this.desiredSize<=0){this.sinkCapability=Promise.withResolvers();this.ready=this.sinkCapability.promise}r.postMessage({sourceName:i,targetName:n,stream:vn,streamId:e,chunk:t},a)},close(){if(!this.isCancelled){this.isCancelled=!0;r.postMessage({sourceName:i,targetName:n,stream:wn,streamId:e});s.delete(e)}},error(t){if(!this.isCancelled){this.isCancelled=!0;r.postMessage({sourceName:i,targetName:n,stream:_n,streamId:e,reason:wrapReason(t)})}},sinkCapability:Promise.withResolvers(),onPull:null,onCancel:null,isCancelled:!1,desiredSize:t.desiredSize,ready:null};o.sinkCapability.resolve();o.ready=o.sinkCapability.promise;s.set(e,o);Promise.try(a,t.data,o).then(()=>{r.postMessage({sourceName:i,targetName:n,stream:Cn,streamId:e,success:!0})},t=>{r.postMessage({sourceName:i,targetName:n,stream:Cn,streamId:e,reason:wrapReason(t)})})}#an(t){const e=t.streamId,i=this.#tn,n=t.sourceName,r=this.#Qi,s=this.#en.get(e),a=this.#nn.get(e);switch(t.stream){case Cn:t.success?s.startCall.resolve():s.startCall.reject(wrapReason(t.reason));break;case xn:t.success?s.pullCall.resolve():s.pullCall.reject(wrapReason(t.reason));break;case An:if(!a){r.postMessage({sourceName:i,targetName:n,stream:xn,streamId:e,success:!0});break}a.desiredSize<=0&&t.desiredSize>0&&a.sinkCapability.resolve();a.desiredSize=t.desiredSize;Promise.try(a.onPull||onFn).then(()=>{r.postMessage({sourceName:i,targetName:n,stream:xn,streamId:e,success:!0})},t=>{r.postMessage({sourceName:i,targetName:n,stream:xn,streamId:e,reason:wrapReason(t)})});break;case vn:util_assert(s,"enqueue should have stream controller");if(s.isClosed)break;s.controller.enqueue(t.chunk);break;case wn:util_assert(s,"close should have stream controller");if(s.isClosed)break;s.isClosed=!0;s.controller.close();this.#ln(s,e);break;case _n:util_assert(s,"error should have stream controller");s.controller.error(wrapReason(t.reason));this.#ln(s,e);break;case yn:t.success?s.cancelCall.resolve():s.cancelCall.reject(wrapReason(t.reason));this.#ln(s,e);break;case bn:if(!a)break;const o=wrapReason(t.reason);Promise.try(a.onCancel||onFn,o).then(()=>{r.postMessage({sourceName:i,targetName:n,stream:yn,streamId:e,success:!0})},t=>{r.postMessage({sourceName:i,targetName:n,stream:yn,streamId:e,reason:wrapReason(t)})});a.sinkCapability.reject(o);a.isCancelled=!0;this.#nn.delete(e);break;default:throw new Error("Unexpected stream case")}}async#ln(t,e){await Promise.allSettled([t.startCall?.promise,t.pullCall?.promise,t.cancelCall?.promise]);this.#en.delete(e)}destroy(){this.#Zi?.abort();this.#Zi=null}get destroyed(){return!this.#Zi}}class BaseBinaryDataFactory{#cn=Object.freeze({cMapUrl:"CMap",standardFontDataUrl:"font",wasmUrl:"wasm"});constructor({cMapUrl:t=null,standardFontDataUrl:e=null,wasmUrl:i=null}){this.cMapUrl=t;this.standardFontDataUrl=e;this.wasmUrl=i}async fetch({kind:t,filename:e}){switch(t){case"cMapUrl":case"standardFontDataUrl":case"wasmUrl":break;default:unreachable(`Not implemented: ${t}`)}const i=this[t];if(!i)throw new Error(`Ensure that the \`${t}\` API parameter is provided.`);const n=`${i}${e}`;return this._fetch(n,t).catch(e=>{throw new Error(`Unable to load ${this.#cn[t]} data at: ${n}`)})}async _fetch(t,e){unreachable("Abstract method `_fetch` called.")}}class DOMBinaryDataFactory extends BaseBinaryDataFactory{async _fetch(t,e){const i="cMapUrl"!==e||t.endsWith(".bcmap")?"bytes":"text",n=await fetchData(t,i);return n instanceof Uint8Array?n:stringToBytes(n)}}class BaseCanvasFactory{#hn=!1;constructor({enableHWA:t=!1}){this.#hn=t}create(t,e){if(t<=0||e<=0)throw new Error("Invalid canvas size");const i=this._createCanvas(t,e);return{canvas:i,context:i.getContext("2d",{willReadFrequently:!this.#hn})}}reset({canvas:t},e,i){if(!t)throw new Error("Canvas is not specified");if(e<=0||i<=0)throw new Error("Invalid canvas size");t.width=e;t.height=i}destroy(t){const{canvas:e}=t;if(!e)throw new Error("Canvas is not specified");e.width=e.height=0;t.canvas=null;t.context=null}getNoAlphaContext(t){return t.getContext("2d",{alpha:!1,willReadFrequently:!this.#hn})}_createCanvas(t,e){unreachable("Abstract method `_createCanvas` called.")}}class BaseFilterFactory{addFilter(t){return"none"}addHCMFilter(t,e){return"none"}addAlphaFilter(t){return"none"}addLuminosityFilter(t){return"none"}addKnockoutFilter(t=0){return"none"}addHighlightHCMFilter(t,e,i,n,r){return"none"}addSelectionHCMFilter(t,e){return"none"}addSelectionFilter(){return"none"}createSelectionStyle(t=null){return null}destroy(t=!1){}}if(ui){let t;try{const e=process.getBuiltinModule("module").createRequire(import.meta.url);try{t=e("@napi-rs/canvas")}catch(t){warn(`Cannot load "@napi-rs/canvas" package: "${t}".`)}}catch(t){warn(`Cannot access the \`require\` function: "${t}".`)}globalThis.DOMMatrix||(t?.DOMMatrix?globalThis.DOMMatrix=t.DOMMatrix:warn("Cannot polyfill `DOMMatrix`, rendering may be broken."));globalThis.Path2D||(t?.Path2D?globalThis.Path2D=t.Path2D:warn("Cannot polyfill `Path2D`, rendering may be broken."));globalThis.navigator?.language||(globalThis.navigator={language:"en-US",platform:"",userAgent:""})}class NodeFilterFactory extends BaseFilterFactory{}class NodeCanvasFactory extends BaseCanvasFactory{_createCanvas(t,e){return process.getBuiltinModule("module").createRequire(import.meta.url)("@napi-rs/canvas").createCanvas(t,e)}}class NodeBinaryDataFactory extends BaseBinaryDataFactory{async _fetch(t,e){return async function node_utils_fetchData(t){const e=process.getBuiltinModule("fs/promises"),i=await e.readFile(t);return new Uint8Array(i)}(t)}}Ne();const En="__forcedDependency",{floor:Sn,ceil:Tn}=Math;function expandBBox(t,e,i,n,r,s){t[4*e+0]=Math.min(t[4*e+0],i);t[4*e+1]=Math.min(t[4*e+1],n);t[4*e+2]=Math.max(t[4*e+2],r);t[4*e+3]=Math.max(t[4*e+3],s)}const kn=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0];class BBoxReader{#dn;#un;constructor(t,e){this.#dn=t;this.#un=e}static fromBuffer(t){return new BBoxReader(new Uint32Array(t),new Uint8ClampedArray(t))}get buffer(){return this.#dn.buffer}get length(){return this.#dn.length}isEmpty(t){return this.#dn[t]===kn}minX(t){return this.#un[4*t+0]/256}minY(t){return this.#un[4*t+1]/256}maxX(t){return(this.#un[4*t+2]+1)/256}maxY(t){return(this.#un[4*t+3]+1)/256}}const ensureDebugMetadata=(t,e)=>t?.getOrInsertComputed(e,()=>({dependencies:new Set,isRenderingOperation:!1}));class CanvasBBoxTracker{#pn=[[1,0,0,1,0,0]];#gn=[-1/0,-1/0,1/0,1/0];#mn=new Float64Array(pi);_pendingBBoxIdx=-1;#fn;#bn;#yn;#dn;_savesStack=[];_markedContentStack=[];constructor(t,e){this.#fn=t.width;this.#bn=t.height;this.#wn(e)}growOperationsCount(t){t>=this.#dn.length&&this.#wn(t,this.#dn)}#wn(t,e){const i=new ArrayBuffer(4*t);this.#yn=new Uint8ClampedArray(i);this.#dn=new Uint32Array(i);if(e&&e.length>0){this.#dn.set(e);this.#dn.fill(kn,e.length)}else this.#dn.fill(kn)}get clipBox(){return this.#gn}save(t){this.#gn={__proto__:this.#gn};this._savesStack.push(t);return this}restore(t,e){const i=Object.getPrototypeOf(this.#gn);if(null===i)return this;this.#gn=i;const n=this._savesStack.pop();if(void 0!==n){e?.(n,t);this.#dn[t]=this.#dn[n]}return this}recordOpenMarker(t){this._savesStack.push(t);return this}getOpenMarker(){return 0===this._savesStack.length?null:this._savesStack.at(-1)}recordCloseMarker(t,e){const i=this._savesStack.pop();if(void 0!==i){e?.(i,t);this.#dn[t]=this.#dn[i]}return this}beginMarkedContent(t){this._markedContentStack.push(t);return this}endMarkedContent(t,e){const i=this._markedContentStack.pop();if(void 0!==i){e?.(i,t);this.#dn[t]=this.#dn[i]}return this}pushBaseTransform(t){this.#pn.push(Util.multiplyByDOMMatrix(this.#pn.at(-1),t.getTransform()));return this}popBaseTransform(){this.#pn.length>1&&this.#pn.pop();return this}resetBBox(t){if(this._pendingBBoxIdx!==t){this._pendingBBoxIdx=t;this.#mn.set(pi,0)}return this}recordClipBox(t,e,i,n,r,s){const a=Util.multiplyByDOMMatrix(this.#pn.at(-1),e.getTransform()),o=pi.slice();Util.axialAlignedBoundingBox([i,r,n,s],a,o);const l=Util.intersect(this.#gn,o);if(l){this.#gn[0]=l[0];this.#gn[1]=l[1];this.#gn[2]=l[2];this.#gn[3]=l[3]}else{this.#gn[0]=this.#gn[1]=1/0;this.#gn[2]=this.#gn[3]=-1/0}return this}recordBBox(t,e,i,n,r,s){const a=this.#gn;if(a[0]===1/0)return this;const o=Util.multiplyByDOMMatrix(this.#pn.at(-1),e.getTransform());if(a[0]===-1/0){Util.axialAlignedBoundingBox([i,r,n,s],o,this.#mn);return this}const l=pi.slice();Util.axialAlignedBoundingBox([i,r,n,s],o,l);this.#mn[0]=MathClamp(l[0],a[0],this.#mn[0]);this.#mn[1]=MathClamp(l[1],a[1],this.#mn[1]);this.#mn[2]=MathClamp(l[2],this.#mn[2],a[2]);this.#mn[3]=MathClamp(l[3],this.#mn[3],a[3]);return this}recordFullPageBBox(t){this.#mn[0]=Math.max(0,this.#gn[0]);this.#mn[1]=Math.max(0,this.#gn[1]);this.#mn[2]=Math.min(this.#fn,this.#gn[2]);this.#mn[3]=Math.min(this.#bn,this.#gn[3]);return this}recordOperation(t,e=!1,i){if(this._pendingBBoxIdx!==t)return this;const n=Sn(256*this.#mn[0]/this.#fn),r=Sn(256*this.#mn[1]/this.#bn),s=Tn(256*this.#mn[2]/this.#fn),a=Tn(256*this.#mn[3]/this.#bn);expandBBox(this.#yn,t,n,r,s,a);if(i)for(const e of i)for(const i of e)i!==t&&expandBBox(this.#yn,i,n,r,s,a);e||(this._pendingBBoxIdx=-1);return this}bboxToClipBoxDropOperation(t){if(this._pendingBBoxIdx===t){this._pendingBBoxIdx=-1;this.#gn[0]=Math.max(this.#gn[0],this.#mn[0]);this.#gn[1]=Math.max(this.#gn[1],this.#mn[1]);this.#gn[2]=Math.min(this.#gn[2],this.#mn[2]);this.#gn[3]=Math.min(this.#gn[3],this.#mn[3])}return this}take(){return new BBoxReader(this.#dn,this.#yn)}takeDebugMetadata(){throw new Error("Unreachable")}recordSimpleData(t,e){return this}recordIncrementalData(t,e){return this}resetIncrementalData(t,e){return this}recordNamedData(t,e){return this}recordSimpleDataFromNamed(t,e,i){return this}recordFutureForcedDependency(t,e){return this}inheritSimpleDataAsFutureForcedDependencies(t){return this}inheritPendingDependenciesAsFutureForcedDependencies(){return this}recordCharacterBBox(t,e,i,n=1,r=0,s=0,a){return this}getSimpleIndex(t){}recordDependencies(t,e){return this}recordNamedDependency(t,e){return this}recordShowTextOperation(t,e=!1){return this}}class CanvasDependencyTracker{#vn={__proto__:null};#_n={__proto__:null,transform:[],moveText:[],sameLineText:[],[En]:[]};#An=new Map;#xn=new Set;#Cn=new Map;#En;#Sn;#Tn;constructor(t,e=!1){this.#Tn=t;if(e){this.#En=new Map;this.#Sn=(t,e)=>{ensureDebugMetadata(this.#En,e).dependencies.add(t)}}}get clipBox(){return this.#Tn.clipBox}growOperationsCount(t){this.#Tn.growOperationsCount(t)}save(t){this.#vn={__proto__:this.#vn};this.#_n={__proto__:this.#_n,transform:{__proto__:this.#_n.transform},moveText:{__proto__:this.#_n.moveText},sameLineText:{__proto__:this.#_n.sameLineText},[En]:{__proto__:this.#_n[En]}};this.#Tn.save(t);return this}restore(t){this.#Tn.restore(t,this.#Sn);const e=Object.getPrototypeOf(this.#vn);if(null===e)return this;this.#vn=e;this.#_n=Object.getPrototypeOf(this.#_n);return this}recordOpenMarker(t){this.#Tn.recordOpenMarker(t,this.#Sn);return this}getOpenMarker(){return this.#Tn.getOpenMarker()}recordCloseMarker(t){this.#Tn.recordCloseMarker(t,this.#Sn);return this}beginMarkedContent(t){this.#Tn.beginMarkedContent(t);return this}endMarkedContent(t){this.#Tn.endMarkedContent(t,this.#Sn);return this}pushBaseTransform(t){this.#Tn.pushBaseTransform(t);return this}popBaseTransform(){this.#Tn.popBaseTransform();return this}recordSimpleData(t,e){this.#vn[t]=e;return this}recordIncrementalData(t,e){this.#_n[t].push(e);return this}resetIncrementalData(t,e){this.#_n[t].length=0;return this}recordNamedData(t,e){this.#An.set(t,e);return this}recordSimpleDataFromNamed(t,e,i){this.#vn[t]=this.#An.get(e)??i}recordFutureForcedDependency(t,e){this.recordIncrementalData(En,e);return this}inheritSimpleDataAsFutureForcedDependencies(t){for(const e of t)e in this.#vn&&this.recordFutureForcedDependency(e,this.#vn[e]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(const t of this.#xn)this.recordFutureForcedDependency(En,t);return this}resetBBox(t){this.#Tn.resetBBox(t);return this}recordClipBox(t,e,i,n,r,s){this.#Tn.recordClipBox(t,e,i,n,r,s);return this}recordBBox(t,e,i,n,r,s){this.#Tn.recordBBox(t,e,i,n,r,s);return this}recordCharacterBBox(t,e,i,n=1,r=0,s=0,a){const o=i.bbox;let l,c;if(o){l=o[2]!==o[0]&&o[3]!==o[1]&&this.#Cn.get(i);if(!1!==l){c=[0,0,0,0];Util.axialAlignedBoundingBox(o,i.fontMatrix,c);1===n&&0===r&&0===s||function scaleCharBBox(t,e,i,n,r){let s;if(t){if(t<0){s=r[0];r[0]=r[2];r[2]=s}r[0]*=t;r[2]*=t;if(e<0){s=r[1];r[1]=r[3];r[3]=s}r[1]*=e;r[3]*=e}else r.fill(0);r[0]+=i;r[1]+=n;r[2]+=i;r[3]+=n}(n,-n,r,s,c);if(l)return this.recordBBox(t,e,c[0],c[2],c[1],c[3])}}if(!a)return this.recordFullPageBBox(t);const h=a();if(o&&c&&void 0===l){l=c[0]<=r-h.actualBoundingBoxLeft&&c[2]>=r+h.actualBoundingBoxRight&&c[1]<=s-h.actualBoundingBoxAscent&&c[3]>=s+h.actualBoundingBoxDescent;this.#Cn.set(i,l);if(l)return this.recordBBox(t,e,c[0],c[2],c[1],c[3])}return this.recordBBox(t,e,r-h.actualBoundingBoxLeft,r+h.actualBoundingBoxRight,s-h.actualBoundingBoxAscent,s+h.actualBoundingBoxDescent)}recordFullPageBBox(t){this.#Tn.recordFullPageBBox(t);return this}getSimpleIndex(t){return this.#vn[t]}recordDependencies(t,e){const i=this.#xn,n=this.#vn,r=this.#_n;for(const t of e)t in this.#vn?i.add(n[t]):t in r&&r[t].forEach(i.add,i);return this}recordNamedDependency(t,e){this.#An.has(e)&&this.#xn.add(this.#An.get(e));return this}recordOperation(t,e=!1){this.recordDependencies(t,[En]);if(this.#En){const e=ensureDebugMetadata(this.#En,t),{dependencies:i}=e;this.#xn.forEach(i.add,i);this.#Tn._savesStack.forEach(i.add,i);this.#Tn._markedContentStack.forEach(i.add,i);i.delete(t);e.isRenderingOperation=!0}const i=!e&&t===this.#Tn._pendingBBoxIdx;this.#Tn.recordOperation(t,e,[this.#xn,this.#Tn._savesStack,this.#Tn._markedContentStack]);i&&this.#xn.clear();return this}recordShowTextOperation(t,e=!1){const i=Array.from(this.#xn);this.recordOperation(t,e);this.recordIncrementalData("sameLineText",t);for(const t of i)this.recordIncrementalData("sameLineText",t);return this}bboxToClipBoxDropOperation(t,e=!1){const i=!e&&t===this.#Tn._pendingBBoxIdx;this.#Tn.bboxToClipBoxDropOperation(t);i&&this.#xn.clear();return this}take(){this.#Cn.clear();return this.#Tn.take()}takeDebugMetadata(){return this.#En}}class CanvasNestedDependencyTracker{#kn;#Pn;#Mn;#Dn=0;#In=0;constructor(t,e,i){if(t instanceof CanvasNestedDependencyTracker&&t.#Mn===!!i)return t;this.#kn=t;this.#Pn=e;this.#Mn=!!i}get clipBox(){return this.#kn.clipBox}growOperationsCount(){throw new Error("Unreachable")}save(t){this.#In++;this.#kn.save(this.#Pn);return this}restore(t){if(this.#In>0){this.#kn.restore(this.#Pn);this.#In--}return this}recordOpenMarker(t){this.#Dn++;return this}getOpenMarker(){return this.#Dn>0?this.#Pn:this.#kn.getOpenMarker()}recordCloseMarker(t){this.#Dn--;return this}beginMarkedContent(t){return this}endMarkedContent(t){return this}pushBaseTransform(t){this.#kn.pushBaseTransform(t);return this}popBaseTransform(){this.#kn.popBaseTransform();return this}recordSimpleData(t,e){this.#kn.recordSimpleData(t,this.#Pn);return this}recordIncrementalData(t,e){this.#kn.recordIncrementalData(t,this.#Pn);return this}resetIncrementalData(t,e){this.#kn.resetIncrementalData(t,this.#Pn);return this}recordNamedData(t,e){return this}recordSimpleDataFromNamed(t,e,i){this.#kn.recordSimpleDataFromNamed(t,e,this.#Pn);return this}recordFutureForcedDependency(t,e){this.#kn.recordFutureForcedDependency(t,this.#Pn);return this}inheritSimpleDataAsFutureForcedDependencies(t){this.#kn.inheritSimpleDataAsFutureForcedDependencies(t);return this}inheritPendingDependenciesAsFutureForcedDependencies(){this.#kn.inheritPendingDependenciesAsFutureForcedDependencies();return this}resetBBox(t){this.#Mn||this.#kn.resetBBox(this.#Pn);return this}recordClipBox(t,e,i,n,r,s){this.#Mn||this.#kn.recordClipBox(this.#Pn,e,i,n,r,s);return this}recordBBox(t,e,i,n,r,s){this.#Mn||this.#kn.recordBBox(this.#Pn,e,i,n,r,s);return this}recordCharacterBBox(t,e,i,n,r,s,a){this.#Mn||this.#kn.recordCharacterBBox(this.#Pn,e,i,n,r,s,a);return this}recordFullPageBBox(t){this.#Mn||this.#kn.recordFullPageBBox(this.#Pn);return this}getSimpleIndex(t){return this.#kn.getSimpleIndex(t)}recordDependencies(t,e){this.#kn.recordDependencies(this.#Pn,e);return this}recordNamedDependency(t,e){this.#kn.recordNamedDependency(this.#Pn,e);return this}recordOperation(t){this.#kn.recordOperation(this.#Pn,!0);return this}recordShowTextOperation(t){this.#kn.recordShowTextOperation(this.#Pn,!0);return this}bboxToClipBoxDropOperation(t){this.#Mn||this.#kn.bboxToClipBoxDropOperation(this.#Pn,!0);return this}take(){throw new Error("Unreachable")}takeDebugMetadata(){throw new Error("Unreachable")}}const Pn=["path","transform","filter","strokeColor","strokeAlpha","lineWidth","lineCap","lineJoin","miterLimit","dash"],Mn=["path","transform","filter","fillColor","fillAlpha","globalCompositeOperation","SMask"],Dn=["transform","SMask","filter","fillAlpha","strokeAlpha","globalCompositeOperation"],In=["filter","fillColor","fillAlpha"],Fn=["transform","leading","charSpacing","wordSpacing","hScale","textRise","moveText","textMatrix","font","fontObj","filter","fillColor","textRenderingMode","SMask","fillAlpha","strokeAlpha","globalCompositeOperation","sameLineText"],On=["transform"],Rn=["transform","filter","fillColor"];class CanvasImagesTracker{#fn;#bn;#Fn=4;#On=0;#un=new CanvasImagesTracker.#Rn(6*this.#Fn);static#Rn=FeatureTest.isFloat16ArraySupported?Float16Array:Float32Array;constructor(t){this.#fn=t.width;this.#bn=t.height}record(t,e,i,n){if(this.#On===this.#Fn){this.#Fn*=2;const t=new CanvasImagesTracker.#Rn(6*this.#Fn);t.set(this.#un);this.#un=t}const r=getCurrentTransform(t);let s;if(n[0]!==1/0){const t=pi.slice();Util.axialAlignedBoundingBox([0,-i,e,0],r,t);const a=Util.intersect(n,t);if(!a)return;const[o,l,c,h]=a;if(o!==t[0]||l!==t[1]||c!==t[2]||h!==t[3]){const t=Math.atan2(r[1],r[0]),e=Math.abs(Math.sin(t)),i=Math.abs(Math.cos(t));if(e<1e-6||i<1e-6||Math.abs(e-i)<1e-6)s=[o,l,o,h,c,l];else{const t=c-o,n=h-l,r=e*e,a=i*i,d=i*e,u=a-r,p=(n*a-t*d)/u;s=[o+(n*d-t*r)/u,l,o,l+p,c,h-p]}}}if(!s){s=[0,-i,0,0,e,-i];Util.applyTransform(s,r,0);Util.applyTransform(s,r,2);Util.applyTransform(s,r,4)}s[0]/=this.#fn;s[1]/=this.#bn;s[2]/=this.#fn;s[3]/=this.#bn;s[4]/=this.#fn;s[5]/=this.#bn;this.#un.set(s,6*this.#On);this.#On++}take(){return this.#un.subarray(0,6*this.#On)}}function convertBlackAndWhiteToRGBA({src:t,srcPos:e=0,dest:i,width:n,height:r,nonBlackColor:s=4294967295,inverseDecode:a=!1}){const o=FeatureTest.isLittleEndian?4278190080:255,[l,c]=a?[s,o]:[o,s],h=n>>3,d=7&n,u=l^c,p=t.length;i=new Uint32Array(i.buffer);let g=0;for(let n=0;n<r;++n){for(const n=e+h;e<n;++e,g+=8){const n=t[e];i[g]=l^-(n>>7&1)&u;i[g+1]=l^-(n>>6&1)&u;i[g+2]=l^-(n>>5&1)&u;i[g+3]=l^-(n>>4&1)&u;i[g+4]=l^-(n>>3&1)&u;i[g+5]=l^-(n>>2&1)&u;i[g+6]=l^-(n>>1&1)&u;i[g+7]=l^-(1&n)&u}if(0===d)continue;const n=e<p?t[e++]:255;for(let t=0;t<d;++t,++g)i[g]=l^-(n>>7-t&1)&u}return{srcPos:e,destPos:g}}function convertRGBToRGBA({src:t,srcPos:e=0,dest:i,destPos:n=0,width:r,height:s}){let a=0;const o=r*s*3,l=t.byteOffset+e,c=l%4==0?Math.floor(MathClamp(t.length-e,0,o)/4):0,h=c>0?new Uint32Array(t.buffer,l,c):null,d=FeatureTest.isLittleEndian?4278190080:255;if(FeatureTest.isLittleEndian){for(;a<c-2;a+=3,n+=4){const t=h[a],e=h[a+1],r=h[a+2];i[n]=t|d;i[n+1]=t>>>24|e<<8|d;i[n+2]=e>>>16|r<<16|d;i[n+3]=r>>>8|d}for(let r=e+4*a,s=e+o;r<s;r+=3)i[n++]=t[r]|t[r+1]<<8|t[r+2]<<16|d}else{for(;a<c-2;a+=3,n+=4){const t=h[a],e=h[a+1],r=h[a+2];i[n]=t|d;i[n+1]=t<<24|e>>>8|d;i[n+2]=e<<16|r>>>16|d;i[n+3]=r<<8|d}for(let r=e+4*a,s=e+o;r<s;r+=3)i[n++]=t[r]<<24|t[r+1]<<16|t[r+2]<<8|d}return{srcPos:e+o,destPos:n}}const Bn="Fill",Ln="Stroke",Nn="Shading";function applyBoundingBox(t,e){if(!e)return;const i=e[2]-e[0],n=e[3]-e[1],r=new Path2D;r.rect(e[0],e[1],i,n);t.clip(r)}class BaseShadingPattern{matrix=null;isModifyingCurrentTransform(){return!1}getPattern(){unreachable("Abstract method `getPattern` called.")}}class RadialAxialShadingPattern extends BaseShadingPattern{constructor(t){super();this._type=t[1];this._bbox=t[2];this._colorStops=t[3];this._p0=t[4];this._p1=t[5];this._r0=t[6];this._r1=t[7]}isOriginBased(){return 0===this._p0[0]&&0===this._p0[1]&&(!this.isRadial()||0===this._p1[0]&&0===this._p1[1])}isRadial(){return"radial"===this._type}areConic(){if(!this.isRadial())return!1;const t=Math.hypot(this._p0[0]-this._p1[0],this._p0[1]-this._p1[1]);return t+this._r1>this._r0&&t+this._r0>this._r1}_createGradient(t,e=null){let i,n=this._p0,r=this._p1;if(e){n=n.slice();r=r.slice();Util.applyTransform(n,e);Util.applyTransform(r,e)}if("axial"===this._type)i=t.createLinearGradient(n[0],n[1],r[0],r[1]);else if("radial"===this._type){let s=this._r0,a=this._r1;if(e){const t=new Float32Array(2);Util.singularValueDecompose2dScale(e,t);s*=t[0];a*=t[0]}i=t.createRadialGradient(n[0],n[1],s,r[0],r[1],a)}for(const t of this._colorStops)i.addColorStop(t[0],t[1]);return i}_createReversedGradient(t,e=null){let i=this._p1,n=this._p0;if(e){i=i.slice();n=n.slice();Util.applyTransform(i,e);Util.applyTransform(n,e)}let r=this._r1,s=this._r0;if(e){const t=new Float32Array(2);Util.singularValueDecompose2dScale(e,t);r*=t[0];s*=t[0]}const a=t.createRadialGradient(i[0],i[1],r,n[0],n[1],s),o=this._colorStops.map(([t,e])=>[1-t,e]).reverse();for(const[t,e]of o)a.addColorStop(t,e);return a}_createRasterPattern(t,e,i,n,r,s){const a=Math.ceil(n[2]-n[0])||1,o=Math.ceil(n[3]-n[1])||1,l=e.canvasFactory.create(a,o),c=l.context;c.clearRect(0,0,a,o);c.beginPath();c.rect(0,0,a,o);c.translate(-n[0],-n[1]);i=Util.transform(i,[1,0,0,1,n[0],n[1]]);c.transform(...r);applyBoundingBox(c,this._bbox);if(this.areConic()){c.fillStyle=this._createReversedGradient(c);c.fill()}c.fillStyle=this._createGradient(c);c.fill();s?.applyToCanvas(c);const h=t.createPattern(l.canvas,"no-repeat");e.canvasFactory.destroy(l);h.setTransform(new DOMMatrix(i));return h}getPattern(t,e,i,n){const r=e.current.transferMapsFallback;if(n===Ln||n===Bn){if(this.isOriginBased()&&!r){let n=Util.transform(i,e.baseTransform);this.matrix&&(n=Util.transform(n,this.matrix));const r=.001,s=Math.hypot(n[0],n[1]),a=Math.hypot(n[2],n[3]),o=(n[0]*n[2]+n[1]*n[3])/(s*a);if(Math.abs(o)<r){if(!this.isRadial())return this._createGradient(t,n);if(Math.abs(s-a)<r)return this._createGradient(t,n)}}const s=e.current.getClippedPathBoundingBox(n,getCurrentTransform(t))||[0,0,0,0],a=this.matrix?Util.transform(e.baseTransform,this.matrix):e.baseTransform;return this._createRasterPattern(t,e,i,s,a,r)}if(r&&i)return this._createRasterPattern(t,e,i,e.current.clipBox,getCurrentTransform(t),r);if(this.areConic()){t.save();applyBoundingBox(t,this._bbox);t.fillStyle=this._createReversedGradient(t);t.fillRect(-1e10,-1e10,2e10,2e10);t.restore()}applyBoundingBox(t,this._bbox);return this._createGradient(t)}}function drawTriangle(t,e,i,n,r,s,a,o){const l=e.coords,c=e.colors,h=t.data,d=4*t.width;let u;if(l[2*i+1]>l[2*n+1]){u=i;i=n;n=u;u=s;s=a;a=u}if(l[2*n+1]>l[2*r+1]){u=n;n=r;r=u;u=a;a=o;o=u}if(l[2*i+1]>l[2*n+1]){u=i;i=n;n=u;u=s;s=a;a=u}const p=(l[2*i]+e.offsetX)*e.scaleX,g=(l[2*i+1]+e.offsetY)*e.scaleY,m=(l[2*n]+e.offsetX)*e.scaleX,f=(l[2*n+1]+e.offsetY)*e.scaleY,b=(l[2*r]+e.offsetX)*e.scaleX,y=(l[2*r+1]+e.offsetY)*e.scaleY;if(g>=y)return;const w=c[4*s],v=c[4*s+1],_=c[4*s+2],A=c[4*a],x=c[4*a+1],C=c[4*a+2],E=c[4*o],S=c[4*o+1],T=c[4*o+2],k=Math.round(g),P=Math.round(y);let M,D,I,O,R,B,L,N;for(let t=k;t<=P;t++){if(t<f){const e=t<g?0:(g-t)/(g-f);M=p-(p-m)*e;D=w-(w-A)*e;I=v-(v-x)*e;O=_-(_-C)*e}else{let e;e=t>y?1:f===y?0:(f-t)/(f-y);M=m-(m-b)*e;D=A-(A-E)*e;I=x-(x-S)*e;O=C-(C-T)*e}let e;e=t<g?0:t>y?1:(g-t)/(g-y);R=p-(p-b)*e;B=w-(w-E)*e;L=v-(v-S)*e;N=_-(_-T)*e;const i=Math.round(Math.min(M,R)),n=Math.round(Math.max(M,R));let r=d*t+4*i;for(let t=i;t<=n;t++){e=(M-t)/(M-R);e<0?e=0:e>1&&(e=1);h[r++]=D-(D-B)*e|0;h[r++]=I-(I-L)*e|0;h[r++]=O-(O-N)*e|0;h[r++]=255}}}class MeshShadingPattern extends BaseShadingPattern{constructor(t){super();this._posData=t[2];this._colData=t[3];this._vertexCount=t[4];this._bounds=t[5];this._bbox=t[6];this._background=t[7];!function loadMeshShader(){gn.loadMeshShader()}()}_createMeshCanvas(t,e,i,n=null){const r=Math.floor(this._bounds[0]),s=Math.floor(this._bounds[1]),a=Math.ceil(this._bounds[2])-r,o=Math.ceil(this._bounds[3])-s,l=Math.min(Math.ceil(Math.abs(a*t[0]*1.1)),3e3)||1,c=Math.min(Math.ceil(Math.abs(o*t[1]*1.1)),3e3)||1,h=a?a/l:1,d=o?o/c:1,u={coords:this._posData,colors:this._colData,offsetX:-r,offsetY:-s,scaleX:1/h,scaleY:1/d},p=l+4,g=c+4,m=i.create(p,g);if(isGPUReady()&&this._vertexCount>48)m.context.drawImage(function drawMeshWithGPU(t,e,i,n,r,s,a,o){return gn.draw(t,e,i,n,r,s,a,o)}(this._posData,this._colData,this._vertexCount,u,e,p,g,2),0,0);else{const t=m.context.createImageData(l,c);if(e){const i=t.data;for(let t=0,n=i.length;t<n;t+=4){i[t]=e[0];i[t+1]=e[1];i[t+2]=e[2];i[t+3]=255}}for(let e=0,i=this._vertexCount;e<i;e+=3)drawTriangle(t,u,e,e+1,e+2,e,e+1,e+2);m.context.putImageData(t,2,2)}n?.applyToCanvas(m.context);return{canvas:m.canvas,offsetX:r-2*h,offsetY:s-2*d,scaleX:h,scaleY:d}}isModifyingCurrentTransform(){return!0}getPattern(t,e,i,n){applyBoundingBox(t,this._bbox);const r=new Float32Array(2);if(n===Nn)Util.singularValueDecompose2dScale(getCurrentTransform(t),r);else if(this.matrix){Util.singularValueDecompose2dScale(this.matrix,r);const[t,i]=r;Util.singularValueDecompose2dScale(e.baseTransform,r);r[0]*=t;r[1]*=i}else Util.singularValueDecompose2dScale(e.baseTransform,r);const s=this._createMeshCanvas(r,n===Nn?null:this._background,e.canvasFactory,e.current.transferMapsFallback);if(n!==Nn){t.setTransform(...e.baseTransform);this.matrix&&t.transform(...this.matrix)}t.translate(s.offsetX,s.offsetY);t.scale(s.scaleX,s.scaleY);const a=t.createPattern(s.canvas,"no-repeat");e.canvasFactory.destroy(s);return a}}class DummyShadingPattern extends BaseShadingPattern{getPattern(){return"hotpink"}}const Un=1,Hn=2;class TilingPattern{static MAX_PATTERN_SIZE=3e3;constructor(t,e,i,n){this.color=t[1];this.operatorList=t[2];this.matrix=t[3];this.bbox=t[4];this.xstep=t[5];this.ystep=t[6];this.paintType=t[7];this.tilingType=t[8];this.needsIsolation=t[9]??!0;this.ctx=e;this.canvasGraphicsFactory=i;this.baseTransform=n;this.patternBaseMatrix=this.matrix?Util.transform(n,this.matrix):n}canSkipPatternCanvas([t,e,i,n]){const[r,s,a,o]=this.bbox,l=Math.abs(this.xstep),c=Math.abs(this.ystep);if(t>l+1e-6||e>c+1e-6)return null;const h=Math.floor((i-a)/l)+1,d=Math.ceil((i+t-r)/l)-1,u=Math.floor((n-o)/c)+1,p=Math.ceil((n+e-s)/c)-1;return d<=h&&p<=u?[h,u]:null}updatePatternDims(t,e){const i=pi.slice();Util.axialAlignedBoundingBox(t,Util.inverseTransform(this.patternBaseMatrix),i);e[0]=i[2]-i[0];e[1]=i[3]-i[1];e[2]=i[0];e[3]=i[1]}_renderTileCanvas(t,e,i,n){const[r,s,a,o]=this.bbox,l=t.canvasFactory.create(i.size,n.size),c=l.context,h=this.canvasGraphicsFactory.createCanvasGraphics(c,e);h.groupLevel=t.groupLevel;h.current.transferMapsFallback=t.current.transferMapsFallback;this.setFillAndStrokeStyleToContext(h,this.paintType,this.color);c.translate(-i.scale*r,-n.scale*s);h.transform(0,i.scale,0,0,n.scale,0,0);c.save();h.dependencyTracker?.save();this.clipBbox(h,r,s,a,o);h.baseTransform=getCurrentTransform(h.ctx);h.executeOperatorList(this.operatorList);h.endDrawing();h.dependencyTracker?.restore();c.restore();return l}_getCombinedScales(){const t=new Float32Array(2);Util.singularValueDecompose2dScale(this.matrix,t);const[e,i]=t;Util.singularValueDecompose2dScale(this.baseTransform,t);return[e*t[0],i*t[1]]}drawPattern(t,e,i=!1,[n,r],s){const[a,o,l,c]=this.bbox,h=t.dependencyTracker;h&&(t.dependencyTracker=new CanvasNestedDependencyTracker(h,s));try{t.save();i?t.ctx.clip(e,"evenodd"):t.ctx.clip(e);t.ctx.setTransform(...this.patternBaseMatrix);t.ctx.translate(n*this.xstep,r*this.ystep);if(this.needsIsolation||1!==t.ctx.globalAlpha||"source-over"!==t.ctx.globalCompositeOperation||t.inSMaskMode){const e=l-a,i=c-o,[n,r]=this._getCombinedScales(),h=this.getSizeAndScale(e,this.ctx.canvas.width,n),d=this.getSizeAndScale(i,this.ctx.canvas.height,r),u=this._renderTileCanvas(t,s,h,d);t.ctx.drawImage(u.canvas,a,o,e,i);t.canvasFactory.destroy(u)}else{t.resetGraphicsState();this.setFillAndStrokeStyleToContext(t,this.paintType,this.color);this.clipBbox(t,a,o,l,c);t.baseTransformStack.push(t.baseTransform);t.baseTransform=getCurrentTransform(t.ctx);t.executeOperatorList(this.operatorList);t.baseTransform=t.baseTransformStack.pop()}t.restore()}finally{h&&(t.dependencyTracker=h)}}createPatternCanvas(t,e){const[i,n,r,s]=this.bbox,a=r-i,o=s-n;let{xstep:l,ystep:c}=this;l=Math.abs(l);c=Math.abs(c);info("TilingType: "+this.tilingType);const[h,d]=this._getCombinedScales();let u=a,p=o,g=!1,m=!1;Math.ceil(l*h)>=Math.ceil(a*h)?u=l:g=!0;Math.ceil(c*d)>=Math.ceil(o*d)?p=c:m=!0;const f=this.getSizeAndScale(u,this.ctx.canvas.width,h),b=this.getSizeAndScale(p,this.ctx.canvas.height,d),y=this._renderTileCanvas(t,e,f,b);if(g||m){const e=y.canvas;g&&(u=l);m&&(p=c);const r=this.getSizeAndScale(u,this.ctx.canvas.width,h),s=this.getSizeAndScale(p,this.ctx.canvas.height,d),f=r.size,b=s.size,w=t.canvasFactory.create(f,b),v=w.context,_=g?Math.min(Math.floor(a/l),Math.ceil(e.width/f)):0,A=m?Math.min(Math.floor(o/c),Math.ceil(e.height/b)):0;let x=e,C=null;if(m){C=t.canvasFactory.create(e.width,b);const i=C.context;for(let t=A;t>=0;t--)i.drawImage(e,0,b*t,e.width,b,0,0,e.width,b);x=C.canvas}for(let t=_;t>=0;t--)v.drawImage(x,f*t,0,f,b,0,0,f,b);C&&t.canvasFactory.destroy(C);t.canvasFactory.destroy(y);return{canvas:w.canvas,canvasEntry:w,scaleX:r.scale,scaleY:s.scale,offsetX:i,offsetY:n}}return{canvas:y.canvas,canvasEntry:y,scaleX:f.scale,scaleY:b.scale,offsetX:i,offsetY:n}}getSizeAndScale(t,e,i){const n=Math.max(TilingPattern.MAX_PATTERN_SIZE,e);let r=Math.ceil(t*i);r>=n?r=n:i=r/t;return{scale:i,size:r}}clipBbox(t,e,i,n,r){const s=n-e,a=r-i,o=new Path2D;o.rect(e,i,s,a);Util.axialAlignedBoundingBox([e,i,n,r],getCurrentTransform(t.ctx),t.current.minMax);t.ctx.clip(o);t.current.updateClipFromPath()}setFillAndStrokeStyleToContext(t,e,i){switch(e){case Un:i="#000000";break;case Hn:break;default:throw new FormatError(`Unsupported paint type: ${e}`)}const{ctx:n,current:r}=t;r.patternFill=r.patternStroke=!1;n.fillStyle=n.strokeStyle=r.transferMapsFallback?.applyToColor(i)??i;r.fillColor=r.strokeColor=i}isModifyingCurrentTransform(){return!1}getPattern(t,e,i,n,r){const s=n!==Nn?Util.transform(i,this.patternBaseMatrix):i,a=this.createPatternCanvas(e,r);let o=new DOMMatrix(s);o=o.translate(a.offsetX,a.offsetY);o=o.scale(1/a.scaleX,1/a.scaleY);const l=t.createPattern(a.canvas,"repeat");e.canvasFactory.destroy(a.canvasEntry);l.setTransform(o);return l}}const zn=16,Gn=new Float32Array(2);function mirrorContextOperations(t,e){if(t._removeMirroring)throw new Error("Context is already forwarding operations.");const i=new Map;for(const n of["save","restore","rotate","scale","translate","transform","setTransform","resetTransform","clip","moveTo","lineTo","bezierCurveTo","quadraticCurveTo","arc","arcTo","ellipse","rect","roundRect","closePath","beginPath"]){const r=t[n];if("function"==typeof r&&"function"==typeof e[n]){i.set(n,r);t[n]=function(...t){e[n](...t);return r.apply(this,t)}}}t._removeMirroring=()=>{for(const[e,n]of i)t[e]=n;delete t._removeMirroring}}function drawImageAtIntegerCoords(t,e,i,n,r,s,a,o,l,c){const[h,d,u,p,g,m]=getCurrentTransform(t);if(0===d&&0===u){const f=a*h+g,b=Math.round(f),y=o*p+m,w=Math.round(y),v=(a+l)*h+g,_=Math.abs(Math.round(v)-b)||1,A=(o+c)*p+m,x=Math.abs(Math.round(A)-w)||1;t.setTransform(Math.sign(h),0,0,Math.sign(p),b,w);t.drawImage(e,i,n,r,s,0,0,_,x);t.setTransform(h,d,u,p,g,m);return[_,x]}if(0===h&&0===p){const f=o*u+g,b=Math.round(f),y=a*d+m,w=Math.round(y),v=(o+c)*u+g,_=Math.abs(Math.round(v)-b)||1,A=(a+l)*d+m,x=Math.abs(Math.round(A)-w)||1;t.setTransform(0,Math.sign(d),Math.sign(u),0,b,w);t.drawImage(e,i,n,r,s,0,0,x,_);t.setTransform(h,d,u,p,g,m);return[x,_]}t.drawImage(e,i,n,r,s,a,o,l,c);return[Math.hypot(h,d)*l,Math.hypot(u,p)*c]}class CanvasExtraState{alphaIsShape=!1;fontSize=0;fontSizeScale=1;textMatrix=null;textMatrixScale=1;fontMatrix=mi;leading=0;x=0;y=0;lineX=0;lineY=0;charSpacing=0;wordSpacing=0;textHScale=1;textRenderingMode=Di;textRise=0;fillColor="#000000";strokeColor="#000000";tilingPatternDims=null;patternFill=!1;patternStroke=!1;fillAlpha=1;strokeAlpha=1;lineWidth=1;activeSMask=null;transferMaps="none";transferMapsFallback=null;minMax=gi.slice();constructor(t,e){this.clipBox=new Float32Array([0,0,t,e])}clone(){const t=Object.create(this);t.clipBox=this.clipBox.slice();t.minMax=this.minMax.slice();t.tilingPatternDims=this.tilingPatternDims?.slice();return t}getPathBoundingBox(t=Bn,e=null){const i=this.minMax.slice();if(t===Ln){e||unreachable("Stroke bounding box must include transform.");Util.singularValueDecompose2dScale(e,Gn);const t=Gn[0]*this.lineWidth/2,n=Gn[1]*this.lineWidth/2;i[0]-=t;i[1]-=n;i[2]+=t;i[3]+=n}return i}updateClipFromPath(){const t=Util.intersect(this.clipBox,this.getPathBoundingBox());this.startNewPathAndClipBox(t||[0,0,0,0])}isEmptyClip(){return this.minMax[0]===1/0}startNewPathAndClipBox(t){this.clipBox.set(t,0);this.minMax.set(gi,0)}getClippedPathBoundingBox(t=Bn,e=null){return Util.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function putBinaryImageData(t,e){const{width:i,height:n,kind:r}=e,s=n%zn,a=(n-s)/zn,o=0===s?a:a+1,l=t.createImageData(i,zn);let c=0;const h=e.data,d=l.data;let u;if(r===Li.GRAYSCALE_1BPP)for(u=0;u<o;u++){({srcPos:c}=convertBlackAndWhiteToRGBA({src:h,srcPos:c,dest:d,width:i,height:u<a?zn:s}));t.putImageData(l,0,u*zn)}else if(r===Li.RGBA_32BPP){let e=0,n=i*zn*4;for(u=0;u<a;u++){d.set(h.subarray(c,c+n));c+=n;t.putImageData(l,0,e);e+=zn}if(u<o){n=i*s*4;d.set(h.subarray(c,c+n));t.putImageData(l,0,e)}}else{if(r!==Li.RGB_24BPP)throw new Error(`bad image kind: ${r}`);for(u=0;u<o;u++){({srcPos:c}=convertRGBToRGBA({src:h,srcPos:c,dest:new Uint32Array(d.buffer),width:i,height:u<a?zn:s}));t.putImageData(l,0,u*zn)}}}function putBinaryImageMask(t,e){if(e.bitmap){t.drawImage(e.bitmap,0,0);return}const{width:i,height:n}=e,r=n%zn,s=(n-r)/zn,a=0===r?s:s+1,o=t.createImageData(i,zn);let l=0;const c=e.data,h=o.data;for(let e=0;e<a;e++){({srcPos:l}=convertBlackAndWhiteToRGBA({src:c,srcPos:l,dest:h,width:i,height:e<s?zn:r,nonBlackColor:0}));t.putImageData(o,0,e*zn)}}function copyCtxState(t,e){const i=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(const n of i)void 0!==t[n]&&(e[n]=t[n]);if(void 0!==t.setLineDash){e.setLineDash(t.getLineDash());e.lineDashOffset=t.lineDashOffset}}function setAnnotationCanvasName(t,e){t.setAttribute?.("data-canvas-name",e);t._pdfjsCanvasName=e}function resetCtxToDefault(t){t.strokeStyle=t.fillStyle="#000000";t.fillRule="nonzero";t.globalAlpha=1;t.lineWidth=1;t.lineCap="butt";t.lineJoin="miter";t.miterLimit=10;t.globalCompositeOperation="source-over";t.font="10px sans-serif";if(void 0!==t.setLineDash){t.setLineDash([]);t.lineDashOffset=0}const{filter:e}=t;"none"!==e&&""!==e&&(t.filter="none")}class TransferMapsFallback{#Bn;constructor(t){const[e,i=e,n=e]=t,r=Util.identity0to256Map.slice();this.#Bn=[e||r,i||r,n||r]}applyToColor(t){if("string"!=typeof t||!t.startsWith("#"))return t;const[e,i,n]=getRGBA(t),[r,s,a]=this.#Bn;return Util.makeHexColor(r[e],s[i],a[n])}applyToImageData({data:t}){const[e,i,n]=this.#Bn;for(let r=0,s=t.length;r<s;r+=4){t[r]=e[t[r]];t[r+1]=i[t[r+1]];t[r+2]=n[t[r+2]]}}applyToCanvas(t){const{width:e,height:i}=t.canvas,n=t.getImageData(0,0,e,i);this.applyToImageData(n);t.putImageData(n,0,0)}}function getImageSmoothingEnabled(t,e,i){if(e)return!0;Util.singularValueDecompose2dScale(t,Gn);const n=Math.fround(i*PixelsPerInch.PDF_TO_CSS_UNITS);return Gn[0]<=n&&Gn[1]<=n}const Wn=["butt","round","square"],jn=["miter","round","bevel"],Vn={},qn={};class CanvasGraphics{static#Ln=null;static#Nn=new WeakMap;#Un=0;#Hn=0;#zn=null;#Gn=null;#Wn=null;#jn=null;#Vn=1;#qn;#$n=null;#Xn=[];constructor(t,e,i,n,r,{optionalContentConfig:s,markedContentStack:a=null,pixelRatio:o=OutputScale.pixelRatio},l,c,h,d){this.ctx=t;this.current=new CanvasExtraState(this.ctx.canvas.width,this.ctx.canvas.height);this.stateStack=[];this.pendingClip=null;this.pendingEOFill=!1;this.commonObjs=e;this.objs=i;this.canvasFactory=n;this.filterFactory=r;this.groupStack=[];this.baseTransform=null;this.baseTransformStack=[];this.groupLevel=0;this.smaskStack=[];this.tempSMask=null;this.smaskGroupCanvases=[];this.smaskPreparedEntry=null;this.smaskPreparedFor=null;this.smaskPreparedOffsetX=0;this.smaskPreparedOffsetY=0;this.smaskPreparedOOBAlpha=null;this.suspendedCtx=null;this.contentVisible=!0;this.markedContentStack=a||[];this.optionalContentConfig=s;this.pixelRatio=o;this.cachedPatterns=new Map;this.annotationCanvasMap=l;this.viewportScale=1;this.outputScaleX=1;this.outputScaleY=1;this.pageColors=c;this._cachedScaleForStroking=[-1,0];this._cachedBitmapsMap=new Map;this.dependencyTracker=h??null;this.imagesTracker=d??null}getObject(t,e,i=null){if("string"==typeof e){this.dependencyTracker?.recordNamedDependency(t,e);return e.startsWith("g_")?this.commonObjs.get(e):this.objs.get(e)}return i}beginDrawing({transform:t,viewport:e,transparency:i=!1,background:n=null}){const r=this.ctx.canvas.width,s=this.ctx.canvas.height,a=this.ctx.fillStyle;this.ctx.fillStyle=n||"#ffffff";this.ctx.fillRect(0,0,r,s);this.ctx.fillStyle=a;if(i){const t=this.transparentCanvasEntry=this.canvasFactory.create(r,s);this.compositeCtx=this.ctx;({canvas:this.transparentCanvas,context:this.ctx}=t);this.ctx.save();this.ctx.transform(...getCurrentTransform(this.compositeCtx))}this.ctx.save();resetCtxToDefault(this.ctx);if(t){this.ctx.transform(...t);this.outputScaleX=t[0];this.outputScaleY=t[3]}this.ctx.transform(...e.transform);this.viewportScale=e.scale;this.baseTransform=getCurrentTransform(this.ctx)}executeOperatorList(t,e,i,n,r,s){const a=t.argsArray,o=t.fnArray,l=this._pathCache;this._pathCache=t.pathCache??CanvasGraphics.#Nn.getOrInsertComputed(t,makeMap);try{let l=e||0;const c=a.length;if(c===l)return l;const h=c-l>10&&"function"==typeof i,d=h?Date.now()+15:0;let u=0;const p=this.commonObjs,g=this.objs;let m,f;for(;;){if(void 0!==r){if(l===r.nextBreakPoint){r.breakIt(l,i);return l}if(r.shouldSkip(l)){if(++l===c)return l;continue}}if(!s||s(l,t)){m=o[l];f=a[l]??null;if(m!==Vi.dependency)null===f?this[m](l):this[m](l,...f);else for(const t of f){this.dependencyTracker?.recordNamedData(t,l);const e=t.startsWith("g_")?p:g;if(!e.has(t)){e.get(t,i,n);return l}}}l++;if(l===c)return l;if(h&&++u>10){if(Date.now()>d){i();return l}u=0}}}finally{this._pathCache=l}}#Kn(){for(;this.stateStack.length||this.inSMaskMode;)this.restore();this.current.activeSMask=null;this.ctx.restore();if(this.transparentCanvas){this.ctx=this.compositeCtx;this.ctx.save();this.ctx.setTransform(1,0,0,1,0,0);this.ctx.drawImage(this.transparentCanvas,0,0);this.ctx.restore();this.canvasFactory.destroy(this.transparentCanvasEntry);this.transparentCanvas=null;this.transparentCanvasEntry=null}}endDrawing(){this.#Kn();for(const t of this.smaskGroupCanvases)this.canvasFactory.destroy(t);this.smaskGroupCanvases.length=0;this._clearPreparedSMask();this.tempSMask=null;this.smaskStack.length=0;for(const t of this.#Xn)this.#Yn(t);this.#Xn.length=0;this.#zn=null;this.#Gn=null;this.#Wn=null;this.#jn=null;this.#Vn=1;this.#$n=null;this.#Hn=0;this.#Un=0;this.cachedPatterns.clear();for(const t of this._cachedBitmapsMap.values()){for(const e of t.values())"undefined"!=typeof HTMLCanvasElement&&e instanceof HTMLCanvasElement&&(e.width=e.height=0);t.clear()}this._cachedBitmapsMap.clear();this.#Jn()}#Jn(){if(this.pageColors){const t=this.filterFactory.addHCMFilter(this.pageColors.foreground,this.pageColors.background);if("none"!==t){const e=this.ctx.filter;this.ctx.filter=t;this.ctx.drawImage(this.ctx.canvas,0,0);this.ctx.filter=e}}}_scaleImage(t,e){const i=t.width??t.displayWidth,n=t.height??t.displayHeight,r=[];let s=Math.max(Math.hypot(e[0],e[1]),1),a=Math.max(Math.hypot(e[2],e[3]),1),o=i,l=n;for(;s>2&&o>1||a>2&&l>1;){let t=o,e=l;if(s>2&&o>1){t=Math.ceil(o/2);s/=o/t}if(a>2&&l>1){e=Math.ceil(l/2);a/=l/e}r.push({newWidth:t,newHeight:e});o=t;l=e}if(0===r.length)return{img:t,paintWidth:i,paintHeight:n,tmpCanvas:null};if(1===r.length){const{newWidth:e,newHeight:s}=r[0],a=this.canvasFactory.create(e,s);a.context.drawImage(t,0,0,i,n,0,0,e,s);return{img:a.canvas,paintWidth:e,paintHeight:s,tmpCanvas:a}}let c=this.canvasFactory.create(1,1),h=this.canvasFactory.create(1,1),d=i,u=n,p=t;for(const{newWidth:t,newHeight:e}of r){this.canvasFactory.reset(h,t,e);h.context.drawImage(p,0,0,d,u,0,0,t,e);[c,h]=[h,c];p=c.canvas;d=t;u=e}this.canvasFactory.destroy(h);return{img:c.canvas,paintWidth:d,paintHeight:u,tmpCanvas:c}}_createMaskCanvas(t,e){const i=this.ctx,{width:n,height:r}=e,s=this.current.patternFill,a=s?this.current.fillColor:i.fillStyle,o=getCurrentTransform(i);let l,c,h,d;if((e.bitmap||e.data)&&e.count>1){const i=e.bitmap||e.data.buffer;c=JSON.stringify(s?o:[o.slice(0,4),a]);l=this._cachedBitmapsMap.getOrInsertComputed(i,makeMap);const n=l.get(c);if(n&&!s){const e=Math.round(Math.min(o[0],o[2])+o[4]),i=Math.round(Math.min(o[1],o[3])+o[5]);this.dependencyTracker?.recordDependencies(t,Rn);return{canvas:n,offsetX:e,offsetY:i}}h=n}if(!h){d=this.canvasFactory.create(n,r);putBinaryImageMask(d.context,e)}let u=Util.transform(o,[1/n,0,0,-1/r,0,0]);u=Util.transform(u,[1,0,0,1,0,-r]);const p=gi.slice();Util.axialAlignedBoundingBox([0,0,n,r],u,p);const[g,m,f,b]=p,y=Math.round(f-g)||1,w=Math.round(b-m)||1,v=this.canvasFactory.create(y,w),_=v.context,A=g,x=m;_.translate(-A,-x);_.transform(...u);let C=null;if(!h){const t=this._scaleImage(d.canvas,getCurrentTransformInverse(_));h=t.img;C=t.tmpCanvas;if(h!==d.canvas){this.canvasFactory.destroy(d);d=null}if(l&&s){l.set(c,h);C=null;d=null}}_.imageSmoothingEnabled=getImageSmoothingEnabled(getCurrentTransform(_),e.interpolate,this.pixelRatio);drawImageAtIntegerCoords(_,h,0,0,h.width,h.height,0,0,n,r);C&&this.canvasFactory.destroy(C);d&&this.canvasFactory.destroy(d);_.globalCompositeOperation="source-in";const E=Util.transform(getCurrentTransformInverse(_),[1,0,0,1,-A,-x]);_.fillStyle=s?a.getPattern(i,this,E,Bn,t):a;_.fillRect(0,0,n,r);l&&!s&&l.set(c,v.canvas);this.dependencyTracker?.recordDependencies(t,Rn);return{canvas:v.canvas,canvasEntry:l&&!s?null:v,offsetX:Math.round(A),offsetY:Math.round(x)}}setLineWidth(t,e){this.dependencyTracker?.recordSimpleData("lineWidth",t);e!==this.current.lineWidth&&(this._cachedScaleForStroking[0]=-1);this.current.lineWidth=e;this.ctx.lineWidth=e}setLineCap(t,e){this.dependencyTracker?.recordSimpleData("lineCap",t);this.ctx.lineCap=Wn[e]}setLineJoin(t,e){this.dependencyTracker?.recordSimpleData("lineJoin",t);this.ctx.lineJoin=jn[e]}setMiterLimit(t,e){this.dependencyTracker?.recordSimpleData("miterLimit",t);this.ctx.miterLimit=e}setDash(t,e,i){this.dependencyTracker?.recordSimpleData("dash",t);const n=this.ctx;if(void 0!==n.setLineDash){n.setLineDash(e);n.lineDashOffset=i}}setRenderingIntent(t,e){}setFlatness(t,e){}setGState(t,e){for(const[i,n]of e)switch(i){case"LW":this.setLineWidth(t,n);break;case"LC":this.setLineCap(t,n);break;case"LJ":this.setLineJoin(t,n);break;case"ML":this.setMiterLimit(t,n);break;case"D":this.setDash(t,n[0],n[1]);break;case"RI":this.setRenderingIntent(t,n);break;case"FL":this.setFlatness(t,n);break;case"Font":this.setFont(t,n[0],n[1]);break;case"CA":this.dependencyTracker?.recordSimpleData("strokeAlpha",t);this.current.strokeAlpha=n;break;case"ca":this.dependencyTracker?.recordSimpleData("fillAlpha",t);this.ctx.globalAlpha=this.current.fillAlpha=n;break;case"BM":this.dependencyTracker?.recordSimpleData("globalCompositeOperation",t);this.ctx.globalCompositeOperation=n;break;case"SMask":this.dependencyTracker?.recordSimpleData("SMask",t);this.current.activeSMask=n?this.tempSMask:null;this.current.activeSMask&&(this.current.activeSMask.blendMode=this.ctx.globalCompositeOperation);this.tempSMask=null;this.checkSMaskState(t);break;case"TR":{this.dependencyTracker?.recordSimpleData("filter",t);let e=this.filterFactory.addFilter(n);this.ctx.filter=e;let i=null;if(n&&("none"===e||!FeatureTest.isCanvasFilterSupported||"none"===this.ctx.filter||""===this.ctx.filter)){this.ctx.filter=e="none";i=new TransferMapsFallback(n)}this.current.transferMaps=e;if(i||this.current.transferMapsFallback){this.current.transferMapsFallback=i;this.current.patternFill||(this.ctx.fillStyle=this.#Qn(this.current.fillColor));this.current.patternStroke||(this.ctx.strokeStyle=this.#Qn(this.current.strokeColor))}break}}}get inSMaskMode(){return!!this.suspendedCtx}_clearPreparedSMask(){if(this.smaskPreparedEntry){this.canvasFactory.destroy(this.smaskPreparedEntry);this.smaskPreparedEntry=null}this.smaskPreparedFor=null;this.smaskPreparedOffsetX=0;this.smaskPreparedOffsetY=0;this.smaskPreparedOOBAlpha=null}_ensurePreparedSMask(t){if(t!==this.smaskPreparedFor){this._clearPreparedSMask();this._prepareSMaskCanvas(t)}}checkSMaskState(t){const e=this.inSMaskMode;this.current.activeSMask&&!e?this.beginSMaskMode(t):!this.current.activeSMask&&e?this.endSMaskMode():this.current.activeSMask&&e&&this._ensurePreparedSMask(this.current.activeSMask)}_prepareSMaskCanvas(t){const{canvas:e,subtype:i,backdrop:n,transferMap:r}=t,s="Luminosity"===i||"Alpha"===i&&r;if(!(s||"Luminosity"===i&&n)){this.smaskPreparedFor=t;return}let a;if("Luminosity"===i&&n){const[t,e,i]=getRGBA(n),s=Math.round(.3*t+.59*e+.11*i);a=r?.[s]??s}else a=r?.[0]??0;const{width:o,height:l}=this.ctx.canvas,c=o*l<4*(e.width*e.height),h=s?{url:"Alpha"===i?this.filterFactory.addAlphaFilter(r):this.filterFactory.addLuminosityFilter(r),subtype:i,transferMap:r}:null,d="Luminosity"===i?n:null;let u,p,g;if(c){u=this._bakeSMaskCanvas(e,t.offsetX,t.offsetY,o,l,d,h);p=0;g=0}else{u=this._bakeSMaskCanvas(e,0,0,e.width,e.height,d,h);p=t.offsetX;g=t.offsetY}this.smaskPreparedEntry=u;this.smaskPreparedFor=t;this.smaskPreparedOffsetX=p;this.smaskPreparedOffsetY=g;this.smaskPreparedOOBAlpha=c||0===a?null:a}_bakeSMaskCanvas(t,e,i,n,r,s,a){s||a||unreachable("_bakeSMaskCanvas with neither backdrop nor filter");const o=this.canvasFactory.create(n,r),l=o.context;l.drawImage(t,e,i);if(s){l.globalCompositeOperation="destination-atop";l.fillStyle=s;l.fillRect(0,0,n,r)}if(!a)return o;const c=this.canvasFactory.create(n,r),h=c.context;h.filter=a.url;const d=FeatureTest.isCanvasFilterSupported&&"none"!==h.filter&&""!==h.filter;h.drawImage(o.canvas,0,0);FeatureTest.isCanvasFilterSupported&&(h.filter="none");if(!d){const t=h.getImageData(0,0,n,r),{data:e}=t,{transferMap:i}=a;if("Luminosity"===a.subtype)for(let t=0,n=e.length;t<n;t+=4){const n=.3*e[t]+.59*e[t+1]+.11*e[t+2]+.5|0;e[t]=e[t+1]=e[t+2]=0;e[t+3]=i?.[n]??n}else for(let t=3,n=e.length;t<n;t+=4)e[t]=i[e[t]];h.putImageData(t,0,0)}this.canvasFactory.destroy(o);return c}beginSMaskMode(t){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const{width:e,height:i}=this.ctx.canvas,n=this.canvasFactory.create(e,i);this.smaskScratchCanvas=n;this.suspendedCtx=this.ctx;const r=this.ctx=n.context;r.setTransform(this.suspendedCtx.getTransform());copyCtxState(this.suspendedCtx,r);mirrorContextOperations(r,this.suspendedCtx);this._ensurePreparedSMask(this.current.activeSMask);this.setGState(t,[["BM","source-over"]])}endSMaskMode(){if(!this.inSMaskMode)throw new Error("endSMaskMode called while not in smask mode");this.ctx._removeMirroring();copyCtxState(this.ctx,this.suspendedCtx);this.ctx=this.suspendedCtx;this.suspendedCtx=null;this.canvasFactory.destroy(this.smaskScratchCanvas);this.smaskScratchCanvas=null;this._clearPreparedSMask()}#Zn(t,e=null,i=1){const{width:n,height:r}=t,s=e??this.canvasFactory.create(n,r),a=s.context,o=(i=Math.round(255*i)/255)<1;o&&void 0===this.#qn&&(this.#qn=FeatureTest.isCanvasFilterSupported?new Map:"none");let l="none";o&&this.#qn instanceof Map&&(l=this.#qn.getOrInsertComputed(i,()=>this.filterFactory.addKnockoutFilter(i)));if(!o||"none"!==l){if(e){a.save();a.setTransform(1,0,0,1,0,0);a.clearRect(0,0,n,r);a.restore()}a.filter=l;a.drawImage(t,0,0);a.filter="none";return s}const c=t.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,n,r),h=a.createImageData(n,r),d=c.data,u=h.data,p=i>0?1/i:1e6;for(let t=3,e=d.length;t<e;t+=4)u[t]=Math.min(Math.round(d[t]*p),255);a.putImageData(h,0,0);return s}#tr(t,e,i,n){let r=t?.[e]??null;if(r&&(r.canvas.width!==i||r.canvas.height!==n)){this.canvasFactory.destroy(r);r=null}if(!r){r=this.canvasFactory.create(i,n);t&&(t[e]=r);return r}const s=r.context;s.save();s.setTransform(1,0,0,1,0,0);s.clearRect(0,0,i,n);s.restore();return r}#er(t,e,i={}){const{backdropCanvas:n=null,destTransform:r=[1,0,0,1,0,0],backdropOffset:s=[0,0],reuseMaskEntry:a=null,poolMeta:o=null,sourceAlpha:l=1,sourceFilter:c="none",knockoutAlpha:h=1}=i,{width:d,height:u}=e,p=this.#Zn(e,a,h),g=t.globalCompositeOperation;t.save();t.setTransform(...r);t.globalAlpha=1;FeatureTest.isCanvasFilterSupported&&(t.filter="none");t.globalCompositeOperation="destination-out";t.drawImage(p.canvas,0,0);if(n){const[e,i]=s,r=this.#tr(o,"knockoutBackdropEntry",d,u),a=r.context;a.drawImage(n,e,i,d,u,0,0,d,u);a.globalCompositeOperation="destination-in";a.drawImage(p.canvas,0,0);a.globalCompositeOperation="source-over";t.globalCompositeOperation="destination-over";t.drawImage(r.canvas,0,0);o||this.canvasFactory.destroy(r)}t.globalCompositeOperation=g;t.globalAlpha=l;FeatureTest.isCanvasFilterSupported&&(t.filter=c??"none");t.drawImage(e,0,0);t.restore();a||this.canvasFactory.destroy(p)}#ir(t=1){if(0===this.#Un||this.#Hn>0||!this.contentVisible)return!1;this.#Hn++;this.#Vn=t;const e=this.#Xn.at(-1),{canvas:i}=this.ctx,n=this.#tr(e,"knockoutTempEntry",i.width,i.height);this.#zn=n;const r=n.context;r.save();r.setTransform(this.ctx.getTransform());copyCtxState(this.ctx,r);this.#jn=r.globalCompositeOperation;r.globalCompositeOperation="source-over";mirrorContextOperations(r,this.ctx);this.#$n=e;this.#Gn=this.ctx;this.#Wn=this.suspendedCtx;this.ctx=r;this.inSMaskMode&&(this.suspendedCtx=r);return!0}#nr(t){if(!t)return;const e=this.#zn,i=this.#Gn,n=this.#Wn,r=e.context;this.#zn=null;this.#Gn=null;this.#Wn=null;this.inSMaskMode&&this.suspendedCtx===r&&this.ctx!==r&&this.endSMaskMode();this.inSMaskMode&&(this.suspendedCtx=n);this.ctx._removeMirroring();this.ctx.globalCompositeOperation=this.#jn;this.#jn=null;copyCtxState(this.ctx,i);this.ctx=i;const s=this.#$n;this.#$n=null;const a=this.#Vn;this.#Vn=1;try{this.#er(n??i,e.canvas,{backdropCanvas:s?.backdropCtx?.canvas??null,backdropOffset:s?.backdropCtx?[s.offsetX,s.offsetY]:[0,0],reuseMaskEntry:s?.knockoutMaskEntry??null,poolMeta:s,knockoutAlpha:a})}finally{r.restore();this.#Hn--;s||this.canvasFactory.destroy(e)}}compose(t){if(!this.current.activeSMask)return;t=t?[Math.floor(t[0]),Math.floor(t[1]),Math.ceil(t[2]),Math.ceil(t[3])]:[0,0,this.ctx.canvas.width,this.ctx.canvas.height];const e=this.current.activeSMask,i=this.suspendedCtx,n=this.#Hn>0&&i===this.ctx;this.composeSMask(n?null:i,e,this.ctx,t);if(!n){this.ctx.save();this.ctx.setTransform(1,0,0,1,0,0);this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height);this.ctx.restore()}}composeSMask(t,e,i,n){const r=n[0],s=n[1],a=n[2]-r,o=n[3]-s;if(0===a||0===o)return;const l=this.smaskPreparedEntry;if(l){let t=r,n=s,c=a,h=o;const d=this.smaskPreparedOOBAlpha,u=null!==d;if(u){t=Math.max(r,e.offsetX);n=Math.max(s,e.offsetY);c=Math.min(r+a,e.offsetX+e.canvas.width)-t;h=Math.min(s+o,e.offsetY+e.canvas.height)-n}if(c>0&&h>0){const e=t-this.smaskPreparedOffsetX,r=n-this.smaskPreparedOffsetY;i.save();i.globalAlpha=1;i.setTransform(1,0,0,1,0,0);const s=new Path2D;s.rect(t,n,c,h);i.clip(s);i.globalCompositeOperation="destination-in";i.drawImage(l.canvas,e,r,c,h,t,n,c,h);i.restore()}u&&d<255&&this._applySMaskOOBAlpha(i,r,s,a,o,t,n,t+c,n+h,d)}else this.genericComposeSMask(e,i,a,o,r,s);if(t){t.save();t.globalAlpha=1;t.globalCompositeOperation=e.blendMode||"source-over";t.setTransform(1,0,0,1,0,0);t.drawImage(i.canvas,r,s,a,o,r,s,a,o);t.restore()}}_applySMaskOOBAlpha(t,e,i,n,r,s,a,o,l,c){const h=s<o&&a<l;if(h&&s===e&&a===i&&o===e+n&&l===i+r)return;const d=new Path2D;d.rect(e,i,n,r);h&&d.rect(s,a,o-s,l-a);t.save();t.globalAlpha=c/255;t.setTransform(1,0,0,1,0,0);t.clip(d,"evenodd");t.globalCompositeOperation="destination-in";t.fillStyle="#000000";t.fillRect(e,i,n,r);t.restore()}genericComposeSMask(t,e,i,n,r,s){const{context:a,offsetX:o,offsetY:l}=t;e.save();e.globalAlpha=1;e.setTransform(1,0,0,1,0,0);const c=new Path2D;c.rect(r,s,i,n);e.clip(c);e.globalCompositeOperation="destination-in";e.drawImage(a.canvas,r-o,s-l,i,n,r,s,i,n);e.restore()}save(t){this.inSMaskMode&&copyCtxState(this.ctx,this.suspendedCtx);this.ctx.save();const e=this.current;this.stateStack.push(e);this.current=e.clone();this.dependencyTracker?.save(t)}restore(t){this.dependencyTracker?.restore(t);if(0!==this.stateStack.length){this.current=this.stateStack.pop();this.ctx.restore();if(this.inSMaskMode){copyCtxState(this.suspendedCtx,this.ctx);this.ctx.setTransform(this.suspendedCtx.getTransform())}this.checkSMaskState(t);this.pendingClip=null;this._cachedScaleForStroking[0]=-1}else this.inSMaskMode&&this.endSMaskMode()}resetGraphicsState(){const{clipBox:t,transferMaps:e,transferMapsFallback:i}=this.current,n=this.current=new CanvasExtraState(0,0);n.clipBox=t;n.transferMaps=e;n.transferMapsFallback=i;const r=this.ctx;r.lineWidth=1;r.lineCap="butt";r.lineJoin="miter";r.miterLimit=10;if(void 0!==r.setLineDash){r.setLineDash([]);r.lineDashOffset=0}this._cachedScaleForStroking[0]=-1}transform(t,e,i,n,r,s,a){this.dependencyTracker?.recordIncrementalData("transform",t);this.ctx.transform(e,i,n,r,s,a);this._cachedScaleForStroking[0]=-1}constructPath(t,e,i,n){let r=this._pathCache.get(t);if(!n){if(!r){r=new Path2D;this._pathCache.set(t,r)}e!==Vi.stroke&&e!==Vi.closeStroke&&(this.current.tilingPatternDims=null);this[e](t,r);return}if(null!==this.dependencyTracker){const i=e===Vi.stroke?this.current.lineWidth/2:0;this.dependencyTracker.resetBBox(t).recordBBox(t,this.ctx,n[0]-i,n[2]+i,n[1]-i,n[3]+i).recordDependencies(t,["transform"])}if(!r){r=makePathFromDrawOPS(i[0]);this._pathCache.set(t,r)}Util.axialAlignedBoundingBox(n,getCurrentTransform(this.ctx),this.current.minMax);const s=this.current.tilingPatternDims;if(s&&e!==Vi.stroke&&e!==Vi.closeStroke&&this.current.fillColor instanceof TilingPattern){const t=Util.intersect(this.current.clipBox,this.current.minMax);t?this.current.fillColor.updatePatternDims(t,s):this.current.tilingPatternDims=null}this[e](t,r);this._pathStartIdx=t}closePath(t){this.ctx.closePath()}stroke(t,e,i=!0){const n=i&&this.#ir(this.current.strokeAlpha),r=this.ctx,s=this.current.strokeColor;r.globalAlpha=this.current.strokeAlpha;if(this.contentVisible)if("object"==typeof s&&s?.getPattern){const i=s.isModifyingCurrentTransform()?r.getTransform():null;r.save();r.strokeStyle=s.getPattern(r,this,getCurrentTransformInverse(r),Ln,t);if(i){const t=new Path2D;t.addPath(e,r.getTransform().invertSelf().multiplySelf(i));e=t}this.rescaleAndStroke(e,!1);r.restore()}else this.rescaleAndStroke(e,!0);this.dependencyTracker?.recordDependencies(t,Pn);i&&this.consumePath(t,e,this.current.getClippedPathBoundingBox(Ln,getCurrentTransform(this.ctx)));r.globalAlpha=this.current.fillAlpha;this.#nr(n)}closeStroke(t,e){this.stroke(t,e)}fill(t,e,i=!0){const n=i&&this.#ir(this.current.fillAlpha),r=this.ctx,s=this.current.fillColor,a=this.current.patternFill;let o=!1;const l=this.current.getClippedPathBoundingBox();this.dependencyTracker?.recordDependencies(t,Mn);if(a){const a=this.current.tilingPatternDims,c=a&&s.canSkipPatternCanvas(a);if(c){const{pendingClip:r,pendingEOFill:a}=this;this.pendingClip=null;this.pendingEOFill=!1;s.drawPattern(this,e,a,c,t);this.pendingClip=r;i&&this.consumePath(t,e,l);this.current.tilingPatternDims=null;this.#nr(n);return}const h=s.isModifyingCurrentTransform()?r.getTransform():null;this.dependencyTracker?.save(t);r.save();r.fillStyle=s.getPattern(r,this,getCurrentTransformInverse(r),Bn,t);if(h){const t=new Path2D;t.addPath(e,r.getTransform().invertSelf().multiplySelf(h));e=t}o=!0}if(this.contentVisible&&null!==l)if(this.pendingEOFill){r.fill(e,"evenodd");this.pendingEOFill=!1}else r.fill(e);if(o){r.restore();this.dependencyTracker?.restore(t)}i&&this.consumePath(t,e,l);this.#nr(n)}eoFill(t,e){this.pendingEOFill=!0;this.fill(t,e)}fillStroke(t,e){const i=this.#ir(Math.min(this.current.fillAlpha,this.current.strokeAlpha));this.fill(t,e,!1);this.stroke(t,e,!1);this.consumePath(t,e);this.#nr(i)}eoFillStroke(t,e){this.pendingEOFill=!0;this.fillStroke(t,e)}closeFillStroke(t,e){this.fillStroke(t,e)}closeEOFillStroke(t,e){this.pendingEOFill=!0;this.fillStroke(t,e)}endPath(t,e){this.consumePath(t,e)}rawFillPath(t,e){const i=this.#ir(this.current.fillAlpha);this.ctx.fill(e);this.dependencyTracker?.recordDependencies(t,In).recordOperation(t);this.#nr(i)}clip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t);this.pendingClip=Vn}eoClip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t);this.pendingClip=qn}beginText(t){this.current.textMatrix=null;this.current.textMatrixScale=1;this.current.x=this.current.lineX=0;this.current.y=this.current.lineY=0;this.dependencyTracker?.recordOpenMarker(t).resetIncrementalData("sameLineText").resetIncrementalData("moveText",t)}endText(t){const e=this.pendingTextPaths,i=this.ctx;if(this.dependencyTracker){const{dependencyTracker:i}=this;void 0!==e&&i.recordFutureForcedDependency("textClip",i.getOpenMarker()).recordFutureForcedDependency("textClip",t);i.recordCloseMarker(t)}if(void 0!==e){const t=new Path2D,n=i.getTransform().invertSelf();for(const{transform:i,x:r,y:s,fontSize:a,path:o}of e)o&&t.addPath(o,new DOMMatrix(i).preMultiplySelf(n).translate(r,s).scale(a,-a));i.clip(t)}delete this.pendingTextPaths}setCharSpacing(t,e){this.dependencyTracker?.recordSimpleData("charSpacing",t);this.current.charSpacing=e}setWordSpacing(t,e){this.dependencyTracker?.recordSimpleData("wordSpacing",t);this.current.wordSpacing=e}setHScale(t,e){this.dependencyTracker?.recordSimpleData("hScale",t);this.current.textHScale=e/100}setLeading(t,e){this.dependencyTracker?.recordSimpleData("leading",t);this.current.leading=-e}setFont(t,e,i){this.dependencyTracker?.recordSimpleData("font",t).recordSimpleDataFromNamed("fontObj",e,t);const n=this.commonObjs.get(e),r=this.current;if(!n)throw new Error(`Can't find font for ${e}`);r.fontMatrix=n.fontMatrix||mi;0!==r.fontMatrix[0]&&0!==r.fontMatrix[3]||warn("Invalid font matrix for font "+e);if(i<0){i=-i;r.fontDirection=-1}else r.fontDirection=1;this.current.font=n;this.current.fontSize=i;if(n.isType3Font)return;const s=n.loadedName||"sans-serif",a=n.systemFontInfo?.css||`"${s}", ${n.fallbackName}`;let o="normal";n.black?o="900":n.bold&&(o="bold");const l=n.italic?"italic":"normal",c=MathClamp(i,16,100);this.current.fontSizeScale=i/c;this.ctx.font=`${l} ${o} ${c}px ${a}`}setTextRenderingMode(t,e){this.dependencyTracker?.recordSimpleData("textRenderingMode",t);this.current.textRenderingMode=e}setTextRise(t,e){this.dependencyTracker?.recordSimpleData("textRise",t);this.current.textRise=e}moveText(t,e,i){this.dependencyTracker?.resetIncrementalData("sameLineText").recordIncrementalData("moveText",t);this.current.x=this.current.lineX+=e;this.current.y=this.current.lineY+=i}setLeadingMoveText(t,e,i){this.setLeading(t,-i);this.moveText(t,e,i)}setTextMatrix(t,e){this.dependencyTracker?.resetIncrementalData("sameLineText").recordSimpleData("textMatrix",t);const{current:i}=this;i.textMatrix=e;i.textMatrixScale=Math.hypot(e[0],e[1]);i.x=i.lineX=0;i.y=i.lineY=0}nextLine(t){this.moveText(t,0,this.current.leading);this.dependencyTracker?.recordIncrementalData("moveText",this.dependencyTracker.getSimpleIndex("leading")??t)}#rr(t,e,i){const n=new Path2D;n.addPath(t,new DOMMatrix(i).invertSelf().multiplySelf(e));return n}paintChar(t,e,i,n,r,s){const a=this.ctx,o=this.current,l=o.font,c=o.textRenderingMode,h=o.fontSize/o.fontSizeScale,d=c&Ri,u=!!(c&Bi),p=o.patternFill&&!l.missingFile,g=o.patternStroke&&!l.missingFile;let m;(l.disableFontFace||u||p||g)&&!l.missingFile&&(m=l.getPathGenerator(this.commonObjs,e));if(m&&(l.disableFontFace||p||g)){a.save();a.translate(i,n);a.scale(h,-h);this.dependencyTracker?.recordCharacterBBox(t,a,l);let e;if(d===Di||d===Fi)if(r){e=a.getTransform();a.setTransform(...r);const t=this.#rr(m,e,r);a.fill(t)}else a.fill(m);if(d===Ii||d===Fi)if(s){e||=a.getTransform();a.setTransform(...s);const{a:t,b:i,c:n,d:r}=e,o=Util.inverseTransform(s),l=Util.transform([t,i,n,r,0,0],o);Util.singularValueDecompose2dScale(l,Gn);a.lineWidth*=Math.max(Gn[0],Gn[1])/h;a.stroke(this.#rr(m,e,s))}else{a.lineWidth/=h;a.stroke(m)}a.restore()}else{if(d===Di||d===Fi){a.fillText(e,i,n);this.dependencyTracker?.recordCharacterBBox(t,a,l,h,i,n,()=>a.measureText(e))}if(d===Ii||d===Fi){this.dependencyTracker&&this.dependencyTracker?.recordCharacterBBox(t,a,l,h,i,n,()=>a.measureText(e)).recordDependencies(t,Pn);a.strokeText(e,i,n)}}if(u){(this.pendingTextPaths||=[]).push({transform:getCurrentTransform(a),x:i,y:n,fontSize:h,path:m});this.dependencyTracker?.recordCharacterBBox(t,a,l,h,i,n)}}get isFontSubpixelAAEnabled(){const t=this.canvasFactory.create(10,10),e=t.context;e.scale(1.5,1);e.fillText("I",0,10);const i=e.getImageData(0,0,10,10).data;this.canvasFactory.destroy(t);let n=!1;for(let t=3;t<i.length;t+=4)if(i[t]>0&&i[t]<255){n=!0;break}return util_shadow(this,"isFontSubpixelAAEnabled",n)}#sr(t,e,i){const n=this.ctx;n.save();const r=t.getPattern(n,this,getCurrentTransformInverse(n),e,i),s=getCurrentTransform(n);n.restore();return[r,s]}showText(t,e){if(this.dependencyTracker){this.dependencyTracker.recordDependencies(t,Fn).resetBBox(t);this.current.textRenderingMode&Bi&&this.dependencyTracker.recordFutureForcedDependency("textClip",t).inheritPendingDependenciesAsFutureForcedDependencies()}const i=this.current,n=i.font;if(n.isType3Font){const n=this.#ir(i.fillAlpha);this.showType3Text(t,e);this.dependencyTracker?.recordShowTextOperation(t);this.#nr(n);return}const r=i.fontSize;if(0===r){this.dependencyTracker?.recordOperation(t);return}const s=this.#ir(i.fillAlpha),a=this.ctx,o=i.fontSizeScale,l=i.charSpacing,c=i.wordSpacing,h=i.fontDirection,d=i.textHScale*h,u=e.length,p=n.vertical,g=p?1:-1,m=r*i.fontMatrix[0],f=i.textRenderingMode===Di&&!n.disableFontFace&&!i.patternFill;a.save();i.textMatrix&&a.transform(...i.textMatrix);a.translate(i.x,i.y+i.textRise);h>0?a.scale(d,-1):a.scale(d,1);let b,y;const w=i.textRenderingMode&Ri,v=w===Di||w===Fi,_=w===Ii||w===Fi;let A=i.lineWidth;const x=i.textMatrixScale;0===x||0===A?_&&(A=this.getSinglePixelWidth()):A/=x;if(1!==o){a.scale(o,o);A/=o}a.lineWidth=A;v&&i.patternFill&&([a.fillStyle,b]=this.#sr(i.fillColor,Bn,t));_&&i.patternStroke&&([a.strokeStyle,y]=this.#sr(i.strokeColor,Ln,t));if(n.isInvalidPDFjsFont){const n=[];let r=0;for(const t of e){n.push(t.unicode);r+=t.width}const o=n.join("");a.fillText(o,0,0);if(null!==this.dependencyTracker){const e=a.measureText(o);this.dependencyTracker.recordBBox(t,this.ctx,-e.actualBoundingBoxLeft,e.actualBoundingBoxRight,-e.actualBoundingBoxAscent,e.actualBoundingBoxDescent).recordShowTextOperation(t)}i.x+=r*m*d;a.restore();this.compose();this.#nr(s);return}let C,E=0,S=null;for(C=0;C<u;++C){const s=e[C];if("number"==typeof s){E+=g*s*r/1e3;continue}let d=!1;const u=(s.isSpace?c:0)+l,w=s.fontChar,v=s.accent;let _,A,x,T=s.width;if(p){const t=s.vmetric,e=-t[1]*m,i=t[2]*m;T=-t[0];_=e/o;A=(E+i)/o;if(s.isRotated){x=a.measureText(w);const t=m/o,e=s.width/2*t,i=_+e;_=A-380*t-e;A=(x.actualBoundingBoxAscent-x.actualBoundingBoxDescent)/2-i;d=!0;a.save();a.rotate(Math.PI/2)}}else{_=E/o;A=0}const k=s.isRotated?s.width:T;let P=1;if((n.remeasure||s.isRotated)&&k>0){x??=a.measureText(w);const t=1e3*x.width/r*o;if(k<t&&this.isFontSubpixelAAEnabled){P=k/t;if(!d){d=!0;a.save()}a.scale(P,1);_/=P}else k!==t&&(_+=(k-t)/2e3*r/o)}if(d&&n.missingFile&&(b||y)){S||=new Map;[a.fillStyle,a.strokeStyle]=S.getOrInsertComputed(s.isRotated?-P:P,()=>[b?this.#sr(i.fillColor,Bn,t)[0]:a.fillStyle,y?this.#sr(i.strokeColor,Ln,t)[0]:a.strokeStyle])}if(this.contentVisible&&(s.isInFont||n.missingFile))if(f&&!v){a.fillText(w,_,A);this.dependencyTracker?.recordCharacterBBox(t,a,x?{bbox:null}:n,r/o,_,A,()=>x??a.measureText(w))}else{this.paintChar(t,w,_,A,b,y);if(v){const e=_+r*v.offset.x/o,i=A-r*v.offset.y/o;this.paintChar(t,v.fontChar,e,i,b,y)}}E+=p?T*m-u*h:T*m+u*h;d&&a.restore()}p?i.y-=E:i.x+=E*d;a.restore();this.compose();this.dependencyTracker?.recordShowTextOperation(t);this.#nr(s)}showType3Text(t,e){const i=this.ctx,n=this.current,r=n.font,s=n.fontSize,a=n.fontDirection,o=r.vertical?1:-1,l=n.charSpacing,c=n.wordSpacing,h=n.textHScale*a,d=n.fontMatrix||mi,u=e.length,p=n.textRenderingMode!==Oi;let g,m,f,b;if(0===s)return;this._cachedScaleForStroking[0]=-1;i.save();n.textMatrix&&i.transform(...n.textMatrix);i.translate(n.x,n.y+n.textRise);i.scale(h,a);const y=this.dependencyTracker;this.dependencyTracker=y?new CanvasNestedDependencyTracker(y,t):null;try{for(g=0;g<u;++g){m=e[g];if("number"==typeof m){b=o*m*s/1e3;this.ctx.translate(b,0);n.x+=b*h;continue}const t=(m.isSpace?c:0)+l,u=r.charProcOperatorList.get(m.operatorListId);if(u){if(this.contentVisible&&p){this.save();i.scale(s,s);i.transform(...d);this.executeOperatorList(u);this.restore()}}else warn(`Type3 character "${m.operatorListId}" is not available.`);f=m.width*d[0]*s+t*a;i.translate(f,0);n.x+=f*h}}finally{y&&(this.dependencyTracker=y)}i.restore()}setCharWidth(t,e,i){}setCharWidthAndBounds(t,e,i,n,r,s,a){const o=new Path2D;o.rect(n,r,s-n,a-r);this.ctx.clip(o);this.dependencyTracker?.recordBBox(t,this.ctx,n,s,r,a).recordClipBox(t,this.ctx,n,s,r,a);this.endPath(t)}getColorN_Pattern(t,e){let i;if("TilingPattern"===e[0]){const t=this.baseTransform||getCurrentTransform(this.ctx),n={createCanvasGraphics:(t,e)=>new CanvasGraphics(t,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack,pixelRatio:this.pixelRatio},void 0,void 0,this.dependencyTracker?new CanvasNestedDependencyTracker(this.dependencyTracker,e,!0):null)};i=new TilingPattern(e,this.ctx,n,t)}else i=this._getPattern(t,e[1],e[2]);return i}setStrokeColorN(t,...e){this.dependencyTracker?.recordSimpleData("strokeColor",t);this.current.strokeColor=this.getColorN_Pattern(t,e);this.current.patternStroke=!0}setFillColorN(t,...e){this.dependencyTracker?.recordSimpleData("fillColor",t);const i=this.current.fillColor=this.getColorN_Pattern(t,e);this.current.patternFill=!0;this.current.tilingPatternDims=i instanceof TilingPattern?[0,0,0,0]:null}#Qn(t){return this.current.transferMapsFallback?.applyToColor(t)??t}setStrokeRGBColor(t,e){this.dependencyTracker?.recordSimpleData("strokeColor",t);this.current.strokeColor=e;this.ctx.strokeStyle=this.#Qn(e);this.current.patternStroke=!1}setStrokeTransparent(t){this.dependencyTracker?.recordSimpleData("strokeColor",t);this.ctx.strokeStyle=this.current.strokeColor="transparent";this.current.patternStroke=!1}setFillRGBColor(t,e){this.dependencyTracker?.recordSimpleData("fillColor",t);this.current.fillColor=e;this.ctx.fillStyle=this.#Qn(e);this.current.patternFill=!1;this.current.tilingPatternDims=null}setFillTransparent(t){this.dependencyTracker?.recordSimpleData("fillColor",t);this.ctx.fillStyle=this.current.fillColor="transparent";this.current.patternFill=!1;this.current.tilingPatternDims=null}_getPattern(t,e,i=null){const n=this.cachedPatterns.getOrInsertComputed(e,()=>function getShadingPattern(t){switch(t[0]){case"RadialAxial":return new RadialAxialShadingPattern(t);case"Mesh":return new MeshShadingPattern(t);case"Dummy":return new DummyShadingPattern}throw new Error(`Unknown IR type: ${t[0]}`)}(this.getObject(t,e)));i&&(n.matrix=i);return n}shadingFill(t,e){if(!this.contentVisible)return;const i=this.#ir(this.current.fillAlpha),n=this.ctx;this.save(t);const r=this._getPattern(t,e);n.fillStyle=r.getPattern(n,this,getCurrentTransformInverse(n),Nn,t);const s=getCurrentTransformInverse(n);if(s){const{width:t,height:e}=n.canvas,i=gi.slice();Util.axialAlignedBoundingBox([0,0,t,e],s,i);const[r,a,o,l]=i;this.ctx.fillRect(r,a,o-r,l-a)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.dependencyTracker?.resetBBox(t).recordFullPageBBox(t).recordDependencies(t,On).recordDependencies(t,Mn).recordOperation(t);this.compose(this.current.getClippedPathBoundingBox());this.restore(t);this.#nr(i)}beginInlineImage(){unreachable("Should not call beginInlineImage")}beginImageData(){unreachable("Should not call beginImageData")}paintFormXObjectBegin(t,e,i){if(this.contentVisible){this.save(t);this.baseTransformStack.push(this.baseTransform);e&&this.transform(t,...e);this.baseTransform=getCurrentTransform(this.ctx);if(i){Util.axialAlignedBoundingBox(i,this.baseTransform,this.current.minMax);const[e,n,r,s]=i,a=new Path2D;a.rect(e,n,r-e,s-n);this.ctx.clip(a);this.dependencyTracker?.recordClipBox(t,this.ctx,e,r,n,s);this.endPath(t)}}}paintFormXObjectEnd(t){if(this.contentVisible){this.restore(t);this.baseTransform=this.baseTransformStack.pop()}}beginGroup(t,e){if(!this.contentVisible)return;this.save(t);const{inSMaskMode:i}=this;if(i){this.endSMaskMode();this.current.activeSMask=null}const n=this.ctx;if(!(e.needsIsolation&&(e.isolated||e.hasSoftMask)||e.knockout||e.isGray||0!==this.#Un||1!==n.globalAlpha||"source-over"!==n.globalCompositeOperation||i)){if(e.bbox){let t=new Path2D;const[i,r,s,a]=e.bbox;t.rect(i,r,s-i,a-r);if(e.matrix){const i=new Path2D;i.addPath(t,new DOMMatrix(e.matrix));t=i}n.clip(t)}this.groupStack.push(null);this.#Xn.push(null);this.groupLevel++;return}e.isolated||e.knockout||0!==this.#Un||info("TODO: Fully support non-isolated non-knockout groups.");const r=getCurrentTransform(n);e.matrix&&n.transform(...e.matrix);const s=[0,0,n.canvas.width,n.canvas.height];let a;if(e.bbox){a=gi.slice();Util.axialAlignedBoundingBox(e.bbox,getCurrentTransform(n),a);a=Util.intersect(a,s)||[0,0,0,0]}else a=s;const o=Math.floor(a[0]),l=Math.floor(a[1]),c=Math.max(Math.ceil(a[2])-o,1),h=Math.max(Math.ceil(a[3])-l,1);this.current.startNewPathAndClipBox([0,0,c,h]);const d=this.canvasFactory.create(c,h);e.smask&&this.smaskGroupCanvases.push(d);const u=d.context,p=e.knockout&&!e.isolated?n:null,g=!e.isolated&&!e.knockout&&!e.smask&&e.needsIsolation&&this.#Un>0,m=e.knockout?this.canvasFactory.create(c,h):null,f=this.#Un;e.knockout?this.#Un++:this.#Un=0;u.translate(-o,-l);u.transform(...r);const b=!e.isolated&&!e.smask&&e.needsIsolation,y=b&&!i&&0===f&&!e.knockout&&!e.isGray&&e.hasSoftMask&&1===n.globalAlpha&&"source-over"===n.globalCompositeOperation&&"none"===this.current.transferMaps&&!this.current.transferMapsFallback;if(b&&(i||y)){u.save();u.setTransform(1,0,0,1,0,0);u.drawImage(n.canvas,-o,-l);u.restore()}if(e.bbox){let t=new Path2D;const[i,n,r,s]=e.bbox;t.rect(i,n,r-i,s-n);if(e.matrix){const i=new Path2D;i.addPath(t,new DOMMatrix(e.matrix));t=i}u.clip(t)}e.smask&&this.smaskStack.push({canvas:d.canvas,context:u,offsetX:o,offsetY:l,subtype:e.smask.subtype,backdrop:e.smask.backdrop,transferMap:e.smask.transferMap||null});if(!e.smask||this.dependencyTracker){n.setTransform(1,0,0,1,0,0);n.translate(o,l);n.save()}copyCtxState(n,u);this.ctx=u;this.dependencyTracker?.inheritSimpleDataAsFutureForcedDependencies(["fillAlpha","strokeAlpha","globalCompositeOperation"]).pushBaseTransform(n);this.setGState(t,[["BM","source-over"],["ca",1],["CA",1],["TR",null]]);this.groupStack.push(n);this.#Xn.push({backdropCtx:p,savedKnockoutLevel:f,offsetX:o,offsetY:l,hasInnerBackdrop:g,replaceBackdrop:y,knockoutMaskEntry:m,knockoutTempEntry:null,knockoutBackdropEntry:null});this.groupLevel++}endGroup(t,e){if(!this.contentVisible)return;this.groupLevel--;const i=this.ctx,n=this.groupStack.pop(),r=this.#Xn.pop();r&&(this.#Un=r.savedKnockoutLevel);if(null!==n){e.isGray&&this.#ar(i);this.ctx=n;this.ctx.imageSmoothingEnabled=!1;this.dependencyTracker?.popBaseTransform();if(e.smask){this.tempSMask=this.smaskStack.pop();this.restore(t);if(this.dependencyTracker){this.ctx.restore();this.inSMaskMode&&this.ctx.setTransform(this.suspendedCtx.getTransform())}this.#Yn(r)}else{this.ctx.restore();const e=getCurrentTransform(this.ctx);this.restore(t);this.current.transferMapsFallback?.applyToCanvas(i);this.ctx.save();this.ctx.setTransform(...e);const s=gi.slice();Util.axialAlignedBoundingBox([0,0,i.canvas.width,i.canvas.height],e,s);const a=this.#Xn.at(-1);if(this.#Un>0)if(r.hasInnerBackdrop){const{width:t,height:s}=i.canvas,a=this.canvasFactory.create(t,s),o=a.context;o.drawImage(n.canvas,r.offsetX,r.offsetY,t,s,0,0,t,s);o.globalCompositeOperation="source-over";o.drawImage(i.canvas,0,0);const l=this.#Zn(i.canvas);o.globalCompositeOperation="destination-in";o.drawImage(l.canvas,0,0);const c=this.ctx.globalCompositeOperation,h=this.ctx.globalAlpha,d=this.ctx.filter;this.ctx.save();this.ctx.setTransform(...e);this.ctx.globalAlpha=1;FeatureTest.isCanvasFilterSupported&&(this.ctx.filter="none");this.ctx.globalCompositeOperation="destination-out";this.ctx.drawImage(l.canvas,0,0);this.ctx.globalCompositeOperation=c;this.ctx.globalAlpha=h;FeatureTest.isCanvasFilterSupported&&(this.ctx.filter=d??"none");this.ctx.drawImage(a.canvas,0,0);this.ctx.restore();this.canvasFactory.destroy(l);this.canvasFactory.destroy(a)}else{const t=a?.backdropCtx??null;this.#er(this.ctx,i.canvas,{backdropCanvas:t?.canvas??null,destTransform:e,backdropOffset:t?[a.offsetX+r.offsetX,a.offsetY+r.offsetY]:[0,0],sourceAlpha:this.ctx.globalAlpha,sourceFilter:this.ctx.filter})}else{if(r.replaceBackdrop){const t=new Path2D;t.rect(0,0,i.canvas.width,i.canvas.height);this.ctx.clip(t);this.ctx.globalCompositeOperation="copy"}this.ctx.drawImage(i.canvas,0,0)}this.ctx.restore();this.canvasFactory.destroy({canvas:i.canvas,context:i});this.#Yn(r);this.compose(s)}}else this.restore(t)}#ar(t){const{canvas:e}=t,{width:i,height:n}=e;if(FeatureTest.isCanvasFilterSupported){t.save();t.setTransform(1,0,0,1,0,0);t.filter="grayscale(1)";t.globalAlpha=1;t.globalCompositeOperation="copy";t.drawImage(e,0,0);t.restore();return}const r=t.getImageData(0,0,i,n),{data:s}=r;for(let t=0,e=s.length;t<e;t+=4){const e=.2126*s[t]+.7152*s[t+1]+.0722*s[t+2]+.5|0;s[t]=s[t+1]=s[t+2]=e}t.putImageData(r,0,0)}#Yn(t){if(t){if(t.knockoutMaskEntry){this.canvasFactory.destroy(t.knockoutMaskEntry);t.knockoutMaskEntry=null}if(t.knockoutTempEntry){this.canvasFactory.destroy(t.knockoutTempEntry);t.knockoutTempEntry=null}if(t.knockoutBackdropEntry){this.canvasFactory.destroy(t.knockoutBackdropEntry);t.knockoutBackdropEntry=null}}}beginAnnotation(t,e,i,n,r,s,a){this.#Kn();resetCtxToDefault(this.ctx);this.ctx.save();this.save(t);this.baseTransform&&this.ctx.setTransform(...this.baseTransform);if(i){const r=i[2]-i[0],o=i[3]-i[1];if(s&&this.annotationCanvasMap){(n=n.slice())[4]-=i[0];n[5]-=i[1];Util.singularValueDecompose2dScale(getCurrentTransform(this.ctx),Gn);const{viewportScale:t}=this,s=Math.ceil(r*this.outputScaleX*t),l=Math.ceil(o*this.outputScaleY*t);this.annotationCanvas=this.canvasFactory.create(s,l);const{canvas:c,context:h}=this.annotationCanvas;if(a){const t=this.annotationCanvasMap.getOrInsertComputed(e,makeArr);setAnnotationCanvasName(c,a);const i=t.findIndex(t=>function getAnnotationCanvasName(t){return t._pdfjsCanvasName??null}(t)===a);-1===i?t.push(c):t[i]=c}else this.annotationCanvasMap.set(e,c);this.annotationCanvas.savedCtx=this.ctx;this.ctx=h;this.ctx.save();this.ctx.setTransform(Gn[0],0,0,-Gn[1],0,o*Gn[1]);resetCtxToDefault(this.ctx)}else{resetCtxToDefault(this.ctx);this.endPath(t);const e=new Path2D;e.rect(i[0],i[1],r,o);this.ctx.clip(e)}}this.current=new CanvasExtraState(this.ctx.canvas.width,this.ctx.canvas.height);this.baseTransformStack.push(this.baseTransform);this.transform(t,...n);this.transform(t,...r);this.baseTransform=getCurrentTransform(this.ctx)}endAnnotation(t){if(this.annotationCanvas){this.ctx.restore();this.#Jn();this.ctx=this.annotationCanvas.savedCtx;delete this.annotationCanvas.savedCtx;delete this.annotationCanvas}this.baseTransform=this.baseTransformStack.pop()}paintImageMaskXObject(t,e){if(!this.contentVisible)return;const i=e.count;(e=this.getObject(t,e.data,e)).count=i;const n=this.#ir(this.current.fillAlpha),r=this.ctx,s=this._createMaskCanvas(t,e),a=s.canvas;r.save();r.setTransform(1,0,0,1,0,0);r.drawImage(a,s.offsetX,s.offsetY);this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,s.offsetX,s.offsetX+a.width,s.offsetY,s.offsetY+a.height).recordOperation(t);r.restore();s.canvasEntry&&this.canvasFactory.destroy(s.canvasEntry);this.compose();this.#nr(n)}paintImageMaskXObjectRepeat(t,e,i,n=0,r=0,s,a){if(!this.contentVisible)return;e=this.getObject(t,e.data,e);const o=this.#ir(this.current.fillAlpha),l=this.ctx;l.save();const c=getCurrentTransform(l);l.transform(i,n,r,s,0,0);const h=this._createMaskCanvas(t,e);l.setTransform(1,0,0,1,h.offsetX-c[4],h.offsetY-c[5]);this.dependencyTracker?.resetBBox(t);for(let e=0,o=a.length;e<o;e+=2){const o=Util.transform(c,[i,n,r,s,a[e],a[e+1]]);l.drawImage(h.canvas,o[4],o[5]);this.dependencyTracker?.recordBBox(t,this.ctx,o[4],o[4]+h.canvas.width,o[5],o[5]+h.canvas.height)}l.restore();h.canvasEntry&&this.canvasFactory.destroy(h.canvasEntry);this.compose();this.dependencyTracker?.recordOperation(t);this.#nr(o)}paintImageMaskXObjectGroup(t,e){if(!this.contentVisible)return;const i=this.#ir(this.current.fillAlpha),n=this.ctx,r=this.current.patternFill,s=r?this.current.fillColor:n.fillStyle;this.dependencyTracker?.resetBBox(t).recordDependencies(t,Rn);for(const i of e){const{data:e,width:a,height:o,transform:l}=i,c=this.canvasFactory.create(a,o),h=c.context;h.save();putBinaryImageMask(h,this.getObject(t,e,i));h.globalCompositeOperation="source-in";h.fillStyle=r?s.getPattern(h,this,getCurrentTransformInverse(n),Bn,t):s;h.fillRect(0,0,a,o);h.restore();n.save();n.transform(...l);n.scale(1,-1);drawImageAtIntegerCoords(n,c.canvas,0,0,a,o,0,-1,1,1);this.canvasFactory.destroy(c);this.dependencyTracker?.recordBBox(t,n,0,a,0,o);n.restore()}this.compose();this.dependencyTracker?.recordOperation(t);this.#nr(i)}paintImageXObject(t,e){if(!this.contentVisible)return;const i=this.getObject(t,e);i?this.paintInlineImageXObject(t,i):warn("Dependent image isn't ready yet")}paintImageXObjectRepeat(t,e,i,n,r){if(!this.contentVisible)return;const s=this.getObject(t,e);if(!s){warn("Dependent image isn't ready yet");return}const a=s.width,o=s.height,l=[];for(let t=0,e=r.length;t<e;t+=2)l.push({transform:[i,0,0,n,r[t],r[t+1]],x:0,y:0,w:a,h:o});this.paintInlineImageXObjectGroup(t,s,l)}applyTransferMapsToCanvas(t){if("none"!==this.current.transferMaps){t.filter=this.current.transferMaps;t.drawImage(t.canvas,0,0);t.filter="none"}else this.current.transferMapsFallback?.applyToCanvas(t);return t.canvas}applyTransferMapsToBitmap(t){const{transferMaps:e,transferMapsFallback:i}=this.current;if("none"===e&&!i)return{img:t.bitmap,canvasEntry:null};const{bitmap:n,width:r,height:s}=t,a=this.canvasFactory.create(r,s),o=a.context;o.filter=e;o.drawImage(n,0,0);o.filter="none";i?.applyToCanvas(o);return{img:a.canvas,canvasEntry:a}}paintInlineImageXObject(t,e){if(!this.contentVisible)return;const i=e.width,n=e.height,r=this.#ir(this.current.fillAlpha),s=this.ctx;this.save(t);const{filter:a}=s;"none"!==a&&""!==a&&(s.filter="none");s.scale(1/i,-1/n);let o,l=null;if(e.bitmap){const t=this.applyTransferMapsToBitmap(e);o=t.img;l=t.canvasEntry}else{const t=this.canvasFactory.create(i,n);putBinaryImageData(t.context,e);o=this.applyTransferMapsToCanvas(t.context);l=t}const c=this._scaleImage(o,getCurrentTransformInverse(s));s.imageSmoothingEnabled=getImageSmoothingEnabled(getCurrentTransform(s),e.interpolate,this.pixelRatio);if(this.dependencyTracker){this.dependencyTracker.resetBBox(t).recordBBox(t,s,0,i,-n,0).recordDependencies(t,Dn).recordOperation(t);this.imagesTracker?.record(s,i,n,this.dependencyTracker.clipBox)}drawImageAtIntegerCoords(s,c.img,0,0,c.paintWidth,c.paintHeight,0,-n,i,n);c.tmpCanvas&&this.canvasFactory.destroy(c.tmpCanvas);l&&this.canvasFactory.destroy(l);this.compose();this.restore(t);this.#nr(r)}paintInlineImageXObjectGroup(t,e,i){if(!this.contentVisible)return;const n=this.#ir(this.current.fillAlpha),r=this.ctx;let s,a=null;if(e.bitmap&&!this.current.transferMapsFallback)s=e.bitmap;else if(e.bitmap)({img:s,canvasEntry:a}=this.applyTransferMapsToBitmap(e));else{const t=e.width,i=e.height,n=this.canvasFactory.create(t,i);putBinaryImageData(n.context,e);s=this.applyTransferMapsToCanvas(n.context);a=n}this.dependencyTracker?.resetBBox(t);for(const e of i){r.save();r.transform(...e.transform);r.scale(1,-1);drawImageAtIntegerCoords(r,s,e.x,e.y,e.w,e.h,0,-1,1,1);this.dependencyTracker?.recordBBox(t,r,0,1,-1,0);r.restore()}a&&this.canvasFactory.destroy(a);this.dependencyTracker?.recordOperation(t);this.compose();this.#nr(n)}paintSolidColorImageMask(t){if(!this.contentVisible)return;const e=this.#ir(this.current.fillAlpha);this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,0,1,0,1).recordDependencies(t,Mn).recordOperation(t);this.ctx.fillRect(0,0,1,1);this.compose();this.#nr(e)}markPoint(t,e){}markPointProps(t,e,i){}beginMarkedContent(t,e){this.dependencyTracker?.beginMarkedContent(t);this.markedContentStack.push({visible:!0})}beginMarkedContentProps(t,e,i){this.dependencyTracker?.beginMarkedContent(t);"OC"===e?this.markedContentStack.push({visible:this.optionalContentConfig.isVisible(i)}):this.markedContentStack.push({visible:!0});this.contentVisible=this.isContentVisible()}endMarkedContent(t){this.dependencyTracker?.endMarkedContent(t);this.markedContentStack.pop();this.contentVisible=this.isContentVisible()}beginCompat(t){}endCompat(t){}consumePath(t,e,i){const n=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath();this.pendingClip||this.compose(i);const r=this.ctx;if(this.pendingClip){n||(this.pendingClip===qn?r.clip(e,"evenodd"):r.clip(e));this.pendingClip=null;this.dependencyTracker?.bboxToClipBoxDropOperation(t).recordFutureForcedDependency("clipPath",t)}else this.dependencyTracker?.recordOperation(t);this.current.startNewPathAndClipBox(this.current.clipBox)}getSinglePixelWidth(){const t=getCurrentTransform(this.ctx);if(0===t[1]&&0===t[2])return 1/Math.min(Math.abs(t[0]),Math.abs(t[3]));const e=Math.abs(t[0]*t[3]-t[2]*t[1]),i=Math.hypot(t[0],t[2]),n=Math.hypot(t[1],t[3]);return Math.max(i,n)/e}getScaleForStroking(){if(-1===this._cachedScaleForStroking[0]){const{lineWidth:t}=this.current,{a:e,b:i,c:n,d:r}=this.ctx.getTransform();let s,a;if(0===i&&0===n){const i=Math.abs(e),n=Math.abs(r);if(i===n)if(0===t)s=a=1/i;else{const e=i*t;s=a=e<1?1/e:1}else if(0===t){s=1/i;a=1/n}else{const e=i*t,r=n*t;s=e<1?1/e:1;a=r<1?1/r:1}}else{const o=Math.abs(e*r-i*n),l=Math.hypot(e,i),c=Math.hypot(n,r);if(0===t){s=c/o;a=l/o}else{const e=t*o;s=c>e?c/e:1;a=l>e?l/e:1}}this._cachedScaleForStroking[0]=s;this._cachedScaleForStroking[1]=a}return this._cachedScaleForStroking}rescaleAndStroke(t,e){const{ctx:i,current:{lineWidth:n}}=this,[r,s]=this.getScaleForStroking();if(r===s){i.lineWidth=(n||1)*r;i.stroke(t);return}const a=CanvasGraphics.#Ln??=new DOMMatrix,o=i.getLineDash();e&&i.save();i.scale(r,s);a.a=1/r;a.d=1/s;const l=new Path2D;l.addPath(t,a);if(o.length>0){const t=Math.max(r,s);i.setLineDash(o.map(e=>e/t));i.lineDashOffset/=t}i.lineWidth=n||1;i.stroke(l);e&&i.restore()}isContentVisible(){for(let t=this.markedContentStack.length-1;t>=0;t--)if(!this.markedContentStack[t].visible)return!1;return!0}}for(const t in Vi)void 0!==CanvasGraphics.prototype[t]&&(CanvasGraphics.prototype[Vi[t]]=CanvasGraphics.prototype[t]);class DOMCanvasFactory extends BaseCanvasFactory{constructor({ownerDocument:t=globalThis.document,enableHWA:e=!1}){super({enableHWA:e});this._document=t}_createCanvas(t,e){const i=this._document.createElement("canvas");i.width=t;i.height=e;return i}}class DOMFilterFactory extends BaseFilterFactory{#or;#lr;#cr;#hr;#dr;#ur;#S=0;constructor({docId:t,ownerDocument:e=globalThis.document}){super();this.#hr=t;this.#dr=e}get#k(){return this.#lr||=new Map}get#pr(){return this.#ur||=new Map}get#gr(){if(!this.#cr){const t=this.#dr.createElement("div"),{style:e}=t;e.colorScheme="only light";e.visibility="hidden";e.contain="strict";e.width=e.height=0;e.position="absolute";e.top=e.left=0;e.zIndex=-1;const i=this.#dr.createElementNS(fi,"svg");i.setAttribute("width",0);i.setAttribute("height",0);this.#cr=this.#dr.createElementNS(fi,"defs");t.append(i);i.append(this.#cr);this.#dr.body.append(t)}return this.#cr}#mr(t){const toTable=t=>t&&Array.from(t,t=>t/255).join(",");if(1===t.length){const e=toTable(t[0]);return[e,e,e]}const[e,i,n]=t;return[toTable(e),toTable(i),toTable(n)]}#fr(t){if(void 0===this.#or){this.#or="";const t=this.#dr.URL;t!==this.#dr.baseURI&&(isDataScheme(t)?warn('#createUrl: ignore "data:"-URL for performance reasons.'):this.#or=updateUrlHash(t,""))}return`url(${this.#or}#${t})`}addFilter(t){if(!t)return"none";let e=this.#k.get(t);if(e)return e;const[i,n,r]=this.#mr(t),s=1===t.length?i:`${i}${n}${r}`;e=this.#k.get(s);if(e){this.#k.set(t,e);return e}const a=`g_${this.#hr}_transfer_map_${this.#S++}`,o=this.#fr(a);this.#k.set(t,o);this.#k.set(s,o);const l=this.#br(a);this.#yr(i,n,r,l);return o}addHCMFilter(t,e){const i=`${t}-${e}`,n="base";let r=this.#pr.get(n);if(r?.key===i)return r.url;if(r){r.filter?.remove();r.key=i;r.url="none";r.filter=null}else{r={key:i,url:"none",filter:null};this.#pr.set(n,r)}if(!t||!e)return r.url;const s=this.#wr(t);t=Util.makeHexColor(...s);const a=this.#wr(e);e=Util.makeHexColor(...a);this.#vr();if("#000000"===t&&"#ffffff"===e||t===e)return r.url;const o=Array.from({length:256},(t,e)=>computeLuminance(e/255)).join(","),l=`g_${this.#hr}_hcm_filter`,c=r.filter=this.#br(l);this.#yr(o,o,o,c);this.#_r(c);const getSteps=(t,e)=>{const i=s[t]/255,n=a[t]/255,r=new Array(e+1);for(let t=0;t<=e;t++)r[t]=i+t/e*(n-i);return r.join(",")};this.#yr(getSteps(0,5),getSteps(1,5),getSteps(2,5),c);r.url=this.#fr(l);return r.url}addSelectionHCMFilter(t,e){return this.addHighlightHCMFilter("selection",t,e,"HighlightText","Highlight")}addSelectionFilter(){return this.addHighlightHCMFilter("selection_default","black","white","HighlightText","Highlight")}createSelectionStyle(t=null){const e=t?this.addSelectionHCMFilter(t.foreground,t.background):this.addSelectionFilter();return"none"!==e&&FeatureTest.platform.isFirefox?{"backdrop-filter":e,"background-color":"transparent"}:null}addAlphaFilter(t){let e=this.#k.get(t);if(e)return e;const[i]=this.#mr([t]),n=`alpha_${i}`;e=this.#k.get(n);if(e){this.#k.set(t,e);return e}const r=`g_${this.#hr}_alpha_map_${this.#S++}`,s=this.#fr(r);this.#k.set(t,s);this.#k.set(n,s);const a=this.#br(r);this.#Ar(i,a);return s}addLuminosityFilter(t){let e,i,n=this.#k.get(t||"luminosity");if(n)return n;if(t){[e]=this.#mr([t]);i=`luminosity_${e}`}else i="luminosity";n=this.#k.get(i);if(n){this.#k.set(t,n);return n}const r=`g_${this.#hr}_luminosity_map_${this.#S++}`,s=this.#fr(r);this.#k.set(t,s);this.#k.set(i,s);const a=this.#br(r);this.#xr(a);t&&this.#Ar(e,a);return s}addKnockoutFilter(t=0){const e=t>0?Math.min(1/t,1e6):1e6,i=`knockout_${e}`,n=this.#k.get(i);if(n)return n;const r=`g_${this.#hr}_knockout_filter_${this.#S++}`,s=this.#fr(r);this.#k.set(i,s);const a=this.#br(r),o=this.#dr.createElementNS(fi,"feComponentTransfer");a.append(o);const l=this.#dr.createElementNS(fi,"feFuncA");l.setAttribute("type","linear");l.setAttribute("slope",`${e}`);l.setAttribute("intercept","0");o.append(l);return s}addHighlightHCMFilter(t,e,i,n,r){const s=`${e}-${i}-${n}-${r}`;let a=this.#pr.get(t);if(a?.key===s)return a.url;if(a){a.filter?.remove();a.key=s;a.url="none";a.filter=null}else{a={key:s,url:"none",filter:null};this.#pr.set(t,a)}if(!e||!i)return a.url;const[o,l]=[e,i].map(this.#wr.bind(this));let c=Math.round(.2126*o[0]+.7152*o[1]+.0722*o[2]),h=Math.round(.2126*l[0]+.7152*l[1]+.0722*l[2]),[d,u]=[n,r].map(this.#Cr.bind(this));h<c&&([c,h,d,u]=[h,c,u,d]);this.#vr();const getSteps=(t,e,i)=>{const n=new Array(256),r=(h-c)/i,s=t/255,a=(e-t)/(255*i);let o=0;for(let t=0;t<=i;t++){const e=Math.round(c+t*r),i=s+t*a;for(let t=o;t<=e;t++)n[t]=i;o=e+1}for(let t=o;t<256;t++)n[t]=n[o-1];return n.join(",")},p=`g_${this.#hr}_hcm_${t}_filter`,g=a.filter=this.#br(p);this.#_r(g);this.#yr(getSteps(d[0],u[0],5),getSteps(d[1],u[1],5),getSteps(d[2],u[2],5),g);a.url=this.#fr(p);return a.url}destroy(t=!1){if(!t||!this.#ur?.size){this.#cr?.parentNode.parentNode.remove();this.#cr=null;this.#lr?.clear();this.#lr=null;this.#ur?.clear();this.#ur=null;this.#S=0}}#xr(t){const e=this.#dr.createElementNS(fi,"feColorMatrix");e.setAttribute("type","matrix");e.setAttribute("values","0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.3 0.59 0.11 0 0");t.append(e)}#_r(t){const e=this.#dr.createElementNS(fi,"feColorMatrix");e.setAttribute("type","matrix");e.setAttribute("values","0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0.2126 0.7152 0.0722 0 0 0 0 0 1 0");t.append(e)}#br(t){const e=this.#dr.createElementNS(fi,"filter");e.setAttribute("color-interpolation-filters","sRGB");e.setAttribute("id",t);this.#gr.append(e);return e}#Er(t,e,i){if(!i)return;const n=this.#dr.createElementNS(fi,e);n.setAttribute("type","discrete");n.setAttribute("tableValues",i);t.append(n)}#yr(t,e,i,n){const r=this.#dr.createElementNS(fi,"feComponentTransfer");n.append(r);this.#Er(r,"feFuncR",t);this.#Er(r,"feFuncG",e);this.#Er(r,"feFuncB",i)}#Ar(t,e){const i=this.#dr.createElementNS(fi,"feComponentTransfer");e.append(i);this.#Er(i,"feFuncA",t)}#wr(t){this.#gr.style.color="CanvasText";this.#gr.style.backgroundColor=t;return getRGB(getComputedStyle(this.#gr).getPropertyValue("background-color"))}#Sr(t){this.#gr.style.color="CanvasText";this.#gr.style.backgroundColor=t;return getRGBA(getComputedStyle(this.#gr).getPropertyValue("background-color"))}#vr(){this.#gr.style.color="";this.#gr.style.backgroundColor=""}#Cr(t){const[e,i,n,r]=this.#Sr(t);if(1===r)return[e,i,n];const[s,a,o]=this.#wr("Canvas");return[blend(e,s,r),blend(i,a,r),blend(n,o,r)]}}function blend(t,e,i){return Math.round(i*t+(1-i)*e)}const $n=/\p{Cc}/u;function serializeFontFamily(t){if(function isCSSString(t){const e=t[0];if(t.length<2||'"'!==e&&"'"!==e||t.at(-1)!==e)return!1;const i=t.length-1;for(let n=1;n<i;n++){const r=t[n];if(r===e||$n.test(r))return!1;if("\\"===r&&(++n>=i||$n.test(t[n])))return!1}return!0}(t))return t;return`"${t.replaceAll(/["\\\p{Cc}]/gu,t=>'"'===t||"\\"===t?`\\${t}`:`\\${t.codePointAt(0).toString(16)} `)}"`}class FontLoader{#Tr=new Set;#kr=new Set;#Pr=null;constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){this._document=t;this.styleElement=null;this.loadingRequests=[];this.loadTestFontId=0}addNativeFontFace(t){this.#Tr.add(t);this._document.fonts.add(t)}removeNativeFontFace(t){this.#Tr.delete(t);this._document.fonts.delete(t)}insertRule(t){const e=this.#Mr();e.insertRule(t,e.cssRules.length)}#Mr(){if(this.#Pr)return this.#Pr;const t=this._document.defaultView?.CSSStyleSheet||globalThis.CSSStyleSheet;if(!this.styleElement&&t){const{adoptedStyleSheets:e}=this._document;if(e){const i=new t;e.push(i);return this.#Pr=i}}if(!this.styleElement){this.styleElement=this._document.createElement("style");this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement)}return this.#Pr=this.styleElement.sheet}clear(){for(const t of this.#Tr)this._document.fonts.delete(t);this.#Tr.clear();this.#kr.clear();if(this.#Pr){const{adoptedStyleSheets:t}=this._document;t?.includes(this.#Pr)&&(this._document.adoptedStyleSheets=t.filter(t=>t!==this.#Pr));this.#Pr=null}this.styleElement?.remove();this.styleElement=null}async loadSystemFont({systemFontInfo:t,disableFontFace:e,_inspectFont:i}){if(t&&!this.#kr.has(t.loadedName)){util_assert(!e,"loadSystemFont shouldn't be called when `disableFontFace` is set.");if(this.isFontLoadingAPISupported){const{loadedName:e,src:n,style:r}=t,s=new FontFace(e,n,r);this.addNativeFontFace(s);try{await s.load();this.#kr.add(e);i?.(t)}catch{warn(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`);this.removeNativeFontFace(s)}return}unreachable("Not implemented: loadSystemFont without the Font Loading API.")}}async bind(t){if(t.attached||t.missingFile&&!t.systemFontInfo)return;t.attached=!0;if(t.systemFontInfo){await this.loadSystemFont(t);return}if(this.isFontLoadingAPISupported){const e=t.createNativeFontFace();if(e){this.addNativeFontFace(e);try{await e.loaded}catch(i){warn(`Failed to load font '${e.family}': '${i}'.`);t.disableFontFace=!0;throw i}}return}const e=t.createFontFaceRule();if(e){this.insertRule(e);if(this.isSyncFontLoadingSupported)return;await this.#Dr(t)}}get isFontLoadingAPISupported(){return util_shadow(this,"isFontLoadingAPISupported",!!this._document?.fonts)}get isSyncFontLoadingSupported(){return util_shadow(this,"isSyncFontLoadingSupported",ui||FeatureTest.platform.isFirefox)}#Dr(t){const{loadingRequests:e}=this,{promise:i,resolve:n}=Promise.withResolvers(),r={done:!1,resolve:n};e.push(r);this._loadTestFont??=atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");function int32(t,e){return t.charCodeAt(e)<<24|t.charCodeAt(e+1)<<16|t.charCodeAt(e+2)<<8|255&t.charCodeAt(e+3)}function spliceString(t,e,i,n){return t.substring(0,e)+n+t.substring(e+i)}let s,a;const o=this._document.createElement("canvas");o.width=1;o.height=1;const l=o.getContext("2d");let c=0;const h=`lt${Date.now()}${this.loadTestFontId++}`;let d=this._loadTestFont;d=spliceString(d,976,h.length,h);const u=1482184792;let p=int32(d,16);for(s=0,a=h.length-3;s<a;s+=4)p=p-u+int32(h,s)|0;s<h.length&&(p=p-u+int32(h+"XXX",s)|0);d=spliceString(d,16,4,function string32(t){return String.fromCharCode(t>>24&255,t>>16&255,t>>8&255,255&t)}(p));const g=`@font-face {font-family:"${h}";src:${`url(data:font/opentype;base64,${btoa(d)});`}}`;this.insertRule(g);const m=this._document.createElement("div");m.style.visibility="hidden";m.style.width=m.style.height="10px";m.style.position="absolute";m.style.top=m.style.left="0px";for(const e of[t.loadedName,h]){const t=this._document.createElement("span");t.textContent="Hi";t.style.fontFamily=e;m.append(t)}this._document.body.append(m);!function isFontReady(t,e){if(++c>30){warn("Load test font never loaded.");e();return}l.font="30px "+t;l.fillText(".",0,20);l.getImageData(0,0,1,1).data[3]>0?e():setTimeout(isFontReady.bind(null,t,e))}(h,()=>{m.remove();!function completeRequest(){util_assert(!r.done,"completeRequest() cannot be called twice.");r.done=!0;for(;e.length>0&&e[0].done;){const t=e.shift();setTimeout(t.resolve,0)}}()});return i}}class FontFaceObject{#Ir=new Map;#Fr;constructor(t,e=null,i,n){this.#Fr=t;this._inspectFont=e;i&&(this.charProcOperatorList=i);n&&Object.assign(this,n)}createNativeFontFace(){const{data:t}=this;if(!t||this.disableFontFace)return null;let e;if(this.cssFontInfo){const i={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(i.style=`oblique ${this.cssFontInfo.italicAngle}deg`);e=new FontFace(serializeFontFamily(this.cssFontInfo.fontFamily),t,i)}else e=new FontFace(this.loadedName,t,{});this._inspectFont?.(this);return e}createFontFaceRule(){const{data:t}=this;if(!t||this.disableFontFace)return null;const e=`url(data:${this.mimetype};base64,${t.toBase64()});`;let i;if(this.cssFontInfo){let t=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(t+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`);i=`@font-face {font-family:${serializeFontFamily(this.cssFontInfo.fontFamily)};${t}src:${e}}`}else i=`@font-face {font-family:"${this.loadedName}";src:${e}}`;this._inspectFont?.(this,e);return i}getPathGenerator(t,e){let i=this.#Ir.get(e);if(i)return i;const n=`${this.loadedName}_path_${e}`;let r;try{r=t.get(n)}catch(t){warn(`getPathGenerator - ignoring character: "${t}".`)}i=makePathFromDrawOPS(r?.path);this.fontExtraProperties||t.delete(n);this.#Ir.set(e,i);return i}get black(){return this.#Fr.black}get bold(){return this.#Fr.bold}get disableFontFace(){return this.#Fr.disableFontFace}set disableFontFace(t){util_shadow(this,"disableFontFace",!!t)}get fontExtraProperties(){return this.#Fr.fontExtraProperties}get isInvalidPDFjsFont(){return this.#Fr.isInvalidPDFjsFont}get isType3Font(){return this.#Fr.isType3Font}get italic(){return this.#Fr.italic}get missingFile(){return this.#Fr.missingFile}get remeasure(){return this.#Fr.remeasure}get vertical(){return this.#Fr.vertical}get bbox(){return this.#Fr.bbox}get fontMatrix(){return this.#Fr.fontMatrix}get fallbackName(){return this.#Fr.fallbackName}get loadedName(){return this.#Fr.loadedName}get mimetype(){return this.missingFile?null:"font/opentype"}get data(){return this.#Fr.data}clearData(){this.#Fr.clearData()}get cssFontInfo(){return this.#Fr.cssFontInfo}get systemFontInfo(){return this.#Fr.systemFontInfo}}class BasePDFStream{#Or=null;#Rr=null;_fullReader=null;_rangeReaders=new Set;_source=null;constructor(t,e,i){this._source=t;this.#Or=e;this.#Rr=i}get _progressiveDataLength(){return this._fullReader?._loaded??0}getFullReader(){util_assert(!this._fullReader,"BasePDFStream.getFullReader can only be called once.");return this._fullReader=new this.#Or(this)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const i=new this.#Rr(this,t,e);this._rangeReaders.add(i);return i}cancelAllRequests(t){this._fullReader?.cancel(t);for(const e of new Set(this._rangeReaders))e.cancel(t)}}class BasePDFStreamReader{onProgress=null;_contentLength=0;_filename=null;_headersCapability=Promise.withResolvers();_isRangeSupported=!1;_isStreamingSupported=!1;_loaded=0;_stream=null;constructor(t){this._stream=t}_callOnProgress(){this.onProgress?.({loaded:this._loaded,total:this._contentLength})}get headersReady(){return this._headersCapability.promise}get filename(){return this._filename}get contentLength(){return this._contentLength}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}async read(){unreachable("Abstract method `read` called")}cancel(t){unreachable("Abstract method `cancel` called")}}class BasePDFStreamRangeReader{_stream=null;constructor(t,e,i){this._stream=t}async read(){unreachable("Abstract method `read` called")}cancel(t){unreachable("Abstract method `cancel` called")}}function createHeaders(t,e){const i=new Headers;if(!t||!e||"object"!=typeof e)return i;for(const t in e){const n=e[t];void 0!==n&&i.append(t,n)}return i}function getResponseOrigin(t){return URL.parse(t)?.origin??null}function validateRangeRequestCapabilities({responseHeaders:t,isHttp:e,rangeChunkSize:i,disableRange:n}){const r={contentLength:0,isRangeSupported:!1},s=parseInt(t.get("Content-Length"),10);if(!Number.isInteger(s))return r;r.contentLength=s;if(s<=2*i)return r;if(n||!e||"bytes"!==t.get("Accept-Ranges"))return r;"identity"===(t.get("Content-Encoding")||"identity")&&(r.isRangeSupported=!0);return r}function extractFilenameFromHeader(t){const e=t.get("Content-Disposition");if(e){let t=function getFilenameFromContentDispositionHeader(t){let e=!0,i=toParamRegExp("filename\\*","i").exec(t);if(i){i=i[1];let t=rfc2616unquote(i);t=unescape(t);t=rfc5987decode(t);t=rfc2047decode(t);return fixupEncoding(t)}i=function rfc2231getparam(t){const e=[];let i;const n=toParamRegExp("filename\\*((?!0\\d)\\d+)(\\*?)","ig");for(;null!==(i=n.exec(t));){let[,t,n,r]=i;t=parseInt(t,10);if(t in e){if(0===t)break}else e[t]=[n,r]}const r=[];for(let t=0;t<e.length&&t in e;++t){let[i,n]=e[t];n=rfc2616unquote(n);if(i){n=unescape(n);0===t&&(n=rfc5987decode(n))}r.push(n)}return r.join("")}(t);if(i)return fixupEncoding(rfc2047decode(i));i=toParamRegExp("filename","i").exec(t);if(i){i=i[1];let t=rfc2616unquote(i);t=rfc2047decode(t);return fixupEncoding(t)}function toParamRegExp(t,e){return new RegExp("(?:^|;)\\s*"+t+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',e)}function textdecode(t,i){if(t){if(!/^[\x00-\xFF]+$/.test(i))return i;try{const n=new TextDecoder(t,{fatal:!0}),r=stringToBytes(i);i=n.decode(r);e=!1}catch{}}return i}function fixupEncoding(t){if(e&&/[\x80-\xff]/.test(t)){t=textdecode("utf-8",t);e&&(t=textdecode("iso-8859-1",t))}return t}function rfc2616unquote(t){if(t.startsWith('"')){const e=t.slice(1).split('\\"');for(let t=0;t<e.length;++t){const i=e[t].indexOf('"');if(-1!==i){e[t]=e[t].slice(0,i);e.length=t+1}e[t]=e[t].replaceAll(/\\(.)/g,"$1")}t=e.join('"')}return t}function rfc5987decode(t){const e=t.indexOf("'");return-1===e?t:textdecode(t.slice(0,e),t.slice(e+1).replace(/^[^']*'/,""))}function rfc2047decode(t){return!t.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(t)?t:t.replaceAll(/=\?([\w-]*)\?([QB])\?((?:[^?]|\?(?!=))*)\?=/gi,function(t,e,i,n){if("q"===i||"Q"===i)return textdecode(e,n=n.replaceAll("_"," ").replaceAll(/=([0-9a-f]{2})/gi,(t,e)=>String.fromCharCode(parseInt(e,16))));try{n=atob(n)}catch{}return textdecode(e,n)})}return""}(e);if(t.includes("%"))try{t=decodeURIComponent(t)}catch{}if(isPdfFile(t))return t}return null}function createResponseError(t,e){return new ResponseException(`Unexpected server response (${t}) while retrieving PDF "${e.href}".`,t,404===t||0===t&&"file:"===e.protocol)}function ensureResponseOrigin(t,e){if(t!==e)throw new Error(`Expected range response-origin "${t}" to match "${e}".`)}function fetchUrl(t,e,i,n){return fetch(t,{method:"GET",headers:e,signal:n.signal,mode:"cors",credentials:i?"include":"same-origin",redirect:"follow"})}function ensureResponseStatus(t,e){if(200!==t&&206!==t)throw createResponseError(t,e)}function getArrayBuffer(t){if(t instanceof Uint8Array)return t.buffer;if(t instanceof ArrayBuffer)return t;throw new Error(`getArrayBuffer - unexpected data: ${t}`)}class PDFFetchStream extends BasePDFStream{_responseOrigin=null;constructor(t){super(t,PDFFetchStreamReader,PDFFetchStreamRangeReader);const{httpHeaders:e,url:i}=t;util_assert(/https?:/.test(i.protocol),"PDFFetchStream only supports http(s):// URLs.");this.headers=createHeaders(!0,e)}}class PDFFetchStreamReader extends BasePDFStreamReader{_abortController=new AbortController;_reader=null;constructor(t){super(t);const{disableRange:e,disableStream:i,rangeChunkSize:n,url:r,withCredentials:s}=t._source;this._isStreamingSupported=!i;const a=new Headers(t.headers);fetchUrl(r,a,s,this._abortController).then(i=>{t._responseOrigin=getResponseOrigin(i.url);ensureResponseStatus(i.status,r);this._reader=i.body.getReader();const s=i.headers,{contentLength:a,isRangeSupported:o}=validateRangeRequestCapabilities({responseHeaders:s,isHttp:!0,rangeChunkSize:n,disableRange:e});this._contentLength=a;this._isRangeSupported=o;this._filename=extractFilenameFromHeader(s);!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new AbortException("Streaming is disabled."));this._headersCapability.resolve()}).catch(this._headersCapability.reject)}async read(){await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();if(e)return{value:t,done:e};this._loaded+=t.byteLength;this._callOnProgress();return{value:getArrayBuffer(t),done:!1}}cancel(t){this._reader?.cancel(t).catch(()=>{});this._abortController.abort()}}class PDFFetchStreamRangeReader extends BasePDFStreamRangeReader{_abortController=new AbortController;_readCapability=Promise.withResolvers();_reader=null;constructor(t,e,i){super(t,e,i);const{url:n,withCredentials:r}=t._source,s=new Headers(t.headers);s.append("Range",`bytes=${e}-${i-1}`);fetchUrl(n,s,r,this._abortController).then(e=>{ensureResponseOrigin(getResponseOrigin(e.url),t._responseOrigin);ensureResponseStatus(e.status,n);this._reader=e.body.getReader();this._readCapability.resolve()}).catch(this._readCapability.reject);this._readCapability.promise.catch(()=>{})}async read(){await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:{value:getArrayBuffer(t),done:!1}}cancel(t){this._reader?.cancel(t).catch(()=>{});this._abortController.abort()}}function transport_stream_getArrayBuffer(t){return t instanceof Uint8Array&&t.byteLength===t.buffer.byteLength?t.buffer:new Uint8Array(t).buffer}function endRequests(){for(const t of this._requests)t.resolve({value:void 0,done:!0});this._requests.length=0}class PDFDataTransportStream extends BasePDFStream{_progressiveDone=!1;_queuedChunks=[];constructor(t){super(t,PDFDataTransportStreamReader,PDFDataTransportStreamRangeReader);const{pdfDataRangeTransport:e}=t,{initialData:i,progressiveDone:n}=e;if(i?.length>0){const t=transport_stream_getArrayBuffer(i);this._queuedChunks.push(t)}this._progressiveDone=n;e.transportReady(t=>{switch(t.type){case"range":case"progressiveRead":this.#Br(t.begin,t.chunk);break;case"progressiveDone":this._fullReader?.progressiveDone();this._progressiveDone=!0}})}#Br(t,e){const i=transport_stream_getArrayBuffer(e);if(void 0===t)this._fullReader?this._fullReader._enqueue(i):this._queuedChunks.push(i);else{const e=this._rangeReaders.keys().find(e=>e._begin===t);util_assert(e,"#onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.");e._enqueue(i)}}getFullReader(){const t=super.getFullReader();this._queuedChunks=null;return t}getRangeReader(t,e){const i=super.getRangeReader(t,e);if(i){i.onDone=()=>this._rangeReaders.delete(i);this._source.pdfDataRangeTransport.requestDataRange(t,e)}return i}cancelAllRequests(t){super.cancelAllRequests(t);this._source.pdfDataRangeTransport.abort()}}class PDFDataTransportStreamReader extends BasePDFStreamReader{#Lr=endRequests.bind(this);_done=!1;_queuedChunks=null;_requests=[];constructor(t){super(t);const{pdfDataRangeTransport:e,disableRange:i,disableStream:n}=t._source,{length:r,contentDispositionFilename:s}=e;this._queuedChunks=t._queuedChunks||[];for(const t of this._queuedChunks)this._loaded+=t.byteLength;this._done=t._progressiveDone;this._contentLength=r;this._isStreamingSupported=!n;this._isRangeSupported=!i;isPdfFile(s)&&(this._filename=s);this._headersCapability.resolve();const a=this._loaded;Promise.resolve().then(()=>{a>0&&this._loaded===a&&this._callOnProgress()})}_enqueue(t){if(!this._done){if(this._requests.length>0){this._requests.shift().resolve({value:t,done:!1})}else this._queuedChunks.push(t);this._loaded+=t.byteLength;this._callOnProgress()}}async read(){if(this._queuedChunks.length>0){return{value:this._queuedChunks.shift(),done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();this._requests.push(t);return t.promise}cancel(t){this._done=!0;this.#Lr()}progressiveDone(){this._done||=!0;0===this._queuedChunks.length&&this.#Lr()}}class PDFDataTransportStreamRangeReader extends BasePDFStreamRangeReader{#Lr=endRequests.bind(this);onDone=null;_begin=-1;_done=!1;_queuedChunk=null;_requests=[];constructor(t,e,i){super(t,e,i);this._begin=e}_enqueue(t){if(!this._done){if(0===this._requests.length)this._queuedChunk=t;else{this._requests.shift().resolve({value:t,done:!1});this.#Lr()}this._done=!0;this.onDone?.()}}async read(){if(this._queuedChunk){const t=this._queuedChunk;this._queuedChunk=null;return{value:t,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();this._requests.push(t);return t.promise}cancel(t){this._done=!0;this.#Lr();this.onDone?.()}}class PDFNetworkStream extends BasePDFStream{#Nr=new WeakMap;_responseOrigin=null;constructor(t){super(t,PDFNetworkStreamReader,PDFNetworkStreamRangeReader);const{httpHeaders:e,url:i}=t;this.url=i;this.isHttp=/https?:/.test(i.protocol);this.headers=createHeaders(this.isHttp,e)}_request(t){const e=new XMLHttpRequest,i={validateStatus:null,onHeadersReceived:t.onHeadersReceived,onDone:t.onDone,onError:t.onError,onProgress:t.onProgress};this.#Nr.set(e,i);e.open("GET",this.url);e.withCredentials=this._source.withCredentials;for(const[t,i]of this.headers)e.setRequestHeader(t,i);if(this.isHttp&&"begin"in t&&"end"in t){e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`);i.validateStatus=t=>206===t||200===t}else i.validateStatus=t=>200===t;e.responseType="arraybuffer";util_assert(t.onError,"Expected `onError` callback to be provided.");e.onerror=()=>t.onError(e.status);e.onreadystatechange=this.#Ur.bind(this,e);e.onprogress=this.#Hr.bind(this,e);e.send(null);return e}#Hr(t,e){const i=this.#Nr.get(t);i?.onProgress?.(e)}#Ur(t,e){const i=this.#Nr.get(t);if(!i)return;if(t.readyState>=2&&i.onHeadersReceived){i.onHeadersReceived();delete i.onHeadersReceived}if(4!==t.readyState)return;if(!this.#Nr.has(t))return;this.#Nr.delete(t);if(0===t.status&&this.isHttp){i.onError(t.status);return}const n=t.status||200;if(!i.validateStatus(n)){i.onError(t.status);return}const r=function network_getArrayBuffer(t){return"string"!=typeof t?t:stringToBytes(t).buffer}(t.response);if(206===n){const e=t.getResponseHeader("Content-Range");if(/bytes \d+-\d+\/\d+/.test(e))i.onDone(r);else{warn('Missing or invalid "Content-Range" header.');i.onError(0)}}else r?i.onDone(r):i.onError(t.status)}_abortRequest(t){if(this.#Nr.has(t)){this.#Nr.delete(t);t.abort()}}getRangeReader(t,e){const i=super.getRangeReader(t,e);i&&(i.onClosed=()=>this._rangeReaders.delete(i));return i}}class PDFNetworkStreamReader extends BasePDFStreamReader{#Lr=endRequests.bind(this);_cachedChunks=[];_done=!1;_requests=[];_storedError=null;constructor(t){super(t);this._fullRequestXhr=t._request({onHeadersReceived:this.#zr.bind(this),onDone:this.#Gr.bind(this),onError:this.#Wr.bind(this),onProgress:this.#Hr.bind(this)})}#zr(){const t=this._stream,{disableRange:e,rangeChunkSize:i}=t._source,n=this._fullRequestXhr;t._responseOrigin=getResponseOrigin(n.responseURL);const r=n.getAllResponseHeaders(),s=new Headers(r?function trimHeadersEnd(t){let e=t.length;for(;e>0&&" "!==t[e-1]&&/\s/.test(t[e-1]);)e--;return t.slice(0,e)}(r.trimStart()).split(/[\r\n]+/).map(t=>{const[e,...i]=t.split(": ");return[e,i.join(": ")]}):[]),{contentLength:a,isRangeSupported:o}=validateRangeRequestCapabilities({responseHeaders:s,isHttp:t.isHttp,rangeChunkSize:i,disableRange:e});this._contentLength=a;this._isRangeSupported=o;this._filename=extractFilenameFromHeader(s);this._isRangeSupported&&t._abortRequest(n);this._headersCapability.resolve()}#Gr(t){if(this._requests.length>0){this._requests.shift().resolve({value:t,done:!1})}else this._cachedChunks.push(t);this._done=!0;0===this._cachedChunks.length&&this.#Lr()}#Wr(t){this._storedError=createResponseError(t,this._stream.url);this._headersCapability.reject(this._storedError);for(const t of this._requests)t.reject(this._storedError);this._requests.length=0;this._cachedChunks.length=0}#Hr(t){this.onProgress?.({loaded:t.loaded,total:t.lengthComputable?t.total:this._contentLength})}async read(){await this._headersCapability.promise;if(this._storedError)throw this._storedError;if(this._cachedChunks.length>0){return{value:this._cachedChunks.shift(),done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();this._requests.push(t);return t.promise}cancel(t){this._done=!0;this._headersCapability.reject(t);this.#Lr();this._stream._abortRequest(this._fullRequestXhr);this._fullRequestXhr=null}}class PDFNetworkStreamRangeReader extends BasePDFStreamRangeReader{#Lr=endRequests.bind(this);onClosed=null;_done=!1;_queuedChunk=null;_requests=[];_storedError=null;constructor(t,e,i){super(t,e,i);this._requestXhr=t._request({begin:e,end:i,onHeadersReceived:this.#zr.bind(this),onDone:this.#Gr.bind(this),onError:this.#Wr.bind(this),onProgress:null})}#zr(){const t=getResponseOrigin(this._requestXhr?.responseURL);try{ensureResponseOrigin(t,this._stream._responseOrigin)}catch(t){this._storedError=t;this.#Wr(0)}}#Gr(t){if(this._requests.length>0){this._requests.shift().resolve({value:t,done:!1})}else this._queuedChunk=t;this._done=!0;this.#Lr();this.onClosed?.()}#Wr(t){this._storedError??=createResponseError(t,this._stream.url);for(const t of this._requests)t.reject(this._storedError);this._requests.length=0;this._queuedChunk=null}async read(){if(this._storedError)throw this._storedError;if(null!==this._queuedChunk){const t=this._queuedChunk;this._queuedChunk=null;return{value:t,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();this._requests.push(t);return t.promise}cancel(t){this._done=!0;this.#Lr();this._stream._abortRequest(this._requestXhr);this.onClosed?.()}}function getReadableStream(t,e=null){const i=process.getBuiltinModule("fs"),{Readable:n}=process.getBuiltinModule("stream"),r=i.createReadStream(t,e);return n.toWeb(r)}class PDFNodeStream extends BasePDFStream{constructor(t){super(t,PDFNodeStreamReader,PDFNodeStreamRangeReader);const{url:e}=t;util_assert("file:"===e.protocol,"PDFNodeStream only supports file:// URLs.")}}class PDFNodeStreamReader extends BasePDFStreamReader{_reader=null;constructor(t){super(t);const{disableRange:e,disableStream:i,rangeChunkSize:n,url:r}=t._source;this._isStreamingSupported=!i;process.getBuiltinModule("fs/promises").lstat(r).then(t=>{const i=getReadableStream(r);this._reader=i.getReader();const{size:s}=t;this._contentLength=s;this._isRangeSupported=!e&&s>2*n;!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new AbortException("Streaming is disabled."));this._headersCapability.resolve()}).catch(t=>{"ENOENT"===t.code&&(t=createResponseError(0,r));this._headersCapability.reject(t)})}async read(){await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();if(e)return{value:t,done:e};this._loaded+=t.byteLength;this._callOnProgress();return{value:getArrayBuffer(t),done:!1}}cancel(t){this._reader?.cancel(t).catch(()=>{})}}class PDFNodeStreamRangeReader extends BasePDFStreamRangeReader{_readCapability=Promise.withResolvers();_reader=null;constructor(t,e,i){super(t,e,i);const{url:n}=t._source;try{const t=getReadableStream(n,{start:e,end:i-1});this._reader=t.getReader();this._readCapability.resolve()}catch(t){this._readCapability.reject(t)}this._readCapability.promise.catch(()=>{})}async read(){await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:{value:getArrayBuffer(t),done:!1}}cancel(t){this._reader?.cancel(t).catch(()=>{})}}class GlobalWorkerOptions{static#jr=null;static#Vr=[];static#qr="";static#$r="";static get rendererPorts(){return this.#Vr}static set rendererPorts(t){if(!Array.isArray(t)||!t.every(t=>"undefined"!=typeof Worker&&t instanceof Worker))throw new Error("Invalid `rendererPorts` type.");this.#Vr=t}static get rendererSrc(){return this.#qr}static set rendererSrc(t){if("string"!=typeof t)throw new Error("Invalid `rendererSrc` type.");this.#qr=t}static get workerPort(){return this.#jr}static set workerPort(t){if(!("undefined"!=typeof Worker&&t instanceof Worker)&&null!==t)throw new Error("Invalid `workerPort` type.");this.#jr=t}static get workerSrc(){return this.#$r}static set workerSrc(t){if("string"!=typeof t)throw new Error("Invalid `workerSrc` type.");this.#$r=t}}class Metadata{#Xr;#Kr;constructor({parsedData:t,rawData:e}){this.#Xr=t;this.#Kr=e}getRaw(){return this.#Kr}get(t){return this.#Xr.get(t)??null}[Symbol.iterator](){return this.#Xr.entries()}}class CSS_FONT_INFO{static strings=["fontFamily","fontWeight","italicAngle"]}class SYSTEM_FONT_INFO{static strings=["css","loadedName","baseFontName","src"]}class FONT_INFO{static bools=["black","bold","disableFontFace","fontExtraProperties","isInvalidPDFjsFont","isType3Font","italic","missingFile","remeasure","vertical"];static strings=["fallbackName","loadedName"];static OFFSET_BBOX=Math.ceil(2*this.bools.length/8);static OFFSET_FONT_MATRIX=this.OFFSET_BBOX+1+8;static OFFSET_STRINGS=this.OFFSET_FONT_MATRIX+1+48}class PATTERN_INFO{static KIND=0;static HAS_BBOX=1;static HAS_BACKGROUND=2;static SHADING_TYPE=3;static N_COORD=4;static N_COLOR=8;static N_STOP=12;static N_FIGURES=16}class InfoUtils{static get decoder(){return util_shadow(this,"decoder",new TextDecoder)}static get encoder(){return util_shadow(this,"encoder",new TextEncoder)}}function readString(t,e,i,n=0){const{decoder:r}=InfoUtils;for(let t=0;t<i;t++)n+=e.getUint32(n)+4;const s=e.getUint32(n);return r.decode(new Uint8Array(t,n+4,s))}class CssFontInfo{#Yr;#Jr;constructor(t){this.#Yr=t;this.#Jr=new DataView(t)}#Qr(t){util_assert(t<CSS_FONT_INFO.strings.length,"Invalid string index");return readString(this.#Yr,this.#Jr,t)}get fontFamily(){return util_shadow(this,"fontFamily",this.#Qr(0))}get fontWeight(){return util_shadow(this,"fontWeight",this.#Qr(1))}get italicAngle(){return util_shadow(this,"italicAngle",this.#Qr(2))}}class SystemFontInfo{#Yr;#Jr;constructor(t){this.#Yr=t;this.#Jr=new DataView(t)}#Qr(t){util_assert(t<SYSTEM_FONT_INFO.strings.length,"Invalid string index");return readString(this.#Yr,this.#Jr,t,4)}get css(){return util_shadow(this,"css",this.#Qr(0))}get loadedName(){return util_shadow(this,"loadedName",this.#Qr(1))}get baseFontName(){return util_shadow(this,"baseFontName",this.#Qr(2))}get src(){return util_shadow(this,"src",this.#Qr(3))}get style(){let t=0;t+=4+this.#Jr.getUint32(t);return util_shadow(this,"style",{style:readString(this.#Yr,this.#Jr,0,t),weight:readString(this.#Yr,this.#Jr,1,t)})}}class FontInfo{#Yr;#Jr;constructor(t){this.#Yr=t;this.#Jr=new DataView(t)}#Zr(t){util_assert(t<FONT_INFO.bools.length,"Invalid boolean index");const e=Math.floor(t/4),i=2*t%8,n=this.#Jr.getUint8(e)>>i&3;return 0===n?void 0:2===n}get black(){return util_shadow(this,"black",this.#Zr(0))}get bold(){return util_shadow(this,"bold",this.#Zr(1))}get disableFontFace(){return util_shadow(this,"disableFontFace",this.#Zr(2))}get fontExtraProperties(){return util_shadow(this,"fontExtraProperties",this.#Zr(3))}get isInvalidPDFjsFont(){return util_shadow(this,"isInvalidPDFjsFont",this.#Zr(4))}get isType3Font(){return util_shadow(this,"isType3Font",this.#Zr(5))}get italic(){return util_shadow(this,"italic",this.#Zr(6))}get missingFile(){return util_shadow(this,"missingFile",this.#Zr(7))}get remeasure(){return util_shadow(this,"remeasure",this.#Zr(8))}get vertical(){return util_shadow(this,"vertical",this.#Zr(9))}#ts(t,e,i,n){const r=this.#Jr.getUint8(t++);if(0===r)return;util_assert(r===e,"Invalid array length.");const s=new Array(r);for(let e=0;e<r;e++){s[e]=this.#Jr[i](t,!0);t+=n}return s}get bbox(){return util_shadow(this,"bbox",this.#ts(FONT_INFO.OFFSET_BBOX,4,"getInt16",2))}get fontMatrix(){return util_shadow(this,"fontMatrix",this.#ts(FONT_INFO.OFFSET_FONT_MATRIX,6,"getFloat64",8))}#Qr(t){util_assert(t<FONT_INFO.strings.length,"Invalid string index");return readString(this.#Yr,this.#Jr,t,FONT_INFO.OFFSET_STRINGS+4)}get fallbackName(){return util_shadow(this,"fallbackName",this.#Qr(0))}get loadedName(){return util_shadow(this,"loadedName",this.#Qr(1))}#es(t){let e=FONT_INFO.OFFSET_STRINGS;for(let i=0;i<=t;i++)e+=4+this.#Jr.getUint32(e);return{offset:e,length:this.#Jr.getUint32(e)}}get data(){const{offset:t,length:e}=this.#es(2);return e?new Uint8Array(this.#Yr,t+4,e):void 0}clearData(){const{offset:t,length:e}=this.#es(2);if(e){this.#Jr.setUint32(t,0);this.#Yr=new Uint8Array(this.#Yr,0,t+4).slice().buffer;this.#Jr=new DataView(this.#Yr)}}get cssFontInfo(){const{offset:t,length:e}=this.#es(1);let i=null;if(e){const n=new Uint8Array(this.#Yr,t+4,e).slice();i=new CssFontInfo(n.buffer)}return util_shadow(this,"cssFontInfo",i)}get systemFontInfo(){const{offset:t,length:e}=this.#es(0);let i=null;if(e){const n=new Uint8Array(this.#Yr,t+4,e).slice();i=new SystemFontInfo(n.buffer)}return util_shadow(this,"systemFontInfo",i)}}class PatternInfo{constructor(t){this.buffer=t;this.view=new DataView(t);this.data=new Uint8Array(t)}getIR(){const t=this.view,e=this.data[PATTERN_INFO.KIND],i=!!this.data[PATTERN_INFO.HAS_BBOX],n=!!this.data[PATTERN_INFO.HAS_BACKGROUND],r=t.getUint32(PATTERN_INFO.N_COORD,!0),s=t.getUint32(PATTERN_INFO.N_COLOR,!0),a=t.getUint32(PATTERN_INFO.N_STOP,!0);let o=20;const l=new Float32Array(this.buffer,o,2*r);o+=8*r;const c=new Uint8Array(this.buffer,o,4*s);o+=4*s;const h=[];for(let e=0;e<a;++e){const e=t.getFloat32(o,!0);o+=4;const i=t.getUint32(o,!0);o+=4;h.push([e,`#${i.toString(16).padStart(6,"0")}`])}let d=null;if(i){d=[];for(let e=0;e<4;++e){d.push(t.getFloat32(o,!0));o+=4}}let u=null;if(n){u=new Uint8Array(this.buffer,o,3);o+=3}if(1===e)return["RadialAxial","axial",d,h,[l[0],l[1]],[l[2],l[3]],null,null];if(2===e)return["RadialAxial","radial",d,h,[l[0],l[1]],[l[3],l[4]],l[2],l[5]];if(3===e){const t=this.data[PATTERN_INFO.SHADING_TYPE];let e=null;if(l.length>0){e=pi.slice();for(let t=0,i=l.length;t<i;t+=2)Util.pointBoundingBox(l[t],l[t+1],e)}return["Mesh",t,l,c,r,e,d,u]}throw new Error(`Unsupported pattern kind: ${e}`)}}class FontPathInfo{#Yr;constructor(t){this.#Yr=t}get path(){return FeatureTest.isFloat16ArraySupported?new Float16Array(this.#Yr):new Float32Array(this.#Yr)}}const Xn=Symbol("INITIAL_DATA"),dataObj=()=>({...Promise.withResolvers(),data:Xn});class PDFObjects{#is=new Map;get(t,e=null,i=null){if(e){const n=this.#is.getOrInsertComputed(t,dataObj);n.promise.then(()=>e(n.data),i);return null}const n=this.#is.get(t);if(!n||n.data===Xn)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return n.data}has(t){const e=this.#is.get(t);return!!e&&e.data!==Xn}delete(t){const e=this.#is.get(t);if(!e||e.data===Xn)return!1;this.#is.delete(t);return!0}resolve(t,e=null){const i=this.#is.getOrInsertComputed(t,dataObj);if(i.data!==Xn)throw new Error(`Object already resolved ${t}.`);i.data=e;i.resolve()}reject(t,e){const i=this.#is.getOrInsertComputed(t,dataObj);if(i.data===Xn){i.promise.catch(()=>{});i.reject(e)}}clear(){for(const{data:t}of this.#is.values())t?.bitmap?.close();this.#is.clear()}*[Symbol.iterator](){for(const[t,{data:e}]of this.#is)e!==Xn&&(yield[t,e])}}class ObjectHandler{constructor({messageHandler:t,commonObjs:e,fontLoader:i,pageCache:n,pdfBug:r=!1,shouldCreatePageObjs:s=!1}){this.messageHandler=t;this.commonObjs=e;this.fontLoader=i;this.pageCache=n;this.pdfBug=r;this.shouldCreatePageObjs=s}resolveCommonObject(t,e,i){if("CopyLocalImage"===e){const{imageRef:e}=i;util_assert(e,"The imageRef must be defined.");for(const i of this.pageCache.values()){const n=i.objs||i;for(const[,i]of n){if(i?.ref!==e)continue;if(!i.dataLen)return null;const n=structuredClone(i);this.commonObjs.resolve(t,n);return i.dataLen}}return null}switch(e){case"Font":if("error"in i){const e=i.error;warn(`Error during font loading: ${e}`);this.commonObjs.resolve(t,e);break}const n=new FontInfo(i.buffer),r=this.pdfBug&&globalThis.FontInspector?.enabled?(t,e)=>globalThis.FontInspector.fontAdded(t,e):null,s=new FontFaceObject(n,r,i.charProcOperatorList,i.extra);this.fontLoader.bind(s).catch(()=>this.messageHandler.sendWithPromise("FontFallback",{id:t}).catch(e=>{warn(`FontFallback failed for "${t}": ${e}`)})).finally(()=>{s.fontExtraProperties||s.clearData();this.commonObjs.resolve(t,s)});break;case"FontPath":this.commonObjs.resolve(t,new FontPathInfo(i));break;case"Image":this.commonObjs.resolve(t,i);break;case"Pattern":const a=new PatternInfo(i);this.commonObjs.resolve(t,a.getIR());break;default:throw new Error(`Got unknown common object type ${e}`)}return null}resolveObject(t,e,i,n){let r=this.pageCache.get(e);if(!r){if(!this.shouldCreatePageObjs)return!1;r=new PDFObjects;this.pageCache.set(e,r)}const s=r.objs||r;if(s.has(t))return!1;if(0===r._intentStates?.size){n?.bitmap?.close();return!1}switch(i){case"Image":case"Pattern":s.resolve(t,n);return!0;default:throw new Error(`Got unknown object type ${i}`)}}}const Kn=Symbol("INTERNAL");class OptionalContentGroup{#ns=!1;#rs=!1;#ss=!1;#as=!0;constructor(t,{name:e,intent:i,usage:n,rbGroups:r}){this.#ns=!!(t&yi);this.#rs=!!(t&wi);this.name=e;this.intent=i;this.usage=n;this.rbGroups=r}get visible(){if(this.#ss)return this.#as;if(!this.#as)return!1;const{print:t,view:e}=this.usage;return this.#ns?"OFF"!==e?.viewState:!this.#rs||"OFF"!==t?.printState}_setVisible(t,e,i=!1){t!==Kn&&unreachable("Internal method `_setVisible` called.");this.#ss=i;this.#as=e}get serializable(){return{userSet:this.#ss,visible:this.#as}}}class OptionalContentConfig{#os=null;#ls=new Map;#cs=null;#hs=null;#ds;creator=null;name=null;constructor(t,e=yi,i=null){this.#ds=t;this.renderingIntent=e;if(null!==t){this.name=t.name;this.creator=t.creator;this.#hs=t.order;for(const i of t.groups)this.#ls.set(i.id,new OptionalContentGroup(e,i));if(i){i.size!==this.#ls.size&&unreachable("Incorrect serialized groupState.");for(const[t,e]of i)this.#ls.get(t)._setVisible(Kn,e.visible,e.userSet)}else{if("OFF"===t.baseState)for(const t of this.#ls.values())t._setVisible(Kn,!1);for(const e of t.on)this.#ls.get(e)._setVisible(Kn,!0);for(const e of t.off)this.#ls.get(e)._setVisible(Kn,!1)}this.#cs=this.getHash()}}#us(t){const e=t.length;if(e<2)return!0;const i=t[0];for(let n=1;n<e;n++){const e=t[n];let r;if(Array.isArray(e))r=this.#us(e);else{if(!this.#ls.has(e)){warn(`Optional content group not found: ${e}`);return!0}r=this.#ls.get(e).visible}switch(i){case"And":if(!r)return!1;break;case"Or":if(r)return!0;break;case"Not":return!r;default:return!0}}return"And"===i}isVisible(t){if(0===this.#ls.size)return!0;if(!t){info("Optional content group not defined.");return!0}if("OCG"===t.type){if(!this.#ls.has(t.id)){warn(`Optional content group not found: ${t.id}`);return!0}return this.#ls.get(t.id).visible}if("OCMD"===t.type){if(t.expression)return this.#us(t.expression);if(!t.policy||"AnyOn"===t.policy){for(const e of t.ids){if(!this.#ls.has(e)){warn(`Optional content group not found: ${e}`);return!0}if(this.#ls.get(e).visible)return!0}return!1}if("AllOn"===t.policy){for(const e of t.ids){if(!this.#ls.has(e)){warn(`Optional content group not found: ${e}`);return!0}if(!this.#ls.get(e).visible)return!1}return!0}if("AnyOff"===t.policy){for(const e of t.ids){if(!this.#ls.has(e)){warn(`Optional content group not found: ${e}`);return!0}if(!this.#ls.get(e).visible)return!0}return!1}if("AllOff"===t.policy){for(const e of t.ids){if(!this.#ls.has(e)){warn(`Optional content group not found: ${e}`);return!0}if(this.#ls.get(e).visible)return!1}return!0}warn(`Unknown optional content policy ${t.policy}.`);return!0}warn(`Unknown group type ${t.type}.`);return!0}setVisibility(t,e=!0,i=!0){const n=this.#ls.get(t);if(n){if(i&&e&&n.rbGroups.length)for(const e of n.rbGroups)for(const i of e)i!==t&&this.#ls.get(i)?._setVisible(Kn,!1,!0);n._setVisible(Kn,!!e,!0);this.#os=null}else warn(`Optional content group not found: ${t}`)}setOCGState({state:t,preserveRB:e}){let i;for(const n of t){switch(n){case"ON":case"OFF":case"Toggle":i=n;continue}const t=this.#ls.get(n);if(t)switch(i){case"ON":this.setVisibility(n,!0,e);break;case"OFF":this.setVisibility(n,!1,e);break;case"Toggle":this.setVisibility(n,!t.visible,e)}}this.#os=null}get hasInitialVisibility(){return null===this.#cs||this.getHash()===this.#cs}getOrder(){return this.#ls.size?this.#hs?this.#hs.slice():[...this.#ls.keys()]:null}getGroup(t){return this.#ls.get(t)||null}getHash(){if(null!==this.#os)return this.#os;const t=new MurmurHash3_64;for(const[e,i]of this.#ls)t.update(`${e}:${i.visible}`);return this.#os=t.hexdigest()}[Symbol.iterator](){return this.#ls.entries()}get serializable(){const t=new Map;for(const[e,i]of this.#ls)t.set(e,i.serializable);return{data:this.#ds,renderingIntent:this.renderingIntent,groupState:t}}static fromSerializable({data:t,renderingIntent:e,groupState:i}){return new OptionalContentConfig(t,e,i)}}class PagesMapper{#ps=null;#gs=null;#ms=0;#fs=0;#bs=null;#ys=null;get pagesNumber(){return this.#ms}set pagesNumber(t){if(this.#ms!==t){this.#ms=this.#fs=t;this.#ps=null;this.#gs=null}}#ws(){if(this.#ps)return;const t=this.#ms,e=this.#ps=new Uint32Array(t);for(let i=0;i<t;i++)e[i]=i+1;this.#gs=new Int32Array(e)}#vs(){const t=new Map,e=this.#ps;for(let i=0,n=this.#ms;i<n;i++){const n=e[i],r=t.get(n);r?r.push(i+1):t.set(n,[i+1])}return t}movePages(t,e,i){this.#ws();const n=this.#ps,r=e.length,s=new Uint32Array(r);let a=0;for(let t=0;t<r;t++){const r=e[t]-1;s[t]=n[r];r<i&&a++}const o=this.#ms,l=o-r,c=new Int32Array(o),h=MathClamp(i-a,0,l);for(let e=0,i=0;e<o;e++)if(!t.has(e+1)){n[i]=n[e];c[i++]=e+1}n.copyWithin(h+r,h,l);n.set(s,h);c.copyWithin(h+r,h,l);c.set(e,h);this.#gs=c;o===this.#fs&&n.every((t,e)=>t===e+1)&&(this.#ps=null)}deletePages(t){this.#ws();const e=this.#ps,i=this.#vs();this.#ys={pageNumberToId:e.slice(),pagesNumber:this.#ms,prevPageNumbers:this.#gs.slice()};const n=this.#ms-t.length;this.#ms=n;const r=this.#ps=new Uint32Array(n);this.#gs=new Int32Array(n);let s=0,a=0;for(const i of t){const t=i-1;if(t!==s){r.set(e.subarray(s,t),a);a+=t-s}s=t+1}s<e.length&&r.set(e.subarray(s),a);this.#_s(i,new Set(t))}cancelDelete(){if(this.#ys){this.#ps=this.#ys.pageNumberToId;this.#ms=this.#ys.pagesNumber;this.#gs=this.#ys.prevPageNumbers;this.#ys=null}}cleanSavedData(){this.#ys=null}copyPages(t){this.#ws();this.#bs={pageNumbers:t,pageIds:t.map(t=>this.#ps[t-1])}}cancelCopy(){this.#bs=null}pastePages(t){this.#ws();const e=this.#ps,i=this.#vs(),{pageNumbers:n,pageIds:r}=this.#bs,s=this.#ms+n.length;this.#ms=s;const a=this.#ps=new Uint32Array(s);this.#gs=new Int32Array(s);a.set(e.subarray(0,t),0);a.set(r,t);a.set(e.subarray(t),t+n.length);this.#_s(i,null,t,n);this.#bs=null}#_s(t,e=null,i=-1,n=null){const r=this.#gs,s=this.#ps,a=i+(n?.length??0),o=new Map;for(let l=0,c=this.#ms;l<c;l++){if(l>=i&&l<a){r[l]=-n[l-i];continue}const c=s[l],h=t.get(c);let d=o.get(c)||0;if(e&&h)for(;d<h.length&&e.has(h[d]);)d++;r[l]=h?.[d];o.set(c,d+1)}}hasBeenAltered(){return null!==this.#ps}#As(t=null){if(!this.#ps)return null;const e=new Int32Array(this.#ms).fill(-1),i=new Map;if(t)for(const n of t){const t=this.getPageId(n),r=i.get(t)??0;i.set(t,r+1);e[n-1]=r}else for(let t=0,n=this.#ms;t<n;t++){const n=this.#ps[t],r=i.get(n)??0;i.set(n,r+1);e[t]=r}return e}getPageMappingForSaving(t=null,e=this.#As()){t??=this.#vs();let i=0;for(const e of t.values())i=Math.max(i,e.length);const n=new Array(i);for(let t=0;t<i;t++)n[t]={document:null,pageIndices:[],includePages:[]};for(const[e,i]of t)for(let t=0,r=i.length;t<r;t++)n[t].includePages.push([e-1,i[t]-1]);for(const{includePages:t,pageIndices:e}of n){t.sort((t,e)=>t[0]-e[0]);for(let i=0,n=t.length;i<n;i++){e.push(t[i][1]);t[i]=t[i][0]}}return{pageInfos:n,copyLevels:e}}extractPages(t){t=Array.from(t).sort((t,e)=>t-e);const e=new Map;for(let i=0,n=t.length;i<n;i++){const n=this.getPageId(t[i]);e.getOrInsertComputed(n,makeArr).push(i+1)}return this.getPageMappingForSaving(e,this.#As(t))}getPrevPageNumber(t){return this.#gs?.[t-1]??0}getPageNumber(t){if(!this.#ps)return t;const e=this.#ps;for(let i=0,n=this.#ms;i<n;i++)if(e[i]===t)return i+1;return 0}getPageId(t){return this.#ps?.[t-1]??t}getMapping(){return this.#ps?.subarray(0,this.pagesNumber)}}function closeFrame({bitmap:t,annotationBitmaps:e}){t?.close();if(e)for(const[,,t]of e)t.close()}class WorkerRenderTask{#xs;#Cs=!1;#Es;#Ss;#Ts=0;#S;#ks;#Wr;#Ps;#Ms;#Ds;#Is;imageCoordinates=null;recordedBBoxes=null;constructor({rendererWorker:t,renderTasks:e,canvas:i,canvasFactory:n,annotationCanvasMap:r,operatorListState:s,initParams:a,onFrame:o,onError:l}){this.#Ds=t;this.#Is=e;this.#Es=i;this.#Ss=n;this.#xs=r;this.#Ms=s;this.#ks=a;this.#S=a.renderTaskId;this.#Ps=o;this.#Wr=l}async initialize(t,e){try{await this.#Ds.promise}catch{return!1}if(!this.#Ds.messageHandler||this.#Cs)return!1;try{await this.#Ds.sendWithPromise("InitializeGraphics",{...this.#ks,width:this.#Es.width,height:this.#Es.height,transparency:t,optionalContentConfig:e.serializable})}catch(t){this.#Cs||warn(`Failed to initialize graphics in renderer worker: ${t.message}. Falling back to main-thread rendering.`);return!1}this.#Cs||this.#Is.set(this.#S,this);return!0}async executeOperatorList(t,e,i){const n=this.#Ds.messageHandler;if(!n)throw new Error("Renderer worker was destroyed during rendering.");const{lastChunk:r}=t,s=t.argsArray.length,a=this.#Ms;if(a.sentLength<s){const e=a.sentLength;n.send("AppendOperatorList",{pageProxyId:this.#ks.pageProxyId,operatorListId:a.id,fnArray:t.fnArray.slice(e,s),argsArray:t.argsArray.slice(e,s)});a.sentLength=s}let o=null;if(i&&this.#Ts<s){const e=this.#Ts;o=new Uint8Array(s-e);for(let n=e;n<s;n++)o[n-e]=i(n,t)?1:0;this.#Ts=s}const l=await this.#Ds.sendWithPromise("ExecuteOperatorList",{renderTaskId:this.#S,operatorListIdx:e,operatorListLength:s,operationsFilterMask:o,lastChunk:r}).catch(t=>{if(!this.#Cs)throw t;return{operatorListIdx:e,aborted:!0}});if(l.aborted&&!this.#Cs)throw new Error("Render task was aborted in the renderer worker.");if(r&&l.operatorListIdx===s){this.#Is.delete(this.#S);const{recordedBBoxesBuffer:t,imageCoordinates:e}=l;t&&(this.recordedBBoxes=BBoxReader.fromBuffer(t));this.imageCoordinates=e??null}return l.operatorListIdx}cancel(){this.#Cs=!0;this.#Is.delete(this.#S);this.#Ds.messageHandler?.send("CleanupRenderTask",{renderTaskId:this.#S})}drawFrame(t){try{if(t.bitmap){this.#Ss.getNoAlphaContext(this.#Es).drawImage(t.bitmap,0,0)}t.annotationBitmaps&&this.#Fs(t.annotationBitmaps)}catch(t){this.#Wr(t);return}finally{closeFrame(t)}this.#Ps()}#Fs(t){const e=this.#xs,i=new Set;for(const[n,r,s]of t){const{canvas:t,context:a}=this.#Ss.create(s.width,s.height);a.drawImage(s,0,0);if(r){setAnnotationCanvasName(t,r);if(i.has(n))e.get(n).push(t);else{i.add(n);e.set(n,[t])}}else e.set(n,t)}}}class RendererWorker{#Os=Promise.withResolvers();#hn;#Rs;#Bs=null;#Ls=0;#Ns=new WeakMap;#Us=[];#Nr=new Set;#jr=null;#Hs=null;#zs=0;#Is=new Map;#Gs=null;#Ws=null;#js=null;static#Vs=0;static#qs=new WeakSet;destroyed=!1;constructor({port:t=null,verbosity:e=getVerbosityLevel(),enableHWA:i=!1,enableWebGPU:n=!1}={}){this.verbosity=e;this.#hn=i;this.#Rs=n;t?this.#$s(t):this.#Xs()}static get isAvailable(){return(!!GlobalWorkerOptions.rendererSrc||GlobalWorkerOptions.rendererPorts.length>0)&&"undefined"!=typeof Worker&&FeatureTest.isOffscreenCanvasSupported&&!!globalThis.document?.fonts}get promise(){return this.#Os.promise}get messageHandler(){return this.#Bs}get port(){return this.#jr}#Ks(){this.#Bs.on("RenderFrame",t=>{const e=this.#Is.get(t.renderTaskId);e?e.drawFrame(t):closeFrame(t)});this.#Os.resolve();this.#Bs.send("configure",{verbosity:this.verbosity,enableHWA:this.#hn,enableWebGPU:this.#Rs});const t=this.#Us;this.#Us=null;for(const e of t)e()}#Ys(t){this.#Us=null;this.#Os.reject(t)}#$s(t){RendererWorker.#qs.add(t);this.#jr=t;const e=RendererWorker.#Vs++,i=`main${e}`,n=`renderer${e}`;this.#Hs={sourceName:i,targetName:n};const r=new MessageHandler("main","renderer",t);r.send("Connect",{sourceName:n,targetName:i});r.destroy();this.#Js(t,new MessageHandler(i,n,t),!0)}#Xs(){try{const{rendererSrc:t}=GlobalWorkerOptions;if(!t)throw new Error('No "GlobalWorkerOptions.rendererSrc" specified.');const e=new Worker(getWorkerSrc(t),{type:"module"});this.#Js(e,new MessageHandler("main","renderer",e),!1)}catch(t){this.#Ys(t)}}#Js(t,e,i){let n=null;const terminateEarly=s=>{this.#Gs=null;clearTimeout(n);r.abort();e.destroy();i?this.#jr=null:t.terminate();this.#Ys(new Error(`Renderer worker failed to initialize: "${s?.message??s}".`))};this.#Gs=terminateEarly;const r=new AbortController,onError=(t,e)=>{if(this.#Bs){t.preventDefault();warn(`Renderer worker failed: "${e}". Falling back to main-thread rendering.`);this.destroy()}else terminateEarly(e)};t.addEventListener("error",t=>onError(t,t.error?.message??t.message),{signal:r.signal});t.addEventListener("messageerror",t=>onError(t,"Cannot deserialize a message."),{signal:r.signal});i&&(n=setTimeout(()=>terminateEarly("Connection timed out."),5e3));e.on("ready",s=>{if(!(s?.testObj instanceof Uint8Array)){terminateEarly("TypedArray transfer test failed.");return}const a="6.5.438";if(a===s.workerVersion){this.#Gs=null;clearTimeout(n);this.#Bs=e;i||(this.#Ws=t);this.#js=r;this.#Ks()}else terminateEarly(`The API version "${a}" does not match the Worker version "${s.workerVersion}".`)})}destroy(){this.destroyed=!0;if(this.#jr){if(this.#Bs){this.#Qs(this.#jr);this.#Bs.send("Disconnect",null)}RendererWorker.#qs.delete(this.#jr);this.#jr=null}this.#Gs?.("Worker was destroyed.");this.#js?.abort();this.#js=null;this.#Ws?.terminate();this.#Ws=null;this.#Bs?.destroy();this.#Bs=null;for(const t of this.#Nr)t(new Error("Renderer worker was destroyed."));this.#Nr.clear()}#Qs(t){const{sourceName:e,targetName:i}=this.#Hs,n=new AbortController,r=setTimeout(()=>n.abort(),5e3);t.addEventListener("message",({data:t})=>{if(t?.targetName===e&&t.sourceName===i)if("RenderFrame"===t.action)closeFrame(t.data);else if("Disconnected"===t.action){clearTimeout(r);n.abort()}},{signal:n.signal})}static create({ports:t=[],...e}={}){const i=t.find(t=>!this.#qs.has(t))??null;!i&&t.length>0&&warn("RendererWorker.create - no unused `rendererPorts` available, falling back to `rendererSrc`.");return new RendererWorker({...e,port:i})}sendWithPromise(t,e){const i=this.#Bs;if(!i)return Promise.reject(new Error("Renderer worker was destroyed."));const{promise:n,resolve:r,reject:s}=Promise.withResolvers();this.#Nr.add(s);i.sendWithPromise(t,e).then(r,s);return n.finally(()=>{this.#Nr.delete(s)})}#Zs(t,e){this.#Us?this.#Us.push(()=>this.#Zs(t,e)):this.#Bs?.send(t,e)}#ta(t,e,i,n,r=!1){try{if(this.#Us){const s=r?structuredClone(e):e;this.#Us.push(()=>this.#ta(t,s,i,n));return}this.#Bs?.send(t,e)}catch(e){warn(`RendererWorker - failed to send "${t}": ${e}`);this.#Zs("objFailed",{id:i,pageProxyId:n,reason:e.message})}}sendCommonObj(t,e,i){this.#ta("commonobj",[t,e,i],t,null,"Font"===e)}sendObj(t,e,i,n){this.#ta("obj",[t,e,i,n],t,e)}cleanup(t){this.#Zs("Cleanup",{keepLoadedFonts:t})}cleanupPage(t){this.#Zs("cleanupPage",{pageProxyId:t})}createRenderTask({pageProxyId:t,operatorList:e,params:i,pageColors:n,canvasFactory:r,annotationCanvasMap:s,onFrame:a,onError:o}){const{canvas:l,canvasContext:c,background:h}=i;if(!this.#Bs&&!this.#Us||c||h&&"string"!=typeof h||n||i.recordForDebugger)return null;const d=this.#Ns.getOrInsertComputed(e,()=>({id:this.#Ls++,sentLength:0}));return new WorkerRenderTask({rendererWorker:this,renderTasks:this.#Is,canvas:l,canvasFactory:r,annotationCanvasMap:s,operatorListState:d,initParams:{pageProxyId:t,operatorListId:d.id,renderTaskId:this.#zs++,hasAnnotationCanvasMap:!!s,recordOperations:i.recordOperations,recordImages:i.recordImages,partialFrames:i.partialFrames,transform:i.transform,viewport:i.viewport,background:h,pixelRatio:OutputScale.pixelRatio},onFrame:a,onError:o})}}class TextLayer{#Os=Promise.withResolvers();#Pt=null;#ea=!1;#ia=!!globalThis.FontInspector?.enabled;#na=null;#ra=null;#sa=null;#aa=0;#oa=0;#la=OutputScale.pixelRatio;#ca=null;#ha=null;#da=0;#ua=0;#pa=Object.create(null);#ga=[];#ma=null;#fa=[];#ba=null;static#ya=new Map;static#wa=new Map;static#va=new WeakMap;static#_a=null;static#Aa=new Set;constructor({textContentSource:t,images:e,container:i,viewport:n}){if(t instanceof ReadableStream)this.#ma=t;else{if("object"!=typeof t)throw new Error('No "textContentSource" parameter specified.');this.#ma=new ReadableStream({start(e){e.enqueue(t);e.close()}})}this.#Pt=this.#ha=i;this.#na=e;this.#ua=n.scale*this.#la;this.#da=n.rotation;this.#sa={div:null,properties:null,ctx:null};const{pageWidth:r,pageHeight:s,pageX:a,pageY:o}=n.rawDims;this.#ba=[1,0,0,-1,-a,o+s];this.#oa=r;this.#aa=s;TextLayer.#xa();i.style.setProperty("--min-font-size",TextLayer.#_a);setLayerDimensions(i,n);this.#Os.promise.finally(()=>{TextLayer.#Aa.delete(this);this.#sa=null;this.#pa=null}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=FeatureTest.platform;return util_shadow(this,"fontFamilyMap",new Map([["sans-serif",(t&&e?"Calibri, ":"")+"sans-serif"],["monospace",(t&&e?"Lucida Console, ":"")+"monospace"]]))}render(){this.#na&&this.#Pt.append(this.#na.render());const pump=()=>{this.#ca.read().then(({value:t,done:e})=>{if(e)this.#Os.resolve();else{this.#ra??=t.lang;Object.assign(this.#pa,t.styles);this.#Ca(t.items);pump()}},this.#Os.reject)};this.#ca=this.#ma.getReader();TextLayer.#Aa.add(this);pump();return this.#Os.promise}update({viewport:t}){const e=t.scale*OutputScale.pixelRatio,i=t.rotation;if(i!==this.#da){this.#da=i;setLayerDimensions(this.#ha,{rotation:i})}if(e!==this.#ua){this.#ua=e;this.#la=OutputScale.pixelRatio}}cancel(){const t=new AbortException("TextLayer task cancelled.");this.#ca?.cancel(t).catch(()=>{});this.#ca=null;this.#Os.reject(t)}get textDivs(){return this.#fa}get textContentItemsStr(){return this.#ga}#Ca(t){if(this.#ea)return;this.#sa.ctx??=TextLayer.#Ea(this.#ra);const e=this.#fa,i=this.#ga;for(const n of t){if(e.length>1e5){warn("Ignoring additional textDivs for performance reasons.");this.#ea=!0;return}if(void 0!==n.str){i.push(n.str);this.#Sa(n)}else if("beginMarkedContentProps"===n.type||"beginMarkedContent"===n.type){const t=this.#Pt;this.#Pt=document.createElement("span");this.#Pt.classList.add("markedContent");n.id&&this.#Pt.setAttribute("id",n.id);"Artifact"===n.tag&&(this.#Pt.ariaHidden=!0);t.append(this.#Pt)}else"endMarkedContent"===n.type&&(this.#Pt=this.#Pt.parentNode)}}#Sa(t){const e=document.createElement("span"),i={angle:0,canvasWidth:0,hasText:""!==t.str,hasEOL:t.hasEOL,fontSize:0};this.#fa.push(e);const n=Util.transform(this.#ba,t.transform);let r=Math.atan2(n[1],n[0]);const s=this.#pa[t.fontName];s.vertical&&(r+=Math.PI/2);let a=this.#ia&&s.fontSubstitution||s.fontFamily;a=TextLayer.fontFamilyMap.get(a)||a;const o=Math.hypot(n[2],n[3]),l=o*TextLayer.#Ta(a,s,this.#ra);let c,h;if(0===r){c=n[4];h=n[5]-l}else{c=n[4]+l*Math.sin(r);h=n[5]-l*Math.cos(r)}const d=e.style;d.left=`${(100*c/this.#oa).toFixed(2)}%`;d.top=`${(100*h/this.#aa).toFixed(2)}%`;const u=Math.round(100*o)/100;d.setProperty("--font-height",`${u}px`);d.fontFamily=a;i.fontSize=u;e.setAttribute("role","presentation");e.textContent=t.str;e.dir=t.dir;this.#ia&&(e.dataset.fontName=s.fontSubstitutionLoadedName||t.fontName);0!==r&&(i.angle=r*(180/Math.PI));let p=!1;if(t.str.length>1)p=!0;else if(" "!==t.str&&t.transform[0]!==t.transform[3]){const e=Math.abs(t.transform[0]),i=Math.abs(t.transform[3]);e!==i&&Math.max(e,i)/Math.min(e,i)>1.5&&(p=!0)}p&&(i.canvasWidth=s.vertical?t.height:t.width);this.#sa.div=e;this.#sa.properties=i;this.#ka(this.#sa);i.hasText&&this.#Pt.append(e);if(i.hasEOL){const t=document.createElement("br");t.setAttribute("role","presentation");this.#Pt.append(t)}}#ka(t){const{div:e,properties:i,ctx:n}=t,{style:r}=e,{canvasWidth:s,fontSize:a}=i;if(0!==s&&0!==a&&i.hasText){const{fontFamily:t}=r,i=this.#la,o=TextLayer.#Pa(a*this.#ua/i)*i;TextLayer.#Ma(n,o,t);const{width:l}=n.measureText(e.textContent);l>0&&r.setProperty("--scale-x",s*o/(l*a))}0!==i.angle&&r.setProperty("--rotate",`${i.angle}deg`)}static cleanup(){if(!(this.#Aa.size>0)){this.#ya.clear();for(const{canvas:t}of this.#wa.values())t.remove();this.#wa.clear()}}static#Ea(t=null){let e=this.#wa.get(t||="");if(!e){const i=document.createElement("canvas");i.style.cssText="position:absolute;top:0;left:0;width:0;height:0;display:none;letter-spacing:normal;word-spacing:normal";i.lang=t;document.body.append(i);e=i.getContext("2d",{alpha:!1,willReadFrequently:!0});this.#wa.set(t,e);this.#va.set(e,{size:0,family:""})}return e}static#Pa(t){t=Math.fround(t);const e=Math.fround(131073*t);return Math.fround(e-Math.fround(e-t))}static#Ma(t,e,i){const n=this.#va.get(t);if(e!==n.size||i!==n.family){t.font=`${e}px ${i}`;n.size=e;n.family=i}}static#xa(){if(null!==this.#_a)return;const t=document.createElement("div");t.style.opacity=0;t.style.lineHeight=1;t.style.fontSize="1px";t.style.position="absolute";t.textContent="X";document.body.append(t);this.#_a=t.getBoundingClientRect().height;t.remove()}static#Ta(t,e,i){const n=this.#ya.get(t);if(n)return n;const r=this.#Ea(i);this.#Ma(r,30,t);const s=r.measureText(""),a=s.fontBoundingBoxAscent,o=Math.abs(s.fontBoundingBoxDescent);let l=.8;if(a)l=a/(a+o);else{FeatureTest.platform.isFirefox&&warn("Enable the `dom.textMetrics.fontBoundingBox.enabled` preference in `about:config` to improve TextLayer rendering.");e.ascent?l=e.ascent:e.descent&&(l=1+e.descent)}this.#ya.set(t,l);return l}}function getDocument(t={}){const e=new PDFDocumentLoadingTask,{docId:i}=e,n=t.url?function getUrlProp(t){if(t instanceof URL)return t;if("string"==typeof t){if(ui){if(/^[a-z][a-z0-9\-+.]+:/i.test(t))return new URL(t);const e=process.getBuiltinModule("url");return new URL(e.pathToFileURL(t))}const e=URL.parse(t,window.location);if(e)return e}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}(t.url):null,r=t.data?function getDataProp(t){if(ui&&"undefined"!=typeof Buffer&&t instanceof Buffer)throw new Error("Please provide binary data as `Uint8Array`, rather than `Buffer`.");if(t instanceof Uint8Array&&t.byteLength===t.buffer.byteLength)return t;if("string"==typeof t)return stringToBytes(t);if(t instanceof ArrayBuffer||ArrayBuffer.isView(t)||"object"==typeof t&&!isNaN(t?.length))return new Uint8Array(t);throw new Error("Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.")}(t.data):null,s=t.httpHeaders||null,a=!0===t.withCredentials,o=t.password??null,l=t.range instanceof PDFDataRangeTransport?t.range:null,c=Number.isInteger(t.rangeChunkSize)&&t.rangeChunkSize>0?t.rangeChunkSize:65536;let h=t.worker instanceof PDFWorker?t.worker:null;const d=t.verbosity,u="string"!=typeof t.docBaseUrl||isDataScheme(t.docBaseUrl)?null:t.docBaseUrl,p=getFactoryUrlProp(t.cMapUrl),g=!1!==t.cMapPacked,m=getFactoryUrlProp(t.iccUrl),f=getFactoryUrlProp(t.standardFontDataUrl),b=getFactoryUrlProp(t.wasmUrl),y=!0!==t.stopAtErrors,w=Number.isInteger(t.maxImageSize)&&t.maxImageSize>-1?t.maxImageSize:-1,v="boolean"==typeof t.isOffscreenCanvasSupported?t.isOffscreenCanvasSupported:!ui,_="boolean"==typeof t.isImageDecoderSupported?t.isImageDecoderSupported:!ui,A=Number.isInteger(t.canvasMaxAreaInBytes)?t.canvasMaxAreaInBytes:-1,x="boolean"==typeof t.disableFontFace?t.disableFontFace:ui,C=!0===t.fontExtraProperties,E=!0===t.enableXfa,S=t.ownerDocument||globalThis.document,T=!0===t.disableRange,k=!0===t.disableStream,P=!0===t.disableAutoFetch,M=!0===t.pdfBug,D=t.CanvasFactory||(ui?NodeCanvasFactory:DOMCanvasFactory),I=t.FilterFactory||(ui?NodeFilterFactory:DOMFilterFactory),O=t.BinaryDataFactory||(ui?NodeBinaryDataFactory:DOMBinaryDataFactory),R=!0===t.enableHWA,B=!0===t.enableWebGPU;B&&initGPU();const L=!1!==t.useWasm,N=t.pagesMapper||new PagesMapper,U="boolean"==typeof t.useSystemFonts?t.useSystemFonts:!ui&&!x,H="boolean"==typeof t.useWorkerFetch?t.useWorkerFetch:!!(O===DOMBinaryDataFactory&&p&&g&&f&&b&&isValidFetchUrl(p,document.baseURI)&&isValidFetchUrl(f,document.baseURI)&&isValidFetchUrl(b,document.baseURI)),z=!0===t.disableWorkerRendering||!v||S!==globalThis.document||!RendererWorker.isAvailable;setVerbosityLevel(d);const G={canvasFactory:new D({ownerDocument:S,enableHWA:R}),filterFactory:new I({docId:i,ownerDocument:S}),binaryDataFactory:H?null:new O({cMapUrl:p,standardFontDataUrl:f,wasmUrl:b})};if(!h){h=PDFWorker.create({verbosity:d,port:GlobalWorkerOptions.workerPort});e._worker=h}if(!z){const t=RendererWorker.create({verbosity:d,enableHWA:R,enableWebGPU:B,ports:GlobalWorkerOptions.rendererPorts});t.promise.catch(e=>{if(!t.destroyed){warn(`Renderer worker disabled: ${e.message}`);t.destroy()}});e._rendererWorker=t}const W={docId:i,apiVersion:"6.5.438",data:r,password:o,disableAutoFetch:P,rangeChunkSize:c,docBaseUrl:u,enableXfa:E,evaluatorOptions:{maxImageSize:w,disableFontFace:x,ignoreErrors:y,isOffscreenCanvasSupported:v,isImageDecoderSupported:_,canvasMaxAreaInBytes:A,fontExtraProperties:C,useSystemFonts:U,useWasm:L,useWorkerFetch:H,cMapUrl:p,cMapPacked:g,iccUrl:m,standardFontDataUrl:f,wasmUrl:b}},j={ownerDocument:S,pdfBug:M,styleElement:null,rendererWorker:e._rendererWorker,enableWebGPU:B,loadingParams:{disableAutoFetch:P,enableXfa:E}};h.promise.then(function(){if(h.destroyed)throw new Error("Worker was destroyed");const t=h.messageHandler.sendWithPromise("GetDocRequest",W,r?[r.buffer]:null);let o;if(r);else if(l)o=new PDFDataTransportStream({pdfDataRangeTransport:l,disableRange:T,disableStream:k});else{if(!n)throw new Error("getDocument - expected either `data`, `range`, or `url` parameter.");{const t=function getNetworkStream(t){return isValidFetchUrl(t)?PDFFetchStream:ui?PDFNodeStream:PDFNetworkStream}(n);o=new t({url:n,httpHeaders:s,withCredentials:a,rangeChunkSize:c,disableRange:T,disableStream:k})}}return t.then(t=>{if(h.destroyed)throw new Error("Worker was destroyed");const n=new MessageHandler(i,t,h.port),r=new WorkerTransport(n,e,o,j,G,N);e._transport=r;if(e.destroyed)throw new Error("Loading aborted");n.send("Ready",null)})}).catch(e._capability.reject).finally(e._setupCapability.resolve);return e}class PDFDocumentLoadingTask{static#hr=0;_capability=Promise.withResolvers();_setupCapability=Promise.withResolvers();_transport=null;_worker=null;_rendererWorker=null;docId="d"+PDFDocumentLoadingTask.#hr++;destroyed=!1;onPassword=null;onProgress=null;get promise(){return this._capability.promise}async destroy(){this.destroyed=!0;this._capability.promise.catch(()=>{});try{this._worker?.port&&(this._worker._pendingDestroy=!0);await this._setupCapability.promise;await(this._transport?.destroy())}catch(t){this._worker?.port&&delete this._worker._pendingDestroy;throw t}finally{this._rendererWorker?.destroy();this._rendererWorker=null}this._transport=null;this._worker?.destroy();this._worker=null}async getData(){return this._transport.getData()}}class PDFDataRangeTransport{#Os=Promise.withResolvers();#Da=null;constructor(t,e,i=!1,n=null){this.length=t;this.initialData=e;this.progressiveDone=i;this.contentDispositionFilename=n}onDataRange(t,e){this.#Da({type:"range",begin:t,chunk:e})}onDataProgressiveRead(t){this.#Os.promise.then(()=>{this.#Da({type:"progressiveRead",chunk:t})})}onDataProgressiveDone(){this.#Os.promise.then(()=>{this.#Da({type:"progressiveDone"})})}transportReady(t){this.#Da=t;this.#Os.resolve()}requestDataRange(t,e){unreachable("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class PDFDocumentProxy{constructor(t,e){this._pdfInfo=t;this._transport=e}get pagesMapper(){return this._transport.pagesMapper}get annotationStorage(){return this._transport.annotationStorage}get canvasFactory(){return this._transport.canvasFactory}get filterFactory(){return this._transport.filterFactory}get numPages(){return this._pdfInfo.numPages}get fingerprints(){return this._pdfInfo.fingerprints}get isPureXfa(){return util_shadow(this,"isPureXfa",!!this._transport._htmlForXfa)}get allXfaHtml(){return this._transport._htmlForXfa}getPage(t){return this._transport.getPage(t)}getPageIndex(t){return this._transport.getPageIndex(t)}getDestinations(){return this._transport.getDestinations()}getDestination(t){return this._transport.getDestination(t)}getPageLabels(){return this._transport.getPageLabels()}getPageLayout(){return this._transport.getPageLayout()}getPageMode(){return this._transport.getPageMode()}getViewerPreferences(){return this._transport.getViewerPreferences()}getOpenAction(){return this._transport.getOpenAction()}getAttachments(){return this._transport.getAttachments()}getAttachmentContent(t){return this._transport.getAttachmentContent(t)}getAnnotationsByType(t,e){return this._transport.getAnnotationsByType(t,e)}getJSActions(){return this._transport.getDocJSActions()}getOutline(){return this._transport.getOutline()}getOptionalContentConfig({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getOptionalContentConfig(e)}getPermissions(){return this._transport.getPermissions()}getMetadata(){return this._transport.getMetadata()}getMarkInfo(){return this._transport.getMarkInfo()}getData(){return this._transport.getData()}saveDocument(t){return this._transport.saveDocument(t)}extractPages(t,e=null){return this._transport.extractPages(t,e)}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}cleanup(t=!1){return this._transport.startCleanup(t||this.isPureXfa)}cachedPageNumber(t){return this._transport.cachedPageNumber(t)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}getSignatures(){return this._transport.getSignatures()}getSignatureData(t){return this._transport.getSignatureData(t)}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}}class PDFPageProxy{#Ia=!1;#Fa=null;static#Oa=0;constructor(t,e,i,n,r=!1){this._pageIndex=t;this._id=PDFPageProxy.#Oa++;this._pageInfo=e;this._transport=i;this._stats=r?new StatTimer:null;this._pdfBug=r;this.commonObjs=i.commonObjs;this.objs=new PDFObjects;this._intentStates=new Map;this.destroyed=!1;this.recordedBBoxes=null;this.#Fa=n;this.imageCoordinates=null}clone(t){const e=new PDFPageProxy(t,this._pageInfo,this._transport,this.#Fa,this._pdfBug);e.clonedFromIndex=this.clonedFromIndex??this._pageIndex;this._transport.updatePage(e);return e}get pageNumber(){return this._pageIndex+1}set pageNumber(t){this._pageIndex=t-1;this._transport.updatePage(this)}get rotate(){return this._pageInfo.rotate}get ref(){return this._pageInfo.ref}get userUnit(){return this._pageInfo.userUnit}get view(){return this._pageInfo.view}getViewport({scale:t,rotation:e=this.rotate,offsetX:i=0,offsetY:n=0,dontFlip:r=!1}={}){return new PageViewport({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:i,offsetY:n,dontFlip:r})}getAnnotations({intent:t="display"}={}){const{renderingIntent:e}=this._transport.getRenderingIntent(t);return this._transport.getAnnotations(this._pageIndex,e)}getJSActions(){return this._transport.getPageJSActions(this._pageIndex)}get filterFactory(){return this._transport.filterFactory}get isPureXfa(){return util_shadow(this,"isPureXfa",!!this._transport._htmlForXfa)}async getXfa(){return this._transport._htmlForXfa?.children[this._pageIndex]||null}render({canvasContext:t,canvas:e=t.canvas,viewport:i,intent:n="display",annotationMode:r=Ei.ENABLE,transform:s=null,background:a=null,optionalContentConfigPromise:o=null,annotationCanvasMap:l=null,pageColors:c=null,printAnnotationStorage:h=null,isEditing:d=!1,recordImages:u=!1,recordOperations:p=!1,partialFrames:g=!1,operationsFilter:m=null}){this._stats?.time("Overall");const f=this._transport.getRenderingIntent(n,r,h,d),{renderingIntent:b,cacheKey:y}=f;this.#Ia=!1;o||=this._transport.getOptionalContentConfig(b);const w=this._intentStates.getOrInsertComputed(y,makeObj);if(w.streamReaderCancelTimeout){clearTimeout(w.streamReaderCancelTimeout);w.streamReaderCancelTimeout=null}const v=!!(b&wi);if(!w.displayReadyCapability){w.displayReadyCapability=Promise.withResolvers();w.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null};this._stats?.time("Page Request");this._pumpOperatorList(f)}const _=!(!this._pdfBug||!globalThis.StepperManager?.enabled),A=!!e&&!this.recordedBBoxes&&(p||_),x=!!e&&!this.imageCoordinates&&u,complete=t=>{w.renderTasks.delete(C);if(A){const{recordedBBoxes:t}=C;if(t){C.stepper?.setOperatorBBoxes(t,C.debugMetadata);p&&(this.recordedBBoxes=t)}}x&&!t&&(this.imageCoordinates=C.imageCoordinates);v&&(this.#Ia=!0);this.#Ra();if(t){C.capability.reject(t);this._abortOperatorList({intentState:w,reason:t instanceof Error?t:new Error(t)})}else C.capability.resolve();if(this._stats){this._stats.timeEnd("Rendering");this._stats.timeEnd("Overall");globalThis.Stats?.enabled&&globalThis.Stats.add(this.pageNumber,this._stats)}},C=new InternalRenderTask({callback:complete,params:{canvas:e,canvasContext:t,viewport:i,transform:s,background:a,recordOperations:A,recordImages:x,partialFrames:g,recordForDebugger:_},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:l,operatorList:w.operatorList,pageIndex:this._pageIndex,pageProxyId:this._id,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!v,pdfBug:this._pdfBug,pageColors:c,operationsFilter:m,rendererWorker:this._transport.rendererWorker,waitForGPU:()=>this._transport.waitForGPU()});(w.renderTasks||=new Set).add(C);const E=C.task;Promise.all([w.displayReadyCapability.promise,o]).then(async([t,e])=>{if(this.destroyed)complete();else{this._stats?.time("Rendering");if(!(e.renderingIntent&b))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");await C.initializeGraphics({transparency:t,optionalContentConfig:e});C.operatorListChanged()}}).catch(complete);return E}getOperatorList({intent:t="display",annotationMode:e=Ei.ENABLE,printAnnotationStorage:i=null,isEditing:n=!1}={}){const r=this._transport.getRenderingIntent(t,e,i,n,!0),s=this._intentStates.getOrInsertComputed(r.cacheKey,makeObj);let a;if(!s.opListReadCapability){a=Object.create(null);a.operatorListChanged=function operatorListChanged(){if(s.operatorList.lastChunk){s.opListReadCapability.resolve(s.operatorList);s.renderTasks.delete(a)}};s.opListReadCapability=Promise.withResolvers();(s.renderTasks||=new Set).add(a);s.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null};this._stats?.time("Page Request");this._pumpOperatorList(r)}return s.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){return this._transport.messageHandler.sendWithStream("GetTextContent",{pageId:this.#Fa.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,includeMarkedContent:!0===t,disableNormalization:!0===e},{highWaterMark:100,size:t=>t.items.length})}async getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(t=>XfaText.textContent(t));const e=this.streamTextContent(t).getReader(),i={items:[],styles:Object.create(null),lang:null};for(;;){const{value:t,done:n}=await e.read();if(n)break;i.lang??=t.lang;Object.assign(i.styles,t.styles);i.items.push(...t.items)}return i}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;const t=[];for(const e of this._intentStates.values()){this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0});if(!e.opListReadCapability)for(const i of e.renderTasks){t.push(i.completed);i.cancel()}}this.objs.clear();this._transport.cleanupPage(this._id);this.#Ia=!1;return Promise.all(t)}cleanup(t=!1){this.#Ia=!0;const e=this.#Ra();t&&e&&(this._stats&&=new StatTimer);return e}#Ra(){if(!this.#Ia||this.destroyed)return!1;for(const{renderTasks:t,operatorList:e}of this._intentStates.values())if(t.size>0||!e.lastChunk)return!1;this._intentStates.clear();this.objs.clear();this._transport.cleanupPage(this._id);this.#Ia=!1;return!0}_startRenderPage(t,e){const i=this._intentStates.get(e);if(i){this._stats?.timeEnd("Page Request");i.displayReadyCapability?.resolve(t)}}_renderPageChunk(t,e){for(let i=0,n=t.length;i<n;i++){e.operatorList.fnArray.push(t.fnArray[i]);e.operatorList.argsArray.push(t.argsArray[i])}e.operatorList.lastChunk=t.lastChunk;e.operatorList.separateAnnots=t.separateAnnots;for(const t of e.renderTasks)t.operatorListChanged();t.lastChunk&&this.#Ra()}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:i,modifiedIds:n}){const{map:r,transfer:s}=i,a=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageId:this.#Fa.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,pageProxyId:this._id,intent:t,cacheKey:e,annotationStorage:r,modifiedIds:n},void 0,s).getReader(),o=this._intentStates.get(e);o.streamReader=a;const pump=()=>{a.read().then(({value:t,done:e})=>{if(e)o.streamReader=null;else if(!this._transport.destroyed){this._renderPageChunk(t,o);pump()}},t=>{o.streamReader=null;if(!this._transport.destroyed){if(o.operatorList){o.operatorList.lastChunk=!0;for(const t of o.renderTasks)t.operatorListChanged();this.#Ra()}if(o.displayReadyCapability)o.displayReadyCapability.reject(t);else{if(!o.opListReadCapability)throw t;o.opListReadCapability.reject(t)}}})};pump()}_abortOperatorList({intentState:t,reason:e,force:i=!1}){if(t.streamReader){if(t.streamReaderCancelTimeout){clearTimeout(t.streamReaderCancelTimeout);t.streamReaderCancelTimeout=null}if(!i){if(t.renderTasks.size>0)return;if(e instanceof RenderingCancelledException){let i=100;e.extraDelay>0&&e.extraDelay<1e3&&(i+=e.extraDelay);t.streamReaderCancelTimeout=setTimeout(()=>{t.streamReaderCancelTimeout=null;this._abortOperatorList({intentState:t,reason:e,force:!0})},i);return}}t.streamReader.cancel(new AbortException(e.message)).catch(()=>{});t.streamReader=null;if(!this._transport.destroyed){for(const[e,i]of this._intentStates)if(i===t){this._intentStates.delete(e);break}this.cleanup()}}}get stats(){return this._stats}}class PDFWorker{#Os=Promise.withResolvers();#Bs=null;#jr=null;#Ws=null;static#Ba=0;static#La=!1;static#Na=new WeakMap;static{if(ui){this.#La=!0;GlobalWorkerOptions.workerSrc||="./pdf.worker.mjs"}}constructor({name:t=null,port:e=null,verbosity:i=getVerbosityLevel()}={}){this.name=t;this.destroyed=!1;this.verbosity=i;if(e){if(PDFWorker.#Na.has(e))throw new Error("Cannot use more than one PDFWorker per port.");PDFWorker.#Na.set(e,this);this.#$s(e)}else this.#Xs()}get promise(){return this.#Os.promise}#Ks(){this.#Os.resolve();this.#Bs.send("configure",{verbosity:this.verbosity})}get port(){return this.#jr}get messageHandler(){return this.#Bs}#$s(t){this.#jr=t;this.#Bs=new MessageHandler("main","worker",t);this.#Bs.on("ready",()=>{});this.#Ks()}#Xs(){if(PDFWorker.#La||PDFWorker.#Ua){this.#Ha();return}const{workerSrc:t}=PDFWorker;try{const e=new Worker(getWorkerSrc(t),{type:"module"}),i=new MessageHandler("main","worker",e),terminateEarly=()=>{n.abort();i.destroy();e.terminate();this.destroyed?this.#Os.reject(new Error("Worker was destroyed")):this.#Ha()},n=new AbortController;e.addEventListener("error",()=>{this.#Ws||terminateEarly()},{signal:n.signal});i.on("ready",t=>{n.abort();if(!this.destroyed&&t instanceof Uint8Array){this.#Bs=i;this.#jr=e;this.#Ws=e;this.#Ks()}else terminateEarly()})}catch{info("The worker has been disabled.");this.#Ha()}}#Ha(){if(!PDFWorker.#La){warn("Setting up fake worker.");PDFWorker.#La=!0}PDFWorker._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this.#Os.reject(new Error("Worker was destroyed"));return}const e=new LoopbackPort;this.#jr=e;const i="fake"+PDFWorker.#Ba++,n=new MessageHandler(i+"_worker",i,e);t.setup(n,e);this.#Bs=new MessageHandler(i,i+"_worker",e);this.#Ks()}).catch(t=>{this.#Os.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){this.destroyed=!0;this.#Ws?.terminate();this.#Ws=null;PDFWorker.#Na.delete(this.#jr);this.#jr=null;this.#Bs?.destroy();this.#Bs=null}static create(t){const e=this.#Na.get(t?.port);if(e){if(e._pendingDestroy)throw new Error("PDFWorker.create - the worker is being destroyed.\nPlease remember to await `PDFDocumentLoadingTask.destroy()`-calls.");return e}return new PDFWorker(t)}static get workerSrc(){if(GlobalWorkerOptions.workerSrc)return GlobalWorkerOptions.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get#Ua(){try{return globalThis.pdfjsWorker?.WorkerMessageHandler||null}catch{return null}}static get _setupFakeWorkerGlobal(){return util_shadow(this,"_setupFakeWorkerGlobal",(async()=>{if(this.#Ua)return this.#Ua;return(await(import(
/*webpackIgnore: true*/
/*@vite-ignore*/
this.workerSrc))).WorkerMessageHandler})())}}class WorkerTransport{downloadInfoCapability=Promise.withResolvers();#za=null;#Ga=!1;#Wa=new Map;#ja=null;#Va=new Map;#qa=new Map;#$a=new Map;#Xa=null;#Ka=null;constructor(t,e,i,n,r,s){this.messageHandler=t;this.loadingTask=e;this.#ja=i;this.commonObjs=new PDFObjects;this.fontLoader=new FontLoader({ownerDocument:n.ownerDocument,styleElement:n.styleElement});this.rendererWorker=n.rendererWorker;this.loadingParams=n.loadingParams;this._params=n;this.canvasFactory=r.canvasFactory;this.filterFactory=r.filterFactory;this.binaryDataFactory=r.binaryDataFactory;this.pagesMapper=s;this.destroyed=!1;this.destroyCapability=null;this.setupMessageHandler()}updatePage(t){this.#Va.set(t._id,t);this.#qa.set(t._pageIndex,Promise.resolve(t))}#Ya(t,e=null){return this.#Wa.getOrInsertComputed(t,()=>this.messageHandler.sendWithPromise(t,e))}#Hr({loaded:t,total:e}){this.loadingTask.onProgress?.({loaded:t,total:e,percent:e?MathClamp(Math.round(t/e*100),0,100):NaN})}get annotationStorage(){return util_shadow(this,"annotationStorage",new AnnotationStorage)}getRenderingIntent(t,e=Ei.ENABLE,i=null,n=!1,r=!1){let s=yi,a=un;switch(t){case"any":s=bi;break;case"display":break;case"print":s=wi;break;default:warn(`getRenderingIntent - invalid intent: ${t}`)}const o=s&wi&&i instanceof PrintAnnotationStorage?i:this.annotationStorage;switch(e){case Ei.DISABLE:s+=Ai;break;case Ei.ENABLE:break;case Ei.ENABLE_FORMS:s+=vi;break;case Ei.ENABLE_STORAGE:s+=_i;a=o.serializable;break;default:warn(`getRenderingIntent - invalid annotationMode: ${e}`)}n&&(s+=xi);r&&(s+=Ci);const{ids:l,hash:c}=o.modifiedIds;return{renderingIntent:s,cacheKey:[s,a.hash,c].join("_"),annotationStorageSerializable:a,modifiedIds:l}}destroy(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0;this.destroyCapability=Promise.withResolvers();this.#Xa?.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const e of this.#Va.values())t.push(e._destroy());this.#Va.clear();this.#qa.clear();this.#$a.clear();Object.hasOwn(this,"annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);t.push(e);Promise.all(t).then(()=>{this.commonObjs.clear();this.fontLoader.clear();this.#Wa.clear();this.filterFactory.destroy();TextLayer.cleanup();this.#ja?.cancelAllRequests(new AbortException("Worker was terminated."));this.messageHandler?.destroy();this.messageHandler=null;this.rendererWorker=null;this.destroyCapability.resolve()},this.destroyCapability.reject);return this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(t,e)=>{util_assert(this.#ja,"GetReader - no `BasePDFStream` instance available.");this.#za=this.#ja.getFullReader();this.#za.onProgress=t=>this.#Hr(t);e.onPull=()=>{this.#za.read().then(function({value:t,done:i}){if(i)e.close();else{util_assert(t instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer.");e.enqueue(new Uint8Array(t),1,[t])}}).catch(t=>{e.error(t)})};e.onCancel=t=>{this.#za.cancel(t);e.ready.catch(t=>{if(!this.destroyed)throw t})}});t.on("ReaderHeadersReady",async t=>{await this.#za.headersReady;const{isStreamingSupported:e,isRangeSupported:i,contentLength:n}=this.#za;e&&i&&(this.#za.onProgress=null);return{isStreamingSupported:e,isRangeSupported:i,contentLength:n}});t.on("GetRangeReader",(t,e)=>{util_assert(this.#ja,"GetRangeReader - no `BasePDFStream` instance available.");const i=this.#ja.getRangeReader(t.begin,t.end);if(i){e.onPull=()=>{i.read().then(function({value:t,done:i}){if(i)e.close();else{util_assert(t instanceof ArrayBuffer,"GetRangeReader - expected an ArrayBuffer.");e.enqueue(new Uint8Array(t),1,[t])}}).catch(t=>{e.error(t)})};e.onCancel=t=>{i.cancel(t);e.ready.catch(t=>{if(!this.destroyed)throw t})}}else e.close()});t.on("GetDoc",({pdfInfo:t})=>{this.pagesMapper.pagesNumber=t.numPages;this._numPages=t.numPages;this._htmlForXfa=t.htmlForXfa;delete t.htmlForXfa;e._capability.resolve(new PDFDocumentProxy(t,this))});t.on("DocException",t=>{e._capability.reject(wrapReason(t))});t.on("PasswordRequest",t=>{this.#Xa=Promise.withResolvers();try{if(!e.onPassword)throw wrapReason(t);const updatePassword=t=>{t instanceof Error?this.#Xa.reject(t):this.#Xa.resolve({password:t})};e.onPassword(updatePassword,t.code)}catch(t){this.#Xa.reject(t)}return this.#Xa.promise});t.on("DataLoaded",t=>{this.#Hr({loaded:t.length,total:t.length});this.downloadInfoCapability.resolve(t)});t.on("StartRenderPage",t=>{if(this.destroyed)return;this.#Va.get(t.pageProxyId)._startRenderPage(t.transparency,t.cacheKey)});const i=new ObjectHandler({messageHandler:t,commonObjs:this.commonObjs,fontLoader:this.fontLoader,pageCache:this.#Va,pdfBug:this._params.pdfBug});this.rendererWorker?.promise.then(()=>{this.rendererWorker?.messageHandler?.on("FontFallback",e=>this.destroyed?null:t.sendWithPromise("FontFallback",e))},()=>{});t.on("commonobj",([t,e,n])=>{if(this.destroyed)return null;const{rendererWorker:r}=this;if("CopyLocalImage"===e){if(this.commonObjs.has(t))return null;const s=i.resolveCommonObject(t,e,n);s&&r?.sendCommonObj(t,"Image",this.commonObjs.get(t));return s}r?.sendCommonObj(t,e,n);if(!this.commonObjs.has(t)){i.resolveCommonObject(t,e,n);"Pattern"===e&&"Mesh"===this.commonObjs.get(t)[0]&&(this.#Ga=!0)}return null});t.on("obj",([t,e,n,r])=>{if(!this.destroyed){"Pattern"===n&&"Mesh"===r[0]&&(this.#Ga=!0);i.resolveObject(t,e,n,r)&&this.rendererWorker?.sendObj(t,e,n,r)}});t.on("DocProgress",t=>{this.destroyed||this.#Hr(t)});t.on("FetchBinaryData",async t=>{if(this.destroyed)throw new Error("Worker was destroyed.");if(!this.binaryDataFactory)throw new Error("`BinaryDataFactory` not initialized, see the `useWorkerFetch` parameter.");return this.binaryDataFactory.fetch(t)})}getData(){return this.messageHandler.sendWithPromise("GetData",null)}saveDocument(t=null){this.annotationStorage.size<=0&&warn("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");const{map:e,transfer:i}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:e,supportsPrintToPDF:null!==this.#Ka,filename:this.#za?.filename??null},i).finally(()=>{this.#Ka=null;this.annotationStorage.resetModified()})}extractPages(t,e=null){const i={pageInfos:t};let n;const r=globalThis.ImageBitmap;if("function"==typeof r){const e=Array.isArray(t)?t:[t];for(const t of e)t?.image instanceof r&&(n||=[]).push(t.image)}if(this.annotationStorage.size>0){const t=this.annotationStorage.serializable;let{map:r}=t;t.transfer?.length&&(n?n.push(...t.transfer):n=t.transfer);const s=this.pagesMapper.getMapping();if(s){const t=new Map;for(const[i,n]of r){if(void 0!==n?.pageIndex&&n.pageIndex>=0&&n.pageIndex<s.length){const r=e?.[n.pageIndex]??0,a=s[n.pageIndex]-1;if(a!==n.pageIndex||0!==r){t.set(i,{...n,pageIndex:a,copyLevel:r});continue}}t.set(i,n)}r=t}i.annotationStorage=r}return this.messageHandler.sendWithPromise("ExtractPages",i,n).finally(()=>{this.annotationStorage.resetModified()})}waitForGPU(){return this._params.enableWebGPU&&this.#Ga&&!isGPUReady()?initGPU():null}getPage(t){if(!Number.isInteger(t)||t<=0||t>this.pagesMapper.pagesNumber)return Promise.reject(new Error("Invalid page request."));const e=t-1,i=this.pagesMapper.getPageId(t)-1,n=this.#qa.get(e);if(n)return n;const r=this.messageHandler.sendWithPromise("GetPage",{pageIndex:i}).then(t=>{if(this.destroyed)throw new Error("Transport destroyed");t.refStr&&this.#$a.set(t.refStr,i);const n=new PDFPageProxy(e,t,this,this.pagesMapper,this._params.pdfBug);this.#Va.set(n._id,n);return n});this.#qa.set(e,r);return r}async getPageIndex(t){if(!isRefProxy(t))throw new Error("Invalid pageIndex request.");const e=await this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}),i=this.pagesMapper.getPageNumber(e+1);if(0===i)throw new Error("GetPageIndex: page has been removed.");return i-1}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:this.pagesMapper.getPageId(t+1)-1,intent:e})}getFieldObjects(){return this.#Ya("GetFieldObjects")}getSignatures(){return this.#Ya("GetSignatures")}getSignatureData(t){return this.messageHandler.sendWithPromise("GetSignatureData",t)}hasJSActions(){return this.#Ya("HasJSActions")}getCalculationOrderIds(){return this.messageHandler.sendWithPromise("GetCalculationOrderIds",null)}getDestinations(){return this.messageHandler.sendWithPromise("GetDestinations",null)}getDestination(t){return"string"!=typeof t?Promise.reject(new Error("Invalid destination request.")):this.messageHandler.sendWithPromise("GetDestination",{id:t})}getPageLabels(){return this.messageHandler.sendWithPromise("GetPageLabels",null)}getPageLayout(){return this.messageHandler.sendWithPromise("GetPageLayout",null)}getPageMode(){return this.messageHandler.sendWithPromise("GetPageMode",null)}getViewerPreferences(){return this.messageHandler.sendWithPromise("GetViewerPreferences",null)}getOpenAction(){return this.messageHandler.sendWithPromise("GetOpenAction",null)}getAttachments(){return this.messageHandler.sendWithPromise("GetAttachments",null)}getAttachmentContent(t){return this.messageHandler.sendWithPromise("GetAttachmentContent",t)}getAnnotationsByType(t,e){return this.messageHandler.sendWithPromise("GetAnnotationsByType",{types:t,pageIndexesToSkip:e})}getDocJSActions(){return this.#Ya("GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:this.pagesMapper.getPageId(t+1)-1})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:this.pagesMapper.getPageId(t+1)-1})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){const e="GetOptionalContentConfig";return this.#Wa.getOrInsertComputed(e,()=>this.messageHandler.sendWithPromise(e,null).catch(t=>{warn(`${e}: "${t}".`);return null})).then(e=>new OptionalContentConfig(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata";return this.#Wa.getOrInsertComputed(t,()=>this.messageHandler.sendWithPromise(t,null).then(t=>({info:t[0],metadata:t[1]?new Metadata(t[1]):null,contentDispositionFilename:this.#za?.filename??null,contentLength:this.#za?.contentLength??null,hasStructTree:t[2]})))}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const t of this.#Va.values()){if(!t.cleanup())throw new Error(`startCleanup: Page ${t.pageNumber} is currently rendering.`)}this.commonObjs.clear();t||this.fontLoader.clear();this.rendererWorker?.cleanup(t);this.#Wa.clear();this.filterFactory.destroy(!0);TextLayer.cleanup()}}cleanupPage(t){this.destroyed||this.messageHandler.send("CleanupPage",{pageProxyId:t});this.rendererWorker?.cleanupPage(t)}cachedPageNumber(t){if(!isRefProxy(t))return null;const e=0===t.gen?`${t.num}R`:`${t.num}R${t.gen}`,i=this.#$a.get(e);if(i>=0){const t=this.pagesMapper.getPageNumber(i+1);if(0!==t)return t}return null}}class RenderTask{_internalRenderTask=null;onContinue=null;onError=null;onFrame=null;constructor(t){this._internalRenderTask=t}get promise(){return this._internalRenderTask.capability.promise}cancel(t=0){this._internalRenderTask.cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=this._internalRenderTask.operatorList;if(!t)return!1;const{annotationCanvasMap:e}=this._internalRenderTask;return t.form||t.canvas&&e?.size>0}get imageCoordinates(){return this._internalRenderTask.imageCoordinates||null}get isWorkerRendering(){return this._internalRenderTask.isWorkerRendering}}class InternalRenderTask{#kn=null;#Ja=null;#Qa=null;#Za=null;#to=null;static#eo=new WeakSet;constructor({callback:t,params:e,objs:i,commonObjs:n,annotationCanvasMap:r,operatorList:s,pageIndex:a,pageProxyId:o,canvasFactory:l,filterFactory:c,useRequestAnimationFrame:h=!1,pdfBug:d=!1,pageColors:u=null,operationsFilter:p=null,rendererWorker:g=null,waitForGPU:m=null}){this.callback=t;this.params=e;this.objs=i;this.commonObjs=n;this.annotationCanvasMap=r;this.operatorListIdx=null;this.operatorList=s;this._pageIndex=a;this.canvasFactory=l;this.filterFactory=c;this._pdfBug=d;this.pageColors=u;this.running=!1;this.graphicsReadyCallback=null;this.graphicsReady=!1;this._useRequestAnimationFrame=!0===h&&"undefined"!=typeof window;this.cancelled=!1;this.capability=Promise.withResolvers();this.task=new RenderTask(this);this._cancelBound=this.cancel.bind(this);this._continueBound=this._continue.bind(this);this._scheduleNextBound=this._scheduleNext.bind(this);this._nextBound=this._next.bind(this);this._canvas=e.canvas;this._canvasContext=e.canvas?null:e.canvasContext;this._operationsFilter=p;this.#to=m;this.#Za=g?.createRenderTask({pageProxyId:o,operatorList:s,params:e,pageColors:u,canvasFactory:l,annotationCanvasMap:r,onFrame:()=>this.task.onFrame?.(),onError:t=>this.cancel(t)})??null}get completed(){return this.capability.promise.catch(()=>{})}get isWorkerRendering(){return!!this.#Za}get imageCoordinates(){return this.#Za?this.#Za.imageCoordinates:this.#Ja?.take()}get recordedBBoxes(){return this.#Za?this.#Za.recordedBBoxes:this.#kn?.take()}get debugMetadata(){return this.#kn?.takeDebugMetadata()??null}async initializeGraphics({transparency:t=!1,optionalContentConfig:e}){if(!this.cancelled){if(this._canvas){if(InternalRenderTask.#eo.has(this._canvas))throw new Error("Cannot use the same canvas during multiple render() operations. Use different canvas or ensure previous operations were cancelled or completed.");InternalRenderTask.#eo.add(this._canvas)}if(this._pdfBug&&globalThis.StepperManager?.enabled){this.stepper=globalThis.StepperManager.create(this._pageIndex);this.stepper.init(this.operatorList);this.stepper.nextBreakPoint=this.stepper.getNextBreakPoint()}if(this.#Za){const i=await this.#Za.initialize(t,e);if(this.cancelled)return;i||(this.#Za=null)}if(!this.#Za){const{viewport:i,transform:n,background:r,recordOperations:s,recordImages:a,recordForDebugger:o}=this.params,l=this._canvasContext||this.canvasFactory.getNoAlphaContext(this._canvas),{dependencyTracker:c,imagesTracker:h}=function createCanvasTrackers(t,e,{recordOperations:i=!1,recordImages:n=!1,recordDebugMetadata:r=!1}){const s=i||n?new CanvasBBoxTracker(t,e):null;return{dependencyTracker:i?new CanvasDependencyTracker(s,r):s,imagesTracker:n?new CanvasImagesTracker(t):null}}(this._canvas,this.operatorList.fnArray.length,{recordOperations:s,recordImages:a,recordDebugMetadata:o});this.#kn=c;this.#Ja=h;this.gfx=new CanvasGraphics(l,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors,c,h);this.gfx.beginDrawing({transform:n,viewport:i,transparency:t,background:r})}this.operatorListIdx=0;this.graphicsReady=!0;this.graphicsReadyCallback?.()}}cancel(t=null,e=0){this.running=!1;this.cancelled=!0;this.#Za?.cancel();this.gfx?.endDrawing();if(this.#Qa){window.cancelAnimationFrame(this.#Qa);this.#Qa=null}InternalRenderTask.#eo.delete(this._canvas);t||=new RenderingCancelledException(`Rendering cancelled, page ${this._pageIndex+1}`,e);this.callback(t);this.task.onError?.(t)}operatorListChanged(){if(this.graphicsReady){this.#kn?.growOperationsCount(this.operatorList.fnArray.length);this.stepper?.updateOperatorList(this.operatorList);this.running||this._continue()}else this.graphicsReadyCallback||=this._continueBound}_continue(){this.running=!0;this.cancelled||(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?this.#Qa=window.requestAnimationFrame(()=>{this.#Qa=null;this._nextBound().catch(this._cancelBound)}):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){if(this.cancelled)return;if(!this.#Za){const t=this.#to?.();if(t){await t;if(this.cancelled)return}}const{operatorList:t}=this,{lastChunk:e}=t;if(this.#Za){this.operatorListIdx=await this.#Za.executeOperatorList(t,this.operatorListIdx,this._operationsFilter);if(this.cancelled)return;if(this.operatorListIdx!==t.argsArray.length||e!==t.lastChunk){this._continue();return}}else this.operatorListIdx=this.gfx.executeOperatorList(t,this.operatorListIdx,this._continueBound,null,this.stepper,this._operationsFilter);if(this.operatorListIdx===t.argsArray.length){this.running=!1;if(e){this.gfx?.endDrawing();InternalRenderTask.#eo.delete(this._canvas);this.callback()}}}}const Yn="6.5.438",Jn="0a4153349";$e();class ColorPicker{#io=null;#no=null;#ro;#so=null;#ao=!1;#oo=!1;#a=null;#lo;#co=null;#y=null;static#ho=null;static get _keyboardManager(){return util_shadow(this,"_keyboardManager",new KeyboardManager([[["Escape"],ColorPicker.prototype._hideDropdownFromKeyboard],[["Space"],ColorPicker.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight"],ColorPicker.prototype._moveToNext],[["ArrowUp","ArrowLeft"],ColorPicker.prototype._moveToPrevious],[["Home"],ColorPicker.prototype._moveToBeginning],[["End"],ColorPicker.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){if(t){this.#oo=!1;this.#a=t}else this.#oo=!0;this.#y=t?._uiManager||e;this.#lo=this.#y._eventBus;this.#ro=t?.color?.toUpperCase()||this.#y?.highlightColors.values().next().value||"#FFFF98";ColorPicker.#ho||=Object.freeze({blue:"pdfjs-editor-colorpicker-blue",green:"pdfjs-editor-colorpicker-green",pink:"pdfjs-editor-colorpicker-pink",red:"pdfjs-editor-colorpicker-red",yellow:"pdfjs-editor-colorpicker-yellow"})}renderButton(){const t=this.#io=document.createElement("button");t.className="colorPicker";t.tabIndex="0";t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button");t.ariaHasPopup="true";this.#a&&(t.ariaControls=`${this.#a.id}_colorpicker_dropdown`);const e=this.#y._signal;t.addEventListener("click",this.#do.bind(this),{signal:e});t.addEventListener("keydown",this.#uo.bind(this),{signal:e});const i=this.#no=document.createElement("span");i.className="swatch";i.ariaHidden="true";i.style.backgroundColor=this.#ro;t.append(i);return t}renderMainDropdown(){const t=this.#so=this.#po();t.ariaOrientation="horizontal";t.ariaLabelledBy="highlightColorPickerLabel";return t}#po(){const t=document.createElement("div"),e=this.#y._signal;t.addEventListener("contextmenu",noContextMenu,{signal:e});t.className="dropdown";t.role="listbox";t.ariaMultiSelectable="false";t.ariaOrientation="vertical";t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");this.#a&&(t.id=`${this.#a.id}_colorpicker_dropdown`);for(const[i,n]of this.#y.highlightColors){const r=document.createElement("button");r.tabIndex="0";r.role="option";r.setAttribute("data-color",n);r.title=i;r.setAttribute("data-l10n-id",ColorPicker.#ho[i]);const s=document.createElement("span");r.append(s);s.className="swatch";s.style.backgroundColor=n;r.ariaSelected=n===this.#ro;r.addEventListener("click",this.#go.bind(this,n),{signal:e});t.append(r)}t.addEventListener("keydown",this.#uo.bind(this),{signal:e});return t}#go(t,e){e.stopPropagation();this.#lo.dispatch("switchannotationeditorparams",{source:this,type:Pi.HIGHLIGHT_COLOR,value:t});this.update(t)}_colorSelectFromKeyboard(t){if(t.target===this.#io){this.#do(t);return}const e=t.target.getAttribute("data-color");e&&this.#go(e,t)}_moveToNext(t){this.#mo?t.target!==this.#io?t.target.nextSibling?.focus():this.#so.firstElementChild?.focus():this.#do(t)}_moveToPrevious(t){if(t.target!==this.#so?.firstElementChild&&t.target!==this.#io){this.#mo||this.#do(t);t.target.previousSibling?.focus()}else this.#mo&&this._hideDropdownFromKeyboard()}_moveToBeginning(t){this.#mo?this.#so.firstElementChild?.focus():this.#do(t)}_moveToEnd(t){this.#mo?this.#so.lastElementChild?.focus():this.#do(t)}#uo(t){ColorPicker._keyboardManager.exec(this,t)}#do(t){if(this.#mo){this.hideDropdown();return}this.#ao=0===t.detail;if(!this.#co){this.#co=new AbortController;window.addEventListener("pointerdown",this.#p.bind(this),{signal:this.#y.combinedSignal(this.#co)})}this.#io.ariaExpanded="true";if(this.#so){this.#so.classList.remove("hidden");return}const e=this.#so=this.#po();this.#io.append(e)}#p(t){this.#so?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#so?.classList.add("hidden");this.#io.ariaExpanded="false";this.#co?.abort();this.#co=null}get#mo(){return this.#so&&!this.#so.classList.contains("hidden")}_hideDropdownFromKeyboard(){if(!this.#oo)if(this.#mo){this.hideDropdown();this.#io.focus({preventScroll:!0,focusVisible:this.#ao})}else this.#a?.unselect()}update(t){this.#no&&(this.#no.style.backgroundColor=t);if(!this.#so)return;const e=this.#y.highlightColors.values();for(const i of this.#so.children)i.ariaSelected=e.next().value===t.toUpperCase()}destroy(){this.#io?.remove();this.#io=null;this.#no=null;this.#so?.remove();this.#so=null}}class BasicColorPicker{#fo=null;#bo=!1;#a=null;#y=null;static#ho=null;constructor(t){this.#a=t;this.#y=t._uiManager;BasicColorPicker.#ho||=Object.freeze({freetext:"pdfjs-editor-color-picker-free-text-input",ink:"pdfjs-editor-color-picker-ink-input"})}renderButton(){if(this.#fo)return this.#fo;const{editorType:t,colorType:e,colorAndOpacityType:i,opacityType:n,color:r,opacity:s}=this.#a,a=this.#bo=FeatureTest.isAlphaColorInputSupported&&void 0!==n,o=this.#fo=document.createElement("input");o.type="color";if(a){o.setAttribute("alpha","");const t=Util.hexNums[Math.round(255*(s??1))];o.value=(r||"#000000")+t}else o.value=r||"#000000";o.className="basicColorPicker";o.tabIndex=0;o.setAttribute("data-l10n-id",BasicColorPicker.#ho[t]);o.addEventListener("input",()=>{if(a){const t=getRGBA(o.value);if(!t)return;const[r,s,a,l]=t,c=Util.makeHexColor(r,s,a);if(void 0!==i)this.#y.updateParams(i,{color:c,opacity:l});else{this.#y.updateParams(e,c);this.#y.updateParams(n,l)}}else this.#y.updateParams(e,o.value)},{signal:this.#y._signal});return o}update(t){if(this.#fo)if(this.#bo){const e=Util.hexNums[Math.round(255*this.#a.opacity)];this.#fo.value=t+e}else this.#fo.value=t}updateOpacity(t){if(!this.#fo||!this.#bo)return;const e=Util.hexNums[Math.round(255*t)];this.#fo.value=this.#a.color+e}destroy(){this.#fo?.remove();this.#fo=null}hideDropdown(){}}Le();function makeColorComp(t){return Math.floor(255*MathClamp(t,0,1)).toString(16).padStart(2,"0")}function scaleAndClamp(t){return 255*MathClamp(t,0,1)}class ColorConverters{static CMYK_G([t,e,i,n]){return["G",1-Math.min(1,.3*t+.59*i+.11*e+n)]}static G_CMYK([t]){return["CMYK",0,0,0,1-t]}static G_RGB([t]){return["RGB",t,t,t]}static G_rgb([t]){return[t=scaleAndClamp(t),t,t]}static G_HTML([t]){const e=makeColorComp(t);return`#${e}${e}${e}`}static RGB_G([t,e,i]){return["G",.3*t+.59*e+.11*i]}static RGB_rgb(t){return t.map(scaleAndClamp)}static RGB_HTML(t){return`#${t.map(makeColorComp).join("")}`}static T_HTML(){return"#00000000"}static T_rgb(){return[null]}static CMYK_RGB([t,e,i,n]){return["RGB",1-Math.min(1,t+n),1-Math.min(1,i+n),1-Math.min(1,e+n)]}static CMYK_rgb([t,e,i,n]){return[scaleAndClamp(1-Math.min(1,t+n)),scaleAndClamp(1-Math.min(1,i+n)),scaleAndClamp(1-Math.min(1,e+n))]}static CMYK_HTML(t){const e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,i]){const n=1-t,r=1-e,s=1-i;return["CMYK",n,r,s,Math.min(n,r,s)]}}class BaseSVGFactory{create(t,e,i=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");const n=this._createSVG("svg:svg");n.setAttribute("version","1.1");if(!i){n.setAttribute("width",`${t}px`);n.setAttribute("height",`${e}px`)}n.setAttribute("preserveAspectRatio","none");n.setAttribute("viewBox",`0 0 ${t} ${e}`);return n}createElement(t){if("string"!=typeof t)throw new Error("Invalid SVG element type");return this._createSVG(t)}_createSVG(t){unreachable("Abstract method `_createSVG` called.")}}class DOMSVGFactory extends BaseSVGFactory{_createSVG(t){return document.createElementNS(fi,t)}}const Qn=new WeakSet,Zn=60*(new Date).getTimezoneOffset()*1e3;class AnnotationElementFactory{static create(t){switch(t.data.annotationType){case Ni.LINK:return new LinkAnnotationElement(t);case Ni.TEXT:return new TextAnnotationElement(t);case Ni.WIDGET:switch(t.data.fieldType){case"Tx":return new TextWidgetAnnotationElement(t);case"Btn":return t.data.radioButton?new RadioButtonWidgetAnnotationElement(t):t.data.checkBox?new CheckboxWidgetAnnotationElement(t):new PushButtonWidgetAnnotationElement(t);case"Ch":return new ChoiceWidgetAnnotationElement(t);case"Sig":return new SignatureWidgetAnnotationElement(t)}return new WidgetAnnotationElement(t);case Ni.POPUP:return new PopupAnnotationElement(t);case Ni.FREETEXT:return new FreeTextAnnotationElement(t);case Ni.LINE:return new LineAnnotationElement(t);case Ni.SQUARE:return new SquareAnnotationElement(t);case Ni.CIRCLE:return new CircleAnnotationElement(t);case Ni.POLYLINE:return new PolylineAnnotationElement(t);case Ni.CARET:return new CaretAnnotationElement(t);case Ni.INK:return new InkAnnotationElement(t);case Ni.POLYGON:return new PolygonAnnotationElement(t);case Ni.HIGHLIGHT:return new HighlightAnnotationElement(t);case Ni.UNDERLINE:return new UnderlineAnnotationElement(t);case Ni.SQUIGGLY:return new SquigglyAnnotationElement(t);case Ni.STRIKEOUT:return new StrikeOutAnnotationElement(t);case Ni.STAMP:return new StampAnnotationElement(t);case Ni.FILEATTACHMENT:return new FileAttachmentAnnotationElement(t);case Ni.RICHMEDIA:case Ni.SCREEN:case Ni.SOUND:return new MediaAnnotationElement(t);default:return new AnnotationElement(t)}}}class AnnotationElement{#yo=null;#wo=!1;#vo=null;constructor(t,{isRenderable:e=!1,ignoreBorder:i=!1,createQuadrilaterals:n=!1}={}){this.isRenderable=e;this.data=t.data;this.layer=t.layer;this.linkService=t.linkService;this.downloadManager=t.downloadManager;this.imageResourcesPath=t.imageResourcesPath;this.renderForms=t.renderForms;this.annotationStorage=t.annotationStorage;this.enableComment=t.enableComment;this.enableAnnotationEditing=!1!==t.enableAnnotationEditing;this.enableScripting=t.enableScripting;this.hasJSActions=t.hasJSActions;this._fieldObjects=t.fieldObjects;this.parent=t.parent;this.hasOwnCommentButton=!1;e&&(this.contentElement=this.container=this._createContainer(i));n&&this._createQuadrilaterals()}static _hasPopupData({contentsObj:t,richText:e}){return!(!t?.str&&!e?.str)}static get _svgFactory(){return util_shadow(this,"_svgFactory",new DOMSVGFactory)}get _isEditable(){return this.enableAnnotationEditing&&this.data.isEditable}get hasPopupData(){return AnnotationElement._hasPopupData(this.data)||this.enableComment&&!!this.commentText}get commentData(){const{data:t}=this,e=this.annotationStorage?.getEditor(t.id);return e?e.getData():t}get hasCommentButton(){return this.enableComment&&this.hasPopupElement}get commentButtonPosition(){const t=this.annotationStorage?.getEditor(this.data.id);if(t)return t.commentButtonPositionInPage;const{quadPoints:e,inkLists:i,rect:n}=this.data;let r=-1/0,s=-1/0;if(e?.length>=8){for(let t=0;t<e.length;t+=8)if(e[t+1]>s){s=e[t+1];r=e[t+2]}else e[t+1]===s&&(r=Math.max(r,e[t+2]));return[r,s]}if(i?.length>=1){for(const t of i)for(let e=0,i=t.length;e<i;e+=2)if(t[e+1]>s){s=t[e+1];r=t[e]}else t[e+1]===s&&(r=Math.max(r,t[e]));if(r!==1/0)return[r,s]}return n?[n[2],n[3]]:null}_normalizePoint(t){const{page:{view:e},viewport:{rawDims:{pageWidth:i,pageHeight:n,pageX:r,pageY:s}}}=this.parent;t[1]=e[3]-t[1]+e[1];t[0]=100*(t[0]-r)/i;t[1]=100*(t[1]-s)/n;return t}get commentText(){const{data:t}=this;return this.annotationStorage.getRawValue(`${Ti}${t.id}`)?.popup?.contents||t.contentsObj?.str||""}set commentText(t){const{data:e}=this,i={deleted:!t,contents:t||""};this.annotationStorage.updateEditor(e.id,{popup:i})||this.annotationStorage.setValue(`${Ti}${e.id}`,{id:e.id,annotationType:e.annotationType,page:this.parent.page,popup:i,popupRef:e.popupRef,modificationDate:new Date});t||this.removePopup()}removePopup(){(this.#vo?.popup||this.popup)?.remove();this.#vo=this.popup=null}updateEdited(t){if(!this.container)return;t.rect&&(this.#yo||={rect:this.data.rect.slice(0)});const{rect:e,popup:i}=t;e&&this.#_o(e);let n=this.#vo?.popup||this.popup;if(!n&&i?.text){this._createPopup(i);n=this.#vo.popup}if(n){n.updateEdited(t);if(i?.deleted){n.remove();this.#vo=null;this.popup=null}}}resetEdited(){if(this.#yo){this.#_o(this.#yo.rect);this.#vo?.popup.resetEdited();this.#yo=null}}#_o(t){const{container:{style:e},data:{rect:i,rotation:n},parent:{viewport:{rawDims:{pageWidth:r,pageHeight:s,pageX:a,pageY:o}}}}=this;i?.splice(0,4,...t);e.left=100*(t[0]-a)/r+"%";e.top=100*(s-t[3]+o)/s+"%";if(0===n){e.width=100*(t[2]-t[0])/r+"%";e.height=100*(t[3]-t[1])/s+"%"}else this.setRotation(n)}_createContainer(t){const{data:e,parent:{page:i,viewport:n}}=this,r=document.createElement("section");r.setAttribute("data-annotation-id",e.id);this instanceof WidgetAnnotationElement||this instanceof LinkAnnotationElement||this instanceof MediaAnnotationElement||(r.tabIndex=0);const{style:s}=r;s.zIndex=this.parent.zIndex;this.parent.zIndex+=2;e.alternativeText&&(r.title=e.alternativeText);e.noRotate&&r.classList.add("norotate");if(!e.rect||this instanceof PopupAnnotationElement){const{rotation:t}=e;e.hasOwnCanvas||0===t||this.setRotation(t,r);return r}const{width:a,height:o}=this;if(!t&&e.borderStyle.width>0){s.borderWidth=`${e.borderStyle.width}px`;const t=e.borderStyle.horizontalCornerRadius,i=e.borderStyle.verticalCornerRadius;if(t>0||i>0){const e=`calc(${t}px * var(--total-scale-factor)) / calc(${i}px * var(--total-scale-factor))`;s.borderRadius=e}switch(e.borderStyle.style){case Ui:s.borderStyle="solid";break;case Hi:s.borderStyle="dashed";break;case zi:warn("Unimplemented border style: beveled");break;case Gi:warn("Unimplemented border style: inset");break;case Wi:s.borderBottomStyle="solid"}const n=e.borderColor||null;if(n){this.#wo=!0;s.borderColor=Util.makeHexColor(...n)}else s.borderWidth=0}const l=Util.normalizeRect([e.rect[0],i.view[3]-e.rect[1]+i.view[1],e.rect[2],i.view[3]-e.rect[3]+i.view[1]]),{pageWidth:c,pageHeight:h,pageX:d,pageY:u}=n.rawDims;s.left=100*(l[0]-d)/c+"%";s.top=100*(l[1]-u)/h+"%";const{rotation:p}=e;if(e.hasOwnCanvas||0===p){s.width=100*a/c+"%";s.height=100*o/h+"%"}else this.setRotation(p,r);return r}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:i,pageHeight:n}=this.parent.viewport.rawDims;let{width:r,height:s}=this;t%180!=0&&([r,s]=[s,r]);e.style.width=100*r/i+"%";e.style.height=100*s/n+"%";e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const setColor=(t,e,i)=>{const n=i.detail[t],r=n[0],s=n.slice(1);i.target.style[e]=ColorConverters[`${r}_HTML`](s);this.annotationStorage.setValue(this.data.id,{[e]:ColorConverters[`${r}_rgb`](s)})};return util_shadow(this,"_commonActions",{display:t=>{const{display:e}=t.detail,i=e%2==1;this.container.style.visibility=i?"hidden":"visible";this.annotationStorage.setValue(this.data.id,{noView:i,noPrint:1===e||2===e})},print:t=>{this.annotationStorage.setValue(this.data.id,{noPrint:!t.detail.print})},hidden:t=>{const{hidden:e}=t.detail;this.container.style.visibility=e?"hidden":"visible";this.annotationStorage.setValue(this.data.id,{noPrint:e,noView:e})},focus:t=>{setTimeout(()=>t.target.focus({preventScroll:!1}),0)},userName:t=>{t.target.title=t.detail.userName},readonly:t=>{t.target.disabled=t.detail.readonly},required:t=>{this._setRequired(t.target,t.detail.required)},bgColor:t=>{setColor("bgColor","backgroundColor",t)},fillColor:t=>{setColor("fillColor","backgroundColor",t)},fgColor:t=>{setColor("fgColor","color",t)},textColor:t=>{setColor("textColor","color",t)},borderColor:t=>{setColor("borderColor","borderColor",t)},strokeColor:t=>{setColor("strokeColor","borderColor",t)},rotation:t=>{const e=t.detail.rotation;this.setRotation(e);this.annotationStorage.setValue(this.data.id,{rotation:e})}})}_dispatchEventFromSandbox(t,e){const i=this._commonActions;for(const n of Object.keys(e.detail)){const r=t[n]||i[n];r?.(e)}}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const i=this._commonActions;for(const[n,r]of Object.entries(e)){const s=i[n];if(s){s({detail:{[n]:r},target:t});delete e[n]}}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:t}=this.data;if(!t)return;const[e,i,n,r]=this.data.rect.map(Math.fround);if(8===t.length){const[s,a,o,l]=t.subarray(2,6);if(n===s&&r===a&&e===o&&i===l)return}const{style:s}=this.container;let a;if(this.#wo){const{borderColor:t,borderWidth:e}=s;s.borderWidth=0;a=["url('data:image/svg+xml;utf8,",`<svg xmlns="${fi}" preserveAspectRatio="none" viewBox="0 0 1 1">`,`<g fill="transparent" stroke="${t}" stroke-width="${e}">`];this.container.classList.add("hasBorder")}const o=n-e,l=r-i,c=AnnotationElement._svgFactory,h=c.createElement("svg");h.classList.add("quadrilateralsContainer");h.setAttribute("width",0);h.setAttribute("height",0);h.role="none";const d=c.createElement("defs");h.append(d);const u=c.createElement("clipPath"),p=`clippath_${this.data.id}`;u.setAttribute("id",p);u.setAttribute("clipPathUnits","objectBoundingBox");d.append(u);for(let i=2,n=t.length;i<n;i+=8){const n=t[i],s=t[i+1],h=t[i+2],d=t[i+3],p=c.createElement("rect"),g=(h-e)/o,m=(r-s)/l,f=(n-h)/o,b=(s-d)/l;p.setAttribute("x",g);p.setAttribute("y",m);p.setAttribute("width",f);p.setAttribute("height",b);u.append(p);a?.push(`<rect vector-effect="non-scaling-stroke" x="${g}" y="${m}" width="${f}" height="${b}"/>`)}if(this.#wo){a.push("</g></svg>')");s.backgroundImage=a.join("")}this.container.append(h);this.container.style.clipPath=`url(#${p})`}_createPopup(t=null){const{data:e}=this;let i,n;if(t){i={str:t.text};n=t.date}else{i=e.contentsObj;n=e.modificationDate}this.#vo=new PopupAnnotationElement({data:{color:e.color,titleObj:e.titleObj,modificationDate:n,contentsObj:i,richText:e.richText,parentRect:e.rect,borderStyle:0,id:`popup_${e.id}`,rotation:e.rotation,noRotate:!0},linkService:this.linkService,parent:this.parent,elements:[this]})}get hasPopupElement(){return!!(this.#vo||this.popup||this.data.popupRef)}get extraPopupElement(){return this.#vo}render(){unreachable("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const i=[];if(this._fieldObjects){const n=this._fieldObjects.get(t)||[];for(const{page:t,id:r,exportValues:s}of n){if(-1===t||r===e)continue;const n="string"==typeof s?s:null,a=document.querySelector(`[data-element-id="${r}"]`);!a||Qn.has(a)?i.push({id:r,exportValue:n,domElement:a}):warn(`_getElementsByName - element not allowed: ${r}`)}return i}for(const n of document.getElementsByName(t)){const{exportValue:t}=n,r=n.getAttribute("data-element-id");r!==e&&Qn.has(n)&&i.push({id:r,exportValue:t,domElement:n})}return i}show(){this.container&&(this.container.hidden=!1);this.popup?.maybeShow()}hide(){this.container&&(this.container.hidden=!0);this.popup?.forceHide()}getElementsToTriggerPopup(){return this.container}addHighlightArea(){const t=this.getElementsToTriggerPopup();if(Array.isArray(t))for(const e of t)e.classList.add("highlightArea");else t.classList.add("highlightArea")}_editOnDoubleClick(){if(!this._isEditable)return;const{annotationEditorType:t,data:{id:e}}=this;this.container.addEventListener("dblclick",()=>{this.linkService.eventBus?.dispatch("switchannotationeditormode",{source:this,mode:t,editId:e,mustEnterInEditMode:!0})})}updateOC(t){if(!this.data.oc||!t)return;t.isVisible(this.data.oc)?this.show():this.hide()}get width(){return this.data.rect[2]-this.data.rect[0]}get height(){return this.data.rect[3]-this.data.rect[1]}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=null===e?"transparent":Util.makeHexColor(...e)}}class EditorAnnotationElement extends AnnotationElement{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0});this.editor=t.editor}render(){this.container.className="editorAnnotation";return this.container}createOrUpdatePopup(){const{editor:t}=this;t.hasComment&&this._createPopup(t.comment)}get hasCommentButton(){return this.enableComment&&this.editor.hasComment}get commentButtonPosition(){return this.editor.commentButtonPositionInPage}get commentText(){return this.editor.comment.text}set commentText(t){this.editor.comment=t;t||this.removePopup()}get commentData(){return this.editor.getData()}remove(){this.parent.removeAnnotation(this.data.id);this.container.remove();this.container=null;this.removePopup()}}class LinkAnnotationElement extends AnnotationElement{constructor(t,e=null){super(t,{isRenderable:!0,ignoreBorder:!!e?.ignoreBorder,createQuadrilaterals:!0});this.isTooltipOnly=t.data.isTooltipOnly}render(){const{data:t,linkService:e}=this,i=document.createElement("a");i.setAttribute("data-element-id",t.id);let n=!1;if(t.url){e.addLinkAttributes(i,t.url,t.newWindow);n=!0}else if(t.action){this._bindNamedAction(i,t.action,t.overlaidText);n=!0}else if(t.attachment){this.#Ao(i,t.attachmentId,t.attachment,t.overlaidText,t.attachmentDest);n=!0}else if(t.setOCGState){this.#xo(i,t.setOCGState,t.overlaidText);n=!0}else if(t.dest){this._bindLink(i,t.dest,t.overlaidText);n=!0}else{if(t.actions&&(t.actions.has("Action")||t.actions.has("Mouse Up")||t.actions.has("Mouse Down"))&&this.enableScripting&&this.hasJSActions){this._bindJSAction(i,t);n=!0}if(t.resetForm){this._bindResetFormAction(i,t.resetForm);n=!0}else if(this.isTooltipOnly&&!n){this._bindLink(i,"");n=!0}}this.container.classList.add("linkAnnotation");if(n){this.contentElement=i;this.container.append(i)}return this.container}#Co(){this.container.setAttribute("data-internal-link","")}_bindLink(t,e,i=""){t.href=this.linkService.getDestinationHash(e);t.onclick=()=>{e&&this.linkService.goToDestination(e);return!1};(e||""===e)&&this.#Co();i&&(t.title=i)}_bindNamedAction(t,e,i=""){t.href=this.linkService.getAnchorUrl("");t.onclick=()=>{this.linkService.executeNamedAction(e);return!1};i&&(t.title=i);this.#Co()}#Ao(t,e,i,n="",r=null){t.href=this.linkService.getAnchorUrl("");i.description?t.title=i.description:n&&(t.title=n);const openAttachment=async()=>{const t=await this.linkService.getAttachmentContent(e);t&&this.downloadManager?.openOrDownloadData(t,i.filename,r)};t.onclick=()=>{openAttachment();return!1};this.#Co()}#xo(t,e,i=""){t.href=this.linkService.getAnchorUrl("");t.onclick=()=>{this.linkService.executeSetOCGState(e);return!1};i&&(t.title=i);this.#Co()}_bindJSAction(t,{actions:e,id:i,overlaidText:n}){t.href=this.linkService.getAnchorUrl("");const r=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const n of e.keys()){const e=r.get(n);e&&(t[e]=()=>{this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:i,name:n}});return!1})}n&&(t.title=n);t.onclick||=()=>!1;this.#Co()}_bindResetFormAction(t,e){const i=t.onclick;i||(t.href=this.linkService.getAnchorUrl(""));this.#Co();if(this._fieldObjects)t.onclick=()=>{i?.();const{fields:t,refs:n,include:r}=e,s=[];if(0!==t.length||0!==n.length){const e=new Set(n);for(const i of t){const t=this._fieldObjects.get(i)||[];for(const{id:i}of t)e.add(i)}const i=new Map;for(const t of this._fieldObjects.values())for(const{id:e,kidIds:n}of t)n&&i.set(e,n);for(const t of e)for(const n of i.get(t)||[])e.add(n);for(const t of this._fieldObjects.values())for(const i of t)e.has(i.id)===r&&s.push(i)}else for(const t of this._fieldObjects.values())s.push(...t);const a=this.annotationStorage,o=[];for(const t of s){const{id:e}=t;o.push(e);switch(t.type){case"text":{const i=t.defaultValue||"";a.setValue(e,{value:i});break}case"checkbox":case"radiobutton":{const i=t.defaultValue===t.exportValues;a.setValue(e,{value:i});break}case"combobox":case"listbox":{const i=t.defaultValue||"";a.setValue(e,{value:i});break}default:continue}const i=document.querySelector(`[data-element-id="${e}"]`);i&&(Qn.has(i)?i.dispatchEvent(new Event("resetform")):warn(`_bindResetFormAction - element not allowed: ${e}`))}this.enableScripting&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:o,name:"ResetForm"}});return!1};else{warn('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.');i||(t.onclick=()=>!1)}}}class TextAnnotationElement extends AnnotationElement{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");const t=document.createElement("img");t.src=this.imageResourcesPath+"annotation-"+this.data.name.toLowerCase()+".svg";t.setAttribute("data-l10n-id","pdfjs-text-annotation-type");t.setAttribute("data-l10n-args",JSON.stringify({type:this.data.name}));if(!this.data.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this.container.append(t);return this.container}}class WidgetAnnotationElement extends AnnotationElement{render(){return this.container}_getKeyModifier(t){return FeatureTest.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,i,n,r){i.includes("mouse")?t.addEventListener(i,t=>{this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:n,value:r(t),shift:t.shiftKey,modifier:this._getKeyModifier(t)}})}):t.addEventListener(i,t=>{if("blur"===i){if(!e.focused||!t.relatedTarget)return;e.focused=!1}else if("focus"===i){if(e.focused)return;e.focused=!0}r&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:n,value:r(t)}})})}_setEventListeners(t,e,i,n){const{actions:r}=this.data;for(const[s,a]of i)if("Action"===a||r?.has(a)){"Focus"!==a&&"Blur"!==a||(e||={focused:!1});this._setEventListener(t,e,s,a,n);"Focus"!==a||r?.has("Blur")?"Blur"!==a||r?.has("Focus")||this._setEventListener(t,e,"focus","Focus",null):this._setEventListener(t,e,"blur","Blur",null)}}_setTextStyle(t){const e=["left","center","right"],{fontColor:i}=this.data.defaultAppearanceData,n=this.data.defaultAppearanceData.fontSize||9,r=t.style;let s;const roundToOneDecimal=t=>Math.round(10*t)/10;if(this.data.multiLine){const t=Math.abs(this.data.rect[3]-this.data.rect[1]-2),e=t/(Math.round(t/(1.35*n))||1);s=Math.min(n,roundToOneDecimal(e/1.35))}else{const t=Math.abs(this.data.rect[3]-this.data.rect[1]-2);s=Math.min(n,roundToOneDecimal(t/1.35))}r.fontSize=`calc(${s}px * var(--total-scale-factor))`;r.color=Util.makeHexColor(...i);null===this.data.textAlignment||this.data.comb||(r.textAlign=e[this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required");t.setAttribute("aria-required",e)}}class TextWidgetAnnotationElement extends WidgetAnnotationElement{constructor(t){super(t,{isRenderable:t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue})}setPropertyOnSiblings(t,e,i,n){const r=this.annotationStorage;for(const s of this._getElementsByName(t.name,t.id)){s.domElement&&(s.domElement[e]=i);r.setValue(s.id,{[n]:i})}}render(){const t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let i=null;if(this.renderForms){const n=t.getValue(e,{value:this.data.fieldValue});let r=n.value||"";const s=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;s&&r.length>s&&(r=r.slice(0,s));let a=n.formattedValue||this.data.textContent?.join("\n")||null;a&&this.data.comb&&(a=a.replaceAll(/\s+/g,""));const o={userValue:r,formattedValue:a,lastCommittedValue:null,commitKey:1,focused:!1};if(this.data.multiLine){i=document.createElement("textarea");i.textContent=a??r;this.data.doNotScroll&&(i.style.overflowY="hidden")}else{i=document.createElement("input");i.type=this.data.password?"password":"text";i.setAttribute("value",a??r);this.data.doNotScroll&&(i.style.overflowX="hidden")}if(this.data.hasOwnCanvas){this.container.classList.add("hasOwnCanvas");t.has(e)&&this.container.classList.add("sandboxModified")}Qn.add(i);this.contentElement=i;i.setAttribute("data-element-id",e);i.disabled=this.data.readOnly;i.name=this.data.fieldName;i.tabIndex=0;const{datetimeFormat:l,datetimeType:c,timeStep:h}=this.data,d=!!c&&this.enableScripting;l&&(i.title=l);this._setRequired(i,this.data.required);s&&(i.maxLength=s);i.addEventListener("input",n=>{t.setValue(e,{value:n.target.value});this.setPropertyOnSiblings(i,"value",n.target.value,"value");o.formattedValue=null});i.addEventListener("resetform",t=>{const e=this.data.defaultFieldValue??"";i.value=o.userValue=e;o.formattedValue=null});let blurListener=t=>{const{formattedValue:e}=o;null!=e&&(t.target.value=e);t.target.scrollLeft=0};if(this.enableScripting&&this.hasJSActions){i.addEventListener("focus",t=>{if(o.focused)return;const{target:e}=t;if(d){e.type=c;h&&(e.step=h)}if(o.userValue){const t=o.userValue;if(d)if("time"===c){const i=new Date(t),n=[i.getHours(),i.getMinutes(),i.getSeconds()];e.value=n.map(t=>t.toString().padStart(2,"0")).join(":")}else e.value=new Date(t-Zn).toISOString().split("date"===c?"T":".",1)[0];else e.value=t}o.lastCommittedValue=e.value;o.commitKey=1;this.data.actions?.has("Focus")||(o.focused=!0)});i.addEventListener("updatefromsandbox",i=>{this.container.classList.add("sandboxModified");const n={value(i){o.userValue=i.detail.value??"";d||t.setValue(e,{value:o.userValue.toString()});i.target.value=o.userValue},formattedValue(i){const{formattedValue:n}=i.detail;o.formattedValue=n;null!=n&&i.target!==document.activeElement&&(i.target.value=n);const r={formattedValue:n};d&&(r.value=n);t.setValue(e,r)},selRange(t){t.target.setSelectionRange(...t.detail.selRange)},charLimit:i=>{const{charLimit:n}=i.detail,{target:r}=i;if(0===n){r.removeAttribute("maxLength");return}r.setAttribute("maxLength",n);let s=o.userValue;if(s&&!(s.length<=n)){s=s.slice(0,n);r.value=o.userValue=s;t.setValue(e,{value:s});this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:s,willCommit:!0,commitKey:1,selStart:r.selectionStart,selEnd:r.selectionEnd}})}}};this._dispatchEventFromSandbox(n,i)});i.addEventListener("keydown",t=>{o.commitKey=1;let i=-1;"Escape"===t.key?i=0:"Enter"!==t.key||this.data.multiLine?"Tab"===t.key&&(o.commitKey=3):i=2;if(-1===i)return;const{value:n}=t.target;if(o.lastCommittedValue!==n){o.lastCommittedValue=n;o.userValue=n;this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:n,willCommit:!0,commitKey:i,selStart:t.target.selectionStart,selEnd:t.target.selectionEnd}})}});const n=blurListener;blurListener=null;i.addEventListener("blur",t=>{if(!o.focused||!t.relatedTarget)return;this.data.actions?.has("Blur")||(o.focused=!1);const{target:i}=t;let{value:r}=i;if(d){if(r&&"time"===c){const t=r.split(":").map(t=>parseInt(t,10));r=new Date(2e3,0,1,t[0],t[1],t[2]||0).valueOf();i.step=""}else{r.includes("T")||(r=`${r}T00:00`);r=new Date(r).valueOf()}i.type="text"}o.userValue=r;o.lastCommittedValue!==r&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:r,willCommit:!0,commitKey:o.commitKey,selStart:t.target.selectionStart,selEnd:t.target.selectionEnd}});n(t)});this.data.actions?.has("Keystroke")&&i.addEventListener("beforeinput",t=>{o.lastCommittedValue=null;const{data:i,target:n}=t,{value:r,selectionStart:s,selectionEnd:a}=n;let l=s,c=a;switch(t.inputType){case"deleteWordBackward":{const t=/\w/;for(;l>0&&!t.test(r[l-1]);)l--;for(;l>0&&t.test(r[l-1]);)l--;break}case"deleteWordForward":{const t=r.substring(s).match(/^\W*\w*/);t&&(c+=t[0].length);break}case"deleteContentBackward":s===a&&(l-=1);break;case"deleteContentForward":s===a&&(c+=1)}t.preventDefault();this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:r,change:i||"",willCommit:!1,selStart:l,selEnd:c}})});this._setEventListeners(i,o,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],t=>t.target.value)}blurListener&&i.addEventListener("blur",blurListener);if(this.data.comb){const t=(this.data.rect[2]-this.data.rect[0])/s;i.classList.add("comb");i.style.setProperty("--comb-width",`calc(${t}px * var(--total-scale-factor))`);const e=this.data.textAlignment;if(1===e||2===e){const setCombOffset=()=>{const t=s-i.value.length;i.style.setProperty("--comb-offset",`${1===e?t>>1:t}`)};setCombOffset();for(const t of["input","blur","resetform","updatefromsandbox"])i.addEventListener(t,setCombOffset)}}}else{i=document.createElement("div");i.textContent=this.data.fieldValue;i.style.verticalAlign="middle";i.style.display="table-cell";this.data.hasOwnCanvas&&(i.hidden=!0)}this._setTextStyle(i);this._setBackgroundColor(i);this._setDefaultPropertiesFromJS(i);this.container.append(i);return this.container}}class SignatureWidgetAnnotationElement extends WidgetAnnotationElement{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class CheckboxWidgetAnnotationElement extends WidgetAnnotationElement{constructor(t){super(t,{isRenderable:t.renderForms})}render(){const t=this.annotationStorage,e=this.data,i=e.id;let n=t.getValue(i,{value:e.exportValue===e.fieldValue}).value;if("string"==typeof n){n="Off"!==n;t.setValue(i,{value:n})}this.container.classList.add("buttonWidgetAnnotation","checkBox");const r=document.createElement("input");Qn.add(r);r.setAttribute("data-element-id",i);r.disabled=e.readOnly;this._setRequired(r,this.data.required);r.type="checkbox";r.name=e.fieldName;n&&r.setAttribute("checked",!0);r.setAttribute("exportValue",e.exportValue);r.tabIndex=0;r.addEventListener("change",n=>{const{name:r,checked:s}=n.target;for(const n of this._getElementsByName(r,i)){const i=s&&n.exportValue===e.exportValue;n.domElement&&(n.domElement.checked=i);t.setValue(n.id,{value:i})}t.setValue(i,{value:s})});r.addEventListener("resetform",t=>{const i=e.defaultFieldValue||"Off";t.target.checked=i===e.exportValue});if(this.enableScripting&&this.hasJSActions){r.addEventListener("updatefromsandbox",e=>{const n={value(e){e.target.checked="Off"!==e.detail.value;t.setValue(i,{value:e.target.checked})}};this._dispatchEventFromSandbox(n,e)});this._setEventListeners(r,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],t=>t.target.checked)}this._setDefaultPropertiesFromJS(r);this.container.append(r);return this.container}}class RadioButtonWidgetAnnotationElement extends WidgetAnnotationElement{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("buttonWidgetAnnotation","radioButton");const t=this.annotationStorage,e=this.data,i=e.id;let n=t.getValue(i,{value:null!==e.buttonValue&&e.fieldValue===e.buttonValue}).value;if("string"==typeof n){n=n!==e.buttonValue;t.setValue(i,{value:n})}if(n)for(const n of this._getElementsByName(e.fieldName,i))t.setValue(n.id,{value:!1});const r=document.createElement("input");Qn.add(r);r.setAttribute("data-element-id",i);r.disabled=e.readOnly;this._setRequired(r,this.data.required);r.type="radio";r.name=e.fieldName;n&&r.setAttribute("checked",!0);r.tabIndex=0;r.addEventListener("change",e=>{const{name:n,checked:r}=e.target;for(const e of this._getElementsByName(n,i))t.setValue(e.id,{value:!1});t.setValue(i,{value:r})});r.addEventListener("resetform",t=>{const i=e.defaultFieldValue;t.target.checked=null!=i&&i===e.buttonValue});if(this.enableScripting&&this.hasJSActions){const n=e.buttonValue;r.addEventListener("updatefromsandbox",e=>{const r={value:e=>{const r=n===e.detail.value;for(const n of this._getElementsByName(e.target.name)){const e=r&&n.id===i;n.domElement&&(n.domElement.checked=e);t.setValue(n.id,{value:e})}}};this._dispatchEventFromSandbox(r,e)});this._setEventListeners(r,null,[["change","Validate"],["change","Action"],["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"]],t=>t.target.checked)}this._setDefaultPropertiesFromJS(r);this.container.append(r);return this.container}}class PushButtonWidgetAnnotationElement extends LinkAnnotationElement{constructor(t){super(t,{ignoreBorder:t.data.hasAppearance})}render(){const t=super.render();t.classList.add("buttonWidgetAnnotation","pushButton");const e=t.lastChild;if(this.enableScripting&&this.hasJSActions&&e){this._setDefaultPropertiesFromJS(e);e.addEventListener("updatefromsandbox",t=>{this._dispatchEventFromSandbox({},t)})}return t}}class ChoiceWidgetAnnotationElement extends WidgetAnnotationElement{constructor(t){super(t,{isRenderable:t.renderForms})}render(){this.container.classList.add("choiceWidgetAnnotation");const t=this.annotationStorage,e=this.data.id,i=t.getValue(e,{value:this.data.fieldValue}),n=document.createElement("select");Qn.add(n);n.setAttribute("data-element-id",e);n.disabled=this.data.readOnly;this._setRequired(n,this.data.required);n.name=this.data.fieldName;n.tabIndex=0;let r=this.data.combo&&this.data.options.length>0;if(!this.data.combo){n.size=this.data.options.length;this.data.multiSelect&&(n.multiple=!0)}n.addEventListener("resetform",t=>{const e=this.data.defaultFieldValue;for(const t of n.options)t.selected=t.value===e});const fixDisplayValue=(t,e)=>{const i=e.replaceAll(" "," ");t.textContent=i;i!==e&&t.setAttribute("display-value",e)};for(const t of this.data.options){const e=document.createElement("option");fixDisplayValue(e,t.displayValue);e.value=t.exportValue;if(i.value.includes(t.exportValue)){e.setAttribute("selected",!0);r=!1}n.append(e)}let s=null;if(r){const t=document.createElement("option");t.value=" ";t.setAttribute("hidden",!0);t.setAttribute("selected",!0);n.prepend(t);s=()=>{t.remove();n.removeEventListener("input",s);s=null};n.addEventListener("input",s)}const getValue=t=>{const e=t?"value":"textContent",{options:i,multiple:r}=n;return r?Array.prototype.filter.call(i,t=>t.selected).map(t=>t[e]):-1===i.selectedIndex?null:i[i.selectedIndex][e]};let a=getValue(!1);const getItems=t=>{const e=t.target.options;return Array.prototype.map.call(e,t=>({displayValue:t.getAttribute("display-value")||t.textContent,exportValue:t.value}))};if(this.enableScripting&&this.hasJSActions){n.addEventListener("updatefromsandbox",i=>{const r={value(i){s?.();const r=i.detail.value,o=new Set(Array.isArray(r)?r:[r]);for(const t of n.options)t.selected=o.has(t.value);t.setValue(e,{value:getValue(!0)});a=getValue(!1)},multipleSelection(t){n.multiple=!0},remove(i){const r=n.options,s=i.detail.remove;r[s].selected=!1;n.remove(s);if(r.length>0){-1===Array.prototype.findIndex.call(r,t=>t.selected)&&(r[0].selected=!0)}t.setValue(e,{value:getValue(!0),items:getItems(i)});a=getValue(!1)},clear(i){for(;0!==n.length;)n.remove(0);t.setValue(e,{value:null,items:[]});a=getValue(!1)},insert(i){const{index:r,displayValue:s,exportValue:o}=i.detail.insert,l=n.children[r],c=document.createElement("option");fixDisplayValue(c,s);c.value=o;l?l.before(c):n.append(c);t.setValue(e,{value:getValue(!0),items:getItems(i)});a=getValue(!1)},items(i){const{items:r}=i.detail;for(;0!==n.length;)n.remove(0);for(const t of r){const{displayValue:e,exportValue:i}=t,r=document.createElement("option");fixDisplayValue(r,e);r.value=i;n.append(r)}n.options.length>0&&(n.options[0].selected=!0);t.setValue(e,{value:getValue(!0),items:getItems(i)});a=getValue(!1)},indices(i){const n=new Set(i.detail.indices);for(const t of i.target.options)t.selected=n.has(t.index);t.setValue(e,{value:getValue(!0)});a=getValue(!1)},editable(t){t.target.disabled=!t.detail.editable}};this._dispatchEventFromSandbox(r,i)});n.addEventListener("input",i=>{const n=getValue(!0),r=getValue(!1);t.setValue(e,{value:n});i.preventDefault();this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:a,change:r,changeEx:n,willCommit:!1,commitKey:1,keyDown:!1}})});this._setEventListeners(n,null,[["focus","Focus"],["blur","Blur"],["mousedown","Mouse Down"],["mouseenter","Mouse Enter"],["mouseleave","Mouse Exit"],["mouseup","Mouse Up"],["input","Action"],["input","Validate"]],t=>t.target.value)}else n.addEventListener("input",function(i){t.setValue(e,{value:getValue(!0)})});this.data.combo&&this._setTextStyle(n);this._setBackgroundColor(n);this._setDefaultPropertiesFromJS(n);this.container.append(n);return this.container}}class PopupAnnotationElement extends AnnotationElement{constructor(t){const{data:e,elements:i,parent:n}=t,r=!!n._commentManager;super(t,{isRenderable:!r&&AnnotationElement._hasPopupData(e)});this.elements=i;if(r&&AnnotationElement._hasPopupData(e)){const t=this.popup=this.#Eo();for(const e of i)e.popup=t}else this.popup=null}#Eo(){return new PopupElement({container:this.container,color:this.data.color,titleObj:this.data.titleObj,modificationDate:this.data.modificationDate||this.data.creationDate,contentsObj:this.data.contentsObj,richText:this.data.richText,rect:this.data.rect,parentRect:this.data.parentRect||null,parent:this.parent,elements:this.elements,open:this.data.open,commentManager:this.parent._commentManager})}render(){const{container:t}=this;t.classList.add("popupAnnotation");t.role="comment";const e=this.popup=this.#Eo(),i=[];for(const t of this.elements){t.popup=e;t.container.ariaHasPopup="dialog";i.push(t.data.id);t.addHighlightArea()}this.container.setAttribute("aria-controls",i.map(t=>`${Si}${t}`).join(","));return this.container}}class PopupElement{#$=null;#So=this.#uo.bind(this);#To=this.#ko.bind(this);#Po=this.#Mo.bind(this);#Do=this.#Io.bind(this);#Fo=null;#Pt=null;#Oo=null;#Ro=null;#Bo=null;#Lo=null;#No=null;#Uo=!1;#Ho=null;#zo=null;#F=null;#Go=null;#Wo=null;#_e=null;#jo=null;#be=null;#Vo=null;#yo=null;#qo=!1;#$o=null;#Xo=null;constructor({container:t,color:e,elements:i,titleObj:n,modificationDate:r,contentsObj:s,richText:a,parent:o,rect:l,parentRect:c,open:h,commentManager:d=null}){this.#Pt=t;this.#Vo=n;this.#Oo=s;this.#be=a;this.#Lo=o;this.#Fo=e;this.#jo=l;this.#No=c;this.#Bo=i;this.#$=d;this.#$o=i[0];this.#Ro=PDFDateString.toDateObject(r);this.trigger=i.flatMap(t=>t.getElementsToTriggerPopup());if(!d){this.#Ko();this.#Pt.hidden=!0;h&&this.#Io()}}#Ko(){if(this.#zo)return;this.#zo=new AbortController;const{signal:t}=this.#zo;for(const e of this.trigger){e.addEventListener("click",this.#Do,{signal:t});e.addEventListener("pointerenter",this.#Po,{signal:t});e.addEventListener("pointerleave",this.#To,{signal:t});e.classList.add("popupTriggerArea")}for(const e of this.#Bo)e.container?.addEventListener("keydown",this.#So,{signal:t})}#Yo(){const t=this.#Bo.find(t=>t.hasCommentButton);t&&(this.#Wo=t._normalizePoint(t.commentButtonPosition))}renderCommentButton(){if(this.#Go){this.#Go.parentNode||this.#$o.container.after(this.#Go);return}this.#Wo||this.#Yo();if(!this.#Wo)return;const{signal:t}=this.#zo=new AbortController,e=this.#$o.hasOwnCommentButton,togglePopup=()=>{this.#$.toggleCommentPopup(this,!0,void 0,!e)},showPopup=()=>{this.#$.toggleCommentPopup(this,!1,!0,!e)},hidePopup=()=>{this.#$.toggleCommentPopup(this,!1,!1)};if(e){this.#Go=this.#$o.container;for(const e of this.trigger){e.ariaHasPopup="dialog";e.ariaControls="commentPopup";e.addEventListener("keydown",this.#So,{signal:t});e.addEventListener("click",togglePopup,{signal:t});e.addEventListener("pointerenter",showPopup,{signal:t});e.addEventListener("pointerleave",hidePopup,{signal:t});e.classList.add("popupTriggerArea")}}else{const e=this.#Go=document.createElement("button");e.className="annotationCommentButton";const i=this.#$o.container;e.style.zIndex=parseInt(i.style.zIndex,10)+1;e.tabIndex=0;e.ariaHasPopup="dialog";e.ariaControls="commentPopup";e.setAttribute("data-l10n-id","pdfjs-show-comment-button");this.#Jo();this.#Qo();e.addEventListener("keydown",this.#So,{signal:t});e.addEventListener("click",togglePopup,{signal:t});e.addEventListener("pointerenter",showPopup,{signal:t});e.addEventListener("pointerleave",hidePopup,{signal:t});i.after(e)}}#Qo(){if(this.#$o.extraPopupElement&&!this.#$o.editor)return;this.#Go||this.renderCommentButton();const[t,e]=this.#Wo,{style:i}=this.#Go;i.left=`calc(${t}%)`;i.top=`calc(${e}% - var(--comment-button-dim))`}#Jo(){if(!this.#$o.extraPopupElement){this.#Go||this.renderCommentButton();this.#Go.style.backgroundColor=this.commentButtonColor||""}}get commentButtonColor(){const{color:t,opacity:e}=this.#$o.commentData;return t?this.#Lo._commentManager.makeCommentColor(t,e):null}focusCommentButton(){setTimeout(()=>{this.#Go?.focus()},0)}getData(){const{richText:t,color:e,opacity:i,creationDate:n,modificationDate:r}=this.#$o.commentData;return{contentsObj:{str:this.comment},richText:t,color:e,opacity:i,creationDate:n,modificationDate:r}}get elementBeforePopup(){return this.#Go}get comment(){this.#Xo||=this.#$o.commentText;return this.#Xo}set comment(t){t!==this.comment&&(this.#$o.commentText=this.#Xo=t)}focus(){this.#$o.container?.focus()}get parentBoundingClientRect(){return this.#$o.layer.getBoundingClientRect()}setCommentButtonStates({selected:t,hasPopup:e}){if(this.#Go){this.#Go.classList.toggle("selected",t);this.#Go.ariaExpanded=e}}setSelectedCommentButton(t){this.#Go.classList.toggle("selected",t)}get commentPopupPosition(){if(this.#_e)return this.#_e;const{x:t,y:e,height:i}=this.#Go.getBoundingClientRect(),{x:n,y:r,width:s,height:a}=this.#$o.layer.getBoundingClientRect();return[(t-n)/s,(e+i-r)/a]}set commentPopupPosition(t){this.#_e=t}hasDefaultPopupPosition(){return null===this.#_e}get commentButtonPosition(){return this.#Wo}get commentButtonWidth(){return this.#Go.getBoundingClientRect().width/this.parentBoundingClientRect.width}editComment(t){const[e,i]=this.#_e||this.commentButtonPosition.map(t=>t/100),n=this.parentBoundingClientRect,{x:r,y:s,width:a,height:o}=n;this.#$.showDialog(null,this,r+e*a,s+i*o,{...t,parentDimensions:n})}render(){if(this.#Ho)return;const t=this.#Ho=document.createElement("div");t.className="popup";if(this.#Fo){const e=t.style.outlineColor=Util.makeHexColor(...this.#Fo);t.style.backgroundColor=`color-mix(in srgb, ${e} 30%, white)`}const e=document.createElement("span");e.className="header";if(this.#Vo?.str){const t=document.createElement("span");t.className="title";e.append(t);({dir:t.dir,str:t.textContent}=this.#Vo)}t.append(e);if(this.#Ro){const t=document.createElement("time");t.className="popupDate";t.setAttribute("data-l10n-id","pdfjs-annotation-date-time-string");t.setAttribute("data-l10n-args",JSON.stringify({dateObj:this.#Ro.valueOf()}));t.dateTime=this.#Ro.toISOString();e.append(t)}renderRichText({html:this.#Zo||this.#Oo.str,dir:this.#Oo?.dir,className:"popupContent"},t);this.#Pt.append(t)}get#Zo(){const t=this.#be,e=this.#Oo;return!t?.str||e?.str&&e.str!==t.str?null:this.#be.html||null}get#tl(){return this.#Zo?.attributes?.style?.fontSize||0}get#el(){return this.#Zo?.attributes?.style?.color||null}#il(t){const e=[],i={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},n={style:{color:this.#el,fontSize:this.#tl?`calc(${this.#tl}px * var(--total-scale-factor))`:""}};for(const i of t.split("\n"))e.push({name:"span",value:i,attributes:n});return i}#uo(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||("Enter"===t.key||"Escape"===t.key&&this.#Uo)&&this.#Io()}updateEdited({rect:t,popup:e,deleted:i}){if(this.#$){if(i){this.remove();this.#Xo=null}else if(e)if(e.deleted)this.remove();else{this.#Jo();this.#Xo=e.text}if(t){this.#Wo=null;this.#Yo();this.#Qo()}}else if(i||e?.deleted)this.remove();else{this.#Ko();this.#yo||={contentsObj:this.#Oo,richText:this.#be};t&&(this.#F=null);if(e&&e.text){this.#be=this.#il(e.text);this.#Ro=PDFDateString.toDateObject(e.date);this.#Oo=null}this.#Ho?.remove();this.#Ho=null}}resetEdited(){if(this.#yo){({contentsObj:this.#Oo,richText:this.#be}=this.#yo);this.#yo=null;this.#Ho?.remove();this.#Ho=null;this.#F=null}}remove(){this.#zo?.abort();this.#zo=null;this.#Ho?.remove();this.#Ho=null;this.#qo=!1;this.#Uo=!1;this.#Go?.remove();this.#Go=null;if(this.trigger)for(const t of this.trigger)t.classList.remove("popupTriggerArea")}#nl(){if(null!==this.#F)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:i,pageX:n,pageY:r}}}=this.#Lo;let s=!!this.#No,a=s?this.#No:this.#jo;for(const t of this.#Bo)if(!a||null!==Util.intersect(t.data.rect,a)){a=t.data.rect;s=!0;break}const o=Util.normalizeRect([a[0],t[3]-a[1]+t[1],a[2],t[3]-a[3]+t[1]]),l=s?a[2]-a[0]+5:0,c=o[0]+l,h=o[1];this.#F=[100*(c-n)/e,100*(h-r)/i];const{style:d}=this.#Pt;d.left=`${this.#F[0]}%`;d.top=`${this.#F[1]}%`}#Io(){if(this.#$)this.#$.toggleCommentPopup(this,!1);else{this.#Uo=!this.#Uo;if(this.#Uo){this.#Mo();this.#Pt.addEventListener("click",this.#Do);this.#Pt.addEventListener("keydown",this.#So)}else{this.#ko();this.#Pt.removeEventListener("click",this.#Do);this.#Pt.removeEventListener("keydown",this.#So)}}}#Mo(){this.#Ho||this.render();if(this.isVisible)this.#Uo&&this.#Pt.classList.add("focused");else{this.#nl();this.#Pt.hidden=!1;this.#Pt.style.zIndex=parseInt(this.#Pt.style.zIndex,10)+1e3}}#ko(){this.#Pt.classList.remove("focused");if(!this.#Uo&&this.isVisible){this.#Pt.hidden=!0;this.#Pt.style.zIndex=parseInt(this.#Pt.style.zIndex,10)-1e3}}forceHide(){this.#qo=this.isVisible;this.#qo&&(this.#Pt.hidden=!0)}maybeShow(){if(!this.#$){this.#Ko();if(this.#qo){this.#Ho||this.#Mo();this.#qo=!1;this.#Pt.hidden=!1}}}get isVisible(){return!this.#$&&!1===this.#Pt.hidden}}class FreeTextAnnotationElement extends AnnotationElement{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0});this.textContent=t.data.textContent;this.textPosition=t.data.textPosition;this.annotationEditorType=ki.FREETEXT}render(){this.container.classList.add("freeTextAnnotation");if(this.textContent){const t=this.contentElement=document.createElement("div");t.classList.add("annotationTextContent");t.setAttribute("role","comment");for(const e of this.textContent){const i=document.createElement("span");i.textContent=e;t.append(i)}this.container.append(t)}if(!this.data.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this._editOnDoubleClick();return this.container}}class LineAnnotationElement extends AnnotationElement{#rl=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("lineAnnotation");const{data:t,width:e,height:i}=this,n=AnnotationElement._svgFactory,r=n.create(e,i,!0),s=this.#rl=n.createElement("svg:line");s.setAttribute("x1",t.rect[2]-t.lineCoordinates[0]);s.setAttribute("y1",t.rect[3]-t.lineCoordinates[1]);s.setAttribute("x2",t.rect[2]-t.lineCoordinates[2]);s.setAttribute("y2",t.rect[3]-t.lineCoordinates[3]);s.setAttribute("stroke-width",t.borderStyle.width||1);s.setAttribute("stroke","transparent");s.setAttribute("fill","transparent");r.append(s);this.container.append(r);if(!t.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}return this.container}getElementsToTriggerPopup(){return this.#rl}addHighlightArea(){this.container.classList.add("highlightArea")}}class SquareAnnotationElement extends AnnotationElement{#sl=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("squareAnnotation");const{data:t,width:e,height:i}=this,n=AnnotationElement._svgFactory,r=n.create(e,i,!0),s=t.borderStyle.width,a=this.#sl=n.createElement("svg:rect");a.setAttribute("x",s/2);a.setAttribute("y",s/2);a.setAttribute("width",e-s);a.setAttribute("height",i-s);a.setAttribute("stroke-width",s||1);a.setAttribute("stroke","transparent");a.setAttribute("fill","transparent");r.append(a);this.container.append(r);if(!t.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}return this.container}getElementsToTriggerPopup(){return this.#sl}addHighlightArea(){this.container.classList.add("highlightArea")}}class CircleAnnotationElement extends AnnotationElement{#al=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("circleAnnotation");const{data:t,width:e,height:i}=this,n=AnnotationElement._svgFactory,r=n.create(e,i,!0),s=t.borderStyle.width,a=this.#al=n.createElement("svg:ellipse");a.setAttribute("cx",e/2);a.setAttribute("cy",i/2);a.setAttribute("rx",e/2-s/2);a.setAttribute("ry",i/2-s/2);a.setAttribute("stroke-width",s||1);a.setAttribute("stroke","transparent");a.setAttribute("fill","transparent");r.append(a);this.container.append(r);if(!t.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}return this.container}getElementsToTriggerPopup(){return this.#al}addHighlightArea(){this.container.classList.add("highlightArea")}}class PolylineAnnotationElement extends AnnotationElement{#ol=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0});this.containerClassName="polylineAnnotation";this.svgElementName="svg:polyline"}render(){this.container.classList.add(this.containerClassName);const{data:{rect:t,vertices:e,borderStyle:i,popupRef:n},width:r,height:s}=this;if(!e)return this.container;const a=AnnotationElement._svgFactory,o=a.create(r,s,!0);let l=[];for(let i=0,n=e.length;i<n;i+=2){const n=e[i]-t[0],r=t[3]-e[i+1];l.push(`${n},${r}`)}l=l.join(" ");const c=this.#ol=a.createElement(this.svgElementName);c.setAttribute("points",l);c.setAttribute("stroke-width",i.width||1);c.setAttribute("stroke","transparent");c.setAttribute("fill","transparent");o.append(c);this.container.append(o);if(!n&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}return this.container}getElementsToTriggerPopup(){return this.#ol}addHighlightArea(){this.container.classList.add("highlightArea")}}class PolygonAnnotationElement extends PolylineAnnotationElement{constructor(t){super(t);this.containerClassName="polygonAnnotation";this.svgElementName="svg:polygon"}}class CaretAnnotationElement extends AnnotationElement{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("caretAnnotation");if(!this.data.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}return this.container}}class InkAnnotationElement extends AnnotationElement{#ll=null;#cl=[];constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0});this.containerClassName="inkAnnotation";this.svgElementName="svg:polyline";this.annotationEditorType="InkHighlight"===this.data.it?ki.HIGHLIGHT:ki.INK}#hl(t,e){switch(t){case 90:return{transform:`rotate(90) translate(${-e[0]},${e[1]}) scale(1,-1)`,width:e[3]-e[1],height:e[2]-e[0]};case 180:return{transform:`rotate(180) translate(${-e[2]},${e[1]}) scale(1,-1)`,width:e[2]-e[0],height:e[3]-e[1]};case 270:return{transform:`rotate(270) translate(${-e[2]},${e[3]}) scale(1,-1)`,width:e[3]-e[1],height:e[2]-e[0]};default:return{transform:`translate(${-e[0]},${e[3]}) scale(1,-1)`,width:e[2]-e[0],height:e[3]-e[1]}}}render(){this.container.classList.add(this.containerClassName);const{data:{rect:t,rotation:e,inkLists:i,borderStyle:n,popupRef:r}}=this,{transform:s,width:a,height:o}=this.#hl(e,t),l=AnnotationElement._svgFactory,c=l.create(a,o,!0),h=this.#ll=l.createElement("svg:g");c.append(h);h.setAttribute("stroke-width",n.width||1);h.setAttribute("stroke-linecap","round");h.setAttribute("stroke-linejoin","round");h.setAttribute("stroke-miterlimit",10);h.setAttribute("stroke","transparent");h.setAttribute("fill","transparent");h.setAttribute("transform",s);for(const t of i){const e=l.createElement(this.svgElementName);this.#cl.push(e);e.setAttribute("points",t.join(","));h.append(e)}if(!r&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this.container.append(c);this._editOnDoubleClick();return this.container}updateEdited(t){super.updateEdited(t);const{thickness:e,points:i,rect:n}=t,r=this.#ll;e>=0&&r.setAttribute("stroke-width",e||1);if(i)for(let t=0,e=this.#cl.length;t<e;t++)this.#cl[t].setAttribute("points",i[t].join(","));if(n){const{transform:t,width:e,height:i}=this.#hl(this.data.rotation,n);r.parentElement.setAttribute("viewBox",`0 0 ${e} ${i}`);r.setAttribute("transform",t)}}getElementsToTriggerPopup(){return this.#cl}addHighlightArea(){this.container.classList.add("highlightArea")}}class HighlightAnnotationElement extends AnnotationElement{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0});this.annotationEditorType=ki.HIGHLIGHT}render(){const{data:{overlaidText:t,popupRef:e}}=this;if(!e&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this.container.classList.add("highlightAnnotation");this._editOnDoubleClick();if(t){const e=document.createElement("mark");e.classList.add("overlaidText");e.textContent=t;this.container.append(e)}return this.container}}class UnderlineAnnotationElement extends AnnotationElement{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){const{data:{overlaidText:t,popupRef:e}}=this;if(!e&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this.container.classList.add("underlineAnnotation");if(t){const e=document.createElement("u");e.classList.add("overlaidText");e.textContent=t;this.container.append(e)}return this.container}}class SquigglyAnnotationElement extends AnnotationElement{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){const{data:{overlaidText:t,popupRef:e}}=this;if(!e&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this.container.classList.add("squigglyAnnotation");if(t){const e=document.createElement("u");e.classList.add("overlaidText");e.textContent=t;this.container.append(e)}return this.container}}class StrikeOutAnnotationElement extends AnnotationElement{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0})}render(){const{data:{overlaidText:t,popupRef:e}}=this;if(!e&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this.container.classList.add("strikeoutAnnotation");if(t){const e=document.createElement("s");e.classList.add("overlaidText");e.textContent=t;this.container.append(e)}return this.container}}class StampAnnotationElement extends AnnotationElement{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0});this.annotationEditorType=ki.STAMP}render(){this.container.classList.add("stampAnnotation");this.container.setAttribute("role","img");if(!this.data.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this._editOnDoubleClick();return this.container}}class FileAttachmentAnnotationElement extends AnnotationElement{#dl=null;constructor(t){super(t,{isRenderable:!0});const{fileId:e,file:i}=this.data;this.filename=i.filename;this.content=i.content;this.fileId=e;this.linkService.eventBus?.dispatch("fileattachmentannotation",{source:this,attachmentId:this.fileId,...i})}render(){this.container.classList.add("fileAttachmentAnnotation");const{container:t,data:e}=this;let i;if(e.hasAppearance||0===e.fillAlpha)i=document.createElement("div");else{i=document.createElement("img");i.src=`${this.imageResourcesPath}annotation-${/paperclip/i.test(e.name)?"paperclip":"pushpin"}.svg`;e.fillAlpha&&e.fillAlpha<1&&(i.style=`filter: opacity(${Math.round(100*e.fillAlpha)}%);`)}i.addEventListener("dblclick",this.#ul.bind(this));this.#dl=i;const{isMac:n}=FeatureTest.platform;t.addEventListener("keydown",t=>{"Enter"===t.key&&(n?t.metaKey:t.ctrlKey)&&this.#ul()});if(!e.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}else i.classList.add("popupTriggerArea");t.append(i);return t}getElementsToTriggerPopup(){return this.#dl}addHighlightArea(){this.container.classList.add("highlightArea")}async#ul(){const{fileId:t,filename:e,content:i}=this,n=await this.linkService.getAttachmentContent(t)||i;n&&this.downloadManager?.openOrDownloadData(n,e)}}class MediaAnnotationElement extends AnnotationElement{#B=new AbortController;#pl=null;#gl=null;constructor(t){super(t,{isRenderable:!!t.data.richMedia})}render(){this.container.classList.add("mediaAnnotation");const{filename:t}=this.data.richMedia,e=document.createElement("button");e.className="mediaPlayButton";e.type="button";e.title=e.ariaLabel=t;e.addEventListener("click",()=>this.#ml(e),{signal:this.#B.signal});this.container.append(e);return this.container}async#ml(t){const{fileId:e,filename:i,contentType:n}=this.data.richMedia;t.disabled=!0;let r;try{r=await this.linkService.getAttachmentContent(e)}catch{return}finally{t.disabled=!1}if(!r||!t.isConnected)return;const{signal:s}=this.#B,a=new Blob([r],{type:n});if(!/^(?:video|audio)\//.test(a.type))return;const o=URL.createObjectURL(a);this.#pl=o;const l=a.type.startsWith("audio/"),c=document.createElement(l?"audio":"video");this.#gl=c;c.className="mediaContent";this._setBackgroundColor(c);c.src=o;c.title=i;c.controls=!0;c.autoplay=!0;c.tabIndex=0;if(l){let t=!1,e=!1;const updateControls=()=>{c.controls=t||e};this.container.addEventListener("pointerenter",()=>{t=!0;updateControls()},{signal:s});this.container.addEventListener("pointerleave",()=>{t=!1;updateControls()},{signal:s});this.container.addEventListener("focusin",()=>{e=!0;updateControls()},{signal:s});this.container.addEventListener("focusout",()=>{e=!1;updateControls()},{signal:s})}c.addEventListener("emptied",()=>this.#fl(o),{once:!0,signal:s});t.replaceWith(c);c.play().catch(()=>{})}#fl(t=this.#pl){if(t&&t===this.#pl){URL.revokeObjectURL(t);this.#pl=null}}destroy(){this.#B.abort();if(this.#gl){this.#gl.pause();this.#gl.removeAttribute("src");this.#gl.load();this.#gl=null}this.#fl()}}class AnnotationLayer{#bl=null;#xs=null;#j=null;#yl=new Map;#wl=null;#vl=null;#Bo=[];#_l=!1;zIndex=0;constructor({div:t,accessibilityManager:e,annotationCanvasMap:i,annotationEditorUIManager:n,page:r,viewport:s,structTreeLayer:a,commentManager:o,linkService:l,annotationStorage:c}){this.div=t;this.#bl=e;this.#xs=i;this.#wl=a||null;this.#vl=l||null;this.#j=c||new AnnotationStorage;this.page=r;this.viewport=s;this._annotationEditorUIManager=n;this._commentManager=o||null}hasEditableAnnotations(){return this.#yl.size>0}async render(t){const{annotations:e,optionalContentConfig:i}=t,n=this.div;setLayerDimensions(n,this.viewport);const r=new Map,s=[],a={data:null,layer:n,linkService:this.#vl,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:!1!==t.renderForms,annotationStorage:this.#j,enableComment:!0===t.enableComment,enableAnnotationEditing:!1!==t.enableAnnotationEditing,enableScripting:!0===t.enableScripting,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(const t of e){if(t.noHTML)continue;const e=t.annotationType===Ni.POPUP;if(e){const e=r.get(t.id);if(!e)continue;if(!this._commentManager){s.push(t);continue}a.elements=e}else if(t.rect[2]===t.rect[0]||t.rect[3]===t.rect[1])continue;a.data=t;const n=AnnotationElementFactory.create(a);if(!n.isRenderable)continue;if(!e){this.#Bo.push(n);t.popupRef&&r.getOrInsertComputed(t.popupRef,makeArr).push(n)}const o=n.render();t.hidden&&(o.style.visibility="hidden");n.updateOC(i);if(n._isEditable){this.#yl.set(n.data.id,n);this._annotationEditorUIManager?.renderAnnotationElement(n)}}await this.#Al();for(const t of s){const e=a.elements=r.get(t.id);a.data=t;const i=AnnotationElementFactory.create(a);if(!i.isRenderable)continue;const n=i.render();i.contentElement.id=`${Si}${t.id}`;t.hidden&&(n.style.visibility="hidden");e.at(-1).container.after(n)}this.#xl()}async#Al(){if(0===this.#Bo.length)return;this.div.replaceChildren();const t=[];if(!this.#_l){this.#_l=!0;for(const{contentElement:e,data:{hidden:i,id:n,oc:r}}of this.#Bo){const s=e.id=`${Si}${n}`,a="a"===e.localName&&!i&&!r;t.push(this.#wl?.getAriaAttributes(s,{enableLinkOwnership:a}).then(t=>{if(t)for(const[i,n]of t)e.setAttribute(i,n)}))}}this.#Bo.sort(({data:{rect:[t,e,i,n]}},{data:{rect:[r,s,a,o]}})=>{if(t===i&&e===n)return 1;if(r===a&&s===o)return-1;const l=(e+n)/2,c=(s+o)/2;if(l>=o&&c<=e)return-1;if(c>=n&&l<=s)return 1;return(t+i)/2-(r+a)/2});const e=document.createDocumentFragment();for(const t of this.#Bo){e.append(t.container);this._commentManager?(t.extraPopupElement?.popup||t.popup)?.renderCommentButton():t.extraPopupElement&&e.append(t.extraPopupElement.render())}this.div.append(e);await Promise.all(t);if(this.#bl){const t=await(this.#wl?.getAnnotationIds());for(const{contentElement:e}of this.#Bo)t?.has(e.id)||this.#bl.addPointerInTextLayer(e,!1)}}async addLinkAnnotations(t){const e={data:null,layer:this.div,linkService:this.#vl,parent:this};for(const i of t){i.borderStyle||=AnnotationLayer._defaultBorderStyle;e.data=i;const t=AnnotationElementFactory.create(e);if(t.isRenderable){t.render();t.contentElement.id=`${Si}${i.id}`;this.#Bo.push(t)}}await this.#Al()}update({viewport:t,optionalContentConfig:e}){const i=this.div;this.viewport=t;setLayerDimensions(i,{rotation:t.rotation});for(const t of this.#Bo)t.updateOC(e);this.#xl();i.hidden=!1}destroy(){for(const t of this.#Bo){t.destroy?.();this.#bl?.removePointerInTextLayer(t.contentElement)}this.#Bo.length=0;this.#yl.clear();this.div.replaceChildren()}#xl(){if(!this.#xs)return;const t=this.div;for(const[e,i]of this.#xs){const n=t.querySelector(`[data-annotation-id="${e}"]`);if(!n)continue;if(Array.isArray(i))for(const t of i){t.className="annotationContent";t.ariaHidden=!0}else{i.className="annotationContent";i.ariaHidden=!0}const r=[];for(const t of n.children)"CANVAS"===t.nodeName&&r.push(t);for(const t of r)t.remove();const s=Array.isArray(i)?i[0]:i,{firstChild:a}=n;a?a.classList.contains("annotationContent")?a.after(s):a.before(s):n.append(s);if(Array.isArray(i)){let t=s;for(let e=1,n=i.length;e<n;e++){t.after(i[e]);t=i[e]}}this.#xs.delete(e);const o=this.#yl.get(e);if(o)if(o._hasNoCanvas){this._annotationEditorUIManager?.setMissingCanvas(e,n.id,i);o._hasNoCanvas=!1}else o.canvas=i}}refreshCanvases(){this.#xl()}getEditableAnnotations(){return this.#yl.values()}getEditableAnnotation(t){return this.#yl.get(t)}addFakeAnnotation(t){const{div:e}=this,{id:i,rotation:n}=t,r=new EditorAnnotationElement({data:{id:i,rect:t.getPDFRect(),rotation:n},editor:t,layer:e,parent:this,enableComment:!!this._commentManager,linkService:this.#vl,annotationStorage:this.#j});r.render();r.contentElement.id=`${Si}${i}`;r.createOrUpdatePopup();this.#Bo.push(r);return r}removeAnnotation(t){const e=this.#Bo.findIndex(e=>e.data.id===t);if(e<0)return;const[i]=this.#Bo.splice(e,1);this.#bl?.removePointerInTextLayer(i.contentElement)}updateFakeAnnotations(t){if(0!==t.length){for(const e of t)e.updateFakeAnnotationElement(this);this.#Al()}}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}static get _defaultBorderStyle(){return util_shadow(this,"_defaultBorderStyle",Object.freeze({width:1,rawWidth:1,style:Ui,dashArray:[3],horizontalCornerRadius:0,verticalCornerRadius:0}))}}const tr=/\r\n?|\n/g;class FreeTextEditor extends AnnotationEditor{#Cl="";#El=`${this.id}-editor`;#Sl=null;#tl;_colorPicker=null;static _freeTextDefaultContent="";static _internalPadding=0;static _defaultColor=null;static _defaultFontSize=10;static get _keyboardManager(){const t=FreeTextEditor.prototype,arrowChecker=t=>t.isEmpty(),e=AnnotationEditorUIManager.TRANSLATE_SMALL,i=AnnotationEditorUIManager.TRANSLATE_BIG;return util_shadow(this,"_keyboardManager",new KeyboardManager([[["ctrl+s","mac+meta+s","ctrl+p","mac+meta+p"],t.commitOrRemove,{bubbles:!0}],[["ctrl+Enter","mac+meta+Enter"],t.commitOrRemove],[["Escape"],t.commitOrRemove],[["ArrowLeft"],t._translateEmpty,{args:[-e,0],checker:arrowChecker}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t._translateEmpty,{args:[-i,0],checker:arrowChecker}],[["ArrowRight"],t._translateEmpty,{args:[e,0],checker:arrowChecker}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t._translateEmpty,{args:[i,0],checker:arrowChecker}],[["ArrowUp"],t._translateEmpty,{args:[0,-e],checker:arrowChecker}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t._translateEmpty,{args:[0,-i],checker:arrowChecker}],[["ArrowDown"],t._translateEmpty,{args:[0,e],checker:arrowChecker}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t._translateEmpty,{args:[0,i],checker:arrowChecker}]]))}static _type="freetext";static _editorType=ki.FREETEXT;constructor(t){super({...t,name:"freeTextEditor"});this.color=t.color||FreeTextEditor._defaultColor||AnnotationEditor._defaultLineColor;this.#tl=t.fontSize||FreeTextEditor._defaultFontSize;this.annotationElementId||this._uiManager.a11yAlert(AnnotationEditor._l10nAlert.freetext);this.canAddComment=!1}static initialize(t,e){AnnotationEditor.initialize(t,e);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(t,e){switch(t){case Pi.FREETEXT_SIZE:FreeTextEditor._defaultFontSize=e;break;case Pi.FREETEXT_COLOR:FreeTextEditor._defaultColor=e}}updateParams(t,e){switch(t){case Pi.FREETEXT_SIZE:this.#Tl(e);break;case Pi.FREETEXT_COLOR:this.#Jo(e)}}static get defaultPropertiesToUpdate(){return[[Pi.FREETEXT_SIZE,FreeTextEditor._defaultFontSize],[Pi.FREETEXT_COLOR,FreeTextEditor._defaultColor||AnnotationEditor._defaultLineColor]]}get propertiesToUpdate(){return[[Pi.FREETEXT_SIZE,this.#tl],[Pi.FREETEXT_COLOR,this.color]]}get toolbarButtons(){this._colorPicker||=new BasicColorPicker(this);return[["colorPicker",this._colorPicker]]}get colorType(){return Pi.FREETEXT_COLOR}#Tl(t){const setFontsize=t=>{this.editorDiv.style.fontSize=`calc(${t}px * var(--total-scale-factor))`;this.translate(0,-(t-this.#tl)*this.parentScale);this.#tl=t;this.#kl()},e=this.#tl;this.addCommands({cmd:setFontsize.bind(this,t),undo:setFontsize.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Pi.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})}onUpdatedColor(){this.editorDiv.style.color=this.color;this._colorPicker?.update(this.color);super.onUpdatedColor()}#Jo(t){const setColor=t=>{this.color=t;this.onUpdatedColor()},e=this.color;this.addCommands({cmd:setColor.bind(this,t),undo:setColor.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:Pi.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})}_translateEmpty(t,e){this._uiManager.translateSelectedEditors(t,e,!0)}getInitialTranslation(){const t=this.parentScale;return[-FreeTextEditor._internalPadding*t,-(FreeTextEditor._internalPadding+this.#tl)*t]}rebuild(){if(this.parent){super.rebuild();null!==this.div&&(this.isAttachedToDOM||this.parent.add(this))}}enableEditMode(){if(!super.enableEditMode())return!1;this.overlayDiv.classList.remove("enabled");this.editorDiv.contentEditable=!0;this._isDraggable=!1;this.div.removeAttribute("aria-activedescendant");this.#Sl=new AbortController;const t=this._uiManager.combinedSignal(this.#Sl);this.editorDiv.addEventListener("keydown",this.editorDivKeydown.bind(this),{signal:t});this.editorDiv.addEventListener("focus",this.editorDivFocus.bind(this),{signal:t});this.editorDiv.addEventListener("blur",this.editorDivBlur.bind(this),{signal:t});this.editorDiv.addEventListener("input",this.editorDivInput.bind(this),{signal:t});this.editorDiv.addEventListener("paste",this.editorDivPaste.bind(this),{signal:t});return!0}disableEditMode(){if(!super.disableEditMode())return!1;this.overlayDiv.classList.add("enabled");this.editorDiv.contentEditable=!1;this.div.setAttribute("aria-activedescendant",this.#El);this._isDraggable=!0;this.#Sl?.abort();this.#Sl=null;this.div.focus({preventScroll:!0});this.isEditing=!1;this.parent.div.classList.add("freetextEditing");return!0}focusin(t){if(this._focusEventsAllowed){super.focusin(t);t.target!==this.editorDiv&&this.editorDiv.focus()}}onceAdded(t){if(!this.width){this.enableEditMode();t&&this.editorDiv.focus();this._initialOptions?.isCentered&&this.center();this._initialOptions=null}}isEmpty(){return!this.editorDiv||""===this.editorDiv.innerText.trim()}remove(){this.isEditing=!1;if(this.parent){this.parent.setEditingState(!0);this.parent.div.classList.add("freetextEditing")}super.remove()}#Pl(){const t=[];this.editorDiv.normalize();let e=null;for(const i of this.editorDiv.childNodes)if(e?.nodeType!==Node.TEXT_NODE||"BR"!==i.nodeName){t.push(FreeTextEditor.#Ml(i));e=i}return t.join("\n")}#kl(){const[t,e]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:t,div:e}=this,n=e.style.display,r=e.classList.contains("hidden");e.classList.remove("hidden");e.style.display="hidden";t.div.append(this.div);i=e.getBoundingClientRect();e.remove();e.style.display=n;e.classList.toggle("hidden",r)}if(this.rotation%180==this.parentRotation%180){this.width=i.width/t;this.height=i.height/e}else{this.width=i.height/t;this.height=i.width/e}this.fixAndSetPosition()}commit(){if(!this.isInEditMode())return;super.commit();this.disableEditMode();const t=this.#Cl,e=this.#Cl=this.#Pl().trimEnd();if(t===e)return;const setText=t=>{this.#Cl=t;if(t){this.#Dl();this._uiManager.rebuild(this);this.#kl()}else this.remove()};this.addCommands({cmd:()=>{setText(e)},undo:()=>{setText(t)},mustExec:!1});this.#kl()}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode();this.editorDiv.focus()}keydown(t){if(t.target===this.div&&"Enter"===t.key){this.enterInEditMode();t.preventDefault()}}editorDivKeydown(t){FreeTextEditor._keyboardManager.exec(this,t)}editorDivFocus(t){this.isEditing=!0}editorDivBlur(t){this.isEditing=!1}editorDivInput(t){this.parent.div.classList.toggle("freetextEditing",this.isEmpty())}disableEditing(){this.editorDiv.setAttribute("role","comment");this.editorDiv.removeAttribute("aria-multiline")}enableEditing(){this.editorDiv.setAttribute("role","textbox");this.editorDiv.setAttribute("aria-multiline",!0)}get canChangeContent(){return!0}render(){if(this.div)return this.div;let t,e;if(this._isCopy||this.annotationElementId){t=this.x;e=this.y}super.render();this.editorDiv=document.createElement("div");this.editorDiv.className="internal";this.editorDiv.setAttribute("id",this.#El);this.editorDiv.setAttribute("data-l10n-id","pdfjs-free-text2");this.editorDiv.setAttribute("data-l10n-attrs","default-content");this.enableEditing();this.editorDiv.contentEditable=!0;const{style:i}=this.editorDiv;i.fontSize=`calc(${this.#tl}px * var(--total-scale-factor))`;i.color=this.color;this.div.append(this.editorDiv);this.overlayDiv=document.createElement("div");this.overlayDiv.classList.add("overlay","enabled");this.div.append(this.overlayDiv);if(this._isCopy||this.annotationElementId){const[i,n]=this.parentDimensions;if(this.annotationElementId){const{position:r}=this._initialData;let[s,a]=this.getInitialTranslation();[s,a]=this.pageTranslationToScreen(s,a);const[o,l]=this.pageDimensions,[c,h]=this.pageTranslation;let d,u;switch(this.rotation){case 0:d=t+(r[0]-c)/o;u=e+this.height-(r[1]-h)/l;break;case 90:d=t+(r[0]-c)/o;u=e-(r[1]-h)/l;[s,a]=[a,-s];break;case 180:d=t-this.width+(r[0]-c)/o;u=e-(r[1]-h)/l;[s,a]=[-s,-a];break;case 270:d=t+(r[0]-c-this.height*l)/o;u=e+(r[1]-h-this.width*o)/l;[s,a]=[-a,s]}this.setAt(d*i,u*n,s,a)}else this._moveAfterPaste(t,e);this.#Dl();this._isDraggable=!0;this.editorDiv.contentEditable=!1}else{this._isDraggable=!1;this.editorDiv.contentEditable=!0}return this.div}static#Ml(t){return(t.nodeType===Node.TEXT_NODE?t.nodeValue:t.innerText).replaceAll(tr,"")}editorDivPaste(t){const e=t.clipboardData||window.clipboardData,{types:i}=e;if(1===i.length&&"text/plain"===i[0])return;t.preventDefault();const n=FreeTextEditor.#Il(e.getData("text")||"").replaceAll(tr,"\n");if(!n)return;const r=window.getSelection();if(!r.rangeCount)return;this.editorDiv.normalize();r.deleteFromDocument();const s=r.getRangeAt(0);if(!n.includes("\n")){s.insertNode(document.createTextNode(n));this.editorDiv.normalize();r.collapseToStart();return}const{startContainer:a,startOffset:o}=s,l=[],c=[];if(a.nodeType===Node.TEXT_NODE){const t=a.parentElement;c.push(a.nodeValue.slice(o).replaceAll(tr,""));if(t!==this.editorDiv){let e=l;for(const i of this.editorDiv.childNodes)i!==t?e.push(FreeTextEditor.#Ml(i)):e=c}l.push(a.nodeValue.slice(0,o).replaceAll(tr,""))}else if(a===this.editorDiv){let t=l,e=0;for(const i of this.editorDiv.childNodes){e++===o&&(t=c);t.push(FreeTextEditor.#Ml(i))}}this.#Cl=`${l.join("\n")}${n}${c.join("\n")}`;this.#Dl();const h=new Range;let d=Math.sumPrecise(l.map(t=>t.length));for(const{firstChild:t}of this.editorDiv.childNodes)if(t.nodeType===Node.TEXT_NODE){const e=t.nodeValue.length;if(d<=e){h.setStart(t,d);h.setEnd(t,d);break}d-=e}r.removeAllRanges();r.addRange(h)}#Dl(){this.editorDiv.replaceChildren();if(this.#Cl)for(const t of this.#Cl.split("\n")){const e=document.createElement("div");e.append(t?document.createTextNode(t):document.createElement("br"));this.editorDiv.append(e)}}#Fl(){return this.#Cl.replaceAll(" "," ")}static#Il(t){return t.replaceAll(" "," ")}get contentDiv(){return this.editorDiv}getPDFRect(){const t=FreeTextEditor._internalPadding*this.parentScale;return this.getRect(t,t)}static async deserialize(t,e,i){let n=null;if(t instanceof FreeTextAnnotationElement){const{data:{defaultAppearanceData:{fontSize:e,fontColor:i},rect:r,rotation:s,id:a,popupRef:o,richText:l,contentsObj:c,creationDate:h,modificationDate:d},textContent:u,textPosition:p,parent:{page:{pageNumber:g}}}=t;if(!u?.length)return null;n=t={annotationType:ki.FREETEXT,color:Array.from(i),fontSize:e,value:u.join("\n"),position:p,pageIndex:g-1,rect:r.slice(0),rotation:s,annotationElementId:a,id:a,deleted:!1,popupRef:o,comment:c?.str||null,richText:l,creationDate:h,modificationDate:d}}const r=await super.deserialize(t,e,i);r.#tl=t.fontSize;r.color=Util.makeHexColor(...t.color);r.#Cl=FreeTextEditor.#Il(t.value);r._initialData=n;t.comment&&r.setCommentData(t);return r}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const e=AnnotationEditor._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),i=Object.assign(super.serialize(t),{color:e,fontSize:this.#tl,value:this.#Fl()});this.addComment(i);if(t){i.isCopy=!0;return i}if(this.annotationElementId&&!this.#Ol(i))return null;i.id=this.annotationElementId;return i}#Ol(t){const{value:e,fontSize:i,color:n,pageIndex:r}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||t.value!==e||t.fontSize!==i||t.color.some((t,e)=>t!==n[e])||t.pageIndex!==r}renderAnnotationElement(t){const e=super.renderAnnotationElement(t);if(!e)return null;const{style:i}=e;i.fontSize=`calc(${this.#tl}px * var(--total-scale-factor))`;i.color=this.color;e.replaceChildren();for(const t of this.#Cl.split("\n")){const i=document.createElement("div");i.append(t?document.createTextNode(t):document.createElement("br"));e.append(i)}t.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#Cl}});return e}resetAnnotationElement(t){super.resetAnnotationElement(t);t.resetEdited()}}class DrawingOptions{#Rl=Object.create(null);updateProperty(t,e){this[t]=e;this.updateSVGProperty(t,e)}updateProperties(t){if(t)for(const[e,i]of Object.entries(t))e.startsWith("_")||this.updateProperty(e,i)}updateSVGProperty(t,e){this.#Rl[t]=e}toSVGProperties(){const t=this.#Rl;this.#Rl=Object.create(null);return{root:t}}reset(){this.#Rl=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){unreachable("Not implemented")}}class DrawingEditor extends AnnotationEditor{#Bl=null;#Ll;_clipPathId=null;_colorPicker=null;_drawId=null;_drawOutlines=null;_focusDrawId=null;static _currentDrawId=-1;static _currentParent=null;static#Nl=null;static#Ul=null;static#Hl=null;static#zl=null;static _INNER_MARGIN=3;constructor(t){super(t);this.#Ll=t.mustBeCommitted||!1;this._addOutlines(t)}onUpdatedColor(){this._colorPicker?.update(this.color);super.onUpdatedColor()}onUpdatedOpacity(){this._colorPicker?.updateOpacity?.(this.opacity)}_addOutlines(t){if(t.drawOutlines){this.#Gl(t);this.#Wl()}}#Gl({drawOutlines:t,drawId:e,drawingOptions:i,clipPathId:n}){this._drawOutlines=t;this._drawingOptions||=i;this.annotationElementId||this._uiManager.a11yAlert(AnnotationEditor._l10nAlert[this.editorType]);if(e>=0){this._drawId=e;this._clipPathId=n??null;this.parent.drawLayer.finalizeDraw(e,t.defaultProperties);this.#jl(this.parent)}else this._drawId=this.#Vl(t,this.parent);this.#ql(t.box)}#Vl(t,e){const{id:i,clipPathId:n}=e.drawLayer.draw(DrawingEditor._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,this.constructor._hasClipPath);this.constructor._hasClipPath&&(this._clipPathId=n);this.#jl(e);return i}#jl(t){const e=this._drawOutlines.getFocusSVGProperties(this.#$l);e&&(this._focusDrawId=t.drawLayer.drawOutline(e,this._drawOutlines.focusMustRemoveSelfIntersections))}#Xl(t=this.#$l){null!==this._focusDrawId&&this.parent?.drawLayer.updateProperties(this._focusDrawId,this._drawOutlines.getFocusSVGProperties(t))}#Kl(t){null!==this._focusDrawId&&this.parent?.drawLayer.updateProperties(this._focusDrawId,{rootClass:t})}#Yl(){const{parent:t,_drawId:e,_focusDrawId:i,_isVisible:n}=this;if(!t||null===e)return;const r={hidden:!n};t.drawLayer.updateProperties(e,{rootClass:r});null!==i&&t.drawLayer.updateProperties(i,{rootClass:r})}static _mergeSVGProperties(t,e){const i=new Set(Object.keys(t));for(const[n,r]of Object.entries(e))i.has(n)?Object.assign(t[n],r):t[n]=r;return t}static getDefaultDrawingOptions(t){unreachable("Not implemented")}static get typesMap(){unreachable("Not implemented")}static get isDrawer(){return!0}static get _hasClipPath(){return!1}static get _hasDrawClass(){return!0}static get supportMultipleDrawings(){return!1}get _drawRotation(){return this.rotation}get _opacityName(){return this.constructor.typesMap.get(this.opacityType)}get#$l(){return(this.parentRotation-this._drawRotation+360)%360}static updateDefaultParams(t,e){const i=this.typesMap.get(t);i&&this._defaultDrawingOptions.updateProperty(i,e);if(this._currentParent){DrawingEditor.#Nl.updateProperty(i,e);this._currentParent.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}updateParams(t,e){const i=this.constructor.typesMap.get(t);i&&this._updateProperty(t,i,e)}static get defaultPropertiesToUpdate(){const t=[],e=this._defaultDrawingOptions;for(const[i,n]of this.typesMap)t.push([i,e[n]]);return t}get propertiesToUpdate(){const t=[],{_drawingOptions:e}=this;for(const[i,n]of this.constructor.typesMap)t.push([i,e[n]]);return t}_updateProperty(t,e,i){const n=this._drawingOptions,r=n[e],setter=i=>{n.updateProperty(e,i);const r=this._drawOutlines.updateProperty(e,i);r&&this.#ql(r);this.parent?.drawLayer.updateProperties(this._drawId,n.toSVGProperties());t===this.colorType?this.onUpdatedColor():t===this.opacityType&&this.onUpdatedOpacity()};this.addCommands({cmd:setter.bind(this,i),undo:setter.bind(this,r),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_updateColorAndOpacity(t,e,i=this.colorAndOpacityType){const n=this.constructor.typesMap.get(this.colorType),r=this._opacityName,s=this._drawingOptions,a=s[n],o=s[r],setter=(t,e)=>{s.updateProperty(n,t);s.updateProperty(r,e);this._drawOutlines.updateProperty(n,t);this._drawOutlines.updateProperty(r,e);this.parent?.drawLayer.updateProperties(this._drawId,s.toSVGProperties());this.onUpdatedColor();this.onUpdatedOpacity()};this.addCommands({cmd:setter.bind(this,t,e),undo:setter.bind(this,a,o),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:i,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,DrawingEditor._mergeSVGProperties(this._drawOutlines.getPathResizingSVGProperties(this.#Jl()),{bbox:this.#Ql()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,DrawingEditor._mergeSVGProperties(this._drawOutlines.getPathResizedSVGProperties(this.#Jl()),{bbox:this.#Ql()}));this.#Xl()}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#Ql()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,DrawingEditor._mergeSVGProperties(this._drawOutlines.getPathTranslatedSVGProperties(this.#Jl(),this.parentDimensions),{bbox:this.#Ql()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}get _mustBeDisabledOnCommit(){return!0}commit(){super.commit();if(this._mustBeDisabledOnCommit){this.disableEditMode();this.disableEditing()}}disableEditing(){super.disableEditing();this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing();this.div.classList.toggle("disabled",!1)}getBaseTranslation(){return[0,0]}get isResizable(){return!0}onceAdded(t){this.annotationElementId||null===this._drawId||this.parent.addUndoableEditor(this);this._isDraggable=!0;if(this.#Ll){this.#Ll=!1;this.commit();this.parent.setSelected(this);t&&this.isOnScreen&&this.div.focus()}}remove(){this._uiManager.removeShouldRescale(this);this.#Zl();super.remove()}rebuild(){if(this.parent){super.rebuild();if(null!==this.div){this.#Wl();this.#ql(this._drawOutlines.box);this.isAttachedToDOM||this.parent.add(this)}}}setParent(t){let e=!1;if(this.parent&&!t){this._uiManager.removeShouldRescale(this);this.#Zl()}else if(t){this._uiManager.addShouldRescale(this);this.#Wl(t);e=!this.parent&&this.div?.classList.contains("selectedEditor")}super.setParent(t);this.#Yl();e&&this.select()}#Zl(){if(null===this._drawId||!this.parent)return;const{drawLayer:t}=this.parent;t.remove(this._drawId);this._drawId=null;if(null!==this._focusDrawId){t.remove(this._focusDrawId);this._focusDrawId=null}this._drawingOptions.reset()}#Wl(t=this.parent){if(null===this._drawId||this.parent!==t){if(null!==this._drawId){const{drawLayer:e}=this.parent;e.updateParent(this._drawId,t.drawLayer);null!==this._focusDrawId&&e.updateParent(this._focusDrawId,t.drawLayer);return}this._drawingOptions.updateAll();this._drawId=this.#Vl(this._drawOutlines,t);this._clipPathId&&this.#Bl&&(this.#Bl.style.clipPath=this._clipPathId)}}#tc([t,e,i,n]){const{parentDimensions:[r,s],_drawRotation:a}=this;switch(a){case 90:return[e,1-t,i*(s/r),n*(r/s)];case 180:return[1-t,1-e,i,n];case 270:return[1-e,t,i*(s/r),n*(r/s)];default:return[t,e,i,n]}}#Jl(){const{x:t,y:e,width:i,height:n,parentDimensions:[r,s],_drawRotation:a}=this;switch(a){case 90:return[1-e,t,i*(r/s),n*(s/r)];case 180:return[1-t,1-e,i,n];case 270:return[e,1-t,i*(r/s),n*(s/r)];default:return[t,e,i,n]}}#ql(t){[this.x,this.y,this.width,this.height]=this.#tc(t);if(this.div){this.fixAndSetPosition();this.setDims()}this._onResized()}#Ql(t=this.parentRotation){const{x:e,y:i,width:n,height:r,_drawRotation:s,parentDimensions:[a,o]}=this;switch((4*s+t)/90){case 1:return[1-i-r,e,r,n];case 2:return[1-e-n,1-i-r,n,r];case 3:return[i,1-e-n,r,n];case 4:return[e,i-n*(a/o),r*(o/a),n*(a/o)];case 5:return[1-i,e,n*(a/o),r*(o/a)];case 6:return[1-e-r*(o/a),1-i,r*(o/a),n*(a/o)];case 7:return[i-n*(a/o),1-e-r*(o/a),n*(a/o),r*(o/a)];case 8:return[e-n,i-r,n,r];case 9:return[1-i,e-n,r,n];case 10:return[1-e,1-i,n,r];case 11:return[i-r,1-e,r,n];case 12:return[e-r*(o/a),i,r*(o/a),n*(a/o)];case 13:return[1-i-n*(a/o),e-r*(o/a),n*(a/o),r*(o/a)];case 14:return[1-e,1-i-n*(a/o),r*(o/a),n*(a/o)];case 15:return[i,1-e,n*(a/o),r*(o/a)];default:return[e,i,n,r]}}rotate(t=this.parentRotation){if(!this.parent||null===this._drawId)return;const e=(t-this._drawRotation+360)%360;this.parent.drawLayer.updateProperties(this._drawId,DrawingEditor._mergeSVGProperties({bbox:this.#Ql(t)},this._drawOutlines.updateRotation(e)));this.#Xl(e)}show(t=this._isVisible){super.show(t);this.#Yl()}select(){super.select();this.#Kl({hovered:!1,selected:!0})}unselect(){super.unselect();this.#Kl({selected:!1})}pointerover(){this.isSelected||this.#Kl({hovered:!0})}pointerleave(){this.isSelected||this.#Kl({hovered:!1})}onScaleChanging(){if(!this.parent)return;const t=this._drawOutlines.updateParentDimensions(this.parentDimensions,this.parent.scale);t&&this.#ql(t)}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let t,e;if(this._isCopy){t=this.x;e=this.y}const i=super.render();this.constructor._hasDrawClass&&i.classList.add("draw");const n=this.#Bl=document.createElement("div");i.append(n);n.setAttribute("aria-hidden","true");n.className="internal";this._clipPathId&&(n.style.clipPath=this._clipPathId);bindEvents(this,n,["pointerover","pointerleave"]);this.setDims();this._uiManager.addShouldRescale(this);this.disableEditing();this._isCopy&&this._moveAfterPaste(t,e);return i}static createDrawerInstance(t){unreachable("Not implemented")}static _getDrawingTarget(t,{target:e}){return e}static _getPointerCoords({offsetX:t,offsetY:e,clientX:i,clientY:n},r=null){if(!r)return[t,e];let s=i-r.clientX,a=n-r.clientY;switch(this._currentParent.viewport.rotation){case 90:[s,a]=[a,-s];break;case 180:[s,a]=[-s,-a];break;case 270:[s,a]=[-a,s]}return[r.offsetX+s,r.offsetY+a]}static _addDrawingListeners(t,e){}static _endDrawingSession(t=!1){return this._currentParent.endDrawingSession(t)}static startDrawing(t,e,i,n){const{pointerId:r,pointerType:s}=n;if(CurrentPointers.isInitializedAndDifferentPointerType(s))return;const a=this._getDrawingTarget(t,n),[o,l]=this._getPointerCoords(n),{viewport:{rotation:c}}=t,{x:h,y:d,width:u,height:p}=a.getBoundingClientRect(),g=DrawingEditor.#Ul=new AbortController,m=t.combinedSignal(g);CurrentPointers.setPointer(s,r);window.addEventListener("pointerup",t=>{CurrentPointers.isSamePointerIdOrRemove(t.pointerId)&&this._endDraw(t)},{signal:m});window.addEventListener("pointercancel",t=>{CurrentPointers.isSamePointerIdOrRemove(t.pointerId)&&this._endDrawingSession()},{signal:m});window.addEventListener("pointerdown",t=>{if(CurrentPointers.isSamePointerType(t.pointerType)){CurrentPointers.initializeAndAddPointerId(t.pointerId);if(DrawingEditor.#Nl.isCancellable()){DrawingEditor.#Nl.removeLastElement();DrawingEditor.#Nl.isEmpty()?this._endDrawingSession(!0):this._endDraw(null)}}},{capture:!0,passive:!1,signal:m});window.addEventListener("contextmenu",noContextMenu,{signal:m});a.addEventListener("pointermove",this._drawMove.bind(this),{signal:m});a.addEventListener("touchmove",t=>{CurrentPointers.isSameTimeStamp(t.timeStamp)&&stopEvent(t)},{signal:m});this._addDrawingListeners(a,m);t.toggleDrawing();e._editorUndoBar?.hide();if(DrawingEditor.#Nl){t.drawLayer.updateProperties(this._currentDrawId,DrawingEditor.#Nl.startNew(o,l,u,p,c,n.timeStamp));return}e.updateUIForDefaultProperties(this);DrawingEditor.#Nl=this.createDrawerInstance({x:o,y:l,box:[h,d,u,p],rotation:c,parent:t,isLTR:i,timeStamp:n.timeStamp});DrawingEditor.#Hl=this.getDefaultDrawingOptions();this._currentParent=t;const{id:f,clipPathId:b}=t.drawLayer.draw(this._mergeSVGProperties(DrawingEditor.#Hl.toSVGProperties(),DrawingEditor.#Nl.defaultSVGProperties),!0,this._hasClipPath);this._currentDrawId=f;DrawingEditor.#zl=this._hasClipPath?b:null}static _drawMove(t){CurrentPointers.isSameTimeStamp(t.timeStamp);if(!DrawingEditor.#Nl||!CurrentPointers.isSamePointerId(t.pointerId))return;if(CurrentPointers.isUsingMultiplePointers()){this._endDraw(t);return}let e;const i=t.getCoalescedEvents?.();if(i?.length){const n=[],r=[];for(const e of i){n.push(...this._getPointerCoords(e,t));r.push(e.timeStamp)}e=DrawingEditor.#Nl.addPoints(n,r)}else e=DrawingEditor.#Nl.add(...this._getPointerCoords(t),t.timeStamp);this._currentParent.drawLayer.updateProperties(this._currentDrawId,e);CurrentPointers.setTimeStamp(t.timeStamp);stopEvent(t)}static _cleanup(t){if(t){this._currentDrawId=-1;this._currentParent=null;DrawingEditor.#Nl=null;DrawingEditor.#Hl=null;DrawingEditor.#zl=null;CurrentPointers.clearTimeStamp()}if(DrawingEditor.#Ul){DrawingEditor.#Ul.abort();DrawingEditor.#Ul=null;CurrentPointers.clearPointerIds()}}static _endDraw(t){const e=this._currentParent;if(e){e.toggleDrawing(!0);this._cleanup(!1);e.drawLayer.updateProperties(this._currentDrawId,t?.target===e.div?DrawingEditor.#Nl.end(...this._getPointerCoords(t),t.timeStamp):DrawingEditor.#Nl.end());if(this.supportMultipleDrawings){const t=DrawingEditor.#Nl,i=this._currentDrawId,n=t.getLastElement();e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,t.setLastElement(n))},undo:()=>{e.drawLayer.updateProperties(i,t.removeLastElement())},mustExec:!1,type:Pi.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(t){const e=this._currentParent;if(!e)return null;e.toggleDrawing(!0);e.cleanUndoStack(Pi.DRAW_STEP);if(!DrawingEditor.#Nl.isEmpty()){const{pageDimensions:[i,n],scale:r}=e,s=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,clipPathId:DrawingEditor.#zl,drawOutlines:DrawingEditor.#Nl.getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:DrawingEditor.#Hl,mustBeCommitted:!t});this._cleanup(!0);return s}e.drawLayer.remove(this._currentDrawId);this._cleanup(!0);return null}createDrawingOptions(t){}static deserializeDraw(t,e,i,n,r,s,a){unreachable("Not implemented")}static async deserialize(t,e,i){const{rawDims:{pageWidth:n,pageHeight:r,pageX:s,pageY:a}}=e.viewport,o=this.deserializeDraw(s,a,n,r,this._INNER_MARGIN,t,i),l=await super.deserialize(t,e,i);l.createDrawingOptions(t);l.#Gl({drawOutlines:o});l.#Wl();l.onScaleChanging();l.rotate();return l}serializeDraw(t){const[e,i]=this.pageTranslation,[n,r]=this.pageDimensions;return this._drawOutlines.serialize([e,i,n,r],t)}renderAnnotationElement(t){t.updateEdited({rect:this.getPDFRect()});return null}static canCreateNewEmptyEditor(){return!1}}class Outline{static PRECISION=1e-4;focusOutline=null;toSVGPath(){unreachable("Abstract method `toSVGPath` must be implemented.")}get box(){unreachable("Abstract getter `box` must be implemented.")}serialize(t,e){unreachable("Abstract method `serialize` must be implemented.")}get defaultSVGProperties(){unreachable("Abstract getter `defaultSVGProperties` must be implemented.")}get defaultProperties(){return this.defaultSVGProperties}getFocusSVGProperties(t){return null}get focusMustRemoveSelfIntersections(){return!1}updateProperty(t,e){return null}updateParentDimensions(t,e){return null}serializeQuadPoints(t,e){return null}updateRotation(t){return{}}getPathResizingSVGProperties(t){return{}}getPathResizedSVGProperties(t){return{}}getPathTranslatedSVGProperties(t,e){return{}}static _rotateBox([t,e,i,n],r){switch(r){case 90:return[1-e-n,t,n,i];case 180:return[1-t-i,1-e-n,i,n];case 270:return[e,1-t-i,n,i]}return[t,e,i,n]}static _rescale(t,e,i,n,r,s){s||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2){s[a]=e+t[a]*n;s[a+1]=i+t[a+1]*r}return s}static _rescaleAndSwap(t,e,i,n,r,s){s||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2){s[a]=e+t[a+1]*n;s[a+1]=i+t[a]*r}return s}static _translate(t,e,i,n){n||=new Float32Array(t.length);for(let r=0,s=t.length;r<s;r+=2){n[r]=e+t[r];n[r+1]=i+t[r+1]}return n}static svgRound(t){return Math.round(1e4*t)}static _normalizePoint(t,e,i,n,r,s=[]){switch(r){case 90:s[0]=1-e/i;s[1]=t/n;break;case 180:s[0]=1-t/i;s[1]=1-e/n;break;case 270:s[0]=e/i;s[1]=1-t/n;break;default:s[0]=t/i;s[1]=e/n}return s}static createBezierPoints(t,e,i,n,r,s,a=[]){a.push((t+5*i)/6,(e+5*n)/6,(5*i+r)/6,(5*n+s)/6,(i+r)/2,(n+s)/2);return a}}class FreeDrawOutliner{#ec;#ic=[];#nc;#rc;#sc=[];#ac=new Float32Array(18);#oc;#lc;#cc;#hc;#dc;#uc;#pc=[];static#gc=8;static#mc=2;static#fc=FreeDrawOutliner.#gc+FreeDrawOutliner.#mc;constructor(t,e,i,n,r,s,a=0){this.#ec=i;this.#uc=r*n;this.#rc=s;this.#ac.set([NaN,NaN,NaN,NaN,t,e],6);this.#nc=a;this.#hc=FreeDrawOutliner.#gc*n;this.#cc=FreeDrawOutliner.#fc*n;this.#dc=n;this.#pc.push(t,e)}isEmpty(){return isNaN(this.#ac[8])}isCancellable(){return this.#pc.length<=10}removeLastElement(){this.#ac.fill(NaN);this.#sc.length=this.#ic.length=this.#pc.length=0;return{path:{d:""}}}#bc(){const t=this.#ac.subarray(4,6),e=this.#ac.subarray(16,18),[i,n,r,s]=this.#ec;return[(this.#oc+(t[0]-e[0])/2-i)/r,(this.#lc+(t[1]-e[1])/2-n)/s,(this.#oc+(e[0]-t[0])/2-i)/r,(this.#lc+(e[1]-t[1])/2-n)/s]}add(t,e){this.#oc=t;this.#lc=e;const[i,n,r,s]=this.#ec;let[a,o,l,c]=this.#ac.subarray(8,12);const h=t-l,d=e-c,u=Math.hypot(h,d);if(u<this.#cc)return!1;const p=u-this.#hc,g=p/u,m=g*h,f=g*d;let b=a,y=o;a=l;o=c;l+=m;c+=f;this.#pc?.push(t,e);const w=m/p,v=-f/p*this.#uc,_=w*this.#uc;this.#ac.set(this.#ac.subarray(2,8),0);this.#ac.set([l+v,c+_],4);this.#ac.set(this.#ac.subarray(14,18),12);this.#ac.set([l-v,c-_],16);if(isNaN(this.#ac[6])){if(0===this.#sc.length){this.#ac.set([a+v,o+_],2);this.#sc.push(NaN,NaN,NaN,NaN,(a+v-i)/r,(o+_-n)/s);this.#ac.set([a-v,o-_],14);this.#ic.push(NaN,NaN,NaN,NaN,(a-v-i)/r,(o-_-n)/s)}this.#ac.set([b,y,a,o,l,c],6);return!this.isEmpty()}this.#ac.set([b,y,a,o,l,c],6);if(Math.abs(Math.atan2(y-o,b-a)-Math.atan2(f,m))<Math.PI/2){[a,o,l,c]=this.#ac.subarray(2,6);this.#sc.push(NaN,NaN,NaN,NaN,((a+l)/2-i)/r,((o+c)/2-n)/s);[a,o,b,y]=this.#ac.subarray(14,18);this.#ic.push(NaN,NaN,NaN,NaN,((b+a)/2-i)/r,((y+o)/2-n)/s);return!0}[b,y,a,o,l,c]=this.#ac.subarray(0,6);this.#sc.push(((b+5*a)/6-i)/r,((y+5*o)/6-n)/s,((5*a+l)/6-i)/r,((5*o+c)/6-n)/s,((a+l)/2-i)/r,((o+c)/2-n)/s);[l,c,a,o,b,y]=this.#ac.subarray(12,18);this.#ic.push(((b+5*a)/6-i)/r,((y+5*o)/6-n)/s,((5*a+l)/6-i)/r,((5*o+c)/6-n)/s,((a+l)/2-i)/r,((o+c)/2-n)/s);return!0}toSVGPath(){if(this.isEmpty())return"";const t=this.#sc,e=this.#ic;if(isNaN(this.#ac[6])&&!this.isEmpty())return this.#yc();const i=[];i.push(`M${t[4]} ${t[5]}`);for(let e=6;e<t.length;e+=6)isNaN(t[e])?i.push(`L${t[e+4]} ${t[e+5]}`):i.push(`C${t[e]} ${t[e+1]} ${t[e+2]} ${t[e+3]} ${t[e+4]} ${t[e+5]}`);this.#wc(i);for(let t=e.length-6;t>=6;t-=6)isNaN(e[t])?i.push(`L${e[t+4]} ${e[t+5]}`):i.push(`C${e[t]} ${e[t+1]} ${e[t+2]} ${e[t+3]} ${e[t+4]} ${e[t+5]}`);this.#vc(i);return i.join(" ")}#yc(){const[t,e,i,n]=this.#ec,[r,s,a,o]=this.#bc();return`M${(this.#ac[2]-t)/i} ${(this.#ac[3]-e)/n} L${(this.#ac[4]-t)/i} ${(this.#ac[5]-e)/n} L${r} ${s} L${a} ${o} L${(this.#ac[16]-t)/i} ${(this.#ac[17]-e)/n} L${(this.#ac[14]-t)/i} ${(this.#ac[15]-e)/n} Z`}#vc(t){const e=this.#ic;t.push(`L${e[4]} ${e[5]} Z`)}#wc(t){const[e,i,n,r]=this.#ec,s=this.#ac.subarray(4,6),a=this.#ac.subarray(16,18),[o,l,c,h]=this.#bc();t.push(`L${(s[0]-e)/n} ${(s[1]-i)/r} L${o} ${l} L${c} ${h} L${(a[0]-e)/n} ${(a[1]-i)/r}`)}newFreeDrawOutline(t,e,i,n,r,s){return new FreeDrawOutline(t,e,i,n,r,s)}getOutlines(){const t=this.#sc,e=this.#ic,i=this.#ac,[n,r,s,a]=this.#ec,o=new Float32Array((this.#pc?.length??0)+2);for(let t=0,e=o.length-2;t<e;t+=2){o[t]=(this.#pc[t]-n)/s;o[t+1]=(this.#pc[t+1]-r)/a}o[o.length-2]=(this.#oc-n)/s;o[o.length-1]=(this.#lc-r)/a;if(isNaN(i[6])&&!this.isEmpty())return this.#_c(o);const l=new Float32Array(this.#sc.length+24+this.#ic.length);let c=t.length;for(let e=0;e<c;e+=2)if(isNaN(t[e]))l[e]=l[e+1]=NaN;else{l[e]=t[e];l[e+1]=t[e+1]}c=this.#Ac(l,c);for(let t=e.length-6;t>=6;t-=6)for(let i=0;i<6;i+=2)if(isNaN(e[t+i])){l[c]=l[c+1]=NaN;c+=2}else{l[c]=e[t+i];l[c+1]=e[t+i+1];c+=2}this.#xc(l,c);return this.newFreeDrawOutline(l,o,this.#ec,this.#dc,this.#nc,this.#rc)}#_c(t){const e=this.#ac,[i,n,r,s]=this.#ec,[a,o,l,c]=this.#bc(),h=new Float32Array(36);h.set([NaN,NaN,NaN,NaN,(e[2]-i)/r,(e[3]-n)/s,NaN,NaN,NaN,NaN,(e[4]-i)/r,(e[5]-n)/s,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,(e[16]-i)/r,(e[17]-n)/s,NaN,NaN,NaN,NaN,(e[14]-i)/r,(e[15]-n)/s],0);return this.newFreeDrawOutline(h,t,this.#ec,this.#dc,this.#nc,this.#rc)}#xc(t,e){const i=this.#ic;t.set([NaN,NaN,NaN,NaN,i[4],i[5]],e);return e+6}#Ac(t,e){const i=this.#ac.subarray(4,6),n=this.#ac.subarray(16,18),[r,s,a,o]=this.#ec,[l,c,h,d]=this.#bc();t.set([NaN,NaN,NaN,NaN,(i[0]-r)/a,(i[1]-s)/o,NaN,NaN,NaN,NaN,l,c,NaN,NaN,NaN,NaN,h,d,NaN,NaN,NaN,NaN,(n[0]-r)/a,(n[1]-s)/o],e);return e+24}}class FreeDrawOutline extends Outline{#ec;#Cc=new Float32Array(4);#nc;#rc;#pc;#dc;#Ec;constructor(t,e,i,n,r,s){super();this.#Ec=t;this.#pc=e;this.#ec=i;this.#dc=n;this.#nc=r;this.#rc=s;this.firstPoint=[NaN,NaN];this.lastPoint=[NaN,NaN];this.#Sc(s);const[a,o,l,c]=this.#Cc;for(let e=0,i=t.length;e<i;e+=2){t[e]=(t[e]-a)/l;t[e+1]=(t[e+1]-o)/c}for(let t=0,i=e.length;t<i;t+=2){e[t]=(e[t]-a)/l;e[t+1]=(e[t+1]-o)/c}}toSVGPath(){const t=[`M${this.#Ec[4]} ${this.#Ec[5]}`];for(let e=6,i=this.#Ec.length;e<i;e+=6)isNaN(this.#Ec[e])?t.push(`L${this.#Ec[e+4]} ${this.#Ec[e+5]}`):t.push(`C${this.#Ec[e]} ${this.#Ec[e+1]} ${this.#Ec[e+2]} ${this.#Ec[e+3]} ${this.#Ec[e+4]} ${this.#Ec[e+5]}`);t.push("Z");return t.join(" ")}serialize([t,e,i,n],r){const s=i-t,a=n-e;let o,l;switch(r){case 0:o=Outline._rescale(this.#Ec,t,n,s,-a);l=Outline._rescale(this.#pc,t,n,s,-a);break;case 90:o=Outline._rescaleAndSwap(this.#Ec,t,e,s,a);l=Outline._rescaleAndSwap(this.#pc,t,e,s,a);break;case 180:o=Outline._rescale(this.#Ec,i,e,-s,a);l=Outline._rescale(this.#pc,i,e,-s,a);break;case 270:o=Outline._rescaleAndSwap(this.#Ec,i,n,-s,-a);l=Outline._rescaleAndSwap(this.#pc,i,n,-s,-a)}return{outline:Array.from(o),points:[Array.from(l)]}}#Sc(t){const e=this.#Ec;let i=e[4],n=e[5];const r=[i,n,i,n];let s=i,a=n,o=i,l=n;const c=t?Math.max:Math.min,h=new Float32Array(4);for(let t=6,d=e.length;t<d;t+=6){const d=e[t+4],u=e[t+5];if(isNaN(e[t])){Util.pointBoundingBox(d,u,r);if(a>u){s=d;a=u}else a===u&&(s=c(s,d));if(l<u){o=d;l=u}else l===u&&(o=c(o,d))}else{h.set(pi,0);Util.bezierBoundingBox(i,n,...e.slice(t,t+6),h);Util.rectBoundingBox(...h,r);if(a>h[1]){s=h[0];a=h[1]}else a===h[1]&&(s=c(s,h[0]));if(l<h[3]){o=h[2];l=h[3]}else l===h[3]&&(o=c(o,h[2]))}i=d;n=u}const d=this.#Cc;d[0]=r[0]-this.#nc;d[1]=r[1]-this.#nc;d[2]=r[2]-r[0]+2*this.#nc;d[3]=r[3]-r[1]+2*this.#nc;this.firstPoint=[s,a];this.lastPoint=[o,l]}get box(){return this.#Cc}newOutliner(t,e,i,n,r,s,a=0){return new FreeDrawOutliner(t,e,i,n,r,s,a)}updateThickness(t){const e=this.getNewOutline(t);this.#Ec=e.#Ec;this.#pc=e.#pc;this.#Cc.set(e.#Cc);this.firstPoint=e.firstPoint;this.lastPoint=e.lastPoint;return this.#Cc}getNewOutline(t,e){const[i,n,r,s]=this.#Cc,[a,o,l,c]=this.#ec,h=r*l,d=s*c,u=i*l+a,p=n*c+o,g=this.#pc,m=this.newOutliner(g[0]*h+u,g[1]*d+p,this.#ec,this.#dc,t,this.#rc,e??this.#nc);for(let t=2,e=g.length;t<e;t+=2)m.add(g[t]*h+u,g[t+1]*d+p);return m.getOutlines()}}function getHighlightSVGProperties(t){return{bbox:t.box,root:{viewBox:"0 0 1 1"},rootClass:{highlight:!0,free:t.isFree},path:{d:t.toSVGPath()}}}function getHighlightFocusSVGProperties(t,e){const{focusOutline:i}=t;return{bbox:Outline._rotateBox(i.box,e),root:{"data-main-rotation":e},rootClass:{highlightOutline:!0,free:t.isFree},path:{d:i.toSVGPath()}}}class HighlightOutliner{#ec;#Tc;#kc;#Pc=[];#Mc=[];constructor(t,e=0,i=0,n=!0){const r=pi.slice(),s=1e-4;for(const{x:i,y:n,width:a,height:o}of t){const t=Math.floor((i-e)/s)*s,l=Math.ceil((i+a+e)/s)*s,c=Math.floor((n-e)/s)*s,h=Math.ceil((n+o+e)/s)*s,d=[t,c,h,!0],u=[l,c,h,!1];this.#Pc.push(d,u);Util.rectBoundingBox(t,c,l,h,r)}const a=r[2]-r[0]+2*i,o=r[3]-r[1]+2*i,l=r[0]-i,c=r[1]-i;let h=n?-1/0:1/0,d=1/0;const u=this.#Pc.at(n?-1:-2),p=[u[0],u[2]];for(const t of this.#Pc){const[e,i,r,s]=t;if(!s&&n)if(i<d){d=i;h=e}else i===d&&(h=Math.max(h,e));else if(s&&!n)if(i<d){d=i;h=e}else i===d&&(h=Math.min(h,e));t[0]=(e-l)/a;t[1]=(i-c)/o;t[2]=(r-c)/o}this.#ec=new Float32Array([l,c,a,o]);this.#Tc=[h,d];this.#kc=p}getOutlines(){this.#Pc.sort((t,e)=>t[0]-e[0]||t[1]-e[1]||t[2]-e[2]);const t=[];for(const e of this.#Pc)if(e[3]){t.push(...this.#Dc(e));this.#Ic(e)}else{this.#Fc(e);t.push(...this.#Dc(e))}return this.#Oc(t)}#Oc(t){const e=[],i=new Set;for(const i of t){const[t,n,r]=i;e.push([t,n,i],[t,r,i])}e.sort((t,e)=>t[1]-e[1]||t[0]-e[0]);for(let t=0,n=e.length;t<n;t+=2){const n=e[t][2],r=e[t+1][2];n.push(r);r.push(n);i.add(n);i.add(r)}const n=[];for(;i.size>0;){const t=i.values().next().value;let[e,r,s,a,o]=t;i.delete(t);let l=e,c=r;const h=[e,s];n.push(h);for(;;){let t;if(i.has(a))t=a;else{if(!i.has(o))break;t=o}i.delete(t);[e,r,s,a,o]=t;if(l!==e){h.push(l,c,e,c===r?r:s);l=e}c=c===r?s:r}h.push(l,c)}return new HighlightOutline(n,this.#ec,this.#Tc,this.#kc)}#Rc(t){const e=this.#Mc;let i=0,n=e.length-1;for(;i<=n;){const r=i+n>>1,s=e[r][0];if(s===t)return r;s<t?i=r+1:n=r-1}return n+1}#Ic([,t,e]){const i=this.#Rc(t);this.#Mc.splice(i,0,[t,e])}#Fc([,t,e]){const i=this.#Rc(t);for(let n=i;n<this.#Mc.length;n++){const[i,r]=this.#Mc[n];if(i!==t)break;if(i===t&&r===e){this.#Mc.splice(n,1);return}}for(let n=i-1;n>=0;n--){const[i,r]=this.#Mc[n];if(i!==t)break;if(i===t&&r===e){this.#Mc.splice(n,1);return}}}#Dc(t){const[e,i,n]=t,r=[[e,i,n]],s=this.#Rc(n);for(let t=0;t<s;t++){const[i,n]=this.#Mc[t];for(let t=0,s=r.length;t<s;t++){const[,a,o]=r[t];if(!(n<=a||o<=i))if(a>=i)if(o>n)r[t][1]=n;else{if(1===s)return[];r.splice(t,1);t--;s--}else{r[t][2]=i;o>n&&r.push([e,n,o])}}}return r}}class HighlightOutline extends Outline{#ec;#Bc=null;#Lc;constructor(t,e,i,n){super();this.#Lc=t;this.#ec=e;this.firstPoint=i;this.lastPoint=n}static build(t,e){const i=new HighlightOutliner(t,.001).getOutlines();i.#Bc=t;i.focusOutline=new HighlightOutliner(t,.0025,.001,e).getOutlines();return i}get isFree(){return!1}get defaultSVGProperties(){return getHighlightSVGProperties(this)}getFocusSVGProperties(t){return getHighlightFocusSVGProperties(this,t)}updateRotation(t){return{root:{"data-main-rotation":t}}}serializeQuadPoints([t,e],[i,n]){const r=this.#Bc,s=new Float32Array(8*r.length);let a=0;for(const{x:o,y:l,width:c,height:h}of r){const r=o*i+t,d=(1-l)*n+e;s[a]=s[a+4]=r;s[a+1]=s[a+3]=d;s[a+2]=s[a+6]=r+c*i;s[a+5]=s[a+7]=d-h*n;a+=8}return s}toSVGPath(){const t=[];for(const e of this.#Lc){let[i,n]=e;t.push(`M${i} ${n}`);for(let r=2;r<e.length;r+=2){const s=e[r],a=e[r+1];if(s===i){t.push(`V${a}`);n=a}else if(a===n){t.push(`H${s}`);i=s}}t.push("Z")}return t.join(" ")}serialize([t,e,i,n],r){const s=[],a=i-t,o=n-e;for(const e of this.#Lc){const i=new Array(e.length);for(let r=0;r<e.length;r+=2){i[r]=t+e[r]*a;i[r+1]=n-e[r+1]*o}s.push(i)}return s}get box(){return this.#ec}}class FreeHighlightOutliner extends FreeDrawOutliner{newFreeDrawOutline(t,e,i,n,r,s){return new FreeHighlightOutline(t,e,i,n,r,s)}}class FreeHighlightDrawer{#Nc;#uc;constructor(t,e,i,n,r,s,a){this.#Nc=new FreeHighlightOutliner(t,e,i,n,r,s,a);this.#uc=r}add(t,e){return this.#Nc.add(t,e)?{path:{d:this.#Nc.toSVGPath()}}:null}addPoints(t){let e=!1;for(let i=0,n=t.length;i<n;i+=2)e=this.#Nc.add(t[i],t[i+1])||e;return e?{path:{d:this.#Nc.toSVGPath()}}:null}end(t,e){return void 0===t?null:this.add(t,e)}isEmpty(){return this.#Nc.isEmpty()}isCancellable(){return this.#Nc.isCancellable()}removeLastElement(){return this.#Nc.removeLastElement()}updateProperty(t,e){return null}getOutlines(){const t=this.#Nc.getOutlines();t.buildFocusOutline(2*this.#uc);return t}get defaultSVGProperties(){return{bbox:[0,0,1,1],root:{viewBox:"0 0 1 1"},rootClass:{highlight:!0,free:!0},path:{d:this.#Nc.toSVGPath()}}}}class FreeHighlightOutline extends FreeDrawOutline{static#Uc=1.5;newOutliner(t,e,i,n,r,s,a=0){return new FreeHighlightOutliner(t,e,i,n,r,s,a)}get isFree(){return!0}buildFocusOutline(t){this.focusOutline=this.getNewOutline(t/2+FreeHighlightOutline.#Uc,.0025)}get defaultSVGProperties(){return getHighlightSVGProperties(this)}getFocusSVGProperties(t){return getHighlightFocusSVGProperties(this,t)}get focusMustRemoveSelfIntersections(){return!0}updateRotation(t){return{root:{"data-main-rotation":t}}}updateProperty(t,e){if("thickness"!==t)return null;const i=this.updateThickness(e/2);this.buildFocusOutline(e);return i}getPathResizedSVGProperties(){return{path:{d:this.toSVGPath()}}}}class HighlightDrawingOptions extends DrawingOptions{constructor(t=null){super();super.updateProperties(t)}updateSVGProperty(t,e){"thickness"!==t&&super.updateSVGProperty(t,e)}clone(){const t=new HighlightDrawingOptions;t.updateAll(this);return t}}class HighlightEditor extends DrawingEditor{#Hc=null;#zc=0;#Gc=null;#Wc=0;#jc="";#ye="";static _DEFAULT_OPACITY=1;static _DEFAULT_THICKNESS=12;static _defaultDrawingOptions=null;static _type="highlight";static _editorType=ki.HIGHLIGHT;static get _keyboardManager(){const t=HighlightEditor.prototype;return util_shadow(this,"_keyboardManager",new KeyboardManager([[["ArrowLeft"],t._moveCaret,{args:[0]}],[["ArrowRight"],t._moveCaret,{args:[1]}],[["ArrowUp"],t._moveCaret,{args:[2]}],[["ArrowDown"],t._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:"highlightEditor"});this.#Hc=t.anchorNode||null;this.#zc=t.anchorOffset||0;this.#Gc=t.focusNode||null;this.#Wc=t.focusOffset||0;this.#jc=t.methodOfCreation||(this._drawOutlines?.isFree?"main_toolbar":"");this.#ye=t.text||"";this._isDraggable=!1;this.defaultL10nId="pdfjs-editor-highlight-editor";this.rotate()}static initialize(t,e){AnnotationEditor.initialize(t,e);this._defaultDrawingOptions||=new HighlightDrawingOptions({fill:e.highlightColors?.values().next().value||"#fff066","fill-opacity":HighlightEditor._DEFAULT_OPACITY,thickness:HighlightEditor._DEFAULT_THICKNESS})}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();e.updateProperties(t);return e}static get typesMap(){return util_shadow(this,"typesMap",new Map([[Pi.HIGHLIGHT_COLOR,"fill"],[Pi.HIGHLIGHT_THICKNESS,"thickness"]]))}static get isDrawer(){return!1}static get _hasClipPath(){return!0}static get _hasDrawClass(){return!1}_addOutlines(t){const{boxes:e,drawOutlines:i}=t;if(e||i){this._drawingOptions||=t.drawingOptions||HighlightEditor.getDefaultDrawingOptions();e&&(t={...t,drawOutlines:HighlightOutline.build(e,"ltr"===this._uiManager.direction)});super._addOutlines(t)}}get colorType(){return Pi.HIGHLIGHT_COLOR}get color(){return this._drawingOptions.fill}get opacity(){return this._drawingOptions["fill-opacity"]}get _opacityName(){return"fill-opacity"}get _drawRotation(){return this._drawOutlines?.isFree?this.rotation:0}get isResizable(){return!1}get _mustBeDisabledOnCommit(){return!1}get _mustFixPosition(){return!this._drawOutlines?.isFree}get telemetryInitialData(){return{action:"added",type:this._drawOutlines.isFree?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:this._drawingOptions.thickness,methodOfCreation:this.#jc}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}translateInPage(t,e){}get toolbarPosition(){return this.#Vc(this._drawOutlines.focusOutline.lastPoint)}get commentButtonPosition(){return this.#Vc(this._drawOutlines.firstPoint)}#Vc([t,e]){const[i,n,r,s]=this._drawOutlines.box;return[(t-i)/r,(e-n)/s]}updateParams(t,e){switch(t){case Pi.HIGHLIGHT_COLOR:this._updateColorAndOpacity(e,HighlightEditor._DEFAULT_OPACITY,t);this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(e)},!0);break;case Pi.HIGHLIGHT_THICKNESS:super.updateParams(t,e);this._reportTelemetry({action:"thickness_changed",thickness:e},!0)}}get propertiesToUpdate(){const t=super.propertiesToUpdate;t.push([Pi.HIGHLIGHT_FREE,this._drawOutlines.isFree]);return t}get toolbarButtons(){if(this._uiManager.highlightColors){this._colorPicker=new ColorPicker({editor:this});return[["colorPicker",this._colorPicker]]}return super.toolbarButtons}fixAndSetPosition(){return super.fixAndSetPosition(this._drawRotation)}getRect(t,e){return super.getRect(t,e,this._drawRotation)}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this);t&&this.div.focus()}remove(){this._reportTelemetry({action:"deleted"});super.remove()}render(){if(this.div)return this.div;const t=super.render();if(this.#ye){t.setAttribute("aria-label",this.#ye);t.setAttribute("role","mark")}this._drawOutlines.isFree?t.classList.add("free"):t.addEventListener("keydown",this.#qc.bind(this),{signal:this._uiManager._signal});this.enableEditing();return t}#qc(t){HighlightEditor._keyboardManager.exec(this,t)}_moveCaret(t){this.parent.unselect(this);switch(t){case 0:case 2:this.#$c(!0);break;case 1:case 3:this.#$c(!1)}}#$c(t){if(!this.#Hc)return;const e=window.getSelection();t?e.setPosition(this.#Hc,this.#zc):e.setPosition(this.#Gc,this.#Wc)}unselect(){super.unselect();this._drawOutlines.isFree||this.#$c(!1)}static createDrawerInstance({x:t,y:e,box:i,parent:n,isLTR:r}){return new FreeHighlightDrawer(t,e,i,n.scale,this._defaultDrawingOptions.thickness/2,r,.001)}static _getDrawingTarget(t,{target:e}){return e.closest(".textLayer")}static _getPointerCoords({x:t,y:e}){return[t,e]}static _addDrawingListeners(t,e){t.classList.add("free");e.addEventListener("abort",()=>t.classList.remove("free"),{once:!0});window.addEventListener("blur",()=>this._endDraw(null),{signal:e});window.addEventListener("pointerdown",stopEvent,{capture:!0,passive:!1,signal:e})}static _endDrawingSession(t=!1){return this.endDrawing(t)}createDrawingOptions({color:t,opacity:e,thickness:i}){const{_defaultDrawingOptions:n,_DEFAULT_OPACITY:r}=HighlightEditor;this._drawingOptions=HighlightEditor.getDefaultDrawingOptions({fill:Util.makeHexColor(...t),"fill-opacity":e||r,thickness:i||n.thickness})}static deserializeDraw(t,e,i,n,r,s,a){const{quadPoints:o}=s;if(o){const r=[];for(let s=0,a=o.length;s<a;s+=8)r.push({x:(o[s]-t)/i,y:1-(o[s+1]-e)/n,width:(o[s+2]-o[s])/i,height:(o[s+1]-o[s+5])/n});return HighlightOutline.build(r,"ltr"===a.direction)}const l=s.thickness||this._defaultDrawingOptions.thickness,c=(s.inkLists||s.outlines.points)[0],h=new FreeHighlightOutliner(c[0]-t,n-(c[1]-e),[0,0,i,n],1,l/2,!0,.001);for(let i=0,r=c.length;i<r;i+=2)h.add(c[i]-t,n-(c[i+1]-e));const d=h.getOutlines();d.buildFocusOutline(l);return d}static async deserialize(t,e,i){let n=null;if(t instanceof HighlightAnnotationElement){const{data:{quadPoints:e,rect:i,rotation:r,id:s,color:a,opacity:o,popupRef:l,richText:c,contentsObj:h,creationDate:d,modificationDate:u},parent:{page:{pageNumber:p}}}=t;n=t={annotationType:ki.HIGHLIGHT,color:Array.from(a),opacity:o,quadPoints:e,pageIndex:p-1,rect:i.slice(0),rotation:r,annotationElementId:s,id:s,deleted:!1,popupRef:l,richText:c,comment:h?.str||null,creationDate:d,modificationDate:u}}else if(t instanceof InkAnnotationElement){const{data:{inkLists:e,rect:i,rotation:r,id:s,color:a,borderStyle:{rawWidth:o},popupRef:l,richText:c,contentsObj:h,creationDate:d,modificationDate:u},parent:{page:{pageNumber:p}}}=t;n=t={annotationType:ki.HIGHLIGHT,color:Array.from(a),thickness:o,inkLists:e,pageIndex:p-1,rect:i.slice(0),rotation:r,annotationElementId:s,id:s,deleted:!1,popupRef:l,richText:c,comment:h?.str||null,creationDate:d,modificationDate:u}}const r=await super.deserialize(t,e,i);r._initialData=n;t.comment&&r.setCommentData(t);return r}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=super.serialize(t);Object.assign(e,{color:AnnotationEditor._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),opacity:this.opacity,thickness:this._drawingOptions.thickness,quadPoints:this._drawOutlines.serializeQuadPoints(this.pageTranslation,this.pageDimensions),outlines:this._drawOutlines.serialize(e.rect,this._drawRotation)});this.addComment(e);if(this.annotationElementId&&!this.#Ol(e))return null;e.id=this.annotationElementId;return e}#Ol(t){const{color:e}=this._initialData;return this.hasEditedComment||t.color.some((t,i)=>t!==e[i])}renderAnnotationElement(t){if(this.deleted){t.hide();return null}t.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}}class InputSmoother{static#Xc=10;static#Kc=1e3/180;static#Yc=100;static#Jc=.001;#Qc;#Zc;#th;constructor(t,e,i){this.#Qc=[t,e,i];this.#Zc=this.#th=i}add(t,e,i){const n=this.#Qc,r=n.at(-1);i=i>r?i:r+InputSmoother.#Jc;n.push(t,e,i);const s=this.#eh(i-InputSmoother.#Xc,!0),a=this.#ih(this.#th-InputSmoother.#Xc);if(a>=n.length/2){n.copyWithin(0,a);n.length-=a}return s}get pendingPoints(){return this.#eh(1/0,!1)}end(){return this.#eh(1/0,!0)}#eh(t,e){const i=this.#Qc,n=this.#Zc,r=i.at(-1),s=[],a=this.#th;for(let o=this.#ih(a)+3;o<i.length;o+=3){const l=i[o-1],c=i[o+2]-l,h=Math.min(Math.ceil(c/InputSmoother.#Kc),InputSmoother.#Yc);for(let d=1;d<=h;d++){const u=d===h?i[o+2]:l+c*d/h;if(u<=a)continue;if(u>t)return s;const p=Math.min(InputSmoother.#Xc,u-n,r-u);this.#nh(u-p,u+p,s);e&&(this.#th=u)}}return s}#ih(t){const e=this.#Qc;let i=0,n=e.length/3-1;for(;i<n;){const r=i+n+1>>1;e[3*r+2]<=t?i=r:n=r-1}return 3*i}#nh(t,e,i){const n=this.#Qc,r=this.#ih(t);let s=0,a=0,o=0;for(let i=r;i<n.length-3&&n[i+2]<e;i+=3){const r=n[i],l=n[i+1],c=n[i+2],h=n[i+5],d=Math.max(c,t),u=Math.min(h,e);if(u<=d)continue;const p=u-d,g=(d+u-2*c)/(h-c);s+=p*(r+g*(n[i+3]-r)/2);a+=p*(l+g*(n[i+4]-l)/2);o+=p}0===o?i.push(n[r],n[r+1]):i.push(s/o,a/o)}}function svgPoint(t,e){return`${Outline.svgRound(t[e])} ${Outline.svgRound(t[e+1])}`}function pushCurves(t,e,i){for(let n=i,r=e.length;n<r;n+=6)t.push(`C${svgPoint(e,n)} ${svgPoint(e,n+2)} ${svgPoint(e,n+4)}`)}function lineToSVGPath(t){const e=`M${svgPoint(t,4)}`;if(6===t.length)return`${e}Z`;if(12===t.length&&isNaN(t[6]))return`${e}L${svgPoint(t,10)}`;const i=[e];pushCurves(i,t,6);return i.join("")}class InkDrawOutliner{#ac=new Float64Array(6);#rh=new Float64Array(2);#rl;#sh;#da;#ah=null;#uc;#pc;#oh=1;#lh=new Float64Array(2);#ch="";#hh=0;#Lc=new InkDrawOutline;#dh;#uh;constructor(t,e,i,n,r,s,a){this.#dh=i;this.#uh=n;this.#da=r;this.#uc=s;this.#sh=[];this.#ph(t,e,a)}#ph(t,e,i){[t,e]=this.#gh(t,e);const n=this.#rl=[NaN,NaN,NaN,NaN,t,e];this.#pc=[t,e];this.#sh.push({line:n,points:this.#pc});this.#ac.set(n,0);this.#hh=0;this.#oh=1;this.#lh.set(this.#rh);this.#ah=void 0===i?null:new InputSmoother(t,e,i)}updateProperty(t,e){"stroke-width"===t&&(this.#uc=e)}#gh(t,e){return Outline._normalizePoint(t,e,this.#dh,this.#uh,this.#da,this.#rh)}isEmpty(){return!this.#sh?.length}isCancellable(){return this.#oh<=5}add(t,e,i){this.#mh(t,e,i);return{path:{d:this.#fh()}}}addPoints(t,e){for(let i=0,n=t.length;i<n;i+=2)this.#mh(t[i],t[i+1],e?.[i/2]);return{path:{d:this.#fh()}}}#mh(t,e,i){[t,e]=this.#gh(t,e);const[n,r]=this.#lh;if(!this.#bh(t,e,n,r)){this.#oh++;this.#lh.set(this.#rh)}this.#ah?this.#yh(this.#ah.add(t,e,i)):this.#wh(t,e)}#bh(t,e,i,n){return Math.hypot(this.#dh*(t-i),this.#uh*(e-n))<=2}#yh(t){for(let e=0,i=t.length;e<i;e+=2)this.#wh(t[e],t[e+1])}#wh(t,e){const[,,i,n,r,s]=this.#ac;if(!this.#bh(t,e,r,s)){this.#pc.push(t,e);if(isNaN(i))this.#rl.push(NaN,NaN,NaN,NaN,t,e);else{isNaN(this.#ac[0])&&this.#rl.splice(6,6);Outline.createBezierPoints(i,n,r,s,t,e,this.#rl)}this.#ac.copyWithin(0,2);this.#ac[4]=t;this.#ac[5]=e}}#vh(){const t=this.#rl;if(this.#pc.length<6||this.#hh===t.length)return;const e=[this.#ch];if(0===this.#hh){e.push(`M${svgPoint(t,4)}`);this.#hh=6}pushCurves(e,t,this.#hh);this.#ch=e.join("");this.#hh=t.length}#_h(){if(this.#rl){if(this.#ah){this.#yh(this.#ah.end());this.#ah=null}if(this.#pc.length<6)this.#ch+=lineToSVGPath(this.#rl);else{const[,,t,e,i,n]=this.#ac;Outline.createBezierPoints(t,e,i,n,i,n,this.#rl);this.#vh()}this.#rl=this.#pc=null}}end(t,e,i){this.#rl&&void 0!==t&&this.#mh(t,e,i);this.#_h();return{path:{d:this.#ch}}}startNew(t,e,i,n,r,s){this.#dh=i;this.#uh=n;this.#da=r;const a=this.#sh.at(-1);if(a){a.line=new Float32Array(a.line);a.points=new Float32Array(a.points)}this.#ph(t,e,s);return null}getLastElement(){return this.#sh.at(-1)}setLastElement(t){if(!this.#sh)return this.#Lc.setLastElement(t);this.#sh.push(t);this.#ch+=lineToSVGPath(t.line);return{path:{d:this.#ch}}}removeLastElement(){if(!this.#sh)return this.#Lc.removeLastElement();this.#rl=this.#pc=this.#ah=null;this.#sh.pop();this.#ch=this.#sh.map(({line:t})=>lineToSVGPath(t)).join("");return{path:{d:this.#ch}}}#fh(){this.#vh();const t=[this.#ch];if(0===this.#hh){t.push(`M${svgPoint(this.#rl,4)}`);4===this.#pc.length&&t.push(`L${svgPoint(this.#rl,10)}`)}let e=this.#ah?.pendingPoints;e?.length||(e=this.#rh);for(let i=0,n=e.length;i<n;i+=2)t.push(`L${svgPoint(e,i)}`);return t.join("")}getOutlines(t,e,i,n){this.#_h();const r=this.#sh.at(-1);r.line=new Float32Array(r.line);r.points=new Float32Array(r.points);this.#Lc.build(this.#sh,t,e,i,this.#da,this.#uc,n);this.#ac=null;this.#rl=null;this.#sh=null;this.#ch=null;return this.#Lc}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class InkDrawOutline extends Outline{#Cc;#Ah=0;#nc;#sh;#dh;#uh;#xh;#da;#uc;build(t,e,i,n,r,s,a){this.#dh=e;this.#uh=i;this.#xh=n;this.#da=r;this.#uc=s;this.#nc=a??0;this.#sh=t;this.#Ch()}get thickness(){return this.#uc}setLastElement(t){this.#sh.push(t);return{path:{d:this.toSVGPath()}}}removeLastElement(){this.#sh.pop();return{path:{d:this.toSVGPath()}}}toSVGPath(){return this.#sh.map(({line:t})=>lineToSVGPath(t)).join("")}serialize([t,e,i,n],r){const s=[],a=[],[o,l,c,h]=this.#Eh();let d,u,p,g,m,f,b,y,w;switch(this.#da){case 0:w=Outline._rescale;d=t;u=e+n;p=i;g=-n;m=t+o*i;f=e+(1-l-h)*n;b=t+(o+c)*i;y=e+(1-l)*n;break;case 90:w=Outline._rescaleAndSwap;d=t;u=e;p=i;g=n;m=t+l*i;f=e+o*n;b=t+(l+h)*i;y=e+(o+c)*n;break;case 180:w=Outline._rescale;d=t+i;u=e;p=-i;g=n;m=t+(1-o-c)*i;f=e+l*n;b=t+(1-o)*i;y=e+(l+h)*n;break;case 270:w=Outline._rescaleAndSwap;d=t+i;u=e+n;p=-i;g=-n;m=t+(1-l-h)*i;f=e+(1-o-c)*n;b=t+(1-l)*i;y=e+(1-o)*n}for(const{line:t,points:e}of this.#sh){s.push(w(t,d,u,p,g,r?new Array(t.length):null));a.push(w(e,d,u,p,g,r?new Array(e.length):null))}return{lines:s,points:a,rect:[m,f,b,y]}}static deserialize(t,e,i,n,r,{paths:{lines:s,points:a},rotation:o,thickness:l}){const c=[];let h,d,u,p,g;switch(o){case 0:g=Outline._rescale;h=-t/i;d=e/n+1;u=1/i;p=-1/n;break;case 90:g=Outline._rescaleAndSwap;h=-e/n;d=-t/i;u=1/n;p=1/i;break;case 180:g=Outline._rescale;h=t/i+1;d=-e/n;u=-1/i;p=1/n;break;case 270:g=Outline._rescaleAndSwap;h=e/n+1;d=t/i+1;u=-1/n;p=-1/i}if(!s){s=[];for(const t of a){const e=t.length;if(2===e){s.push(new Float32Array([NaN,NaN,NaN,NaN,t[0],t[1]]));continue}if(4===e){s.push(new Float32Array([NaN,NaN,NaN,NaN,t[0],t[1],NaN,NaN,NaN,NaN,t[2],t[3]]));continue}const i=new Float32Array(3*e);s.push(i);let[n,r,a,o]=t.subarray(0,4);i.set([NaN,NaN,NaN,NaN,n,r],0);for(let s=4;s<=e;s+=2){const l=Math.min(s,e-2),c=t[l],h=t[l+1];i.set(Outline.createBezierPoints(n,r,a,o,c,h),3*(s-2));[n,r,a,o]=[a,o,c,h]}}}for(let t=0,e=s.length;t<e;t++)c.push({line:g(s[t].map(t=>t??NaN),h,d,u,p),points:g(a[t].map(t=>t??NaN),h,d,u,p)});const m=new this.prototype.constructor;m.build(c,i,n,1,o,l,r);return m}#Sh(t=this.#uc){const e=this.#nc+t/2*this.#xh;return this.#da%180==0?[e/this.#dh,e/this.#uh]:[e/this.#uh,e/this.#dh]}#Eh(){const[t,e,i,n]=this.#Cc,[r,s]=this.#Sh(0);return[t+r,e+s,i-2*r,n-2*s]}#Ch(){const t=this.#Cc=gi.slice();for(const{line:e}of this.#sh){if(e.length<=12){for(let i=4,n=e.length;i<n;i+=6)Util.pointBoundingBox(e[i],e[i+1],t);continue}let i=e[4],n=e[5];for(let r=6,s=e.length;r<s;r+=6){const[s,a,o,l,c,h]=e.subarray(r,r+6);Util.bezierBoundingBox(i,n,s,a,o,l,c,h,t);i=c;n=h}}const[e,i]=this.#Sh();t[0]=MathClamp(t[0]-e,0,1);t[1]=MathClamp(t[1]-i,0,1);t[2]=MathClamp(t[2]+e,0,1);t[3]=MathClamp(t[3]+i,0,1);t[2]-=t[0];t[3]-=t[1]}get box(){return this.#Cc}updateProperty(t,e){return"stroke-width"===t?this.#Th(e):null}#Th(t){const[e,i]=this.#Sh();this.#uc=t;const[n,r]=this.#Sh(),[s,a]=[n-e,r-i],o=this.#Cc;o[0]-=s;o[1]-=a;o[2]+=2*s;o[3]+=2*a;return o}updateParentDimensions([t,e],i){const[n,r]=this.#Sh();this.#dh=t;this.#uh=e;this.#xh=i;const[s,a]=this.#Sh(),o=s-n,l=a-r,c=this.#Cc;c[0]-=o;c[1]-=l;c[2]+=2*o;c[3]+=2*l;return c}updateRotation(t){this.#Ah=t;return{path:{transform:this.rotationTransform}}}get viewBox(){return this.#Cc.map(Outline.svgRound).join(" ")}get defaultProperties(){const[t,e]=this.#Cc;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Outline.svgRound(t)} ${Outline.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=this.#Cc;let i=0,n=0,r=0,s=0,a=0,o=0;switch(this.#Ah){case 90:n=e/t;r=-t/e;a=t;break;case 180:i=-1;s=-1;a=t;o=e;break;case 270:n=-e/t;r=t/e;o=e;break;default:return""}return`matrix(${i} ${n} ${r} ${s} ${Outline.svgRound(a)} ${Outline.svgRound(o)})`}getPathResizingSVGProperties([t,e,i,n]){const[r,s]=this.#Sh(),[a,o,l,c]=this.#Cc;if(Math.abs(l-r)<=Outline.PRECISION||Math.abs(c-s)<=Outline.PRECISION){const r=t+i/2-(a+l/2),s=e+n/2-(o+c/2);return{path:{"transform-origin":`${Outline.svgRound(t)} ${Outline.svgRound(e)}`,transform:`${this.rotationTransform} translate(${r} ${s})`}}}const h=(i-2*r)/(l-2*r),d=(n-2*s)/(c-2*s),u=l/i,p=c/n;return{path:{"transform-origin":`${Outline.svgRound(a)} ${Outline.svgRound(o)}`,transform:`${this.rotationTransform} scale(${u} ${p}) translate(${Outline.svgRound(r)} ${Outline.svgRound(s)}) scale(${h} ${d}) translate(${Outline.svgRound(-r)} ${Outline.svgRound(-s)})`}}}getPathResizedSVGProperties([t,e,i,n]){const[r,s]=this.#Sh(),a=this.#Cc,[o,l,c,h]=a;a[0]=t;a[1]=e;a[2]=i;a[3]=n;if(Math.abs(c-r)<=Outline.PRECISION||Math.abs(h-s)<=Outline.PRECISION){const r=t+i/2-(o+c/2),s=e+n/2-(l+h/2);for(const{line:t,points:e}of this.#sh){Outline._translate(t,r,s,t);Outline._translate(e,r,s,e)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Outline.svgRound(t)} ${Outline.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const d=(i-2*r)/(c-2*r),u=(n-2*s)/(h-2*s),p=-d*(o+r)+t+r,g=-u*(l+s)+e+s;if(1!==d||1!==u||0!==p||0!==g)for(const{line:t,points:e}of this.#sh){Outline._rescale(t,p,g,d,u,t);Outline._rescale(e,p,g,d,u,e)}return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Outline.svgRound(t)} ${Outline.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],i){const[n,r]=i,s=this.#Cc,a=t-s[0],o=e-s[1];if(this.#dh===n&&this.#uh===r)for(const{line:t,points:e}of this.#sh){Outline._translate(t,a,o,t);Outline._translate(e,a,o,e)}else{const t=this.#dh/n,e=this.#uh/r;this.#dh=n;this.#uh=r;for(const{line:i,points:n}of this.#sh){Outline._rescale(i,a,o,t,e,i);Outline._rescale(n,a,o,t,e,n)}s[2]*=t;s[3]*=e}s[0]=t;s[1]=e;return{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${Outline.svgRound(t)} ${Outline.svgRound(e)}`}}}get defaultSVGProperties(){const t=this.#Cc;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${Outline.svgRound(t[0])} ${Outline.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}class InkDrawingOptions extends DrawingOptions{constructor(t){super();this._viewParameters=t;super.updateProperties({fill:"none",stroke:AnnotationEditor._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){if("stroke-width"===t){e??=this["stroke-width"];e*=this._viewParameters.realScale}super.updateSVGProperty(t,e)}clone(){const t=new InkDrawingOptions(this._viewParameters);t.updateAll(this);return t}}class InkEditor extends DrawingEditor{static _type="ink";static _editorType=ki.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"});this._willKeepAspectRatio=!0;this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(t,e){AnnotationEditor.initialize(t,e);this._defaultDrawingOptions=new InkDrawingOptions(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();e.updateProperties(t);return e}static get supportMultipleDrawings(){return!0}static get typesMap(){return util_shadow(this,"typesMap",new Map([[Pi.INK_THICKNESS,"stroke-width"],[Pi.INK_COLOR,"stroke"],[Pi.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance({x:t,y:e,box:[,,i,n],rotation:r,timeStamp:s}){return new InkDrawOutliner(t,e,i,n,r,this._defaultDrawingOptions["stroke-width"],s)}static deserializeDraw(t,e,i,n,r,s){return InkDrawOutline.deserialize(t,e,i,n,r,s)}static async deserialize(t,e,i){let n=null;if(t instanceof InkAnnotationElement){const{data:{inkLists:e,rect:i,rotation:r,id:s,color:a,opacity:o,borderStyle:{rawWidth:l},popupRef:c,richText:h,contentsObj:d,creationDate:u,modificationDate:p},parent:{page:{pageNumber:g}}}=t;n=t={annotationType:ki.INK,color:Array.from(a),thickness:l,opacity:o,paths:{points:e},boxes:null,pageIndex:g-1,rect:i.slice(0),rotation:r,annotationElementId:s,id:s,deleted:!1,popupRef:c,richText:h,comment:d?.str||null,creationDate:u,modificationDate:p}}const r=await super.deserialize(t,e,i);r._initialData=n;t.comment&&r.setCommentData(t);return r}get toolbarButtons(){this._colorPicker||=new BasicColorPicker(this);return[["colorPicker",this._colorPicker]]}get colorType(){return Pi.INK_COLOR}get colorAndOpacityType(){return Pi.INK_COLOR_AND_OPACITY}get opacityType(){return Pi.INK_OPACITY}updateParams(t,e){t!==Pi.INK_COLOR_AND_OPACITY?super.updateParams(t,e):this._updateColorAndOpacity(e.color,e.opacity)}static updateDefaultParams(t,e){if(t!==Pi.INK_COLOR_AND_OPACITY)super.updateDefaultParams(t,e);else{super.updateDefaultParams(Pi.INK_COLOR,e.color);super.updateDefaultParams(Pi.INK_OPACITY,e.opacity)}}get color(){return this._drawingOptions.stroke}get opacity(){return this._drawingOptions["stroke-opacity"]}onScaleChanging(){if(!this.parent)return;super.onScaleChanging();const{_drawId:t,_drawingOptions:e,parent:i}=this;e.updateSVGProperty("stroke-width");i.drawLayer.updateProperties(t,e.toSVGProperties())}static onScaleChangingWhenDrawing(){const t=this._currentParent;if(t){super.onScaleChangingWhenDrawing();this._defaultDrawingOptions.updateSVGProperty("stroke-width");t.drawLayer.updateProperties(this._currentDrawId,this._defaultDrawingOptions.toSVGProperties())}}createDrawingOptions({color:t,thickness:e,opacity:i}){this._drawingOptions=InkEditor.getDefaultDrawingOptions({stroke:Util.makeHexColor(...t),"stroke-width":e,"stroke-opacity":i})}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const{lines:e,points:i}=this.serializeDraw(t),{_drawingOptions:{stroke:n,"stroke-opacity":r,"stroke-width":s}}=this,a=Object.assign(super.serialize(t),{color:AnnotationEditor._colorManager.convert(n),opacity:r,thickness:s,paths:{lines:e,points:i}});this.addComment(a);if(t){a.isCopy=!0;return a}if(this.annotationElementId&&!this.#Ol(a))return null;a.id=this.annotationElementId;return a}#Ol(t){const{color:e,thickness:i,opacity:n,pageIndex:r}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||t.color.some((t,i)=>t!==e[i])||t.thickness!==i||t.opacity!==n||t.pageIndex!==r}renderAnnotationElement(t){if(this.deleted){t.hide();return null}const{points:e,rect:i}=this.serializeDraw(!1);t.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:e,popup:this.comment});return null}}class ContourDrawOutline extends InkDrawOutline{toSVGPath(){let t=super.toSVGPath();t.endsWith("Z")||(t+="Z");return t}}ni();class SignatureExtractor{static#kh={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#Ph(t,e,i,n){n-=e;return 0===(i-=t)?n>0?0:4:1===i?n+6:2-n}static#Mh=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#Dh(t,e,i,n,r,s,a){const o=this.#Ph(i,n,r,s);for(let r=0;r<8;r++){const s=(-r+o-a+16)%8;if(0!==t[(i+this.#Mh[2*s])*e+(n+this.#Mh[2*s+1])])return s}return-1}static#Ih(t,e,i,n,r,s,a){const o=this.#Ph(i,n,r,s);for(let r=0;r<8;r++){const s=(r+o+a+16)%8;if(0!==t[(i+this.#Mh[2*s])*e+(n+this.#Mh[2*s+1])])return s}return-1}static#Fh(t,e,i,n){const r=t.length,s=new Int32Array(r);for(let e=0;e<r;e++)s[e]=t[e]<=n?1:0;for(let t=1;t<i-1;t++)s[t*e]=s[t*e+e-1]=0;for(let t=0;t<e;t++)s[t]=s[e*i-1-t]=0;let a,o=1;const l=[];for(let t=1;t<i-1;t++){a=1;for(let i=1;i<e-1;i++){const n=t*e+i,r=s[n];if(0===r)continue;let c=t,h=i;if(1===r&&0===s[n-1]){o+=1;h-=1}else{if(!(r>=1&&0===s[n+1])){1!==r&&(a=Math.abs(r));continue}o+=1;h+=1;r>1&&(a=r)}const d=[i,t],u=h===i+1,p={isHole:u,points:d,id:o,parent:0};l.push(p);let g;for(const t of l)if(t.id===a){g=t;break}g?g.isHole?p.parent=u?g.parent:a:p.parent=u?a:g.parent:p.parent=u?a:0;const m=this.#Dh(s,e,t,i,c,h,0);if(-1===m){s[n]=-o;1!==s[n]&&(a=Math.abs(s[n]));continue}let f=this.#Mh[2*m],b=this.#Mh[2*m+1];const y=t+f,w=i+b;c=y;h=w;let v=t,_=i;for(;;){const r=this.#Ih(s,e,v,_,c,h,1);f=this.#Mh[2*r];b=this.#Mh[2*r+1];const l=v+f,u=_+b;d.push(u,l);const p=v*e+_;0===s[p+1]?s[p]=-o:1===s[p]&&(s[p]=o);if(l===t&&u===i&&v===y&&_===w){1!==s[n]&&(a=Math.abs(s[n]));break}c=v;h=_;v=l;_=u}}}return l}static#Oh(t,e,i,n){if(i-e<=4){for(let r=e;r<i-2;r+=2)n.push(t[r],t[r+1]);return}const r=t[e],s=t[e+1],a=t[i-4]-r,o=t[i-3]-s,l=Math.hypot(a,o),c=a/l,h=o/l,d=c*s-h*r,u=o/a,p=1/l,g=Math.atan(u),m=Math.cos(g),f=Math.sin(g),b=p*(Math.abs(m)+Math.abs(f)),y=p*(1-b+b**2),w=Math.max(Math.atan(Math.abs(f+m)*y),Math.atan(Math.abs(f-m)*y));let v=0,_=e;for(let n=e+2;n<i-2;n+=2){const e=Math.abs(d-c*t[n+1]+h*t[n]);if(e>v){_=n;v=e}}if(v>(l*w)**2){this.#Oh(t,e,_+2,n);this.#Oh(t,_,i,n)}else n.push(r,s)}static#Rh(t){const e=[],i=t.length;this.#Oh(t,0,i,e);e.push(t[i-2],t[i-1]);return e.length<=4?null:e}static#Bh(t,e,i,n,r,s){const a=new Float32Array(s**2),o=-2*n**2,l=s>>1;for(let t=0;t<s;t++){const e=(t-l)**2;for(let i=0;i<s;i++)a[t*s+i]=Math.exp((e+(i-l)**2)/o)}const c=new Float32Array(256),h=-2*r**2;for(let t=0;t<256;t++)c[t]=Math.exp(t**2/h);const d=t.length,u=new Uint8Array(d),p=new Uint32Array(256);for(let n=0;n<i;n++)for(let r=0;r<e;r++){const o=n*e+r,h=t[o];let d=0,g=0;for(let o=0;o<s;o++){const u=n+o-l;if(!(u<0||u>=i))for(let i=0;i<s;i++){const n=r+i-l;if(n<0||n>=e)continue;const p=t[u*e+n],m=a[o*s+i]*c[Math.abs(p-h)];d+=p*m;g+=m}}p[u[o]=Math.round(d/g)]++}return[u,p]}static#Lh(t){const e=new Uint32Array(256);for(const i of t)e[i]++;return e}static#Nh(t){const e=t.length,i=new Uint8ClampedArray(e>>2);let n=-1/0,r=1/0;for(let e=0,s=i.length;e<s;e++){const s=i[e]=t[e<<2];n=Math.max(n,s);r=Math.min(r,s)}const s=255/(n-r);for(let t=0,e=i.length;t<e;t++)i[t]=(i[t]-r)*s;return i}static#Uh(t){let e,i=-1/0,n=-1/0;const r=t.findIndex(t=>0!==t);let s=r,a=r;for(e=r;e<256;e++){const r=t[e];if(r>i){if(e-s>n){n=e-s;a=e-1}i=r;s=e}}for(e=a-1;e>=0&&!(t[e]>t[e+1]);e--);return e}static#Hh(t){const e=t,{width:i,height:n}=t,{maxDim:r}=this.#kh;let s=i,a=n;if(i>r||n>r){let o=i,l=n,c=Math.log2(Math.max(i,n)/r);const h=Math.floor(c);c=c===h?h-1:h;for(let i=0;i<c;i++){s=Math.ceil(o/2);a=Math.ceil(l/2);const i=new OffscreenCanvas(s,a);i.getContext("2d").drawImage(t,0,0,o,l,0,0,s,a);o=s;l=a;t!==e&&t.close();t=i.transferToImageBitmap()}const d=Math.min(r/s,r/a);s=Math.round(s*d);a=Math.round(a*d)}const o=new OffscreenCanvas(s,a).getContext("2d",{willReadFrequently:!0});o.fillStyle="white";o.fillRect(0,0,s,a);o.filter="grayscale(1)";o.drawImage(t,0,0,t.width,t.height,0,0,s,a);const l=o.getImageData(0,0,s,a).data;return[this.#Nh(l),s,a]}static extractContoursFromText(t,{fontFamily:e,fontStyle:i,fontWeight:n},r,s,a,o){let l=new OffscreenCanvas(1,1),c=l.getContext("2d",{alpha:!1});const h=c.font=`${i} ${n} 200px ${e}`,{actualBoundingBoxLeft:d,actualBoundingBoxRight:u,actualBoundingBoxAscent:p,actualBoundingBoxDescent:g,fontBoundingBoxAscent:m,fontBoundingBoxDescent:f,width:b}=c.measureText(t),y=1.5,w=Math.ceil(Math.max(Math.abs(d)+Math.abs(u)||0,b)*y),v=Math.ceil(Math.max(Math.abs(p)+Math.abs(g)||200,Math.abs(m)+Math.abs(f)||200)*y);l=new OffscreenCanvas(w,v);c=l.getContext("2d",{alpha:!0,willReadFrequently:!0});c.font=h;c.filter="grayscale(1)";c.fillStyle="white";c.fillRect(0,0,w,v);c.fillStyle="black";c.fillText(t,.5*w/2,1.5*v/2);const _=this.#Nh(c.getImageData(0,0,w,v).data),A=this.#Lh(_),x=this.#Uh(A),C=this.#Fh(_,w,v,x);return this.processDrawnLines({lines:{curves:C,width:w,height:v},pageWidth:r,pageHeight:s,rotation:a,innerMargin:o,mustSmooth:!0,areContours:!0})}static process(t,e,i,n,r){const[s,a,o]=this.#Hh(t),[l,c]=this.#Bh(s,a,o,Math.hypot(a,o)*this.#kh.sigmaSFactor,this.#kh.sigmaR,this.#kh.kernelSize),h=this.#Uh(c),d=this.#Fh(l,a,o,h);return this.processDrawnLines({lines:{curves:d,width:a,height:o},pageWidth:e,pageHeight:i,rotation:n,innerMargin:r,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:t,pageWidth:e,pageHeight:i,rotation:n,innerMargin:r,mustSmooth:s,areContours:a}){n%180!=0&&([e,i]=[i,e]);const{curves:o,width:l,height:c}=t,h=t.thickness??0,d=[],u=Math.min(e/l,i/c),p=u/e,g=u/i,m=[];for(const{points:t}of o){const e=s?this.#Rh(t):t;if(!e)continue;m.push(e);const i=e.length,n=new Float32Array(i),r=new Float32Array(3*(2===i?2:i-2));d.push({line:r,points:n});if(2===i){n[0]=e[0]*p;n[1]=e[1]*g;r.set([NaN,NaN,NaN,NaN,n[0],n[1]],0);continue}let[a,o,l,c]=e;a*=p;o*=g;l*=p;c*=g;n.set([a,o,l,c],0);r.set([NaN,NaN,NaN,NaN,a,o],0);for(let t=4;t<i;t+=2){const i=n[t]=e[t]*p,s=n[t+1]=e[t+1]*g;r.set(Outline.createBezierPoints(a,o,l,c,i,s),3*(t-2));[a,o,l,c]=[l,c,i,s]}}if(0===d.length)return null;const f=a?new ContourDrawOutline:new InkDrawOutline;f.build(d,e,i,1,n,a?0:h,r);return{outline:f,newCurves:m,areContours:a,thickness:h,width:l,height:c}}static async compressSignature({outlines:t,areContours:e,thickness:i,width:n,height:r}){let s,a=1/0,o=-1/0,l=0;for(const e of t){l+=e.length;for(let t=2,i=e.length;t<i;t++){const i=e[t]-e[t-2];a=Math.min(a,i);o=Math.max(o,i)}}s=a>=-128&&o<=127?Int8Array:a>=-32768&&o<=32767?Int16Array:Int32Array;const c=t.length,h=8+3*c,d=new Uint32Array(h);let u=0;d[u++]=h*Uint32Array.BYTES_PER_ELEMENT+(l-2*c)*s.BYTES_PER_ELEMENT;d[u++]=0;d[u++]=n;d[u++]=r;d[u++]=e?0:1;d[u++]=Math.max(0,Math.floor(i??0));d[u++]=c;d[u++]=s.BYTES_PER_ELEMENT;for(const e of t){d[u++]=e.length-2;d[u++]=e[0];d[u++]=e[1]}const p=new CompressionStream("deflate-raw"),g=p.writable.getWriter();await g.ready;g.write(d);const m=s.prototype.constructor;for(const e of t){const t=new m(e.length-2);for(let i=2,n=e.length;i<n;i++)t[i-2]=e[i]-e[i-2];g.write(t)}g.close();return(await new Response(p.readable).bytes()).toBase64()}static async decompressSignature(t){try{const e=Uint8Array.fromBase64(t),{readable:i,writable:n}=new DecompressionStream("deflate-raw"),r=n.getWriter();await r.ready;r.write(e).then(async()=>{await r.ready;await r.close()}).catch(()=>{});let s=null,a=0;for await(const t of i){s||=new Uint8Array(new Uint32Array(t.buffer,0,4)[0]);s.set(t,a);a+=t.length}const o=new Uint32Array(s.buffer,0,s.length>>2),l=o[1];if(0!==l)throw new Error(`Invalid version: ${l}`);const c=o[2],h=o[3],d=0===o[4],u=o[5],p=o[6],g=o[7],m=[],f=(8+3*p)*Uint32Array.BYTES_PER_ELEMENT;let b;switch(g){case Int8Array.BYTES_PER_ELEMENT:b=new Int8Array(s.buffer,f);break;case Int16Array.BYTES_PER_ELEMENT:b=new Int16Array(s.buffer,f);break;case Int32Array.BYTES_PER_ELEMENT:b=new Int32Array(s.buffer,f)}a=0;for(let t=0;t<p;t++){const e=o[3*t+8],i=new Float32Array(e+2);m.push(i);for(let e=0;e<2;e++)i[e]=o[3*t+8+e+1];for(let t=0;t<e;t++)i[t+2]=i[t]+b[a++]}return{areContours:d,thickness:u,outlines:m,width:c,height:h}}catch(t){warn(`decompressSignature: ${t}`);return null}}}class SignatureOptions extends DrawingOptions{constructor(){super();super.updateProperties({fill:AnnotationEditor._defaultLineColor,"stroke-width":0})}clone(){const t=new SignatureOptions;t.updateAll(this);return t}}class DrawnSignatureOptions extends InkDrawingOptions{constructor(t){super(t);super.updateProperties({stroke:AnnotationEditor._defaultLineColor,"stroke-width":1})}clone(){const t=new DrawnSignatureOptions(this._viewParameters);t.updateAll(this);return t}}class SignatureEditor extends DrawingEditor{#zh=!1;#Gh=null;#Wh=null;#jh=null;#Vh=!1;static _type="signature";static _editorType=ki.SIGNATURE;static _defaultDrawingOptions=null;constructor(t){super({...t,mustBeCommitted:!0,name:"signatureEditor"});this._willKeepAspectRatio=!0;this.#Wh=t.signatureData||null;this.#Gh=null;this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(t,e){AnnotationEditor.initialize(t,e);this._defaultDrawingOptions=new SignatureOptions;this._defaultDrawnSignatureOptions=new DrawnSignatureOptions(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();e.updateProperties(t);return e}static get supportMultipleDrawings(){return!1}static get typesMap(){return util_shadow(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!this.#Gh}}static computeTelemetryFinalData(t){const e=t.get("hasDescription");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}get isResizable(){return!0}onceAdded(t){this.#Vh=null===this._drawId;super.onceAdded(t)}onScaleChanging(){null!==this._drawId&&super.onScaleChanging()}render(){if(this.div)return this.div;let t,e;const{_isCopy:i}=this;if(i){this._isCopy=!1;t=this.x;e=this.y}super.render();if(null===this._drawId)if(this.#Wh){const{lines:t,mustSmooth:e,areContours:i,description:n,uuid:r,heightInPage:s}=this.#Wh,{rawDims:{pageWidth:a,pageHeight:o},rotation:l}=this.parent.viewport,c=SignatureExtractor.processDrawnLines({lines:t,pageWidth:a,pageHeight:o,rotation:l,innerMargin:SignatureEditor._INNER_MARGIN,mustSmooth:e,areContours:i});this.addSignature(c,s,n,r)}else{this.div.setAttribute("data-l10n-args",JSON.stringify({description:""}));this.div.hidden=!0;this._uiManager.getSignature(this)}else this.div.setAttribute("data-l10n-args",JSON.stringify({description:this.#Gh||""}));if(i){this._isCopy=!0;this._moveAfterPaste(t,e)}return this.div}setUuid(t){this.#jh=t;this.addEditToolbar()}getUuid(){return this.#jh}get description(){return this.#Gh}set description(t){this.#Gh=t;if(this.div){this.div.setAttribute("data-l10n-args",JSON.stringify({description:t}));super.addEditToolbar().then(e=>{e?.updateEditSignatureButton(t)})}}getSignaturePreview(){const{newCurves:t,areContours:e,thickness:i,width:n,height:r}=this.#Wh,s=Math.max(n,r);return{areContours:e,outline:SignatureExtractor.processDrawnLines({lines:{curves:t.map(t=>({points:t})),thickness:i,width:n,height:r},pageWidth:s,pageHeight:s,rotation:0,innerMargin:0,mustSmooth:!1,areContours:e}).outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(t,e,i,n){const{x:r,y:s}=this,{outline:a}=this.#Wh=t;this.#zh=a instanceof ContourDrawOutline;this.description=i;let o;if(this.#zh)o=SignatureEditor.getDefaultDrawingOptions();else{o=SignatureEditor._defaultDrawnSignatureOptions.clone();o.updateProperties({"stroke-width":a.thickness})}this._addOutlines({drawOutlines:a,drawingOptions:o});const[,l]=this.pageDimensions;let c=e/l;c=c>=1?.5:c;this.width*=c/this.height;if(this.width>=1){c*=.9/this.width;this.width=.9}this.height=c;this.setDims();this.x=r;this.y=s;this.center();this._onResized();this.onScaleChanging();this.rotate();this._uiManager.addToAnnotationStorage(this);this.setUuid(n);this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!n,hasDescription:!!i}});this.div.hidden=!1;if(this.#Vh){this.#Vh=!1;this.parent.addUndoableEditor(this)}}getFromImage(t){const{rawDims:{pageWidth:e,pageHeight:i},rotation:n}=this.parent.viewport;return SignatureExtractor.process(t,e,i,n,SignatureEditor._INNER_MARGIN)}getFromText(t,e){const{rawDims:{pageWidth:i,pageHeight:n},rotation:r}=this.parent.viewport;return SignatureExtractor.extractContoursFromText(t,e,i,n,r,SignatureEditor._INNER_MARGIN)}getDrawnSignature(t){const{rawDims:{pageWidth:e,pageHeight:i},rotation:n}=this.parent.viewport;return SignatureExtractor.processDrawnLines({lines:t,pageWidth:e,pageHeight:i,rotation:n,innerMargin:SignatureEditor._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:t,thickness:e}){if(t)this._drawingOptions=SignatureEditor.getDefaultDrawingOptions();else{this._drawingOptions=SignatureEditor._defaultDrawnSignatureOptions.clone();this._drawingOptions.updateProperties({"stroke-width":e})}}serialize(t=!1){if(this.isEmpty())return null;const{lines:e,points:i}=this.serializeDraw(t),{_drawingOptions:{"stroke-width":n}}=this,r=Object.assign(super.serialize(t),{isSignature:!0,areContours:this.#zh,color:[0,0,0],thickness:this.#zh?0:n});this.addComment(r);if(t){r.paths={lines:e,points:i};r.uuid=this.#jh;r.isCopy=!0}else r.lines=e;this.#Gh&&(r.accessibilityData={type:"Figure",alt:this.#Gh});return r}static deserializeDraw(t,e,i,n,r,s){return s.areContours?ContourDrawOutline.deserialize(t,e,i,n,r,s):InkDrawOutline.deserialize(t,e,i,n,r,s)}static async deserialize(t,e,i){const n=await super.deserialize(t,e,i);n.#zh=t.areContours;n.description=t.accessibilityData?.alt||"";n.#jh=t.uuid;return n}}class StampEditor extends AnnotationEditor{#qh=null;#$h=null;#Xh=null;#Kh=null;#Yh=null;#Jh="";#Es=null;#Qh=!1;#Zh=null;#td=!1;#ed=!1;static _type="stamp";static _editorType=ki.STAMP;constructor(t){super({...t,name:"stampEditor"});this.#Kh=t.bitmapUrl;this.#Yh=t.bitmapFile;this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(t,e){AnnotationEditor.initialize(t,e)}static isHandlingMimeForPasting(t){return an.has(t)}static paste(t,e){e.pasteEditor({mode:ki.STAMP},{bitmapFile:t.getAsFile()})}altTextFinish(){this._uiManager.useNewAltTextFlow&&(this.div.hidden=!1);super.altTextFinish()}get telemetryFinalData(){return{type:"stamp",hasAltText:!!this.altTextData?.altText}}static computeTelemetryFinalData(t){const e=t.get("hasAltText");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}#id(t,e=!1){if(t){this.#qh=t.bitmap;if(!e){this.#$h=t.id;this.#td=t.isSvg}t.file&&(this.#Jh=t.file.name);this.#nd()}else this.remove()}#rd(){this.#Xh=null;this._uiManager.enableWaiting(!1);if(this.#Es)if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#qh)this.addEditToolbar().then(()=>{this._editToolbar.hide();this._uiManager.editAltText(this,!0)});else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#qh){this._reportTelemetry({action:"pdfjs.image.image_added",data:{alt_text_modal:!1,alt_text_type:"empty"}});try{this.mlGuessAltText()}catch{}}this.div.focus()}}async mlGuessAltText(t=null,e=!0){if(this.hasAltTextData())return null;const{mlManager:i}=this._uiManager;if(!i)throw new Error("No ML.");if(!await i.isEnabledFor("altText"))throw new Error("ML isn't enabled for alt text.");const{data:n,width:r,height:s}=t||this.copyCanvas(null,null,!0).imageData,a=await i.guess({name:"altText",request:{data:n,width:r,height:s,channels:n.length/(r*s)}});if(!a)throw new Error("No response from the AI service.");if(a.error)throw new Error("Error from the AI service.");if(a.cancel)return null;if(!a.output)throw new Error("No valid response from the AI service.");const o=a.output;await this.setGuessedAltText(o);e&&!this.hasAltTextData()&&(this.altTextData={alt:o,decorative:!1});return o}#sd(){if(this.#$h){this._uiManager.enableWaiting(!0);this._uiManager.imageManager.getFromId(this.#$h).then(t=>this.#id(t,!0)).finally(()=>this.#rd());return}if(this.#Kh){const t=this.#Kh;this.#Kh=null;this._uiManager.enableWaiting(!0);this.#Xh=this._uiManager.imageManager.getFromUrl(t).then(t=>this.#id(t)).finally(()=>this.#rd());return}if(this.#Yh){const t=this.#Yh;this.#Yh=null;this._uiManager.enableWaiting(!0);this.#Xh=this._uiManager.imageManager.getFromFile(t).then(t=>this.#id(t)).finally(()=>this.#rd());return}const t=document.createElement("input");t.type="file";t.accept=an.keys().join(",");const e=this._uiManager._signal;this.#Xh=new Promise(i=>{t.addEventListener("change",async()=>{if(t.files&&0!==t.files.length){this._uiManager.enableWaiting(!0);const e=await this._uiManager.imageManager.getFromFile(t.files[0]);this._reportTelemetry({action:"pdfjs.image.image_selected",data:{alt_text_modal:this._uiManager.useNewAltTextFlow}});this.#id(e)}else this.remove();i()},{signal:e});t.addEventListener("cancel",()=>{this.remove();i()},{signal:e})}).finally(()=>this.#rd());t.click()}remove(){if(this.#$h){this.#qh=null;this._uiManager.imageManager.deleteId(this.#$h);this.#Es?.remove();this.#Es=null;if(this.#Zh){clearTimeout(this.#Zh);this.#Zh=null}}super.remove()}rebuild(){if(this.parent){super.rebuild();if(null!==this.div){this.#$h&&null===this.#Es&&this.#sd();this.isAttachedToDOM||this.parent.add(this)}}else this.#$h&&this.#sd()}onceAdded(t){this._isDraggable=!0;t&&this.div.focus()}isEmpty(){return!(this.#Xh||this.#qh||this.#Kh||this.#Yh||this.#$h||this.#Qh)}get toolbarButtons(){return[["altText",this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;if(this._isCopy){t=this.x;e=this.y}super.render();this.div.hidden=!0;this.createAltText();this.#Qh||(this.#qh?this.#nd():this.#sd());this._isCopy&&this._moveAfterPaste(t,e);this._uiManager.addShouldRescale(this);return this.div}setCanvas(t,e){const{id:i,bitmap:n}=this._uiManager.imageManager.getFromCanvas(t,e);e.remove();if(i&&this._uiManager.imageManager.isValidId(i)){this.#$h=i;n&&(this.#qh=n);this.#Qh=!1;this.#nd()}}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;null!==this.#Zh&&clearTimeout(this.#Zh);this.#Zh=setTimeout(()=>{this.#Zh=null;this.#ad()},200)}#nd(){const{div:t}=this;let{width:e,height:i}=this.#qh;const[n,r]=this.pageDimensions,s=.75;if(this.width){e=this.width*n;i=this.height*r}else if(e>s*n||i>s*r){const t=Math.min(s*n/e,s*r/i);e*=t;i*=t}this._uiManager.enableWaiting(!1);const a=this.#Es=document.createElement("canvas");a.setAttribute("role","img");this.addContainer(a);this.width=e/n;this.height=i/r;this.setDims();this._initialOptions?.isCentered?this.center():this.fixAndSetPosition();this._initialOptions=null;this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&!this.annotationElementId||(t.hidden=!1);this.#ad();if(!this.#ed){this.parent.addUndoableEditor(this);this.#ed=!0}this._reportTelemetry({action:"inserted_image"});this.#Jh&&this.div.setAttribute("aria-description",this.#Jh);this.annotationElementId||this._uiManager.a11yAlert(AnnotationEditor._l10nAlert.stamp)}copyCanvas(t,e,i=!1){t||=224;const{width:n,height:r}=this.#qh,s=new OutputScale;let a=this.#qh,o=n,l=r,c=null;if(e){if(n>e||r>e){const t=Math.min(e/n,e/r);o=Math.floor(n*t);l=Math.floor(r*t)}c=document.createElement("canvas");const t=c.width=Math.ceil(o*s.sx),i=c.height=Math.ceil(l*s.sy);this.#td||(a=this.#od(t,i));const h=c.getContext("2d");h.filter=this._uiManager.hcmFilter;let d="white",u="#cfcfd8";if("none"!==this._uiManager.hcmFilter)u="black";else if(ColorScheme.isDarkMode){d="#8f8f9d";u="#42414d"}const p=15,g=p*s.sx,m=p*s.sy,f=new OffscreenCanvas(2*g,2*m),b=f.getContext("2d");b.fillStyle=d;b.fillRect(0,0,2*g,2*m);b.fillStyle=u;b.fillRect(0,0,g,m);b.fillRect(g,m,g,m);h.fillStyle=h.createPattern(f,"repeat");h.fillRect(0,0,t,i);h.drawImage(a,0,0,a.width,a.height,0,0,t,i)}let h=null;if(i){let e,i;if(s.symmetric&&a.width<t&&a.height<t){e=a.width;i=a.height}else{a=this.#qh;if(n>t||r>t){const s=Math.min(t/n,t/r);e=Math.floor(n*s);i=Math.floor(r*s);this.#td||(a=this.#od(e,i))}}const o=new OffscreenCanvas(e,i).getContext("2d",{willReadFrequently:!0});o.drawImage(a,0,0,a.width,a.height,0,0,e,i);h={width:e,height:i,data:o.getImageData(0,0,e,i).data}}return{canvas:c,width:o,height:l,imageData:h}}#od(t,e){const{width:i,height:n}=this.#qh;let r=i,s=n,a=this.#qh;for(;r>2*t||s>2*e;){const i=r,n=s;r>2*t&&(r=Math.ceil(r/2));s>2*e&&(s=Math.ceil(s/2));const o=new OffscreenCanvas(r,s);o.getContext("2d").drawImage(a,0,0,i,n,0,0,r,s);a=o.transferToImageBitmap()}return a}#ad(){const[t,e]=this.parentDimensions,{width:i,height:n}=this,r=new OutputScale,s=Math.ceil(i*t*r.sx),a=Math.ceil(n*e*r.sy),o=this.#Es;if(!o||o.width===s&&o.height===a)return;o.width=s;o.height=a;const l=this.#td?this.#qh:this.#od(s,a),c=o.getContext("2d");c.filter=this._uiManager.hcmFilter;c.drawImage(l,0,0,l.width,l.height,0,0,s,a)}#ld(t){if(t){if(this.#td){const t=this._uiManager.imageManager.getSvgUrl(this.#$h);if(t)return t}const t=document.createElement("canvas");({width:t.width,height:t.height}=this.#qh);t.getContext("2d").drawImage(this.#qh,0,0);return t.toDataURL()}if(this.#td){const[t,e]=this.pageDimensions,i=Math.round(this.width*t*PixelsPerInch.PDF_TO_CSS_UNITS),n=Math.round(this.height*e*PixelsPerInch.PDF_TO_CSS_UNITS),r=new OffscreenCanvas(i,n);r.getContext("2d").drawImage(this.#qh,0,0,this.#qh.width,this.#qh.height,0,0,i,n);return r.transferToImageBitmap()}return structuredClone(this.#qh)}static async deserialize(t,e,i){let n=null,r=!1;if(t instanceof StampAnnotationElement){const{data:{rect:s,rotation:a,id:o,structParent:l,popupRef:c,richText:h,contentsObj:d,creationDate:u,modificationDate:p},container:g,parent:{page:{pageNumber:m}},canvas:f}=t;let b,y;if(f){delete t.canvas;({id:b,bitmap:y}=i.imageManager.getFromCanvas(g.id,f));f.remove()}else{r=!0;t._hasNoCanvas=!0}const w=(await e._structTree.getAriaAttributes(`${Si}${o}`))?.get("aria-label")||"";n=t={annotationType:ki.STAMP,bitmapId:b,bitmap:y,pageIndex:m-1,rect:s.slice(0),rotation:a,annotationElementId:o,id:o,deleted:!1,accessibilityData:{decorative:!1,altText:w},isSvg:!1,structParent:l,popupRef:c,richText:h,comment:d?.str||null,creationDate:u,modificationDate:p}}const s=await super.deserialize(t,e,i),{rect:a,bitmap:o,bitmapUrl:l,bitmapId:c,isSvg:h,accessibilityData:d}=t;if(r){i.addMissingCanvas(t.id,s);s.#Qh=!0}else if(c&&i.imageManager.isValidId(c)){s.#$h=c;o&&(s.#qh=o)}else s.#Kh=l;s.#td=h;const[u,p]=s.pageDimensions;s.width=(a[2]-a[0])/u;s.height=(a[3]-a[1])/p;d&&(s.altTextData=d);s._initialData=n;t.comment&&s.setCommentData(t);s.#ed=!!n;return s}serialize(t=!1,e=null){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const i=Object.assign(super.serialize(t),{bitmapId:this.#$h,isSvg:this.#td});this.addComment(i);if(t){i.bitmapUrl=this.#ld(!0);i.accessibilityData=this.serializeAltText(!0);i.isCopy=!0;return i}const{decorative:n,altText:r}=this.serializeAltText(!1);!n&&r&&(i.accessibilityData={type:"Figure",alt:r});if(this.annotationElementId){const t=this.#Ol(i);if(t.isSame)return null;if(t.isSameAltText)delete i.accessibilityData;else{const t=this._initialData.structParent??-1;i.accessibilityData?i.accessibilityData.structParent=t:t>=0&&(i.accessibilityData={type:"Figure",alt:"",structParent:t})}i.id=this.annotationElementId;delete i.bitmapId;return i}if(null===e)return i;e.stamps||=new Map;const s=this.#td?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(e.stamps.has(this.#$h)){if(this.#td){const t=e.stamps.get(this.#$h);if(s>t.area){t.area=s;t.serialized.bitmap.close();t.serialized.bitmap=this.#ld(!1)}}}else{e.stamps.set(this.#$h,{area:s,serialized:i});i.bitmap=this.#ld(!1)}return i}#Ol(t){const{pageIndex:e,accessibilityData:{altText:i}}=this._initialData,n=t.pageIndex===e,r=(t.accessibilityData?.alt||"")===i;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&n&&r,isSameAltText:r}}renderAnnotationElement(t){if(this.deleted){t.hide();return null}t.updateEdited({rect:this.getPDFRect(),popup:this.comment});return null}}class AnnotationEditorLayer{#bl;#cd=!1;#hd=null;#dd=null;#ud=null;#pd=new Map;#gd=!1;#md=!1;#fd=!1;#bd=null;#yd=null;#wd=null;#vd=null;#_d=null;#Ad=-1;#y;static _initialized=!1;static#Z=new Map([FreeTextEditor,InkEditor,StampEditor,HighlightEditor,SignatureEditor].map(t=>[t._editorType,t]));constructor({uiManager:t,pageIndex:e,div:i,structTreeLayer:n,accessibilityManager:r,annotationLayer:s,drawLayer:a,textLayer:o,viewport:l,l10n:c}){const h=[...AnnotationEditorLayer.#Z.values()];if(!AnnotationEditorLayer._initialized){AnnotationEditorLayer._initialized=!0;for(const e of h)e.initialize(c,t)}t.registerEditorTypes(h);this.#y=t;this.pageIndex=e;this.div=i;this.#bl=r;this.#hd=s;this.viewport=l;this.#wd=o;this.drawLayer=a;this._structTree=n;this.#y.addLayer(this)}get isEmpty(){return 0===this.#pd.size}get isInvisible(){return this.isEmpty&&this.#y.getMode()===ki.NONE}updateToolbar(t){this.#y.updateToolbar(t)}updateMode(t=this.#y.getMode()){this.#xd();switch(t){case ki.NONE:this.div.classList.toggle("nonEditing",!0);this.disableTextSelection();this.togglePointerEvents(!1);this.toggleAnnotationLayerPointerEvents(!0);this.disableClick();return;case ki.INK:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick();break;case ki.HIGHLIGHT:this.enableTextSelection();this.togglePointerEvents(!1);this.disableClick();break;default:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick()}this.toggleAnnotationLayerPointerEvents(!1);const{classList:e}=this.div;e.toggle("nonEditing",!1);if(t===ki.POPUP)e.toggle("commentEditing",!0);else{e.toggle("commentEditing",!1);for(const i of AnnotationEditorLayer.#Z.values())e.toggle(`${i._type}Editing`,t===i._editorType)}this.div.hidden=!1}hasTextLayer(t){return t===this.#wd?.div}setEditingState(t){this.#y.setEditingState(t)}addCommands(t){this.#y.addCommands(t)}cleanUndoStack(t){this.#y.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#hd?.togglePointerEvents(t)}get#Cd(){return 0!==this.#pd.size?this.#pd.values():this.#y.getEditors(this.pageIndex)}async enable(){this.#fd=!0;this.div.tabIndex=0;this.togglePointerEvents(!0);this.div.classList.toggle("nonEditing",!1);this.#_d?.abort();this.#_d=null;const t=new Set;for(const e of this.#Cd){e.enableEditing();e.show(!0);if(e.annotationElementId){this.#y.removeChangedExistingAnnotation(e);t.add(e.annotationElementId)}}const e=this.#hd;if(e)for(const i of e.getEditableAnnotations()){i.hide();if(this.#y.isDeletedAnnotationElement(i.data.id)||t.has(i.data.id))continue;const e=await this.deserialize(i);if(e){this.addOrRebuild(e);e.enableEditing()}}this.#fd=!1;this.#y._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){this.#md=!0;this.div.tabIndex=-1;this.togglePointerEvents(!1);this.div.classList.toggle("nonEditing",!0);if(this.#wd&&!this.#_d){this.#_d=new AbortController;const t=this.#y.combinedSignal(this.#_d);this.#wd.div.addEventListener("pointerdown",t=>{const{clientX:e,clientY:i,timeStamp:n}=t;if(n-this.#Ad>500){this.#Ad=n;return}this.#Ad=-1;const{classList:r}=this.div;r.toggle("getElements",!0);const s=document.elementsFromPoint(e,i);r.toggle("getElements",!1);if(!this.div.contains(s[0]))return;let a;const o=new RegExp(`^${Ti}[0-9]+$`);for(const t of s)if(o.test(t.id)){a=t.id;break}if(!a)return;const l=this.#pd.get(a);if(null===l?.annotationElementId){stopEvent(t);l.dblclick(t)}},{signal:t,capture:!0})}const t=this.#hd,e=[];if(t){const i=new Map,n=new Map;for(const t of this.#Cd){t.disableEditing();if(t.annotationElementId)if(null===t.serialize()){n.set(t.annotationElementId,t);this.getEditableAnnotation(t.annotationElementId)?.show();t.remove()}else i.set(t.annotationElementId,t);else e.push(t)}for(const e of t.getEditableAnnotations()){const{id:t}=e.data;if(this.#y.isDeletedAnnotationElement(t)){e.updateEdited({deleted:!0});continue}let r=n.get(t);if(r){r.resetAnnotationElement(e);r.show(!1);e.show()}else{r=i.get(t);if(r){this.#y.addChangedExistingAnnotation(r);r.renderAnnotationElement(e)&&r.show(!1)}e.show()}}}this.#xd();this.isEmpty&&(this.div.hidden=!0);const{classList:i}=this.div;for(const t of AnnotationEditorLayer.#Z.values())i.remove(`${t._type}Editing`);this.disableTextSelection();this.toggleAnnotationLayerPointerEvents(!0);t?.updateFakeAnnotations(e);this.#md=!1}getEditableAnnotation(t){return this.#hd?.getEditableAnnotation(t)||null}setActiveEditor(t){this.#y.getActive()!==t&&this.#y.setActiveEditor(t)}enableTextSelection(){this.div.tabIndex=-1;if(this.#wd?.div&&!this.#vd){this.#vd=new AbortController;const t=this.#y.combinedSignal(this.#vd);this.#wd.div.addEventListener("pointerdown",this.#Ed.bind(this),{signal:t});this.#wd.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0;if(this.#wd?.div&&this.#vd){this.#vd.abort();this.#vd=null;this.#wd.div.classList.remove("highlighting")}}#Ed(t){this.#y.unselectAll();const{target:e}=t;if(e===this.#wd.div||("img"===e.getAttribute("role")||e.classList.contains("endOfContent")||e.classList.contains("textLayerImages")||e.classList.contains("textLayerImagePlaceholder"))&&this.#wd.div.contains(e)){const{isMac:e}=FeatureTest.platform;if(0!==t.button||t.ctrlKey&&e)return;this.#y.showAllEditors("highlight",!0,!0);HighlightEditor.startDrawing(this,this.#y,"ltr"===this.#y.direction,t);t.preventDefault()}}enableClick(){if(this.#dd)return;this.#dd=new AbortController;const t=this.#y.combinedSignal(this.#dd);this.div.addEventListener("pointerdown",this.pointerdown.bind(this),{signal:t});const e=this.pointerup.bind(this);this.div.addEventListener("pointerup",e,{signal:t});this.div.addEventListener("pointercancel",e,{signal:t})}disableClick(){this.#dd?.abort();this.#dd=null}attach(t){this.#pd.set(t.id,t);const{annotationElementId:e}=t;e&&this.#y.isDeletedAnnotationElement(e)&&this.#y.removeDeletedAnnotationElement(t)}detach(t){this.#pd.delete(t.id);this.#bl?.removePointerInTextLayer(t.contentDiv);!this.#md&&t.annotationElementId&&this.#y.addDeletedAnnotationElement(t)}remove(t){this.detach(t);this.#y.removeEditor(t);t.div.remove();t.isAttachedToDOM=!1}changeParent(t){if(t.parent!==this){if(t.parent&&t.annotationElementId){this.#y.addDeletedAnnotationElement(t);AnnotationEditor.deleteAnnotationElement(t);t.annotationElementId=null}this.attach(t);t.parent?.detach(t);t.setParent(this);if(t.div&&t.isAttachedToDOM){t.div.remove();this.div.append(t.div)}}}add(t){if(t.parent!==this||!t.isAttachedToDOM){this.changeParent(t);this.#y.addEditor(t);this.attach(t);if(!t.isAttachedToDOM){const e=t.render();this.div.append(e);t.isAttachedToDOM=!0}t.fixAndSetPosition();t.onceAdded(!this.#fd);this.#y.addToAnnotationStorage(t);t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;const{activeElement:e}=document;if(t.div.contains(e)&&!this.#ud){t._focusEventsAllowed=!1;this.#ud=setTimeout(()=>{this.#ud=null;if(t.div.contains(document.activeElement))t._focusEventsAllowed=!0;else{t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this.#y._signal});e.focus()}},0)}t._structTreeParentId=this.#bl?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){if(t.needsToBeRebuilt()){t.parent||=this;t.rebuild();t.show()}else this.add(t)}addUndoableEditor(t){this.addCommands({cmd:()=>t._uiManager.rebuild(t),undo:()=>{t.remove()},mustExec:!1})}getEditorByUID(t){for(const e of this.#pd.values())if(e.uid===t)return e;return null}get#Sd(){return AnnotationEditorLayer.#Z.get(this.#y.getMode())}combinedSignal(t){return this.#y.combinedSignal(t)}#Td(t){const e=this.#Sd;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#Sd?.canCreateNewEmptyEditor()}async pasteEditor(t,e){this.updateToolbar(t);await this.#y.updateMode(t.mode);const{offsetX:i,offsetY:n}=this.#kd(),r=this.#y.getId(),s=this.#Td({parent:this,id:r,x:i,y:n,uiManager:this.#y,isCentered:!0,...e});s&&this.add(s)}async deserialize(t){return await(AnnotationEditorLayer.#Z.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#y))||null}createAndAddNewEditor(t,e,i={}){const n=this.#y.getId(),r=this.#Td({parent:this,id:n,x:t.offsetX,y:t.offsetY,uiManager:this.#y,isCentered:e,...i});r&&this.add(r);return r}get boundingClientRect(){return this.div.getBoundingClientRect()}#kd(){const{x:t,y:e,width:i,height:n}=this.boundingClientRect,r=Math.max(0,t),s=Math.max(0,e),a=(r+Math.min(window.innerWidth,t+i))/2-t,o=(s+Math.min(window.innerHeight,e+n))/2-e,[l,c]=this.viewport.rotation%180==0?[a,o]:[o,a];return{offsetX:l,offsetY:c}}addNewEditor(t={}){this.createAndAddNewEditor(this.#kd(),!0,t)}setSelected(t){this.#y.setSelected(t)}toggleSelected(t){this.#y.toggleSelected(t)}unselect(t){this.#y.unselect(t)}pointerup(t){const{isMac:e}=FeatureTest.platform;if(0!==t.button||t.ctrlKey&&e)return;if(t.target!==this.div)return;if(!this.#gd)return;this.#gd=!1;if(this.#Sd?.isDrawer&&this.#Sd.supportMultipleDrawings)return;if(!this.#cd){this.#cd=!0;return}const i=this.#y.getMode();i!==ki.STAMP&&i!==ki.POPUP&&i!==ki.SIGNATURE?this.createAndAddNewEditor(t,!1):this.#y.unselectAll()}pointerdown(t){this.#y.getMode()===ki.HIGHLIGHT&&this.enableTextSelection();if(this.#gd){this.#gd=!1;return}const{isMac:e}=FeatureTest.platform;if(0!==t.button||t.ctrlKey&&e)return;if(t.target!==this.div)return;this.#gd=!0;if(this.#Sd?.isDrawer){this.startDrawingSession(t);return}const i=this.#y.getActive();this.#cd=!i||i.isEmpty()}startDrawingSession(t){this.div.focus({preventScroll:!0});if(this.#bd){this.#Sd.startDrawing(this,this.#y,!1,t);return}this.#y.setCurrentDrawingSession(this);this.#bd=new AbortController;const e=this.#y.combinedSignal(this.#bd);this.div.addEventListener("blur",({relatedTarget:t})=>{if(t&&!this.div.contains(t)){this.#yd=null;this.commitOrRemove()}},{signal:e});this.#Sd.startDrawing(this,this.#y,!1,t)}pause(t){if(t){const{activeElement:t}=document;this.div.contains(t)&&(this.#yd=t);return}this.#yd&&setTimeout(()=>{this.#yd?.focus();this.#yd=null},0)}endDrawingSession(t=!1){if(!this.#bd)return null;this.#y.setCurrentDrawingSession(null);this.#bd.abort();this.#bd=null;this.#yd=null;return this.#Sd.endDrawing(t)}findNewParent(t,e,i){const n=this.#y.findParent(e,i);if(null===n||n===this)return!1;n.changeParent(t);return!0}commitOrRemove(){if(this.#bd){this.endDrawingSession();return!0}return!1}onScaleChanging(){this.#bd&&this.#Sd.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove();if(this.#y.getActive()?.parent===this){this.#y.commitOrRemove();this.#y.setActiveEditor(null)}if(this.#ud){clearTimeout(this.#ud);this.#ud=null}for(const t of this.#pd.values()){this.#bl?.removePointerInTextLayer(t.contentDiv);t.setParent(null);t.isAttachedToDOM=!1;t.div.remove()}this.div=null;this.#pd.clear();this.#y.removeLayer(this)}#xd(){for(const t of this.#pd.values())t.isEmpty()&&t.remove()}async render({viewport:t}){this.viewport=t;setLayerDimensions(this.div,t);for(const t of this.#y.getEditors(this.pageIndex)){this.add(t);t.rebuild()}await this.#y.findClonesForPage(this);this.div.hidden=this.isEmpty;this.updateMode()}update({viewport:t}){this.#y.commitOrRemove();this.#xd();const e=this.viewport.rotation,i=t.rotation;this.viewport=t;setLayerDimensions(this.div,{rotation:i});if(e!==i)for(const t of this.#pd.values())t.rotate(i)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#y.viewParameters.realScale}}Ge();function compareTextLayers(t,e){return t===e?0:t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1}function getTextLayer(t){return t?t.nodeType===Node.ELEMENT_NODE?t.closest(".textLayer"):t.parentElement?.closest(".textLayer")||null:null}function isPointBefore(t,e,i,n){if(t===i)return e<=n;const r=t.compareDocumentPosition(i);return!!(r&Node.DOCUMENT_POSITION_FOLLOWING)||!(r&Node.DOCUMENT_POSITION_PRECEDING)&&null}function normalizeEdgeBoundary(t,e,i){if(t.nodeType!==Node.ELEMENT_NODE||!t.classList.contains("textLayer")||e!==t.childNodes.length)return{container:t,offset:e};let n=t.lastChild;n?.nodeType===Node.ELEMENT_NODE&&n.classList.contains("endOfContent")&&(n=n.previousSibling);return n&&i.contains(n)?n.nodeType===Node.TEXT_NODE?{container:n,offset:n.textContent.length}:{container:n,offset:n.childNodes.length}:null}class DrawLayer{#Lo=null;#Pd=new Map;#wd=null;#rt=null;#xt=null;#Md=null;#Dd=new Map;static#S=0;static#Id=0;static#Fd=null;static#Od=new Set;static#Rd=!1;static#Bd=new Set;static#Ld=new WeakMap;constructor({filterFactory:t=null,pageColors:e=null,pageIndex:i,textLayer:n=null}){this.pageIndex=i;this.#rt=t;this.#xt=e;if(n){const t=DrawLayer.#Ld.get(n);if(t?.selectionDiv){t.selectionDiv.remove();DrawLayer.#Od.delete(t.selectionDiv)}DrawLayer.#Ld.set(n,{drawLayer:this});DrawLayer.#Bd.add(n);this.#wd=n;this.#Md=new MutationObserver(t=>{if(this.#Lo&&this.#wd?.isConnected&&DrawLayer.#Nd())for(const{addedNodes:e}of t)for(const t of e)if(t.nodeType===Node.ELEMENT_NODE&&t.classList.contains("endOfContent")){DrawLayer.#Ut();return}});this.#Md.observe(n,{childList:!0});if(null===DrawLayer.#Fd){DrawLayer.#Fd=new AbortController;const{signal:t}=DrawLayer.#Fd;document.addEventListener("selectionchange",DrawLayer.#Ut.bind(DrawLayer),{signal:t});document.addEventListener("pointerdown",()=>{DrawLayer.#Rd=!0},{signal:t});document.addEventListener("pointerup",()=>{DrawLayer.#Rd=!1},{signal:t});window.addEventListener("blur",()=>{DrawLayer.#Rd=!1},{signal:t})}}}setParent(t){if(this.#Lo){if(this.#Lo!==t){if(this.#Pd.size>0)for(const e of this.#Pd.values()){e.remove();t.append(e)}this.#Lo=t}}else{this.#Lo=t;this.#wd?.isConnected&&DrawLayer.#Nd()&&DrawLayer.#Ut()}}static#Ud(t){const e=this.#Ld.get(t);if(e?.selectionDiv){e.selectionDiv.remove();this.#Od.delete(e.selectionDiv);e.selectionDiv=null;e.path=null}}static#Nd(){const t=document.getSelection();return!!t&&!t.isCollapsed}static#Hd(){return this.#Bd.keys().filter(t=>t.isConnected).toArray().sort(compareTextLayers)}static#Ut(){const t=document.getSelection();if(!t||t.isCollapsed){for(const t of this.#Od)t.remove();this.#Od.clear();return}const e=new WeakMap,i=this.#Hd(),n=[];for(let e=0,r=t.rangeCount;e<r;e++){const r=t.getRangeAt(e);if(r.collapsed)continue;let{startContainer:s,startOffset:a,endContainer:o,endOffset:l}=r,c=getTextLayer(s),h=getTextLayer(o);const d=null===c,u=null===h;if(this.#Rd&&d!==u)return;if(1===t.rangeCount){const{anchorNode:e,anchorOffset:i,focusNode:n,focusOffset:r}=t,d=getTextLayer(e),u=getTextLayer(n),p=isPointBefore(e,i,n,r);if(d&&u&&null!==p)if(p){s=e;a=i;c=d;o=n;l=r;h=u}else{s=n;a=r;c=u;o=e;l=i;h=d}}const p=i.filter(t=>r.intersectsNode(t));if(0===p.length)continue;let g=!1;if(!c){c=p[0];s=c;a=0;g=!0}if(!h){h=p.at(-1);o=h;l=h.childNodes.length;g=!0}if(o.nodeType===Node.ELEMENT_NODE)if(o.classList.contains("endOfContent")){const t=o.previousSibling;if(!t)continue;o=t;l=t.nodeType===Node.TEXT_NODE?t.textContent.length:t.childNodes.length}else if(o.classList.contains("textLayer")&&o.childNodes.length===l){const t=normalizeEdgeBoundary(o,l,h);if(!t)continue;o=t.container;l=t.offset}if(s.nodeType===Node.ELEMENT_NODE){const t=normalizeEdgeBoundary(s,a,c);if(!t)continue;s=t.container;a=t.offset}if(c!==h||g||!p.includes(c))for(const t of p){const e=t.firstChild;if(!e)continue;const i=document.createRange();t===c?i.setStart(s,a):i.setStartBefore(e);if(t===h)i.setEnd(o,l);else{const e=t.lastChild;if(!e)continue;if(e.nodeType===Node.ELEMENT_NODE&&e.classList.contains("endOfContent")){const t=e.previousSibling;if(!t)continue;i.setEndAfter(t)}else i.setEndAfter(e)}i.collapsed||n.push([i,t])}else n.push([r,c])}const r=new Set(n.map(t=>t[1]));for(const t of this.#Bd)r.has(t)||this.#Ud(t);for(const[t,i]of n){const n=DrawLayer.#Ld.get(i);if(!n)continue;let r=e.get(i);if(!r){const t=i.getBoundingClientRect();r=(e,i,n,r)=>({x:(e-t.x)/t.width,y:(i-t.y)/t.height,width:n/t.width,height:r/t.height});e.set(i,r)}const s=[];for(let{x:e,y:i,width:n,height:a}of t.getClientRects())if(0!==n&&0!==a){({x:e,y:i,width:n,height:a}=r(e,i,n,a));1===n&&1===a||s.push(`M${e} ${i} h${n} v${a} h-${n} Z`)}if(0===s.length)continue;const a=n.drawLayer;let o=n.selectionDiv,l=n.path;if(!o){const t="clip_selection_"+DrawLayer.#Id++;o=document.createElement("div");o.className="selection";o.style.clipPath=`url(#${t})`;const e=a.#rt?.createSelectionStyle(a.#xt);if(e)for(const[t,i]of Object.entries(e))o.style.setProperty(t,i);const i=DrawLayer._svgFactory.create(1,1,!0);i.setAttribute("aria-hidden","true");i.setAttribute("width","100%");i.setAttribute("height","100%");const r=DrawLayer._svgFactory.createElement("clipPath");r.setAttribute("id",t);r.setAttribute("clipPathUnits","objectBoundingBox");l=DrawLayer._svgFactory.createElement("path");r.append(l);i.append(r);o.append(i);n.path=l;n.selectionDiv=o}if(a.#Lo&&o.parentNode!==a.#Lo){a.#Lo.append(o);this.#Od.add(o)}l.setAttribute("d",s.join(" "))}}static get _svgFactory(){return util_shadow(this,"_svgFactory",new DOMSVGFactory)}static#zd(t,[e,i,n,r]){const{style:s}=t;s.top=100*i+"%";s.left=100*e+"%";s.width=100*n+"%";s.height=100*r+"%"}#Gd(){const t=DrawLayer._svgFactory.create(1,1,!0);this.#Lo.append(t);t.setAttribute("aria-hidden","true");return t}#Wd(t,e){const i=DrawLayer._svgFactory.createElement("clipPath");t.append(i);const n=`clip_${e}`;i.setAttribute("id",n);i.setAttribute("clipPathUnits","objectBoundingBox");const r=DrawLayer._svgFactory.createElement("use");i.append(r);r.setAttribute("href",`#${e}`);r.classList.add("clip");return n}#jd(t,e){for(const[i,n]of Object.entries(e))null===n?t.removeAttribute(i):t.setAttribute(i,n)}draw(t,e=!1,i=!1){const n=DrawLayer.#S++,r=this.#Gd(),s=DrawLayer._svgFactory.createElement("defs");r.append(s);const a=DrawLayer._svgFactory.createElement("path");s.append(a);const o=`path_${n}`;a.setAttribute("id",o);a.setAttribute("vector-effect","non-scaling-stroke");e&&this.#Dd.set(n,a);const l=i?this.#Wd(s,o):null,c=DrawLayer._svgFactory.createElement("use");r.append(c);c.setAttribute("href",`#${o}`);this.updateProperties(r,t);this.#Pd.set(n,r);return{id:n,clipPathId:`url(#${l})`}}drawOutline(t,e){const i=DrawLayer.#S++,n=this.#Gd(),r=DrawLayer._svgFactory.createElement("defs");n.append(r);const s=DrawLayer._svgFactory.createElement("path");r.append(s);const a=`path_${i}`;s.setAttribute("id",a);s.setAttribute("vector-effect","non-scaling-stroke");let o;if(e){const t=DrawLayer._svgFactory.createElement("mask");r.append(t);o=`mask_${i}`;t.setAttribute("id",o);t.setAttribute("maskUnits","objectBoundingBox");const e=DrawLayer._svgFactory.createElement("rect");t.append(e);e.setAttribute("width","1");e.setAttribute("height","1");e.setAttribute("fill","white");const n=DrawLayer._svgFactory.createElement("use");t.append(n);n.setAttribute("href",`#${a}`);n.setAttribute("stroke","none");n.setAttribute("fill","black");n.setAttribute("fill-rule","nonzero");n.classList.add("mask")}const l=DrawLayer._svgFactory.createElement("use");n.append(l);l.setAttribute("href",`#${a}`);o&&l.setAttribute("mask",`url(#${o})`);const c=l.cloneNode();n.append(c);l.classList.add("mainOutline");c.classList.add("secondaryOutline");this.updateProperties(n,t);this.#Pd.set(i,n);return i}finalizeDraw(t,e){this.#Dd.delete(t);this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;const{root:i,bbox:n,rootClass:r,path:s}=e,a="number"==typeof t?this.#Pd.get(t):t;if(a){i&&this.#jd(a,i);n&&DrawLayer.#zd(a,n);if(r){const{classList:t}=a;for(const[e,i]of Object.entries(r))t.toggle(e,i)}if(s){const t=a.firstElementChild.firstElementChild;this.#jd(t,s)}}}updateParent(t,e){if(e===this)return;const i=this.#Pd.get(t);if(i){e.#Lo.append(i);this.#Pd.delete(t);e.#Pd.set(t,i)}}remove(t){this.#Dd.delete(t);if(null!==this.#Lo){this.#Pd.get(t).remove();this.#Pd.delete(t)}}destroy(){this.#Lo=null;for(const t of this.#Pd.values())t.remove();this.#Pd.clear();this.#Dd.clear();this.#Md?.disconnect();this.#Md=null;if(this.#wd){const t=DrawLayer.#Ld.get(this.#wd);if(t?.drawLayer===this){DrawLayer.#Ud(this.#wd);DrawLayer.#Ld.delete(this.#wd);DrawLayer.#Bd.delete(this.#wd);if(0===DrawLayer.#Bd.size){DrawLayer.#Fd?.abort();DrawLayer.#Fd=null;DrawLayer.#Rd=!1}}this.#wd=null}}}function percentage(t){return`${(100*t).toFixed(2)}%`}class TextLayerImages{#Vd=[];#qd=new Map;#$d=null;#Xd=0;#oa=0;#aa=0;static#Kd=null;constructor(t,e,i,n){this.#Xd=t;this.#Vd=e;this.#oa=i.rawDims.pageWidth;this.#aa=i.rawDims.pageHeight;this.#$d=n}render(){const t=document.createElement("div");t.className="textLayerImages";for(let e=0;e<this.#Vd.length;e+=6){const i=this.#Yd(this.#Vd.subarray(e,e+6));i&&t.append(i)}t.addEventListener("contextmenu",t=>{if(!(t.target instanceof HTMLCanvasElement))return;const e=t.target,i=this.#qd.get(e);if(!i)return;const n=TextLayerImages.#Kd?.deref();if(n===e)return;if(n){n.width=0;n.height=0}TextLayerImages.#Kd=new WeakRef(e);const{inverseTransform:r,x1:s,y1:a,width:o,height:l}=i,c=this.#$d(),h=Math.ceil(s*c.width),d=Math.ceil(a*c.height),u=Math.floor((s+o/this.#oa)*c.width),p=Math.floor((a+l/this.#aa)*c.height);e.width=u-h;e.height=p-d;const g=e.getContext("2d");g.setTransform(...r);g.translate(-h,-d);g.drawImage(c,0,0)});return t}#Yd([t,e,i,n,r,s]){const a=Math.hypot((r-t)*this.#oa,(s-e)*this.#aa),o=Math.hypot((i-t)*this.#oa,(n-e)*this.#aa);if(a<this.#Xd||o<this.#Xd)return null;const l=[(r-t)*this.#oa/a,(s-e)*this.#aa/a,(i-t)*this.#oa/o,(n-e)*this.#aa/o,0,0],c=Util.inverseTransform(l),h=document.createElement("canvas");h.className="textLayerImagePlaceholder";h.width=0;h.height=0;Object.assign(h.style,{opacity:0,position:"absolute",left:percentage(t),top:percentage(e),width:percentage(a/this.#oa),height:percentage(o/this.#aa),transformOrigin:"0% 0%",transform:`matrix(${l.join(",")})`});this.#qd.set(h,{inverseTransform:c,width:a,height:o,x1:t,y1:e});return h}}globalThis._pdfjsTestingUtils={HighlightOutliner};globalThis.pdfjsLib={AbortException,AnnotationEditorLayer,AnnotationEditorParamsType:Pi,AnnotationEditorType:ki,AnnotationEditorUIManager,AnnotationLayer,AnnotationMode:Ei,AnnotationType:Ni,applyOpacity,build:Jn,ColorPicker,createValidAbsoluteUrl,CSSConstants,DOMSVGFactory,DrawLayer,FeatureTest,fetchData,findContrastColor,getDocument,getFilenameFromUrl,getPdfFilenameFromUrl,getRGB,getRGBA,getUuid,GlobalWorkerOptions,ImageKind:Li,InvalidPDFException,isDataScheme,isPdfFile,isValidExplicitDest:pn,makeArr,makeMap,makeObj,makeSet,MathClamp,noContextMenu,normalizeUnicode,OPS:Vi,OutputScale,PasswordException,PasswordResponses:Ji,PDFDataRangeTransport,PDFDateString,PDFWorker,PermissionFlag:Mi,PixelsPerInch,RenderingCancelledException,renderRichText,ResponseException,setLayerDimensions,shadow:util_shadow,SignatureExtractor,stopEvent,SupportedImageMimeTypes:an,TextLayer,TextLayerImages,TouchManager,updateUrlHash,Util,VerbosityLevel:ji,version:Yn,XfaLayer};export{AbortException,AnnotationEditorLayer,Pi as AnnotationEditorParamsType,ki as AnnotationEditorType,AnnotationEditorUIManager,AnnotationLayer,Ei as AnnotationMode,Ni as AnnotationType,CSSConstants,ColorPicker,DOMSVGFactory,DrawLayer,FeatureTest,GlobalWorkerOptions,Li as ImageKind,InvalidPDFException,MathClamp,Vi as OPS,OutputScale,PDFDataRangeTransport,PDFDateString,PDFWorker,PasswordException,Ji as PasswordResponses,Mi as PermissionFlag,PixelsPerInch,RenderingCancelledException,ResponseException,SignatureExtractor,an as SupportedImageMimeTypes,TextLayer,TextLayerImages,TouchManager,Util,ji as VerbosityLevel,XfaLayer,applyOpacity,Jn as build,createValidAbsoluteUrl,fetchData,findContrastColor,getDocument,getFilenameFromUrl,getPdfFilenameFromUrl,getRGB,getRGBA,getUuid,isDataScheme,isPdfFile,pn as isValidExplicitDest,makeArr,makeMap,makeObj,makeSet,noContextMenu,normalizeUnicode,renderRichText,setLayerDimensions,util_shadow as shadow,stopEvent,updateUrlHash,Yn as version};