FastAPI backend (Python 3.11, MSSQL ODBC for SambaPOS, Azure DI OCR),
kitchen_db on central PG. React/TS/Vite frontend with navy sidebar layout.
Backend: auth.py (APP_SLUG=kitchen, SimpleNamespace — archive routes use
.kitchen_id/.is_admin without modification), main.py (51 migrations, scheduler,
internal router for KDS bookings feed), api/internal.py, full archive API
(31 routers: invoices, recipes, menus, sambapos, resos, newbook, disputes,
purchase_orders, etc.), models, migrations, OCR pipeline.
kitchen_id pinned to 1 (B1 — single hotel).
Frontend: AuthGate (app=kitchen, token shim for archive compat — B5b pending),
Layout (navy sidebar, 6 sections, Lucide icons, teal --app-primary),
App.tsx (Outlet pattern, UploadApp outside Layout), index.css (full :root block).
strict: false — archive components have type issues; build clean.
Note: 45 archive components call fetch('/api/...') without /kitchen/ prefix
(B5b). Runtime 404s; deferred until after initial testing.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
28 lines
No EOL
485 KiB
JavaScript
28 lines
No EOL
485 KiB
JavaScript
/**
|
||
* @licstart The following is the entire license notice for the
|
||
* JavaScript code in this page
|
||
*
|
||
* Copyright 2024 Mozilla Foundation
|
||
*
|
||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
* you may not use this file except in compliance with the License.
|
||
* You may obtain a copy of the License at
|
||
*
|
||
* http://www.apache.org/licenses/LICENSE-2.0
|
||
*
|
||
* Unless required by applicable law or agreed to in writing, software
|
||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
* See the License for the specific language governing permissions and
|
||
* limitations under the License.
|
||
*
|
||
* @licend The above is the entire license notice for the
|
||
* JavaScript code in this page
|
||
*/
|
||
/**
|
||
* pdfjsVersion = 5.7.284
|
||
* pdfjsBuild = 7e5b36c2d
|
||
*/var t={9306(t,e,i){var n=i(4901),r=i(6823),s=TypeError;t.exports=function(t){if(n(t))return t;throw new s(r(t)+" is not a function")}},3506(t,e,i){var n=i(3925),r=String,s=TypeError;t.exports=function(t){if(n(t))return t;throw new s("Can't set "+r(t)+" as a prototype")}},7080(t,e,i){var n=i(4402).has;t.exports=function(t){n(t);return t}},3463(t){var e=TypeError;t.exports=function(t){if("string"==typeof t)return t;throw new e("Argument is not a string")}},4328(t,e,i){var n=i(4995),r=new n.WeakMap,s=n.set,a=n.remove;t.exports=function(t){s(r,t,1);a(r,t);return t}},6557(t,e,i){var n=i(4995).has;t.exports=function(t){n(t);return t}},6469(t,e,i){var n=i(608),r=i(2360),s=i(4913).f,a=n("unscopables"),o=Array.prototype;void 0===o[a]&&s(o,a,{configurable:!0,value:r(null)});t.exports=function(t){o[a][t]=!0}},679(t,e,i){var n=i(1625),r=TypeError;t.exports=function(t,e){if(n(e,t))return t;throw new r("Incorrect invocation")}},3972(t,e,i){var n=i(34),r=String,s=TypeError;t.exports=function(t){if(void 0===t||n(t))return t;throw new s(r(t)+" is not an object or undefined")}},8551(t,e,i){var n=i(34),r=String,s=TypeError;t.exports=function(t){if(n(t))return t;throw new s(r(t)+" is not an object")}},4154(t,e,i){var n=i(6955),r=TypeError;t.exports=function(t){if("Uint8Array"===n(t))return t;throw new r("Argument is not an Uint8Array")}},7811(t){t.exports="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView},7394(t,e,i){var n=i(4576),r=i(6706),s=i(2195),a=n.ArrayBuffer,o=n.TypeError;t.exports=a&&r(a.prototype,"byteLength","get")||function(t){if("ArrayBuffer"!==s(t))throw new o("ArrayBuffer expected");return t.byteLength}},3238(t,e,i){var n=i(4576),r=i(7811),s=i(7394),a=n.DataView;t.exports=function(t){if(!r||0!==s(t))return!1;try{new a(t);return!1}catch(t){return!0}}},5169(t,e,i){var n=i(3238),r=TypeError;t.exports=function(t){if(n(t))throw new r("ArrayBuffer is detached");return t}},5636(t,e,i){var n=i(4576),r=i(9504),s=i(6706),a=i(7696),o=i(5169),l=i(7394),h=i(4483),c=i(1548),d=n.structuredClone,u=n.ArrayBuffer,p=n.DataView,g=Math.max,m=Math.min,f=u.prototype,b=p.prototype,y=r(f.slice),v=s(f,"resizable","get"),w=s(f,"maxByteLength","get"),A=r(b.getInt8),x=r(b.setInt8);t.exports=(c||h)&&function(t,e,i){var n,r=l(t),s=void 0===e?r:a(e),f=!v||!v(t);o(t);if(c){t=d(t,{transfer:[t]});if(r===s&&(i||f))return t}if(r>=s&&(!i||f))n=y(t,0,s);else{var b=i&&!f&&w?{maxByteLength:g(s,w(t))}:void 0;n=new u(s,b);for(var E=new p(t),_=new p(n),T=m(s,r),C=0;C<T;C++)x(_,C,A(E,C))}c||h(t);return n}},4644(t,e,i){var n,r,s,a=i(7811),o=i(3724),l=i(4576),h=i(4901),c=i(34),d=i(9297),u=i(6955),p=i(6823),g=i(6699),m=i(6840),f=i(2106),b=i(1625),y=i(2787),v=i(2967),w=i(608),A=i(3392),x=i(1181),E=x.enforce,_=x.get,T=l.Int8Array,C=T&&T.prototype,S=l.Uint8ClampedArray,D=S&&S.prototype,P=T&&y(T),M=C&&y(C),k=Object.prototype,I=l.TypeError,R=w("toStringTag"),O=A("TYPED_ARRAY_TAG"),B="TypedArrayConstructor",L=a&&!!v&&"Opera"!==u(l.opera),N=!1,U={Int8Array:1,Uint8Array:1,Uint8ClampedArray:1,Int16Array:2,Uint16Array:2,Int32Array:4,Uint32Array:4,Float32Array:4,Float64Array:8},H={BigInt64Array:8,BigUint64Array:8},getTypedArrayConstructor=function(t){var e=y(t);if(c(e)){var i=_(e);return i&&d(i,B)?i[B]:getTypedArrayConstructor(e)}},isTypedArray=function(t){if(!c(t))return!1;var e=u(t);return d(U,e)||d(H,e)};for(n in U)(s=(r=l[n])&&r.prototype)?E(s)[B]=r:L=!1;for(n in H)(s=(r=l[n])&&r.prototype)&&(E(s)[B]=r);if(!L||!h(P)||P===Function.prototype){P=function TypedArray(){throw new I("Incorrect invocation")};if(L)for(n in U)l[n]&&v(l[n],P)}if(!L||!M||M===k){M=P.prototype;if(L)for(n in U)l[n]&&v(l[n].prototype,M)}L&&y(D)!==M&&v(D,M);if(o&&!d(M,R)){N=!0;f(M,R,{configurable:!0,get:function(){return c(this)?this[O]:void 0}});for(n in U)l[n]&&g(l[n].prototype,O,n)}t.exports={NATIVE_ARRAY_BUFFER_VIEWS:L,TYPED_ARRAY_TAG:N&&O,aTypedArray:function(t){if(isTypedArray(t))return t;throw new I("Target is not a typed array")},aTypedArrayConstructor:function(t){if(h(t)&&(!v||b(P,t)))return t;throw new I(p(t)+" is not a typed array constructor")},exportTypedArrayMethod:function(t,e,i,n){if(o){if(i)for(var r in U){var s=l[r];if(s&&d(s.prototype,t))try{delete s.prototype[t]}catch(i){try{s.prototype[t]=e}catch(t){}}}M[t]&&!i||m(M,t,i?e:L&&C[t]||e,n)}},exportTypedArrayStaticMethod:function(t,e,i){var n,r;if(o){if(v){if(i)for(n in U)if((r=l[n])&&d(r,t))try{delete r[t]}catch(t){}if(P[t]&&!i)return;try{return m(P,t,i?e:L&&P[t]||e)}catch(t){}}for(n in U)!(r=l[n])||r[t]&&!i||m(r,t,e)}},getTypedArrayConstructor,isView:function isView(t){if(!c(t))return!1;var e=u(t);return"DataView"===e||d(U,e)||d(H,e)},isTypedArray,TypedArray:P,TypedArrayPrototype:M}},5370(t,e,i){var n=i(6198);t.exports=function(t,e,i){for(var r=0,s=arguments.length>2?i:n(e),a=new t(s);s>r;)a[r]=e[r++];return a}},9617(t,e,i){var n=i(5397),r=i(5610),s=i(6198),createMethod=function(t){return function(e,i,a){var o=n(e),l=s(o);if(0===l)return!t&&-1;var h,c=r(a,l);if(t&&i!=i){for(;l>c;)if((h=o[c++])!=h)return!0}else for(;l>c;c++)if((t||c in o)&&o[c]===i)return t||c||0;return!t&&-1}};t.exports={includes:createMethod(!0),indexOf:createMethod(!1)}},4527(t,e,i){var n=i(3724),r=i(4376),s=TypeError,a=Object.getOwnPropertyDescriptor,o=n&&!function(){if(void 0!==this)return!0;try{Object.defineProperty([],"length",{writable:!1}).length=1}catch(t){return t instanceof TypeError}}();t.exports=o?function(t,e){if(r(t)&&!a(t,"length").writable)throw new s("Cannot set read only .length");return t.length=e}:function(t,e){return t.length=e}},7680(t,e,i){var n=i(9504);t.exports=n([].slice)},2804(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)}},6319(t,e,i){var n=i(8551),r=i(9539);t.exports=function(t,e,i,s){try{return s?e(n(i)[0],i[1]):e(i)}catch(e){r(t,"throw",e)}}},2195(t,e,i){var n=i(9504),r=n({}.toString),s=n("".slice);t.exports=function(t){return s(r(t),8,-1)}},6955(t,e,i){var n=i(2140),r=i(4901),s=i(2195),a=i(608)("toStringTag"),o=Object,l="Arguments"===s(function(){return arguments}());t.exports=n?s:function(t){var e,i,n;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(i=function(t,e){try{return t[e]}catch(t){}}(e=o(t),a))?i:l?s(e):"Object"===(n=s(e))&&r(e.callee)?"Arguments":n}},7740(t,e,i){var n=i(9297),r=i(5031),s=i(7347),a=i(4913);t.exports=function(t,e,i){for(var o=r(e),l=a.f,h=s.f,c=0;c<o.length;c++){var d=o[c];n(t,d)||i&&n(i,d)||l(t,d,h(e,d))}}},2211(t,e,i){var n=i(9039);t.exports=!n(function(){function F(){}F.prototype.constructor=null;return Object.getPrototypeOf(new F)!==F.prototype})},2529(t){t.exports=function(t,e){return{value:t,done:e}}},6699(t,e,i){var n=i(3724),r=i(4913),s=i(6980);t.exports=n?function(t,e,i){return r.f(t,e,s(1,i))}:function(t,e,i){t[e]=i;return t}},6980(t){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},4659(t,e,i){var n=i(3724),r=i(4913),s=i(6980);t.exports=function(t,e,i){n?r.f(t,e,s(0,i)):t[e]=i}},2106(t,e,i){var n=i(283),r=i(4913);t.exports=function(t,e,i){i.get&&n(i.get,e,{getter:!0});i.set&&n(i.set,e,{setter:!0});return r.f(t,e,i)}},6840(t,e,i){var n=i(4901),r=i(4913),s=i(283),a=i(9433);t.exports=function(t,e,i,o){o||(o={});var l=o.enumerable,h=void 0!==o.name?o.name:e;n(i)&&s(i,h,o);if(o.global)l?t[e]=i:a(e,i);else{try{o.unsafe?t[e]&&(l=!0):delete t[e]}catch(t){}l?t[e]=i:r.f(t,e,{value:i,enumerable:!1,configurable:!o.nonConfigurable,writable:!o.nonWritable})}return t}},6279(t,e,i){var n=i(6840);t.exports=function(t,e,i){for(var r in e)n(t,r,e[r],i);return t}},9433(t,e,i){var n=i(4576),r=Object.defineProperty;t.exports=function(t,e){try{r(n,t,{value:e,configurable:!0,writable:!0})}catch(i){n[t]=e}return e}},3724(t,e,i){var n=i(9039);t.exports=!n(function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]})},4483(t,e,i){var n,r,s,a,o=i(4576),l=i(9429),h=i(1548),c=o.structuredClone,d=o.ArrayBuffer,u=o.MessageChannel,p=!1;if(h)p=function(t){c(t,{transfer:[t]})};else if(d)try{u||(n=l("worker_threads"))&&(u=n.MessageChannel);if(u){r=new u;s=new d(2);a=function(t){r.port1.postMessage(null,[t])};if(2===s.byteLength){a(s);0===s.byteLength&&(p=a)}}}catch(t){}t.exports=p},4055(t,e,i){var n=i(4576),r=i(34),s=n.document,a=r(s)&&r(s.createElement);t.exports=function(t){return a?s.createElement(t):{}}},6837(t){var e=TypeError;t.exports=function(t){if(t>9007199254740991)throw new e("Maximum allowed index exceeded");return t}},5002(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}}},8727(t){t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},6193(t,e,i){var n=i(4215);t.exports="NODE"===n},2839(t,e,i){var n=i(4576).navigator,r=n&&n.userAgent;t.exports=r?String(r):""},9519(t,e,i){var n,r,s=i(4576),a=i(2839),o=s.process,l=s.Deno,h=o&&o.versions||l&&l.version,c=h&&h.v8;c&&(r=(n=c.split("."))[0]>0&&n[0]<4?1:+(n[0]+n[1]));!r&&a&&(!(n=a.match(/Edge\/(\d+)/))||n[1]>=74)&&(n=a.match(/Chrome\/(\d+)/))&&(r=+n[1]);t.exports=r},4215(t,e,i){var n=i(4576),r=i(2839),s=i(2195),userAgentStartsWith=function(t){return r.slice(0,t.length)===t};t.exports=userAgentStartsWith("Bun/")?"BUN":userAgentStartsWith("Cloudflare-Workers")?"CLOUDFLARE":userAgentStartsWith("Deno/")?"DENO":userAgentStartsWith("Node.js/")?"NODE":n.Bun&&"string"==typeof Bun.version?"BUN":n.Deno&&"object"==typeof Deno.version?"DENO":"process"===s(n.process)?"NODE":n.window&&n.document?"BROWSER":"REST"},8574(t,e,i){var n=i(9504),r=Error,s=n("".replace),a=String(new r("zxcasd").stack),o=/\n\s*at [^:]*:[^\n]*/,l=o.test(a);t.exports=function(t,e){if(l&&"string"==typeof t&&!r.prepareStackTrace)for(;e--;)t=s(t,o,"");return t}},6518(t,e,i){var n=i(4576),r=i(7347).f,s=i(6699),a=i(6840),o=i(9433),l=i(7740),h=i(2796);t.exports=function(t,e){var i,c,d,u,p,g=t.target,m=t.global,f=t.stat;if(i=m?n:f?n[g]||o(g,{}):n[g]&&n[g].prototype)for(c in e){u=e[c];d=t.dontCallGetSet?(p=r(i,c))&&p.value:i[c];if(!h(m?c:g+(f?".":"#")+c,t.forced)&&void 0!==d){if(typeof u==typeof d)continue;l(u,d)}(t.sham||d&&d.sham)&&s(u,"sham",!0);a(i,c,u,t)}}},9039(t){t.exports=function(t){try{return!!t()}catch(t){return!0}}},8745(t,e,i){var n=i(616),r=Function.prototype,s=r.apply,a=r.call;t.exports="object"==typeof Reflect&&Reflect.apply||(n?a.bind(s):function(){return a.apply(s,arguments)})},6080(t,e,i){var n=i(7476),r=i(9306),s=i(616),a=n(n.bind);t.exports=function(t,e){r(t);return void 0===e?t:s?a(t,e):function(){return t.apply(e,arguments)}}},616(t,e,i){var n=i(9039);t.exports=!n(function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})},9565(t,e,i){var n=i(616),r=Function.prototype.call;t.exports=n?r.bind(r):function(){return r.apply(r,arguments)}},350(t,e,i){var n=i(3724),r=i(9297),s=Function.prototype,a=n&&Object.getOwnPropertyDescriptor,o=r(s,"name"),l=o&&"something"===function something(){}.name,h=o&&(!n||n&&a(s,"name").configurable);t.exports={EXISTS:o,PROPER:l,CONFIGURABLE:h}},6706(t,e,i){var n=i(9504),r=i(9306);t.exports=function(t,e,i){try{return n(r(Object.getOwnPropertyDescriptor(t,e)[i]))}catch(t){}}},7476(t,e,i){var n=i(2195),r=i(9504);t.exports=function(t){if("Function"===n(t))return r(t)}},9504(t,e,i){var n=i(616),r=Function.prototype,s=r.call,a=n&&r.bind.bind(s,s);t.exports=n?a:function(t){return function(){return s.apply(t,arguments)}}},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")}},9429(t,e,i){var n=i(4576),r=i(6193);t.exports=function(t){if(r){try{return n.process.getBuiltinModule(t)}catch(t){}try{return Function('return require("'+t+'")')()}catch(t){}}}},7751(t,e,i){var n=i(4576),r=i(4901);t.exports=function(t,e){return arguments.length<2?(i=n[t],r(i)?i:void 0):n[t]&&n[t][e];var i}},1767(t){t.exports=function(t){return{iterator:t,next:t.next,done:!1}}},8646(t,e,i){var n=i(9565),r=i(8551),s=i(1767),a=i(851);t.exports=function(t,e){e&&"string"==typeof t||r(t);var i=a(t);return s(r(void 0!==i?n(i,t):t))}},851(t,e,i){var n=i(6955),r=i(5966),s=i(4117),a=i(6269),o=i(608)("iterator");t.exports=function(t){if(!s(t))return r(t,o)||r(t,"@@iterator")||a[n(t)]}},81(t,e,i){var n=i(9565),r=i(9306),s=i(8551),a=i(6823),o=i(851),l=TypeError;t.exports=function(t,e){var i=arguments.length<2?o(t):e;if(r(i))return s(n(i,t));throw new l(a(t)+" is not iterable")}},5966(t,e,i){var n=i(9306),r=i(4117);t.exports=function(t,e){var i=t[e];return r(i)?void 0:n(i)}},3789(t,e,i){var n=i(9306),r=i(8551),s=i(9565),a=i(1291),o=i(1767),l="Invalid size",h=RangeError,c=TypeError,d=Math.max,SetRecord=function(t,e){this.set=t;this.size=d(e,0);this.has=n(t.has);this.keys=n(t.keys)};SetRecord.prototype={getIterator:function(){return o(r(s(this.keys,this.set)))},includes:function(t){return s(this.has,this.set,t)}};t.exports=function(t){r(t);var e=+t.size;if(e!=e)throw new c(l);var i=a(e);if(i<0)throw new h(l);return new SetRecord(t,i)}},4576(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")()},9297(t,e,i){var n=i(9504),r=i(8981),s=n({}.hasOwnProperty);t.exports=Object.hasOwn||function hasOwn(t,e){return s(r(t),e)}},421(t){t.exports={}},397(t,e,i){var n=i(7751);t.exports=n("document","documentElement")},5917(t,e,i){var n=i(3724),r=i(9039),s=i(4055);t.exports=!n&&!r(function(){return 7!==Object.defineProperty(s("div"),"a",{get:function(){return 7}}).a})},7055(t,e,i){var n=i(9504),r=i(9039),s=i(2195),a=Object,o=n("".split);t.exports=r(function(){return!a("z").propertyIsEnumerable(0)})?function(t){return"String"===s(t)?o(t,""):a(t)}:a},3167(t,e,i){var n=i(4901),r=i(34),s=i(2967);t.exports=function(t,e,i){var a,o;s&&n(a=e.constructor)&&a!==i&&r(o=a.prototype)&&o!==i.prototype&&s(t,o);return t}},3706(t,e,i){var n=i(9504),r=i(4901),s=i(7629),a=n(Function.toString);r(s.inspectSource)||(s.inspectSource=function(t){return a(t)});t.exports=s.inspectSource},1181(t,e,i){var n,r,s,a=i(8622),o=i(4576),l=i(34),h=i(6699),c=i(9297),d=i(7629),u=i(6119),p=i(421),g="Object already initialized",m=o.TypeError,f=o.WeakMap;if(a||d.state){var b=d.state||(d.state=new f);b.get=b.get;b.has=b.has;b.set=b.set;n=function(t,e){if(b.has(t))throw new m(g);e.facade=t;b.set(t,e);return e};r=function(t){return b.get(t)||{}};s=function(t){return b.has(t)}}else{var y=u("state");p[y]=!0;n=function(t,e){if(c(t,y))throw new m(g);e.facade=t;h(t,y,e);return e};r=function(t){return c(t,y)?t[y]:{}};s=function(t){return c(t,y)}}t.exports={set:n,get:r,has:s,enforce:function(t){return s(t)?r(t):n(t,{})},getterFor:function(t){return function(e){var i;if(!l(e)||(i=r(e)).type!==t)throw new m("Incompatible receiver, "+t+" required");return i}}}},4209(t,e,i){var n=i(608),r=i(6269),s=n("iterator"),a=Array.prototype;t.exports=function(t){return void 0!==t&&(r.Array===t||a[s]===t)}},4376(t,e,i){var n=i(2195);t.exports=Array.isArray||function isArray(t){return"Array"===n(t)}},1108(t,e,i){var n=i(6955);t.exports=function(t){var e=n(t);return"BigInt64Array"===e||"BigUint64Array"===e}},4901(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}},2796(t,e,i){var n=i(9039),r=i(4901),s=/#|\.prototype\./,isForced=function(t,e){var i=o[a(t)];return i===h||i!==l&&(r(e)?n(e):!!e)},a=isForced.normalize=function(t){return String(t).replace(s,".").toLowerCase()},o=isForced.data={},l=isForced.NATIVE="N",h=isForced.POLYFILL="P";t.exports=isForced},4117(t){t.exports=function(t){return null==t}},34(t,e,i){var n=i(4901);t.exports=function(t){return"object"==typeof t?null!==t:n(t)}},3925(t,e,i){var n=i(34);t.exports=function(t){return n(t)||null===t}},6395(t){t.exports=!1},5810(t,e,i){var n=i(34),r=i(1181).get;t.exports=function isRawJSON(t){if(!n(t))return!1;var e=r(t);return!!e&&"RawJSON"===e.type}},757(t,e,i){var n=i(7751),r=i(4901),s=i(1625),a=i(7040),o=Object;t.exports=a?function(t){return"symbol"==typeof t}:function(t){var e=n("Symbol");return r(e)&&s(e.prototype,o(t))}},507(t,e,i){var n=i(9565);t.exports=function(t,e,i){for(var r,s,a=i?t:t.iterator,o=t.next;!(r=n(o,a)).done;)if(void 0!==(s=e(r.value)))return s}},2652(t,e,i){var n=i(6080),r=i(9565),s=i(8551),a=i(6823),o=i(4209),l=i(6198),h=i(1625),c=i(81),d=i(851),u=i(9539),p=TypeError,Result=function(t,e){this.stopped=t;this.result=e},g=Result.prototype;t.exports=function(t,e,i){var m,f,b,y,v,w,A,x=i&&i.that,E=!(!i||!i.AS_ENTRIES),_=!(!i||!i.IS_RECORD),T=!(!i||!i.IS_ITERATOR),C=!(!i||!i.INTERRUPTED),S=n(e,x),stop=function(t){var e=m;m=void 0;e&&u(e,"normal");return new Result(!0,t)},callFn=function(t){if(E){s(t);return C?S(t[0],t[1],stop):S(t[0],t[1])}return C?S(t,stop):S(t)};if(_)m=t.iterator;else if(T)m=t;else{if(!(f=d(t)))throw new p(a(t)+" is not iterable");if(o(f)){for(b=0,y=l(t);y>b;b++)if((v=callFn(t[b]))&&h(g,v))return v;return new Result(!1)}m=c(t,f)}w=_?t.next:m.next;for(;!(A=r(w,m)).done;){var D=A.value;try{v=callFn(D)}catch(t){if(!m)throw t;u(m,"throw",t)}if("object"==typeof v&&v&&h(g,v))return v}return new Result(!1)}},1385(t,e,i){var n=i(9539);t.exports=function(t,e,i){for(var r=t.length-1;r>=0;r--)if(void 0!==t[r])try{i=n(t[r].iterator,e,i)}catch(t){e="throw";i=t}if("throw"===e)throw i;return i}},9539(t,e,i){var n=i(9565),r=i(8551),s=i(5966);t.exports=function(t,e,i){var a,o;r(t);try{if(!(a=s(t,"return"))){if("throw"===e)throw i;return i}a=n(a,t)}catch(t){o=!0;a=t}if("throw"===e)throw i;if(o)throw a;r(a);return i}},9462(t,e,i){var n=i(9565),r=i(2360),s=i(6699),a=i(6279),o=i(608),l=i(1181),h=i(5966),c=i(7657).IteratorPrototype,d=i(2529),u=i(9539),p=i(1385),g=o("toStringTag"),m="IteratorHelper",f="WrapForValidIterator",b="normal",y="throw",v=l.set,createIteratorProxyPrototype=function(t){var e=l.getterFor(t?f:m);return a(r(c),{next:function next(){var i=e(this);if(t)return i.nextHandler();if(i.done)return d(void 0,!0);try{var n=i.nextHandler();return i.returnHandlerResult?n:d(n,i.done)}catch(t){i.done=!0;throw t}},return:function(){var i=e(this),r=i.iterator,s=i.done;i.done=!0;if(t){var a=h(r,"return");return a?n(a,r):d(void 0,!0)}if(s)return d(void 0,!0);if(i.inner)try{u(i.inner.iterator,b)}catch(t){return u(r,y,t)}if(i.openIters)try{p(i.openIters,b)}catch(t){if(r)return u(r,y,t);throw t}r&&u(r,b);return d(void 0,!0)}})},w=createIteratorProxyPrototype(!0),A=createIteratorProxyPrototype(!1);s(A,g,"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?f:m;r.returnHandlerResult=!!i;r.nextHandler=t;r.counter=0;r.done=!1;v(this,r)};n.prototype=e?w:A;return n}},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}}},4549(t,e,i){var n=i(4576);t.exports=function(t,e){var i=n.Iterator,r=i&&i.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 e||(a=!1)}if(!a)return s}},7657(t,e,i){var n,r,s,a=i(9039),o=i(4901),l=i(34),h=i(2360),c=i(2787),d=i(6840),u=i(608),p=i(6395),g=u("iterator"),m=!1;[].keys&&("next"in(s=[].keys())?(r=c(c(s)))!==Object.prototype&&(n=r):m=!0);!l(n)||a(function(){var t={};return n[g].call(t)!==t})?n={}:p&&(n=h(n));o(n[g])||d(n,g,function(){return this});t.exports={IteratorPrototype:n,BUGGY_SAFARI_ITERATORS:m}},6269(t){t.exports={}},6198(t,e,i){var n=i(8014);t.exports=function(t){return n(t.length)}},283(t,e,i){var n=i(9504),r=i(9039),s=i(4901),a=i(9297),o=i(3724),l=i(350).CONFIGURABLE,h=i(3706),c=i(1181),d=c.enforce,u=c.get,p=String,g=Object.defineProperty,m=n("".slice),f=n("".replace),b=n([].join),y=o&&!r(function(){return 8!==g(function(){},"length",{value:8}).length}),v=String(String).split("String"),w=t.exports=function(t,e,i){"Symbol("===m(p(e),0,7)&&(e="["+f(p(e),/^Symbol\(([^)]*)\).*$/,"$1")+"]");i&&i.getter&&(e="get "+e);i&&i.setter&&(e="set "+e);(!a(t,"name")||l&&t.name!==e)&&(o?g(t,"name",{value:e,configurable:!0}):t.name=e);y&&i&&a(i,"arity")&&t.length!==i.arity&&g(t,"length",{value:i.arity});try{i&&a(i,"constructor")&&i.constructor?o&&g(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch(t){}var n=d(t);a(n,"source")||(n.source=b(v,"string"==typeof e?e:""));return t};Function.prototype.toString=w(function toString(){return s(this)&&u(this).source||h(this)},"toString")},2248(t,e,i){var n=i(9504),r=Map.prototype;t.exports={Map,set:n(r.set),get:n(r.get),has:n(r.has),remove:n(r.delete),proto:r}},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)}},7819(t,e,i){var n=i(9039);t.exports=!n(function(){var t="9007199254740993",e=JSON.rawJSON(t);return!JSON.isRawJSON(e)||JSON.stringify(e)!==t})},6043(t,e,i){var n=i(9306),r=TypeError,PromiseCapability=function(t){var e,i;this.promise=new t(function(t,n){if(void 0!==e||void 0!==i)throw new r("Bad Promise constructor");e=t;i=n});this.resolve=n(e);this.reject=n(i)};t.exports.f=function(t){return new PromiseCapability(t)}},2603(t,e,i){var n=i(655);t.exports=function(t,e){return void 0===t?arguments.length<2?"":e:n(t)}},4149(t){var e=RangeError;t.exports=function(t){if(t==t)return t;throw new e("NaN is not allowed")}},2360(t,e,i){var n,r=i(8551),s=i(6801),a=i(8727),o=i(421),l=i(397),h=i(4055),c=i(6119),d="prototype",u="script",p=c("IE_PROTO"),EmptyConstructor=function(){},scriptTag=function(t){return"<"+u+">"+t+"</"+u+">"},NullProtoObjectViaActiveX=function(t){t.write(scriptTag(""));t.close();var e=t.parentWindow.Object;t=null;return e},NullProtoObject=function(){try{n=new ActiveXObject("htmlfile")}catch(t){}NullProtoObject="undefined"!=typeof document?document.domain&&n?NullProtoObjectViaActiveX(n):function(){var t,e=h("iframe"),i="java"+u+":";e.style.display="none";l.appendChild(e);e.src=String(i);(t=e.contentWindow.document).open();t.write(scriptTag("document.F=Object"));t.close();return t.F}():NullProtoObjectViaActiveX(n);for(var t=a.length;t--;)delete NullProtoObject[d][a[t]];return NullProtoObject()};o[p]=!0;t.exports=Object.create||function create(t,e){var i;if(null!==t){EmptyConstructor[d]=r(t);i=new EmptyConstructor;EmptyConstructor[d]=null;i[p]=t}else i=NullProtoObject();return void 0===e?i:s.f(i,e)}},6801(t,e,i){var n=i(3724),r=i(8686),s=i(4913),a=i(8551),o=i(5397),l=i(1072);e.f=n&&!r?Object.defineProperties:function defineProperties(t,e){a(t);for(var i,n=o(e),r=l(e),h=r.length,c=0;h>c;)s.f(t,i=r[c++],n[i]);return t}},4913(t,e,i){var n=i(3724),r=i(5917),s=i(8686),a=i(8551),o=i(6969),l=TypeError,h=Object.defineProperty,c=Object.getOwnPropertyDescriptor,d="enumerable",u="configurable",p="writable";e.f=n?s?function defineProperty(t,e,i){a(t);e=o(e);a(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 h(t,e,i)}:h:function defineProperty(t,e,i){a(t);e=o(e);a(i);if(r)try{return h(t,e,i)}catch(t){}if("get"in i||"set"in i)throw new l("Accessors not supported");"value"in i&&(t[e]=i.value);return t}},7347(t,e,i){var n=i(3724),r=i(9565),s=i(8773),a=i(6980),o=i(5397),l=i(6969),h=i(9297),c=i(5917),d=Object.getOwnPropertyDescriptor;e.f=n?d:function getOwnPropertyDescriptor(t,e){t=o(t);e=l(e);if(c)try{return d(t,e)}catch(t){}if(h(t,e))return a(!r(s.f,t,e),t[e])}},8480(t,e,i){var n=i(1828),r=i(8727).concat("length","prototype");e.f=Object.getOwnPropertyNames||function getOwnPropertyNames(t){return n(t,r)}},3717(t,e){e.f=Object.getOwnPropertySymbols},2787(t,e,i){var n=i(9297),r=i(4901),s=i(8981),a=i(6119),o=i(2211),l=a("IE_PROTO"),h=Object,c=h.prototype;t.exports=o?h.getPrototypeOf:function(t){var e=s(t);if(n(e,l))return e[l];var i=e.constructor;return r(i)&&e instanceof i?i.prototype:e instanceof h?c:null}},1625(t,e,i){var n=i(9504);t.exports=n({}.isPrototypeOf)},1828(t,e,i){var n=i(9504),r=i(9297),s=i(5397),a=i(9617).indexOf,o=i(421),l=n([].push);t.exports=function(t,e){var i,n=s(t),h=0,c=[];for(i in n)!r(o,i)&&r(n,i)&&l(c,i);for(;e.length>h;)r(n,i=e[h++])&&(~a(c,i)||l(c,i));return c}},1072(t,e,i){var n=i(1828),r=i(8727);t.exports=Object.keys||function keys(t){return n(t,r)}},8773(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},2967(t,e,i){var n=i(6706),r=i(34),s=i(7750),a=i(3506);t.exports=Object.setPrototypeOf||("__proto__"in{}?function(){var t,e=!1,i={};try{(t=n(Object.prototype,"__proto__","set"))(i,[]);e=i instanceof Array}catch(t){}return function setPrototypeOf(i,n){s(i);a(n);if(!r(i))return i;e?t(i,n):i.__proto__=n;return i}}():void 0)},4270(t,e,i){var n=i(9565),r=i(4901),s=i(34),a=TypeError;t.exports=function(t,e){var i,o;if("string"===e&&r(i=t.toString)&&!s(o=n(i,t)))return o;if(r(i=t.valueOf)&&!s(o=n(i,t)))return o;if("string"!==e&&r(i=t.toString)&&!s(o=n(i,t)))return o;throw new a("Can't convert object to primitive value")}},5031(t,e,i){var n=i(7751),r=i(9504),s=i(8480),a=i(3717),o=i(8551),l=r([].concat);t.exports=n("Reflect","ownKeys")||function ownKeys(t){var e=s.f(o(t)),i=a.f;return i?l(e,i(t)):e}},8235(t,e,i){var n=i(9504),r=i(9297),s=SyntaxError,a=parseInt,o=String.fromCharCode,l=n("".charAt),h=n("".slice),c=n(/./.exec),d={'\\"':'"',"\\\\":"\\","\\/":"/","\\b":"\b","\\f":"\f","\\n":"\n","\\r":"\r","\\t":"\t"},u=/^[\da-f]{4}$/i,p=/^[\u0000-\u001F]$/;t.exports=function(t,e){for(var i=!0,n="";e<t.length;){var g=l(t,e);if("\\"===g){var m=h(t,e,e+2);if(r(d,m)){n+=d[m];e+=2}else{if("\\u"!==m)throw new s('Unknown escape sequence: "'+m+'"');var f=h(t,e+=2,e+4);if(!c(u,f))throw new s("Bad Unicode escape at: "+e);n+=o(a(f,16));e+=4}}else{if('"'===g){i=!1;e++;break}if(c(p,g))throw new s("Bad control character in string literal at: "+e);n+=g;e++}}if(i)throw new s("Unterminated string at: "+e);return{value:n,end:e}}},1103(t){t.exports=function(t){try{return{error:!1,value:t()}}catch(t){return{error:!0,value:t}}}},7750(t,e,i){var n=i(4117),r=TypeError;t.exports=function(t){if(n(t))throw new r("Can't call method on "+t);return t}},9286(t,e,i){var n=i(4402),r=i(8469),s=n.Set,a=n.add;t.exports=function(t){var e=new s;r(t,function(t){a(e,t)});return e}},3440(t,e,i){var n=i(7080),r=i(4402),s=i(9286),a=i(5170),o=i(3789),l=i(8469),h=i(507),c=r.has,d=r.remove;t.exports=function difference(t){var e=n(this),i=o(t),r=s(e);a(r)<=i.size?l(r,function(t){i.includes(t)&&d(r,t)}):h(i.getIterator(),function(t){c(r,t)&&d(r,t)});return r}},4402(t,e,i){var n=i(9504),r=Set.prototype;t.exports={Set,add:n(r.add),has:n(r.has),remove:n(r.delete),proto:r}},8750(t,e,i){var n=i(7080),r=i(4402),s=i(5170),a=i(3789),o=i(8469),l=i(507),h=r.Set,c=r.add,d=r.has;t.exports=function intersection(t){var e=n(this),i=a(t),r=new h;s(e)>i.size?l(i.getIterator(),function(t){d(e,t)&&c(r,t)}):o(e,function(t){i.includes(t)&&c(r,t)});return r}},4449(t,e,i){var n=i(7080),r=i(4402).has,s=i(5170),a=i(3789),o=i(8469),l=i(507),h=i(9539);t.exports=function isDisjointFrom(t){var e=n(this),i=a(t);if(s(e)<=i.size)return!1!==o(e,function(t){if(i.includes(t))return!1},!0);var c=i.getIterator();return!1!==l(c,function(t){if(r(e,t))return h(c.iterator,"normal",!1)})}},3838(t,e,i){var n=i(7080),r=i(5170),s=i(8469),a=i(3789);t.exports=function isSubsetOf(t){var e=n(this),i=a(t);return!(r(e)>i.size)&&!1!==s(e,function(t){if(!i.includes(t))return!1},!0)}},8527(t,e,i){var n=i(7080),r=i(4402).has,s=i(5170),a=i(3789),o=i(507),l=i(9539);t.exports=function isSupersetOf(t){var e=n(this),i=a(t);if(s(e)<i.size)return!1;var h=i.getIterator();return!1!==o(h,function(t){if(!r(e,t))return l(h.iterator,"normal",!1)})}},8469(t,e,i){var n=i(9504),r=i(507),s=i(4402),a=s.Set,o=s.proto,l=n(o.forEach),h=n(o.keys),c=h(new a).next;t.exports=function(t,e,i){return i?r({iterator:h(t),next:c},e):l(t,e)}},4916(t,e,i){var n=i(7751),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,e){var i=n("Set");try{(new i)[t](createSetLike(0));try{(new i)[t](createSetLike(-1));return!1}catch(n){if(!e)return!0;try{(new i)[t](createSetLikeWithInfinitySize(-1/0));return!1}catch(n){return e(new i([1,2])[t](createSetLikeWithInfinitySize(1/0)))}}}catch(t){return!1}}},9835(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}}},5170(t,e,i){var n=i(6706),r=i(4402);t.exports=n(r.proto,"size","get")||function(t){return t.size}},3650(t,e,i){var n=i(7080),r=i(4402),s=i(9286),a=i(3789),o=i(507),l=r.add,h=r.has,c=r.remove;t.exports=function symmetricDifference(t){var e=n(this),i=a(t).getIterator(),r=s(e);o(i,function(t){h(e,t)?c(r,t):l(r,t)});return r}},4204(t,e,i){var n=i(7080),r=i(4402).add,s=i(9286),a=i(3789),o=i(507);t.exports=function union(t){var e=n(this),i=a(t).getIterator(),l=s(e);o(i,function(t){r(l,t)});return l}},6119(t,e,i){var n=i(5745),r=i(3392),s=n("keys");t.exports=function(t){return s[t]||(s[t]=r(t))}},7629(t,e,i){var n=i(6395),r=i(4576),s=i(9433),a="__core-js_shared__",o=t.exports=r[a]||s(a,{});(o.versions||(o.versions=[])).push({version:"3.49.0",mode:n?"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.49.0/LICENSE",source:"https://github.com/zloirock/core-js"})},5745(t,e,i){var n=i(7629);t.exports=function(t,e){return n[t]||(n[t]=e||{})}},1548(t,e,i){var n=i(4576),r=i(9039),s=i(9519),a=i(4215),o=n.structuredClone;t.exports=!!o&&!r(function(){if("DENO"===a&&s>92||"NODE"===a&&s>94||"BROWSER"===a&&s>97)return!1;var t=new ArrayBuffer(8),e=o(t,{transfer:[t]});return 0!==t.byteLength||8!==e.byteLength})},4495(t,e,i){var n=i(9519),r=i(9039),s=i(4576).String;t.exports=!!Object.getOwnPropertySymbols&&!r(function(){var t=Symbol("symbol detection");return!s(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&n&&n<41})},5610(t,e,i){var n=i(1291),r=Math.max,s=Math.min;t.exports=function(t,e){var i=n(t);return i<0?r(i+e,0):s(i,e)}},5854(t,e,i){var n=i(2777),r=TypeError;t.exports=function(t){var e=n(t,"number");if("number"==typeof e)throw new r("Can't convert number to bigint");return BigInt(e)}},7696(t,e,i){var n=i(1291),r=i(8014),s=RangeError;t.exports=function(t){if(void 0===t)return 0;var e=n(t),i=r(e);if(e!==i)throw new s("Wrong length or index");return i}},5397(t,e,i){var n=i(7055),r=i(7750);t.exports=function(t){return n(r(t))}},1291(t,e,i){var n=i(741);t.exports=function(t){var e=+t;return e!=e||0===e?0:n(e)}},8014(t,e,i){var n=i(1291),r=Math.min;t.exports=function(t){var e=n(t);return e>0?r(e,9007199254740991):0}},8981(t,e,i){var n=i(7750),r=Object;t.exports=function(t){return r(n(t))}},9590(t,e,i){var n=i(1291),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}},2777(t,e,i){var n=i(9565),r=i(34),s=i(757),a=i(5966),o=i(4270),l=i(608),h=TypeError,c=l("toPrimitive");t.exports=function(t,e){if(!r(t)||s(t))return t;var i,l=a(t,c);if(l){void 0===e&&(e="default");i=n(l,t,e);if(!r(i)||s(i))return i;throw new h("Can't convert object to primitive value")}void 0===e&&(e="number");return o(t,e)}},6969(t,e,i){var n=i(2777),r=i(757);t.exports=function(t){var e=n(t,"string");return r(e)?e:e+""}},2140(t,e,i){var n={};n[i(608)("toStringTag")]="z";t.exports="[object z]"===String(n)},655(t,e,i){var n=i(6955),r=String;t.exports=function(t){if("Symbol"===n(t))throw new TypeError("Cannot convert a Symbol value to a string");return r(t)}},6823(t){var e=String;t.exports=function(t){try{return e(t)}catch(t){return"Object"}}},3392(t,e,i){var n=i(9504),r=0,s=Math.random(),a=n(1.1.toString);t.exports=function(t){return"Symbol("+(void 0===t?"":t)+")_"+a(++r+s,36)}},9143(t,e,i){var n=i(4576),r=i(9504),s=i(3972),a=i(3463),o=i(9297),l=i(2804),h=i(944),c=i(5169),d=l.c2i,u=l.c2iUrl,p=n.SyntaxError,g=n.TypeError,m=r("".charAt),skipAsciiWhitespace=function(t,e){for(var i=t.length;e<i;e++){var n=m(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[m(t,0)]<<18)+(e[m(t,1)]<<12)+(e[m(t,2)]<<6)+e[m(t,3)],s=[r>>16&255,r>>8&255,255&r];if(2===n){if(i&&0!==s[1])throw new p("Extra bits");return[s[0]]}if(3===n){if(i&&0!==s[2])throw new p("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,n){a(t);s(e);var r="base64"===h(e)?d:u,l=e?e.lastChunkHandling:void 0;void 0===l&&(l="loose");if("loose"!==l&&"strict"!==l&&"stop-before-partial"!==l)throw new g("Incorrect `lastChunkHandling` option");i&&c(i.buffer);var f=t.length,b=i||[],y=0,v=0,w="",A=0;if(n)for(;;){if((A=skipAsciiWhitespace(t,A))===f){if(w.length>0){if("stop-before-partial"===l)break;if("loose"!==l)throw new p("Missing padding");if(1===w.length)throw new p("Malformed padding: exactly one additional character");y=writeBytes(b,decodeBase64Chunk(w,r,!1),y)}v=f;break}var x=m(t,A);++A;if("="===x){if(w.length<2)throw new p("Padding is too early");A=skipAsciiWhitespace(t,A);if(2===w.length){if(A===f){if("stop-before-partial"===l)break;throw new p("Malformed padding: only one =")}if("="===m(t,A)){++A;A=skipAsciiWhitespace(t,A)}}if(A<f)throw new p("Unexpected character after padding");y=writeBytes(b,decodeBase64Chunk(w,r,"strict"===l),y);v=f;break}if(!o(r,x))throw new p("Unexpected character");var E=n-y;if(1===E&&2===w.length||2===E&&3===w.length)break;if(4===(w+=x).length){y=writeBytes(b,decodeBase64Chunk(w,r,!1),y);w="";v=A;if(y===n)break}}return{bytes:b,read:v,written:y}}},2303(t,e,i){var n=i(4576),r=i(9504),s=n.Uint8Array,a=n.SyntaxError,o=Math.min,l=r("".match);t.exports=function(t,e){var i=t.length;if(i%2!=0)throw new a("String should be an even number of characters");for(var n=e?o(e.length,i/2):i/2,r=e||new s(n),h=l(t,/.{2}/g),c=0;c<n;c++){var d=+("0x"+h[c]+"0");if(d!=d)throw new a("String should only contain hex characters");r[c]=d>>4}return{bytes:r,read:c<<1}}},7416(t,e,i){var n=i(9039),r=i(608),s=i(3724),a=i(6395),o=r("iterator");t.exports=!n(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"),n="";t.pathname="c%20d";e.forEach(function(t,i){e.delete("b");n+=i+t});i.delete("a",2);i.delete("b",void 0);return a&&(!t.toJSON||!i.has("a",1)||i.has("a",2)||!i.has("a",void 0)||i.has("b"))||!e.size&&(a||!s)||!e.sort||"https://a/c%20d?a=1&c=3"!==t.href||"3"!==e.get("c")||"a=1"!==String(new URLSearchParams("?a=1"))||!e[o]||"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"!==n||"x"!==new URL("https://x",void 0).host})},7040(t,e,i){var n=i(4495);t.exports=n&&!Symbol.sham&&"symbol"==typeof Symbol.iterator},8686(t,e,i){var n=i(3724),r=i(9039);t.exports=n&&r(function(){return 42!==Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype})},2812(t){var e=TypeError;t.exports=function(t,i){if(t<i)throw new e("Not enough arguments");return t}},8622(t,e,i){var n=i(4576),r=i(4901),s=n.WeakMap;t.exports=r(s)&&/native code/.test(String(s))},4995(t,e,i){var n=i(9504),r=WeakMap.prototype;t.exports={WeakMap,set:n(r.set),get:n(r.get),has:n(r.has),remove:n(r.delete)}},608(t,e,i){var n=i(4576),r=i(5745),s=i(9297),a=i(3392),o=i(4495),l=i(7040),h=n.Symbol,c=r("wks"),d=l?h.for||h:h&&h.withoutSetter||a;t.exports=function(t){s(c,t)||(c[t]=o&&s(h,t)?h[t]:d("Symbol."+t));return c[t]}},6573(t,e,i){var n=i(3724),r=i(2106),s=i(3238),a=ArrayBuffer.prototype;n&&!("detached"in a)&&r(a,"detached",{configurable:!0,get:function detached(){return s(this)}})},7936(t,e,i){var n=i(6518),r=i(5636);r&&n({target:"ArrayBuffer",proto:!0},{transferToFixedLength:function transferToFixedLength(){return r(this,arguments.length?arguments[0]:void 0,!1)}})},8100(t,e,i){var n=i(6518),r=i(5636);r&&n({target:"ArrayBuffer",proto:!0},{transfer:function transfer(){return r(this,arguments.length?arguments[0]:void 0,!0)}})},4423(t,e,i){var n=i(6518),r=i(9617).includes,s=i(9039),a=i(6469),o=s(function(){return!Array(1).includes()}),l=s(function(){return[,1].includes(void 0,1)});n({target:"Array",proto:!0,forced:o||l},{includes:function includes(t){return r(this,t,arguments.length>1?arguments[1]:void 0)}});a("includes")},4114(t,e,i){var n=i(6518),r=i(8981),s=i(6198),a=i(4527),o=i(6837);n({target:"Array",proto:!0,arity:1,forced:i(9039)(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 e=r(this),i=s(e),n=arguments.length;o(i+n);for(var l=0;l<n;l++){e[i]=arguments[l];i++}a(e,i);return i}})},8111(t,e,i){var n=i(6518),r=i(4576),s=i(679),a=i(8551),o=i(4901),l=i(2787),h=i(2106),c=i(4659),d=i(9039),u=i(9297),p=i(608),g=i(7657).IteratorPrototype,m=i(3724),f=i(6395),b="constructor",y="Iterator",v=p("toStringTag"),w=TypeError,A=r[y],x=f||!o(A)||A.prototype!==g||!d(function(){A({})}),E=function Iterator(){s(this,g);if(l(this)===g)throw new w("Abstract class Iterator not directly constructable")},defineIteratorPrototypeAccessor=function(t,e){m?h(g,t,{configurable:!0,get:function(){return e},set:function(e){a(this);if(this===g)throw new w("You can't redefine this property");u(this,t)?this[t]=e:c(this,t,e)}}):g[t]=e};u(g,v)||defineIteratorPrototypeAccessor(v,y);!x&&u(g,b)&&g[b]!==Object||defineIteratorPrototypeAccessor(b,E);E.prototype=g;n({global:!0,constructor:!0,forced:x},{Iterator:E})},9314(t,e,i){var n=i(6518),r=i(9565),s=i(8551),a=i(1767),o=i(4149),l=i(9590),h=i(9539),c=i(9462),d=i(684),u=i(4549),p=i(6395),g=!p&&!d("drop",0),m=!p&&!g&&u("drop",RangeError),f=p||g||m,b=c(function(){for(var t,e=this.iterator,i=this.next;this.remaining;){this.remaining--;t=s(r(i,e));if(this.done=!!t.done)return}t=s(r(i,e));if(!(this.done=!!t.done))return t.value});n({target:"Iterator",proto:!0,real:!0,forced:f},{drop:function drop(t){s(this);var e;try{e=l(o(+t))}catch(t){h(this,"throw",t)}return m?r(m,this,e):new b(a(this),{remaining:e})}})},1148(t,e,i){var n=i(6518),r=i(9565),s=i(2652),a=i(9306),o=i(8551),l=i(1767),h=i(9539),c=i(4549)("every",TypeError);n({target:"Iterator",proto:!0,real:!0,forced:c},{every:function every(t){o(this);try{a(t)}catch(t){h(this,"throw",t)}if(c)return r(c,this,t);var e=l(this),i=0;return!s(e,function(e,n){if(!t(e,i++))return n()},{IS_RECORD:!0,INTERRUPTED:!0}).stopped}})},2489(t,e,i){var n=i(6518),r=i(9565),s=i(9306),a=i(8551),o=i(1767),l=i(9462),h=i(6319),c=i(6395),d=i(9539),u=i(684),p=i(4549),g=!c&&!u("filter",function(){}),m=!c&&!g&&p("filter",TypeError),f=c||g||m,b=l(function(){for(var t,e,i=this.iterator,n=this.predicate,s=this.next;;){t=a(r(s,i));if(this.done=!!t.done)return;e=t.value;if(h(i,n,[e,this.counter++],!0))return e}});n({target:"Iterator",proto:!0,real:!0,forced:f},{filter:function filter(t){a(this);try{s(t)}catch(t){d(this,"throw",t)}return m?r(m,this,t):new b(o(this),{predicate:t})}})},116(t,e,i){var n=i(6518),r=i(9565),s=i(2652),a=i(9306),o=i(8551),l=i(1767),h=i(9539),c=i(4549)("find",TypeError);n({target:"Iterator",proto:!0,real:!0,forced:c},{find:function find(t){o(this);try{a(t)}catch(t){h(this,"throw",t)}if(c)return r(c,this,t);var e=l(this),i=0;return s(e,function(e,n){if(t(e,i++))return n(e)},{IS_RECORD:!0,INTERRUPTED:!0}).result}})},531(t,e,i){var n=i(6518),r=i(9565),s=i(9306),a=i(8551),o=i(1767),l=i(8646),h=i(9462),c=i(9539),d=i(6395),u=i(684),p=i(4549);var g=!d&&!u("flatMap",function(){}),m=!d&&!g&&p("flatMap",TypeError),f=d||g||m||function throwsOnIteratorWithoutReturn(){try{var t=Iterator.prototype.flatMap.call(new Map([[4,5]]).entries(),function(t){return t});t.next();t.return()}catch(t){return!0}}(),b=h(function(){for(var t,e,i=this.iterator,n=this.mapper;;){if(e=this.inner)try{if(!(t=a(r(e.next,e.iterator))).done)return t.value;this.inner=null}catch(t){c(i,"throw",t)}t=a(r(this.next,i));if(this.done=!!t.done)return;try{this.inner=l(n(t.value,this.counter++),!1)}catch(t){c(i,"throw",t)}}});n({target:"Iterator",proto:!0,real:!0,forced:f},{flatMap:function flatMap(t){a(this);try{s(t)}catch(t){c(this,"throw",t)}return m?r(m,this,t):new b(o(this),{mapper:t,inner:null})}})},7588(t,e,i){var n=i(6518),r=i(9565),s=i(2652),a=i(9306),o=i(8551),l=i(1767),h=i(9539),c=i(4549)("forEach",TypeError);n({target:"Iterator",proto:!0,real:!0,forced:c},{forEach:function forEach(t){o(this);try{a(t)}catch(t){h(this,"throw",t)}if(c)return r(c,this,t);var e=l(this),i=0;s(e,function(e){t(e,i++)},{IS_RECORD:!0})}})},1701(t,e,i){var n=i(6518),r=i(9565),s=i(9306),a=i(8551),o=i(1767),l=i(9462),h=i(6319),c=i(9539),d=i(684),u=i(4549),p=i(6395),g=!p&&!d("map",function(){}),m=!p&&!g&&u("map",TypeError),f=p||g||m,b=l(function(){var t=this.iterator,e=a(r(this.next,t));if(!(this.done=!!e.done))return h(t,this.mapper,[e.value,this.counter++],!0)});n({target:"Iterator",proto:!0,real:!0,forced:f},{map:function map(t){a(this);try{s(t)}catch(t){c(this,"throw",t)}return m?r(m,this,t):new b(o(this),{mapper:t})}})},3579(t,e,i){var n=i(6518),r=i(9565),s=i(2652),a=i(9306),o=i(8551),l=i(1767),h=i(9539),c=i(4549)("some",TypeError);n({target:"Iterator",proto:!0,real:!0,forced:c},{some:function some(t){o(this);try{a(t)}catch(t){h(this,"throw",t)}if(c)return r(c,this,t);var e=l(this),i=0;return s(e,function(e,n){if(t(e,i++))return n()},{IS_RECORD:!0,INTERRUPTED:!0}).stopped}})},4972(t,e,i){var n=i(6518),r=i(9565),s=i(8551),a=i(1767),o=i(4149),l=i(9590),h=i(9462),c=i(9539),d=i(684),u=i(4549),p=i(6395),g=!p&&!d("take",1),m=!p&&!g&&u("take",RangeError),f=p||g||m,b=h(function(){var t=this.iterator;if(!this.remaining--){this.done=!0;return c(t,"normal",void 0)}var e=s(r(this.next,t));if(!(this.done=!!e.done))return e.value});n({target:"Iterator",proto:!0,real:!0,forced:f},{take:function take(t){s(this);var e;try{e=l(o(+t))}catch(t){c(this,"throw",t)}return m?r(m,this,e):new b(a(this),{remaining:e})}})},9112(t,e,i){var n=i(6518),r=i(3724),s=i(4576),a=i(7751),o=i(9504),l=i(9565),h=i(4901),c=i(34),d=i(4376),u=i(9297),p=i(655),g=i(6198),m=i(4659),f=i(9039),b=i(8235),y=i(4495),v=s.JSON,w=s.Number,A=s.SyntaxError,x=v&&v.parse,E=a("Object","keys"),_=Object.getOwnPropertyDescriptor,T=o("".charAt),C=o("".slice),S=o(/./.exec),D=o([].push),P=/^\d$/,M=/^[1-9]$/,k=/^[\d-]$/,I=/^[\t\n\r ]$/,internalize=function(t,e,i,n){var r,s,a,o,h,p=t[e],m=n&&p===n.value,f=m&&"string"==typeof n.source?{source:n.source}:{};if(c(p)){var b=d(p),y=m?n.nodes:b?[]:{};if(b){r=y.length;a=g(p);for(o=0;o<a;o++)internalizeProperty(p,o,internalize(p,""+o,i,o<r?y[o]:void 0))}else{s=E(p);a=g(s);for(o=0;o<a;o++){h=s[o];internalizeProperty(p,h,internalize(p,h,i,u(y,h)?y[h]:void 0))}}}return l(i,t,e,p,f)},internalizeProperty=function(t,e,i){if(r){var n=_(t,e);if(n&&!n.configurable)return}void 0===i?delete t[e]:m(t,e,i)},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(I,this.index),i=this.fork(e),n=T(t,e);if(S(k,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 A('Unexpected character: "'+n+'" at: '+e)},node:function(t,e,i,n,r){return new Node(e,n,t?null:C(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("}"===T(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(I,e);a=this.fork(e).parse();m(r,o,a);m(n,o,a.value);e=this.until([",","}"],a.end);var l=T(t,e);if(","===l){i=!0;e++}else if("}"===l){e++;s=!0;break}}if(!s)throw new A("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(I,e);if("]"===T(t,e)&&!i){e++;s=!0;break}var a=this.fork(e).parse();D(r,a);D(n,a.value);e=this.until([",","]"],a.end);if(","===T(t,e)){i=!0;e++}else if("]"===T(t,e)){e++;s=!0;break}}if(!s)throw new A("Unterminated array at: "+e);return this.node(1,n,this.index,e,r)},string:function(){var t=this.index,e=b(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;"-"===T(t,i)&&i++;if("0"===T(t,i))i++;else{if(!S(M,T(t,i)))throw new A("Failed to parse number at: "+i);i=this.skip(P,i+1)}if("."===T(t,i)){var n=i+1;if(n===(i=this.skip(P,n)))throw new A("Failed to parse number's fraction at: "+i)}if("e"===T(t,i)||"E"===T(t,i)){i++;"+"!==T(t,i)&&"-"!==T(t,i)||i++;if(i===(i=this.skip(P,i)))throw new A("Failed to parse number's exponent value at: "+i)}return this.node(0,w(C(t,e,i)),e,i)},keyword:function(t){var e=""+t,i=this.index,n=i+e.length;if(C(this.source,i,n)!==e)throw new A("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&&S(t,T(i,e));e++);return e},until:function(t,e){e=this.skip(I,e);for(var i=T(this.source,e),n=0;n<t.length;n++)if(t[n]===i)return e;throw new A('Unexpected character: "'+i+'" at: '+e)}};var R=f(function(){var t,e="9007199254740993";x(e,function(e,i,n){t=n.source});return t!==e}),O=y&&!f(function(){return 1/x("-0 \t")!=-1/0});n({target:"JSON",stat:!0,forced:R},{parse:function parse(t,e){return O&&!h(e)?x(t):function(t,e){t=p(t);var i=new Context(t,0,""),n=i.parse(),r=n.value,s=i.skip(I,n.end);if(s<t.length)throw new A('Unexpected extra character: "'+T(t,s)+'" after the parsed data at: '+s);return h(e)?internalize({"":r},"",e,n):r}(t,e)}})},3110(t,e,i){var n=i(6518),r=i(7751),s=i(8745),a=i(9565),o=i(9504),l=i(9039),h=i(4376),c=i(4901),d=i(5810),u=i(757),p=i(2195),g=i(655),m=i(7680),f=i(8235),b=i(3392),y=i(4495),v=i(7819),w=String,A=r("JSON","stringify"),x=o(/./.exec),E=o("".charAt),_=o("".charCodeAt),T=o("".replace),C=o("".slice),S=o([].push),D=o(1.1.toString),P=/[\uD800-\uDFFF]/g,M=/^[\uD800-\uDBFF]$/,k=/^[\uDC00-\uDFFF]$/,I=b(),R=I.length,O=!y||l(function(){var t=r("Symbol")("stringify detection");return"[null]"!==A([t])||"{}"!==A({a:t})||"{}"!==A(Object(t))}),B=l(function(){return'"\\udf06\\ud834"'!==A("\udf06\ud834")||'"\\udead"'!==A("\udead")}),L=O?function(t,e){var i=m(arguments),n=getReplacerFunction(e);if(c(n)||void 0!==t&&!u(t)){i[1]=function(t,e){c(n)&&(e=a(n,this,w(t),e));if(!u(e))return e};return s(A,null,i)}}:A,fixIllFormedJSON=function(t,e,i){var n=E(i,e-1),r=E(i,e+1);return x(M,t)&&!x(k,r)||x(k,t)&&!x(M,n)?"\\u"+D(_(t,0),16):t},getReplacerFunction=function(t){if(c(t))return t;if(h(t)){for(var e=t.length,i=[],n=0;n<e;n++){var r=t[n];"string"==typeof r?S(i,r):"number"!=typeof r&&"Number"!==p(r)&&"String"!==p(r)||S(i,g(r))}var s=i.length,a=!0;return function(t,e){if(a){a=!1;return e}if(h(this))return e;for(var n=0;n<s;n++)if(i[n]===t)return e}}};A&&n({target:"JSON",stat:!0,arity:3,forced:O||B||!v},{stringify:function stringify(t,e,i){var n=getReplacerFunction(e),r=[],s=L(t,function(t,e){var i=c(n)?a(n,this,w(t),e):e;return!v&&d(i)?I+(S(r,i.rawJSON)-1):i},i);if("string"!=typeof s)return s;B&&(s=T(s,P,fixIllFormedJSON));if(v)return s;for(var o="",l=s.length,h=0;h<l;h++){var u=E(s,h);if('"'===u){var p=f(s,++h).end-1,g=C(s,h,p);o+=C(g,0,R)===I?r[C(g,R)]:'"'+g+'"';h=p}else o+=u}return o}})},2731(t,e,i){var n=i(6518),r=i(9306),s=i(2248),a=i(6395),o=s.get,l=s.has,h=s.set;n({target:"Map",proto:!0,real:!0,forced:a},{getOrInsertComputed:function getOrInsertComputed(t,e){var i=l(this,t);r(e);if(i)return o(this,t);0===t&&1/t==-1/0&&(t=0);var n=e(t);h(this,t,n);return n}})},5367(t,e,i){var n=i(6518),r=i(2248),s=i(6395),a=r.get,o=r.has,l=r.set;n({target:"Map",proto:!0,real:!0,forced:s},{getOrInsert:function getOrInsert(t,e){if(o(this,t))return a(this,t);l(this,t,e);return e}})},3068(t,e,i){var n=i(6518),r=i(9504),s=i(2652),a=RangeError,o=TypeError,l=1/0,h=Math.abs,c=Math.pow,d=r([].push),u=c(2,1023),p=c(2,53)-1,g=Number.MAX_VALUE,m=c(2,971),f={},b={},y={},v={},w={},twosum=function(t,e){var i=t+e;return{hi:i,lo:e-(i-t)}};n({target:"Math",stat:!0},{sumPrecise:function sumPrecise(t){var e=[],i=0,n=v;s(t,function(t){if(++i>p)throw new a("Maximum allowed index exceeded");if("number"!=typeof t)throw new o("Value is not a number");if(n!==f)if(t!=t)n=f;else if(t===l)n=n===b?f:y;else if(t===-1/0)n=n===y?f:b;else if(!(0===t&&1/t!==l||n!==v&&n!==w)){n=w;d(e,t)}});switch(n){case f:return NaN;case b:return-1/0;case y:return l;case v:return-0}for(var r,c,A,x,E,_,T=[],C=0,S=0;S<e.length;S++){r=e[S];for(var D=0,P=0;P<T.length;P++){c=T[P];if(h(r)<h(c)){_=r;r=c;c=_}x=(A=twosum(r,c)).hi;E=A.lo;if(h(x)===l){var M=x===l?1:-1;C+=M;if(h(r=r-M*u-M*u)<h(c)){_=r;r=c;c=_}x=(A=twosum(r,c)).hi;E=A.lo}0!==E&&(T[D++]=E);r=x}T.length=D;0!==r&&d(T,r)}var k=T.length-1;x=0;E=0;if(0!==C){var I=k>=0?T[k]:0;k--;if(h(C)>1||C>0&&I>0||C<0&&I<0)return C>0?l:-1/0;x=(A=twosum(C*u,I/2)).hi;E=A.lo;E*=2;if(h(2*x)===l)return x>0?x===u&&E===-m/2&&k>=0&&T[k]<0?g:l:x===-u&&E===m/2&&k>=0&&T[k]>0?-g:-1/0;if(0!==E){T[++k]=E;E=0}x*=2}for(;k>=0;){x=(A=twosum(x,T[k--])).hi;if(0!==(E=A.lo))break}k>=0&&(E<0&&T[k]<0||E>0&&T[k]>0)&&(c=2*E)===(r=x+c)-x&&(x=r);return x}})},1689(t,e,i){var n=i(6518),r=i(4576),s=i(8745),a=i(7680),o=i(6043),l=i(9306),h=i(1103),c=r.Promise,d=!1;n({target:"Promise",stat:!0,forced:!c||!c.try||h(function(){c.try(function(t){d=8===t},8)}).error||!d},{try:function(t){var e=arguments.length>1?a(arguments,1):[],i=o.f(this),n=h(function(){return s(l(t),void 0,e)});(n.error?i.reject:i.resolve)(n.value);return i.promise}})},4628(t,e,i){var n=i(6518),r=i(6043);n({target:"Promise",stat:!0},{withResolvers:function withResolvers(){var t=r.f(this);return{promise:t.promise,resolve:t.resolve,reject:t.reject}}})},7642(t,e,i){var n=i(6518),r=i(3440),s=i(9039);n({target:"Set",proto:!0,real:!0,forced:!i(4916)("difference",function(t){return 0===t.size})||s(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:r})},8004(t,e,i){var n=i(6518),r=i(9039),s=i(8750);n({target:"Set",proto:!0,real:!0,forced:!i(4916)("intersection",function(t){return 2===t.size&&t.has(1)&&t.has(2)})||r(function(){return"3,2"!==String(Array.from(new Set([1,2,3]).intersection(new Set([3,2]))))})},{intersection:s})},3853(t,e,i){var n=i(6518),r=i(4449);n({target:"Set",proto:!0,real:!0,forced:!i(4916)("isDisjointFrom",function(t){return!t})},{isDisjointFrom:r})},5876(t,e,i){var n=i(6518),r=i(3838);n({target:"Set",proto:!0,real:!0,forced:!i(4916)("isSubsetOf",function(t){return t})},{isSubsetOf:r})},2475(t,e,i){var n=i(6518),r=i(8527);n({target:"Set",proto:!0,real:!0,forced:!i(4916)("isSupersetOf",function(t){return!t})},{isSupersetOf:r})},5024(t,e,i){var n=i(6518),r=i(3650),s=i(9835);n({target:"Set",proto:!0,real:!0,forced:!i(4916)("symmetricDifference")||!s("symmetricDifference")},{symmetricDifference:r})},1698(t,e,i){var n=i(6518),r=i(4204),s=i(9835);n({target:"Set",proto:!0,real:!0,forced:!i(4916)("union")||!s("union")},{union:r})},9577(t,e,i){var n=i(4644),r=i(1108),s=i(6198),a=i(1291),o=i(5854),l=n.aTypedArray,h=n.getTypedArrayConstructor,c=n.exportTypedArrayMethod,d=RangeError,u=function(){try{new Int8Array(1).with(2,{valueOf:function(){throw 8}})}catch(t){return 8===t}}(),p=u&&function(){try{new Int8Array(1).with(-.5,1)}catch(t){return!0}}();c("with",{with:function(t,e){var i=l(this),n=s(i),c=a(t),u=c<0?n+c:c,p=r(i)?o(e):+e;if(u>=n||u<0)throw new d("Incorrect index");for(var g=new(h(i))(n),m=0;m<n;m++)g[m]=m===u?p:i[m];return g}}.with,!u||p)},5213(t,e,i){var n=i(6518),r=i(4576),s=i(5370),a=i(9143),o=r.Uint8Array,l=!o||!o.fromBase64||!function(){try{o.fromBase64("a");return}catch(t){}try{o.fromBase64("",null)}catch(t){return!0}}();o&&n({target:"Uint8Array",stat:!0,forced:l},{fromBase64:function fromBase64(t){var e=a(t,arguments.length>1?arguments[1]:void 0,null,9007199254740991);return s(o,e.bytes)}})},6632(t,e,i){var n=i(6518),r=i(4576),s=i(9143),a=i(4154),o=r.Uint8Array,l=!o||!o.prototype.setFromBase64||!function(){var t=new o([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]}}();o&&n({target:"Uint8Array",proto:!0,forced:l},{setFromBase64:function setFromBase64(t){a(this);var e=s(t,arguments.length>1?arguments[1]:void 0,this,this.length);return{read:e.read,written:e.written}}})},4226(t,e,i){var n=i(6518),r=i(4576),s=i(3463),a=i(4154),o=i(5169),l=i(2303);r.Uint8Array&&n({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){a(this);s(t);o(this.buffer);var e=l(t,this).read;return{read:e,written:e/2}}})},9486(t,e,i){var n=i(6518),r=i(4576),s=i(9504),a=i(3972),o=i(4154),l=i(5169),h=i(2804),c=i(944),d=h.i2c,u=h.i2cUrl,p=s("".charAt),g=r.Uint8Array,m=!g||!g.prototype.toBase64||!function(){try{(new g).toBase64(null)}catch(t){return!0}}();g&&n({target:"Uint8Array",proto:!0,forced:m},{toBase64:function toBase64(){var t=o(this),e=arguments.length?a(arguments[0]):void 0,i="base64"===c(e)?d:u,n=!!e&&!!e.omitPadding;l(this.buffer);for(var r,s="",h=0,g=t.length,at=function(t){return p(i,r>>6*t&63)};h+2<g;h+=3){r=(t[h]<<16)+(t[h+1]<<8)+t[h+2];s+=at(3)+at(2)+at(1)+at(0)}if(h+2===g){r=(t[h]<<16)+(t[h+1]<<8);s+=at(3)+at(2)+at(1)+(n?"":"=")}else if(h+1===g){r=t[h]<<16;s+=at(3)+at(2)+(n?"":"==")}return s}})},456(t,e,i){var n=i(6518),r=i(4576),s=i(9504),a=i(4154),o=i(5169),l=s(1.1.toString),h=s([].join),c=Array,d=r.Uint8Array,u=!d||!d.prototype.toHex||!function(){try{return"ffffffffffffffff"===new d([255,255,255,255,255,255,255,255]).toHex()}catch(t){return!1}}();d&&n({target:"Uint8Array",proto:!0,forced:u},{toHex:function toHex(){a(this);o(this.buffer);for(var t=c(this.length),e=0,i=this.length;e<i;e++){var n=l(this[e],16);t[e]=1===n.length?"0"+n:n}return h(t,"")}})},9452(t,e,i){var n=i(6518),r=i(9306),s=i(6557),a=i(4328),o=i(4995),l=i(6395),h=o.get,c=o.has,d=o.set;n({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,e){l||s(this);a(t);r(e);if(c(this,t))return h(this,t);var i=e(t);d(this,t,i);return i}})},8454(t,e,i){var n=i(6518),r=i(4995),s=i(6395),a=r.get,o=r.has,l=r.set;n({target:"WeakMap",proto:!0,real:!0,forced:s},{getOrInsert:function getOrInsert(t,e){if(o(this,t))return a(this,t);l(this,t,e);return e}})},4979(t,e,i){var n=i(6518),r=i(4576),s=i(7751),a=i(6980),o=i(4913).f,l=i(9297),h=i(679),c=i(3167),d=i(2603),u=i(5002),p=i(8574),g=i(3724),m=i(6395),f="DOMException",b=s("Error"),y=s(f),v=function DOMException(){h(this,w);var t=arguments.length,e=d(t<1?void 0:arguments[0]),i=d(t<2?void 0:arguments[1],"Error"),n=new y(e,i),r=new b(e);r.name=f;o(n,"stack",a(1,p(r.stack,1)));c(n,this,v);return n},w=v.prototype=y.prototype,A="stack"in new b(f),x="stack"in new y(1,2),E=y&&g&&Object.getOwnPropertyDescriptor(r,f),_=!(!E||E.writable&&E.configurable),T=A&&!_&&!x;n({global:!0,constructor:!0,forced:m||T},{DOMException:T?v:y});var C=s(f),S=C.prototype;if(S.constructor!==C){m||o(S,"constructor",a(1,C));for(var D in u)if(l(u,D)){var P=u[D],M=P.s;l(C,M)||o(C,M,a(6,P.c))}}},4603(t,e,i){var n=i(6840),r=i(9504),s=i(655),a=i(2812),o=URLSearchParams,l=o.prototype,h=r(l.append),c=r(l.delete),d=r(l.forEach),u=r([].push),p=new o("a=1&a=2&b=3");p.delete("a",1);p.delete("b",void 0);p+""!="a=2"&&n(l,"delete",function(t){var e=arguments.length,i=e<2?void 0:arguments[1];if(e&&void 0===i)return c(this,t);var n=[];d(this,function(t,e){u(n,{key:e,value:t})});a(e,1);for(var r,o=s(t),l=s(i),p=0,g=n.length;p<g;){c(this,(r=n[p]).key);p++}p=0;for(;p<g;)(r=n[p++]).key===o&&r.value===l||h(this,r.key,r.value)},{enumerable:!0,unsafe:!0})},7566(t,e,i){var n=i(6840),r=i(9504),s=i(655),a=i(2812),o=URLSearchParams,l=o.prototype,h=r(l.getAll),c=r(l.has),d=new o("a=1");!d.has("a",2)&&d.has("a",void 0)||n(l,"has",function has(t){var e=arguments.length,i=e<2?void 0:arguments[1];if(e&&void 0===i)return c(this,t);var n=h(this,t);a(e,1);for(var r=s(i),o=0;o<n.length;)if(n[o++]===r)return!0;return!1},{enumerable:!0,unsafe:!0})},8721(t,e,i){var n=i(3724),r=i(9504),s=i(2106),a=URLSearchParams.prototype,o=r(a.forEach);n&&!("size"in a)&&s(a,"size",{get:function size(){var t=0;o(this,function(){t++});return t},configurable:!0,enumerable:!0})},5781(t,e,i){var n=i(6518),r=i(7751),s=i(2812),a=i(655),o=i(7416),l=r("URL");n({target:"URL",stat:!0,forced:!o},{parse:function parse(t){var e=s(arguments.length,1),i=a(t),n=e<2||void 0===arguments[1]?void 0:a(arguments[1]);try{return new l(i,n)}catch(t){return null}}})}},e={};function __webpack_require__(i){var n=e[i];if(void 0!==n)return n.exports;var r=e[i]={exports:{}};t[i].call(r.exports,r,r.exports,__webpack_require__);return r.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);__webpack_require__(4423),__webpack_require__(4114),__webpack_require__(6573),__webpack_require__(8100),__webpack_require__(7936),__webpack_require__(5367),__webpack_require__(2731),__webpack_require__(9577),__webpack_require__(6632),__webpack_require__(4226),__webpack_require__(9486),__webpack_require__(456),__webpack_require__(5781);const i=!("object"!=typeof process||process+""!="[object process]"||process.versions.nw||process.versions.electron&&process.type&&"browser"!==process.type),n=[1/0,1/0,-1/0,-1/0],r=new Float32Array(n),s=[.001,0,0,.001,0,0],a=1.35,o=1,l=2,h=4,c=16,d=32,u=64,p=128,g=256,m={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},f="pdfjs_internal_editor_",b={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101,COMMENT:102},y={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},v={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},w=0,A=1,x=2,E=3,_=3,T=4,C={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},S={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},D=1,P=2,M=3,k=4,I=5,R={ERRORS:0,WARNINGS:1,INFOS:5},O={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},B=0,L=1,N=2,U=3,H=4,z={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let j=R.WARNINGS;function setVerbosityLevel(t){Number.isInteger(t)&&(j=t)}function getVerbosityLevel(){return j}function info(t){j>=R.INFOS&&console.info(`Info: ${t}`)}function warn(t){j>=R.WARNINGS&&console.warn(`Warning: ${t}`)}function unreachable(t){throw new Error(t)}function 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 shadow(t,e,i,n=!1){Object.defineProperty(t,e,{value:i,enumerable:!n,configurable:!0,writable:!1});return i}const G=function BaseExceptionClosure(){function BaseException(t,e){this.message=t;this.name=e}BaseException.prototype=new Error;BaseException.constructor=BaseException;return BaseException}();class PasswordException extends G{constructor(t,e){super(t,"PasswordException");this.code=e}}class UnknownErrorException extends G{constructor(t,e){super(t,"UnknownErrorException");this.details=e}}class InvalidPDFException extends G{constructor(t){super(t,"InvalidPDFException")}}class ResponseException extends G{constructor(t,e,i){super(t,"ResponseException");this.status=e;this.missing=i}}class FormatError extends G{constructor(t){super(t,"FormatError")}}class AbortException extends G{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(){return shadow(this,"isLittleEndian",function isLittleEndian(){const t=new Uint8Array(4);t[0]=1;return 1===new Uint32Array(t.buffer,0,1)[0]}())}static get isOffscreenCanvasSupported(){return shadow(this,"isOffscreenCanvasSupported","undefined"!=typeof OffscreenCanvas)}static get isImageDecoderSupported(){return shadow(this,"isImageDecoderSupported","undefined"!=typeof ImageDecoder)}static get isFloat16ArraySupported(){return shadow(this,"isFloat16ArraySupported","undefined"!=typeof Float16Array)}static get isSanitizerSupported(){return shadow(this,"isSanitizerSupported","undefined"!=typeof Sanitizer)}static get platform(){const{platform:t,userAgent:e}=navigator;return shadow(this,"platform",{isAndroid:e.includes("Android"),isLinux:t.includes("Linux"),isMac:t.includes("Mac"),isWindows:t.includes("Win"),isFirefox:e.includes("Firefox")})}static get isCSSRoundSupported(){return shadow(this,"isCSSRoundSupported",globalThis.CSS?.supports?.("width: round(1.5px, 1px)"))}static get isAlphaColorInputSupported(){return shadow(this,"isAlphaColorInputSupported",(()=>{if("undefined"==typeof document)return!1;const t=document.createElement("input");t.type="color";t.setAttribute("alpha","");t.value="#ff000080";return"#ff0000"!==t.value})())}}class Util{static get hexNums(){return shadow(this,"hexNums",Array.from(Array(256).keys(),t=>t.toString(16).padStart(2,"0")))}static makeHexColor(t,e,i){return`#${this.hexNums[t]}${this.hexNums[e]}${this.hexNums[i]}`}static domMatrixToTransform(t){return[t.a,t.b,t.c,t.d,t.e,t.f]}static scaleMinMax(t,e){let i;if(t[0]){if(t[0]<0){i=e[0];e[0]=e[2];e[2]=i}e[0]*=t[0];e[2]*=t[0];if(t[3]<0){i=e[1];e[1]=e[3];e[3]=i}e[1]*=t[3];e[3]*=t[3]}else{i=e[0];e[0]=e[1];e[1]=i;i=e[2];e[2]=e[3];e[3]=i;if(t[1]<0){i=e[1];e[1]=e[3];e[3]=i}e[1]*=t[1];e[3]*=t[1];if(t[2]<0){i=e[0];e[0]=e[2];e[2]=i}e[0]*=t[2];e[2]*=t[2]}e[0]+=t[4];e[1]+=t[5];e[2]+=t[4];e[3]+=t[5]}static transform(t,e){return[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]]}static multiplyByDOMMatrix(t,e){return[t[0]*e.a+t[2]*e.b,t[1]*e.a+t[3]*e.b,t[0]*e.c+t[2]*e.d,t[1]*e.c+t[3]*e.d,t[0]*e.e+t[2]*e.f+t[4],t[1]*e.e+t[3]*e.f+t[5]]}static applyTransform(t,e,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 h=t[i+e],c=t[i+e+1];t[i+e]=h*n+c*s+o;t[i+e+1]=h*r+c*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],h=t[0],c=t[1],d=t[2],u=t[3];let p=n*h+o,g=p,m=n*d+o,f=m,b=a*c+l,y=b,v=a*u+l,w=v;if(0!==r||0!==s){const t=r*h,e=r*d,i=s*c,n=s*u;p+=i;f+=i;m+=n;g+=n;b+=t;w+=t;v+=e;y+=e}i[0]=Math.min(i[0],p,m,g,f);i[1]=Math.min(i[1],b,v,y,w);i[2]=Math.max(i[2],p,m,g,f);i[3]=Math.max(i[3],b,v,y,w)}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,h=(a+l)/2,c=Math.sqrt(h**2-(a*l-o**2));e[0]=Math.sqrt(h+c||1);e[1]=Math.sqrt(h-c||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,h){if(l<=0||l>=1)return;const c=1-l,d=l*l,u=d*l,p=c*(c*(c*t+3*l*e)+3*d*i)+u*n,g=c*(c*(c*r+3*l*s)+3*d*a)+u*o;h[0]=Math.min(h[0],p);h[1]=Math.min(h[1],g);h[2]=Math.max(h[2],p);h[3]=Math.max(h[3],g)}static#e(t,e,i,n,r,s,a,o,l,h,c,d){if(Math.abs(l)<1e-12){Math.abs(h)>=1e-12&&this.#t(t,e,i,n,r,s,a,o,-c/h,d);return}const u=h**2-4*c*l;if(u<0)return;const p=Math.sqrt(u),g=2*l;this.#t(t,e,i,n,r,s,a,o,(-h+p)/g,d);this.#t(t,e,i,n,r,s,a,o,(-h-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 W=null,V=null;function normalizeUnicode(t){if(!W){W=/([\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;V=new Map([["ſt","ſt"]])}return t.replaceAll(W,(t,e,i)=>e?e.normalize("NFKC"):V.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 $="pdfjs_internal_id_";const makeArr=()=>[],makeMap=()=>new Map,makeObj=()=>Object.create(null);"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 AbortSignal.any&&(AbortSignal.any=function(t){const e=new AbortController,{signal:i}=e;for(const n of t)if(n.aborted){e.abort(n.reason);return i}for(const n of t)n.addEventListener("abort",()=>{e.abort(n.reason)},{signal:i});return i});__webpack_require__(8111),__webpack_require__(1701),__webpack_require__(4603),__webpack_require__(7566),__webpack_require__(8721);function MathClamp(t,e,i){return Math.min(Math.max(t,e),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)}}class XfaLayer{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)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":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 render(t){const e=t.annotationStorage,i=t.linkService,n=t.xfaHtml,r=t.intent||"display",s=document.createElement(n.name);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 h=[[n,-1,s]];for(;h.length>0;){const[t,n,s]=h.at(-1);if(n+1===t.children.length){h.pop();continue}const o=t.children[++h.at(-1)[1]];if(null===o)continue;const{name:c}=o;if("#text"===c){const t=document.createTextNode(o.value);l.push(t);s.append(t);continue}const d=o?.attributes?.xmlns?document.createElementNS(o.attributes.xmlns,c):document.createElement(c);s.append(d);o.attributes&&this.setAttributes({html:d,element:o,storage:e,intent:r,linkService:i});if(o.children?.length>0)h.push([o,-1,d]);else if(o.value){const t=document.createTextNode(o.value);a&&XfaText.shouldBuildText(c)&&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}}const q="http://www.w3.org/2000/svg";class PixelsPerInch{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}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)})}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 h,c,d,u,p,g,m,f;(n%=360)<0&&(n+=360);switch(n){case 180:h=-1;c=0;d=0;u=1;break;case 90:h=0;c=1;d=1;u=0;break;case 270:h=0;c=-1;d=-1;u=0;break;case 0:h=1;c=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===h){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=[h*i,c*i,d*i,u*i,p-h*i*o-d*i*l,g-c*i*o-u*i*l];this.width=m;this.height=f}get rawDims(){const t=this.viewBox;return 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}convertToViewportRectangle(t){const e=[t[0],t[1]];Util.applyTransform(e,this.transform);const i=[t[2],t[3]];Util.applyTransform(i,this.transform);return[e[0],e[1],i[0],i[1]]}convertToPdfPoint(t,e){const i=[t,e];Util.applyInverseTransform(i,this.transform);return i}}class RenderingCancelledException extends G{constructor(t,e=0){super(t,"RenderingCancelledException");this.extraDelay=e}}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(/^\.pdf$/i.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 t=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i.exec(i.hash);if(t)return decode(t[0])}return e}class StatTimer{#i=new Map;times=[];time(t){this.#i.has(t)&&warn(`Timer is already running for ${t}`);this.#i.set(t,Date.now())}timeEnd(t){this.#i.has(t)||warn(`Timer has not been started for ${t}`);this.times.push({name:t,start:this.#i.get(t),end:Date.now()});this.#i.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("")}}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 h=parseInt(e[8],10);h=h>=0&&h<=23?h:0;let c=parseInt(e[9],10)||0;c=c>=0&&c<=59?c:0;if("-"===l){s+=h;a+=c}else if("+"===l){s-=h;a-=c}return new Date(Date.UTC(i,n,r,s,a,o))}}function getXfaPageViewport(t,{scale:e=1,rotation:i=0}){const{width:n,height:r}=t.attributes.style,s=[0,0,parseInt(n,10),parseInt(r,10)];return new PageViewport({viewBox:s,userUnit:1,scale:e,rotation:i})}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]}function setLayerDimensions(t,e,i=!1,n=!0){if(e instanceof PageViewport){const{pageWidth:n,pageHeight:r}=e.rawDims,{style:s}=t,a=FeatureTest.isCSSRoundSupported,o=`var(--total-scale-factor) * ${n}px`,l=`var(--total-scale-factor) * ${r}px`,h=a?`round(down, ${o}, var(--scale-round-x))`:`calc(${o})`,c=a?`round(down, ${l}, var(--scale-round-y))`:`calc(${l})`;if(i&&e.rotation%180!=0){s.width=c;s.height=h}else{s.width=h;s.height=c}}n&&t.setAttribute("data-main-rotation",e.rotation)}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}}const X=["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 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 shadow(this,"commentForegroundColor",getRGB(i))}}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 Y=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=Y.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,h=l?12:4.5;a[2]=l?Math.sqrt(a[2]):1-Math.sqrt(1-a[2]);if(contrastRatio(a,o,s)<h){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)<h?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]));Y.set(i,n);return n}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)}function makePathFromDrawOPS(t){const e=new Path2D;if(!t)return e;for(let i=0,n=t.length;i<n;)switch(t[i++]){case B:e.moveTo(t[i++],t[i++]);break;case L:e.lineTo(t[i++],t[i++]);break;case N:e.bezierCurveTo(t[i++],t[i++],t[i++],t[i++],t[i++],t[i++]);break;case U:e.quadraticCurveTo(t[i++],t[i++],t[i++],t[i++]);break;case H:e.closePath();break;default:warn(`Unrecognized drawing path operator: ${t[i-1]}`)}return e}__webpack_require__(4972),__webpack_require__(4628),__webpack_require__(7642),__webpack_require__(8004),__webpack_require__(3853),__webpack_require__(5876),__webpack_require__(2475),__webpack_require__(5024),__webpack_require__(1698),__webpack_require__(8454),__webpack_require__(9452),__webpack_require__(4979),__webpack_require__(3579),__webpack_require__(3110),__webpack_require__(9314),__webpack_require__(1148),__webpack_require__(9112);class EditorToolbar{#r=null;#s=null;#a;#o=null;#l=null;#h=null;#c=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.#h?.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.#h)return;const i=t.renderForToolbar();if(!i)return;this.#f(i);const n=this.#c=this.#b;if(e){this.#o.insertBefore(i,e);this.#o.insertBefore(n,e)}else this.#o.append(i,n);this.#h=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);this.#f(e);this.#o.append(e,this.#b)}removeButton(t){if("comment"===t){this.#h?.removeToolbarCommentButton();this.#h=null;this.#c?.remove();this.#c=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}#v(){const t=this.#r=document.createElement("div");t.className="editToolbar";t.setAttribute("role","toolbar");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.#w("commentButton","pdfjs-comment-floating-button","pdfjs-comment-floating-button-label",()=>{this.#y.commentSelection("floating_button")});this.#w("highlightButton","pdfjs-highlight-floating-button1","pdfjs-highlight-floating-button-label",()=>{this.#y.highlightSelection("floating_button")});return t}#A(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.#A(e,i),{style:s}=this.#r||=this.#v();t.append(this.#r);s.insetInlineEnd=100*n+"%";s.top=`calc(${100*r}% + var(--editor-toolbar-vert-offset))`}hide(){this.#r.remove()}#w(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)}}function bindEvents(t,e,i){for(const n of i)e.addEventListener(n,t[n].bind(t))}class CurrentPointers{static#x=NaN;static#E=null;static#_=NaN;static#T=null;static initializeAndAddPointerId(t){(CurrentPointers.#E||=new Set).add(t)}static setPointer(t,e){CurrentPointers.#x||=e;CurrentPointers.#T??=t}static setTimeStamp(t){CurrentPointers.#_=t}static isSamePointerId(t){return CurrentPointers.#x===t}static isSamePointerIdOrRemove(t){if(CurrentPointers.#x===t)return!0;CurrentPointers.#E?.delete(t);return!1}static isSamePointerType(t){return CurrentPointers.#T===t}static isInitializedAndDifferentPointerType(t){return null!==CurrentPointers.#T&&!CurrentPointers.isSamePointerType(t)}static isSameTimeStamp(t){return CurrentPointers.#_===t}static isUsingMultiplePointers(){return CurrentPointers.#E?.size>=1}static clearPointerType(){CurrentPointers.#T=null}static clearPointerIds(){CurrentPointers.#x=NaN;CurrentPointers.#E=null}static clearTimeStamp(){CurrentPointers.#_=NaN}}class IdManager{#C=0;get id(){return`${f}${this.#C++}`}}class ImageManager{#S=getUuid();#C=0;#D=null;static get _isSVGFittingCanvas(){const t=new OffscreenCanvas(1,3).getContext("2d",{willReadFrequently:!0}),e=new Image;e.src='data:image/svg+xml;charset=UTF-8,<svg viewBox="0 0 1 1" width="1" height="1" xmlns="http://www.w3.org/2000/svg"><rect width="1" height="1" style="fill:red;"/></svg>';return shadow(this,"_isSVGFittingCanvas",e.decode().then(()=>{t.drawImage(e,0,0,1,1,0,0,1,3);return 0===new Uint32Array(t.getImageData(0,0,1,1).data.buffer)[0]}))}async#P(t,e){this.#D||=new Map;let i=this.#D.get(t);if(null===i)return null;if(i?.bitmap){i.refCounter+=1;return i}try{i||={bitmap:null,id:`image_${this.#S}_${this.#C++}`,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.#D.set(t,i);i&&this.#D.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.#D||=new Map;const e=this.#D.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.#D||=new Map;let i=this.#D.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.#S}_${this.#C++}`,refCounter:1,isSvg:!1};this.#D.set(t,i);this.#D.set(i.id,i);return i}getSvgUrl(t){const e=this.#D.get(t);return e?.isSvg?e.svgUrl:null}deleteId(t){this.#D||=new Map;const e=this.#D.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.#S}_`)}}class CommandManager{#M=[];#k=!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.#k)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.#k=!0;const{undo:t,post:e}=this.#M[this.#F];t();e?.();this.#k=!1;this.#F-=1}redo(){if(this.#F<this.#M.length-1){this.#F+=1;this.#k=!0;const{cmd:t,post:e}=this.#M[this.#F];t();e?.();this.#k=!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{constructor(t){this.buffer=[];this.callbacks=new Map;this.allKeys=new Set;const{isMac:e}=FeatureTest.platform;for(const[i,n,r={}]of t)for(const t of i){const i=t.startsWith("mac+");if(e&&i){this.callbacks.set(t.slice(4),{callback:n,options:r});this.allKeys.add(t.split("+").at(-1))}else if(!e&&!i){this.callbacks.set(t,{callback:n,options:r});this.allKeys.add(t.split("+").at(-1))}}}#R(t){t.altKey&&this.buffer.push("alt");t.ctrlKey&&this.buffer.push("ctrl");t.metaKey&&this.buffer.push("meta");t.shiftKey&&this.buffer.push("shift");this.buffer.push(t.key);const e=this.buffer.join("+");this.buffer.length=0;return e}exec(t,e){if(!this.allKeys.has(e.key))return;const i=this.callbacks.get(this.#R(e));if(!i)return;const{callback:n,options:{bubbles:r=!1,args:s=[],checker:a=null}}=i;if(!a||a(t,e)){n.bind(t,...s,e)();r||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 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{#O=new AbortController;#B=null;#L=null;#N=new Map;#U=new Map;#H=null;#z=null;#j=null;#G=null;#W=new CommandManager;#V=null;#$=null;#q=null;#X=0;#Y=new Set;#K=null;#J=null;#Q=new Set;_editorUndoBar=null;#Z=!1;#tt=!1;#et=!1;#it=null;#nt=null;#rt=null;#st=null;#at=!1;#ot=null;#lt=new IdManager;#ht=!1;#ct=!1;#dt=!1;#ut=null;#pt=null;#gt=null;#mt=null;#ft=null;#bt=b.NONE;#yt=new Set;#vt=null;#wt=null;#At=null;#xt=null;#Et=null;#_t={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#Tt=[0,0];#Ct=null;#St=null;#Dt=null;#Pt=null;#Mt=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){const t=AnnotationEditorUIManager.prototype,arrowChecker=t=>t.#St.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 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","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#St.contains(e)&&!t.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#St.contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-e,0],checker:arrowChecker}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-i,0],checker:arrowChecker}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[e,0],checker:arrowChecker}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[i,0],checker:arrowChecker}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-e],checker:arrowChecker}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-i],checker:arrowChecker}],[["ArrowDown","mac+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,h,c,d,u,p,g,m){const f=this._signal=this.#O.signal;this.#St=t;this.#Dt=e;this.#Pt=i;this.#z=n;this.#V=r;this.#wt=s;this.#Et=o;this._eventBus=a;a._on("editingaction",this.onEditingAction.bind(this),{signal:f});a._on("pagechanging",this.onPageChanging.bind(this),{signal:f});a._on("scalechanging",this.onScaleChanging.bind(this),{signal:f});a._on("rotationchanging",this.onRotationChanging.bind(this),{signal:f});a._on("setpreference",this.onSetPreference.bind(this),{signal:f});a._on("switchannotationeditorparams",t=>this.updateParams(t.type,t.value),{signal:f});window.addEventListener("pointerdown",()=>{this.#ct=!0},{capture:!0,signal:f});window.addEventListener("pointerup",()=>{this.#ct=!1},{capture:!0,signal:f});window.addEventListener("beforeunload",this.#kt.bind(this),{capture:!0,signal:f});this.#It();this.#Ft();this.#Rt();this.#j=o.annotationStorage;this.#it=o.filterFactory;this.#At=l;this.#st=h||null;this.#Z=c;this.#tt=d;this.#et=u;this.#ft=p||null;this.viewParameters={realScale:PixelsPerInch.PDF_TO_CSS_UNITS,rotation:0};this.isShiftKeyDown=!1;this._editorUndoBar=g||null;this._supportsPinchToZoom=!1!==m;r?.setSidebarUiManager(this)}destroy(){this.#Mt?.resolve();this.#Mt=null;this.#O?.abort();this.#O=null;this._signal=null;for(const t of this.#U.values())t.destroy();this.#U.clear();this.#N.clear();this.#Q.clear();this.#mt?.clear();this.#B=null;this.#yt.clear();this.#W.destroy();this.#z?.destroy();this.#V?.destroy();this.#wt?.destroy();this.#ot?.hide();this.#ot=null;this.#gt?.destroy();this.#gt=null;this.#L=null;if(this.#nt){clearTimeout(this.#nt);this.#nt=null}if(this.#Ct){clearTimeout(this.#Ct);this.#Ct=null}this._editorUndoBar?.destroy();this.#Et=null}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return this.#ft}get useNewAltTextFlow(){return this.#tt}get useNewAltTextWhenAddingImage(){return this.#et}get hcmFilter(){return shadow(this,"hcmFilter",this.#At?this.#it.addHCMFilter(this.#At.foreground,this.#At.background):"none")}get direction(){return shadow(this,"direction",getComputedStyle(this.#St).direction)}get _highlightColors(){return shadow(this,"_highlightColors",this.#st?new Map(this.#st.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 shadow(this,"highlightColors",null);const e=new Map,i=!!this.#At;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 shadow(this,"highlightColors",e)}get highlightColorNames(){return 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.#q=t}setMainHighlightColorPicker(t){this.#gt=t}editAltText(t,e=!1){this.#z?.editAltText(this,t,e)}hasCommentManager(){return!!this.#V}editComment(t,e,i,n){this.#V?.showDialog(this,t,e,i,n)}selectComment(t,e){const i=this.#U.get(t),n=i?.getEditorByUID(e);n?.toggleComment(!0,!0)}updateComment(t){this.#V?.updateComment(t.getData())}updatePopupColor(t){this.#V?.updatePopupColor(t)}removeComment(t){this.#V?.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.#V?.toggleCommentPopup(t,e,i)}makeCommentColor(t,e){return t&&this.#V?.makeCommentColor(t,e)||null}getCommentDialogElement(){return this.#V?.dialogElement||null}async waitForEditorsRendered(t){if(this.#U.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);await i}getSignature(t){this.#wt?.getSignature({uiManager:this,editor:t})}get signatureManager(){return this.#wt}switchToMode(t,e){this._eventBus.on("annotationeditormodechanged",e,{once:!0,signal:this._signal});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.#et=e}onPageChanging({pageNumber:t}){this.#X=t-1}deletePage(t){for(const e of this.getEditors(t))e.remove();this.#U.delete(t);this.#X===t&&(this.#X=0)}focusMainContainer(){this.#St.focus()}findParent(t,e){for(const i of this.#U.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.#Dt.classList.toggle("noUserSelect",t)}addShouldRescale(t){this.#Q.add(t)}removeShouldRescale(t){this.#Q.delete(t)}onScaleChanging({scale:t}){this.commitOrRemove();this.viewParameters.realScale=t*PixelsPerInch.PDF_TO_CSS_UNITS;for(const t of this.#Q)t.onScaleChanging();this.#q?.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove();this.viewParameters.rotation=t}#Ot({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t}#Bt(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const e of this.#U.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.#Ot(i).closest(".textLayer"),h=this.getSelectionBoxes(l);if(!h)return;i.empty();const c=this.#Bt(l),d=this.#bt===b.NONE,callback=()=>{const i=c?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:h,anchorNode:n,anchorOffset:r,focusNode:s,focusOffset:a,text:o});d&&this.showAllEditors("highlight",!0,!0);e&&i?.editComment()};d?this.switchToMode(b.HIGHLIGHT,callback):callback()}commentSelection(t=""){this.highlightSelection(t,!0)}#kt(t){this.commitOrRemove();this.currentLayer?.endDrawingSession(!1)}#Lt(){const t=document.getSelection();if(!t||t.isCollapsed)return;const e=this.#Ot(t).closest(".textLayer"),i=this.getSelectionBoxes(e);if(i){this.#ot||=new FloatingToolbar(this);this.#ot.show(e,i,"ltr"===this.direction)}}getAndRemoveDataFromAnnotationStorage(t){if(!this.#j)return null;const e=`${f}${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.#Pt;if(i){i.setAttribute("data-l10n-id",t);e?i.setAttribute("data-l10n-args",JSON.stringify(e)):i.removeAttribute("data-l10n-args")}}#Nt(){const t=document.getSelection();if(!t||t.isCollapsed){if(this.#vt){this.#ot?.hide();this.#vt=null;this.#Ut({hasSelectedText:!1})}return}const{anchorNode:e}=t;if(e===this.#vt)return;const i=this.#Ot(t).closest(".textLayer");if(i){this.#ot?.hide();this.#vt=e;this.#Ut({hasSelectedText:!0});if(this.#bt===b.HIGHLIGHT||this.#bt===b.NONE){this.#bt===b.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0);this.#at=this.isShiftKeyDown;if(!this.isShiftKeyDown){const t=this.#bt===b.HIGHLIGHT?this.#Bt(i):null;t?.toggleDrawing();if(this.#ct){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.#Ht("main_toolbar")}};window.addEventListener("pointerup",pointerup,{signal:i});window.addEventListener("blur",pointerup,{signal:i})}else{t?.toggleDrawing(!0);this.#Ht("main_toolbar")}}}}else if(this.#vt){this.#ot?.hide();this.#vt=null;this.#Ut({hasSelectedText:!1})}}#Ht(t=""){this.#bt===b.HIGHLIGHT?this.highlightSelection(t):this.#Z&&this.#Lt()}#It(){document.addEventListener("selectionchange",this.#Nt.bind(this),{signal:this._signal})}#zt(){if(this.#rt)return;this.#rt=new AbortController;const t=this.combinedSignal(this.#rt);window.addEventListener("focus",this.focus.bind(this),{signal:t});window.addEventListener("blur",this.blur.bind(this),{signal:t})}#jt(){this.#rt?.abort();this.#rt=null}blur(){this.isShiftKeyDown=!1;if(this.#at){this.#at=!1;this.#Ht("main_toolbar")}if(!this.hasSelection)return;const{activeElement:t}=document;for(const e of this.#yt)if(e.div.contains(t)){this.#pt=[e,t];e._focusEventsAllowed=!1;break}}focus(){if(!this.#pt)return;const[t,e]=this.#pt;this.#pt=null;e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal});e.focus()}#Rt(){if(this.#ut)return;this.#ut=new AbortController;const t=this.combinedSignal(this.#ut);window.addEventListener("keydown",this.keydown.bind(this),{signal:t});window.addEventListener("keyup",this.keyup.bind(this),{signal:t})}#Gt(){this.#ut?.abort();this.#ut=null}#Wt(){if(this.#$)return;this.#$=new AbortController;const t=this.combinedSignal(this.#$);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})}#Vt(){this.#$?.abort();this.#$=null}#Ft(){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.#Gt();this.setEditingState(!1)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const i of this.#J)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.#J)if(i.isHandlingMimeForPasting(e.type)){i.paste(e,this.currentLayer);t.preventDefault();return}}copy(t){t.preventDefault();this.#B?.commitOrRemove();if(!this.hasSelection)return;const e=[];for(const t of this.#yt){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.#J)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.#qt(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.#bt===b.NONE||this.isEditorHandlingKeyboard||AnnotationEditorUIManager._keyboardManager.exec(this,t)}keyup(t){if(this.isShiftKeyDown&&"Shift"===t.key){this.isShiftKeyDown=!1;if(this.#at){this.#at=!1;this.#Ht("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.getEditors(t))i.pageIndex=e;const i=this.#H.get(t);if(i){i.pageIndex=e;this.#U.set(e,i);this.#ht?i.enable():i.disable()}}startUpdatePages(){this.#H=new Map(this.#U);this.#U.clear()}endUpdatePages(){this.#H=null}clonePage(t,e){for(const i of this.getEditors(t)){const t=i.serialize(i.mode!==b.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)}#Ut(t){if(Object.entries(t).some(([t,e])=>this.#_t[t]!==e)){this._eventBus.dispatch("editingstateschanged",{source:this,details:Object.assign(this.#_t,t)});this.#bt===b.HIGHLIGHT&&!1===t.hasSelectedEditor&&this.#Xt([[y.HIGHLIGHT_FREE,!0]])}}#Xt(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})}setEditingState(t){if(t){this.#zt();this.#Wt();this.#Ut({isEditing:this.#bt!==b.NONE,isEmpty:this.#Yt(),hasSomethingToUndo:this.#W.hasSomethingToUndo(),hasSomethingToRedo:this.#W.hasSomethingToRedo(),hasSelectedEditor:!1})}else{this.#jt();this.#Vt();this.#Ut({isEditing:!1});this.disableUserSelect(!1)}}registerEditorTypes(t){if(!this.#J){this.#J=t;for(const t of this.#J)this.#Xt(t.defaultPropertiesToUpdate)}}getId(){return this.#lt.id}get currentLayer(){return this.#U.get(this.#X)}getLayer(t){return this.#U.get(t)}get currentPageIndex(){return this.#X}addLayer(t){this.#U.set(t.pageIndex,t);this.#ht?t.enable():t.disable()}removeLayer(t){this.#U.delete(t.pageIndex)}async updateMode(t,e=null,i=!1,n=!1,r=!1,s=!1){if(this.#bt!==t){if(this.#Mt){await this.#Mt.promise;if(!this.#Mt)return}this.#Mt=Promise.withResolvers();this.#q?.commitOrRemove();this.#bt===b.POPUP&&this.#V?.hideSidebar();this.#V?.destroyPopup();this.#bt=t;if(t!==b.NONE){for(const t of this.#N.values())t.addStandaloneCommentButton();t===b.SIGNATURE&&await(this.#wt?.loadSignatures());i&&CurrentPointers.clearPointerType();this.setEditingState(!0);await this.#Kt();this.unselectAll();for(const e of this.#U.values())e.updateMode(t);if(t===b.POPUP){this.#L||=await this.#Et.getAnnotationsByType(new Set(this.#J.map(t=>t._editorType)));const t=new Set,e=[];for(const i of this.#N.values()){const{annotationElementId:n,hasComment:r,deleted:s}=i;n&&t.add(n);r&&!s&&e.push(i.getData())}for(const i of this.#L){const{id:n,popupRef:r,contentsObj:s}=i;r&&s?.str&&!t.has(n)&&!this.#Y.has(n)&&e.push(i)}this.#V?.showSidebar(e)}if(e){for(const t of this.#N.values())if(t.uid===e){this.setSelected(t);s?t.editComment():r?t.enterInEditMode():t.focus()}else t.unselect();this.#Mt.resolve()}else{n&&this.addNewEditorFromKeyboard();this.#Mt.resolve()}}else{this.setEditingState(!1);this.#Jt();for(const t of this.#N.values())t.hideStandaloneCommentButton();this._editorUndoBar?.hide();this.toggleComment(null);this.#Mt.resolve()}}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t.mode!==this.#bt&&this._eventBus.dispatch("switchannotationeditormode",{source:this,...t})}updateParams(t,e){if(this.#J){switch(t){case y.CREATE:this.currentLayer.addNewEditor(e);return;case y.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}});(this.#xt||=new Map).set(t,e);this.showAllEditors("highlight",e)}if(this.hasSelection)for(const i of this.#yt)i.updateParams(t,e);else for(const i of this.#J)i.updateDefaultParams(t,e)}}showAllEditors(t,e,i=!1){for(const i of this.#N.values())i.editorType===t&&i.show(e);(this.#xt?.get(y.HIGHLIGHT_SHOW_ALL)??!0)!==e&&this.#Xt([[y.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(this.#dt!==t){this.#dt=t;for(const e of this.#U.values()){t?e.disableClick():e.enableClick();e.div.classList.toggle("waiting",t)}}}async#Kt(){if(!this.#ht){this.#ht=!0;const t=[];for(const e of this.#U.values())t.push(e.enable());await Promise.all(t);for(const t of this.#N.values())t.enable()}}#Jt(){this.unselectAll();if(this.#ht){this.#ht=!1;for(const t of this.#U.values())t.disable();for(const t of this.#N.values())t.disable()}}*getEditors(t){for(const e of this.#N.values())e.pageIndex===t&&(yield e)}getEditor(t){return this.#N.get(t)}addEditor(t){this.#N.set(t.id,t)}removeEditor(t){if(t.div.contains(document.activeElement)){this.#nt&&clearTimeout(this.#nt);this.#nt=setTimeout(()=>{this.focusMainContainer();this.#nt=null},0)}this.#N.delete(t.id);t.annotationElementId&&this.#mt?.delete(t.annotationElementId);this.unselect(t);t.annotationElementId&&this.#Y.has(t.annotationElementId)||this.#j?.remove(t.id)}addDeletedAnnotationElement(t){this.#Y.add(t.annotationElementId);this.addChangedExistingAnnotation(t);t.deleted=!0}isDeletedAnnotationElement(t){return this.#Y.has(t)}removeDeletedAnnotationElement(t){this.#Y.delete(t.annotationElementId);this.removeChangedExistingAnnotation(t);t.deleted=!1}#$t(t){const e=this.#U.get(t.pageIndex);if(e)e.addOrRebuild(t);else{this.addEditor(t);this.addToAnnotationStorage(t)}}setActiveEditor(t){if(this.#B!==t){this.#B=t;t&&this.#Xt(t.propertiesToUpdate)}}get#Qt(){let t=null;for(t of this.#yt);return t}updateUI(t){this.#Qt===t&&this.#Xt(t.propertiesToUpdate)}updateUIForDefaultProperties(t){this.#Xt(t.defaultPropertiesToUpdate)}toggleSelected(t){if(this.#yt.has(t)){this.#yt.delete(t);t.unselect();this.#Ut({hasSelectedEditor:this.hasSelection})}else{this.#yt.add(t);t.select();this.#Xt(t.propertiesToUpdate);this.#Ut({hasSelectedEditor:!0})}}setSelected(t){this.updateToolbar({mode:t.mode,editId:t.uid});this.#q?.commitOrRemove();for(const e of this.#yt)e!==t&&e.unselect();this.#V?.destroyPopup();this.#yt.clear();this.#yt.add(t);t.select();this.#Xt(t.propertiesToUpdate);this.#Ut({hasSelectedEditor:!0})}isSelected(t){return this.#yt.has(t)}get firstSelectedEditor(){return this.#yt.values().next().value}unselect(t){t.unselect();this.#yt.delete(t);this.#Ut({hasSelectedEditor:this.hasSelection})}get hasSelection(){return 0!==this.#yt.size}get isEnterHandled(){return 1===this.#yt.size&&this.firstSelectedEditor.isEnterHandled}undo(){this.#W.undo();this.#Ut({hasSomethingToUndo:this.#W.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#Yt()});this._editorUndoBar?.hide()}redo(){this.#W.redo();this.#Ut({hasSomethingToUndo:!0,hasSomethingToRedo:this.#W.hasSomethingToRedo(),isEmpty:this.#Yt()})}addCommands(t){this.#W.add(t);this.#Ut({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#Yt()})}cleanUndoStack(t){this.#W.cleanType(t)}#Yt(){if(0===this.#N.size)return!0;if(1===this.#N.size)for(const t of this.#N.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.#yt],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.#B?.commitOrRemove()}hasSomethingToControl(){return this.#B||this.hasSelection}#qt(t){for(const t of this.#yt)t.unselect();this.#yt.clear();for(const e of t)if(!e.isEmpty()){this.#yt.add(e);e.select()}this.#Ut({hasSelectedEditor:this.hasSelection})}selectAll(){for(const t of this.#yt)t.commit();this.#qt(this.#N.values())}unselectAll(){if(this.#B){this.#B.commitOrRemove();if(this.#bt!==b.NONE)return}if(!this.#q?.commitOrRemove()){this.#V?.destroyPopup();if(this.hasSelection){for(const t of this.#yt)t.unselect();this.#yt.clear();this.#Ut({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.#yt];this.#Ct&&clearTimeout(this.#Ct);this.#Ct=setTimeout(()=>{this.#Ct=null;this.#Tt[0]=this.#Tt[1]=0;this.addCommands({cmd:()=>{for(const t of s)if(this.#N.has(t.id)){t.translateInPage(n,r);t.translationDone()}},undo:()=>{for(const t of s)if(this.#N.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.#K=new Map;for(const t of this.#yt)this.#K.set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#K)return!1;this.disableUserSelect(!1);const t=this.#K;this.#K=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.#N.has(t.id)){const r=this.#U.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.#K)for(const i of this.#K.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.#yt.size&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return this.#B===t}getActive(){return this.#B}getMode(){return this.#bt}isEditingMode(){return this.#bt!==b.NONE}get imageManager(){return 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.#G||=new Map).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){this.#G?.delete(t)}renderAnnotationElement(t){const e=this.#G?.get(t.data.id);if(!e)return;const i=this.#j.getRawValue(e);i&&(this.#bt!==b.NONE||i.hasBeenModified)&&i.renderAnnotationElement(t)}setMissingCanvas(t,e,i){const n=this.#mt?.get(t);if(n){n.setCanvas(e,i);this.#mt.delete(t)}}addMissingCanvas(t,e){(this.#mt||=new Map).set(t,e)}}class AltText{#l=null;#Zt=!1;#te=null;#ee=null;#ie=null;#ne=null;#re=!1;#se=null;#a=null;#ae=null;#oe=null;#le=!1;static#he=null;static _l10n=null;constructor(t){this.#a=t;this.#le=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.#te=document.createElement("button");t.className="altText";t.tabIndex="0";const e=this.#ee=document.createElement("span");t.append(e);if(this.#le){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.#le&&this.#a._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:this.#ce}})};t.addEventListener("click",onClick,{capture:!0,signal:i});t.addEventListener("keydown",e=>{if(e.target===t&&"Enter"===e.key){this.#re=!0;onClick(e)}},{signal:i});await this.#de();return t}get#ce(){return(this.#l?"added":null===this.#l&&this.guessedText&&"review")||"missing"}finish(){if(this.#te){this.#te.focus({focusVisible:this.#re});this.#re=!1}}isEmpty(){return this.#le?null===this.#l:!this.#l&&!this.#Zt}hasData(){return this.#le?null!==this.#l||!!this.#ae:this.isEmpty()}get guessedText(){return this.#ae}async setGuessedText(t){if(null===this.#l){this.#ae=t;this.#oe=await AltText._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t});this.#de()}}toggleAltTextBadge(t=!1){if(this.#le&&!this.#l){if(!this.#se){const t=this.#se=document.createElement("div");t.className="noAltTextBadge";this.#a.div.append(t)}this.#se.classList.toggle("hidden",!t)}else{this.#se?.remove();this.#se=null}}serialize(t){let e=this.#l;t||this.#ae!==e||(e=this.#oe);return{altText:e,decorative:this.#Zt,guessedText:this.#ae,textWithDisclaimer:this.#oe}}get data(){return{altText:this.#l,decorative:this.#Zt}}set data({altText:t,decorative:e,guessedText:i,textWithDisclaimer:n,cancel:r=!1}){if(i){this.#ae=i;this.#oe=n}if(this.#l!==t||this.#Zt!==e){if(!r){this.#l=t;this.#Zt=e}this.#de()}}toggle(t=!1){if(this.#te){if(!t&&this.#ne){clearTimeout(this.#ne);this.#ne=null}this.#te.disabled=!t}}shown(){this.#a._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:this.#ce}})}destroy(){this.#te?.remove();this.#te=null;this.#ee=null;this.#ie=null;this.#se?.remove();this.#se=null}async#de(){const t=this.#te;if(!t)return;if(this.#le){t.classList.toggle("done",!!this.#l);t.setAttribute("data-l10n-id",AltText.#he[this.#ce]);this.#ee?.setAttribute("data-l10n-id",AltText.#he[`${this.#ce}-label`]);if(!this.#l){this.#ie?.remove();return}}else{if(!this.#l&&!this.#Zt){t.classList.remove("done");this.#ie?.remove();return}t.classList.add("done");t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=this.#ie;if(!e){this.#ie=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.#ne);this.#ne=null},{once:!0});t.addEventListener("mouseenter",()=>{this.#ne=setTimeout(()=>{this.#ne=null;this.#ie.classList.add("show");this.#a._reportTelemetry({action:"alt_text_tooltip"})},i)},{signal:n});t.addEventListener("mouseleave",()=>{if(this.#ne){clearTimeout(this.#ne);this.#ne=null}this.#ie?.classList.remove("show")},{signal:n})}if(this.#Zt)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{#ue=null;#pe=null;#ge=!1;#a=null;#me=null;#fe=null;#be=null;#ye=null;#ve=!1;#we=null;constructor(t){this.#a=t}renderForToolbar(){const t=this.#pe=document.createElement("button");t.className="comment";return this.#v(t,!1)}renderForStandalone(){const t=this.#ue=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.#v(t,!0)}focusButton(){setTimeout(()=>{(this.#ue??this.#pe)?.focus()},0)}onUpdatedColor(){if(!this.#ue)return;const t=this.#a.commentButtonColor;t&&(this.#ue.style.backgroundColor=t);this.#a._uiManager.updatePopupColor(this.#a)}get commentButtonWidth(){return(this.#ue?.getBoundingClientRect().width??0)/this.#a.parent.boundingClientRect.width}get commentPopupPositionInLayer(){if(this.#we)return this.#we;if(!this.#ue)return null;const{x:t,y:e,height:i}=this.#ue.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.#we=t}hasDefaultPopupPosition(){return null===this.#we}removeStandaloneCommentButton(){this.#ue?.remove();this.#ue=null}removeToolbarCommentButton(){this.#pe?.remove();this.#pe=null}setCommentButtonStates({selected:t,hasPopup:e}){if(this.#ue){this.#ue.classList.toggle("selected",t);this.#ue.ariaExpanded=e}}#v(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.#pe?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.#ge=!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.#pe){this.#pe.focus({focusVisible:this.#ge});this.#ge=!1}}isDeleted(){return this.#ve||""===this.#be}isEmpty(){return null===this.#be}hasBeenEdited(){return this.isDeleted()||this.#be!==this.#me}serialize(){return this.data}get data(){return{text:this.#be,richText:this.#fe,date:this.#ye,deleted:this.isDeleted()}}set data(t){t!==this.#be&&(this.#fe=null);if(null!==t){this.#be=t;this.#ye=new Date;this.#ve=!1}else{this.#be="";this.#ve=!0}}restoreData({text:t,richText:e,date:i}){this.#be=t;this.#fe=e;this.#ye=i;this.#ve=!1}setInitialText(t,e=null){this.#me=t;this.data=t;this.#ye=null;this.#fe=e}shown(){}destroy(){this.#pe?.remove();this.#pe=null;this.#ue?.remove();this.#ue=null;this.#be="";this.#fe=null;this.#ye=null;this.#a=null;this.#ge=!1;this.#ve=!1}}class TouchManager{#St;#Ae=!1;#xe=null;#Ee;#_e;#Te;#Ce;#Se=null;#De;#Pe=null;#Me;#ke=null;constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:i=null,onPinchStart:n=null,onPinching:r=null,onPinchEnd:s=null,signal:a}){this.#St=t;this.#xe=i;this.#Ee=e;this.#_e=n;this.#Te=r;this.#Ce=s;this.#Me=new AbortController;this.#De=AbortSignal.any([a,this.#Me.signal]);t.addEventListener("touchstart",this.#Ie.bind(this),{passive:!1,signal:this.#De})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return 35/OutputScale.pixelRatio}#Ie(t){if(this.#Ee?.())return;if(1===t.touches.length){if(this.#Se)return;const t=this.#Se=new AbortController,e=AbortSignal.any([this.#De,t.signal]),i=this.#St,n={capture:!0,signal:e,passive:!1},cancelPointerDown=t=>{if("touch"===t.pointerType){this.#Se?.abort();this.#Se=null}};i.addEventListener("pointerdown",t=>{if("touch"===t.pointerType){stopEvent(t);cancelPointerDown(t)}},n);i.addEventListener("pointerup",cancelPointerDown,n);i.addEventListener("pointercancel",cancelPointerDown,n);return}if(!this.#ke){this.#ke=new AbortController;const t=AbortSignal.any([this.#De,this.#ke.signal]),e=this.#St,i={signal:t,capture:!1,passive:!1};e.addEventListener("touchmove",this.#Fe.bind(this),i);const n=this.#Re.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",stopEvent,i);e.addEventListener("pointerup",stopEvent,i);this.#_e?.()}stopEvent(t);if(2!==t.touches.length||this.#xe?.()){this.#Pe=null;return}let[e,i]=t.touches;e.identifier>i.identifier&&([e,i]=[i,e]);this.#Pe={touch0X:e.screenX,touch0Y:e.screenY,touch1X:i.screenX,touch1Y:i.screenY}}#Fe(t){if(!this.#Pe||2!==t.touches.length)return;stopEvent(t);let[e,i]=t.touches;e.identifier>i.identifier&&([e,i]=[i,e]);const{screenX:n,screenY:r}=e,{screenX:s,screenY:a}=i,o=this.#Pe,{touch0X:l,touch0Y:h,touch1X:c,touch1Y:d}=o,u=c-l,p=d-h,g=s-n,m=a-r,f=Math.hypot(g,m)||1,b=Math.hypot(u,p)||1;if(!this.#Ae&&Math.abs(b-f)<=TouchManager.MIN_TOUCH_DISTANCE_TO_PINCH)return;o.touch0X=n;o.touch0Y=r;o.touch1X=s;o.touch1Y=a;if(!this.#Ae){this.#Ae=!0;return}const y=[(n+s)/2,(r+a)/2];this.#Te?.(y,b,f)}#Re(t){if(!(t.touches.length>=2)){if(this.#ke){this.#ke.abort();this.#ke=null;this.#Ce?.()}if(this.#Pe){stopEvent(t);this.#Pe=null;this.#Ae=!1}}}destroy(){this.#Me?.abort();this.#Me=null;this.#Se?.abort();this.#Se=null}}class AnnotationEditor{#Oe=null;#Be=null;#l=null;#h=null;#ue=null;#Le=!1;#Ne=null;#Ue="";#He=null;#ze=null;#je=null;#Ge=null;#We=null;#Ve="";#$e=!1;#qe=null;#Xe=!1;#Ye=!1;#Ke=!1;#Je=null;#Qe=0;#Ze=0;#ti=null;#ei=null;isSelected=!1;_isCopy=!1;_editToolbar=null;_initialOptions=Object.create(null);_initialData=null;_isVisible=!0;_uiManager=null;_focusEventsAllowed=!0;static _l10n=null;static _l10nResizer=null;#ii=!1;#ni=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 shadow(this,"_resizerKeyboardManager",new KeyboardManager([[["ArrowLeft","mac+ArrowLeft"],t,{args:[-e,0]}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t,{args:[-i,0]}],[["ArrowRight","mac+ArrowRight"],t,{args:[e,0]}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t,{args:[i,0]}],[["ArrowUp","mac+ArrowUp"],t,{args:[0,-e]}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t,{args:[0,-i]}],[["ArrowDown","mac+ArrowDown"],t,{args:[0,e]}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t,{args:[0,i]}],[["Escape","mac+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 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._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.#ii}set _isDraggable(t){this.#ii=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.#ni}setParent(t){if(null!==t){this.pageIndex=t.pageIndex;this.pageDimensions=t.pageDimensions}else{this.#ri();this.#Ge?.remove();this.#Ge=null}this.parent=t}focusin(t){this._focusEventsAllowed&&(this.#$e?this.#$e=!1:this.parent.setSelected(this))}focusout(t){if(!this._focusEventsAllowed)return;if(!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()}#si([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.#si(this.parentDimensions,t,e)}translateInPage(t,e){this.#qe||=[this.x,this.y,this.width,this.height];this.#si(this.pageDimensions,t,e);this.div.scrollIntoView({block:"nearest"})}translationDone(){this._onTranslated(this.x,this.y)}drag(t,e){this.#qe||=[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:h}=i;h.left=`${(100*s).toFixed(2)}%`;h.top=`${(100*a).toFixed(2)}%`;this._onTranslating(s,a);i.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!this.#qe&&(this.#qe[0]!==this.x||this.#qe[1]!==this.y)}get _hasBeenResized(){return!!this.#qe&&(this.#qe[2]!==this.width||this.#qe[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;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/=i;this.y=s/=n;const[l,h]=this.getBaseTranslation();r+=l;s+=h;e.left=`${(100*r).toFixed(2)}%`;e.top=`${(100*s).toFixed(2)}%`;this.moveInDOM()}static#ai(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.#ai(t,e,this.parentRotation)}pageTranslationToScreen(t,e){return AnnotationEditor.#ai(t,e,360-this.parentRotation)}#oi(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]}#li(){if(this.#He)return;this.#He=document.createElement("div");this.#He.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.#He.append(t);t.classList.add("resizer",i);t.setAttribute("data-resizer-name",i);t.addEventListener("pointerdown",this.#hi.bind(this,i),{signal:e});t.addEventListener("contextmenu",noContextMenu,{signal:e});t.tabIndex=-1}this.div.prepend(this.#He)}#hi(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.#ze=[e.screenX,e.screenY];const r=new AbortController,s=this._uiManager.combinedSignal(r);this.parent.togglePointerEvents(!1);window.addEventListener("pointermove",this.#ci.bind(this,t),{passive:!0,capture:!0,signal:s});window.addEventListener("touchmove",stopEvent,{passive:!1,signal:s});window.addEventListener("contextmenu",noContextMenu,{signal:s});this.#je={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.#di()};window.addEventListener("pointerup",pointerUpCallback,{signal:s});window.addEventListener("blur",pointerUpCallback,{signal:s})}#ui(t,e,i,n){this.width=i;this.height=n;this.x=t;this.y=e;this.setDims();this.fixAndSetPosition();this._onResized()}_onResized(){}#di(){if(!this.#je)return;const{savedX:t,savedY:e,savedWidth:i,savedHeight:n}=this.#je;this.#je=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.#ui.bind(this,r,s,a,o),undo:this.#ui.bind(this,t,e,i,n),mustExec:!0})}static _round(t){return Math.round(1e4*t)/1e4}#ci(t,e){const[i,n]=this.parentDimensions,r=this.x,s=this.y,a=this.width,o=this.height,l=AnnotationEditor.MIN_SIZE/i,h=AnnotationEditor.MIN_SIZE/n,c=this.#oi(this.rotation),transf=(t,e)=>[c[0]*t+c[2]*e,c[1]*t+c[3]*e],d=this.#oi(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 v=AnnotationEditor._round(r+y[0]),w=AnnotationEditor._round(s+y[1]);let A,x,E=1,_=1;if(e.fromKeyboard)({deltaX:A,deltaY:x}=e);else{const{screenX:t,screenY:i}=e,[n,r]=this.#ze;[A,x]=this.screenToPageTranslation(t-n,i-r);this.#ze[0]=t;this.#ze[1]=i}[A,x]=(T=A/i,C=x/n,[d[0]*T+d[2]*C,d[1]*T+d[3]*C]);var T,C;if(g){const t=Math.hypot(a,o);E=_=Math.max(Math.min(Math.hypot(b[0]-f[0]-A,b[1]-f[1]-x)/t,1/a,1/o),l/a,h/o)}else m?E=MathClamp(Math.abs(b[0]-f[0]-A),l,1)/a:_=MathClamp(Math.abs(b[1]-f[1]-x),h,1)/o;const S=AnnotationEditor._round(a*E),D=AnnotationEditor._round(o*_);y=transf(...p(S,D));const P=v-y[0],M=w-y[1];this.#qe||=[this.x,this.y,this.width,this.height];this.width=S;this.height=D;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.#Ye)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.#Oe){this.#l.data=this.#Oe;this.#Oe=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.#h?.focusButton()}addCommentButton(){return this.canAddComment?this.#h||=new Comment(this):null}addStandaloneCommentButton(){if(this._uiManager.hasCommentManager())if(this.#ue)this._uiManager.isEditingMode()&&this.#ue.classList.remove("hidden");else if(this.hasComment){this.#ue=this.#h.renderForStandalone();this.div.append(this.#ue)}}removeStandaloneCommentButton(){this.#h.removeStandaloneCommentButton();this.#ue=null}hideStandaloneCommentButton(){this.#ue?.classList.add("hidden")}get comment(){if(!this.#h)return null;const{data:{richText:t,text:e,date:i,deleted:n}}=this.#h;return{text:e,richText:t,date:i,deleted:n,color:this.getNonHCMColor(),opacity:this.opacity??1}}set comment(t){this.#h||=new Comment(this);"object"==typeof t&&null!==t?this.#h.restoreData(t):this.#h.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.#h||=new Comment(this);this.#h.setInitialText(t,i);if(!this.annotationElementId)return;const n=this._uiManager.getAndRemoveDataFromAnnotationStorage(this.annotationElementId);n&&this.updateFromAnnotationLayer(n)}get hasEditedComment(){return this.#h?.hasBeenEdited()}get hasDeletedComment(){return this.#h?.isDeleted()}get hasComment(){return!!this.#h&&!this.#h.isEmpty()&&!this.#h.isDeleted()}async editComment(t){this.#h||=new Comment(this);this.#h.edit(t)}toggleComment(t,e=void 0){this.hasComment&&this._uiManager.toggleComment(this,t,e)}setSelectedCommentButton(t){this.#h.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.#h.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.#Le?-1:0;t.setAttribute("role","application");this.defaultL10nId&&t.setAttribute("data-l10n-id",this.defaultL10nId);this._isVisible||t.classList.add("hidden");this.setInForeground();this.#pi();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.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#ei||=new TouchManager({container:t,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#gi.bind(this),onPinching:this.#mi.bind(this),onPinchEnd:this.#fi.bind(this),signal:this._uiManager._signal}));this.addStandaloneCommentButton();this._uiManager._editorUndoBar?.hide();return t}#gi(){this.#je={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};this.#l?.toggle(!1);this.parent.togglePointerEvents(!1)}#mi(t,e,i){let n=i/e*.7+1-.7;if(1===n)return;const r=this.#oi(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,h=this.width,c=this.height,d=AnnotationEditor.MIN_SIZE/s,u=AnnotationEditor.MIN_SIZE/a;n=Math.max(Math.min(n,1/h,1/c),d/h,u/c);const p=AnnotationEditor._round(h*n),g=AnnotationEditor._round(c*n);if(p===h&&g===c)return;this.#qe||=[o,l,h,c];const m=transf(h/2,c/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()}#fi(){this.#l?.toggle(!0);this.parent.togglePointerEvents(!0);this.#di()}pointerdown(t){const{isMac:e}=FeatureTest.platform;if(0!==t.button||t.ctrlKey&&e)t.preventDefault();else{this.#$e=!0;this._isDraggable?this.#bi(t):this.#yi(t)}}#yi(t){const{isMac:e}=FeatureTest.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)}#bi(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.#Ne=null;this.#$e=!1;this._uiManager.endDragSession()||this.#yi(t);i&&this._onStopDragging()};if(e){this.#Qe=t.clientX;this.#Ze=t.clientY;this.#Ne=t.pointerId;this.#Ue=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.#Ne){stopEvent(t);return}const[s,a]=this.screenToPageTranslation(e-this.#Qe,n-this.#Ze);this.#Qe=e;this.#Ze=n;this._uiManager.dragSelectedEditors(s,a)},s);window.addEventListener("touchmove",stopEvent,s);window.addEventListener("pointerdown",t=>{t.pointerType===this.#Ue&&(this.#ei||t.isPrimary)&&cancelDrag(t);stopEvent(t)},s)}const pointerUpCallback=t=>{this.#Ne&&this.#Ne!==t.pointerId?stopEvent(t):cancelDrag(t)};window.addEventListener("pointerup",pointerUpCallback,{signal:r});window.addEventListener("blur",pointerUpCallback,{signal:r})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#Je&&clearTimeout(this.#Je);this.#Je=setTimeout(()=>{this.#Je=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,h=e/n,c=this.x*r,d=this.y*s,u=this.width*r,p=this.height*s;switch(i){case 0:return[c+l+a,s-d-h-p+o,c+l+u+a,s-d-h+o];case 90:return[c+h+a,s-d+l+o,c+h+p+a,s-d+l+u+o];case 180:return[c-l-u+a,s-d+h+o,c-l+a,s-d+h+p+o];case 270:return[c-h-p+a,s-d-l-u+o,c-h+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.#h?.onUpdatedColor()}getData(){const{comment:{text:t,color:e,date:i,opacity:n,deleted:r,richText:s},uid:a,pageIndex:o,creationDate:l,modificationDate:h}=this;return{id:a,pageIndex:o,rect:this.getPDFRect(),richText:s,contentsObj:{str:t},creationDate:l,modificationDate:i||h,popupRef:!r,color:e,opacity:n}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){if(this.isInEditMode())return!1;this.parent.setEditingState(!1);this.#Ye=!0;return!0}disableEditMode(){if(!this.isInEditMode())return!1;this.parent.setEditingState(!0);this.#Ye=!1;return!0}isInEditMode(){return this.#Ye}shouldGetKeyboardEvents(){return this.#Ke}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}#pi(){if(this.#We||!this.div)return;this.#We=new AbortController;const t=this._uiManager.combinedSignal(this.#We);this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t});this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})}rebuild(){this.#pi()}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.#Oe=t.accessibilityData;n._isCopy=t.isCopy||!1;const[r,s]=n.pageDimensions,[a,o,l,h]=n.getRectInCurrentCoords(t.rect,s);n.x=a/r;n.y=o/s;n.width=l/r;n.height=h/s;return n}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||null!==this.serialize())}remove(){this.#We?.abort();this.#We=null;this.isEmpty()||this.commit();this.parent?this.parent.remove(this):this._uiManager.removeEditor(this);this.hideCommentPopup();if(this.#Je){clearTimeout(this.#Je);this.#Je=null}this.#ri();this.removeEditToolbar();if(this.#ti){for(const t of this.#ti.values())clearTimeout(t);this.#ti=null}this.parent=null;this.#ei?.destroy();this.#ei=null;this.#Ge?.remove();this.#Ge=null}get isResizable(){return!1}makeResizable(){if(this.isResizable){this.#li();this.#He.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.#h.commentPopupPositionInLayer}set commentPopupPosition(t){this.#h.commentPopupPositionInLayer=t}hasDefaultPopupPosition(){return this.#h.hasDefaultPopupPosition()}get commentButtonWidth(){return this.#h.commentButtonWidth}get elementBeforePopup(){return this.div}setCommentButtonStates(t){this.#h?.setCommentButtonStates(t)}keydown(t){if(!this.isResizable||t.target!==this.div||"Enter"!==t.key)return;this._uiManager.setSelected(this);this.#je={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};const e=this.#He.children;if(!this.#Be){this.#Be=Array.from(e);const t=this.#vi.bind(this),i=this.#wi.bind(this),n=this._uiManager._signal;for(const e of this.#Be){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.#Ai.bind(this,r),{signal:n});e.setAttribute("data-l10n-id",AnnotationEditor._l10nResizer[r])}}const i=this.#Be[0];let n=0;for(const t of e){if(t===i)break;n++}const r=(360-this.rotation+this.parentRotation)%360/90*(this.#Be.length/4);if(r!==n){if(r<n)for(let t=0;t<n-r;t++)this.#He.append(this.#He.firstElementChild);else if(r>n)for(let t=0;t<r-n;t++)this.#He.firstElementChild.before(this.#He.lastElementChild);let t=0;for(const i of e){const e=this.#Be[t++].getAttribute("data-resizer-name");i.setAttribute("data-l10n-id",AnnotationEditor._l10nResizer[e])}}this.#xi(0);this.#Ke=!0;this.#He.firstElementChild.focus({focusVisible:!0});t.preventDefault();t.stopImmediatePropagation()}#vi(t){AnnotationEditor._resizerKeyboardManager.exec(this,t)}#wi(t){this.#Ke&&t.relatedTarget?.parentNode!==this.#He&&this.#ri()}#Ai(t){this.#Ve=this.#Ke?t:""}#xi(t){if(this.#Be)for(const e of this.#Be)e.tabIndex=t}_resizeWithKeyboard(t,e){this.#Ke&&this.#ci(this.#Ve,{deltaX:t,deltaY:e,fromKeyboard:!0})}#ri(){this.#Ke=!1;this.#xi(-1);this.#di()}_stopResizingWithKeyboard(){this.#ri();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._editToolbar?.show();this.#l?.toggleAltTextBadge(!1)}else this.addEditToolbar().then(()=>{this.div?.classList.contains("selectedEditor")&&this._editToolbar?.show()})}}focus(){this.div&&!this.div.contains(document.activeElement)&&setTimeout(()=>this.div?.focus({preventScroll:!0}),0)}unselect(){if(this.isSelected){this.isSelected=!1;this.#He?.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.#Xe}set isEditing(t){this.#Xe=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.#ti||=new Map;const{action:e}=t;let i=this.#ti.get(e);i&&clearTimeout(i);i=setTimeout(()=>{this._reportTelemetry(t);this.#ti.delete(e);0===this.#ti.size&&(this.#ti=null)},AnnotationEditor._telemetryTimeout);this.#ti.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.#Le=!1}disable(){this.div&&(this.div.tabIndex=-1);this.#Le=!0}updateFakeAnnotationElement(t){if(this.#Ge||this.deleted)if(this.deleted){this.#Ge.remove();this.#Ge=null}else(this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized)&&this.#Ge.updateEdited({rect:this.getPDFRect(),popup:this.comment});else this.#Ge=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 K=3285377520,J=4294901760,Q=65535;class MurmurHash3_64{constructor(t){this.h1=t?4294967295&t:K;this.h2=t?4294967295&t:K}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,h=this.h2;const c=3432918353,d=461845907,u=11601,p=13715;for(let t=0;t<n;t++)if(1&t){a=s[t];a=a*c&J|a*u&Q;a=a<<15|a>>>17;a=a*d&J|a*p&Q;l^=a;l=l<<13|l>>>19;l=5*l+3864292196}else{o=s[t];o=o*c&J|o*u&Q;o=o<<15|o>>>17;o=o*d&J|o*p&Q;h^=o;h=h<<13|h>>>19;h=5*h+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*c&J|a*u&Q;a=a<<15|a>>>17;a=a*d&J|a*p&Q;1&n?l^=a:h^=a}this.h1=l;this.h2=h}hexdigest(){let t=this.h1,e=this.h2;t^=e>>>1;t=3981806797*t&J|36045*t&Q;e=4283543511*e&J|(2950163797*(e<<16|t>>>16)&J)>>>16;t^=e>>>1;t=444984403*t&J|60499*t&Q;e=3301882366*e&J|(3120437893*(e<<16|t>>>16)&J)>>>16;t^=e>>>1;return(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const Z=Object.freeze({map:null,hash:"",transfer:void 0});class AnnotationStorage{#Ei=!1;#_i=null;#Ti=null;#Ci=new Map;onSetModified=null;onResetModified=null;onAnnotationEditor=null;getValue(t,e){const i=this.#Ci.get(t);return void 0===i?e:Object.assign(e,i)}getRawValue(t){return this.#Ci.get(t)}remove(t){const e=this.#Ci.get(t);if(void 0!==e){e instanceof AnnotationEditor&&this.#Ti.delete(e.annotationElementId);this.#Ci.delete(t);0===this.#Ci.size&&this.resetModified();this.#Ci.values().some(t=>t instanceof AnnotationEditor)||this.onAnnotationEditor?.(null)}}setValue(t,e){const i=this.#Ci.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.#Ci.set(t,e)}n&&this.#Si();if(e instanceof AnnotationEditor){(this.#Ti||=new Map).set(e.annotationElementId,e);this.onAnnotationEditor?.(e.constructor._type)}}has(t){return this.#Ci.has(t)}get size(){return this.#Ci.size}#Si(){if(!this.#Ei){this.#Ei=!0;this.onSetModified?.()}}resetModified(){if(this.#Ei){this.#Ei=!1;this.onResetModified?.()}}get print(){return new PrintAnnotationStorage(this)}get serializable(){if(0===this.#Ci.size)return Z;const t=new Map,e=new MurmurHash3_64,i=[],n=Object.create(null);let r=!1;for(const[i,s]of this.#Ci){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}:Z}get editorStats(){let t=null;const e=new Map;let i=0,n=0;for(const r of this.#Ci.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.has(a)||e.set(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.#_i=null}updateEditor(t,e){const i=this.#Ti?.get(t);if(i){i.updateFromAnnotationLayer(e);return!0}return!1}getEditor(t){return this.#Ti?.get(t)||null}get modifiedIds(){if(this.#_i)return this.#_i;const t=[];if(this.#Ti)for(const e of this.#Ti.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.#_i={ids:new Set(t),hash:e}}[Symbol.iterator](){return this.#Ci.entries()}}class PrintAnnotationStorage extends AnnotationStorage{#Di=Z;constructor(t){super();const{serializable:e}=t;if(e===Z)return;const{map:i,hash:n,transfer:r}=e,s=structuredClone(i,r?{transfer:r}:null);this.#Di={map:s,hash:n,transfer:[]}}get print(){unreachable("Should not call PrintAnnotationStorage.print")}get serializable(){return this.#Di}get modifiedIds(){return shadow(this,"modifiedIds",{ids:new Set,hash:""})}}__webpack_require__(7588);const tt="__forcedDependency",{floor:et,ceil:it}=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 nt=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0];class BBoxReader{#Pi;#Mi;constructor(t,e){this.#Pi=t;this.#Mi=e}get length(){return this.#Pi.length}isEmpty(t){return this.#Pi[t]===nt}minX(t){return this.#Mi[4*t+0]/256}minY(t){return this.#Mi[4*t+1]/256}maxX(t){return(this.#Mi[4*t+2]+1)/256}maxY(t){return(this.#Mi[4*t+3]+1)/256}}const ensureDebugMetadata=(t,e)=>t?.getOrInsertComputed(e,()=>({dependencies:new Set,isRenderingOperation:!1}));class CanvasBBoxTracker{#ki=[[1,0,0,1,0,0]];#Ii=[-1/0,-1/0,1/0,1/0];#Fi=new Float64Array(n);_pendingBBoxIdx=-1;#Ri;#Oi;#Bi;#Pi;_savesStack=[];_markedContentStack=[];constructor(t,e){this.#Ri=t.width;this.#Oi=t.height;this.#Li(e)}growOperationsCount(t){t>=this.#Pi.length&&this.#Li(t,this.#Pi)}#Li(t,e){const i=new ArrayBuffer(4*t);this.#Bi=new Uint8ClampedArray(i);this.#Pi=new Uint32Array(i);if(e&&e.length>0){this.#Pi.set(e);this.#Pi.fill(nt,e.length)}else this.#Pi.fill(nt)}get clipBox(){return this.#Ii}save(t){this.#Ii={__proto__:this.#Ii};this._savesStack.push(t);return this}restore(t,e){const i=Object.getPrototypeOf(this.#Ii);if(null===i)return this;this.#Ii=i;const n=this._savesStack.pop();if(void 0!==n){e?.(n,t);this.#Pi[t]=this.#Pi[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.#Pi[t]=this.#Pi[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.#Pi[t]=this.#Pi[i]}return this}pushBaseTransform(t){this.#ki.push(Util.multiplyByDOMMatrix(this.#ki.at(-1),t.getTransform()));return this}popBaseTransform(){this.#ki.length>1&&this.#ki.pop();return this}resetBBox(t){if(this._pendingBBoxIdx!==t){this._pendingBBoxIdx=t;this.#Fi.set(n,0)}return this}recordClipBox(t,e,i,r,s,a){const o=Util.multiplyByDOMMatrix(this.#ki.at(-1),e.getTransform()),l=n.slice();Util.axialAlignedBoundingBox([i,s,r,a],o,l);const h=Util.intersect(this.#Ii,l);if(h){this.#Ii[0]=h[0];this.#Ii[1]=h[1];this.#Ii[2]=h[2];this.#Ii[3]=h[3]}else{this.#Ii[0]=this.#Ii[1]=1/0;this.#Ii[2]=this.#Ii[3]=-1/0}return this}recordBBox(t,e,i,r,s,a){const o=this.#Ii;if(o[0]===1/0)return this;const l=Util.multiplyByDOMMatrix(this.#ki.at(-1),e.getTransform());if(o[0]===-1/0){Util.axialAlignedBoundingBox([i,s,r,a],l,this.#Fi);return this}const h=n.slice();Util.axialAlignedBoundingBox([i,s,r,a],l,h);this.#Fi[0]=MathClamp(h[0],o[0],this.#Fi[0]);this.#Fi[1]=MathClamp(h[1],o[1],this.#Fi[1]);this.#Fi[2]=MathClamp(h[2],this.#Fi[2],o[2]);this.#Fi[3]=MathClamp(h[3],this.#Fi[3],o[3]);return this}recordFullPageBBox(t){this.#Fi[0]=Math.max(0,this.#Ii[0]);this.#Fi[1]=Math.max(0,this.#Ii[1]);this.#Fi[2]=Math.min(this.#Ri,this.#Ii[2]);this.#Fi[3]=Math.min(this.#Oi,this.#Ii[3]);return this}recordOperation(t,e=!1,i){if(this._pendingBBoxIdx!==t)return this;const n=et(256*this.#Fi[0]/this.#Ri),r=et(256*this.#Fi[1]/this.#Oi),s=it(256*this.#Fi[2]/this.#Ri),a=it(256*this.#Fi[3]/this.#Oi);expandBBox(this.#Bi,t,n,r,s,a);if(i)for(const e of i)for(const i of e)i!==t&&expandBBox(this.#Bi,i,n,r,s,a);e||(this._pendingBBoxIdx=-1);return this}bboxToClipBoxDropOperation(t){if(this._pendingBBoxIdx===t){this._pendingBBoxIdx=-1;this.#Ii[0]=Math.max(this.#Ii[0],this.#Fi[0]);this.#Ii[1]=Math.max(this.#Ii[1],this.#Fi[1]);this.#Ii[2]=Math.min(this.#Ii[2],this.#Fi[2]);this.#Ii[3]=Math.min(this.#Ii[3],this.#Fi[3])}return this}take(){return new BBoxReader(this.#Pi,this.#Bi)}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{#Ni={__proto__:null};#Ui={__proto__:null,transform:[],moveText:[],sameLineText:[],[tt]:[]};#Hi=new Map;#zi=new Set;#ji=new Map;#Gi;#Wi;#Vi;constructor(t,e=!1){this.#Vi=t;if(e){this.#Gi=new Map;this.#Wi=(t,e)=>{ensureDebugMetadata(this.#Gi,e).dependencies.add(t)}}}get clipBox(){return this.#Vi.clipBox}growOperationsCount(t){this.#Vi.growOperationsCount(t)}save(t){this.#Ni={__proto__:this.#Ni};this.#Ui={__proto__:this.#Ui,transform:{__proto__:this.#Ui.transform},moveText:{__proto__:this.#Ui.moveText},sameLineText:{__proto__:this.#Ui.sameLineText},[tt]:{__proto__:this.#Ui[tt]}};this.#Vi.save(t);return this}restore(t){this.#Vi.restore(t,this.#Wi);const e=Object.getPrototypeOf(this.#Ni);if(null===e)return this;this.#Ni=e;this.#Ui=Object.getPrototypeOf(this.#Ui);return this}recordOpenMarker(t){this.#Vi.recordOpenMarker(t,this.#Wi);return this}getOpenMarker(){return this.#Vi.getOpenMarker()}recordCloseMarker(t){this.#Vi.recordCloseMarker(t,this.#Wi);return this}beginMarkedContent(t){this.#Vi.beginMarkedContent(t);return this}endMarkedContent(t){this.#Vi.endMarkedContent(t,this.#Wi);return this}pushBaseTransform(t){this.#Vi.pushBaseTransform(t);return this}popBaseTransform(){this.#Vi.popBaseTransform();return this}recordSimpleData(t,e){this.#Ni[t]=e;return this}recordIncrementalData(t,e){this.#Ui[t].push(e);return this}resetIncrementalData(t,e){this.#Ui[t].length=0;return this}recordNamedData(t,e){this.#Hi.set(t,e);return this}recordSimpleDataFromNamed(t,e,i){this.#Ni[t]=this.#Hi.get(e)??i}recordFutureForcedDependency(t,e){this.recordIncrementalData(tt,e);return this}inheritSimpleDataAsFutureForcedDependencies(t){for(const e of t)e in this.#Ni&&this.recordFutureForcedDependency(e,this.#Ni[e]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(const t of this.#zi)this.recordFutureForcedDependency(tt,t);return this}resetBBox(t){this.#Vi.resetBBox(t);return this}recordClipBox(t,e,i,n,r,s){this.#Vi.recordClipBox(t,e,i,n,r,s);return this}recordBBox(t,e,i,n,r,s){this.#Vi.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,h;if(o){l=o[2]!==o[0]&&o[3]!==o[1]&&this.#ji.get(i);if(!1!==l){h=[0,0,0,0];Util.axialAlignedBoundingBox(o,i.fontMatrix,h);1===n&&0===r&&0===s||Util.scaleMinMax([n,0,0,-n,r,s],h);if(l)return this.recordBBox(t,e,h[0],h[2],h[1],h[3])}}if(!a)return this.recordFullPageBBox(t);const c=a();if(o&&h&&void 0===l){l=h[0]<=r-c.actualBoundingBoxLeft&&h[2]>=r+c.actualBoundingBoxRight&&h[1]<=s-c.actualBoundingBoxAscent&&h[3]>=s+c.actualBoundingBoxDescent;this.#ji.set(i,l);if(l)return this.recordBBox(t,e,h[0],h[2],h[1],h[3])}return this.recordBBox(t,e,r-c.actualBoundingBoxLeft,r+c.actualBoundingBoxRight,s-c.actualBoundingBoxAscent,s+c.actualBoundingBoxDescent)}recordFullPageBBox(t){this.#Vi.recordFullPageBBox(t);return this}getSimpleIndex(t){return this.#Ni[t]}recordDependencies(t,e){const i=this.#zi,n=this.#Ni,r=this.#Ui;for(const t of e)t in this.#Ni?i.add(n[t]):t in r&&r[t].forEach(i.add,i);return this}recordNamedDependency(t,e){this.#Hi.has(e)&&this.#zi.add(this.#Hi.get(e));return this}recordOperation(t,e=!1){this.recordDependencies(t,[tt]);if(this.#Gi){const e=ensureDebugMetadata(this.#Gi,t),{dependencies:i}=e;this.#zi.forEach(i.add,i);this.#Vi._savesStack.forEach(i.add,i);this.#Vi._markedContentStack.forEach(i.add,i);i.delete(t);e.isRenderingOperation=!0}const i=!e&&t===this.#Vi._pendingBBoxIdx;this.#Vi.recordOperation(t,e,[this.#zi,this.#Vi._savesStack,this.#Vi._markedContentStack]);i&&this.#zi.clear();return this}recordShowTextOperation(t,e=!1){const i=Array.from(this.#zi);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.#Vi._pendingBBoxIdx;this.#Vi.bboxToClipBoxDropOperation(t);i&&this.#zi.clear();return this}take(){this.#ji.clear();return this.#Vi.take()}takeDebugMetadata(){return this.#Gi}}class CanvasNestedDependencyTracker{#$i;#qi;#Xi;#Yi=0;#Ki=0;constructor(t,e,i){if(t instanceof CanvasNestedDependencyTracker&&t.#Xi===!!i)return t;this.#$i=t;this.#qi=e;this.#Xi=!!i}get clipBox(){return this.#$i.clipBox}growOperationsCount(){throw new Error("Unreachable")}save(t){this.#Ki++;this.#$i.save(this.#qi);return this}restore(t){if(this.#Ki>0){this.#$i.restore(this.#qi);this.#Ki--}return this}recordOpenMarker(t){this.#Yi++;return this}getOpenMarker(){return this.#Yi>0?this.#qi:this.#$i.getOpenMarker()}recordCloseMarker(t){this.#Yi--;return this}beginMarkedContent(t){return this}endMarkedContent(t){return this}pushBaseTransform(t){this.#$i.pushBaseTransform(t);return this}popBaseTransform(){this.#$i.popBaseTransform();return this}recordSimpleData(t,e){this.#$i.recordSimpleData(t,this.#qi);return this}recordIncrementalData(t,e){this.#$i.recordIncrementalData(t,this.#qi);return this}resetIncrementalData(t,e){this.#$i.resetIncrementalData(t,this.#qi);return this}recordNamedData(t,e){return this}recordSimpleDataFromNamed(t,e,i){this.#$i.recordSimpleDataFromNamed(t,e,this.#qi);return this}recordFutureForcedDependency(t,e){this.#$i.recordFutureForcedDependency(t,this.#qi);return this}inheritSimpleDataAsFutureForcedDependencies(t){this.#$i.inheritSimpleDataAsFutureForcedDependencies(t);return this}inheritPendingDependenciesAsFutureForcedDependencies(){this.#$i.inheritPendingDependenciesAsFutureForcedDependencies();return this}resetBBox(t){this.#Xi||this.#$i.resetBBox(this.#qi);return this}recordClipBox(t,e,i,n,r,s){this.#Xi||this.#$i.recordClipBox(this.#qi,e,i,n,r,s);return this}recordBBox(t,e,i,n,r,s){this.#Xi||this.#$i.recordBBox(this.#qi,e,i,n,r,s);return this}recordCharacterBBox(t,e,i,n,r,s,a){this.#Xi||this.#$i.recordCharacterBBox(this.#qi,e,i,n,r,s,a);return this}recordFullPageBBox(t){this.#Xi||this.#$i.recordFullPageBBox(this.#qi);return this}getSimpleIndex(t){return this.#$i.getSimpleIndex(t)}recordDependencies(t,e){this.#$i.recordDependencies(this.#qi,e);return this}recordNamedDependency(t,e){this.#$i.recordNamedDependency(this.#qi,e);return this}recordOperation(t){this.#$i.recordOperation(this.#qi,!0);return this}recordShowTextOperation(t){this.#$i.recordShowTextOperation(this.#qi,!0);return this}bboxToClipBoxDropOperation(t){this.#Xi||this.#$i.bboxToClipBoxDropOperation(this.#qi,!0);return this}take(){throw new Error("Unreachable")}takeDebugMetadata(){throw new Error("Unreachable")}}const rt=["path","transform","filter","strokeColor","strokeAlpha","lineWidth","lineCap","lineJoin","miterLimit","dash"],st=["path","transform","filter","fillColor","fillAlpha","globalCompositeOperation","SMask"],ot=["transform","SMask","filter","fillAlpha","strokeAlpha","globalCompositeOperation"],lt=["filter","fillColor","fillAlpha"],ht=["transform","leading","charSpacing","wordSpacing","hScale","textRise","moveText","textMatrix","font","fontObj","filter","fillColor","textRenderingMode","SMask","fillAlpha","strokeAlpha","globalCompositeOperation","sameLineText"],ct=["transform"],dt=["transform","fillColor"];class CanvasImagesTracker{#Ri;#Oi;#Ji=4;#Qi=0;#Mi=new CanvasImagesTracker.#Zi(6*this.#Ji);static#Zi=FeatureTest.isFloat16ArraySupported?Float16Array:Float32Array;constructor(t){this.#Ri=t.width;this.#Oi=t.height}record(t,e,i,r){if(this.#Qi===this.#Ji){this.#Ji*=2;const t=new CanvasImagesTracker.#Zi(6*this.#Ji);t.set(this.#Mi);this.#Mi=t}const s=Util.domMatrixToTransform(t.getTransform());let a;if(r[0]!==1/0){const t=n.slice();Util.axialAlignedBoundingBox([0,-i,e,0],s,t);const o=Util.intersect(r,t);if(!o)return;const[l,h,c,d]=o;if(l!==t[0]||h!==t[1]||c!==t[2]||d!==t[3]){const t=Math.atan2(s[1],s[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)a=[l,h,l,d,c,h];else{const t=c-l,n=d-h,r=e*e,s=i*i,o=i*e,u=s-r,p=(n*s-t*o)/u;a=[l+(n*o-t*r)/u,h,l,h+p,c,d-p]}}}if(!a){a=[0,-i,0,0,e,-i];Util.applyTransform(a,s,0);Util.applyTransform(a,s,2);Util.applyTransform(a,s,4)}a[0]/=this.#Ri;a[1]/=this.#Oi;a[2]/=this.#Ri;a[3]/=this.#Oi;a[4]/=this.#Ri;a[5]/=this.#Oi;this.#Mi.set(a,6*this.#Qi);this.#Qi++}take(){return this.#Mi.subarray(0,6*this.#Qi)}}class FontLoader{#tn=new Set;constructor({ownerDocument:t=globalThis.document,styleElement:e=null}){this._document=t;this.nativeFontFaces=new Set;this.styleElement=null;this.loadingRequests=[];this.loadTestFontId=0}addNativeFontFace(t){this.nativeFontFaces.add(t);this._document.fonts.add(t)}removeNativeFontFace(t){this.nativeFontFaces.delete(t);this._document.fonts.delete(t)}insertRule(t){if(!this.styleElement){this.styleElement=this._document.createElement("style");this._document.documentElement.getElementsByTagName("head")[0].append(this.styleElement)}const e=this.styleElement.sheet;e.insertRule(t,e.cssRules.length)}clear(){for(const t of this.nativeFontFaces)this._document.fonts.delete(t);this.nativeFontFaces.clear();this.#tn.clear();if(this.styleElement){this.styleElement.remove();this.styleElement=null}}async loadSystemFont({systemFontInfo:t,disableFontFace:e,_inspectFont:i}){if(t&&!this.#tn.has(t.loadedName)){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.#tn.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 new Promise(e=>{const i=this._queueLoadingCallback(e);this._prepareFontLoadEvent(t,i)})}}get isFontLoadingAPISupported(){return shadow(this,"isFontLoadingAPISupported",!!this._document?.fonts)}get isSyncFontLoadingSupported(){return shadow(this,"isSyncFontLoadingSupported",i||FeatureTest.platform.isFirefox)}_queueLoadingCallback(t){const{loadingRequests:e}=this,i={done:!1,complete:function completeRequest(){assert(!i.done,"completeRequest() cannot be called twice.");i.done=!0;for(;e.length>0&&e[0].done;){const t=e.shift();setTimeout(t.callback,0)}},callback:t};e.push(i);return i}get _loadTestFont(){return shadow(this,"_loadTestFont",atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA=="))}_prepareFontLoadEvent(t,e){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 i,n;const r=this._document.createElement("canvas");r.width=1;r.height=1;const s=r.getContext("2d");let a=0;const o=`lt${Date.now()}${this.loadTestFontId++}`;let l=this._loadTestFont;l=spliceString(l,976,o.length,o);const h=1482184792;let c=int32(l,16);for(i=0,n=o.length-3;i<n;i+=4)c=c-h+int32(o,i)|0;i<o.length&&(c=c-h+int32(o+"XXX",i)|0);l=spliceString(l,16,4,function string32(t){return String.fromCharCode(t>>24&255,t>>16&255,t>>8&255,255&t)}(c));const d=`@font-face {font-family:"${o}";src:${`url(data:font/opentype;base64,${btoa(l)});`}}`;this.insertRule(d);const u=this._document.createElement("div");u.style.visibility="hidden";u.style.width=u.style.height="10px";u.style.position="absolute";u.style.top=u.style.left="0px";for(const e of[t.loadedName,o]){const t=this._document.createElement("span");t.textContent="Hi";t.style.fontFamily=e;u.append(t)}this._document.body.append(u);!function isFontReady(t,e){if(++a>30){warn("Load test font never loaded.");e();return}s.font="30px "+t;s.fillText(".",0,20);s.getImageData(0,0,1,1).data[3]>0?e():setTimeout(isFontReady.bind(null,t,e))}(o,()=>{u.remove();e.complete()})}}class FontFaceObject{compiledGlyphs=Object.create(null);#en;constructor(t,e=null,i,n){this.#en=t;this._inspectFont=e;i&&(this.charProcOperatorList=i);n&&Object.assign(this,n)}createNativeFontFace(){if(!this.data||this.disableFontFace)return null;let t;if(this.cssFontInfo){const e={weight:this.cssFontInfo.fontWeight};this.cssFontInfo.italicAngle&&(e.style=`oblique ${this.cssFontInfo.italicAngle}deg`);t=new FontFace(this.cssFontInfo.fontFamily,this.data,e)}else t=new FontFace(this.loadedName,this.data,{});this._inspectFont?.(this);return t}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${this.data.toBase64()});`;let e;if(this.cssFontInfo){let i=`font-weight: ${this.cssFontInfo.fontWeight};`;this.cssFontInfo.italicAngle&&(i+=`font-style: oblique ${this.cssFontInfo.italicAngle}deg;`);e=`@font-face {font-family:"${this.cssFontInfo.fontFamily}";${i}src:${t}}`}else e=`@font-face {font-family:"${this.loadedName}";src:${t}}`;this._inspectFont?.(this,t);return e}getPathGenerator(t,e){if(void 0!==this.compiledGlyphs[e])return this.compiledGlyphs[e];const i=this.loadedName+"_path_"+e;let n;try{n=t.get(i)}catch(t){warn(`getPathGenerator - ignoring character: "${t}".`)}const r=makePathFromDrawOPS(n?.path);this.fontExtraProperties||t.delete(i);return this.compiledGlyphs[e]=r}get black(){return this.#en.black}get bold(){return this.#en.bold}get disableFontFace(){return this.#en.disableFontFace}set disableFontFace(t){shadow(this,"disableFontFace",!!t)}get fontExtraProperties(){return this.#en.fontExtraProperties}get isInvalidPDFjsFont(){return this.#en.isInvalidPDFjsFont}get isType3Font(){return this.#en.isType3Font}get italic(){return this.#en.italic}get missingFile(){return this.#en.missingFile}get remeasure(){return this.#en.remeasure}get vertical(){return this.#en.vertical}get ascent(){return this.#en.ascent}get defaultWidth(){return this.#en.defaultWidth}get descent(){return this.#en.descent}get bbox(){return this.#en.bbox}get fontMatrix(){return this.#en.fontMatrix}get fallbackName(){return this.#en.fallbackName}get loadedName(){return this.#en.loadedName}get mimetype(){return this.#en.mimetype}get name(){return this.#en.name}get data(){return this.#en.data}clearData(){this.#en.clearData()}get cssFontInfo(){return this.#en.cssFontInfo}get systemFontInfo(){return this.#en.systemFontInfo}get defaultVMetrics(){return this.#en.defaultVMetrics}}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 numbers=["ascent","defaultWidth","descent"];static strings=["fallbackName","loadedName","mimetype","name"];static OFFSET_NUMBERS=Math.ceil(2*this.bools.length/8);static OFFSET_BBOX=this.OFFSET_NUMBERS+8*this.numbers.length;static OFFSET_FONT_MATRIX=this.OFFSET_BBOX+1+8;static OFFSET_DEFAULT_VMETRICS=this.OFFSET_FONT_MATRIX+1+48;static OFFSET_STRINGS=this.OFFSET_DEFAULT_VMETRICS+1+6}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 CssFontInfo{#in;#nn=new TextDecoder;#rn;constructor(t){this.#in=t;this.#rn=new DataView(t)}#sn(t){assert(t<CSS_FONT_INFO.strings.length,"Invalid string index");let e=0;for(let i=0;i<t;i++)e+=this.#rn.getUint32(e)+4;const i=this.#rn.getUint32(e);return this.#nn.decode(new Uint8Array(this.#in,e+4,i))}get fontFamily(){return this.#sn(0)}get fontWeight(){return this.#sn(1)}get italicAngle(){return this.#sn(2)}}class SystemFontInfo{#in;#nn=new TextDecoder;#rn;constructor(t){this.#in=t;this.#rn=new DataView(t)}get guessFallback(){return 0!==this.#rn.getUint8(0)}#sn(t){assert(t<SYSTEM_FONT_INFO.strings.length,"Invalid string index");let e=5;for(let i=0;i<t;i++)e+=this.#rn.getUint32(e)+4;const i=this.#rn.getUint32(e);return this.#nn.decode(new Uint8Array(this.#in,e+4,i))}get css(){return this.#sn(0)}get loadedName(){return this.#sn(1)}get baseFontName(){return this.#sn(2)}get src(){return this.#sn(3)}get style(){let t=1;t+=4+this.#rn.getUint32(t);const e=this.#rn.getUint32(t),i=this.#nn.decode(new Uint8Array(this.#in,t+4,e));t+=4+e;const n=this.#rn.getUint32(t);return{style:i,weight:this.#nn.decode(new Uint8Array(this.#in,t+4,n))}}}class FontInfo{#in;#nn=new TextDecoder;#rn;constructor({buffer:t,extra:e}){this.#in=t;this.#rn=new DataView(t);e&&Object.assign(this,e)}#an(t){assert(t<FONT_INFO.bools.length,"Invalid boolean index");const e=Math.floor(t/4),i=2*t%8,n=this.#rn.getUint8(e)>>i&3;return 0===n?void 0:2===n}get black(){return this.#an(0)}get bold(){return this.#an(1)}get disableFontFace(){return this.#an(2)}get fontExtraProperties(){return this.#an(3)}get isInvalidPDFjsFont(){return this.#an(4)}get isType3Font(){return this.#an(5)}get italic(){return this.#an(6)}get missingFile(){return this.#an(7)}get remeasure(){return this.#an(8)}get vertical(){return this.#an(9)}#on(t){assert(t<FONT_INFO.numbers.length,"Invalid number index");return this.#rn.getFloat64(FONT_INFO.OFFSET_NUMBERS+8*t)}get ascent(){return this.#on(0)}get defaultWidth(){return this.#on(1)}get descent(){return this.#on(2)}#ln(t,e,i,n){const r=this.#rn.getUint8(t);if(0===r)return;assert(r===e,"Invalid array length.");t+=1;const s=new Array(r);for(let e=0;e<r;e++){s[e]=this.#rn[i](t,!0);t+=n}return s}get bbox(){return this.#ln(FONT_INFO.OFFSET_BBOX,4,"getInt16",2)}get fontMatrix(){return this.#ln(FONT_INFO.OFFSET_FONT_MATRIX,6,"getFloat64",8)}get defaultVMetrics(){return this.#ln(FONT_INFO.OFFSET_DEFAULT_VMETRICS,3,"getInt16",2)}#sn(t){assert(t<FONT_INFO.strings.length,"Invalid string index");let e=FONT_INFO.OFFSET_STRINGS+4;for(let i=0;i<t;i++)e+=this.#rn.getUint32(e)+4;const i=this.#rn.getUint32(e);return this.#nn.decode(new Uint8Array(this.#in,e+4,i))}get fallbackName(){return this.#sn(0)}get loadedName(){return this.#sn(1)}get mimetype(){return this.#sn(2)}get name(){return this.#sn(3)}#hn(){let t=FONT_INFO.OFFSET_STRINGS;t+=4+this.#rn.getUint32(t);t+=4+this.#rn.getUint32(t);t+=4+this.#rn.getUint32(t);return{offset:t,length:this.#rn.getUint32(t)}}get data(){const{offset:t,length:e}=this.#hn();return 0===e?void 0:new Uint8Array(this.#in,t+4,e)}clearData(){const{offset:t,length:e}=this.#hn();if(0!==e){this.#rn.setUint32(t,0);this.#in=new Uint8Array(this.#in,0,t+4).slice().buffer;this.#rn=new DataView(this.#in)}}get cssFontInfo(){let t=FONT_INFO.OFFSET_STRINGS;t+=4+this.#rn.getUint32(t);t+=4+this.#rn.getUint32(t);const e=this.#rn.getUint32(t);if(0===e)return null;const i=new Uint8Array(e);i.set(new Uint8Array(this.#in,t+4,e));return new CssFontInfo(i.buffer)}get systemFontInfo(){let t=FONT_INFO.OFFSET_STRINGS;t+=4+this.#rn.getUint32(t);const e=this.#rn.getUint32(t);if(0===e)return null;const i=new Uint8Array(e);i.set(new Uint8Array(this.#in,t+4,e));return new SystemFontInfo(i.buffer)}}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],r=!!this.data[PATTERN_INFO.HAS_BACKGROUND],s=t.getUint32(PATTERN_INFO.N_COORD,!0),a=t.getUint32(PATTERN_INFO.N_COLOR,!0),o=t.getUint32(PATTERN_INFO.N_STOP,!0);let l=20;const h=new Float32Array(this.buffer,l,2*s);l+=8*s;const c=new Uint8Array(this.buffer,l,4*a);l+=4*a;const d=[];for(let e=0;e<o;++e){const e=t.getFloat32(l,!0);l+=4;const i=t.getUint32(l,!0);l+=4;d.push([e,`#${i.toString(16).padStart(6,"0")}`])}let u=null;if(i){u=[];for(let e=0;e<4;++e){u.push(t.getFloat32(l,!0));l+=4}}let p=null;if(r){p=new Uint8Array(this.buffer,l,3);l+=3}if(1===e)return["RadialAxial","axial",u,d,Array.from(h.slice(0,2)),Array.from(h.slice(2,4)),null,null];if(2===e)return["RadialAxial","radial",u,d,[h[0],h[1]],[h[3],h[4]],h[2],h[5]];if(3===e){const t=this.data[PATTERN_INFO.SHADING_TYPE];let e=null;if(h.length>0){e=n.slice();for(let t=0,i=h.length;t<i;t+=2)Util.pointBoundingBox(h[t],h[t+1],e)}return["Mesh",t,h,c,s,e,u,p]}throw new Error(`Unsupported pattern kind: ${e}`)}}class FontPathInfo{#in;constructor(t){this.#in=t}get path(){return FeatureTest.isFloat16ArraySupported?new Float16Array(this.#in):new Float32Array(this.#in)}}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,ut=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);class LoopbackPort{#cn=new Map;#dn=Promise.resolve();postMessage(t,e){const i={data:structuredClone(t,e?{transfer:e}:null)};this.#dn.then(()=>{for(const[t]of this.#cn)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.#cn.set(e,n)}removeEventListener(t,e){const i=this.#cn.get(e);i?.();this.#cn.delete(e)}terminate(){for(const[,t]of this.#cn)t?.();this.#cn.clear()}}__webpack_require__(1689);const pt=1,gt=2,mt=1,ft=2,bt=3,yt=4,vt=5,wt=6,At=7,xt=8;function onFn(){}function wrapReason(t){if(t instanceof AbortException||t instanceof InvalidPDFException||t instanceof PasswordException||t instanceof ResponseException||t instanceof UnknownErrorException)return t;t instanceof Error||"object"==typeof t&&null!==t||unreachable('wrapReason: Expected "reason" to be a (possibly cloned) Error.');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{#un=new AbortController;constructor(t,e,i){this.sourceName=t;this.targetName=e;this.comObj=i;this.callbackId=1;this.streamId=1;this.streamSinks=Object.create(null);this.streamControllers=Object.create(null);this.callbackCapabilities=Object.create(null);this.actionHandler=Object.create(null);i.addEventListener("message",this.#pn.bind(this),{signal:this.#un.signal})}#pn({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream){this.#gn(t);return}if(t.callback){const e=t.callbackId,i=this.callbackCapabilities[e];if(!i)throw new Error(`Cannot resolve callback ${e}`);delete this.callbackCapabilities[e];if(t.callback===pt)i.resolve(t.data);else{if(t.callback!==gt)throw new Error("Unexpected callback case");i.reject(wrapReason(t.reason))}return}const e=this.actionHandler[t.action];if(!e)throw new Error(`Unknown action from worker: ${t.action}`);if(t.callbackId){const i=this.sourceName,n=t.sourceName,r=this.comObj;Promise.try(e,t.data).then(function(e){r.postMessage({sourceName:i,targetName:n,callback:pt,callbackId:t.callbackId,data:e})},function(e){r.postMessage({sourceName:i,targetName:n,callback:gt,callbackId:t.callbackId,reason:wrapReason(e)})});return}t.streamId?this.#mn(t):e(t.data)}on(t,e){const i=this.actionHandler;if(i[t])throw new Error(`There is already an actionName called "${t}"`);i[t]=e}send(t,e,i){this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,data:e},i)}sendWithPromise(t,e,i){const n=this.callbackId++,r=Promise.withResolvers();this.callbackCapabilities[n]=r;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,callbackId:n,data:e},i)}catch(t){r.reject(t)}return r.promise}sendWithStream(t,e,i,n){const r=this.streamId++,s=this.sourceName,a=this.targetName,o=this.comObj;return new ReadableStream({start:i=>{const l=Promise.withResolvers();this.streamControllers[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.streamControllers[r].pullCall=e;o.postMessage({sourceName:s,targetName:a,stream:wt,streamId:r,desiredSize:t.desiredSize});return e.promise},cancel:t=>{assert(t instanceof Error,"cancel must have a valid reason");const e=Promise.withResolvers();this.streamControllers[r].cancelCall=e;this.streamControllers[r].isClosed=!0;o.postMessage({sourceName:s,targetName:a,stream:mt,streamId:r,reason:wrapReason(t)});return e.promise}},i)}#mn(t){const e=t.streamId,i=this.sourceName,n=t.sourceName,r=this.comObj,s=this,a=this.actionHandler[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:yt,streamId:e,chunk:t},a)},close(){if(!this.isCancelled){this.isCancelled=!0;r.postMessage({sourceName:i,targetName:n,stream:bt,streamId:e});delete s.streamSinks[e]}},error(t){assert(t instanceof Error,"error must have a valid reason");if(!this.isCancelled){this.isCancelled=!0;r.postMessage({sourceName:i,targetName:n,stream:vt,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;this.streamSinks[e]=o;Promise.try(a,t.data,o).then(function(){r.postMessage({sourceName:i,targetName:n,stream:xt,streamId:e,success:!0})},function(t){r.postMessage({sourceName:i,targetName:n,stream:xt,streamId:e,reason:wrapReason(t)})})}#gn(t){const e=t.streamId,i=this.sourceName,n=t.sourceName,r=this.comObj,s=this.streamControllers[e],a=this.streamSinks[e];switch(t.stream){case xt:t.success?s.startCall.resolve():s.startCall.reject(wrapReason(t.reason));break;case At:t.success?s.pullCall.resolve():s.pullCall.reject(wrapReason(t.reason));break;case wt:if(!a){r.postMessage({sourceName:i,targetName:n,stream:At,streamId:e,success:!0});break}a.desiredSize<=0&&t.desiredSize>0&&a.sinkCapability.resolve();a.desiredSize=t.desiredSize;Promise.try(a.onPull||onFn).then(function(){r.postMessage({sourceName:i,targetName:n,stream:At,streamId:e,success:!0})},function(t){r.postMessage({sourceName:i,targetName:n,stream:At,streamId:e,reason:wrapReason(t)})});break;case yt:assert(s,"enqueue should have stream controller");if(s.isClosed)break;s.controller.enqueue(t.chunk);break;case bt:assert(s,"close should have stream controller");if(s.isClosed)break;s.isClosed=!0;s.controller.close();this.#fn(s,e);break;case vt:assert(s,"error should have stream controller");s.controller.error(wrapReason(t.reason));this.#fn(s,e);break;case ft:t.success?s.cancelCall.resolve():s.cancelCall.reject(wrapReason(t.reason));this.#fn(s,e);break;case mt:if(!a)break;const o=wrapReason(t.reason);Promise.try(a.onCancel||onFn,o).then(function(){r.postMessage({sourceName:i,targetName:n,stream:ft,streamId:e,success:!0})},function(t){r.postMessage({sourceName:i,targetName:n,stream:ft,streamId:e,reason:wrapReason(t)})});a.sinkCapability.reject(o);a.isCancelled=!0;delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}}async#fn(t,e){await Promise.allSettled([t.startCall?.promise,t.pullCall?.promise,t.cancelCall?.promise]);delete this.streamControllers[e]}destroy(){this.#un?.abort();this.#un=null}}class BaseBinaryDataFactory{#bn=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.#bn[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{#yn=!1;constructor({enableHWA:t=!1}){this.#yn=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.#yn})}}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}_createCanvas(t,e){unreachable("Abstract method `_createCanvas` called.")}}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}}__webpack_require__(2489);class BaseFilterFactory{addFilter(t){return"none"}addHCMFilter(t,e){return"none"}addAlphaFilter(t){return"none"}addLuminosityFilter(t){return"none"}addHighlightHCMFilter(t,e,i,n,r){return"none"}destroy(t=!1){}}class DOMFilterFactory extends BaseFilterFactory{#vn;#wn;#An;#xn;#En;#_n;#C=0;constructor({docId:t,ownerDocument:e=globalThis.document}){super();this.#xn=t;this.#En=e}get#D(){return this.#wn||=new Map}get#Tn(){return this.#_n||=new Map}get#Cn(){if(!this.#An){const t=this.#En.createElement("div"),{style:e}=t;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.#En.createElementNS(q,"svg");i.setAttribute("width",0);i.setAttribute("height",0);this.#An=this.#En.createElementNS(q,"defs");t.append(i);i.append(this.#An);this.#En.body.append(t)}return this.#An}#Sn(t){if(1===t.length){const e=t[0],i=new Array(256);for(let t=0;t<256;t++)i[t]=e[t]/255;const n=i.join(",");return[n,n,n]}const[e,i,n]=t,r=new Array(256),s=new Array(256),a=new Array(256);for(let t=0;t<256;t++){r[t]=e[t]/255;s[t]=i[t]/255;a[t]=n[t]/255}return[r.join(","),s.join(","),a.join(",")]}#Dn(t){if(void 0===this.#vn){this.#vn="";const t=this.#En.URL;t!==this.#En.baseURI&&(isDataScheme(t)?warn('#createUrl: ignore "data:"-URL for performance reasons.'):this.#vn=updateUrlHash(t,""))}return`url(${this.#vn}#${t})`}addFilter(t){if(!t)return"none";let e=this.#D.get(t);if(e)return e;const[i,n,r]=this.#Sn(t),s=1===t.length?i:`${i}${n}${r}`;e=this.#D.get(s);if(e){this.#D.set(t,e);return e}const a=`g_${this.#xn}_transfer_map_${this.#C++}`,o=this.#Dn(a);this.#D.set(t,o);this.#D.set(s,o);const l=this.#Pn(a);this.#Mn(i,n,r,l);return o}addHCMFilter(t,e){const i=`${t}-${e}`,n="base";let r=this.#Tn.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.#Tn.set(n,r)}if(!t||!e)return r.url;const s=this.#kn(t);t=Util.makeHexColor(...s);const a=this.#kn(e);e=Util.makeHexColor(...a);this.#Cn.style.color="";if("#000000"===t&&"#ffffff"===e||t===e)return r.url;const o=new Array(256);for(let t=0;t<=255;t++){const e=t/255;o[t]=e<=.03928?e/12.92:((e+.055)/1.055)**2.4}const l=o.join(","),h=`g_${this.#xn}_hcm_filter`,c=r.filter=this.#Pn(h);this.#Mn(l,l,l,c);this.#In(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.#Mn(getSteps(0,5),getSteps(1,5),getSteps(2,5),c);r.url=this.#Dn(h);return r.url}addAlphaFilter(t){let e=this.#D.get(t);if(e)return e;const[i]=this.#Sn([t]),n=`alpha_${i}`;e=this.#D.get(n);if(e){this.#D.set(t,e);return e}const r=`g_${this.#xn}_alpha_map_${this.#C++}`,s=this.#Dn(r);this.#D.set(t,s);this.#D.set(n,s);const a=this.#Pn(r);this.#Fn(i,a);return s}addLuminosityFilter(t){let e,i,n=this.#D.get(t||"luminosity");if(n)return n;if(t){[e]=this.#Sn([t]);i=`luminosity_${e}`}else i="luminosity";n=this.#D.get(i);if(n){this.#D.set(t,n);return n}const r=`g_${this.#xn}_luminosity_map_${this.#C++}`,s=this.#Dn(r);this.#D.set(t,s);this.#D.set(i,s);const a=this.#Pn(r);this.#Rn(a);t&&this.#Fn(e,a);return s}addHighlightHCMFilter(t,e,i,n,r){const s=`${e}-${i}-${n}-${r}`;let a=this.#Tn.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.#Tn.set(t,a)}if(!e||!i)return a.url;const[o,l]=[e,i].map(this.#kn.bind(this));let h=Math.round(.2126*o[0]+.7152*o[1]+.0722*o[2]),c=Math.round(.2126*l[0]+.7152*l[1]+.0722*l[2]),[d,u]=[n,r].map(this.#kn.bind(this));c<h&&([h,c,d,u]=[c,h,u,d]);this.#Cn.style.color="";const getSteps=(t,e,i)=>{const n=new Array(256),r=(c-h)/i,s=t/255,a=(e-t)/(255*i);let o=0;for(let t=0;t<=i;t++){const e=Math.round(h+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.#xn}_hcm_${t}_filter`,g=a.filter=this.#Pn(p);this.#In(g);this.#Mn(getSteps(d[0],u[0],5),getSteps(d[1],u[1],5),getSteps(d[2],u[2],5),g);a.url=this.#Dn(p);return a.url}destroy(t=!1){if(!t||!this.#_n?.size){this.#An?.parentNode.parentNode.remove();this.#An=null;this.#wn?.clear();this.#wn=null;this.#_n?.clear();this.#_n=null;this.#C=0}}#Rn(t){const e=this.#En.createElementNS(q,"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)}#In(t){const e=this.#En.createElementNS(q,"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)}#Pn(t){const e=this.#En.createElementNS(q,"filter");e.setAttribute("color-interpolation-filters","sRGB");e.setAttribute("id",t);this.#Cn.append(e);return e}#On(t,e,i){const n=this.#En.createElementNS(q,e);n.setAttribute("type","discrete");n.setAttribute("tableValues",i);t.append(n)}#Mn(t,e,i,n){const r=this.#En.createElementNS(q,"feComponentTransfer");n.append(r);this.#On(r,"feFuncR",t);this.#On(r,"feFuncG",e);this.#On(r,"feFuncB",i)}#Fn(t,e){const i=this.#En.createElementNS(q,"feComponentTransfer");e.append(i);this.#On(i,"feFuncA",t)}#kn(t){this.#Cn.style.color=t;return getRGB(getComputedStyle(this.#Cn).getPropertyValue("color"))}}if(i){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.ImageData||(t?.ImageData?globalThis.ImageData=t.ImageData:warn("Cannot polyfill `ImageData`, 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)}}const Et=new class WebGPU{#Bn=null;#Ln=null;#Nn=null;#Un=null;async#Hn(){if(!globalThis.navigator?.gpu)return!1;try{const t=await navigator.gpu.requestAdapter();if(!t)return!1;this.#Un=navigator.gpu.getPreferredCanvasFormat();this.#Ln=await t.requestDevice();return!0}catch{return!1}}init(){return this.#Bn||=this.#Hn()}get isReady(){return null!==this.#Ln}loadMeshShader(){if(!this.#Ln||this.#Nn)return;const t=this.#Ln.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.#Nn=this.#Ln.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.#Un}]},primitive:{topology:"triangle-list"}})}draw(t,e,i,n,r,s,a,o){this.loadMeshShader();const l=this.#Ln,{offsetX:h,offsetY:c,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([h,c,d,u,s,a,o,0]));const f=l.createBindGroup({layout:this.#Nn.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:m}}]}),b=new OffscreenCanvas(s,a),y=b.getContext("webgpu");y.configure({device:l,format:this.#Un,alphaMode:r?"opaque":"premultiplied"});const v=r?{r:r[0]/255,g:r[1]/255,b:r[2]/255,a:1}:{r:0,g:0,b:0,a:0},w=l.createCommandEncoder(),A=w.beginRenderPass({colorAttachments:[{view:y.getCurrentTexture().createView(),clearValue:v,loadOp:"clear",storeOp:"store"}]});if(i>0){A.setPipeline(this.#Nn);A.setBindGroup(0,f);A.setVertexBuffer(0,p);A.setVertexBuffer(1,g);A.draw(i)}A.end();l.queue.submit([w.finish()]);p.destroy();g.destroy();m.destroy();return b.transferToImageBitmap()}};const _t="Fill",Tt="Stroke",Ct="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{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];this.matrix=null}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}getPattern(t,e,i,n){let r;if(n===Tt||n===_t){if(this.isOriginBased()){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=Math.ceil(s[2]-s[0])||1,o=Math.ceil(s[3]-s[1])||1,l=e.canvasFactory.create(a,o),h=l.context;h.clearRect(0,0,h.canvas.width,h.canvas.height);h.beginPath();h.rect(0,0,h.canvas.width,h.canvas.height);h.translate(-s[0],-s[1]);i=Util.transform(i,[1,0,0,1,s[0],s[1]]);h.transform(...e.baseTransform);this.matrix&&h.transform(...this.matrix);applyBoundingBox(h,this._bbox);if(this.areConic()){h.fillStyle=this._createReversedGradient(h);h.fill()}h.fillStyle=this._createGradient(h);h.fill();r=t.createPattern(l.canvas,"no-repeat");e.canvasFactory.destroy(l);const c=new DOMMatrix(i);r.setTransform(c)}else{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);r=this._createGradient(t)}return r}}function drawTriangle(t,e,i,n,r,s,a,o){const l=e.coords,h=e.colors,c=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 v=h[4*s],w=h[4*s+1],A=h[4*s+2],x=h[4*a],E=h[4*a+1],_=h[4*a+2],T=h[4*o],C=h[4*o+1],S=h[4*o+2],D=Math.round(g),P=Math.round(y);let M,k,I,R,O,B,L,N;for(let t=D;t<=P;t++){if(t<f){const e=t<g?0:(g-t)/(g-f);M=p-(p-m)*e;k=v-(v-x)*e;I=w-(w-E)*e;R=A-(A-_)*e}else{let e;e=t>y?1:f===y?0:(f-t)/(f-y);M=m-(m-b)*e;k=x-(x-T)*e;I=E-(E-C)*e;R=_-(_-S)*e}let e;e=t<g?0:t>y?1:(g-t)/(g-y);O=p-(p-b)*e;B=v-(v-T)*e;L=w-(w-C)*e;N=A-(A-S)*e;const i=Math.round(Math.min(M,O)),n=Math.round(Math.max(M,O));let r=d*t+4*i;for(let t=i;t<=n;t++){e=(M-t)/(M-O);e<0?e=0:e>1&&(e=1);c[r++]=k-(k-B)*e|0;c[r++]=I-(I-L)*e|0;c[r++]=R-(R-N)*e|0;c[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];this.matrix=null;!function loadMeshShader(){Et.loadMeshShader()}()}_createMeshCanvas(t,e,i){const n=Math.floor(this._bounds[0]),r=Math.floor(this._bounds[1]),s=Math.ceil(this._bounds[2])-n,a=Math.ceil(this._bounds[3])-r,o=Math.min(Math.ceil(Math.abs(s*t[0]*1.1)),3e3)||1,l=Math.min(Math.ceil(Math.abs(a*t[1]*1.1)),3e3)||1,h=s?s/o:1,c=a?a/l:1,d={coords:this._posData,colors:this._colData,offsetX:-n,offsetY:-r,scaleX:1/h,scaleY:1/c},u=o+4,p=l+4,g=i.create(u,p);if(function isGPUReady(){return Et.isReady}()&&this._vertexCount>48)g.context.drawImage(function drawMeshWithGPU(t,e,i,n,r,s,a,o){return Et.draw(t,e,i,n,r,s,a,o)}(this._posData,this._colData,this._vertexCount,d,e,u,p,2),0,0);else{const t=g.context.createImageData(o,l);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,d,e,e+1,e+2,e,e+1,e+2);g.context.putImageData(t,2,2)}return{canvas:g.canvas,offsetX:n-2*h,offsetY:r-2*c,scaleX:h,scaleY:c}}isModifyingCurrentTransform(){return!0}getPattern(t,e,i,n){applyBoundingBox(t,this._bbox);const r=new Float32Array(2);if(n===Ct)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===Ct?null:this._background,e.canvasFactory);if(n!==Ct){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 St=1,Dt=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),h=Math.abs(this.ystep);if(t>l+1e-6||e>h+1e-6)return null;const c=Math.floor((i-a)/l)+1,d=Math.ceil((i+t-r)/l)-1,u=Math.floor((n-o)/h)+1,p=Math.ceil((n+e-s)/h)-1;return d<=c&&p<=u?[c,u]:null}updatePatternDims(t,e){const i=Util.inverseTransform(this.patternBaseMatrix),n=[t[0],t[1]],r=[t[2],t[3]];Util.applyTransform(n,i);Util.applyTransform(r,i);e[0]=Math.abs(r[0]-n[0]);e[1]=Math.abs(r[1]-n[1]);e[2]=Math.min(n[0],r[0]);e[3]=Math.min(n[1],r[1])}_renderTileCanvas(t,e,i,n){const[r,s,a,o]=this.bbox,l=t.canvasFactory.create(i.size,n.size),h=l.context,c=this.canvasGraphicsFactory.createCanvasGraphics(h,e);c.groupLevel=t.groupLevel;this.setFillAndStrokeStyleToContext(c,this.paintType,this.color);h.translate(-i.scale*r,-n.scale*s);c.transform(0,i.scale,0,0,n.scale,0,0);h.save();c.dependencyTracker?.save();this.clipBbox(c,r,s,a,o);c.baseTransform=getCurrentTransform(c.ctx);c.executeOperatorList(this.operatorList);c.endDrawing();c.dependencyTracker?.restore();h.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,h]=this.bbox,c=t.dependencyTracker;c&&(t.dependencyTracker=new CanvasNestedDependencyTracker(c,s));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=h-o,[n,r]=this._getCombinedScales(),c=this.getSizeAndScale(e,this.ctx.canvas.width,n),d=this.getSizeAndScale(i,this.ctx.canvas.height,r),u=this._renderTileCanvas(t,s,c,d);t.ctx.drawImage(u.canvas,a,o,e,i);t.canvasFactory.destroy(u)}else{this.setFillAndStrokeStyleToContext(t,this.paintType,this.color);this.clipBbox(t,a,o,l,h);t.baseTransformStack.push(t.baseTransform);t.baseTransform=getCurrentTransform(t.ctx);t.executeOperatorList(this.operatorList);t.baseTransform=t.baseTransformStack.pop()}t.restore();c&&(t.dependencyTracker=c)}createPatternCanvas(t,e){const[i,n,r,s]=this.bbox,a=r-i,o=s-n;let{xstep:l,ystep:h}=this;l=Math.abs(l);h=Math.abs(h);info("TilingType: "+this.tilingType);const[c,d]=this._getCombinedScales();let u=a,p=o,g=!1,m=!1;Math.ceil(l*c)>=Math.ceil(a*c)?u=l:g=!0;Math.ceil(h*d)>=Math.ceil(o*d)?p=h:m=!0;const f=this.getSizeAndScale(u,this.ctx.canvas.width,c),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=h);const r=this.getSizeAndScale(u,this.ctx.canvas.width,c),s=this.getSizeAndScale(p,this.ctx.canvas.height,d),f=r.size,b=s.size,v=t.canvasFactory.create(f,b),w=v.context,A=g?Math.floor(a/l):0,x=m?Math.floor(o/h):0;for(let t=0;t<=A;t++)for(let i=0;i<=x;i++)w.drawImage(e,f*t,b*i,f,b,0,0,f,b);t.canvasFactory.destroy(y);return{canvas:v.canvas,canvasEntry:v,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){const n=t.ctx,r=t.current;r.patternFill=r.patternStroke=!1;switch(e){case St:const{fillStyle:t,strokeStyle:s}=this.ctx;n.fillStyle=r.fillColor=t;n.strokeStyle=r.strokeColor=s;break;case Dt:n.fillStyle=n.strokeStyle=i;r.fillColor=r.strokeColor=i;break;default:throw new FormatError(`Unsupported paint type: ${e}`)}}isModifyingCurrentTransform(){return!1}getPattern(t,e,i,n,r){const s=n!==Ct?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}}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,h]=a?[s,o]:[o,s],c=n>>3,d=7&n,u=l^h,p=t.length;i=new Uint32Array(i.buffer);let g=0;for(let n=0;n<r;++n){for(const n=e+c;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}}const Pt=16,Mt=new DOMMatrix,kt=new Float32Array(2);function drawImageAtIntegerCoords(t,e,i,n,r,s,a,o,l,h){const[c,d,u,p,g,m]=getCurrentTransform(t);if(0===d&&0===u){const f=a*c+g,b=Math.round(f),y=o*p+m,v=Math.round(y),w=(a+l)*c+g,A=Math.abs(Math.round(w)-b)||1,x=(o+h)*p+m,E=Math.abs(Math.round(x)-v)||1;t.setTransform(Math.sign(c),0,0,Math.sign(p),b,v);t.drawImage(e,i,n,r,s,0,0,A,E);t.setTransform(c,d,u,p,g,m);return[A,E]}if(0===c&&0===p){const f=o*u+g,b=Math.round(f),y=a*d+m,v=Math.round(y),w=(o+h)*u+g,A=Math.abs(Math.round(w)-b)||1,x=(a+l)*d+m,E=Math.abs(Math.round(x)-v)||1;t.setTransform(0,Math.sign(d),Math.sign(u),0,b,v);t.drawImage(e,i,n,r,s,0,0,E,A);t.setTransform(c,d,u,p,g,m);return[E,A]}t.drawImage(e,i,n,r,s,a,o,l,h);return[Math.hypot(c,d)*l,Math.hypot(u,p)*h]}class CanvasExtraState{alphaIsShape=!1;fontSize=0;fontSizeScale=1;textMatrix=null;textMatrixScale=1;fontMatrix=s;leading=0;x=0;y=0;lineX=0;lineY=0;charSpacing=0;wordSpacing=0;textHScale=1;textRenderingMode=w;textRise=0;fillColor="#000000";strokeColor="#000000";tilingPatternDims=null;patternFill=!1;patternStroke=!1;fillAlpha=1;strokeAlpha=1;lineWidth=1;activeSMask=null;transferMaps="none";minMax=r.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=_t,e=null){const i=this.minMax.slice();if(t===Tt){e||unreachable("Stroke bounding box must include transform.");Util.singularValueDecompose2dScale(e,kt);const t=kt[0]*this.lineWidth/2,n=kt[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(r,0)}getClippedPathBoundingBox(t=_t,e=null){return Util.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function putBinaryImageData(t,e){if(e instanceof ImageData){t.putImageData(e,0,0);return}const i=e.height,n=e.width,r=i%Pt,s=(i-r)/Pt,a=0===r?s:s+1,o=t.createImageData(n,Pt);let l,h=0;const c=e.data,d=o.data;let u,p,g,m;if(e.kind===C.GRAYSCALE_1BPP){const e=c.byteLength,i=new Uint32Array(d.buffer,0,d.byteLength>>2),m=i.length,f=n+7>>3,b=4294967295,y=FeatureTest.isLittleEndian?4278190080:255;for(u=0;u<a;u++){g=u<s?Pt:r;l=0;for(p=0;p<g;p++){const t=e-h;let r=0;const s=t>f?n:8*t-7,a=-8&s;let o=0,d=0;for(;r<a;r+=8){d=c[h++];i[l++]=128&d?b:y;i[l++]=64&d?b:y;i[l++]=32&d?b:y;i[l++]=16&d?b:y;i[l++]=8&d?b:y;i[l++]=4&d?b:y;i[l++]=2&d?b:y;i[l++]=1&d?b:y}for(;r<s;r++){if(0===o){d=c[h++];o=128}i[l++]=d&o?b:y;o>>=1}}for(;l<m;)i[l++]=0;t.putImageData(o,0,u*Pt)}}else if(e.kind===C.RGBA_32BPP){p=0;m=n*Pt*4;for(u=0;u<s;u++){d.set(c.subarray(h,h+m));h+=m;t.putImageData(o,0,p);p+=Pt}if(u<a){m=n*r*4;d.set(c.subarray(h,h+m));t.putImageData(o,0,p)}}else{if(e.kind!==C.RGB_24BPP)throw new Error(`bad image kind: ${e.kind}`);g=Pt;m=n*g;for(u=0;u<a;u++){if(u>=s){g=r;m=n*g}l=0;for(p=m;p--;){d[l++]=c[h++];d[l++]=c[h++];d[l++]=c[h++];d[l++]=255}t.putImageData(o,0,u*Pt)}}}function putBinaryImageMask(t,e){if(e.bitmap){t.drawImage(e.bitmap,0,0);return}const i=e.height,n=e.width,r=i%Pt,s=(i-r)/Pt,a=0===r?s:s+1,o=t.createImageData(n,Pt);let l=0;const h=e.data,c=o.data;for(let e=0;e<a;e++){const i=e<s?Pt:r;({srcPos:l}=convertBlackAndWhiteToRGBA({src:h,srcPos:l,dest:c,width:n,height:i,nonBlackColor:0}));t.putImageData(o,0,e*Pt)}}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 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")}function getImageSmoothingEnabled(t,e){if(e)return!0;Util.singularValueDecompose2dScale(t,kt);const i=Math.fround(OutputScale.pixelRatio*PixelsPerInch.PDF_TO_CSS_UNITS);return kt[0]<=i&&kt[1]<=i}const It=["butt","round","square"],Ft=["miter","round","bevel"],Rt={},Ot={};class CanvasGraphics{constructor(t,e,i,n,r,{optionalContentConfig:s,markedContentStack:a=null},o,l,h,c){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.suspendedCtx=null;this.contentVisible=!0;this.markedContentStack=a||[];this.optionalContentConfig=s;this.cachedPatterns=new Map;this.annotationCanvasMap=o;this.viewportScale=1;this.outputScaleX=1;this.outputScaleY=1;this.pageColors=l;this._cachedScaleForStroking=[-1,0];this._cachedGetSinglePixelWidth=null;this._cachedBitmapsMap=new Map;this.dependencyTracker=h??null;this.imagesTracker=c??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){const s=t.argsArray,a=t.fnArray;let o=e||0;const l=s.length;if(l===o)return o;const h=l-o>10&&"function"==typeof i,c=h?Date.now()+15:0;let d=0;const u=this.commonObjs,p=this.objs;let g,m;for(;;){if(void 0!==n){if(o===n.nextBreakPoint){n.breakIt(o,i);return o}if(n.shouldSkip(o)){if(++o===l)return o;continue}}if(!r||r(o)){g=a[o];m=s[o]??null;if(g!==O.dependency)null===m?this[g](o):this[g](o,...m);else for(const t of m){this.dependencyTracker?.recordNamedData(t,o);const e=t.startsWith("g_")?u:p;if(!e.has(t)){e.get(t,i);return o}}}o++;if(o===l)return o;if(h&&++d>10){if(Date.now()>c){i();return o}d=0}}}#zn(){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.#zn();for(const t of this.smaskGroupCanvases)this.canvasFactory.destroy(t);this.smaskGroupCanvases.length=0;this._clearPreparedSMask();this.tempSMask=null;this.smaskStack.length=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 h=this.canvasFactory.create(1,1),c=this.canvasFactory.create(1,1),d=i,u=n,p=t;for(const{newWidth:t,newHeight:e}of r){this.canvasFactory.reset(c,t,e);c.context.drawImage(p,0,0,d,u,0,0,t,e);[h,c]=[c,h];p=h.canvas;d=t;u=e}this.canvasFactory.destroy(c);return{img:h.canvas,paintWidth:d,paintHeight:u,tmpCanvas:h}}_createMaskCanvas(t,e){const i=this.ctx,{width:n,height:s}=e,a=this.current.fillColor,o=this.current.patternFill,l=getCurrentTransform(i);let h,c,d,u;if((e.bitmap||e.data)&&e.count>1){const i=e.bitmap||e.data.buffer;c=JSON.stringify(o?l:[l.slice(0,4),a]);h=this._cachedBitmapsMap.getOrInsertComputed(i,makeMap);const n=h.get(c);if(n&&!o){const e=Math.round(Math.min(l[0],l[2])+l[4]),i=Math.round(Math.min(l[1],l[3])+l[5]);this.dependencyTracker?.recordDependencies(t,dt);return{canvas:n,offsetX:e,offsetY:i}}d=n}if(!d){u=this.canvasFactory.create(n,s);putBinaryImageMask(u.context,e)}let p=Util.transform(l,[1/n,0,0,-1/s,0,0]);p=Util.transform(p,[1,0,0,1,0,-s]);const g=r.slice();Util.axialAlignedBoundingBox([0,0,n,s],p,g);const[m,f,b,y]=g,v=Math.round(b-m)||1,w=Math.round(y-f)||1,A=this.canvasFactory.create(v,w),x=A.context,E=m,_=f;x.translate(-E,-_);x.transform(...p);let T=null;if(!d){const t=this._scaleImage(u.canvas,getCurrentTransformInverse(x));d=t.img;T=t.tmpCanvas;if(d!==u.canvas){this.canvasFactory.destroy(u);u=null}if(h&&o){h.set(c,d);T=null;u=null}}x.imageSmoothingEnabled=getImageSmoothingEnabled(getCurrentTransform(x),e.interpolate);drawImageAtIntegerCoords(x,d,0,0,d.width,d.height,0,0,n,s);T&&this.canvasFactory.destroy(T);u&&this.canvasFactory.destroy(u);x.globalCompositeOperation="source-in";const C=Util.transform(getCurrentTransformInverse(x),[1,0,0,1,-E,-_]);x.fillStyle=o?a.getPattern(i,this,C,_t,t):a;x.fillRect(0,0,n,s);h&&!o&&h.set(c,A.canvas);this.dependencyTracker?.recordDependencies(t,dt);return{canvas:A.canvas,canvasEntry:h&&!o?null:A,offsetX:Math.round(E),offsetY:Math.round(_)}}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=It[e]}setLineJoin(t,e){this.dependencyTracker?.recordSimpleData("lineJoin",t);this.ctx.lineJoin=Ft[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);this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(n)}}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}_ensurePreparedSMask(t,e,i){if(t!==this.smaskPreparedFor){this._clearPreparedSMask();this._prepareSMaskCanvas(t,e,i)}}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,this.ctx.canvas.width,this.ctx.canvas.height)}_prepareSMaskCanvas(t,e,i){const{canvas:n,subtype:r,backdrop:s,transferMap:a}=t,o="Luminosity"===r||"Alpha"===r&&a;if(!s&&!o){this.smaskPreparedFor=t;return}let l,h,c;if(s&&o){const o=this.canvasFactory.create(e,i),d=o.context;d.drawImage(n,t.offsetX,t.offsetY);d.globalCompositeOperation="destination-atop";d.fillStyle=s;d.fillRect(0,0,e,i);d.globalCompositeOperation="source-over";l=this.canvasFactory.create(e,i);const u=l.context;u.filter="Alpha"===r?this.filterFactory.addAlphaFilter(a):this.filterFactory.addLuminosityFilter(a);u.drawImage(o.canvas,0,0);u.filter="none";this.canvasFactory.destroy(o);h=c=0}else if(o){l=this.canvasFactory.create(n.width,n.height);const e=l.context;e.filter="Alpha"===r?this.filterFactory.addAlphaFilter(a):this.filterFactory.addLuminosityFilter(a);e.drawImage(n,0,0);e.filter="none";({offsetX:h,offsetY:c}=t)}else{l=this.canvasFactory.create(e,i);const r=l.context;r.drawImage(n,t.offsetX,t.offsetY);r.globalCompositeOperation="destination-atop";r.fillStyle=s;r.fillRect(0,0,e,i);r.globalCompositeOperation="source-over";h=c=0}this.smaskPreparedEntry=l;this.smaskPreparedFor=t;this.smaskPreparedOffsetX=h;this.smaskPreparedOffsetY=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);!function mirrorContextOperations(t,e){if(t._removeMirroring)throw new Error("Context is already forwarding operations.");t.__originalSave=t.save;t.__originalRestore=t.restore;t.__originalRotate=t.rotate;t.__originalScale=t.scale;t.__originalTranslate=t.translate;t.__originalTransform=t.transform;t.__originalSetTransform=t.setTransform;t.__originalResetTransform=t.resetTransform;t.__originalClip=t.clip;t.__originalMoveTo=t.moveTo;t.__originalLineTo=t.lineTo;t.__originalBezierCurveTo=t.bezierCurveTo;t.__originalRect=t.rect;t.__originalClosePath=t.closePath;t.__originalBeginPath=t.beginPath;t._removeMirroring=()=>{t.save=t.__originalSave;t.restore=t.__originalRestore;t.rotate=t.__originalRotate;t.scale=t.__originalScale;t.translate=t.__originalTranslate;t.transform=t.__originalTransform;t.setTransform=t.__originalSetTransform;t.resetTransform=t.__originalResetTransform;t.clip=t.__originalClip;t.moveTo=t.__originalMoveTo;t.lineTo=t.__originalLineTo;t.bezierCurveTo=t.__originalBezierCurveTo;t.rect=t.__originalRect;t.closePath=t.__originalClosePath;t.beginPath=t.__originalBeginPath;delete t._removeMirroring};t.save=function(){e.save();this.__originalSave()};t.restore=function(){e.restore();this.__originalRestore()};t.translate=function(t,i){e.translate(t,i);this.__originalTranslate(t,i)};t.scale=function(t,i){e.scale(t,i);this.__originalScale(t,i)};t.transform=function(t,i,n,r,s,a){e.transform(t,i,n,r,s,a);this.__originalTransform(t,i,n,r,s,a)};t.setTransform=function(t,i,n,r,s,a){if(void 0===i){e.setTransform(t);this.__originalSetTransform(t)}else{e.setTransform(t,i,n,r,s,a);this.__originalSetTransform(t,i,n,r,s,a)}};t.resetTransform=function(){e.resetTransform();this.__originalResetTransform()};t.rotate=function(t){e.rotate(t);this.__originalRotate(t)};t.clip=function(t){e.clip(t);this.__originalClip(t)};t.moveTo=function(t,i){e.moveTo(t,i);this.__originalMoveTo(t,i)};t.lineTo=function(t,i){e.lineTo(t,i);this.__originalLineTo(t,i)};t.bezierCurveTo=function(t,i,n,r,s,a){e.bezierCurveTo(t,i,n,r,s,a);this.__originalBezierCurveTo(t,i,n,r,s,a)};t.rect=function(t,i,n,r){e.rect(t,i,n,r);this.__originalRect(t,i,n,r)};t.closePath=function(){e.closePath();this.__originalClosePath()};t.beginPath=function(){e.beginPath();this.__originalBeginPath()}}(r,this.suspendedCtx);this._ensurePreparedSMask(this.current.activeSMask,e,i);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()}compose(t){if(!this.current.activeSMask)return;if(t){t[0]=Math.floor(t[0]);t[1]=Math.floor(t[1]);t[2]=Math.ceil(t[2]);t[3]=Math.ceil(t[3])}else t=[0,0,this.ctx.canvas.width,this.ctx.canvas.height];const e=this.current.activeSMask,i=this.suspendedCtx;this.composeSMask(i,e,this.ctx,t);this.ctx.save();this.ctx.setTransform(1,0,0,1,0,0);this.ctx.clearRect(t[0],t[1],t[2]-t[0],t[3]-t[1]);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){const t=r-this.smaskPreparedOffsetX,e=s-this.smaskPreparedOffsetY;i.save();i.globalAlpha=1;i.setTransform(1,0,0,1,0,0);const n=new Path2D;n.rect(r,s,a,o);i.clip(n);i.globalCompositeOperation="destination-in";i.drawImage(l.canvas,t,e,a,o,r,s,a,o);i.restore()}else this.genericComposeSMask(e.context,i,a,o,r,s,e.offsetX,e.offsetY);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()}genericComposeSMask(t,e,i,n,r,s,a,o){const l=t.canvas,h=r-a,c=s-o;e.save();e.globalAlpha=1;e.setTransform(1,0,0,1,0,0);const d=new Path2D;d.rect(r,s,i,n);e.clip(d);e.globalCompositeOperation="destination-in";e.drawImage(l,h,c,i,n,r,s,i,n);e.restore()}save(t){this.inSMaskMode&©CtxState(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;this._cachedGetSinglePixelWidth=null}else this.inSMaskMode&&this.endSMaskMode()}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;this._cachedGetSinglePixelWidth=null}constructPath(t,e,i,n){let[r]=i;if(!n){r||=i[0]=new Path2D;e!==O.stroke&&e!==O.closeStroke&&(this.current.tilingPatternDims=null);this[e](t,r);return}if(null!==this.dependencyTracker){const i=e===O.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"])}r instanceof Path2D||(r=i[0]=makePathFromDrawOPS(r));Util.axialAlignedBoundingBox(n,getCurrentTransform(this.ctx),this.current.minMax);const s=this.current.tilingPatternDims;if(s&&e!==O.stroke&&e!==O.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=this.ctx,r=this.current.strokeColor;n.globalAlpha=this.current.strokeAlpha;if(this.contentVisible)if("object"==typeof r&&r?.getPattern){const i=r.isModifyingCurrentTransform()?n.getTransform():null;n.save();n.strokeStyle=r.getPattern(n,this,getCurrentTransformInverse(n),Tt,t);if(i){const t=new Path2D;t.addPath(e,n.getTransform().invertSelf().multiplySelf(i));e=t}this.rescaleAndStroke(e,!1);n.restore()}else this.rescaleAndStroke(e,!0);this.dependencyTracker?.recordDependencies(t,rt);i&&this.consumePath(t,e,this.current.getClippedPathBoundingBox(Tt,getCurrentTransform(this.ctx)));n.globalAlpha=this.current.fillAlpha}closeStroke(t,e){this.stroke(t,e)}fill(t,e,i=!0){const n=this.ctx,r=this.current.fillColor,s=this.current.patternFill;let a=!1;const o=this.current.getClippedPathBoundingBox();this.dependencyTracker?.recordDependencies(t,st);if(s){const s=this.current.tilingPatternDims,l=s&&r.canSkipPatternCanvas(s);if(l){r.drawPattern(this,e,this.pendingEOFill,l,t);this.pendingEOFill=!1;i&&this.consumePath(t,e,o);this.current.tilingPatternDims=null;return}const h=r.isModifyingCurrentTransform()?n.getTransform():null;this.dependencyTracker?.save(t);n.save();n.fillStyle=r.getPattern(n,this,getCurrentTransformInverse(n),_t,t);if(h){const t=new Path2D;t.addPath(e,n.getTransform().invertSelf().multiplySelf(h));e=t}a=!0}if(this.contentVisible&&null!==o)if(this.pendingEOFill){n.fill(e,"evenodd");this.pendingEOFill=!1}else n.fill(e);if(a){n.restore();this.dependencyTracker?.restore(t)}i&&this.consumePath(t,e,o)}eoFill(t,e){this.pendingEOFill=!0;this.fill(t,e)}fillStroke(t,e){this.fill(t,e,!1);this.stroke(t,e,!1);this.consumePath(t,e)}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){this.ctx.fill(e);this.dependencyTracker?.recordDependencies(t,lt).recordOperation(t)}clip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t);this.pendingClip=Rt}eoClip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t);this.pendingClip=Ot}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||s;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 a=n.loadedName||"sans-serif",o=n.systemFontInfo?.css||`"${a}", ${n.fallbackName}`;let l="normal";n.black?l="900":n.bold&&(l="bold");const h=n.italic?"italic":"normal";let c=i;i<16?c=16:i>100&&(c=100);this.current.fontSizeScale=i/c;this.ctx.font=`${h} ${l} ${c}px ${o}`}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)}#Gn(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,h=o.textRenderingMode,c=o.fontSize/o.fontSizeScale,d=h&_,u=!!(h&T),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(c,-c);this.dependencyTracker?.recordCharacterBBox(t,a,l);let e;if(d===w||d===x)if(r){e=a.getTransform();a.setTransform(...r);const t=this.#Gn(m,e,r);a.fill(t)}else a.fill(m);if(d===A||d===x)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,kt);a.lineWidth*=Math.max(kt[0],kt[1])/c;a.stroke(this.#Gn(m,e,s))}else{a.lineWidth/=c;a.stroke(m)}a.restore()}else{if(d===w||d===x){a.fillText(e,i,n);this.dependencyTracker?.recordCharacterBBox(t,a,l,c,i,n,()=>a.measureText(e))}if(d===A||d===x){this.dependencyTracker&&this.dependencyTracker?.recordCharacterBBox(t,a,l,c,i,n,()=>a.measureText(e)).recordDependencies(t,rt);a.strokeText(e,i,n)}}if(u){(this.pendingTextPaths||=[]).push({transform:getCurrentTransform(a),x:i,y:n,fontSize:c,path:m});this.dependencyTracker?.recordCharacterBBox(t,a,l,c,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 shadow(this,"isFontSubpixelAAEnabled",n)}showText(t,e){if(this.dependencyTracker){this.dependencyTracker.recordDependencies(t,ht).resetBBox(t);this.current.textRenderingMode&T&&this.dependencyTracker.recordFutureForcedDependency("textClip",t).inheritPendingDependenciesAsFutureForcedDependencies()}const i=this.current,n=i.font;if(n.isType3Font){this.showType3Text(t,e);this.dependencyTracker?.recordShowTextOperation(t);return}const r=i.fontSize;if(0===r){this.dependencyTracker?.recordOperation(t);return}const s=this.ctx,a=i.fontSizeScale,o=i.charSpacing,l=i.wordSpacing,h=i.fontDirection,c=i.textHScale*h,d=e.length,u=n.vertical,p=u?1:-1,g=n.defaultVMetrics,m=r*i.fontMatrix[0],f=i.textRenderingMode===w&&!n.disableFontFace&&!i.patternFill;s.save();i.textMatrix&&s.transform(...i.textMatrix);s.translate(i.x,i.y+i.textRise);h>0?s.scale(c,-1):s.scale(c,1);let b,y;const v=i.textRenderingMode&_,E=v===w||v===x,C=v===A||v===x;let S=i.lineWidth;const D=i.textMatrixScale;0===D||0===S?C&&(S=this.getSinglePixelWidth()):S/=D;if(1!==a){s.scale(a,a);S/=a}s.lineWidth=S;if(E&&i.patternFill){s.save();const e=i.fillColor.getPattern(s,this,getCurrentTransformInverse(s),_t,t);b=getCurrentTransform(s);s.restore();s.fillStyle=e}if(C&&i.patternStroke){s.save();const e=i.strokeColor.getPattern(s,this,getCurrentTransformInverse(s),Tt,t);y=getCurrentTransform(s);s.restore();s.strokeStyle=e}if(n.isInvalidPDFjsFont){const n=[];let r=0;for(const t of e){n.push(t.unicode);r+=t.width}const a=n.join("");s.fillText(a,0,0);if(null!==this.dependencyTracker){const e=s.measureText(a);this.dependencyTracker.recordBBox(t,this.ctx,-e.actualBoundingBoxLeft,e.actualBoundingBoxRight,-e.actualBoundingBoxAscent,e.actualBoundingBoxDescent).recordShowTextOperation(t)}i.x+=r*m*c;s.restore();this.compose();return}let P,M=0;for(P=0;P<d;++P){const i=e[P];if("number"==typeof i){M+=p*i*r/1e3;continue}let c=!1;const d=(i.isSpace?l:0)+o,v=i.fontChar,w=i.accent;let A,x,E,_=i.width;if(u){const t=i.vmetric||g,e=-(i.vmetric?t[1]:.5*_)*m,n=t[2]*m;_=t?-t[0]:_;A=e/a;x=(M+n)/a}else{A=M/a;x=0}if(n.remeasure&&_>0){E=s.measureText(v);const t=1e3*E.width/r*a;if(_<t&&this.isFontSubpixelAAEnabled){const e=_/t;c=!0;s.save();s.scale(e,1);A/=e}else _!==t&&(A+=(_-t)/2e3*r/a)}if(this.contentVisible&&(i.isInFont||n.missingFile))if(f&&!w){s.fillText(v,A,x);this.dependencyTracker?.recordCharacterBBox(t,s,E?{bbox:null}:n,r/a,A,x,()=>E??s.measureText(v))}else{this.paintChar(t,v,A,x,b,y);if(w){const e=A+r*w.offset.x/a,i=x-r*w.offset.y/a;this.paintChar(t,w.fontChar,e,i,b,y)}}M+=u?_*m-d*h:_*m+d*h;c&&s.restore()}u?i.y-=M:i.x+=M*c;s.restore();this.compose();this.dependencyTracker?.recordShowTextOperation(t)}showType3Text(t,e){const i=this.ctx,n=this.current,r=n.font,a=n.fontSize,o=n.fontDirection,l=r.vertical?1:-1,h=n.charSpacing,c=n.wordSpacing,d=n.textHScale*o,u=n.fontMatrix||s,p=e.length;let g,m,f,b;if(n.textRenderingMode===E||0===a)return;this._cachedScaleForStroking[0]=-1;this._cachedGetSinglePixelWidth=null;i.save();n.textMatrix&&i.transform(...n.textMatrix);i.translate(n.x,n.y+n.textRise);i.scale(d,o);const y=this.dependencyTracker;this.dependencyTracker=y?new CanvasNestedDependencyTracker(y,t):null;for(g=0;g<p;++g){m=e[g];if("number"==typeof m){b=l*m*a/1e3;this.ctx.translate(b,0);n.x+=b*d;continue}const t=(m.isSpace?c:0)+h,s=r.charProcOperatorList[m.operatorListId];if(s){if(this.contentVisible){this.save();i.scale(a,a);i.transform(...u);this.executeOperatorList(s);this.restore()}}else warn(`Type3 character "${m.operatorListId}" is not available.`);const o=[m.width,0];Util.applyTransform(o,u);f=o[0]*a+t;i.translate(f,0);n.x+=f*d}i.restore();y&&(this.dependencyTracker=y)}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},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}setStrokeRGBColor(t,e){this.dependencyTracker?.recordSimpleData("strokeColor",t);this.ctx.strokeStyle=this.current.strokeColor=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.ctx.fillStyle=this.current.fillColor=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){let n;if(this.cachedPatterns.has(e))n=this.cachedPatterns.get(e);else{n=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));this.cachedPatterns.set(e,n)}i&&(n.matrix=i);return n}shadingFill(t,e){if(!this.contentVisible)return;const i=this.ctx;this.save(t);const n=this._getPattern(t,e);i.fillStyle=n.getPattern(i,this,getCurrentTransformInverse(i),Ct,t);const s=getCurrentTransformInverse(i);if(s){const{width:t,height:e}=i.canvas,n=r.slice();Util.axialAlignedBoundingBox([0,0,t,e],s,n);const[a,o,l,h]=n;this.ctx.fillRect(a,o,l-a,h-o)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.dependencyTracker?.resetBBox(t).recordFullPageBBox(t).recordDependencies(t,ct).recordDependencies(t,st).recordOperation(t);this.compose(this.current.getClippedPathBoundingBox());this.restore(t)}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;e.isolated||info("TODO: Support non-isolated groups.");e.knockout&&warn("Knockout groups not supported.");if(!e.needsIsolation&&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.groupLevel++;return}const s=getCurrentTransform(n);e.matrix&&n.transform(...e.matrix);const a=[0,0,n.canvas.width,n.canvas.height];let o;if(e.bbox){o=r.slice();Util.axialAlignedBoundingBox(e.bbox,getCurrentTransform(n),o);o=Util.intersect(o,a)||[0,0,0,0]}else o=a;const l=Math.floor(o[0]),h=Math.floor(o[1]),c=Math.max(Math.ceil(o[2])-l,1),d=Math.max(Math.ceil(o[3])-h,1);this.current.startNewPathAndClipBox([0,0,c,d]);const u=this.canvasFactory.create(c,d);e.smask&&this.smaskGroupCanvases.push(u);const p=u.context;p.translate(-l,-h);p.transform(...s);if(!e.isolated&&!e.smask&&i&&e.needsIsolation){p.save();p.setTransform(1,0,0,1,0,0);p.drawImage(n.canvas,-l,-h);p.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}p.clip(t)}e.smask&&this.smaskStack.push({canvas:u.canvas,context:p,offsetX:l,offsetY:h,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(l,h);n.save()}copyCtxState(n,p);this.ctx=p;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.groupLevel++}endGroup(t,e){if(!this.contentVisible)return;this.groupLevel--;const i=this.ctx,n=this.groupStack.pop();if(null!==n){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())}}else{this.ctx.restore();const e=getCurrentTransform(this.ctx);this.restore(t);this.ctx.save();this.ctx.setTransform(...e);const n=r.slice();Util.axialAlignedBoundingBox([0,0,i.canvas.width,i.canvas.height],e,n);this.ctx.drawImage(i.canvas,0,0);this.ctx.restore();this.canvasFactory.destroy({canvas:i.canvas,context:i});this.compose(n)}}else this.restore(t)}beginAnnotation(t,e,i,n,r,s){this.#zn();resetCtxToDefault(this.ctx);this.ctx.save();this.save(t);this.baseTransform&&this.ctx.setTransform(...this.baseTransform);if(i){const r=i[2]-i[0],a=i[3]-i[1];if(s&&this.annotationCanvasMap){(n=n.slice())[4]-=i[0];n[5]-=i[1];(i=i.slice())[0]=i[1]=0;i[2]=r;i[3]=a;Util.singularValueDecompose2dScale(getCurrentTransform(this.ctx),kt);const{viewportScale:t}=this,s=Math.ceil(r*this.outputScaleX*t),o=Math.ceil(a*this.outputScaleY*t);this.annotationCanvas=this.canvasFactory.create(s,o);const{canvas:l,context:h}=this.annotationCanvas;this.annotationCanvasMap.set(e,l);this.annotationCanvas.savedCtx=this.ctx;this.ctx=h;this.ctx.save();this.ctx.setTransform(kt[0],0,0,-kt[1],0,a*kt[1]);resetCtxToDefault(this.ctx)}else{resetCtxToDefault(this.ctx);this.endPath(t);const e=new Path2D;e.rect(i[0],i[1],r,a);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.ctx,r=this._createMaskCanvas(t,e),s=r.canvas;n.save();n.setTransform(1,0,0,1,0,0);n.drawImage(s,r.offsetX,r.offsetY);this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,r.offsetX,r.offsetX+s.width,r.offsetY,r.offsetY+s.height).recordOperation(t);n.restore();r.canvasEntry&&this.canvasFactory.destroy(r.canvasEntry);this.compose()}paintImageMaskXObjectRepeat(t,e,i,n=0,r=0,s,a){if(!this.contentVisible)return;e=this.getObject(t,e.data,e);const o=this.ctx;o.save();const l=getCurrentTransform(o);o.transform(i,n,r,s,0,0);const h=this._createMaskCanvas(t,e);o.setTransform(1,0,0,1,h.offsetX-l[4],h.offsetY-l[5]);this.dependencyTracker?.resetBBox(t);for(let e=0,c=a.length;e<c;e+=2){const c=Util.transform(l,[i,n,r,s,a[e],a[e+1]]);o.drawImage(h.canvas,c[4],c[5]);this.dependencyTracker?.recordBBox(t,this.ctx,c[4],c[4]+h.canvas.width,c[5],c[5]+h.canvas.height)}o.restore();h.canvasEntry&&this.canvasFactory.destroy(h.canvasEntry);this.compose();this.dependencyTracker?.recordOperation(t)}paintImageMaskXObjectGroup(t,e){if(!this.contentVisible)return;const i=this.ctx,n=this.current.fillColor,r=this.current.patternFill;this.dependencyTracker?.resetBBox(t).recordDependencies(t,dt);for(const s of e){const{data:e,width:a,height:o,transform:l}=s,h=this.canvasFactory.create(a,o),c=h.context;c.save();putBinaryImageMask(c,this.getObject(t,e,s));c.globalCompositeOperation="source-in";c.fillStyle=r?n.getPattern(c,this,getCurrentTransformInverse(i),_t,t):n;c.fillRect(0,0,a,o);c.restore();i.save();i.transform(...l);i.scale(1,-1);drawImageAtIntegerCoords(i,h.canvas,0,0,a,o,0,-1,1,1);this.canvasFactory.destroy(h);this.dependencyTracker?.recordBBox(t,i,0,a,0,o);i.restore()}this.compose();this.dependencyTracker?.recordOperation(t)}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"}return t.canvas}applyTransferMapsToBitmap(t){if("none"===this.current.transferMaps)return{img:t.bitmap,canvasEntry:null};const{bitmap:e,width:i,height:n}=t,r=this.canvasFactory.create(i,n),s=r.context;s.filter=this.current.transferMaps;s.drawImage(e,0,0);s.filter="none";return{img:r.canvas,canvasEntry:r}}paintInlineImageXObject(t,e){if(!this.contentVisible)return;const i=e.width,n=e.height,r=this.ctx;this.save(t);const{filter:s}=r;"none"!==s&&""!==s&&(r.filter="none");r.scale(1/i,-1/n);let a,o=null;if(e.bitmap){const t=this.applyTransferMapsToBitmap(e);a=t.img;o=t.canvasEntry}else if("function"==typeof HTMLElement&&e instanceof HTMLElement||!e.data)a=e;else{const t=this.canvasFactory.create(i,n);putBinaryImageData(t.context,e);a=this.applyTransferMapsToCanvas(t.context);o=t}const l=this._scaleImage(a,getCurrentTransformInverse(r));r.imageSmoothingEnabled=getImageSmoothingEnabled(getCurrentTransform(r),e.interpolate);if(this.dependencyTracker){this.dependencyTracker.resetBBox(t).recordBBox(t,r,0,i,-n,0).recordDependencies(t,ot).recordOperation(t);this.imagesTracker?.record(r,i,n,this.dependencyTracker.clipBox)}drawImageAtIntegerCoords(r,l.img,0,0,l.paintWidth,l.paintHeight,0,-n,i,n);l.tmpCanvas&&this.canvasFactory.destroy(l.tmpCanvas);o&&this.canvasFactory.destroy(o);this.compose();this.restore(t)}paintInlineImageXObjectGroup(t,e,i){if(!this.contentVisible)return;const n=this.ctx;let r,s=null;if(e.bitmap)r=e.bitmap;else{const t=e.width,i=e.height,n=this.canvasFactory.create(t,i);putBinaryImageData(n.context,e);r=this.applyTransferMapsToCanvas(n.context);s=n}this.dependencyTracker?.resetBBox(t);for(const e of i){n.save();n.transform(...e.transform);n.scale(1,-1);drawImageAtIntegerCoords(n,r,e.x,e.y,e.w,e.h,0,-1,1,1);this.dependencyTracker?.recordBBox(t,n,0,1,-1,0);n.restore()}s&&this.canvasFactory.destroy(s);this.dependencyTracker?.recordOperation(t);this.compose()}paintSolidColorImageMask(t){if(this.contentVisible){this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,0,1,0,1).recordDependencies(t,st).recordOperation(t);this.ctx.fillRect(0,0,1,1);this.compose()}}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===Ot?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(){if(!this._cachedGetSinglePixelWidth){const t=getCurrentTransform(this.ctx);if(0===t[1]&&0===t[2])this._cachedGetSinglePixelWidth=1/Math.min(Math.abs(t[0]),Math.abs(t[3]));else{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]);this._cachedGetSinglePixelWidth=Math.max(i,n)/e}}return this._cachedGetSinglePixelWidth}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),h=Math.hypot(n,r);if(0===t){s=h/o;a=l/o}else{const e=t*o;s=h>e?h/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=i.getLineDash();e&&i.save();i.scale(r,s);Mt.a=1/r;Mt.d=1/s;const o=new Path2D;o.addPath(t,Mt);if(a.length>0){const t=Math.max(r,s);i.setLineDash(a.map(e=>e/t));i.lineDashOffset/=t}i.lineWidth=n||1;i.stroke(o);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 O)void 0!==CanvasGraphics.prototype[t]&&(CanvasGraphics.prototype[O[t]]=CanvasGraphics.prototype[t]);class BasePDFStream{#Wn=null;#Vn=null;_fullReader=null;_rangeReaders=new Set;_source=null;constructor(t,e,i){this._source=t;this.#Wn=e;this.#Vn=i}get _progressiveDataLength(){return this._fullReader?._loaded??0}getFullReader(){assert(!this._fullReader,"BasePDFStream.getFullReader can only be called once.");return this._fullReader=new this.#Wn(this)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const i=new this.#Vn(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)return r;if("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-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(t,e,i,n){if("q"===i||"Q"===i)return textdecode(e,n=(n=n.replaceAll("_"," ")).replaceAll(/=([0-9a-fA-F]{2})/g,function(t,e){return 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;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);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)}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);this._abortController.abort()}}__webpack_require__(116);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.#$n(t.begin,t.chunk);break;case"progressiveDone":this._fullReader?.progressiveDone();this._progressiveDone=!0}})}#$n(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);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{#qn=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.#qn()}progressiveDone(){this._done||=!0;0===this._queuedChunks.length&&this.#qn()}}class PDFDataTransportStreamRangeReader extends BasePDFStreamRangeReader{#qn=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.#qn()}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.#qn();this.onDone?.()}}class PDFNetworkStream extends BasePDFStream{#Xn=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.#Xn.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";assert(t.onError,"Expected `onError` callback to be provided.");e.onerror=()=>t.onError(e.status);e.onreadystatechange=this.#Yn.bind(this,e);e.onprogress=this.#Kn.bind(this,e);e.send(null);return e}#Kn(t,e){const i=this.#Xn.get(t);i?.onProgress?.(e)}#Yn(t,e){const i=this.#Xn.get(t);if(!i)return;if(t.readyState>=2&&i.onHeadersReceived){i.onHeadersReceived();delete i.onHeadersReceived}if(4!==t.readyState)return;if(!this.#Xn.has(t))return;this.#Xn.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.#Xn.has(t)){this.#Xn.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{#qn=endRequests.bind(this);_cachedChunks=[];_done=!1;_requests=[];_storedError=null;constructor(t){super(t);this._fullRequestXhr=t._request({onHeadersReceived:this.#Jn.bind(this),onDone:this.#Qn.bind(this),onError:this.#Zn.bind(this),onProgress:this.#Kn.bind(this)})}#Jn(){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?r.trimStart().replace(/[^\S ]+$/,"").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()}#Qn(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.#qn()}#Zn(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}#Kn(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.#qn();this._stream._abortRequest(this._fullRequestXhr);this._fullRequestXhr=null}}class PDFNetworkStreamRangeReader extends BasePDFStreamRangeReader{#qn=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.#Jn.bind(this),onDone:this.#Qn.bind(this),onError:this.#Zn.bind(this),onProgress:null})}#Jn(){const t=getResponseOrigin(this._requestXhr?.responseURL);try{ensureResponseOrigin(t,this._stream._responseOrigin)}catch(t){this._storedError=t;this.#Zn(0)}}#Qn(t){if(this._requests.length>0){this._requests.shift().resolve({value:t,done:!1})}else this._queuedChunk=t;this._done=!0;this.#qn();this.onClosed?.()}#Zn(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.#qn();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;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)}}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)}}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)}}class GlobalWorkerOptions{static#tr=null;static#er="";static get workerPort(){return this.#tr}static set workerPort(t){if(!("undefined"!=typeof Worker&&t instanceof Worker)&&null!==t)throw new Error("Invalid `workerPort` type.");this.#tr=t}static get workerSrc(){return this.#er}static set workerSrc(t){if("string"!=typeof t)throw new Error("Invalid `workerSrc` type.");this.#er=t}}class Metadata{#ir;#nr;constructor({parsedData:t,rawData:e}){this.#ir=t;this.#nr=e}getRaw(){return this.#nr}get(t){return this.#ir.get(t)??null}[Symbol.iterator](){return this.#ir.entries()}}const Bt=Symbol("INTERNAL");class OptionalContentGroup{#rr=!1;#sr=!1;#ar=!1;#or=!0;constructor(t,{name:e,intent:i,usage:n,rbGroups:r}){this.#rr=!!(t&l);this.#sr=!!(t&h);this.name=e;this.intent=i;this.usage=n;this.rbGroups=r}get visible(){if(this.#ar)return this.#or;if(!this.#or)return!1;const{print:t,view:e}=this.usage;return this.#rr?"OFF"!==e?.viewState:!this.#sr||"OFF"!==t?.printState}_setVisible(t,e,i=!1){t!==Bt&&unreachable("Internal method `_setVisible` called.");this.#ar=i;this.#or=e}}class OptionalContentConfig{#lr=null;#hr=new Map;#cr=null;#dr=null;constructor(t,e=l){this.renderingIntent=e;this.name=null;this.creator=null;if(null!==t){this.name=t.name;this.creator=t.creator;this.#dr=t.order;for(const i of t.groups)this.#hr.set(i.id,new OptionalContentGroup(e,i));if("OFF"===t.baseState)for(const t of this.#hr.values())t._setVisible(Bt,!1);for(const e of t.on)this.#hr.get(e)._setVisible(Bt,!0);for(const e of t.off)this.#hr.get(e)._setVisible(Bt,!1);this.#cr=this.getHash()}}#ur(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.#ur(e);else{if(!this.#hr.has(e)){warn(`Optional content group not found: ${e}`);return!0}r=this.#hr.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.#hr.size)return!0;if(!t){info("Optional content group not defined.");return!0}if("OCG"===t.type){if(!this.#hr.has(t.id)){warn(`Optional content group not found: ${t.id}`);return!0}return this.#hr.get(t.id).visible}if("OCMD"===t.type){if(t.expression)return this.#ur(t.expression);if(!t.policy||"AnyOn"===t.policy){for(const e of t.ids){if(!this.#hr.has(e)){warn(`Optional content group not found: ${e}`);return!0}if(this.#hr.get(e).visible)return!0}return!1}if("AllOn"===t.policy){for(const e of t.ids){if(!this.#hr.has(e)){warn(`Optional content group not found: ${e}`);return!0}if(!this.#hr.get(e).visible)return!1}return!0}if("AnyOff"===t.policy){for(const e of t.ids){if(!this.#hr.has(e)){warn(`Optional content group not found: ${e}`);return!0}if(!this.#hr.get(e).visible)return!0}return!1}if("AllOff"===t.policy){for(const e of t.ids){if(!this.#hr.has(e)){warn(`Optional content group not found: ${e}`);return!0}if(this.#hr.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.#hr.get(t);if(n){if(i&&e&&n.rbGroups.length)for(const e of n.rbGroups)for(const i of e)i!==t&&this.#hr.get(i)?._setVisible(Bt,!1,!0);n._setVisible(Bt,!!e,!0);this.#lr=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.#hr.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.#lr=null}get hasInitialVisibility(){return null===this.#cr||this.getHash()===this.#cr}getOrder(){return this.#hr.size?this.#dr?this.#dr.slice():[...this.#hr.keys()]:null}getGroup(t){return this.#hr.get(t)||null}getHash(){if(null!==this.#lr)return this.#lr;const t=new MurmurHash3_64;for(const[e,i]of this.#hr)t.update(`${e}:${i.visible}`);return this.#lr=t.hexdigest()}[Symbol.iterator](){return this.#hr.entries()}}class PagesMapper{#pr=null;#gr=null;#mr=0;#fr=null;#br=null;get pagesNumber(){return this.#mr}set pagesNumber(t){if(this.#mr!==t){this.#mr=t;this.#pr=null;this.#gr=null}}#yr(){if(this.#pr)return;const t=this.#mr,e=this.#pr=new Uint32Array(t);for(let i=0;i<t;i++)e[i]=i+1;this.#gr=new Int32Array(e)}#vr(){const t=new Map,e=this.#pr;for(let i=0,n=this.#mr;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.#yr();const n=this.#pr,r=this.#vr(),s=e.length,a=new Uint32Array(s);let o=0;for(let t=0;t<s;t++){const r=e[t]-1;a[t]=n[r];r<i&&o++}const l=this.#mr,h=l-s,c=MathClamp(i-o,0,h);for(let e=0,i=0;e<l;e++)t.has(e+1)||(n[i++]=n[e]);n.copyWithin(c+s,c,h);n.set(a,c);this.#wr(r);n.every((t,e)=>t===e+1)&&(this.#pr=null)}deletePages(t){this.#yr();const e=this.#pr,i=this.#vr();this.#br={pageNumberToId:e.slice(),pagesNumber:this.#mr,prevPageNumbers:this.#gr.slice()};const n=this.#mr-t.length;this.#mr=n;const r=this.#pr=new Uint32Array(n);this.#gr=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.#wr(i,new Set(t))}cancelDelete(){if(this.#br){this.#pr=this.#br.pageNumberToId;this.#mr=this.#br.pagesNumber;this.#gr=this.#br.prevPageNumbers;this.#br=null}}cleanSavedData(){this.#br=null}copyPages(t){this.#yr();this.#fr={pageNumbers:t,pageIds:t.map(t=>this.#pr[t-1])}}cancelCopy(){this.#fr=null}pastePages(t){this.#yr();const e=this.#pr,i=this.#vr(),{pageNumbers:n,pageIds:r}=this.#fr,s=this.#mr+n.length;this.#mr=s;const a=this.#pr=new Uint32Array(s);this.#gr=new Int32Array(s);a.set(e.subarray(0,t),0);a.set(r,t);a.set(e.subarray(t),t+n.length);this.#wr(i,null,t,n);this.#fr=null}#wr(t,e=null,i=-1,n=null){const r=this.#gr,s=this.#pr,a=i+(n?.length??0),o=new Map;for(let l=0,h=this.#mr;l<h;l++){if(l>=i&&l<a){r[l]=-n[l-i];continue}const h=s[l],c=t.get(h);let d=o.get(h)||0;if(e&&c)for(;d<c.length&&e.has(c[d]);)d++;r[l]=c?.[d];o.set(h,d+1)}}hasBeenAltered(){return null!==this.#pr}getPageMappingForSaving(t=null){t??=this.#vr();let e=0;for(const i of t.values())e=Math.max(e,i.length);const i=new Array(e);for(let t=0;t<e;t++)i[t]={document:null,pageIndices:[],includePages:[]};for(const[e,n]of t)for(let t=0,r=n.length;t<r;t++)i[t].includePages.push([e-1,n[t]-1]);for(const{includePages:t,pageIndices:e}of i){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 i}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)}getPrevPageNumber(t){return this.#gr?.[t-1]??0}getPageNumber(t){if(!this.#pr)return t;const e=this.#pr;for(let i=0,n=this.#mr;i<n;i++)if(e[i]===t)return i+1;return 0}getPageId(t){return this.#pr?.[t-1]??t}getMapping(){return this.#pr?.subarray(0,this.pagesNumber)}}const Lt=Symbol("INITIAL_DATA"),dataObj=()=>({...Promise.withResolvers(),data:Lt});class PDFObjects{#Ar=new Map;get(t,e=null){if(e){const i=this.#Ar.getOrInsertComputed(t,dataObj);i.promise.then(()=>e(i.data));return null}const i=this.#Ar.get(t);if(!i||i.data===Lt)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return i.data}has(t){const e=this.#Ar.get(t);return!!e&&e.data!==Lt}delete(t){const e=this.#Ar.get(t);if(!e||e.data===Lt)return!1;this.#Ar.delete(t);return!0}resolve(t,e=null){const i=this.#Ar.getOrInsertComputed(t,dataObj);if(i.data!==Lt)throw new Error(`Object already resolved ${t}.`);i.data=e;i.resolve()}clear(){for(const{data:t}of this.#Ar.values())t?.bitmap?.close();this.#Ar.clear()}*[Symbol.iterator](){for(const[t,{data:e}]of this.#Ar)e!==Lt&&(yield[t,e])}}class TextLayer{#xr=Promise.withResolvers();#St=null;#Er=!1;#_r=!!globalThis.FontInspector?.enabled;#Tr=null;#Cr=null;#Sr=null;#Dr=0;#Pr=0;#Mr=null;#kr=null;#Ir=0;#Fr=0;#Rr=Object.create(null);#Or=[];#Br=null;#Lr=[];#Nr=new WeakMap;#Ur=null;static#Hr=new Map;static#zr=new Map;static#jr=new WeakMap;static#Gr=null;static#Wr=new Set;constructor({textContentSource:t,images:e,container:i,viewport:n}){if(t instanceof ReadableStream)this.#Br=t;else{if("object"!=typeof t)throw new Error('No "textContentSource" parameter specified.');this.#Br=new ReadableStream({start(e){e.enqueue(t);e.close()}})}this.#St=this.#kr=i;this.#Tr=e;this.#Fr=n.scale*OutputScale.pixelRatio;this.#Ir=n.rotation;this.#Sr={div:null,properties:null,ctx:null};const{pageWidth:r,pageHeight:s,pageX:a,pageY:o}=n.rawDims;this.#Ur=[1,0,0,-1,-a,o+s];this.#Pr=r;this.#Dr=s;TextLayer.#Vr();i.style.setProperty("--min-font-size",TextLayer.#Gr);setLayerDimensions(i,n);this.#xr.promise.finally(()=>{TextLayer.#Wr.delete(this);this.#Sr=null;this.#Rr=null}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=FeatureTest.platform;return shadow(this,"fontFamilyMap",new Map([["sans-serif",(t&&e?"Calibri, ":"")+"sans-serif"],["monospace",(t&&e?"Lucida Console, ":"")+"monospace"]]))}render(){this.#Tr&&this.#St.append(this.#Tr.render());const pump=()=>{this.#Mr.read().then(({value:t,done:e})=>{if(e)this.#xr.resolve();else{this.#Cr??=t.lang;Object.assign(this.#Rr,t.styles);this.#$r(t.items);pump()}},this.#xr.reject)};this.#Mr=this.#Br.getReader();TextLayer.#Wr.add(this);pump();return this.#xr.promise}update({viewport:t,onBefore:e=null}){const i=t.scale*OutputScale.pixelRatio,n=t.rotation;if(n!==this.#Ir){e?.();this.#Ir=n;setLayerDimensions(this.#kr,{rotation:n})}if(i!==this.#Fr){e?.();this.#Fr=i;const t={div:null,properties:null,ctx:TextLayer.#qr(this.#Cr)};for(const e of this.#Lr){t.properties=this.#Nr.get(e);t.div=e;this.#Xr(t)}}}cancel(){const t=new AbortException("TextLayer task cancelled.");this.#Mr?.cancel(t).catch(()=>{});this.#Mr=null;this.#xr.reject(t)}get textDivs(){return this.#Lr}get textContentItemsStr(){return this.#Or}#$r(t){if(this.#Er)return;this.#Sr.ctx??=TextLayer.#qr(this.#Cr);const e=this.#Lr,i=this.#Or;for(const n of t){if(e.length>1e5){warn("Ignoring additional textDivs for performance reasons.");this.#Er=!0;return}if(void 0!==n.str){i.push(n.str);this.#Yr(n)}else if("beginMarkedContentProps"===n.type||"beginMarkedContent"===n.type){const t=this.#St;this.#St=document.createElement("span");this.#St.classList.add("markedContent");n.id&&this.#St.setAttribute("id",`${n.id}`);"Artifact"===n.tag&&(this.#St.ariaHidden=!0);t.append(this.#St)}else"endMarkedContent"===n.type&&(this.#St=this.#St.parentNode)}}#Yr(t){const e=document.createElement("span"),i={angle:0,canvasWidth:0,hasText:""!==t.str,hasEOL:t.hasEOL,fontSize:0};this.#Lr.push(e);const n=Util.transform(this.#Ur,t.transform);let r=Math.atan2(n[1],n[0]);const s=this.#Rr[t.fontName];s.vertical&&(r+=Math.PI/2);let a=this.#_r&&s.fontSubstitution||s.fontFamily;a=TextLayer.fontFamilyMap.get(a)||a;const o=Math.hypot(n[2],n[3]),l=o*TextLayer.#Kr(a,s,this.#Cr);let h,c;if(0===r){h=n[4];c=n[5]-l}else{h=n[4]+l*Math.sin(r);c=n[5]-l*Math.cos(r)}const d=e.style;d.left=`${(100*h/this.#Pr).toFixed(2)}%`;d.top=`${(100*c/this.#Dr).toFixed(2)}%`;d.setProperty("--font-height",`${o.toFixed(2)}px`);d.fontFamily=a;i.fontSize=o;e.setAttribute("role","presentation");e.textContent=t.str;e.dir=t.dir;this.#_r&&(e.dataset.fontName=s.fontSubstitutionLoadedName||t.fontName);0!==r&&(i.angle=r*(180/Math.PI));let u=!1;if(t.str.length>1)u=!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&&(u=!0)}u&&(i.canvasWidth=s.vertical?t.height:t.width);this.#Nr.set(e,i);this.#Sr.div=e;this.#Sr.properties=i;this.#Xr(this.#Sr);i.hasText&&this.#St.append(e);if(i.hasEOL){const t=document.createElement("br");t.setAttribute("role","presentation");this.#St.append(t)}}#Xr(t){const{div:e,properties:i,ctx:n}=t,{style:r}=e;if(0!==i.canvasWidth&&i.hasText){const{fontFamily:t}=r,{canvasWidth:s,fontSize:a}=i;TextLayer.#Jr(n,a*this.#Fr,t);const{width:o}=n.measureText(e.textContent);o>0&&r.setProperty("--scale-x",s*this.#Fr/o)}0!==i.angle&&r.setProperty("--rotate",`${i.angle}deg`)}static cleanup(){if(!(this.#Wr.size>0)){this.#Hr.clear();for(const{canvas:t}of this.#zr.values())t.remove();this.#zr.clear()}}static#qr(t=null){let e=this.#zr.get(t||="");if(!e){const i=document.createElement("canvas");i.className="hiddenCanvasElement";i.lang=t;document.body.append(i);e=i.getContext("2d",{alpha:!1,willReadFrequently:!0});this.#zr.set(t,e);this.#jr.set(e,{size:0,family:""})}return e}static#Jr(t,e,i){const n=this.#jr.get(t);if(e!==n.size||i!==n.family){t.font=`${e}px ${i}`;n.size=e;n.family=i}}static#Vr(){if(null!==this.#Gr)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.#Gr=t.getBoundingClientRect().height;t.remove()}static#Kr(t,e,i){const n=this.#Hr.get(t);if(n)return n;const r=this.#qr(i);r.canvas.width=r.canvas.height=30;this.#Jr(r,30,t);const s=r.measureText(""),a=s.fontBoundingBoxAscent,o=Math.abs(s.fontBoundingBoxDescent);r.canvas.width=r.canvas.height=0;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.#Hr.set(t,l);return l}}function getDocument(t={}){"string"==typeof t||t instanceof URL?t={url:t}:(t instanceof ArrayBuffer||ArrayBuffer.isView(t))&&(t={data:t});const e=new PDFDocumentLoadingTask,{docId:n}=e,r=t.url?function getUrlProp(t){if(t instanceof URL)return t;if("string"==typeof t){if(i){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,s=t.data?function getDataProp(t){if(i&&"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,a=t.httpHeaders||null,o=!0===t.withCredentials,l=t.password??null,h=t.range instanceof PDFDataRangeTransport?t.range:null,c=Number.isInteger(t.rangeChunkSize)&&t.rangeChunkSize>0?t.rangeChunkSize:65536;let d=t.worker instanceof PDFWorker?t.worker:null;const u=t.verbosity,p="string"!=typeof t.docBaseUrl||isDataScheme(t.docBaseUrl)?null:t.docBaseUrl,g=getFactoryUrlProp(t.cMapUrl),m=!1!==t.cMapPacked,f=getFactoryUrlProp(t.iccUrl),b=getFactoryUrlProp(t.standardFontDataUrl),y=getFactoryUrlProp(t.wasmUrl),v=!0!==t.stopAtErrors,w=Number.isInteger(t.maxImageSize)&&t.maxImageSize>-1?t.maxImageSize:-1,A="boolean"==typeof t.isOffscreenCanvasSupported?t.isOffscreenCanvasSupported:!i,x="boolean"==typeof t.isImageDecoderSupported?t.isImageDecoderSupported:!i&&(FeatureTest.platform.isFirefox||!globalThis.chrome),E=Number.isInteger(t.canvasMaxAreaInBytes)?t.canvasMaxAreaInBytes:-1,_="boolean"==typeof t.disableFontFace?t.disableFontFace:i,T=!0===t.fontExtraProperties,C=!0===t.enableXfa,S=t.ownerDocument||globalThis.document,D=!0===t.disableRange,P=!0===t.disableStream,M=!0===t.disableAutoFetch,k=!0===t.pdfBug,I=t.CanvasFactory||(i?NodeCanvasFactory:DOMCanvasFactory),R=t.FilterFactory||(i?NodeFilterFactory:DOMFilterFactory),O=t.BinaryDataFactory||(i?NodeBinaryDataFactory:DOMBinaryDataFactory),B=!0===t.enableHWA,L=!0===t.enableWebGPU?function initGPU(){return Et.init()}():Promise.resolve(!1),N=!1!==t.useWasm,U=t.pagesMapper||new PagesMapper,H="boolean"==typeof t.useSystemFonts?t.useSystemFonts:!i&&!_,z="boolean"==typeof t.useWorkerFetch?t.useWorkerFetch:!!(O===DOMBinaryDataFactory&&g&&m&&b&&y&&isValidFetchUrl(g,document.baseURI)&&isValidFetchUrl(b,document.baseURI)&&isValidFetchUrl(y,document.baseURI));setVerbosityLevel(u);const j={canvasFactory:new I({ownerDocument:S,enableHWA:B}),filterFactory:new R({docId:n,ownerDocument:S}),binaryDataFactory:z?null:new O({cMapUrl:g,standardFontDataUrl:b,wasmUrl:y})};if(!d){d=PDFWorker.create({verbosity:u,port:GlobalWorkerOptions.workerPort});e._worker=d}const G={docId:n,apiVersion:"5.7.284",data:s,password:l,disableAutoFetch:M,rangeChunkSize:c,docBaseUrl:p,enableXfa:C,evaluatorOptions:{maxImageSize:w,disableFontFace:_,ignoreErrors:v,isOffscreenCanvasSupported:A,isImageDecoderSupported:x,canvasMaxAreaInBytes:E,fontExtraProperties:T,useSystemFonts:H,useWasm:N,useWorkerFetch:z,cMapUrl:g,cMapPacked:m,iccUrl:f,standardFontDataUrl:b,wasmUrl:y,hasGPU:!1}},W={ownerDocument:S,pdfBug:k,styleElement:null,enableHWA:B,loadingParams:{disableAutoFetch:M,enableXfa:C}};Promise.all([d.promise,L]).then(function([,t]){if(e.destroyed)throw new Error("Loading aborted");if(d.destroyed)throw new Error("Worker was destroyed");G.evaluatorOptions.hasGPU=t;const l=d.messageHandler.sendWithPromise("GetDocRequest",G,s?[s.buffer]:null);let u;if(s);else if(h)u=new PDFDataTransportStream({pdfDataRangeTransport:h,disableRange:D,disableStream:P});else{if(!r)throw new Error("getDocument - expected either `data`, `range`, or `url` parameter.");{const t=function getNetworkStream(t){return isValidFetchUrl(t)?PDFFetchStream:i?PDFNodeStream:PDFNetworkStream}(r);u=new t({url:r,httpHeaders:a,withCredentials:o,rangeChunkSize:c,disableRange:D,disableStream:P})}}return l.then(t=>{if(e.destroyed)throw new Error("Loading aborted");if(d.destroyed)throw new Error("Worker was destroyed");const i=new MessageHandler(n,t,d.port),r=new WorkerTransport(i,e,u,W,j,U);e._transport=r;i.send("Ready",null)})}).catch(e._capability.reject);return e}class PDFDocumentLoadingTask{static#xn=0;_capability=Promise.withResolvers();_transport=null;_worker=null;docId="d"+PDFDocumentLoadingTask.#xn++;destroyed=!1;onPassword=null;onProgress=null;get promise(){return this._capability.promise}async destroy(){this.destroyed=!0;try{this._worker?.port&&(this._worker._pendingDestroy=!0);await(this._transport?.destroy())}catch(t){this._worker?.port&&delete this._worker._pendingDestroy;throw t}this._transport=null;this._worker?.destroy();this._worker=null}async getData(){return this._transport.getData()}}class PDFDataRangeTransport{#xr=Promise.withResolvers();#Qr=null;constructor(t,e,i=!1,n=null){this.length=t;this.initialData=e;this.progressiveDone=i;this.contentDispositionFilename=n;Object.defineProperty(this,"onDataProgress",{value:()=>{!function deprecated(t){console.log("Deprecated API usage: "+t)}("`PDFDataRangeTransport.prototype.onDataProgress` - method was removed, since loading progress is now reported automatically through the `PDFDataTransportStream` class (and related code).")}})}onDataRange(t,e){this.#Qr({type:"range",begin:t,chunk:e})}onDataProgressiveRead(t){this.#xr.promise.then(()=>{this.#Qr({type:"progressiveRead",chunk:t})})}onDataProgressiveDone(){this.#xr.promise.then(()=>{this.#Qr({type:"progressiveDone"})})}transportReady(t){this.#Qr=t;this.#xr.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 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()}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(){return this._transport.saveDocument()}extractPages(t){return this._transport.extractPages(t)}getDownloadInfo(){return this._transport.downloadInfoCapability.promise}getRawData(t){return this._transport.getRawData(t)}cleanup(t=!1){return this._transport.startCleanup(t||this.isPureXfa)}destroy(){return this.loadingTask.destroy()}cachedPageNumber(t){return this._transport.cachedPageNumber(t)}get loadingParams(){return this._transport.loadingParams}get loadingTask(){return this._transport.loadingTask}getFieldObjects(){return this._transport.getFieldObjects()}hasJSActions(){return this._transport.hasJSActions()}getCalculationOrderIds(){return this._transport.getCalculationOrderIds()}}class PDFPageProxy{#Zr=!1;#ts=null;constructor(t,e,i,n,r=!1){this._pageIndex=t;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.#ts=n;this.imageCoordinates=null}clone(t){const e=new PDFPageProxy(t,this._pageInfo,this._transport,this.#ts,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 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=m.ENABLE,transform:s=null,background:a=null,optionalContentConfigPromise:o=null,annotationCanvasMap:l=null,pageColors:c=null,printAnnotationStorage:d=null,isEditing:u=!1,recordImages:p=!1,recordOperations:g=!1,operationsFilter:f=null}){this._stats?.time("Overall");const b=this._transport.getRenderingIntent(n,r,d,u),{renderingIntent:y,cacheKey:v}=b;this.#Zr=!1;o||=this._transport.getOptionalContentConfig(y);const w=this._intentStates.getOrInsertComputed(v,makeObj);if(w.streamReaderCancelTimeout){clearTimeout(w.streamReaderCancelTimeout);w.streamReaderCancelTimeout=null}const A=!!(y&h);if(!w.displayReadyCapability){w.displayReadyCapability=Promise.withResolvers();w.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null};this._stats?.time("Page Request");this._pumpOperatorList(b)}const x=!(!this._pdfBug||!globalThis.StepperManager?.enabled),E=!!e&&!this.recordedBBoxes&&(g||x),_=!!e&&!this.imageCoordinates&&p,complete=t=>{w.renderTasks.delete(S);if(E){const t=S.gfx?.dependencyTracker.take();if(t){S.stepper?.setOperatorBBoxes(t,S.gfx.dependencyTracker.takeDebugMetadata());g&&(this.recordedBBoxes=t)}}_&&!t&&(this.imageCoordinates=S.gfx?.imagesTracker.take());A&&(this.#Zr=!0);this.#es();if(t){S.capability.reject(t);this._abortOperatorList({intentState:w,reason:t instanceof Error?t:new Error(t)})}else S.capability.resolve();if(this._stats){this._stats.timeEnd("Rendering");this._stats.timeEnd("Overall");globalThis.Stats?.enabled&&globalThis.Stats.add(this.pageNumber,this._stats)}};let T=null,C=null;(E||_)&&(C=new CanvasBBoxTracker(e,w.operatorList.length));E&&(T=new CanvasDependencyTracker(C,x));const S=new InternalRenderTask({callback:complete,params:{canvas:e,canvasContext:t,dependencyTracker:T??C,imagesTracker:_?new CanvasImagesTracker(e):null,viewport:i,transform:s,background:a},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:l,operatorList:w.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!A,pdfBug:this._pdfBug,pageColors:c,enableHWA:this._transport.enableHWA,operationsFilter:f});(w.renderTasks||=new Set).add(S);const D=S.task;Promise.all([w.displayReadyCapability.promise,o]).then(([t,e])=>{if(this.destroyed)complete();else{this._stats?.time("Rendering");if(!(e.renderingIntent&y))throw new Error("Must use the same `intent`-argument when calling the `PDFPageProxy.render` and `PDFDocumentProxy.getOptionalContentConfig` methods.");S.initializeGraphics({transparency:t,optionalContentConfig:e});S.operatorListChanged()}}).catch(complete);return D}getOperatorList({intent:t="display",annotationMode:e=m.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.#ts.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),i={items:[],styles:Object.create(null),lang:null};for await(const t of e){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.#Zr=!1;return Promise.all(t)}cleanup(t=!1){this.#Zr=!0;const e=this.#es();t&&e&&(this._stats&&=new StatTimer);return e}#es(){if(!this.#Zr||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.#Zr=!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.#es()}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:i,modifiedIds:n}){const{map:r,transfer:s}=i,a=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageId:this.#ts.getPageId(this._pageIndex+1)-1,pageIndex:this._pageIndex,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.#es()}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{#xr=Promise.withResolvers();#is=null;#tr=null;#ns=null;static#rs=0;static#ss=!1;static#as=new WeakMap;static{if(i){this.#ss=!0;GlobalWorkerOptions.workerSrc||="./pdf.worker.mjs"}this._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};this._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))}}constructor({name:t=null,port:e=null,verbosity:i=getVerbosityLevel()}={}){this.name=t;this.destroyed=!1;this.verbosity=i;if(e){if(PDFWorker.#as.has(e))throw new Error("Cannot use more than one PDFWorker per port.");PDFWorker.#as.set(e,this);this.#os(e)}else this.#ls()}get promise(){return this.#xr.promise}#hs(){this.#xr.resolve();this.#is.send("configure",{verbosity:this.verbosity})}get port(){return this.#tr}get messageHandler(){return this.#is}#os(t){this.#tr=t;this.#is=new MessageHandler("main","worker",t);this.#is.on("ready",()=>{});this.#hs()}#ls(){if(PDFWorker.#ss||PDFWorker.#cs){this.#ds();return}let{workerSrc:t}=PDFWorker;try{PDFWorker._isSameOrigin(window.location,t)||(t=PDFWorker._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),i=new MessageHandler("main","worker",e),terminateEarly=()=>{n.abort();i.destroy();e.terminate();this.destroyed?this.#xr.reject(new Error("Worker was destroyed")):this.#ds()},n=new AbortController;e.addEventListener("error",()=>{this.#ns||terminateEarly()},{signal:n.signal});i.on("test",t=>{n.abort();if(!this.destroyed&&t){this.#is=i;this.#tr=e;this.#ns=e;this.#hs()}else terminateEarly()});i.on("ready",t=>{n.abort();if(this.destroyed)terminateEarly();else try{sendTest()}catch{this.#ds()}});const sendTest=()=>{const t=new Uint8Array;i.send("test",t,[t.buffer])};sendTest();return}catch{info("The worker has been disabled.")}this.#ds()}#ds(){if(!PDFWorker.#ss){warn("Setting up fake worker.");PDFWorker.#ss=!0}PDFWorker._setupFakeWorkerGlobal.then(t=>{if(this.destroyed){this.#xr.reject(new Error("Worker was destroyed"));return}const e=new LoopbackPort;this.#tr=e;const i="fake"+PDFWorker.#rs++,n=new MessageHandler(i+"_worker",i,e);t.setup(n,e);this.#is=new MessageHandler(i,i+"_worker",e);this.#hs()}).catch(t=>{this.#xr.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){this.destroyed=!0;this.#ns?.terminate();this.#ns=null;PDFWorker.#as.delete(this.#tr);this.#tr=null;this.#is?.destroy();this.#is=null}static create(t){const e=this.#as.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#cs(){try{return globalThis.pdfjsWorker?.WorkerMessageHandler||null}catch{return null}}static get _setupFakeWorkerGlobal(){return shadow(this,"_setupFakeWorkerGlobal",(async()=>{if(this.#cs)return this.#cs;return(await import(
|
||
/*webpackIgnore: true*/
|
||
/*@vite-ignore*/
|
||
this.workerSrc)).WorkerMessageHandler})())}}class WorkerTransport{downloadInfoCapability=Promise.withResolvers();#us=null;#ps=new Map;#gs=null;#ms=new Map;#fs=new Map;#bs=new Map;#ys=null;constructor(t,e,i,n,r,s){this.messageHandler=t;this.loadingTask=e;this.#gs=i;this.commonObjs=new PDFObjects;this.fontLoader=new FontLoader({ownerDocument:n.ownerDocument,styleElement:n.styleElement});this.enableHWA=n.enableHWA;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){const{_pageIndex:e}=t;this.#ms.set(e,t);this.#fs.set(e,Promise.resolve(t))}#vs(t,e=null){return this.#ps.getOrInsertComputed(t,()=>this.messageHandler.sendWithPromise(t,e))}#Kn({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 shadow(this,"annotationStorage",new AnnotationStorage)}getRenderingIntent(t,e=m.ENABLE,i=null,n=!1,r=!1){let s=l,a=Z;switch(t){case"any":s=o;break;case"display":break;case"print":s=h;break;default:warn(`getRenderingIntent - invalid intent: ${t}`)}const f=s&h&&i instanceof PrintAnnotationStorage?i:this.annotationStorage;switch(e){case m.DISABLE:s+=u;break;case m.ENABLE:break;case m.ENABLE_FORMS:s+=c;break;case m.ENABLE_STORAGE:s+=d;a=f.serializable;break;default:warn(`getRenderingIntent - invalid annotationMode: ${e}`)}n&&(s+=p);r&&(s+=g);const{ids:b,hash:y}=f.modifiedIds;return{renderingIntent:s,cacheKey:[s,a.hash,y].join("_"),annotationStorageSerializable:a,modifiedIds:b}}destroy(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0;this.destroyCapability=Promise.withResolvers();this.#ys?.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const e of this.#ms.values())t.push(e._destroy());this.#ms.clear();this.#fs.clear();this.#bs.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.#ps.clear();this.filterFactory.destroy();TextLayer.cleanup();this.#gs?.cancelAllRequests(new AbortException("Worker was terminated."));this.messageHandler?.destroy();this.messageHandler=null;this.destroyCapability.resolve()},this.destroyCapability.reject);return this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(t,e)=>{assert(this.#gs,"GetReader - no `BasePDFStream` instance available.");this.#us=this.#gs.getFullReader();this.#us.onProgress=t=>this.#Kn(t);e.onPull=()=>{this.#us.read().then(function({value:t,done:i}){if(i)e.close();else{assert(t instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer.");e.enqueue(new Uint8Array(t),1,[t])}}).catch(t=>{e.error(t)})};e.onCancel=t=>{this.#us.cancel(t);e.ready.catch(t=>{if(!this.destroyed)throw t})}});t.on("ReaderHeadersReady",async t=>{await this.#us.headersReady;const{isStreamingSupported:e,isRangeSupported:i,contentLength:n}=this.#us;e&&i&&(this.#us.onProgress=null);return{isStreamingSupported:e,isRangeSupported:i,contentLength:n}});t.on("GetRangeReader",(t,e)=>{assert(this.#gs,"GetRangeReader - no `BasePDFStream` instance available.");const i=this.#gs.getRangeReader(t.begin,t.end);if(i){e.onPull=()=>{i.read().then(function({value:t,done:i}){if(i)e.close();else{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.#ys=Promise.withResolvers();try{if(!e.onPassword)throw wrapReason(t);const updatePassword=t=>{t instanceof Error?this.#ys.reject(t):this.#ys.resolve({password:t})};e.onPassword(updatePassword,t.code)}catch(t){this.#ys.reject(t)}return this.#ys.promise});t.on("DataLoaded",t=>{this.#Kn({loaded:t.length,total:t.length});this.downloadInfoCapability.resolve(t)});t.on("StartRenderPage",t=>{if(this.destroyed)return;this.#ms.get(t.pageIndex)._startRenderPage(t.transparency,t.cacheKey)});t.on("commonobj",([e,i,n])=>{if(this.destroyed)return null;if(this.commonObjs.has(e))return null;switch(i){case"Font":if("error"in n){const t=n.error;warn(`Error during font loading: ${t}`);this.commonObjs.resolve(e,t);break}const r=new FontInfo(n),s=this._params.pdfBug&&globalThis.FontInspector?.enabled?(t,e)=>globalThis.FontInspector.fontAdded(t,e):null,a=new FontFaceObject(r,s,n.charProcOperatorList,n.extra);this.fontLoader.bind(a).catch(()=>t.sendWithPromise("FontFallback",{id:e})).finally(()=>{a.fontExtraProperties||a.clearData();this.commonObjs.resolve(e,a)});break;case"CopyLocalImage":const{imageRef:o}=n;assert(o,"The imageRef must be defined.");for(const t of this.#ms.values())for(const[,i]of t.objs){if(i?.ref!==o)continue;if(!i.dataLen)return null;const t=structuredClone(i);this.commonObjs.resolve(e,t);return i.dataLen}break;case"FontPath":this.commonObjs.resolve(e,new FontPathInfo(n));break;case"Image":this.commonObjs.resolve(e,n);break;case"Pattern":const l=new PatternInfo(n);this.commonObjs.resolve(e,l.getIR());break;default:throw new Error(`Got unknown common object type ${i}`)}return null});t.on("obj",([t,e,i,n])=>{if(this.destroyed)return;const r=this.#ms.get(e);if(!r.objs.has(t))if(0!==r._intentStates.size)switch(i){case"Image":case"Pattern":r.objs.resolve(t,n);break;default:throw new Error(`Got unknown object type ${i}`)}else n?.bitmap?.close()});t.on("DocProgress",t=>{this.destroyed||this.#Kn(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(){this.annotationStorage.size<=0&&warn("saveDocument called while `annotationStorage` is empty, please use the getData-method instead.");const{map:t,transfer:e}=this.annotationStorage.serializable;return this.messageHandler.sendWithPromise("SaveDocument",{isPureXfa:!!this._htmlForXfa,numPages:this._numPages,annotationStorage:t,filename:this.#us?.filename??null},e).finally(()=>{this.annotationStorage.resetModified()})}extractPages(t){const e={pageInfos:t};let i;if(this.annotationStorage.size>0){const{map:t,transfer:n}=this.annotationStorage.serializable;e.annotationStorage=t;i=n}return this.messageHandler.sendWithPromise("ExtractPages",e,i).finally(()=>{this.annotationStorage.resetModified()})}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.#fs.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.#bs.set(t.refStr,i);const n=new PDFPageProxy(e,t,this,this.pagesMapper,this._params.pdfBug);this.#ms.set(e,n);return n});this.#fs.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.#vs("GetFieldObjects")}hasJSActions(){return this.#vs("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)}getAnnotationsByType(t,e){return this.messageHandler.sendWithPromise("GetAnnotationsByType",{types:t,pageIndexesToSkip:e})}getDocJSActions(){return this.#vs("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){return this.#vs("GetOptionalContentConfig").then(e=>new OptionalContentConfig(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata";return this.#ps.getOrInsertComputed(t,()=>this.messageHandler.sendWithPromise(t,null).then(t=>({info:t[0],metadata:t[1]?new Metadata(t[1]):null,contentDispositionFilename:this.#us?.filename??null,contentLength:this.#us?.contentLength??null,hasStructTree:t[2]})))}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}getRawData(t){return this.messageHandler.sendWithPromise("GetRawData",t)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const t of this.#ms.values()){if(!t.cleanup())throw new Error(`startCleanup: Page ${t.pageNumber} is currently rendering.`)}this.commonObjs.clear();t||this.fontLoader.clear();this.#ps.clear();this.filterFactory.destroy(!0);TextLayer.cleanup()}}cachedPageNumber(t){if(!isRefProxy(t))return null;const e=0===t.gen?`${t.num}R`:`${t.num}R${t.gen}`,i=this.#bs.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;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}}class InternalRenderTask{#ws=null;static#As=new WeakSet;constructor({callback:t,params:e,objs:i,commonObjs:n,annotationCanvasMap:r,operatorList:s,pageIndex:a,canvasFactory:o,filterFactory:l,useRequestAnimationFrame:h=!1,pdfBug:c=!1,pageColors:d=null,enableHWA:u=!1,operationsFilter:p=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=o;this.filterFactory=l;this._pdfBug=c;this.pageColors=d;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._enableHWA=u;this._dependencyTracker=e.dependencyTracker;this._imagesTracker=e.imagesTracker;this._operationsFilter=p}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){if(this.cancelled)return;if(this._canvas){if(InternalRenderTask.#As.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.#As.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()}const{viewport:i,transform:n,background:r,dependencyTracker:s,imagesTracker:a}=this.params,o=this._canvasContext||this._canvas.getContext("2d",{alpha:!1,willReadFrequently:!this._enableHWA});this.gfx=new CanvasGraphics(o,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors,s,a);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.gfx?.endDrawing();if(this.#ws){window.cancelAnimationFrame(this.#ws);this.#ws=null}InternalRenderTask.#As.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.gfx.dependencyTracker?.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.#ws=window.requestAnimationFrame(()=>{this.#ws=null;this._nextBound().catch(this._cancelBound)}):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){if(!this.cancelled){this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper,this._operationsFilter);if(this.operatorListIdx===this.operatorList.argsArray.length){this.running=!1;if(this.operatorList.lastChunk){this.gfx.endDrawing();InternalRenderTask.#As.delete(this._canvas);this.callback()}}}}}const Nt="5.7.284",Ut="7e5b36c2d";__webpack_require__(3068);class ColorPicker{#xs=null;#Es=null;#_s;#Ts=null;#Cs=!1;#Ss=!1;#a=null;#Ds;#Ps=null;#y=null;static#Ms=null;static get _keyboardManager(){return shadow(this,"_keyboardManager",new KeyboardManager([[["Escape","mac+Escape"],ColorPicker.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],ColorPicker.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],ColorPicker.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],ColorPicker.prototype._moveToPrevious],[["Home","mac+Home"],ColorPicker.prototype._moveToBeginning],[["End","mac+End"],ColorPicker.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){if(t){this.#Ss=!1;this.#a=t}else this.#Ss=!0;this.#y=t?._uiManager||e;this.#Ds=this.#y._eventBus;this.#_s=t?.color?.toUpperCase()||this.#y?.highlightColors.values().next().value||"#FFFF98";ColorPicker.#Ms||=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.#xs=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.#ks.bind(this),{signal:e});t.addEventListener("keydown",this.#Is.bind(this),{signal:e});const i=this.#Es=document.createElement("span");i.className="swatch";i.ariaHidden="true";i.style.backgroundColor=this.#_s;t.append(i);return t}renderMainDropdown(){const t=this.#Ts=this.#Fs();t.ariaOrientation="horizontal";t.ariaLabelledBy="highlightColorPickerLabel";return t}#Fs(){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.#Ms[i]);const s=document.createElement("span");r.append(s);s.className="swatch";s.style.backgroundColor=n;r.ariaSelected=n===this.#_s;r.addEventListener("click",this.#Rs.bind(this,n),{signal:e});t.append(r)}t.addEventListener("keydown",this.#Is.bind(this),{signal:e});return t}#Rs(t,e){e.stopPropagation();this.#Ds.dispatch("switchannotationeditorparams",{source:this,type:y.HIGHLIGHT_COLOR,value:t});this.updateColor(t)}_colorSelectFromKeyboard(t){if(t.target===this.#xs){this.#ks(t);return}const e=t.target.getAttribute("data-color");e&&this.#Rs(e,t)}_moveToNext(t){this.#Os?t.target!==this.#xs?t.target.nextSibling?.focus():this.#Ts.firstElementChild?.focus():this.#ks(t)}_moveToPrevious(t){if(t.target!==this.#Ts?.firstElementChild&&t.target!==this.#xs){this.#Os||this.#ks(t);t.target.previousSibling?.focus()}else this.#Os&&this._hideDropdownFromKeyboard()}_moveToBeginning(t){this.#Os?this.#Ts.firstElementChild?.focus():this.#ks(t)}_moveToEnd(t){this.#Os?this.#Ts.lastElementChild?.focus():this.#ks(t)}#Is(t){ColorPicker._keyboardManager.exec(this,t)}#ks(t){if(this.#Os){this.hideDropdown();return}this.#Cs=0===t.detail;if(!this.#Ps){this.#Ps=new AbortController;window.addEventListener("pointerdown",this.#p.bind(this),{signal:this.#y.combinedSignal(this.#Ps)})}this.#xs.ariaExpanded="true";if(this.#Ts){this.#Ts.classList.remove("hidden");return}const e=this.#Ts=this.#Fs();this.#xs.append(e)}#p(t){this.#Ts?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#Ts?.classList.add("hidden");this.#xs.ariaExpanded="false";this.#Ps?.abort();this.#Ps=null}get#Os(){return this.#Ts&&!this.#Ts.classList.contains("hidden")}_hideDropdownFromKeyboard(){if(!this.#Ss)if(this.#Os){this.hideDropdown();this.#xs.focus({preventScroll:!0,focusVisible:this.#Cs})}else this.#a?.unselect()}updateColor(t){this.#Es&&(this.#Es.style.backgroundColor=t);if(!this.#Ts)return;const e=this.#y.highlightColors.values();for(const i of this.#Ts.children)i.ariaSelected=e.next().value===t.toUpperCase()}destroy(){this.#xs?.remove();this.#xs=null;this.#Es=null;this.#Ts?.remove();this.#Ts=null}}class BasicColorPicker{#Bs=null;#Ls=!1;#a=null;#y=null;static#Ms=null;constructor(t){this.#a=t;this.#y=t._uiManager;BasicColorPicker.#Ms||=Object.freeze({freetext:"pdfjs-editor-color-picker-free-text-input",ink:"pdfjs-editor-color-picker-ink-input"})}renderButton(){if(this.#Bs)return this.#Bs;const{editorType:t,colorType:e,colorAndOpacityType:i,opacityType:n,color:r,opacity:s}=this.#a,a=this.#Ls=FeatureTest.isAlphaColorInputSupported&&void 0!==n,o=this.#Bs=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.#Ms[t]);o.addEventListener("input",()=>{if(a){const t=getRGBA(o.value);if(!t)return;const[r,s,a,l]=t,h=Util.makeHexColor(r,s,a);if(void 0!==i)this.#y.updateParams(i,{color:h,opacity:l});else{this.#y.updateParams(e,h);this.#y.updateParams(n,l)}}else this.#y.updateParams(e,o.value)},{signal:this.#y._signal});return o}update(t){if(this.#Bs)if(this.#Ls){const e=Util.hexNums[Math.round(255*this.#a.opacity)];this.#Bs.value=t+e}else this.#Bs.value=t}updateOpacity(t){if(!this.#Bs||!this.#Ls)return;const e=Util.hexNums[Math.round(255*t)];this.#Bs.value=this.#a.color+e}destroy(){this.#Bs?.remove();this.#Bs=null}hideDropdown(){}}__webpack_require__(531);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(q,t)}}const Ht=new WeakSet,zt=60*(new Date).getTimezoneOffset()*1e3;class AnnotationElementFactory{static create(t){switch(t.data.annotationType){case S.LINK:return new LinkAnnotationElement(t);case S.TEXT:return new TextAnnotationElement(t);case S.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 S.POPUP:return new PopupAnnotationElement(t);case S.FREETEXT:return new FreeTextAnnotationElement(t);case S.LINE:return new LineAnnotationElement(t);case S.SQUARE:return new SquareAnnotationElement(t);case S.CIRCLE:return new CircleAnnotationElement(t);case S.POLYLINE:return new PolylineAnnotationElement(t);case S.CARET:return new CaretAnnotationElement(t);case S.INK:return new InkAnnotationElement(t);case S.POLYGON:return new PolygonAnnotationElement(t);case S.HIGHLIGHT:return new HighlightAnnotationElement(t);case S.UNDERLINE:return new UnderlineAnnotationElement(t);case S.SQUIGGLY:return new SquigglyAnnotationElement(t);case S.STRIKEOUT:return new StrikeOutAnnotationElement(t);case S.STAMP:return new StampAnnotationElement(t);case S.FILEATTACHMENT:return new FileAttachmentAnnotationElement(t);default:return new AnnotationElement(t)}}}class AnnotationElement{#Ns=null;#Us=!1;#Hs=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.svgFactory=t.svgFactory;this.annotationStorage=t.annotationStorage;this.enableComment=t.enableComment;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)}get _isEditable(){return 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(`${f}${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(`${f}${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.#Hs?.popup||this.popup)?.remove();this.#Hs=this.popup=null}updateEdited(t){if(!this.container)return;t.rect&&(this.#Ns||={rect:this.data.rect.slice(0)});const{rect:e,popup:i}=t;e&&this.#zs(e);let n=this.#Hs?.popup||this.popup;if(!n&&i?.text){this._createPopup(i);n=this.#Hs.popup}if(n){n.updateEdited(t);if(i?.deleted){n.remove();this.#Hs=null;this.popup=null}}}resetEdited(){if(this.#Ns){this.#zs(this.#Ns.rect);this.#Hs?.popup.resetEdited();this.#Ns=null}}#zs(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||(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}else if(this instanceof RadioButtonWidgetAnnotationElement){const t=`calc(${a}px * var(--total-scale-factor)) / calc(${o}px * var(--total-scale-factor))`;s.borderRadius=t}switch(e.borderStyle.style){case D:s.borderStyle="solid";break;case P:s.borderStyle="dashed";break;case M:warn("Unimplemented border style: beveled");break;case k:warn("Unimplemented border style: inset");break;case I:s.borderBottomStyle="solid"}const n=e.borderColor||null;if(n){this.#Us=!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:h,pageHeight:c,pageX:d,pageY:u}=n.rawDims;s.left=100*(l[0]-d)/h+"%";s.top=100*(l[1]-u)/c+"%";const{rotation:p}=e;if(e.hasOwnCanvas||0===p){s.width=100*a/h+"%";s.height=100*o/c+"%"}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 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(t=>Math.fround(t));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.#Us){const{borderColor:t,borderWidth:e}=s;s.borderWidth=0;a=["url('data:image/svg+xml;utf8,",'<svg xmlns="http://www.w3.org/2000/svg"',' 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,{svgFactory:h}=this,c=h.createElement("svg");c.classList.add("quadrilateralsContainer");c.setAttribute("width",0);c.setAttribute("height",0);c.role="none";const d=h.createElement("defs");c.append(d);const u=h.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],c=t[i+2],d=t[i+3],p=h.createElement("rect"),g=(c-e)/o,m=(r-s)/l,f=(n-c)/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.#Us){a.push("</g></svg>')");s.backgroundImage=a.join("")}this.container.append(c);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.#Hs=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.#Hs||this.popup||this.data.popupRef)}get extraPopupElement(){return this.#Hs}render(){unreachable("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const i=[];if(this._fieldObjects){const n=this._fieldObjects[t];if(n)for(const{page:t,id:r,exportValues:s}of n){if(-1===t)continue;if(r===e)continue;const n="string"==typeof s?s:null,a=document.querySelector(`[data-element-id="${r}"]`);!a||Ht.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&&(Ht.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})})}get width(){return this.data.rect[2]-this.data.rect[0]}get height(){return this.data.rect[3]-this.data.rect[1]}}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.#js(i,t.attachment,t.overlaidText,t.attachmentDest);n=!0}else if(t.setOCGState){this.#Gs(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.Action||t.actions["Mouse Up"]||t.actions["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}#Ws(){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.#Ws();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.#Ws()}#js(t,e,i="",n=null){t.href=this.linkService.getAnchorUrl("");e.description?t.title=e.description:i&&(t.title=i);t.onclick=()=>{this.downloadManager?.openOrDownloadData(e.content,e.filename,n);return!1};this.#Ws()}#Gs(t,e,i=""){t.href=this.linkService.getAnchorUrl("");t.onclick=()=>{this.linkService.executeSetOCGState(e);return!1};i&&(t.title=i);this.#Ws()}_bindJSAction(t,e){t.href=this.linkService.getAnchorUrl("");const i=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const n of Object.keys(e.actions)){const r=i.get(n);r&&(t[r]=()=>{this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e.id,name:n}});return!1})}e.overlaidText&&(t.title=e.overlaidText);t.onclick||(t.onclick=()=>!1);this.#Ws()}_bindResetFormAction(t,e){const i=t.onclick;i||(t.href=this.linkService.getAnchorUrl(""));this.#Ws();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[i]||[];for(const{id:i}of t)e.add(i)}for(const t of Object.values(this._fieldObjects))for(const i of t)e.has(i.id)===r&&s.push(i)}else for(const t of Object.values(this._fieldObjects))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&&(Ht.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}showElementAndHideCanvas(t){if(this.data.hasOwnCanvas){"CANVAS"===t.previousSibling?.nodeName&&(t.previousSibling.hidden=!0);t.hidden=!1}}_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){for(const[r,s]of i)if("Action"===s||this.data.actions?.[s]){"Focus"!==s&&"Blur"!==s||(e||={focused:!1});this._setEventListener(t,e,r,s,n);"Focus"!==s||this.data.actions?.Blur?"Blur"!==s||this.data.actions?.Focus||this._setEventListener(t,e,"focus","Focus",null):this._setEventListener(t,e,"blur","Blur",null)}}_setBackgroundColor(t){const e=this.data.backgroundColor||null;t.style.backgroundColor=null===e?"transparent":Util.makeHexColor(...e)}_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/(a*n))||1);s=Math.min(n,roundToOneDecimal(e/a))}else{const t=Math.abs(this.data.rect[3]-this.data.rect[1]-2);s=Math.min(n,roundToOneDecimal(t/a))}r.fontSize=`calc(${s}px * var(--total-scale-factor))`;r.color=Util.makeHexColor(...i);null!==this.data.textAlignment&&(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")}this.data.hasOwnCanvas&&(i.hidden=!0);Ht.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:h,timeStep:c}=this.data,d=!!h&&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=h;c&&(e.step=c)}if(o.userValue){const t=o.userValue;if(d)if("time"===h){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-zt).toISOString().split("date"===h?"T":".",1)[0];else e.value=t}o.lastCommittedValue=e.value;o.commitKey=1;this.data.actions?.Focus||(o.focused=!0)});i.addEventListener("updatefromsandbox",i=>{this.showElementAndHideCanvas(i.target);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?.Blur||(o.focused=!1);const{target:i}=t;let{value:r}=i;if(d){if(r&&"time"===h){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?.Keystroke&&i.addEventListener("beforeinput",t=>{o.lastCommittedValue=null;const{data:i,target:n}=t,{value:r,selectionStart:s,selectionEnd:a}=n;let l=s,h=a;switch(t.inputType){case"deleteWordBackward":{const t=r.substring(0,s).match(/\w*[^\w]*$/);t&&(l-=t[0].length);break}case"deleteWordForward":{const t=r.substring(s).match(/^[^\w]*\w*/);t&&(h+=t[0].length);break}case"deleteContentBackward":s===a&&(l-=1);break;case"deleteContentForward":s===a&&(h+=1)}t.preventDefault();this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:r,change:i||"",willCommit:!1,selStart:l,selEnd:h}})});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.letterSpacing=`calc(${t}px * var(--total-scale-factor) - 1ch)`}}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");Ht.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._setBackgroundColor(r);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: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");Ht.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._setBackgroundColor(r);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");Ht.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],h=document.createElement("option");fixDisplayValue(h,s);h.value=o;l?l.before(h):n.append(h);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.#Vs();for(const e of i)e.popup=t}else this.popup=null}#Vs(){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.#Vs(),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=>`${$}${t}`).join(","));return this.container}}class PopupElement{#V=null;#$s=this.#Is.bind(this);#qs=this.#Xs.bind(this);#Ys=this.#Ks.bind(this);#Js=this.#Qs.bind(this);#Zs=null;#St=null;#ta=null;#ea=null;#ia=null;#na=null;#ra=null;#sa=!1;#aa=null;#oa=null;#F=null;#la=null;#ha=null;#we=null;#ca=null;#fe=null;#da=null;#Ns=null;#ua=!1;#pa=null;#ga=null;constructor({container:t,color:e,elements:i,titleObj:n,modificationDate:r,contentsObj:s,richText:a,parent:o,rect:l,parentRect:h,open:c,commentManager:d=null}){this.#St=t;this.#da=n;this.#ta=s;this.#fe=a;this.#na=o;this.#Zs=e;this.#ca=l;this.#ra=h;this.#ia=i;this.#V=d;this.#pa=i[0];this.#ea=PDFDateString.toDateObject(r);this.trigger=i.flatMap(t=>t.getElementsToTriggerPopup());if(!d){this.#ma();this.#St.hidden=!0;c&&this.#Qs()}}#ma(){if(this.#oa)return;this.#oa=new AbortController;const{signal:t}=this.#oa;for(const e of this.trigger){e.addEventListener("click",this.#Js,{signal:t});e.addEventListener("pointerenter",this.#Ys,{signal:t});e.addEventListener("pointerleave",this.#qs,{signal:t});e.classList.add("popupTriggerArea")}for(const e of this.#ia)e.container?.addEventListener("keydown",this.#$s,{signal:t})}#fa(){const t=this.#ia.find(t=>t.hasCommentButton);t&&(this.#ha=t._normalizePoint(t.commentButtonPosition))}renderCommentButton(){if(this.#la){this.#la.parentNode||this.#pa.container.after(this.#la);return}this.#ha||this.#fa();if(!this.#ha)return;const{signal:t}=this.#oa=new AbortController,e=this.#pa.hasOwnCommentButton,togglePopup=()=>{this.#V.toggleCommentPopup(this,!0,void 0,!e)},showPopup=()=>{this.#V.toggleCommentPopup(this,!1,!0,!e)},hidePopup=()=>{this.#V.toggleCommentPopup(this,!1,!1)};if(e){this.#la=this.#pa.container;for(const e of this.trigger){e.ariaHasPopup="dialog";e.ariaControls="commentPopup";e.addEventListener("keydown",this.#$s,{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.#la=document.createElement("button");e.className="annotationCommentButton";const i=this.#pa.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.#ba();this.#ya();e.addEventListener("keydown",this.#$s,{signal:t});e.addEventListener("click",togglePopup,{signal:t});e.addEventListener("pointerenter",showPopup,{signal:t});e.addEventListener("pointerleave",hidePopup,{signal:t});i.after(e)}}#ya(){if(this.#pa.extraPopupElement&&!this.#pa.editor)return;this.#la||this.renderCommentButton();const[t,e]=this.#ha,{style:i}=this.#la;i.left=`calc(${t}%)`;i.top=`calc(${e}% - var(--comment-button-dim))`}#ba(){if(!this.#pa.extraPopupElement){this.#la||this.renderCommentButton();this.#la.style.backgroundColor=this.commentButtonColor||""}}get commentButtonColor(){const{color:t,opacity:e}=this.#pa.commentData;return t?this.#na._commentManager.makeCommentColor(t,e):null}focusCommentButton(){setTimeout(()=>{this.#la?.focus()},0)}getData(){const{richText:t,color:e,opacity:i,creationDate:n,modificationDate:r}=this.#pa.commentData;return{contentsObj:{str:this.comment},richText:t,color:e,opacity:i,creationDate:n,modificationDate:r}}get elementBeforePopup(){return this.#la}get comment(){this.#ga||=this.#pa.commentText;return this.#ga}set comment(t){t!==this.comment&&(this.#pa.commentText=this.#ga=t)}focus(){this.#pa.container?.focus()}get parentBoundingClientRect(){return this.#pa.layer.getBoundingClientRect()}setCommentButtonStates({selected:t,hasPopup:e}){if(this.#la){this.#la.classList.toggle("selected",t);this.#la.ariaExpanded=e}}setSelectedCommentButton(t){this.#la.classList.toggle("selected",t)}get commentPopupPosition(){if(this.#we)return this.#we;const{x:t,y:e,height:i}=this.#la.getBoundingClientRect(),{x:n,y:r,width:s,height:a}=this.#pa.layer.getBoundingClientRect();return[(t-n)/s,(e+i-r)/a]}set commentPopupPosition(t){this.#we=t}hasDefaultPopupPosition(){return null===this.#we}get commentButtonPosition(){return this.#ha}get commentButtonWidth(){return this.#la.getBoundingClientRect().width/this.parentBoundingClientRect.width}editComment(t){const[e,i]=this.#we||this.commentButtonPosition.map(t=>t/100),n=this.parentBoundingClientRect,{x:r,y:s,width:a,height:o}=n;this.#V.showDialog(null,this,r+e*a,s+i*o,{...t,parentDimensions:n})}render(){if(this.#aa)return;const t=this.#aa=document.createElement("div");t.className="popup";if(this.#Zs){const e=t.style.outlineColor=Util.makeHexColor(...this.#Zs);t.style.backgroundColor=`color-mix(in srgb, ${e} 30%, white)`}const e=document.createElement("span");e.className="header";if(this.#da?.str){const t=document.createElement("span");t.className="title";e.append(t);({dir:t.dir,str:t.textContent}=this.#da)}t.append(e);if(this.#ea){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.#ea.valueOf()}));t.dateTime=this.#ea.toISOString();e.append(t)}renderRichText({html:this.#va||this.#ta.str,dir:this.#ta?.dir,className:"popupContent"},t);this.#St.append(t)}get#va(){const t=this.#fe,e=this.#ta;return!t?.str||e?.str&&e.str!==t.str?null:this.#fe.html||null}get#wa(){return this.#va?.attributes?.style?.fontSize||0}get#Aa(){return this.#va?.attributes?.style?.color||null}#xa(t){const e=[],i={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},n={style:{color:this.#Aa,fontSize:this.#wa?`calc(${this.#wa}px * var(--total-scale-factor))`:""}};for(const i of t.split("\n"))e.push({name:"span",value:i,attributes:n});return i}#Is(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||("Enter"===t.key||"Escape"===t.key&&this.#sa)&&this.#Qs()}updateEdited({rect:t,popup:e,deleted:i}){if(this.#V){if(i){this.remove();this.#ga=null}else if(e)if(e.deleted)this.remove();else{this.#ba();this.#ga=e.text}if(t){this.#ha=null;this.#fa();this.#ya()}}else if(i||e?.deleted)this.remove();else{this.#ma();this.#Ns||={contentsObj:this.#ta,richText:this.#fe};t&&(this.#F=null);if(e&&e.text){this.#fe=this.#xa(e.text);this.#ea=PDFDateString.toDateObject(e.date);this.#ta=null}this.#aa?.remove();this.#aa=null}}resetEdited(){if(this.#Ns){({contentsObj:this.#ta,richText:this.#fe}=this.#Ns);this.#Ns=null;this.#aa?.remove();this.#aa=null;this.#F=null}}remove(){this.#oa?.abort();this.#oa=null;this.#aa?.remove();this.#aa=null;this.#ua=!1;this.#sa=!1;this.#la?.remove();this.#la=null;if(this.trigger)for(const t of this.trigger)t.classList.remove("popupTriggerArea")}#Ea(){if(null!==this.#F)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:i,pageX:n,pageY:r}}}=this.#na;let s=!!this.#ra,a=s?this.#ra:this.#ca;for(const t of this.#ia)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,h=o[0]+l,c=o[1];this.#F=[100*(h-n)/e,100*(c-r)/i];const{style:d}=this.#St;d.left=`${this.#F[0]}%`;d.top=`${this.#F[1]}%`}#Qs(){if(this.#V)this.#V.toggleCommentPopup(this,!1);else{this.#sa=!this.#sa;if(this.#sa){this.#Ks();this.#St.addEventListener("click",this.#Js);this.#St.addEventListener("keydown",this.#$s)}else{this.#Xs();this.#St.removeEventListener("click",this.#Js);this.#St.removeEventListener("keydown",this.#$s)}}}#Ks(){this.#aa||this.render();if(this.isVisible)this.#sa&&this.#St.classList.add("focused");else{this.#Ea();this.#St.hidden=!1;this.#St.style.zIndex=parseInt(this.#St.style.zIndex,10)+1e3}}#Xs(){this.#St.classList.remove("focused");if(!this.#sa&&this.isVisible){this.#St.hidden=!0;this.#St.style.zIndex=parseInt(this.#St.style.zIndex,10)-1e3}}forceHide(){this.#ua=this.isVisible;this.#ua&&(this.#St.hidden=!0)}maybeShow(){if(!this.#V){this.#ma();if(this.#ua){this.#aa||this.#Ks();this.#ua=!1;this.#St.hidden=!1}}}get isVisible(){return!this.#V&&!1===this.#St.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=b.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{#_a=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("lineAnnotation");const{data:t,width:e,height:i}=this,n=this.svgFactory.create(e,i,!0),r=this.#_a=this.svgFactory.createElement("svg:line");r.setAttribute("x1",t.rect[2]-t.lineCoordinates[0]);r.setAttribute("y1",t.rect[3]-t.lineCoordinates[1]);r.setAttribute("x2",t.rect[2]-t.lineCoordinates[2]);r.setAttribute("y2",t.rect[3]-t.lineCoordinates[3]);r.setAttribute("stroke-width",t.borderStyle.width||1);r.setAttribute("stroke","transparent");r.setAttribute("fill","transparent");n.append(r);this.container.append(n);if(!t.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}return this.container}getElementsToTriggerPopup(){return this.#_a}addHighlightArea(){this.container.classList.add("highlightArea")}}class SquareAnnotationElement extends AnnotationElement{#Ta=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("squareAnnotation");const{data:t,width:e,height:i}=this,n=this.svgFactory.create(e,i,!0),r=t.borderStyle.width,s=this.#Ta=this.svgFactory.createElement("svg:rect");s.setAttribute("x",r/2);s.setAttribute("y",r/2);s.setAttribute("width",e-r);s.setAttribute("height",i-r);s.setAttribute("stroke-width",r||1);s.setAttribute("stroke","transparent");s.setAttribute("fill","transparent");n.append(s);this.container.append(n);if(!t.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}return this.container}getElementsToTriggerPopup(){return this.#Ta}addHighlightArea(){this.container.classList.add("highlightArea")}}class CircleAnnotationElement extends AnnotationElement{#Ca=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("circleAnnotation");const{data:t,width:e,height:i}=this,n=this.svgFactory.create(e,i,!0),r=t.borderStyle.width,s=this.#Ca=this.svgFactory.createElement("svg:ellipse");s.setAttribute("cx",e/2);s.setAttribute("cy",i/2);s.setAttribute("rx",e/2-r/2);s.setAttribute("ry",i/2-r/2);s.setAttribute("stroke-width",r||1);s.setAttribute("stroke","transparent");s.setAttribute("fill","transparent");n.append(s);this.container.append(n);if(!t.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}return this.container}getElementsToTriggerPopup(){return this.#Ca}addHighlightArea(){this.container.classList.add("highlightArea")}}class PolylineAnnotationElement extends AnnotationElement{#Sa=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=this.svgFactory.create(r,s,!0);let o=[];for(let i=0,n=e.length;i<n;i+=2){const n=e[i]-t[0],r=t[3]-e[i+1];o.push(`${n},${r}`)}o=o.join(" ");const l=this.#Sa=this.svgFactory.createElement(this.svgElementName);l.setAttribute("points",o);l.setAttribute("stroke-width",i.width||1);l.setAttribute("stroke","transparent");l.setAttribute("fill","transparent");a.append(l);this.container.append(a);if(!n&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}return this.container}getElementsToTriggerPopup(){return this.#Sa}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{#Da=null;#Pa=[];constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0});this.containerClassName="inkAnnotation";this.svgElementName="svg:polyline";this.annotationEditorType="InkHighlight"===this.data.it?b.HIGHLIGHT:b.INK}#Ma(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.#Ma(e,t),l=this.svgFactory.create(a,o,!0),h=this.#Da=this.svgFactory.createElement("svg:g");l.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(let t=0,e=i.length;t<e;t++){const e=this.svgFactory.createElement(this.svgElementName);this.#Pa.push(e);e.setAttribute("points",i[t].join(","));h.append(e)}if(!r&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}this.container.append(l);this._editOnDoubleClick();return this.container}updateEdited(t){super.updateEdited(t);const{thickness:e,points:i,rect:n}=t,r=this.#Da;e>=0&&r.setAttribute("stroke-width",e||1);if(i)for(let t=0,e=this.#Pa.length;t<e;t++)this.#Pa[t].setAttribute("points",i[t].join(","));if(n){const{transform:t,width:e,height:i}=this.#Ma(this.data.rotation,n);r.parentElement.setAttribute("viewBox",`0 0 ${e} ${i}`);r.setAttribute("transform",t)}}getElementsToTriggerPopup(){return this.#Pa}addHighlightArea(){this.container.classList.add("highlightArea")}}class HighlightAnnotationElement extends AnnotationElement{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0});this.annotationEditorType=b.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=b.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{#ka=null;constructor(t){super(t,{isRenderable:!0});const{file:e}=this.data;this.filename=e.filename;this.content=e.content;this.linkService.eventBus?.dispatch("fileattachmentannotation",{source:this,...e})}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.#Ia.bind(this));this.#ka=i;const{isMac:n}=FeatureTest.platform;t.addEventListener("keydown",t=>{"Enter"===t.key&&(n?t.metaKey:t.ctrlKey)&&this.#Ia()});if(!e.popupRef&&this.hasPopupData){this.hasOwnCommentButton=!0;this._createPopup()}else i.classList.add("popupTriggerArea");t.append(i);return t}getElementsToTriggerPopup(){return this.#ka}addHighlightArea(){this.container.classList.add("highlightArea")}#Ia(){this.downloadManager?.openOrDownloadData(this.content,this.filename)}}class AnnotationLayer{#Fa=null;#Ra=null;#j=null;#Oa=new Map;#Ba=null;#La=null;#ia=[];#Na=!1;zIndex=0;constructor({div:t,accessibilityManager:e,annotationCanvasMap:i,annotationEditorUIManager:n,page:r,viewport:s,structTreeLayer:a,commentManager:o,linkService:l,annotationStorage:h}){this.div=t;this.#Fa=e;this.#Ra=i;this.#Ba=a||null;this.#La=l||null;this.#j=h||new AnnotationStorage;this.page=r;this.viewport=s;this._annotationEditorUIManager=n;this._commentManager=o||null}hasEditableAnnotations(){return this.#Oa.size>0}async render(t){const{annotations:e}=t,i=this.div;setLayerDimensions(i,this.viewport);const n=new Map,r=[],s={data:null,layer:i,linkService:this.#La,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:!1!==t.renderForms,svgFactory:new DOMSVGFactory,annotationStorage:this.#j,enableComment:!0===t.enableComment,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===S.POPUP;if(e){const e=n.get(t.id);if(!e)continue;if(!this._commentManager){r.push(t);continue}s.elements=e}else if(t.rect[2]===t.rect[0]||t.rect[3]===t.rect[1])continue;s.data=t;const i=AnnotationElementFactory.create(s);if(!i.isRenderable)continue;if(!e){this.#ia.push(i);t.popupRef&&n.getOrInsertComputed(t.popupRef,makeArr).push(i)}const a=i.render();t.hidden&&(a.style.visibility="hidden");if(i._isEditable){this.#Oa.set(i.data.id,i);this._annotationEditorUIManager?.renderAnnotationElement(i)}}await this.#Ua();for(const t of r){const e=s.elements=n.get(t.id);s.data=t;const i=AnnotationElementFactory.create(s);if(!i.isRenderable)continue;const r=i.render();i.contentElement.id=`${$}${t.id}`;t.hidden&&(r.style.visibility="hidden");e.at(-1).container.after(r)}this.#Ha()}async#Ua(){if(0===this.#ia.length)return;this.div.replaceChildren();const t=[];if(!this.#Na){this.#Na=!0;for(const{contentElement:e,data:{id:i}}of this.#ia){const n=e.id=`${$}${i}`;t.push(this.#Ba?.getAriaAttributes(n).then(t=>{if(t)for(const[i,n]of t)e.setAttribute(i,n)}))}}this.#ia.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,h=(s+o)/2;if(l>=o&&h<=e)return-1;if(h>=n&&l<=s)return 1;return(t+i)/2-(r+a)/2});const e=document.createDocumentFragment();for(const t of this.#ia){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.#Fa)for(const t of this.#ia)this.#Fa.addPointerInTextLayer(t.contentElement,!1)}async addLinkAnnotations(t){const e={data:null,layer:this.div,linkService:this.#La,svgFactory:new DOMSVGFactory,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=`${$}${i.id}`;this.#ia.push(t)}}await this.#Ua()}update({viewport:t}){const e=this.div;this.viewport=t;setLayerDimensions(e,{rotation:t.rotation});this.#Ha();e.hidden=!1}#Ha(){if(!this.#Ra)return;const t=this.div;for(const[e,i]of this.#Ra){const n=t.querySelector(`[data-annotation-id="${e}"]`);if(!n)continue;i.className="annotationContent";const{firstChild:r}=n;r?"CANVAS"===r.nodeName?r.replaceWith(i):r.classList.contains("annotationContent")?r.after(i):r.before(i):n.append(i);const s=this.#Oa.get(e);if(s)if(s._hasNoCanvas){this._annotationEditorUIManager?.setMissingCanvas(e,n.id,i);s._hasNoCanvas=!1}else s.canvas=i}this.#Ra.clear()}getEditableAnnotations(){return this.#Oa.values()}getEditableAnnotation(t){return this.#Oa.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.#La,annotationStorage:this.#j});r.render();r.contentElement.id=`${$}${i}`;r.createOrUpdatePopup();this.#ia.push(r);return r}removeAnnotation(t){const e=this.#ia.findIndex(e=>e.data.id===t);if(e<0)return;const[i]=this.#ia.splice(e,1);this.#Fa?.removePointerInTextLayer(i.contentElement)}updateFakeAnnotations(t){if(0!==t.length){for(const e of t)e.updateFakeAnnotationElement(this);this.#Ua()}}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}static get _defaultBorderStyle(){return shadow(this,"_defaultBorderStyle",Object.freeze({width:1,rawWidth:1,style:D,dashArray:[3],horizontalCornerRadius:0,verticalCornerRadius:0}))}}const jt=/\r\n?|\n/g;class FreeTextEditor extends AnnotationEditor{#za="";#ja=`${this.id}-editor`;#Ga=null;#wa;_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 shadow(this,"_keyboardManager",new KeyboardManager([[["ctrl+s","mac+meta+s","ctrl+p","mac+meta+p"],t.commitOrRemove,{bubbles:!0}],[["ctrl+Enter","mac+meta+Enter","Escape","mac+Escape"],t.commitOrRemove],[["ArrowLeft","mac+ArrowLeft"],t._translateEmpty,{args:[-e,0],checker:arrowChecker}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t._translateEmpty,{args:[-i,0],checker:arrowChecker}],[["ArrowRight","mac+ArrowRight"],t._translateEmpty,{args:[e,0],checker:arrowChecker}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t._translateEmpty,{args:[i,0],checker:arrowChecker}],[["ArrowUp","mac+ArrowUp"],t._translateEmpty,{args:[0,-e],checker:arrowChecker}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t._translateEmpty,{args:[0,-i],checker:arrowChecker}],[["ArrowDown","mac+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=b.FREETEXT;constructor(t){super({...t,name:"freeTextEditor"});this.color=t.color||FreeTextEditor._defaultColor||AnnotationEditor._defaultLineColor;this.#wa=t.fontSize||FreeTextEditor._defaultFontSize;this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-freetext-added-alert");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 y.FREETEXT_SIZE:FreeTextEditor._defaultFontSize=e;break;case y.FREETEXT_COLOR:FreeTextEditor._defaultColor=e}}updateParams(t,e){switch(t){case y.FREETEXT_SIZE:this.#Wa(e);break;case y.FREETEXT_COLOR:this.#ba(e)}}static get defaultPropertiesToUpdate(){return[[y.FREETEXT_SIZE,FreeTextEditor._defaultFontSize],[y.FREETEXT_COLOR,FreeTextEditor._defaultColor||AnnotationEditor._defaultLineColor]]}get propertiesToUpdate(){return[[y.FREETEXT_SIZE,this.#wa],[y.FREETEXT_COLOR,this.color]]}get toolbarButtons(){this._colorPicker||=new BasicColorPicker(this);return[["colorPicker",this._colorPicker]]}get colorType(){return y.FREETEXT_COLOR}#Wa(t){const setFontsize=t=>{this.editorDiv.style.fontSize=`calc(${t}px * var(--total-scale-factor))`;this.translate(0,-(t-this.#wa)*this.parentScale);this.#wa=t;this.#Va()},e=this.#wa;this.addCommands({cmd:setFontsize.bind(this,t),undo:setFontsize.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:y.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})}onUpdatedColor(){this.editorDiv.style.color=this.color;this._colorPicker?.update(this.color);super.onUpdatedColor()}#ba(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:y.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.#wa)*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.#Ga=new AbortController;const t=this._uiManager.combinedSignal(this.#Ga);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.#ja);this._isDraggable=!0;this.#Ga?.abort();this.#Ga=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()}#$a(){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.#qa(i));e=i}return t.join("\n")}#Va(){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.#za,e=this.#za=this.#$a().trimEnd();if(t===e)return;const setText=t=>{this.#za=t;if(t){this.#Xa();this._uiManager.rebuild(this);this.#Va()}else this.remove()};this.addCommands({cmd:()=>{setText(e)},undo:()=>{setText(t)},mustExec:!1});this.#Va()}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.#ja);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.#wa}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,[h,c]=this.pageTranslation;let d,u;switch(this.rotation){case 0:d=t+(r[0]-h)/o;u=e+this.height-(r[1]-c)/l;break;case 90:d=t+(r[0]-h)/o;u=e-(r[1]-c)/l;[s,a]=[a,-s];break;case 180:d=t-this.width+(r[0]-h)/o;u=e-(r[1]-c)/l;[s,a]=[-s,-a];break;case 270:d=t+(r[0]-h-this.height*l)/o;u=e+(r[1]-c-this.width*o)/l;[s,a]=[-a,s]}this.setAt(d*i,u*n,s,a)}else this._moveAfterPaste(t,e);this.#Xa();this._isDraggable=!0;this.editorDiv.contentEditable=!1}else{this._isDraggable=!1;this.editorDiv.contentEditable=!0}return this.div}static#qa(t){return(t.nodeType===Node.TEXT_NODE?t.nodeValue:t.innerText).replaceAll(jt,"")}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.#Ya(e.getData("text")||"").replaceAll(jt,"\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=[],h=[];if(a.nodeType===Node.TEXT_NODE){const t=a.parentElement;h.push(a.nodeValue.slice(o).replaceAll(jt,""));if(t!==this.editorDiv){let e=l;for(const i of this.editorDiv.childNodes)i!==t?e.push(FreeTextEditor.#qa(i)):e=h}l.push(a.nodeValue.slice(0,o).replaceAll(jt,""))}else if(a===this.editorDiv){let t=l,e=0;for(const i of this.editorDiv.childNodes){e++===o&&(t=h);t.push(FreeTextEditor.#qa(i))}}this.#za=`${l.join("\n")}${n}${h.join("\n")}`;this.#Xa();const c=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){c.setStart(t,d);c.setEnd(t,d);break}d-=e}r.removeAllRanges();r.addRange(c)}#Xa(){this.editorDiv.replaceChildren();if(this.#za)for(const t of this.#za.split("\n")){const e=document.createElement("div");e.append(t?document.createTextNode(t):document.createElement("br"));this.editorDiv.append(e)}}#Ka(){return this.#za.replaceAll(" "," ")}static#Ya(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:h,creationDate:c,modificationDate:d},textContent:u,textPosition:p,parent:{page:{pageNumber:g}}}=t;if(!u||0===u.length)return null;n=t={annotationType:b.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:h?.str||null,richText:l,creationDate:c,modificationDate:d}}const r=await super.deserialize(t,e,i);r.#wa=t.fontSize;r.color=Util.makeHexColor(...t.color);r.#za=FreeTextEditor.#Ya(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.#wa,value:this.#Ka()});this.addComment(i);if(t){i.isCopy=!0;return i}if(this.annotationElementId&&!this.#Ja(i))return null;i.id=this.annotationElementId;return i}#Ja(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.#wa}px * var(--total-scale-factor))`;i.color=this.color;e.replaceChildren();for(const t of this.#za.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.#za}});return e}resetAnnotationElement(t){super.resetAnnotationElement(t);t.resetEdited()}}class Outline{static PRECISION=1e-4;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.")}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){switch(r){case 90:return[1-e/i,t/n];case 180:return[1-t/i,1-e/n];case 270:return[e/i,1-t/n];default:return[t/i,e/n]}}static _normalizePagePoint(t,e,i){switch(i){case 90:return[1-e,t];case 180:return[1-t,1-e];case 270:return[e,1-t];default:return[t,e]}}static createBezierPoints(t,e,i,n,r,s){return[(t+5*i)/6,(e+5*n)/6,(5*i+r)/6,(5*n+s)/6,(i+r)/2,(n+s)/2]}}class FreeDrawOutliner{#Qa;#Za=[];#to;#eo;#io=[];#no=new Float32Array(18);#ro;#so;#ao;#oo;#lo;#ho;#co=[];static#do=8;static#uo=2;static#po=FreeDrawOutliner.#do+FreeDrawOutliner.#uo;constructor({x:t,y:e},i,n,r,s,a=0){this.#Qa=i;this.#ho=r*n;this.#eo=s;this.#no.set([NaN,NaN,NaN,NaN,t,e],6);this.#to=a;this.#oo=FreeDrawOutliner.#do*n;this.#ao=FreeDrawOutliner.#po*n;this.#lo=n;this.#co.push(t,e)}isEmpty(){return isNaN(this.#no[8])}#go(){const t=this.#no.subarray(4,6),e=this.#no.subarray(16,18),[i,n,r,s]=this.#Qa;return[(this.#ro+(t[0]-e[0])/2-i)/r,(this.#so+(t[1]-e[1])/2-n)/s,(this.#ro+(e[0]-t[0])/2-i)/r,(this.#so+(e[1]-t[1])/2-n)/s]}add({x:t,y:e}){this.#ro=t;this.#so=e;const[i,n,r,s]=this.#Qa;let[a,o,l,h]=this.#no.subarray(8,12);const c=t-l,d=e-h,u=Math.hypot(c,d);if(u<this.#ao)return!1;const p=u-this.#oo,g=p/u,m=g*c,f=g*d;let b=a,y=o;a=l;o=h;l+=m;h+=f;this.#co?.push(t,e);const v=m/p,w=-f/p*this.#ho,A=v*this.#ho;this.#no.set(this.#no.subarray(2,8),0);this.#no.set([l+w,h+A],4);this.#no.set(this.#no.subarray(14,18),12);this.#no.set([l-w,h-A],16);if(isNaN(this.#no[6])){if(0===this.#io.length){this.#no.set([a+w,o+A],2);this.#io.push(NaN,NaN,NaN,NaN,(a+w-i)/r,(o+A-n)/s);this.#no.set([a-w,o-A],14);this.#Za.push(NaN,NaN,NaN,NaN,(a-w-i)/r,(o-A-n)/s)}this.#no.set([b,y,a,o,l,h],6);return!this.isEmpty()}this.#no.set([b,y,a,o,l,h],6);if(Math.abs(Math.atan2(y-o,b-a)-Math.atan2(f,m))<Math.PI/2){[a,o,l,h]=this.#no.subarray(2,6);this.#io.push(NaN,NaN,NaN,NaN,((a+l)/2-i)/r,((o+h)/2-n)/s);[a,o,b,y]=this.#no.subarray(14,18);this.#Za.push(NaN,NaN,NaN,NaN,((b+a)/2-i)/r,((y+o)/2-n)/s);return!0}[b,y,a,o,l,h]=this.#no.subarray(0,6);this.#io.push(((b+5*a)/6-i)/r,((y+5*o)/6-n)/s,((5*a+l)/6-i)/r,((5*o+h)/6-n)/s,((a+l)/2-i)/r,((o+h)/2-n)/s);[l,h,a,o,b,y]=this.#no.subarray(12,18);this.#Za.push(((b+5*a)/6-i)/r,((y+5*o)/6-n)/s,((5*a+l)/6-i)/r,((5*o+h)/6-n)/s,((a+l)/2-i)/r,((o+h)/2-n)/s);return!0}toSVGPath(){if(this.isEmpty())return"";const t=this.#io,e=this.#Za;if(isNaN(this.#no[6])&&!this.isEmpty())return this.#mo();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.#fo(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.#bo(i);return i.join(" ")}#mo(){const[t,e,i,n]=this.#Qa,[r,s,a,o]=this.#go();return`M${(this.#no[2]-t)/i} ${(this.#no[3]-e)/n} L${(this.#no[4]-t)/i} ${(this.#no[5]-e)/n} L${r} ${s} L${a} ${o} L${(this.#no[16]-t)/i} ${(this.#no[17]-e)/n} L${(this.#no[14]-t)/i} ${(this.#no[15]-e)/n} Z`}#bo(t){const e=this.#Za;t.push(`L${e[4]} ${e[5]} Z`)}#fo(t){const[e,i,n,r]=this.#Qa,s=this.#no.subarray(4,6),a=this.#no.subarray(16,18),[o,l,h,c]=this.#go();t.push(`L${(s[0]-e)/n} ${(s[1]-i)/r} L${o} ${l} L${h} ${c} 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.#io,e=this.#Za,i=this.#no,[n,r,s,a]=this.#Qa,o=new Float32Array((this.#co?.length??0)+2);for(let t=0,e=o.length-2;t<e;t+=2){o[t]=(this.#co[t]-n)/s;o[t+1]=(this.#co[t+1]-r)/a}o[o.length-2]=(this.#ro-n)/s;o[o.length-1]=(this.#so-r)/a;if(isNaN(i[6])&&!this.isEmpty())return this.#yo(o);const l=new Float32Array(this.#io.length+24+this.#Za.length);let h=t.length;for(let e=0;e<h;e+=2)if(isNaN(t[e]))l[e]=l[e+1]=NaN;else{l[e]=t[e];l[e+1]=t[e+1]}h=this.#vo(l,h);for(let t=e.length-6;t>=6;t-=6)for(let i=0;i<6;i+=2)if(isNaN(e[t+i])){l[h]=l[h+1]=NaN;h+=2}else{l[h]=e[t+i];l[h+1]=e[t+i+1];h+=2}this.#wo(l,h);return this.newFreeDrawOutline(l,o,this.#Qa,this.#lo,this.#to,this.#eo)}#yo(t){const e=this.#no,[i,n,r,s]=this.#Qa,[a,o,l,h]=this.#go(),c=new Float32Array(36);c.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,h,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(c,t,this.#Qa,this.#lo,this.#to,this.#eo)}#wo(t,e){const i=this.#Za;t.set([NaN,NaN,NaN,NaN,i[4],i[5]],e);return e+6}#vo(t,e){const i=this.#no.subarray(4,6),n=this.#no.subarray(16,18),[r,s,a,o]=this.#Qa,[l,h,c,d]=this.#go();t.set([NaN,NaN,NaN,NaN,(i[0]-r)/a,(i[1]-s)/o,NaN,NaN,NaN,NaN,l,h,NaN,NaN,NaN,NaN,c,d,NaN,NaN,NaN,NaN,(n[0]-r)/a,(n[1]-s)/o],e);return e+24}}class FreeDrawOutline extends Outline{#Qa;#Ao=new Float32Array(4);#to;#eo;#co;#lo;#xo;constructor(t,e,i,n,r,s){super();this.#xo=t;this.#co=e;this.#Qa=i;this.#lo=n;this.#to=r;this.#eo=s;this.firstPoint=[NaN,NaN];this.lastPoint=[NaN,NaN];this.#Eo(s);const[a,o,l,h]=this.#Ao;for(let e=0,i=t.length;e<i;e+=2){t[e]=(t[e]-a)/l;t[e+1]=(t[e+1]-o)/h}for(let t=0,i=e.length;t<i;t+=2){e[t]=(e[t]-a)/l;e[t+1]=(e[t+1]-o)/h}}toSVGPath(){const t=[`M${this.#xo[4]} ${this.#xo[5]}`];for(let e=6,i=this.#xo.length;e<i;e+=6)isNaN(this.#xo[e])?t.push(`L${this.#xo[e+4]} ${this.#xo[e+5]}`):t.push(`C${this.#xo[e]} ${this.#xo[e+1]} ${this.#xo[e+2]} ${this.#xo[e+3]} ${this.#xo[e+4]} ${this.#xo[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.#xo,t,n,s,-a);l=Outline._rescale(this.#co,t,n,s,-a);break;case 90:o=Outline._rescaleAndSwap(this.#xo,t,e,s,a);l=Outline._rescaleAndSwap(this.#co,t,e,s,a);break;case 180:o=Outline._rescale(this.#xo,i,e,-s,a);l=Outline._rescale(this.#co,i,e,-s,a);break;case 270:o=Outline._rescaleAndSwap(this.#xo,i,n,-s,-a);l=Outline._rescaleAndSwap(this.#co,i,n,-s,-a)}return{outline:Array.from(o),points:[Array.from(l)]}}#Eo(t){const e=this.#xo;let i=e[4],r=e[5];const s=[i,r,i,r];let a=i,o=r,l=i,h=r;const c=t?Math.max:Math.min,d=new Float32Array(4);for(let t=6,u=e.length;t<u;t+=6){const u=e[t+4],p=e[t+5];if(isNaN(e[t])){Util.pointBoundingBox(u,p,s);if(o>p){a=u;o=p}else o===p&&(a=c(a,u));if(h<p){l=u;h=p}else h===p&&(l=c(l,u))}else{d.set(n,0);Util.bezierBoundingBox(i,r,...e.slice(t,t+6),d);Util.rectBoundingBox(...d,s);if(o>d[1]){a=d[0];o=d[1]}else o===d[1]&&(a=c(a,d[0]));if(h<d[3]){l=d[2];h=d[3]}else h===d[3]&&(l=c(l,d[2]))}i=u;r=p}const u=this.#Ao;u[0]=s[0]-this.#to;u[1]=s[1]-this.#to;u[2]=s[2]-s[0]+2*this.#to;u[3]=s[3]-s[1]+2*this.#to;this.firstPoint=[a,o];this.lastPoint=[l,h]}get box(){return this.#Ao}newOutliner(t,e,i,n,r,s=0){return new FreeDrawOutliner(t,e,i,n,r,s)}getNewOutline(t,e){const[i,n,r,s]=this.#Ao,[a,o,l,h]=this.#Qa,c=r*l,d=s*h,u=i*l+a,p=n*h+o,g=this.newOutliner({x:this.#co[0]*c+u,y:this.#co[1]*d+p},this.#Qa,this.#lo,t,this.#eo,e??this.#to);for(let t=2;t<this.#co.length;t+=2)g.add({x:this.#co[t]*c+u,y:this.#co[t+1]*d+p});return g.getOutlines()}}class HighlightOutliner{#Qa;#_o;#To;#Co=[];#So=[];constructor(t,e=0,i=0,r=!0){const s=n.slice(),a=1e-4;for(const{x:i,y:n,width:r,height:o}of t){const t=Math.floor((i-e)/a)*a,l=Math.ceil((i+r+e)/a)*a,h=Math.floor((n-e)/a)*a,c=Math.ceil((n+o+e)/a)*a,d=[t,h,c,!0],u=[l,h,c,!1];this.#Co.push(d,u);Util.rectBoundingBox(t,h,l,c,s)}const o=s[2]-s[0]+2*i,l=s[3]-s[1]+2*i,h=s[0]-i,c=s[1]-i;let d=r?-1/0:1/0,u=1/0;const p=this.#Co.at(r?-1:-2),g=[p[0],p[2]];for(const t of this.#Co){const[e,i,n,s]=t;if(!s&&r)if(i<u){u=i;d=e}else i===u&&(d=Math.max(d,e));else if(s&&!r)if(i<u){u=i;d=e}else i===u&&(d=Math.min(d,e));t[0]=(e-h)/o;t[1]=(i-c)/l;t[2]=(n-c)/l}this.#Qa=new Float32Array([h,c,o,l]);this.#_o=[d,u];this.#To=g}getOutlines(){this.#Co.sort((t,e)=>t[0]-e[0]||t[1]-e[1]||t[2]-e[2]);const t=[];for(const e of this.#Co)if(e[3]){t.push(...this.#Do(e));this.#Po(e)}else{this.#Mo(e);t.push(...this.#Do(e))}return this.#ko(t)}#ko(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=[];let r;for(;i.size>0;){const t=i.values().next().value;let[e,s,a,o,l]=t;i.delete(t);let h=e,c=s;r=[e,a];n.push(r);for(;;){let t;if(i.has(o))t=o;else{if(!i.has(l))break;t=l}i.delete(t);[e,s,a,o,l]=t;if(h!==e){r.push(h,c,e,c===s?s:a);h=e}c=c===s?a:s}r.push(h,c)}return new HighlightOutline(n,this.#Qa,this.#_o,this.#To)}#Io(t){const e=this.#So;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}#Po([,t,e]){const i=this.#Io(t);this.#So.splice(i,0,[t,e])}#Mo([,t,e]){const i=this.#Io(t);for(let n=i;n<this.#So.length;n++){const[i,r]=this.#So[n];if(i!==t)break;if(i===t&&r===e){this.#So.splice(n,1);return}}for(let n=i-1;n>=0;n--){const[i,r]=this.#So[n];if(i!==t)break;if(i===t&&r===e){this.#So.splice(n,1);return}}}#Do(t){const[e,i,n]=t,r=[[e,i,n]],s=this.#Io(n);for(let t=0;t<s;t++){const[i,n]=this.#So[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{#Qa;#Fo;constructor(t,e,i,n){super();this.#Fo=t;this.#Qa=e;this.firstPoint=i;this.lastPoint=n}toSVGPath(){const t=[];for(const e of this.#Fo){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.#Fo){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.#Qa}get classNamesForOutlining(){return["highlightOutline"]}}class FreeHighlightOutliner extends FreeDrawOutliner{newFreeDrawOutline(t,e,i,n,r,s){return new FreeHighlightOutline(t,e,i,n,r,s)}}class FreeHighlightOutline extends FreeDrawOutline{newOutliner(t,e,i,n,r,s=0){return new FreeHighlightOutliner(t,e,i,n,r,s)}}class HighlightEditor extends AnnotationEditor{#Ro=null;#Oo=0;#Bo;#Lo=null;#s=null;#No=null;#Uo=null;#Ho=0;#zo=null;#jo=null;#C=null;#Go=!1;#_o=null;#To=null;#Wo=null;#be="";#ho;#Vo="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=b.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const t=HighlightEditor.prototype;return shadow(this,"_keyboardManager",new KeyboardManager([[["ArrowLeft","mac+ArrowLeft"],t._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],t._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],t._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],t._moveCaret,{args:[3]}]]))}constructor(t){super({...t,name:"highlightEditor"});this.color=t.color||HighlightEditor._defaultColor;this.#ho=t.thickness||HighlightEditor._defaultThickness;this.opacity=t.opacity||HighlightEditor._defaultOpacity;this.#Bo=t.boxes||null;this.#Vo=t.methodOfCreation||"";this.#be=t.text||"";this._isDraggable=!1;this.defaultL10nId="pdfjs-editor-highlight-editor";if(t.highlightId>-1){this.#Go=!0;this.#$o(t);this.#qo()}else if(this.#Bo){this.#Ro=t.anchorNode;this.#Oo=t.anchorOffset;this.#Uo=t.focusNode;this.#Ho=t.focusOffset;this.#Xo();this.#qo();this.rotate(this.rotation)}this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert")}get telemetryInitialData(){return{action:"added",type:this.#Go?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#ho,methodOfCreation:this.#Vo}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}#Xo(){const t=new HighlightOutliner(this.#Bo,.001);this.#jo=t.getOutlines();[this.x,this.y,this.width,this.height]=this.#jo.box;const e=new HighlightOutliner(this.#Bo,.0025,.001,"ltr"===this._uiManager.direction);this.#No=e.getOutlines();const{firstPoint:i}=this.#jo;this.#_o=[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height];const{lastPoint:n}=this.#No;this.#To=[(n[0]-this.x)/this.width,(n[1]-this.y)/this.height]}#$o({highlightOutlines:t,highlightId:e,clipPathId:i}){this.#jo=t;this.#No=t.getNewOutline(this.#ho/2+1.5,.0025);if(e>=0){this.#C=e;this.#Lo=i;this.parent.drawLayer.finalizeDraw(e,{bbox:t.box,path:{d:t.toSVGPath()}});this.#Wo=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#No.box,path:{d:this.#No.toSVGPath()}},!0)}else if(this.parent){const e=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#C,{bbox:HighlightEditor.#Yo(this.#jo.box,(e-this.rotation+360)%360),path:{d:t.toSVGPath()}});this.parent.drawLayer.updateProperties(this.#Wo,{bbox:HighlightEditor.#Yo(this.#No.box,e),path:{d:this.#No.toSVGPath()}})}const[n,r,s,a]=t.box;switch(this.rotation){case 0:this.x=n;this.y=r;this.width=s;this.height=a;break;case 90:{const[t,e]=this.parentDimensions;this.x=r;this.y=1-n;this.width=s*e/t;this.height=a*t/e;break}case 180:this.x=1-n;this.y=1-r;this.width=s;this.height=a;break;case 270:{const[t,e]=this.parentDimensions;this.x=1-r;this.y=n;this.width=s*e/t;this.height=a*t/e;break}}const{firstPoint:o}=t;this.#_o=[(o[0]-n)/s,(o[1]-r)/a];const{lastPoint:l}=this.#No;this.#To=[(l[0]-n)/s,(l[1]-r)/a]}static initialize(t,e){AnnotationEditor.initialize(t,e);HighlightEditor._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case y.HIGHLIGHT_COLOR:HighlightEditor._defaultColor=e;break;case y.HIGHLIGHT_THICKNESS:HighlightEditor._defaultThickness=e}}translateInPage(t,e){}get toolbarPosition(){return this.#To}get commentButtonPosition(){return this.#_o}updateParams(t,e){switch(t){case y.HIGHLIGHT_COLOR:this.#ba(e);break;case y.HIGHLIGHT_THICKNESS:this.#Ko(e)}}static get defaultPropertiesToUpdate(){return[[y.HIGHLIGHT_COLOR,HighlightEditor._defaultColor],[y.HIGHLIGHT_THICKNESS,HighlightEditor._defaultThickness]]}get propertiesToUpdate(){return[[y.HIGHLIGHT_COLOR,this.color||HighlightEditor._defaultColor],[y.HIGHLIGHT_THICKNESS,this.#ho||HighlightEditor._defaultThickness],[y.HIGHLIGHT_FREE,this.#Go]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#C,{root:{fill:this.color,"fill-opacity":this.opacity}});this.#s?.updateColor(this.color);super.onUpdatedColor()}#ba(t){const setColorAndOpacity=(t,e)=>{this.color=t;this.opacity=e;this.onUpdatedColor()},e=this.color,i=this.opacity;this.addCommands({cmd:setColorAndOpacity.bind(this,t,HighlightEditor._defaultOpacity),undo:setColorAndOpacity.bind(this,e,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:y.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(t)},!0)}#Ko(t){const e=this.#ho,setThickness=t=>{this.#ho=t;this.#Jo(t)};this.addCommands({cmd:setThickness.bind(this,t),undo:setThickness.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:y.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0});this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}get toolbarButtons(){if(this._uiManager.highlightColors){return[["colorPicker",this.#s=new ColorPicker({editor:this})]]}return super.toolbarButtons}disableEditing(){super.disableEditing();this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing();this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(this.#Qo())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#Qo())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this);t&&this.div.focus()}remove(){this.#Zo();this._reportTelemetry({action:"deleted"});super.remove()}rebuild(){if(this.parent){super.rebuild();if(null!==this.div){this.#qo();this.isAttachedToDOM||this.parent.add(this)}}}setParent(t){let e=!1;if(this.parent&&!t)this.#Zo();else if(t){this.#qo(t);e=!this.parent&&this.div?.classList.contains("selectedEditor")}super.setParent(t);this.show(this._isVisible);e&&this.select()}#Jo(t){if(this.#Go){this.#$o({highlightOutlines:this.#jo.getNewOutline(t/2)});this.fixAndSetPosition();this.setDims()}}#Zo(){if(null!==this.#C&&this.parent){this.parent.drawLayer.remove(this.#C);this.#C=null;this.parent.drawLayer.remove(this.#Wo);this.#Wo=null}}#qo(t=this.parent){if(null===this.#C){({id:this.#C,clipPathId:this.#Lo}=t.drawLayer.draw({bbox:this.#jo.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#Go},path:{d:this.#jo.toSVGPath()}},!1,!0));this.#Wo=t.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#Go},bbox:this.#No.box,path:{d:this.#No.toSVGPath()}},this.#Go);this.#zo&&(this.#zo.style.clipPath=this.#Lo)}}static#Yo([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]}rotate(t){const{drawLayer:e}=this.parent;let i;if(this.#Go){t=(t-this.rotation+360)%360;i=HighlightEditor.#Yo(this.#jo.box,t)}else i=HighlightEditor.#Yo([this.x,this.y,this.width,this.height],t);e.updateProperties(this.#C,{bbox:i,root:{"data-main-rotation":t}});e.updateProperties(this.#Wo,{bbox:HighlightEditor.#Yo(this.#No.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;const t=super.render();if(this.#be){t.setAttribute("aria-label",this.#be);t.setAttribute("role","mark")}this.#Go?t.classList.add("free"):this.div.addEventListener("keydown",this.#tl.bind(this),{signal:this._uiManager._signal});const e=this.#zo=document.createElement("div");t.append(e);e.setAttribute("aria-hidden","true");e.className="internal";e.style.clipPath=this.#Lo;this.setDims();bindEvents(this,this.#zo,["pointerover","pointerleave"]);this.enableEditing();return t}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#Wo,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#Wo,{rootClass:{hovered:!1}})}#tl(t){HighlightEditor._keyboardManager.exec(this,t)}_moveCaret(t){this.parent.unselect(this);switch(t){case 0:case 2:this.#el(!0);break;case 1:case 3:this.#el(!1)}}#el(t){if(!this.#Ro)return;const e=window.getSelection();t?e.setPosition(this.#Ro,this.#Oo):e.setPosition(this.#Uo,this.#Ho)}select(){super.select();this.#Wo&&this.parent?.drawLayer.updateProperties(this.#Wo,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect();if(this.#Wo){this.parent?.drawLayer.updateProperties(this.#Wo,{rootClass:{selected:!1}});this.#Go||this.#el(!1)}}get _mustFixPosition(){return!this.#Go}show(t=this._isVisible){super.show(t);if(this.parent){this.parent.drawLayer.updateProperties(this.#C,{rootClass:{hidden:!t}});this.parent.drawLayer.updateProperties(this.#Wo,{rootClass:{hidden:!t}})}}#Qo(){return this.#Go?this.rotation:0}#il(){if(this.#Go)return null;const[t,e]=this.pageDimensions,[i,n]=this.pageTranslation,r=this.#Bo,s=new Float32Array(8*r.length);let a=0;for(const{x:o,y:l,width:h,height:c}of r){const r=o*t+i,d=(1-l)*e+n;s[a]=s[a+4]=r;s[a+1]=s[a+3]=d;s[a+2]=s[a+6]=r+h*t;s[a+5]=s[a+7]=d-c*e;a+=8}return s}#nl(t){return this.#jo.serialize(t,this.#Qo())}static startHighlighting(t,e,{target:i,x:n,y:r}){const{x:s,y:a,width:o,height:l}=i.getBoundingClientRect(),h=new AbortController,c=t.combinedSignal(h),pointerUpCallback=e=>{h.abort();this.#rl(t,e)};window.addEventListener("blur",pointerUpCallback,{signal:c});window.addEventListener("pointerup",pointerUpCallback,{signal:c});window.addEventListener("pointerdown",stopEvent,{capture:!0,passive:!1,signal:c});window.addEventListener("contextmenu",noContextMenu,{signal:c});i.addEventListener("pointermove",this.#sl.bind(this,t),{signal:c});this._freeHighlight=new FreeHighlightOutliner({x:n,y:r},[s,a,o,l],t.scale,this._defaultThickness/2,e,.001);({id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=t.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:this._defaultColor,"fill-opacity":this._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:this._freeHighlight.toSVGPath()}},!0,!0))}static#sl(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#rl(t,e){this._freeHighlight.isEmpty()?t.drawLayer.remove(this._freeHighlightId):t.createAndAddNewEditor(e,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"});this._freeHighlightId=-1;this._freeHighlight=null;this._freeHighlightClipId=""}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:h,contentsObj:c,creationDate:d,modificationDate:u},parent:{page:{pageNumber:p}}}=t;n=t={annotationType:b.HIGHLIGHT,color:Array.from(a),opacity:o,quadPoints:e,boxes:null,pageIndex:p-1,rect:i.slice(0),rotation:r,annotationElementId:s,id:s,deleted:!1,popupRef:l,richText:h,comment:c?.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:h,contentsObj:c,creationDate:d,modificationDate:u},parent:{page:{pageNumber:p}}}=t;n=t={annotationType:b.HIGHLIGHT,color:Array.from(a),thickness:o,inkLists:e,boxes:null,pageIndex:p-1,rect:i.slice(0),rotation:r,annotationElementId:s,id:s,deleted:!1,popupRef:l,richText:h,comment:c?.str||null,creationDate:d,modificationDate:u}}const{color:r,quadPoints:s,inkLists:a,outlines:o,opacity:l}=t,h=await super.deserialize(t,e,i);h.color=Util.makeHexColor(...r);h.opacity=l||1;a&&(h.#ho=t.thickness);h._initialData=n;t.comment&&h.setCommentData(t);const[c,d]=h.pageDimensions,[u,p]=h.pageTranslation;if(s){const t=h.#Bo=[];for(let e=0;e<s.length;e+=8)t.push({x:(s[e]-u)/c,y:1-(s[e+1]-p)/d,width:(s[e+2]-s[e])/c,height:(s[e+1]-s[e+5])/d});h.#Xo();h.#qo();h.rotate(h.rotation)}else if(a||o){h.#Go=!0;const t=(a||o.points)[0],i={x:t[0]-u,y:d-(t[1]-p)},n=new FreeHighlightOutliner(i,[0,0,c,d],1,h.#ho/2,!0,.001);for(let e=0,r=t.length;e<r;e+=2){i.x=t[e]-u;i.y=d-(t[e+1]-p);n.add(i)}const{id:r,clipPathId:s}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:h.color,"fill-opacity":h._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:n.toSVGPath()}},!0,!0);h.#$o({highlightOutlines:n.getOutlines(),highlightId:r,clipPathId:s});h.#qo();h.rotate(h.parentRotation)}return h}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=AnnotationEditor._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),i=super.serialize(t);Object.assign(i,{color:e,opacity:this.opacity,thickness:this.#ho,quadPoints:this.#il(),outlines:this.#nl(i.rect)});this.addComment(i);if(this.annotationElementId&&!this.#Ja(i))return null;i.id=this.annotationElementId;return i}#Ja(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}static canCreateNewEmptyEditor(){return!1}}class DrawingOptions{#al=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.#al[t]=e}toSVGProperties(){const t=this.#al;this.#al=Object.create(null);return{root:t}}reset(){this.#al=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){unreachable("Not implemented")}}class DrawingEditor extends AnnotationEditor{#ol=null;#ll;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#hl=null;static#cl=null;static#dl=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.#ul(t);this.#qo()}}#ul({drawOutlines:t,drawId:e,drawingOptions:i}){this.#ol=t;this._drawingOptions||=i;this.annotationElementId||this._uiManager.a11yAlert(`pdfjs-editor-${this.editorType}-added-alert`);if(e>=0){this._drawId=e;this.parent.drawLayer.finalizeDraw(e,t.defaultProperties)}else this._drawId=this.#pl(t,this.parent);this.#gl(t.box)}#pl(t,e){const{id:i}=e.drawLayer.draw(DrawingEditor._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return i}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 supportMultipleDrawings(){return!1}static updateDefaultParams(t,e){const i=this.typesMap.get(t);i&&this._defaultDrawingOptions.updateProperty(i,e);if(this._currentParent){DrawingEditor.#hl.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.#ol.updateProperty(e,i);r&&this.#gl(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){const i=this.constructor.typesMap.get(this.colorType),n=this.constructor.typesMap.get(this.opacityType),r=this._drawingOptions,s=r[i],a=r[n],setter=(t,e)=>{r.updateProperty(i,t);r.updateProperty(n,e);this.#ol.updateProperty(i,t);this.#ol.updateProperty(n,e);this.parent?.drawLayer.updateProperties(this._drawId,r.toSVGProperties());this.onUpdatedColor();this.onUpdatedOpacity()};this.addCommands({cmd:setter.bind(this,t,e),undo:setter.bind(this,s,a),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:y.INK_COLOR_AND_OPACITY,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,DrawingEditor._mergeSVGProperties(this.#ol.getPathResizingSVGProperties(this.#ml()),{bbox:this.#fl()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,DrawingEditor._mergeSVGProperties(this.#ol.getPathResizedSVGProperties(this.#ml()),{bbox:this.#fl()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#fl()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,DrawingEditor._mergeSVGProperties(this.#ol.getPathTranslatedSVGProperties(this.#ml(),this.parentDimensions),{bbox:this.#fl()}))}_onStartDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!0}})}_onStopDragging(){this.parent?.drawLayer.updateProperties(this._drawId,{rootClass:{moving:!1}})}commit(){super.commit();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||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.#Zo();super.remove()}rebuild(){if(this.parent){super.rebuild();if(null!==this.div){this.#qo();this.#gl(this.#ol.box);this.isAttachedToDOM||this.parent.add(this)}}}setParent(t){let e=!1;if(this.parent&&!t){this._uiManager.removeShouldRescale(this);this.#Zo()}else if(t){this._uiManager.addShouldRescale(this);this.#qo(t);e=!this.parent&&this.div?.classList.contains("selectedEditor")}super.setParent(t);e&&this.select()}#Zo(){if(null!==this._drawId&&this.parent){this.parent.drawLayer.remove(this._drawId);this._drawId=null;this._drawingOptions.reset()}}#qo(t=this.parent){if(null===this._drawId||this.parent!==t)if(null===this._drawId){this._drawingOptions.updateAll();this._drawId=this.#pl(this.#ol,t)}else this.parent.drawLayer.updateParent(this._drawId,t.drawLayer)}#bl([t,e,i,n]){const{parentDimensions:[r,s],rotation: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]}}#ml(){const{x:t,y:e,width:i,height:n,parentDimensions:[r,s],rotation: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]}}#gl(t){[this.x,this.y,this.width,this.height]=this.#bl(t);if(this.div){this.fixAndSetPosition();this.setDims()}this._onResized()}#fl(){const{x:t,y:e,width:i,height:n,rotation:r,parentRotation:s,parentDimensions:[a,o]}=this;switch((4*r+s)/90){case 1:return[1-e-n,t,n,i];case 2:return[1-t-i,1-e-n,i,n];case 3:return[e,1-t-i,n,i];case 4:return[t,e-i*(a/o),n*(o/a),i*(a/o)];case 5:return[1-e,t,i*(a/o),n*(o/a)];case 6:return[1-t-n*(o/a),1-e,n*(o/a),i*(a/o)];case 7:return[e-i*(a/o),1-t-n*(o/a),i*(a/o),n*(o/a)];case 8:return[t-i,e-n,i,n];case 9:return[1-e,t-i,n,i];case 10:return[1-t,1-e,i,n];case 11:return[e-n,1-t,n,i];case 12:return[t-n*(o/a),e,n*(o/a),i*(a/o)];case 13:return[1-e-i*(a/o),t-n*(o/a),i*(a/o),n*(o/a)];case 14:return[1-t,1-e-i*(a/o),n*(o/a),i*(a/o)];case 15:return[e,1-t,i*(a/o),n*(o/a)];default:return[t,e,i,n]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,DrawingEditor._mergeSVGProperties({bbox:this.#fl()},this.#ol.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#gl(this.#ol.updateParentDimensions(this.parentDimensions,this.parent.scale))}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();i.classList.add("draw");const n=document.createElement("div");i.append(n);n.setAttribute("aria-hidden","true");n.className="internal";this.setDims();this._uiManager.addShouldRescale(this);this.disableEditing();this._isCopy&&this._moveAfterPaste(t,e);return i}static createDrawerInstance(t,e,i,n,r){unreachable("Not implemented")}static startDrawing(t,e,i,n){const{target:r,offsetX:s,offsetY:a,pointerId:o,pointerType:l}=n;if(CurrentPointers.isInitializedAndDifferentPointerType(l))return;const{viewport:{rotation:h}}=t,{width:c,height:d}=r.getBoundingClientRect(),u=DrawingEditor.#cl=new AbortController,p=t.combinedSignal(u);CurrentPointers.setPointer(l,o);window.addEventListener("pointerup",t=>{CurrentPointers.isSamePointerIdOrRemove(t.pointerId)&&this._endDraw(t)},{signal:p});window.addEventListener("pointercancel",t=>{CurrentPointers.isSamePointerIdOrRemove(t.pointerId)&&this._currentParent.endDrawingSession()},{signal:p});window.addEventListener("pointerdown",t=>{if(CurrentPointers.isSamePointerType(t.pointerType)){CurrentPointers.initializeAndAddPointerId(t.pointerId);if(DrawingEditor.#hl.isCancellable()){DrawingEditor.#hl.removeLastElement();DrawingEditor.#hl.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)}}},{capture:!0,passive:!1,signal:p});window.addEventListener("contextmenu",noContextMenu,{signal:p});r.addEventListener("pointermove",this._drawMove.bind(this),{signal:p});r.addEventListener("touchmove",t=>{CurrentPointers.isSameTimeStamp(t.timeStamp)&&stopEvent(t)},{signal:p});t.toggleDrawing();e._editorUndoBar?.hide();if(DrawingEditor.#hl)t.drawLayer.updateProperties(this._currentDrawId,DrawingEditor.#hl.startNew(s,a,c,d,h));else{e.updateUIForDefaultProperties(this);DrawingEditor.#hl=this.createDrawerInstance(s,a,c,d,h);DrawingEditor.#dl=this.getDefaultDrawingOptions();this._currentParent=t;({id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(DrawingEditor.#dl.toSVGProperties(),DrawingEditor.#hl.defaultSVGProperties),!0,!1))}}static _drawMove(t){CurrentPointers.isSameTimeStamp(t.timeStamp);if(!DrawingEditor.#hl)return;const{offsetX:e,offsetY:i,pointerId:n}=t;if(CurrentPointers.isSamePointerId(n))if(CurrentPointers.isUsingMultiplePointers())this._endDraw(t);else{this._currentParent.drawLayer.updateProperties(this._currentDrawId,DrawingEditor.#hl.add(e,i));CurrentPointers.setTimeStamp(t.timeStamp);stopEvent(t)}}static _cleanup(t){if(t){this._currentDrawId=-1;this._currentParent=null;DrawingEditor.#hl=null;DrawingEditor.#dl=null;CurrentPointers.clearTimeStamp()}if(DrawingEditor.#cl){DrawingEditor.#cl.abort();DrawingEditor.#cl=null;CurrentPointers.clearPointerIds()}}static _endDraw(t){const e=this._currentParent;if(e){e.toggleDrawing(!0);this._cleanup(!1);t?.target===e.div&&e.drawLayer.updateProperties(this._currentDrawId,DrawingEditor.#hl.end(t.offsetX,t.offsetY));if(this.supportMultipleDrawings){const t=DrawingEditor.#hl,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:y.DRAW_STEP});return}this.endDrawing(!1)}}static endDrawing(t){const e=this._currentParent;if(!e)return null;e.toggleDrawing(!0);e.cleanUndoStack(y.DRAW_STEP);if(!DrawingEditor.#hl.isEmpty()){const{pageDimensions:[i,n],scale:r}=e,s=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:DrawingEditor.#hl.getOutlines(i*r,n*r,r,this._INNER_MARGIN),drawingOptions:DrawingEditor.#dl,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){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),l=await super.deserialize(t,e,i);l.createDrawingOptions(t);l.#ul({drawOutlines:o});l.#qo();l.onScaleChanging();l.rotate();return l}serializeDraw(t){const[e,i]=this.pageTranslation,[n,r]=this.pageDimensions;return this.#ol.serialize([e,i,n,r],t)}renderAnnotationElement(t){t.updateEdited({rect:this.getPDFRect()});return null}static canCreateNewEmptyEditor(){return!1}}class InkDrawOutliner{#no=new Float64Array(6);#_a;#yl;#Ir;#ho;#co;#vl="";#wl=0;#Fo=new InkDrawOutline;#Al;#xl;constructor(t,e,i,n,r,s){this.#Al=i;this.#xl=n;this.#Ir=r;this.#ho=s;[t,e]=this.#El(t,e);const a=this.#_a=[NaN,NaN,NaN,NaN,t,e];this.#co=[t,e];this.#yl=[{line:a,points:this.#co}];this.#no.set(a,0)}updateProperty(t,e){"stroke-width"===t&&(this.#ho=e)}#El(t,e){return Outline._normalizePoint(t,e,this.#Al,this.#xl,this.#Ir)}isEmpty(){return!this.#yl||0===this.#yl.length}isCancellable(){return this.#co.length<=10}add(t,e){[t,e]=this.#El(t,e);const[i,n,r,s]=this.#no.subarray(2,6),a=t-r,o=e-s;if(Math.hypot(this.#Al*a,this.#xl*o)<=2)return null;this.#co.push(t,e);if(isNaN(i)){this.#no.set([r,s,t,e],2);this.#_a.push(NaN,NaN,NaN,NaN,t,e);return{path:{d:this.toSVGPath()}}}isNaN(this.#no[0])&&this.#_a.splice(6,6);this.#no.set([i,n,r,s,t,e],0);this.#_a.push(...Outline.createBezierPoints(i,n,r,s,t,e));return{path:{d:this.toSVGPath()}}}end(t,e){const i=this.add(t,e);return i||(2===this.#co.length?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,i,n,r){this.#Al=i;this.#xl=n;this.#Ir=r;[t,e]=this.#El(t,e);const s=this.#_a=[NaN,NaN,NaN,NaN,t,e];this.#co=[t,e];const a=this.#yl.at(-1);if(a){a.line=new Float32Array(a.line);a.points=new Float32Array(a.points)}this.#yl.push({line:s,points:this.#co});this.#no.set(s,0);this.#wl=0;this.toSVGPath();return null}getLastElement(){return this.#yl.at(-1)}setLastElement(t){if(!this.#yl)return this.#Fo.setLastElement(t);this.#yl.push(t);this.#_a=t.line;this.#co=t.points;this.#wl=0;return{path:{d:this.toSVGPath()}}}removeLastElement(){if(!this.#yl)return this.#Fo.removeLastElement();this.#yl.pop();this.#vl="";for(let t=0,e=this.#yl.length;t<e;t++){const{line:e,points:i}=this.#yl[t];this.#_a=e;this.#co=i;this.#wl=0;this.toSVGPath()}return{path:{d:this.#vl}}}toSVGPath(){const t=Outline.svgRound(this.#_a[4]),e=Outline.svgRound(this.#_a[5]);if(2===this.#co.length){this.#vl=`${this.#vl} M ${t} ${e} Z`;return this.#vl}if(this.#co.length<=6){const i=this.#vl.lastIndexOf("M");this.#vl=`${this.#vl.slice(0,i)} M ${t} ${e}`;this.#wl=6}if(4===this.#co.length){const t=Outline.svgRound(this.#_a[10]),e=Outline.svgRound(this.#_a[11]);this.#vl=`${this.#vl} L ${t} ${e}`;this.#wl=12;return this.#vl}const i=[];if(0===this.#wl){i.push(`M ${t} ${e}`);this.#wl=6}for(let t=this.#wl,e=this.#_a.length;t<e;t+=6){const[e,n,r,s,a,o]=this.#_a.slice(t,t+6).map(Outline.svgRound);i.push(`C${e} ${n} ${r} ${s} ${a} ${o}`)}this.#vl+=i.join(" ");this.#wl=this.#_a.length;return this.#vl}getOutlines(t,e,i,n){const r=this.#yl.at(-1);r.line=new Float32Array(r.line);r.points=new Float32Array(r.points);this.#Fo.build(this.#yl,t,e,i,this.#Ir,this.#ho,n);this.#no=null;this.#_a=null;this.#yl=null;this.#vl=null;return this.#Fo}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class InkDrawOutline extends Outline{#Ao;#_l=0;#to;#yl;#Al;#xl;#Tl;#Ir;#ho;build(t,e,i,n,r,s,a){this.#Al=e;this.#xl=i;this.#Tl=n;this.#Ir=r;this.#ho=s;this.#to=a??0;this.#yl=t;this.#Cl()}get thickness(){return this.#ho}setLastElement(t){this.#yl.push(t);return{path:{d:this.toSVGPath()}}}removeLastElement(){this.#yl.pop();return{path:{d:this.toSVGPath()}}}toSVGPath(){const t=[];for(const{line:e}of this.#yl){t.push(`M${Outline.svgRound(e[4])} ${Outline.svgRound(e[5])}`);if(6!==e.length)if(12===e.length&&isNaN(e[6]))t.push(`L${Outline.svgRound(e[10])} ${Outline.svgRound(e[11])}`);else for(let i=6,n=e.length;i<n;i+=6){const[n,r,s,a,o,l]=e.subarray(i,i+6).map(Outline.svgRound);t.push(`C${n} ${r} ${s} ${a} ${o} ${l}`)}else t.push("Z")}return t.join("")}serialize([t,e,i,n],r){const s=[],a=[],[o,l,h,c]=this.#Sl();let d,u,p,g,m,f,b,y,v;switch(this.#Ir){case 0:v=Outline._rescale;d=t;u=e+n;p=i;g=-n;m=t+o*i;f=e+(1-l-c)*n;b=t+(o+h)*i;y=e+(1-l)*n;break;case 90:v=Outline._rescaleAndSwap;d=t;u=e;p=i;g=n;m=t+l*i;f=e+o*n;b=t+(l+c)*i;y=e+(o+h)*n;break;case 180:v=Outline._rescale;d=t+i;u=e;p=-i;g=n;m=t+(1-o-h)*i;f=e+l*n;b=t+(1-o)*i;y=e+(l+c)*n;break;case 270:v=Outline._rescaleAndSwap;d=t+i;u=e+n;p=-i;g=-n;m=t+(1-l-c)*i;f=e+(1-o-h)*n;b=t+(1-l)*i;y=e+(1-o)*n}for(const{line:t,points:e}of this.#yl){s.push(v(t,d,u,p,g,r?new Array(t.length):null));a.push(v(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 h=[];let c,d,u,p,g;switch(o){case 0:g=Outline._rescale;c=-t/i;d=e/n+1;u=1/i;p=-1/n;break;case 90:g=Outline._rescaleAndSwap;c=-e/n;d=-t/i;u=1/n;p=1/i;break;case 180:g=Outline._rescale;c=t/i+1;d=-e/n;u=-1/i;p=1/n;break;case 270:g=Outline._rescaleAndSwap;c=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-2));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 e=t[s],l=t[s+1];i.set(Outline.createBezierPoints(n,r,a,o,e,l),3*(s-2));[n,r,a,o]=[a,o,e,l]}}}for(let t=0,e=s.length;t<e;t++)h.push({line:g(s[t].map(t=>t??NaN),c,d,u,p),points:g(a[t].map(t=>t??NaN),c,d,u,p)});const m=new this.prototype.constructor;m.build(h,i,n,1,o,l,r);return m}#Dl(t=this.#ho){const e=this.#to+t/2*this.#Tl;return this.#Ir%180==0?[e/this.#Al,e/this.#xl]:[e/this.#xl,e/this.#Al]}#Sl(){const[t,e,i,n]=this.#Ao,[r,s]=this.#Dl(0);return[t+r,e+s,i-2*r,n-2*s]}#Cl(){const t=this.#Ao=r.slice();for(const{line:e}of this.#yl){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,h,c]=e.subarray(r,r+6);Util.bezierBoundingBox(i,n,s,a,o,l,h,c,t);i=h;n=c}}const[e,i]=this.#Dl();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.#Ao}updateProperty(t,e){return"stroke-width"===t?this.#Ko(e):null}#Ko(t){const[e,i]=this.#Dl();this.#ho=t;const[n,r]=this.#Dl(),[s,a]=[n-e,r-i],o=this.#Ao;o[0]-=s;o[1]-=a;o[2]+=2*s;o[3]+=2*a;return o}updateParentDimensions([t,e],i){const[n,r]=this.#Dl();this.#Al=t;this.#xl=e;this.#Tl=i;const[s,a]=this.#Dl(),o=s-n,l=a-r,h=this.#Ao;h[0]-=o;h[1]-=l;h[2]+=2*o;h[3]+=2*l;return h}updateRotation(t){this.#_l=t;return{path:{transform:this.rotationTransform}}}get viewBox(){return this.#Ao.map(Outline.svgRound).join(" ")}get defaultProperties(){const[t,e]=this.#Ao;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${Outline.svgRound(t)} ${Outline.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=this.#Ao;let i=0,n=0,r=0,s=0,a=0,o=0;switch(this.#_l){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.#Dl(),[a,o,l,h]=this.#Ao;if(Math.abs(l-r)<=Outline.PRECISION||Math.abs(h-s)<=Outline.PRECISION){const r=t+i/2-(a+l/2),s=e+n/2-(o+h/2);return{path:{"transform-origin":`${Outline.svgRound(t)} ${Outline.svgRound(e)}`,transform:`${this.rotationTransform} translate(${r} ${s})`}}}const c=(i-2*r)/(l-2*r),d=(n-2*s)/(h-2*s),u=l/i,p=h/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(${c} ${d}) translate(${Outline.svgRound(-r)} ${Outline.svgRound(-s)})`}}}getPathResizedSVGProperties([t,e,i,n]){const[r,s]=this.#Dl(),a=this.#Ao,[o,l,h,c]=a;a[0]=t;a[1]=e;a[2]=i;a[3]=n;if(Math.abs(h-r)<=Outline.PRECISION||Math.abs(c-s)<=Outline.PRECISION){const r=t+i/2-(o+h/2),s=e+n/2-(l+c/2);for(const{line:t,points:e}of this.#yl){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)/(h-2*r),u=(n-2*s)/(c-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.#yl){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.#Ao,a=t-s[0],o=e-s[1];if(this.#Al===n&&this.#xl===r)for(const{line:t,points:e}of this.#yl){Outline._translate(t,a,o,t);Outline._translate(e,a,o,e)}else{const t=this.#Al/n,e=this.#xl/r;this.#Al=n;this.#xl=r;for(const{line:i,points:n}of this.#yl){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.#Ao;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=b.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 shadow(this,"typesMap",new Map([[y.INK_THICKNESS,"stroke-width"],[y.INK_COLOR,"stroke"],[y.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,i,n,r){return new InkDrawOutliner(t,e,i,n,r,this._defaultDrawingOptions["stroke-width"])}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:h,richText:c,contentsObj:d,creationDate:u,modificationDate:p},parent:{page:{pageNumber:g}}}=t;n=t={annotationType:b.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:h,richText:c,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 y.INK_COLOR}get colorAndOpacityType(){return y.INK_COLOR_AND_OPACITY}get opacityType(){return y.INK_OPACITY}updateParams(t,e){t!==y.INK_COLOR_AND_OPACITY?super.updateParams(t,e):this._updateColorAndOpacity(e.color,e.opacity)}static updateDefaultParams(t,e){if(t!==y.INK_COLOR_AND_OPACITY)super.updateDefaultParams(t,e);else{super.updateDefaultParams(y.INK_COLOR,e.color);super.updateDefaultParams(y.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.#Ja(a))return null;a.id=this.annotationElementId;return a}#Ja(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}}__webpack_require__(5213);class SignatureExtractor{static#Pl={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#Ml(t,e,i,n){n-=e;return 0===(i-=t)?n>0?0:4:1===i?n+6:2-n}static#kl=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#Il(t,e,i,n,r,s,a){const o=this.#Ml(i,n,r,s);for(let r=0;r<8;r++){const s=(-r+o-a+16)%8;if(0!==t[(i+this.#kl[2*s])*e+(n+this.#kl[2*s+1])])return s}return-1}static#Fl(t,e,i,n,r,s,a){const o=this.#Ml(i,n,r,s);for(let r=0;r<8;r++){const s=(r+o+a+16)%8;if(0!==t[(i+this.#kl[2*s])*e+(n+this.#kl[2*s+1])])return s}return-1}static#Rl(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 h=t,c=i;if(1===r&&0===s[n-1]){o+=1;c-=1}else{if(!(r>=1&&0===s[n+1])){1!==r&&(a=Math.abs(r));continue}o+=1;c+=1;r>1&&(a=r)}const d=[i,t],u=c===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.#Il(s,e,t,i,h,c,0);if(-1===m){s[n]=-o;1!==s[n]&&(a=Math.abs(s[n]));continue}let f=this.#kl[2*m],b=this.#kl[2*m+1];const y=t+f,v=i+b;h=y;c=v;let w=t,A=i;for(;;){const r=this.#Fl(s,e,w,A,h,c,1);f=this.#kl[2*r];b=this.#kl[2*r+1];const l=w+f,u=A+b;d.push(u,l);const p=w*e+A;0===s[p+1]?s[p]=-o:1===s[p]&&(s[p]=o);if(l===t&&u===i&&w===y&&A===v){1!==s[n]&&(a=Math.abs(s[n]));break}h=w;c=A;w=l;A=u}}}return l}static#Ol(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),h=a/l,c=o/l,d=h*s-c*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),v=Math.max(Math.atan(Math.abs(f+m)*y),Math.atan(Math.abs(f-m)*y));let w=0,A=e;for(let n=e+2;n<i-2;n+=2){const e=Math.abs(d-h*t[n+1]+c*t[n]);if(e>w){A=n;w=e}}if(w>(l*v)**2){this.#Ol(t,e,A+2,n);this.#Ol(t,A,i,n)}else n.push(r,s)}static#Bl(t){const e=[],i=t.length;this.#Ol(t,0,i,e);e.push(t[i-2],t[i-1]);return e.length<=4?null:e}static#Ll(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 h=new Float32Array(256),c=-2*r**2;for(let t=0;t<256;t++)h[t]=Math.exp(t**2/c);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,c=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]*h[Math.abs(p-c)];d+=p*m;g+=m}}p[u[o]=Math.round(d/g)]++}return[u,p]}static#Nl(t){const e=new Uint32Array(256);for(const i of t)e[i]++;return e}static#Ul(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#Hl(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#zl(t){const e=t,{width:i,height:n}=t,{maxDim:r}=this.#Pl;let s=i,a=n;if(i>r||n>r){let o=i,l=n,h=Math.log2(Math.max(i,n)/r);const c=Math.floor(h);h=h===c?c-1:c;for(let i=0;i<h;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.#Ul(l),s,a]}static extractContoursFromText(t,{fontFamily:e,fontStyle:i,fontWeight:n},r,s,a,o){let l=new OffscreenCanvas(1,1),h=l.getContext("2d",{alpha:!1});const c=h.font=`${i} ${n} 200px ${e}`,{actualBoundingBoxLeft:d,actualBoundingBoxRight:u,actualBoundingBoxAscent:p,actualBoundingBoxDescent:g,fontBoundingBoxAscent:m,fontBoundingBoxDescent:f,width:b}=h.measureText(t),y=1.5,v=Math.ceil(Math.max(Math.abs(d)+Math.abs(u)||0,b)*y),w=Math.ceil(Math.max(Math.abs(p)+Math.abs(g)||200,Math.abs(m)+Math.abs(f)||200)*y);l=new OffscreenCanvas(v,w);h=l.getContext("2d",{alpha:!0,willReadFrequently:!0});h.font=c;h.filter="grayscale(1)";h.fillStyle="white";h.fillRect(0,0,v,w);h.fillStyle="black";h.fillText(t,.5*v/2,1.5*w/2);const A=this.#Ul(h.getImageData(0,0,v,w).data),x=this.#Nl(A),E=this.#Hl(x),_=this.#Rl(A,v,w,E);return this.processDrawnLines({lines:{curves:_,width:v,height:w},pageWidth:r,pageHeight:s,rotation:a,innerMargin:o,mustSmooth:!0,areContours:!0})}static process(t,e,i,n,r){const[s,a,o]=this.#zl(t),[l,h]=this.#Ll(s,a,o,Math.hypot(a,o)*this.#Pl.sigmaSFactor,this.#Pl.sigmaR,this.#Pl.kernelSize),c=this.#Hl(h),d=this.#Rl(l,a,o,c);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:h}=t,c=t.thickness??0,d=[],u=Math.min(e/l,i/h),p=u/e,g=u/i,m=[];for(const{points:t}of o){const e=s?this.#Bl(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,h]=e;a*=p;o*=g;l*=p;h*=g;n.set([a,o,l,h],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,h,i,s),3*(t-2));[a,o,l,h]=[l,h,i,s]}}if(0===d.length)return null;const f=a?new ContourDrawOutline:new InkDrawOutline;f.build(d,e,i,1,n,a?0:c,r);return{outline:f,newCurves:m,areContours:a,thickness:c,width:l,height:h}}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 h=t.length,c=8+3*h,d=new Uint32Array(c);let u=0;d[u++]=c*Uint32Array.BYTES_PER_ELEMENT+(l-2*h)*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++]=h;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 h=o[2],c=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:h,height:c}}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{#jl=!1;#Gl=null;#Wl=null;#Vl=null;static _type="signature";static _editorType=b.SIGNATURE;static _defaultDrawingOptions=null;constructor(t){super({...t,mustBeCommitted:!0,name:"signatureEditor"});this._willKeepAspectRatio=!0;this.#Wl=t.signatureData||null;this.#Gl=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 shadow(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!this.#Gl}}static computeTelemetryFinalData(t){const e=t.get("hasDescription");return{hasAltText:e.get(!0)??0,hasNoAltText:e.get(!1)??0}}get isResizable(){return!0}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.#Wl){const{lines:t,mustSmooth:e,areContours:i,description:n,uuid:r,heightInPage:s}=this.#Wl,{rawDims:{pageWidth:a,pageHeight:o},rotation:l}=this.parent.viewport,h=SignatureExtractor.processDrawnLines({lines:t,pageWidth:a,pageHeight:o,rotation:l,innerMargin:SignatureEditor._INNER_MARGIN,mustSmooth:e,areContours:i});this.addSignature(h,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.#Gl||""}));if(i){this._isCopy=!0;this._moveAfterPaste(t,e)}return this.div}setUuid(t){this.#Vl=t;this.addEditToolbar()}getUuid(){return this.#Vl}get description(){return this.#Gl}set description(t){this.#Gl=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.#Wl,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.#Wl=t;this.#jl=a instanceof ContourDrawOutline;this.description=i;let o;if(this.#jl)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 h=e/l;h=h>=1?.5:h;this.width*=h/this.height;if(this.width>=1){h*=.9/this.width;this.width=.9}this.height=h;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}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.#jl,color:[0,0,0],thickness:this.#jl?0:n});this.addComment(r);if(t){r.paths={lines:e,points:i};r.uuid=this.#Vl;r.isCopy=!0}else r.lines=e;this.#Gl&&(r.accessibilityData={type:"Figure",alt:this.#Gl});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.#jl=t.areContours;n.description=t.accessibilityData?.alt||"";n.#Vl=t.uuid;return n}}class StampEditor extends AnnotationEditor{#$l=null;#ql=null;#Xl=null;#Yl=null;#Kl=null;#Jl="";#Ql=null;#Zl=!1;#th=null;#eh=!1;#ih=!1;static _type="stamp";static _editorType=b.STAMP;constructor(t){super({...t,name:"stampEditor"});this.#Yl=t.bitmapUrl;this.#Kl=t.bitmapFile;this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(t,e){AnnotationEditor.initialize(t,e)}static isHandlingMimeForPasting(t){return X.includes(t)}static paste(t,e){e.pasteEditor({mode:b.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}}#nh(t,e=!1){if(t){this.#$l=t.bitmap;if(!e){this.#ql=t.id;this.#eh=t.isSvg}t.file&&(this.#Jl=t.file.name);this.#rh()}else this.remove()}#sh(){this.#Xl=null;this._uiManager.enableWaiting(!1);if(this.#Ql)if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#$l)this.addEditToolbar().then(()=>{this._editToolbar.hide();this._uiManager.editAltText(this,!0)});else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#$l){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}#ah(){if(this.#ql){this._uiManager.enableWaiting(!0);this._uiManager.imageManager.getFromId(this.#ql).then(t=>this.#nh(t,!0)).finally(()=>this.#sh());return}if(this.#Yl){const t=this.#Yl;this.#Yl=null;this._uiManager.enableWaiting(!0);this.#Xl=this._uiManager.imageManager.getFromUrl(t).then(t=>this.#nh(t)).finally(()=>this.#sh());return}if(this.#Kl){const t=this.#Kl;this.#Kl=null;this._uiManager.enableWaiting(!0);this.#Xl=this._uiManager.imageManager.getFromFile(t).then(t=>this.#nh(t)).finally(()=>this.#sh());return}const t=document.createElement("input");t.type="file";t.accept=X.join(",");const e=this._uiManager._signal;this.#Xl=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.#nh(e)}else this.remove();i()},{signal:e});t.addEventListener("cancel",()=>{this.remove();i()},{signal:e})}).finally(()=>this.#sh());t.click()}remove(){if(this.#ql){this.#$l=null;this._uiManager.imageManager.deleteId(this.#ql);this.#Ql?.remove();this.#Ql=null;if(this.#th){clearTimeout(this.#th);this.#th=null}}super.remove()}rebuild(){if(this.parent){super.rebuild();if(null!==this.div){this.#ql&&null===this.#Ql&&this.#ah();this.isAttachedToDOM||this.parent.add(this)}}else this.#ql&&this.#ah()}onceAdded(t){this._isDraggable=!0;t&&this.div.focus()}isEmpty(){return!(this.#Xl||this.#$l||this.#Yl||this.#Kl||this.#ql||this.#Zl)}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.#Zl||(this.#$l?this.#rh():this.#ah());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.#ql=i;n&&(this.#$l=n);this.#Zl=!1;this.#rh()}}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;null!==this.#th&&clearTimeout(this.#th);this.#th=setTimeout(()=>{this.#th=null;this.#oh()},200)}#rh(){const{div:t}=this;let{width:e,height:i}=this.#$l;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.#Ql=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.#oh();if(!this.#ih){this.parent.addUndoableEditor(this);this.#ih=!0}this._reportTelemetry({action:"inserted_image"});this.#Jl&&this.div.setAttribute("aria-description",this.#Jl);this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert")}copyCanvas(t,e,i=!1){t||(t=224);const{width:n,height:r}=this.#$l,s=new OutputScale;let a=this.#$l,o=n,l=r,h=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)}h=document.createElement("canvas");const t=h.width=Math.ceil(o*s.sx),i=h.height=Math.ceil(l*s.sy);this.#eh||(a=this.#lh(t,i));const c=h.getContext("2d");c.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);c.fillStyle=c.createPattern(f,"repeat");c.fillRect(0,0,t,i);c.drawImage(a,0,0,a.width,a.height,0,0,t,i)}let c=null;if(i){let e,i;if(s.symmetric&&a.width<t&&a.height<t){e=a.width;i=a.height}else{a=this.#$l;if(n>t||r>t){const s=Math.min(t/n,t/r);e=Math.floor(n*s);i=Math.floor(r*s);this.#eh||(a=this.#lh(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);c={width:e,height:i,data:o.getImageData(0,0,e,i).data}}return{canvas:h,width:o,height:l,imageData:c}}#lh(t,e){const{width:i,height:n}=this.#$l;let r=i,s=n,a=this.#$l;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}#oh(){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.#Ql;if(!o||o.width===s&&o.height===a)return;o.width=s;o.height=a;const l=this.#eh?this.#$l:this.#lh(s,a),h=o.getContext("2d");h.filter=this._uiManager.hcmFilter;h.drawImage(l,0,0,l.width,l.height,0,0,s,a)}#hh(t){if(t){if(this.#eh){const t=this._uiManager.imageManager.getSvgUrl(this.#ql);if(t)return t}const t=document.createElement("canvas");({width:t.width,height:t.height}=this.#$l);t.getContext("2d").drawImage(this.#$l,0,0);return t.toDataURL()}if(this.#eh){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.#$l,0,0,this.#$l.width,this.#$l.height,0,0,i,n);return r.transferToImageBitmap()}return structuredClone(this.#$l)}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:h,richText:c,contentsObj:d,creationDate:u,modificationDate:p},container:g,parent:{page:{pageNumber:m}},canvas:f}=t;let y,v;if(f){delete t.canvas;({id:y,bitmap:v}=i.imageManager.getFromCanvas(g.id,f));f.remove()}else{r=!0;t._hasNoCanvas=!0}const w=(await e._structTree.getAriaAttributes(`${$}${o}`))?.get("aria-label")||"";n=t={annotationType:b.STAMP,bitmapId:y,bitmap:v,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:h,richText:c,comment:d?.str||null,creationDate:u,modificationDate:p}}const s=await super.deserialize(t,e,i),{rect:a,bitmap:o,bitmapUrl:l,bitmapId:h,isSvg:c,accessibilityData:d}=t;if(r){i.addMissingCanvas(t.id,s);s.#Zl=!0}else if(h&&i.imageManager.isValidId(h)){s.#ql=h;o&&(s.#$l=o)}else s.#Yl=l;s.#eh=c;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.#ih=!!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.#ql,isSvg:this.#eh});this.addComment(i);if(t){i.bitmapUrl=this.#hh(!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.#Ja(i);if(t.isSame)return null;t.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1;i.id=this.annotationElementId;delete i.bitmapId;return i}if(null===e)return i;e.stamps||=new Map;const s=this.#eh?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(e.stamps.has(this.#ql)){if(this.#eh){const t=e.stamps.get(this.#ql);if(s>t.area){t.area=s;t.serialized.bitmap.close();t.serialized.bitmap=this.#hh(!1)}}}else{e.stamps.set(this.#ql,{area:s,serialized:i});i.bitmap=this.#hh(!1)}return i}#Ja(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{#Fa;#ch=!1;#dh=null;#uh=null;#ph=null;#gh=new Map;#mh=!1;#fh=!1;#bh=!1;#yh=null;#vh=null;#wh=null;#Ah=null;#xh=null;#Eh=-1;#y;static _initialized=!1;static#J=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:h}){const c=[...AnnotationEditorLayer.#J.values()];if(!AnnotationEditorLayer._initialized){AnnotationEditorLayer._initialized=!0;for(const e of c)e.initialize(h,t)}t.registerEditorTypes(c);this.#y=t;this.pageIndex=e;this.div=i;this.#Fa=r;this.#dh=s;this.viewport=l;this.#wh=o;this.drawLayer=a;this._structTree=n;this.#y.addLayer(this)}get isEmpty(){return 0===this.#gh.size}get isInvisible(){return this.isEmpty&&this.#y.getMode()===b.NONE}updateToolbar(t){this.#y.updateToolbar(t)}updateMode(t=this.#y.getMode()){this.#_h();switch(t){case b.NONE:this.div.classList.toggle("nonEditing",!0);this.disableTextSelection();this.togglePointerEvents(!1);this.toggleAnnotationLayerPointerEvents(!0);this.disableClick();return;case b.INK:this.disableTextSelection();this.togglePointerEvents(!0);this.enableClick();break;case b.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===b.POPUP)e.toggle("commentEditing",!0);else{e.toggle("commentEditing",!1);for(const i of AnnotationEditorLayer.#J.values())e.toggle(`${i._type}Editing`,t===i._editorType)}this.div.hidden=!1}hasTextLayer(t){return t===this.#wh?.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.#dh?.togglePointerEvents(t)}get#Th(){return 0!==this.#gh.size?this.#gh.values():this.#y.getEditors(this.pageIndex)}async enable(){this.#bh=!0;this.div.tabIndex=0;this.togglePointerEvents(!0);this.div.classList.toggle("nonEditing",!1);this.#xh?.abort();this.#xh=null;const t=new Set;for(const e of this.#Th){e.enableEditing();e.show(!0);if(e.annotationElementId){this.#y.removeChangedExistingAnnotation(e);t.add(e.annotationElementId)}}const e=this.#dh;if(e)for(const i of e.getEditableAnnotations()){i.hide();if(this.#y.isDeletedAnnotationElement(i.data.id))continue;if(t.has(i.data.id))continue;const e=await this.deserialize(i);if(e){this.addOrRebuild(e);e.enableEditing()}}this.#bh=!1;this.#y._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){this.#fh=!0;this.div.tabIndex=-1;this.togglePointerEvents(!1);this.div.classList.toggle("nonEditing",!0);if(this.#wh&&!this.#xh){this.#xh=new AbortController;const t=this.#y.combinedSignal(this.#xh);this.#wh.div.addEventListener("pointerdown",t=>{const{clientX:e,clientY:i,timeStamp:n}=t;if(n-this.#Eh>500){this.#Eh=n;return}this.#Eh=-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(`^${f}[0-9]+$`);for(const t of s)if(o.test(t.id)){a=t.id;break}if(!a)return;const l=this.#gh.get(a);if(null===l?.annotationElementId){stopEvent(t);l.dblclick(t)}},{signal:t,capture:!0})}const t=this.#dh,e=[];if(t){const i=new Map,n=new Map;for(const t of this.#Th){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.#_h();this.isEmpty&&(this.div.hidden=!0);const{classList:i}=this.div;for(const t of AnnotationEditorLayer.#J.values())i.remove(`${t._type}Editing`);this.disableTextSelection();this.toggleAnnotationLayerPointerEvents(!0);t?.updateFakeAnnotations(e);this.#fh=!1}getEditableAnnotation(t){return this.#dh?.getEditableAnnotation(t)||null}setActiveEditor(t){this.#y.getActive()!==t&&this.#y.setActiveEditor(t)}enableTextSelection(){this.div.tabIndex=-1;if(this.#wh?.div&&!this.#Ah){this.#Ah=new AbortController;const t=this.#y.combinedSignal(this.#Ah);this.#wh.div.addEventListener("pointerdown",this.#Ch.bind(this),{signal:t});this.#wh.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0;if(this.#wh?.div&&this.#Ah){this.#Ah.abort();this.#Ah=null;this.#wh.div.classList.remove("highlighting")}}#Ch(t){this.#y.unselectAll();const{target:e}=t;if(e===this.#wh.div||("img"===e.getAttribute("role")||e.classList.contains("endOfContent")||e.classList.contains("textLayerImagePlaceholder"))&&this.#wh.div.contains(e)){const{isMac:e}=FeatureTest.platform;if(0!==t.button||t.ctrlKey&&e)return;this.#y.showAllEditors("highlight",!0,!0);this.#wh.div.classList.add("free");this.toggleDrawing();HighlightEditor.startHighlighting(this,"ltr"===this.#y.direction,{target:this.#wh.div,x:t.x,y:t.y});this.#wh.div.addEventListener("pointerup",()=>{this.#wh.div.classList.remove("free");this.toggleDrawing(!0)},{once:!0,signal:this.#y._signal});t.preventDefault()}}enableClick(){if(this.#uh)return;this.#uh=new AbortController;const t=this.#y.combinedSignal(this.#uh);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.#uh?.abort();this.#uh=null}attach(t){this.#gh.set(t.id,t);const{annotationElementId:e}=t;e&&this.#y.isDeletedAnnotationElement(e)&&this.#y.removeDeletedAnnotationElement(t)}detach(t){this.#gh.delete(t.id);this.#Fa?.removePointerInTextLayer(t.contentDiv);!this.#fh&&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.#bh);this.#y.addToAnnotationStorage(t);t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;const{activeElement:e}=document;if(t.div.contains(e)&&!this.#ph){t._focusEventsAllowed=!1;this.#ph=setTimeout(()=>{this.#ph=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.#Fa?.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.#gh.values())if(e.uid===t)return e;return null}get#Sh(){return AnnotationEditorLayer.#J.get(this.#y.getMode())}combinedSignal(t){return this.#y.combinedSignal(t)}#Dh(t){const e=this.#Sh;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#Sh?.canCreateNewEmptyEditor()}async pasteEditor(t,e){this.updateToolbar(t);await this.#y.updateMode(t.mode);const{offsetX:i,offsetY:n}=this.#Ph(),r=this.#y.getId(),s=this.#Dh({parent:this,id:r,x:i,y:n,uiManager:this.#y,isCentered:!0,...e});s&&this.add(s)}async deserialize(t){return await(AnnotationEditorLayer.#J.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#y))||null}createAndAddNewEditor(t,e,i={}){const n=this.#y.getId(),r=this.#Dh({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()}#Ph(){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,h]=this.viewport.rotation%180==0?[a,o]:[o,a];return{offsetX:l,offsetY:h}}addNewEditor(t={}){this.createAndAddNewEditor(this.#Ph(),!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.#mh)return;this.#mh=!1;if(this.#Sh?.isDrawer&&this.#Sh.supportMultipleDrawings)return;if(!this.#ch){this.#ch=!0;return}const i=this.#y.getMode();i!==b.STAMP&&i!==b.POPUP&&i!==b.SIGNATURE?this.createAndAddNewEditor(t,!1):this.#y.unselectAll()}pointerdown(t){this.#y.getMode()===b.HIGHLIGHT&&this.enableTextSelection();if(this.#mh){this.#mh=!1;return}const{isMac:e}=FeatureTest.platform;if(0!==t.button||t.ctrlKey&&e)return;if(t.target!==this.div)return;this.#mh=!0;if(this.#Sh?.isDrawer){this.startDrawingSession(t);return}const i=this.#y.getActive();this.#ch=!i||i.isEmpty()}startDrawingSession(t){this.div.focus({preventScroll:!0});if(this.#yh){this.#Sh.startDrawing(this,this.#y,!1,t);return}this.#y.setCurrentDrawingSession(this);this.#yh=new AbortController;const e=this.#y.combinedSignal(this.#yh);this.div.addEventListener("blur",({relatedTarget:t})=>{if(t&&!this.div.contains(t)){this.#vh=null;this.commitOrRemove()}},{signal:e});this.#Sh.startDrawing(this,this.#y,!1,t)}pause(t){if(t){const{activeElement:t}=document;this.div.contains(t)&&(this.#vh=t);return}this.#vh&&setTimeout(()=>{this.#vh?.focus();this.#vh=null},0)}endDrawingSession(t=!1){if(!this.#yh)return null;this.#y.setCurrentDrawingSession(null);this.#yh.abort();this.#yh=null;this.#vh=null;return this.#Sh.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.#yh){this.endDrawingSession();return!0}return!1}onScaleChanging(){this.#yh&&this.#Sh.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove();if(this.#y.getActive()?.parent===this){this.#y.commitOrRemove();this.#y.setActiveEditor(null)}if(this.#ph){clearTimeout(this.#ph);this.#ph=null}for(const t of this.#gh.values()){this.#Fa?.removePointerInTextLayer(t.contentDiv);t.setParent(null);t.isAttachedToDOM=!1;t.div.remove()}this.div=null;this.#gh.clear();this.#y.removeLayer(this)}#_h(){for(const t of this.#gh.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.#_h();const e=this.viewport.rotation,i=t.rotation;this.viewport=t;setLayerDimensions(this.div,{rotation:i});if(e!==i)for(const t of this.#gh.values())t.rotate(i)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#y.viewParameters.realScale}}class DrawLayer{#na=null;#Mh=new Map;#kh=new Map;static#C=0;setParent(t){if(this.#na){if(this.#na!==t){if(this.#Mh.size>0)for(const e of this.#Mh.values()){e.remove();t.append(e)}this.#na=t}}else this.#na=t}static get _svgFactory(){return shadow(this,"_svgFactory",new DOMSVGFactory)}static#Ih(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+"%"}#Fh(){const t=DrawLayer._svgFactory.create(1,1,!0);this.#na.append(t);t.setAttribute("aria-hidden",!0);return t}#Rh(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}#Oh(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.#C++,r=this.#Fh(),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.#kh.set(n,a);const l=i?this.#Rh(s,o):null,h=DrawLayer._svgFactory.createElement("use");r.append(h);h.setAttribute("href",`#${o}`);this.updateProperties(r,t);this.#Mh.set(n,r);return{id:n,clipPathId:`url(#${l})`}}drawOutline(t,e){const i=DrawLayer.#C++,n=this.#Fh(),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 h=l.cloneNode();n.append(h);l.classList.add("mainOutline");h.classList.add("secondaryOutline");this.updateProperties(n,t);this.#Mh.set(i,n);return i}finalizeDraw(t,e){this.#kh.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.#Mh.get(t):t;if(a){i&&this.#Oh(a,i);n&&DrawLayer.#Ih(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.#Oh(t,s)}}}updateParent(t,e){if(e===this)return;const i=this.#Mh.get(t);if(i){e.#na.append(i);this.#Mh.delete(t);e.#Mh.set(t,i)}}remove(t){this.#kh.delete(t);if(null!==this.#na){this.#Mh.get(t).remove();this.#Mh.delete(t)}}destroy(){this.#na=null;for(const t of this.#Mh.values())t.remove();this.#Mh.clear();this.#kh.clear()}}function percentage(t){return`${(100*t).toFixed(2)}%`}class TextLayerImages{#Bh=[];#Lh=new Map;#Nh=null;#Uh=0;#Pr=0;#Dr=0;static#Hh=null;constructor(t,e,i,n){this.#Uh=t;this.#Bh=e;this.#Pr=i.rawDims.pageWidth;this.#Dr=i.rawDims.pageHeight;this.#Nh=n}render(){const t=document.createElement("div");t.className="textLayerImages";for(let e=0;e<this.#Bh.length;e+=6){const i=this.#zh(this.#Bh.subarray(e,e+6));i&&t.append(i)}t.addEventListener("contextmenu",t=>{if(!(t.target instanceof HTMLCanvasElement))return;const e=t.target,i=this.#Lh.get(e);if(!i)return;const n=TextLayerImages.#Hh?.deref();if(n===e)return;if(n){n.width=0;n.height=0}TextLayerImages.#Hh=new WeakRef(e);const{inverseTransform:r,x1:s,y1:a,width:o,height:l}=i,h=this.#Nh(),c=Math.ceil(s*h.width),d=Math.ceil(a*h.height),u=Math.floor((s+o/this.#Pr)*h.width),p=Math.floor((a+l/this.#Dr)*h.height);e.width=u-c;e.height=p-d;const g=e.getContext("2d");g.setTransform(...r);g.translate(-c,-d);g.drawImage(h,0,0)});return t}#zh([t,e,i,n,r,s]){const a=Math.hypot((r-t)*this.#Pr,(s-e)*this.#Dr),o=Math.hypot((i-t)*this.#Pr,(n-e)*this.#Dr);if(a<this.#Uh||o<this.#Uh)return null;const l=[(r-t)*this.#Pr/a,(s-e)*this.#Dr/a,(i-t)*this.#Pr/o,(n-e)*this.#Dr/o,0,0],h=Util.inverseTransform(l),c=document.createElement("canvas");c.className="textLayerImagePlaceholder";c.width=0;c.height=0;Object.assign(c.style,{opacity:0,position:"absolute",left:percentage(t),top:percentage(e),width:percentage(a/this.#Pr),height:percentage(o/this.#Dr),transformOrigin:"0% 0%",transform:`matrix(${l.join(",")})`});this.#Lh.set(c,{inverseTransform:h,width:a,height:o,x1:t,y1:e});return c}}globalThis._pdfjsTestingUtils={HighlightOutliner};globalThis.pdfjsLib={AbortException,AnnotationEditorLayer,AnnotationEditorParamsType:y,AnnotationEditorType:b,AnnotationEditorUIManager,AnnotationLayer,AnnotationMode:m,AnnotationType:S,applyOpacity,build:Ut,ColorPicker,createValidAbsoluteUrl,CSSConstants,DOMSVGFactory,DrawLayer,FeatureTest,fetchData,findContrastColor,getDocument,getFilenameFromUrl,getPdfFilenameFromUrl,getRGB,getRGBA,getUuid,getXfaPageViewport,GlobalWorkerOptions,ImageKind:C,InvalidPDFException,isDataScheme,isPdfFile,isValidExplicitDest:ut,makeArr,makeMap,makeObj,MathClamp,noContextMenu,normalizeUnicode,OPS:O,OutputScale,PasswordResponses:z,PDFDataRangeTransport,PDFDateString,PDFWorker,PermissionFlag:v,PixelsPerInch,RenderingCancelledException,renderRichText,ResponseException,setLayerDimensions,shadow,SignatureExtractor,stopEvent,SupportedImageMimeTypes:X,TextLayer,TextLayerImages,TouchManager,updateUrlHash,Util,VerbosityLevel:R,version:Nt,XfaLayer};export{AbortException,AnnotationEditorLayer,y as AnnotationEditorParamsType,b as AnnotationEditorType,AnnotationEditorUIManager,AnnotationLayer,m as AnnotationMode,S as AnnotationType,CSSConstants,ColorPicker,DOMSVGFactory,DrawLayer,FeatureTest,GlobalWorkerOptions,C as ImageKind,InvalidPDFException,MathClamp,O as OPS,OutputScale,PDFDataRangeTransport,PDFDateString,PDFWorker,z as PasswordResponses,v as PermissionFlag,PixelsPerInch,RenderingCancelledException,ResponseException,SignatureExtractor,X as SupportedImageMimeTypes,TextLayer,TextLayerImages,TouchManager,Util,R as VerbosityLevel,XfaLayer,applyOpacity,Ut as build,createValidAbsoluteUrl,fetchData,findContrastColor,getDocument,getFilenameFromUrl,getPdfFilenameFromUrl,getRGB,getRGBA,getUuid,getXfaPageViewport,isDataScheme,isPdfFile,ut as isValidExplicitDest,makeArr,makeMap,makeObj,noContextMenu,normalizeUnicode,renderRichText,setLayerDimensions,shadow,stopEvent,updateUrlHash,Nt as version}; |