@libresign/pdf-elements 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- (function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define([],e):"object"===typeof exports?exports["pdf-elements"]=e():t["pdf-elements"]=e()})("undefined"!==typeof self?self:this,()=>(()=>{"use strict";var t={34(t,e,i){var s=i(4901);t.exports=function(t){return"object"==typeof t?null!==t:s(t)}},81(t,e,i){var s=i(9565),n=i(9306),r=i(8551),a=i(6823),o=i(851),l=TypeError;t.exports=function(t,e){var i=arguments.length<2?o(t):e;if(n(i))return r(s(i,t));throw new l(a(t)+" is not iterable")}},116(t,e,i){var s=i(6518),n=i(9565),r=i(2652),a=i(9306),o=i(8551),l=i(1767),h=i(9539),c=i(4549),d=c("find",TypeError);s({target:"Iterator",proto:!0,real:!0,forced:d},{find:function(t){o(this);try{a(t)}catch(s){h(this,"throw",s)}if(d)return n(d,this,t);var e=l(this),i=0;return r(e,function(e,s){if(t(e,i++))return s(e)},{IS_RECORD:!0,INTERRUPTED:!0}).result}})},283(t,e,i){var s=i(9504),n=i(9039),r=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=s("".slice),f=s("".replace),b=s([].join),v=o&&!n(function(){return 8!==g(function(){},"length",{value:8}).length}),y=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),v&&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(n){}var s=d(t);return a(s,"source")||(s.source=b(y,"string"==typeof e?e:"")),t};Function.prototype.toString=w(function(){return r(this)&&u(this).source||h(this)},"toString")},350(t,e,i){var s=i(3724),n=i(9297),r=Function.prototype,a=s&&Object.getOwnPropertyDescriptor,o=n(r,"name"),l=o&&"something"===function(){}.name,h=o&&(!s||s&&a(r,"name").configurable);t.exports={EXISTS:o,PROPER:l,CONFIGURABLE:h}},397(t,e,i){var s=i(7751);t.exports=s("document","documentElement")},421(t){t.exports={}},616(t,e,i){var s=i(9039);t.exports=!s(function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})},679(t,e,i){var s=i(1625),n=TypeError;t.exports=function(t,e){if(s(e,t))return t;throw new n("Incorrect invocation")}},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(s){return!0}}},741(t){var e=Math.ceil,i=Math.floor;t.exports=Math.trunc||function(t){var s=+t;return(s>0?i:e)(s)}},757(t,e,i){var s=i(7751),n=i(4901),r=i(1625),a=i(7040),o=Object;t.exports=a?function(t){return"symbol"==typeof t}:function(t){var e=s("Symbol");return n(e)&&r(e.prototype,o(t))}},851(t,e,i){var s=i(6955),n=i(5966),r=i(4117),a=i(6269),o=i(8227),l=o("iterator");t.exports=function(t){if(!r(t))return n(t,l)||n(t,"@@iterator")||a[s(t)]}},1072(t,e,i){var s=i(1828),n=i(8727);t.exports=Object.keys||function(t){return s(t,n)}},1181(t,e,i){var s,n,r,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,b=function(t){return r(t)?n(t):s(t,{})},v=function(t){return function(e){var i;if(!l(e)||(i=n(e)).type!==t)throw new m("Incompatible receiver, "+t+" required");return i}};if(a||d.state){var y=d.state||(d.state=new f);y.get=y.get,y.has=y.has,y.set=y.set,s=function(t,e){if(y.has(t))throw new m(g);return e.facade=t,y.set(t,e),e},n=function(t){return y.get(t)||{}},r=function(t){return y.has(t)}}else{var w=u("state");p[w]=!0,s=function(t,e){if(c(t,w))throw new m(g);return e.facade=t,h(t,w,e),e},n=function(t){return c(t,w)?t[w]:{}},r=function(t){return c(t,w)}}t.exports={set:s,get:n,has:r,enforce:b,getterFor:v}},1291(t,e,i){var s=i(741);t.exports=function(t){var e=+t;return e!==e||0===e?0:s(e)}},1385(t,e,i){var s=i(9539);t.exports=function(t,e,i){for(var n=t.length-1;n>=0;n--)if(void 0!==t[n])try{i=s(t[n].iterator,e,i)}catch(r){e="throw",i=r}if("throw"===e)throw i;return i}},1625(t,e,i){var s=i(9504);t.exports=s({}.isPrototypeOf)},1701(t,e,i){var s=i(6518),n=i(9565),r=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(n(this.next,t)),i=this.done=!!e.done;if(!i)return h(t,this.mapper,[e.value,this.counter++],!0)});s({target:"Iterator",proto:!0,real:!0,forced:f},{map:function(t){a(this);try{r(t)}catch(e){c(this,"throw",e)}return m?n(m,this,t):new b(o(this),{mapper:t})}})},1767(t){t.exports=function(t){return{iterator:t,next:t.next,done:!1}}},1828(t,e,i){var s=i(9504),n=i(9297),r=i(5397),a=i(9617).indexOf,o=i(421),l=s([].push);t.exports=function(t,e){var i,s=r(t),h=0,c=[];for(i in s)!n(o,i)&&n(s,i)&&l(c,i);while(e.length>h)n(s,i=e[h++])&&(~a(c,i)||l(c,i));return c}},2106(t,e,i){var s=i(283),n=i(4913);t.exports=function(t,e,i){return i.get&&s(i.get,e,{getter:!0}),i.set&&s(i.set,e,{setter:!0}),n.f(t,e,i)}},2140(t,e,i){var s=i(8227),n=s("toStringTag"),r={};r[n]="z",t.exports="[object z]"===String(r)},2195(t,e,i){var s=i(9504),n=s({}.toString),r=s("".slice);t.exports=function(t){return r(n(t),8,-1)}},2211(t,e,i){var s=i(9039);t.exports=!s(function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})},2360(t,e,i){var s,n=i(8551),r=i(6801),a=i(8727),o=i(421),l=i(397),h=i(4055),c=i(6119),d=">",u="<",p="prototype",g="script",m=c("IE_PROTO"),f=function(){},b=function(t){return u+g+d+t+u+"/"+g+d},v=function(t){t.write(b("")),t.close();var e=t.parentWindow.Object;return t=null,e},y=function(){var t,e=h("iframe"),i="java"+g+":";return e.style.display="none",l.appendChild(e),e.src=String(i),t=e.contentWindow.document,t.open(),t.write(b("document.F=Object")),t.close(),t.F},w=function(){try{s=new ActiveXObject("htmlfile")}catch(e){}w="undefined"!=typeof document?document.domain&&s?v(s):y():v(s);var t=a.length;while(t--)delete w[p][a[t]];return w()};o[m]=!0,t.exports=Object.create||function(t,e){var i;return null!==t?(f[p]=n(t),i=new f,f[p]=null,i[m]=t):i=w(),void 0===e?i:r.f(i,e)}},2489(t,e,i){var s=i(6518),n=i(9565),r=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(){var t,e,i,s=this.iterator,r=this.predicate,o=this.next;while(1){if(t=a(n(o,s)),e=this.done=!!t.done,e)return;if(i=t.value,h(s,r,[i,this.counter++],!0))return i}});s({target:"Iterator",proto:!0,real:!0,forced:f},{filter:function(t){a(this);try{r(t)}catch(e){d(this,"throw",e)}return m?n(m,this,t):new b(o(this),{predicate:t})}})},2529(t){t.exports=function(t,e){return{value:t,done:e}}},2652(t,e,i){var s=i(6080),n=i(9565),r=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,g=function(t,e){this.stopped=t,this.result=e},m=g.prototype;t.exports=function(t,e,i){var f,b,v,y,w,A,x,_=i&&i.that,S=!(!i||!i.AS_ENTRIES),E=!(!i||!i.IS_RECORD),C=!(!i||!i.IS_ITERATOR),T=!(!i||!i.INTERRUPTED),M=s(e,_),D=function(t){return f&&u(f,"normal"),new g(!0,t)},P=function(t){return S?(r(t),T?M(t[0],t[1],D):M(t[0],t[1])):T?M(t,D):M(t)};if(E)f=t.iterator;else if(C)f=t;else{if(b=d(t),!b)throw new p(a(t)+" is not iterable");if(o(b)){for(v=0,y=l(t);y>v;v++)if(w=P(t[v]),w&&h(m,w))return w;return new g(!1)}f=c(t,b)}A=E?t.next:f.next;while(!(x=n(A,f)).done){try{w=P(x.value)}catch(I){u(f,"throw",I)}if("object"==typeof w&&w&&h(m,w))return w}return new g(!1)}},2777(t,e,i){var s=i(9565),n=i(34),r=i(757),a=i(5966),o=i(4270),l=i(8227),h=TypeError,c=l("toPrimitive");t.exports=function(t,e){if(!n(t)||r(t))return t;var i,l=a(t,c);if(l){if(void 0===e&&(e="default"),i=s(l,t,e),!n(i)||r(i))return i;throw new h("Can't convert object to primitive value")}return void 0===e&&(e="number"),o(t,e)}},2787(t,e,i){var s=i(9297),n=i(4901),r=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=r(t);if(s(e,l))return e[l];var i=e.constructor;return n(i)&&e instanceof i?i.prototype:e instanceof h?c:null}},2796(t,e,i){var s=i(9039),n=i(4901),r=/#|\.prototype\./,a=function(t,e){var i=l[o(t)];return i===c||i!==h&&(n(e)?s(e):!!e)},o=a.normalize=function(t){return String(t).replace(r,".").toLowerCase()},l=a.data={},h=a.NATIVE="N",c=a.POLYFILL="P";t.exports=a},2839(t,e,i){var s=i(4576),n=s.navigator,r=n&&n.userAgent;t.exports=r?String(r):""},3392(t,e,i){var s=i(9504),n=0,r=Math.random(),a=s(1.1.toString);t.exports=function(t){return"Symbol("+(void 0===t?"":t)+")_"+a(++n+r,36)}},3706(t,e,i){var s=i(9504),n=i(4901),r=i(7629),a=s(Function.toString);n(r.inspectSource)||(r.inspectSource=function(t){return a(t)}),t.exports=r.inspectSource},3717(t,e){e.f=Object.getOwnPropertySymbols},3724(t,e,i){var s=i(9039);t.exports=!s(function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]})},4055(t,e,i){var s=i(4576),n=i(34),r=s.document,a=n(r)&&n(r.createElement);t.exports=function(t){return a?r.createElement(t):{}}},4114(t,e,i){var s=i(6518),n=i(8981),r=i(6198),a=i(4527),o=i(6837),l=i(9039),h=l(function(){return 4294967297!==[].push.call({length:4294967296},1)}),c=function(){try{Object.defineProperty([],"length",{writable:!1}).push()}catch(t){return t instanceof TypeError}},d=h||!c();s({target:"Array",proto:!0,arity:1,forced:d},{push:function(t){var e=n(this),i=r(e),s=arguments.length;o(i+s);for(var l=0;l<s;l++)e[i]=arguments[l],i++;return a(e,i),i}})},4117(t){t.exports=function(t){return null===t||void 0===t}},4209(t,e,i){var s=i(8227),n=i(6269),r=s("iterator"),a=Array.prototype;t.exports=function(t){return void 0!==t&&(n.Array===t||a[r]===t)}},4270(t,e,i){var s=i(9565),n=i(4901),r=i(34),a=TypeError;t.exports=function(t,e){var i,o;if("string"===e&&n(i=t.toString)&&!r(o=s(i,t)))return o;if(n(i=t.valueOf)&&!r(o=s(i,t)))return o;if("string"!==e&&n(i=t.toString)&&!r(o=s(i,t)))return o;throw new a("Can't convert object to primitive value")}},4376(t,e,i){var s=i(2195);t.exports=Array.isArray||function(t){return"Array"===s(t)}},4495(t,e,i){var s=i(9519),n=i(9039),r=i(4576),a=r.String;t.exports=!!Object.getOwnPropertySymbols&&!n(function(){var t=Symbol("symbol detection");return!a(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&s&&s<41})},4527(t,e,i){var s=i(3724),n=i(4376),r=TypeError,a=Object.getOwnPropertyDescriptor,o=s&&!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(n(t)&&!a(t,"length").writable)throw new r("Cannot set read only .length");return t.length=e}:function(t,e){return t.length=e}},4549(t,e,i){var s=i(4576);t.exports=function(t,e){var i=s.Iterator,n=i&&i.prototype,r=n&&n[t],a=!1;if(r)try{r.call({next:function(){return{done:!0}},return:function(){a=!0}},-1)}catch(o){o instanceof e||(a=!1)}if(!a)return r}},4576(t){var e=function(t){return t&&t.Math===Math&&t};t.exports=e("object"==typeof globalThis&&globalThis)||e("object"==typeof window&&window)||e("object"==typeof self&&self)||e("object"==typeof globalThis&&globalThis)||e("object"==typeof this&&this)||function(){return this}()||Function("return this")()},4659(t,e,i){var s=i(3724),n=i(4913),r=i(6980);t.exports=function(t,e,i){s?n.f(t,e,r(0,i)):t[e]=i}},4901(t){var e="object"==typeof document&&document.all;t.exports="undefined"==typeof e&&void 0!==e?function(t){return"function"==typeof t||t===e}:function(t){return"function"==typeof t}},4913(t,e,i){var s=i(3724),n=i(5917),r=i(8686),a=i(8551),o=i(6969),l=TypeError,h=Object.defineProperty,c=Object.getOwnPropertyDescriptor,d="enumerable",u="configurable",p="writable";e.f=s?r?function(t,e,i){if(a(t),e=o(e),a(i),"function"===typeof t&&"prototype"===e&&"value"in i&&p in i&&!i[p]){var s=c(t,e);s&&s[p]&&(t[e]=i.value,i={configurable:u in i?i[u]:s[u],enumerable:d in i?i[d]:s[d],writable:!1})}return h(t,e,i)}:h:function(t,e,i){if(a(t),e=o(e),a(i),n)try{return h(t,e,i)}catch(s){}if("get"in i||"set"in i)throw new l("Accessors not supported");return"value"in i&&(t[e]=i.value),t}},5031(t,e,i){var s=i(7751),n=i(9504),r=i(8480),a=i(3717),o=i(8551),l=n([].concat);t.exports=s("Reflect","ownKeys")||function(t){var e=r.f(o(t)),i=a.f;return i?l(e,i(t)):e}},5397(t,e,i){var s=i(7055),n=i(7750);t.exports=function(t){return s(n(t))}},5610(t,e,i){var s=i(1291),n=Math.max,r=Math.min;t.exports=function(t,e){var i=s(t);return i<0?n(i+e,0):r(i,e)}},5745(t,e,i){var s=i(7629);t.exports=function(t,e){return s[t]||(s[t]=e||{})}},5917(t,e,i){var s=i(3724),n=i(9039),r=i(4055);t.exports=!s&&!n(function(){return 7!==Object.defineProperty(r("div"),"a",{get:function(){return 7}}).a})},5966(t,e,i){var s=i(9306),n=i(4117);t.exports=function(t,e){var i=t[e];return n(i)?void 0:s(i)}},6080(t,e,i){var s=i(7476),n=i(9306),r=i(616),a=s(s.bind);t.exports=function(t,e){return n(t),void 0===e?t:r?a(t,e):function(){return t.apply(e,arguments)}}},6119(t,e,i){var s=i(5745),n=i(3392),r=s("keys");t.exports=function(t){return r[t]||(r[t]=n(t))}},6198(t,e,i){var s=i(8014);t.exports=function(t){return s(t.length)}},6269(t){t.exports={}},6279(t,e,i){var s=i(6840);t.exports=function(t,e,i){for(var n in e)s(t,n,e[n],i);return t}},6319(t,e,i){var s=i(8551),n=i(9539);t.exports=function(t,e,i,r){try{return r?e(s(i)[0],i[1]):e(i)}catch(a){n(t,"throw",a)}}},6395(t){t.exports=!1},6518(t,e,i){var s=i(4576),n=i(7347).f,r=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,m=t.target,f=t.global,b=t.stat;if(c=f?s:b?s[m]||o(m,{}):s[m]&&s[m].prototype,c)for(d in e){if(p=e[d],t.dontCallGetSet?(g=n(c,d),u=g&&g.value):u=c[d],i=h(f?d:m+(b?".":"#")+d,t.forced),!i&&void 0!==u){if(typeof p==typeof u)continue;l(p,u)}(t.sham||u&&u.sham)&&r(p,"sham",!0),a(c,d,p,t)}}},6699(t,e,i){var s=i(3724),n=i(4913),r=i(6980);t.exports=s?function(t,e,i){return n.f(t,e,r(1,i))}:function(t,e,i){return t[e]=i,t}},6801(t,e,i){var s=i(3724),n=i(8686),r=i(4913),a=i(8551),o=i(5397),l=i(1072);e.f=s&&!n?Object.defineProperties:function(t,e){a(t);var i,s=o(e),n=l(e),h=n.length,c=0;while(h>c)r.f(t,i=n[c++],s[i]);return t}},6823(t){var e=String;t.exports=function(t){try{return e(t)}catch(i){return"Object"}}},6837(t){var e=TypeError,i=9007199254740991;t.exports=function(t){if(t>i)throw e("Maximum allowed index exceeded");return t}},6840(t,e,i){var s=i(4901),n=i(4913),r=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;if(s(i)&&r(i,h,o),o.global)l?t[e]=i:a(e,i);else{try{o.unsafe?t[e]&&(l=!0):delete t[e]}catch(c){}l?t[e]=i:n.f(t,e,{value:i,enumerable:!1,configurable:!o.nonConfigurable,writable:!o.nonWritable})}return t}},6955(t,e,i){var s=i(2140),n=i(4901),r=i(2195),a=i(8227),o=a("toStringTag"),l=Object,h="Arguments"===r(function(){return arguments}()),c=function(t,e){try{return t[e]}catch(i){}};t.exports=s?r:function(t){var e,i,s;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(i=c(e=l(t),o))?i:h?r(e):"Object"===(s=r(e))&&n(e.callee)?"Arguments":s}},6969(t,e,i){var s=i(2777),n=i(757);t.exports=function(t){var e=s(t,"string");return n(e)?e:e+""}},6980(t){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},7040(t,e,i){var s=i(4495);t.exports=s&&!Symbol.sham&&"symbol"==typeof Symbol.iterator},7055(t,e,i){var s=i(9504),n=i(9039),r=i(2195),a=Object,o=s("".split);t.exports=n(function(){return!a("z").propertyIsEnumerable(0)})?function(t){return"String"===r(t)?o(t,""):a(t)}:a},7347(t,e,i){var s=i(3724),n=i(9565),r=i(8773),a=i(6980),o=i(5397),l=i(6969),h=i(9297),c=i(5917),d=Object.getOwnPropertyDescriptor;e.f=s?d:function(t,e){if(t=o(t),e=l(e),c)try{return d(t,e)}catch(i){}if(h(t,e))return a(!n(r.f,t,e),t[e])}},7476(t,e,i){var s=i(2195),n=i(9504);t.exports=function(t){if("Function"===s(t))return n(t)}},7588(t,e,i){var s=i(6518),n=i(9565),r=i(2652),a=i(9306),o=i(8551),l=i(1767),h=i(9539),c=i(4549),d=c("forEach",TypeError);s({target:"Iterator",proto:!0,real:!0,forced:d},{forEach:function(t){o(this);try{a(t)}catch(s){h(this,"throw",s)}if(d)return n(d,this,t);var e=l(this),i=0;r(e,function(e){t(e,i++)},{IS_RECORD:!0})}})},7629(t,e,i){var s=i(6395),n=i(4576),r=i(9433),a="__core-js_shared__",o=t.exports=n[a]||r(a,{});(o.versions||(o.versions=[])).push({version:"3.47.0",mode:s?"pure":"global",copyright:"© 2014-2025 Denis Pushkarev (zloirock.ru), 2025 CoreJS Company (core-js.io)",license:"https://github.com/zloirock/core-js/blob/v3.47.0/LICENSE",source:"https://github.com/zloirock/core-js"})},7657(t,e,i){var s,n,r,a=i(9039),o=i(4901),l=i(34),h=i(2360),c=i(2787),d=i(6840),u=i(8227),p=i(6395),g=u("iterator"),m=!1;[].keys&&(r=[].keys(),"next"in r?(n=c(c(r)),n!==Object.prototype&&(s=n)):m=!0);var f=!l(s)||a(function(){var t={};return s[g].call(t)!==t});f?s={}:p&&(s=h(s)),o(s[g])||d(s,g,function(){return this}),t.exports={IteratorPrototype:s,BUGGY_SAFARI_ITERATORS:m}},7740(t,e,i){var s=i(9297),n=i(5031),r=i(7347),a=i(4913);t.exports=function(t,e,i){for(var o=n(e),l=a.f,h=r.f,c=0;c<o.length;c++){var d=o[c];s(t,d)||i&&s(i,d)||l(t,d,h(e,d))}}},7750(t,e,i){var s=i(4117),n=TypeError;t.exports=function(t){if(s(t))throw new n("Can't call method on "+t);return t}},7751(t,e,i){var s=i(4576),n=i(4901),r=function(t){return n(t)?t:void 0};t.exports=function(t,e){return arguments.length<2?r(s[t]):s[t]&&s[t][e]}},8014(t,e,i){var s=i(1291),n=Math.min;t.exports=function(t){var e=s(t);return e>0?n(e,9007199254740991):0}},8111(t,e,i){var s=i(6518),n=i(4576),r=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(8227),g=i(7657).IteratorPrototype,m=i(3724),f=i(6395),b="constructor",v="Iterator",y=p("toStringTag"),w=TypeError,A=n[v],x=f||!o(A)||A.prototype!==g||!d(function(){A({})}),_=function(){if(r(this,g),l(this)===g)throw new w("Abstract class Iterator not directly constructable")},S=function(t,e){m?h(g,t,{configurable:!0,get:function(){return e},set:function(e){if(a(this),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,y)||S(y,v),!x&&u(g,b)&&g[b]!==Object||S(b,_),_.prototype=g,s({global:!0,constructor:!0,forced:x},{Iterator:_})},8227(t,e,i){var s=i(4576),n=i(5745),r=i(9297),a=i(3392),o=i(4495),l=i(7040),h=s.Symbol,c=n("wks"),d=l?h["for"]||h:h&&h.withoutSetter||a;t.exports=function(t){return r(c,t)||(c[t]=o&&r(h,t)?h[t]:d("Symbol."+t)),c[t]}},8480(t,e,i){var s=i(1828),n=i(8727),r=n.concat("length","prototype");e.f=Object.getOwnPropertyNames||function(t){return s(t,r)}},8551(t,e,i){var s=i(34),n=String,r=TypeError;t.exports=function(t){if(s(t))return t;throw new r(n(t)+" is not an object")}},8622(t,e,i){var s=i(4576),n=i(4901),r=s.WeakMap;t.exports=n(r)&&/native code/.test(String(r))},8686(t,e,i){var s=i(3724),n=i(9039);t.exports=s&&n(function(){return 42!==Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype})},8727(t){t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},8773(t,e){var i={}.propertyIsEnumerable,s=Object.getOwnPropertyDescriptor,n=s&&!i.call({1:2},1);e.f=n?function(t){var e=s(this,t);return!!e&&e.enumerable}:i},8981(t,e,i){var s=i(7750),n=Object;t.exports=function(t){return n(s(t))}},9039(t){t.exports=function(t){try{return!!t()}catch(e){return!0}}},9297(t,e,i){var s=i(9504),n=i(8981),r=s({}.hasOwnProperty);t.exports=Object.hasOwn||function(t,e){return r(n(t),e)}},9306(t,e,i){var s=i(4901),n=i(6823),r=TypeError;t.exports=function(t){if(s(t))return t;throw new r(n(t)+" is not a function")}},9433(t,e,i){var s=i(4576),n=Object.defineProperty;t.exports=function(t,e){try{n(s,t,{value:e,configurable:!0,writable:!0})}catch(i){s[t]=e}return e}},9462(t,e,i){var s=i(9565),n=i(2360),r=i(6699),a=i(6279),o=i(8227),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",v="throw",y=l.set,w=function(t){var e=l.getterFor(t?f:m);return a(n(c),{next:function(){var i=e(this);if(t)return i.nextHandler();if(i.done)return d(void 0,!0);try{var s=i.nextHandler();return i.returnHandlerResult?s:d(s,i.done)}catch(n){throw i.done=!0,n}},return:function(){var i=e(this),n=i.iterator;if(i.done=!0,t){var r=h(n,"return");return r?s(r,n):d(void 0,!0)}if(i.inner)try{u(i.inner.iterator,b)}catch(a){return u(n,v,a)}if(i.openIters)try{p(i.openIters,b)}catch(a){return u(n,v,a)}return n&&u(n,b),d(void 0,!0)}})},A=w(!0),x=w(!1);r(x,g,"Iterator Helper"),t.exports=function(t,e,i){var s=function(s,n){n?(n.iterator=s.iterator,n.next=s.next):n=s,n.type=e?f:m,n.returnHandlerResult=!!i,n.nextHandler=t,n.counter=0,n.done=!1,y(this,n)};return s.prototype=e?A:x,s}},9504(t,e,i){var s=i(616),n=Function.prototype,r=n.call,a=s&&n.bind.bind(r,r);t.exports=s?a:function(t){return function(){return r.apply(t,arguments)}}},9519(t,e,i){var s,n,r=i(4576),a=i(2839),o=r.process,l=r.Deno,h=o&&o.versions||l&&l.version,c=h&&h.v8;c&&(s=c.split("."),n=s[0]>0&&s[0]<4?1:+(s[0]+s[1])),!n&&a&&(s=a.match(/Edge\/(\d+)/),(!s||s[1]>=74)&&(s=a.match(/Chrome\/(\d+)/),s&&(n=+s[1]))),t.exports=n},9539(t,e,i){var s=i(9565),n=i(8551),r=i(5966);t.exports=function(t,e,i){var a,o;n(t);try{if(a=r(t,"return"),!a){if("throw"===e)throw i;return i}a=s(a,t)}catch(l){o=!0,a=l}if("throw"===e)throw i;if(o)throw a;return n(a),i}},9565(t,e,i){var s=i(616),n=Function.prototype.call;t.exports=s?n.bind(n):function(){return n.apply(n,arguments)}},9617(t,e,i){var s=i(5397),n=i(5610),r=i(6198),a=function(t){return function(e,i,a){var o=s(e),l=r(o);if(0===l)return!t&&-1;var h,c=n(a,l);if(t&&i!==i){while(l>c)if(h=o[c++],h!==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:a(!0),indexOf:a(!1)}}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s].call(r.exports,r,r.exports,i),r.exports}(()=>{i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})}})(),(()=>{i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)})(),(()=>{i.p=""})();var s={};if(i.d(s,{default:()=>pr}),"undefined"!==typeof window){var n=window.document.currentScript,r=n&&n.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);r&&(i.p=r[1])}
1
+ (function(t,e){"object"===typeof exports&&"object"===typeof module?module.exports=e():"function"===typeof define&&define.amd?define([],e):"object"===typeof exports?exports["pdf-elements"]=e():t["pdf-elements"]=e()})("undefined"!==typeof self?self:this,()=>(()=>{"use strict";var t={34(t,e,i){var s=i(4901);t.exports=function(t){return"object"==typeof t?null!==t:s(t)}},81(t,e,i){var s=i(9565),n=i(9306),r=i(8551),a=i(6823),o=i(851),l=TypeError;t.exports=function(t,e){var i=arguments.length<2?o(t):e;if(n(i))return r(s(i,t));throw new l(a(t)+" is not iterable")}},116(t,e,i){var s=i(6518),n=i(9565),r=i(2652),a=i(9306),o=i(8551),l=i(1767),h=i(9539),c=i(4549),d=c("find",TypeError);s({target:"Iterator",proto:!0,real:!0,forced:d},{find:function(t){o(this);try{a(t)}catch(s){h(this,"throw",s)}if(d)return n(d,this,t);var e=l(this),i=0;return r(e,function(e,s){if(t(e,i++))return s(e)},{IS_RECORD:!0,INTERRUPTED:!0}).result}})},283(t,e,i){var s=i(9504),n=i(9039),r=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=s("".slice),f=s("".replace),b=s([].join),v=o&&!n(function(){return 8!==g(function(){},"length",{value:8}).length}),y=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),v&&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(n){}var s=d(t);return a(s,"source")||(s.source=b(y,"string"==typeof e?e:"")),t};Function.prototype.toString=w(function(){return r(this)&&u(this).source||h(this)},"toString")},350(t,e,i){var s=i(3724),n=i(9297),r=Function.prototype,a=s&&Object.getOwnPropertyDescriptor,o=n(r,"name"),l=o&&"something"===function(){}.name,h=o&&(!s||s&&a(r,"name").configurable);t.exports={EXISTS:o,PROPER:l,CONFIGURABLE:h}},397(t,e,i){var s=i(7751);t.exports=s("document","documentElement")},421(t){t.exports={}},531(t,e,i){var s=i(6518),n=i(9565),r=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),g=!d&&!u("flatMap",function(){}),m=!d&&!g&&p("flatMap",TypeError),f=d||g||m,b=h(function(){var t,e,i=this.iterator,s=this.mapper;while(1){if(e=this.inner)try{if(t=a(n(e.next,e.iterator)),!t.done)return t.value;this.inner=null}catch(r){c(i,"throw",r)}if(t=a(n(this.next,i)),this.done=!!t.done)return;try{this.inner=l(s(t.value,this.counter++),!1)}catch(r){c(i,"throw",r)}}});s({target:"Iterator",proto:!0,real:!0,forced:f},{flatMap:function(t){a(this);try{r(t)}catch(e){c(this,"throw",e)}return m?n(m,this,t):new b(o(this),{mapper:t,inner:null})}})},616(t,e,i){var s=i(9039);t.exports=!s(function(){var t=function(){}.bind();return"function"!=typeof t||t.hasOwnProperty("prototype")})},679(t,e,i){var s=i(1625),n=TypeError;t.exports=function(t,e){if(s(e,t))return t;throw new n("Incorrect invocation")}},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(s){return!0}}},741(t){var e=Math.ceil,i=Math.floor;t.exports=Math.trunc||function(t){var s=+t;return(s>0?i:e)(s)}},757(t,e,i){var s=i(7751),n=i(4901),r=i(1625),a=i(7040),o=Object;t.exports=a?function(t){return"symbol"==typeof t}:function(t){var e=s("Symbol");return n(e)&&r(e.prototype,o(t))}},851(t,e,i){var s=i(6955),n=i(5966),r=i(4117),a=i(6269),o=i(8227),l=o("iterator");t.exports=function(t){if(!r(t))return n(t,l)||n(t,"@@iterator")||a[s(t)]}},1072(t,e,i){var s=i(1828),n=i(8727);t.exports=Object.keys||function(t){return s(t,n)}},1181(t,e,i){var s,n,r,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,b=function(t){return r(t)?n(t):s(t,{})},v=function(t){return function(e){var i;if(!l(e)||(i=n(e)).type!==t)throw new m("Incompatible receiver, "+t+" required");return i}};if(a||d.state){var y=d.state||(d.state=new f);y.get=y.get,y.has=y.has,y.set=y.set,s=function(t,e){if(y.has(t))throw new m(g);return e.facade=t,y.set(t,e),e},n=function(t){return y.get(t)||{}},r=function(t){return y.has(t)}}else{var w=u("state");p[w]=!0,s=function(t,e){if(c(t,w))throw new m(g);return e.facade=t,h(t,w,e),e},n=function(t){return c(t,w)?t[w]:{}},r=function(t){return c(t,w)}}t.exports={set:s,get:n,has:r,enforce:b,getterFor:v}},1291(t,e,i){var s=i(741);t.exports=function(t){var e=+t;return e!==e||0===e?0:s(e)}},1385(t,e,i){var s=i(9539);t.exports=function(t,e,i){for(var n=t.length-1;n>=0;n--)if(void 0!==t[n])try{i=s(t[n].iterator,e,i)}catch(r){e="throw",i=r}if("throw"===e)throw i;return i}},1625(t,e,i){var s=i(9504);t.exports=s({}.isPrototypeOf)},1701(t,e,i){var s=i(6518),n=i(9565),r=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(n(this.next,t)),i=this.done=!!e.done;if(!i)return h(t,this.mapper,[e.value,this.counter++],!0)});s({target:"Iterator",proto:!0,real:!0,forced:f},{map:function(t){a(this);try{r(t)}catch(e){c(this,"throw",e)}return m?n(m,this,t):new b(o(this),{mapper:t})}})},1767(t){t.exports=function(t){return{iterator:t,next:t.next,done:!1}}},1828(t,e,i){var s=i(9504),n=i(9297),r=i(5397),a=i(9617).indexOf,o=i(421),l=s([].push);t.exports=function(t,e){var i,s=r(t),h=0,c=[];for(i in s)!n(o,i)&&n(s,i)&&l(c,i);while(e.length>h)n(s,i=e[h++])&&(~a(c,i)||l(c,i));return c}},2106(t,e,i){var s=i(283),n=i(4913);t.exports=function(t,e,i){return i.get&&s(i.get,e,{getter:!0}),i.set&&s(i.set,e,{setter:!0}),n.f(t,e,i)}},2140(t,e,i){var s=i(8227),n=s("toStringTag"),r={};r[n]="z",t.exports="[object z]"===String(r)},2195(t,e,i){var s=i(9504),n=s({}.toString),r=s("".slice);t.exports=function(t){return r(n(t),8,-1)}},2211(t,e,i){var s=i(9039);t.exports=!s(function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype})},2360(t,e,i){var s,n=i(8551),r=i(6801),a=i(8727),o=i(421),l=i(397),h=i(4055),c=i(6119),d=">",u="<",p="prototype",g="script",m=c("IE_PROTO"),f=function(){},b=function(t){return u+g+d+t+u+"/"+g+d},v=function(t){t.write(b("")),t.close();var e=t.parentWindow.Object;return t=null,e},y=function(){var t,e=h("iframe"),i="java"+g+":";return e.style.display="none",l.appendChild(e),e.src=String(i),t=e.contentWindow.document,t.open(),t.write(b("document.F=Object")),t.close(),t.F},w=function(){try{s=new ActiveXObject("htmlfile")}catch(e){}w="undefined"!=typeof document?document.domain&&s?v(s):y():v(s);var t=a.length;while(t--)delete w[p][a[t]];return w()};o[m]=!0,t.exports=Object.create||function(t,e){var i;return null!==t?(f[p]=n(t),i=new f,f[p]=null,i[m]=t):i=w(),void 0===e?i:r.f(i,e)}},2489(t,e,i){var s=i(6518),n=i(9565),r=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(){var t,e,i,s=this.iterator,r=this.predicate,o=this.next;while(1){if(t=a(n(o,s)),e=this.done=!!t.done,e)return;if(i=t.value,h(s,r,[i,this.counter++],!0))return i}});s({target:"Iterator",proto:!0,real:!0,forced:f},{filter:function(t){a(this);try{r(t)}catch(e){d(this,"throw",e)}return m?n(m,this,t):new b(o(this),{predicate:t})}})},2529(t){t.exports=function(t,e){return{value:t,done:e}}},2652(t,e,i){var s=i(6080),n=i(9565),r=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,g=function(t,e){this.stopped=t,this.result=e},m=g.prototype;t.exports=function(t,e,i){var f,b,v,y,w,A,x,_=i&&i.that,S=!(!i||!i.AS_ENTRIES),E=!(!i||!i.IS_RECORD),C=!(!i||!i.IS_ITERATOR),T=!(!i||!i.INTERRUPTED),M=s(e,_),D=function(t){return f&&u(f,"normal"),new g(!0,t)},P=function(t){return S?(r(t),T?M(t[0],t[1],D):M(t[0],t[1])):T?M(t,D):M(t)};if(E)f=t.iterator;else if(C)f=t;else{if(b=d(t),!b)throw new p(a(t)+" is not iterable");if(o(b)){for(v=0,y=l(t);y>v;v++)if(w=P(t[v]),w&&h(m,w))return w;return new g(!1)}f=c(t,b)}A=E?t.next:f.next;while(!(x=n(A,f)).done){try{w=P(x.value)}catch(I){u(f,"throw",I)}if("object"==typeof w&&w&&h(m,w))return w}return new g(!1)}},2777(t,e,i){var s=i(9565),n=i(34),r=i(757),a=i(5966),o=i(4270),l=i(8227),h=TypeError,c=l("toPrimitive");t.exports=function(t,e){if(!n(t)||r(t))return t;var i,l=a(t,c);if(l){if(void 0===e&&(e="default"),i=s(l,t,e),!n(i)||r(i))return i;throw new h("Can't convert object to primitive value")}return void 0===e&&(e="number"),o(t,e)}},2787(t,e,i){var s=i(9297),n=i(4901),r=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=r(t);if(s(e,l))return e[l];var i=e.constructor;return n(i)&&e instanceof i?i.prototype:e instanceof h?c:null}},2796(t,e,i){var s=i(9039),n=i(4901),r=/#|\.prototype\./,a=function(t,e){var i=l[o(t)];return i===c||i!==h&&(n(e)?s(e):!!e)},o=a.normalize=function(t){return String(t).replace(r,".").toLowerCase()},l=a.data={},h=a.NATIVE="N",c=a.POLYFILL="P";t.exports=a},2839(t,e,i){var s=i(4576),n=s.navigator,r=n&&n.userAgent;t.exports=r?String(r):""},3392(t,e,i){var s=i(9504),n=0,r=Math.random(),a=s(1.1.toString);t.exports=function(t){return"Symbol("+(void 0===t?"":t)+")_"+a(++n+r,36)}},3706(t,e,i){var s=i(9504),n=i(4901),r=i(7629),a=s(Function.toString);n(r.inspectSource)||(r.inspectSource=function(t){return a(t)}),t.exports=r.inspectSource},3717(t,e){e.f=Object.getOwnPropertySymbols},3724(t,e,i){var s=i(9039);t.exports=!s(function(){return 7!==Object.defineProperty({},1,{get:function(){return 7}})[1]})},4055(t,e,i){var s=i(4576),n=i(34),r=s.document,a=n(r)&&n(r.createElement);t.exports=function(t){return a?r.createElement(t):{}}},4114(t,e,i){var s=i(6518),n=i(8981),r=i(6198),a=i(4527),o=i(6837),l=i(9039),h=l(function(){return 4294967297!==[].push.call({length:4294967296},1)}),c=function(){try{Object.defineProperty([],"length",{writable:!1}).push()}catch(t){return t instanceof TypeError}},d=h||!c();s({target:"Array",proto:!0,arity:1,forced:d},{push:function(t){var e=n(this),i=r(e),s=arguments.length;o(i+s);for(var l=0;l<s;l++)e[i]=arguments[l],i++;return a(e,i),i}})},4117(t){t.exports=function(t){return null===t||void 0===t}},4209(t,e,i){var s=i(8227),n=i(6269),r=s("iterator"),a=Array.prototype;t.exports=function(t){return void 0!==t&&(n.Array===t||a[r]===t)}},4270(t,e,i){var s=i(9565),n=i(4901),r=i(34),a=TypeError;t.exports=function(t,e){var i,o;if("string"===e&&n(i=t.toString)&&!r(o=s(i,t)))return o;if(n(i=t.valueOf)&&!r(o=s(i,t)))return o;if("string"!==e&&n(i=t.toString)&&!r(o=s(i,t)))return o;throw new a("Can't convert object to primitive value")}},4376(t,e,i){var s=i(2195);t.exports=Array.isArray||function(t){return"Array"===s(t)}},4495(t,e,i){var s=i(9519),n=i(9039),r=i(4576),a=r.String;t.exports=!!Object.getOwnPropertySymbols&&!n(function(){var t=Symbol("symbol detection");return!a(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&s&&s<41})},4527(t,e,i){var s=i(3724),n=i(4376),r=TypeError,a=Object.getOwnPropertyDescriptor,o=s&&!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(n(t)&&!a(t,"length").writable)throw new r("Cannot set read only .length");return t.length=e}:function(t,e){return t.length=e}},4549(t,e,i){var s=i(4576);t.exports=function(t,e){var i=s.Iterator,n=i&&i.prototype,r=n&&n[t],a=!1;if(r)try{r.call({next:function(){return{done:!0}},return:function(){a=!0}},-1)}catch(o){o instanceof e||(a=!1)}if(!a)return r}},4576(t){var e=function(t){return t&&t.Math===Math&&t};t.exports=e("object"==typeof globalThis&&globalThis)||e("object"==typeof window&&window)||e("object"==typeof self&&self)||e("object"==typeof globalThis&&globalThis)||e("object"==typeof this&&this)||function(){return this}()||Function("return this")()},4659(t,e,i){var s=i(3724),n=i(4913),r=i(6980);t.exports=function(t,e,i){s?n.f(t,e,r(0,i)):t[e]=i}},4901(t){var e="object"==typeof document&&document.all;t.exports="undefined"==typeof e&&void 0!==e?function(t){return"function"==typeof t||t===e}:function(t){return"function"==typeof t}},4913(t,e,i){var s=i(3724),n=i(5917),r=i(8686),a=i(8551),o=i(6969),l=TypeError,h=Object.defineProperty,c=Object.getOwnPropertyDescriptor,d="enumerable",u="configurable",p="writable";e.f=s?r?function(t,e,i){if(a(t),e=o(e),a(i),"function"===typeof t&&"prototype"===e&&"value"in i&&p in i&&!i[p]){var s=c(t,e);s&&s[p]&&(t[e]=i.value,i={configurable:u in i?i[u]:s[u],enumerable:d in i?i[d]:s[d],writable:!1})}return h(t,e,i)}:h:function(t,e,i){if(a(t),e=o(e),a(i),n)try{return h(t,e,i)}catch(s){}if("get"in i||"set"in i)throw new l("Accessors not supported");return"value"in i&&(t[e]=i.value),t}},5031(t,e,i){var s=i(7751),n=i(9504),r=i(8480),a=i(3717),o=i(8551),l=n([].concat);t.exports=s("Reflect","ownKeys")||function(t){var e=r.f(o(t)),i=a.f;return i?l(e,i(t)):e}},5397(t,e,i){var s=i(7055),n=i(7750);t.exports=function(t){return s(n(t))}},5610(t,e,i){var s=i(1291),n=Math.max,r=Math.min;t.exports=function(t,e){var i=s(t);return i<0?n(i+e,0):r(i,e)}},5745(t,e,i){var s=i(7629);t.exports=function(t,e){return s[t]||(s[t]=e||{})}},5917(t,e,i){var s=i(3724),n=i(9039),r=i(4055);t.exports=!s&&!n(function(){return 7!==Object.defineProperty(r("div"),"a",{get:function(){return 7}}).a})},5966(t,e,i){var s=i(9306),n=i(4117);t.exports=function(t,e){var i=t[e];return n(i)?void 0:s(i)}},6080(t,e,i){var s=i(7476),n=i(9306),r=i(616),a=s(s.bind);t.exports=function(t,e){return n(t),void 0===e?t:r?a(t,e):function(){return t.apply(e,arguments)}}},6119(t,e,i){var s=i(5745),n=i(3392),r=s("keys");t.exports=function(t){return r[t]||(r[t]=n(t))}},6198(t,e,i){var s=i(8014);t.exports=function(t){return s(t.length)}},6269(t){t.exports={}},6279(t,e,i){var s=i(6840);t.exports=function(t,e,i){for(var n in e)s(t,n,e[n],i);return t}},6319(t,e,i){var s=i(8551),n=i(9539);t.exports=function(t,e,i,r){try{return r?e(s(i)[0],i[1]):e(i)}catch(a){n(t,"throw",a)}}},6395(t){t.exports=!1},6518(t,e,i){var s=i(4576),n=i(7347).f,r=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,m=t.target,f=t.global,b=t.stat;if(c=f?s:b?s[m]||o(m,{}):s[m]&&s[m].prototype,c)for(d in e){if(p=e[d],t.dontCallGetSet?(g=n(c,d),u=g&&g.value):u=c[d],i=h(f?d:m+(b?".":"#")+d,t.forced),!i&&void 0!==u){if(typeof p==typeof u)continue;l(p,u)}(t.sham||u&&u.sham)&&r(p,"sham",!0),a(c,d,p,t)}}},6699(t,e,i){var s=i(3724),n=i(4913),r=i(6980);t.exports=s?function(t,e,i){return n.f(t,e,r(1,i))}:function(t,e,i){return t[e]=i,t}},6801(t,e,i){var s=i(3724),n=i(8686),r=i(4913),a=i(8551),o=i(5397),l=i(1072);e.f=s&&!n?Object.defineProperties:function(t,e){a(t);var i,s=o(e),n=l(e),h=n.length,c=0;while(h>c)r.f(t,i=n[c++],s[i]);return t}},6823(t){var e=String;t.exports=function(t){try{return e(t)}catch(i){return"Object"}}},6837(t){var e=TypeError,i=9007199254740991;t.exports=function(t){if(t>i)throw e("Maximum allowed index exceeded");return t}},6840(t,e,i){var s=i(4901),n=i(4913),r=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;if(s(i)&&r(i,h,o),o.global)l?t[e]=i:a(e,i);else{try{o.unsafe?t[e]&&(l=!0):delete t[e]}catch(c){}l?t[e]=i:n.f(t,e,{value:i,enumerable:!1,configurable:!o.nonConfigurable,writable:!o.nonWritable})}return t}},6955(t,e,i){var s=i(2140),n=i(4901),r=i(2195),a=i(8227),o=a("toStringTag"),l=Object,h="Arguments"===r(function(){return arguments}()),c=function(t,e){try{return t[e]}catch(i){}};t.exports=s?r:function(t){var e,i,s;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(i=c(e=l(t),o))?i:h?r(e):"Object"===(s=r(e))&&n(e.callee)?"Arguments":s}},6969(t,e,i){var s=i(2777),n=i(757);t.exports=function(t){var e=s(t,"string");return n(e)?e:e+""}},6980(t){t.exports=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}}},7040(t,e,i){var s=i(4495);t.exports=s&&!Symbol.sham&&"symbol"==typeof Symbol.iterator},7055(t,e,i){var s=i(9504),n=i(9039),r=i(2195),a=Object,o=s("".split);t.exports=n(function(){return!a("z").propertyIsEnumerable(0)})?function(t){return"String"===r(t)?o(t,""):a(t)}:a},7347(t,e,i){var s=i(3724),n=i(9565),r=i(8773),a=i(6980),o=i(5397),l=i(6969),h=i(9297),c=i(5917),d=Object.getOwnPropertyDescriptor;e.f=s?d:function(t,e){if(t=o(t),e=l(e),c)try{return d(t,e)}catch(i){}if(h(t,e))return a(!n(r.f,t,e),t[e])}},7476(t,e,i){var s=i(2195),n=i(9504);t.exports=function(t){if("Function"===s(t))return n(t)}},7588(t,e,i){var s=i(6518),n=i(9565),r=i(2652),a=i(9306),o=i(8551),l=i(1767),h=i(9539),c=i(4549),d=c("forEach",TypeError);s({target:"Iterator",proto:!0,real:!0,forced:d},{forEach:function(t){o(this);try{a(t)}catch(s){h(this,"throw",s)}if(d)return n(d,this,t);var e=l(this),i=0;r(e,function(e){t(e,i++)},{IS_RECORD:!0})}})},7629(t,e,i){var s=i(6395),n=i(4576),r=i(9433),a="__core-js_shared__",o=t.exports=n[a]||r(a,{});(o.versions||(o.versions=[])).push({version:"3.47.0",mode:s?"pure":"global",copyright:"© 2014-2025 Denis Pushkarev (zloirock.ru), 2025 CoreJS Company (core-js.io)",license:"https://github.com/zloirock/core-js/blob/v3.47.0/LICENSE",source:"https://github.com/zloirock/core-js"})},7657(t,e,i){var s,n,r,a=i(9039),o=i(4901),l=i(34),h=i(2360),c=i(2787),d=i(6840),u=i(8227),p=i(6395),g=u("iterator"),m=!1;[].keys&&(r=[].keys(),"next"in r?(n=c(c(r)),n!==Object.prototype&&(s=n)):m=!0);var f=!l(s)||a(function(){var t={};return s[g].call(t)!==t});f?s={}:p&&(s=h(s)),o(s[g])||d(s,g,function(){return this}),t.exports={IteratorPrototype:s,BUGGY_SAFARI_ITERATORS:m}},7740(t,e,i){var s=i(9297),n=i(5031),r=i(7347),a=i(4913);t.exports=function(t,e,i){for(var o=n(e),l=a.f,h=r.f,c=0;c<o.length;c++){var d=o[c];s(t,d)||i&&s(i,d)||l(t,d,h(e,d))}}},7750(t,e,i){var s=i(4117),n=TypeError;t.exports=function(t){if(s(t))throw new n("Can't call method on "+t);return t}},7751(t,e,i){var s=i(4576),n=i(4901),r=function(t){return n(t)?t:void 0};t.exports=function(t,e){return arguments.length<2?r(s[t]):s[t]&&s[t][e]}},8014(t,e,i){var s=i(1291),n=Math.min;t.exports=function(t){var e=s(t);return e>0?n(e,9007199254740991):0}},8111(t,e,i){var s=i(6518),n=i(4576),r=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(8227),g=i(7657).IteratorPrototype,m=i(3724),f=i(6395),b="constructor",v="Iterator",y=p("toStringTag"),w=TypeError,A=n[v],x=f||!o(A)||A.prototype!==g||!d(function(){A({})}),_=function(){if(r(this,g),l(this)===g)throw new w("Abstract class Iterator not directly constructable")},S=function(t,e){m?h(g,t,{configurable:!0,get:function(){return e},set:function(e){if(a(this),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,y)||S(y,v),!x&&u(g,b)&&g[b]!==Object||S(b,_),_.prototype=g,s({global:!0,constructor:!0,forced:x},{Iterator:_})},8227(t,e,i){var s=i(4576),n=i(5745),r=i(9297),a=i(3392),o=i(4495),l=i(7040),h=s.Symbol,c=n("wks"),d=l?h["for"]||h:h&&h.withoutSetter||a;t.exports=function(t){return r(c,t)||(c[t]=o&&r(h,t)?h[t]:d("Symbol."+t)),c[t]}},8480(t,e,i){var s=i(1828),n=i(8727),r=n.concat("length","prototype");e.f=Object.getOwnPropertyNames||function(t){return s(t,r)}},8551(t,e,i){var s=i(34),n=String,r=TypeError;t.exports=function(t){if(s(t))return t;throw new r(n(t)+" is not an object")}},8622(t,e,i){var s=i(4576),n=i(4901),r=s.WeakMap;t.exports=n(r)&&/native code/.test(String(r))},8646(t,e,i){var s=i(9565),n=i(8551),r=i(1767),a=i(851);t.exports=function(t,e){e&&"string"===typeof t||n(t);var i=a(t);return r(n(void 0!==i?s(i,t):t))}},8686(t,e,i){var s=i(3724),n=i(9039);t.exports=s&&n(function(){return 42!==Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype})},8727(t){t.exports=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"]},8773(t,e){var i={}.propertyIsEnumerable,s=Object.getOwnPropertyDescriptor,n=s&&!i.call({1:2},1);e.f=n?function(t){var e=s(this,t);return!!e&&e.enumerable}:i},8981(t,e,i){var s=i(7750),n=Object;t.exports=function(t){return n(s(t))}},9039(t){t.exports=function(t){try{return!!t()}catch(e){return!0}}},9297(t,e,i){var s=i(9504),n=i(8981),r=s({}.hasOwnProperty);t.exports=Object.hasOwn||function(t,e){return r(n(t),e)}},9306(t,e,i){var s=i(4901),n=i(6823),r=TypeError;t.exports=function(t){if(s(t))return t;throw new r(n(t)+" is not a function")}},9433(t,e,i){var s=i(4576),n=Object.defineProperty;t.exports=function(t,e){try{n(s,t,{value:e,configurable:!0,writable:!0})}catch(i){s[t]=e}return e}},9462(t,e,i){var s=i(9565),n=i(2360),r=i(6699),a=i(6279),o=i(8227),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",v="throw",y=l.set,w=function(t){var e=l.getterFor(t?f:m);return a(n(c),{next:function(){var i=e(this);if(t)return i.nextHandler();if(i.done)return d(void 0,!0);try{var s=i.nextHandler();return i.returnHandlerResult?s:d(s,i.done)}catch(n){throw i.done=!0,n}},return:function(){var i=e(this),n=i.iterator;if(i.done=!0,t){var r=h(n,"return");return r?s(r,n):d(void 0,!0)}if(i.inner)try{u(i.inner.iterator,b)}catch(a){return u(n,v,a)}if(i.openIters)try{p(i.openIters,b)}catch(a){return u(n,v,a)}return n&&u(n,b),d(void 0,!0)}})},A=w(!0),x=w(!1);r(x,g,"Iterator Helper"),t.exports=function(t,e,i){var s=function(s,n){n?(n.iterator=s.iterator,n.next=s.next):n=s,n.type=e?f:m,n.returnHandlerResult=!!i,n.nextHandler=t,n.counter=0,n.done=!1,y(this,n)};return s.prototype=e?A:x,s}},9504(t,e,i){var s=i(616),n=Function.prototype,r=n.call,a=s&&n.bind.bind(r,r);t.exports=s?a:function(t){return function(){return r.apply(t,arguments)}}},9519(t,e,i){var s,n,r=i(4576),a=i(2839),o=r.process,l=r.Deno,h=o&&o.versions||l&&l.version,c=h&&h.v8;c&&(s=c.split("."),n=s[0]>0&&s[0]<4?1:+(s[0]+s[1])),!n&&a&&(s=a.match(/Edge\/(\d+)/),(!s||s[1]>=74)&&(s=a.match(/Chrome\/(\d+)/),s&&(n=+s[1]))),t.exports=n},9539(t,e,i){var s=i(9565),n=i(8551),r=i(5966);t.exports=function(t,e,i){var a,o;n(t);try{if(a=r(t,"return"),!a){if("throw"===e)throw i;return i}a=s(a,t)}catch(l){o=!0,a=l}if("throw"===e)throw i;if(o)throw a;return n(a),i}},9565(t,e,i){var s=i(616),n=Function.prototype.call;t.exports=s?n.bind(n):function(){return n.apply(n,arguments)}},9617(t,e,i){var s=i(5397),n=i(5610),r=i(6198),a=function(t){return function(e,i,a){var o=s(e),l=r(o);if(0===l)return!t&&-1;var h,c=n(a,l);if(t&&i!==i){while(l>c)if(h=o[c++],h!==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:a(!0),indexOf:a(!1)}}},e={};function i(s){var n=e[s];if(void 0!==n)return n.exports;var r=e[s]={exports:{}};return t[s].call(r.exports,r,r.exports,i),r.exports}(()=>{i.d=(t,e)=>{for(var s in e)i.o(e,s)&&!i.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})}})(),(()=>{i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)})(),(()=>{i.p=""})();var s={};if(i.d(s,{default:()=>pr}),"undefined"!==typeof window){var n=window.document.currentScript,r=n&&n.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);r&&(i.p=r[1])}
2
2
  /**
3
3
  * @licstart The following is the entire license notice for the
4
4
  * JavaScript code in this page
@@ -19,5 +19,5 @@
19
19
  *
20
20
  * @licend The above is the entire license notice for the
21
21
  * JavaScript code in this page
22
- */var a={};(()=>{a.d=(t,e)=>{for(var i in e)a.o(e,i)&&!a.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})}})(),(()=>{a.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)})();const o="object"===typeof process&&process+""==="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&"browser"!==process.type),l=[.001,0,0,.001,0,0],h=1.35,c={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},d={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},u="pdfjs_internal_editor_",p={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101,COMMENT:102},g={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,HIGHLIGHT_COLOR:31,HIGHLIGHT_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},m={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},f={TRIANGLES:1,LATTICE:2,PATCH:3},b={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_ADD_TO_PATH:4,STROKE_ADD_TO_PATH:5,FILL_STROKE_ADD_TO_PATH:6,ADD_TO_PATH:7,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},v={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},y={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},w={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},A={ERRORS:0,WARNINGS:1,INFOS:5},x={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},_={moveTo:0,lineTo:1,curveTo:2,quadraticCurveTo:3,closePath:4},S={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let E=A.WARNINGS;function C(t){Number.isInteger(t)&&(E=t)}function T(){return E}function M(t){E>=A.INFOS&&console.info(`Info: ${t}`)}function D(t){E>=A.WARNINGS&&console.warn(`Warning: ${t}`)}function P(t){throw new Error(t)}function I(t,e){t||P(e)}function k(t){switch(t?.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function R(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=Q(t)}catch{}}const s=e?URL.parse(t,e):URL.parse(t);return k(s)?s:null}function L(t,e,i=!1){const s=URL.parse(t);return s?(s.hash=e,s.href):i&&R(t,"http://example.com")?t.split("#",1)[0]+""+(e?`#${e}`:""):""}function F(t,e,i,s=!1){return Object.defineProperty(t,e,{value:i,enumerable:!s,configurable:!0,writable:!1}),i}const O=function(){function t(t,e){this.message=t,this.name=e}return t.prototype=new Error,t.constructor=t,t}();class B extends O{constructor(t,e){super(t,"PasswordException"),this.code=e}}class N extends O{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class U extends O{constructor(t){super(t,"InvalidPDFException")}}class j extends O{constructor(t,e,i){super(t,"ResponseException"),this.status=e,this.missing=i}}class H extends O{constructor(t){super(t,"FormatError")}}class z extends O{constructor(t){super(t,"AbortException")}}function $(t){"object"===typeof t&&void 0!==t?.length||P("Invalid argument for bytesToString");const e=t.length,i=8192;if(e<i)return String.fromCharCode.apply(null,t);const s=[];for(let n=0;n<e;n+=i){const r=Math.min(n+i,e),a=t.subarray(n,r);s.push(String.fromCharCode.apply(null,a))}return s.join("")}function G(t){"string"!==typeof t&&P("Invalid argument for stringToBytes");const e=t.length,i=new Uint8Array(e);for(let s=0;s<e;++s)i[s]=255&t.charCodeAt(s);return i}function W(t){return String.fromCharCode(t>>24&255,t>>16&255,t>>8&255,255&t)}function V(){const t=new Uint8Array(4);t[0]=1;const e=new Uint32Array(t.buffer,0,1);return 1===e[0]}function q(){try{return new Function(""),!0}catch{return!1}}class X{static get isLittleEndian(){return F(this,"isLittleEndian",V())}static get isEvalSupported(){return F(this,"isEvalSupported",q())}static get isOffscreenCanvasSupported(){return F(this,"isOffscreenCanvasSupported","undefined"!==typeof OffscreenCanvas)}static get isImageDecoderSupported(){return F(this,"isImageDecoderSupported","undefined"!==typeof ImageDecoder)}static get isFloat16ArraySupported(){return F(this,"isFloat16ArraySupported","undefined"!==typeof Float16Array)}static get isSanitizerSupported(){return F(this,"isSanitizerSupported","undefined"!==typeof Sanitizer)}static get platform(){const{platform:t,userAgent:e}=navigator;return F(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 F(this,"isCSSRoundSupported",globalThis.CSS?.supports?.("width: round(1.5px, 1px)"))}}const Y=Array.from(Array(256).keys(),t=>t.toString(16).padStart(2,"0"));class K{static makeHexColor(t,e,i){return`#${Y[t]}${Y[e]}${Y[i]}`}static domMatrixToTransform(t){return[t.a,t.b,t.c,t.d,t.e,t.f]}static scaleMinMax(t,e){let i;t[0]?(t[0]<0&&(i=e[0],e[0]=e[2],e[2]=i),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(i=e[1],e[1]=e[3],e[3]=i),e[1]*=t[3],e[3]*=t[3]):(i=e[0],e[0]=e[1],e[1]=i,i=e[2],e[2]=e[3],e[3]=i,t[1]<0&&(i=e[1],e[1]=e[3],e[3]=i),e[1]*=t[1],e[3]*=t[1],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 s=t[i],n=t[i+1];t[i]=s*e[0]+n*e[2]+e[4],t[i+1]=s*e[1]+n*e[3]+e[5]}static applyTransformToBezier(t,e,i=0){const s=e[0],n=e[1],r=e[2],a=e[3],o=e[4],l=e[5];for(let h=0;h<6;h+=2){const e=t[i+h],c=t[i+h+1];t[i+h]=e*s+c*r+o,t[i+h+1]=e*n+c*a+l}}static applyInverseTransform(t,e){const i=t[0],s=t[1],n=e[0]*e[3]-e[1]*e[2];t[0]=(i*e[3]-s*e[2]+e[2]*e[5]-e[4]*e[3])/n,t[1]=(-i*e[1]+s*e[0]+e[4]*e[1]-e[5]*e[0])/n}static axialAlignedBoundingBox(t,e,i){const s=e[0],n=e[1],r=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=s*h+o,g=p,m=s*d+o,f=m,b=a*c+l,v=b,y=a*u+l,w=y;if(0!==n||0!==r){const t=n*h,e=n*d,i=r*c,s=r*u;p+=i,f+=i,m+=s,g+=s,b+=t,w+=t,y+=e,v+=e}i[0]=Math.min(i[0],p,m,g,f),i[1]=Math.min(i[1],b,y,v,w),i[2]=Math.max(i[2],p,m,g,f),i[3]=Math.max(i[3],b,y,v,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],s=t[1],n=t[2],r=t[3],a=i**2+s**2,o=i*n+s*r,l=n**2+r**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);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}static intersect(t,e){const i=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),s=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(i>s)return null;const n=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),r=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return n>r?null:[i,n,s,r]}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,s,n){n[0]=Math.min(n[0],t,i),n[1]=Math.min(n[1],e,s),n[2]=Math.max(n[2],t,i),n[3]=Math.max(n[3],e,s)}static#t(t,e,i,s,n,r,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*s,g=c*(c*(c*n+3*l*r)+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,s,n,r,a,o,l,h,c,d){if(Math.abs(l)<1e-12)return void(Math.abs(h)>=1e-12&&this.#t(t,e,i,s,n,r,a,o,-c/h,d));const u=h**2-4*c*l;if(u<0)return;const p=Math.sqrt(u),g=2*l;this.#t(t,e,i,s,n,r,a,o,(-h+p)/g,d),this.#t(t,e,i,s,n,r,a,o,(-h-p)/g,d)}static bezierBoundingBox(t,e,i,s,n,r,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,n,a,e,s,r,o,3*(3*(i-n)-t+a),6*(t-2*i+n),3*(i-t),l),this.#e(t,i,n,a,e,s,r,o,3*(3*(s-r)-e+o),6*(e-2*s+r),3*(s-e),l)}}function Q(t){return decodeURIComponent(escape(t))}let J=null,Z=null;function tt(t){return J||(J=/([\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,Z=new Map([["ſt","ſt"]])),t.replaceAll(J,(t,e,i)=>e?e.normalize("NFKC"):Z.get(i))}function et(){if("function"===typeof crypto.randomUUID)return crypto.randomUUID();const t=new Uint8Array(32);return crypto.getRandomValues(t),$(t)}const it="pdfjs_internal_id_";function st(t,e,i){if(!Array.isArray(i)||i.length<2)return!1;const[s,n,...r]=i;if(!t(s)&&!Number.isInteger(s))return!1;if(!e(n))return!1;const a=r.length;let o=!0;switch(n.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 l of r)if(!("number"===typeof l||o&&null===l))return!1;return!0}function nt(t,e,i){return Math.min(Math.max(t,e),i)}function rt(t){return Uint8Array.prototype.toBase64?t.toBase64():btoa($(t))}function at(t){return Uint8Array.fromBase64?Uint8Array.fromBase64(t):G(atob(t))}"function"!==typeof Promise.try&&(Promise.try=function(t,...e){return new Promise(i=>{i(t(...e))})}),"function"!==typeof Math.sumPrecise&&(Math.sumPrecise=function(t){return t.reduce((t,e)=>t+e,0)});class ot{static textContent(t){const e=[],i={items:e,styles:Object.create(null)};function s(t){if(!t)return;let i=null;const n=t.name;if("#text"===n)i=t.value;else{if(!ot.shouldBuildText(n))return;t?.attributes?.textContent?i=t.attributes.textContent:t.value&&(i=t.value)}if(null!==i&&e.push({str:i}),t.children)for(const e of t.children)s(e)}return s(t),i}static shouldBuildText(t){return!("textarea"===t||"input"===t||"option"===t||"select"===t)}}class lt{static setupStorage(t,e,i,s,n){const r=s.getValue(e,{value:null});switch(i.name){case"textarea":if(null!==r.value&&(t.textContent=r.value),"print"===n)break;t.addEventListener("input",t=>{s.setValue(e,{value:t.target.value})});break;case"input":if("radio"===i.attributes.type||"checkbox"===i.attributes.type){if(r.value===i.attributes.xfaOn?t.setAttribute("checked",!0):r.value===i.attributes.xfaOff&&t.removeAttribute("checked"),"print"===n)break;t.addEventListener("change",t=>{s.setValue(e,{value:t.target.checked?t.target.getAttribute("xfaOn"):t.target.getAttribute("xfaOff")})})}else{if(null!==r.value&&t.setAttribute("value",r.value),"print"===n)break;t.addEventListener("input",t=>{s.setValue(e,{value:t.target.value})})}break;case"select":if(null!==r.value){t.setAttribute("value",r.value);for(const t of i.children)t.attributes.value===r.value?t.attributes.selected=!0:t.attributes.hasOwnProperty("selected")&&delete t.attributes.selected}t.addEventListener("input",t=>{const i=t.target.options,n=-1===i.selectedIndex?"":i[i.selectedIndex].value;s.setValue(e,{value:n})});break}}static setAttributes({html:t,element:e,storage:i=null,intent:s,linkService:n}){const{attributes:r}=e,a=t instanceof HTMLAnchorElement;"radio"===r.type&&(r.name=`${r.name}-${s}`);for(const[o,l]of Object.entries(r))if(null!==l&&void 0!==l)switch(o){case"class":l.length&&t.setAttribute(o,l.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",l);break;case"style":Object.assign(t.style,l);break;case"textContent":t.textContent=l;break;default:(!a||"href"!==o&&"newWindow"!==o)&&t.setAttribute(o,l)}a&&n.addLinkAttributes(t,r.href,r.newWindow),i&&r.dataId&&this.setupStorage(t,r.dataId,e,i)}static render(t){const e=t.annotationStorage,i=t.linkService,s=t.xfaHtml,n=t.intent||"display",r=document.createElement(s.name);s.attributes&&this.setAttributes({html:r,element:s,intent:n,linkService:i});const a="richText"!==n,o=t.div;if(o.append(r),t.viewport){const e=`matrix(${t.viewport.transform.join(",")})`;o.style.transform=e}a&&o.setAttribute("class","xfaLayer xfaFont");const l=[];if(0===s.children.length){if(s.value){const t=document.createTextNode(s.value);r.append(t),a&&ot.shouldBuildText(s.name)&&l.push(t)}return{textDivs:l}}const h=[[s,-1,r]];while(h.length>0){const[t,s,r]=h.at(-1);if(s+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),r.append(t);continue}const d=o?.attributes?.xmlns?document.createElementNS(o.attributes.xmlns,c):document.createElement(c);if(r.append(d),o.attributes&&this.setAttributes({html:d,element:o,storage:e,intent:n,linkService:i}),o.children?.length>0)h.push([o,-1,d]);else if(o.value){const t=document.createTextNode(o.value);a&&ot.shouldBuildText(c)&&l.push(t),d.append(t)}}for(const c of o.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))c.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 ht="http://www.w3.org/2000/svg";class ct{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}async function dt(t,e="text"){if(yt(t,document.baseURI)){const i=await fetch(t);if(!i.ok)throw new Error(i.statusText);switch(e){case"arraybuffer":return i.arrayBuffer();case"blob":return i.blob();case"json":return i.json()}return i.text()}return new Promise((i,s)=>{const n=new XMLHttpRequest;n.open("GET",t,!0),n.responseType=e,n.onreadystatechange=()=>{if(n.readyState===XMLHttpRequest.DONE)if(200!==n.status&&0!==n.status)s(new Error(n.statusText));else{switch(e){case"arraybuffer":case"blob":case"json":return void i(n.response)}i(n.responseText)}},n.send(null)})}class ut{constructor({viewBox:t,userUnit:e,scale:i,rotation:s,offsetX:n=0,offsetY:r=0,dontFlip:a=!1}){this.viewBox=t,this.userUnit=e,this.scale=i,this.rotation=s,this.offsetX=n,this.offsetY=r,i*=e;const o=(t[2]+t[0])/2,l=(t[3]+t[1])/2;let h,c,d,u,p,g,m,f;switch(s%=360,s<0&&(s+=360),s){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.")}a&&(d=-d,u=-u),0===h?(p=Math.abs(l-t[1])*i+n,g=Math.abs(o-t[0])*i+r,m=(t[3]-t[1])*i,f=(t[2]-t[0])*i):(p=Math.abs(o-t[0])*i+n,g=Math.abs(l-t[1])*i+r,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 F(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:s=this.offsetY,dontFlip:n=!1}={}){return new ut({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:i,offsetY:s,dontFlip:n})}convertToViewportPoint(t,e){const i=[t,e];return K.applyTransform(i,this.transform),i}convertToViewportRectangle(t){const e=[t[0],t[1]];K.applyTransform(e,this.transform);const i=[t[2],t[3]];return K.applyTransform(i,this.transform),[e[0],e[1],i[0],i[1]]}convertToPdfPoint(t,e){const i=[t,e];return K.applyInverseTransform(i,this.transform),i}}class pt extends O{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function gt(t){const e=t.length;let i=0;while(i<e&&""===t[i].trim())i++;return"data:"===t.substring(i,i+5).toLowerCase()}function mt(t){return"string"===typeof t&&/\.pdf$/i.test(t)}function ft(t){return[t]=t.split(/[#?]/,1),t.substring(t.lastIndexOf("/")+1)}function bt(t,e="document.pdf"){if("string"!==typeof t)return e;if(gt(t))return D('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),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}}}}},s=i(t);if(!s)return e;const n=t=>{try{let e=decodeURIComponent(t);return e.includes("/")?(e=e.split("/").at(-1),e.test(/^\.pdf$/i)?e:t):e}catch{return t}},r=/\.pdf$/i,a=s.pathname.split("/").at(-1);if(r.test(a))return n(a);if(s.searchParams.size>0){const t=Array.from(s.searchParams.values()).reverse();for(const i of t)if(r.test(i))return n(i);const e=Array.from(s.searchParams.keys()).reverse();for(const i of e)if(r.test(i))return n(i)}if(s.hash){const t=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,e=t.exec(s.hash);if(e)return n(e[0])}return e}class vt{started=Object.create(null);times=[];time(t){t in this.started&&D(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||D(`Timer has not been started for ${t}`),this.times.push({name:t,start:this.started[t],end:Date.now()}),delete this.started[t]}toString(){const t=[];let e=0;for(const{name:i}of this.times)e=Math.max(i.length,e);for(const{name:i,start:s,end:n}of this.times)t.push(`${i.padEnd(e)} ${n-s}ms\n`);return t.join("")}}function yt(t,e){const i=e?URL.parse(t,e):URL.parse(t);return"http:"===i?.protocol||"https:"===i?.protocol}function wt(t){t.preventDefault()}function At(t){t.preventDefault(),t.stopPropagation()}function xt(t){console.log("Deprecated API usage: "+t)}class _t{static#i;static toDateObject(t){if(t instanceof Date)return t;if(!t||"string"!==typeof t)return null;this.#i||=new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?");const e=this.#i.exec(t);if(!e)return null;const i=parseInt(e[1],10);let s=parseInt(e[2],10);s=s>=1&&s<=12?s-1:0;let n=parseInt(e[3],10);n=n>=1&&n<=31?n:1;let r=parseInt(e[4],10);r=r>=0&&r<=23?r: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;return c=c>=0&&c<=59?c:0,"-"===l?(r+=h,a+=c):"+"===l&&(r-=h,a-=c),new Date(Date.UTC(i,s,n,r,a,o))}}function St(t,{scale:e=1,rotation:i=0}){const{width:s,height:n}=t.attributes.style,r=[0,0,parseInt(s),parseInt(n)];return new ut({viewBox:r,userUnit:1,scale:e,rotation:i})}function Et(t){if(t.startsWith("#")){const e=parseInt(t.slice(1),16);return[(16711680&e)>>16,(65280&e)>>8,255&e]}return t.startsWith("rgb(")?t.slice(4,-1).split(",").map(t=>parseInt(t)):t.startsWith("rgba(")?t.slice(5,-1).split(",").map(t=>parseInt(t)).slice(0,3):(D(`Not a valid color format: "${t}"`),[0,0,0])}function Ct(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 s=window.getComputedStyle(e).color;t.set(i,Et(s))}e.remove()}function Tt(t){const{a:e,b:i,c:s,d:n,e:r,f:a}=t.getTransform();return[e,i,s,n,r,a]}function Mt(t){const{a:e,b:i,c:s,d:n,e:r,f:a}=t.getTransform().invertSelf();return[e,i,s,n,r,a]}function Dt(t,e,i=!1,s=!0){if(e instanceof ut){const{pageWidth:s,pageHeight:n}=e.rawDims,{style:r}=t,a=X.isCSSRoundSupported,o=`var(--total-scale-factor) * ${s}px`,l=`var(--total-scale-factor) * ${n}px`,h=a?`round(down, ${o}, var(--scale-round-x))`:`calc(${o})`,c=a?`round(down, ${l}, var(--scale-round-y))`:`calc(${l})`;i&&e.rotation%180!==0?(r.width=c,r.height=h):(r.width=h,r.height=c)}s&&t.setAttribute("data-main-rotation",e.rotation)}class Pt{constructor(){const{pixelRatio:t}=Pt;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,s,n=-1){let r=1/0,a=1/0,o=1/0;i=Pt.capPixels(i,n),i>0&&(r=Math.sqrt(i/(t*e))),-1!==s&&(a=s/t,o=s/e);const l=Math.min(r,a,o);return(this.sx>l||this.sy>l)&&(this.sx=l,this.sy=l,!0)}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 It=["image/apng","image/avif","image/bmp","image/gif","image/jpeg","image/png","image/svg+xml","image/webp","image/x-icon"];class kt{static get isDarkMode(){return F(this,"isDarkMode",!!window?.matchMedia?.("(prefers-color-scheme: dark)").matches)}}class Rt{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);return t.remove(),F(this,"commentForegroundColor",Et(i))}}function Lt(t,e,i,s){s=Math.min(Math.max(s??1,0),1);const n=255*(1-s);return t=Math.round(t*s+n),e=Math.round(e*s+n),i=Math.round(i*s+n),[t,e,i]}function Ft(t,e){const i=t[0]/255,s=t[1]/255,n=t[2]/255,r=Math.max(i,s,n),a=Math.min(i,s,n),o=(r+a)/2;if(r===a)e[0]=e[1]=0;else{const t=r-a;switch(e[1]=o<.5?t/(r+a):t/(2-r-a),r){case i:e[0]=60*((s-n)/t+(s<n?6:0));break;case s:e[0]=60*((n-i)/t+2);break;case n:e[0]=60*((i-s)/t+4);break}}e[2]=o}function Ot(t,e){const i=t[0],s=t[1],n=t[2],r=(1-Math.abs(2*n-1))*s,a=r*(1-Math.abs(i/60%2-1)),o=n-r/2;switch(Math.floor(i/60)){case 0:e[0]=r+o,e[1]=a+o,e[2]=o;break;case 1:e[0]=a+o,e[1]=r+o,e[2]=o;break;case 2:e[0]=o,e[1]=r+o,e[2]=a+o;break;case 3:e[0]=o,e[1]=a+o,e[2]=r+o;break;case 4:e[0]=a+o,e[1]=o,e[2]=r+o;break;case 5:case 6:e[0]=r+o,e[1]=o,e[2]=a+o;break}}function Bt(t){return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Nt(t,e,i){Ot(t,i),i.map(Bt);const s=.2126*i[0]+.7152*i[1]+.0722*i[2];Ot(e,i),i.map(Bt);const n=.2126*i[0]+.7152*i[1]+.0722*i[2];return s>n?(s+.05)/(n+.05):(n+.05)/(s+.05)}const Ut=new Map;function jt(t,e){const i=t[0]+256*t[1]+65536*t[2]+16777216*e[0]+4294967296*e[1]+1099511627776*e[2];let s=Ut.get(i);if(s)return s;const n=new Float32Array(9),r=n.subarray(0,3),a=n.subarray(3,6);Ft(t,a);const o=n.subarray(6,9);Ft(e,o);const l=o[2]<.5,h=l?12:4.5;if(a[2]=l?Math.sqrt(a[2]):1-Math.sqrt(1-a[2]),Nt(a,o,r)<h){let t,e;l?(t=a[2],e=1):(t=0,e=a[2]);const i=.005;while(e-t>i){const i=a[2]=(t+e)/2;l===Nt(a,o,r)<h?t=i:e=i}a[2]=l?e:t}return Ot(a,r),s=K.makeHexColor(Math.round(255*r[0]),Math.round(255*r[1]),Math.round(255*r[2])),Ut.set(i,s),s}function Ht({html:t,dir:e,className:i},s){const n=document.createDocumentFragment();if("string"===typeof t){const i=document.createElement("p");i.dir=e||"auto";const s=t.split(/(?:\r\n?|\n)/);for(let t=0,e=s.length;t<e;++t){const n=s[t];i.append(document.createTextNode(n)),t<e-1&&i.append(document.createElement("br"))}n.append(i)}else lt.render({xfaHtml:t,div:n,intent:"richText"});n.firstElementChild.classList.add("richText",i),s.append(n)}function zt(t){const e=new Path2D;if(!t)return e;for(let i=0,s=t.length;i<s;)switch(t[i++]){case _.moveTo:e.moveTo(t[i++],t[i++]);break;case _.lineTo:e.lineTo(t[i++],t[i++]);break;case _.curveTo:e.bezierCurveTo(t[i++],t[i++],t[i++],t[i++],t[i++],t[i++]);break;case _.quadraticCurveTo:e.quadraticCurveTo(t[i++],t[i++],t[i++],t[i++]);break;case _.closePath:e.closePath();break;default:D(`Unrecognized drawing path operator: ${t[i-1]}`);break}return e}class $t{#s=null;#n=null;#r;#a=null;#o=null;#l=null;#h=null;#c=null;static#d=null;constructor(t){this.#r=t,$t.#d||=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.#s=document.createElement("div");t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=this.#r._uiManager._signal;e instanceof AbortSignal&&!e.aborted&&(t.addEventListener("contextmenu",wt,{signal:e}),t.addEventListener("pointerdown",$t.#u,{signal:e}));const i=this.#a=document.createElement("div");i.className="buttons",t.append(i);const s=this.#r.toolbarPosition;if(s){const{style:e}=t,i="ltr"===this.#r._uiManager.direction?1-s[0]:s[0];e.insetInlineEnd=100*i+"%",e.top=`calc(${100*s[1]}% + var(--editor-toolbar-vert-offset))`}return t}get div(){return this.#s}static#u(t){t.stopPropagation()}#p(t){this.#r._focusEventsAllowed=!1,At(t)}#g(t){this.#r._focusEventsAllowed=!0,At(t)}#m(t){const e=this.#r._uiManager._signal;return e instanceof AbortSignal&&!e.aborted&&(t.addEventListener("focusin",this.#p.bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",this.#g.bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",wt,{signal:e}),!0)}hide(){this.#s.classList.add("hidden"),this.#n?.hideDropdown()}show(){this.#s.classList.remove("hidden"),this.#o?.shown(),this.#l?.shown()}addDeleteButton(){const{editorType:t,_uiManager:e}=this.#r,i=document.createElement("button");i.classList.add("basic","deleteButton"),i.tabIndex=0,i.setAttribute("data-l10n-id",$t.#d[t]),this.#m(i)&&i.addEventListener("click",t=>{e.delete()},{signal:e._signal}),this.#a.append(i)}get#f(){const t=document.createElement("div");return t.className="divider",t}async addAltText(t){const e=await t.render();this.#m(e),this.#a.append(e,this.#f),this.#o=t}addComment(t,e=null){if(this.#l)return;const i=t.renderForToolbar();if(!i)return;this.#m(i);const s=this.#h=this.#f;e?(this.#a.insertBefore(i,e),this.#a.insertBefore(s,e)):this.#a.append(i,s),this.#l=t,t.toolbar=this}addColorPicker(t){if(this.#n)return;this.#n=t;const e=t.renderButton();this.#m(e),this.#a.append(e,this.#f)}async addEditSignatureButton(t){const e=this.#c=await t.renderEditButton(this.#r);this.#m(e),this.#a.append(e,this.#f)}removeButton(t){switch(t){case"comment":this.#l?.removeToolbarCommentButton(),this.#l=null,this.#h?.remove(),this.#h=null;break}}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);break}}async addButtonBefore(t,e,i){if(!e&&"comment"===t)return;const s=this.#a.querySelector(i);s&&"comment"===t&&this.addComment(e,s)}updateEditSignatureButton(t){this.#c&&(this.#c.title=t)}remove(){this.#s.remove(),this.#n?.destroy(),this.#n=null}}class Gt{#a=null;#s=null;#b;constructor(t){this.#b=t}#v(){const t=this.#s=document.createElement("div");t.className="editToolbar",t.setAttribute("role","toolbar");const e=this.#b._signal;e instanceof AbortSignal&&!e.aborted&&t.addEventListener("contextmenu",wt,{signal:e});const i=this.#a=document.createElement("div");return i.className="buttons",t.append(i),this.#b.hasCommentManager()&&this.#y("commentButton","pdfjs-comment-floating-button","pdfjs-comment-floating-button-label",()=>{this.#b.commentSelection("floating_button")}),this.#y("highlightButton","pdfjs-highlight-floating-button1","pdfjs-highlight-floating-button-label",()=>{this.#b.highlightSelection("floating_button")}),t}#w(t,e){let i=0,s=0;for(const n of t){const t=n.y+n.height;if(t<i)continue;const r=n.x+(e?n.width:0);t>i?(s=r,i=t):e?r>s&&(s=r):r<s&&(s=r)}return[e?1-s:s,i]}show(t,e,i){const[s,n]=this.#w(e,i),{style:r}=this.#s||=this.#v();t.append(this.#s),r.insetInlineEnd=100*s+"%",r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){this.#s.remove()}#y(t,e,i,s){const n=document.createElement("button");n.classList.add("basic",t),n.tabIndex=0,n.setAttribute("data-l10n-id",e);const r=document.createElement("span");n.append(r),r.className="visuallyHidden",r.setAttribute("data-l10n-id",i);const a=this.#b._signal;a instanceof AbortSignal&&!a.aborted&&(n.addEventListener("contextmenu",wt,{signal:a}),n.addEventListener("click",s,{signal:a})),this.#a.append(n)}}function Wt(t,e,i){for(const s of i)e.addEventListener(s,t[s].bind(t))}class Vt{static#A=NaN;static#x=null;static#_=NaN;static#S=null;static initializeAndAddPointerId(t){(Vt.#x||=new Set).add(t)}static setPointer(t,e){Vt.#A||=e,Vt.#S??=t}static setTimeStamp(t){Vt.#_=t}static isSamePointerId(t){return Vt.#A===t}static isSamePointerIdOrRemove(t){return Vt.#A===t||(Vt.#x?.delete(t),!1)}static isSamePointerType(t){return Vt.#S===t}static isInitializedAndDifferentPointerType(t){return null!==Vt.#S&&!Vt.isSamePointerType(t)}static isSameTimeStamp(t){return Vt.#_===t}static isUsingMultiplePointers(){return Vt.#x?.size>=1}static clearPointerType(){Vt.#S=null}static clearPointerIds(){Vt.#A=NaN,Vt.#x=null}static clearTimeStamp(){Vt.#_=NaN}}class qt{#E=0;get id(){return`${u}${this.#E++}`}}class Xt{#C=et();#E=0;#T=null;static get _isSVGFittingCanvas(){const t='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>',e=new OffscreenCanvas(1,3),i=e.getContext("2d",{willReadFrequently:!0}),s=new Image;s.src=t;const n=s.decode().then(()=>(i.drawImage(s,0,0,1,1,0,0,1,3),0===new Uint32Array(i.getImageData(0,0,1,1).data.buffer)[0]));return F(this,"_isSVGFittingCanvas",n)}async#M(t,e){this.#T||=new Map;let i=this.#T.get(t);if(null===i)return null;if(i?.bitmap)return i.refCounter+=1,i;try{let t;if(i||={bitmap:null,id:`image_${this.#C}_${this.#E++}`,refCounter:0,isSvg:!1},"string"===typeof e?(i.url=e,t=await dt(e,"blob")):e instanceof File?t=i.file=e:e instanceof Blob&&(t=e),"image/svg+xml"===t.type){const e=Xt._isSVGFittingCanvas,s=new FileReader,n=new Image,r=new Promise((t,r)=>{n.onload=()=>{i.bitmap=n,i.isSvg=!0,t()},s.onload=async()=>{const t=i.svgUrl=s.result;n.src=await e?`${t}#svgView(preserveAspectRatio(none))`:t},n.onerror=s.onerror=r});s.readAsDataURL(t),await r}else i.bitmap=await createImageBitmap(t);i.refCounter=1}catch(s){D(s),i=null}return this.#T.set(t,i),i&&this.#T.set(i.id,i),i}async getFromFile(t){const{lastModified:e,name:i,size:s,type:n}=t;return this.#M(`${e}_${i}_${s}_${n}`,t)}async getFromUrl(t){return this.#M(t,t)}async getFromBlob(t,e){const i=await e;return this.#M(t,i)}async getFromId(t){this.#T||=new Map;const e=this.#T.get(t);if(!e)return null;if(e.bitmap)return e.refCounter+=1,e;if(e.file)return this.getFromFile(e.file);if(e.blobPromise){const{blobPromise:t}=e;return delete e.blobPromise,this.getFromBlob(e.id,t)}return this.getFromUrl(e.url)}getFromCanvas(t,e){this.#T||=new Map;let i=this.#T.get(t);if(i?.bitmap)return i.refCounter+=1,i;const s=new OffscreenCanvas(e.width,e.height),n=s.getContext("2d");return n.drawImage(e,0,0),i={bitmap:s.transferToImageBitmap(),id:`image_${this.#C}_${this.#E++}`,refCounter:1,isSvg:!1},this.#T.set(t,i),this.#T.set(i.id,i),i}getSvgUrl(t){const e=this.#T.get(t);return e?.isSvg?e.svgUrl:null}deleteId(t){this.#T||=new Map;const e=this.#T.get(t);if(!e)return;if(e.refCounter-=1,0!==e.refCounter)return;const{bitmap:i}=e;if(!e.url&&!e.file){const t=new OffscreenCanvas(i.width,i.height),s=t.getContext("bitmaprenderer");s.transferFromImageBitmap(i),e.blobPromise=t.convertToBlob()}i.close?.(),e.bitmap=null}isValidId(t){return t.startsWith(`image_${this.#C}_`)}}class Yt{#D=[];#P=!1;#I;#k=-1;constructor(t=128){this.#I=t}add({cmd:t,undo:e,post:i,mustExec:s,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:a=!1}){if(s&&t(),this.#P)return;const o={cmd:t,undo:e,post:i,type:n};if(-1===this.#k)return this.#D.length>0&&(this.#D.length=0),this.#k=0,void this.#D.push(o);if(r&&this.#D[this.#k].type===n)return a&&(o.undo=this.#D[this.#k].undo),void(this.#D[this.#k]=o);const l=this.#k+1;l===this.#I?this.#D.splice(0,1):(this.#k=l,l<this.#D.length&&this.#D.splice(l)),this.#D.push(o)}undo(){if(-1===this.#k)return;this.#P=!0;const{undo:t,post:e}=this.#D[this.#k];t(),e?.(),this.#P=!1,this.#k-=1}redo(){if(this.#k<this.#D.length-1){this.#k+=1,this.#P=!0;const{cmd:t,post:e}=this.#D[this.#k];t(),e?.(),this.#P=!1}}hasSomethingToUndo(){return-1!==this.#k}hasSomethingToRedo(){return this.#k<this.#D.length-1}cleanType(t){if(-1!==this.#k){for(let e=this.#k;e>=0;e--)if(this.#D[e].type!==t)return this.#D.splice(e+1,this.#k-e),void(this.#k=e);this.#D.length=0,this.#k=-1}}destroy(){this.#D=null}}class Kt{constructor(t){this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=X.platform;for(const[i,s,n={}]of t)for(const t of i){const i=t.startsWith("mac+");e&&i?(this.callbacks.set(t.slice(4),{callback:s,options:n}),this.allKeys.add(t.split("+").at(-1))):e||i||(this.callbacks.set(t,{callback:s,options:n}),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("+");return this.buffer.length=0,e}exec(t,e){if(!this.allKeys.has(e.key))return;const i=this.callbacks.get(this.#R(e));if(!i)return;const{callback:s,options:{bubbles:n=!1,args:r=[],checker:a=null}}=i;a&&!a(t,e)||(s.bind(t,...r,e)(),n||At(e))}}class Qt{static _colorsMapping=new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]);get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return Ct(t),F(this,"_colors",t)}convert(t){const e=Et(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(const[i,s]of this._colors)if(s.every((t,i)=>t===e[i]))return Qt._colorsMapping.get(i);return e}getHexCode(t){const e=this._colors.get(t);return e?K.makeHexColor(...e):t}}class Jt{#L=new AbortController;#F=null;#O=null;#B=new Map;#N=new Map;#U=null;#j=null;#H=null;#z=new Yt;#$=null;#G=null;#W=null;#V=0;#q=new Set;#X=null;#Y=null;#K=new Set;_editorUndoBar=null;#Q=!1;#J=!1;#Z=!1;#tt=null;#et=null;#it=null;#st=null;#nt=!1;#rt=null;#at=new qt;#ot=!1;#lt=!1;#ht=!1;#ct=null;#dt=null;#ut=null;#pt=null;#gt=null;#mt=p.NONE;#ft=new Set;#bt=null;#vt=null;#yt=null;#wt=null;#At=null;#xt={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#_t=[0,0];#St=null;#Et=null;#Ct=null;#Tt=null;#Mt=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){const t=Jt.prototype,e=t=>t.#Et.contains(document.activeElement)&&"BUTTON"!==document.activeElement.tagName&&t.hasSomethingToControl(),i=(t,{target:e})=>{if(e instanceof HTMLInputElement){const{type:t}=e;return"text"!==t&&"number"!==t}return!0},s=this.TRANSLATE_SMALL,n=this.TRANSLATE_BIG;return F(this,"_keyboardManager",new Kt([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:i}],[["ctrl+z","mac+meta+z"],t.undo,{checker:i}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.redo,{checker:i}],[["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:i}],[["Enter","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#Et.contains(e)&&!t.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#Et.contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-s,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-n,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[s,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[n,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-s],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-n],checker:e}],[["ArrowDown","mac+ArrowDown"],t.translateSelectedEditors,{args:[0,s],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,n],checker:e}]]))}constructor(t,e,i,s,n,r,a,o,l,h,c,d,u,p,g,m){const f=this._signal=this.#L.signal;this.#Et=t,this.#Ct=e,this.#Tt=i,this.#U=s,this.#$=n,this.#vt=r,this.#At=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.#lt=!0},{capture:!0,signal:f}),window.addEventListener("pointerup",()=>{this.#lt=!1},{capture:!0,signal:f}),this.#Dt(),this.#Pt(),this.#It(),this.#j=o.annotationStorage,this.#tt=o.filterFactory,this.#yt=l,this.#st=h||null,this.#Q=c,this.#J=d,this.#Z=u,this.#gt=p||null,this.viewParameters={realScale:ct.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=g||null,this._supportsPinchToZoom=!1!==m,n?.setSidebarUiManager(this)}destroy(){this.#Mt?.resolve(),this.#Mt=null,this.#L?.abort(),this.#L=null,this._signal=null;for(const t of this.#N.values())t.destroy();this.#N.clear(),this.#B.clear(),this.#K.clear(),this.#pt?.clear(),this.#F=null,this.#ft.clear(),this.#z.destroy(),this.#U?.destroy(),this.#$?.destroy(),this.#vt?.destroy(),this.#rt?.hide(),this.#rt=null,this.#ut?.destroy(),this.#ut=null,this.#O=null,this.#et&&(clearTimeout(this.#et),this.#et=null),this.#St&&(clearTimeout(this.#St),this.#St=null),this._editorUndoBar?.destroy(),this.#At=null}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return this.#gt}get useNewAltTextFlow(){return this.#J}get useNewAltTextWhenAddingImage(){return this.#Z}get hcmFilter(){return F(this,"hcmFilter",this.#yt?this.#tt.addHCMFilter(this.#yt.foreground,this.#yt.background):"none")}get direction(){return F(this,"direction",getComputedStyle(this.#Et).direction)}get _highlightColors(){return F(this,"_highlightColors",this.#st?new Map(this.#st.split(",").map(t=>(t=t.split("=").map(t=>t.trim()),t[1]=t[1].toUpperCase(),t))):null)}get highlightColors(){const{_highlightColors:t}=this;if(!t)return F(this,"highlightColors",null);const e=new Map,i=!!this.#yt;for(const[s,n]of t){const t=s.endsWith("_HCM");i&&t?e.set(s.replace("_HCM",""),n):i||t||e.set(s,n)}return F(this,"highlightColors",e)}get highlightColorNames(){return F(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){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),this.#W=t}setMainHighlightColorPicker(t){this.#ut=t}editAltText(t,e=!1){this.#U?.editAltText(this,t,e)}hasCommentManager(){return!!this.#$}editComment(t,e,i,s){this.#$?.showDialog(this,t,e,i,s)}selectComment(t,e){const i=this.#N.get(t),s=i?.getEditorByUID(e);s?.toggleComment(!0,!0)}updateComment(t){this.#$?.updateComment(t.getData())}updatePopupColor(t){this.#$?.updatePopupColor(t)}removeComment(t){this.#$?.removeComments([t.uid])}toggleComment(t,e,i=void 0){this.#$?.toggleCommentPopup(t,e,i)}makeCommentColor(t,e){return t&&this.#$?.makeCommentColor(t,e)||null}getCommentDialogElement(){return this.#$?.dialogElement||null}async waitForEditorsRendered(t){if(this.#N.has(t-1))return;const{resolve:e,promise:i}=Promise.withResolvers(),s=i=>{i.pageNumber===t&&(this._eventBus._off("editorsrendered",s),e())};this._eventBus.on("editorsrendered",s),await i}getSignature(t){this.#vt?.getSignature({uiManager:this,editor:t})}get signatureManager(){return this.#vt}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}){switch(t){case"enableNewAltTextWhenAddingImage":this.#Z=e;break}}onPageChanging({pageNumber:t}){this.#V=t-1}focusMainContainer(){this.#Et.focus()}findParent(t,e){for(const i of this.#N.values()){const{x:s,y:n,width:r,height:a}=i.div.getBoundingClientRect();if(t>=s&&t<=s+r&&e>=n&&e<=n+a)return i}return null}disableUserSelect(t=!1){this.#Ct.classList.toggle("noUserSelect",t)}addShouldRescale(t){this.#K.add(t)}removeShouldRescale(t){this.#K.delete(t)}onScaleChanging({scale:t}){this.commitOrRemove(),this.viewParameters.realScale=t*ct.PDF_TO_CSS_UNITS;for(const e of this.#K)e.onScaleChanging();this.#W?.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}#kt({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t}#Rt(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const i of this.#N.values())if(i.hasTextLayer(t))return i;return null}highlightSelection(t="",e=!1){const i=document.getSelection();if(!i||i.isCollapsed)return;const{anchorNode:s,anchorOffset:n,focusNode:r,focusOffset:a}=i,o=i.toString(),l=this.#kt(i),h=l.closest(".textLayer"),c=this.getSelectionBoxes(h);if(!c)return;i.empty();const d=this.#Rt(h),u=this.#mt===p.NONE,g=()=>{const i=d?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:c,anchorNode:s,anchorOffset:n,focusNode:r,focusOffset:a,text:o});u&&this.showAllEditors("highlight",!0,!0),e&&i?.editComment()};u?this.switchToMode(p.HIGHLIGHT,g):g()}commentSelection(t=""){this.highlightSelection(t,!0)}#Lt(){const t=document.getSelection();if(!t||t.isCollapsed)return;const e=this.#kt(t),i=e.closest(".textLayer"),s=this.getSelectionBoxes(i);s&&(this.#rt||=new Gt(this),this.#rt.show(i,s,"ltr"===this.direction))}getAndRemoveDataFromAnnotationStorage(t){if(!this.#j)return null;const e=`${u}${t}`,i=this.#j.getRawValue(e);return i&&this.#j.remove(e),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.#Tt;i&&(i.setAttribute("data-l10n-id",t),e?i.setAttribute("data-l10n-args",JSON.stringify(e)):i.removeAttribute("data-l10n-args"))}#Ft(){const t=document.getSelection();if(!t||t.isCollapsed)return void(this.#bt&&(this.#rt?.hide(),this.#bt=null,this.#Ot({hasSelectedText:!1})));const{anchorNode:e}=t;if(e===this.#bt)return;const i=this.#kt(t),s=i.closest(".textLayer");if(s){if(this.#rt?.hide(),this.#bt=e,this.#Ot({hasSelectedText:!0}),(this.#mt===p.HIGHLIGHT||this.#mt===p.NONE)&&(this.#mt===p.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),this.#nt=this.isShiftKeyDown,!this.isShiftKeyDown)){const t=this.#mt===p.HIGHLIGHT?this.#Rt(s):null;if(t?.toggleDrawing(),this.#lt){const e=new AbortController,i=this.combinedSignal(e),s=i=>{"pointerup"===i.type&&0!==i.button||(e.abort(),t?.toggleDrawing(!0),"pointerup"===i.type&&this.#Bt("main_toolbar"))};window.addEventListener("pointerup",s,{signal:i}),window.addEventListener("blur",s,{signal:i})}else t?.toggleDrawing(!0),this.#Bt("main_toolbar")}}else this.#bt&&(this.#rt?.hide(),this.#bt=null,this.#Ot({hasSelectedText:!1}))}#Bt(t=""){this.#mt===p.HIGHLIGHT?this.highlightSelection(t):this.#Q&&this.#Lt()}#Dt(){document.addEventListener("selectionchange",this.#Ft.bind(this),{signal:this._signal})}#Nt(){if(this.#it)return;this.#it=new AbortController;const t=this.combinedSignal(this.#it);window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})}#Ut(){this.#it?.abort(),this.#it=null}blur(){if(this.isShiftKeyDown=!1,this.#nt&&(this.#nt=!1,this.#Bt("main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of this.#ft)if(e.div.contains(t)){this.#dt=[e,t],e._focusEventsAllowed=!1;break}}focus(){if(!this.#dt)return;const[t,e]=this.#dt;this.#dt=null,e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}#It(){if(this.#ct)return;this.#ct=new AbortController;const t=this.combinedSignal(this.#ct);window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})}#jt(){this.#ct?.abort(),this.#ct=null}#Ht(){if(this.#G)return;this.#G=new AbortController;const t=this.combinedSignal(this.#G);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})}#zt(){this.#G?.abort(),this.#G=null}#Pt(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})}addEditListeners(){this.#It(),this.setEditingState(!0)}removeEditListeners(){this.#jt(),this.setEditingState(!1)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const i of this.#Y)if(i.isHandlingMimeForPasting(e))return t.dataTransfer.dropEffect="copy",void t.preventDefault()}drop(t){for(const e of t.dataTransfer.items)for(const i of this.#Y)if(i.isHandlingMimeForPasting(e.type))return i.paste(e,this.currentLayer),void t.preventDefault()}copy(t){if(t.preventDefault(),this.#F?.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of this.#ft){const t=i.serialize(!0);t&&e.push(t)}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 r of e.items)for(const t of this.#Y)if(t.isHandlingMimeForPasting(r.type))return void t.paste(r,this.currentLayer);let i=e.getData("application/pdfjs");if(!i)return;try{i=JSON.parse(i)}catch(n){return void D(`paste: "${n.message}".`)}if(!Array.isArray(i))return;this.unselectAll();const s=this.currentLayer;try{const t=[];for(const r of i){const e=await s.deserialize(r);if(!e)return;t.push(e)}const e=()=>{for(const e of t)this.#$t(e);this.#Gt(t)},n=()=>{for(const e of t)e.remove()};this.addCommands({cmd:e,undo:n,mustExec:!0})}catch(n){D(`paste: "${n.message}".`)}}keydown(t){this.isShiftKeyDown||"Shift"!==t.key||(this.isShiftKeyDown=!0),this.#mt===p.NONE||this.isEditorHandlingKeyboard||Jt._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&"Shift"===t.key&&(this.isShiftKeyDown=!1,this.#nt&&(this.#nt=!1,this.#Bt("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");break}}#Ot(t){const e=Object.entries(t).some(([t,e])=>this.#xt[t]!==e);e&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(this.#xt,t)}),this.#mt===p.HIGHLIGHT&&!1===t.hasSelectedEditor&&this.#Wt([[g.HIGHLIGHT_FREE,!0]]))}#Wt(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})}setEditingState(t){t?(this.#Nt(),this.#Ht(),this.#Ot({isEditing:this.#mt!==p.NONE,isEmpty:this.#Vt(),hasSomethingToUndo:this.#z.hasSomethingToUndo(),hasSomethingToRedo:this.#z.hasSomethingToRedo(),hasSelectedEditor:!1})):(this.#Ut(),this.#zt(),this.#Ot({isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!this.#Y){this.#Y=t;for(const t of this.#Y)this.#Wt(t.defaultPropertiesToUpdate)}}getId(){return this.#at.id}get currentLayer(){return this.#N.get(this.#V)}getLayer(t){return this.#N.get(t)}get currentPageIndex(){return this.#V}addLayer(t){this.#N.set(t.pageIndex,t),this.#ot?t.enable():t.disable()}removeLayer(t){this.#N.delete(t.pageIndex)}async updateMode(t,e=null,i=!1,s=!1,n=!1,r=!1){if(this.#mt!==t&&(!this.#Mt||(await this.#Mt.promise,this.#Mt))){if(this.#Mt=Promise.withResolvers(),this.#W?.commitOrRemove(),this.#mt===p.POPUP&&this.#$?.hideSidebar(),this.#$?.destroyPopup(),this.#mt=t,t===p.NONE){this.setEditingState(!1),this.#qt();for(const t of this.#B.values())t.hideStandaloneCommentButton();return this._editorUndoBar?.hide(),this.toggleComment(null),void this.#Mt.resolve()}for(const t of this.#B.values())t.addStandaloneCommentButton();t===p.SIGNATURE&&await(this.#vt?.loadSignatures()),i&&Vt.clearPointerType(),this.setEditingState(!0),await this.#Xt(),this.unselectAll();for(const e of this.#N.values())e.updateMode(t);if(t===p.POPUP){this.#O||=await this.#At.getAnnotationsByType(new Set(this.#Y.map(t=>t._editorType)));const t=new Set,e=[];for(const i of this.#B.values()){const{annotationElementId:s,hasComment:n,deleted:r}=i;s&&t.add(s),n&&!r&&e.push(i.getData())}for(const i of this.#O){const{id:s,popupRef:n,contentsObj:r}=i;n&&r?.str&&!t.has(s)&&!this.#q.has(s)&&e.push(i)}this.#$?.showSidebar(e)}if(!e)return s&&this.addNewEditorFromKeyboard(),void this.#Mt.resolve();for(const t of this.#B.values())t.uid===e?(this.setSelected(t),r?t.editComment():n?t.enterInEditMode():t.focus()):t.unselect();this.#Mt.resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t.mode!==this.#mt&&this._eventBus.dispatch("switchannotationeditormode",{source:this,...t})}updateParams(t,e){if(this.#Y){switch(t){case g.CREATE:return void this.currentLayer.addNewEditor(e);case g.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(this.#wt||=new Map).set(t,e),this.showAllEditors("highlight",e);break}if(this.hasSelection)for(const i of this.#ft)i.updateParams(t,e);else for(const i of this.#Y)i.updateDefaultParams(t,e)}}showAllEditors(t,e,i=!1){for(const n of this.#B.values())n.editorType===t&&n.show(e);const s=this.#wt?.get(g.HIGHLIGHT_SHOW_ALL)??!0;s!==e&&this.#Wt([[g.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(this.#ht!==t){this.#ht=t;for(const e of this.#N.values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}async#Xt(){if(!this.#ot){this.#ot=!0;const t=[];for(const e of this.#N.values())t.push(e.enable());await Promise.all(t);for(const e of this.#B.values())e.enable()}}#qt(){if(this.unselectAll(),this.#ot){this.#ot=!1;for(const t of this.#N.values())t.disable();for(const t of this.#B.values())t.disable()}}*getEditors(t){for(const e of this.#B.values())e.pageIndex===t&&(yield e)}getEditor(t){return this.#B.get(t)}addEditor(t){this.#B.set(t.id,t)}removeEditor(t){t.div.contains(document.activeElement)&&(this.#et&&clearTimeout(this.#et),this.#et=setTimeout(()=>{this.focusMainContainer(),this.#et=null},0)),this.#B.delete(t.id),t.annotationElementId&&this.#pt?.delete(t.annotationElementId),this.unselect(t),t.annotationElementId&&this.#q.has(t.annotationElementId)||this.#j?.remove(t.id)}addDeletedAnnotationElement(t){this.#q.add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return this.#q.has(t)}removeDeletedAnnotationElement(t){this.#q.delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}#$t(t){const e=this.#N.get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))}setActiveEditor(t){this.#F!==t&&(this.#F=t,t&&this.#Wt(t.propertiesToUpdate))}get#Yt(){let t=null;for(t of this.#ft);return t}updateUI(t){this.#Yt===t&&this.#Wt(t.propertiesToUpdate)}updateUIForDefaultProperties(t){this.#Wt(t.defaultPropertiesToUpdate)}toggleSelected(t){if(this.#ft.has(t))return this.#ft.delete(t),t.unselect(),void this.#Ot({hasSelectedEditor:this.hasSelection});this.#ft.add(t),t.select(),this.#Wt(t.propertiesToUpdate),this.#Ot({hasSelectedEditor:!0})}setSelected(t){this.updateToolbar({mode:t.mode,editId:t.uid}),this.#W?.commitOrRemove();for(const e of this.#ft)e!==t&&e.unselect();this.#ft.clear(),this.#ft.add(t),t.select(),this.#Wt(t.propertiesToUpdate),this.#Ot({hasSelectedEditor:!0})}isSelected(t){return this.#ft.has(t)}get firstSelectedEditor(){return this.#ft.values().next().value}unselect(t){t.unselect(),this.#ft.delete(t),this.#Ot({hasSelectedEditor:this.hasSelection})}get hasSelection(){return 0!==this.#ft.size}get isEnterHandled(){return 1===this.#ft.size&&this.firstSelectedEditor.isEnterHandled}undo(){this.#z.undo(),this.#Ot({hasSomethingToUndo:this.#z.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#Vt()}),this._editorUndoBar?.hide()}redo(){this.#z.redo(),this.#Ot({hasSomethingToUndo:!0,hasSomethingToRedo:this.#z.hasSomethingToRedo(),isEmpty:this.#Vt()})}addCommands(t){this.#z.add(t),this.#Ot({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#Vt()})}cleanUndoStack(t){this.#z.cleanType(t)}#Vt(){if(0===this.#B.size)return!0;if(1===this.#B.size)for(const t of this.#B.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.#ft],i=()=>{this._editorUndoBar?.show(s,1===e.length?e[0].editorType:e.length);for(const t of e)t.remove()},s=()=>{for(const t of e)this.#$t(t)};this.addCommands({cmd:i,undo:s,mustExec:!0})}commitOrRemove(){this.#F?.commitOrRemove()}hasSomethingToControl(){return this.#F||this.hasSelection}#Gt(t){for(const e of this.#ft)e.unselect();this.#ft.clear();for(const e of t)e.isEmpty()||(this.#ft.add(e),e.select());this.#Ot({hasSelectedEditor:this.hasSelection})}selectAll(){for(const t of this.#ft)t.commit();this.#Gt(this.#B.values())}unselectAll(){if((!this.#F||(this.#F.commitOrRemove(),this.#mt===p.NONE))&&!this.#W?.commitOrRemove()&&this.hasSelection){for(const t of this.#ft)t.unselect();this.#ft.clear(),this.#Ot({hasSelectedEditor:!1})}}translateSelectedEditors(t,e,i=!1){if(i||this.commitOrRemove(),!this.hasSelection)return;this.#_t[0]+=t,this.#_t[1]+=e;const[s,n]=this.#_t,r=[...this.#ft],a=1e3;this.#St&&clearTimeout(this.#St),this.#St=setTimeout(()=>{this.#St=null,this.#_t[0]=this.#_t[1]=0,this.addCommands({cmd:()=>{for(const t of r)this.#B.has(t.id)&&(t.translateInPage(s,n),t.translationDone())},undo:()=>{for(const t of r)this.#B.has(t.id)&&(t.translateInPage(-s,-n),t.translationDone())},mustExec:!1})},a);for(const o of r)o.translateInPage(t,e),o.translationDone()}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),this.#X=new Map;for(const t of this.#ft)this.#X.set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#X)return!1;this.disableUserSelect(!1);const t=this.#X;this.#X=null;let e=!1;for(const[{x:s,y:n,pageIndex:r},a]of t)a.newX=s,a.newY=n,a.newPageIndex=r,e||=s!==a.savedX||n!==a.savedY||r!==a.savedPageIndex;if(!e)return!1;const i=(t,e,i,s)=>{if(this.#B.has(t.id)){const n=this.#N.get(s);n?t._setParentAndPosition(n,e,i):(t.pageIndex=s,t.x=e,t.y=i)}};return this.addCommands({cmd:()=>{for(const[e,{newX:s,newY:n,newPageIndex:r}]of t)i(e,s,n,r)},undo:()=>{for(const[e,{savedX:s,savedY:n,savedPageIndex:r}]of t)i(e,s,n,r)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(this.#X)for(const i of this.#X.keys())i.drag(t,e)}rebuild(t){if(null===t.parent){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){return this.getActive()?.shouldGetKeyboardEvents()||1===this.#ft.size&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return this.#F===t}getActive(){return this.#F}getMode(){return this.#mt}isEditingMode(){return this.#mt!==p.NONE}get imageManager(){return F(this,"imageManager",new Xt)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let l=0,h=e.rangeCount;l<h;l++)if(!t.contains(e.getRangeAt(l).commonAncestorContainer))return null;const{x:i,y:s,width:n,height:r}=t.getBoundingClientRect();let a;switch(t.getAttribute("data-main-rotation")){case"90":a=(t,e,a,o)=>({x:(e-s)/r,y:1-(t+a-i)/n,width:o/r,height:a/n});break;case"180":a=(t,e,a,o)=>({x:1-(t+a-i)/n,y:1-(e+o-s)/r,width:a/n,height:o/r});break;case"270":a=(t,e,a,o)=>({x:1-(e+o-s)/r,y:(t-i)/n,width:o/r,height:a/n});break;default:a=(t,e,a,o)=>({x:(t-i)/n,y:(e-s)/r,width:a/n,height:o/r});break}const o=[];for(let l=0,h=e.rangeCount;l<h;l++){const t=e.getRangeAt(l);if(!t.collapsed)for(const{x:e,y:i,width:s,height:n}of t.getClientRects())0!==s&&0!==n&&o.push(a(e,i,s,n))}return 0===o.length?null:o}addChangedExistingAnnotation({annotationElementId:t,id:e}){(this.#H||=new Map).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){this.#H?.delete(t)}renderAnnotationElement(t){const e=this.#H?.get(t.data.id);if(!e)return;const i=this.#j.getRawValue(e);i&&(this.#mt!==p.NONE||i.hasBeenModified)&&i.renderAnnotationElement(t)}setMissingCanvas(t,e,i){const s=this.#pt?.get(t);s&&(s.setCanvas(e,i),this.#pt.delete(t))}addMissingCanvas(t,e){(this.#pt||=new Map).set(t,e)}}class Zt{#o=null;#Kt=!1;#Qt=null;#Jt=null;#Zt=null;#te=null;#ee=!1;#ie=null;#r=null;#se=null;#ne=null;#re=!1;static#ae=null;static _l10n=null;constructor(t){this.#r=t,this.#re=t._uiManager.useNewAltTextFlow,Zt.#ae||=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){Zt._l10n??=t}async render(){const t=this.#Qt=document.createElement("button");t.className="altText",t.tabIndex="0";const e=this.#Jt=document.createElement("span");t.append(e),this.#re?(t.classList.add("new"),t.setAttribute("data-l10n-id",Zt.#ae.missing),e.setAttribute("data-l10n-id",Zt.#ae["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const i=this.#r._uiManager._signal;t.addEventListener("contextmenu",wt,{signal:i}),t.addEventListener("pointerdown",t=>t.stopPropagation(),{signal:i});const s=t=>{t.preventDefault(),this.#r._uiManager.editAltText(this.#r),this.#re&&this.#r._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:this.#oe}})};return t.addEventListener("click",s,{capture:!0,signal:i}),t.addEventListener("keydown",e=>{e.target===t&&"Enter"===e.key&&(this.#ee=!0,s(e))},{signal:i}),await this.#le(),t}get#oe(){return(this.#o?"added":null===this.#o&&this.guessedText&&"review")||"missing"}finish(){this.#Qt&&(this.#Qt.focus({focusVisible:this.#ee}),this.#ee=!1)}isEmpty(){return this.#re?null===this.#o:!this.#o&&!this.#Kt}hasData(){return this.#re?null!==this.#o||!!this.#se:this.isEmpty()}get guessedText(){return this.#se}async setGuessedText(t){null===this.#o&&(this.#se=t,this.#ne=await Zt._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t}),this.#le())}toggleAltTextBadge(t=!1){if(!this.#re||this.#o)return this.#ie?.remove(),void(this.#ie=null);if(!this.#ie){const t=this.#ie=document.createElement("div");t.className="noAltTextBadge",this.#r.div.append(t)}this.#ie.classList.toggle("hidden",!t)}serialize(t){let e=this.#o;return t||this.#se!==e||(e=this.#ne),{altText:e,decorative:this.#Kt,guessedText:this.#se,textWithDisclaimer:this.#ne}}get data(){return{altText:this.#o,decorative:this.#Kt}}set data({altText:t,decorative:e,guessedText:i,textWithDisclaimer:s,cancel:n=!1}){i&&(this.#se=i,this.#ne=s),this.#o===t&&this.#Kt===e||(n||(this.#o=t,this.#Kt=e),this.#le())}toggle(t=!1){this.#Qt&&(!t&&this.#te&&(clearTimeout(this.#te),this.#te=null),this.#Qt.disabled=!t)}shown(){this.#r._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:this.#oe}})}destroy(){this.#Qt?.remove(),this.#Qt=null,this.#Jt=null,this.#Zt=null,this.#ie?.remove(),this.#ie=null}async#le(){const t=this.#Qt;if(!t)return;if(this.#re){if(t.classList.toggle("done",!!this.#o),t.setAttribute("data-l10n-id",Zt.#ae[this.#oe]),this.#Jt?.setAttribute("data-l10n-id",Zt.#ae[`${this.#oe}-label`]),!this.#o)return void this.#Zt?.remove()}else{if(!this.#o&&!this.#Kt)return t.classList.remove("done"),void this.#Zt?.remove();t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=this.#Zt;if(!e){this.#Zt=e=document.createElement("span"),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${this.#r.id}`;const i=100,s=this.#r._uiManager._signal;s.addEventListener("abort",()=>{clearTimeout(this.#te),this.#te=null},{once:!0}),t.addEventListener("mouseenter",()=>{this.#te=setTimeout(()=>{this.#te=null,this.#Zt.classList.add("show"),this.#r._reportTelemetry({action:"alt_text_tooltip"})},i)},{signal:s}),t.addEventListener("mouseleave",()=>{this.#te&&(clearTimeout(this.#te),this.#te=null),this.#Zt?.classList.remove("show")},{signal:s})}this.#Kt?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=this.#o),e.parentNode||t.append(e);const i=this.#r.getElementForAltText();i?.setAttribute("aria-describedby",e.id)}}class te{#he=null;#ce=null;#de=!1;#r=null;#ue=null;#pe=null;#ge=null;#me=null;#fe=!1;#be=null;constructor(t){this.#r=t}renderForToolbar(){const t=this.#ce=document.createElement("button");return t.className="comment",this.#v(t,!1)}renderForStandalone(){const t=this.#he=document.createElement("button");t.className="annotationCommentButton";const e=this.#r.commentButtonPosition;if(e){const{style:i}=t;i.insetInlineEnd=`calc(${100*("ltr"===this.#r._uiManager.direction?1-e[0]:e[0])}% - var(--comment-button-dim))`,i.top=`calc(${100*e[1]}% - var(--comment-button-dim))`;const s=this.#r.commentButtonColor;s&&(i.backgroundColor=s)}return this.#v(t,!0)}focusButton(){setTimeout(()=>{(this.#he??this.#ce)?.focus()},0)}onUpdatedColor(){if(!this.#he)return;const t=this.#r.commentButtonColor;t&&(this.#he.style.backgroundColor=t),this.#r._uiManager.updatePopupColor(this.#r)}get commentButtonWidth(){return(this.#he?.getBoundingClientRect().width??0)/this.#r.parent.boundingClientRect.width}get commentPopupPositionInLayer(){if(this.#be)return this.#be;if(!this.#he)return null;const{x:t,y:e,height:i}=this.#he.getBoundingClientRect(),{x:s,y:n,width:r,height:a}=this.#r.parent.boundingClientRect;return[(t-s)/r,(e+i-n)/a]}set commentPopupPositionInLayer(t){this.#be=t}hasDefaultPopupPosition(){return null===this.#be}removeStandaloneCommentButton(){this.#he?.remove(),this.#he=null}removeToolbarCommentButton(){this.#ce?.remove(),this.#ce=null}setCommentButtonStates({selected:t,hasPopup:e}){this.#he&&(this.#he.classList.toggle("selected",t),this.#he.ariaExpanded=e)}#v(t,e){if(!this.#r._uiManager.hasCommentManager())return null;t.tabIndex="0",t.ariaHasPopup="dialog",e?(t.ariaControls="commentPopup",t.setAttribute("data-l10n-id","pdfjs-show-comment-button")):(t.ariaControlsElements=[this.#r._uiManager.getCommentDialogElement()],t.setAttribute("data-l10n-id","pdfjs-editor-add-comment-button"));const i=this.#r._uiManager._signal;if(!(i instanceof AbortSignal)||i.aborted)return t;t.addEventListener("contextmenu",wt,{signal:i}),e&&(t.addEventListener("focusin",t=>{this.#r._focusEventsAllowed=!1,At(t)},{capture:!0,signal:i}),t.addEventListener("focusout",t=>{this.#r._focusEventsAllowed=!0,At(t)},{capture:!0,signal:i})),t.addEventListener("pointerdown",t=>t.stopPropagation(),{signal:i});const s=e=>{e.preventDefault(),t===this.#ce?this.edit():this.#r.toggleComment(!0)};return t.addEventListener("click",s,{capture:!0,signal:i}),t.addEventListener("keydown",e=>{e.target===t&&"Enter"===e.key&&(this.#de=!0,s(e))},{signal:i}),t.addEventListener("pointerenter",()=>{this.#r.toggleComment(!1,!0)},{signal:i}),t.addEventListener("pointerleave",()=>{this.#r.toggleComment(!1,!1)},{signal:i}),t}edit(t){const e=this.commentPopupPositionInLayer;let i,s;if(e)[i,s]=e;else{[i,s]=this.#r.commentButtonPosition;const{width:t,height:e,x:n,y:r}=this.#r;i=n+i*t,s=r+s*e}const n=this.#r.parent.boundingClientRect,{x:r,y:a,width:o,height:l}=n;this.#r._uiManager.editComment(this.#r,r+i*o,a+s*l,{...t,parentDimensions:n})}finish(){this.#ce&&(this.#ce.focus({focusVisible:this.#de}),this.#de=!1)}isDeleted(){return this.#fe||""===this.#ge}isEmpty(){return null===this.#ge}hasBeenEdited(){return this.isDeleted()||this.#ge!==this.#ue}serialize(){return this.data}get data(){return{text:this.#ge,richText:this.#pe,date:this.#me,deleted:this.isDeleted()}}set data(t){if(t!==this.#ge&&(this.#pe=null),null===t)return this.#ge="",void(this.#fe=!0);this.#ge=t,this.#me=new Date,this.#fe=!1}setInitialText(t,e=null){this.#ue=t,this.data=t,this.#me=null,this.#pe=e}shown(){}destroy(){this.#ce?.remove(),this.#ce=null,this.#he?.remove(),this.#he=null,this.#ge="",this.#pe=null,this.#me=null,this.#r=null,this.#de=!1,this.#fe=!1}}class ee{#Et;#ve=!1;#ye=null;#we;#Ae;#xe;#_e;#Se=null;#Ee;#Ce=null;#Te;#Me=null;constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:i=null,onPinchStart:s=null,onPinching:n=null,onPinchEnd:r=null,signal:a}){this.#Et=t,this.#ye=i,this.#we=e,this.#Ae=s,this.#xe=n,this.#_e=r,this.#Te=new AbortController,this.#Ee=AbortSignal.any([a,this.#Te.signal]),t.addEventListener("touchstart",this.#De.bind(this),{passive:!1,signal:this.#Ee})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return 35/Pt.pixelRatio}#De(t){if(this.#we?.())return;if(1===t.touches.length){if(this.#Se)return;const t=this.#Se=new AbortController,e=AbortSignal.any([this.#Ee,t.signal]),i=this.#Et,s={capture:!0,signal:e,passive:!1},n=t=>{"touch"===t.pointerType&&(this.#Se?.abort(),this.#Se=null)};return i.addEventListener("pointerdown",t=>{"touch"===t.pointerType&&(At(t),n(t))},s),i.addEventListener("pointerup",n,s),void i.addEventListener("pointercancel",n,s)}if(!this.#Me){this.#Me=new AbortController;const t=AbortSignal.any([this.#Ee,this.#Me.signal]),e=this.#Et,i={signal:t,capture:!1,passive:!1};e.addEventListener("touchmove",this.#Pe.bind(this),i);const s=this.#Ie.bind(this);e.addEventListener("touchend",s,i),e.addEventListener("touchcancel",s,i),i.capture=!0,e.addEventListener("pointerdown",At,i),e.addEventListener("pointermove",At,i),e.addEventListener("pointercancel",At,i),e.addEventListener("pointerup",At,i),this.#Ae?.()}if(At(t),2!==t.touches.length||this.#ye?.())return void(this.#Ce=null);let[e,i]=t.touches;e.identifier>i.identifier&&([e,i]=[i,e]),this.#Ce={touch0X:e.screenX,touch0Y:e.screenY,touch1X:i.screenX,touch1Y:i.screenY}}#Pe(t){if(!this.#Ce||2!==t.touches.length)return;At(t);let[e,i]=t.touches;e.identifier>i.identifier&&([e,i]=[i,e]);const{screenX:s,screenY:n}=e,{screenX:r,screenY:a}=i,o=this.#Ce,{touch0X:l,touch0Y:h,touch1X:c,touch1Y:d}=o,u=c-l,p=d-h,g=r-s,m=a-n,f=Math.hypot(g,m)||1,b=Math.hypot(u,p)||1;if(!this.#ve&&Math.abs(b-f)<=ee.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(o.touch0X=s,o.touch0Y=n,o.touch1X=r,o.touch1Y=a,!this.#ve)return void(this.#ve=!0);const v=[(s+r)/2,(n+a)/2];this.#xe?.(v,b,f)}#Ie(t){t.touches.length>=2||(this.#Me&&(this.#Me.abort(),this.#Me=null,this.#_e?.()),this.#Ce&&(At(t),this.#Ce=null,this.#ve=!1))}destroy(){this.#Te?.abort(),this.#Te=null,this.#Se?.abort(),this.#Se=null}}class ie{#ke=null;#Re=null;#o=null;#l=null;#he=null;#Le=!1;#Fe=null;#Oe="";#Be=null;#Ne=null;#Ue=null;#je=null;#He=null;#ze="";#$e=!1;#Ge=null;#We=!1;#Ve=!1;#qe=!1;#Xe=null;#Ye=0;#Ke=0;#Qe=null;#Je=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;#Ze=!1;#ti=ie._zIndex++;static _borderLineWidth=-1;static _colorManager=new Qt;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){const t=ie.prototype._resizeWithKeyboard,e=Jt.TRANSLATE_SMALL,i=Jt.TRANSLATE_BIG;return F(this,"_resizerKeyboardManager",new Kt([[["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"],ie.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:s,pageX:n,pageY:r}}=this.parent.viewport;this.rotation=e,this.pageRotation=(360+e-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[i,s],this.pageTranslation=[n,r];const[a,o]=this.parentDimensions;this.x=t.x/a,this.y=t.y/o,this.isAttachedToDOM=!1,this.deleted=!1}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 F(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new se({id:t.parent.getNextId(),parent:t.parent,uiManager:t._uiManager});e.annotationElementId=t.annotationElementId,e.deleted=!0,e._uiManager.addToAnnotationStorage(e)}static initialize(t,e){if(ie._l10n??=t,ie._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"}),-1!==ie._borderLineWidth)return;const i=getComputedStyle(document.documentElement);ie._borderLineWidth=parseFloat(i.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){P("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#Ze}set _isDraggable(t){this.#Ze=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;break}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.#ti}setParent(t){null!==t?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):(this.#ei(),this.#je?.remove(),this.#je=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;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,s){const[n,r]=this.parentDimensions;[i,s]=this.screenToPageTranslation(i,s),this.x=(t+i)/n,this.y=(e+s)/r,this.fixAndSetPosition()}_moveAfterPaste(t,e){const[i,s]=this.parentDimensions;this.setAt(t*i,e*s,this.width*i,this.height*s),this._onTranslated()}#ii([t,e],i,s){[i,s]=this.screenToPageTranslation(i,s),this.x+=i/t,this.y+=s/e,this._onTranslating(this.x,this.y),this.fixAndSetPosition()}translate(t,e){this.#ii(this.parentDimensions,t,e)}translateInPage(t,e){this.#Ge||=[this.x,this.y,this.width,this.height],this.#ii(this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}translationDone(){this._onTranslated(this.x,this.y)}drag(t,e){this.#Ge||=[this.x,this.y,this.width,this.height];const{div:i,parentDimensions:[s,n]}=this;if(this.x+=t/s,this.y+=e/n,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:t,y:e}=this.div.getBoundingClientRect();this.parent.findNewParent(this,t,e)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:r,y:a}=this;const[o,l]=this.getBaseTranslation();r+=o,a+=l;const{style:h}=i;h.left=`${(100*r).toFixed(2)}%`,h.top=`${(100*a).toFixed(2)}%`,this._onTranslating(r,a),i.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!this.#Ge&&(this.#Ge[0]!==this.x||this.#Ge[1]!==this.y)}get _hasBeenResized(){return!!this.#Ge&&(this.#Ge[2]!==this.width||this.#Ge[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:i}=ie,s=i/t,n=i/e;switch(this.rotation){case 90:return[-s,n];case 180:return[s,n];case 270:return[s,-n];default:return[-s,-n]}}get _mustFixPosition(){return!0}fixAndSetPosition(t=this.rotation){const{div:{style:e},pageDimensions:[i,s]}=this;let{x:n,y:r,width:a,height:o}=this;if(a*=i,o*=s,n*=i,r*=s,this._mustFixPosition)switch(t){case 0:n=nt(n,0,i-a),r=nt(r,0,s-o);break;case 90:n=nt(n,0,i-o),r=nt(r,a,s);break;case 180:n=nt(n,a,i),r=nt(r,o,s);break;case 270:n=nt(n,o,i),r=nt(r,0,s-a);break}this.x=n/=i,this.y=r/=s;const[l,h]=this.getBaseTranslation();n+=l,r+=h,e.left=`${(100*n).toFixed(2)}%`,e.top=`${(100*r).toFixed(2)}%`,this.moveInDOM()}static#si(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 ie.#si(t,e,this.parentRotation)}pageTranslationToScreen(t,e){return ie.#si(t,e,360-this.parentRotation)}#ni(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]}#ri(){if(this.#Be)return;this.#Be=document.createElement("div"),this.#Be.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.#Be.append(t),t.classList.add("resizer",i),t.setAttribute("data-resizer-name",i),t.addEventListener("pointerdown",this.#ai.bind(this,i),{signal:e}),t.addEventListener("contextmenu",wt,{signal:e}),t.tabIndex=-1}this.div.prepend(this.#Be)}#ai(t,e){e.preventDefault();const{isMac:i}=X.platform;if(0!==e.button||e.ctrlKey&&i)return;this.#o?.toggle(!1);const s=this._isDraggable;this._isDraggable=!1,this.#Ne=[e.screenX,e.screenY];const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",this.#oi.bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",At,{passive:!1,signal:r}),window.addEventListener("contextmenu",wt,{signal:r}),this.#Ue={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 l=()=>{n.abort(),this.parent.togglePointerEvents(!0),this.#o?.toggle(!0),this._isDraggable=s,this.parent.div.style.cursor=a,this.div.style.cursor=o,this.#li()};window.addEventListener("pointerup",l,{signal:r}),window.addEventListener("blur",l,{signal:r})}#hi(t,e,i,s){this.width=i,this.height=s,this.x=t,this.y=e,this.setDims(),this.fixAndSetPosition(),this._onResized()}_onResized(){}#li(){if(!this.#Ue)return;const{savedX:t,savedY:e,savedWidth:i,savedHeight:s}=this.#Ue;this.#Ue=null;const n=this.x,r=this.y,a=this.width,o=this.height;n===t&&r===e&&a===i&&o===s||this.addCommands({cmd:this.#hi.bind(this,n,r,a,o),undo:this.#hi.bind(this,t,e,i,s),mustExec:!0})}static _round(t){return Math.round(1e4*t)/1e4}#oi(t,e){const[i,s]=this.parentDimensions,n=this.x,r=this.y,a=this.width,o=this.height,l=ie.MIN_SIZE/i,h=ie.MIN_SIZE/s,c=this.#ni(this.rotation),d=(t,e)=>[c[0]*t+c[2]*e,c[1]*t+c[3]*e],u=this.#ni(360-this.rotation),p=(t,e)=>[u[0]*t+u[2]*e,u[1]*t+u[3]*e];let g,m,f=!1,b=!1;switch(t){case"topLeft":f=!0,g=(t,e)=>[0,0],m=(t,e)=>[t,e];break;case"topMiddle":g=(t,e)=>[t/2,0],m=(t,e)=>[t/2,e];break;case"topRight":f=!0,g=(t,e)=>[t,0],m=(t,e)=>[0,e];break;case"middleRight":b=!0,g=(t,e)=>[t,e/2],m=(t,e)=>[0,e/2];break;case"bottomRight":f=!0,g=(t,e)=>[t,e],m=(t,e)=>[0,0];break;case"bottomMiddle":g=(t,e)=>[t/2,e],m=(t,e)=>[t/2,0];break;case"bottomLeft":f=!0,g=(t,e)=>[0,e],m=(t,e)=>[t,0];break;case"middleLeft":b=!0,g=(t,e)=>[0,e/2],m=(t,e)=>[t,e/2];break}const v=g(a,o),y=m(a,o);let w=d(...y);const A=ie._round(n+w[0]),x=ie._round(r+w[1]);let _,S,E=1,C=1;if(e.fromKeyboard)({deltaX:_,deltaY:S}=e);else{const{screenX:t,screenY:i}=e,[s,n]=this.#Ne;[_,S]=this.screenToPageTranslation(t-s,i-n),this.#Ne[0]=t,this.#Ne[1]=i}if([_,S]=p(_/i,S/s),f){const t=Math.hypot(a,o);E=C=Math.max(Math.min(Math.hypot(y[0]-v[0]-_,y[1]-v[1]-S)/t,1/a,1/o),l/a,h/o)}else b?E=nt(Math.abs(y[0]-v[0]-_),l,1)/a:C=nt(Math.abs(y[1]-v[1]-S),h,1)/o;const T=ie._round(a*E),M=ie._round(o*C);w=d(...m(T,M));const D=A-w[0],P=x-w[1];this.#Ge||=[this.x,this.y,this.width,this.height],this.width=T,this.height=M,this.x=D,this.y=P,this.setDims(),this.fixAndSetPosition(),this._onResizing()}_onResizing(){}altTextFinish(){this.#o?.finish()}get toolbarButtons(){return null}async addEditToolbar(){if(this._editToolbar||this.#Ve)return this._editToolbar;this._editToolbar=new $t(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);return this.hasComment||this._editToolbar.addButton("comment",this.addCommentButton()),this._editToolbar.addButton("delete"),this._editToolbar}addCommentButtonInToolbar(){this._editToolbar?.addButtonBefore("comment",this.addCommentButton(),".deleteButton")}removeCommentButtonFromToolbar(){this._editToolbar?.removeButton("comment")}removeEditToolbar(){this._editToolbar?.remove(),this._editToolbar=null,this.#o?.destroy()}addContainer(t){const e=this._editToolbar?.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}createAltText(){return this.#o||(Zt.initialize(ie._l10n),this.#o=new Zt(this),this.#ke&&(this.#o.data=this.#ke,this.#ke=null)),this.#o}get altTextData(){return this.#o?.data}set altTextData(t){this.#o&&(this.#o.data=t)}get guessedAltText(){return this.#o?.guessedText}async setGuessedAltText(t){await(this.#o?.setGuessedText(t))}serializeAltText(t){return this.#o?.serialize(t)}hasAltText(){return!!this.#o&&!this.#o.isEmpty()}hasAltTextData(){return this.#o?.hasData()??!1}focusCommentButton(){this.#l?.focusButton()}addCommentButton(){return this.canAddComment?this.#l||=new te(this):null}addStandaloneCommentButton(){this._uiManager.hasCommentManager()&&(this.#he?this._uiManager.isEditingMode()&&this.#he.classList.remove("hidden"):this.hasComment&&(this.#he=this.#l.renderForStandalone(),this.div.append(this.#he)))}removeStandaloneCommentButton(){this.#l.removeStandaloneCommentButton(),this.#he=null}hideStandaloneCommentButton(){this.#he?.classList.add("hidden")}get comment(){const{data:{richText:t,text:e,date:i,deleted:s}}=this.#l;return{text:e,richText:t,date:i,deleted:s,color:this.getNonHCMColor(),opacity:this.opacity??1}}set comment(t){this.#l||=new te(this),this.#l.data=t,this.hasComment?(this.removeCommentButtonFromToolbar(),this.addStandaloneCommentButton(),this._uiManager.updateComment(this)):(this.addCommentButtonInToolbar(),this.removeStandaloneCommentButton(),this._uiManager.removeComment(this))}setCommentData({comment:t,popupRef:e,richText:i}){if(!e)return;if(this.#l||=new te(this),this.#l.setInitialText(t,i),!this.annotationElementId)return;const s=this._uiManager.getAndRemoveDataFromAnnotationStorage(this.annotationElementId);s&&this.updateFromAnnotationLayer(s)}get hasEditedComment(){return this.#l?.hasBeenEdited()}get hasDeletedComment(){return this.#l?.isDeleted()}get hasComment(){return!!this.#l&&!this.#l.isEmpty()&&!this.#l.isDeleted()}async editComment(t){this.#l||=new te(this),this.#l.edit(t)}toggleComment(t,e=void 0){this.hasComment&&this._uiManager.toggleComment(this,t,e)}setSelectedCommentButton(t){this.#l.setSelectedButton(t)}addComment(t){if(this.hasEditedComment){const e=180,i=100,[,,,s]=t.rect,[n]=this.pageDimensions,[r]=this.pageTranslation,a=r+n+1,o=s-i,l=a+e;t.popup={contents:this.comment.text,deleted:this.comment.deleted,rect:[a,o,l,s]}}}updateFromAnnotationLayer({popup:{contents:t,deleted:e}}){this.#l.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.#ci();const[e,i]=this.parentDimensions;this.parentRotation%180!==0&&(t.style.maxWidth=`${(100*i/e).toFixed(2)}%`,t.style.maxHeight=`${(100*e/i).toFixed(2)}%`);const[s,n]=this.getInitialTranslation();return this.translate(s,n),Wt(this,t,["keydown","pointerdown","dblclick"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#Je||=new ee({container:t,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#di.bind(this),onPinching:this.#ui.bind(this),onPinchEnd:this.#pi.bind(this),signal:this._uiManager._signal})),this.addStandaloneCommentButton(),this._uiManager._editorUndoBar?.hide(),t}#di(){this.#Ue={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height},this.#o?.toggle(!1),this.parent.togglePointerEvents(!1)}#ui(t,e,i){const s=.7;let n=s*(i/e)+1-s;if(1===n)return;const r=this.#ni(this.rotation),a=(t,e)=>[r[0]*t+r[2]*e,r[1]*t+r[3]*e],[o,l]=this.parentDimensions,h=this.x,c=this.y,d=this.width,u=this.height,p=ie.MIN_SIZE/o,g=ie.MIN_SIZE/l;n=Math.max(Math.min(n,1/d,1/u),p/d,g/u);const m=ie._round(d*n),f=ie._round(u*n);if(m===d&&f===u)return;this.#Ge||=[h,c,d,u];const b=a(d/2,u/2),v=ie._round(h+b[0]),y=ie._round(c+b[1]),w=a(m/2,f/2);this.x=v-w[0],this.y=y-w[1],this.width=m,this.height=f,this.setDims(),this.fixAndSetPosition(),this._onResizing()}#pi(){this.#o?.toggle(!0),this.parent.togglePointerEvents(!0),this.#li()}pointerdown(t){const{isMac:e}=X.platform;0!==t.button||t.ctrlKey&&e?t.preventDefault():(this.#$e=!0,this._isDraggable?this.#gi(t):this.#mi(t))}#mi(t){const{isMac:e}=X.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)}#gi(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();let i=!1;const s=new AbortController,n=this._uiManager.combinedSignal(s),r={capture:!0,passive:!1,signal:n},a=t=>{s.abort(),this.#Fe=null,this.#$e=!1,this._uiManager.endDragSession()||this.#mi(t),i&&this._onStopDragging()};e&&(this.#Ye=t.clientX,this.#Ke=t.clientY,this.#Fe=t.pointerId,this.#Oe=t.pointerType,window.addEventListener("pointermove",t=>{i||(i=!0,this._uiManager.toggleComment(this,!0,!1),this._onStartDragging());const{clientX:e,clientY:s,pointerId:n}=t;if(n!==this.#Fe)return void At(t);const[r,a]=this.screenToPageTranslation(e-this.#Ye,s-this.#Ke);this.#Ye=e,this.#Ke=s,this._uiManager.dragSelectedEditors(r,a)},r),window.addEventListener("touchmove",At,r),window.addEventListener("pointerdown",t=>{t.pointerType===this.#Oe&&(this.#Je||t.isPrimary)&&a(t),At(t)},r));const o=t=>{this.#Fe&&this.#Fe!==t.pointerId?At(t):a(t)};window.addEventListener("pointerup",o,{signal:n}),window.addEventListener("blur",o,{signal:n})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#Xe&&clearTimeout(this.#Xe),this.#Xe=setTimeout(()=>{this.#Xe=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 s=this.parentScale,[n,r]=this.pageDimensions,[a,o]=this.pageTranslation,l=t/s,h=e/s,c=this.x*n,d=this.y*r,u=this.width*n,p=this.height*r;switch(i){case 0:return[c+l+a,r-d-h-p+o,c+l+u+a,r-d-h+o];case 90:return[c+h+a,r-d+l+o,c+h+p+a,r-d+l+u+o];case 180:return[c-l-u+a,r-d+h+o,c-l+a,r-d+h+p+o];case 270:return[c-h-p+a,r-d-l-u+o,c-h+a,r-d-l+o];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[i,s,n,r]=t,a=n-i,o=r-s;switch(this.rotation){case 0:return[i,e-r,a,o];case 90:return[i,e-s,o,a];case 180:return[n,e-s,a,o];case 270:return[n,e-r,o,a];default:throw new Error("Invalid rotation")}}getPDFRect(){return this.getRect(0,0)}getNonHCMColor(){return this.color&&ie._colorManager.convert(this._uiManager.getNonHCMColor(this.color))}onUpdatedColor(){this.#l?.onUpdatedColor()}getData(){const{comment:{text:t,color:e,date:i,opacity:s,deleted:n,richText:r},uid:a,pageIndex:o,creationDate:l,modificationDate:h}=this;return{id:a,pageIndex:o,rect:this.getPDFRect(),richText:r,contentsObj:{str:t},creationDate:l,modificationDate:i||h,popupRef:!n,color:e,opacity:s}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){return!this.isInEditMode()&&(this.parent.setEditingState(!1),this.#Ve=!0,!0)}disableEditMode(){return!!this.isInEditMode()&&(this.parent.setEditingState(!0),this.#Ve=!1,!0)}isInEditMode(){return this.#Ve}shouldGetKeyboardEvents(){return this.#qe}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){const{top:t,left:e,bottom:i,right:s}=this.getClientDimensions(),{innerHeight:n,innerWidth:r}=window;return e<r&&s>0&&t<n&&i>0}#ci(){if(this.#He||!this.div)return;this.#He=new AbortController;const t=this._uiManager.combinedSignal(this.#He);this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})}rebuild(){this.#ci()}rotate(t){}resize(){}serializeDeleted(){return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:this._initialData?.popupRef||""}}serialize(t=!1,e=null){return{annotationType:this.mode,pageIndex:this.pageIndex,rect:this.getPDFRect(),rotation:this.rotation,structTreeParentId:this._structTreeParentId,popupRef:this._initialData?.popupRef||""}}static async deserialize(t,e,i){const s=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:i,annotationElementId:t.annotationElementId,creationDate:t.creationDate,modificationDate:t.modificationDate});s.rotation=t.rotation,s.#ke=t.accessibilityData,s._isCopy=t.isCopy||!1;const[n,r]=s.pageDimensions,[a,o,l,h]=s.getRectInCurrentCoords(t.rect,r);return s.x=a/n,s.y=o/r,s.width=l/n,s.height=h/r,s}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||null!==this.serialize())}remove(){if(this.#He?.abort(),this.#He=null,this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),this.hideCommentPopup(),this.#Xe&&(clearTimeout(this.#Xe),this.#Xe=null),this.#ei(),this.removeEditToolbar(),this.#Qe){for(const t of this.#Qe.values())clearTimeout(t);this.#Qe=null}this.parent=null,this.#Je?.destroy(),this.#Je=null,this.#je?.remove(),this.#je=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(this.#ri(),this.#Be.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,s,n,r]=this.getPDFRect();return[ie._round(i+(n-i)*t),ie._round(s+(r-s)*(1-e))]}get commentButtonColor(){return this._uiManager.makeCommentColor(this.getNonHCMColor(),this.opacity)}get commentPopupPosition(){return this.#l.commentPopupPositionInLayer}set commentPopupPosition(t){this.#l.commentPopupPositionInLayer=t}hasDefaultPopupPosition(){return this.#l.hasDefaultPopupPosition()}get commentButtonWidth(){return this.#l.commentButtonWidth}get elementBeforePopup(){return this.div}setCommentButtonStates(t){this.#l?.setCommentButtonStates(t)}keydown(t){if(!this.isResizable||t.target!==this.div||"Enter"!==t.key)return;this._uiManager.setSelected(this),this.#Ue={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};const e=this.#Be.children;if(!this.#Re){this.#Re=Array.from(e);const t=this.#fi.bind(this),i=this.#bi.bind(this),s=this._uiManager._signal;for(const e of this.#Re){const n=e.getAttribute("data-resizer-name");e.setAttribute("role","spinbutton"),e.addEventListener("keydown",t,{signal:s}),e.addEventListener("blur",i,{signal:s}),e.addEventListener("focus",this.#vi.bind(this,n),{signal:s}),e.setAttribute("data-l10n-id",ie._l10nResizer[n])}}const i=this.#Re[0];let s=0;for(const r of e){if(r===i)break;s++}const n=(360-this.rotation+this.parentRotation)%360/90*(this.#Re.length/4);if(n!==s){if(n<s)for(let e=0;e<s-n;e++)this.#Be.append(this.#Be.firstElementChild);else if(n>s)for(let e=0;e<n-s;e++)this.#Be.firstElementChild.before(this.#Be.lastElementChild);let t=0;for(const i of e){const e=this.#Re[t++],s=e.getAttribute("data-resizer-name");i.setAttribute("data-l10n-id",ie._l10nResizer[s])}}this.#yi(0),this.#qe=!0,this.#Be.firstElementChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}#fi(t){ie._resizerKeyboardManager.exec(this,t)}#bi(t){this.#qe&&t.relatedTarget?.parentNode!==this.#Be&&this.#ei()}#vi(t){this.#ze=this.#qe?t:""}#yi(t){if(this.#Re)for(const e of this.#Re)e.tabIndex=t}_resizeWithKeyboard(t,e){this.#qe&&this.#oi(this.#ze,{deltaX:t,deltaY:e,fromKeyboard:!0})}#ei(){this.#qe=!1,this.#yi(-1),this.#li()}_stopResizingWithKeyboard(){this.#ei(),this.div.focus()}select(){this.isSelected&&this._editToolbar?this._editToolbar.show():(this.isSelected=!0,this.makeResizable(),this.div?.classList.add("selectedEditor"),this._editToolbar?(this._editToolbar?.show(),this.#o?.toggleAltTextBadge(!1)):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(){this.isSelected&&(this.isSelected=!1,this.#Be?.classList.add("hidden"),this.div?.classList.remove("selectedEditor"),this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),this._editToolbar?.hide(),this.#o?.toggleAltTextBadge(!0),this.hideCommentPopup())}hideCommentPopup(){this.hasComment&&this._uiManager.toggleComment(null)}updateParams(t,e){}disableEditing(){}enableEditing(){}get canChangeContent(){return!1}enterInEditMode(){this.canChangeContent&&(this.enableEditMode(),this.div.focus())}dblclick(t){"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.#We}set isEditing(t){this.#We=t,this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):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.#Qe||=new Map;const{action:e}=t;let i=this.#Qe.get(e);return i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),this.#Qe.delete(e),0===this.#Qe.size&&(this.#Qe=null)},ie._telemetryTimeout),void this.#Qe.set(e,i)}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.#je||this.deleted)return this.deleted?(this.#je.remove(),void(this.#je=null)):void((this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized)&&this.#je.updateEdited({rect:this.getPDFRect(),popup:this.comment}));this.#je=t.addFakeAnnotation(this)}renderAnnotationElement(t){if(this.deleted)return t.hide(),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 se extends ie{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const ne=3285377520,re=4294901760,ae=65535;class oe{constructor(t){this.h1=t?4294967295&t:ne,this.h2=t?4294967295&t:ne}update(t){let e,i;if("string"===typeof t){e=new Uint8Array(2*t.length),i=0;for(let s=0,n=t.length;s<n;s++){const n=t.charCodeAt(s);n<=255?e[i++]=n:(e[i++]=n>>>8,e[i++]=255&n)}}else{if(!ArrayBuffer.isView(t))throw new Error("Invalid data format, must be a string or TypedArray.");e=t.slice(),i=e.byteLength}const s=i>>2,n=i-4*s,r=new Uint32Array(e.buffer,0,s);let a=0,o=0,l=this.h1,h=this.h2;const c=3432918353,d=461845907,u=c&ae,p=d&ae;for(let g=0;g<s;g++)1&g?(a=r[g],a=a*c&re|a*u&ae,a=a<<15|a>>>17,a=a*d&re|a*p&ae,l^=a,l=l<<13|l>>>19,l=5*l+3864292196):(o=r[g],o=o*c&re|o*u&ae,o=o<<15|o>>>17,o=o*d&re|o*p&ae,h^=o,h=h<<13|h>>>19,h=5*h+3864292196);switch(a=0,n){case 3:a^=e[4*s+2]<<16;case 2:a^=e[4*s+1]<<8;case 1:a^=e[4*s],a=a*c&re|a*u&ae,a=a<<15|a>>>17,a=a*d&re|a*p&ae,1&s?l^=a:h^=a}this.h1=l,this.h2=h}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=3981806797*t&re|36045*t&ae,e=4283543511*e&re|(2950163797*(e<<16|t>>>16)&re)>>>16,t^=e>>>1,t=444984403*t&re|60499*t&ae,e=3301882366*e&re|(3120437893*(e<<16|t>>>16)&re)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const le=Object.freeze({map:null,hash:"",transfer:void 0});class he{#wi=!1;#Ai=null;#xi=null;#_i=new Map;constructor(){this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const i=this.#_i.get(t);return void 0===i?e:Object.assign(e,i)}getRawValue(t){return this.#_i.get(t)}remove(t){const e=this.#_i.get(t);if(void 0!==e&&(e instanceof ie&&this.#xi.delete(e.annotationElementId),this.#_i.delete(t),0===this.#_i.size&&this.resetModified(),"function"===typeof this.onAnnotationEditor)){for(const t of this.#_i.values())if(t instanceof ie)return;this.onAnnotationEditor(null)}}setValue(t,e){const i=this.#_i.get(t);let s=!1;if(void 0!==i)for(const[n,r]of Object.entries(e))i[n]!==r&&(s=!0,i[n]=r);else s=!0,this.#_i.set(t,e);s&&this.#Si(),e instanceof ie&&((this.#xi||=new Map).set(e.annotationElementId,e),"function"===typeof this.onAnnotationEditor&&this.onAnnotationEditor(e.constructor._type))}has(t){return this.#_i.has(t)}get size(){return this.#_i.size}#Si(){this.#wi||(this.#wi=!0,"function"===typeof this.onSetModified&&this.onSetModified())}resetModified(){this.#wi&&(this.#wi=!1,"function"===typeof this.onResetModified&&this.onResetModified())}get print(){return new ce(this)}get serializable(){if(0===this.#_i.size)return le;const t=new Map,e=new oe,i=[],s=Object.create(null);let n=!1;for(const[r,a]of this.#_i){const i=a instanceof ie?a.serialize(!1,s):a;i&&(t.set(r,i),e.update(`${r}:${JSON.stringify(i)}`),n||=!!i.bitmap)}if(n)for(const r of t.values())r.bitmap&&i.push(r.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:i}:le}get editorStats(){let t=null;const e=new Map;let i=0,s=0;for(const n of this.#_i.values()){if(!(n instanceof ie)){n.popup&&(n.popup.deleted?s+=1:i+=1);continue}n.isCommentDeleted?s+=1:n.hasEditedComment&&(i+=1);const r=n.telemetryFinalData;if(!r)continue;const{type:a}=r;e.has(a)||e.set(a,Object.getPrototypeOf(n).constructor),t||=Object.create(null);const o=t[a]||=new Map;for(const[t,e]of Object.entries(r)){if("type"===t)continue;let i=o.get(t);i||(i=new Map,o.set(t,i));const s=i.get(e)??0;i.set(e,s+1)}}if((s>0||i>0)&&(t||=Object.create(null),t.comments={deleted:s,edited:i}),!t)return null;for(const[n,r]of e)t[n]=r.computeTelemetryFinalData(t[n]);return t}resetModifiedIds(){this.#Ai=null}updateEditor(t,e){const i=this.#xi?.get(t);return!!i&&(i.updateFromAnnotationLayer(e),!0)}getEditor(t){return this.#xi?.get(t)||null}get modifiedIds(){if(this.#Ai)return this.#Ai;const t=[];if(this.#xi)for(const e of this.#xi.values())e.serialize()&&t.push(e.annotationElementId);return this.#Ai={ids:new Set(t),hash:t.join(",")}}[Symbol.iterator](){return this.#_i.entries()}}class ce extends he{#Ei;constructor(t){super();const{map:e,hash:i,transfer:s}=t.serializable,n=structuredClone(e,s?{transfer:s}:null);this.#Ei={map:n,hash:i,transfer:s}}get print(){P("Should not call PrintAnnotationStorage.print")}get serializable(){return this.#Ei}get modifiedIds(){return F(this,"modifiedIds",{ids:new Set,hash:""})}}class de{#Ci=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){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.#Ci.clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,disableFontFace:e,_inspectFont:i}){if(t&&!this.#Ci.has(t.loadedName)){if(I(!e,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){const{loadedName:e,src:s,style:n}=t,r=new FontFace(e,s,n);this.addNativeFontFace(r);try{await r.load(),this.#Ci.add(e),i?.(t)}catch{D(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}P("Not implemented: loadSystemFont without the Font Loading API.")}}async bind(t){if(t.attached||t.missingFile&&!t.systemFontInfo)return;if(t.attached=!0,t.systemFontInfo)return void await this.loadSystemFont(t);if(this.isFontLoadingAPISupported){const e=t.createNativeFontFace();if(e){this.addNativeFontFace(e);try{await e.loaded}catch(i){throw D(`Failed to load font '${e.family}': '${i}'.`),t.disableFontFace=!0,i}}return}const e=t.createFontFaceRule();if(e){if(this.insertRule(e),this.isSyncFontLoadingSupported)return;await new Promise(e=>{const i=this._queueLoadingCallback(e);this._prepareFontLoadEvent(t,i)})}}get isFontLoadingAPISupported(){const t=!!this._document?.fonts;return F(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){return F(this,"isSyncFontLoadingSupported",o||X.platform.isFirefox)}_queueLoadingCallback(t){function e(){I(!s.done,"completeRequest() cannot be called twice."),s.done=!0;while(i.length>0&&i[0].done){const t=i.shift();setTimeout(t.callback,0)}}const{loadingRequests:i}=this,s={done:!1,complete:e,callback:t};return i.push(s),s}get _loadTestFont(){const t=atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");return F(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function i(t,e){return t.charCodeAt(e)<<24|t.charCodeAt(e+1)<<16|t.charCodeAt(e+2)<<8|255&t.charCodeAt(e+3)}function s(t,e,i,s){const n=t.substring(0,e),r=t.substring(e+i);return n+s+r}let n,r;const a=this._document.createElement("canvas");a.width=1,a.height=1;const o=a.getContext("2d");let l=0;function h(t,e){if(++l>30)return D("Load test font never loaded."),void e();o.font="30px "+t,o.fillText(".",0,20);const i=o.getImageData(0,0,1,1);i.data[3]>0?e():setTimeout(h.bind(null,t,e))}const c=`lt${Date.now()}${this.loadTestFontId++}`;let d=this._loadTestFont;const u=976;d=s(d,u,c.length,c);const p=16,g=1482184792;let m=i(d,p);for(n=0,r=c.length-3;n<r;n+=4)m=m-g+i(c,n)|0;n<c.length&&(m=m-g+i(c+"XXX",n)|0),d=s(d,p,4,W(m));const f=`url(data:font/opentype;base64,${btoa(d)});`,b=`@font-face {font-family:"${c}";src:${f}}`;this.insertRule(b);const v=this._document.createElement("div");v.style.visibility="hidden",v.style.width=v.style.height="10px",v.style.position="absolute",v.style.top=v.style.left="0px";for(const y of[t.loadedName,c]){const t=this._document.createElement("span");t.textContent="Hi",t.style.fontFamily=y,v.append(t)}this._document.body.append(v),h(c,()=>{v.remove(),e.complete()})}}class ue{#Ti;constructor(t,e=null,i,s){this.compiledGlyphs=Object.create(null),this.#Ti=t,this._inspectFont=e,i&&Object.assign(this,i),s&&(this.charProcOperatorList=s)}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,{});return this._inspectFont?.(this),t}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${rt(this.data)});`;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}}`;return this._inspectFont?.(this,t),e}getPathGenerator(t,e){if(void 0!==this.compiledGlyphs[e])return this.compiledGlyphs[e];const i=this.loadedName+"_path_"+e;let s;try{s=t.get(i)}catch(r){D(`getPathGenerator - ignoring character: "${r}".`)}const n=zt(s?.path);return this.fontExtraProperties||t.delete(i),this.compiledGlyphs[e]=n}get black(){return this.#Ti.black}get bold(){return this.#Ti.bold}get disableFontFace(){return this.#Ti.disableFontFace??!1}set disableFontFace(t){F(this,"disableFontFace",!!t)}get fontExtraProperties(){return this.#Ti.fontExtraProperties??!1}get isInvalidPDFjsFont(){return this.#Ti.isInvalidPDFjsFont}get isType3Font(){return this.#Ti.isType3Font}get italic(){return this.#Ti.italic}get missingFile(){return this.#Ti.missingFile}get remeasure(){return this.#Ti.remeasure}get vertical(){return this.#Ti.vertical}get ascent(){return this.#Ti.ascent}get defaultWidth(){return this.#Ti.defaultWidth}get descent(){return this.#Ti.descent}get bbox(){return this.#Ti.bbox}set bbox(t){F(this,"bbox",t)}get fontMatrix(){return this.#Ti.fontMatrix}get fallbackName(){return this.#Ti.fallbackName}get loadedName(){return this.#Ti.loadedName}get mimetype(){return this.#Ti.mimetype}get name(){return this.#Ti.name}get data(){return this.#Ti.data}clearData(){this.#Ti.clearData()}get cssFontInfo(){return this.#Ti.cssFontInfo}get systemFontInfo(){return this.#Ti.systemFontInfo}get defaultVMetrics(){return this.#Ti.defaultVMetrics}}class pe{#Mi;#Di;#Pi;static strings=["fontFamily","fontWeight","italicAngle"];static write(t){const e=new TextEncoder,i={};let s=0;for(const l of pe.strings){const n=e.encode(t[l]);i[l]=n,s+=4+n.length}const n=new ArrayBuffer(s),r=new Uint8Array(n),a=new DataView(n);let o=0;for(const l of pe.strings){const t=i[l],e=t.length;a.setUint32(o,e),r.set(t,o+4),o+=4+e}return I(o===n.byteLength,"CssFontInfo.write: Buffer overflow"),n}constructor(t){this.#Mi=t,this.#Di=new DataView(this.#Mi),this.#Pi=new TextDecoder}#Ii(t){I(t<pe.strings.length,"Invalid string index");let e=0;for(let s=0;s<t;s++)e+=this.#Di.getUint32(e)+4;const i=this.#Di.getUint32(e);return this.#Pi.decode(new Uint8Array(this.#Mi,e+4,i))}get fontFamily(){return this.#Ii(0)}get fontWeight(){return this.#Ii(1)}get italicAngle(){return this.#Ii(2)}}class ge{#Mi;#Di;#Pi;static strings=["css","loadedName","baseFontName","src"];static write(t){const e=new TextEncoder,i={};let s=0;for(const d of ge.strings){const n=e.encode(t[d]);i[d]=n,s+=4+n.length}s+=4;let n,r,a=1+s;t.style&&(n=e.encode(t.style.style),r=e.encode(t.style.weight),a+=4+n.length+4+r.length);const o=new ArrayBuffer(a),l=new Uint8Array(o),h=new DataView(o);let c=0;h.setUint8(c++,t.guessFallback?1:0),h.setUint32(c,0),c+=4,s=0;for(const d of ge.strings){const t=i[d],e=t.length;s+=4+e,h.setUint32(c,e),l.set(t,c+4),c+=4+e}return h.setUint32(c-s-4,s),t.style&&(h.setUint32(c,n.length),l.set(n,c+4),c+=4+n.length,h.setUint32(c,r.length),l.set(r,c+4),c+=4+r.length),I(c<=o.byteLength,"SubstitionInfo.write: Buffer overflow"),o.transferToFixedLength(c)}constructor(t){this.#Mi=t,this.#Di=new DataView(this.#Mi),this.#Pi=new TextDecoder}get guessFallback(){return 0!==this.#Di.getUint8(0)}#Ii(t){I(t<ge.strings.length,"Invalid string index");let e=5;for(let s=0;s<t;s++)e+=this.#Di.getUint32(e)+4;const i=this.#Di.getUint32(e);return this.#Pi.decode(new Uint8Array(this.#Mi,e+4,i))}get css(){return this.#Ii(0)}get loadedName(){return this.#Ii(1)}get baseFontName(){return this.#Ii(2)}get src(){return this.#Ii(3)}get style(){let t=1;t+=4+this.#Di.getUint32(t);const e=this.#Di.getUint32(t),i=this.#Pi.decode(new Uint8Array(this.#Mi,t+4,e));t+=4+e;const s=this.#Di.getUint32(t),n=this.#Pi.decode(new Uint8Array(this.#Mi,t+4,s));return{style:i,weight:n}}}class me{static bools=["black","bold","disableFontFace","fontExtraProperties","isInvalidPDFjsFont","isType3Font","italic","missingFile","remeasure","vertical"];static numbers=["ascent","defaultWidth","descent"];static strings=["fallbackName","loadedName","mimetype","name"];static#ki=Math.ceil(2*this.bools.length/8);static#Ri=this.#ki+8*this.numbers.length;static#Li=this.#Ri+1+8;static#Fi=this.#Li+1+48;static#Oi=this.#Fi+1+6;#Mi;#Pi;#Di;constructor({data:t,extra:e}){this.#Mi=t,this.#Pi=new TextDecoder,this.#Di=new DataView(this.#Mi),e&&Object.assign(this,e)}#Bi(t){I(t<me.bools.length,"Invalid boolean index");const e=Math.floor(t/4),i=2*t%8,s=this.#Di.getUint8(e)>>i&3;return 0===s?void 0:2===s}get black(){return this.#Bi(0)}get bold(){return this.#Bi(1)}get disableFontFace(){return this.#Bi(2)}get fontExtraProperties(){return this.#Bi(3)}get isInvalidPDFjsFont(){return this.#Bi(4)}get isType3Font(){return this.#Bi(5)}get italic(){return this.#Bi(6)}get missingFile(){return this.#Bi(7)}get remeasure(){return this.#Bi(8)}get vertical(){return this.#Bi(9)}#Ni(t){return I(t<me.numbers.length,"Invalid number index"),this.#Di.getFloat64(me.#ki+8*t)}get ascent(){return this.#Ni(0)}get defaultWidth(){return this.#Ni(1)}get descent(){return this.#Ni(2)}get bbox(){let t=me.#Ri;const e=this.#Di.getUint8(t);if(0===e)return;t+=1;const i=[];for(let s=0;s<4;s++)i.push(this.#Di.getInt16(t,!0)),t+=2;return i}get fontMatrix(){let t=me.#Li;const e=this.#Di.getUint8(t);if(0===e)return;t+=1;const i=[];for(let s=0;s<6;s++)i.push(this.#Di.getFloat64(t,!0)),t+=8;return i}get defaultVMetrics(){let t=me.#Fi;const e=this.#Di.getUint8(t);if(0===e)return;t+=1;const i=[];for(let s=0;s<3;s++)i.push(this.#Di.getInt16(t,!0)),t+=2;return i}#Ii(t){I(t<me.strings.length,"Invalid string index");let e=me.#Oi+4;for(let n=0;n<t;n++)e+=this.#Di.getUint32(e)+4;const i=this.#Di.getUint32(e),s=new Uint8Array(i);return s.set(new Uint8Array(this.#Mi,e+4,i)),this.#Pi.decode(s)}get fallbackName(){return this.#Ii(0)}get loadedName(){return this.#Ii(1)}get mimetype(){return this.#Ii(2)}get name(){return this.#Ii(3)}get data(){let t=me.#Oi;const e=this.#Di.getUint32(t);t+=4+e;const i=this.#Di.getUint32(t);t+=4+i;const s=this.#Di.getUint32(t);t+=4+s;const n=this.#Di.getUint32(t);if(0!==n)return new Uint8Array(this.#Mi,t+4,n)}clearData(){let t=me.#Oi;const e=this.#Di.getUint32(t);t+=4+e;const i=this.#Di.getUint32(t);t+=4+i;const s=this.#Di.getUint32(t);t+=4+s;const n=this.#Di.getUint32(t),r=new Uint8Array(this.#Mi,t+4,n);r.fill(0),this.#Di.setUint32(t,0)}get cssFontInfo(){let t=me.#Oi;const e=this.#Di.getUint32(t);t+=4+e;const i=this.#Di.getUint32(t);t+=4+i;const s=this.#Di.getUint32(t);if(0===s)return null;const n=new Uint8Array(s);return n.set(new Uint8Array(this.#Mi,t+4,s)),new pe(n.buffer)}get systemFontInfo(){let t=me.#Oi;const e=this.#Di.getUint32(t);t+=4+e;const i=this.#Di.getUint32(t);if(0===i)return null;const s=new Uint8Array(i);return s.set(new Uint8Array(this.#Mi,t+4,i)),new ge(s.buffer)}static write(t){const e=t.systemFontInfo?ge.write(t.systemFontInfo):null,i=t.cssFontInfo?pe.write(t.cssFontInfo):null,s=new TextEncoder,n={};let r=0;for(const g of me.strings)n[g]=s.encode(t[g]),r+=4+n[g].length;const a=me.#Oi+4+r+4+(e?e.byteLength:0)+4+(i?i.byteLength:0)+4+(t.data?t.data.length:0),o=new ArrayBuffer(a),l=new Uint8Array(o),h=new DataView(o);let c=0;const d=me.bools.length;let u=0,p=0;for(let g=0;g<d;g++){const e=t[me.bools[g]],i=void 0===e?0:e?2:1;u|=i<<p,p+=2,8!==p&&g!==d-1||(h.setUint8(c++,u),u=0,p=0)}I(c===me.#ki,"FontInfo.write: Boolean properties offset mismatch");for(const g of me.numbers)h.setFloat64(c,t[g]),c+=8;if(I(c===me.#Ri,"FontInfo.write: Number properties offset mismatch"),t.bbox){h.setUint8(c++,4);for(const e of t.bbox)h.setInt16(c,e,!0),c+=2}else h.setUint8(c++,0),c+=8;if(I(c===me.#Li,"FontInfo.write: BBox properties offset mismatch"),t.fontMatrix){h.setUint8(c++,6);for(const e of t.fontMatrix)h.setFloat64(c,e,!0),c+=8}else h.setUint8(c++,0),c+=48;if(I(c===me.#Fi,"FontInfo.write: FontMatrix properties offset mismatch"),t.defaultVMetrics){h.setUint8(c++,1);for(const e of t.defaultVMetrics)h.setInt16(c,e,!0),c+=2}else h.setUint8(c++,0),c+=6;I(c===me.#Oi,"FontInfo.write: DefaultVMetrics properties offset mismatch"),h.setUint32(me.#Oi,0),c+=4;for(const g of me.strings){const t=n[g],e=t.length;h.setUint32(c,e),l.set(t,c+4),c+=4+e}if(h.setUint32(me.#Oi,c-me.#Oi-4),e){const t=e.byteLength;h.setUint32(c,t),I(c+4+t<=o.byteLength,"FontInfo.write: Buffer overflow at systemFontInfo"),l.set(new Uint8Array(e),c+4),c+=4+t}else h.setUint32(c,0),c+=4;if(i){const t=i.byteLength;h.setUint32(c,t),I(c+4+t<=o.byteLength,"FontInfo.write: Buffer overflow at cssFontInfo"),l.set(new Uint8Array(i),c+4),c+=4+t}else h.setUint32(c,0),c+=4;return void 0===t.data?(h.setUint32(c,0),c+=4):(h.setUint32(c,t.data.length),l.set(t.data,c+4),c+=4+t.data.length),I(c<=o.byteLength,"FontInfo.write: Buffer overflow"),o.transferToFixedLength(c)}}class fe{static#Ui=0;static#ji=1;static#Hi=2;static#zi=3;static#$i=4;static#Gi=8;static#Wi=12;static#Vi=16;constructor(t){this.buffer=t,this.view=new DataView(t),this.data=new Uint8Array(t)}static write(t){let e,i=null,s=[],n=[],r=[],a=[],o=null,l=null;switch(t[0]){case"RadialAxial":e="axial"===t[1]?1:2,i=t[2],r=t[3],1===e?s.push(...t[4],...t[5]):s.push(t[4][0],t[4][1],t[6],t[5][0],t[5][1],t[7]);break;case"Mesh":e=3,o=t[1],s=t[2],n=t[3],a=t[4]||[],i=t[6],l=t[7];break;default:throw new Error(`Unsupported pattern type: ${t[0]}`)}const h=Math.floor(s.length/2),c=Math.floor(n.length/3),d=r.length,u=a.length;let p=0;for(const w of a)p+=1,p=4*Math.ceil(p/4),p+=4+4*w.coords.length,p+=4+4*w.colors.length,void 0!==w.verticesPerRow&&(p+=4);const g=20+8*h+3*c+8*d+(i?16:0)+(l?3:0)+p,m=new ArrayBuffer(g),f=new DataView(m),b=new Uint8Array(m);f.setUint8(fe.#Ui,e),f.setUint8(fe.#ji,i?1:0),f.setUint8(fe.#Hi,l?1:0),f.setUint8(fe.#zi,o),f.setUint32(fe.#$i,h,!0),f.setUint32(fe.#Gi,c,!0),f.setUint32(fe.#Wi,d,!0),f.setUint32(fe.#Vi,u,!0);let v=20;const y=new Float32Array(m,v,2*h);y.set(s),v+=8*h,b.set(n,v),v+=3*c;for(const[w,A]of r)f.setFloat32(v,w,!0),v+=4,f.setUint32(v,parseInt(A.slice(1),16),!0),v+=4;if(i)for(const w of i)f.setFloat32(v,w,!0),v+=4;l&&(b.set(l,v),v+=3);for(let w=0;w<a.length;w++){const t=a[w];f.setUint8(v,t.type),v+=1,v=4*Math.ceil(v/4),f.setUint32(v,t.coords.length,!0),v+=4;const e=new Int32Array(m,v,t.coords.length);e.set(t.coords),v+=4*t.coords.length,f.setUint32(v,t.colors.length,!0),v+=4;const i=new Int32Array(m,v,t.colors.length);i.set(t.colors),v+=4*t.colors.length,void 0!==t.verticesPerRow&&(f.setUint32(v,t.verticesPerRow,!0),v+=4)}return m}getIR(){const t=this.view,e=this.data[fe.#Ui],i=!!this.data[fe.#ji],s=!!this.data[fe.#Hi],n=t.getUint32(fe.#$i,!0),r=t.getUint32(fe.#Gi,!0),a=t.getUint32(fe.#Wi,!0),o=t.getUint32(fe.#Vi,!0);let l=20;const h=new Float32Array(this.buffer,l,2*n);l+=8*n;const c=new Uint8Array(this.buffer,l,3*r);l+=3*r;const d=[];for(let m=0;m<a;++m){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;s&&(p=new Uint8Array(this.buffer,l,3),l+=3);const g=[];for(let m=0;m<o;++m){const e=t.getUint8(l);l+=1,l=4*Math.ceil(l/4);const i=t.getUint32(l,!0);l+=4;const s=new Int32Array(this.buffer,l,i);l+=4*i;const n=t.getUint32(l,!0);l+=4;const r=new Int32Array(this.buffer,l,n);l+=4*n;const a={type:e,coords:s,colors:r};e===f.LATTICE&&(a.verticesPerRow=t.getUint32(l,!0),l+=4),g.push(a)}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[fe.#zi];let e=null;if(h.length>0){let t=h[0],i=h[0],s=h[1],n=h[1];for(let e=0;e<h.length;e+=2){const r=h[e],a=h[e+1];t=t>r?r:t,s=s>a?a:s,i=i<r?r:i,n=n<a?a:n}e=[t,s,i,n]}return["Mesh",t,h,c,g,e,u,p]}throw new Error(`Unsupported pattern kind: ${e}`)}}class be{static write(t){let e,i;return X.isFloat16ArraySupported?(i=new ArrayBuffer(2*t.length),e=new Float16Array(i)):(i=new ArrayBuffer(4*t.length),e=new Float32Array(i)),e.set(t),i}#Mi;constructor(t){this.#Mi=t}get path(){return X.isFloat16ArraySupported?new Float16Array(this.#Mi):new Float32Array(this.#Mi)}}function ve(t){if(t instanceof URL)return t.href;if("string"===typeof t){if(o)return t;const e=URL.parse(t,window.location);if(e)return e.href}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function ye(t){if(o&&"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 G(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.")}function we(t){if("string"!==typeof t)return null;if(t.endsWith("/"))return t;throw new Error(`Invalid factory url: "${t}" must include trailing slash.`)}const Ae=t=>"object"===typeof t&&Number.isInteger(t?.num)&&t.num>=0&&Number.isInteger(t?.gen)&&t.gen>=0,xe=t=>"object"===typeof t&&"string"===typeof t?.name,_e=st.bind(null,Ae,xe);class Se{#qi=new Map;#Xi=Promise.resolve();postMessage(t,e){const i={data:structuredClone(t,e?{transfer:e}:null)};this.#Xi.then(()=>{for(const[t]of this.#qi)t.call(this,i)})}addEventListener(t,e,i=null){let s=null;if(i?.signal instanceof AbortSignal){const{signal:n}=i;if(n.aborted)return void D("LoopbackPort - cannot use an `aborted` signal.");const r=()=>this.removeEventListener(t,e);s=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}this.#qi.set(e,s)}removeEventListener(t,e){const i=this.#qi.get(e);i?.(),this.#qi.delete(e)}terminate(){for(const[,t]of this.#qi)t?.();this.#qi.clear()}}const Ee={DATA:1,ERROR:2},Ce={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function Te(){}function Me(t){if(t instanceof z||t instanceof U||t instanceof B||t instanceof j||t instanceof N)return t;switch(t instanceof Error||"object"===typeof t&&null!==t||P('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),t.name){case"AbortException":return new z(t.message);case"InvalidPDFException":return new U(t.message);case"PasswordException":return new B(t.message,t.code);case"ResponseException":return new j(t.message,t.status,t.missing);case"UnknownErrorException":return new N(t.message,t.details)}return new N(t.message,t.toString())}class De{#Yi=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.#Ki.bind(this),{signal:this.#Yi.signal})}#Ki({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream)return void this.#Qi(t);if(t.callback){const e=t.callbackId,i=this.callbackCapabilities[e];if(!i)throw new Error(`Cannot resolve callback ${e}`);if(delete this.callbackCapabilities[e],t.callback===Ee.DATA)i.resolve(t.data);else{if(t.callback!==Ee.ERROR)throw new Error("Unexpected callback case");i.reject(Me(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,s=t.sourceName,n=this.comObj;return void Promise.try(e,t.data).then(function(e){n.postMessage({sourceName:i,targetName:s,callback:Ee.DATA,callbackId:t.callbackId,data:e})},function(e){n.postMessage({sourceName:i,targetName:s,callback:Ee.ERROR,callbackId:t.callbackId,reason:Me(e)})})}t.streamId?this.#Ji(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 s=this.callbackId++,n=Promise.withResolvers();this.callbackCapabilities[s]=n;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,callbackId:s,data:e},i)}catch(r){n.reject(r)}return n.promise}sendWithStream(t,e,i,s){const n=this.streamId++,r=this.sourceName,a=this.targetName,o=this.comObj;return new ReadableStream({start:i=>{const l=Promise.withResolvers();return this.streamControllers[n]={controller:i,startCall:l,pullCall:null,cancelCall:null,isClosed:!1},o.postMessage({sourceName:r,targetName:a,action:t,streamId:n,data:e,desiredSize:i.desiredSize},s),l.promise},pull:t=>{const e=Promise.withResolvers();return this.streamControllers[n].pullCall=e,o.postMessage({sourceName:r,targetName:a,stream:Ce.PULL,streamId:n,desiredSize:t.desiredSize}),e.promise},cancel:t=>{I(t instanceof Error,"cancel must have a valid reason");const e=Promise.withResolvers();return this.streamControllers[n].cancelCall=e,this.streamControllers[n].isClosed=!0,o.postMessage({sourceName:r,targetName:a,stream:Ce.CANCEL,streamId:n,reason:Me(t)}),e.promise}},i)}#Ji(t){const e=t.streamId,i=this.sourceName,s=t.sourceName,n=this.comObj,r=this,a=this.actionHandler[t.action],o={enqueue(t,r=1,a){if(this.isCancelled)return;const o=this.desiredSize;this.desiredSize-=r,o>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:i,targetName:s,stream:Ce.ENQUEUE,streamId:e,chunk:t},a)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:i,targetName:s,stream:Ce.CLOSE,streamId:e}),delete r.streamSinks[e])},error(t){I(t instanceof Error,"error must have a valid reason"),this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:i,targetName:s,stream:Ce.ERROR,streamId:e,reason:Me(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(){n.postMessage({sourceName:i,targetName:s,stream:Ce.START_COMPLETE,streamId:e,success:!0})},function(t){n.postMessage({sourceName:i,targetName:s,stream:Ce.START_COMPLETE,streamId:e,reason:Me(t)})})}#Qi(t){const e=t.streamId,i=this.sourceName,s=t.sourceName,n=this.comObj,r=this.streamControllers[e],a=this.streamSinks[e];switch(t.stream){case Ce.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(Me(t.reason));break;case Ce.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(Me(t.reason));break;case Ce.PULL:if(!a){n.postMessage({sourceName:i,targetName:s,stream:Ce.PULL_COMPLETE,streamId:e,success:!0});break}a.desiredSize<=0&&t.desiredSize>0&&a.sinkCapability.resolve(),a.desiredSize=t.desiredSize,Promise.try(a.onPull||Te).then(function(){n.postMessage({sourceName:i,targetName:s,stream:Ce.PULL_COMPLETE,streamId:e,success:!0})},function(t){n.postMessage({sourceName:i,targetName:s,stream:Ce.PULL_COMPLETE,streamId:e,reason:Me(t)})});break;case Ce.ENQUEUE:if(I(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case Ce.CLOSE:if(I(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),this.#Zi(r,e);break;case Ce.ERROR:I(r,"error should have stream controller"),r.controller.error(Me(t.reason)),this.#Zi(r,e);break;case Ce.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(Me(t.reason)),this.#Zi(r,e);break;case Ce.CANCEL:if(!a)break;const o=Me(t.reason);Promise.try(a.onCancel||Te,o).then(function(){n.postMessage({sourceName:i,targetName:s,stream:Ce.CANCEL_COMPLETE,streamId:e,success:!0})},function(t){n.postMessage({sourceName:i,targetName:s,stream:Ce.CANCEL_COMPLETE,streamId:e,reason:Me(t)})}),a.sinkCapability.reject(o),a.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}}async#Zi(t,e){await Promise.allSettled([t.startCall?.promise,t.pullCall?.promise,t.cancelCall?.promise]),delete this.streamControllers[e]}destroy(){this.#Yi?.abort(),this.#Yi=null}}class Pe{#ts=!1;constructor({enableHWA:t=!1}){this.#ts=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.#ts})}}reset(t,e,i){if(!t.canvas)throw new Error("Canvas is not specified");if(e<=0||i<=0)throw new Error("Invalid canvas size");t.canvas.width=e,t.canvas.height=i}destroy(t){if(!t.canvas)throw new Error("Canvas is not specified");t.canvas.width=0,t.canvas.height=0,t.canvas=null,t.context=null}_createCanvas(t,e){P("Abstract method `_createCanvas` called.")}}class Ie extends Pe{constructor({ownerDocument:t=globalThis.document,enableHWA:e=!1}){super({enableHWA:e}),this._document=t}_createCanvas(t,e){const i=this._document.createElement("canvas");return i.width=t,i.height=e,i}}class ke{constructor({baseUrl:t=null,isCompressed:e=!0}){this.baseUrl=t,this.isCompressed=e}async fetch({name:t}){if(!this.baseUrl)throw new Error("Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided.");if(!t)throw new Error("CMap name must be specified.");const e=this.baseUrl+t+(this.isCompressed?".bcmap":"");return this._fetch(e).then(t=>({cMapData:t,isCompressed:this.isCompressed})).catch(t=>{throw new Error(`Unable to load ${this.isCompressed?"binary ":""}CMap at: ${e}`)})}async _fetch(t){P("Abstract method `_fetch` called.")}}class Re extends ke{async _fetch(t){const e=await dt(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):G(e)}}class Le{addFilter(t){return"none"}addHCMFilter(t,e){return"none"}addAlphaFilter(t){return"none"}addLuminosityFilter(t){return"none"}addHighlightHCMFilter(t,e,i,s,n){return"none"}destroy(t=!1){}}class Fe extends Le{#es;#is;#ss;#ns;#rs;#as;#E=0;constructor({docId:t,ownerDocument:e=globalThis.document}){super(),this.#ns=t,this.#rs=e}get#T(){return this.#is||=new Map}get#os(){return this.#as||=new Map}get#ls(){if(!this.#ss){const t=this.#rs.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.#rs.createElementNS(ht,"svg");i.setAttribute("width",0),i.setAttribute("height",0),this.#ss=this.#rs.createElementNS(ht,"defs"),t.append(i),i.append(this.#ss),this.#rs.body.append(t)}return this.#ss}#hs(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 s=i.join(",");return[s,s,s]}const[e,i,s]=t,n=new Array(256),r=new Array(256),a=new Array(256);for(let o=0;o<256;o++)n[o]=e[o]/255,r[o]=i[o]/255,a[o]=s[o]/255;return[n.join(","),r.join(","),a.join(",")]}#cs(t){if(void 0===this.#es){this.#es="";const t=this.#rs.URL;t!==this.#rs.baseURI&&(gt(t)?D('#createUrl: ignore "data:"-URL for performance reasons.'):this.#es=L(t,""))}return`url(${this.#es}#${t})`}addFilter(t){if(!t)return"none";let e=this.#T.get(t);if(e)return e;const[i,s,n]=this.#hs(t),r=1===t.length?i:`${i}${s}${n}`;if(e=this.#T.get(r),e)return this.#T.set(t,e),e;const a=`g_${this.#ns}_transfer_map_${this.#E++}`,o=this.#cs(a);this.#T.set(t,o),this.#T.set(r,o);const l=this.#ds(a);return this.#us(i,s,n,l),o}addHCMFilter(t,e){const i=`${t}-${e}`,s="base";let n=this.#os.get(s);if(n?.key===i)return n.url;if(n?(n.filter?.remove(),n.key=i,n.url="none",n.filter=null):(n={key:i,url:"none",filter:null},this.#os.set(s,n)),!t||!e)return n.url;const r=this.#ps(t);t=K.makeHexColor(...r);const a=this.#ps(e);if(e=K.makeHexColor(...a),this.#ls.style.color="","#000000"===t&&"#ffffff"===e||t===e)return n.url;const o=new Array(256);for(let u=0;u<=255;u++){const t=u/255;o[u]=t<=.03928?t/12.92:((t+.055)/1.055)**2.4}const l=o.join(","),h=`g_${this.#ns}_hcm_filter`,c=n.filter=this.#ds(h);this.#us(l,l,l,c),this.#gs(c);const d=(t,e)=>{const i=r[t]/255,s=a[t]/255,n=new Array(e+1);for(let r=0;r<=e;r++)n[r]=i+r/e*(s-i);return n.join(",")};return this.#us(d(0,5),d(1,5),d(2,5),c),n.url=this.#cs(h),n.url}addAlphaFilter(t){let e=this.#T.get(t);if(e)return e;const[i]=this.#hs([t]),s=`alpha_${i}`;if(e=this.#T.get(s),e)return this.#T.set(t,e),e;const n=`g_${this.#ns}_alpha_map_${this.#E++}`,r=this.#cs(n);this.#T.set(t,r),this.#T.set(s,r);const a=this.#ds(n);return this.#ms(i,a),r}addLuminosityFilter(t){let e,i,s=this.#T.get(t||"luminosity");if(s)return s;if(t?([e]=this.#hs([t]),i=`luminosity_${e}`):i="luminosity",s=this.#T.get(i),s)return this.#T.set(t,s),s;const n=`g_${this.#ns}_luminosity_map_${this.#E++}`,r=this.#cs(n);this.#T.set(t,r),this.#T.set(i,r);const a=this.#ds(n);return this.#fs(a),t&&this.#ms(e,a),r}addHighlightHCMFilter(t,e,i,s,n){const r=`${e}-${i}-${s}-${n}`;let a=this.#os.get(t);if(a?.key===r)return a.url;if(a?(a.filter?.remove(),a.key=r,a.url="none",a.filter=null):(a={key:r,url:"none",filter:null},this.#os.set(t,a)),!e||!i)return a.url;const[o,l]=[e,i].map(this.#ps.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]=[s,n].map(this.#ps.bind(this));c<h&&([h,c,d,u]=[c,h,u,d]),this.#ls.style.color="";const p=(t,e,i)=>{const s=new Array(256),n=(c-h)/i,r=t/255,a=(e-t)/(255*i);let o=0;for(let l=0;l<=i;l++){const t=Math.round(h+l*n),e=r+l*a;for(let i=o;i<=t;i++)s[i]=e;o=t+1}for(let l=o;l<256;l++)s[l]=s[o-1];return s.join(",")},g=`g_${this.#ns}_hcm_${t}_filter`,m=a.filter=this.#ds(g);return this.#gs(m),this.#us(p(d[0],u[0],5),p(d[1],u[1],5),p(d[2],u[2],5),m),a.url=this.#cs(g),a.url}destroy(t=!1){t&&this.#as?.size||(this.#ss?.parentNode.parentNode.remove(),this.#ss=null,this.#is?.clear(),this.#is=null,this.#as?.clear(),this.#as=null,this.#E=0)}#fs(t){const e=this.#rs.createElementNS(ht,"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)}#gs(t){const e=this.#rs.createElementNS(ht,"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)}#ds(t){const e=this.#rs.createElementNS(ht,"filter");return e.setAttribute("color-interpolation-filters","sRGB"),e.setAttribute("id",t),this.#ls.append(e),e}#bs(t,e,i){const s=this.#rs.createElementNS(ht,e);s.setAttribute("type","discrete"),s.setAttribute("tableValues",i),t.append(s)}#us(t,e,i,s){const n=this.#rs.createElementNS(ht,"feComponentTransfer");s.append(n),this.#bs(n,"feFuncR",t),this.#bs(n,"feFuncG",e),this.#bs(n,"feFuncB",i)}#ms(t,e){const i=this.#rs.createElementNS(ht,"feComponentTransfer");e.append(i),this.#bs(i,"feFuncA",t)}#ps(t){return this.#ls.style.color=t,Et(getComputedStyle(this.#ls).getPropertyValue("color"))}}class Oe{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `standardFontDataUrl` API parameter is provided.");if(!t)throw new Error("Font filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch(t=>{throw new Error(`Unable to load font data at: ${e}`)})}async _fetch(t){P("Abstract method `_fetch` called.")}}class Be extends Oe{async _fetch(t){const e=await dt(t,"arraybuffer");return new Uint8Array(e)}}class Ne{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `wasmUrl` API parameter is provided.");if(!t)throw new Error("Wasm filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch(t=>{throw new Error(`Unable to load wasm data at: ${e}`)})}async _fetch(t){P("Abstract method `_fetch` called.")}}class Ue extends Ne{async _fetch(t){const e=await dt(t,"arraybuffer");return new Uint8Array(e)}}async function je(t){const e=process.getBuiltinModule("fs"),i=await e.promises.readFile(t);return new Uint8Array(i)}o&&D("Please use the `legacy` build in Node.js environments.");class He extends Le{}class ze extends Pe{_createCanvas(t,e){const i=process.getBuiltinModule("module").createRequire("file:///home/runner/work/pdf-elements/pdf-elements/node_modules/pdfjs-dist/build/pdf.mjs"),s=i("@napi-rs/canvas");return s.createCanvas(t,e)}}class $e extends ke{async _fetch(t){return je(t)}}class Ge extends Oe{async _fetch(t){return je(t)}}class We extends Ne{async _fetch(t){return je(t)}}const Ve="__forcedDependency",{floor:qe,ceil:Xe}=Math;function Ye(t,e,i,s,n,r){t[4*e+0]=Math.min(t[4*e+0],i),t[4*e+1]=Math.min(t[4*e+1],s),t[4*e+2]=Math.max(t[4*e+2],n),t[4*e+3]=Math.max(t[4*e+3],r)}const Ke=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0];class Qe{#vs;#ys;constructor(t,e){this.#vs=t,this.#ys=e}get length(){return this.#vs.length}isEmpty(t){return this.#vs[t]===Ke}minX(t){return this.#ys[4*t+0]/256}minY(t){return this.#ys[4*t+1]/256}maxX(t){return(this.#ys[4*t+2]+1)/256}maxY(t){return(this.#ys[4*t+3]+1)/256}}const Je=(t,e)=>{if(!t)return;let i=t.get(e);return i||(i={dependencies:new Set,isRenderingOperation:!1},t.set(e,i)),i};class Ze{#ws={__proto__:null};#As={__proto__:null,transform:[],moveText:[],sameLineText:[],[Ve]:[]};#xs=new Map;#_s=[];#Ss=[];#Es=[[1,0,0,1,0,0]];#Cs=[-1/0,-1/0,1/0,1/0];#Ts=new Float64Array([1/0,1/0,-1/0,-1/0]);#Ms=-1;#Ds=new Set;#Ps=new Map;#Is=new Map;#ks;#Rs;#Ls;#vs;#Fs;constructor(t,e,i=!1){this.#ks=t.width,this.#Rs=t.height,this.#Os(e),i&&(this.#Fs=new Map)}growOperationsCount(t){t>=this.#vs.length&&this.#Os(t,this.#vs)}#Os(t,e){const i=new ArrayBuffer(4*t);this.#Ls=new Uint8ClampedArray(i),this.#vs=new Uint32Array(i),e&&e.length>0?(this.#vs.set(e),this.#vs.fill(Ke,e.length)):this.#vs.fill(Ke)}save(t){return this.#ws={__proto__:this.#ws},this.#As={__proto__:this.#As,transform:{__proto__:this.#As.transform},moveText:{__proto__:this.#As.moveText},sameLineText:{__proto__:this.#As.sameLineText},[Ve]:{__proto__:this.#As[Ve]}},this.#Cs={__proto__:this.#Cs},this.#_s.push(t),this}restore(t){const e=Object.getPrototypeOf(this.#ws);if(null===e)return this;this.#ws=e,this.#As=Object.getPrototypeOf(this.#As),this.#Cs=Object.getPrototypeOf(this.#Cs);const i=this.#_s.pop();return void 0!==i&&(Je(this.#Fs,t)?.dependencies.add(i),this.#vs[t]=this.#vs[i]),this}recordOpenMarker(t){return this.#_s.push(t),this}getOpenMarker(){return 0===this.#_s.length?null:this.#_s.at(-1)}recordCloseMarker(t){const e=this.#_s.pop();return void 0!==e&&(Je(this.#Fs,t)?.dependencies.add(e),this.#vs[t]=this.#vs[e]),this}beginMarkedContent(t){return this.#Ss.push(t),this}endMarkedContent(t){const e=this.#Ss.pop();return void 0!==e&&(Je(this.#Fs,t)?.dependencies.add(e),this.#vs[t]=this.#vs[e]),this}pushBaseTransform(t){return this.#Es.push(K.multiplyByDOMMatrix(this.#Es.at(-1),t.getTransform())),this}popBaseTransform(){return this.#Es.length>1&&this.#Es.pop(),this}recordSimpleData(t,e){return this.#ws[t]=e,this}recordIncrementalData(t,e){return this.#As[t].push(e),this}resetIncrementalData(t,e){return this.#As[t].length=0,this}recordNamedData(t,e){return this.#xs.set(t,e),this}recordSimpleDataFromNamed(t,e,i){this.#ws[t]=this.#xs.get(e)??i}recordFutureForcedDependency(t,e){return this.recordIncrementalData(Ve,e),this}inheritSimpleDataAsFutureForcedDependencies(t){for(const e of t)e in this.#ws&&this.recordFutureForcedDependency(e,this.#ws[e]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(const t of this.#Ds)this.recordFutureForcedDependency(Ve,t);return this}resetBBox(t){return this.#Ms!==t&&(this.#Ms=t,this.#Ts[0]=1/0,this.#Ts[1]=1/0,this.#Ts[2]=-1/0,this.#Ts[3]=-1/0),this}recordClipBox(t,e,i,s,n,r){const a=K.multiplyByDOMMatrix(this.#Es.at(-1),e.getTransform()),o=[1/0,1/0,-1/0,-1/0];K.axialAlignedBoundingBox([i,n,s,r],a,o);const l=K.intersect(this.#Cs,o);return l?(this.#Cs[0]=l[0],this.#Cs[1]=l[1],this.#Cs[2]=l[2],this.#Cs[3]=l[3]):(this.#Cs[0]=this.#Cs[1]=1/0,this.#Cs[2]=this.#Cs[3]=-1/0),this}recordBBox(t,e,i,s,n,r){const a=this.#Cs;if(a[0]===1/0)return this;const o=K.multiplyByDOMMatrix(this.#Es.at(-1),e.getTransform());if(a[0]===-1/0)return K.axialAlignedBoundingBox([i,n,s,r],o,this.#Ts),this;const l=[1/0,1/0,-1/0,-1/0];return K.axialAlignedBoundingBox([i,n,s,r],o,l),this.#Ts[0]=Math.min(this.#Ts[0],Math.max(l[0],a[0])),this.#Ts[1]=Math.min(this.#Ts[1],Math.max(l[1],a[1])),this.#Ts[2]=Math.max(this.#Ts[2],Math.min(l[2],a[2])),this.#Ts[3]=Math.max(this.#Ts[3],Math.min(l[3],a[3])),this}recordCharacterBBox(t,e,i,s=1,n=0,r=0,a){const o=i.bbox;let l,h;if(o&&(l=o[2]!==o[0]&&o[3]!==o[1]&&this.#Is.get(i),!1!==l&&(h=[0,0,0,0],K.axialAlignedBoundingBox(o,i.fontMatrix,h),1===s&&0===n&&0===r||K.scaleMinMax([s,0,0,-s,n,r],h),l)))return this.recordBBox(t,e,h[0],h[2],h[1],h[3]);if(!a)return this.recordFullPageBBox(t);const c=a();return o&&h&&void 0===l&&(l=h[0]<=n-c.actualBoundingBoxLeft&&h[2]>=n+c.actualBoundingBoxRight&&h[1]<=r-c.actualBoundingBoxAscent&&h[3]>=r+c.actualBoundingBoxDescent,this.#Is.set(i,l),l)?this.recordBBox(t,e,h[0],h[2],h[1],h[3]):this.recordBBox(t,e,n-c.actualBoundingBoxLeft,n+c.actualBoundingBoxRight,r-c.actualBoundingBoxAscent,r+c.actualBoundingBoxDescent)}recordFullPageBBox(t){return this.#Ts[0]=Math.max(0,this.#Cs[0]),this.#Ts[1]=Math.max(0,this.#Cs[1]),this.#Ts[2]=Math.min(this.#ks,this.#Cs[2]),this.#Ts[3]=Math.min(this.#Rs,this.#Cs[3]),this}getSimpleIndex(t){return this.#ws[t]}recordDependencies(t,e){const i=this.#Ds,s=this.#ws,n=this.#As;for(const r of e)r in this.#ws?i.add(s[r]):r in n&&n[r].forEach(i.add,i);return this}recordNamedDependency(t,e){return this.#xs.has(e)&&this.#Ds.add(this.#xs.get(e)),this}recordOperation(t,e=!1){if(this.recordDependencies(t,[Ve]),this.#Fs){const e=Je(this.#Fs,t),{dependencies:i}=e;this.#Ds.forEach(i.add,i),this.#_s.forEach(i.add,i),this.#Ss.forEach(i.add,i),i.delete(t),e.isRenderingOperation=!0}if(this.#Ms===t){const i=qe(256*this.#Ts[0]/this.#ks),s=qe(256*this.#Ts[1]/this.#Rs),n=Xe(256*this.#Ts[2]/this.#ks),r=Xe(256*this.#Ts[3]/this.#Rs);Ye(this.#Ls,t,i,s,n,r);for(const e of this.#Ds)e!==t&&Ye(this.#Ls,e,i,s,n,r);for(const e of this.#_s)e!==t&&Ye(this.#Ls,e,i,s,n,r);for(const e of this.#Ss)e!==t&&Ye(this.#Ls,e,i,s,n,r);e||(this.#Ds.clear(),this.#Ms=-1)}return this}recordShowTextOperation(t,e=!1){const i=Array.from(this.#Ds);this.recordOperation(t,e),this.recordIncrementalData("sameLineText",t);for(const s of i)this.recordIncrementalData("sameLineText",s);return this}bboxToClipBoxDropOperation(t,e=!1){return this.#Ms===t&&(this.#Ms=-1,this.#Cs[0]=Math.max(this.#Cs[0],this.#Ts[0]),this.#Cs[1]=Math.max(this.#Cs[1],this.#Ts[1]),this.#Cs[2]=Math.min(this.#Cs[2],this.#Ts[2]),this.#Cs[3]=Math.min(this.#Cs[3],this.#Ts[3]),e||this.#Ds.clear()),this}_takePendingDependencies(){const t=this.#Ds;return this.#Ds=new Set,t}_extractOperation(t){const e=this.#Ps.get(t);return this.#Ps.delete(t),e}_pushPendingDependencies(t){for(const e of t)this.#Ds.add(e)}take(){return this.#Is.clear(),new Qe(this.#vs,this.#Ls)}takeDebugMetadata(){return this.#Fs}}class ti{#Bs;#Ns;#Us;#js=0;#Hs=0;constructor(t,e,i){if(t instanceof ti&&t.#Us===!!i)return t;this.#Bs=t,this.#Ns=e,this.#Us=!!i}growOperationsCount(){throw new Error("Unreachable")}save(t){return this.#Hs++,this.#Bs.save(this.#Ns),this}restore(t){return this.#Hs>0&&(this.#Bs.restore(this.#Ns),this.#Hs--),this}recordOpenMarker(t){return this.#js++,this}getOpenMarker(){return this.#js>0?this.#Ns:this.#Bs.getOpenMarker()}recordCloseMarker(t){return this.#js--,this}beginMarkedContent(t){return this}endMarkedContent(t){return this}pushBaseTransform(t){return this.#Bs.pushBaseTransform(t),this}popBaseTransform(){return this.#Bs.popBaseTransform(),this}recordSimpleData(t,e){return this.#Bs.recordSimpleData(t,this.#Ns),this}recordIncrementalData(t,e){return this.#Bs.recordIncrementalData(t,this.#Ns),this}resetIncrementalData(t,e){return this.#Bs.resetIncrementalData(t,this.#Ns),this}recordNamedData(t,e){return this}recordSimpleDataFromNamed(t,e,i){return this.#Bs.recordSimpleDataFromNamed(t,e,this.#Ns),this}recordFutureForcedDependency(t,e){return this.#Bs.recordFutureForcedDependency(t,this.#Ns),this}inheritSimpleDataAsFutureForcedDependencies(t){return this.#Bs.inheritSimpleDataAsFutureForcedDependencies(t),this}inheritPendingDependenciesAsFutureForcedDependencies(){return this.#Bs.inheritPendingDependenciesAsFutureForcedDependencies(),this}resetBBox(t){return this.#Us||this.#Bs.resetBBox(this.#Ns),this}recordClipBox(t,e,i,s,n,r){return this.#Us||this.#Bs.recordClipBox(this.#Ns,e,i,s,n,r),this}recordBBox(t,e,i,s,n,r){return this.#Us||this.#Bs.recordBBox(this.#Ns,e,i,s,n,r),this}recordCharacterBBox(t,e,i,s,n,r,a){return this.#Us||this.#Bs.recordCharacterBBox(this.#Ns,e,i,s,n,r,a),this}recordFullPageBBox(t){return this.#Us||this.#Bs.recordFullPageBBox(this.#Ns),this}getSimpleIndex(t){return this.#Bs.getSimpleIndex(t)}recordDependencies(t,e){return this.#Bs.recordDependencies(this.#Ns,e),this}recordNamedDependency(t,e){return this.#Bs.recordNamedDependency(this.#Ns,e),this}recordOperation(t){return this.#Bs.recordOperation(this.#Ns,!0),this}recordShowTextOperation(t){return this.#Bs.recordShowTextOperation(this.#Ns,!0),this}bboxToClipBoxDropOperation(t){return this.#Us||this.#Bs.bboxToClipBoxDropOperation(this.#Ns,!0),this}take(){throw new Error("Unreachable")}takeDebugMetadata(){throw new Error("Unreachable")}}const ei={stroke:["path","transform","filter","strokeColor","strokeAlpha","lineWidth","lineCap","lineJoin","miterLimit","dash"],fill:["path","transform","filter","fillColor","fillAlpha","globalCompositeOperation","SMask"],imageXObject:["transform","SMask","filter","fillAlpha","strokeAlpha","globalCompositeOperation"],rawFillPath:["filter","fillColor","fillAlpha"],showText:["transform","leading","charSpacing","wordSpacing","hScale","textRise","moveText","textMatrix","font","fontObj","filter","fillColor","textRenderingMode","SMask","fillAlpha","strokeAlpha","globalCompositeOperation","sameLineText"],transform:["transform"],transformAndFill:["transform","fillColor"]},ii={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function si(t,e){if(!e)return;const i=e[2]-e[0],s=e[3]-e[1],n=new Path2D;n.rect(e[0],e[1],i,s),t.clip(n)}class ni{isModifyingCurrentTransform(){return!1}getPattern(){P("Abstract method `getPattern` called.")}}class ri extends ni{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}_createGradient(t,e=null){let i,s=this._p0,n=this._p1;if(e&&(s=s.slice(),n=n.slice(),K.applyTransform(s,e),K.applyTransform(n,e)),"axial"===this._type)i=t.createLinearGradient(s[0],s[1],n[0],n[1]);else if("radial"===this._type){let r=this._r0,a=this._r1;if(e){const t=new Float32Array(2);K.singularValueDecompose2dScale(e,t),r*=t[0],a*=t[0]}i=t.createRadialGradient(s[0],s[1],r,n[0],n[1],a)}for(const r of this._colorStops)i.addColorStop(r[0],r[1]);return i}getPattern(t,e,i,s){let n;if(s===ii.STROKE||s===ii.FILL){if(this.isOriginBased()){let s=K.transform(i,e.baseTransform);this.matrix&&(s=K.transform(s,this.matrix));const n=.001,r=Math.hypot(s[0],s[1]),a=Math.hypot(s[2],s[3]),o=(s[0]*s[2]+s[1]*s[3])/(r*a);if(Math.abs(o)<n){if(!this.isRadial())return this._createGradient(t,s);if(Math.abs(r-a)<n)return this._createGradient(t,s)}}const r=e.current.getClippedPathBoundingBox(s,Tt(t))||[0,0,0,0],a=Math.ceil(r[2]-r[0])||1,o=Math.ceil(r[3]-r[1])||1,l=e.cachedCanvases.getCanvas("pattern",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(-r[0],-r[1]),i=K.transform(i,[1,0,0,1,r[0],r[1]]),h.transform(...e.baseTransform),this.matrix&&h.transform(...this.matrix),si(h,this._bbox),h.fillStyle=this._createGradient(h),h.fill(),n=t.createPattern(l.canvas,"no-repeat");const c=new DOMMatrix(i);n.setTransform(c)}else si(t,this._bbox),n=this._createGradient(t);return n}}function ai(t,e,i,s,n,r,a,o){const l=e.coords,h=e.colors,c=t.data,d=4*t.width;let u;l[i+1]>l[s+1]&&(u=i,i=s,s=u,u=r,r=a,a=u),l[s+1]>l[n+1]&&(u=s,s=n,n=u,u=a,a=o,o=u),l[i+1]>l[s+1]&&(u=i,i=s,s=u,u=r,r=a,a=u);const p=(l[i]+e.offsetX)*e.scaleX,g=(l[i+1]+e.offsetY)*e.scaleY,m=(l[s]+e.offsetX)*e.scaleX,f=(l[s+1]+e.offsetY)*e.scaleY,b=(l[n]+e.offsetX)*e.scaleX,v=(l[n+1]+e.offsetY)*e.scaleY;if(g>=v)return;const y=h[r],w=h[r+1],A=h[r+2],x=h[a],_=h[a+1],S=h[a+2],E=h[o],C=h[o+1],T=h[o+2],M=Math.round(g),D=Math.round(v);let P,I,k,R,L,F,O,B;for(let N=M;N<=D;N++){if(N<f){const t=N<g?0:(g-N)/(g-f);P=p-(p-m)*t,I=y-(y-x)*t,k=w-(w-_)*t,R=A-(A-S)*t}else{let t;t=N>v?1:f===v?0:(f-N)/(f-v),P=m-(m-b)*t,I=x-(x-E)*t,k=_-(_-C)*t,R=S-(S-T)*t}let t;t=N<g?0:N>v?1:(g-N)/(g-v),L=p-(p-b)*t,F=y-(y-E)*t,O=w-(w-C)*t,B=A-(A-T)*t;const e=Math.round(Math.min(P,L)),i=Math.round(Math.max(P,L));let s=d*N+4*e;for(let n=e;n<=i;n++)t=(P-n)/(P-L),t<0?t=0:t>1&&(t=1),c[s++]=I-(I-F)*t|0,c[s++]=k-(k-O)*t|0,c[s++]=R-(R-B)*t|0,c[s++]=255}}function oi(t,e,i){const s=e.coords,n=e.colors;let r,a;switch(e.type){case f.LATTICE:const o=e.verticesPerRow,l=Math.floor(s.length/o)-1,h=o-1;for(r=0;r<l;r++){let e=r*o;for(let r=0;r<h;r++,e++)ai(t,i,s[e],s[e+1],s[e+o],n[e],n[e+1],n[e+o]),ai(t,i,s[e+o+1],s[e+1],s[e+o],n[e+o+1],n[e+1],n[e+o])}break;case f.TRIANGLES:for(r=0,a=s.length;r<a;r+=3)ai(t,i,s[r],s[r+1],s[r+2],n[r],n[r+1],n[r+2]);break;default:throw new Error("illegal figure")}}class li extends ni{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[6],this._background=t[7],this.matrix=null}_createMeshCanvas(t,e,i){const s=1.1,n=3e3,r=2,a=Math.floor(this._bounds[0]),o=Math.floor(this._bounds[1]),l=Math.ceil(this._bounds[2])-a,h=Math.ceil(this._bounds[3])-o,c=Math.min(Math.ceil(Math.abs(l*t[0]*s)),n),d=Math.min(Math.ceil(Math.abs(h*t[1]*s)),n),u=l/c,p=h/d,g={coords:this._coords,colors:this._colors,offsetX:-a,offsetY:-o,scaleX:1/u,scaleY:1/p},m=c+2*r,f=d+2*r,b=i.getCanvas("mesh",m,f),v=b.context,y=v.createImageData(c,d);if(e){const t=y.data;for(let i=0,s=t.length;i<s;i+=4)t[i]=e[0],t[i+1]=e[1],t[i+2]=e[2],t[i+3]=255}for(const A of this._figures)oi(y,A,g);v.putImageData(y,r,r);const w=b.canvas;return{canvas:w,offsetX:a-r*u,offsetY:o-r*p,scaleX:u,scaleY:p}}isModifyingCurrentTransform(){return!0}getPattern(t,e,i,s){si(t,this._bbox);const n=new Float32Array(2);if(s===ii.SHADING)K.singularValueDecompose2dScale(Tt(t),n);else if(this.matrix){K.singularValueDecompose2dScale(this.matrix,n);const[t,i]=n;K.singularValueDecompose2dScale(e.baseTransform,n),n[0]*=t,n[1]*=i}else K.singularValueDecompose2dScale(e.baseTransform,n);const r=this._createMeshCanvas(n,s===ii.SHADING?null:this._background,e.cachedCanvases);return s!==ii.SHADING&&(t.setTransform(...e.baseTransform),this.matrix&&t.transform(...this.matrix)),t.translate(r.offsetX,r.offsetY),t.scale(r.scaleX,r.scaleY),t.createPattern(r.canvas,"no-repeat")}}class hi extends ni{getPattern(){return"hotpink"}}function ci(t){switch(t[0]){case"RadialAxial":return new ri(t);case"Mesh":return new li(t);case"Dummy":return new hi}throw new Error(`Unknown IR type: ${t[0]}`)}const di={COLORED:1,UNCOLORED:2};class ui{static MAX_PATTERN_SIZE=3e3;constructor(t,e,i,s){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.ctx=e,this.canvasGraphicsFactory=i,this.baseTransform=s}createPatternCanvas(t,e){const{bbox:i,operatorList:s,paintType:n,tilingType:r,color:a,canvasGraphicsFactory:o}=this;let{xstep:l,ystep:h}=this;l=Math.abs(l),h=Math.abs(h),M("TilingType: "+r);const c=i[0],d=i[1],u=i[2],p=i[3],g=u-c,m=p-d,f=new Float32Array(2);K.singularValueDecompose2dScale(this.matrix,f);const[b,v]=f;K.singularValueDecompose2dScale(this.baseTransform,f);const y=b*f[0],w=v*f[1];let A=g,x=m,_=!1,S=!1;const E=Math.ceil(l*y),C=Math.ceil(h*w),T=Math.ceil(g*y),D=Math.ceil(m*w);E>=T?A=l:_=!0,C>=D?x=h:S=!0;const P=this.getSizeAndScale(A,this.ctx.canvas.width,y),I=this.getSizeAndScale(x,this.ctx.canvas.height,w),k=t.cachedCanvases.getCanvas("pattern",P.size,I.size),R=k.context,L=o.createCanvasGraphics(R,e);if(L.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(L,n,a),R.translate(-P.scale*c,-I.scale*d),L.transform(0,P.scale,0,0,I.scale,0,0),R.save(),L.dependencyTracker?.save(),this.clipBbox(L,c,d,u,p),L.baseTransform=Tt(L.ctx),L.executeOperatorList(s),L.endDrawing(),L.dependencyTracker?.restore(),R.restore(),_||S){const e=k.canvas;_&&(A=l),S&&(x=h);const i=this.getSizeAndScale(A,this.ctx.canvas.width,y),s=this.getSizeAndScale(x,this.ctx.canvas.height,w),n=i.size,r=s.size,a=t.cachedCanvases.getCanvas("pattern-workaround",n,r),o=a.context,u=_?Math.floor(g/l):0,p=S?Math.floor(m/h):0;for(let t=0;t<=u;t++)for(let i=0;i<=p;i++)o.drawImage(e,n*t,r*i,n,r,0,0,n,r);return{canvas:a.canvas,scaleX:i.scale,scaleY:s.scale,offsetX:c,offsetY:d}}return{canvas:k.canvas,scaleX:P.scale,scaleY:I.scale,offsetX:c,offsetY:d}}getSizeAndScale(t,e,i){const s=Math.max(ui.MAX_PATTERN_SIZE,e);let n=Math.ceil(t*i);return n>=s?n=s:i=n/t,{scale:i,size:n}}clipBbox(t,e,i,s,n){const r=s-e,a=n-i;t.ctx.rect(e,i,r,a),K.axialAlignedBoundingBox([e,i,s,n],Tt(t.ctx),t.current.minMax),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,i){const s=t.ctx,n=t.current;switch(e){case di.COLORED:const{fillStyle:t,strokeStyle:r}=this.ctx;s.fillStyle=n.fillColor=t,s.strokeStyle=n.strokeColor=r;break;case di.UNCOLORED:s.fillStyle=s.strokeStyle=i,n.fillColor=n.strokeColor=i;break;default:throw new H(`Unsupported paint type: ${e}`)}}isModifyingCurrentTransform(){return!1}getPattern(t,e,i,s,n){let r=i;s!==ii.SHADING&&(r=K.transform(r,e.baseTransform),this.matrix&&(r=K.transform(r,this.matrix)));const a=this.createPatternCanvas(e,n);let o=new DOMMatrix(r);o=o.translate(a.offsetX,a.offsetY),o=o.scale(1/a.scaleX,1/a.scaleY);const l=t.createPattern(a.canvas,"repeat");return l.setTransform(o),l}}function pi({src:t,srcPos:e=0,dest:i,width:s,height:n,nonBlackColor:r=4294967295,inverseDecode:a=!1}){const o=X.isLittleEndian?4278190080:255,[l,h]=a?[r,o]:[o,r],c=s>>3,d=7&s,u=t.length;i=new Uint32Array(i.buffer);let p=0;for(let g=0;g<n;g++){for(const n=e+c;e<n;e++){const s=e<u?t[e]:255;i[p++]=128&s?h:l,i[p++]=64&s?h:l,i[p++]=32&s?h:l,i[p++]=16&s?h:l,i[p++]=8&s?h:l,i[p++]=4&s?h:l,i[p++]=2&s?h:l,i[p++]=1&s?h:l}if(0===d)continue;const s=e<u?t[e++]:255;for(let t=0;t<d;t++)i[p++]=s&1<<7-t?h:l}return{srcPos:e,destPos:p}}const gi=16,mi=100,fi=15,bi=10,vi=16,yi=new DOMMatrix,wi=new Float32Array(2),Ai=new Float32Array([1/0,1/0,-1/0,-1/0]);function xi(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,s,n,r,a){e.transform(t,i,s,n,r,a),this.__originalTransform(t,i,s,n,r,a)},t.setTransform=function(t,i,s,n,r,a){e.setTransform(t,i,s,n,r,a),this.__originalSetTransform(t,i,s,n,r,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,s,n,r,a){e.bezierCurveTo(t,i,s,n,r,a),this.__originalBezierCurveTo(t,i,s,n,r,a)},t.rect=function(t,i,s,n){e.rect(t,i,s,n),this.__originalRect(t,i,s,n)},t.closePath=function(){e.closePath(),this.__originalClosePath()},t.beginPath=function(){e.beginPath(),this.__originalBeginPath()}}class _i{constructor(t){this.canvasFactory=t,this.cache=Object.create(null)}getCanvas(t,e,i){let s;return void 0!==this.cache[t]?(s=this.cache[t],this.canvasFactory.reset(s,e,i)):(s=this.canvasFactory.create(e,i),this.cache[t]=s),s}delete(t){delete this.cache[t]}clear(){for(const t in this.cache){const e=this.cache[t];this.canvasFactory.destroy(e),delete this.cache[t]}}}function Si(t,e,i,s,n,r,a,o,l,h){const[c,d,u,p,g,m]=Tt(t);if(0===d&&0===u){const f=a*c+g,b=Math.round(f),v=o*p+m,y=Math.round(v),w=(a+l)*c+g,A=Math.abs(Math.round(w)-b)||1,x=(o+h)*p+m,_=Math.abs(Math.round(x)-y)||1;return t.setTransform(Math.sign(c),0,0,Math.sign(p),b,y),t.drawImage(e,i,s,n,r,0,0,A,_),t.setTransform(c,d,u,p,g,m),[A,_]}if(0===c&&0===p){const f=o*u+g,b=Math.round(f),v=a*d+m,y=Math.round(v),w=(o+h)*u+g,A=Math.abs(Math.round(w)-b)||1,x=(a+l)*d+m,_=Math.abs(Math.round(x)-y)||1;return t.setTransform(0,Math.sign(d),Math.sign(u),0,b,y),t.drawImage(e,i,s,n,r,0,0,_,A),t.setTransform(c,d,u,p,g,m),[_,A]}t.drawImage(e,i,s,n,r,a,o,l,h);const f=Math.hypot(c,d),b=Math.hypot(u,p);return[f*l,b*h]}class Ei{alphaIsShape=!1;fontSize=0;fontSizeScale=1;textMatrix=null;textMatrixScale=1;fontMatrix=l;leading=0;x=0;y=0;lineX=0;lineY=0;charSpacing=0;wordSpacing=0;textHScale=1;textRenderingMode=b.FILL;textRise=0;fillColor="#000000";strokeColor="#000000";patternFill=!1;patternStroke=!1;fillAlpha=1;strokeAlpha=1;lineWidth=1;activeSMask=null;transferMaps="none";constructor(t,e,i){i?.(this),this.clipBox=new Float32Array([0,0,t,e]),this.minMax=Ai.slice()}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t.minMax=this.minMax.slice(),t}getPathBoundingBox(t=ii.FILL,e=null){const i=this.minMax.slice();if(t===ii.STROKE){e||P("Stroke bounding box must include transform."),K.singularValueDecompose2dScale(e,wi);const t=wi[0]*this.lineWidth/2,s=wi[1]*this.lineWidth/2;i[0]-=t,i[1]-=s,i[2]+=t,i[3]+=s}return i}updateClipFromPath(){const t=K.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(Ai,0)}getClippedPathBoundingBox(t=ii.FILL,e=null){return K.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function Ci(t,e){if(e instanceof ImageData)return void t.putImageData(e,0,0);const i=e.height,s=e.width,n=i%vi,r=(i-n)/vi,a=0===n?r:r+1,o=t.createImageData(s,vi);let l,h=0;const c=e.data,d=o.data;let u,p,g,m;if(e.kind===v.GRAYSCALE_1BPP){const e=c.byteLength,i=new Uint32Array(d.buffer,0,d.byteLength>>2),m=i.length,f=s+7>>3,b=4294967295,v=X.isLittleEndian?4278190080:255;for(u=0;u<a;u++){for(g=u<r?vi:n,l=0,p=0;p<g;p++){const t=e-h;let n=0;const r=t>f?s:8*t-7,a=-8&r;let o=0,d=0;for(;n<a;n+=8)d=c[h++],i[l++]=128&d?b:v,i[l++]=64&d?b:v,i[l++]=32&d?b:v,i[l++]=16&d?b:v,i[l++]=8&d?b:v,i[l++]=4&d?b:v,i[l++]=2&d?b:v,i[l++]=1&d?b:v;for(;n<r;n++)0===o&&(d=c[h++],o=128),i[l++]=d&o?b:v,o>>=1}while(l<m)i[l++]=0;t.putImageData(o,0,u*vi)}}else if(e.kind===v.RGBA_32BPP){for(p=0,m=s*vi*4,u=0;u<r;u++)d.set(c.subarray(h,h+m)),h+=m,t.putImageData(o,0,p),p+=vi;u<a&&(m=s*n*4,d.set(c.subarray(h,h+m)),t.putImageData(o,0,p))}else{if(e.kind!==v.RGB_24BPP)throw new Error(`bad image kind: ${e.kind}`);for(g=vi,m=s*g,u=0;u<a;u++){for(u>=r&&(g=n,m=s*g),l=0,p=m;p--;)d[l++]=c[h++],d[l++]=c[h++],d[l++]=c[h++],d[l++]=255;t.putImageData(o,0,u*vi)}}}function Ti(t,e){if(e.bitmap)return void t.drawImage(e.bitmap,0,0);const i=e.height,s=e.width,n=i%vi,r=(i-n)/vi,a=0===n?r:r+1,o=t.createImageData(s,vi);let l=0;const h=e.data,c=o.data;for(let d=0;d<a;d++){const e=d<r?vi:n;({srcPos:l}=pi({src:h,srcPos:l,dest:c,width:s,height:e,nonBlackColor:0})),t.putImageData(o,0,d*vi)}}function Mi(t,e){const i=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(const s of i)void 0!==t[s]&&(e[s]=t[s]);void 0!==t.setLineDash&&(e.setLineDash(t.getLineDash()),e.lineDashOffset=t.lineDashOffset)}function Di(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",void 0!==t.setLineDash&&(t.setLineDash([]),t.lineDashOffset=0);const{filter:e}=t;"none"!==e&&""!==e&&(t.filter="none")}function Pi(t,e){if(e)return!0;K.singularValueDecompose2dScale(t,wi);const i=Math.fround(Pt.pixelRatio*ct.PDF_TO_CSS_UNITS);return wi[0]<=i&&wi[1]<=i}const Ii=["butt","round","square"],ki=["miter","round","bevel"],Ri={},Li={};class Fi{constructor(t,e,i,s,n,{optionalContentConfig:r,markedContentStack:a=null},o,l,h){this.ctx=t,this.current=new Ei(this.ctx.canvas.width,this.ctx.canvas.height),this.stateStack=[],this.pendingClip=null,this.pendingEOFill=!1,this.res=null,this.xobjs=null,this.commonObjs=e,this.objs=i,this.canvasFactory=s,this.filterFactory=n,this.groupStack=[],this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.smaskCounter=0,this.tempSMask=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=a||[],this.optionalContentConfig=r,this.cachedCanvases=new _i(this.canvasFactory),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}getObject(t,e,i=null){return"string"===typeof e?(this.dependencyTracker?.recordNamedDependency(t,e),e.startsWith("g_")?this.commonObjs.get(e):this.objs.get(e)):i}beginDrawing({transform:t,viewport:e,transparency:i=!1,background:s=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,a=this.ctx.fillStyle;if(this.ctx.fillStyle=s||"#ffffff",this.ctx.fillRect(0,0,n,r),this.ctx.fillStyle=a,i){const t=this.cachedCanvases.getCanvas("transparent",n,r);this.compositeCtx=this.ctx,this.transparentCanvas=t.canvas,this.ctx=t.context,this.ctx.save(),this.ctx.transform(...Tt(this.compositeCtx))}this.ctx.save(),Di(this.ctx),t&&(this.ctx.transform(...t),this.outputScaleX=t[0],this.outputScaleY=t[0]),this.ctx.transform(...e.transform),this.viewportScale=e.scale,this.baseTransform=Tt(this.ctx)}executeOperatorList(t,e,i,s,n){const r=t.argsArray,a=t.fnArray;let o=e||0;const l=r.length;if(l===o)return o;const h=l-o>bi&&"function"===typeof i,c=h?Date.now()+fi:0;let d=0;const u=this.commonObjs,p=this.objs;let g,m;while(1){if(void 0!==s&&o===s.nextBreakPoint)return s.breakIt(o,i),o;if(!n||n(o))if(g=a[o],m=r[o]??null,g!==x.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))return e.get(t,i),o}if(o++,o===l)return o;if(h&&++d>bi){if(Date.now()>c)return i(),o;d=0}}}#zs(){while(this.stateStack.length||this.inSMaskMode)this.restore();this.current.activeSMask=null,this.ctx.restore(),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.transparentCanvas=null)}endDrawing(){this.#zs(),this.cachedCanvases.clear(),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.#$s()}#$s(){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,s=t.height??t.displayHeight;let n,r,a=Math.max(Math.hypot(e[0],e[1]),1),o=Math.max(Math.hypot(e[2],e[3]),1),l=i,h=s,c="prescale1";while(a>2&&l>1||o>2&&h>1){let e=l,i=h;a>2&&l>1&&(e=l>=16384?Math.floor(l/2)-1||1:Math.ceil(l/2),a/=l/e),o>2&&h>1&&(i=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,o/=h/i),n=this.cachedCanvases.getCanvas(c,e,i),r=n.context,r.clearRect(0,0,e,i),r.drawImage(t,0,0,l,h,0,0,e,i),t=n.canvas,l=e,h=i,c="prescale1"===c?"prescale2":"prescale1"}return{img:t,paintWidth:l,paintHeight:h}}_createMaskCanvas(t,e){const i=this.ctx,{width:s,height:n}=e,r=this.current.fillColor,a=this.current.patternFill,o=Tt(i);let l,h,c,d;if((e.bitmap||e.data)&&e.count>1){const i=e.bitmap||e.data.buffer;h=JSON.stringify(a?o:[o.slice(0,4),r]),l=this._cachedBitmapsMap.get(i),l||(l=new Map,this._cachedBitmapsMap.set(i,l));const s=l.get(h);if(s&&!a){const e=Math.round(Math.min(o[0],o[2])+o[4]),i=Math.round(Math.min(o[1],o[3])+o[5]);return this.dependencyTracker?.recordDependencies(t,ei.transformAndFill),{canvas:s,offsetX:e,offsetY:i}}c=s}c||(d=this.cachedCanvases.getCanvas("maskCanvas",s,n),Ti(d.context,e));let u=K.transform(o,[1/s,0,0,-1/n,0,0]);u=K.transform(u,[1,0,0,1,0,-n]);const p=Ai.slice();K.axialAlignedBoundingBox([0,0,s,n],u,p);const[g,m,f,b]=p,v=Math.round(f-g)||1,y=Math.round(b-m)||1,w=this.cachedCanvases.getCanvas("fillCanvas",v,y),A=w.context,x=g,_=m;A.translate(-x,-_),A.transform(...u),c||(c=this._scaleImage(d.canvas,Mt(A)),c=c.img,l&&a&&l.set(h,c)),A.imageSmoothingEnabled=Pi(Tt(A),e.interpolate),Si(A,c,0,0,c.width,c.height,0,0,s,n),A.globalCompositeOperation="source-in";const S=K.transform(Mt(A),[1,0,0,1,-x,-_]);return A.fillStyle=a?r.getPattern(i,this,S,ii.FILL,t):r,A.fillRect(0,0,s,n),l&&!a&&(this.cachedCanvases.delete("fillCanvas"),l.set(h,w.canvas)),this.dependencyTracker?.recordDependencies(t,ei.transformAndFill),{canvas:w.canvas,offsetX:Math.round(x),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=Ii[e]}setLineJoin(t,e){this.dependencyTracker?.recordSimpleData("lineJoin",t),this.ctx.lineJoin=ki[e]}setMiterLimit(t,e){this.dependencyTracker?.recordSimpleData("miterLimit",t),this.ctx.miterLimit=e}setDash(t,e,i){this.dependencyTracker?.recordSimpleData("dash",t);const s=this.ctx;void 0!==s.setLineDash&&(s.setLineDash(e),s.lineDashOffset=i)}setRenderingIntent(t,e){}setFlatness(t,e){}setGState(t,e){for(const[i,s]of e)switch(i){case"LW":this.setLineWidth(t,s);break;case"LC":this.setLineCap(t,s);break;case"LJ":this.setLineJoin(t,s);break;case"ML":this.setMiterLimit(t,s);break;case"D":this.setDash(t,s[0],s[1]);break;case"RI":this.setRenderingIntent(t,s);break;case"FL":this.setFlatness(t,s);break;case"Font":this.setFont(t,s[0],s[1]);break;case"CA":this.dependencyTracker?.recordSimpleData("strokeAlpha",t),this.current.strokeAlpha=s;break;case"ca":this.dependencyTracker?.recordSimpleData("fillAlpha",t),this.ctx.globalAlpha=this.current.fillAlpha=s;break;case"BM":this.dependencyTracker?.recordSimpleData("globalCompositeOperation",t),this.ctx.globalCompositeOperation=s;break;case"SMask":this.dependencyTracker?.recordSimpleData("SMask",t),this.current.activeSMask=s?this.tempSMask:null,this.tempSMask=null,this.checkSMaskState();break;case"TR":this.dependencyTracker?.recordSimpleData("filter",t),this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(s);break}}get inSMaskMode(){return!!this.suspendedCtx}checkSMaskState(){const t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode():!this.current.activeSMask&&t&&this.endSMaskMode()}beginSMaskMode(t){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const e=this.ctx.canvas.width,i=this.ctx.canvas.height,s="smaskGroupAt"+this.groupLevel,n=this.cachedCanvases.getCanvas(s,e,i);this.suspendedCtx=this.ctx;const r=this.ctx=n.context;r.setTransform(this.suspendedCtx.getTransform()),Mi(this.suspendedCtx,r),xi(r,this.suspendedCtx),this.setGState(t,[["BM","source-over"]])}endSMaskMode(){if(!this.inSMaskMode)throw new Error("endSMaskMode called while not in smask mode");this.ctx._removeMirroring(),Mi(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null}compose(t){if(!this.current.activeSMask)return;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])):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(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore()}composeSMask(t,e,i,s){const n=s[0],r=s[1],a=s[2]-n,o=s[3]-r;0!==a&&0!==o&&(this.genericComposeSMask(e.context,i,a,o,e.subtype,e.backdrop,e.transferMap,n,r,e.offsetX,e.offsetY),t.save(),t.globalAlpha=1,t.globalCompositeOperation="source-over",t.setTransform(1,0,0,1,0,0),t.drawImage(i.canvas,0,0),t.restore())}genericComposeSMask(t,e,i,s,n,r,a,o,l,h,c){let d=t.canvas,u=o-h,p=l-c;if(r)if(u<0||p<0||u+i>d.width||p+s>d.height){const t=this.cachedCanvases.getCanvas("maskExtension",i,s),e=t.context;e.drawImage(d,-u,-p),e.globalCompositeOperation="destination-atop",e.fillStyle=r,e.fillRect(0,0,i,s),e.globalCompositeOperation="source-over",d=t.canvas,u=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const e=new Path2D;e.rect(u,p,i,s),t.clip(e),t.globalCompositeOperation="destination-atop",t.fillStyle=r,t.fillRect(u,p,i,s),t.restore()}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),"Alpha"===n&&a?e.filter=this.filterFactory.addAlphaFilter(a):"Luminosity"===n&&(e.filter=this.filterFactory.addLuminosityFilter(a));const g=new Path2D;g.rect(o,l,i,s),e.clip(g),e.globalCompositeOperation="destination-in",e.drawImage(d,u,p,i,s,o,l,i,s),e.restore()}save(t){this.inSMaskMode&&Mi(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),0!==this.stateStack.length?(this.current=this.stateStack.pop(),this.ctx.restore(),this.inSMaskMode&&Mi(this.suspendedCtx,this.ctx),this.checkSMaskState(),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null):this.inSMaskMode&&this.endSMaskMode()}transform(t,e,i,s,n,r,a){this.dependencyTracker?.recordIncrementalData("transform",t),this.ctx.transform(e,i,s,n,r,a),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(t,e,i,s){let[n]=i;if(!s)return n||=i[0]=new Path2D,void this[e](t,n);if(null!==this.dependencyTracker){const i=e===x.stroke?this.current.lineWidth/2:0;this.dependencyTracker.resetBBox(t).recordBBox(t,this.ctx,s[0]-i,s[2]+i,s[1]-i,s[3]+i).recordDependencies(t,["transform"])}n instanceof Path2D||(n=i[0]=zt(n)),K.axialAlignedBoundingBox(s,Tt(this.ctx),this.current.minMax),this[e](t,n),this._pathStartIdx=t}closePath(t){this.ctx.closePath()}stroke(t,e,i=!0){const s=this.ctx,n=this.current.strokeColor;if(s.globalAlpha=this.current.strokeAlpha,this.contentVisible)if("object"===typeof n&&n?.getPattern){const i=n.isModifyingCurrentTransform()?s.getTransform():null;if(s.save(),s.strokeStyle=n.getPattern(s,this,Mt(s),ii.STROKE,t),i){const t=new Path2D;t.addPath(e,s.getTransform().invertSelf().multiplySelf(i)),e=t}this.rescaleAndStroke(e,!1),s.restore()}else this.rescaleAndStroke(e,!0);this.dependencyTracker?.recordDependencies(t,ei.stroke),i&&this.consumePath(t,e,this.current.getClippedPathBoundingBox(ii.STROKE,Tt(this.ctx))),s.globalAlpha=this.current.fillAlpha}closeStroke(t,e){this.stroke(t,e)}fill(t,e,i=!0){const s=this.ctx,n=this.current.fillColor,r=this.current.patternFill;let a=!1;if(r){const i=n.isModifyingCurrentTransform()?s.getTransform():null;if(this.dependencyTracker?.save(t),s.save(),s.fillStyle=n.getPattern(s,this,Mt(s),ii.FILL,t),i){const t=new Path2D;t.addPath(e,s.getTransform().invertSelf().multiplySelf(i)),e=t}a=!0}const o=this.current.getClippedPathBoundingBox();this.contentVisible&&null!==o&&(this.pendingEOFill?(s.fill(e,"evenodd"),this.pendingEOFill=!1):s.fill(e)),this.dependencyTracker?.recordDependencies(t,ei.fill),a&&(s.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,ei.rawFillPath).recordOperation(t)}clip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t),this.pendingClip=Ri}eoClip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t),this.pendingClip=Li}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,s=i.getTransform().invertSelf();for(const{transform:i,x:n,y:r,fontSize:a,path:o}of e)o&&t.addPath(o,new DOMMatrix(i).preMultiplySelf(s).translate(n,r).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 s=this.commonObjs.get(e),n=this.current;if(!s)throw new Error(`Can't find font for ${e}`);if(n.fontMatrix=s.fontMatrix||l,0!==n.fontMatrix[0]&&0!==n.fontMatrix[3]||D("Invalid font matrix for font "+e),i<0?(i=-i,n.fontDirection=-1):n.fontDirection=1,this.current.font=s,this.current.fontSize=i,s.isType3Font)return;const r=s.loadedName||"sans-serif",a=s.systemFontInfo?.css||`"${r}", ${s.fallbackName}`;let o="normal";s.black?o="900":s.bold&&(o="bold");const h=s.italic?"italic":"normal";let c=i;i<gi?c=gi:i>mi&&(c=mi),this.current.fontSizeScale=i/c,this.ctx.font=`${h} ${o} ${c}px ${a}`}setTextRenderingMode(t,e){this.dependencyTracker?.recordSimpleData("textRenderingMode",t),this.current.textRenderingMode=e}setTextRise(t,e){this.dependencyTracker?.recordSimpleData("textRise",t),this.current.textRise=e}moveText(t,e,i){this.dependencyTracker?.resetIncrementalData("sameLineText").recordIncrementalData("moveText",t),this.current.x=this.current.lineX+=e,this.current.y=this.current.lineY+=i}setLeadingMoveText(t,e,i){this.setLeading(t,-i),this.moveText(t,e,i)}setTextMatrix(t,e){this.dependencyTracker?.resetIncrementalData("sameLineText").recordSimpleData("textMatrix",t);const{current:i}=this;i.textMatrix=e,i.textMatrixScale=Math.hypot(e[0],e[1]),i.x=i.lineX=0,i.y=i.lineY=0}nextLine(t){this.moveText(t,0,this.current.leading),this.dependencyTracker?.recordIncrementalData("moveText",this.dependencyTracker.getSimpleIndex("leading")??t)}#Gs(t,e,i){const s=new Path2D;return s.addPath(t,new DOMMatrix(i).invertSelf().multiplySelf(e)),s}paintChar(t,e,i,s,n,r){const a=this.ctx,o=this.current,l=o.font,h=o.textRenderingMode,c=o.fontSize/o.fontSizeScale,d=h&b.FILL_STROKE_MASK,u=!!(h&b.ADD_TO_PATH_FLAG),p=o.patternFill&&!l.missingFile,g=o.patternStroke&&!l.missingFile;let m;if((l.disableFontFace||u||p||g)&&!l.missingFile&&(m=l.getPathGenerator(this.commonObjs,e)),m&&(l.disableFontFace||p||g)){let e;if(a.save(),a.translate(i,s),a.scale(c,-c),this.dependencyTracker?.recordCharacterBBox(t,a,l),d===b.FILL||d===b.FILL_STROKE)if(n){e=a.getTransform(),a.setTransform(...n);const t=this.#Gs(m,e,n);a.fill(t)}else a.fill(m);if(d===b.STROKE||d===b.FILL_STROKE)if(r){e||=a.getTransform(),a.setTransform(...r);const{a:t,b:i,c:s,d:n}=e,o=K.inverseTransform(r),l=K.transform([t,i,s,n,0,0],o);K.singularValueDecompose2dScale(l,wi),a.lineWidth*=Math.max(wi[0],wi[1])/c,a.stroke(this.#Gs(m,e,r))}else a.lineWidth/=c,a.stroke(m);a.restore()}else d!==b.FILL&&d!==b.FILL_STROKE||(a.fillText(e,i,s),this.dependencyTracker?.recordCharacterBBox(t,a,l,c,i,s,()=>a.measureText(e))),d!==b.STROKE&&d!==b.FILL_STROKE||(this.dependencyTracker&&this.dependencyTracker?.recordCharacterBBox(t,a,l,c,i,s,()=>a.measureText(e)).recordDependencies(t,ei.stroke),a.strokeText(e,i,s));if(u){const e=this.pendingTextPaths||=[];e.push({transform:Tt(a),x:i,y:s,fontSize:c,path:m}),this.dependencyTracker?.recordCharacterBBox(t,a,l,c,i,s)}}get isFontSubpixelAAEnabled(){const{context:t}=this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled",10,10);t.scale(1.5,1),t.fillText("I",0,10);const e=t.getImageData(0,0,10,10).data;let i=!1;for(let s=3;s<e.length;s+=4)if(e[s]>0&&e[s]<255){i=!0;break}return F(this,"isFontSubpixelAAEnabled",i)}showText(t,e){this.dependencyTracker&&(this.dependencyTracker.recordDependencies(t,ei.showText).resetBBox(t),this.current.textRenderingMode&b.ADD_TO_PATH_FLAG&&this.dependencyTracker.recordFutureForcedDependency("textClip",t).inheritPendingDependenciesAsFutureForcedDependencies());const i=this.current,s=i.font;if(s.isType3Font)return this.showType3Text(t,e),void this.dependencyTracker?.recordShowTextOperation(t);const n=i.fontSize;if(0===n)return void this.dependencyTracker?.recordOperation(t);const r=this.ctx,a=i.fontSizeScale,o=i.charSpacing,l=i.wordSpacing,h=i.fontDirection,c=i.textHScale*h,d=e.length,u=s.vertical,p=u?1:-1,g=s.defaultVMetrics,m=n*i.fontMatrix[0],f=i.textRenderingMode===b.FILL&&!s.disableFontFace&&!i.patternFill;let v,y;r.save(),i.textMatrix&&r.transform(...i.textMatrix),r.translate(i.x,i.y+i.textRise),h>0?r.scale(c,-1):r.scale(c,1);const w=i.textRenderingMode&b.FILL_STROKE_MASK,A=w===b.FILL||w===b.FILL_STROKE,x=w===b.STROKE||w===b.FILL_STROKE;if(A&&i.patternFill){r.save();const e=i.fillColor.getPattern(r,this,Mt(r),ii.FILL,t);v=Tt(r),r.restore(),r.fillStyle=e}if(x&&i.patternStroke){r.save();const e=i.strokeColor.getPattern(r,this,Mt(r),ii.STROKE,t);y=Tt(r),r.restore(),r.strokeStyle=e}let _=i.lineWidth;const S=i.textMatrixScale;if(0===S||0===_?x&&(_=this.getSinglePixelWidth()):_/=S,1!==a&&(r.scale(a,a),_/=a),r.lineWidth=_,s.isInvalidPDFjsFont){const s=[];let n=0;for(const t of e)s.push(t.unicode),n+=t.width;const a=s.join("");if(r.fillText(a,0,0),null!==this.dependencyTracker){const e=r.measureText(a);this.dependencyTracker.recordBBox(t,this.ctx,-e.actualBoundingBoxLeft,e.actualBoundingBoxRight,-e.actualBoundingBoxAscent,e.actualBoundingBoxDescent).recordShowTextOperation(t)}return i.x+=n*m*c,r.restore(),void this.compose()}let E,C=0;for(E=0;E<d;++E){const i=e[E];if("number"===typeof i){C+=p*i*n/1e3;continue}let c=!1;const d=(i.isSpace?l:0)+o,b=i.fontChar,w=i.accent;let A,x,_,S=i.width;if(u){const t=i.vmetric||g,e=-(i.vmetric?t[1]:.5*S)*m,s=t[2]*m;S=t?-t[0]:S,A=e/a,x=(C+s)/a}else A=C/a,x=0;if(s.remeasure&&S>0){_=r.measureText(b);const t=1e3*_.width/n*a;if(S<t&&this.isFontSubpixelAAEnabled){const e=S/t;c=!0,r.save(),r.scale(e,1),A/=e}else S!==t&&(A+=(S-t)/2e3*n/a)}if(this.contentVisible&&(i.isInFont||s.missingFile))if(f&&!w)r.fillText(b,A,x),this.dependencyTracker?.recordCharacterBBox(t,r,_?{bbox:null}:s,n/a,A,x,()=>_??r.measureText(b));else if(this.paintChar(t,b,A,x,v,y),w){const e=A+n*w.offset.x/a,i=x-n*w.offset.y/a;this.paintChar(t,w.fontChar,e,i,v,y)}const T=u?S*m-d*h:S*m+d*h;C+=T,c&&r.restore()}u?i.y-=C:i.x+=C*c,r.restore(),this.compose(),this.dependencyTracker?.recordShowTextOperation(t)}showType3Text(t,e){const i=this.ctx,s=this.current,n=s.font,r=s.fontSize,a=s.fontDirection,o=n.vertical?1:-1,h=s.charSpacing,c=s.wordSpacing,d=s.textHScale*a,u=s.fontMatrix||l,p=e.length,g=s.textRenderingMode===b.INVISIBLE;let m,f,v,y;if(g||0===r)return;this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,i.save(),s.textMatrix&&i.transform(...s.textMatrix),i.translate(s.x,s.y+s.textRise),i.scale(d,a);const w=this.dependencyTracker;for(this.dependencyTracker=w?new ti(w,t):null,m=0;m<p;++m){if(f=e[m],"number"===typeof f){y=o*f*r/1e3,this.ctx.translate(y,0),s.x+=y*d;continue}const t=(f.isSpace?c:0)+h,a=n.charProcOperatorList[f.operatorListId];a?this.contentVisible&&(this.save(),i.scale(r,r),i.transform(...u),this.executeOperatorList(a),this.restore()):D(`Type3 character "${f.operatorListId}" is not available.`);const l=[f.width,0];K.applyTransform(l,u),v=l[0]*r+t,i.translate(v,0),s.x+=v*d}i.restore(),w&&(this.dependencyTracker=w)}setCharWidth(t,e,i){}setCharWidthAndBounds(t,e,i,s,n,r,a){const o=new Path2D;o.rect(s,n,r-s,a-n),this.ctx.clip(o),this.dependencyTracker?.recordBBox(t,this.ctx,s,r,n,a).recordClipBox(t,this.ctx,s,r,n,a),this.endPath(t)}getColorN_Pattern(t,e){let i;if("TilingPattern"===e[0]){const t=this.baseTransform||Tt(this.ctx),s={createCanvasGraphics:(t,e)=>new Fi(t,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack},void 0,void 0,this.dependencyTracker?new ti(this.dependencyTracker,e,!0):null)};i=new ui(e,this.ctx,s,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),this.current.fillColor=this.getColorN_Pattern(t,e),this.current.patternFill=!0}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}setFillTransparent(t){this.dependencyTracker?.recordSimpleData("fillColor",t),this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e,i=null){let s;return this.cachedPatterns.has(e)?s=this.cachedPatterns.get(e):(s=ci(this.getObject(t,e)),this.cachedPatterns.set(e,s)),i&&(s.matrix=i),s}shadingFill(t,e){if(!this.contentVisible)return;const i=this.ctx;this.save(t);const s=this._getPattern(t,e);i.fillStyle=s.getPattern(i,this,Mt(i),ii.SHADING,t);const n=Mt(i);if(n){const{width:t,height:e}=i.canvas,s=Ai.slice();K.axialAlignedBoundingBox([0,0,t,e],n,s);const[r,a,o,l]=s;this.ctx.fillRect(r,a,o-r,l-a)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.dependencyTracker?.resetBBox(t).recordFullPageBBox(t).recordDependencies(t,ei.transform).recordDependencies(t,ei.fill).recordOperation(t),this.compose(this.current.getClippedPathBoundingBox()),this.restore(t)}beginInlineImage(){P("Should not call beginInlineImage")}beginImageData(){P("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=Tt(this.ctx),i)){K.axialAlignedBoundingBox(i,this.baseTransform,this.current.minMax);const[e,s,n,r]=i,a=new Path2D;a.rect(e,s,n-e,r-s),this.ctx.clip(a),this.dependencyTracker?.recordClipBox(t,this.ctx,e,n,s,r),this.endPath(t)}}paintFormXObjectEnd(t){this.contentVisible&&(this.restore(t),this.baseTransform=this.baseTransformStack.pop())}beginGroup(t,e){if(!this.contentVisible)return;this.save(t),this.inSMaskMode&&(this.endSMaskMode(),this.current.activeSMask=null);const i=this.ctx;e.isolated||M("TODO: Support non-isolated groups."),e.knockout&&D("Knockout groups not supported.");const s=Tt(i);if(e.matrix&&i.transform(...e.matrix),!e.bbox)throw new Error("Bounding box is required.");let n=Ai.slice();K.axialAlignedBoundingBox(e.bbox,Tt(i),n);const r=[0,0,i.canvas.width,i.canvas.height];n=K.intersect(n,r)||[0,0,0,0];const a=Math.floor(n[0]),o=Math.floor(n[1]),l=Math.max(Math.ceil(n[2])-a,1),h=Math.max(Math.ceil(n[3])-o,1);this.current.startNewPathAndClipBox([0,0,l,h]);let c="groupAt"+this.groupLevel;e.smask&&(c+="_smask_"+this.smaskCounter++%2);const d=this.cachedCanvases.getCanvas(c,l,h),u=d.context;u.translate(-a,-o),u.transform(...s);let p=new Path2D;const[g,m,f,b]=e.bbox;if(p.rect(g,m,f-g,b-m),e.matrix){const t=new Path2D;t.addPath(p,new DOMMatrix(e.matrix)),p=t}u.clip(p),e.smask&&this.smaskStack.push({canvas:d.canvas,context:u,offsetX:a,offsetY:o,subtype:e.smask.subtype,backdrop:e.smask.backdrop,transferMap:e.smask.transferMap||null,startTransformInverse:null}),e.smask&&!this.dependencyTracker||(i.setTransform(1,0,0,1,0,0),i.translate(a,o),i.save()),Mi(i,u),this.ctx=u,this.dependencyTracker?.inheritSimpleDataAsFutureForcedDependencies(["fillAlpha","strokeAlpha","globalCompositeOperation"]).pushBaseTransform(i),this.setGState(t,[["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(i),this.groupLevel++}endGroup(t,e){if(!this.contentVisible)return;this.groupLevel--;const i=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,this.dependencyTracker?.popBaseTransform(),e.smask)this.tempSMask=this.smaskStack.pop(),this.restore(t),this.dependencyTracker&&this.ctx.restore();else{this.ctx.restore();const e=Tt(this.ctx);this.restore(t),this.ctx.save(),this.ctx.setTransform(...e);const s=Ai.slice();K.axialAlignedBoundingBox([0,0,i.canvas.width,i.canvas.height],e,s),this.ctx.drawImage(i.canvas,0,0),this.ctx.restore(),this.compose(s)}}beginAnnotation(t,e,i,s,n,r){if(this.#zs(),Di(this.ctx),this.ctx.save(),this.save(t),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),i){const n=i[2]-i[0],a=i[3]-i[1];if(r&&this.annotationCanvasMap){s=s.slice(),s[4]-=i[0],s[5]-=i[1],i=i.slice(),i[0]=i[1]=0,i[2]=n,i[3]=a,K.singularValueDecompose2dScale(Tt(this.ctx),wi);const{viewportScale:t}=this,r=Math.ceil(n*this.outputScaleX*t),o=Math.ceil(a*this.outputScaleY*t);this.annotationCanvas=this.canvasFactory.create(r,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(wi[0],0,0,-wi[1],0,a*wi[1]),Di(this.ctx)}else{Di(this.ctx),this.endPath(t);const e=new Path2D;e.rect(i[0],i[1],n,a),this.ctx.clip(e)}}this.current=new Ei(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(t,...s),this.transform(t,...n)}endAnnotation(t){this.annotationCanvas&&(this.ctx.restore(),this.#$s(),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas)}paintImageMaskXObject(t,e){if(!this.contentVisible)return;const i=e.count;e=this.getObject(t,e.data,e),e.count=i;const s=this.ctx,n=this._createMaskCanvas(t,e),r=n.canvas;s.save(),s.setTransform(1,0,0,1,0,0),s.drawImage(r,n.offsetX,n.offsetY),this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,n.offsetX,n.offsetX+r.width,n.offsetY,n.offsetY+r.height).recordOperation(t),s.restore(),this.compose()}paintImageMaskXObjectRepeat(t,e,i,s=0,n=0,r,a){if(!this.contentVisible)return;e=this.getObject(t,e.data,e);const o=this.ctx;o.save();const l=Tt(o);o.transform(i,s,n,r,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 c=0,d=a.length;c<d;c+=2){const e=K.transform(l,[i,s,n,r,a[c],a[c+1]]);o.drawImage(h.canvas,e[4],e[5]),this.dependencyTracker?.recordBBox(t,this.ctx,e[4],e[4]+h.canvas.width,e[5],e[5]+h.canvas.height)}o.restore(),this.compose(),this.dependencyTracker?.recordOperation(t)}paintImageMaskXObjectGroup(t,e){if(!this.contentVisible)return;const i=this.ctx,s=this.current.fillColor,n=this.current.patternFill;this.dependencyTracker?.resetBBox(t).recordDependencies(t,ei.transformAndFill);for(const r of e){const{data:e,width:a,height:o,transform:l}=r,h=this.cachedCanvases.getCanvas("maskCanvas",a,o),c=h.context;c.save();const d=this.getObject(t,e,r);Ti(c,d),c.globalCompositeOperation="source-in",c.fillStyle=n?s.getPattern(c,this,Mt(i),ii.FILL,t):s,c.fillRect(0,0,a,o),c.restore(),i.save(),i.transform(...l),i.scale(1,-1),Si(i,h.canvas,0,0,a,o,0,-1,1,1),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):D("Dependent image isn't ready yet")}paintImageXObjectRepeat(t,e,i,s,n){if(!this.contentVisible)return;const r=this.getObject(t,e);if(!r)return void D("Dependent image isn't ready yet");const a=r.width,o=r.height,l=[];for(let h=0,c=n.length;h<c;h+=2)l.push({transform:[i,0,0,s,n[h],n[h+1]],x:0,y:0,w:a,h:o});this.paintInlineImageXObjectGroup(t,r,l)}applyTransferMapsToCanvas(t){return"none"!==this.current.transferMaps&&(t.filter=this.current.transferMaps,t.drawImage(t.canvas,0,0),t.filter="none"),t.canvas}applyTransferMapsToBitmap(t){if("none"===this.current.transferMaps)return t.bitmap;const{bitmap:e,width:i,height:s}=t,n=this.cachedCanvases.getCanvas("inlineImage",i,s),r=n.context;return r.filter=this.current.transferMaps,r.drawImage(e,0,0),r.filter="none",n.canvas}paintInlineImageXObject(t,e){if(!this.contentVisible)return;const i=e.width,s=e.height,n=this.ctx;this.save(t);const{filter:r}=n;let a;if("none"!==r&&""!==r&&(n.filter="none"),n.scale(1/i,-1/s),e.bitmap)a=this.applyTransferMapsToBitmap(e);else if("function"===typeof HTMLElement&&e instanceof HTMLElement||!e.data)a=e;else{const t=this.cachedCanvases.getCanvas("inlineImage",i,s),n=t.context;Ci(n,e),a=this.applyTransferMapsToCanvas(n)}const o=this._scaleImage(a,Mt(n));n.imageSmoothingEnabled=Pi(Tt(n),e.interpolate),this.dependencyTracker?.resetBBox(t).recordBBox(t,n,0,i,-s,0).recordDependencies(t,ei.imageXObject).recordOperation(t),Si(n,o.img,0,0,o.paintWidth,o.paintHeight,0,-s,i,s),this.compose(),this.restore(t)}paintInlineImageXObjectGroup(t,e,i){if(!this.contentVisible)return;const s=this.ctx;let n;if(e.bitmap)n=e.bitmap;else{const t=e.width,i=e.height,s=this.cachedCanvases.getCanvas("inlineImage",t,i),r=s.context;Ci(r,e),n=this.applyTransferMapsToCanvas(r)}this.dependencyTracker?.resetBBox(t);for(const r of i)s.save(),s.transform(...r.transform),s.scale(1,-1),Si(s,n,r.x,r.y,r.w,r.h,0,-1,1,1),this.dependencyTracker?.recordBBox(t,s,0,1,-1,0),s.restore();this.dependencyTracker?.recordOperation(t),this.compose()}paintSolidColorImageMask(t){this.contentVisible&&(this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,0,1,0,1).recordDependencies(t,ei.fill).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 s=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath(),this.pendingClip||this.compose(i);const n=this.ctx;this.pendingClip?(s||(this.pendingClip===Li?n.clip(e,"evenodd"):n.clip(e)),this.pendingClip=null,this.dependencyTracker?.bboxToClipBoxDropOperation(t).recordFutureForcedDependency("clipPath",t)):this.dependencyTracker?.recordOperation(t),this.current.startNewPathAndClipBox(this.current.clipBox)}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=Tt(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]),s=Math.hypot(t[1],t[3]);this._cachedGetSinglePixelWidth=Math.max(i,s)/e}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(-1===this._cachedScaleForStroking[0]){const{lineWidth:t}=this.current,{a:e,b:i,c:s,d:n}=this.ctx.getTransform();let r,a;if(0===i&&0===s){const i=Math.abs(e),s=Math.abs(n);if(i===s)if(0===t)r=a=1/i;else{const e=i*t;r=a=e<1?1/e:1}else if(0===t)r=1/i,a=1/s;else{const e=i*t,n=s*t;r=e<1?1/e:1,a=n<1?1/n:1}}else{const o=Math.abs(e*n-i*s),l=Math.hypot(e,i),h=Math.hypot(s,n);if(0===t)r=h/o,a=l/o;else{const e=t*o;r=h>e?h/e:1,a=l>e?l/e:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=a}return this._cachedScaleForStroking}rescaleAndStroke(t,e){const{ctx:i,current:{lineWidth:s}}=this,[n,r]=this.getScaleForStroking();if(n===r)return i.lineWidth=(s||1)*n,void i.stroke(t);const a=i.getLineDash();e&&i.save(),i.scale(n,r),yi.a=1/n,yi.d=1/r;const o=new Path2D;if(o.addPath(t,yi),a.length>0){const t=Math.max(n,r);i.setLineDash(a.map(e=>e/t)),i.lineDashOffset/=t}i.lineWidth=s||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 gr in x)void 0!==Fi.prototype[gr]&&(Fi.prototype[x[gr]]=Fi.prototype[gr]);class Oi{static#Ws=null;static#Vs="";static get workerPort(){return this.#Ws}static set workerPort(t){if(!("undefined"!==typeof Worker&&t instanceof Worker)&&null!==t)throw new Error("Invalid `workerPort` type.");this.#Ws=t}static get workerSrc(){return this.#Vs}static set workerSrc(t){if("string"!==typeof t)throw new Error("Invalid `workerSrc` type.");this.#Vs=t}}class Bi{#qs;#Xs;constructor({parsedData:t,rawData:e}){this.#qs=t,this.#Xs=e}getRaw(){return this.#Xs}get(t){return this.#qs.get(t)??null}[Symbol.iterator](){return this.#qs.entries()}}const Ni=Symbol("INTERNAL");class Ui{#Ys=!1;#Ks=!1;#Qs=!1;#Js=!0;constructor(t,{name:e,intent:i,usage:s,rbGroups:n}){this.#Ys=!!(t&c.DISPLAY),this.#Ks=!!(t&c.PRINT),this.name=e,this.intent=i,this.usage=s,this.rbGroups=n}get visible(){if(this.#Qs)return this.#Js;if(!this.#Js)return!1;const{print:t,view:e}=this.usage;return this.#Ys?"OFF"!==e?.viewState:!this.#Ks||"OFF"!==t?.printState}_setVisible(t,e,i=!1){t!==Ni&&P("Internal method `_setVisible` called."),this.#Qs=i,this.#Js=e}}class ji{#Zs=null;#tn=new Map;#en=null;#in=null;constructor(t,e=c.DISPLAY){if(this.renderingIntent=e,this.name=null,this.creator=null,null!==t){this.name=t.name,this.creator=t.creator,this.#in=t.order;for(const i of t.groups)this.#tn.set(i.id,new Ui(e,i));if("OFF"===t.baseState)for(const t of this.#tn.values())t._setVisible(Ni,!1);for(const e of t.on)this.#tn.get(e)._setVisible(Ni,!0);for(const e of t.off)this.#tn.get(e)._setVisible(Ni,!1);this.#en=this.getHash()}}#sn(t){const e=t.length;if(e<2)return!0;const i=t[0];for(let s=1;s<e;s++){const e=t[s];let n;if(Array.isArray(e))n=this.#sn(e);else{if(!this.#tn.has(e))return D(`Optional content group not found: ${e}`),!0;n=this.#tn.get(e).visible}switch(i){case"And":if(!n)return!1;break;case"Or":if(n)return!0;break;case"Not":return!n;default:return!0}}return"And"===i}isVisible(t){if(0===this.#tn.size)return!0;if(!t)return M("Optional content group not defined."),!0;if("OCG"===t.type)return this.#tn.has(t.id)?this.#tn.get(t.id).visible:(D(`Optional content group not found: ${t.id}`),!0);if("OCMD"===t.type){if(t.expression)return this.#sn(t.expression);if(!t.policy||"AnyOn"===t.policy){for(const e of t.ids){if(!this.#tn.has(e))return D(`Optional content group not found: ${e}`),!0;if(this.#tn.get(e).visible)return!0}return!1}if("AllOn"===t.policy){for(const e of t.ids){if(!this.#tn.has(e))return D(`Optional content group not found: ${e}`),!0;if(!this.#tn.get(e).visible)return!1}return!0}if("AnyOff"===t.policy){for(const e of t.ids){if(!this.#tn.has(e))return D(`Optional content group not found: ${e}`),!0;if(!this.#tn.get(e).visible)return!0}return!1}if("AllOff"===t.policy){for(const e of t.ids){if(!this.#tn.has(e))return D(`Optional content group not found: ${e}`),!0;if(this.#tn.get(e).visible)return!1}return!0}return D(`Unknown optional content policy ${t.policy}.`),!0}return D(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,i=!0){const s=this.#tn.get(t);if(s){if(i&&e&&s.rbGroups.length)for(const e of s.rbGroups)for(const i of e)i!==t&&this.#tn.get(i)?._setVisible(Ni,!1,!0);s._setVisible(Ni,!!e,!0),this.#Zs=null}else D(`Optional content group not found: ${t}`)}setOCGState({state:t,preserveRB:e}){let i;for(const s of t){switch(s){case"ON":case"OFF":case"Toggle":i=s;continue}const t=this.#tn.get(s);if(t)switch(i){case"ON":this.setVisibility(s,!0,e);break;case"OFF":this.setVisibility(s,!1,e);break;case"Toggle":this.setVisibility(s,!t.visible,e);break}}this.#Zs=null}get hasInitialVisibility(){return null===this.#en||this.getHash()===this.#en}getOrder(){return this.#tn.size?this.#in?this.#in.slice():[...this.#tn.keys()]:null}getGroup(t){return this.#tn.get(t)||null}getHash(){if(null!==this.#Zs)return this.#Zs;const t=new oe;for(const[e,i]of this.#tn)t.update(`${e}:${i.visible}`);return this.#Zs=t.hexdigest()}[Symbol.iterator](){return this.#tn.entries()}}class Hi{constructor(t,{disableRange:e=!1,disableStream:i=!1}){I(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');const{length:s,initialData:n,progressiveDone:r,contentDispositionFilename:a}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=a,n?.length>0){const t=n instanceof Uint8Array&&n.byteLength===n.buffer.byteLength?n.buffer:new Uint8Array(n).buffer;this._queuedChunks.push(t)}this._pdfDataRangeTransport=t,this._isStreamingSupported=!i,this._isRangeSupported=!e,this._contentLength=s,this._fullRequestReader=null,this._rangeReaders=[],t.addRangeListener((t,e)=>{this._onReceiveData({begin:t,chunk:e})}),t.addProgressListener((t,e)=>{this._onProgress({loaded:t,total:e})}),t.addProgressiveReadListener(t=>{this._onReceiveData({chunk:t})}),t.addProgressiveDoneListener(()=>{this._onProgressiveDone()}),t.transportReady()}_onReceiveData({begin:t,chunk:e}){const i=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;if(void 0===t)this._fullRequestReader?this._fullRequestReader._enqueue(i):this._queuedChunks.push(i);else{const e=this._rangeReaders.some(function(e){return e._begin===t&&(e._enqueue(i),!0)});I(e,"_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.")}}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}_onProgress(t){void 0===t.total?this._rangeReaders[0]?.onProgress?.({loaded:t.loaded}):this._fullRequestReader?.onProgress?.({loaded:t.loaded,total:t.total})}_onProgressiveDone(){this._fullRequestReader?.progressiveDone(),this._progressiveDone=!0}_removeRangeReader(t){const e=this._rangeReaders.indexOf(t);e>=0&&this._rangeReaders.splice(e,1)}getFullReader(){I(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new zi(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const i=new $i(this,t,e);return this._pdfDataRangeTransport.requestDataRange(t,e),this._rangeReaders.push(i),i}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(const e of this._rangeReaders.slice(0))e.cancel(t);this._pdfDataRangeTransport.abort()}}class zi{constructor(t,e,i=!1,s=null){this._stream=t,this._done=i||!1,this._filename=mt(s)?s:null,this._queuedChunks=e||[],this._loaded=0;for(const n of this._queuedChunks)this._loaded+=n.byteLength;this._requests=[],this._headersReady=Promise.resolve(),t._fullRequestReader=this,this.onProgress=null}_enqueue(t){if(!this._done){if(this._requests.length>0){const e=this._requests.shift();e.resolve({value:t,done:!1})}else this._queuedChunks.push(t);this._loaded+=t.byteLength}}get headersReady(){return this._headersReady}get filename(){return this._filename}get isRangeSupported(){return this._stream._isRangeSupported}get isStreamingSupported(){return this._stream._isStreamingSupported}get contentLength(){return this._stream._contentLength}async read(){if(this._queuedChunks.length>0){const t=this._queuedChunks.shift();return{value:t,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}progressiveDone(){this._done||(this._done=!0)}}class $i{constructor(t,e,i){this._stream=t,this._begin=e,this._end=i,this._queuedChunk=null,this._requests=[],this._done=!1,this.onProgress=null}_enqueue(t){if(!this._done){if(0===this._requests.length)this._queuedChunk=t;else{const e=this._requests.shift();e.resolve({value:t,done:!1});for(const t of this._requests)t.resolve({value:void 0,done:!0});this._requests.length=0}this._done=!0,this._stream._removeRangeReader(this)}}get isStreamingSupported(){return!1}async read(){if(this._queuedChunk){const t=this._queuedChunk;return this._queuedChunk=null,{value:t,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._stream._removeRangeReader(this)}}function Gi(t){let e=!0,i=s("filename\\*","i").exec(t);if(i){i=i[1];let t=o(i);return t=unescape(t),t=l(t),t=h(t),r(t)}if(i=a(t),i){const t=h(i);return r(t)}if(i=s("filename","i").exec(t),i){i=i[1];let t=o(i);return t=h(t),r(t)}function s(t,e){return new RegExp("(?:^|;)\\s*"+t+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',e)}function n(t,i){if(t){if(!/^[\x00-\xFF]+$/.test(i))return i;try{const s=new TextDecoder(t,{fatal:!0}),n=G(i);i=s.decode(n),e=!1}catch{}}return i}function r(t){return e&&/[\x80-\xff]/.test(t)&&(t=n("utf-8",t),e&&(t=n("iso-8859-1",t))),t}function a(t){const e=[];let i;const n=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");while(null!==(i=n.exec(t))){let[,t,s,n]=i;if(t=parseInt(t,10),t in e){if(0===t)break}else e[t]=[s,n]}const r=[];for(let s=0;s<e.length;++s){if(!(s in e))break;let[t,i]=e[s];i=o(i),t&&(i=unescape(i),0===s&&(i=l(i))),r.push(i)}return r.join("")}function o(t){if(t.startsWith('"')){const e=t.slice(1).split('\\"');for(let t=0;t<e.length;++t){const i=e[t].indexOf('"');-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 l(t){const e=t.indexOf("'");if(-1===e)return t;const i=t.slice(0,e),s=t.slice(e+1),r=s.replace(/^[^']*'/,"");return n(i,r)}function h(t){return!t.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(t)?t:t.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(t,e,i,s){if("q"===i||"Q"===i)return s=s.replaceAll("_"," "),s=s.replaceAll(/=([0-9a-fA-F]{2})/g,function(t,e){return String.fromCharCode(parseInt(e,16))}),n(e,s);try{s=atob(s)}catch{}return n(e,s)})}return""}function Wi(t,e){const i=new Headers;if(!t||!e||"object"!==typeof e)return i;for(const s in e){const t=e[s];void 0!==t&&i.append(s,t)}return i}function Vi(t){return URL.parse(t)?.origin??null}function qi({responseHeaders:t,isHttp:e,rangeChunkSize:i,disableRange:s}){const n={allowRangeRequests:!1,suggestedLength:void 0},r=parseInt(t.get("Content-Length"),10);if(!Number.isInteger(r))return n;if(n.suggestedLength=r,r<=2*i)return n;if(s||!e)return n;if("bytes"!==t.get("Accept-Ranges"))return n;const a=t.get("Content-Encoding")||"identity";return"identity"!==a||(n.allowRangeRequests=!0),n}function Xi(t){const e=t.get("Content-Disposition");if(e){let t=Gi(e);if(t.includes("%"))try{t=decodeURIComponent(t)}catch{}if(mt(t))return t}return null}function Yi(t,e){return new j(`Unexpected server response (${t}) while retrieving PDF "${e}".`,t,404===t||0===t&&e.startsWith("file:"))}function Ki(t){return 200===t||206===t}function Qi(t,e,i){return{method:"GET",headers:t,signal:i.signal,mode:"cors",credentials:e?"include":"same-origin",redirect:"follow"}}function Ji(t){return t instanceof Uint8Array?t.buffer:t instanceof ArrayBuffer?t:(D(`getArrayBuffer - unexpected data format: ${t}`),new Uint8Array(t).buffer)}class Zi{_responseOrigin=null;constructor(t){this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=Wi(this.isHttp,t.httpHeaders),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}getFullReader(){return I(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new ts(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const i=new es(this,t,e);return this._rangeRequestReaders.push(i),i}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(const e of this._rangeRequestReaders.slice(0))e.cancel(t)}}class ts{constructor(t){this._stream=t,this._reader=null,this._loaded=0,this._filename=null;const e=t.source;this._withCredentials=e.withCredentials||!1,this._contentLength=e.length,this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,this._rangeChunkSize||this._disableRange||(this._disableRange=!0),this._abortController=new AbortController,this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange;const i=new Headers(t.headers),s=e.url;fetch(s,Qi(i,this._withCredentials,this._abortController)).then(e=>{if(t._responseOrigin=Vi(e.url),!Ki(e.status))throw Yi(e.status,s);this._reader=e.body.getReader(),this._headersCapability.resolve();const i=e.headers,{allowRangeRequests:n,suggestedLength:r}=qi({responseHeaders:i,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=n,this._contentLength=r||this._contentLength,this._filename=Xi(i),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new z("Streaming is disabled."))}).catch(this._headersCapability.reject),this.onProgress=null}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(){await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,this.onProgress?.({loaded:this._loaded,total:this._contentLength}),{value:Ji(t),done:!1})}cancel(t){this._reader?.cancel(t),this._abortController.abort()}}class es{constructor(t,e,i){this._stream=t,this._reader=null,this._loaded=0;const s=t.source;this._withCredentials=s.withCredentials||!1,this._readCapability=Promise.withResolvers(),this._isStreamingSupported=!s.disableStream,this._abortController=new AbortController;const n=new Headers(t.headers);n.append("Range",`bytes=${e}-${i-1}`);const r=s.url;fetch(r,Qi(n,this._withCredentials,this._abortController)).then(e=>{const i=Vi(e.url);if(i!==t._responseOrigin)throw new Error(`Expected range response-origin "${i}" to match "${t._responseOrigin}".`);if(!Ki(e.status))throw Yi(e.status,r);this._readCapability.resolve(),this._reader=e.body.getReader()}).catch(this._readCapability.reject),this.onProgress=null}get isStreamingSupported(){return this._isStreamingSupported}async read(){await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,this.onProgress?.({loaded:this._loaded}),{value:Ji(t),done:!1})}cancel(t){this._reader?.cancel(t),this._abortController.abort()}}const is=200,ss=206;function ns(t){const e=t.response;return"string"!==typeof e?e:G(e).buffer}class rs{_responseOrigin=null;constructor({url:t,httpHeaders:e,withCredentials:i}){this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=Wi(this.isHttp,e),this.withCredentials=i||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}request(t){const e=new XMLHttpRequest,i=this.currXhrId++,s=this.pendingRequests[i]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),s.expectedStatus=ss):s.expectedStatus=is,e.responseType="arraybuffer",I(t.onError,"Expected `onError` callback to be provided."),e.onerror=()=>{t.onError(e.status)},e.onreadystatechange=this.onStateChange.bind(this,i),e.onprogress=this.onProgress.bind(this,i),s.onHeadersReceived=t.onHeadersReceived,s.onDone=t.onDone,s.onError=t.onError,s.onProgress=t.onProgress,e.send(null),i}onProgress(t,e){const i=this.pendingRequests[t];i&&i.onProgress?.(e)}onStateChange(t,e){const i=this.pendingRequests[t];if(!i)return;const s=i.xhr;if(s.readyState>=2&&i.onHeadersReceived&&(i.onHeadersReceived(),delete i.onHeadersReceived),4!==s.readyState)return;if(!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],0===s.status&&this.isHttp)return void i.onError(s.status);const n=s.status||is,r=n===is&&i.expectedStatus===ss;if(!r&&n!==i.expectedStatus)return void i.onError(s.status);const a=ns(s);if(n===ss){const t=s.getResponseHeader("Content-Range"),e=/bytes (\d+)-(\d+)\/(\d+)/.exec(t);e?i.onDone({begin:parseInt(e[1],10),chunk:a}):(D('Missing or invalid "Content-Range" header.'),i.onError(0))}else a?i.onDone({begin:0,chunk:a}):i.onError(s.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){const e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}}class as{constructor(t){this._source=t,this._manager=new rs(t),this._rangeChunkSize=t.rangeChunkSize,this._fullRequestReader=null,this._rangeRequestReaders=[]}_onRangeRequestReaderClosed(t){const e=this._rangeRequestReaders.indexOf(t);e>=0&&this._rangeRequestReaders.splice(e,1)}getFullReader(){return I(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new os(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const i=new ls(this._manager,t,e);return i.onClosed=this._onRangeRequestReaderClosed.bind(this),this._rangeRequestReaders.push(i),i}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(const e of this._rangeRequestReaders.slice(0))e.cancel(t)}}class os{constructor(t,e){this._manager=t,this._url=e.url,this._fullRequestId=t.request({onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,this._rangeChunkSize||this._disableRange||(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=Vi(e.responseURL);const i=e.getAllResponseHeaders(),s=new Headers(i?i.trimStart().replace(/[^\S ]+$/,"").split(/[\r\n]+/).map(t=>{const[e,...i]=t.split(": ");return[e,i.join(": ")]}):[]),{allowRangeRequests:n,suggestedLength:r}=qi({responseHeaders:s,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=Xi(s),this._isRangeSupported&&this._manager.abortRequest(t),this._headersCapability.resolve()}_onDone(t){if(t)if(this._requests.length>0){const e=this._requests.shift();e.resolve({value:t.chunk,done:!1})}else this._cachedChunks.push(t.chunk);if(this._done=!0,!(this._cachedChunks.length>0)){for(const t of this._requests)t.resolve({value:void 0,done:!0});this._requests.length=0}}_onError(t){this._storedError=Yi(t,this._url),this._headersCapability.reject(this._storedError);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}_onProgress(t){this.onProgress?.({loaded:t.loaded,total:t.lengthComputable?t.total:this._contentLength})}get filename(){return this._filename}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}get contentLength(){return this._contentLength}get headersReady(){return this._headersCapability.promise}async read(){if(await this._headersCapability.promise,this._storedError)throw this._storedError;if(this._cachedChunks.length>0){const t=this._cachedChunks.shift();return{value:t,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this._headersCapability.reject(t);for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._fullRequestId)&&this._manager.abortRequest(this._fullRequestId),this._fullRequestReader=null}}class ls{constructor(t,e,i){this._manager=t,this._url=t.url,this._requestId=t.request({begin:e,end:i,onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_onHeadersReceived(){const t=Vi(this._manager.getRequestXhr(this._requestId)?.responseURL);t!==this._manager._responseOrigin&&(this._storedError=new Error(`Expected range response-origin "${t}" to match "${this._manager._responseOrigin}".`),this._onError(0))}_close(){this.onClosed?.(this)}_onDone(t){const e=t.chunk;if(this._requests.length>0){const t=this._requests.shift();t.resolve({value:e,done:!1})}else this._queuedChunk=e;this._done=!0;for(const i of this._requests)i.resolve({value:void 0,done:!0});this._requests.length=0,this._close()}_onError(t){this._storedError??=Yi(t,this._url);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._queuedChunk=null}_onProgress(t){this.isStreamingSupported||this.onProgress?.({loaded:t.loaded})}get isStreamingSupported(){return!1}async read(){if(this._storedError)throw this._storedError;if(null!==this._queuedChunk){const t=this._queuedChunk;return this._queuedChunk=null,{value:t,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._requestId)&&this._manager.abortRequest(this._requestId),this._close()}}const hs=/^[a-z][a-z0-9\-+.]+:/i;function cs(t){if(hs.test(t))return new URL(t);const e=process.getBuiltinModule("url");return new URL(e.pathToFileURL(t))}class ds{constructor(t){this.source=t,this.url=cs(t.url),I("file:"===this.url.protocol,"PDFNodeStream only supports file:// URLs."),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}getFullReader(){return I(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new us(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const i=new ps(this,t,e);return this._rangeRequestReaders.push(i),i}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(const e of this._rangeRequestReaders.slice(0))e.cancel(t)}}class us{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null;const e=t.source;this._contentLength=e.length,this._loaded=0,this._filename=null,this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,this._rangeChunkSize||this._disableRange||(this._disableRange=!0),this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange,this._readableStream=null,this._readCapability=Promise.withResolvers(),this._headersCapability=Promise.withResolvers();const i=process.getBuiltinModule("fs");i.promises.lstat(this._url).then(t=>{this._contentLength=t.size,this._setReadableStream(i.createReadStream(this._url)),this._headersCapability.resolve()},t=>{"ENOENT"===t.code&&(t=Yi(0,this._url.href)),this._storedError=t,this._headersCapability.reject(t)})}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(){if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();if(null===t)return this._readCapability=Promise.withResolvers(),this.read();this._loaded+=t.length,this.onProgress?.({loaded:this._loaded,total:this._contentLength});const e=new Uint8Array(t).buffer;return{value:e,done:!1}}cancel(t){this._readableStream?this._readableStream.destroy(t):this._error(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",t=>{this._error(t)}),!this._isStreamingSupported&&this._isRangeSupported&&this._error(new z("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class ps{constructor(t,e,i){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null,this._loaded=0,this._readableStream=null,this._readCapability=Promise.withResolvers();const s=t.source;this._isStreamingSupported=!s.disableStream;const n=process.getBuiltinModule("fs");this._setReadableStream(n.createReadStream(this._url,{start:e,end:i-1}))}get isStreamingSupported(){return this._isStreamingSupported}async read(){if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();if(null===t)return this._readCapability=Promise.withResolvers(),this.read();this._loaded+=t.length,this.onProgress?.({loaded:this._loaded});const e=new Uint8Array(t).buffer;return{value:e,done:!1}}cancel(t){this._readableStream?this._readableStream.destroy(t):this._error(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",t=>{this._error(t)}),this._storedError&&this._readableStream.destroy(this._storedError)}}const gs=Symbol("INITIAL_DATA");class ms{#nn=Object.create(null);#rn(t){return this.#nn[t]||={...Promise.withResolvers(),data:gs}}get(t,e=null){if(e){const i=this.#rn(t);return i.promise.then(()=>e(i.data)),null}const i=this.#nn[t];if(!i||i.data===gs)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return i.data}has(t){const e=this.#nn[t];return!!e&&e.data!==gs}delete(t){const e=this.#nn[t];return!(!e||e.data===gs)&&(delete this.#nn[t],!0)}resolve(t,e=null){const i=this.#rn(t);i.data=e,i.resolve()}clear(){for(const t in this.#nn){const{data:e}=this.#nn[t];e?.bitmap?.close()}this.#nn=Object.create(null)}*[Symbol.iterator](){for(const t in this.#nn){const{data:e}=this.#nn[t];e!==gs&&(yield[t,e])}}}const fs=1e5,bs=30;class vs{#an=Promise.withResolvers();#Et=null;#on=!1;#ln=!!globalThis.FontInspector?.enabled;#hn=null;#cn=null;#dn=0;#un=0;#pn=null;#gn=null;#mn=0;#fn=0;#bn=Object.create(null);#vn=[];#yn=null;#wn=[];#An=new WeakMap;#xn=null;static#_n=new Map;static#Sn=new Map;static#En=new WeakMap;static#Cn=null;static#Tn=new Set;constructor({textContentSource:t,container:e,viewport:i}){if(t instanceof ReadableStream)this.#yn=t;else{if("object"!==typeof t)throw new Error('No "textContentSource" parameter specified.');this.#yn=new ReadableStream({start(e){e.enqueue(t),e.close()}})}this.#Et=this.#gn=e,this.#fn=i.scale*Pt.pixelRatio,this.#mn=i.rotation,this.#cn={div:null,properties:null,ctx:null};const{pageWidth:s,pageHeight:n,pageX:r,pageY:a}=i.rawDims;this.#xn=[1,0,0,-1,-r,a+n],this.#un=s,this.#dn=n,vs.#Mn(),e.style.setProperty("--min-font-size",vs.#Cn),Dt(e,i),this.#an.promise.finally(()=>{vs.#Tn.delete(this),this.#cn=null,this.#bn=null}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=X.platform;return F(this,"fontFamilyMap",new Map([["sans-serif",(t&&e?"Calibri, ":"")+"sans-serif"],["monospace",(t&&e?"Lucida Console, ":"")+"monospace"]]))}render(){const t=()=>{this.#pn.read().then(({value:e,done:i})=>{i?this.#an.resolve():(this.#hn??=e.lang,Object.assign(this.#bn,e.styles),this.#Dn(e.items),t())},this.#an.reject)};return this.#pn=this.#yn.getReader(),vs.#Tn.add(this),t(),this.#an.promise}update({viewport:t,onBefore:e=null}){const i=t.scale*Pt.pixelRatio,s=t.rotation;if(s!==this.#mn&&(e?.(),this.#mn=s,Dt(this.#gn,{rotation:s})),i!==this.#fn){e?.(),this.#fn=i;const t={div:null,properties:null,ctx:vs.#Pn(this.#hn)};for(const e of this.#wn)t.properties=this.#An.get(e),t.div=e,this.#In(t)}}cancel(){const t=new z("TextLayer task cancelled.");this.#pn?.cancel(t).catch(()=>{}),this.#pn=null,this.#an.reject(t)}get textDivs(){return this.#wn}get textContentItemsStr(){return this.#vn}#Dn(t){if(this.#on)return;this.#cn.ctx??=vs.#Pn(this.#hn);const e=this.#wn,i=this.#vn;for(const s of t){if(e.length>fs)return D("Ignoring additional textDivs for performance reasons."),void(this.#on=!0);if(void 0!==s.str)i.push(s.str),this.#kn(s);else if("beginMarkedContentProps"===s.type||"beginMarkedContent"===s.type){const t=this.#Et;this.#Et=document.createElement("span"),this.#Et.classList.add("markedContent"),s.id&&this.#Et.setAttribute("id",`${s.id}`),t.append(this.#Et)}else"endMarkedContent"===s.type&&(this.#Et=this.#Et.parentNode)}}#kn(t){const e=document.createElement("span"),i={angle:0,canvasWidth:0,hasText:""!==t.str,hasEOL:t.hasEOL,fontSize:0};this.#wn.push(e);const s=K.transform(this.#xn,t.transform);let n=Math.atan2(s[1],s[0]);const r=this.#bn[t.fontName];r.vertical&&(n+=Math.PI/2);let a=this.#ln&&r.fontSubstitution||r.fontFamily;a=vs.fontFamilyMap.get(a)||a;const o=Math.hypot(s[2],s[3]),l=o*vs.#Rn(a,r,this.#hn);let h,c;0===n?(h=s[4],c=s[5]-l):(h=s[4]+l*Math.sin(n),c=s[5]-l*Math.cos(n));const d=e.style;d.left=`${(100*h/this.#un).toFixed(2)}%`,d.top=`${(100*c/this.#dn).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.#ln&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),0!==n&&(i.angle=n*(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)}if(u&&(i.canvasWidth=r.vertical?t.height:t.width),this.#An.set(e,i),this.#cn.div=e,this.#cn.properties=i,this.#In(this.#cn),i.hasText&&this.#Et.append(e),i.hasEOL){const t=document.createElement("br");t.setAttribute("role","presentation"),this.#Et.append(t)}}#In(t){const{div:e,properties:i,ctx:s}=t,{style:n}=e;if(0!==i.canvasWidth&&i.hasText){const{fontFamily:t}=n,{canvasWidth:r,fontSize:a}=i;vs.#Ln(s,a*this.#fn,t);const{width:o}=s.measureText(e.textContent);o>0&&n.setProperty("--scale-x",r*this.#fn/o)}0!==i.angle&&n.setProperty("--rotate",`${i.angle}deg`)}static cleanup(){if(!(this.#Tn.size>0)){this.#_n.clear();for(const{canvas:t}of this.#Sn.values())t.remove();this.#Sn.clear()}}static#Pn(t=null){let e=this.#Sn.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.#Sn.set(t,e),this.#En.set(e,{size:0,family:""})}return e}static#Ln(t,e,i){const s=this.#En.get(t);e===s.size&&i===s.family||(t.font=`${e}px ${i}`,s.size=e,s.family=i)}static#Mn(){if(null!==this.#Cn)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.#Cn=t.getBoundingClientRect().height,t.remove()}static#Rn(t,e,i){const s=this.#_n.get(t);if(s)return s;const n=this.#Pn(i);n.canvas.width=n.canvas.height=bs,this.#Ln(n,bs,t);const r=n.measureText(""),a=r.fontBoundingBoxAscent,o=Math.abs(r.fontBoundingBoxDescent);n.canvas.width=n.canvas.height=0;let l=.8;return a?l=a/(a+o):(X.platform.isFirefox&&D("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.#_n.set(t,l),l}}const ys=100;function ws(t={}){"string"===typeof t||t instanceof URL?t={url:t}:(t instanceof ArrayBuffer||ArrayBuffer.isView(t))&&(t={data:t});const e=new As,{docId:i}=e,s=t.url?ve(t.url):null,n=t.data?ye(t.data):null,r=t.httpHeaders||null,a=!0===t.withCredentials,l=t.password??null,h=t.range instanceof xs?t.range:null,c=Number.isInteger(t.rangeChunkSize)&&t.rangeChunkSize>0?t.rangeChunkSize:65536;let d=t.worker instanceof Es?t.worker:null;const u=t.verbosity,p="string"!==typeof t.docBaseUrl||gt(t.docBaseUrl)?null:t.docBaseUrl,g=we(t.cMapUrl),m=!1!==t.cMapPacked,f=t.CMapReaderFactory||(o?$e:Re),b=we(t.iccUrl),v=we(t.standardFontDataUrl),y=t.StandardFontDataFactory||(o?Ge:Be),w=we(t.wasmUrl),A=t.WasmFactory||(o?We:Ue),x=!0!==t.stopAtErrors,_=Number.isInteger(t.maxImageSize)&&t.maxImageSize>-1?t.maxImageSize:-1,S=!1!==t.isEvalSupported,E="boolean"===typeof t.isOffscreenCanvasSupported?t.isOffscreenCanvasSupported:!o,T="boolean"===typeof t.isImageDecoderSupported?t.isImageDecoderSupported:!o&&(X.platform.isFirefox||!globalThis.chrome),M=Number.isInteger(t.canvasMaxAreaInBytes)?t.canvasMaxAreaInBytes:-1,D="boolean"===typeof t.disableFontFace?t.disableFontFace:o,P=!0===t.fontExtraProperties,I=!0===t.enableXfa,k=t.ownerDocument||globalThis.document,R=!0===t.disableRange,L=!0===t.disableStream,F=!0===t.disableAutoFetch,O=!0===t.pdfBug,B=t.CanvasFactory||(o?ze:Ie),N=t.FilterFactory||(o?He:Fe),U=!0===t.enableHWA,j=!1!==t.useWasm,H=h?h.length:t.length??NaN,z="boolean"===typeof t.useSystemFonts?t.useSystemFonts:!o&&!D,$="boolean"===typeof t.useWorkerFetch?t.useWorkerFetch:!!(f===Re&&y===Be&&A===Ue&&g&&v&&w&&yt(g,document.baseURI)&&yt(v,document.baseURI)&&yt(w,document.baseURI)),G=null;C(u);const W={canvasFactory:new B({ownerDocument:k,enableHWA:U}),filterFactory:new N({docId:i,ownerDocument:k}),cMapReaderFactory:$?null:new f({baseUrl:g,isCompressed:m}),standardFontDataFactory:$?null:new y({baseUrl:v}),wasmFactory:$?null:new A({baseUrl:w})};d||(d=Es.create({verbosity:u,port:Oi.workerPort}),e._worker=d);const V={docId:i,apiVersion:"5.4.530",data:n,password:l,disableAutoFetch:F,rangeChunkSize:c,length:H,docBaseUrl:p,enableXfa:I,evaluatorOptions:{maxImageSize:_,disableFontFace:D,ignoreErrors:x,isEvalSupported:S,isOffscreenCanvasSupported:E,isImageDecoderSupported:T,canvasMaxAreaInBytes:M,fontExtraProperties:P,useSystemFonts:z,useWasm:j,useWorkerFetch:$,cMapUrl:g,iccUrl:b,standardFontDataUrl:v,wasmUrl:w}},q={ownerDocument:k,pdfBug:O,styleElement:G,loadingParams:{disableAutoFetch:F,enableXfa:I}};return d.promise.then(function(){if(e.destroyed)throw new Error("Loading aborted");if(d.destroyed)throw new Error("Worker was destroyed");const t=d.messageHandler.sendWithPromise("GetDocRequest",V,n?[n.buffer]:null);let l;if(h)l=new Hi(h,{disableRange:R,disableStream:L});else if(!n){if(!s)throw new Error("getDocument - no `url` parameter provided.");const t=yt(s)?Zi:o?ds:as;l=new t({url:s,length:H,httpHeaders:r,withCredentials:a,rangeChunkSize:c,disableRange:R,disableStream:L})}return t.then(t=>{if(e.destroyed)throw new Error("Loading aborted");if(d.destroyed)throw new Error("Worker was destroyed");const s=new De(i,t,d.port),n=new Cs(s,e,l,q,W,U);e._transport=n,s.send("Ready",null)})}).catch(e._capability.reject),e}class As{static#ns=0;_capability=Promise.withResolvers();_transport=null;_worker=null;docId="d"+As.#ns++;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){throw this._worker?.port&&delete this._worker._pendingDestroy,t}this._transport=null,this._worker?.destroy(),this._worker=null}async getData(){return this._transport.getData()}}class xs{#an=Promise.withResolvers();#Fn=[];#On=[];#Bn=[];#Nn=[];constructor(t,e,i=!1,s=null){this.length=t,this.initialData=e,this.progressiveDone=i,this.contentDispositionFilename=s}addRangeListener(t){this.#Nn.push(t)}addProgressListener(t){this.#Bn.push(t)}addProgressiveReadListener(t){this.#On.push(t)}addProgressiveDoneListener(t){this.#Fn.push(t)}onDataRange(t,e){for(const i of this.#Nn)i(t,e)}onDataProgress(t,e){this.#an.promise.then(()=>{for(const i of this.#Bn)i(t,e)})}onDataProgressiveRead(t){this.#an.promise.then(()=>{for(const e of this.#On)e(t)})}onDataProgressiveDone(){this.#an.promise.then(()=>{for(const t of this.#Fn)t()})}transportReady(){this.#an.resolve()}requestDataRange(t,e){P("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class _s{constructor(t,e){this._pdfInfo=t,this._transport=e}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 F(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}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 Ss{#Un=!1;constructor(t,e,i,s=!1){this._pageIndex=t,this._pageInfo=e,this._transport=i,this._stats=s?new vt:null,this._pdfBug=s,this.commonObjs=i.commonObjs,this.objs=new ms,this._intentStates=new Map,this.destroyed=!1,this.recordedBBoxes=null}get pageNumber(){return this._pageIndex+1}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:s=0,dontFlip:n=!1}={}){return new ut({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:i,offsetY:s,dontFlip:n})}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 F(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:s="display",annotationMode:n=d.ENABLE,transform:r=null,background:a=null,optionalContentConfigPromise:o=null,annotationCanvasMap:l=null,pageColors:h=null,printAnnotationStorage:u=null,isEditing:p=!1,recordOperations:g=!1,operationsFilter:m=null}){this._stats?.time("Overall");const f=this._transport.getRenderingIntent(s,n,u,p),{renderingIntent:b,cacheKey:v}=f;this.#Un=!1,o||=this._transport.getOptionalContentConfig(b);let y=this._intentStates.get(v);y||(y=Object.create(null),this._intentStates.set(v,y)),y.streamReaderCancelTimeout&&(clearTimeout(y.streamReaderCancelTimeout),y.streamReaderCancelTimeout=null);const w=!!(b&c.PRINT);y.displayReadyCapability||(y.displayReadyCapability=Promise.withResolvers(),y.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time("Page Request"),this._pumpOperatorList(f));const A=Boolean(this._pdfBug&&globalThis.StepperManager?.enabled),x=!this.recordedBBoxes&&(g||A),_=t=>{if(y.renderTasks.delete(S),x){const t=S.gfx?.dependencyTracker.take();t&&(S.stepper&&S.stepper.setOperatorBBoxes(t,S.gfx.dependencyTracker.takeDebugMetadata()),g&&(this.recordedBBoxes=t))}w&&(this.#Un=!0),this.#jn(),t?(S.capability.reject(t),this._abortOperatorList({intentState:y,reason:t instanceof Error?t:new Error(t)})):S.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),globalThis.Stats?.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},S=new Ms({callback:_,params:{canvas:e,canvasContext:t,dependencyTracker:x?new Ze(e,y.operatorList.length,A):null,viewport:i,transform:r,background:a},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:l,operatorList:y.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!w,pdfBug:this._pdfBug,pageColors:h,enableHWA:this._transport.enableHWA,operationsFilter:m});(y.renderTasks||=new Set).add(S);const E=S.task;return Promise.all([y.displayReadyCapability.promise,o]).then(([t,e])=>{if(this.destroyed)_();else{if(this._stats?.time("Rendering"),!(e.renderingIntent&b))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(_),E}getOperatorList({intent:t="display",annotationMode:e=d.ENABLE,printAnnotationStorage:i=null,isEditing:s=!1}={}){function n(){o.operatorList.lastChunk&&(o.opListReadCapability.resolve(o.operatorList),o.renderTasks.delete(a))}const r=this._transport.getRenderingIntent(t,e,i,s,!0);let a,o=this._intentStates.get(r.cacheKey);return o||(o=Object.create(null),this._intentStates.set(r.cacheKey,o)),o.opListReadCapability||(a=Object.create(null),a.operatorListChanged=n,o.opListReadCapability=Promise.withResolvers(),(o.renderTasks||=new Set).add(a),o.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time("Page Request"),this._pumpOperatorList(r)),o.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){const i=100;return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:!0===t,disableNormalization:!0===e},{highWaterMark:i,size(t){return t.items.length}})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(t=>ot.textContent(t));const e=this.streamTextContent(t);return new Promise(function(t,i){function s(){n.read().then(function({value:e,done:i}){i?t(r):(r.lang??=e.lang,Object.assign(r.styles,e.styles),r.items.push(...e.items),s())},i)}const n=e.getReader(),r={items:[],styles:Object.create(null),lang:null};s()})}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;const t=[];for(const e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(const i of e.renderTasks)t.push(i.completed),i.cancel();return this.objs.clear(),this.#Un=!1,Promise.all(t)}cleanup(t=!1){this.#Un=!0;const e=this.#jn();return t&&e&&(this._stats&&=new vt),e}#jn(){if(!this.#Un||this.destroyed)return!1;for(const{renderTasks:t,operatorList:e}of this._intentStates.values())if(t.size>0||!e.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),this.#Un=!1,!0}_startRenderPage(t,e){const i=this._intentStates.get(e);i&&(this._stats?.timeEnd("Page Request"),i.displayReadyCapability?.resolve(t))}_renderPageChunk(t,e){for(let i=0,s=t.length;i<s;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 i of e.renderTasks)i.operatorListChanged();t.lastChunk&&this.#jn()}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:i,modifiedIds:s}){const{map:n,transfer:r}=i,a=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageIndex:this._pageIndex,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:s},r),o=a.getReader(),l=this._intentStates.get(e);l.streamReader=o;const h=()=>{o.read().then(({value:t,done:e})=>{e?l.streamReader=null:this._transport.destroyed||(this._renderPageChunk(t,l),h())},t=>{if(l.streamReader=null,!this._transport.destroyed){if(l.operatorList){l.operatorList.lastChunk=!0;for(const t of l.renderTasks)t.operatorListChanged();this.#jn()}if(l.displayReadyCapability)l.displayReadyCapability.reject(t);else{if(!l.opListReadCapability)throw t;l.opListReadCapability.reject(t)}}})};h()}_abortOperatorList({intentState:t,reason:e,force:i=!1}){if(t.streamReader){if(t.streamReaderCancelTimeout&&(clearTimeout(t.streamReaderCancelTimeout),t.streamReaderCancelTimeout=null),!i){if(t.renderTasks.size>0)return;if(e instanceof pt){let i=ys;return e.extraDelay>0&&e.extraDelay<1e3&&(i+=e.extraDelay),void(t.streamReaderCancelTimeout=setTimeout(()=>{t.streamReaderCancelTimeout=null,this._abortOperatorList({intentState:t,reason:e,force:!0})},i))}}if(t.streamReader.cancel(new z(e.message)).catch(()=>{}),t.streamReader=null,!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 Es{#an=Promise.withResolvers();#Hn=null;#Ws=null;#zn=null;static#$n=0;static#Gn=!1;static#Wn=new WeakMap;static{o&&(this.#Gn=!0,Oi.workerSrc||="./pdf.worker.mjs"),this._isSameOrigin=(t,e)=>{const i=URL.parse(t);if(!i?.origin||"null"===i.origin)return!1;const s=new URL(e,i);return i.origin===s.origin},this._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))},this.fromPort=t=>{if(xt("`PDFWorker.fromPort` - please use `PDFWorker.create` instead."),!t?.port)throw new Error("PDFWorker.fromPort - invalid method signature.");return this.create(t)}}constructor({name:t=null,port:e=null,verbosity:i=T()}={}){if(this.name=t,this.destroyed=!1,this.verbosity=i,e){if(Es.#Wn.has(e))throw new Error("Cannot use more than one PDFWorker per port.");Es.#Wn.set(e,this),this.#Vn(e)}else this.#qn()}get promise(){return this.#an.promise}#Xn(){this.#an.resolve(),this.#Hn.send("configure",{verbosity:this.verbosity})}get port(){return this.#Ws}get messageHandler(){return this.#Hn}#Vn(t){this.#Ws=t,this.#Hn=new De("main","worker",t),this.#Hn.on("ready",()=>{}),this.#Xn()}#qn(){if(Es.#Gn||Es.#Yn)return void this.#Kn();let{workerSrc:t}=Es;try{Es._isSameOrigin(window.location,t)||(t=Es._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),i=new De("main","worker",e),s=()=>{n.abort(),i.destroy(),e.terminate(),this.destroyed?this.#an.reject(new Error("Worker was destroyed")):this.#Kn()},n=new AbortController;e.addEventListener("error",()=>{this.#zn||s()},{signal:n.signal}),i.on("test",t=>{n.abort(),!this.destroyed&&t?(this.#Hn=i,this.#Ws=e,this.#zn=e,this.#Xn()):s()}),i.on("ready",t=>{if(n.abort(),this.destroyed)s();else try{r()}catch{this.#Kn()}});const r=()=>{const t=new Uint8Array;i.send("test",t,[t.buffer])};return void r()}catch{M("The worker has been disabled.")}this.#Kn()}#Kn(){Es.#Gn||(D("Setting up fake worker."),Es.#Gn=!0),Es._setupFakeWorkerGlobal.then(t=>{if(this.destroyed)return void this.#an.reject(new Error("Worker was destroyed"));const e=new Se;this.#Ws=e;const i="fake"+Es.#$n++,s=new De(i+"_worker",i,e);t.setup(s,e),this.#Hn=new De(i,i+"_worker",e),this.#Xn()}).catch(t=>{this.#an.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){this.destroyed=!0,this.#zn?.terminate(),this.#zn=null,Es.#Wn.delete(this.#Ws),this.#Ws=null,this.#Hn?.destroy(),this.#Hn=null}static create(t){const e=this.#Wn.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 Es(t)}static get workerSrc(){if(Oi.workerSrc)return Oi.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get#Yn(){try{return globalThis.pdfjsWorker?.WorkerMessageHandler||null}catch{return null}}static get _setupFakeWorkerGlobal(){const t=async()=>{if(this.#Yn)return this.#Yn;const t=await import(this.workerSrc);return t.WorkerMessageHandler};return F(this,"_setupFakeWorkerGlobal",t())}}class Cs{#Qn=new Map;#Jn=new Map;#Zn=new Map;#tr=new Map;#er=null;constructor(t,e,i,s,n,r){this.messageHandler=t,this.loadingTask=e,this.commonObjs=new ms,this.fontLoader=new de({ownerDocument:s.ownerDocument,styleElement:s.styleElement}),this.loadingParams=s.loadingParams,this._params=s,this.canvasFactory=n.canvasFactory,this.filterFactory=n.filterFactory,this.cMapReaderFactory=n.cMapReaderFactory,this.standardFontDataFactory=n.standardFontDataFactory,this.wasmFactory=n.wasmFactory,this.destroyed=!1,this.destroyCapability=null,this._networkStream=i,this._fullReader=null,this._lastProgress=null,this.downloadInfoCapability=Promise.withResolvers(),this.enableHWA=r,this.setupMessageHandler()}#ir(t,e=null){const i=this.#Qn.get(t);if(i)return i;const s=this.messageHandler.sendWithPromise(t,e);return this.#Qn.set(t,s),s}get annotationStorage(){return F(this,"annotationStorage",new he)}getRenderingIntent(t,e=d.ENABLE,i=null,s=!1,n=!1){let r=c.DISPLAY,a=le;switch(t){case"any":r=c.ANY;break;case"display":break;case"print":r=c.PRINT;break;default:D(`getRenderingIntent - invalid intent: ${t}`)}const o=r&c.PRINT&&i instanceof ce?i:this.annotationStorage;switch(e){case d.DISABLE:r+=c.ANNOTATIONS_DISABLE;break;case d.ENABLE:break;case d.ENABLE_FORMS:r+=c.ANNOTATIONS_FORMS;break;case d.ENABLE_STORAGE:r+=c.ANNOTATIONS_STORAGE,a=o.serializable;break;default:D(`getRenderingIntent - invalid annotationMode: ${e}`)}s&&(r+=c.IS_EDITING),n&&(r+=c.OPLIST);const{ids:l,hash:h}=o.modifiedIds,u=[r,a.hash,h];return{renderingIntent:r,cacheKey:u.join("_"),annotationStorageSerializable:a,modifiedIds:l}}destroy(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),this.#er?.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of this.#Jn.values())t.push(i._destroy());this.#Jn.clear(),this.#Zn.clear(),this.#tr.clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{this.commonObjs.clear(),this.fontLoader.clear(),this.#Qn.clear(),this.filterFactory.destroy(),vs.cleanup(),this._networkStream?.cancelAllRequests(new z("Worker was terminated.")),this.messageHandler?.destroy(),this.messageHandler=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(t,e)=>{I(this._networkStream,"GetReader - no `IPDFStream` instance available."),this._fullReader=this._networkStream.getFullReader(),this._fullReader.onProgress=t=>{this._lastProgress={loaded:t.loaded,total:t.total}},e.onPull=()=>{this._fullReader.read().then(function({value:t,done:i}){i?e.close():(I(t instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer."),e.enqueue(new Uint8Array(t),1,[t]))}).catch(t=>{e.error(t)})},e.onCancel=t=>{this._fullReader.cancel(t),e.ready.catch(t=>{if(!this.destroyed)throw t})}}),t.on("ReaderHeadersReady",async t=>{await this._fullReader.headersReady;const{isStreamingSupported:i,isRangeSupported:s,contentLength:n}=this._fullReader;return i&&s||(this._lastProgress&&e.onProgress?.(this._lastProgress),this._fullReader.onProgress=t=>{e.onProgress?.({loaded:t.loaded,total:t.total})}),{isStreamingSupported:i,isRangeSupported:s,contentLength:n}}),t.on("GetRangeReader",(t,e)=>{I(this._networkStream,"GetRangeReader - no `IPDFStream` instance available.");const i=this._networkStream.getRangeReader(t.begin,t.end);i?(e.onPull=()=>{i.read().then(function({value:t,done:i}){i?e.close():(I(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})}):e.close()}),t.on("GetDoc",({pdfInfo:t})=>{this._numPages=t.numPages,this._htmlForXfa=t.htmlForXfa,delete t.htmlForXfa,e._capability.resolve(new _s(t,this))}),t.on("DocException",t=>{e._capability.reject(Me(t))}),t.on("PasswordRequest",t=>{this.#er=Promise.withResolvers();try{if(!e.onPassword)throw Me(t);const i=t=>{t instanceof Error?this.#er.reject(t):this.#er.resolve({password:t})};e.onPassword(i,t.code)}catch(i){this.#er.reject(i)}return this.#er.promise}),t.on("DataLoaded",t=>{e.onProgress?.({loaded:t.length,total:t.length}),this.downloadInfoCapability.resolve(t)}),t.on("StartRenderPage",t=>{if(this.destroyed)return;const e=this.#Jn.get(t.pageIndex);e._startRenderPage(t.transparency,t.cacheKey)}),t.on("commonobj",([e,i,s])=>{if(this.destroyed)return null;if(this.commonObjs.has(e))return null;switch(i){case"Font":if("error"in s){const t=s.error;D(`Error during font loading: ${t}`),this.commonObjs.resolve(e,t);break}const n=new me(s),r=this._params.pdfBug&&globalThis.FontInspector?.enabled?(t,e)=>globalThis.FontInspector.fontAdded(t,e):null,a=new ue(n,r,s.extra,s.charProcOperatorList);this.fontLoader.bind(a).catch(()=>t.sendWithPromise("FontFallback",{id:e})).finally(()=>{!a.fontExtraProperties&&a.data&&a.clearData(),this.commonObjs.resolve(e,a)});break;case"CopyLocalImage":const{imageRef:o}=s;I(o,"The imageRef must be defined.");for(const t of this.#Jn.values())for(const[,i]of t.objs)if(i?.ref===o)return i.dataLen?(this.commonObjs.resolve(e,structuredClone(i)),i.dataLen):null;break;case"FontPath":this.commonObjs.resolve(e,new be(s));break;case"Image":this.commonObjs.resolve(e,s);break;case"Pattern":const l=new fe(s);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,s])=>{if(this.destroyed)return;const n=this.#Jn.get(e);if(!n.objs.has(t))if(0!==n._intentStates.size)switch(i){case"Image":case"Pattern":n.objs.resolve(t,s);break;default:throw new Error(`Got unknown object type ${i}`)}else s?.bitmap?.close()}),t.on("DocProgress",t=>{this.destroyed||e.onProgress?.({loaded:t.loaded,total:t.total})}),t.on("FetchBinaryData",async t=>{if(this.destroyed)throw new Error("Worker was destroyed.");const e=this[t.type];if(!e)throw new Error(`${t.type} not initialized, see the \`useWorkerFetch\` parameter.`);return e.fetch(t)})}getData(){return this.messageHandler.sendWithPromise("GetData",null)}saveDocument(){this.annotationStorage.size<=0&&D("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._fullReader?.filename??null},e).finally(()=>{this.annotationStorage.resetModified()})}extractPages(t){return this.messageHandler.sendWithPromise("ExtractPages",{pageInfos:t})}getPage(t){if(!Number.isInteger(t)||t<=0||t>this._numPages)return Promise.reject(new Error("Invalid page request."));const e=t-1,i=this.#Zn.get(e);if(i)return i;const s=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then(i=>{if(this.destroyed)throw new Error("Transport destroyed");i.refStr&&this.#tr.set(i.refStr,t);const s=new Ss(e,i,this,this._params.pdfBug);return this.#Jn.set(e,s),s});return this.#Zn.set(e,s),s}getPageIndex(t){return Ae(t)?this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}):Promise.reject(new Error("Invalid pageIndex request."))}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:t,intent:e})}getFieldObjects(){return this.#ir("GetFieldObjects")}hasJSActions(){return this.#ir("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.#ir("GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:t})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:t})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){return this.#ir("GetOptionalContentConfig").then(e=>new ji(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=this.#Qn.get(t);if(e)return e;const i=this.messageHandler.sendWithPromise(t,null).then(t=>({info:t[0],metadata:t[1]?new Bi(t[1]):null,contentDispositionFilename:this._fullReader?.filename??null,contentLength:this._fullReader?.contentLength??null,hasStructTree:t[2]}));return this.#Qn.set(t,i),i}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const t of this.#Jn.values()){const e=t.cleanup();if(!e)throw new Error(`startCleanup: Page ${t.pageNumber} is currently rendering.`)}this.commonObjs.clear(),t||this.fontLoader.clear(),this.#Qn.clear(),this.filterFactory.destroy(!0),vs.cleanup()}}cachedPageNumber(t){if(!Ae(t))return null;const e=0===t.gen?`${t.num}R`:`${t.num}R${t.gen}`;return this.#tr.get(e)??null}}class Ts{#sr=null;onContinue=null;onError=null;constructor(t){this.#sr=t}get promise(){return this.#sr.capability.promise}cancel(t=0){this.#sr.cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=this.#sr.operatorList;if(!t)return!1;const{annotationCanvasMap:e}=this.#sr;return t.form||t.canvas&&e?.size>0}}class Ms{#nr=null;static#rr=new WeakSet;constructor({callback:t,params:e,objs:i,commonObjs:s,annotationCanvasMap:n,operatorList:r,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=s,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,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 Ts(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._operationsFilter=p}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){if(this.cancelled)return;if(this._canvas){if(Ms.#rr.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.");Ms.#rr.add(this._canvas)}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:s,background:n,dependencyTracker:r}=this.params,a=this._canvasContext||this._canvas.getContext("2d",{alpha:!1,willReadFrequently:!this._enableHWA});this.gfx=new Fi(a,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors,r),this.gfx.beginDrawing({transform:s,viewport:i,transparency:t,background:n}),this.operatorListIdx=0,this.graphicsReady=!0,this.graphicsReadyCallback?.()}cancel(t=null,e=0){this.running=!1,this.cancelled=!0,this.gfx?.endDrawing(),this.#nr&&(window.cancelAnimationFrame(this.#nr),this.#nr=null),Ms.#rr.delete(this._canvas),t||=new pt(`Rendering cancelled, page ${this._pageIndex+1}`,e),this.callback(t),this.task.onError?.(t)}operatorListChanged(){this.graphicsReady?(this.gfx.dependencyTracker?.growOperationsCount(this.operatorList.fnArray.length),this.stepper?.updateOperatorList(this.operatorList),this.running||this._continue()):this.graphicsReadyCallback||=this._continueBound}_continue(){this.running=!0,this.cancelled||(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?this.#nr=window.requestAnimationFrame(()=>{this.#nr=null,this._nextBound().catch(this._cancelBound)}):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper,this._operationsFilter),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),Ms.#rr.delete(this._canvas),this.callback())))}}const Ds="5.4.530",Ps="50cc4adac";class Is{#ar=null;#or=null;#lr;#hr=null;#cr=!1;#dr=!1;#r=null;#ur;#pr=null;#b=null;static#gr=null;static get _keyboardManager(){return F(this,"_keyboardManager",new Kt([[["Escape","mac+Escape"],Is.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Is.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Is.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Is.prototype._moveToPrevious],[["Home","mac+Home"],Is.prototype._moveToBeginning],[["End","mac+End"],Is.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#dr=!1,this.#r=t):this.#dr=!0,this.#b=t?._uiManager||e,this.#ur=this.#b._eventBus,this.#lr=t?.color?.toUpperCase()||this.#b?.highlightColors.values().next().value||"#FFFF98",Is.#gr||=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.#ar=document.createElement("button");t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.ariaHasPopup="true",this.#r&&(t.ariaControls=`${this.#r.id}_colorpicker_dropdown`);const e=this.#b._signal;t.addEventListener("click",this.#mr.bind(this),{signal:e}),t.addEventListener("keydown",this.#fr.bind(this),{signal:e});const i=this.#or=document.createElement("span");return i.className="swatch",i.ariaHidden="true",i.style.backgroundColor=this.#lr,t.append(i),t}renderMainDropdown(){const t=this.#hr=this.#br();return t.ariaOrientation="horizontal",t.ariaLabelledBy="highlightColorPickerLabel",t}#br(){const t=document.createElement("div"),e=this.#b._signal;t.addEventListener("contextmenu",wt,{signal:e}),t.className="dropdown",t.role="listbox",t.ariaMultiSelectable="false",t.ariaOrientation="vertical",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown"),this.#r&&(t.id=`${this.#r.id}_colorpicker_dropdown`);for(const[i,s]of this.#b.highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",s),n.title=i,n.setAttribute("data-l10n-id",Is.#gr[i]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=s,n.ariaSelected=s===this.#lr,n.addEventListener("click",this.#vr.bind(this,s),{signal:e}),t.append(n)}return t.addEventListener("keydown",this.#fr.bind(this),{signal:e}),t}#vr(t,e){e.stopPropagation(),this.#ur.dispatch("switchannotationeditorparams",{source:this,type:g.HIGHLIGHT_COLOR,value:t}),this.updateColor(t)}_colorSelectFromKeyboard(t){if(t.target===this.#ar)return void this.#mr(t);const e=t.target.getAttribute("data-color");e&&this.#vr(e,t)}_moveToNext(t){this.#yr?t.target!==this.#ar?t.target.nextSibling?.focus():this.#hr.firstElementChild?.focus():this.#mr(t)}_moveToPrevious(t){t.target!==this.#hr?.firstElementChild&&t.target!==this.#ar?(this.#yr||this.#mr(t),t.target.previousSibling?.focus()):this.#yr&&this._hideDropdownFromKeyboard()}_moveToBeginning(t){this.#yr?this.#hr.firstElementChild?.focus():this.#mr(t)}_moveToEnd(t){this.#yr?this.#hr.lastElementChild?.focus():this.#mr(t)}#fr(t){Is._keyboardManager.exec(this,t)}#mr(t){if(this.#yr)return void this.hideDropdown();if(this.#cr=0===t.detail,this.#pr||(this.#pr=new AbortController,window.addEventListener("pointerdown",this.#u.bind(this),{signal:this.#b.combinedSignal(this.#pr)})),this.#ar.ariaExpanded="true",this.#hr)return void this.#hr.classList.remove("hidden");const e=this.#hr=this.#br();this.#ar.append(e)}#u(t){this.#hr?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#hr?.classList.add("hidden"),this.#ar.ariaExpanded="false",this.#pr?.abort(),this.#pr=null}get#yr(){return this.#hr&&!this.#hr.classList.contains("hidden")}_hideDropdownFromKeyboard(){this.#dr||(this.#yr?(this.hideDropdown(),this.#ar.focus({preventScroll:!0,focusVisible:this.#cr})):this.#r?.unselect())}updateColor(t){if(this.#or&&(this.#or.style.backgroundColor=t),!this.#hr)return;const e=this.#b.highlightColors.values();for(const i of this.#hr.children)i.ariaSelected=e.next().value===t.toUpperCase()}destroy(){this.#ar?.remove(),this.#ar=null,this.#or=null,this.#hr?.remove(),this.#hr=null}}class ks{#wr=null;#r=null;#b=null;static#gr=null;constructor(t){this.#r=t,this.#b=t._uiManager,ks.#gr||=Object.freeze({freetext:"pdfjs-editor-color-picker-free-text-input",ink:"pdfjs-editor-color-picker-ink-input"})}renderButton(){if(this.#wr)return this.#wr;const{editorType:t,colorType:e,color:i}=this.#r,s=this.#wr=document.createElement("input");return s.type="color",s.value=i||"#000000",s.className="basicColorPicker",s.tabIndex=0,s.setAttribute("data-l10n-id",ks.#gr[t]),s.addEventListener("input",()=>{this.#b.updateParams(e,s.value)},{signal:this.#b._signal}),s}update(t){this.#wr&&(this.#wr.value=t)}destroy(){this.#wr?.remove(),this.#wr=null}hideDropdown(){}}function Rs(t){return Math.floor(255*Math.max(0,Math.min(1,t))).toString(16).padStart(2,"0")}function Ls(t){return Math.max(0,Math.min(255,255*t))}class Fs{static CMYK_G([t,e,i,s]){return["G",1-Math.min(1,.3*t+.59*i+.11*e+s)]}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=Ls(t),[t,t,t]}static G_HTML([t]){const e=Rs(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(Ls)}static RGB_HTML(t){return`#${t.map(Rs).join("")}`}static T_HTML(){return"#00000000"}static T_rgb(){return[null]}static CMYK_RGB([t,e,i,s]){return["RGB",1-Math.min(1,t+s),1-Math.min(1,i+s),1-Math.min(1,e+s)]}static CMYK_rgb([t,e,i,s]){return[Ls(1-Math.min(1,t+s)),Ls(1-Math.min(1,i+s)),Ls(1-Math.min(1,e+s))]}static CMYK_HTML(t){const e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,i]){const s=1-t,n=1-e,r=1-i,a=Math.min(s,n,r);return["CMYK",s,n,r,a]}}class Os{create(t,e,i=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");const s=this._createSVG("svg:svg");return s.setAttribute("version","1.1"),i||(s.setAttribute("width",`${t}px`),s.setAttribute("height",`${e}px`)),s.setAttribute("preserveAspectRatio","none"),s.setAttribute("viewBox",`0 0 ${t} ${e}`),s}createElement(t){if("string"!==typeof t)throw new Error("Invalid SVG element type");return this._createSVG(t)}_createSVG(t){P("Abstract method `_createSVG` called.")}}class Bs extends Os{_createSVG(t){return document.createElementNS(ht,t)}}const Ns=9,Us=new WeakSet,js=60*(new Date).getTimezoneOffset()*1e3;class Hs{static create(t){const e=t.data.annotationType;switch(e){case y.LINK:return new Gs(t);case y.TEXT:return new Ws(t);case y.WIDGET:const e=t.data.fieldType;switch(e){case"Tx":return new qs(t);case"Btn":return t.data.radioButton?new Ks(t):t.data.checkBox?new Ys(t):new Qs(t);case"Ch":return new Js(t);case"Sig":return new Xs(t)}return new Vs(t);case y.POPUP:return new Zs(t);case y.FREETEXT:return new en(t);case y.LINE:return new sn(t);case y.SQUARE:return new nn(t);case y.CIRCLE:return new rn(t);case y.POLYLINE:return new an(t);case y.CARET:return new ln(t);case y.INK:return new hn(t);case y.POLYGON:return new on(t);case y.HIGHLIGHT:return new cn(t);case y.UNDERLINE:return new dn(t);case y.SQUIGGLY:return new un(t);case y.STRIKEOUT:return new pn(t);case y.STAMP:return new gn(t);case y.FILEATTACHMENT:return new mn(t);default:return new zs(t)}}}class zs{#Ar=null;#xr=!1;#_r=null;constructor(t,{isRenderable:e=!1,ignoreBorder:i=!1,createQuadrilaterals:s=!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)),s&&this._createQuadrilaterals()}static _hasPopupData({contentsObj:t,richText:e}){return!(!t?.str&&!e?.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return zs._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:s}=this.data;let n=-1/0,r=-1/0;if(e?.length>=8){for(let t=0;t<e.length;t+=8)e[t+1]>r?(r=e[t+1],n=e[t+2]):e[t+1]===r&&(n=Math.max(n,e[t+2]));return[n,r]}if(i?.length>=1){for(const t of i)for(let e=0,i=t.length;e<i;e+=2)t[e+1]>r?(r=t[e+1],n=t[e]):t[e+1]===r&&(n=Math.max(n,t[e]));if(n!==1/0)return[n,r]}return s?[s[2],s[3]]:null}_normalizePoint(t){const{page:{view:e},viewport:{rawDims:{pageWidth:i,pageHeight:s,pageX:n,pageY:r}}}=this.parent;return t[1]=e[3]-t[1]+e[1],t[0]=100*(t[0]-n)/i,t[1]=100*(t[1]-r)/s,t}get commentText(){const{data:t}=this;return this.annotationStorage.getRawValue(`${u}${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(`${u}${e.id}`,{id:e.id,annotationType:e.annotationType,pageIndex:this.parent.page._pageIndex,popup:i,popupRef:e.popupRef,modificationDate:new Date}),t||this.removePopup()}removePopup(){(this.#_r?.popup||this.popup)?.remove(),this.#_r=this.popup=null}updateEdited(t){if(!this.container)return;t.rect&&(this.#Ar||={rect:this.data.rect.slice(0)});const{rect:e,popup:i}=t;e&&this.#Sr(e);let s=this.#_r?.popup||this.popup;!s&&i?.text&&(this._createPopup(i),s=this.#_r.popup),s&&(s.updateEdited(t),i?.deleted&&(s.remove(),this.#_r=null,this.popup=null))}resetEdited(){this.#Ar&&(this.#Sr(this.#Ar.rect),this.#_r?.popup.resetEdited(),this.#Ar=null)}#Sr(t){const{container:{style:e},data:{rect:i,rotation:s},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:a,pageY:o}}}}=this;i?.splice(0,4,...t),e.left=100*(t[0]-a)/n+"%",e.top=100*(r-t[3]+o)/r+"%",0===s?(e.width=100*(t[2]-t[0])/n+"%",e.height=100*(t[3]-t[1])/r+"%"):this.setRotation(s)}_createContainer(t){const{data:e,parent:{page:i,viewport:s}}=this,n=document.createElement("section");n.setAttribute("data-annotation-id",e.id),this instanceof Vs||this instanceof Gs||(n.tabIndex=0);const{style:r}=n;if(r.zIndex=this.parent.zIndex,this.parent.zIndex+=2,e.alternativeText&&(n.title=e.alternativeText),e.noRotate&&n.classList.add("norotate"),!e.rect||this instanceof Zs){const{rotation:t}=e;return e.hasOwnCanvas||0===t||this.setRotation(t,n),n}const{width:a,height:o}=this;if(!t&&e.borderStyle.width>0){r.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))`;r.borderRadius=e}else if(this instanceof Ks){const t=`calc(${a}px * var(--total-scale-factor)) / calc(${o}px * var(--total-scale-factor))`;r.borderRadius=t}switch(e.borderStyle.style){case w.SOLID:r.borderStyle="solid";break;case w.DASHED:r.borderStyle="dashed";break;case w.BEVELED:D("Unimplemented border style: beveled");break;case w.INSET:D("Unimplemented border style: inset");break;case w.UNDERLINE:r.borderBottomStyle="solid";break;default:break}const s=e.borderColor||null;s?(this.#xr=!0,r.borderColor=K.makeHexColor(0|s[0],0|s[1],0|s[2])):r.borderWidth=0}const l=K.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}=s.rawDims;r.left=100*(l[0]-d)/h+"%",r.top=100*(l[1]-u)/c+"%";const{rotation:p}=e;return e.hasOwnCanvas||0===p?(r.width=100*a/h+"%",r.height=100*o/c+"%"):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:i,pageHeight:s}=this.parent.viewport.rawDims;let{width:n,height:r}=this;t%180!==0&&([n,r]=[r,n]),e.style.width=100*n/i+"%",e.style.height=100*r/s+"%",e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(t,e,i)=>{const s=i.detail[t],n=s[0],r=s.slice(1);i.target.style[e]=Fs[`${n}_HTML`](r),this.annotationStorage.setValue(this.data.id,{[e]:Fs[`${n}_rgb`](r)})};return F(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:e=>{t("bgColor","backgroundColor",e)},fillColor:e=>{t("fillColor","backgroundColor",e)},fgColor:e=>{t("fgColor","color",e)},textColor:e=>{t("textColor","color",e)},borderColor:e=>{t("borderColor","borderColor",e)},strokeColor:e=>{t("strokeColor","borderColor",e)},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 s of Object.keys(e.detail)){const n=t[s]||i[s];n?.(e)}}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const i=this._commonActions;for(const[s,n]of Object.entries(e)){const r=i[s];if(r){const i={detail:{[s]:n},target:t};r(i),delete e[s]}}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:t}=this.data;if(!t)return;const[e,i,s,n]=this.data.rect.map(t=>Math.fround(t));if(8===t.length){const[r,a,o,l]=t.subarray(2,6);if(s===r&&n===a&&e===o&&i===l)return}const{style:r}=this.container;let a;if(this.#xr){const{borderColor:t,borderWidth:e}=r;r.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=s-e,l=n-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 g=2,m=t.length;g<m;g+=8){const i=t[g],s=t[g+1],r=t[g+2],c=t[g+3],d=h.createElement("rect"),p=(r-e)/o,m=(n-s)/l,f=(i-r)/o,b=(s-c)/l;d.setAttribute("x",p),d.setAttribute("y",m),d.setAttribute("width",f),d.setAttribute("height",b),u.append(d),a?.push(`<rect vector-effect="non-scaling-stroke" x="${p}" y="${m}" width="${f}" height="${b}"/>`)}this.#xr&&(a.push("</g></svg>')"),r.backgroundImage=a.join("")),this.container.append(c),this.container.style.clipPath=`url(#${p})`}_createPopup(t=null){const{data:e}=this;let i,s;t?(i={str:t.text},s=t.date):(i=e.contentsObj,s=e.modificationDate),this.#_r=new Zs({data:{color:e.color,titleObj:e.titleObj,modificationDate:s,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.#_r||this.popup||this.data.popupRef)}get extraPopupElement(){return this.#_r}render(){P("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const i=[];if(this._fieldObjects){const s=this._fieldObjects[t];if(s)for(const{page:t,id:n,exportValues:r}of s){if(-1===t)continue;if(n===e)continue;const s="string"===typeof r?r:null,a=document.querySelector(`[data-element-id="${n}"]`);!a||Us.has(a)?i.push({id:n,exportValue:s,domElement:a}):D(`_getElementsByName - element not allowed: ${n}`)}return i}for(const s of document.getElementsByName(t)){const{exportValue:t}=s,n=s.getAttribute("data-element-id");n!==e&&(Us.has(s)&&i.push({id:n,exportValue:t,domElement:s}))}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 $s extends zs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.editor=t.editor}render(){return this.container.className="editorAnnotation",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 Gs extends zs{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 s=!1;return t.url?(e.addLinkAttributes(i,t.url,t.newWindow),s=!0):t.action?(this._bindNamedAction(i,t.action,t.overlaidText),s=!0):t.attachment?(this.#Er(i,t.attachment,t.overlaidText,t.attachmentDest),s=!0):t.setOCGState?(this.#Cr(i,t.setOCGState,t.overlaidText),s=!0):t.dest?(this._bindLink(i,t.dest,t.overlaidText),s=!0):(t.actions&&(t.actions.Action||t.actions["Mouse Up"]||t.actions["Mouse Down"])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(i,t),s=!0),t.resetForm?(this._bindResetFormAction(i,t.resetForm),s=!0):this.isTooltipOnly&&!s&&(this._bindLink(i,""),s=!0)),this.container.classList.add("linkAnnotation"),s&&(this.contentElement=i,this.container.append(i)),this.container}#Tr(){this.container.setAttribute("data-internal-link","")}_bindLink(t,e,i=""){t.href=this.linkService.getDestinationHash(e),t.onclick=()=>(e&&this.linkService.goToDestination(e),!1),(e||""===e)&&this.#Tr(),i&&(t.title=i)}_bindNamedAction(t,e,i=""){t.href=this.linkService.getAnchorUrl(""),t.onclick=()=>(this.linkService.executeNamedAction(e),!1),i&&(t.title=i),this.#Tr()}#Er(t,e,i="",s=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,s),!1),this.#Tr()}#Cr(t,e,i=""){t.href=this.linkService.getAnchorUrl(""),t.onclick=()=>(this.linkService.executeSetOCGState(e),!1),i&&(t.title=i),this.#Tr()}_bindJSAction(t,e){t.href=this.linkService.getAnchorUrl("");const i=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const s of Object.keys(e.actions)){const n=i.get(s);n&&(t[n]=()=>(this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e.id,name:s}}),!1))}e.overlaidText&&(t.title=e.overlaidText),t.onclick||(t.onclick=()=>!1),this.#Tr()}_bindResetFormAction(t,e){const i=t.onclick;if(i||(t.href=this.linkService.getAnchorUrl("")),this.#Tr(),!this._fieldObjects)return D('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),void(i||(t.onclick=()=>!1));t.onclick=()=>{i?.();const{fields:t,refs:s,include:n}=e,r=[];if(0!==t.length||0!==s.length){const e=new Set(s);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)===n&&r.push(i)}else for(const e of Object.values(this._fieldObjects))r.push(...e);const a=this.annotationStorage,o=[];for(const e of r){const{id:t}=e;switch(o.push(t),e.type){case"text":{const i=e.defaultValue||"";a.setValue(t,{value:i});break}case"checkbox":case"radiobutton":{const i=e.defaultValue===e.exportValues;a.setValue(t,{value:i});break}case"combobox":case"listbox":{const i=e.defaultValue||"";a.setValue(t,{value:i});break}default:continue}const i=document.querySelector(`[data-element-id="${t}"]`);i&&(Us.has(i)?i.dispatchEvent(new Event("resetform")):D(`_bindResetFormAction - element not allowed: ${t}`))}return this.enableScripting&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:o,name:"ResetForm"}}),!1}}}class Ws extends zs{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");const t=document.createElement("img");return 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})),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.append(t),this.container}}class Vs extends zs{render(){return this.container}showElementAndHideCanvas(t){this.data.hasOwnCanvas&&("CANVAS"===t.previousSibling?.nodeName&&(t.previousSibling.hidden=!0),t.hidden=!1)}_getKeyModifier(t){return X.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,i,s,n){i.includes("mouse")?t.addEventListener(i,t=>{this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:s,value:n(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}n&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:s,value:n(t)}})})}_setEventListeners(t,e,i,s){for(const[n,r]of i)("Action"===r||this.data.actions?.[r])&&("Focus"!==r&&"Blur"!==r||(e||={focused:!1}),this._setEventListener(t,e,n,r,s),"Focus"!==r||this.data.actions?.Blur?"Blur"!==r||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":K.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:i}=this.data.defaultAppearanceData,s=this.data.defaultAppearanceData.fontSize||Ns,n=t.style;let r;const a=2,o=t=>Math.round(10*t)/10;if(this.data.multiLine){const t=Math.abs(this.data.rect[3]-this.data.rect[1]-a),e=Math.round(t/(h*s))||1,i=t/e;r=Math.min(s,o(i/h))}else{const t=Math.abs(this.data.rect[3]-this.data.rect[1]-a);r=Math.min(s,o(t/h))}n.fontSize=`calc(${r}px * var(--total-scale-factor))`,n.color=K.makeHexColor(i[0],i[1],i[2]),null!==this.data.textAlignment&&(n.textAlign=e[this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}}class qs extends Vs{constructor(t){const e=t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue;super(t,{isRenderable:e})}setPropertyOnSiblings(t,e,i,s){const n=this.annotationStorage;for(const r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=i),n.setValue(r.id,{[s]:i})}render(){const t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let i=null;if(this.renderForms){const s=t.getValue(e,{value:this.data.fieldValue});let n=s.value||"";const r=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;r&&n.length>r&&(n=n.slice(0,r));let a=s.formattedValue||this.data.textContent?.join("\n")||null;a&&this.data.comb&&(a=a.replaceAll(/\s+/g,""));const o={userValue:n,formattedValue:a,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(i=document.createElement("textarea"),i.textContent=a??n,this.data.doNotScroll&&(i.style.overflowY="hidden")):(i=document.createElement("input"),i.type=this.data.password?"password":"text",i.setAttribute("value",a??n),this.data.doNotScroll&&(i.style.overflowX="hidden")),this.data.hasOwnCanvas&&(i.hidden=!0),Us.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),r&&(i.maxLength=r),i.addEventListener("input",s=>{t.setValue(e,{value:s.target.value}),this.setPropertyOnSiblings(i,"value",s.target.value,"value"),o.formattedValue=null}),i.addEventListener("resetform",t=>{const e=this.data.defaultFieldValue??"";i.value=o.userValue=e,o.formattedValue=null});let u=t=>{const{formattedValue:e}=o;null!==e&&void 0!==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)),o.userValue){const t=o.userValue;if(d)if("time"===h){const i=new Date(t),s=[i.getHours(),i.getMinutes(),i.getSeconds()];e.value=s.map(t=>t.toString().padStart(2,"0")).join(":")}else e.value=new Date(t-js).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 s={value(i){o.userValue=i.detail.value??"",d||t.setValue(e,{value:o.userValue.toString()}),i.target.value=o.userValue},formattedValue(i){const{formattedValue:s}=i.detail;o.formattedValue=s,null!==s&&void 0!==s&&i.target!==document.activeElement&&(i.target.value=s);const n={formattedValue:s};d&&(n.value=s),t.setValue(e,n)},selRange(t){t.target.setSelectionRange(...t.detail.selRange)},charLimit:i=>{const{charLimit:s}=i.detail,{target:n}=i;if(0===s)return void n.removeAttribute("maxLength");n.setAttribute("maxLength",s);let r=o.userValue;!r||r.length<=s||(r=r.slice(0,s),n.value=o.userValue=r,t.setValue(e,{value:r}),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:r,willCommit:!0,commitKey:1,selStart:n.selectionStart,selEnd:n.selectionEnd}}))}};this._dispatchEventFromSandbox(s,i)}),i.addEventListener("keydown",t=>{o.commitKey=1;let i=-1;if("Escape"===t.key?i=0:"Enter"!==t.key||this.data.multiLine?"Tab"===t.key&&(o.commitKey=3):i=2,-1===i)return;const{value:s}=t.target;o.lastCommittedValue!==s&&(o.lastCommittedValue=s,o.userValue=s,this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:s,willCommit:!0,commitKey:i,selStart:t.target.selectionStart,selEnd:t.target.selectionEnd}}))});const s=u;u=null,i.addEventListener("blur",t=>{if(!o.focused||!t.relatedTarget)return;this.data.actions?.Blur||(o.focused=!1);const{target:i}=t;let{value:n}=i;if(d){if(n&&"time"===h){const t=n.split(":").map(t=>parseInt(t,10));n=new Date(2e3,0,1,t[0],t[1],t[2]||0).valueOf(),i.step=""}else n.includes("T")||(n=`${n}T00:00`),n=new Date(n).valueOf();i.type="text"}o.userValue=n,o.lastCommittedValue!==n&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:n,willCommit:!0,commitKey:o.commitKey,selStart:t.target.selectionStart,selEnd:t.target.selectionEnd}}),s(t)}),this.data.actions?.Keystroke&&i.addEventListener("beforeinput",t=>{o.lastCommittedValue=null;const{data:i,target:s}=t,{value:n,selectionStart:r,selectionEnd:a}=s;let l=r,h=a;switch(t.inputType){case"deleteWordBackward":{const t=n.substring(0,r).match(/\w*[^\w]*$/);t&&(l-=t[0].length);break}case"deleteWordForward":{const t=n.substring(r).match(/^[^\w]*\w*/);t&&(h+=t[0].length);break}case"deleteContentBackward":r===a&&(l-=1);break;case"deleteContentForward":r===a&&(h+=1);break}t.preventDefault(),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:n,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)}if(u&&i.addEventListener("blur",u),this.data.comb){const t=this.data.rect[2]-this.data.rect[0],e=t/r;i.classList.add("comb"),i.style.letterSpacing=`calc(${e}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);return this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class Xs extends Vs{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class Ys extends Vs{constructor(t){super(t,{isRenderable:t.renderForms})}render(){const t=this.annotationStorage,e=this.data,i=e.id;let s=t.getValue(i,{value:e.exportValue===e.fieldValue}).value;"string"===typeof s&&(s="Off"!==s,t.setValue(i,{value:s})),this.container.classList.add("buttonWidgetAnnotation","checkBox");const n=document.createElement("input");return Us.add(n),n.setAttribute("data-element-id",i),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="checkbox",n.name=e.fieldName,s&&n.setAttribute("checked",!0),n.setAttribute("exportValue",e.exportValue),n.tabIndex=0,n.addEventListener("change",s=>{const{name:n,checked:r}=s.target;for(const a of this._getElementsByName(n,i)){const i=r&&a.exportValue===e.exportValue;a.domElement&&(a.domElement.checked=i),t.setValue(a.id,{value:i})}t.setValue(i,{value:r})}),n.addEventListener("resetform",t=>{const i=e.defaultFieldValue||"Off";t.target.checked=i===e.exportValue}),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",e=>{const s={value(e){e.target.checked="Off"!==e.detail.value,t.setValue(i,{value:e.target.checked})}};this._dispatchEventFromSandbox(s,e)}),this._setEventListeners(n,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(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class Ks extends Vs{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 s=t.getValue(i,{value:e.fieldValue===e.buttonValue}).value;if("string"===typeof s&&(s=s!==e.buttonValue,t.setValue(i,{value:s})),s)for(const r of this._getElementsByName(e.fieldName,i))t.setValue(r.id,{value:!1});const n=document.createElement("input");if(Us.add(n),n.setAttribute("data-element-id",i),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="radio",n.name=e.fieldName,s&&n.setAttribute("checked",!0),n.tabIndex=0,n.addEventListener("change",e=>{const{name:s,checked:n}=e.target;for(const r of this._getElementsByName(s,i))t.setValue(r.id,{value:!1});t.setValue(i,{value:n})}),n.addEventListener("resetform",t=>{const i=e.defaultFieldValue;t.target.checked=null!==i&&void 0!==i&&i===e.buttonValue}),this.enableScripting&&this.hasJSActions){const s=e.buttonValue;n.addEventListener("updatefromsandbox",e=>{const n={value:e=>{const n=s===e.detail.value;for(const s of this._getElementsByName(e.target.name)){const e=n&&s.id===i;s.domElement&&(s.domElement.checked=e),t.setValue(s.id,{value:e})}}};this._dispatchEventFromSandbox(n,e)}),this._setEventListeners(n,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)}return this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class Qs extends Gs{constructor(t){super(t,{ignoreBorder:t.data.hasAppearance})}render(){const t=super.render();t.classList.add("buttonWidgetAnnotation","pushButton");const e=t.lastChild;return this.enableScripting&&this.hasJSActions&&e&&(this._setDefaultPropertiesFromJS(e),e.addEventListener("updatefromsandbox",t=>{this._dispatchEventFromSandbox({},t)})),t}}class Js extends Vs{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}),s=document.createElement("select");Us.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,this._setRequired(s,this.data.required),s.name=this.data.fieldName,s.tabIndex=0;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(s.size=this.data.options.length,this.data.multiSelect&&(s.multiple=!0)),s.addEventListener("resetform",t=>{const e=this.data.defaultFieldValue;for(const i of s.options)i.selected=i.value===e});for(const h of this.data.options){const t=document.createElement("option");t.textContent=h.displayValue,t.value=h.exportValue,i.value.includes(h.exportValue)&&(t.setAttribute("selected",!0),n=!1),s.append(t)}let r=null;if(n){const t=document.createElement("option");t.value=" ",t.setAttribute("hidden",!0),t.setAttribute("selected",!0),s.prepend(t),r=()=>{t.remove(),s.removeEventListener("input",r),r=null},s.addEventListener("input",r)}const a=t=>{const e=t?"value":"textContent",{options:i,multiple:n}=s;return n?Array.prototype.filter.call(i,t=>t.selected).map(t=>t[e]):-1===i.selectedIndex?null:i[i.selectedIndex][e]};let o=a(!1);const l=t=>{const e=t.target.options;return Array.prototype.map.call(e,t=>({displayValue:t.textContent,exportValue:t.value}))};return this.enableScripting&&this.hasJSActions?(s.addEventListener("updatefromsandbox",i=>{const n={value(i){r?.();const n=i.detail.value,l=new Set(Array.isArray(n)?n:[n]);for(const t of s.options)t.selected=l.has(t.value);t.setValue(e,{value:a(!0)}),o=a(!1)},multipleSelection(t){s.multiple=!0},remove(i){const n=s.options,r=i.detail.remove;if(n[r].selected=!1,s.remove(r),n.length>0){const t=Array.prototype.findIndex.call(n,t=>t.selected);-1===t&&(n[0].selected=!0)}t.setValue(e,{value:a(!0),items:l(i)}),o=a(!1)},clear(i){while(0!==s.length)s.remove(0);t.setValue(e,{value:null,items:[]}),o=a(!1)},insert(i){const{index:n,displayValue:r,exportValue:h}=i.detail.insert,c=s.children[n],d=document.createElement("option");d.textContent=r,d.value=h,c?c.before(d):s.append(d),t.setValue(e,{value:a(!0),items:l(i)}),o=a(!1)},items(i){const{items:n}=i.detail;while(0!==s.length)s.remove(0);for(const t of n){const{displayValue:e,exportValue:i}=t,n=document.createElement("option");n.textContent=e,n.value=i,s.append(n)}s.options.length>0&&(s.options[0].selected=!0),t.setValue(e,{value:a(!0),items:l(i)}),o=a(!1)},indices(i){const s=new Set(i.detail.indices);for(const t of i.target.options)t.selected=s.has(t.index);t.setValue(e,{value:a(!0)}),o=a(!1)},editable(t){t.target.disabled=!t.detail.editable}};this._dispatchEventFromSandbox(n,i)}),s.addEventListener("input",i=>{const s=a(!0),n=a(!1);t.setValue(e,{value:s}),i.preventDefault(),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:o,change:n,changeEx:s,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(s,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)):s.addEventListener("input",function(i){t.setValue(e,{value:a(!0)})}),this.data.combo&&this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class Zs extends zs{constructor(t){const{data:e,elements:i,parent:s}=t,n=!!s._commentManager;if(super(t,{isRenderable:!n&&zs._hasPopupData(e)}),this.elements=i,n&&zs._hasPopupData(e)){const t=this.popup=this.#Mr();for(const e of i)e.popup=t}else this.popup=null}#Mr(){return new tn({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.#Mr(),i=[];for(const s of this.elements)s.popup=e,s.container.ariaHasPopup="dialog",i.push(s.data.id),s.addHighlightArea();return this.container.setAttribute("aria-controls",i.map(t=>`${it}${t}`).join(",")),this.container}}class tn{#$=null;#Dr=this.#fr.bind(this);#Pr=this.#Ir.bind(this);#kr=this.#Rr.bind(this);#Lr=this.#Fr.bind(this);#Or=null;#Et=null;#Br=null;#Nr=null;#Ur=null;#jr=null;#Hr=null;#zr=!1;#$r=null;#Gr=null;#k=null;#Wr=null;#Vr=null;#be=null;#qr=null;#pe=null;#Xr=null;#Ar=null;#Yr=!1;#Kr=null;#Qr=null;constructor({container:t,color:e,elements:i,titleObj:s,modificationDate:n,contentsObj:r,richText:a,parent:o,rect:l,parentRect:h,open:c,commentManager:d=null}){this.#Et=t,this.#Xr=s,this.#Br=r,this.#pe=a,this.#jr=o,this.#Or=e,this.#qr=l,this.#Hr=h,this.#Ur=i,this.#$=d,this.#Kr=i[0],this.#Nr=_t.toDateObject(n),this.trigger=i.flatMap(t=>t.getElementsToTriggerPopup()),d||(this.#Jr(),this.#Et.hidden=!0,c&&this.#Fr())}#Jr(){if(this.#Gr)return;this.#Gr=new AbortController;const{signal:t}=this.#Gr;for(const e of this.trigger)e.addEventListener("click",this.#Lr,{signal:t}),e.addEventListener("pointerenter",this.#kr,{signal:t}),e.addEventListener("pointerleave",this.#Pr,{signal:t}),e.classList.add("popupTriggerArea");for(const e of this.#Ur)e.container?.addEventListener("keydown",this.#Dr,{signal:t})}#Zr(){const t=this.#Ur.find(t=>t.hasCommentButton);t&&(this.#Vr=t._normalizePoint(t.commentButtonPosition))}renderCommentButton(){if(this.#Wr)return void(this.#Wr.parentNode||this.#Kr.container.after(this.#Wr));if(this.#Vr||this.#Zr(),!this.#Vr)return;const{signal:t}=this.#Gr=new AbortController,e=this.#Kr.hasOwnCommentButton,i=()=>{this.#$.toggleCommentPopup(this,!0,void 0,!e)},s=()=>{this.#$.toggleCommentPopup(this,!1,!0,!e)},n=()=>{this.#$.toggleCommentPopup(this,!1,!1)};if(e){this.#Wr=this.#Kr.container;for(const e of this.trigger)e.ariaHasPopup="dialog",e.ariaControls="commentPopup",e.addEventListener("keydown",this.#Dr,{signal:t}),e.addEventListener("click",i,{signal:t}),e.addEventListener("pointerenter",s,{signal:t}),e.addEventListener("pointerleave",n,{signal:t}),e.classList.add("popupTriggerArea")}else{const e=this.#Wr=document.createElement("button");e.className="annotationCommentButton";const r=this.#Kr.container;e.style.zIndex=r.style.zIndex+1,e.tabIndex=0,e.ariaHasPopup="dialog",e.ariaControls="commentPopup",e.setAttribute("data-l10n-id","pdfjs-show-comment-button"),this.#ta(),this.#ea(),e.addEventListener("keydown",this.#Dr,{signal:t}),e.addEventListener("click",i,{signal:t}),e.addEventListener("pointerenter",s,{signal:t}),e.addEventListener("pointerleave",n,{signal:t}),r.after(e)}}#ea(){if(this.#Kr.extraPopupElement&&!this.#Kr.editor)return;this.#Wr||this.renderCommentButton();const[t,e]=this.#Vr,{style:i}=this.#Wr;i.left=`calc(${t}%)`,i.top=`calc(${e}% - var(--comment-button-dim))`}#ta(){this.#Kr.extraPopupElement||(this.#Wr||this.renderCommentButton(),this.#Wr.style.backgroundColor=this.commentButtonColor||"")}get commentButtonColor(){const{color:t,opacity:e}=this.#Kr.commentData;return t?this.#jr._commentManager.makeCommentColor(t,e):null}focusCommentButton(){setTimeout(()=>{this.#Wr?.focus()},0)}getData(){const{richText:t,color:e,opacity:i,creationDate:s,modificationDate:n}=this.#Kr.commentData;return{contentsObj:{str:this.comment},richText:t,color:e,opacity:i,creationDate:s,modificationDate:n}}get elementBeforePopup(){return this.#Wr}get comment(){return this.#Qr||=this.#Kr.commentText,this.#Qr}set comment(t){t!==this.comment&&(this.#Kr.commentText=this.#Qr=t)}focus(){this.#Kr.container?.focus()}get parentBoundingClientRect(){return this.#Kr.layer.getBoundingClientRect()}setCommentButtonStates({selected:t,hasPopup:e}){this.#Wr&&(this.#Wr.classList.toggle("selected",t),this.#Wr.ariaExpanded=e)}setSelectedCommentButton(t){this.#Wr.classList.toggle("selected",t)}get commentPopupPosition(){if(this.#be)return this.#be;const{x:t,y:e,height:i}=this.#Wr.getBoundingClientRect(),{x:s,y:n,width:r,height:a}=this.#Kr.layer.getBoundingClientRect();return[(t-s)/r,(e+i-n)/a]}set commentPopupPosition(t){this.#be=t}hasDefaultPopupPosition(){return null===this.#be}get commentButtonPosition(){return this.#Vr}get commentButtonWidth(){return this.#Wr.getBoundingClientRect().width/this.parentBoundingClientRect.width}editComment(t){const[e,i]=this.#be||this.commentButtonPosition.map(t=>t/100),s=this.parentBoundingClientRect,{x:n,y:r,width:a,height:o}=s;this.#$.showDialog(null,this,n+e*a,r+i*o,{...t,parentDimensions:s})}render(){if(this.#$r)return;const t=this.#$r=document.createElement("div");if(t.className="popup",this.#Or){const e=t.style.outlineColor=K.makeHexColor(...this.#Or);t.style.backgroundColor=`color-mix(in srgb, ${e} 30%, white)`}const e=document.createElement("span");if(e.className="header",this.#Xr?.str){const t=document.createElement("span");t.className="title",e.append(t),({dir:t.dir,str:t.textContent}=this.#Xr)}if(t.append(e),this.#Nr){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.#Nr.valueOf()})),t.dateTime=this.#Nr.toISOString(),e.append(t)}Ht({html:this.#ia||this.#Br.str,dir:this.#Br?.dir,className:"popupContent"},t),this.#Et.append(t)}get#ia(){const t=this.#pe,e=this.#Br;return!t?.str||e?.str&&e.str!==t.str?null:this.#pe.html||null}get#sa(){return this.#ia?.attributes?.style?.fontSize||0}get#na(){return this.#ia?.attributes?.style?.color||null}#ra(t){const e=[],i={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},s={style:{color:this.#na,fontSize:this.#sa?`calc(${this.#sa}px * var(--total-scale-factor))`:""}};for(const n of t.split("\n"))e.push({name:"span",value:n,attributes:s});return i}#fr(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||("Enter"===t.key||"Escape"===t.key&&this.#zr)&&this.#Fr()}updateEdited({rect:t,popup:e,deleted:i}){if(this.#$)return i?(this.remove(),this.#Qr=null):e&&(e.deleted?this.remove():(this.#ta(),this.#Qr=e.text)),void(t&&(this.#Vr=null,this.#Zr(),this.#ea()));i||e?.deleted?this.remove():(this.#Jr(),this.#Ar||={contentsObj:this.#Br,richText:this.#pe},t&&(this.#k=null),e&&e.text&&(this.#pe=this.#ra(e.text),this.#Nr=_t.toDateObject(e.date),this.#Br=null),this.#$r?.remove(),this.#$r=null)}resetEdited(){this.#Ar&&(({contentsObj:this.#Br,richText:this.#pe}=this.#Ar),this.#Ar=null,this.#$r?.remove(),this.#$r=null,this.#k=null)}remove(){if(this.#Gr?.abort(),this.#Gr=null,this.#$r?.remove(),this.#$r=null,this.#Yr=!1,this.#zr=!1,this.#Wr?.remove(),this.#Wr=null,this.trigger)for(const t of this.trigger)t.classList.remove("popupTriggerArea")}#aa(){if(null!==this.#k)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:i,pageX:s,pageY:n}}}=this.#jr;let r=!!this.#Hr,a=r?this.#Hr:this.#qr;for(const p of this.#Ur)if(!a||null!==K.intersect(p.data.rect,a)){a=p.data.rect,r=!0;break}const o=K.normalizeRect([a[0],t[3]-a[1]+t[1],a[2],t[3]-a[3]+t[1]]),l=5,h=r?a[2]-a[0]+l:0,c=o[0]+h,d=o[1];this.#k=[100*(c-s)/e,100*(d-n)/i];const{style:u}=this.#Et;u.left=`${this.#k[0]}%`,u.top=`${this.#k[1]}%`}#Fr(){this.#$?this.#$.toggleCommentPopup(this,!1):(this.#zr=!this.#zr,this.#zr?(this.#Rr(),this.#Et.addEventListener("click",this.#Lr),this.#Et.addEventListener("keydown",this.#Dr)):(this.#Ir(),this.#Et.removeEventListener("click",this.#Lr),this.#Et.removeEventListener("keydown",this.#Dr)))}#Rr(){this.#$r||this.render(),this.isVisible?this.#zr&&this.#Et.classList.add("focused"):(this.#aa(),this.#Et.hidden=!1,this.#Et.style.zIndex=parseInt(this.#Et.style.zIndex)+1e3)}#Ir(){this.#Et.classList.remove("focused"),!this.#zr&&this.isVisible&&(this.#Et.hidden=!0,this.#Et.style.zIndex=parseInt(this.#Et.style.zIndex)-1e3)}forceHide(){this.#Yr=this.isVisible,this.#Yr&&(this.#Et.hidden=!0)}maybeShow(){this.#$||(this.#Jr(),this.#Yr&&(this.#$r||this.#Rr(),this.#Yr=!1,this.#Et.hidden=!1))}get isVisible(){return!this.#$&&!1===this.#Et.hidden}}class en extends zs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=p.FREETEXT}render(){if(this.container.classList.add("freeTextAnnotation"),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)}return!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this._editOnDoubleClick(),this.container}}class sn extends zs{#oa=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("lineAnnotation");const{data:t,width:e,height:i}=this,s=this.svgFactory.create(e,i,!0),n=this.#oa=this.svgFactory.createElement("svg:line");return n.setAttribute("x1",t.rect[2]-t.lineCoordinates[0]),n.setAttribute("y1",t.rect[3]-t.lineCoordinates[1]),n.setAttribute("x2",t.rect[2]-t.lineCoordinates[2]),n.setAttribute("y2",t.rect[3]-t.lineCoordinates[3]),n.setAttribute("stroke-width",t.borderStyle.width||1),n.setAttribute("stroke","transparent"),n.setAttribute("fill","transparent"),s.append(n),this.container.append(s),!t.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#oa}addHighlightArea(){this.container.classList.add("highlightArea")}}class nn extends zs{#la=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("squareAnnotation");const{data:t,width:e,height:i}=this,s=this.svgFactory.create(e,i,!0),n=t.borderStyle.width,r=this.#la=this.svgFactory.createElement("svg:rect");return r.setAttribute("x",n/2),r.setAttribute("y",n/2),r.setAttribute("width",e-n),r.setAttribute("height",i-n),r.setAttribute("stroke-width",n||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),s.append(r),this.container.append(s),!t.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#la}addHighlightArea(){this.container.classList.add("highlightArea")}}class rn extends zs{#ha=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("circleAnnotation");const{data:t,width:e,height:i}=this,s=this.svgFactory.create(e,i,!0),n=t.borderStyle.width,r=this.#ha=this.svgFactory.createElement("svg:ellipse");return r.setAttribute("cx",e/2),r.setAttribute("cy",i/2),r.setAttribute("rx",e/2-n/2),r.setAttribute("ry",i/2-n/2),r.setAttribute("stroke-width",n||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),s.append(r),this.container.append(s),!t.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#ha}addHighlightArea(){this.container.classList.add("highlightArea")}}class an extends zs{#ca=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:s},width:n,height:r}=this;if(!e)return this.container;const a=this.svgFactory.create(n,r,!0);let o=[];for(let h=0,c=e.length;h<c;h+=2){const i=e[h]-t[0],s=t[3]-e[h+1];o.push(`${i},${s}`)}o=o.join(" ");const l=this.#ca=this.svgFactory.createElement(this.svgElementName);return 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),!s&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#ca}addHighlightArea(){this.container.classList.add("highlightArea")}}class on extends an{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class ln extends zs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}}class hn extends zs{#da=null;#ua=[];constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType="InkHighlight"===this.data.it?p.HIGHLIGHT:p.INK}#pa(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:s,popupRef:n}}=this,{transform:r,width:a,height:o}=this.#pa(e,t),l=this.svgFactory.create(a,o,!0),h=this.#da=this.svgFactory.createElement("svg:g");l.append(h),h.setAttribute("stroke-width",s.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",r);for(let c=0,d=i.length;c<d;c++){const t=this.svgFactory.createElement(this.svgElementName);this.#ua.push(t),t.setAttribute("points",i[c].join(",")),h.append(t)}return!n&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.append(l),this._editOnDoubleClick(),this.container}updateEdited(t){super.updateEdited(t);const{thickness:e,points:i,rect:s}=t,n=this.#da;if(e>=0&&n.setAttribute("stroke-width",e||1),i)for(let r=0,a=this.#ua.length;r<a;r++)this.#ua[r].setAttribute("points",i[r].join(","));if(s){const{transform:t,width:e,height:i}=this.#pa(this.data.rotation,s),r=n.parentElement;r.setAttribute("viewBox",`0 0 ${e} ${i}`),n.setAttribute("transform",t)}}getElementsToTriggerPopup(){return this.#ua}addHighlightArea(){this.container.classList.add("highlightArea")}}class cn extends zs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=p.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(),t){const e=document.createElement("mark");e.classList.add("overlaidText"),e.textContent=t,this.container.append(e)}return this.container}}class dn extends zs{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"),t){const e=document.createElement("u");e.classList.add("overlaidText"),e.textContent=t,this.container.append(e)}return this.container}}class un extends zs{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"),t){const e=document.createElement("u");e.classList.add("overlaidText"),e.textContent=t,this.container.append(e)}return this.container}}class pn extends zs{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"),t){const e=document.createElement("s");e.classList.add("overlaidText"),e.textContent=t,this.container.append(e)}return this.container}}class gn extends zs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=p.STAMP}render(){return this.container.classList.add("stampAnnotation"),this.container.setAttribute("role","img"),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this._editOnDoubleClick(),this.container}}class mn extends zs{#ga=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;e.hasAppearance||0===e.fillAlpha?i=document.createElement("div"):(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.#ma.bind(this)),this.#ga=i;const{isMac:s}=X.platform;return t.addEventListener("keydown",t=>{"Enter"===t.key&&(s?t.metaKey:t.ctrlKey)&&this.#ma()}),!e.popupRef&&this.hasPopupData?(this.hasOwnCommentButton=!0,this._createPopup()):i.classList.add("popupTriggerArea"),t.append(i),t}getElementsToTriggerPopup(){return this.#ga}addHighlightArea(){this.container.classList.add("highlightArea")}#ma(){this.downloadManager?.openOrDownloadData(this.content,this.filename)}}class fn{#fa=null;#ba=null;#j=null;#va=new Map;#ya=null;#wa=null;#Ur=[];#Aa=!1;constructor({div:t,accessibilityManager:e,annotationCanvasMap:i,annotationEditorUIManager:s,page:n,viewport:r,structTreeLayer:a,commentManager:o,linkService:l,annotationStorage:h}){this.div=t,this.#fa=e,this.#ba=i,this.#ya=a||null,this.#wa=l||null,this.#j=h||new he,this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=s,this._commentManager=o||null}hasEditableAnnotations(){return this.#va.size>0}async render(t){const{annotations:e}=t,i=this.div;Dt(i,this.viewport);const s=new Map,n=[],r={data:null,layer:i,linkService:this.#wa,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:!1!==t.renderForms,svgFactory:new Bs,annotationStorage:this.#j,enableComment:!0===t.enableComment,enableScripting:!0===t.enableScripting,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(const a of e){if(a.noHTML)continue;const t=a.annotationType===y.POPUP;if(t){const t=s.get(a.id);if(!t)continue;if(!this._commentManager){n.push(a);continue}r.elements=t}else if(a.rect[2]===a.rect[0]||a.rect[3]===a.rect[1])continue;r.data=a;const e=Hs.create(r);if(!e.isRenderable)continue;if(!t&&(this.#Ur.push(e),a.popupRef)){const t=s.get(a.popupRef);t?t.push(e):s.set(a.popupRef,[e])}const i=e.render();a.hidden&&(i.style.visibility="hidden"),e._isEditable&&(this.#va.set(e.data.id,e),this._annotationEditorUIManager?.renderAnnotationElement(e))}await this.#xa();for(const a of n){const t=r.elements=s.get(a.id);r.data=a;const e=Hs.create(r);if(!e.isRenderable)continue;const i=e.render();e.contentElement.id=`${it}${a.id}`,a.hidden&&(i.style.visibility="hidden"),t.at(-1).container.after(i)}this.#_a()}async#xa(){if(0===this.#Ur.length)return;this.div.replaceChildren();const t=[];if(!this.#Aa){this.#Aa=!0;for(const{contentElement:e,data:{id:i}}of this.#Ur){const s=e.id=`${it}${i}`;t.push(this.#ya?.getAriaAttributes(s).then(t=>{if(t)for(const[i,s]of t)e.setAttribute(i,s)}))}}this.#Ur.sort(({data:{rect:[t,e,i,s]}},{data:{rect:[n,r,a,o]}})=>{if(t===i&&e===s)return 1;if(n===a&&r===o)return-1;const l=s,h=e,c=(e+s)/2,d=o,u=r,p=(r+o)/2;if(c>=d&&p<=h)return-1;if(p>=l&&c<=u)return 1;const g=(t+i)/2,m=(n+a)/2;return g-m});const e=document.createDocumentFragment();for(const i of this.#Ur)e.append(i.container),this._commentManager?(i.extraPopupElement?.popup||i.popup)?.renderCommentButton():i.extraPopupElement&&e.append(i.extraPopupElement.render());if(this.div.append(e),await Promise.all(t),this.#fa)for(const i of this.#Ur)this.#fa.addPointerInTextLayer(i.contentElement,!1)}async addLinkAnnotations(t){const e={data:null,layer:this.div,linkService:this.#wa,svgFactory:new Bs,parent:this};for(const i of t){i.borderStyle||=fn._defaultBorderStyle,e.data=i;const t=Hs.create(e);t.isRenderable&&(t.render(),t.contentElement.id=`${it}${i.id}`,this.#Ur.push(t))}await this.#xa()}update({viewport:t}){const e=this.div;this.viewport=t,Dt(e,{rotation:t.rotation}),this.#_a(),e.hidden=!1}#_a(){if(!this.#ba)return;const t=this.div;for(const[e,i]of this.#ba){const s=t.querySelector(`[data-annotation-id="${e}"]`);if(!s)continue;i.className="annotationContent";const{firstChild:n}=s;n?"CANVAS"===n.nodeName?n.replaceWith(i):n.classList.contains("annotationContent")?n.after(i):n.before(i):s.append(i);const r=this.#va.get(e);r&&(r._hasNoCanvas?(this._annotationEditorUIManager?.setMissingCanvas(e,s.id,i),r._hasNoCanvas=!1):r.canvas=i)}this.#ba.clear()}getEditableAnnotations(){return Array.from(this.#va.values())}getEditableAnnotation(t){return this.#va.get(t)}addFakeAnnotation(t){const{div:e}=this,{id:i,rotation:s}=t,n=new $s({data:{id:i,rect:t.getPDFRect(),rotation:s},editor:t,layer:e,parent:this,enableComment:!!this._commentManager,linkService:this.#wa,annotationStorage:this.#j});return n.render(),n.contentElement.id=`${it}${i}`,n.createOrUpdatePopup(),this.#Ur.push(n),n}removeAnnotation(t){const e=this.#Ur.findIndex(e=>e.data.id===t);if(e<0)return;const[i]=this.#Ur.splice(e,1);this.#fa?.removePointerInTextLayer(i.contentElement)}updateFakeAnnotations(t){if(0!==t.length){for(const e of t)e.updateFakeAnnotationElement(this);this.#xa()}}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}static get _defaultBorderStyle(){return F(this,"_defaultBorderStyle",Object.freeze({width:1,rawWidth:1,style:w.SOLID,dashArray:[3],horizontalCornerRadius:0,verticalCornerRadius:0}))}}const bn=/\r\n?|\n/g;class vn extends ie{#Sa="";#Ea=`${this.id}-editor`;#Ca=null;#sa;_colorPicker=null;static _freeTextDefaultContent="";static _internalPadding=0;static _defaultColor=null;static _defaultFontSize=10;static get _keyboardManager(){const t=vn.prototype,e=t=>t.isEmpty(),i=Jt.TRANSLATE_SMALL,s=Jt.TRANSLATE_BIG;return F(this,"_keyboardManager",new Kt([[["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:[-i,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t._translateEmpty,{args:[-s,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t._translateEmpty,{args:[i,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t._translateEmpty,{args:[s,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t._translateEmpty,{args:[0,-i],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t._translateEmpty,{args:[0,-s],checker:e}],[["ArrowDown","mac+ArrowDown"],t._translateEmpty,{args:[0,i],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t._translateEmpty,{args:[0,s],checker:e}]]))}static _type="freetext";static _editorType=p.FREETEXT;constructor(t){super({...t,name:"freeTextEditor"}),this.color=t.color||vn._defaultColor||ie._defaultLineColor,this.#sa=t.fontSize||vn._defaultFontSize,this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-freetext-added-alert"),this.canAddComment=!1}static initialize(t,e){ie.initialize(t,e);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(t,e){switch(t){case g.FREETEXT_SIZE:vn._defaultFontSize=e;break;case g.FREETEXT_COLOR:vn._defaultColor=e;break}}updateParams(t,e){switch(t){case g.FREETEXT_SIZE:this.#Ta(e);break;case g.FREETEXT_COLOR:this.#ta(e);break}}static get defaultPropertiesToUpdate(){return[[g.FREETEXT_SIZE,vn._defaultFontSize],[g.FREETEXT_COLOR,vn._defaultColor||ie._defaultLineColor]]}get propertiesToUpdate(){return[[g.FREETEXT_SIZE,this.#sa],[g.FREETEXT_COLOR,this.color]]}get toolbarButtons(){return this._colorPicker||=new ks(this),[["colorPicker",this._colorPicker]]}get colorType(){return g.FREETEXT_COLOR}#Ta(t){const e=t=>{this.editorDiv.style.fontSize=`calc(${t}px * var(--total-scale-factor))`,this.translate(0,-(t-this.#sa)*this.parentScale),this.#sa=t,this.#Ma()},i=this.#sa;this.addCommands({cmd:e.bind(this,t),undo:e.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:g.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})}onUpdatedColor(){this.editorDiv.style.color=this.color,this._colorPicker?.update(this.color),super.onUpdatedColor()}#ta(t){const e=t=>{this.color=t,this.onUpdatedColor()},i=this.color;this.addCommands({cmd:e.bind(this,t),undo:e.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:g.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})}_translateEmpty(t,e){this._uiManager.translateSelectedEditors(t,e,!0)}getInitialTranslation(){const t=this.parentScale;return[-vn._internalPadding*t,-(vn._internalPadding+this.#sa)*t]}rebuild(){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.#Ca=new AbortController;const t=this._uiManager.combinedSignal(this.#Ca);return 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}),!0}disableEditMode(){return!!super.disableEditMode()&&(this.overlayDiv.classList.add("enabled"),this.editorDiv.contentEditable=!1,this.div.setAttribute("aria-activedescendant",this.#Ea),this._isDraggable=!0,this.#Ca?.abort(),this.#Ca=null,this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"),!0)}focusin(t){this._focusEventsAllowed&&(super.focusin(t),t.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(t){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,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add("freetextEditing")),super.remove()}#Da(){const t=[];this.editorDiv.normalize();let e=null;for(const i of this.editorDiv.childNodes)e?.nodeType===Node.TEXT_NODE&&"BR"===i.nodeName||(t.push(vn.#Pa(i)),e=i);return t.join("\n")}#Ma(){const[t,e]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:t,div:e}=this,s=e.style.display,n=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=s,e.classList.toggle("hidden",n)}this.rotation%180===this.parentRotation%180?(this.width=i.width/t,this.height=i.height/e):(this.width=i.height/t,this.height=i.width/e),this.fixAndSetPosition()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();const t=this.#Sa,e=this.#Sa=this.#Da().trimEnd();if(t===e)return;const i=t=>{this.#Sa=t,t?(this.#Ia(),this._uiManager.rebuild(this),this.#Ma()):this.remove()};this.addCommands({cmd:()=>{i(e)},undo:()=>{i(t)},mustExec:!1}),this.#Ma()}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}keydown(t){t.target===this.div&&"Enter"===t.key&&(this.enterInEditMode(),t.preventDefault())}editorDivKeydown(t){vn._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;(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.#Ea),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;if(i.fontSize=`calc(${this.#sa}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),this._isCopy||this.annotationElementId){const[i,s]=this.parentDimensions;if(this.annotationElementId){const{position:n}=this._initialData;let[r,a]=this.getInitialTranslation();[r,a]=this.pageTranslationToScreen(r,a);const[o,l]=this.pageDimensions,[h,c]=this.pageTranslation;let d,u;switch(this.rotation){case 0:d=t+(n[0]-h)/o,u=e+this.height-(n[1]-c)/l;break;case 90:d=t+(n[0]-h)/o,u=e-(n[1]-c)/l,[r,a]=[a,-r];break;case 180:d=t-this.width+(n[0]-h)/o,u=e-(n[1]-c)/l,[r,a]=[-r,-a];break;case 270:d=t+(n[0]-h-this.height*l)/o,u=e+(n[1]-c-this.width*o)/l,[r,a]=[-a,r];break}this.setAt(d*i,u*s,r,a)}else this._moveAfterPaste(t,e);this.#Ia(),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}static#Pa(t){return(t.nodeType===Node.TEXT_NODE?t.nodeValue:t.innerText).replaceAll(bn,"")}editorDivPaste(t){const e=t.clipboardData||window.clipboardData,{types:i}=e;if(1===i.length&&"text/plain"===i[0])return;t.preventDefault();const s=vn.#ka(e.getData("text")||"").replaceAll(bn,"\n");if(!s)return;const n=window.getSelection();if(!n.rangeCount)return;this.editorDiv.normalize(),n.deleteFromDocument();const r=n.getRangeAt(0);if(!s.includes("\n"))return r.insertNode(document.createTextNode(s)),this.editorDiv.normalize(),void n.collapseToStart();const{startContainer:a,startOffset:o}=r,l=[],h=[];if(a.nodeType===Node.TEXT_NODE){const t=a.parentElement;if(h.push(a.nodeValue.slice(o).replaceAll(bn,"")),t!==this.editorDiv){let e=l;for(const i of this.editorDiv.childNodes)i!==t?e.push(vn.#Pa(i)):e=h}l.push(a.nodeValue.slice(0,o).replaceAll(bn,""))}else if(a===this.editorDiv){let t=l,e=0;for(const i of this.editorDiv.childNodes)e++===o&&(t=h),t.push(vn.#Pa(i))}this.#Sa=`${l.join("\n")}${s}${h.join("\n")}`,this.#Ia();const c=new Range;let d=Math.sumPrecise(l.map(t=>t.length));for(const{firstChild:u}of this.editorDiv.childNodes)if(u.nodeType===Node.TEXT_NODE){const t=u.nodeValue.length;if(d<=t){c.setStart(u,d),c.setEnd(u,d);break}d-=t}n.removeAllRanges(),n.addRange(c)}#Ia(){if(this.editorDiv.replaceChildren(),this.#Sa)for(const t of this.#Sa.split("\n")){const e=document.createElement("div");e.append(t?document.createTextNode(t):document.createElement("br")),this.editorDiv.append(e)}}#Ra(){return this.#Sa.replaceAll(" "," ")}static#ka(t){return t.replaceAll(" "," ")}get contentDiv(){return this.editorDiv}getPDFRect(){const t=vn._internalPadding*this.parentScale;return this.getRect(t,t)}static async deserialize(t,e,i){let s=null;if(t instanceof en){const{data:{defaultAppearanceData:{fontSize:e,fontColor:i},rect:n,rotation:r,id:a,popupRef:o,richText:l,contentsObj:h,creationDate:c,modificationDate:d},textContent:u,textPosition:g,parent:{page:{pageNumber:m}}}=t;if(!u||0===u.length)return null;s=t={annotationType:p.FREETEXT,color:Array.from(i),fontSize:e,value:u.join("\n"),position:g,pageIndex:m-1,rect:n.slice(0),rotation:r,annotationElementId:a,id:a,deleted:!1,popupRef:o,comment:h?.str||null,richText:l,creationDate:c,modificationDate:d}}const n=await super.deserialize(t,e,i);return n.#sa=t.fontSize,n.color=K.makeHexColor(...t.color),n.#Sa=vn.#ka(t.value),n._initialData=s,t.comment&&n.setCommentData(t),n}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const e=ie._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),i=Object.assign(super.serialize(t),{color:e,fontSize:this.#sa,value:this.#Ra()});return this.addComment(i),t?(i.isCopy=!0,i):this.annotationElementId&&!this.#La(i)?null:(i.id=this.annotationElementId,i)}#La(t){const{value:e,fontSize:i,color:s,pageIndex:n}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||t.value!==e||t.fontSize!==i||t.color.some((t,e)=>t!==s[e])||t.pageIndex!==n}renderAnnotationElement(t){const e=super.renderAnnotationElement(t);if(!e)return null;const{style:i}=e;i.fontSize=`calc(${this.#sa}px * var(--total-scale-factor))`,i.color=this.color,e.replaceChildren();for(const s of this.#Sa.split("\n")){const t=document.createElement("div");t.append(s?document.createTextNode(s):document.createElement("br")),e.append(t)}return t.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#Sa}}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}}class yn{static PRECISION=1e-4;toSVGPath(){P("Abstract method `toSVGPath` must be implemented.")}get box(){P("Abstract getter `box` must be implemented.")}serialize(t,e){P("Abstract method `serialize` must be implemented.")}static _rescale(t,e,i,s,n,r){r||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)r[a]=e+t[a]*s,r[a+1]=i+t[a+1]*n;return r}static _rescaleAndSwap(t,e,i,s,n,r){r||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)r[a]=e+t[a+1]*s,r[a+1]=i+t[a]*n;return r}static _translate(t,e,i,s){s||=new Float32Array(t.length);for(let n=0,r=t.length;n<r;n+=2)s[n]=e+t[n],s[n+1]=i+t[n+1];return s}static svgRound(t){return Math.round(1e4*t)}static _normalizePoint(t,e,i,s,n){switch(n){case 90:return[1-e/i,t/s];case 180:return[1-t/i,1-e/s];case 270:return[e/i,1-t/s];default:return[t/i,e/s]}}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,s,n,r){return[(t+5*i)/6,(e+5*s)/6,(5*i+n)/6,(5*s+r)/6,(i+n)/2,(s+r)/2]}}class wn{#Fa;#Oa=[];#Ba;#Na;#Ua=[];#ja=new Float32Array(18);#Ha;#za;#$a;#Ga;#Wa;#Va;#qa=[];static#Xa=8;static#Ya=2;static#Ka=wn.#Xa+wn.#Ya;constructor({x:t,y:e},i,s,n,r,a=0){this.#Fa=i,this.#Va=n*s,this.#Na=r,this.#ja.set([NaN,NaN,NaN,NaN,t,e],6),this.#Ba=a,this.#Ga=wn.#Xa*s,this.#$a=wn.#Ka*s,this.#Wa=s,this.#qa.push(t,e)}isEmpty(){return isNaN(this.#ja[8])}#Qa(){const t=this.#ja.subarray(4,6),e=this.#ja.subarray(16,18),[i,s,n,r]=this.#Fa;return[(this.#Ha+(t[0]-e[0])/2-i)/n,(this.#za+(t[1]-e[1])/2-s)/r,(this.#Ha+(e[0]-t[0])/2-i)/n,(this.#za+(e[1]-t[1])/2-s)/r]}add({x:t,y:e}){this.#Ha=t,this.#za=e;const[i,s,n,r]=this.#Fa;let[a,o,l,h]=this.#ja.subarray(8,12);const c=t-l,d=e-h,u=Math.hypot(c,d);if(u<this.#$a)return!1;const p=u-this.#Ga,g=p/u,m=g*c,f=g*d;let b=a,v=o;a=l,o=h,l+=m,h+=f,this.#qa?.push(t,e);const y=-f/p,w=m/p,A=y*this.#Va,x=w*this.#Va;if(this.#ja.set(this.#ja.subarray(2,8),0),this.#ja.set([l+A,h+x],4),this.#ja.set(this.#ja.subarray(14,18),12),this.#ja.set([l-A,h-x],16),isNaN(this.#ja[6]))return 0===this.#Ua.length&&(this.#ja.set([a+A,o+x],2),this.#Ua.push(NaN,NaN,NaN,NaN,(a+A-i)/n,(o+x-s)/r),this.#ja.set([a-A,o-x],14),this.#Oa.push(NaN,NaN,NaN,NaN,(a-A-i)/n,(o-x-s)/r)),this.#ja.set([b,v,a,o,l,h],6),!this.isEmpty();this.#ja.set([b,v,a,o,l,h],6);const _=Math.abs(Math.atan2(v-o,b-a)-Math.atan2(f,m));return _<Math.PI/2?([a,o,l,h]=this.#ja.subarray(2,6),this.#Ua.push(NaN,NaN,NaN,NaN,((a+l)/2-i)/n,((o+h)/2-s)/r),[a,o,b,v]=this.#ja.subarray(14,18),this.#Oa.push(NaN,NaN,NaN,NaN,((b+a)/2-i)/n,((v+o)/2-s)/r),!0):([b,v,a,o,l,h]=this.#ja.subarray(0,6),this.#Ua.push(((b+5*a)/6-i)/n,((v+5*o)/6-s)/r,((5*a+l)/6-i)/n,((5*o+h)/6-s)/r,((a+l)/2-i)/n,((o+h)/2-s)/r),[l,h,a,o,b,v]=this.#ja.subarray(12,18),this.#Oa.push(((b+5*a)/6-i)/n,((v+5*o)/6-s)/r,((5*a+l)/6-i)/n,((5*o+h)/6-s)/r,((a+l)/2-i)/n,((o+h)/2-s)/r),!0)}toSVGPath(){if(this.isEmpty())return"";const t=this.#Ua,e=this.#Oa;if(isNaN(this.#ja[6])&&!this.isEmpty())return this.#Ja();const i=[];i.push(`M${t[4]} ${t[5]}`);for(let s=6;s<t.length;s+=6)isNaN(t[s])?i.push(`L${t[s+4]} ${t[s+5]}`):i.push(`C${t[s]} ${t[s+1]} ${t[s+2]} ${t[s+3]} ${t[s+4]} ${t[s+5]}`);this.#Za(i);for(let s=e.length-6;s>=6;s-=6)isNaN(e[s])?i.push(`L${e[s+4]} ${e[s+5]}`):i.push(`C${e[s]} ${e[s+1]} ${e[s+2]} ${e[s+3]} ${e[s+4]} ${e[s+5]}`);return this.#to(i),i.join(" ")}#Ja(){const[t,e,i,s]=this.#Fa,[n,r,a,o]=this.#Qa();return`M${(this.#ja[2]-t)/i} ${(this.#ja[3]-e)/s} L${(this.#ja[4]-t)/i} ${(this.#ja[5]-e)/s} L${n} ${r} L${a} ${o} L${(this.#ja[16]-t)/i} ${(this.#ja[17]-e)/s} L${(this.#ja[14]-t)/i} ${(this.#ja[15]-e)/s} Z`}#to(t){const e=this.#Oa;t.push(`L${e[4]} ${e[5]} Z`)}#Za(t){const[e,i,s,n]=this.#Fa,r=this.#ja.subarray(4,6),a=this.#ja.subarray(16,18),[o,l,h,c]=this.#Qa();t.push(`L${(r[0]-e)/s} ${(r[1]-i)/n} L${o} ${l} L${h} ${c} L${(a[0]-e)/s} ${(a[1]-i)/n}`)}newFreeDrawOutline(t,e,i,s,n,r){return new An(t,e,i,s,n,r)}getOutlines(){const t=this.#Ua,e=this.#Oa,i=this.#ja,[s,n,r,a]=this.#Fa,o=new Float32Array((this.#qa?.length??0)+2);for(let c=0,d=o.length-2;c<d;c+=2)o[c]=(this.#qa[c]-s)/r,o[c+1]=(this.#qa[c+1]-n)/a;if(o[o.length-2]=(this.#Ha-s)/r,o[o.length-1]=(this.#za-n)/a,isNaN(i[6])&&!this.isEmpty())return this.#eo(o);const l=new Float32Array(this.#Ua.length+24+this.#Oa.length);let h=t.length;for(let c=0;c<h;c+=2)isNaN(t[c])?l[c]=l[c+1]=NaN:(l[c]=t[c],l[c+1]=t[c+1]);h=this.#io(l,h);for(let c=e.length-6;c>=6;c-=6)for(let t=0;t<6;t+=2)isNaN(e[c+t])?(l[h]=l[h+1]=NaN,h+=2):(l[h]=e[c+t],l[h+1]=e[c+t+1],h+=2);return this.#so(l,h),this.newFreeDrawOutline(l,o,this.#Fa,this.#Wa,this.#Ba,this.#Na)}#eo(t){const e=this.#ja,[i,s,n,r]=this.#Fa,[a,o,l,h]=this.#Qa(),c=new Float32Array(36);return c.set([NaN,NaN,NaN,NaN,(e[2]-i)/n,(e[3]-s)/r,NaN,NaN,NaN,NaN,(e[4]-i)/n,(e[5]-s)/r,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,l,h,NaN,NaN,NaN,NaN,(e[16]-i)/n,(e[17]-s)/r,NaN,NaN,NaN,NaN,(e[14]-i)/n,(e[15]-s)/r],0),this.newFreeDrawOutline(c,t,this.#Fa,this.#Wa,this.#Ba,this.#Na)}#so(t,e){const i=this.#Oa;return t.set([NaN,NaN,NaN,NaN,i[4],i[5]],e),e+6}#io(t,e){const i=this.#ja.subarray(4,6),s=this.#ja.subarray(16,18),[n,r,a,o]=this.#Fa,[l,h,c,d]=this.#Qa();return t.set([NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/o,NaN,NaN,NaN,NaN,l,h,NaN,NaN,NaN,NaN,c,d,NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/o],e),e+24}}class An extends yn{#Fa;#no=new Float32Array(4);#Ba;#Na;#qa;#Wa;#ro;constructor(t,e,i,s,n,r){super(),this.#ro=t,this.#qa=e,this.#Fa=i,this.#Wa=s,this.#Ba=n,this.#Na=r,this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],this.#ao(r);const[a,o,l,h]=this.#no;for(let c=0,d=t.length;c<d;c+=2)t[c]=(t[c]-a)/l,t[c+1]=(t[c+1]-o)/h;for(let c=0,d=e.length;c<d;c+=2)e[c]=(e[c]-a)/l,e[c+1]=(e[c+1]-o)/h}toSVGPath(){const t=[`M${this.#ro[4]} ${this.#ro[5]}`];for(let e=6,i=this.#ro.length;e<i;e+=6)isNaN(this.#ro[e])?t.push(`L${this.#ro[e+4]} ${this.#ro[e+5]}`):t.push(`C${this.#ro[e]} ${this.#ro[e+1]} ${this.#ro[e+2]} ${this.#ro[e+3]} ${this.#ro[e+4]} ${this.#ro[e+5]}`);return t.push("Z"),t.join(" ")}serialize([t,e,i,s],n){const r=i-t,a=s-e;let o,l;switch(n){case 0:o=yn._rescale(this.#ro,t,s,r,-a),l=yn._rescale(this.#qa,t,s,r,-a);break;case 90:o=yn._rescaleAndSwap(this.#ro,t,e,r,a),l=yn._rescaleAndSwap(this.#qa,t,e,r,a);break;case 180:o=yn._rescale(this.#ro,i,e,-r,a),l=yn._rescale(this.#qa,i,e,-r,a);break;case 270:o=yn._rescaleAndSwap(this.#ro,i,s,-r,-a),l=yn._rescaleAndSwap(this.#qa,i,s,-r,-a);break}return{outline:Array.from(o),points:[Array.from(l)]}}#ao(t){const e=this.#ro;let i=e[4],s=e[5];const n=[i,s,i,s];let r=i,a=s,o=i,l=s;const h=t?Math.max:Math.min,c=new Float32Array(4);for(let u=6,p=e.length;u<p;u+=6){const t=e[u+4],d=e[u+5];isNaN(e[u])?(K.pointBoundingBox(t,d,n),a>d?(r=t,a=d):a===d&&(r=h(r,t)),l<d?(o=t,l=d):l===d&&(o=h(o,t))):(c[0]=c[1]=1/0,c[2]=c[3]=-1/0,K.bezierBoundingBox(i,s,...e.slice(u,u+6),c),K.rectBoundingBox(c[0],c[1],c[2],c[3],n),a>c[1]?(r=c[0],a=c[1]):a===c[1]&&(r=h(r,c[0])),l<c[3]?(o=c[2],l=c[3]):l===c[3]&&(o=h(o,c[2]))),i=t,s=d}const d=this.#no;d[0]=n[0]-this.#Ba,d[1]=n[1]-this.#Ba,d[2]=n[2]-n[0]+2*this.#Ba,d[3]=n[3]-n[1]+2*this.#Ba,this.firstPoint=[r,a],this.lastPoint=[o,l]}get box(){return this.#no}newOutliner(t,e,i,s,n,r=0){return new wn(t,e,i,s,n,r)}getNewOutline(t,e){const[i,s,n,r]=this.#no,[a,o,l,h]=this.#Fa,c=n*l,d=r*h,u=i*l+a,p=s*h+o,g=this.newOutliner({x:this.#qa[0]*c+u,y:this.#qa[1]*d+p},this.#Fa,this.#Wa,t,this.#Na,e??this.#Ba);for(let m=2;m<this.#qa.length;m+=2)g.add({x:this.#qa[m]*c+u,y:this.#qa[m+1]*d+p});return g.getOutlines()}}class xn{#Fa;#oo;#lo;#ho=[];#co=[];constructor(t,e=0,i=0,s=!0){const n=[1/0,1/0,-1/0,-1/0],r=4,a=10**-r;for(const{x:m,y:f,width:b,height:v}of t){const t=Math.floor((m-e)/a)*a,i=Math.ceil((m+b+e)/a)*a,s=Math.floor((f-e)/a)*a,r=Math.ceil((f+v+e)/a)*a,o=[t,s,r,!0],l=[i,s,r,!1];this.#ho.push(o,l),K.rectBoundingBox(t,s,i,r,n)}const o=n[2]-n[0]+2*i,l=n[3]-n[1]+2*i,h=n[0]-i,c=n[1]-i;let d=s?-1/0:1/0,u=1/0;const p=this.#ho.at(s?-1:-2),g=[p[0],p[2]];for(const m of this.#ho){const[t,e,i,n]=m;!n&&s?e<u?(u=e,d=t):e===u&&(d=Math.max(d,t)):n&&!s&&(e<u?(u=e,d=t):e===u&&(d=Math.min(d,t))),m[0]=(t-h)/o,m[1]=(e-c)/l,m[2]=(i-c)/l}this.#Fa=new Float32Array([h,c,o,l]),this.#oo=[d,u],this.#lo=g}getOutlines(){this.#ho.sort((t,e)=>t[0]-e[0]||t[1]-e[1]||t[2]-e[2]);const t=[];for(const e of this.#ho)e[3]?(t.push(...this.#do(e)),this.#uo(e)):(this.#po(e),t.push(...this.#do(e)));return this.#go(t)}#go(t){const e=[],i=new Set;for(const r of t){const[t,i,s]=r;e.push([t,i,r],[t,s,r])}e.sort((t,e)=>t[1]-e[1]||t[0]-e[0]);for(let r=0,a=e.length;r<a;r+=2){const t=e[r][2],s=e[r+1][2];t.push(s),s.push(t),i.add(t),i.add(s)}const s=[];let n;while(i.size>0){const t=i.values().next().value;let[e,r,a,o,l]=t;i.delete(t);let h=e,c=r;n=[e,a],s.push(n);while(1){let t;if(i.has(o))t=o;else{if(!i.has(l))break;t=l}i.delete(t),[e,r,a,o,l]=t,h!==e&&(n.push(h,c,e,c===r?r:a),h=e),c=c===r?a:r}n.push(h,c)}return new _n(s,this.#Fa,this.#oo,this.#lo)}#mo(t){const e=this.#co;let i=0,s=e.length-1;while(i<=s){const n=i+s>>1,r=e[n][0];if(r===t)return n;r<t?i=n+1:s=n-1}return s+1}#uo([,t,e]){const i=this.#mo(t);this.#co.splice(i,0,[t,e])}#po([,t,e]){const i=this.#mo(t);for(let s=i;s<this.#co.length;s++){const[i,n]=this.#co[s];if(i!==t)break;if(i===t&&n===e)return void this.#co.splice(s,1)}for(let s=i-1;s>=0;s--){const[i,n]=this.#co[s];if(i!==t)break;if(i===t&&n===e)return void this.#co.splice(s,1)}}#do(t){const[e,i,s]=t,n=[[e,i,s]],r=this.#mo(s);for(let a=0;a<r;a++){const[t,i]=this.#co[a];for(let s=0,r=n.length;s<r;s++){const[,a,o]=n[s];if(!(i<=a||o<=t))if(a>=t)if(o>i)n[s][1]=i;else{if(1===r)return[];n.splice(s,1),s--,r--}else n[s][2]=t,o>i&&n.push([e,i,o])}}return n}}class _n extends yn{#Fa;#fo;constructor(t,e,i,s){super(),this.#fo=t,this.#Fa=e,this.firstPoint=i,this.lastPoint=s}toSVGPath(){const t=[];for(const e of this.#fo){let[i,s]=e;t.push(`M${i} ${s}`);for(let n=2;n<e.length;n+=2){const r=e[n],a=e[n+1];r===i?(t.push(`V${a}`),s=a):a===s&&(t.push(`H${r}`),i=r)}t.push("Z")}return t.join(" ")}serialize([t,e,i,s],n){const r=[],a=i-t,o=s-e;for(const l of this.#fo){const e=new Array(l.length);for(let i=0;i<l.length;i+=2)e[i]=t+l[i]*a,e[i+1]=s-l[i+1]*o;r.push(e)}return r}get box(){return this.#Fa}get classNamesForOutlining(){return["highlightOutline"]}}class Sn extends wn{newFreeDrawOutline(t,e,i,s,n,r){return new En(t,e,i,s,n,r)}}class En extends An{newOutliner(t,e,i,s,n,r=0){return new Sn(t,e,i,s,n,r)}}class Cn extends ie{#bo=null;#vo=0;#yo;#wo=null;#n=null;#Ao=null;#xo=null;#_o=0;#So=null;#Eo=null;#E=null;#Co=!1;#oo=null;#lo=null;#To=null;#ge="";#Va;#Mo="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=p.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const t=Cn.prototype;return F(this,"_keyboardManager",new Kt([[["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||Cn._defaultColor,this.#Va=t.thickness||Cn._defaultThickness,this.opacity=t.opacity||Cn._defaultOpacity,this.#yo=t.boxes||null,this.#Mo=t.methodOfCreation||"",this.#ge=t.text||"",this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",t.highlightId>-1?(this.#Co=!0,this.#Do(t),this.#Po()):this.#yo&&(this.#bo=t.anchorNode,this.#vo=t.anchorOffset,this.#xo=t.focusNode,this.#_o=t.focusOffset,this.#Io(),this.#Po(),this.rotate(this.rotation)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert")}get telemetryInitialData(){return{action:"added",type:this.#Co?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#Va,methodOfCreation:this.#Mo}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}#Io(){const t=new xn(this.#yo,.001);this.#Eo=t.getOutlines(),[this.x,this.y,this.width,this.height]=this.#Eo.box;const e=new xn(this.#yo,.0025,.001,"ltr"===this._uiManager.direction);this.#Ao=e.getOutlines();const{firstPoint:i}=this.#Eo;this.#oo=[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height];const{lastPoint:s}=this.#Ao;this.#lo=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#Do({highlightOutlines:t,highlightId:e,clipPathId:i}){this.#Eo=t;const s=1.5;if(this.#Ao=t.getNewOutline(this.#Va/2+s,.0025),e>=0)this.#E=e,this.#wo=i,this.parent.drawLayer.finalizeDraw(e,{bbox:t.box,path:{d:t.toSVGPath()}}),this.#To=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#Ao.box,path:{d:this.#Ao.toSVGPath()}},!0);else if(this.parent){const e=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#E,{bbox:Cn.#ko(this.#Eo.box,(e-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#To,{bbox:Cn.#ko(this.#Ao.box,e),path:{d:this.#Ao.toSVGPath()}})}const[n,r,a,o]=t.box;switch(this.rotation){case 0:this.x=n,this.y=r,this.width=a,this.height=o;break;case 90:{const[t,e]=this.parentDimensions;this.x=r,this.y=1-n,this.width=a*e/t,this.height=o*t/e;break}case 180:this.x=1-n,this.y=1-r,this.width=a,this.height=o;break;case 270:{const[t,e]=this.parentDimensions;this.x=1-r,this.y=n,this.width=a*e/t,this.height=o*t/e;break}}const{firstPoint:l}=t;this.#oo=[(l[0]-n)/a,(l[1]-r)/o];const{lastPoint:h}=this.#Ao;this.#lo=[(h[0]-n)/a,(h[1]-r)/o]}static initialize(t,e){ie.initialize(t,e),Cn._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case g.HIGHLIGHT_COLOR:Cn._defaultColor=e;break;case g.HIGHLIGHT_THICKNESS:Cn._defaultThickness=e;break}}translateInPage(t,e){}get toolbarPosition(){return this.#lo}get commentButtonPosition(){return this.#oo}updateParams(t,e){switch(t){case g.HIGHLIGHT_COLOR:this.#ta(e);break;case g.HIGHLIGHT_THICKNESS:this.#Ro(e);break}}static get defaultPropertiesToUpdate(){return[[g.HIGHLIGHT_COLOR,Cn._defaultColor],[g.HIGHLIGHT_THICKNESS,Cn._defaultThickness]]}get propertiesToUpdate(){return[[g.HIGHLIGHT_COLOR,this.color||Cn._defaultColor],[g.HIGHLIGHT_THICKNESS,this.#Va||Cn._defaultThickness],[g.HIGHLIGHT_FREE,this.#Co]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#E,{root:{fill:this.color,"fill-opacity":this.opacity}}),this.#n?.updateColor(this.color),super.onUpdatedColor()}#ta(t){const e=(t,e)=>{this.color=t,this.opacity=e,this.onUpdatedColor()},i=this.color,s=this.opacity;this.addCommands({cmd:e.bind(this,t,Cn._defaultOpacity),undo:e.bind(this,i,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:g.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(t)},!0)}#Ro(t){const e=this.#Va,i=t=>{this.#Va=t,this.#Lo(t)};this.addCommands({cmd:i.bind(this,t),undo:i.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:g.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}get toolbarButtons(){if(this._uiManager.highlightColors){const t=this.#n=new Is({editor:this});return[["colorPicker",t]]}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.#Fo())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#Fo())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this.#Oo(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),null!==this.div&&(this.#Po(),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?this.#Oo():t&&(this.#Po(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.show(this._isVisible),e&&this.select()}#Lo(t){this.#Co&&(this.#Do({highlightOutlines:this.#Eo.getNewOutline(t/2)}),this.fixAndSetPosition(),this.setDims())}#Oo(){null!==this.#E&&this.parent&&(this.parent.drawLayer.remove(this.#E),this.#E=null,this.parent.drawLayer.remove(this.#To),this.#To=null)}#Po(t=this.parent){null===this.#E&&(({id:this.#E,clipPathId:this.#wo}=t.drawLayer.draw({bbox:this.#Eo.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#Co},path:{d:this.#Eo.toSVGPath()}},!1,!0)),this.#To=t.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#Co},bbox:this.#Ao.box,path:{d:this.#Ao.toSVGPath()}},this.#Co),this.#So&&(this.#So.style.clipPath=this.#wo))}static#ko([t,e,i,s],n){switch(n){case 90:return[1-e-s,t,s,i];case 180:return[1-t-i,1-e-s,i,s];case 270:return[e,1-t-i,s,i]}return[t,e,i,s]}rotate(t){const{drawLayer:e}=this.parent;let i;this.#Co?(t=(t-this.rotation+360)%360,i=Cn.#ko(this.#Eo.box,t)):i=Cn.#ko([this.x,this.y,this.width,this.height],t),e.updateProperties(this.#E,{bbox:i,root:{"data-main-rotation":t}}),e.updateProperties(this.#To,{bbox:Cn.#ko(this.#Ao.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;const t=super.render();this.#ge&&(t.setAttribute("aria-label",this.#ge),t.setAttribute("role","mark")),this.#Co?t.classList.add("free"):this.div.addEventListener("keydown",this.#Bo.bind(this),{signal:this._uiManager._signal});const e=this.#So=document.createElement("div");return t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=this.#wo,this.setDims(),Wt(this,this.#So,["pointerover","pointerleave"]),this.enableEditing(),t}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#To,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#To,{rootClass:{hovered:!1}})}#Bo(t){Cn._keyboardManager.exec(this,t)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#No(!0);break;case 1:case 3:this.#No(!1);break}}#No(t){if(!this.#bo)return;const e=window.getSelection();t?e.setPosition(this.#bo,this.#vo):e.setPosition(this.#xo,this.#_o)}select(){super.select(),this.#To&&this.parent?.drawLayer.updateProperties(this.#To,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#To&&(this.parent?.drawLayer.updateProperties(this.#To,{rootClass:{selected:!1}}),this.#Co||this.#No(!1))}get _mustFixPosition(){return!this.#Co}show(t=this._isVisible){super.show(t),this.parent&&(this.parent.drawLayer.updateProperties(this.#E,{rootClass:{hidden:!t}}),this.parent.drawLayer.updateProperties(this.#To,{rootClass:{hidden:!t}}))}#Fo(){return this.#Co?this.rotation:0}#Uo(){if(this.#Co)return null;const[t,e]=this.pageDimensions,[i,s]=this.pageTranslation,n=this.#yo,r=new Float32Array(8*n.length);let a=0;for(const{x:o,y:l,width:h,height:c}of n){const n=o*t+i,d=(1-l)*e+s;r[a]=r[a+4]=n,r[a+1]=r[a+3]=d,r[a+2]=r[a+6]=n+h*t,r[a+5]=r[a+7]=d-c*e,a+=8}return r}#jo(t){return this.#Eo.serialize(t,this.#Fo())}static startHighlighting(t,e,{target:i,x:s,y:n}){const{x:r,y:a,width:o,height:l}=i.getBoundingClientRect(),h=new AbortController,c=t.combinedSignal(h),d=e=>{h.abort(),this.#Ho(t,e)};window.addEventListener("blur",d,{signal:c}),window.addEventListener("pointerup",d,{signal:c}),window.addEventListener("pointerdown",At,{capture:!0,passive:!1,signal:c}),window.addEventListener("contextmenu",wt,{signal:c}),i.addEventListener("pointermove",this.#zo.bind(this,t),{signal:c}),this._freeHighlight=new Sn({x:s,y:n},[r,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#zo(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#Ho(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 s=null;if(t instanceof cn){const{data:{quadPoints:e,rect:i,rotation:n,id:r,color:a,opacity:o,popupRef:l,richText:h,contentsObj:c,creationDate:d,modificationDate:u},parent:{page:{pageNumber:g}}}=t;s=t={annotationType:p.HIGHLIGHT,color:Array.from(a),opacity:o,quadPoints:e,boxes:null,pageIndex:g-1,rect:i.slice(0),rotation:n,annotationElementId:r,id:r,deleted:!1,popupRef:l,richText:h,comment:c?.str||null,creationDate:d,modificationDate:u}}else if(t instanceof hn){const{data:{inkLists:e,rect:i,rotation:n,id:r,color:a,borderStyle:{rawWidth:o},popupRef:l,richText:h,contentsObj:c,creationDate:d,modificationDate:u},parent:{page:{pageNumber:g}}}=t;s=t={annotationType:p.HIGHLIGHT,color:Array.from(a),thickness:o,inkLists:e,boxes:null,pageIndex:g-1,rect:i.slice(0),rotation:n,annotationElementId:r,id:r,deleted:!1,popupRef:l,richText:h,comment:c?.str||null,creationDate:d,modificationDate:u}}const{color:n,quadPoints:r,inkLists:a,opacity:o}=t,l=await super.deserialize(t,e,i);l.color=K.makeHexColor(...n),l.opacity=o||1,a&&(l.#Va=t.thickness),l._initialData=s,t.comment&&l.setCommentData(t);const[h,c]=l.pageDimensions,[d,u]=l.pageTranslation;if(r){const t=l.#yo=[];for(let e=0;e<r.length;e+=8)t.push({x:(r[e]-d)/h,y:1-(r[e+1]-u)/c,width:(r[e+2]-r[e])/h,height:(r[e+1]-r[e+5])/c});l.#Io(),l.#Po(),l.rotate(l.rotation)}else if(a){l.#Co=!0;const t=a[0],i={x:t[0]-d,y:c-(t[1]-u)},s=new Sn(i,[0,0,h,c],1,l.#Va/2,!0,.001);for(let e=0,a=t.length;e<a;e+=2)i.x=t[e]-d,i.y=c-(t[e+1]-u),s.add(i);const{id:n,clipPathId:r}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:s.toSVGPath()}},!0,!0);l.#Do({highlightOutlines:s.getOutlines(),highlightId:n,clipPathId:r}),l.#Po(),l.rotate(l.parentRotation)}return l}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=ie._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),i=super.serialize(t);return Object.assign(i,{color:e,opacity:this.opacity,thickness:this.#Va,quadPoints:this.#Uo(),outlines:this.#jo(i.rect)}),this.addComment(i),this.annotationElementId&&!this.#La(i)?null:(i.id=this.annotationElementId,i)}#La(t){const{color:e}=this._initialData;return this.hasEditedComment||t.color.some((t,i)=>t!==e[i])}renderAnnotationElement(t){return this.deleted?(t.hide(),null):(t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}static canCreateNewEmptyEditor(){return!1}}class Tn{#$o=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.#$o[t]=e}toSVGProperties(){const t=this.#$o;return this.#$o=Object.create(null),{root:t}}reset(){this.#$o=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){P("Not implemented")}}class Mn extends ie{#Go=null;#Wo;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#Vo=null;static#qo=null;static#Xo=null;static _INNER_MARGIN=3;constructor(t){super(t),this.#Wo=t.mustBeCommitted||!1,this._addOutlines(t)}onUpdatedColor(){this._colorPicker?.update(this.color),super.onUpdatedColor()}_addOutlines(t){t.drawOutlines&&(this.#Yo(t),this.#Po())}#Yo({drawOutlines:t,drawId:e,drawingOptions:i}){this.#Go=t,this._drawingOptions||=i,this.annotationElementId||this._uiManager.a11yAlert(`pdfjs-editor-${this.editorType}-added-alert`),e>=0?(this._drawId=e,this.parent.drawLayer.finalizeDraw(e,t.defaultProperties)):this._drawId=this.#Ko(t,this.parent),this.#Qo(t.box)}#Ko(t,e){const{id:i}=e.drawLayer.draw(Mn._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return i}static _mergeSVGProperties(t,e){const i=new Set(Object.keys(t));for(const[s,n]of Object.entries(e))i.has(s)?Object.assign(t[s],n):t[s]=n;return t}static getDefaultDrawingOptions(t){P("Not implemented")}static get typesMap(){P("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),this._currentParent&&(Mn.#Vo.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,s]of this.typesMap)t.push([i,e[s]]);return t}get propertiesToUpdate(){const t=[],{_drawingOptions:e}=this;for(const[i,s]of this.constructor.typesMap)t.push([i,e[s]]);return t}_updateProperty(t,e,i){const s=this._drawingOptions,n=s[e],r=i=>{s.updateProperty(e,i);const n=this.#Go.updateProperty(e,i);n&&this.#Qo(n),this.parent?.drawLayer.updateProperties(this._drawId,s.toSVGProperties()),t===this.colorType&&this.onUpdatedColor()};this.addCommands({cmd:r.bind(this,i),undo:r.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,Mn._mergeSVGProperties(this.#Go.getPathResizingSVGProperties(this.#Jo()),{bbox:this.#Zo()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,Mn._mergeSVGProperties(this.#Go.getPathResizedSVGProperties(this.#Jo()),{bbox:this.#Zo()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#Zo()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,Mn._mergeSVGProperties(this.#Go.getPathTranslatedSVGProperties(this.#Jo(),this.parentDimensions),{bbox:this.#Zo()}))}_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,this.#Wo&&(this.#Wo=!1,this.commit(),this.parent.setSelected(this),t&&this.isOnScreen&&this.div.focus())}remove(){this.#Oo(),super.remove()}rebuild(){this.parent&&(super.rebuild(),null!==this.div&&(this.#Po(),this.#Qo(this.#Go.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),this.#Oo()):t&&(this._uiManager.addShouldRescale(this),this.#Po(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),e&&this.select()}#Oo(){null!==this._drawId&&this.parent&&(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#Po(t=this.parent){null!==this._drawId&&this.parent===t||(null===this._drawId?(this._drawingOptions.updateAll(),this._drawId=this.#Ko(this.#Go,t)):this.parent.drawLayer.updateParent(this._drawId,t.drawLayer))}#tl([t,e,i,s]){const{parentDimensions:[n,r],rotation:a}=this;switch(a){case 90:return[e,1-t,i*(r/n),s*(n/r)];case 180:return[1-t,1-e,i,s];case 270:return[1-e,t,i*(r/n),s*(n/r)];default:return[t,e,i,s]}}#Jo(){const{x:t,y:e,width:i,height:s,parentDimensions:[n,r],rotation:a}=this;switch(a){case 90:return[1-e,t,i*(n/r),s*(r/n)];case 180:return[1-t,1-e,i,s];case 270:return[e,1-t,i*(n/r),s*(r/n)];default:return[t,e,i,s]}}#Qo(t){[this.x,this.y,this.width,this.height]=this.#tl(t),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()}#Zo(){const{x:t,y:e,width:i,height:s,rotation:n,parentRotation:r,parentDimensions:[a,o]}=this;switch((4*n+r)/90){case 1:return[1-e-s,t,s,i];case 2:return[1-t-i,1-e-s,i,s];case 3:return[e,1-t-i,s,i];case 4:return[t,e-i*(a/o),s*(o/a),i*(a/o)];case 5:return[1-e,t,i*(a/o),s*(o/a)];case 6:return[1-t-s*(o/a),1-e,s*(o/a),i*(a/o)];case 7:return[e-i*(a/o),1-t-s*(o/a),i*(a/o),s*(o/a)];case 8:return[t-i,e-s,i,s];case 9:return[1-e,t-i,s,i];case 10:return[1-t,1-e,i,s];case 11:return[e-s,1-t,s,i];case 12:return[t-s*(o/a),e,s*(o/a),i*(a/o)];case 13:return[1-e-i*(a/o),t-s*(o/a),i*(a/o),s*(o/a)];case 14:return[1-t,1-e-i*(a/o),s*(o/a),i*(a/o)];case 15:return[e,1-t,i*(a/o),s*(o/a)];default:return[t,e,i,s]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,Mn._mergeSVGProperties({bbox:this.#Zo()},this.#Go.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#Qo(this.#Go.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let t,e;this._isCopy&&(t=this.x,e=this.y);const i=super.render();i.classList.add("draw");const s=document.createElement("div");return i.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(t,e),i}static createDrawerInstance(t,e,i,s,n){P("Not implemented")}static startDrawing(t,e,i,s){const{target:n,offsetX:r,offsetY:a,pointerId:o,pointerType:l}=s;if(Vt.isInitializedAndDifferentPointerType(l))return;const{viewport:{rotation:h}}=t,{width:c,height:d}=n.getBoundingClientRect(),u=Mn.#qo=new AbortController,p=t.combinedSignal(u);Vt.setPointer(l,o),window.addEventListener("pointerup",t=>{Vt.isSamePointerIdOrRemove(t.pointerId)&&this._endDraw(t)},{signal:p}),window.addEventListener("pointercancel",t=>{Vt.isSamePointerIdOrRemove(t.pointerId)&&this._currentParent.endDrawingSession()},{signal:p}),window.addEventListener("pointerdown",t=>{Vt.isSamePointerType(t.pointerType)&&(Vt.initializeAndAddPointerId(t.pointerId),Mn.#Vo.isCancellable()&&(Mn.#Vo.removeLastElement(),Mn.#Vo.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:p}),window.addEventListener("contextmenu",wt,{signal:p}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:p}),n.addEventListener("touchmove",t=>{Vt.isSameTimeStamp(t.timeStamp)&&At(t)},{signal:p}),t.toggleDrawing(),e._editorUndoBar?.hide(),Mn.#Vo?t.drawLayer.updateProperties(this._currentDrawId,Mn.#Vo.startNew(r,a,c,d,h)):(e.updateUIForDefaultProperties(this),Mn.#Vo=this.createDrawerInstance(r,a,c,d,h),Mn.#Xo=this.getDefaultDrawingOptions(),this._currentParent=t,({id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(Mn.#Xo.toSVGProperties(),Mn.#Vo.defaultSVGProperties),!0,!1)))}static _drawMove(t){if(Vt.isSameTimeStamp(t.timeStamp),!Mn.#Vo)return;const{offsetX:e,offsetY:i,pointerId:s}=t;Vt.isSamePointerId(s)&&(Vt.isUsingMultiplePointers()?this._endDraw(t):(this._currentParent.drawLayer.updateProperties(this._currentDrawId,Mn.#Vo.add(e,i)),Vt.setTimeStamp(t.timeStamp),At(t)))}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,Mn.#Vo=null,Mn.#Xo=null,Vt.clearTimeStamp()),Mn.#qo&&(Mn.#qo.abort(),Mn.#qo=null,Vt.clearPointerIds())}static _endDraw(t){const e=this._currentParent;if(e){if(e.toggleDrawing(!0),this._cleanup(!1),t?.target===e.div&&e.drawLayer.updateProperties(this._currentDrawId,Mn.#Vo.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){const t=Mn.#Vo,i=this._currentDrawId,s=t.getLastElement();return void e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,t.setLastElement(s))},undo:()=>{e.drawLayer.updateProperties(i,t.removeLastElement())},mustExec:!1,type:g.DRAW_STEP})}this.endDrawing(!1)}}static endDrawing(t){const e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(g.DRAW_STEP),!Mn.#Vo.isEmpty()){const{pageDimensions:[i,s],scale:n}=e,r=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:Mn.#Vo.getOutlines(i*n,s*n,n,this._INNER_MARGIN),drawingOptions:Mn.#Xo,mustBeCommitted:!t});return this._cleanup(!0),r}return e.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,i,s,n,r){P("Not implemented")}static async deserialize(t,e,i){const{rawDims:{pageWidth:s,pageHeight:n,pageX:r,pageY:a}}=e.viewport,o=this.deserializeDraw(r,a,s,n,this._INNER_MARGIN,t),l=await super.deserialize(t,e,i);return l.createDrawingOptions(t),l.#Yo({drawOutlines:o}),l.#Po(),l.onScaleChanging(),l.rotate(),l}serializeDraw(t){const[e,i]=this.pageTranslation,[s,n]=this.pageDimensions;return this.#Go.serialize([e,i,s,n],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}}class Dn{#ja=new Float64Array(6);#oa;#el;#mn;#Va;#qa;#il="";#sl=0;#fo=new Pn;#nl;#rl;constructor(t,e,i,s,n,r){this.#nl=i,this.#rl=s,this.#mn=n,this.#Va=r,[t,e]=this.#al(t,e);const a=this.#oa=[NaN,NaN,NaN,NaN,t,e];this.#qa=[t,e],this.#el=[{line:a,points:this.#qa}],this.#ja.set(a,0)}updateProperty(t,e){"stroke-width"===t&&(this.#Va=e)}#al(t,e){return yn._normalizePoint(t,e,this.#nl,this.#rl,this.#mn)}isEmpty(){return!this.#el||0===this.#el.length}isCancellable(){return this.#qa.length<=10}add(t,e){[t,e]=this.#al(t,e);const[i,s,n,r]=this.#ja.subarray(2,6),a=t-n,o=e-r,l=Math.hypot(this.#nl*a,this.#rl*o);return l<=2?null:(this.#qa.push(t,e),isNaN(i)?(this.#ja.set([n,r,t,e],2),this.#oa.push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(this.#ja[0])&&this.#oa.splice(6,6),this.#ja.set([i,s,n,r,t,e],0),this.#oa.push(...yn.createBezierPoints(i,s,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const i=this.add(t,e);return i||(2===this.#qa.length?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,i,s,n){this.#nl=i,this.#rl=s,this.#mn=n,[t,e]=this.#al(t,e);const r=this.#oa=[NaN,NaN,NaN,NaN,t,e];this.#qa=[t,e];const a=this.#el.at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),this.#el.push({line:r,points:this.#qa}),this.#ja.set(r,0),this.#sl=0,this.toSVGPath(),null}getLastElement(){return this.#el.at(-1)}setLastElement(t){return this.#el?(this.#el.push(t),this.#oa=t.line,this.#qa=t.points,this.#sl=0,{path:{d:this.toSVGPath()}}):this.#fo.setLastElement(t)}removeLastElement(){if(!this.#el)return this.#fo.removeLastElement();this.#el.pop(),this.#il="";for(let t=0,e=this.#el.length;t<e;t++){const{line:e,points:i}=this.#el[t];this.#oa=e,this.#qa=i,this.#sl=0,this.toSVGPath()}return{path:{d:this.#il}}}toSVGPath(){const t=yn.svgRound(this.#oa[4]),e=yn.svgRound(this.#oa[5]);if(2===this.#qa.length)return this.#il=`${this.#il} M ${t} ${e} Z`,this.#il;if(this.#qa.length<=6){const i=this.#il.lastIndexOf("M");this.#il=`${this.#il.slice(0,i)} M ${t} ${e}`,this.#sl=6}if(4===this.#qa.length){const t=yn.svgRound(this.#oa[10]),e=yn.svgRound(this.#oa[11]);return this.#il=`${this.#il} L ${t} ${e}`,this.#sl=12,this.#il}const i=[];0===this.#sl&&(i.push(`M ${t} ${e}`),this.#sl=6);for(let s=this.#sl,n=this.#oa.length;s<n;s+=6){const[t,e,n,r,a,o]=this.#oa.slice(s,s+6).map(yn.svgRound);i.push(`C${t} ${e} ${n} ${r} ${a} ${o}`)}return this.#il+=i.join(" "),this.#sl=this.#oa.length,this.#il}getOutlines(t,e,i,s){const n=this.#el.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#fo.build(this.#el,t,e,i,this.#mn,this.#Va,s),this.#ja=null,this.#oa=null,this.#el=null,this.#il=null,this.#fo}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Pn extends yn{#no;#ol=0;#Ba;#el;#nl;#rl;#ll;#mn;#Va;build(t,e,i,s,n,r,a){this.#nl=e,this.#rl=i,this.#ll=s,this.#mn=n,this.#Va=r,this.#Ba=a??0,this.#el=t,this.#hl()}get thickness(){return this.#Va}setLastElement(t){return this.#el.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#el.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const t=[];for(const{line:e}of this.#el)if(t.push(`M${yn.svgRound(e[4])} ${yn.svgRound(e[5])}`),6!==e.length)if(12===e.length&&isNaN(e[6]))t.push(`L${yn.svgRound(e[10])} ${yn.svgRound(e[11])}`);else for(let i=6,s=e.length;i<s;i+=6){const[s,n,r,a,o,l]=e.subarray(i,i+6).map(yn.svgRound);t.push(`C${s} ${n} ${r} ${a} ${o} ${l}`)}else t.push("Z");return t.join("")}serialize([t,e,i,s],n){const r=[],a=[],[o,l,h,c]=this.#cl();let d,u,p,g,m,f,b,v,y;switch(this.#mn){case 0:y=yn._rescale,d=t,u=e+s,p=i,g=-s,m=t+o*i,f=e+(1-l-c)*s,b=t+(o+h)*i,v=e+(1-l)*s;break;case 90:y=yn._rescaleAndSwap,d=t,u=e,p=i,g=s,m=t+l*i,f=e+o*s,b=t+(l+c)*i,v=e+(o+h)*s;break;case 180:y=yn._rescale,d=t+i,u=e,p=-i,g=s,m=t+(1-o-h)*i,f=e+l*s,b=t+(1-o)*i,v=e+(l+c)*s;break;case 270:y=yn._rescaleAndSwap,d=t+i,u=e+s,p=-i,g=-s,m=t+(1-l-c)*i,f=e+(1-o-h)*s,b=t+(1-l)*i,v=e+(1-o)*s;break}for(const{line:w,points:A}of this.#el)r.push(y(w,d,u,p,g,n?new Array(w.length):null)),a.push(y(A,d,u,p,g,n?new Array(A.length):null));return{lines:r,points:a,rect:[m,f,b,v]}}static deserialize(t,e,i,s,n,{paths:{lines:r,points:a},rotation:o,thickness:l}){const h=[];let c,d,u,p,g;switch(o){case 0:g=yn._rescale,c=-t/i,d=e/s+1,u=1/i,p=-1/s;break;case 90:g=yn._rescaleAndSwap,c=-e/s,d=-t/i,u=1/s,p=1/i;break;case 180:g=yn._rescale,c=t/i+1,d=-e/s,u=-1/i,p=1/s;break;case 270:g=yn._rescaleAndSwap,c=e/s+1,d=t/i+1,u=-1/s,p=-1/i;break}if(!r){r=[];for(const t of a){const e=t.length;if(2===e){r.push(new Float32Array([NaN,NaN,NaN,NaN,t[0],t[1]]));continue}if(4===e){r.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));r.push(i);let[s,n,a,o]=t.subarray(0,4);i.set([NaN,NaN,NaN,NaN,s,n],0);for(let r=4;r<e;r+=2){const e=t[r],l=t[r+1];i.set(yn.createBezierPoints(s,n,a,o,e,l),3*(r-2)),[s,n,a,o]=[a,o,e,l]}}}for(let f=0,b=r.length;f<b;f++)h.push({line:g(r[f].map(t=>t??NaN),c,d,u,p),points:g(a[f].map(t=>t??NaN),c,d,u,p)});const m=new this.prototype.constructor;return m.build(h,i,s,1,o,l,n),m}#dl(t=this.#Va){const e=this.#Ba+t/2*this.#ll;return this.#mn%180===0?[e/this.#nl,e/this.#rl]:[e/this.#rl,e/this.#nl]}#cl(){const[t,e,i,s]=this.#no,[n,r]=this.#dl(0);return[t+n,e+r,i-2*n,s-2*r]}#hl(){const t=this.#no=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:s}of this.#el){if(s.length<=12){for(let e=4,i=s.length;e<i;e+=6)K.pointBoundingBox(s[e],s[e+1],t);continue}let e=s[4],i=s[5];for(let n=6,r=s.length;n<r;n+=6){const[r,a,o,l,h,c]=s.subarray(n,n+6);K.bezierBoundingBox(e,i,r,a,o,l,h,c,t),e=h,i=c}}const[e,i]=this.#dl();t[0]=nt(t[0]-e,0,1),t[1]=nt(t[1]-i,0,1),t[2]=nt(t[2]+e,0,1),t[3]=nt(t[3]+i,0,1),t[2]-=t[0],t[3]-=t[1]}get box(){return this.#no}updateProperty(t,e){return"stroke-width"===t?this.#Ro(e):null}#Ro(t){const[e,i]=this.#dl();this.#Va=t;const[s,n]=this.#dl(),[r,a]=[s-e,n-i],o=this.#no;return o[0]-=r,o[1]-=a,o[2]+=2*r,o[3]+=2*a,o}updateParentDimensions([t,e],i){const[s,n]=this.#dl();this.#nl=t,this.#rl=e,this.#ll=i;const[r,a]=this.#dl(),o=r-s,l=a-n,h=this.#no;return h[0]-=o,h[1]-=l,h[2]+=2*o,h[3]+=2*l,h}updateRotation(t){return this.#ol=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#no.map(yn.svgRound).join(" ")}get defaultProperties(){const[t,e]=this.#no;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${yn.svgRound(t)} ${yn.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=this.#no;let i=0,s=0,n=0,r=0,a=0,o=0;switch(this.#ol){case 90:s=e/t,n=-t/e,a=t;break;case 180:i=-1,r=-1,a=t,o=e;break;case 270:s=-e/t,n=t/e,o=e;break;default:return""}return`matrix(${i} ${s} ${n} ${r} ${yn.svgRound(a)} ${yn.svgRound(o)})`}getPathResizingSVGProperties([t,e,i,s]){const[n,r]=this.#dl(),[a,o,l,h]=this.#no;if(Math.abs(l-n)<=yn.PRECISION||Math.abs(h-r)<=yn.PRECISION){const n=t+i/2-(a+l/2),r=e+s/2-(o+h/2);return{path:{"transform-origin":`${yn.svgRound(t)} ${yn.svgRound(e)}`,transform:`${this.rotationTransform} translate(${n} ${r})`}}}const c=(i-2*n)/(l-2*n),d=(s-2*r)/(h-2*r),u=l/i,p=h/s;return{path:{"transform-origin":`${yn.svgRound(a)} ${yn.svgRound(o)}`,transform:`${this.rotationTransform} scale(${u} ${p}) translate(${yn.svgRound(n)} ${yn.svgRound(r)}) scale(${c} ${d}) translate(${yn.svgRound(-n)} ${yn.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,i,s]){const[n,r]=this.#dl(),a=this.#no,[o,l,h,c]=a;if(a[0]=t,a[1]=e,a[2]=i,a[3]=s,Math.abs(h-n)<=yn.PRECISION||Math.abs(c-r)<=yn.PRECISION){const n=t+i/2-(o+h/2),r=e+s/2-(l+c/2);for(const{line:t,points:e}of this.#el)yn._translate(t,n,r,t),yn._translate(e,n,r,e);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${yn.svgRound(t)} ${yn.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const d=(i-2*n)/(h-2*n),u=(s-2*r)/(c-2*r),p=-d*(o+n)+t+n,g=-u*(l+r)+e+r;if(1!==d||1!==u||0!==p||0!==g)for(const{line:m,points:f}of this.#el)yn._rescale(m,p,g,d,u,m),yn._rescale(f,p,g,d,u,f);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${yn.svgRound(t)} ${yn.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],i){const[s,n]=i,r=this.#no,a=t-r[0],o=e-r[1];if(this.#nl===s&&this.#rl===n)for(const{line:l,points:h}of this.#el)yn._translate(l,a,o,l),yn._translate(h,a,o,h);else{const t=this.#nl/s,e=this.#rl/n;this.#nl=s,this.#rl=n;for(const{line:i,points:s}of this.#el)yn._rescale(i,a,o,t,e,i),yn._rescale(s,a,o,t,e,s);r[2]*=t,r[3]*=e}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${yn.svgRound(t)} ${yn.svgRound(e)}`}}}get defaultSVGProperties(){const t=this.#no;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${yn.svgRound(t[0])} ${yn.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}class In extends Tn{constructor(t){super(),this._viewParameters=t,super.updateProperties({fill:"none",stroke:ie._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){"stroke-width"===t&&(e??=this["stroke-width"],e*=this._viewParameters.realScale),super.updateSVGProperty(t,e)}clone(){const t=new In(this._viewParameters);return t.updateAll(this),t}}class kn extends Mn{static _type="ink";static _editorType=p.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(t,e){ie.initialize(t,e),this._defaultDrawingOptions=new In(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return F(this,"typesMap",new Map([[g.INK_THICKNESS,"stroke-width"],[g.INK_COLOR,"stroke"],[g.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,i,s,n){return new Dn(t,e,i,s,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,i,s,n,r){return Pn.deserialize(t,e,i,s,n,r)}static async deserialize(t,e,i){let s=null;if(t instanceof hn){const{data:{inkLists:e,rect:i,rotation:n,id:r,color:a,opacity:o,borderStyle:{rawWidth:l},popupRef:h,richText:c,contentsObj:d,creationDate:u,modificationDate:g},parent:{page:{pageNumber:m}}}=t;s=t={annotationType:p.INK,color:Array.from(a),thickness:l,opacity:o,paths:{points:e},boxes:null,pageIndex:m-1,rect:i.slice(0),rotation:n,annotationElementId:r,id:r,deleted:!1,popupRef:h,richText:c,comment:d?.str||null,creationDate:u,modificationDate:g}}const n=await super.deserialize(t,e,i);return n._initialData=s,t.comment&&n.setCommentData(t),n}get toolbarButtons(){return this._colorPicker||=new ks(this),[["colorPicker",this._colorPicker]]}get colorType(){return g.INK_COLOR}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;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=kn.getDefaultDrawingOptions({stroke:K.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:s,"stroke-opacity":n,"stroke-width":r}}=this,a=Object.assign(super.serialize(t),{color:ie._colorManager.convert(s),opacity:n,thickness:r,paths:{lines:e,points:i}});return this.addComment(a),t?(a.isCopy=!0,a):this.annotationElementId&&!this.#La(a)?null:(a.id=this.annotationElementId,a)}#La(t){const{color:e,thickness:i,opacity:s,pageIndex:n}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||t.color.some((t,i)=>t!==e[i])||t.thickness!==i||t.opacity!==s||t.pageIndex!==n}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;const{points:e,rect:i}=this.serializeDraw(!1);return t.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:e,popup:this.comment}),null}}class Rn extends Pn{toSVGPath(){let t=super.toSVGPath();return t.endsWith("Z")||(t+="Z"),t}}const Ln=8,Fn=3;class On{static#ul={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#pl(t,e,i,s){return i-=t,s-=e,0===i?s>0?0:4:1===i?s+6:2-s}static#gl=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#ml(t,e,i,s,n,r,a){const o=this.#pl(i,s,n,r);for(let l=0;l<8;l++){const n=(-l+o-a+16)%8,r=this.#gl[2*n],h=this.#gl[2*n+1];if(0!==t[(i+r)*e+(s+h)])return n}return-1}static#fl(t,e,i,s,n,r,a){const o=this.#pl(i,s,n,r);for(let l=0;l<8;l++){const n=(l+o+a+16)%8,r=this.#gl[2*n],h=this.#gl[2*n+1];if(0!==t[(i+r)*e+(s+h)])return n}return-1}static#bl(t,e,i,s){const n=t.length,r=new Int32Array(n);for(let h=0;h<n;h++)r[h]=t[h]<=s?1:0;for(let h=1;h<i-1;h++)r[h*e]=r[h*e+e-1]=0;for(let h=0;h<e;h++)r[h]=r[e*i-1-h]=0;let a,o=1;const l=[];for(let h=1;h<i-1;h++){a=1;for(let t=1;t<e-1;t++){const i=h*e+t,s=r[i];if(0===s)continue;let n=h,c=t;if(1===s&&0===r[i-1])o+=1,c-=1;else{if(!(s>=1&&0===r[i+1])){1!==s&&(a=Math.abs(s));continue}o+=1,c+=1,s>1&&(a=s)}const d=[t,h],u=c===t+1,p={isHole:u,points:d,id:o,parent:0};let g;l.push(p);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.#ml(r,e,h,t,n,c,0);if(-1===m){r[i]=-o,1!==r[i]&&(a=Math.abs(r[i]));continue}let f=this.#gl[2*m],b=this.#gl[2*m+1];const v=h+f,y=t+b;n=v,c=y;let w=h,A=t;while(1){const s=this.#fl(r,e,w,A,n,c,1);f=this.#gl[2*s],b=this.#gl[2*s+1];const l=w+f,u=A+b;d.push(u,l);const p=w*e+A;if(0===r[p+1]?r[p]=-o:1===r[p]&&(r[p]=o),l===h&&u===t&&w===v&&A===y){1!==r[i]&&(a=Math.abs(r[i]));break}n=w,c=A,w=l,A=u}}}return l}static#vl(t,e,i,s){if(i-e<=4){for(let n=e;n<i-2;n+=2)s.push(t[n],t[n+1]);return}const n=t[e],r=t[e+1],a=t[i-4]-n,o=t[i-3]-r,l=Math.hypot(a,o),h=a/l,c=o/l,d=h*r-c*n,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)),v=p*(1-b+b**2),y=Math.max(Math.atan(Math.abs(f+m)*v),Math.atan(Math.abs(f-m)*v));let w=0,A=e;for(let x=e+2;x<i-2;x+=2){const e=Math.abs(d-h*t[x+1]+c*t[x]);e>w&&(A=x,w=e)}w>(l*y)**2?(this.#vl(t,e,A+2,s),this.#vl(t,A,i,s)):s.push(n,r)}static#yl(t){const e=[],i=t.length;return this.#vl(t,0,i,e),e.push(t[i-2],t[i-1]),e.length<=4?null:e}static#wl(t,e,i,s,n,r){const a=new Float32Array(r**2),o=-2*s**2,l=r>>1;for(let g=0;g<r;g++){const t=(g-l)**2;for(let e=0;e<r;e++)a[g*r+e]=Math.exp((t+(e-l)**2)/o)}const h=new Float32Array(256),c=-2*n**2;for(let g=0;g<256;g++)h[g]=Math.exp(g**2/c);const d=t.length,u=new Uint8Array(d),p=new Uint32Array(256);for(let g=0;g<i;g++)for(let s=0;s<e;s++){const n=g*e+s,o=t[n];let c=0,d=0;for(let u=0;u<r;u++){const n=g+u-l;if(!(n<0||n>=i))for(let i=0;i<r;i++){const p=s+i-l;if(p<0||p>=e)continue;const g=t[n*e+p],m=a[u*r+i]*h[Math.abs(g-o)];c+=g*m,d+=m}}const m=u[n]=Math.round(c/d);p[m]++}return[u,p]}static#Al(t){const e=new Uint32Array(256);for(const i of t)e[i]++;return e}static#xl(t){const e=t.length,i=new Uint8ClampedArray(e>>2);let s=-1/0,n=1/0;for(let a=0,o=i.length;a<o;a++){const e=i[a]=t[a<<2];s=Math.max(s,e),n=Math.min(n,e)}const r=255/(s-n);for(let a=0,o=i.length;a<o;a++)i[a]=(i[a]-n)*r;return i}static#_l(t){let e,i=-1/0,s=-1/0;const n=t.findIndex(t=>0!==t);let r=n,a=n;for(e=n;e<256;e++){const n=t[e];n>i&&(e-r>s&&(s=e-r,a=e-1),i=n,r=e)}for(e=a-1;e>=0;e--)if(t[e]>t[e+1])break;return e}static#Sl(t){const e=t,{width:i,height:s}=t,{maxDim:n}=this.#ul;let r=i,a=s;if(i>n||s>n){let o=i,l=s,h=Math.log2(Math.max(i,s)/n);const c=Math.floor(h);h=h===c?c-1:c;for(let i=0;i<h;i++){r=Math.ceil(o/2),a=Math.ceil(l/2);const i=new OffscreenCanvas(r,a),s=i.getContext("2d");s.drawImage(t,0,0,o,l,0,0,r,a),o=r,l=a,t!==e&&t.close(),t=i.transferToImageBitmap()}const d=Math.min(n/r,n/a);r=Math.round(r*d),a=Math.round(a*d)}const o=new OffscreenCanvas(r,a),l=o.getContext("2d",{willReadFrequently:!0});l.fillStyle="white",l.fillRect(0,0,r,a),l.filter="grayscale(1)",l.drawImage(t,0,0,t.width,t.height,0,0,r,a);const h=l.getImageData(0,0,r,a).data,c=this.#xl(h);return[c,r,a]}static extractContoursFromText(t,{fontFamily:e,fontStyle:i,fontWeight:s},n,r,a,o){let l=new OffscreenCanvas(1,1),h=l.getContext("2d",{alpha:!1});const c=200,d=h.font=`${i} ${s} ${c}px ${e}`,{actualBoundingBoxLeft:u,actualBoundingBoxRight:p,actualBoundingBoxAscent:g,actualBoundingBoxDescent:m,fontBoundingBoxAscent:f,fontBoundingBoxDescent:b,width:v}=h.measureText(t),y=1.5,w=Math.ceil(Math.max(Math.abs(u)+Math.abs(p)||0,v)*y),A=Math.ceil(Math.max(Math.abs(g)+Math.abs(m)||c,Math.abs(f)+Math.abs(b)||c)*y);l=new OffscreenCanvas(w,A),h=l.getContext("2d",{alpha:!0,willReadFrequently:!0}),h.font=d,h.filter="grayscale(1)",h.fillStyle="white",h.fillRect(0,0,w,A),h.fillStyle="black",h.fillText(t,w*(y-1)/2,A*(3-y)/2);const x=this.#xl(h.getImageData(0,0,w,A).data),_=this.#Al(x),S=this.#_l(_),E=this.#bl(x,w,A,S);return this.processDrawnLines({lines:{curves:E,width:w,height:A},pageWidth:n,pageHeight:r,rotation:a,innerMargin:o,mustSmooth:!0,areContours:!0})}static process(t,e,i,s,n){const[r,a,o]=this.#Sl(t),[l,h]=this.#wl(r,a,o,Math.hypot(a,o)*this.#ul.sigmaSFactor,this.#ul.sigmaR,this.#ul.kernelSize),c=this.#_l(h),d=this.#bl(l,a,o,c);return this.processDrawnLines({lines:{curves:d,width:a,height:o},pageWidth:e,pageHeight:i,rotation:s,innerMargin:n,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:t,pageWidth:e,pageHeight:i,rotation:s,innerMargin:n,mustSmooth:r,areContours:a}){s%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:b}of o){const t=r?this.#yl(b):b;if(!t)continue;m.push(t);const e=t.length,i=new Float32Array(e),s=new Float32Array(3*(2===e?2:e-2));if(d.push({line:s,points:i}),2===e){i[0]=t[0]*p,i[1]=t[1]*g,s.set([NaN,NaN,NaN,NaN,i[0],i[1]],0);continue}let[n,a,o,l]=t;n*=p,a*=g,o*=p,l*=g,i.set([n,a,o,l],0),s.set([NaN,NaN,NaN,NaN,n,a],0);for(let r=4;r<e;r+=2){const e=i[r]=t[r]*p,h=i[r+1]=t[r+1]*g;s.set(yn.createBezierPoints(n,a,o,l,e,h),3*(r-2)),[n,a,o,l]=[o,l,e,h]}}if(0===d.length)return null;const f=a?new Rn:new Pn;return f.build(d,e,i,1,s,a?0:c,n),{outline:f,newCurves:m,areContours:a,thickness:c,width:l,height:h}}static async compressSignature({outlines:t,areContours:e,thickness:i,width:s,height:n}){let r,a=1/0,o=-1/0,l=0;for(const v of t){l+=v.length;for(let t=2,e=v.length;t<e;t++){const e=v[t]-v[t-2];a=Math.min(a,e),o=Math.max(o,e)}}r=a>=-128&&o<=127?Int8Array:a>=-32768&&o<=32767?Int16Array:Int32Array;const h=t.length,c=Ln+Fn*h,d=new Uint32Array(c);let u=0;d[u++]=c*Uint32Array.BYTES_PER_ELEMENT+(l-2*h)*r.BYTES_PER_ELEMENT,d[u++]=0,d[u++]=s,d[u++]=n,d[u++]=e?0:1,d[u++]=Math.max(0,Math.floor(i??0)),d[u++]=h,d[u++]=r.BYTES_PER_ELEMENT;for(const v of t)d[u++]=v.length-2,d[u++]=v[0],d[u++]=v[1];const p=new CompressionStream("deflate-raw"),g=p.writable.getWriter();await g.ready,g.write(d);const m=r.prototype.constructor;for(const v of t){const t=new m(v.length-2);for(let e=2,i=v.length;e<i;e++)t[e-2]=v[e]-v[e-2];g.write(t)}g.close();const f=await new Response(p.readable).arrayBuffer(),b=new Uint8Array(f);return rt(b)}static async decompressSignature(t){try{const e=at(t),{readable:i,writable:s}=new DecompressionStream("deflate-raw"),n=s.getWriter();await n.ready,n.write(e).then(async()=>{await n.ready,await n.close()}).catch(()=>{});let r=null,a=0;for await(const t of i)r||=new Uint8Array(new Uint32Array(t.buffer,0,4)[0]),r.set(t,a),a+=t.length;const o=new Uint32Array(r.buffer,0,r.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=(Ln+Fn*p)*Uint32Array.BYTES_PER_ELEMENT;let b;switch(g){case Int8Array.BYTES_PER_ELEMENT:b=new Int8Array(r.buffer,f);break;case Int16Array.BYTES_PER_ELEMENT:b=new Int16Array(r.buffer,f);break;case Int32Array.BYTES_PER_ELEMENT:b=new Int32Array(r.buffer,f);break}a=0;for(let t=0;t<p;t++){const e=o[Fn*t+Ln],i=new Float32Array(e+2);m.push(i);for(let s=0;s<Fn-1;s++)i[s]=o[Fn*t+Ln+s+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(e){return D(`decompressSignature: ${e}`),null}}}class Bn extends Tn{constructor(){super(),super.updateProperties({fill:ie._defaultLineColor,"stroke-width":0})}clone(){const t=new Bn;return t.updateAll(this),t}}class Nn extends In{constructor(t){super(t),super.updateProperties({stroke:ie._defaultLineColor,"stroke-width":1})}clone(){const t=new Nn(this._viewParameters);return t.updateAll(this),t}}class Un extends Mn{#El=!1;#Cl=null;#Tl=null;#Ml=null;static _type="signature";static _editorType=p.SIGNATURE;static _defaultDrawingOptions=null;constructor(t){super({...t,mustBeCommitted:!0,name:"signatureEditor"}),this._willKeepAspectRatio=!0,this.#Tl=t.signatureData||null,this.#Cl=null,this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(t,e){ie.initialize(t,e),this._defaultDrawingOptions=new Bn,this._defaultDrawnSignatureOptions=new Nn(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!1}static get typesMap(){return F(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!this.#Cl}}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(),null===this._drawId)if(this.#Tl){const{lines:t,mustSmooth:e,areContours:i,description:s,uuid:n,heightInPage:r}=this.#Tl,{rawDims:{pageWidth:a,pageHeight:o},rotation:l}=this.parent.viewport,h=On.processDrawnLines({lines:t,pageWidth:a,pageHeight:o,rotation:l,innerMargin:Un._INNER_MARGIN,mustSmooth:e,areContours:i});this.addSignature(h,r,s,n)}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.#Cl||""}));return i&&(this._isCopy=!0,this._moveAfterPaste(t,e)),this.div}setUuid(t){this.#Ml=t,this.addEditToolbar()}getUuid(){return this.#Ml}get description(){return this.#Cl}set description(t){this.#Cl=t,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:s,height:n}=this.#Tl,r=Math.max(s,n),a=On.processDrawnLines({lines:{curves:t.map(t=>({points:t})),thickness:i,width:s,height:n},pageWidth:r,pageHeight:r,rotation:0,innerMargin:0,mustSmooth:!1,areContours:e});return{areContours:e,outline:a.outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(t,e,i,s){const{x:n,y:r}=this,{outline:a}=this.#Tl=t;let o;this.#El=a instanceof Rn,this.description=i,this.#El?o=Un.getDefaultDrawingOptions():(o=Un._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,this.width>=1&&(h*=.9/this.width,this.width=.9),this.height=h,this.setDims(),this.x=n,this.y=r,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(s),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!s,hasDescription:!!i}}),this.div.hidden=!1}getFromImage(t){const{rawDims:{pageWidth:e,pageHeight:i},rotation:s}=this.parent.viewport;return On.process(t,e,i,s,Un._INNER_MARGIN)}getFromText(t,e){const{rawDims:{pageWidth:i,pageHeight:s},rotation:n}=this.parent.viewport;return On.extractContoursFromText(t,e,i,s,n,Un._INNER_MARGIN)}getDrawnSignature(t){const{rawDims:{pageWidth:e,pageHeight:i},rotation:s}=this.parent.viewport;return On.processDrawnLines({lines:t,pageWidth:e,pageHeight:i,rotation:s,innerMargin:Un._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:t,thickness:e}){t?this._drawingOptions=Un.getDefaultDrawingOptions():(this._drawingOptions=Un._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":s}}=this,n=Object.assign(super.serialize(t),{isSignature:!0,areContours:this.#El,color:[0,0,0],thickness:this.#El?0:s});return this.addComment(n),t?(n.paths={lines:e,points:i},n.uuid=this.#Ml,n.isCopy=!0):n.lines=e,this.#Cl&&(n.accessibilityData={type:"Figure",alt:this.#Cl}),n}static deserializeDraw(t,e,i,s,n,r){return r.areContours?Rn.deserialize(t,e,i,s,n,r):Pn.deserialize(t,e,i,s,n,r)}static async deserialize(t,e,i){const s=await super.deserialize(t,e,i);return s.#El=t.areContours,s.description=t.accessibilityData?.alt||"",s.#Ml=t.uuid,s}}class jn extends ie{#Dl=null;#Pl=null;#Il=null;#kl=null;#Rl=null;#Ll="";#Fl=null;#Ol=!1;#Bl=null;#Nl=!1;#Ul=!1;static _type="stamp";static _editorType=p.STAMP;constructor(t){super({...t,name:"stampEditor"}),this.#kl=t.bitmapUrl,this.#Rl=t.bitmapFile,this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(t,e){ie.initialize(t,e)}static isHandlingMimeForPasting(t){return It.includes(t)}static paste(t,e){e.pasteEditor({mode:p.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}}#jl(t,e=!1){t?(this.#Dl=t.bitmap,e||(this.#Pl=t.id,this.#Nl=t.isSvg),t.file&&(this.#Ll=t.file.name),this.#Hl()):this.remove()}#zl(){if(this.#Il=null,this._uiManager.enableWaiting(!1),this.#Fl)if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#Dl)this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#Dl){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:s,width:n,height:r}=t||this.copyCanvas(null,null,!0).imageData,a=await i.guess({name:"altText",request:{data:s,width:n,height:r,channels:s.length/(n*r)}});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;return await this.setGuessedAltText(o),e&&!this.hasAltTextData()&&(this.altTextData={alt:o,decorative:!1}),o}#$l(){if(this.#Pl)return this._uiManager.enableWaiting(!0),void this._uiManager.imageManager.getFromId(this.#Pl).then(t=>this.#jl(t,!0)).finally(()=>this.#zl());if(this.#kl){const t=this.#kl;return this.#kl=null,this._uiManager.enableWaiting(!0),void(this.#Il=this._uiManager.imageManager.getFromUrl(t).then(t=>this.#jl(t)).finally(()=>this.#zl()))}if(this.#Rl){const t=this.#Rl;return this.#Rl=null,this._uiManager.enableWaiting(!0),void(this.#Il=this._uiManager.imageManager.getFromFile(t).then(t=>this.#jl(t)).finally(()=>this.#zl()))}const t=document.createElement("input");t.type="file",t.accept=It.join(",");const e=this._uiManager._signal;this.#Il=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.#jl(e)}else this.remove();i()},{signal:e}),t.addEventListener("cancel",()=>{this.remove(),i()},{signal:e})}).finally(()=>this.#zl()),t.click()}remove(){this.#Pl&&(this.#Dl=null,this._uiManager.imageManager.deleteId(this.#Pl),this.#Fl?.remove(),this.#Fl=null,this.#Bl&&(clearTimeout(this.#Bl),this.#Bl=null)),super.remove()}rebuild(){this.parent?(super.rebuild(),null!==this.div&&(this.#Pl&&null===this.#Fl&&this.#$l(),this.isAttachedToDOM||this.parent.add(this))):this.#Pl&&this.#$l()}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(this.#Il||this.#Dl||this.#kl||this.#Rl||this.#Pl||this.#Ol)}get toolbarButtons(){return[["altText",this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;return this._isCopy&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.createAltText(),this.#Ol||(this.#Dl?this.#Hl():this.#$l()),this._isCopy&&this._moveAfterPaste(t,e),this._uiManager.addShouldRescale(this),this.div}setCanvas(t,e){const{id:i,bitmap:s}=this._uiManager.imageManager.getFromCanvas(t,e);e.remove(),i&&this._uiManager.imageManager.isValidId(i)&&(this.#Pl=i,s&&(this.#Dl=s),this.#Ol=!1,this.#Hl())}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;null!==this.#Bl&&clearTimeout(this.#Bl);const t=200;this.#Bl=setTimeout(()=>{this.#Bl=null,this.#Gl()},t)}#Hl(){const{div:t}=this;let{width:e,height:i}=this.#Dl;const[s,n]=this.pageDimensions,r=.75;if(this.width)e=this.width*s,i=this.height*n;else if(e>r*s||i>r*n){const t=Math.min(r*s/e,r*n/i);e*=t,i*=t}this._uiManager.enableWaiting(!1);const a=this.#Fl=document.createElement("canvas");a.setAttribute("role","img"),this.addContainer(a),this.width=e/s,this.height=i/n,this.setDims(),this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&!this.annotationElementId||(t.hidden=!1),this.#Gl(),this.#Ul||(this.parent.addUndoableEditor(this),this.#Ul=!0),this._reportTelemetry({action:"inserted_image"}),this.#Ll&&this.div.setAttribute("aria-description",this.#Ll),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert")}copyCanvas(t,e,i=!1){t||(t=224);const{width:s,height:n}=this.#Dl,r=new Pt;let a=this.#Dl,o=s,l=n,h=null;if(e){if(s>e||n>e){const t=Math.min(e/s,e/n);o=Math.floor(s*t),l=Math.floor(n*t)}h=document.createElement("canvas");const t=h.width=Math.ceil(o*r.sx),i=h.height=Math.ceil(l*r.sy);this.#Nl||(a=this.#Wl(t,i));const c=h.getContext("2d");c.filter=this._uiManager.hcmFilter;let d="white",u="#cfcfd8";"none"!==this._uiManager.hcmFilter?u="black":kt.isDarkMode&&(d="#8f8f9d",u="#42414d");const p=15,g=p*r.sx,m=p*r.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(r.symmetric&&a.width<t&&a.height<t)e=a.width,i=a.height;else if(a=this.#Dl,s>t||n>t){const r=Math.min(t/s,t/n);e=Math.floor(s*r),i=Math.floor(n*r),this.#Nl||(a=this.#Wl(e,i))}const o=new OffscreenCanvas(e,i),l=o.getContext("2d",{willReadFrequently:!0});l.drawImage(a,0,0,a.width,a.height,0,0,e,i),c={width:e,height:i,data:l.getImageData(0,0,e,i).data}}return{canvas:h,width:o,height:l,imageData:c}}#Wl(t,e){const{width:i,height:s}=this.#Dl;let n=i,r=s,a=this.#Dl;while(n>2*t||r>2*e){const i=n,s=r;n>2*t&&(n=n>=16384?Math.floor(n/2)-1:Math.ceil(n/2)),r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2));const o=new OffscreenCanvas(n,r),l=o.getContext("2d");l.drawImage(a,0,0,i,s,0,0,n,r),a=o.transferToImageBitmap()}return a}#Gl(){const[t,e]=this.parentDimensions,{width:i,height:s}=this,n=new Pt,r=Math.ceil(i*t*n.sx),a=Math.ceil(s*e*n.sy),o=this.#Fl;if(!o||o.width===r&&o.height===a)return;o.width=r,o.height=a;const l=this.#Nl?this.#Dl:this.#Wl(r,a),h=o.getContext("2d");h.filter=this._uiManager.hcmFilter,h.drawImage(l,0,0,l.width,l.height,0,0,r,a)}#Vl(t){if(t){if(this.#Nl){const t=this._uiManager.imageManager.getSvgUrl(this.#Pl);if(t)return t}const t=document.createElement("canvas");({width:t.width,height:t.height}=this.#Dl);const e=t.getContext("2d");return e.drawImage(this.#Dl,0,0),t.toDataURL()}if(this.#Nl){const[t,e]=this.pageDimensions,i=Math.round(this.width*t*ct.PDF_TO_CSS_UNITS),s=Math.round(this.height*e*ct.PDF_TO_CSS_UNITS),n=new OffscreenCanvas(i,s),r=n.getContext("2d");return r.drawImage(this.#Dl,0,0,this.#Dl.width,this.#Dl.height,0,0,i,s),n.transferToImageBitmap()}return structuredClone(this.#Dl)}static async deserialize(t,e,i){let s=null,n=!1;if(t instanceof gn){const{data:{rect:r,rotation:a,id:o,structParent:l,popupRef:h,richText:c,contentsObj:d,creationDate:u,modificationDate:g},container:m,parent:{page:{pageNumber:f}},canvas:b}=t;let v,y;b?(delete t.canvas,({id:v,bitmap:y}=i.imageManager.getFromCanvas(m.id,b)),b.remove()):(n=!0,t._hasNoCanvas=!0);const w=(await e._structTree.getAriaAttributes(`${it}${o}`))?.get("aria-label")||"";s=t={annotationType:p.STAMP,bitmapId:v,bitmap:y,pageIndex:f-1,rect:r.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:g}}const r=await super.deserialize(t,e,i),{rect:a,bitmap:o,bitmapUrl:l,bitmapId:h,isSvg:c,accessibilityData:d}=t;n?(i.addMissingCanvas(t.id,r),r.#Ol=!0):h&&i.imageManager.isValidId(h)?(r.#Pl=h,o&&(r.#Dl=o)):r.#kl=l,r.#Nl=c;const[u,g]=r.pageDimensions;return r.width=(a[2]-a[0])/u,r.height=(a[3]-a[1])/g,d&&(r.altTextData=d),r._initialData=s,t.comment&&r.setCommentData(t),r.#Ul=!!s,r}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.#Pl,isSvg:this.#Nl});if(this.addComment(i),t)return i.bitmapUrl=this.#Vl(!0),i.accessibilityData=this.serializeAltText(!0),i.isCopy=!0,i;const{decorative:s,altText:n}=this.serializeAltText(!1);if(!s&&n&&(i.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){const t=this.#La(i);return t.isSame?null:(t.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1,i.id=this.annotationElementId,delete i.bitmapId,i)}if(null===e)return i;e.stamps||=new Map;const r=this.#Nl?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(e.stamps.has(this.#Pl)){if(this.#Nl){const t=e.stamps.get(this.#Pl);r>t.area&&(t.area=r,t.serialized.bitmap.close(),t.serialized.bitmap=this.#Vl(!1))}}else e.stamps.set(this.#Pl,{area:r,serialized:i}),i.bitmap=this.#Vl(!1);return i}#La(t){const{pageIndex:e,accessibilityData:{altText:i}}=this._initialData,s=t.pageIndex===e,n=(t.accessibilityData?.alt||"")===i;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&s&&n,isSameAltText:n}}renderAnnotationElement(t){return this.deleted?(t.hide(),null):(t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}}class Hn{#fa;#ql=!1;#Xl=null;#Yl=null;#Kl=null;#Ql=new Map;#Jl=!1;#Zl=!1;#th=!1;#eh=null;#ih=null;#sh=null;#nh=null;#rh=null;#ah=-1;#b;static _initialized=!1;static#Y=new Map([vn,kn,jn,Cn,Un].map(t=>[t._editorType,t]));constructor({uiManager:t,pageIndex:e,div:i,structTreeLayer:s,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:o,viewport:l,l10n:h}){const c=[...Hn.#Y.values()];if(!Hn._initialized){Hn._initialized=!0;for(const e of c)e.initialize(h,t)}t.registerEditorTypes(c),this.#b=t,this.pageIndex=e,this.div=i,this.#fa=n,this.#Xl=r,this.viewport=l,this.#sh=o,this.drawLayer=a,this._structTree=s,this.#b.addLayer(this)}get isEmpty(){return 0===this.#Ql.size}get isInvisible(){return this.isEmpty&&this.#b.getMode()===p.NONE}updateToolbar(t){this.#b.updateToolbar(t)}updateMode(t=this.#b.getMode()){switch(this.#oh(),t){case p.NONE:return this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),void this.disableClick();case p.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case p.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;if(e.toggle("nonEditing",!1),t===p.POPUP)e.toggle("commentEditing",!0);else{e.toggle("commentEditing",!1);for(const i of Hn.#Y.values())e.toggle(`${i._type}Editing`,t===i._editorType)}this.div.hidden=!1}hasTextLayer(t){return t===this.#sh?.div}setEditingState(t){this.#b.setEditingState(t)}addCommands(t){this.#b.addCommands(t)}cleanUndoStack(t){this.#b.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#Xl?.togglePointerEvents(t)}get#lh(){return 0!==this.#Ql.size?this.#Ql.values():this.#b.getEditors(this.pageIndex)}async enable(){this.#th=!0,this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle("nonEditing",!1),this.#rh?.abort(),this.#rh=null;const t=new Set;for(const i of this.#lh)i.enableEditing(),i.show(!0),i.annotationElementId&&(this.#b.removeChangedExistingAnnotation(i),t.add(i.annotationElementId));const e=this.#Xl;if(e)for(const i of e.getEditableAnnotations()){if(i.hide(),this.#b.isDeletedAnnotationElement(i.data.id))continue;if(t.has(i.data.id))continue;const e=await this.deserialize(i);e&&(this.addOrRebuild(e),e.enableEditing())}this.#th=!1,this.#b._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){if(this.#Zl=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle("nonEditing",!0),this.#sh&&!this.#rh){this.#rh=new AbortController;const t=this.#b.combinedSignal(this.#rh);this.#sh.div.addEventListener("pointerdown",t=>{const e=500,{clientX:i,clientY:s,timeStamp:n}=t,r=this.#ah;if(n-r>e)return void(this.#ah=n);this.#ah=-1;const{classList:a}=this.div;a.toggle("getElements",!0);const o=document.elementsFromPoint(i,s);if(a.toggle("getElements",!1),!this.div.contains(o[0]))return;let l;const h=new RegExp(`^${u}[0-9]+$`);for(const d of o)if(h.test(d.id)){l=d.id;break}if(!l)return;const c=this.#Ql.get(l);null===c?.annotationElementId&&(t.stopPropagation(),t.preventDefault(),c.dblclick(t))},{signal:t,capture:!0})}const t=this.#Xl,e=[];if(t){const i=new Map,s=new Map;for(const t of this.#lh)t.disableEditing(),t.annotationElementId?null===t.serialize()?(s.set(t.annotationElementId,t),this.getEditableAnnotation(t.annotationElementId)?.show(),t.remove()):i.set(t.annotationElementId,t):e.push(t);const n=t.getEditableAnnotations();for(const t of n){const{id:e}=t.data;if(this.#b.isDeletedAnnotationElement(e)){t.updateEdited({deleted:!0});continue}let n=s.get(e);n?(n.resetAnnotationElement(t),n.show(!1),t.show()):(n=i.get(e),n&&(this.#b.addChangedExistingAnnotation(n),n.renderAnnotationElement(t)&&n.show(!1)),t.show())}}this.#oh(),this.isEmpty&&(this.div.hidden=!0);const{classList:i}=this.div;for(const s of Hn.#Y.values())i.remove(`${s._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),t?.updateFakeAnnotations(e),this.#Zl=!1}getEditableAnnotation(t){return this.#Xl?.getEditableAnnotation(t)||null}setActiveEditor(t){const e=this.#b.getActive();e!==t&&this.#b.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#sh?.div&&!this.#nh){this.#nh=new AbortController;const t=this.#b.combinedSignal(this.#nh);this.#sh.div.addEventListener("pointerdown",this.#hh.bind(this),{signal:t}),this.#sh.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#sh?.div&&this.#nh&&(this.#nh.abort(),this.#nh=null,this.#sh.div.classList.remove("highlighting"))}#hh(t){this.#b.unselectAll();const{target:e}=t;if(e===this.#sh.div||("img"===e.getAttribute("role")||e.classList.contains("endOfContent"))&&this.#sh.div.contains(e)){const{isMac:e}=X.platform;if(0!==t.button||t.ctrlKey&&e)return;this.#b.showAllEditors("highlight",!0,!0),this.#sh.div.classList.add("free"),this.toggleDrawing(),Cn.startHighlighting(this,"ltr"===this.#b.direction,{target:this.#sh.div,x:t.x,y:t.y}),this.#sh.div.addEventListener("pointerup",()=>{this.#sh.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#b._signal}),t.preventDefault()}}enableClick(){if(this.#Yl)return;this.#Yl=new AbortController;const t=this.#b.combinedSignal(this.#Yl);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.#Yl?.abort(),this.#Yl=null}attach(t){this.#Ql.set(t.id,t);const{annotationElementId:e}=t;e&&this.#b.isDeletedAnnotationElement(e)&&this.#b.removeDeletedAnnotationElement(t)}detach(t){this.#Ql.delete(t.id),this.#fa?.removePointerInTextLayer(t.contentDiv),!this.#Zl&&t.annotationElementId&&this.#b.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#b.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){t.parent!==this&&(t.parent&&t.annotationElementId&&(this.#b.addDeletedAnnotationElement(t),ie.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),t.parent?.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(t.parent!==this||!t.isAttachedToDOM){if(this.changeParent(t),this.#b.addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#th),this.#b.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!this.#Kl&&(t._focusEventsAllowed=!1,this.#Kl=setTimeout(()=>{this.#Kl=null,t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this.#b._signal}),e.focus())},0)),t._structTreeParentId=this.#fa?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||=this,t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),i=()=>{t.remove()};this.addCommands({cmd:e,undo:i,mustExec:!1})}getEditorByUID(t){for(const e of this.#Ql.values())if(e.uid===t)return e;return null}getNextId(){return this.#b.getId()}get#ch(){return Hn.#Y.get(this.#b.getMode())}combinedSignal(t){return this.#b.combinedSignal(t)}#dh(t){const e=this.#ch;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#ch?.canCreateNewEmptyEditor()}async pasteEditor(t,e){this.updateToolbar(t),await this.#b.updateMode(t.mode);const{offsetX:i,offsetY:s}=this.#uh(),n=this.getNextId(),r=this.#dh({parent:this,id:n,x:i,y:s,uiManager:this.#b,isCentered:!0,...e});r&&this.add(r)}async deserialize(t){return await(Hn.#Y.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#b))||null}createAndAddNewEditor(t,e,i={}){const s=this.getNextId(),n=this.#dh({parent:this,id:s,x:t.offsetX,y:t.offsetY,uiManager:this.#b,isCentered:e,...i});return n&&this.add(n),n}get boundingClientRect(){return this.div.getBoundingClientRect()}#uh(){const{x:t,y:e,width:i,height:s}=this.boundingClientRect,n=Math.max(0,t),r=Math.max(0,e),a=Math.min(window.innerWidth,t+i),o=Math.min(window.innerHeight,e+s),l=(n+a)/2-t,h=(r+o)/2-e,[c,d]=this.viewport.rotation%180===0?[l,h]:[h,l];return{offsetX:c,offsetY:d}}addNewEditor(t={}){this.createAndAddNewEditor(this.#uh(),!0,t)}setSelected(t){this.#b.setSelected(t)}toggleSelected(t){this.#b.toggleSelected(t)}unselect(t){this.#b.unselect(t)}pointerup(t){const{isMac:e}=X.platform;if(0!==t.button||t.ctrlKey&&e)return;if(t.target!==this.div)return;if(!this.#Jl)return;if(this.#Jl=!1,this.#ch?.isDrawer&&this.#ch.supportMultipleDrawings)return;if(!this.#ql)return void(this.#ql=!0);const i=this.#b.getMode();i!==p.STAMP&&i!==p.SIGNATURE?this.createAndAddNewEditor(t,!1):this.#b.unselectAll()}pointerdown(t){if(this.#b.getMode()===p.HIGHLIGHT&&this.enableTextSelection(),this.#Jl)return void(this.#Jl=!1);const{isMac:e}=X.platform;if(0!==t.button||t.ctrlKey&&e)return;if(t.target!==this.div)return;if(this.#Jl=!0,this.#ch?.isDrawer)return void this.startDrawingSession(t);const i=this.#b.getActive();this.#ql=!i||i.isEmpty()}startDrawingSession(t){if(this.div.focus({preventScroll:!0}),this.#eh)return void this.#ch.startDrawing(this,this.#b,!1,t);this.#b.setCurrentDrawingSession(this),this.#eh=new AbortController;const e=this.#b.combinedSignal(this.#eh);this.div.addEventListener("blur",({relatedTarget:t})=>{t&&!this.div.contains(t)&&(this.#ih=null,this.commitOrRemove())},{signal:e}),this.#ch.startDrawing(this,this.#b,!1,t)}pause(t){if(t){const{activeElement:t}=document;return void(this.div.contains(t)&&(this.#ih=t))}this.#ih&&setTimeout(()=>{this.#ih?.focus(),this.#ih=null},0)}endDrawingSession(t=!1){return this.#eh?(this.#b.setCurrentDrawingSession(null),this.#eh.abort(),this.#eh=null,this.#ih=null,this.#ch.endDrawing(t)):null}findNewParent(t,e,i){const s=this.#b.findParent(e,i);return null!==s&&s!==this&&(s.changeParent(t),!0)}commitOrRemove(){return!!this.#eh&&(this.endDrawingSession(),!0)}onScaleChanging(){this.#eh&&this.#ch.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#b.getActive()?.parent===this&&(this.#b.commitOrRemove(),this.#b.setActiveEditor(null)),this.#Kl&&(clearTimeout(this.#Kl),this.#Kl=null);for(const t of this.#Ql.values())this.#fa?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#Ql.clear(),this.#b.removeLayer(this)}#oh(){for(const t of this.#Ql.values())t.isEmpty()&&t.remove()}render({viewport:t}){this.viewport=t,Dt(this.div,t);for(const e of this.#b.getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){this.#b.commitOrRemove(),this.#oh();const e=this.viewport.rotation,i=t.rotation;if(this.viewport=t,Dt(this.div,{rotation:i}),e!==i)for(const s of this.#Ql.values())s.rotate(i)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#b.viewParameters.realScale}}class zn{#jr=null;#ph=new Map;#gh=new Map;static#E=0;constructor({pageIndex:t}){this.pageIndex=t}setParent(t){if(this.#jr){if(this.#jr!==t){if(this.#ph.size>0)for(const e of this.#ph.values())e.remove(),t.append(e);this.#jr=t}}else this.#jr=t}static get _svgFactory(){return F(this,"_svgFactory",new Bs)}static#mh(t,[e,i,s,n]){const{style:r}=t;r.top=100*i+"%",r.left=100*e+"%",r.width=100*s+"%",r.height=100*n+"%"}#fh(){const t=zn._svgFactory.create(1,1,!0);return this.#jr.append(t),t.setAttribute("aria-hidden",!0),t}#bh(t,e){const i=zn._svgFactory.createElement("clipPath");t.append(i);const s=`clip_${e}`;i.setAttribute("id",s),i.setAttribute("clipPathUnits","objectBoundingBox");const n=zn._svgFactory.createElement("use");return i.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),s}#vh(t,e){for(const[i,s]of Object.entries(e))null===s?t.removeAttribute(i):t.setAttribute(i,s)}draw(t,e=!1,i=!1){const s=zn.#E++,n=this.#fh(),r=zn._svgFactory.createElement("defs");n.append(r);const a=zn._svgFactory.createElement("path");r.append(a);const o=`path_p${this.pageIndex}_${s}`;a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke"),e&&this.#gh.set(s,a);const l=i?this.#bh(r,o):null,h=zn._svgFactory.createElement("use");return n.append(h),h.setAttribute("href",`#${o}`),this.updateProperties(n,t),this.#ph.set(s,n),{id:s,clipPathId:`url(#${l})`}}drawOutline(t,e){const i=zn.#E++,s=this.#fh(),n=zn._svgFactory.createElement("defs");s.append(n);const r=zn._svgFactory.createElement("path");n.append(r);const a=`path_p${this.pageIndex}_${i}`;let o;if(r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke"),e){const t=zn._svgFactory.createElement("mask");n.append(t),o=`mask_p${this.pageIndex}_${i}`,t.setAttribute("id",o),t.setAttribute("maskUnits","objectBoundingBox");const e=zn._svgFactory.createElement("rect");t.append(e),e.setAttribute("width","1"),e.setAttribute("height","1"),e.setAttribute("fill","white");const s=zn._svgFactory.createElement("use");t.append(s),s.setAttribute("href",`#${a}`),s.setAttribute("stroke","none"),s.setAttribute("fill","black"),s.setAttribute("fill-rule","nonzero"),s.classList.add("mask")}const l=zn._svgFactory.createElement("use");s.append(l),l.setAttribute("href",`#${a}`),o&&l.setAttribute("mask",`url(#${o})`);const h=l.cloneNode();return s.append(h),l.classList.add("mainOutline"),h.classList.add("secondaryOutline"),this.updateProperties(s,t),this.#ph.set(i,s),i}finalizeDraw(t,e){this.#gh.delete(t),this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;const{root:i,bbox:s,rootClass:n,path:r}=e,a="number"===typeof t?this.#ph.get(t):t;if(a){if(i&&this.#vh(a,i),s&&zn.#mh(a,s),n){const{classList:t}=a;for(const[e,i]of Object.entries(n))t.toggle(e,i)}if(r){const t=a.firstElementChild,e=t.firstElementChild;this.#vh(e,r)}}}updateParent(t,e){if(e===this)return;const i=this.#ph.get(t);i&&(e.#jr.append(i),this.#ph.delete(t),e.#ph.set(t,i))}remove(t){this.#gh.delete(t),null!==this.#jr&&(this.#ph.get(t).remove(),this.#ph.delete(t))}destroy(){this.#jr=null;for(const t of this.#ph.values())t.remove();this.#ph.clear(),this.#gh.clear()}}globalThis._pdfjsTestingUtils={HighlightOutliner:xn},globalThis.pdfjsLib={AbortException:z,AnnotationEditorLayer:Hn,AnnotationEditorParamsType:g,AnnotationEditorType:p,AnnotationEditorUIManager:Jt,AnnotationLayer:fn,AnnotationMode:d,AnnotationType:y,applyOpacity:Lt,build:Ps,ColorPicker:Is,createValidAbsoluteUrl:R,CSSConstants:Rt,DOMSVGFactory:Bs,DrawLayer:zn,FeatureTest:X,fetchData:dt,findContrastColor:jt,getDocument:ws,getFilenameFromUrl:ft,getPdfFilenameFromUrl:bt,getRGB:Et,getUuid:et,getXfaPageViewport:St,GlobalWorkerOptions:Oi,ImageKind:v,InvalidPDFException:U,isDataScheme:gt,isPdfFile:mt,isValidExplicitDest:_e,MathClamp:nt,noContextMenu:wt,normalizeUnicode:tt,OPS:x,OutputScale:Pt,PasswordResponses:S,PDFDataRangeTransport:xs,PDFDateString:_t,PDFWorker:Es,PermissionFlag:m,PixelsPerInch:ct,RenderingCancelledException:pt,renderRichText:Ht,ResponseException:j,setLayerDimensions:Dt,shadow:F,SignatureExtractor:On,stopEvent:At,SupportedImageMimeTypes:It,TextLayer:vs,TouchManager:ee,updateUrlHash:L,Util:K,VerbosityLevel:A,version:Ds,XfaLayer:lt};const $n=i.p+"pdf.worker.min.mjs";var Gn=function(){var t=this,e=t._self._c;return e("div",{staticClass:"pdf-elements-root",style:{width:t.width,height:t.height}},[t.pdfDocuments.length?e("div",{staticClass:"pages-container",style:{transform:`scale(${t.visualScale/t.scale})`,transformOrigin:"top center"}},t._l(t.pdfDocuments,function(i,s){return e("div",{key:s},t._l(i.pages,function(n,r){return e("div",{key:`${s}-${r}`,staticClass:"page-slot"},[e("div",{staticClass:"page-wrapper",on:{mousedown:function(e){return t.selectPage(s,r)},touchstart:function(e){return t.selectPage(s,r)}}},[e("div",{staticClass:"page-canvas",class:{"shadow-outline":s===t.selectedDocIndex&&r===t.selectedPageIndex}},[e("PDFPage",{ref:`page${s}-${r}`,refInFor:!0,attrs:{page:n,scale:t.scale},on:{onMeasure:function(e){return t.onMeasure(e,s,r)}}}),e("div",{staticClass:"overlay"},[t.isAddingMode&&t.previewPageDocIndex===s&&t.previewPageIndex===r&&t.previewElement&&t.previewVisible?e("div",{staticClass:"preview-element",style:{left:t.previewPosition.x*t.previewScale.x+"px",top:t.previewPosition.y*t.previewScale.y+"px",width:t.previewElement.width*t.previewScale.x+"px",height:t.previewElement.height*t.previewScale.y+"px"}},[t._t("custom",null,{object:t.previewElement,isSelected:!1})],2):t._e(),t._l(i.allObjects[r],function(i){return e("DraggableElement",{key:i.id,ref:`draggable${s}-${r}-${i.id}`,refInFor:!0,attrs:{object:i,"pages-scale":t.getRenderPageScale(s,r),"page-width":t.getPageWidth(s,r),"page-height":t.getPageHeight(s,r),"on-update":e=>t.updateObject(s,i.id,e),"on-delete":()=>t.deleteObject(s,i.id),"on-drag-start":(e,n,a,o)=>t.startDraggingElement(s,r,i,e,n,a,o),"on-drag-move":t.updateDraggingPosition,"on-drag-end":t.stopDraggingElement,"is-being-dragged-globally":t.isDraggingElement&&t.draggingObject&&t.draggingObject.id===i.id,"dragging-client-pos":t.draggingClientPosition,"current-doc-index":s,"current-page-index":r,"global-drag-doc-index":t.draggingDocIndex,"global-drag-page-index":t.draggingPageIndex,"show-selection-ui":t.showSelectionHandles&&!t.hideSelectionUI&&!1!==i.resizable,"show-default-actions":t.showElementActions&&!t.hideSelectionUI},scopedSlots:t._u([{key:"default",fn:function(e){return[t._t(e.object.type?`element-${e.object.type}`:"custom",function(){return[t._t("custom",null,{object:e.object,onDelete:e.onDelete,onResize:e.onResize})]},{object:e.object,onDelete:e.onDelete,onResize:e.onResize})]}},{key:"actions",fn:function(e){return[t._t("actions",null,{object:e.object,onDelete:e.onDelete})]}}],null,!0)})})],2)],1),t.showPageFooter?e("div",{staticClass:"page-footer"},[e("span",[t._v(t._s(i.name))]),e("span",[t._v(t._s(t.formatPageNumber(r+1,i.numPages)))])]):t._e()])])}),0)}),0):t._e(),t.isDraggingElement&&t.draggingObject?e("div",{staticClass:"drag-portal",style:{position:"fixed",left:`${t.draggingClientPosition.x}px`,top:`${t.draggingClientPosition.y}px`,width:t.draggingObject.width*t.draggingScale+"px",height:t.draggingObject.height*t.draggingScale+"px",pointerEvents:"none"}},[t._t(t.draggingObject.type?`element-${t.draggingObject.type}`:"custom",function(){return[t._t("custom",null,{object:t.draggingObject,isSelected:!1})]},{object:t.draggingObject,isSelected:!1})],2):t._e()])},Wn=[];i(4114),i(8111),i(2489),i(116),i(7588),i(1701);function Vn(t,e=100,i={}){if("function"!==typeof t)throw new TypeError(`Expected the first parameter to be a function, got \`${typeof t}\`.`);if(e<0)throw new RangeError("`wait` must not be negative.");if("boolean"===typeof i)throw new TypeError("The `options` parameter must be an object, not a boolean. Use `{immediate: true}` instead.");const{immediate:s}=i;let n,r,a,o,l;function h(){const e=n,i=r;return n=void 0,r=void 0,l=t.apply(e,i),l}function c(){const t=Date.now()-o;t<e&&t>=0?a=setTimeout(c,e-t):(a=void 0,s||(l=h()))}const d=function(...t){if(n&&this!==n&&Object.getPrototypeOf(this)===Object.getPrototypeOf(n))throw new Error("Debounced method called with different contexts of the same prototype.");n=this,r=t,o=Date.now();const i=s&&!a;if(a||(a=setTimeout(c,e)),i)return l=h(),l};return Object.defineProperty(d,"isPending",{get(){return void 0!==a}}),d.clear=()=>{a&&(clearTimeout(a),a=void 0,n=void 0,r=void 0)},d.flush=()=>{a&&d.trigger()},d.trigger=()=>{l=h(),d.clear()},d}var qn=function(){var t=this,e=t._self._c;return e("canvas",{ref:"canvas"})},Xn=[];const Yn={name:"PDFPage",props:{page:{type:Promise,required:!0},scale:{type:Number,default:1}},data(){return{dynamicScale:this.scale,isRendering:!1,boundMeasure:null}},watch:{scale(t){this.dynamicScale=t,this.render()}},mounted(){this.boundMeasure=this.measure.bind(this),window.addEventListener("resize",this.boundMeasure),this.render()},beforeUnmount(){this.boundMeasure&&window.removeEventListener("resize",this.boundMeasure)},methods:{getCanvasMeasurement(){return{canvasWidth:this.$refs.canvas.width,canvasHeight:this.$refs.canvas.height}},measure(){this.$emit("onMeasure",{scale:this.dynamicScale})},async render(){if(!this.isRendering){this.isRendering=!0;try{const t=await this.page,e=this.$refs.canvas,i=e.getContext("2d"),s=t.getViewport({scale:this.dynamicScale});e.width=s.width,e.height=s.height,await t.render({canvasContext:i,viewport:s}).promise,this.measure()}finally{this.isRendering=!1}}}}},Kn=Yn;function Qn(t,e,i,s,n,r,a,o){var l,h="function"===typeof t?t.options:t;if(e&&(h.render=e,h.staticRenderFns=i,h._compiled=!0),s&&(h.functional=!0),r&&(h._scopeId="data-v-"+r),a?(l=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"===typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),n&&n.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(a)},h._ssrRegister=l):n&&(l=o?function(){n.call(this,(h.functional?this.parent:this).$root.$options.shadowRoot)}:n),l)if(h.functional){h._injectStyles=l;var c=h.render;h.render=function(t,e){return l.call(e),c(t,e)}}else{var d=h.beforeCreate;h.beforeCreate=d?[].concat(d,l):[l]}return{exports:t,options:h}}var Jn=Qn(Kn,qn,Xn,!1,null,"2c9e224a",null);const Zn=Jn.exports;var tr=function(){var t=this,e=t._self._c;return e("div",{staticClass:"draggable-wrapper"},[t.isSelected&&!t.isBeingDraggedGlobally&&t.showSelectionUi&&t.showDefaultActions?e("div",{staticClass:"actions-toolbar",style:t.toolbarStyle},[t._t("actions",function(){return[e("button",{staticClass:"action-btn",attrs:{type:"button",title:"Delete"},on:{click:function(e){return e.stopPropagation(),t.onDelete.apply(null,arguments)}}},[e("svg",{attrs:{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor"}},[e("path",{attrs:{d:"M6.5 1h3a.5.5 0 0 1 .5.5v1H6v-1a.5.5 0 0 1 .5-.5ZM11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3A1.5 1.5 0 0 0 5 1.5v1H2.5a.5.5 0 0 0 0 1h.5v10.5A1.5 1.5 0 0 0 4.5 15h7a1.5 1.5 0 0 0 1.5-1.5V3.5h.5a.5.5 0 0 0 0-1H11Zm1 1v10.5a.5.5 0 0 1-.5.5h-7a.5.5 0 0 1-.5-.5V3.5h8Z"}})])])]},{object:t.object,onDelete:t.onDelete})],2):t._e(),e("div",{staticClass:"draggable-element",class:{selected:t.isSelected&&t.showSelectionUi},style:[t.elementStyle,t.dragElementStyle],attrs:{draggable:"false"},on:{dragstart:function(t){t.preventDefault()},mousedown:t.handleElementClick,touchstart:t.handleElementClick}},[t._t("default",null,{object:t.object,isSelected:t.isSelected,onDelete:t.onDelete,onResize:t.startResizeFromSlot}),t.isSelected&&t.showSelectionUi?t._l(t.resizeDirections,function(i){return e("button",{key:i,staticClass:"resize-handle",class:`handle-${i}`,attrs:{type:"button"},on:{mousedown:function(e){return e.stopPropagation(),e.preventDefault(),t.startResize(i,e)},touchstart:function(e){return e.stopPropagation(),e.preventDefault(),t.startResize(i,e)}}})}):t._e()],2)])},er=[];const ir={name:"DraggableElement",props:{object:{type:Object,required:!0},pagesScale:{type:Number,default:1},pageWidth:{type:Number,required:!0},pageHeight:{type:Number,required:!0},onUpdate:{type:Function,default:()=>{}},onDelete:{type:Function,default:()=>{}},onDragStart:{type:Function,default:()=>{}},onDragMove:{type:Function,default:()=>{}},onDragEnd:{type:Function,default:()=>{}},isBeingDraggedGlobally:{type:Boolean,default:!1},draggingClientPos:{type:Object,default:()=>({x:0,y:0})},currentDocIndex:{type:Number,default:-1},currentPageIndex:{type:Number,default:-1},globalDragDocIndex:{type:Number,default:-1},globalDragPageIndex:{type:Number,default:-1},showSelectionUi:{type:Boolean,default:!0},showDefaultActions:{type:Boolean,default:!0}},data(){return{isSelected:!1,mode:"idle",direction:"",startX:0,startY:0,startLeft:0,startTop:0,startWidth:0,startHeight:0,offsetX:0,offsetY:0,resizeOffsetX:0,resizeOffsetY:0,resizeOffsetW:0,resizeOffsetH:0,aspectRatio:1,lastMouseX:0,lastMouseY:0,pointerOffsetDoc:{x:0,y:0},currentPageRect:null,rafId:null}},computed:{resizeDirections(){return["top-left","top-right","bottom-left","bottom-right"]},elementStyle(){const t=this.pagesScale||1,e=this.object.x+this.offsetX+this.resizeOffsetX,i=this.object.y+this.offsetY+this.resizeOffsetY,s=this.object.width+this.resizeOffsetW,n=this.object.height+this.resizeOffsetH;return{left:e*t+"px",top:i*t+"px",width:s*t+"px",height:n*t+"px"}},toolbarStyle(){const t=this.pagesScale||1,e=this.object.x+this.offsetX+this.resizeOffsetX,i=this.object.y+this.offsetY+this.resizeOffsetY,s=this.object.width+this.resizeOffsetW;return{left:(e+s/2)*t+"px",top:(i-48)*t+"px",transform:"translateX(-50%)"}},dragElementStyle(){return this.isBeingDraggedGlobally&&this.draggingClientPos?{opacity:0,pointerEvents:"none"}:{}}},mounted(){this.handleClickOutside=this.handleClickOutside.bind(this),this.boundHandleMove=this.handleMove.bind(this),this.boundStopInteraction=this.stopInteraction.bind(this),document.addEventListener("mousedown",this.handleClickOutside),document.addEventListener("touchstart",this.handleClickOutside)},beforeUnmount(){document.removeEventListener("mousedown",this.handleClickOutside),document.removeEventListener("touchstart",this.handleClickOutside),window.removeEventListener("mousemove",this.boundHandleMove),window.removeEventListener("mouseup",this.boundStopInteraction),window.removeEventListener("touchmove",this.boundHandleMove),window.removeEventListener("touchend",this.boundStopInteraction),this.rafId&&cancelAnimationFrame(this.rafId)},methods:{handleElementClick(t){t.target.closest(".delete-handle")||t.target.closest("[data-stop-drag]")||t.target.closest(".actions-toolbar")||(t.preventDefault(),this.isSelected=!0,this.startDrag(t))},handleClickOutside(t){this.$el&&!this.$el.contains(t.target)&&(this.isSelected=!1)},startResizeFromSlot(t,e){t&&e&&this.startResize(t,e)},startDrag(t){if(t.target.classList.contains("delete"))return;if(t.target.classList.contains("resize-handle"))return;this.mode="drag",this.startX=t.type.includes("touch")?t.touches[0].clientX:t.clientX,this.startY=t.type.includes("touch")?t.touches[0].clientY:t.clientY,this.startLeft=this.object.x,this.startTop=this.object.y,this.offsetX=0,this.offsetY=0,this.resetResizeOffsets();const e=this.$el.querySelector(".draggable-element").getBoundingClientRect();this.pointerOffsetDoc.x=this.startX-e.left,this.pointerOffsetDoc.y=this.startY-e.top;const i=this.capturePageRect();this.currentPageRect=i;let s={x:0,y:0};if(i){const t=i.left+this.object.x*this.pagesScale,n=i.top+this.object.y*this.pagesScale;s={x:e.left-t,y:e.top-n}}this.onDragStart(this.startX,this.startY,{...this.pointerOffsetDoc},s),window.addEventListener("mousemove",this.boundHandleMove),window.addEventListener("mouseup",this.boundStopInteraction),window.addEventListener("touchmove",this.boundHandleMove),window.addEventListener("touchend",this.boundStopInteraction)},startResize(t,e){this.mode="resize",this.direction=t,this.startX=e.type.includes("touch")?e.touches[0].clientX:e.clientX,this.startY=e.type.includes("touch")?e.touches[0].clientY:e.clientY,this.startLeft=this.object.x,this.startTop=this.object.y,this.startWidth=this.object.width,this.startHeight=this.object.height,this.aspectRatio=this.startWidth/this.startHeight,this.offsetX=0,this.offsetY=0,this.resetResizeOffsets(),window.addEventListener("mousemove",this.boundHandleMove),window.addEventListener("mouseup",this.boundStopInteraction),window.addEventListener("touchmove",this.boundHandleMove),window.addEventListener("touchend",this.boundStopInteraction)},handleMove(t){"idle"!==this.mode&&(t.preventDefault(),this.rafId||(this.rafId=requestAnimationFrame(()=>{const e=t.type.includes("touch")?t.touches[0]?.clientX:t.clientX,i=t.type.includes("touch")?t.touches[0]?.clientY:t.clientY;if(void 0===e||void 0===i)return;this.lastMouseX=e,this.lastMouseY=i;const s=(e-this.startX)/this.pagesScale,n=(i-this.startY)/this.pagesScale;if("drag"===this.mode){const t=this.currentPageRect;if(t){const s=e-this.pointerOffsetDoc.x,n=i-this.pointerOffsetDoc.y,r=(s-t.left)/this.pagesScale,a=(n-t.top)/this.pagesScale;this.offsetX=r-this.object.x,this.offsetY=a-this.object.y}else this.offsetX=s,this.offsetY=n;return this.onDragMove(e,i),this.isBeingDraggedGlobally&&this.onUpdate({_globalDrag:!0,_mouseX:e,_mouseY:i}),void(this.rafId=null)}const r=16;let a=this.startWidth,o=this.startHeight,l=this.startLeft,h=this.startTop;const c=this.direction.includes("right")?s:this.direction.includes("left")?-s:0;if(a=this.startWidth+c,a<r&&(a=r),o=a/this.aspectRatio,this.direction.includes("left")&&(l=this.startLeft+(this.startWidth-a),l<0)){const t=-l;l=0,a-=t,o=a/this.aspectRatio}if(this.direction.includes("top")&&(h=this.startTop+(this.startHeight-o),h<0)){const t=-h;h=0,o-=t,a=o*this.aspectRatio,this.direction.includes("left")&&(l=this.startLeft+(this.startWidth-a))}if(l+a>this.pageWidth){const t=l+a-this.pageWidth;a-=t,o=a/this.aspectRatio}if(h+o>this.pageHeight){const t=h+o-this.pageHeight;o-=t,a=o*this.aspectRatio,this.direction.includes("left")&&(l=this.startLeft+(this.startWidth-a))}this.resizeOffsetX=l-this.object.x,this.resizeOffsetY=h-this.object.y,this.resizeOffsetW=a-this.object.width,this.resizeOffsetH=o-this.object.height,this.rafId=null})))},stopInteraction(){if("idle"!==this.mode){if("drag"===this.mode&&(0!==this.offsetX||0!==this.offsetY))if(this.isBeingDraggedGlobally)this.onUpdate({_globalDrag:!0,_mouseX:this.lastMouseX,_mouseY:this.lastMouseY});else{const t=Math.max(0,Math.min(this.object.x+this.offsetX,this.pageWidth-this.object.width)),e=Math.max(0,Math.min(this.object.y+this.offsetY,this.pageHeight-this.object.height));this.onUpdate({x:t,y:e})}if("resize"===this.mode&&(0!==this.resizeOffsetW||0!==this.resizeOffsetH||0!==this.resizeOffsetX||0!==this.resizeOffsetY)){const t=this.object.x+this.resizeOffsetX,e=this.object.y+this.resizeOffsetY,i=this.object.width+this.resizeOffsetW,s=this.object.height+this.resizeOffsetH;this.onUpdate({x:t,y:e,width:i,height:s})}this.resetOffsets(),this.onDragEnd(),window.removeEventListener("mousemove",this.boundHandleMove),window.removeEventListener("mouseup",this.boundStopInteraction),window.removeEventListener("touchmove",this.boundHandleMove),window.removeEventListener("touchend",this.boundStopInteraction)}},capturePageRect(){const t=this.$el.closest(".page-wrapper");if(!t)return null;const e=t.querySelector("canvas");return e?e.getBoundingClientRect():null},resetResizeOffsets(){this.resizeOffsetX=0,this.resizeOffsetY=0,this.resizeOffsetW=0,this.resizeOffsetH=0},resetOffsets(){this.mode="idle",this.offsetX=0,this.offsetY=0,this.resetResizeOffsets(),this.pointerOffsetDoc={x:0,y:0},this.currentPageRect=null}}},sr=ir;var nr=Qn(sr,tr,er,!1,null,"55db89ce",null);const rr=nr.exports;function ar(t){return new Promise((e,i)=>{const s=new FileReader;s.onload=()=>e(s.result),s.onerror=i,s.readAsArrayBuffer(t)})}function or(t){return ws(t).promise}Oi.workerSrc=$n;const lr={name:"PDFElements",components:{PDFPage:Zn,DraggableElement:rr},props:{width:{type:String,default:"100%"},height:{type:String,default:"100%"},initFiles:{type:Array,default:()=>[]},initFileNames:{type:Array,default:()=>[]},initialScale:{type:Number,default:1},showPageFooter:{type:Boolean,default:!0},hideSelectionUI:{type:Boolean,default:!1},showSelectionHandles:{type:Boolean,default:!0},showElementActions:{type:Boolean,default:!0},pageCountFormat:{type:String,default:"{currentPage} of {totalPages}"},autoFitZoom:{type:Boolean,default:!1}},data(){return{scale:this.initialScale,pdfDocuments:[],selectedDocIndex:-1,selectedPageIndex:-1,isAddingMode:!1,previewElement:null,previewPosition:{x:0,y:0},previewScale:{x:1,y:1},previewPageDocIndex:-1,previewPageIndex:-1,previewVisible:!1,pagesBoundingRects:{},isDraggingElement:!1,draggingObject:null,draggingDocIndex:-1,draggingPageIndex:-1,draggingClientPosition:{x:0,y:0},draggingScale:1,draggingInitialMouseOffset:{x:0,y:0},draggingElementShift:{x:0,y:0},lastMouseClientPos:{x:0,y:0},viewportRafId:0,objectIndexCache:{},zoomRafId:null,boundHandleWheel:null,debouncedApplyZoom:null,visualScale:this.initialScale}},mounted(){this.boundHandleWheel=this.handleWheel.bind(this),this.debouncedApplyZoom=Vn(this.commitZoom,150),this.init(),document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("touchmove",this.handleMouseMove,{passive:!0}),document.addEventListener("mouseup",this.finishAdding),document.addEventListener("touchend",this.finishAdding),document.addEventListener("keydown",this.handleKeyDown),window.addEventListener("scroll",this.onViewportScroll,{passive:!0}),window.addEventListener("resize",this.onViewportScroll),this.$el?.addEventListener("scroll",this.onViewportScroll,{passive:!0}),this.$el?.addEventListener("wheel",this.boundHandleWheel,{passive:!1}),this.autoFitZoom&&window.addEventListener("resize",this.adjustZoomToFit)},beforeUnmount(){this.zoomRafId&&cancelAnimationFrame(this.zoomRafId),this.debouncedApplyZoom?.clear?.(),this.boundHandleWheel&&this.$el?.removeEventListener("wheel",this.boundHandleWheel),document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("touchmove",this.handleMouseMove),document.removeEventListener("mouseup",this.finishAdding),document.removeEventListener("touchend",this.finishAdding),document.removeEventListener("keydown",this.handleKeyDown),window.removeEventListener("scroll",this.onViewportScroll),window.removeEventListener("resize",this.onViewportScroll),this.$el?.removeEventListener("scroll",this.onViewportScroll),this.autoFitZoom&&window.removeEventListener("resize",this.adjustZoomToFit),this.viewportRafId&&(window.cancelAnimationFrame(this.viewportRafId),this.viewportRafId=0)},methods:{async init(){if(!this.initFiles||0===this.initFiles.length)return;const t=[];for(let e=0;e<this.initFiles.length;e++){const i=this.initFiles[e],s=this.initFileNames[e]||`document-${e+1}.pdf`;let n;if(i instanceof Blob){const t=await ar(i);n=await or({data:t})}else n=await or(i);const r=[];for(let t=1;t<=n.numPages;t++)r.push(n.getPage(t));t.push({name:s,file:i,pdfDoc:n,numPages:n.numPages,pages:r,pagesScale:Array(n.numPages).fill(this.scale),allObjects:Array(n.numPages).fill(0).map(()=>[])})}this.pdfDocuments=t,t.length&&(this.selectedDocIndex=0,this.selectedPageIndex=0,this.$emit("pdf-elements:end-init",{docsCount:t.length}),this.$nextTick(()=>{this.autoFitZoom&&this.adjustZoomToFit()}))},selectPage(t,e){this.selectedDocIndex=t,this.selectedPageIndex=e},startDraggingElement(t,e,i,s,n,r,a){this.isDraggingElement=!0,this.draggingObject={...i},this.draggingDocIndex=t,this.draggingPageIndex=e,this.draggingScale=this.getDisplayedPageScale(t,e),this.lastMouseClientPos.x=s,this.lastMouseClientPos.y=n,this.draggingElementShift=a&&"number"===typeof a.x&&"number"===typeof a.y?a:{x:0,y:0};const o=`${t}-${e}`;this.pagesBoundingRects[o]||this.cachePageBounds();const l=this.pagesBoundingRects[o]?.rect;if(r&&"number"===typeof r.x&&"number"===typeof r.y)this.draggingInitialMouseOffset.x=r.x,this.draggingInitialMouseOffset.y=r.y,this.draggingClientPosition.x=s-this.draggingInitialMouseOffset.x,this.draggingClientPosition.y=n-this.draggingInitialMouseOffset.y;else if(l){const t=l.left+i.x*this.draggingScale,e=l.top+i.y*this.draggingScale;this.draggingInitialMouseOffset.x=s-t,this.draggingInitialMouseOffset.y=n-e,this.draggingClientPosition.x=s-this.draggingInitialMouseOffset.x,this.draggingClientPosition.y=n-this.draggingInitialMouseOffset.y}this.cachePageBounds()},updateDraggingPosition(t,e){this.isDraggingElement&&(this.lastMouseClientPos.x=t,this.lastMouseClientPos.y=e,this.draggingClientPosition.x=t-this.draggingInitialMouseOffset.x,this.draggingClientPosition.y=e-this.draggingInitialMouseOffset.y)},stopDraggingElement(){if(this.draggingObject){const t=this.draggingObject.id,e=this.draggingDocIndex,i=this.checkAndMoveObjectPage(this.draggingDocIndex,t,this.lastMouseClientPos.x,this.lastMouseClientPos.y);void 0!==i&&this.$nextTick(()=>{this.selectPage(e,i);const s=`draggable${e}-${i}-${t}`,n=this.$refs[s];n&&Array.isArray(n)&&n[0]&&(n[0].isSelected=!0)})}this.isDraggingElement=!1,this.draggingObject=null,this.draggingDocIndex=-1,this.draggingPageIndex=-1,this.draggingElementShift={x:0,y:0}},startAddingElement(t){this.pdfDocuments.length&&(this.isAddingMode=!0,this.previewElement={...t},this.previewPageDocIndex=0,this.previewPageIndex=0,this.previewVisible=!1,this.previewScale={x:1,y:1},this.cachePageBounds())},cachePageBounds(){this.pagesBoundingRects={};for(let t=0;t<this.pdfDocuments.length;t++)for(let e=0;e<this.pdfDocuments[t].pages.length;e++){const i=this.getPageCanvasElement(t,e);if(!i)continue;const s=i.getBoundingClientRect();this.pagesBoundingRects[`${t}-${e}`]={docIndex:t,pageIndex:e,rect:s}}},getDisplayedPageScale(t,e){const i=this.pdfDocuments[t];if(!i)return 1;const s=i.pagesScale[e]||1,n=this.visualScale&&this.scale?this.visualScale/this.scale:1;return s*n},getRenderPageScale(t,e){const i=this.pdfDocuments[t];return i&&i.pagesScale[e]||1},getPageComponent(t,e){const i=this.$refs[`page${t}-${e}`];return i&&Array.isArray(i)&&i[0]?i[0]:null},getPageCanvasElement(t,e){const i=this.getPageComponent(t,e);return i?i.$el||i:null},onViewportScroll(){this.viewportRafId||(this.viewportRafId=window.requestAnimationFrame(()=>{(this.isAddingMode||this.isDraggingElement)&&this.cachePageBounds(),this.viewportRafId=0}))},handleMouseMove(t){if(!this.isAddingMode||!this.previewElement)return;const e=t.type.includes("touch")?t.touches[0].clientX:t.clientX,i=t.type.includes("touch")?t.touches[0].clientY:t.clientY;let s=!1;for(const n in this.pagesBoundingRects){const{docIndex:t,pageIndex:r,rect:a}=this.pagesBoundingRects[n];if(e>=a.left&&e<=a.right&&i>=a.top&&i<=a.bottom){this.previewPageDocIndex=t,this.previewPageIndex=r,s=!0;const n=this.getPageCanvasElement(t,r),o=this.pdfDocuments[t]?.pagesScale?.[r]||1,l=n?.offsetWidth||a.width,h=n?.offsetHeight||a.height,c=l?a.width/l:1,d=h?a.height/h:1,u=(e-a.left)/c/o,p=(i-a.top)/d/o,g=l/o,m=h/o;this.previewScale.x=o*c,this.previewScale.y=o*d;let f=u-this.previewElement.width/2,b=p-this.previewElement.height/2;f=Math.max(0,Math.min(f,g-this.previewElement.width)),b=Math.max(0,Math.min(b,m-this.previewElement.height)),this.previewPosition.x=f,this.previewPosition.y=b,this.previewVisible=!0;break}}s||(this.previewVisible=!1,this.previewScale={x:1,y:1})},handleKeyDown(t){"Escape"===t.key&&this.isAddingMode&&this.cancelAdding()},handleWheel(t){if(!t.ctrlKey)return;t.preventDefault();const e=1-.002*t.deltaY,i=Math.max(.5,Math.min(3,this.visualScale*e));this.visualScale=i,this.debouncedApplyZoom()},commitZoom(){const t=this.visualScale;this.scale=t,this.pdfDocuments.forEach(t=>{t.pagesScale=t.pagesScale.map(()=>this.scale)}),this.cachePageBounds()},finishAdding(){if(!this.isAddingMode||!this.previewElement)return;if(!this.previewVisible)return;const t={...this.previewElement,id:`obj-${Date.now()}`,x:Math.round(this.previewPosition.x),y:Math.round(this.previewPosition.y)},e=this.pdfDocuments[this.previewPageDocIndex],i=this.getPageWidth(this.previewPageDocIndex,this.previewPageIndex),s=this.getPageHeight(this.previewPageDocIndex,this.previewPageIndex);if(t.x<0||t.y<0||t.x+t.width>i||t.y+t.height>s)return void this.cancelAdding();e.allObjects[this.previewPageIndex].push(t);const n=this.previewPageIndex,r=this.previewPageDocIndex,a=t.id;this.cancelAdding(),this.$nextTick(()=>{const t=`draggable${r}-${n}-${a}`,e=this.$refs[t];e&&Array.isArray(e)&&e[0]&&(e[0].isSelected=!0)})},cancelAdding(){this.isAddingMode=!1,this.previewElement=null,this.previewVisible=!1},addObjectToPage(t,e=this.selectedPageIndex,i=this.selectedDocIndex){if(i<0||i>=this.pdfDocuments.length)return!1;if(e<0||e>=this.pdfDocuments[i].pages.length)return!1;const s=this.pdfDocuments[i],n=this.getPageComponent(i,e);if(!n)return!1;const r=this.getPageWidth(i,e),a=this.getPageHeight(i,e);return!(t.x<0||t.y<0||t.x+t.width>r||t.y+t.height>a)&&(s.allObjects=s.allObjects.map((i,s)=>s===e?[...i,t]:i),!0)},getAllObjects(t=this.selectedDocIndex){if(t<0||t>=this.pdfDocuments.length)return[];const e=this.pdfDocuments[t],i=this.scale||1,s=[];return e.allObjects.forEach((e,n)=>{const r=this.getPageComponent(t,n);if(!r)return;const a=r.getCanvasMeasurement(),o=a.canvasHeight/i;e.forEach(t=>{s.push({...t,pageIndex:n,pageNumber:n+1,scale:i,normalizedCoordinates:{llx:parseInt(t.x,10),lly:parseInt(o-t.y,10),ury:parseInt(o-t.y-t.height,10)}})})}),s},updateObject(t,e,i){if(t<0||t>=this.pdfDocuments.length)return;const s=this.pdfDocuments[t],n=`${t}-${e}`;let r=this.objectIndexCache[n];if(void 0===r&&s.allObjects.forEach((t,i)=>{t.find(t=>t.id===e)&&(r=i,this.objectIndexCache[n]=i)}),void 0===r)return;const a=s.allObjects[r]?.find(t=>t.id===e);if(a){if(i._globalDrag&&void 0!==i._mouseX&&void 0!==i._mouseY){const n=i._mouseX,a=i._mouseY;this.pagesBoundingRects&&0!==Object.keys(this.pagesBoundingRects).length||this.cachePageBounds();const o=this.pagesBoundingRects[`${t}-${r}`]?.rect;if(o){const i=this.getDisplayedPageScale(t,r),l=(n-o.left-this.draggingElementShift.x)/i-this.draggingInitialMouseOffset.x/i,h=(a-o.top-this.draggingElementShift.y)/i-this.draggingInitialMouseOffset.y/i;s.allObjects[r]=s.allObjects[r].map(t=>t.id===e?{...t,x:l,y:h}:t)}return}if(void 0!==i.x||void 0!==i.y){const n=void 0!==i.x?i.x:a.x,o=void 0!==i.y?i.y:a.y,l=void 0!==i.width?i.width:a.width,h=void 0!==i.height?i.height:a.height;let c=r,d=0;for(let e=0;e<s.pages.length;e++){const i=this.getPageWidth(t,e),s=this.getPageHeight(t,e),r=Math.max(0,n),a=Math.max(0,o),u=Math.min(i,n+l),p=Math.min(s,o+h);if(u>r&&p>a){const t=(u-r)*(p-a);t>d&&(d=t,c=e)}}if(c!==r){const d=this.getPageWidth(t,c),u=this.getPageHeight(t,c),p=Math.max(0,Math.min(n,d-l)),g=Math.max(0,Math.min(o,u-h));s.allObjects[r]=s.allObjects[r].filter(t=>t.id!==e);const m={...a,...i,x:p,y:g};return s.allObjects[c].push(m),void(this.objectIndexCache[`${t}-${e}`]=c)}const u=this.getPageWidth(t,r),p=this.getPageHeight(t,r);if(n<0||o<0||n+l>u||o+h>p)return}s.allObjects=s.allObjects.map(t=>t.map(t=>t.id===e?{...t,...i}:t))}},deleteObject(t,e){if(t<0||t>=this.pdfDocuments.length)return;const i=this.pdfDocuments[t];i.allObjects=i.allObjects.map(t=>t.filter(t=>t.id!==e)),delete this.objectIndexCache[`${t}-${e}`]},checkAndMoveObjectPage(t,e,i,s){if(t<0||t>=this.pdfDocuments.length)return;const n=this.pdfDocuments[t],r=`${t}-${e}`;let a=this.objectIndexCache[r];if(void 0===a&&n.allObjects.forEach((t,i)=>{t.find(t=>t.id===e)&&(a=i,this.objectIndexCache[r]=i)}),void 0===a)return;const o=n.allObjects[a]?.find(t=>t.id===e);if(!o)return a;let l=a;for(const b in this.pagesBoundingRects){const{docIndex:e,pageIndex:n,rect:r}=this.pagesBoundingRects[b];if(e===t&&i>=r.left&&i<=r.right&&s>=r.top&&s<=r.bottom){l=n;break}}const h=this.pagesBoundingRects[`${t}-${l}`]?.rect;if(!h)return a;const c=this.getDisplayedPageScale(t,l),d=(i-h.left-this.draggingElementShift.x)/c-this.draggingInitialMouseOffset.x/c,u=(s-h.top-this.draggingElementShift.y)/c-this.draggingInitialMouseOffset.y/c,p=this.getPageWidth(t,l),g=this.getPageHeight(t,l),m=Math.max(0,Math.min(d,p-o.width)),f=Math.max(0,Math.min(u,g-o.height));return l!==a?(n.allObjects[a]=n.allObjects[a].filter(t=>t.id!==e),n.allObjects[l].push({...o,x:m,y:f}),this.objectIndexCache[r]=l):m===o.x&&f===o.y||(n.allObjects[a]=n.allObjects[a].map(t=>t.id===e?{...t,x:m,y:f}:t)),l},onMeasure(t,e,i){e<0||e>=this.pdfDocuments.length||(this.pdfDocuments[e].pagesScale[i]=t.scale,this.cachePageBounds())},formatPageNumber(t,e){return this.pageCountFormat.replace("{currentPage}",t).replace("{totalPages}",e)},getPageWidth(t,e){const i=this.getPageComponent(t,e);if(!i)return 0;const s=this.pdfDocuments[t],n=s.pagesScale[e]||1;return i.getCanvasMeasurement().canvasWidth/n},getPageHeight(t,e){const i=this.getPageComponent(t,e);if(!i)return 0;const s=this.pdfDocuments[t],n=s.pagesScale[e]||1;return i.getCanvasMeasurement().canvasHeight/n},calculateOptimalScale(t){const e=this.$el?.clientWidth||0;if(!e||!t)return 1;const i=e-40;return Math.max(.1,Math.min(2,i/t))},adjustZoomToFit(){if(!this.autoFitZoom||!this.pdfDocuments.length)return;const t=this.$el?.querySelectorAll("canvas");if(!t?.length)return;const e=Math.max(...Array.from(t).map(t=>t.width/(this.scale||1))),i=this.calculateOptimalScale(e);Math.abs(i-this.scale)>.01&&(this.scale=i,this.visualScale=i,this.pdfDocuments.forEach(t=>{t.pagesScale=t.pagesScale.map(()=>this.scale)}),this.cachePageBounds())}}},hr=lr;var cr=Qn(hr,Gn,Wn,!1,null,"00b0fcba",null);const dr=cr.exports;Oi.workerSrc=$n,dr.install=function(t){dr.install.installed||t.component(dr.name,dr)},"undefined"!==typeof window&&window.Vue&&dr.install(window.Vue);const ur=dr,pr=ur;return s=s["default"],s})());
22
+ */var a={};(()=>{a.d=(t,e)=>{for(var i in e)a.o(e,i)&&!a.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})}})(),(()=>{a.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)})();const o="object"===typeof process&&process+""==="[object process]"&&!process.versions.nw&&!(process.versions.electron&&process.type&&"browser"!==process.type),l=[.001,0,0,.001,0,0],h=1.35,c={ANY:1,DISPLAY:2,PRINT:4,SAVE:8,ANNOTATIONS_FORMS:16,ANNOTATIONS_STORAGE:32,ANNOTATIONS_DISABLE:64,IS_EDITING:128,OPLIST:256},d={DISABLE:0,ENABLE:1,ENABLE_FORMS:2,ENABLE_STORAGE:3},u="pdfjs_internal_editor_",p={DISABLE:-1,NONE:0,FREETEXT:3,HIGHLIGHT:9,STAMP:13,INK:15,POPUP:16,SIGNATURE:101,COMMENT:102},g={RESIZE:1,CREATE:2,FREETEXT_SIZE:11,FREETEXT_COLOR:12,FREETEXT_OPACITY:13,INK_COLOR:21,INK_THICKNESS:22,INK_OPACITY:23,HIGHLIGHT_COLOR:31,HIGHLIGHT_THICKNESS:32,HIGHLIGHT_FREE:33,HIGHLIGHT_SHOW_ALL:34,DRAW_STEP:41},m={PRINT:4,MODIFY_CONTENTS:8,COPY:16,MODIFY_ANNOTATIONS:32,FILL_INTERACTIVE_FORMS:256,COPY_FOR_ACCESSIBILITY:512,ASSEMBLE:1024,PRINT_HIGH_QUALITY:2048},f={TRIANGLES:1,LATTICE:2,PATCH:3},b={FILL:0,STROKE:1,FILL_STROKE:2,INVISIBLE:3,FILL_ADD_TO_PATH:4,STROKE_ADD_TO_PATH:5,FILL_STROKE_ADD_TO_PATH:6,ADD_TO_PATH:7,FILL_STROKE_MASK:3,ADD_TO_PATH_FLAG:4},v={GRAYSCALE_1BPP:1,RGB_24BPP:2,RGBA_32BPP:3},y={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},w={SOLID:1,DASHED:2,BEVELED:3,INSET:4,UNDERLINE:5},A={ERRORS:0,WARNINGS:1,INFOS:5},x={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},_={moveTo:0,lineTo:1,curveTo:2,quadraticCurveTo:3,closePath:4},S={NEED_PASSWORD:1,INCORRECT_PASSWORD:2};let E=A.WARNINGS;function C(t){Number.isInteger(t)&&(E=t)}function T(){return E}function M(t){E>=A.INFOS&&console.info(`Info: ${t}`)}function D(t){E>=A.WARNINGS&&console.warn(`Warning: ${t}`)}function P(t){throw new Error(t)}function I(t,e){t||P(e)}function k(t){switch(t?.protocol){case"http:":case"https:":case"ftp:":case"mailto:":case"tel:":return!0;default:return!1}}function R(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=Q(t)}catch{}}const s=e?URL.parse(t,e):URL.parse(t);return k(s)?s:null}function L(t,e,i=!1){const s=URL.parse(t);return s?(s.hash=e,s.href):i&&R(t,"http://example.com")?t.split("#",1)[0]+""+(e?`#${e}`:""):""}function F(t,e,i,s=!1){return Object.defineProperty(t,e,{value:i,enumerable:!s,configurable:!0,writable:!1}),i}const O=function(){function t(t,e){this.message=t,this.name=e}return t.prototype=new Error,t.constructor=t,t}();class B extends O{constructor(t,e){super(t,"PasswordException"),this.code=e}}class N extends O{constructor(t,e){super(t,"UnknownErrorException"),this.details=e}}class U extends O{constructor(t){super(t,"InvalidPDFException")}}class j extends O{constructor(t,e,i){super(t,"ResponseException"),this.status=e,this.missing=i}}class z extends O{constructor(t){super(t,"FormatError")}}class H extends O{constructor(t){super(t,"AbortException")}}function $(t){"object"===typeof t&&void 0!==t?.length||P("Invalid argument for bytesToString");const e=t.length,i=8192;if(e<i)return String.fromCharCode.apply(null,t);const s=[];for(let n=0;n<e;n+=i){const r=Math.min(n+i,e),a=t.subarray(n,r);s.push(String.fromCharCode.apply(null,a))}return s.join("")}function G(t){"string"!==typeof t&&P("Invalid argument for stringToBytes");const e=t.length,i=new Uint8Array(e);for(let s=0;s<e;++s)i[s]=255&t.charCodeAt(s);return i}function W(t){return String.fromCharCode(t>>24&255,t>>16&255,t>>8&255,255&t)}function V(){const t=new Uint8Array(4);t[0]=1;const e=new Uint32Array(t.buffer,0,1);return 1===e[0]}function q(){try{return new Function(""),!0}catch{return!1}}class X{static get isLittleEndian(){return F(this,"isLittleEndian",V())}static get isEvalSupported(){return F(this,"isEvalSupported",q())}static get isOffscreenCanvasSupported(){return F(this,"isOffscreenCanvasSupported","undefined"!==typeof OffscreenCanvas)}static get isImageDecoderSupported(){return F(this,"isImageDecoderSupported","undefined"!==typeof ImageDecoder)}static get isFloat16ArraySupported(){return F(this,"isFloat16ArraySupported","undefined"!==typeof Float16Array)}static get isSanitizerSupported(){return F(this,"isSanitizerSupported","undefined"!==typeof Sanitizer)}static get platform(){const{platform:t,userAgent:e}=navigator;return F(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 F(this,"isCSSRoundSupported",globalThis.CSS?.supports?.("width: round(1.5px, 1px)"))}}const Y=Array.from(Array(256).keys(),t=>t.toString(16).padStart(2,"0"));class K{static makeHexColor(t,e,i){return`#${Y[t]}${Y[e]}${Y[i]}`}static domMatrixToTransform(t){return[t.a,t.b,t.c,t.d,t.e,t.f]}static scaleMinMax(t,e){let i;t[0]?(t[0]<0&&(i=e[0],e[0]=e[2],e[2]=i),e[0]*=t[0],e[2]*=t[0],t[3]<0&&(i=e[1],e[1]=e[3],e[3]=i),e[1]*=t[3],e[3]*=t[3]):(i=e[0],e[0]=e[1],e[1]=i,i=e[2],e[2]=e[3],e[3]=i,t[1]<0&&(i=e[1],e[1]=e[3],e[3]=i),e[1]*=t[1],e[3]*=t[1],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 s=t[i],n=t[i+1];t[i]=s*e[0]+n*e[2]+e[4],t[i+1]=s*e[1]+n*e[3]+e[5]}static applyTransformToBezier(t,e,i=0){const s=e[0],n=e[1],r=e[2],a=e[3],o=e[4],l=e[5];for(let h=0;h<6;h+=2){const e=t[i+h],c=t[i+h+1];t[i+h]=e*s+c*r+o,t[i+h+1]=e*n+c*a+l}}static applyInverseTransform(t,e){const i=t[0],s=t[1],n=e[0]*e[3]-e[1]*e[2];t[0]=(i*e[3]-s*e[2]+e[2]*e[5]-e[4]*e[3])/n,t[1]=(-i*e[1]+s*e[0]+e[4]*e[1]-e[5]*e[0])/n}static axialAlignedBoundingBox(t,e,i){const s=e[0],n=e[1],r=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=s*h+o,g=p,m=s*d+o,f=m,b=a*c+l,v=b,y=a*u+l,w=y;if(0!==n||0!==r){const t=n*h,e=n*d,i=r*c,s=r*u;p+=i,f+=i,m+=s,g+=s,b+=t,w+=t,y+=e,v+=e}i[0]=Math.min(i[0],p,m,g,f),i[1]=Math.min(i[1],b,y,v,w),i[2]=Math.max(i[2],p,m,g,f),i[3]=Math.max(i[3],b,y,v,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],s=t[1],n=t[2],r=t[3],a=i**2+s**2,o=i*n+s*r,l=n**2+r**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);return t[0]>t[2]&&(e[0]=t[2],e[2]=t[0]),t[1]>t[3]&&(e[1]=t[3],e[3]=t[1]),e}static intersect(t,e){const i=Math.max(Math.min(t[0],t[2]),Math.min(e[0],e[2])),s=Math.min(Math.max(t[0],t[2]),Math.max(e[0],e[2]));if(i>s)return null;const n=Math.max(Math.min(t[1],t[3]),Math.min(e[1],e[3])),r=Math.min(Math.max(t[1],t[3]),Math.max(e[1],e[3]));return n>r?null:[i,n,s,r]}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,s,n){n[0]=Math.min(n[0],t,i),n[1]=Math.min(n[1],e,s),n[2]=Math.max(n[2],t,i),n[3]=Math.max(n[3],e,s)}static#t(t,e,i,s,n,r,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*s,g=c*(c*(c*n+3*l*r)+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,s,n,r,a,o,l,h,c,d){if(Math.abs(l)<1e-12)return void(Math.abs(h)>=1e-12&&this.#t(t,e,i,s,n,r,a,o,-c/h,d));const u=h**2-4*c*l;if(u<0)return;const p=Math.sqrt(u),g=2*l;this.#t(t,e,i,s,n,r,a,o,(-h+p)/g,d),this.#t(t,e,i,s,n,r,a,o,(-h-p)/g,d)}static bezierBoundingBox(t,e,i,s,n,r,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,n,a,e,s,r,o,3*(3*(i-n)-t+a),6*(t-2*i+n),3*(i-t),l),this.#e(t,i,n,a,e,s,r,o,3*(3*(s-r)-e+o),6*(e-2*s+r),3*(s-e),l)}}function Q(t){return decodeURIComponent(escape(t))}let Z=null,J=null;function tt(t){return Z||(Z=/([\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,J=new Map([["ſt","ſt"]])),t.replaceAll(Z,(t,e,i)=>e?e.normalize("NFKC"):J.get(i))}function et(){if("function"===typeof crypto.randomUUID)return crypto.randomUUID();const t=new Uint8Array(32);return crypto.getRandomValues(t),$(t)}const it="pdfjs_internal_id_";function st(t,e,i){if(!Array.isArray(i)||i.length<2)return!1;const[s,n,...r]=i;if(!t(s)&&!Number.isInteger(s))return!1;if(!e(n))return!1;const a=r.length;let o=!0;switch(n.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 l of r)if(!("number"===typeof l||o&&null===l))return!1;return!0}function nt(t,e,i){return Math.min(Math.max(t,e),i)}function rt(t){return Uint8Array.prototype.toBase64?t.toBase64():btoa($(t))}function at(t){return Uint8Array.fromBase64?Uint8Array.fromBase64(t):G(atob(t))}"function"!==typeof Promise.try&&(Promise.try=function(t,...e){return new Promise(i=>{i(t(...e))})}),"function"!==typeof Math.sumPrecise&&(Math.sumPrecise=function(t){return t.reduce((t,e)=>t+e,0)});class ot{static textContent(t){const e=[],i={items:e,styles:Object.create(null)};function s(t){if(!t)return;let i=null;const n=t.name;if("#text"===n)i=t.value;else{if(!ot.shouldBuildText(n))return;t?.attributes?.textContent?i=t.attributes.textContent:t.value&&(i=t.value)}if(null!==i&&e.push({str:i}),t.children)for(const e of t.children)s(e)}return s(t),i}static shouldBuildText(t){return!("textarea"===t||"input"===t||"option"===t||"select"===t)}}class lt{static setupStorage(t,e,i,s,n){const r=s.getValue(e,{value:null});switch(i.name){case"textarea":if(null!==r.value&&(t.textContent=r.value),"print"===n)break;t.addEventListener("input",t=>{s.setValue(e,{value:t.target.value})});break;case"input":if("radio"===i.attributes.type||"checkbox"===i.attributes.type){if(r.value===i.attributes.xfaOn?t.setAttribute("checked",!0):r.value===i.attributes.xfaOff&&t.removeAttribute("checked"),"print"===n)break;t.addEventListener("change",t=>{s.setValue(e,{value:t.target.checked?t.target.getAttribute("xfaOn"):t.target.getAttribute("xfaOff")})})}else{if(null!==r.value&&t.setAttribute("value",r.value),"print"===n)break;t.addEventListener("input",t=>{s.setValue(e,{value:t.target.value})})}break;case"select":if(null!==r.value){t.setAttribute("value",r.value);for(const t of i.children)t.attributes.value===r.value?t.attributes.selected=!0:t.attributes.hasOwnProperty("selected")&&delete t.attributes.selected}t.addEventListener("input",t=>{const i=t.target.options,n=-1===i.selectedIndex?"":i[i.selectedIndex].value;s.setValue(e,{value:n})});break}}static setAttributes({html:t,element:e,storage:i=null,intent:s,linkService:n}){const{attributes:r}=e,a=t instanceof HTMLAnchorElement;"radio"===r.type&&(r.name=`${r.name}-${s}`);for(const[o,l]of Object.entries(r))if(null!==l&&void 0!==l)switch(o){case"class":l.length&&t.setAttribute(o,l.join(" "));break;case"dataId":break;case"id":t.setAttribute("data-element-id",l);break;case"style":Object.assign(t.style,l);break;case"textContent":t.textContent=l;break;default:(!a||"href"!==o&&"newWindow"!==o)&&t.setAttribute(o,l)}a&&n.addLinkAttributes(t,r.href,r.newWindow),i&&r.dataId&&this.setupStorage(t,r.dataId,e,i)}static render(t){const e=t.annotationStorage,i=t.linkService,s=t.xfaHtml,n=t.intent||"display",r=document.createElement(s.name);s.attributes&&this.setAttributes({html:r,element:s,intent:n,linkService:i});const a="richText"!==n,o=t.div;if(o.append(r),t.viewport){const e=`matrix(${t.viewport.transform.join(",")})`;o.style.transform=e}a&&o.setAttribute("class","xfaLayer xfaFont");const l=[];if(0===s.children.length){if(s.value){const t=document.createTextNode(s.value);r.append(t),a&&ot.shouldBuildText(s.name)&&l.push(t)}return{textDivs:l}}const h=[[s,-1,r]];while(h.length>0){const[t,s,r]=h.at(-1);if(s+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),r.append(t);continue}const d=o?.attributes?.xmlns?document.createElementNS(o.attributes.xmlns,c):document.createElement(c);if(r.append(d),o.attributes&&this.setAttributes({html:d,element:o,storage:e,intent:n,linkService:i}),o.children?.length>0)h.push([o,-1,d]);else if(o.value){const t=document.createTextNode(o.value);a&&ot.shouldBuildText(c)&&l.push(t),d.append(t)}}for(const c of o.querySelectorAll(".xfaNonInteractive input, .xfaNonInteractive textarea"))c.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 ht="http://www.w3.org/2000/svg";class ct{static CSS=96;static PDF=72;static PDF_TO_CSS_UNITS=this.CSS/this.PDF}async function dt(t,e="text"){if(yt(t,document.baseURI)){const i=await fetch(t);if(!i.ok)throw new Error(i.statusText);switch(e){case"arraybuffer":return i.arrayBuffer();case"blob":return i.blob();case"json":return i.json()}return i.text()}return new Promise((i,s)=>{const n=new XMLHttpRequest;n.open("GET",t,!0),n.responseType=e,n.onreadystatechange=()=>{if(n.readyState===XMLHttpRequest.DONE)if(200!==n.status&&0!==n.status)s(new Error(n.statusText));else{switch(e){case"arraybuffer":case"blob":case"json":return void i(n.response)}i(n.responseText)}},n.send(null)})}class ut{constructor({viewBox:t,userUnit:e,scale:i,rotation:s,offsetX:n=0,offsetY:r=0,dontFlip:a=!1}){this.viewBox=t,this.userUnit=e,this.scale=i,this.rotation=s,this.offsetX=n,this.offsetY=r,i*=e;const o=(t[2]+t[0])/2,l=(t[3]+t[1])/2;let h,c,d,u,p,g,m,f;switch(s%=360,s<0&&(s+=360),s){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.")}a&&(d=-d,u=-u),0===h?(p=Math.abs(l-t[1])*i+n,g=Math.abs(o-t[0])*i+r,m=(t[3]-t[1])*i,f=(t[2]-t[0])*i):(p=Math.abs(o-t[0])*i+n,g=Math.abs(l-t[1])*i+r,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 F(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:s=this.offsetY,dontFlip:n=!1}={}){return new ut({viewBox:this.viewBox.slice(),userUnit:this.userUnit,scale:t,rotation:e,offsetX:i,offsetY:s,dontFlip:n})}convertToViewportPoint(t,e){const i=[t,e];return K.applyTransform(i,this.transform),i}convertToViewportRectangle(t){const e=[t[0],t[1]];K.applyTransform(e,this.transform);const i=[t[2],t[3]];return K.applyTransform(i,this.transform),[e[0],e[1],i[0],i[1]]}convertToPdfPoint(t,e){const i=[t,e];return K.applyInverseTransform(i,this.transform),i}}class pt extends O{constructor(t,e=0){super(t,"RenderingCancelledException"),this.extraDelay=e}}function gt(t){const e=t.length;let i=0;while(i<e&&""===t[i].trim())i++;return"data:"===t.substring(i,i+5).toLowerCase()}function mt(t){return"string"===typeof t&&/\.pdf$/i.test(t)}function ft(t){return[t]=t.split(/[#?]/,1),t.substring(t.lastIndexOf("/")+1)}function bt(t,e="document.pdf"){if("string"!==typeof t)return e;if(gt(t))return D('getPdfFilenameFromUrl: ignore "data:"-URL for performance reasons.'),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}}}}},s=i(t);if(!s)return e;const n=t=>{try{let e=decodeURIComponent(t);return e.includes("/")?(e=e.split("/").at(-1),e.test(/^\.pdf$/i)?e:t):e}catch{return t}},r=/\.pdf$/i,a=s.pathname.split("/").at(-1);if(r.test(a))return n(a);if(s.searchParams.size>0){const t=Array.from(s.searchParams.values()).reverse();for(const i of t)if(r.test(i))return n(i);const e=Array.from(s.searchParams.keys()).reverse();for(const i of e)if(r.test(i))return n(i)}if(s.hash){const t=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,e=t.exec(s.hash);if(e)return n(e[0])}return e}class vt{started=Object.create(null);times=[];time(t){t in this.started&&D(`Timer is already running for ${t}`),this.started[t]=Date.now()}timeEnd(t){t in this.started||D(`Timer has not been started for ${t}`),this.times.push({name:t,start:this.started[t],end:Date.now()}),delete this.started[t]}toString(){const t=[];let e=0;for(const{name:i}of this.times)e=Math.max(i.length,e);for(const{name:i,start:s,end:n}of this.times)t.push(`${i.padEnd(e)} ${n-s}ms\n`);return t.join("")}}function yt(t,e){const i=e?URL.parse(t,e):URL.parse(t);return"http:"===i?.protocol||"https:"===i?.protocol}function wt(t){t.preventDefault()}function At(t){t.preventDefault(),t.stopPropagation()}function xt(t){console.log("Deprecated API usage: "+t)}class _t{static#i;static toDateObject(t){if(t instanceof Date)return t;if(!t||"string"!==typeof t)return null;this.#i||=new RegExp("^D:(\\d{4})(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?(\\d{2})?([Z|+|-])?(\\d{2})?'?(\\d{2})?'?");const e=this.#i.exec(t);if(!e)return null;const i=parseInt(e[1],10);let s=parseInt(e[2],10);s=s>=1&&s<=12?s-1:0;let n=parseInt(e[3],10);n=n>=1&&n<=31?n:1;let r=parseInt(e[4],10);r=r>=0&&r<=23?r: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;return c=c>=0&&c<=59?c:0,"-"===l?(r+=h,a+=c):"+"===l&&(r-=h,a-=c),new Date(Date.UTC(i,s,n,r,a,o))}}function St(t,{scale:e=1,rotation:i=0}){const{width:s,height:n}=t.attributes.style,r=[0,0,parseInt(s),parseInt(n)];return new ut({viewBox:r,userUnit:1,scale:e,rotation:i})}function Et(t){if(t.startsWith("#")){const e=parseInt(t.slice(1),16);return[(16711680&e)>>16,(65280&e)>>8,255&e]}return t.startsWith("rgb(")?t.slice(4,-1).split(",").map(t=>parseInt(t)):t.startsWith("rgba(")?t.slice(5,-1).split(",").map(t=>parseInt(t)).slice(0,3):(D(`Not a valid color format: "${t}"`),[0,0,0])}function Ct(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 s=window.getComputedStyle(e).color;t.set(i,Et(s))}e.remove()}function Tt(t){const{a:e,b:i,c:s,d:n,e:r,f:a}=t.getTransform();return[e,i,s,n,r,a]}function Mt(t){const{a:e,b:i,c:s,d:n,e:r,f:a}=t.getTransform().invertSelf();return[e,i,s,n,r,a]}function Dt(t,e,i=!1,s=!0){if(e instanceof ut){const{pageWidth:s,pageHeight:n}=e.rawDims,{style:r}=t,a=X.isCSSRoundSupported,o=`var(--total-scale-factor) * ${s}px`,l=`var(--total-scale-factor) * ${n}px`,h=a?`round(down, ${o}, var(--scale-round-x))`:`calc(${o})`,c=a?`round(down, ${l}, var(--scale-round-y))`:`calc(${l})`;i&&e.rotation%180!==0?(r.width=c,r.height=h):(r.width=h,r.height=c)}s&&t.setAttribute("data-main-rotation",e.rotation)}class Pt{constructor(){const{pixelRatio:t}=Pt;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,s,n=-1){let r=1/0,a=1/0,o=1/0;i=Pt.capPixels(i,n),i>0&&(r=Math.sqrt(i/(t*e))),-1!==s&&(a=s/t,o=s/e);const l=Math.min(r,a,o);return(this.sx>l||this.sy>l)&&(this.sx=l,this.sy=l,!0)}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 It=["image/apng","image/avif","image/bmp","image/gif","image/jpeg","image/png","image/svg+xml","image/webp","image/x-icon"];class kt{static get isDarkMode(){return F(this,"isDarkMode",!!window?.matchMedia?.("(prefers-color-scheme: dark)").matches)}}class Rt{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);return t.remove(),F(this,"commentForegroundColor",Et(i))}}function Lt(t,e,i,s){s=Math.min(Math.max(s??1,0),1);const n=255*(1-s);return t=Math.round(t*s+n),e=Math.round(e*s+n),i=Math.round(i*s+n),[t,e,i]}function Ft(t,e){const i=t[0]/255,s=t[1]/255,n=t[2]/255,r=Math.max(i,s,n),a=Math.min(i,s,n),o=(r+a)/2;if(r===a)e[0]=e[1]=0;else{const t=r-a;switch(e[1]=o<.5?t/(r+a):t/(2-r-a),r){case i:e[0]=60*((s-n)/t+(s<n?6:0));break;case s:e[0]=60*((n-i)/t+2);break;case n:e[0]=60*((i-s)/t+4);break}}e[2]=o}function Ot(t,e){const i=t[0],s=t[1],n=t[2],r=(1-Math.abs(2*n-1))*s,a=r*(1-Math.abs(i/60%2-1)),o=n-r/2;switch(Math.floor(i/60)){case 0:e[0]=r+o,e[1]=a+o,e[2]=o;break;case 1:e[0]=a+o,e[1]=r+o,e[2]=o;break;case 2:e[0]=o,e[1]=r+o,e[2]=a+o;break;case 3:e[0]=o,e[1]=a+o,e[2]=r+o;break;case 4:e[0]=a+o,e[1]=o,e[2]=r+o;break;case 5:case 6:e[0]=r+o,e[1]=o,e[2]=a+o;break}}function Bt(t){return t<=.03928?t/12.92:((t+.055)/1.055)**2.4}function Nt(t,e,i){Ot(t,i),i.map(Bt);const s=.2126*i[0]+.7152*i[1]+.0722*i[2];Ot(e,i),i.map(Bt);const n=.2126*i[0]+.7152*i[1]+.0722*i[2];return s>n?(s+.05)/(n+.05):(n+.05)/(s+.05)}const Ut=new Map;function jt(t,e){const i=t[0]+256*t[1]+65536*t[2]+16777216*e[0]+4294967296*e[1]+1099511627776*e[2];let s=Ut.get(i);if(s)return s;const n=new Float32Array(9),r=n.subarray(0,3),a=n.subarray(3,6);Ft(t,a);const o=n.subarray(6,9);Ft(e,o);const l=o[2]<.5,h=l?12:4.5;if(a[2]=l?Math.sqrt(a[2]):1-Math.sqrt(1-a[2]),Nt(a,o,r)<h){let t,e;l?(t=a[2],e=1):(t=0,e=a[2]);const i=.005;while(e-t>i){const i=a[2]=(t+e)/2;l===Nt(a,o,r)<h?t=i:e=i}a[2]=l?e:t}return Ot(a,r),s=K.makeHexColor(Math.round(255*r[0]),Math.round(255*r[1]),Math.round(255*r[2])),Ut.set(i,s),s}function zt({html:t,dir:e,className:i},s){const n=document.createDocumentFragment();if("string"===typeof t){const i=document.createElement("p");i.dir=e||"auto";const s=t.split(/(?:\r\n?|\n)/);for(let t=0,e=s.length;t<e;++t){const n=s[t];i.append(document.createTextNode(n)),t<e-1&&i.append(document.createElement("br"))}n.append(i)}else lt.render({xfaHtml:t,div:n,intent:"richText"});n.firstElementChild.classList.add("richText",i),s.append(n)}function Ht(t){const e=new Path2D;if(!t)return e;for(let i=0,s=t.length;i<s;)switch(t[i++]){case _.moveTo:e.moveTo(t[i++],t[i++]);break;case _.lineTo:e.lineTo(t[i++],t[i++]);break;case _.curveTo:e.bezierCurveTo(t[i++],t[i++],t[i++],t[i++],t[i++],t[i++]);break;case _.quadraticCurveTo:e.quadraticCurveTo(t[i++],t[i++],t[i++],t[i++]);break;case _.closePath:e.closePath();break;default:D(`Unrecognized drawing path operator: ${t[i-1]}`);break}return e}class $t{#s=null;#n=null;#r;#a=null;#o=null;#l=null;#h=null;#c=null;static#d=null;constructor(t){this.#r=t,$t.#d||=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.#s=document.createElement("div");t.classList.add("editToolbar","hidden"),t.setAttribute("role","toolbar");const e=this.#r._uiManager._signal;e instanceof AbortSignal&&!e.aborted&&(t.addEventListener("contextmenu",wt,{signal:e}),t.addEventListener("pointerdown",$t.#u,{signal:e}));const i=this.#a=document.createElement("div");i.className="buttons",t.append(i);const s=this.#r.toolbarPosition;if(s){const{style:e}=t,i="ltr"===this.#r._uiManager.direction?1-s[0]:s[0];e.insetInlineEnd=100*i+"%",e.top=`calc(${100*s[1]}% + var(--editor-toolbar-vert-offset))`}return t}get div(){return this.#s}static#u(t){t.stopPropagation()}#p(t){this.#r._focusEventsAllowed=!1,At(t)}#g(t){this.#r._focusEventsAllowed=!0,At(t)}#m(t){const e=this.#r._uiManager._signal;return e instanceof AbortSignal&&!e.aborted&&(t.addEventListener("focusin",this.#p.bind(this),{capture:!0,signal:e}),t.addEventListener("focusout",this.#g.bind(this),{capture:!0,signal:e}),t.addEventListener("contextmenu",wt,{signal:e}),!0)}hide(){this.#s.classList.add("hidden"),this.#n?.hideDropdown()}show(){this.#s.classList.remove("hidden"),this.#o?.shown(),this.#l?.shown()}addDeleteButton(){const{editorType:t,_uiManager:e}=this.#r,i=document.createElement("button");i.classList.add("basic","deleteButton"),i.tabIndex=0,i.setAttribute("data-l10n-id",$t.#d[t]),this.#m(i)&&i.addEventListener("click",t=>{e.delete()},{signal:e._signal}),this.#a.append(i)}get#f(){const t=document.createElement("div");return t.className="divider",t}async addAltText(t){const e=await t.render();this.#m(e),this.#a.append(e,this.#f),this.#o=t}addComment(t,e=null){if(this.#l)return;const i=t.renderForToolbar();if(!i)return;this.#m(i);const s=this.#h=this.#f;e?(this.#a.insertBefore(i,e),this.#a.insertBefore(s,e)):this.#a.append(i,s),this.#l=t,t.toolbar=this}addColorPicker(t){if(this.#n)return;this.#n=t;const e=t.renderButton();this.#m(e),this.#a.append(e,this.#f)}async addEditSignatureButton(t){const e=this.#c=await t.renderEditButton(this.#r);this.#m(e),this.#a.append(e,this.#f)}removeButton(t){switch(t){case"comment":this.#l?.removeToolbarCommentButton(),this.#l=null,this.#h?.remove(),this.#h=null;break}}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);break}}async addButtonBefore(t,e,i){if(!e&&"comment"===t)return;const s=this.#a.querySelector(i);s&&"comment"===t&&this.addComment(e,s)}updateEditSignatureButton(t){this.#c&&(this.#c.title=t)}remove(){this.#s.remove(),this.#n?.destroy(),this.#n=null}}class Gt{#a=null;#s=null;#b;constructor(t){this.#b=t}#v(){const t=this.#s=document.createElement("div");t.className="editToolbar",t.setAttribute("role","toolbar");const e=this.#b._signal;e instanceof AbortSignal&&!e.aborted&&t.addEventListener("contextmenu",wt,{signal:e});const i=this.#a=document.createElement("div");return i.className="buttons",t.append(i),this.#b.hasCommentManager()&&this.#y("commentButton","pdfjs-comment-floating-button","pdfjs-comment-floating-button-label",()=>{this.#b.commentSelection("floating_button")}),this.#y("highlightButton","pdfjs-highlight-floating-button1","pdfjs-highlight-floating-button-label",()=>{this.#b.highlightSelection("floating_button")}),t}#w(t,e){let i=0,s=0;for(const n of t){const t=n.y+n.height;if(t<i)continue;const r=n.x+(e?n.width:0);t>i?(s=r,i=t):e?r>s&&(s=r):r<s&&(s=r)}return[e?1-s:s,i]}show(t,e,i){const[s,n]=this.#w(e,i),{style:r}=this.#s||=this.#v();t.append(this.#s),r.insetInlineEnd=100*s+"%",r.top=`calc(${100*n}% + var(--editor-toolbar-vert-offset))`}hide(){this.#s.remove()}#y(t,e,i,s){const n=document.createElement("button");n.classList.add("basic",t),n.tabIndex=0,n.setAttribute("data-l10n-id",e);const r=document.createElement("span");n.append(r),r.className="visuallyHidden",r.setAttribute("data-l10n-id",i);const a=this.#b._signal;a instanceof AbortSignal&&!a.aborted&&(n.addEventListener("contextmenu",wt,{signal:a}),n.addEventListener("click",s,{signal:a})),this.#a.append(n)}}function Wt(t,e,i){for(const s of i)e.addEventListener(s,t[s].bind(t))}class Vt{static#A=NaN;static#x=null;static#_=NaN;static#S=null;static initializeAndAddPointerId(t){(Vt.#x||=new Set).add(t)}static setPointer(t,e){Vt.#A||=e,Vt.#S??=t}static setTimeStamp(t){Vt.#_=t}static isSamePointerId(t){return Vt.#A===t}static isSamePointerIdOrRemove(t){return Vt.#A===t||(Vt.#x?.delete(t),!1)}static isSamePointerType(t){return Vt.#S===t}static isInitializedAndDifferentPointerType(t){return null!==Vt.#S&&!Vt.isSamePointerType(t)}static isSameTimeStamp(t){return Vt.#_===t}static isUsingMultiplePointers(){return Vt.#x?.size>=1}static clearPointerType(){Vt.#S=null}static clearPointerIds(){Vt.#A=NaN,Vt.#x=null}static clearTimeStamp(){Vt.#_=NaN}}class qt{#E=0;get id(){return`${u}${this.#E++}`}}class Xt{#C=et();#E=0;#T=null;static get _isSVGFittingCanvas(){const t='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>',e=new OffscreenCanvas(1,3),i=e.getContext("2d",{willReadFrequently:!0}),s=new Image;s.src=t;const n=s.decode().then(()=>(i.drawImage(s,0,0,1,1,0,0,1,3),0===new Uint32Array(i.getImageData(0,0,1,1).data.buffer)[0]));return F(this,"_isSVGFittingCanvas",n)}async#M(t,e){this.#T||=new Map;let i=this.#T.get(t);if(null===i)return null;if(i?.bitmap)return i.refCounter+=1,i;try{let t;if(i||={bitmap:null,id:`image_${this.#C}_${this.#E++}`,refCounter:0,isSvg:!1},"string"===typeof e?(i.url=e,t=await dt(e,"blob")):e instanceof File?t=i.file=e:e instanceof Blob&&(t=e),"image/svg+xml"===t.type){const e=Xt._isSVGFittingCanvas,s=new FileReader,n=new Image,r=new Promise((t,r)=>{n.onload=()=>{i.bitmap=n,i.isSvg=!0,t()},s.onload=async()=>{const t=i.svgUrl=s.result;n.src=await e?`${t}#svgView(preserveAspectRatio(none))`:t},n.onerror=s.onerror=r});s.readAsDataURL(t),await r}else i.bitmap=await createImageBitmap(t);i.refCounter=1}catch(s){D(s),i=null}return this.#T.set(t,i),i&&this.#T.set(i.id,i),i}async getFromFile(t){const{lastModified:e,name:i,size:s,type:n}=t;return this.#M(`${e}_${i}_${s}_${n}`,t)}async getFromUrl(t){return this.#M(t,t)}async getFromBlob(t,e){const i=await e;return this.#M(t,i)}async getFromId(t){this.#T||=new Map;const e=this.#T.get(t);if(!e)return null;if(e.bitmap)return e.refCounter+=1,e;if(e.file)return this.getFromFile(e.file);if(e.blobPromise){const{blobPromise:t}=e;return delete e.blobPromise,this.getFromBlob(e.id,t)}return this.getFromUrl(e.url)}getFromCanvas(t,e){this.#T||=new Map;let i=this.#T.get(t);if(i?.bitmap)return i.refCounter+=1,i;const s=new OffscreenCanvas(e.width,e.height),n=s.getContext("2d");return n.drawImage(e,0,0),i={bitmap:s.transferToImageBitmap(),id:`image_${this.#C}_${this.#E++}`,refCounter:1,isSvg:!1},this.#T.set(t,i),this.#T.set(i.id,i),i}getSvgUrl(t){const e=this.#T.get(t);return e?.isSvg?e.svgUrl:null}deleteId(t){this.#T||=new Map;const e=this.#T.get(t);if(!e)return;if(e.refCounter-=1,0!==e.refCounter)return;const{bitmap:i}=e;if(!e.url&&!e.file){const t=new OffscreenCanvas(i.width,i.height),s=t.getContext("bitmaprenderer");s.transferFromImageBitmap(i),e.blobPromise=t.convertToBlob()}i.close?.(),e.bitmap=null}isValidId(t){return t.startsWith(`image_${this.#C}_`)}}class Yt{#D=[];#P=!1;#I;#k=-1;constructor(t=128){this.#I=t}add({cmd:t,undo:e,post:i,mustExec:s,type:n=NaN,overwriteIfSameType:r=!1,keepUndo:a=!1}){if(s&&t(),this.#P)return;const o={cmd:t,undo:e,post:i,type:n};if(-1===this.#k)return this.#D.length>0&&(this.#D.length=0),this.#k=0,void this.#D.push(o);if(r&&this.#D[this.#k].type===n)return a&&(o.undo=this.#D[this.#k].undo),void(this.#D[this.#k]=o);const l=this.#k+1;l===this.#I?this.#D.splice(0,1):(this.#k=l,l<this.#D.length&&this.#D.splice(l)),this.#D.push(o)}undo(){if(-1===this.#k)return;this.#P=!0;const{undo:t,post:e}=this.#D[this.#k];t(),e?.(),this.#P=!1,this.#k-=1}redo(){if(this.#k<this.#D.length-1){this.#k+=1,this.#P=!0;const{cmd:t,post:e}=this.#D[this.#k];t(),e?.(),this.#P=!1}}hasSomethingToUndo(){return-1!==this.#k}hasSomethingToRedo(){return this.#k<this.#D.length-1}cleanType(t){if(-1!==this.#k){for(let e=this.#k;e>=0;e--)if(this.#D[e].type!==t)return this.#D.splice(e+1,this.#k-e),void(this.#k=e);this.#D.length=0,this.#k=-1}}destroy(){this.#D=null}}class Kt{constructor(t){this.buffer=[],this.callbacks=new Map,this.allKeys=new Set;const{isMac:e}=X.platform;for(const[i,s,n={}]of t)for(const t of i){const i=t.startsWith("mac+");e&&i?(this.callbacks.set(t.slice(4),{callback:s,options:n}),this.allKeys.add(t.split("+").at(-1))):e||i||(this.callbacks.set(t,{callback:s,options:n}),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("+");return this.buffer.length=0,e}exec(t,e){if(!this.allKeys.has(e.key))return;const i=this.callbacks.get(this.#R(e));if(!i)return;const{callback:s,options:{bubbles:n=!1,args:r=[],checker:a=null}}=i;a&&!a(t,e)||(s.bind(t,...r,e)(),n||At(e))}}class Qt{static _colorsMapping=new Map([["CanvasText",[0,0,0]],["Canvas",[255,255,255]]]);get _colors(){const t=new Map([["CanvasText",null],["Canvas",null]]);return Ct(t),F(this,"_colors",t)}convert(t){const e=Et(t);if(!window.matchMedia("(forced-colors: active)").matches)return e;for(const[i,s]of this._colors)if(s.every((t,i)=>t===e[i]))return Qt._colorsMapping.get(i);return e}getHexCode(t){const e=this._colors.get(t);return e?K.makeHexColor(...e):t}}class Zt{#L=new AbortController;#F=null;#O=null;#B=new Map;#N=new Map;#U=null;#j=null;#z=null;#H=new Yt;#$=null;#G=null;#W=null;#V=0;#q=new Set;#X=null;#Y=null;#K=new Set;_editorUndoBar=null;#Q=!1;#Z=!1;#J=!1;#tt=null;#et=null;#it=null;#st=null;#nt=!1;#rt=null;#at=new qt;#ot=!1;#lt=!1;#ht=!1;#ct=null;#dt=null;#ut=null;#pt=null;#gt=null;#mt=p.NONE;#ft=new Set;#bt=null;#vt=null;#yt=null;#wt=null;#At=null;#xt={isEditing:!1,isEmpty:!0,hasSomethingToUndo:!1,hasSomethingToRedo:!1,hasSelectedEditor:!1,hasSelectedText:!1};#_t=[0,0];#St=null;#Et=null;#Ct=null;#Tt=null;#Mt=null;static TRANSLATE_SMALL=1;static TRANSLATE_BIG=10;static get _keyboardManager(){const t=Zt.prototype,e=t=>t.#Et.contains(document.activeElement)&&"BUTTON"!==document.activeElement.tagName&&t.hasSomethingToControl(),i=(t,{target:e})=>{if(e instanceof HTMLInputElement){const{type:t}=e;return"text"!==t&&"number"!==t}return!0},s=this.TRANSLATE_SMALL,n=this.TRANSLATE_BIG;return F(this,"_keyboardManager",new Kt([[["ctrl+a","mac+meta+a"],t.selectAll,{checker:i}],[["ctrl+z","mac+meta+z"],t.undo,{checker:i}],[["ctrl+y","ctrl+shift+z","mac+meta+shift+z","ctrl+shift+Z","mac+meta+shift+Z"],t.redo,{checker:i}],[["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:i}],[["Enter","mac+Enter"],t.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#Et.contains(e)&&!t.isEnterHandled}],[[" ","mac+ "],t.addNewEditorFromKeyboard,{checker:(t,{target:e})=>!(e instanceof HTMLButtonElement)&&t.#Et.contains(document.activeElement)}],[["Escape","mac+Escape"],t.unselectAll],[["ArrowLeft","mac+ArrowLeft"],t.translateSelectedEditors,{args:[-s,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t.translateSelectedEditors,{args:[-n,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t.translateSelectedEditors,{args:[s,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t.translateSelectedEditors,{args:[n,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t.translateSelectedEditors,{args:[0,-s],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t.translateSelectedEditors,{args:[0,-n],checker:e}],[["ArrowDown","mac+ArrowDown"],t.translateSelectedEditors,{args:[0,s],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t.translateSelectedEditors,{args:[0,n],checker:e}]]))}constructor(t,e,i,s,n,r,a,o,l,h,c,d,u,p,g,m){const f=this._signal=this.#L.signal;this.#Et=t,this.#Ct=e,this.#Tt=i,this.#U=s,this.#$=n,this.#vt=r,this.#At=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.#lt=!0},{capture:!0,signal:f}),window.addEventListener("pointerup",()=>{this.#lt=!1},{capture:!0,signal:f}),this.#Dt(),this.#Pt(),this.#It(),this.#j=o.annotationStorage,this.#tt=o.filterFactory,this.#yt=l,this.#st=h||null,this.#Q=c,this.#Z=d,this.#J=u,this.#gt=p||null,this.viewParameters={realScale:ct.PDF_TO_CSS_UNITS,rotation:0},this.isShiftKeyDown=!1,this._editorUndoBar=g||null,this._supportsPinchToZoom=!1!==m,n?.setSidebarUiManager(this)}destroy(){this.#Mt?.resolve(),this.#Mt=null,this.#L?.abort(),this.#L=null,this._signal=null;for(const t of this.#N.values())t.destroy();this.#N.clear(),this.#B.clear(),this.#K.clear(),this.#pt?.clear(),this.#F=null,this.#ft.clear(),this.#H.destroy(),this.#U?.destroy(),this.#$?.destroy(),this.#vt?.destroy(),this.#rt?.hide(),this.#rt=null,this.#ut?.destroy(),this.#ut=null,this.#O=null,this.#et&&(clearTimeout(this.#et),this.#et=null),this.#St&&(clearTimeout(this.#St),this.#St=null),this._editorUndoBar?.destroy(),this.#At=null}combinedSignal(t){return AbortSignal.any([this._signal,t.signal])}get mlManager(){return this.#gt}get useNewAltTextFlow(){return this.#Z}get useNewAltTextWhenAddingImage(){return this.#J}get hcmFilter(){return F(this,"hcmFilter",this.#yt?this.#tt.addHCMFilter(this.#yt.foreground,this.#yt.background):"none")}get direction(){return F(this,"direction",getComputedStyle(this.#Et).direction)}get _highlightColors(){return F(this,"_highlightColors",this.#st?new Map(this.#st.split(",").map(t=>(t=t.split("=").map(t=>t.trim()),t[1]=t[1].toUpperCase(),t))):null)}get highlightColors(){const{_highlightColors:t}=this;if(!t)return F(this,"highlightColors",null);const e=new Map,i=!!this.#yt;for(const[s,n]of t){const t=s.endsWith("_HCM");i&&t?e.set(s.replace("_HCM",""),n):i||t||e.set(s,n)}return F(this,"highlightColors",e)}get highlightColorNames(){return F(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){t?(this.unselectAll(),this.disableUserSelect(!0)):this.disableUserSelect(!1),this.#W=t}setMainHighlightColorPicker(t){this.#ut=t}editAltText(t,e=!1){this.#U?.editAltText(this,t,e)}hasCommentManager(){return!!this.#$}editComment(t,e,i,s){this.#$?.showDialog(this,t,e,i,s)}selectComment(t,e){const i=this.#N.get(t),s=i?.getEditorByUID(e);s?.toggleComment(!0,!0)}updateComment(t){this.#$?.updateComment(t.getData())}updatePopupColor(t){this.#$?.updatePopupColor(t)}removeComment(t){this.#$?.removeComments([t.uid])}toggleComment(t,e,i=void 0){this.#$?.toggleCommentPopup(t,e,i)}makeCommentColor(t,e){return t&&this.#$?.makeCommentColor(t,e)||null}getCommentDialogElement(){return this.#$?.dialogElement||null}async waitForEditorsRendered(t){if(this.#N.has(t-1))return;const{resolve:e,promise:i}=Promise.withResolvers(),s=i=>{i.pageNumber===t&&(this._eventBus._off("editorsrendered",s),e())};this._eventBus.on("editorsrendered",s),await i}getSignature(t){this.#vt?.getSignature({uiManager:this,editor:t})}get signatureManager(){return this.#vt}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}){switch(t){case"enableNewAltTextWhenAddingImage":this.#J=e;break}}onPageChanging({pageNumber:t}){this.#V=t-1}focusMainContainer(){this.#Et.focus()}findParent(t,e){for(const i of this.#N.values()){const{x:s,y:n,width:r,height:a}=i.div.getBoundingClientRect();if(t>=s&&t<=s+r&&e>=n&&e<=n+a)return i}return null}disableUserSelect(t=!1){this.#Ct.classList.toggle("noUserSelect",t)}addShouldRescale(t){this.#K.add(t)}removeShouldRescale(t){this.#K.delete(t)}onScaleChanging({scale:t}){this.commitOrRemove(),this.viewParameters.realScale=t*ct.PDF_TO_CSS_UNITS;for(const e of this.#K)e.onScaleChanging();this.#W?.onScaleChanging()}onRotationChanging({pagesRotation:t}){this.commitOrRemove(),this.viewParameters.rotation=t}#kt({anchorNode:t}){return t.nodeType===Node.TEXT_NODE?t.parentElement:t}#Rt(t){const{currentLayer:e}=this;if(e.hasTextLayer(t))return e;for(const i of this.#N.values())if(i.hasTextLayer(t))return i;return null}highlightSelection(t="",e=!1){const i=document.getSelection();if(!i||i.isCollapsed)return;const{anchorNode:s,anchorOffset:n,focusNode:r,focusOffset:a}=i,o=i.toString(),l=this.#kt(i),h=l.closest(".textLayer"),c=this.getSelectionBoxes(h);if(!c)return;i.empty();const d=this.#Rt(h),u=this.#mt===p.NONE,g=()=>{const i=d?.createAndAddNewEditor({x:0,y:0},!1,{methodOfCreation:t,boxes:c,anchorNode:s,anchorOffset:n,focusNode:r,focusOffset:a,text:o});u&&this.showAllEditors("highlight",!0,!0),e&&i?.editComment()};u?this.switchToMode(p.HIGHLIGHT,g):g()}commentSelection(t=""){this.highlightSelection(t,!0)}#Lt(){const t=document.getSelection();if(!t||t.isCollapsed)return;const e=this.#kt(t),i=e.closest(".textLayer"),s=this.getSelectionBoxes(i);s&&(this.#rt||=new Gt(this),this.#rt.show(i,s,"ltr"===this.direction))}getAndRemoveDataFromAnnotationStorage(t){if(!this.#j)return null;const e=`${u}${t}`,i=this.#j.getRawValue(e);return i&&this.#j.remove(e),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.#Tt;i&&(i.setAttribute("data-l10n-id",t),e?i.setAttribute("data-l10n-args",JSON.stringify(e)):i.removeAttribute("data-l10n-args"))}#Ft(){const t=document.getSelection();if(!t||t.isCollapsed)return void(this.#bt&&(this.#rt?.hide(),this.#bt=null,this.#Ot({hasSelectedText:!1})));const{anchorNode:e}=t;if(e===this.#bt)return;const i=this.#kt(t),s=i.closest(".textLayer");if(s){if(this.#rt?.hide(),this.#bt=e,this.#Ot({hasSelectedText:!0}),(this.#mt===p.HIGHLIGHT||this.#mt===p.NONE)&&(this.#mt===p.HIGHLIGHT&&this.showAllEditors("highlight",!0,!0),this.#nt=this.isShiftKeyDown,!this.isShiftKeyDown)){const t=this.#mt===p.HIGHLIGHT?this.#Rt(s):null;if(t?.toggleDrawing(),this.#lt){const e=new AbortController,i=this.combinedSignal(e),s=i=>{"pointerup"===i.type&&0!==i.button||(e.abort(),t?.toggleDrawing(!0),"pointerup"===i.type&&this.#Bt("main_toolbar"))};window.addEventListener("pointerup",s,{signal:i}),window.addEventListener("blur",s,{signal:i})}else t?.toggleDrawing(!0),this.#Bt("main_toolbar")}}else this.#bt&&(this.#rt?.hide(),this.#bt=null,this.#Ot({hasSelectedText:!1}))}#Bt(t=""){this.#mt===p.HIGHLIGHT?this.highlightSelection(t):this.#Q&&this.#Lt()}#Dt(){document.addEventListener("selectionchange",this.#Ft.bind(this),{signal:this._signal})}#Nt(){if(this.#it)return;this.#it=new AbortController;const t=this.combinedSignal(this.#it);window.addEventListener("focus",this.focus.bind(this),{signal:t}),window.addEventListener("blur",this.blur.bind(this),{signal:t})}#Ut(){this.#it?.abort(),this.#it=null}blur(){if(this.isShiftKeyDown=!1,this.#nt&&(this.#nt=!1,this.#Bt("main_toolbar")),!this.hasSelection)return;const{activeElement:t}=document;for(const e of this.#ft)if(e.div.contains(t)){this.#dt=[e,t],e._focusEventsAllowed=!1;break}}focus(){if(!this.#dt)return;const[t,e]=this.#dt;this.#dt=null,e.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this._signal}),e.focus()}#It(){if(this.#ct)return;this.#ct=new AbortController;const t=this.combinedSignal(this.#ct);window.addEventListener("keydown",this.keydown.bind(this),{signal:t}),window.addEventListener("keyup",this.keyup.bind(this),{signal:t})}#jt(){this.#ct?.abort(),this.#ct=null}#zt(){if(this.#G)return;this.#G=new AbortController;const t=this.combinedSignal(this.#G);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})}#Ht(){this.#G?.abort(),this.#G=null}#Pt(){const t=this._signal;document.addEventListener("dragover",this.dragOver.bind(this),{signal:t}),document.addEventListener("drop",this.drop.bind(this),{signal:t})}addEditListeners(){this.#It(),this.setEditingState(!0)}removeEditListeners(){this.#jt(),this.setEditingState(!1)}dragOver(t){for(const{type:e}of t.dataTransfer.items)for(const i of this.#Y)if(i.isHandlingMimeForPasting(e))return t.dataTransfer.dropEffect="copy",void t.preventDefault()}drop(t){for(const e of t.dataTransfer.items)for(const i of this.#Y)if(i.isHandlingMimeForPasting(e.type))return i.paste(e,this.currentLayer),void t.preventDefault()}copy(t){if(t.preventDefault(),this.#F?.commitOrRemove(),!this.hasSelection)return;const e=[];for(const i of this.#ft){const t=i.serialize(!0);t&&e.push(t)}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 r of e.items)for(const t of this.#Y)if(t.isHandlingMimeForPasting(r.type))return void t.paste(r,this.currentLayer);let i=e.getData("application/pdfjs");if(!i)return;try{i=JSON.parse(i)}catch(n){return void D(`paste: "${n.message}".`)}if(!Array.isArray(i))return;this.unselectAll();const s=this.currentLayer;try{const t=[];for(const r of i){const e=await s.deserialize(r);if(!e)return;t.push(e)}const e=()=>{for(const e of t)this.#$t(e);this.#Gt(t)},n=()=>{for(const e of t)e.remove()};this.addCommands({cmd:e,undo:n,mustExec:!0})}catch(n){D(`paste: "${n.message}".`)}}keydown(t){this.isShiftKeyDown||"Shift"!==t.key||(this.isShiftKeyDown=!0),this.#mt===p.NONE||this.isEditorHandlingKeyboard||Zt._keyboardManager.exec(this,t)}keyup(t){this.isShiftKeyDown&&"Shift"===t.key&&(this.isShiftKeyDown=!1,this.#nt&&(this.#nt=!1,this.#Bt("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");break}}#Ot(t){const e=Object.entries(t).some(([t,e])=>this.#xt[t]!==e);e&&(this._eventBus.dispatch("annotationeditorstateschanged",{source:this,details:Object.assign(this.#xt,t)}),this.#mt===p.HIGHLIGHT&&!1===t.hasSelectedEditor&&this.#Wt([[g.HIGHLIGHT_FREE,!0]]))}#Wt(t){this._eventBus.dispatch("annotationeditorparamschanged",{source:this,details:t})}setEditingState(t){t?(this.#Nt(),this.#zt(),this.#Ot({isEditing:this.#mt!==p.NONE,isEmpty:this.#Vt(),hasSomethingToUndo:this.#H.hasSomethingToUndo(),hasSomethingToRedo:this.#H.hasSomethingToRedo(),hasSelectedEditor:!1})):(this.#Ut(),this.#Ht(),this.#Ot({isEditing:!1}),this.disableUserSelect(!1))}registerEditorTypes(t){if(!this.#Y){this.#Y=t;for(const t of this.#Y)this.#Wt(t.defaultPropertiesToUpdate)}}getId(){return this.#at.id}get currentLayer(){return this.#N.get(this.#V)}getLayer(t){return this.#N.get(t)}get currentPageIndex(){return this.#V}addLayer(t){this.#N.set(t.pageIndex,t),this.#ot?t.enable():t.disable()}removeLayer(t){this.#N.delete(t.pageIndex)}async updateMode(t,e=null,i=!1,s=!1,n=!1,r=!1){if(this.#mt!==t&&(!this.#Mt||(await this.#Mt.promise,this.#Mt))){if(this.#Mt=Promise.withResolvers(),this.#W?.commitOrRemove(),this.#mt===p.POPUP&&this.#$?.hideSidebar(),this.#$?.destroyPopup(),this.#mt=t,t===p.NONE){this.setEditingState(!1),this.#qt();for(const t of this.#B.values())t.hideStandaloneCommentButton();return this._editorUndoBar?.hide(),this.toggleComment(null),void this.#Mt.resolve()}for(const t of this.#B.values())t.addStandaloneCommentButton();t===p.SIGNATURE&&await(this.#vt?.loadSignatures()),i&&Vt.clearPointerType(),this.setEditingState(!0),await this.#Xt(),this.unselectAll();for(const e of this.#N.values())e.updateMode(t);if(t===p.POPUP){this.#O||=await this.#At.getAnnotationsByType(new Set(this.#Y.map(t=>t._editorType)));const t=new Set,e=[];for(const i of this.#B.values()){const{annotationElementId:s,hasComment:n,deleted:r}=i;s&&t.add(s),n&&!r&&e.push(i.getData())}for(const i of this.#O){const{id:s,popupRef:n,contentsObj:r}=i;n&&r?.str&&!t.has(s)&&!this.#q.has(s)&&e.push(i)}this.#$?.showSidebar(e)}if(!e)return s&&this.addNewEditorFromKeyboard(),void this.#Mt.resolve();for(const t of this.#B.values())t.uid===e?(this.setSelected(t),r?t.editComment():n?t.enterInEditMode():t.focus()):t.unselect();this.#Mt.resolve()}}addNewEditorFromKeyboard(){this.currentLayer.canCreateNewEmptyEditor()&&this.currentLayer.addNewEditor()}updateToolbar(t){t.mode!==this.#mt&&this._eventBus.dispatch("switchannotationeditormode",{source:this,...t})}updateParams(t,e){if(this.#Y){switch(t){case g.CREATE:return void this.currentLayer.addNewEditor(e);case g.HIGHLIGHT_SHOW_ALL:this._eventBus.dispatch("reporttelemetry",{source:this,details:{type:"editing",data:{type:"highlight",action:"toggle_visibility"}}}),(this.#wt||=new Map).set(t,e),this.showAllEditors("highlight",e);break}if(this.hasSelection)for(const i of this.#ft)i.updateParams(t,e);else for(const i of this.#Y)i.updateDefaultParams(t,e)}}showAllEditors(t,e,i=!1){for(const n of this.#B.values())n.editorType===t&&n.show(e);const s=this.#wt?.get(g.HIGHLIGHT_SHOW_ALL)??!0;s!==e&&this.#Wt([[g.HIGHLIGHT_SHOW_ALL,e]])}enableWaiting(t=!1){if(this.#ht!==t){this.#ht=t;for(const e of this.#N.values())t?e.disableClick():e.enableClick(),e.div.classList.toggle("waiting",t)}}async#Xt(){if(!this.#ot){this.#ot=!0;const t=[];for(const e of this.#N.values())t.push(e.enable());await Promise.all(t);for(const e of this.#B.values())e.enable()}}#qt(){if(this.unselectAll(),this.#ot){this.#ot=!1;for(const t of this.#N.values())t.disable();for(const t of this.#B.values())t.disable()}}*getEditors(t){for(const e of this.#B.values())e.pageIndex===t&&(yield e)}getEditor(t){return this.#B.get(t)}addEditor(t){this.#B.set(t.id,t)}removeEditor(t){t.div.contains(document.activeElement)&&(this.#et&&clearTimeout(this.#et),this.#et=setTimeout(()=>{this.focusMainContainer(),this.#et=null},0)),this.#B.delete(t.id),t.annotationElementId&&this.#pt?.delete(t.annotationElementId),this.unselect(t),t.annotationElementId&&this.#q.has(t.annotationElementId)||this.#j?.remove(t.id)}addDeletedAnnotationElement(t){this.#q.add(t.annotationElementId),this.addChangedExistingAnnotation(t),t.deleted=!0}isDeletedAnnotationElement(t){return this.#q.has(t)}removeDeletedAnnotationElement(t){this.#q.delete(t.annotationElementId),this.removeChangedExistingAnnotation(t),t.deleted=!1}#$t(t){const e=this.#N.get(t.pageIndex);e?e.addOrRebuild(t):(this.addEditor(t),this.addToAnnotationStorage(t))}setActiveEditor(t){this.#F!==t&&(this.#F=t,t&&this.#Wt(t.propertiesToUpdate))}get#Yt(){let t=null;for(t of this.#ft);return t}updateUI(t){this.#Yt===t&&this.#Wt(t.propertiesToUpdate)}updateUIForDefaultProperties(t){this.#Wt(t.defaultPropertiesToUpdate)}toggleSelected(t){if(this.#ft.has(t))return this.#ft.delete(t),t.unselect(),void this.#Ot({hasSelectedEditor:this.hasSelection});this.#ft.add(t),t.select(),this.#Wt(t.propertiesToUpdate),this.#Ot({hasSelectedEditor:!0})}setSelected(t){this.updateToolbar({mode:t.mode,editId:t.uid}),this.#W?.commitOrRemove();for(const e of this.#ft)e!==t&&e.unselect();this.#ft.clear(),this.#ft.add(t),t.select(),this.#Wt(t.propertiesToUpdate),this.#Ot({hasSelectedEditor:!0})}isSelected(t){return this.#ft.has(t)}get firstSelectedEditor(){return this.#ft.values().next().value}unselect(t){t.unselect(),this.#ft.delete(t),this.#Ot({hasSelectedEditor:this.hasSelection})}get hasSelection(){return 0!==this.#ft.size}get isEnterHandled(){return 1===this.#ft.size&&this.firstSelectedEditor.isEnterHandled}undo(){this.#H.undo(),this.#Ot({hasSomethingToUndo:this.#H.hasSomethingToUndo(),hasSomethingToRedo:!0,isEmpty:this.#Vt()}),this._editorUndoBar?.hide()}redo(){this.#H.redo(),this.#Ot({hasSomethingToUndo:!0,hasSomethingToRedo:this.#H.hasSomethingToRedo(),isEmpty:this.#Vt()})}addCommands(t){this.#H.add(t),this.#Ot({hasSomethingToUndo:!0,hasSomethingToRedo:!1,isEmpty:this.#Vt()})}cleanUndoStack(t){this.#H.cleanType(t)}#Vt(){if(0===this.#B.size)return!0;if(1===this.#B.size)for(const t of this.#B.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.#ft],i=()=>{this._editorUndoBar?.show(s,1===e.length?e[0].editorType:e.length);for(const t of e)t.remove()},s=()=>{for(const t of e)this.#$t(t)};this.addCommands({cmd:i,undo:s,mustExec:!0})}commitOrRemove(){this.#F?.commitOrRemove()}hasSomethingToControl(){return this.#F||this.hasSelection}#Gt(t){for(const e of this.#ft)e.unselect();this.#ft.clear();for(const e of t)e.isEmpty()||(this.#ft.add(e),e.select());this.#Ot({hasSelectedEditor:this.hasSelection})}selectAll(){for(const t of this.#ft)t.commit();this.#Gt(this.#B.values())}unselectAll(){if((!this.#F||(this.#F.commitOrRemove(),this.#mt===p.NONE))&&!this.#W?.commitOrRemove()&&this.hasSelection){for(const t of this.#ft)t.unselect();this.#ft.clear(),this.#Ot({hasSelectedEditor:!1})}}translateSelectedEditors(t,e,i=!1){if(i||this.commitOrRemove(),!this.hasSelection)return;this.#_t[0]+=t,this.#_t[1]+=e;const[s,n]=this.#_t,r=[...this.#ft],a=1e3;this.#St&&clearTimeout(this.#St),this.#St=setTimeout(()=>{this.#St=null,this.#_t[0]=this.#_t[1]=0,this.addCommands({cmd:()=>{for(const t of r)this.#B.has(t.id)&&(t.translateInPage(s,n),t.translationDone())},undo:()=>{for(const t of r)this.#B.has(t.id)&&(t.translateInPage(-s,-n),t.translationDone())},mustExec:!1})},a);for(const o of r)o.translateInPage(t,e),o.translationDone()}setUpDragSession(){if(this.hasSelection){this.disableUserSelect(!0),this.#X=new Map;for(const t of this.#ft)this.#X.set(t,{savedX:t.x,savedY:t.y,savedPageIndex:t.pageIndex,newX:0,newY:0,newPageIndex:-1})}}endDragSession(){if(!this.#X)return!1;this.disableUserSelect(!1);const t=this.#X;this.#X=null;let e=!1;for(const[{x:s,y:n,pageIndex:r},a]of t)a.newX=s,a.newY=n,a.newPageIndex=r,e||=s!==a.savedX||n!==a.savedY||r!==a.savedPageIndex;if(!e)return!1;const i=(t,e,i,s)=>{if(this.#B.has(t.id)){const n=this.#N.get(s);n?t._setParentAndPosition(n,e,i):(t.pageIndex=s,t.x=e,t.y=i)}};return this.addCommands({cmd:()=>{for(const[e,{newX:s,newY:n,newPageIndex:r}]of t)i(e,s,n,r)},undo:()=>{for(const[e,{savedX:s,savedY:n,savedPageIndex:r}]of t)i(e,s,n,r)},mustExec:!0}),!0}dragSelectedEditors(t,e){if(this.#X)for(const i of this.#X.keys())i.drag(t,e)}rebuild(t){if(null===t.parent){const e=this.getLayer(t.pageIndex);e?(e.changeParent(t),e.addOrRebuild(t)):(this.addEditor(t),this.addToAnnotationStorage(t),t.rebuild())}else t.parent.addOrRebuild(t)}get isEditorHandlingKeyboard(){return this.getActive()?.shouldGetKeyboardEvents()||1===this.#ft.size&&this.firstSelectedEditor.shouldGetKeyboardEvents()}isActive(t){return this.#F===t}getActive(){return this.#F}getMode(){return this.#mt}isEditingMode(){return this.#mt!==p.NONE}get imageManager(){return F(this,"imageManager",new Xt)}getSelectionBoxes(t){if(!t)return null;const e=document.getSelection();for(let l=0,h=e.rangeCount;l<h;l++)if(!t.contains(e.getRangeAt(l).commonAncestorContainer))return null;const{x:i,y:s,width:n,height:r}=t.getBoundingClientRect();let a;switch(t.getAttribute("data-main-rotation")){case"90":a=(t,e,a,o)=>({x:(e-s)/r,y:1-(t+a-i)/n,width:o/r,height:a/n});break;case"180":a=(t,e,a,o)=>({x:1-(t+a-i)/n,y:1-(e+o-s)/r,width:a/n,height:o/r});break;case"270":a=(t,e,a,o)=>({x:1-(e+o-s)/r,y:(t-i)/n,width:o/r,height:a/n});break;default:a=(t,e,a,o)=>({x:(t-i)/n,y:(e-s)/r,width:a/n,height:o/r});break}const o=[];for(let l=0,h=e.rangeCount;l<h;l++){const t=e.getRangeAt(l);if(!t.collapsed)for(const{x:e,y:i,width:s,height:n}of t.getClientRects())0!==s&&0!==n&&o.push(a(e,i,s,n))}return 0===o.length?null:o}addChangedExistingAnnotation({annotationElementId:t,id:e}){(this.#z||=new Map).set(t,e)}removeChangedExistingAnnotation({annotationElementId:t}){this.#z?.delete(t)}renderAnnotationElement(t){const e=this.#z?.get(t.data.id);if(!e)return;const i=this.#j.getRawValue(e);i&&(this.#mt!==p.NONE||i.hasBeenModified)&&i.renderAnnotationElement(t)}setMissingCanvas(t,e,i){const s=this.#pt?.get(t);s&&(s.setCanvas(e,i),this.#pt.delete(t))}addMissingCanvas(t,e){(this.#pt||=new Map).set(t,e)}}class Jt{#o=null;#Kt=!1;#Qt=null;#Zt=null;#Jt=null;#te=null;#ee=!1;#ie=null;#r=null;#se=null;#ne=null;#re=!1;static#ae=null;static _l10n=null;constructor(t){this.#r=t,this.#re=t._uiManager.useNewAltTextFlow,Jt.#ae||=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){Jt._l10n??=t}async render(){const t=this.#Qt=document.createElement("button");t.className="altText",t.tabIndex="0";const e=this.#Zt=document.createElement("span");t.append(e),this.#re?(t.classList.add("new"),t.setAttribute("data-l10n-id",Jt.#ae.missing),e.setAttribute("data-l10n-id",Jt.#ae["missing-label"])):(t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button"),e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-button-label"));const i=this.#r._uiManager._signal;t.addEventListener("contextmenu",wt,{signal:i}),t.addEventListener("pointerdown",t=>t.stopPropagation(),{signal:i});const s=t=>{t.preventDefault(),this.#r._uiManager.editAltText(this.#r),this.#re&&this.#r._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_clicked",data:{label:this.#oe}})};return t.addEventListener("click",s,{capture:!0,signal:i}),t.addEventListener("keydown",e=>{e.target===t&&"Enter"===e.key&&(this.#ee=!0,s(e))},{signal:i}),await this.#le(),t}get#oe(){return(this.#o?"added":null===this.#o&&this.guessedText&&"review")||"missing"}finish(){this.#Qt&&(this.#Qt.focus({focusVisible:this.#ee}),this.#ee=!1)}isEmpty(){return this.#re?null===this.#o:!this.#o&&!this.#Kt}hasData(){return this.#re?null!==this.#o||!!this.#se:this.isEmpty()}get guessedText(){return this.#se}async setGuessedText(t){null===this.#o&&(this.#se=t,this.#ne=await Jt._l10n.get("pdfjs-editor-new-alt-text-generated-alt-text-with-disclaimer",{generatedAltText:t}),this.#le())}toggleAltTextBadge(t=!1){if(!this.#re||this.#o)return this.#ie?.remove(),void(this.#ie=null);if(!this.#ie){const t=this.#ie=document.createElement("div");t.className="noAltTextBadge",this.#r.div.append(t)}this.#ie.classList.toggle("hidden",!t)}serialize(t){let e=this.#o;return t||this.#se!==e||(e=this.#ne),{altText:e,decorative:this.#Kt,guessedText:this.#se,textWithDisclaimer:this.#ne}}get data(){return{altText:this.#o,decorative:this.#Kt}}set data({altText:t,decorative:e,guessedText:i,textWithDisclaimer:s,cancel:n=!1}){i&&(this.#se=i,this.#ne=s),this.#o===t&&this.#Kt===e||(n||(this.#o=t,this.#Kt=e),this.#le())}toggle(t=!1){this.#Qt&&(!t&&this.#te&&(clearTimeout(this.#te),this.#te=null),this.#Qt.disabled=!t)}shown(){this.#r._reportTelemetry({action:"pdfjs.image.alt_text.image_status_label_displayed",data:{label:this.#oe}})}destroy(){this.#Qt?.remove(),this.#Qt=null,this.#Zt=null,this.#Jt=null,this.#ie?.remove(),this.#ie=null}async#le(){const t=this.#Qt;if(!t)return;if(this.#re){if(t.classList.toggle("done",!!this.#o),t.setAttribute("data-l10n-id",Jt.#ae[this.#oe]),this.#Zt?.setAttribute("data-l10n-id",Jt.#ae[`${this.#oe}-label`]),!this.#o)return void this.#Jt?.remove()}else{if(!this.#o&&!this.#Kt)return t.classList.remove("done"),void this.#Jt?.remove();t.classList.add("done"),t.setAttribute("data-l10n-id","pdfjs-editor-alt-text-edit-button")}let e=this.#Jt;if(!e){this.#Jt=e=document.createElement("span"),e.className="tooltip",e.setAttribute("role","tooltip"),e.id=`alt-text-tooltip-${this.#r.id}`;const i=100,s=this.#r._uiManager._signal;s.addEventListener("abort",()=>{clearTimeout(this.#te),this.#te=null},{once:!0}),t.addEventListener("mouseenter",()=>{this.#te=setTimeout(()=>{this.#te=null,this.#Jt.classList.add("show"),this.#r._reportTelemetry({action:"alt_text_tooltip"})},i)},{signal:s}),t.addEventListener("mouseleave",()=>{this.#te&&(clearTimeout(this.#te),this.#te=null),this.#Jt?.classList.remove("show")},{signal:s})}this.#Kt?e.setAttribute("data-l10n-id","pdfjs-editor-alt-text-decorative-tooltip"):(e.removeAttribute("data-l10n-id"),e.textContent=this.#o),e.parentNode||t.append(e);const i=this.#r.getElementForAltText();i?.setAttribute("aria-describedby",e.id)}}class te{#he=null;#ce=null;#de=!1;#r=null;#ue=null;#pe=null;#ge=null;#me=null;#fe=!1;#be=null;constructor(t){this.#r=t}renderForToolbar(){const t=this.#ce=document.createElement("button");return t.className="comment",this.#v(t,!1)}renderForStandalone(){const t=this.#he=document.createElement("button");t.className="annotationCommentButton";const e=this.#r.commentButtonPosition;if(e){const{style:i}=t;i.insetInlineEnd=`calc(${100*("ltr"===this.#r._uiManager.direction?1-e[0]:e[0])}% - var(--comment-button-dim))`,i.top=`calc(${100*e[1]}% - var(--comment-button-dim))`;const s=this.#r.commentButtonColor;s&&(i.backgroundColor=s)}return this.#v(t,!0)}focusButton(){setTimeout(()=>{(this.#he??this.#ce)?.focus()},0)}onUpdatedColor(){if(!this.#he)return;const t=this.#r.commentButtonColor;t&&(this.#he.style.backgroundColor=t),this.#r._uiManager.updatePopupColor(this.#r)}get commentButtonWidth(){return(this.#he?.getBoundingClientRect().width??0)/this.#r.parent.boundingClientRect.width}get commentPopupPositionInLayer(){if(this.#be)return this.#be;if(!this.#he)return null;const{x:t,y:e,height:i}=this.#he.getBoundingClientRect(),{x:s,y:n,width:r,height:a}=this.#r.parent.boundingClientRect;return[(t-s)/r,(e+i-n)/a]}set commentPopupPositionInLayer(t){this.#be=t}hasDefaultPopupPosition(){return null===this.#be}removeStandaloneCommentButton(){this.#he?.remove(),this.#he=null}removeToolbarCommentButton(){this.#ce?.remove(),this.#ce=null}setCommentButtonStates({selected:t,hasPopup:e}){this.#he&&(this.#he.classList.toggle("selected",t),this.#he.ariaExpanded=e)}#v(t,e){if(!this.#r._uiManager.hasCommentManager())return null;t.tabIndex="0",t.ariaHasPopup="dialog",e?(t.ariaControls="commentPopup",t.setAttribute("data-l10n-id","pdfjs-show-comment-button")):(t.ariaControlsElements=[this.#r._uiManager.getCommentDialogElement()],t.setAttribute("data-l10n-id","pdfjs-editor-add-comment-button"));const i=this.#r._uiManager._signal;if(!(i instanceof AbortSignal)||i.aborted)return t;t.addEventListener("contextmenu",wt,{signal:i}),e&&(t.addEventListener("focusin",t=>{this.#r._focusEventsAllowed=!1,At(t)},{capture:!0,signal:i}),t.addEventListener("focusout",t=>{this.#r._focusEventsAllowed=!0,At(t)},{capture:!0,signal:i})),t.addEventListener("pointerdown",t=>t.stopPropagation(),{signal:i});const s=e=>{e.preventDefault(),t===this.#ce?this.edit():this.#r.toggleComment(!0)};return t.addEventListener("click",s,{capture:!0,signal:i}),t.addEventListener("keydown",e=>{e.target===t&&"Enter"===e.key&&(this.#de=!0,s(e))},{signal:i}),t.addEventListener("pointerenter",()=>{this.#r.toggleComment(!1,!0)},{signal:i}),t.addEventListener("pointerleave",()=>{this.#r.toggleComment(!1,!1)},{signal:i}),t}edit(t){const e=this.commentPopupPositionInLayer;let i,s;if(e)[i,s]=e;else{[i,s]=this.#r.commentButtonPosition;const{width:t,height:e,x:n,y:r}=this.#r;i=n+i*t,s=r+s*e}const n=this.#r.parent.boundingClientRect,{x:r,y:a,width:o,height:l}=n;this.#r._uiManager.editComment(this.#r,r+i*o,a+s*l,{...t,parentDimensions:n})}finish(){this.#ce&&(this.#ce.focus({focusVisible:this.#de}),this.#de=!1)}isDeleted(){return this.#fe||""===this.#ge}isEmpty(){return null===this.#ge}hasBeenEdited(){return this.isDeleted()||this.#ge!==this.#ue}serialize(){return this.data}get data(){return{text:this.#ge,richText:this.#pe,date:this.#me,deleted:this.isDeleted()}}set data(t){if(t!==this.#ge&&(this.#pe=null),null===t)return this.#ge="",void(this.#fe=!0);this.#ge=t,this.#me=new Date,this.#fe=!1}setInitialText(t,e=null){this.#ue=t,this.data=t,this.#me=null,this.#pe=e}shown(){}destroy(){this.#ce?.remove(),this.#ce=null,this.#he?.remove(),this.#he=null,this.#ge="",this.#pe=null,this.#me=null,this.#r=null,this.#de=!1,this.#fe=!1}}class ee{#Et;#ve=!1;#ye=null;#we;#Ae;#xe;#_e;#Se=null;#Ee;#Ce=null;#Te;#Me=null;constructor({container:t,isPinchingDisabled:e=null,isPinchingStopped:i=null,onPinchStart:s=null,onPinching:n=null,onPinchEnd:r=null,signal:a}){this.#Et=t,this.#ye=i,this.#we=e,this.#Ae=s,this.#xe=n,this.#_e=r,this.#Te=new AbortController,this.#Ee=AbortSignal.any([a,this.#Te.signal]),t.addEventListener("touchstart",this.#De.bind(this),{passive:!1,signal:this.#Ee})}get MIN_TOUCH_DISTANCE_TO_PINCH(){return 35/Pt.pixelRatio}#De(t){if(this.#we?.())return;if(1===t.touches.length){if(this.#Se)return;const t=this.#Se=new AbortController,e=AbortSignal.any([this.#Ee,t.signal]),i=this.#Et,s={capture:!0,signal:e,passive:!1},n=t=>{"touch"===t.pointerType&&(this.#Se?.abort(),this.#Se=null)};return i.addEventListener("pointerdown",t=>{"touch"===t.pointerType&&(At(t),n(t))},s),i.addEventListener("pointerup",n,s),void i.addEventListener("pointercancel",n,s)}if(!this.#Me){this.#Me=new AbortController;const t=AbortSignal.any([this.#Ee,this.#Me.signal]),e=this.#Et,i={signal:t,capture:!1,passive:!1};e.addEventListener("touchmove",this.#Pe.bind(this),i);const s=this.#Ie.bind(this);e.addEventListener("touchend",s,i),e.addEventListener("touchcancel",s,i),i.capture=!0,e.addEventListener("pointerdown",At,i),e.addEventListener("pointermove",At,i),e.addEventListener("pointercancel",At,i),e.addEventListener("pointerup",At,i),this.#Ae?.()}if(At(t),2!==t.touches.length||this.#ye?.())return void(this.#Ce=null);let[e,i]=t.touches;e.identifier>i.identifier&&([e,i]=[i,e]),this.#Ce={touch0X:e.screenX,touch0Y:e.screenY,touch1X:i.screenX,touch1Y:i.screenY}}#Pe(t){if(!this.#Ce||2!==t.touches.length)return;At(t);let[e,i]=t.touches;e.identifier>i.identifier&&([e,i]=[i,e]);const{screenX:s,screenY:n}=e,{screenX:r,screenY:a}=i,o=this.#Ce,{touch0X:l,touch0Y:h,touch1X:c,touch1Y:d}=o,u=c-l,p=d-h,g=r-s,m=a-n,f=Math.hypot(g,m)||1,b=Math.hypot(u,p)||1;if(!this.#ve&&Math.abs(b-f)<=ee.MIN_TOUCH_DISTANCE_TO_PINCH)return;if(o.touch0X=s,o.touch0Y=n,o.touch1X=r,o.touch1Y=a,!this.#ve)return void(this.#ve=!0);const v=[(s+r)/2,(n+a)/2];this.#xe?.(v,b,f)}#Ie(t){t.touches.length>=2||(this.#Me&&(this.#Me.abort(),this.#Me=null,this.#_e?.()),this.#Ce&&(At(t),this.#Ce=null,this.#ve=!1))}destroy(){this.#Te?.abort(),this.#Te=null,this.#Se?.abort(),this.#Se=null}}class ie{#ke=null;#Re=null;#o=null;#l=null;#he=null;#Le=!1;#Fe=null;#Oe="";#Be=null;#Ne=null;#Ue=null;#je=null;#ze=null;#He="";#$e=!1;#Ge=null;#We=!1;#Ve=!1;#qe=!1;#Xe=null;#Ye=0;#Ke=0;#Qe=null;#Ze=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;#Je=!1;#ti=ie._zIndex++;static _borderLineWidth=-1;static _colorManager=new Qt;static _zIndex=1;static _telemetryTimeout=1e3;static get _resizerKeyboardManager(){const t=ie.prototype._resizeWithKeyboard,e=Zt.TRANSLATE_SMALL,i=Zt.TRANSLATE_BIG;return F(this,"_resizerKeyboardManager",new Kt([[["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"],ie.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:s,pageX:n,pageY:r}}=this.parent.viewport;this.rotation=e,this.pageRotation=(360+e-this._uiManager.viewParameters.rotation)%360,this.pageDimensions=[i,s],this.pageTranslation=[n,r];const[a,o]=this.parentDimensions;this.x=t.x/a,this.y=t.y/o,this.isAttachedToDOM=!1,this.deleted=!1}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 F(this,"_defaultLineColor",this._colorManager.getHexCode("CanvasText"))}static deleteAnnotationElement(t){const e=new se({id:t.parent.getNextId(),parent:t.parent,uiManager:t._uiManager});e.annotationElementId=t.annotationElementId,e.deleted=!0,e._uiManager.addToAnnotationStorage(e)}static initialize(t,e){if(ie._l10n??=t,ie._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"}),-1!==ie._borderLineWidth)return;const i=getComputedStyle(document.documentElement);ie._borderLineWidth=parseFloat(i.getPropertyValue("--outline-width"))||0}static updateDefaultParams(t,e){}static get defaultPropertiesToUpdate(){return[]}static isHandlingMimeForPasting(t){return!1}static paste(t,e){P("Not implemented")}get propertiesToUpdate(){return[]}get _isDraggable(){return this.#Je}set _isDraggable(t){this.#Je=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;break}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.#ti}setParent(t){null!==t?(this.pageIndex=t.pageIndex,this.pageDimensions=t.pageDimensions):(this.#ei(),this.#je?.remove(),this.#je=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;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,s){const[n,r]=this.parentDimensions;[i,s]=this.screenToPageTranslation(i,s),this.x=(t+i)/n,this.y=(e+s)/r,this.fixAndSetPosition()}_moveAfterPaste(t,e){const[i,s]=this.parentDimensions;this.setAt(t*i,e*s,this.width*i,this.height*s),this._onTranslated()}#ii([t,e],i,s){[i,s]=this.screenToPageTranslation(i,s),this.x+=i/t,this.y+=s/e,this._onTranslating(this.x,this.y),this.fixAndSetPosition()}translate(t,e){this.#ii(this.parentDimensions,t,e)}translateInPage(t,e){this.#Ge||=[this.x,this.y,this.width,this.height],this.#ii(this.pageDimensions,t,e),this.div.scrollIntoView({block:"nearest"})}translationDone(){this._onTranslated(this.x,this.y)}drag(t,e){this.#Ge||=[this.x,this.y,this.width,this.height];const{div:i,parentDimensions:[s,n]}=this;if(this.x+=t/s,this.y+=e/n,this.parent&&(this.x<0||this.x>1||this.y<0||this.y>1)){const{x:t,y:e}=this.div.getBoundingClientRect();this.parent.findNewParent(this,t,e)&&(this.x-=Math.floor(this.x),this.y-=Math.floor(this.y))}let{x:r,y:a}=this;const[o,l]=this.getBaseTranslation();r+=o,a+=l;const{style:h}=i;h.left=`${(100*r).toFixed(2)}%`,h.top=`${(100*a).toFixed(2)}%`,this._onTranslating(r,a),i.scrollIntoView({block:"nearest"})}_onTranslating(t,e){}_onTranslated(t,e){}get _hasBeenMoved(){return!!this.#Ge&&(this.#Ge[0]!==this.x||this.#Ge[1]!==this.y)}get _hasBeenResized(){return!!this.#Ge&&(this.#Ge[2]!==this.width||this.#Ge[3]!==this.height)}getBaseTranslation(){const[t,e]=this.parentDimensions,{_borderLineWidth:i}=ie,s=i/t,n=i/e;switch(this.rotation){case 90:return[-s,n];case 180:return[s,n];case 270:return[s,-n];default:return[-s,-n]}}get _mustFixPosition(){return!0}fixAndSetPosition(t=this.rotation){const{div:{style:e},pageDimensions:[i,s]}=this;let{x:n,y:r,width:a,height:o}=this;if(a*=i,o*=s,n*=i,r*=s,this._mustFixPosition)switch(t){case 0:n=nt(n,0,i-a),r=nt(r,0,s-o);break;case 90:n=nt(n,0,i-o),r=nt(r,a,s);break;case 180:n=nt(n,a,i),r=nt(r,o,s);break;case 270:n=nt(n,o,i),r=nt(r,0,s-a);break}this.x=n/=i,this.y=r/=s;const[l,h]=this.getBaseTranslation();n+=l,r+=h,e.left=`${(100*n).toFixed(2)}%`,e.top=`${(100*r).toFixed(2)}%`,this.moveInDOM()}static#si(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 ie.#si(t,e,this.parentRotation)}pageTranslationToScreen(t,e){return ie.#si(t,e,360-this.parentRotation)}#ni(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]}#ri(){if(this.#Be)return;this.#Be=document.createElement("div"),this.#Be.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.#Be.append(t),t.classList.add("resizer",i),t.setAttribute("data-resizer-name",i),t.addEventListener("pointerdown",this.#ai.bind(this,i),{signal:e}),t.addEventListener("contextmenu",wt,{signal:e}),t.tabIndex=-1}this.div.prepend(this.#Be)}#ai(t,e){e.preventDefault();const{isMac:i}=X.platform;if(0!==e.button||e.ctrlKey&&i)return;this.#o?.toggle(!1);const s=this._isDraggable;this._isDraggable=!1,this.#Ne=[e.screenX,e.screenY];const n=new AbortController,r=this._uiManager.combinedSignal(n);this.parent.togglePointerEvents(!1),window.addEventListener("pointermove",this.#oi.bind(this,t),{passive:!0,capture:!0,signal:r}),window.addEventListener("touchmove",At,{passive:!1,signal:r}),window.addEventListener("contextmenu",wt,{signal:r}),this.#Ue={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 l=()=>{n.abort(),this.parent.togglePointerEvents(!0),this.#o?.toggle(!0),this._isDraggable=s,this.parent.div.style.cursor=a,this.div.style.cursor=o,this.#li()};window.addEventListener("pointerup",l,{signal:r}),window.addEventListener("blur",l,{signal:r})}#hi(t,e,i,s){this.width=i,this.height=s,this.x=t,this.y=e,this.setDims(),this.fixAndSetPosition(),this._onResized()}_onResized(){}#li(){if(!this.#Ue)return;const{savedX:t,savedY:e,savedWidth:i,savedHeight:s}=this.#Ue;this.#Ue=null;const n=this.x,r=this.y,a=this.width,o=this.height;n===t&&r===e&&a===i&&o===s||this.addCommands({cmd:this.#hi.bind(this,n,r,a,o),undo:this.#hi.bind(this,t,e,i,s),mustExec:!0})}static _round(t){return Math.round(1e4*t)/1e4}#oi(t,e){const[i,s]=this.parentDimensions,n=this.x,r=this.y,a=this.width,o=this.height,l=ie.MIN_SIZE/i,h=ie.MIN_SIZE/s,c=this.#ni(this.rotation),d=(t,e)=>[c[0]*t+c[2]*e,c[1]*t+c[3]*e],u=this.#ni(360-this.rotation),p=(t,e)=>[u[0]*t+u[2]*e,u[1]*t+u[3]*e];let g,m,f=!1,b=!1;switch(t){case"topLeft":f=!0,g=(t,e)=>[0,0],m=(t,e)=>[t,e];break;case"topMiddle":g=(t,e)=>[t/2,0],m=(t,e)=>[t/2,e];break;case"topRight":f=!0,g=(t,e)=>[t,0],m=(t,e)=>[0,e];break;case"middleRight":b=!0,g=(t,e)=>[t,e/2],m=(t,e)=>[0,e/2];break;case"bottomRight":f=!0,g=(t,e)=>[t,e],m=(t,e)=>[0,0];break;case"bottomMiddle":g=(t,e)=>[t/2,e],m=(t,e)=>[t/2,0];break;case"bottomLeft":f=!0,g=(t,e)=>[0,e],m=(t,e)=>[t,0];break;case"middleLeft":b=!0,g=(t,e)=>[0,e/2],m=(t,e)=>[t,e/2];break}const v=g(a,o),y=m(a,o);let w=d(...y);const A=ie._round(n+w[0]),x=ie._round(r+w[1]);let _,S,E=1,C=1;if(e.fromKeyboard)({deltaX:_,deltaY:S}=e);else{const{screenX:t,screenY:i}=e,[s,n]=this.#Ne;[_,S]=this.screenToPageTranslation(t-s,i-n),this.#Ne[0]=t,this.#Ne[1]=i}if([_,S]=p(_/i,S/s),f){const t=Math.hypot(a,o);E=C=Math.max(Math.min(Math.hypot(y[0]-v[0]-_,y[1]-v[1]-S)/t,1/a,1/o),l/a,h/o)}else b?E=nt(Math.abs(y[0]-v[0]-_),l,1)/a:C=nt(Math.abs(y[1]-v[1]-S),h,1)/o;const T=ie._round(a*E),M=ie._round(o*C);w=d(...m(T,M));const D=A-w[0],P=x-w[1];this.#Ge||=[this.x,this.y,this.width,this.height],this.width=T,this.height=M,this.x=D,this.y=P,this.setDims(),this.fixAndSetPosition(),this._onResizing()}_onResizing(){}altTextFinish(){this.#o?.finish()}get toolbarButtons(){return null}async addEditToolbar(){if(this._editToolbar||this.#Ve)return this._editToolbar;this._editToolbar=new $t(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);return this.hasComment||this._editToolbar.addButton("comment",this.addCommentButton()),this._editToolbar.addButton("delete"),this._editToolbar}addCommentButtonInToolbar(){this._editToolbar?.addButtonBefore("comment",this.addCommentButton(),".deleteButton")}removeCommentButtonFromToolbar(){this._editToolbar?.removeButton("comment")}removeEditToolbar(){this._editToolbar?.remove(),this._editToolbar=null,this.#o?.destroy()}addContainer(t){const e=this._editToolbar?.div;e?e.before(t):this.div.append(t)}getClientDimensions(){return this.div.getBoundingClientRect()}createAltText(){return this.#o||(Jt.initialize(ie._l10n),this.#o=new Jt(this),this.#ke&&(this.#o.data=this.#ke,this.#ke=null)),this.#o}get altTextData(){return this.#o?.data}set altTextData(t){this.#o&&(this.#o.data=t)}get guessedAltText(){return this.#o?.guessedText}async setGuessedAltText(t){await(this.#o?.setGuessedText(t))}serializeAltText(t){return this.#o?.serialize(t)}hasAltText(){return!!this.#o&&!this.#o.isEmpty()}hasAltTextData(){return this.#o?.hasData()??!1}focusCommentButton(){this.#l?.focusButton()}addCommentButton(){return this.canAddComment?this.#l||=new te(this):null}addStandaloneCommentButton(){this._uiManager.hasCommentManager()&&(this.#he?this._uiManager.isEditingMode()&&this.#he.classList.remove("hidden"):this.hasComment&&(this.#he=this.#l.renderForStandalone(),this.div.append(this.#he)))}removeStandaloneCommentButton(){this.#l.removeStandaloneCommentButton(),this.#he=null}hideStandaloneCommentButton(){this.#he?.classList.add("hidden")}get comment(){const{data:{richText:t,text:e,date:i,deleted:s}}=this.#l;return{text:e,richText:t,date:i,deleted:s,color:this.getNonHCMColor(),opacity:this.opacity??1}}set comment(t){this.#l||=new te(this),this.#l.data=t,this.hasComment?(this.removeCommentButtonFromToolbar(),this.addStandaloneCommentButton(),this._uiManager.updateComment(this)):(this.addCommentButtonInToolbar(),this.removeStandaloneCommentButton(),this._uiManager.removeComment(this))}setCommentData({comment:t,popupRef:e,richText:i}){if(!e)return;if(this.#l||=new te(this),this.#l.setInitialText(t,i),!this.annotationElementId)return;const s=this._uiManager.getAndRemoveDataFromAnnotationStorage(this.annotationElementId);s&&this.updateFromAnnotationLayer(s)}get hasEditedComment(){return this.#l?.hasBeenEdited()}get hasDeletedComment(){return this.#l?.isDeleted()}get hasComment(){return!!this.#l&&!this.#l.isEmpty()&&!this.#l.isDeleted()}async editComment(t){this.#l||=new te(this),this.#l.edit(t)}toggleComment(t,e=void 0){this.hasComment&&this._uiManager.toggleComment(this,t,e)}setSelectedCommentButton(t){this.#l.setSelectedButton(t)}addComment(t){if(this.hasEditedComment){const e=180,i=100,[,,,s]=t.rect,[n]=this.pageDimensions,[r]=this.pageTranslation,a=r+n+1,o=s-i,l=a+e;t.popup={contents:this.comment.text,deleted:this.comment.deleted,rect:[a,o,l,s]}}}updateFromAnnotationLayer({popup:{contents:t,deleted:e}}){this.#l.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.#ci();const[e,i]=this.parentDimensions;this.parentRotation%180!==0&&(t.style.maxWidth=`${(100*i/e).toFixed(2)}%`,t.style.maxHeight=`${(100*e/i).toFixed(2)}%`);const[s,n]=this.getInitialTranslation();return this.translate(s,n),Wt(this,t,["keydown","pointerdown","dblclick"]),this.isResizable&&this._uiManager._supportsPinchToZoom&&(this.#Ze||=new ee({container:t,isPinchingDisabled:()=>!this.isSelected,onPinchStart:this.#di.bind(this),onPinching:this.#ui.bind(this),onPinchEnd:this.#pi.bind(this),signal:this._uiManager._signal})),this.addStandaloneCommentButton(),this._uiManager._editorUndoBar?.hide(),t}#di(){this.#Ue={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height},this.#o?.toggle(!1),this.parent.togglePointerEvents(!1)}#ui(t,e,i){const s=.7;let n=s*(i/e)+1-s;if(1===n)return;const r=this.#ni(this.rotation),a=(t,e)=>[r[0]*t+r[2]*e,r[1]*t+r[3]*e],[o,l]=this.parentDimensions,h=this.x,c=this.y,d=this.width,u=this.height,p=ie.MIN_SIZE/o,g=ie.MIN_SIZE/l;n=Math.max(Math.min(n,1/d,1/u),p/d,g/u);const m=ie._round(d*n),f=ie._round(u*n);if(m===d&&f===u)return;this.#Ge||=[h,c,d,u];const b=a(d/2,u/2),v=ie._round(h+b[0]),y=ie._round(c+b[1]),w=a(m/2,f/2);this.x=v-w[0],this.y=y-w[1],this.width=m,this.height=f,this.setDims(),this.fixAndSetPosition(),this._onResizing()}#pi(){this.#o?.toggle(!0),this.parent.togglePointerEvents(!0),this.#li()}pointerdown(t){const{isMac:e}=X.platform;0!==t.button||t.ctrlKey&&e?t.preventDefault():(this.#$e=!0,this._isDraggable?this.#gi(t):this.#mi(t))}#mi(t){const{isMac:e}=X.platform;t.ctrlKey&&!e||t.shiftKey||t.metaKey&&e?this.parent.toggleSelected(this):this.parent.setSelected(this)}#gi(t){const{isSelected:e}=this;this._uiManager.setUpDragSession();let i=!1;const s=new AbortController,n=this._uiManager.combinedSignal(s),r={capture:!0,passive:!1,signal:n},a=t=>{s.abort(),this.#Fe=null,this.#$e=!1,this._uiManager.endDragSession()||this.#mi(t),i&&this._onStopDragging()};e&&(this.#Ye=t.clientX,this.#Ke=t.clientY,this.#Fe=t.pointerId,this.#Oe=t.pointerType,window.addEventListener("pointermove",t=>{i||(i=!0,this._uiManager.toggleComment(this,!0,!1),this._onStartDragging());const{clientX:e,clientY:s,pointerId:n}=t;if(n!==this.#Fe)return void At(t);const[r,a]=this.screenToPageTranslation(e-this.#Ye,s-this.#Ke);this.#Ye=e,this.#Ke=s,this._uiManager.dragSelectedEditors(r,a)},r),window.addEventListener("touchmove",At,r),window.addEventListener("pointerdown",t=>{t.pointerType===this.#Oe&&(this.#Ze||t.isPrimary)&&a(t),At(t)},r));const o=t=>{this.#Fe&&this.#Fe!==t.pointerId?At(t):a(t)};window.addEventListener("pointerup",o,{signal:n}),window.addEventListener("blur",o,{signal:n})}_onStartDragging(){}_onStopDragging(){}moveInDOM(){this.#Xe&&clearTimeout(this.#Xe),this.#Xe=setTimeout(()=>{this.#Xe=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 s=this.parentScale,[n,r]=this.pageDimensions,[a,o]=this.pageTranslation,l=t/s,h=e/s,c=this.x*n,d=this.y*r,u=this.width*n,p=this.height*r;switch(i){case 0:return[c+l+a,r-d-h-p+o,c+l+u+a,r-d-h+o];case 90:return[c+h+a,r-d+l+o,c+h+p+a,r-d+l+u+o];case 180:return[c-l-u+a,r-d+h+o,c-l+a,r-d+h+p+o];case 270:return[c-h-p+a,r-d-l-u+o,c-h+a,r-d-l+o];default:throw new Error("Invalid rotation")}}getRectInCurrentCoords(t,e){const[i,s,n,r]=t,a=n-i,o=r-s;switch(this.rotation){case 0:return[i,e-r,a,o];case 90:return[i,e-s,o,a];case 180:return[n,e-s,a,o];case 270:return[n,e-r,o,a];default:throw new Error("Invalid rotation")}}getPDFRect(){return this.getRect(0,0)}getNonHCMColor(){return this.color&&ie._colorManager.convert(this._uiManager.getNonHCMColor(this.color))}onUpdatedColor(){this.#l?.onUpdatedColor()}getData(){const{comment:{text:t,color:e,date:i,opacity:s,deleted:n,richText:r},uid:a,pageIndex:o,creationDate:l,modificationDate:h}=this;return{id:a,pageIndex:o,rect:this.getPDFRect(),richText:r,contentsObj:{str:t},creationDate:l,modificationDate:i||h,popupRef:!n,color:e,opacity:s}}onceAdded(t){}isEmpty(){return!1}enableEditMode(){return!this.isInEditMode()&&(this.parent.setEditingState(!1),this.#Ve=!0,!0)}disableEditMode(){return!!this.isInEditMode()&&(this.parent.setEditingState(!0),this.#Ve=!1,!0)}isInEditMode(){return this.#Ve}shouldGetKeyboardEvents(){return this.#qe}needsToBeRebuilt(){return this.div&&!this.isAttachedToDOM}get isOnScreen(){const{top:t,left:e,bottom:i,right:s}=this.getClientDimensions(),{innerHeight:n,innerWidth:r}=window;return e<r&&s>0&&t<n&&i>0}#ci(){if(this.#ze||!this.div)return;this.#ze=new AbortController;const t=this._uiManager.combinedSignal(this.#ze);this.div.addEventListener("focusin",this.focusin.bind(this),{signal:t}),this.div.addEventListener("focusout",this.focusout.bind(this),{signal:t})}rebuild(){this.#ci()}rotate(t){}resize(){}serializeDeleted(){return{id:this.annotationElementId,deleted:!0,pageIndex:this.pageIndex,popupRef:this._initialData?.popupRef||""}}serialize(t=!1,e=null){return{annotationType:this.mode,pageIndex:this.pageIndex,rect:this.getPDFRect(),rotation:this.rotation,structTreeParentId:this._structTreeParentId,popupRef:this._initialData?.popupRef||""}}static async deserialize(t,e,i){const s=new this.prototype.constructor({parent:e,id:e.getNextId(),uiManager:i,annotationElementId:t.annotationElementId,creationDate:t.creationDate,modificationDate:t.modificationDate});s.rotation=t.rotation,s.#ke=t.accessibilityData,s._isCopy=t.isCopy||!1;const[n,r]=s.pageDimensions,[a,o,l,h]=s.getRectInCurrentCoords(t.rect,r);return s.x=a/n,s.y=o/r,s.width=l/n,s.height=h/r,s}get hasBeenModified(){return!!this.annotationElementId&&(this.deleted||null!==this.serialize())}remove(){if(this.#ze?.abort(),this.#ze=null,this.isEmpty()||this.commit(),this.parent?this.parent.remove(this):this._uiManager.removeEditor(this),this.hideCommentPopup(),this.#Xe&&(clearTimeout(this.#Xe),this.#Xe=null),this.#ei(),this.removeEditToolbar(),this.#Qe){for(const t of this.#Qe.values())clearTimeout(t);this.#Qe=null}this.parent=null,this.#Ze?.destroy(),this.#Ze=null,this.#je?.remove(),this.#je=null}get isResizable(){return!1}makeResizable(){this.isResizable&&(this.#ri(),this.#Be.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,s,n,r]=this.getPDFRect();return[ie._round(i+(n-i)*t),ie._round(s+(r-s)*(1-e))]}get commentButtonColor(){return this._uiManager.makeCommentColor(this.getNonHCMColor(),this.opacity)}get commentPopupPosition(){return this.#l.commentPopupPositionInLayer}set commentPopupPosition(t){this.#l.commentPopupPositionInLayer=t}hasDefaultPopupPosition(){return this.#l.hasDefaultPopupPosition()}get commentButtonWidth(){return this.#l.commentButtonWidth}get elementBeforePopup(){return this.div}setCommentButtonStates(t){this.#l?.setCommentButtonStates(t)}keydown(t){if(!this.isResizable||t.target!==this.div||"Enter"!==t.key)return;this._uiManager.setSelected(this),this.#Ue={savedX:this.x,savedY:this.y,savedWidth:this.width,savedHeight:this.height};const e=this.#Be.children;if(!this.#Re){this.#Re=Array.from(e);const t=this.#fi.bind(this),i=this.#bi.bind(this),s=this._uiManager._signal;for(const e of this.#Re){const n=e.getAttribute("data-resizer-name");e.setAttribute("role","spinbutton"),e.addEventListener("keydown",t,{signal:s}),e.addEventListener("blur",i,{signal:s}),e.addEventListener("focus",this.#vi.bind(this,n),{signal:s}),e.setAttribute("data-l10n-id",ie._l10nResizer[n])}}const i=this.#Re[0];let s=0;for(const r of e){if(r===i)break;s++}const n=(360-this.rotation+this.parentRotation)%360/90*(this.#Re.length/4);if(n!==s){if(n<s)for(let e=0;e<s-n;e++)this.#Be.append(this.#Be.firstElementChild);else if(n>s)for(let e=0;e<n-s;e++)this.#Be.firstElementChild.before(this.#Be.lastElementChild);let t=0;for(const i of e){const e=this.#Re[t++],s=e.getAttribute("data-resizer-name");i.setAttribute("data-l10n-id",ie._l10nResizer[s])}}this.#yi(0),this.#qe=!0,this.#Be.firstElementChild.focus({focusVisible:!0}),t.preventDefault(),t.stopImmediatePropagation()}#fi(t){ie._resizerKeyboardManager.exec(this,t)}#bi(t){this.#qe&&t.relatedTarget?.parentNode!==this.#Be&&this.#ei()}#vi(t){this.#He=this.#qe?t:""}#yi(t){if(this.#Re)for(const e of this.#Re)e.tabIndex=t}_resizeWithKeyboard(t,e){this.#qe&&this.#oi(this.#He,{deltaX:t,deltaY:e,fromKeyboard:!0})}#ei(){this.#qe=!1,this.#yi(-1),this.#li()}_stopResizingWithKeyboard(){this.#ei(),this.div.focus()}select(){this.isSelected&&this._editToolbar?this._editToolbar.show():(this.isSelected=!0,this.makeResizable(),this.div?.classList.add("selectedEditor"),this._editToolbar?(this._editToolbar?.show(),this.#o?.toggleAltTextBadge(!1)):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(){this.isSelected&&(this.isSelected=!1,this.#Be?.classList.add("hidden"),this.div?.classList.remove("selectedEditor"),this.div?.contains(document.activeElement)&&this._uiManager.currentLayer.div.focus({preventScroll:!0}),this._editToolbar?.hide(),this.#o?.toggleAltTextBadge(!0),this.hideCommentPopup())}hideCommentPopup(){this.hasComment&&this._uiManager.toggleComment(null)}updateParams(t,e){}disableEditing(){}enableEditing(){}get canChangeContent(){return!1}enterInEditMode(){this.canChangeContent&&(this.enableEditMode(),this.div.focus())}dblclick(t){"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.#We}set isEditing(t){this.#We=t,this.parent&&(t?(this.parent.setSelected(this),this.parent.setActiveEditor(this)):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.#Qe||=new Map;const{action:e}=t;let i=this.#Qe.get(e);return i&&clearTimeout(i),i=setTimeout(()=>{this._reportTelemetry(t),this.#Qe.delete(e),0===this.#Qe.size&&(this.#Qe=null)},ie._telemetryTimeout),void this.#Qe.set(e,i)}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.#je||this.deleted)return this.deleted?(this.#je.remove(),void(this.#je=null)):void((this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized)&&this.#je.updateEdited({rect:this.getPDFRect(),popup:this.comment}));this.#je=t.addFakeAnnotation(this)}renderAnnotationElement(t){if(this.deleted)return t.hide(),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 se extends ie{constructor(t){super(t),this.annotationElementId=t.annotationElementId,this.deleted=!0}serialize(){return this.serializeDeleted()}}const ne=3285377520,re=4294901760,ae=65535;class oe{constructor(t){this.h1=t?4294967295&t:ne,this.h2=t?4294967295&t:ne}update(t){let e,i;if("string"===typeof t){e=new Uint8Array(2*t.length),i=0;for(let s=0,n=t.length;s<n;s++){const n=t.charCodeAt(s);n<=255?e[i++]=n:(e[i++]=n>>>8,e[i++]=255&n)}}else{if(!ArrayBuffer.isView(t))throw new Error("Invalid data format, must be a string or TypedArray.");e=t.slice(),i=e.byteLength}const s=i>>2,n=i-4*s,r=new Uint32Array(e.buffer,0,s);let a=0,o=0,l=this.h1,h=this.h2;const c=3432918353,d=461845907,u=c&ae,p=d&ae;for(let g=0;g<s;g++)1&g?(a=r[g],a=a*c&re|a*u&ae,a=a<<15|a>>>17,a=a*d&re|a*p&ae,l^=a,l=l<<13|l>>>19,l=5*l+3864292196):(o=r[g],o=o*c&re|o*u&ae,o=o<<15|o>>>17,o=o*d&re|o*p&ae,h^=o,h=h<<13|h>>>19,h=5*h+3864292196);switch(a=0,n){case 3:a^=e[4*s+2]<<16;case 2:a^=e[4*s+1]<<8;case 1:a^=e[4*s],a=a*c&re|a*u&ae,a=a<<15|a>>>17,a=a*d&re|a*p&ae,1&s?l^=a:h^=a}this.h1=l,this.h2=h}hexdigest(){let t=this.h1,e=this.h2;return t^=e>>>1,t=3981806797*t&re|36045*t&ae,e=4283543511*e&re|(2950163797*(e<<16|t>>>16)&re)>>>16,t^=e>>>1,t=444984403*t&re|60499*t&ae,e=3301882366*e&re|(3120437893*(e<<16|t>>>16)&re)>>>16,t^=e>>>1,(t>>>0).toString(16).padStart(8,"0")+(e>>>0).toString(16).padStart(8,"0")}}const le=Object.freeze({map:null,hash:"",transfer:void 0});class he{#wi=!1;#Ai=null;#xi=null;#_i=new Map;constructor(){this.onSetModified=null,this.onResetModified=null,this.onAnnotationEditor=null}getValue(t,e){const i=this.#_i.get(t);return void 0===i?e:Object.assign(e,i)}getRawValue(t){return this.#_i.get(t)}remove(t){const e=this.#_i.get(t);if(void 0!==e&&(e instanceof ie&&this.#xi.delete(e.annotationElementId),this.#_i.delete(t),0===this.#_i.size&&this.resetModified(),"function"===typeof this.onAnnotationEditor)){for(const t of this.#_i.values())if(t instanceof ie)return;this.onAnnotationEditor(null)}}setValue(t,e){const i=this.#_i.get(t);let s=!1;if(void 0!==i)for(const[n,r]of Object.entries(e))i[n]!==r&&(s=!0,i[n]=r);else s=!0,this.#_i.set(t,e);s&&this.#Si(),e instanceof ie&&((this.#xi||=new Map).set(e.annotationElementId,e),"function"===typeof this.onAnnotationEditor&&this.onAnnotationEditor(e.constructor._type))}has(t){return this.#_i.has(t)}get size(){return this.#_i.size}#Si(){this.#wi||(this.#wi=!0,"function"===typeof this.onSetModified&&this.onSetModified())}resetModified(){this.#wi&&(this.#wi=!1,"function"===typeof this.onResetModified&&this.onResetModified())}get print(){return new ce(this)}get serializable(){if(0===this.#_i.size)return le;const t=new Map,e=new oe,i=[],s=Object.create(null);let n=!1;for(const[r,a]of this.#_i){const i=a instanceof ie?a.serialize(!1,s):a;i&&(t.set(r,i),e.update(`${r}:${JSON.stringify(i)}`),n||=!!i.bitmap)}if(n)for(const r of t.values())r.bitmap&&i.push(r.bitmap);return t.size>0?{map:t,hash:e.hexdigest(),transfer:i}:le}get editorStats(){let t=null;const e=new Map;let i=0,s=0;for(const n of this.#_i.values()){if(!(n instanceof ie)){n.popup&&(n.popup.deleted?s+=1:i+=1);continue}n.isCommentDeleted?s+=1:n.hasEditedComment&&(i+=1);const r=n.telemetryFinalData;if(!r)continue;const{type:a}=r;e.has(a)||e.set(a,Object.getPrototypeOf(n).constructor),t||=Object.create(null);const o=t[a]||=new Map;for(const[t,e]of Object.entries(r)){if("type"===t)continue;let i=o.get(t);i||(i=new Map,o.set(t,i));const s=i.get(e)??0;i.set(e,s+1)}}if((s>0||i>0)&&(t||=Object.create(null),t.comments={deleted:s,edited:i}),!t)return null;for(const[n,r]of e)t[n]=r.computeTelemetryFinalData(t[n]);return t}resetModifiedIds(){this.#Ai=null}updateEditor(t,e){const i=this.#xi?.get(t);return!!i&&(i.updateFromAnnotationLayer(e),!0)}getEditor(t){return this.#xi?.get(t)||null}get modifiedIds(){if(this.#Ai)return this.#Ai;const t=[];if(this.#xi)for(const e of this.#xi.values())e.serialize()&&t.push(e.annotationElementId);return this.#Ai={ids:new Set(t),hash:t.join(",")}}[Symbol.iterator](){return this.#_i.entries()}}class ce extends he{#Ei;constructor(t){super();const{map:e,hash:i,transfer:s}=t.serializable,n=structuredClone(e,s?{transfer:s}:null);this.#Ei={map:n,hash:i,transfer:s}}get print(){P("Should not call PrintAnnotationStorage.print")}get serializable(){return this.#Ei}get modifiedIds(){return F(this,"modifiedIds",{ids:new Set,hash:""})}}class de{#Ci=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){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.#Ci.clear(),this.styleElement&&(this.styleElement.remove(),this.styleElement=null)}async loadSystemFont({systemFontInfo:t,disableFontFace:e,_inspectFont:i}){if(t&&!this.#Ci.has(t.loadedName)){if(I(!e,"loadSystemFont shouldn't be called when `disableFontFace` is set."),this.isFontLoadingAPISupported){const{loadedName:e,src:s,style:n}=t,r=new FontFace(e,s,n);this.addNativeFontFace(r);try{await r.load(),this.#Ci.add(e),i?.(t)}catch{D(`Cannot load system font: ${t.baseFontName}, installing it could help to improve PDF rendering.`),this.removeNativeFontFace(r)}return}P("Not implemented: loadSystemFont without the Font Loading API.")}}async bind(t){if(t.attached||t.missingFile&&!t.systemFontInfo)return;if(t.attached=!0,t.systemFontInfo)return void await this.loadSystemFont(t);if(this.isFontLoadingAPISupported){const e=t.createNativeFontFace();if(e){this.addNativeFontFace(e);try{await e.loaded}catch(i){throw D(`Failed to load font '${e.family}': '${i}'.`),t.disableFontFace=!0,i}}return}const e=t.createFontFaceRule();if(e){if(this.insertRule(e),this.isSyncFontLoadingSupported)return;await new Promise(e=>{const i=this._queueLoadingCallback(e);this._prepareFontLoadEvent(t,i)})}}get isFontLoadingAPISupported(){const t=!!this._document?.fonts;return F(this,"isFontLoadingAPISupported",t)}get isSyncFontLoadingSupported(){return F(this,"isSyncFontLoadingSupported",o||X.platform.isFirefox)}_queueLoadingCallback(t){function e(){I(!s.done,"completeRequest() cannot be called twice."),s.done=!0;while(i.length>0&&i[0].done){const t=i.shift();setTimeout(t.callback,0)}}const{loadingRequests:i}=this,s={done:!1,complete:e,callback:t};return i.push(s),s}get _loadTestFont(){const t=atob("T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQAABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwAAAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbmFtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAAAADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6AABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAAMQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAAAAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAAAAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQAAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMAAQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAAEAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgcA/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQAAAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAgABAAAAAAAAAAAD6AAAAAAAAA==");return F(this,"_loadTestFont",t)}_prepareFontLoadEvent(t,e){function i(t,e){return t.charCodeAt(e)<<24|t.charCodeAt(e+1)<<16|t.charCodeAt(e+2)<<8|255&t.charCodeAt(e+3)}function s(t,e,i,s){const n=t.substring(0,e),r=t.substring(e+i);return n+s+r}let n,r;const a=this._document.createElement("canvas");a.width=1,a.height=1;const o=a.getContext("2d");let l=0;function h(t,e){if(++l>30)return D("Load test font never loaded."),void e();o.font="30px "+t,o.fillText(".",0,20);const i=o.getImageData(0,0,1,1);i.data[3]>0?e():setTimeout(h.bind(null,t,e))}const c=`lt${Date.now()}${this.loadTestFontId++}`;let d=this._loadTestFont;const u=976;d=s(d,u,c.length,c);const p=16,g=1482184792;let m=i(d,p);for(n=0,r=c.length-3;n<r;n+=4)m=m-g+i(c,n)|0;n<c.length&&(m=m-g+i(c+"XXX",n)|0),d=s(d,p,4,W(m));const f=`url(data:font/opentype;base64,${btoa(d)});`,b=`@font-face {font-family:"${c}";src:${f}}`;this.insertRule(b);const v=this._document.createElement("div");v.style.visibility="hidden",v.style.width=v.style.height="10px",v.style.position="absolute",v.style.top=v.style.left="0px";for(const y of[t.loadedName,c]){const t=this._document.createElement("span");t.textContent="Hi",t.style.fontFamily=y,v.append(t)}this._document.body.append(v),h(c,()=>{v.remove(),e.complete()})}}class ue{#Ti;constructor(t,e=null,i,s){this.compiledGlyphs=Object.create(null),this.#Ti=t,this._inspectFont=e,i&&Object.assign(this,i),s&&(this.charProcOperatorList=s)}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,{});return this._inspectFont?.(this),t}createFontFaceRule(){if(!this.data||this.disableFontFace)return null;const t=`url(data:${this.mimetype};base64,${rt(this.data)});`;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}}`;return this._inspectFont?.(this,t),e}getPathGenerator(t,e){if(void 0!==this.compiledGlyphs[e])return this.compiledGlyphs[e];const i=this.loadedName+"_path_"+e;let s;try{s=t.get(i)}catch(r){D(`getPathGenerator - ignoring character: "${r}".`)}const n=Ht(s?.path);return this.fontExtraProperties||t.delete(i),this.compiledGlyphs[e]=n}get black(){return this.#Ti.black}get bold(){return this.#Ti.bold}get disableFontFace(){return this.#Ti.disableFontFace??!1}set disableFontFace(t){F(this,"disableFontFace",!!t)}get fontExtraProperties(){return this.#Ti.fontExtraProperties??!1}get isInvalidPDFjsFont(){return this.#Ti.isInvalidPDFjsFont}get isType3Font(){return this.#Ti.isType3Font}get italic(){return this.#Ti.italic}get missingFile(){return this.#Ti.missingFile}get remeasure(){return this.#Ti.remeasure}get vertical(){return this.#Ti.vertical}get ascent(){return this.#Ti.ascent}get defaultWidth(){return this.#Ti.defaultWidth}get descent(){return this.#Ti.descent}get bbox(){return this.#Ti.bbox}set bbox(t){F(this,"bbox",t)}get fontMatrix(){return this.#Ti.fontMatrix}get fallbackName(){return this.#Ti.fallbackName}get loadedName(){return this.#Ti.loadedName}get mimetype(){return this.#Ti.mimetype}get name(){return this.#Ti.name}get data(){return this.#Ti.data}clearData(){this.#Ti.clearData()}get cssFontInfo(){return this.#Ti.cssFontInfo}get systemFontInfo(){return this.#Ti.systemFontInfo}get defaultVMetrics(){return this.#Ti.defaultVMetrics}}class pe{#Mi;#Di;#Pi;static strings=["fontFamily","fontWeight","italicAngle"];static write(t){const e=new TextEncoder,i={};let s=0;for(const l of pe.strings){const n=e.encode(t[l]);i[l]=n,s+=4+n.length}const n=new ArrayBuffer(s),r=new Uint8Array(n),a=new DataView(n);let o=0;for(const l of pe.strings){const t=i[l],e=t.length;a.setUint32(o,e),r.set(t,o+4),o+=4+e}return I(o===n.byteLength,"CssFontInfo.write: Buffer overflow"),n}constructor(t){this.#Mi=t,this.#Di=new DataView(this.#Mi),this.#Pi=new TextDecoder}#Ii(t){I(t<pe.strings.length,"Invalid string index");let e=0;for(let s=0;s<t;s++)e+=this.#Di.getUint32(e)+4;const i=this.#Di.getUint32(e);return this.#Pi.decode(new Uint8Array(this.#Mi,e+4,i))}get fontFamily(){return this.#Ii(0)}get fontWeight(){return this.#Ii(1)}get italicAngle(){return this.#Ii(2)}}class ge{#Mi;#Di;#Pi;static strings=["css","loadedName","baseFontName","src"];static write(t){const e=new TextEncoder,i={};let s=0;for(const d of ge.strings){const n=e.encode(t[d]);i[d]=n,s+=4+n.length}s+=4;let n,r,a=1+s;t.style&&(n=e.encode(t.style.style),r=e.encode(t.style.weight),a+=4+n.length+4+r.length);const o=new ArrayBuffer(a),l=new Uint8Array(o),h=new DataView(o);let c=0;h.setUint8(c++,t.guessFallback?1:0),h.setUint32(c,0),c+=4,s=0;for(const d of ge.strings){const t=i[d],e=t.length;s+=4+e,h.setUint32(c,e),l.set(t,c+4),c+=4+e}return h.setUint32(c-s-4,s),t.style&&(h.setUint32(c,n.length),l.set(n,c+4),c+=4+n.length,h.setUint32(c,r.length),l.set(r,c+4),c+=4+r.length),I(c<=o.byteLength,"SubstitionInfo.write: Buffer overflow"),o.transferToFixedLength(c)}constructor(t){this.#Mi=t,this.#Di=new DataView(this.#Mi),this.#Pi=new TextDecoder}get guessFallback(){return 0!==this.#Di.getUint8(0)}#Ii(t){I(t<ge.strings.length,"Invalid string index");let e=5;for(let s=0;s<t;s++)e+=this.#Di.getUint32(e)+4;const i=this.#Di.getUint32(e);return this.#Pi.decode(new Uint8Array(this.#Mi,e+4,i))}get css(){return this.#Ii(0)}get loadedName(){return this.#Ii(1)}get baseFontName(){return this.#Ii(2)}get src(){return this.#Ii(3)}get style(){let t=1;t+=4+this.#Di.getUint32(t);const e=this.#Di.getUint32(t),i=this.#Pi.decode(new Uint8Array(this.#Mi,t+4,e));t+=4+e;const s=this.#Di.getUint32(t),n=this.#Pi.decode(new Uint8Array(this.#Mi,t+4,s));return{style:i,weight:n}}}class me{static bools=["black","bold","disableFontFace","fontExtraProperties","isInvalidPDFjsFont","isType3Font","italic","missingFile","remeasure","vertical"];static numbers=["ascent","defaultWidth","descent"];static strings=["fallbackName","loadedName","mimetype","name"];static#ki=Math.ceil(2*this.bools.length/8);static#Ri=this.#ki+8*this.numbers.length;static#Li=this.#Ri+1+8;static#Fi=this.#Li+1+48;static#Oi=this.#Fi+1+6;#Mi;#Pi;#Di;constructor({data:t,extra:e}){this.#Mi=t,this.#Pi=new TextDecoder,this.#Di=new DataView(this.#Mi),e&&Object.assign(this,e)}#Bi(t){I(t<me.bools.length,"Invalid boolean index");const e=Math.floor(t/4),i=2*t%8,s=this.#Di.getUint8(e)>>i&3;return 0===s?void 0:2===s}get black(){return this.#Bi(0)}get bold(){return this.#Bi(1)}get disableFontFace(){return this.#Bi(2)}get fontExtraProperties(){return this.#Bi(3)}get isInvalidPDFjsFont(){return this.#Bi(4)}get isType3Font(){return this.#Bi(5)}get italic(){return this.#Bi(6)}get missingFile(){return this.#Bi(7)}get remeasure(){return this.#Bi(8)}get vertical(){return this.#Bi(9)}#Ni(t){return I(t<me.numbers.length,"Invalid number index"),this.#Di.getFloat64(me.#ki+8*t)}get ascent(){return this.#Ni(0)}get defaultWidth(){return this.#Ni(1)}get descent(){return this.#Ni(2)}get bbox(){let t=me.#Ri;const e=this.#Di.getUint8(t);if(0===e)return;t+=1;const i=[];for(let s=0;s<4;s++)i.push(this.#Di.getInt16(t,!0)),t+=2;return i}get fontMatrix(){let t=me.#Li;const e=this.#Di.getUint8(t);if(0===e)return;t+=1;const i=[];for(let s=0;s<6;s++)i.push(this.#Di.getFloat64(t,!0)),t+=8;return i}get defaultVMetrics(){let t=me.#Fi;const e=this.#Di.getUint8(t);if(0===e)return;t+=1;const i=[];for(let s=0;s<3;s++)i.push(this.#Di.getInt16(t,!0)),t+=2;return i}#Ii(t){I(t<me.strings.length,"Invalid string index");let e=me.#Oi+4;for(let n=0;n<t;n++)e+=this.#Di.getUint32(e)+4;const i=this.#Di.getUint32(e),s=new Uint8Array(i);return s.set(new Uint8Array(this.#Mi,e+4,i)),this.#Pi.decode(s)}get fallbackName(){return this.#Ii(0)}get loadedName(){return this.#Ii(1)}get mimetype(){return this.#Ii(2)}get name(){return this.#Ii(3)}get data(){let t=me.#Oi;const e=this.#Di.getUint32(t);t+=4+e;const i=this.#Di.getUint32(t);t+=4+i;const s=this.#Di.getUint32(t);t+=4+s;const n=this.#Di.getUint32(t);if(0!==n)return new Uint8Array(this.#Mi,t+4,n)}clearData(){let t=me.#Oi;const e=this.#Di.getUint32(t);t+=4+e;const i=this.#Di.getUint32(t);t+=4+i;const s=this.#Di.getUint32(t);t+=4+s;const n=this.#Di.getUint32(t),r=new Uint8Array(this.#Mi,t+4,n);r.fill(0),this.#Di.setUint32(t,0)}get cssFontInfo(){let t=me.#Oi;const e=this.#Di.getUint32(t);t+=4+e;const i=this.#Di.getUint32(t);t+=4+i;const s=this.#Di.getUint32(t);if(0===s)return null;const n=new Uint8Array(s);return n.set(new Uint8Array(this.#Mi,t+4,s)),new pe(n.buffer)}get systemFontInfo(){let t=me.#Oi;const e=this.#Di.getUint32(t);t+=4+e;const i=this.#Di.getUint32(t);if(0===i)return null;const s=new Uint8Array(i);return s.set(new Uint8Array(this.#Mi,t+4,i)),new ge(s.buffer)}static write(t){const e=t.systemFontInfo?ge.write(t.systemFontInfo):null,i=t.cssFontInfo?pe.write(t.cssFontInfo):null,s=new TextEncoder,n={};let r=0;for(const g of me.strings)n[g]=s.encode(t[g]),r+=4+n[g].length;const a=me.#Oi+4+r+4+(e?e.byteLength:0)+4+(i?i.byteLength:0)+4+(t.data?t.data.length:0),o=new ArrayBuffer(a),l=new Uint8Array(o),h=new DataView(o);let c=0;const d=me.bools.length;let u=0,p=0;for(let g=0;g<d;g++){const e=t[me.bools[g]],i=void 0===e?0:e?2:1;u|=i<<p,p+=2,8!==p&&g!==d-1||(h.setUint8(c++,u),u=0,p=0)}I(c===me.#ki,"FontInfo.write: Boolean properties offset mismatch");for(const g of me.numbers)h.setFloat64(c,t[g]),c+=8;if(I(c===me.#Ri,"FontInfo.write: Number properties offset mismatch"),t.bbox){h.setUint8(c++,4);for(const e of t.bbox)h.setInt16(c,e,!0),c+=2}else h.setUint8(c++,0),c+=8;if(I(c===me.#Li,"FontInfo.write: BBox properties offset mismatch"),t.fontMatrix){h.setUint8(c++,6);for(const e of t.fontMatrix)h.setFloat64(c,e,!0),c+=8}else h.setUint8(c++,0),c+=48;if(I(c===me.#Fi,"FontInfo.write: FontMatrix properties offset mismatch"),t.defaultVMetrics){h.setUint8(c++,1);for(const e of t.defaultVMetrics)h.setInt16(c,e,!0),c+=2}else h.setUint8(c++,0),c+=6;I(c===me.#Oi,"FontInfo.write: DefaultVMetrics properties offset mismatch"),h.setUint32(me.#Oi,0),c+=4;for(const g of me.strings){const t=n[g],e=t.length;h.setUint32(c,e),l.set(t,c+4),c+=4+e}if(h.setUint32(me.#Oi,c-me.#Oi-4),e){const t=e.byteLength;h.setUint32(c,t),I(c+4+t<=o.byteLength,"FontInfo.write: Buffer overflow at systemFontInfo"),l.set(new Uint8Array(e),c+4),c+=4+t}else h.setUint32(c,0),c+=4;if(i){const t=i.byteLength;h.setUint32(c,t),I(c+4+t<=o.byteLength,"FontInfo.write: Buffer overflow at cssFontInfo"),l.set(new Uint8Array(i),c+4),c+=4+t}else h.setUint32(c,0),c+=4;return void 0===t.data?(h.setUint32(c,0),c+=4):(h.setUint32(c,t.data.length),l.set(t.data,c+4),c+=4+t.data.length),I(c<=o.byteLength,"FontInfo.write: Buffer overflow"),o.transferToFixedLength(c)}}class fe{static#Ui=0;static#ji=1;static#zi=2;static#Hi=3;static#$i=4;static#Gi=8;static#Wi=12;static#Vi=16;constructor(t){this.buffer=t,this.view=new DataView(t),this.data=new Uint8Array(t)}static write(t){let e,i=null,s=[],n=[],r=[],a=[],o=null,l=null;switch(t[0]){case"RadialAxial":e="axial"===t[1]?1:2,i=t[2],r=t[3],1===e?s.push(...t[4],...t[5]):s.push(t[4][0],t[4][1],t[6],t[5][0],t[5][1],t[7]);break;case"Mesh":e=3,o=t[1],s=t[2],n=t[3],a=t[4]||[],i=t[6],l=t[7];break;default:throw new Error(`Unsupported pattern type: ${t[0]}`)}const h=Math.floor(s.length/2),c=Math.floor(n.length/3),d=r.length,u=a.length;let p=0;for(const w of a)p+=1,p=4*Math.ceil(p/4),p+=4+4*w.coords.length,p+=4+4*w.colors.length,void 0!==w.verticesPerRow&&(p+=4);const g=20+8*h+3*c+8*d+(i?16:0)+(l?3:0)+p,m=new ArrayBuffer(g),f=new DataView(m),b=new Uint8Array(m);f.setUint8(fe.#Ui,e),f.setUint8(fe.#ji,i?1:0),f.setUint8(fe.#zi,l?1:0),f.setUint8(fe.#Hi,o),f.setUint32(fe.#$i,h,!0),f.setUint32(fe.#Gi,c,!0),f.setUint32(fe.#Wi,d,!0),f.setUint32(fe.#Vi,u,!0);let v=20;const y=new Float32Array(m,v,2*h);y.set(s),v+=8*h,b.set(n,v),v+=3*c;for(const[w,A]of r)f.setFloat32(v,w,!0),v+=4,f.setUint32(v,parseInt(A.slice(1),16),!0),v+=4;if(i)for(const w of i)f.setFloat32(v,w,!0),v+=4;l&&(b.set(l,v),v+=3);for(let w=0;w<a.length;w++){const t=a[w];f.setUint8(v,t.type),v+=1,v=4*Math.ceil(v/4),f.setUint32(v,t.coords.length,!0),v+=4;const e=new Int32Array(m,v,t.coords.length);e.set(t.coords),v+=4*t.coords.length,f.setUint32(v,t.colors.length,!0),v+=4;const i=new Int32Array(m,v,t.colors.length);i.set(t.colors),v+=4*t.colors.length,void 0!==t.verticesPerRow&&(f.setUint32(v,t.verticesPerRow,!0),v+=4)}return m}getIR(){const t=this.view,e=this.data[fe.#Ui],i=!!this.data[fe.#ji],s=!!this.data[fe.#zi],n=t.getUint32(fe.#$i,!0),r=t.getUint32(fe.#Gi,!0),a=t.getUint32(fe.#Wi,!0),o=t.getUint32(fe.#Vi,!0);let l=20;const h=new Float32Array(this.buffer,l,2*n);l+=8*n;const c=new Uint8Array(this.buffer,l,3*r);l+=3*r;const d=[];for(let m=0;m<a;++m){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;s&&(p=new Uint8Array(this.buffer,l,3),l+=3);const g=[];for(let m=0;m<o;++m){const e=t.getUint8(l);l+=1,l=4*Math.ceil(l/4);const i=t.getUint32(l,!0);l+=4;const s=new Int32Array(this.buffer,l,i);l+=4*i;const n=t.getUint32(l,!0);l+=4;const r=new Int32Array(this.buffer,l,n);l+=4*n;const a={type:e,coords:s,colors:r};e===f.LATTICE&&(a.verticesPerRow=t.getUint32(l,!0),l+=4),g.push(a)}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[fe.#Hi];let e=null;if(h.length>0){let t=h[0],i=h[0],s=h[1],n=h[1];for(let e=0;e<h.length;e+=2){const r=h[e],a=h[e+1];t=t>r?r:t,s=s>a?a:s,i=i<r?r:i,n=n<a?a:n}e=[t,s,i,n]}return["Mesh",t,h,c,g,e,u,p]}throw new Error(`Unsupported pattern kind: ${e}`)}}class be{static write(t){let e,i;return X.isFloat16ArraySupported?(i=new ArrayBuffer(2*t.length),e=new Float16Array(i)):(i=new ArrayBuffer(4*t.length),e=new Float32Array(i)),e.set(t),i}#Mi;constructor(t){this.#Mi=t}get path(){return X.isFloat16ArraySupported?new Float16Array(this.#Mi):new Float32Array(this.#Mi)}}function ve(t){if(t instanceof URL)return t.href;if("string"===typeof t){if(o)return t;const e=URL.parse(t,window.location);if(e)return e.href}throw new Error("Invalid PDF url data: either string or URL-object is expected in the url property.")}function ye(t){if(o&&"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 G(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.")}function we(t){if("string"!==typeof t)return null;if(t.endsWith("/"))return t;throw new Error(`Invalid factory url: "${t}" must include trailing slash.`)}const Ae=t=>"object"===typeof t&&Number.isInteger(t?.num)&&t.num>=0&&Number.isInteger(t?.gen)&&t.gen>=0,xe=t=>"object"===typeof t&&"string"===typeof t?.name,_e=st.bind(null,Ae,xe);class Se{#qi=new Map;#Xi=Promise.resolve();postMessage(t,e){const i={data:structuredClone(t,e?{transfer:e}:null)};this.#Xi.then(()=>{for(const[t]of this.#qi)t.call(this,i)})}addEventListener(t,e,i=null){let s=null;if(i?.signal instanceof AbortSignal){const{signal:n}=i;if(n.aborted)return void D("LoopbackPort - cannot use an `aborted` signal.");const r=()=>this.removeEventListener(t,e);s=()=>n.removeEventListener("abort",r),n.addEventListener("abort",r)}this.#qi.set(e,s)}removeEventListener(t,e){const i=this.#qi.get(e);i?.(),this.#qi.delete(e)}terminate(){for(const[,t]of this.#qi)t?.();this.#qi.clear()}}const Ee={DATA:1,ERROR:2},Ce={CANCEL:1,CANCEL_COMPLETE:2,CLOSE:3,ENQUEUE:4,ERROR:5,PULL:6,PULL_COMPLETE:7,START_COMPLETE:8};function Te(){}function Me(t){if(t instanceof H||t instanceof U||t instanceof B||t instanceof j||t instanceof N)return t;switch(t instanceof Error||"object"===typeof t&&null!==t||P('wrapReason: Expected "reason" to be a (possibly cloned) Error.'),t.name){case"AbortException":return new H(t.message);case"InvalidPDFException":return new U(t.message);case"PasswordException":return new B(t.message,t.code);case"ResponseException":return new j(t.message,t.status,t.missing);case"UnknownErrorException":return new N(t.message,t.details)}return new N(t.message,t.toString())}class De{#Yi=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.#Ki.bind(this),{signal:this.#Yi.signal})}#Ki({data:t}){if(t.targetName!==this.sourceName)return;if(t.stream)return void this.#Qi(t);if(t.callback){const e=t.callbackId,i=this.callbackCapabilities[e];if(!i)throw new Error(`Cannot resolve callback ${e}`);if(delete this.callbackCapabilities[e],t.callback===Ee.DATA)i.resolve(t.data);else{if(t.callback!==Ee.ERROR)throw new Error("Unexpected callback case");i.reject(Me(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,s=t.sourceName,n=this.comObj;return void Promise.try(e,t.data).then(function(e){n.postMessage({sourceName:i,targetName:s,callback:Ee.DATA,callbackId:t.callbackId,data:e})},function(e){n.postMessage({sourceName:i,targetName:s,callback:Ee.ERROR,callbackId:t.callbackId,reason:Me(e)})})}t.streamId?this.#Zi(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 s=this.callbackId++,n=Promise.withResolvers();this.callbackCapabilities[s]=n;try{this.comObj.postMessage({sourceName:this.sourceName,targetName:this.targetName,action:t,callbackId:s,data:e},i)}catch(r){n.reject(r)}return n.promise}sendWithStream(t,e,i,s){const n=this.streamId++,r=this.sourceName,a=this.targetName,o=this.comObj;return new ReadableStream({start:i=>{const l=Promise.withResolvers();return this.streamControllers[n]={controller:i,startCall:l,pullCall:null,cancelCall:null,isClosed:!1},o.postMessage({sourceName:r,targetName:a,action:t,streamId:n,data:e,desiredSize:i.desiredSize},s),l.promise},pull:t=>{const e=Promise.withResolvers();return this.streamControllers[n].pullCall=e,o.postMessage({sourceName:r,targetName:a,stream:Ce.PULL,streamId:n,desiredSize:t.desiredSize}),e.promise},cancel:t=>{I(t instanceof Error,"cancel must have a valid reason");const e=Promise.withResolvers();return this.streamControllers[n].cancelCall=e,this.streamControllers[n].isClosed=!0,o.postMessage({sourceName:r,targetName:a,stream:Ce.CANCEL,streamId:n,reason:Me(t)}),e.promise}},i)}#Zi(t){const e=t.streamId,i=this.sourceName,s=t.sourceName,n=this.comObj,r=this,a=this.actionHandler[t.action],o={enqueue(t,r=1,a){if(this.isCancelled)return;const o=this.desiredSize;this.desiredSize-=r,o>0&&this.desiredSize<=0&&(this.sinkCapability=Promise.withResolvers(),this.ready=this.sinkCapability.promise),n.postMessage({sourceName:i,targetName:s,stream:Ce.ENQUEUE,streamId:e,chunk:t},a)},close(){this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:i,targetName:s,stream:Ce.CLOSE,streamId:e}),delete r.streamSinks[e])},error(t){I(t instanceof Error,"error must have a valid reason"),this.isCancelled||(this.isCancelled=!0,n.postMessage({sourceName:i,targetName:s,stream:Ce.ERROR,streamId:e,reason:Me(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(){n.postMessage({sourceName:i,targetName:s,stream:Ce.START_COMPLETE,streamId:e,success:!0})},function(t){n.postMessage({sourceName:i,targetName:s,stream:Ce.START_COMPLETE,streamId:e,reason:Me(t)})})}#Qi(t){const e=t.streamId,i=this.sourceName,s=t.sourceName,n=this.comObj,r=this.streamControllers[e],a=this.streamSinks[e];switch(t.stream){case Ce.START_COMPLETE:t.success?r.startCall.resolve():r.startCall.reject(Me(t.reason));break;case Ce.PULL_COMPLETE:t.success?r.pullCall.resolve():r.pullCall.reject(Me(t.reason));break;case Ce.PULL:if(!a){n.postMessage({sourceName:i,targetName:s,stream:Ce.PULL_COMPLETE,streamId:e,success:!0});break}a.desiredSize<=0&&t.desiredSize>0&&a.sinkCapability.resolve(),a.desiredSize=t.desiredSize,Promise.try(a.onPull||Te).then(function(){n.postMessage({sourceName:i,targetName:s,stream:Ce.PULL_COMPLETE,streamId:e,success:!0})},function(t){n.postMessage({sourceName:i,targetName:s,stream:Ce.PULL_COMPLETE,streamId:e,reason:Me(t)})});break;case Ce.ENQUEUE:if(I(r,"enqueue should have stream controller"),r.isClosed)break;r.controller.enqueue(t.chunk);break;case Ce.CLOSE:if(I(r,"close should have stream controller"),r.isClosed)break;r.isClosed=!0,r.controller.close(),this.#Ji(r,e);break;case Ce.ERROR:I(r,"error should have stream controller"),r.controller.error(Me(t.reason)),this.#Ji(r,e);break;case Ce.CANCEL_COMPLETE:t.success?r.cancelCall.resolve():r.cancelCall.reject(Me(t.reason)),this.#Ji(r,e);break;case Ce.CANCEL:if(!a)break;const o=Me(t.reason);Promise.try(a.onCancel||Te,o).then(function(){n.postMessage({sourceName:i,targetName:s,stream:Ce.CANCEL_COMPLETE,streamId:e,success:!0})},function(t){n.postMessage({sourceName:i,targetName:s,stream:Ce.CANCEL_COMPLETE,streamId:e,reason:Me(t)})}),a.sinkCapability.reject(o),a.isCancelled=!0,delete this.streamSinks[e];break;default:throw new Error("Unexpected stream case")}}async#Ji(t,e){await Promise.allSettled([t.startCall?.promise,t.pullCall?.promise,t.cancelCall?.promise]),delete this.streamControllers[e]}destroy(){this.#Yi?.abort(),this.#Yi=null}}class Pe{#ts=!1;constructor({enableHWA:t=!1}){this.#ts=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.#ts})}}reset(t,e,i){if(!t.canvas)throw new Error("Canvas is not specified");if(e<=0||i<=0)throw new Error("Invalid canvas size");t.canvas.width=e,t.canvas.height=i}destroy(t){if(!t.canvas)throw new Error("Canvas is not specified");t.canvas.width=0,t.canvas.height=0,t.canvas=null,t.context=null}_createCanvas(t,e){P("Abstract method `_createCanvas` called.")}}class Ie extends Pe{constructor({ownerDocument:t=globalThis.document,enableHWA:e=!1}){super({enableHWA:e}),this._document=t}_createCanvas(t,e){const i=this._document.createElement("canvas");return i.width=t,i.height=e,i}}class ke{constructor({baseUrl:t=null,isCompressed:e=!0}){this.baseUrl=t,this.isCompressed=e}async fetch({name:t}){if(!this.baseUrl)throw new Error("Ensure that the `cMapUrl` and `cMapPacked` API parameters are provided.");if(!t)throw new Error("CMap name must be specified.");const e=this.baseUrl+t+(this.isCompressed?".bcmap":"");return this._fetch(e).then(t=>({cMapData:t,isCompressed:this.isCompressed})).catch(t=>{throw new Error(`Unable to load ${this.isCompressed?"binary ":""}CMap at: ${e}`)})}async _fetch(t){P("Abstract method `_fetch` called.")}}class Re extends ke{async _fetch(t){const e=await dt(t,this.isCompressed?"arraybuffer":"text");return e instanceof ArrayBuffer?new Uint8Array(e):G(e)}}class Le{addFilter(t){return"none"}addHCMFilter(t,e){return"none"}addAlphaFilter(t){return"none"}addLuminosityFilter(t){return"none"}addHighlightHCMFilter(t,e,i,s,n){return"none"}destroy(t=!1){}}class Fe extends Le{#es;#is;#ss;#ns;#rs;#as;#E=0;constructor({docId:t,ownerDocument:e=globalThis.document}){super(),this.#ns=t,this.#rs=e}get#T(){return this.#is||=new Map}get#os(){return this.#as||=new Map}get#ls(){if(!this.#ss){const t=this.#rs.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.#rs.createElementNS(ht,"svg");i.setAttribute("width",0),i.setAttribute("height",0),this.#ss=this.#rs.createElementNS(ht,"defs"),t.append(i),i.append(this.#ss),this.#rs.body.append(t)}return this.#ss}#hs(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 s=i.join(",");return[s,s,s]}const[e,i,s]=t,n=new Array(256),r=new Array(256),a=new Array(256);for(let o=0;o<256;o++)n[o]=e[o]/255,r[o]=i[o]/255,a[o]=s[o]/255;return[n.join(","),r.join(","),a.join(",")]}#cs(t){if(void 0===this.#es){this.#es="";const t=this.#rs.URL;t!==this.#rs.baseURI&&(gt(t)?D('#createUrl: ignore "data:"-URL for performance reasons.'):this.#es=L(t,""))}return`url(${this.#es}#${t})`}addFilter(t){if(!t)return"none";let e=this.#T.get(t);if(e)return e;const[i,s,n]=this.#hs(t),r=1===t.length?i:`${i}${s}${n}`;if(e=this.#T.get(r),e)return this.#T.set(t,e),e;const a=`g_${this.#ns}_transfer_map_${this.#E++}`,o=this.#cs(a);this.#T.set(t,o),this.#T.set(r,o);const l=this.#ds(a);return this.#us(i,s,n,l),o}addHCMFilter(t,e){const i=`${t}-${e}`,s="base";let n=this.#os.get(s);if(n?.key===i)return n.url;if(n?(n.filter?.remove(),n.key=i,n.url="none",n.filter=null):(n={key:i,url:"none",filter:null},this.#os.set(s,n)),!t||!e)return n.url;const r=this.#ps(t);t=K.makeHexColor(...r);const a=this.#ps(e);if(e=K.makeHexColor(...a),this.#ls.style.color="","#000000"===t&&"#ffffff"===e||t===e)return n.url;const o=new Array(256);for(let u=0;u<=255;u++){const t=u/255;o[u]=t<=.03928?t/12.92:((t+.055)/1.055)**2.4}const l=o.join(","),h=`g_${this.#ns}_hcm_filter`,c=n.filter=this.#ds(h);this.#us(l,l,l,c),this.#gs(c);const d=(t,e)=>{const i=r[t]/255,s=a[t]/255,n=new Array(e+1);for(let r=0;r<=e;r++)n[r]=i+r/e*(s-i);return n.join(",")};return this.#us(d(0,5),d(1,5),d(2,5),c),n.url=this.#cs(h),n.url}addAlphaFilter(t){let e=this.#T.get(t);if(e)return e;const[i]=this.#hs([t]),s=`alpha_${i}`;if(e=this.#T.get(s),e)return this.#T.set(t,e),e;const n=`g_${this.#ns}_alpha_map_${this.#E++}`,r=this.#cs(n);this.#T.set(t,r),this.#T.set(s,r);const a=this.#ds(n);return this.#ms(i,a),r}addLuminosityFilter(t){let e,i,s=this.#T.get(t||"luminosity");if(s)return s;if(t?([e]=this.#hs([t]),i=`luminosity_${e}`):i="luminosity",s=this.#T.get(i),s)return this.#T.set(t,s),s;const n=`g_${this.#ns}_luminosity_map_${this.#E++}`,r=this.#cs(n);this.#T.set(t,r),this.#T.set(i,r);const a=this.#ds(n);return this.#fs(a),t&&this.#ms(e,a),r}addHighlightHCMFilter(t,e,i,s,n){const r=`${e}-${i}-${s}-${n}`;let a=this.#os.get(t);if(a?.key===r)return a.url;if(a?(a.filter?.remove(),a.key=r,a.url="none",a.filter=null):(a={key:r,url:"none",filter:null},this.#os.set(t,a)),!e||!i)return a.url;const[o,l]=[e,i].map(this.#ps.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]=[s,n].map(this.#ps.bind(this));c<h&&([h,c,d,u]=[c,h,u,d]),this.#ls.style.color="";const p=(t,e,i)=>{const s=new Array(256),n=(c-h)/i,r=t/255,a=(e-t)/(255*i);let o=0;for(let l=0;l<=i;l++){const t=Math.round(h+l*n),e=r+l*a;for(let i=o;i<=t;i++)s[i]=e;o=t+1}for(let l=o;l<256;l++)s[l]=s[o-1];return s.join(",")},g=`g_${this.#ns}_hcm_${t}_filter`,m=a.filter=this.#ds(g);return this.#gs(m),this.#us(p(d[0],u[0],5),p(d[1],u[1],5),p(d[2],u[2],5),m),a.url=this.#cs(g),a.url}destroy(t=!1){t&&this.#as?.size||(this.#ss?.parentNode.parentNode.remove(),this.#ss=null,this.#is?.clear(),this.#is=null,this.#as?.clear(),this.#as=null,this.#E=0)}#fs(t){const e=this.#rs.createElementNS(ht,"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)}#gs(t){const e=this.#rs.createElementNS(ht,"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)}#ds(t){const e=this.#rs.createElementNS(ht,"filter");return e.setAttribute("color-interpolation-filters","sRGB"),e.setAttribute("id",t),this.#ls.append(e),e}#bs(t,e,i){const s=this.#rs.createElementNS(ht,e);s.setAttribute("type","discrete"),s.setAttribute("tableValues",i),t.append(s)}#us(t,e,i,s){const n=this.#rs.createElementNS(ht,"feComponentTransfer");s.append(n),this.#bs(n,"feFuncR",t),this.#bs(n,"feFuncG",e),this.#bs(n,"feFuncB",i)}#ms(t,e){const i=this.#rs.createElementNS(ht,"feComponentTransfer");e.append(i),this.#bs(i,"feFuncA",t)}#ps(t){return this.#ls.style.color=t,Et(getComputedStyle(this.#ls).getPropertyValue("color"))}}class Oe{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `standardFontDataUrl` API parameter is provided.");if(!t)throw new Error("Font filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch(t=>{throw new Error(`Unable to load font data at: ${e}`)})}async _fetch(t){P("Abstract method `_fetch` called.")}}class Be extends Oe{async _fetch(t){const e=await dt(t,"arraybuffer");return new Uint8Array(e)}}class Ne{constructor({baseUrl:t=null}){this.baseUrl=t}async fetch({filename:t}){if(!this.baseUrl)throw new Error("Ensure that the `wasmUrl` API parameter is provided.");if(!t)throw new Error("Wasm filename must be specified.");const e=`${this.baseUrl}${t}`;return this._fetch(e).catch(t=>{throw new Error(`Unable to load wasm data at: ${e}`)})}async _fetch(t){P("Abstract method `_fetch` called.")}}class Ue extends Ne{async _fetch(t){const e=await dt(t,"arraybuffer");return new Uint8Array(e)}}async function je(t){const e=process.getBuiltinModule("fs"),i=await e.promises.readFile(t);return new Uint8Array(i)}o&&D("Please use the `legacy` build in Node.js environments.");class ze extends Le{}class He extends Pe{_createCanvas(t,e){const i=process.getBuiltinModule("module").createRequire("file:///home/runner/work/pdf-elements/pdf-elements/node_modules/pdfjs-dist/build/pdf.mjs"),s=i("@napi-rs/canvas");return s.createCanvas(t,e)}}class $e extends ke{async _fetch(t){return je(t)}}class Ge extends Oe{async _fetch(t){return je(t)}}class We extends Ne{async _fetch(t){return je(t)}}const Ve="__forcedDependency",{floor:qe,ceil:Xe}=Math;function Ye(t,e,i,s,n,r){t[4*e+0]=Math.min(t[4*e+0],i),t[4*e+1]=Math.min(t[4*e+1],s),t[4*e+2]=Math.max(t[4*e+2],n),t[4*e+3]=Math.max(t[4*e+3],r)}const Ke=new Uint32Array(new Uint8Array([255,255,0,0]).buffer)[0];class Qe{#vs;#ys;constructor(t,e){this.#vs=t,this.#ys=e}get length(){return this.#vs.length}isEmpty(t){return this.#vs[t]===Ke}minX(t){return this.#ys[4*t+0]/256}minY(t){return this.#ys[4*t+1]/256}maxX(t){return(this.#ys[4*t+2]+1)/256}maxY(t){return(this.#ys[4*t+3]+1)/256}}const Ze=(t,e)=>{if(!t)return;let i=t.get(e);return i||(i={dependencies:new Set,isRenderingOperation:!1},t.set(e,i)),i};class Je{#ws={__proto__:null};#As={__proto__:null,transform:[],moveText:[],sameLineText:[],[Ve]:[]};#xs=new Map;#_s=[];#Ss=[];#Es=[[1,0,0,1,0,0]];#Cs=[-1/0,-1/0,1/0,1/0];#Ts=new Float64Array([1/0,1/0,-1/0,-1/0]);#Ms=-1;#Ds=new Set;#Ps=new Map;#Is=new Map;#ks;#Rs;#Ls;#vs;#Fs;constructor(t,e,i=!1){this.#ks=t.width,this.#Rs=t.height,this.#Os(e),i&&(this.#Fs=new Map)}growOperationsCount(t){t>=this.#vs.length&&this.#Os(t,this.#vs)}#Os(t,e){const i=new ArrayBuffer(4*t);this.#Ls=new Uint8ClampedArray(i),this.#vs=new Uint32Array(i),e&&e.length>0?(this.#vs.set(e),this.#vs.fill(Ke,e.length)):this.#vs.fill(Ke)}save(t){return this.#ws={__proto__:this.#ws},this.#As={__proto__:this.#As,transform:{__proto__:this.#As.transform},moveText:{__proto__:this.#As.moveText},sameLineText:{__proto__:this.#As.sameLineText},[Ve]:{__proto__:this.#As[Ve]}},this.#Cs={__proto__:this.#Cs},this.#_s.push(t),this}restore(t){const e=Object.getPrototypeOf(this.#ws);if(null===e)return this;this.#ws=e,this.#As=Object.getPrototypeOf(this.#As),this.#Cs=Object.getPrototypeOf(this.#Cs);const i=this.#_s.pop();return void 0!==i&&(Ze(this.#Fs,t)?.dependencies.add(i),this.#vs[t]=this.#vs[i]),this}recordOpenMarker(t){return this.#_s.push(t),this}getOpenMarker(){return 0===this.#_s.length?null:this.#_s.at(-1)}recordCloseMarker(t){const e=this.#_s.pop();return void 0!==e&&(Ze(this.#Fs,t)?.dependencies.add(e),this.#vs[t]=this.#vs[e]),this}beginMarkedContent(t){return this.#Ss.push(t),this}endMarkedContent(t){const e=this.#Ss.pop();return void 0!==e&&(Ze(this.#Fs,t)?.dependencies.add(e),this.#vs[t]=this.#vs[e]),this}pushBaseTransform(t){return this.#Es.push(K.multiplyByDOMMatrix(this.#Es.at(-1),t.getTransform())),this}popBaseTransform(){return this.#Es.length>1&&this.#Es.pop(),this}recordSimpleData(t,e){return this.#ws[t]=e,this}recordIncrementalData(t,e){return this.#As[t].push(e),this}resetIncrementalData(t,e){return this.#As[t].length=0,this}recordNamedData(t,e){return this.#xs.set(t,e),this}recordSimpleDataFromNamed(t,e,i){this.#ws[t]=this.#xs.get(e)??i}recordFutureForcedDependency(t,e){return this.recordIncrementalData(Ve,e),this}inheritSimpleDataAsFutureForcedDependencies(t){for(const e of t)e in this.#ws&&this.recordFutureForcedDependency(e,this.#ws[e]);return this}inheritPendingDependenciesAsFutureForcedDependencies(){for(const t of this.#Ds)this.recordFutureForcedDependency(Ve,t);return this}resetBBox(t){return this.#Ms!==t&&(this.#Ms=t,this.#Ts[0]=1/0,this.#Ts[1]=1/0,this.#Ts[2]=-1/0,this.#Ts[3]=-1/0),this}recordClipBox(t,e,i,s,n,r){const a=K.multiplyByDOMMatrix(this.#Es.at(-1),e.getTransform()),o=[1/0,1/0,-1/0,-1/0];K.axialAlignedBoundingBox([i,n,s,r],a,o);const l=K.intersect(this.#Cs,o);return l?(this.#Cs[0]=l[0],this.#Cs[1]=l[1],this.#Cs[2]=l[2],this.#Cs[3]=l[3]):(this.#Cs[0]=this.#Cs[1]=1/0,this.#Cs[2]=this.#Cs[3]=-1/0),this}recordBBox(t,e,i,s,n,r){const a=this.#Cs;if(a[0]===1/0)return this;const o=K.multiplyByDOMMatrix(this.#Es.at(-1),e.getTransform());if(a[0]===-1/0)return K.axialAlignedBoundingBox([i,n,s,r],o,this.#Ts),this;const l=[1/0,1/0,-1/0,-1/0];return K.axialAlignedBoundingBox([i,n,s,r],o,l),this.#Ts[0]=Math.min(this.#Ts[0],Math.max(l[0],a[0])),this.#Ts[1]=Math.min(this.#Ts[1],Math.max(l[1],a[1])),this.#Ts[2]=Math.max(this.#Ts[2],Math.min(l[2],a[2])),this.#Ts[3]=Math.max(this.#Ts[3],Math.min(l[3],a[3])),this}recordCharacterBBox(t,e,i,s=1,n=0,r=0,a){const o=i.bbox;let l,h;if(o&&(l=o[2]!==o[0]&&o[3]!==o[1]&&this.#Is.get(i),!1!==l&&(h=[0,0,0,0],K.axialAlignedBoundingBox(o,i.fontMatrix,h),1===s&&0===n&&0===r||K.scaleMinMax([s,0,0,-s,n,r],h),l)))return this.recordBBox(t,e,h[0],h[2],h[1],h[3]);if(!a)return this.recordFullPageBBox(t);const c=a();return o&&h&&void 0===l&&(l=h[0]<=n-c.actualBoundingBoxLeft&&h[2]>=n+c.actualBoundingBoxRight&&h[1]<=r-c.actualBoundingBoxAscent&&h[3]>=r+c.actualBoundingBoxDescent,this.#Is.set(i,l),l)?this.recordBBox(t,e,h[0],h[2],h[1],h[3]):this.recordBBox(t,e,n-c.actualBoundingBoxLeft,n+c.actualBoundingBoxRight,r-c.actualBoundingBoxAscent,r+c.actualBoundingBoxDescent)}recordFullPageBBox(t){return this.#Ts[0]=Math.max(0,this.#Cs[0]),this.#Ts[1]=Math.max(0,this.#Cs[1]),this.#Ts[2]=Math.min(this.#ks,this.#Cs[2]),this.#Ts[3]=Math.min(this.#Rs,this.#Cs[3]),this}getSimpleIndex(t){return this.#ws[t]}recordDependencies(t,e){const i=this.#Ds,s=this.#ws,n=this.#As;for(const r of e)r in this.#ws?i.add(s[r]):r in n&&n[r].forEach(i.add,i);return this}recordNamedDependency(t,e){return this.#xs.has(e)&&this.#Ds.add(this.#xs.get(e)),this}recordOperation(t,e=!1){if(this.recordDependencies(t,[Ve]),this.#Fs){const e=Ze(this.#Fs,t),{dependencies:i}=e;this.#Ds.forEach(i.add,i),this.#_s.forEach(i.add,i),this.#Ss.forEach(i.add,i),i.delete(t),e.isRenderingOperation=!0}if(this.#Ms===t){const i=qe(256*this.#Ts[0]/this.#ks),s=qe(256*this.#Ts[1]/this.#Rs),n=Xe(256*this.#Ts[2]/this.#ks),r=Xe(256*this.#Ts[3]/this.#Rs);Ye(this.#Ls,t,i,s,n,r);for(const e of this.#Ds)e!==t&&Ye(this.#Ls,e,i,s,n,r);for(const e of this.#_s)e!==t&&Ye(this.#Ls,e,i,s,n,r);for(const e of this.#Ss)e!==t&&Ye(this.#Ls,e,i,s,n,r);e||(this.#Ds.clear(),this.#Ms=-1)}return this}recordShowTextOperation(t,e=!1){const i=Array.from(this.#Ds);this.recordOperation(t,e),this.recordIncrementalData("sameLineText",t);for(const s of i)this.recordIncrementalData("sameLineText",s);return this}bboxToClipBoxDropOperation(t,e=!1){return this.#Ms===t&&(this.#Ms=-1,this.#Cs[0]=Math.max(this.#Cs[0],this.#Ts[0]),this.#Cs[1]=Math.max(this.#Cs[1],this.#Ts[1]),this.#Cs[2]=Math.min(this.#Cs[2],this.#Ts[2]),this.#Cs[3]=Math.min(this.#Cs[3],this.#Ts[3]),e||this.#Ds.clear()),this}_takePendingDependencies(){const t=this.#Ds;return this.#Ds=new Set,t}_extractOperation(t){const e=this.#Ps.get(t);return this.#Ps.delete(t),e}_pushPendingDependencies(t){for(const e of t)this.#Ds.add(e)}take(){return this.#Is.clear(),new Qe(this.#vs,this.#Ls)}takeDebugMetadata(){return this.#Fs}}class ti{#Bs;#Ns;#Us;#js=0;#zs=0;constructor(t,e,i){if(t instanceof ti&&t.#Us===!!i)return t;this.#Bs=t,this.#Ns=e,this.#Us=!!i}growOperationsCount(){throw new Error("Unreachable")}save(t){return this.#zs++,this.#Bs.save(this.#Ns),this}restore(t){return this.#zs>0&&(this.#Bs.restore(this.#Ns),this.#zs--),this}recordOpenMarker(t){return this.#js++,this}getOpenMarker(){return this.#js>0?this.#Ns:this.#Bs.getOpenMarker()}recordCloseMarker(t){return this.#js--,this}beginMarkedContent(t){return this}endMarkedContent(t){return this}pushBaseTransform(t){return this.#Bs.pushBaseTransform(t),this}popBaseTransform(){return this.#Bs.popBaseTransform(),this}recordSimpleData(t,e){return this.#Bs.recordSimpleData(t,this.#Ns),this}recordIncrementalData(t,e){return this.#Bs.recordIncrementalData(t,this.#Ns),this}resetIncrementalData(t,e){return this.#Bs.resetIncrementalData(t,this.#Ns),this}recordNamedData(t,e){return this}recordSimpleDataFromNamed(t,e,i){return this.#Bs.recordSimpleDataFromNamed(t,e,this.#Ns),this}recordFutureForcedDependency(t,e){return this.#Bs.recordFutureForcedDependency(t,this.#Ns),this}inheritSimpleDataAsFutureForcedDependencies(t){return this.#Bs.inheritSimpleDataAsFutureForcedDependencies(t),this}inheritPendingDependenciesAsFutureForcedDependencies(){return this.#Bs.inheritPendingDependenciesAsFutureForcedDependencies(),this}resetBBox(t){return this.#Us||this.#Bs.resetBBox(this.#Ns),this}recordClipBox(t,e,i,s,n,r){return this.#Us||this.#Bs.recordClipBox(this.#Ns,e,i,s,n,r),this}recordBBox(t,e,i,s,n,r){return this.#Us||this.#Bs.recordBBox(this.#Ns,e,i,s,n,r),this}recordCharacterBBox(t,e,i,s,n,r,a){return this.#Us||this.#Bs.recordCharacterBBox(this.#Ns,e,i,s,n,r,a),this}recordFullPageBBox(t){return this.#Us||this.#Bs.recordFullPageBBox(this.#Ns),this}getSimpleIndex(t){return this.#Bs.getSimpleIndex(t)}recordDependencies(t,e){return this.#Bs.recordDependencies(this.#Ns,e),this}recordNamedDependency(t,e){return this.#Bs.recordNamedDependency(this.#Ns,e),this}recordOperation(t){return this.#Bs.recordOperation(this.#Ns,!0),this}recordShowTextOperation(t){return this.#Bs.recordShowTextOperation(this.#Ns,!0),this}bboxToClipBoxDropOperation(t){return this.#Us||this.#Bs.bboxToClipBoxDropOperation(this.#Ns,!0),this}take(){throw new Error("Unreachable")}takeDebugMetadata(){throw new Error("Unreachable")}}const ei={stroke:["path","transform","filter","strokeColor","strokeAlpha","lineWidth","lineCap","lineJoin","miterLimit","dash"],fill:["path","transform","filter","fillColor","fillAlpha","globalCompositeOperation","SMask"],imageXObject:["transform","SMask","filter","fillAlpha","strokeAlpha","globalCompositeOperation"],rawFillPath:["filter","fillColor","fillAlpha"],showText:["transform","leading","charSpacing","wordSpacing","hScale","textRise","moveText","textMatrix","font","fontObj","filter","fillColor","textRenderingMode","SMask","fillAlpha","strokeAlpha","globalCompositeOperation","sameLineText"],transform:["transform"],transformAndFill:["transform","fillColor"]},ii={FILL:"Fill",STROKE:"Stroke",SHADING:"Shading"};function si(t,e){if(!e)return;const i=e[2]-e[0],s=e[3]-e[1],n=new Path2D;n.rect(e[0],e[1],i,s),t.clip(n)}class ni{isModifyingCurrentTransform(){return!1}getPattern(){P("Abstract method `getPattern` called.")}}class ri extends ni{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}_createGradient(t,e=null){let i,s=this._p0,n=this._p1;if(e&&(s=s.slice(),n=n.slice(),K.applyTransform(s,e),K.applyTransform(n,e)),"axial"===this._type)i=t.createLinearGradient(s[0],s[1],n[0],n[1]);else if("radial"===this._type){let r=this._r0,a=this._r1;if(e){const t=new Float32Array(2);K.singularValueDecompose2dScale(e,t),r*=t[0],a*=t[0]}i=t.createRadialGradient(s[0],s[1],r,n[0],n[1],a)}for(const r of this._colorStops)i.addColorStop(r[0],r[1]);return i}getPattern(t,e,i,s){let n;if(s===ii.STROKE||s===ii.FILL){if(this.isOriginBased()){let s=K.transform(i,e.baseTransform);this.matrix&&(s=K.transform(s,this.matrix));const n=.001,r=Math.hypot(s[0],s[1]),a=Math.hypot(s[2],s[3]),o=(s[0]*s[2]+s[1]*s[3])/(r*a);if(Math.abs(o)<n){if(!this.isRadial())return this._createGradient(t,s);if(Math.abs(r-a)<n)return this._createGradient(t,s)}}const r=e.current.getClippedPathBoundingBox(s,Tt(t))||[0,0,0,0],a=Math.ceil(r[2]-r[0])||1,o=Math.ceil(r[3]-r[1])||1,l=e.cachedCanvases.getCanvas("pattern",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(-r[0],-r[1]),i=K.transform(i,[1,0,0,1,r[0],r[1]]),h.transform(...e.baseTransform),this.matrix&&h.transform(...this.matrix),si(h,this._bbox),h.fillStyle=this._createGradient(h),h.fill(),n=t.createPattern(l.canvas,"no-repeat");const c=new DOMMatrix(i);n.setTransform(c)}else si(t,this._bbox),n=this._createGradient(t);return n}}function ai(t,e,i,s,n,r,a,o){const l=e.coords,h=e.colors,c=t.data,d=4*t.width;let u;l[i+1]>l[s+1]&&(u=i,i=s,s=u,u=r,r=a,a=u),l[s+1]>l[n+1]&&(u=s,s=n,n=u,u=a,a=o,o=u),l[i+1]>l[s+1]&&(u=i,i=s,s=u,u=r,r=a,a=u);const p=(l[i]+e.offsetX)*e.scaleX,g=(l[i+1]+e.offsetY)*e.scaleY,m=(l[s]+e.offsetX)*e.scaleX,f=(l[s+1]+e.offsetY)*e.scaleY,b=(l[n]+e.offsetX)*e.scaleX,v=(l[n+1]+e.offsetY)*e.scaleY;if(g>=v)return;const y=h[r],w=h[r+1],A=h[r+2],x=h[a],_=h[a+1],S=h[a+2],E=h[o],C=h[o+1],T=h[o+2],M=Math.round(g),D=Math.round(v);let P,I,k,R,L,F,O,B;for(let N=M;N<=D;N++){if(N<f){const t=N<g?0:(g-N)/(g-f);P=p-(p-m)*t,I=y-(y-x)*t,k=w-(w-_)*t,R=A-(A-S)*t}else{let t;t=N>v?1:f===v?0:(f-N)/(f-v),P=m-(m-b)*t,I=x-(x-E)*t,k=_-(_-C)*t,R=S-(S-T)*t}let t;t=N<g?0:N>v?1:(g-N)/(g-v),L=p-(p-b)*t,F=y-(y-E)*t,O=w-(w-C)*t,B=A-(A-T)*t;const e=Math.round(Math.min(P,L)),i=Math.round(Math.max(P,L));let s=d*N+4*e;for(let n=e;n<=i;n++)t=(P-n)/(P-L),t<0?t=0:t>1&&(t=1),c[s++]=I-(I-F)*t|0,c[s++]=k-(k-O)*t|0,c[s++]=R-(R-B)*t|0,c[s++]=255}}function oi(t,e,i){const s=e.coords,n=e.colors;let r,a;switch(e.type){case f.LATTICE:const o=e.verticesPerRow,l=Math.floor(s.length/o)-1,h=o-1;for(r=0;r<l;r++){let e=r*o;for(let r=0;r<h;r++,e++)ai(t,i,s[e],s[e+1],s[e+o],n[e],n[e+1],n[e+o]),ai(t,i,s[e+o+1],s[e+1],s[e+o],n[e+o+1],n[e+1],n[e+o])}break;case f.TRIANGLES:for(r=0,a=s.length;r<a;r+=3)ai(t,i,s[r],s[r+1],s[r+2],n[r],n[r+1],n[r+2]);break;default:throw new Error("illegal figure")}}class li extends ni{constructor(t){super(),this._coords=t[2],this._colors=t[3],this._figures=t[4],this._bounds=t[5],this._bbox=t[6],this._background=t[7],this.matrix=null}_createMeshCanvas(t,e,i){const s=1.1,n=3e3,r=2,a=Math.floor(this._bounds[0]),o=Math.floor(this._bounds[1]),l=Math.ceil(this._bounds[2])-a,h=Math.ceil(this._bounds[3])-o,c=Math.min(Math.ceil(Math.abs(l*t[0]*s)),n),d=Math.min(Math.ceil(Math.abs(h*t[1]*s)),n),u=l/c,p=h/d,g={coords:this._coords,colors:this._colors,offsetX:-a,offsetY:-o,scaleX:1/u,scaleY:1/p},m=c+2*r,f=d+2*r,b=i.getCanvas("mesh",m,f),v=b.context,y=v.createImageData(c,d);if(e){const t=y.data;for(let i=0,s=t.length;i<s;i+=4)t[i]=e[0],t[i+1]=e[1],t[i+2]=e[2],t[i+3]=255}for(const A of this._figures)oi(y,A,g);v.putImageData(y,r,r);const w=b.canvas;return{canvas:w,offsetX:a-r*u,offsetY:o-r*p,scaleX:u,scaleY:p}}isModifyingCurrentTransform(){return!0}getPattern(t,e,i,s){si(t,this._bbox);const n=new Float32Array(2);if(s===ii.SHADING)K.singularValueDecompose2dScale(Tt(t),n);else if(this.matrix){K.singularValueDecompose2dScale(this.matrix,n);const[t,i]=n;K.singularValueDecompose2dScale(e.baseTransform,n),n[0]*=t,n[1]*=i}else K.singularValueDecompose2dScale(e.baseTransform,n);const r=this._createMeshCanvas(n,s===ii.SHADING?null:this._background,e.cachedCanvases);return s!==ii.SHADING&&(t.setTransform(...e.baseTransform),this.matrix&&t.transform(...this.matrix)),t.translate(r.offsetX,r.offsetY),t.scale(r.scaleX,r.scaleY),t.createPattern(r.canvas,"no-repeat")}}class hi extends ni{getPattern(){return"hotpink"}}function ci(t){switch(t[0]){case"RadialAxial":return new ri(t);case"Mesh":return new li(t);case"Dummy":return new hi}throw new Error(`Unknown IR type: ${t[0]}`)}const di={COLORED:1,UNCOLORED:2};class ui{static MAX_PATTERN_SIZE=3e3;constructor(t,e,i,s){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.ctx=e,this.canvasGraphicsFactory=i,this.baseTransform=s}createPatternCanvas(t,e){const{bbox:i,operatorList:s,paintType:n,tilingType:r,color:a,canvasGraphicsFactory:o}=this;let{xstep:l,ystep:h}=this;l=Math.abs(l),h=Math.abs(h),M("TilingType: "+r);const c=i[0],d=i[1],u=i[2],p=i[3],g=u-c,m=p-d,f=new Float32Array(2);K.singularValueDecompose2dScale(this.matrix,f);const[b,v]=f;K.singularValueDecompose2dScale(this.baseTransform,f);const y=b*f[0],w=v*f[1];let A=g,x=m,_=!1,S=!1;const E=Math.ceil(l*y),C=Math.ceil(h*w),T=Math.ceil(g*y),D=Math.ceil(m*w);E>=T?A=l:_=!0,C>=D?x=h:S=!0;const P=this.getSizeAndScale(A,this.ctx.canvas.width,y),I=this.getSizeAndScale(x,this.ctx.canvas.height,w),k=t.cachedCanvases.getCanvas("pattern",P.size,I.size),R=k.context,L=o.createCanvasGraphics(R,e);if(L.groupLevel=t.groupLevel,this.setFillAndStrokeStyleToContext(L,n,a),R.translate(-P.scale*c,-I.scale*d),L.transform(0,P.scale,0,0,I.scale,0,0),R.save(),L.dependencyTracker?.save(),this.clipBbox(L,c,d,u,p),L.baseTransform=Tt(L.ctx),L.executeOperatorList(s),L.endDrawing(),L.dependencyTracker?.restore(),R.restore(),_||S){const e=k.canvas;_&&(A=l),S&&(x=h);const i=this.getSizeAndScale(A,this.ctx.canvas.width,y),s=this.getSizeAndScale(x,this.ctx.canvas.height,w),n=i.size,r=s.size,a=t.cachedCanvases.getCanvas("pattern-workaround",n,r),o=a.context,u=_?Math.floor(g/l):0,p=S?Math.floor(m/h):0;for(let t=0;t<=u;t++)for(let i=0;i<=p;i++)o.drawImage(e,n*t,r*i,n,r,0,0,n,r);return{canvas:a.canvas,scaleX:i.scale,scaleY:s.scale,offsetX:c,offsetY:d}}return{canvas:k.canvas,scaleX:P.scale,scaleY:I.scale,offsetX:c,offsetY:d}}getSizeAndScale(t,e,i){const s=Math.max(ui.MAX_PATTERN_SIZE,e);let n=Math.ceil(t*i);return n>=s?n=s:i=n/t,{scale:i,size:n}}clipBbox(t,e,i,s,n){const r=s-e,a=n-i;t.ctx.rect(e,i,r,a),K.axialAlignedBoundingBox([e,i,s,n],Tt(t.ctx),t.current.minMax),t.clip(),t.endPath()}setFillAndStrokeStyleToContext(t,e,i){const s=t.ctx,n=t.current;switch(e){case di.COLORED:const{fillStyle:t,strokeStyle:r}=this.ctx;s.fillStyle=n.fillColor=t,s.strokeStyle=n.strokeColor=r;break;case di.UNCOLORED:s.fillStyle=s.strokeStyle=i,n.fillColor=n.strokeColor=i;break;default:throw new z(`Unsupported paint type: ${e}`)}}isModifyingCurrentTransform(){return!1}getPattern(t,e,i,s,n){let r=i;s!==ii.SHADING&&(r=K.transform(r,e.baseTransform),this.matrix&&(r=K.transform(r,this.matrix)));const a=this.createPatternCanvas(e,n);let o=new DOMMatrix(r);o=o.translate(a.offsetX,a.offsetY),o=o.scale(1/a.scaleX,1/a.scaleY);const l=t.createPattern(a.canvas,"repeat");return l.setTransform(o),l}}function pi({src:t,srcPos:e=0,dest:i,width:s,height:n,nonBlackColor:r=4294967295,inverseDecode:a=!1}){const o=X.isLittleEndian?4278190080:255,[l,h]=a?[r,o]:[o,r],c=s>>3,d=7&s,u=t.length;i=new Uint32Array(i.buffer);let p=0;for(let g=0;g<n;g++){for(const n=e+c;e<n;e++){const s=e<u?t[e]:255;i[p++]=128&s?h:l,i[p++]=64&s?h:l,i[p++]=32&s?h:l,i[p++]=16&s?h:l,i[p++]=8&s?h:l,i[p++]=4&s?h:l,i[p++]=2&s?h:l,i[p++]=1&s?h:l}if(0===d)continue;const s=e<u?t[e++]:255;for(let t=0;t<d;t++)i[p++]=s&1<<7-t?h:l}return{srcPos:e,destPos:p}}const gi=16,mi=100,fi=15,bi=10,vi=16,yi=new DOMMatrix,wi=new Float32Array(2),Ai=new Float32Array([1/0,1/0,-1/0,-1/0]);function xi(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,s,n,r,a){e.transform(t,i,s,n,r,a),this.__originalTransform(t,i,s,n,r,a)},t.setTransform=function(t,i,s,n,r,a){e.setTransform(t,i,s,n,r,a),this.__originalSetTransform(t,i,s,n,r,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,s,n,r,a){e.bezierCurveTo(t,i,s,n,r,a),this.__originalBezierCurveTo(t,i,s,n,r,a)},t.rect=function(t,i,s,n){e.rect(t,i,s,n),this.__originalRect(t,i,s,n)},t.closePath=function(){e.closePath(),this.__originalClosePath()},t.beginPath=function(){e.beginPath(),this.__originalBeginPath()}}class _i{constructor(t){this.canvasFactory=t,this.cache=Object.create(null)}getCanvas(t,e,i){let s;return void 0!==this.cache[t]?(s=this.cache[t],this.canvasFactory.reset(s,e,i)):(s=this.canvasFactory.create(e,i),this.cache[t]=s),s}delete(t){delete this.cache[t]}clear(){for(const t in this.cache){const e=this.cache[t];this.canvasFactory.destroy(e),delete this.cache[t]}}}function Si(t,e,i,s,n,r,a,o,l,h){const[c,d,u,p,g,m]=Tt(t);if(0===d&&0===u){const f=a*c+g,b=Math.round(f),v=o*p+m,y=Math.round(v),w=(a+l)*c+g,A=Math.abs(Math.round(w)-b)||1,x=(o+h)*p+m,_=Math.abs(Math.round(x)-y)||1;return t.setTransform(Math.sign(c),0,0,Math.sign(p),b,y),t.drawImage(e,i,s,n,r,0,0,A,_),t.setTransform(c,d,u,p,g,m),[A,_]}if(0===c&&0===p){const f=o*u+g,b=Math.round(f),v=a*d+m,y=Math.round(v),w=(o+h)*u+g,A=Math.abs(Math.round(w)-b)||1,x=(a+l)*d+m,_=Math.abs(Math.round(x)-y)||1;return t.setTransform(0,Math.sign(d),Math.sign(u),0,b,y),t.drawImage(e,i,s,n,r,0,0,_,A),t.setTransform(c,d,u,p,g,m),[_,A]}t.drawImage(e,i,s,n,r,a,o,l,h);const f=Math.hypot(c,d),b=Math.hypot(u,p);return[f*l,b*h]}class Ei{alphaIsShape=!1;fontSize=0;fontSizeScale=1;textMatrix=null;textMatrixScale=1;fontMatrix=l;leading=0;x=0;y=0;lineX=0;lineY=0;charSpacing=0;wordSpacing=0;textHScale=1;textRenderingMode=b.FILL;textRise=0;fillColor="#000000";strokeColor="#000000";patternFill=!1;patternStroke=!1;fillAlpha=1;strokeAlpha=1;lineWidth=1;activeSMask=null;transferMaps="none";constructor(t,e,i){i?.(this),this.clipBox=new Float32Array([0,0,t,e]),this.minMax=Ai.slice()}clone(){const t=Object.create(this);return t.clipBox=this.clipBox.slice(),t.minMax=this.minMax.slice(),t}getPathBoundingBox(t=ii.FILL,e=null){const i=this.minMax.slice();if(t===ii.STROKE){e||P("Stroke bounding box must include transform."),K.singularValueDecompose2dScale(e,wi);const t=wi[0]*this.lineWidth/2,s=wi[1]*this.lineWidth/2;i[0]-=t,i[1]-=s,i[2]+=t,i[3]+=s}return i}updateClipFromPath(){const t=K.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(Ai,0)}getClippedPathBoundingBox(t=ii.FILL,e=null){return K.intersect(this.clipBox,this.getPathBoundingBox(t,e))}}function Ci(t,e){if(e instanceof ImageData)return void t.putImageData(e,0,0);const i=e.height,s=e.width,n=i%vi,r=(i-n)/vi,a=0===n?r:r+1,o=t.createImageData(s,vi);let l,h=0;const c=e.data,d=o.data;let u,p,g,m;if(e.kind===v.GRAYSCALE_1BPP){const e=c.byteLength,i=new Uint32Array(d.buffer,0,d.byteLength>>2),m=i.length,f=s+7>>3,b=4294967295,v=X.isLittleEndian?4278190080:255;for(u=0;u<a;u++){for(g=u<r?vi:n,l=0,p=0;p<g;p++){const t=e-h;let n=0;const r=t>f?s:8*t-7,a=-8&r;let o=0,d=0;for(;n<a;n+=8)d=c[h++],i[l++]=128&d?b:v,i[l++]=64&d?b:v,i[l++]=32&d?b:v,i[l++]=16&d?b:v,i[l++]=8&d?b:v,i[l++]=4&d?b:v,i[l++]=2&d?b:v,i[l++]=1&d?b:v;for(;n<r;n++)0===o&&(d=c[h++],o=128),i[l++]=d&o?b:v,o>>=1}while(l<m)i[l++]=0;t.putImageData(o,0,u*vi)}}else if(e.kind===v.RGBA_32BPP){for(p=0,m=s*vi*4,u=0;u<r;u++)d.set(c.subarray(h,h+m)),h+=m,t.putImageData(o,0,p),p+=vi;u<a&&(m=s*n*4,d.set(c.subarray(h,h+m)),t.putImageData(o,0,p))}else{if(e.kind!==v.RGB_24BPP)throw new Error(`bad image kind: ${e.kind}`);for(g=vi,m=s*g,u=0;u<a;u++){for(u>=r&&(g=n,m=s*g),l=0,p=m;p--;)d[l++]=c[h++],d[l++]=c[h++],d[l++]=c[h++],d[l++]=255;t.putImageData(o,0,u*vi)}}}function Ti(t,e){if(e.bitmap)return void t.drawImage(e.bitmap,0,0);const i=e.height,s=e.width,n=i%vi,r=(i-n)/vi,a=0===n?r:r+1,o=t.createImageData(s,vi);let l=0;const h=e.data,c=o.data;for(let d=0;d<a;d++){const e=d<r?vi:n;({srcPos:l}=pi({src:h,srcPos:l,dest:c,width:s,height:e,nonBlackColor:0})),t.putImageData(o,0,d*vi)}}function Mi(t,e){const i=["strokeStyle","fillStyle","fillRule","globalAlpha","lineWidth","lineCap","lineJoin","miterLimit","globalCompositeOperation","font","filter"];for(const s of i)void 0!==t[s]&&(e[s]=t[s]);void 0!==t.setLineDash&&(e.setLineDash(t.getLineDash()),e.lineDashOffset=t.lineDashOffset)}function Di(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",void 0!==t.setLineDash&&(t.setLineDash([]),t.lineDashOffset=0);const{filter:e}=t;"none"!==e&&""!==e&&(t.filter="none")}function Pi(t,e){if(e)return!0;K.singularValueDecompose2dScale(t,wi);const i=Math.fround(Pt.pixelRatio*ct.PDF_TO_CSS_UNITS);return wi[0]<=i&&wi[1]<=i}const Ii=["butt","round","square"],ki=["miter","round","bevel"],Ri={},Li={};class Fi{constructor(t,e,i,s,n,{optionalContentConfig:r,markedContentStack:a=null},o,l,h){this.ctx=t,this.current=new Ei(this.ctx.canvas.width,this.ctx.canvas.height),this.stateStack=[],this.pendingClip=null,this.pendingEOFill=!1,this.res=null,this.xobjs=null,this.commonObjs=e,this.objs=i,this.canvasFactory=s,this.filterFactory=n,this.groupStack=[],this.baseTransform=null,this.baseTransformStack=[],this.groupLevel=0,this.smaskStack=[],this.smaskCounter=0,this.tempSMask=null,this.suspendedCtx=null,this.contentVisible=!0,this.markedContentStack=a||[],this.optionalContentConfig=r,this.cachedCanvases=new _i(this.canvasFactory),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}getObject(t,e,i=null){return"string"===typeof e?(this.dependencyTracker?.recordNamedDependency(t,e),e.startsWith("g_")?this.commonObjs.get(e):this.objs.get(e)):i}beginDrawing({transform:t,viewport:e,transparency:i=!1,background:s=null}){const n=this.ctx.canvas.width,r=this.ctx.canvas.height,a=this.ctx.fillStyle;if(this.ctx.fillStyle=s||"#ffffff",this.ctx.fillRect(0,0,n,r),this.ctx.fillStyle=a,i){const t=this.cachedCanvases.getCanvas("transparent",n,r);this.compositeCtx=this.ctx,this.transparentCanvas=t.canvas,this.ctx=t.context,this.ctx.save(),this.ctx.transform(...Tt(this.compositeCtx))}this.ctx.save(),Di(this.ctx),t&&(this.ctx.transform(...t),this.outputScaleX=t[0],this.outputScaleY=t[0]),this.ctx.transform(...e.transform),this.viewportScale=e.scale,this.baseTransform=Tt(this.ctx)}executeOperatorList(t,e,i,s,n){const r=t.argsArray,a=t.fnArray;let o=e||0;const l=r.length;if(l===o)return o;const h=l-o>bi&&"function"===typeof i,c=h?Date.now()+fi:0;let d=0;const u=this.commonObjs,p=this.objs;let g,m;while(1){if(void 0!==s&&o===s.nextBreakPoint)return s.breakIt(o,i),o;if(!n||n(o))if(g=a[o],m=r[o]??null,g!==x.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))return e.get(t,i),o}if(o++,o===l)return o;if(h&&++d>bi){if(Date.now()>c)return i(),o;d=0}}}#Hs(){while(this.stateStack.length||this.inSMaskMode)this.restore();this.current.activeSMask=null,this.ctx.restore(),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.transparentCanvas=null)}endDrawing(){this.#Hs(),this.cachedCanvases.clear(),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.#$s()}#$s(){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,s=t.height??t.displayHeight;let n,r,a=Math.max(Math.hypot(e[0],e[1]),1),o=Math.max(Math.hypot(e[2],e[3]),1),l=i,h=s,c="prescale1";while(a>2&&l>1||o>2&&h>1){let e=l,i=h;a>2&&l>1&&(e=l>=16384?Math.floor(l/2)-1||1:Math.ceil(l/2),a/=l/e),o>2&&h>1&&(i=h>=16384?Math.floor(h/2)-1||1:Math.ceil(h)/2,o/=h/i),n=this.cachedCanvases.getCanvas(c,e,i),r=n.context,r.clearRect(0,0,e,i),r.drawImage(t,0,0,l,h,0,0,e,i),t=n.canvas,l=e,h=i,c="prescale1"===c?"prescale2":"prescale1"}return{img:t,paintWidth:l,paintHeight:h}}_createMaskCanvas(t,e){const i=this.ctx,{width:s,height:n}=e,r=this.current.fillColor,a=this.current.patternFill,o=Tt(i);let l,h,c,d;if((e.bitmap||e.data)&&e.count>1){const i=e.bitmap||e.data.buffer;h=JSON.stringify(a?o:[o.slice(0,4),r]),l=this._cachedBitmapsMap.get(i),l||(l=new Map,this._cachedBitmapsMap.set(i,l));const s=l.get(h);if(s&&!a){const e=Math.round(Math.min(o[0],o[2])+o[4]),i=Math.round(Math.min(o[1],o[3])+o[5]);return this.dependencyTracker?.recordDependencies(t,ei.transformAndFill),{canvas:s,offsetX:e,offsetY:i}}c=s}c||(d=this.cachedCanvases.getCanvas("maskCanvas",s,n),Ti(d.context,e));let u=K.transform(o,[1/s,0,0,-1/n,0,0]);u=K.transform(u,[1,0,0,1,0,-n]);const p=Ai.slice();K.axialAlignedBoundingBox([0,0,s,n],u,p);const[g,m,f,b]=p,v=Math.round(f-g)||1,y=Math.round(b-m)||1,w=this.cachedCanvases.getCanvas("fillCanvas",v,y),A=w.context,x=g,_=m;A.translate(-x,-_),A.transform(...u),c||(c=this._scaleImage(d.canvas,Mt(A)),c=c.img,l&&a&&l.set(h,c)),A.imageSmoothingEnabled=Pi(Tt(A),e.interpolate),Si(A,c,0,0,c.width,c.height,0,0,s,n),A.globalCompositeOperation="source-in";const S=K.transform(Mt(A),[1,0,0,1,-x,-_]);return A.fillStyle=a?r.getPattern(i,this,S,ii.FILL,t):r,A.fillRect(0,0,s,n),l&&!a&&(this.cachedCanvases.delete("fillCanvas"),l.set(h,w.canvas)),this.dependencyTracker?.recordDependencies(t,ei.transformAndFill),{canvas:w.canvas,offsetX:Math.round(x),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=Ii[e]}setLineJoin(t,e){this.dependencyTracker?.recordSimpleData("lineJoin",t),this.ctx.lineJoin=ki[e]}setMiterLimit(t,e){this.dependencyTracker?.recordSimpleData("miterLimit",t),this.ctx.miterLimit=e}setDash(t,e,i){this.dependencyTracker?.recordSimpleData("dash",t);const s=this.ctx;void 0!==s.setLineDash&&(s.setLineDash(e),s.lineDashOffset=i)}setRenderingIntent(t,e){}setFlatness(t,e){}setGState(t,e){for(const[i,s]of e)switch(i){case"LW":this.setLineWidth(t,s);break;case"LC":this.setLineCap(t,s);break;case"LJ":this.setLineJoin(t,s);break;case"ML":this.setMiterLimit(t,s);break;case"D":this.setDash(t,s[0],s[1]);break;case"RI":this.setRenderingIntent(t,s);break;case"FL":this.setFlatness(t,s);break;case"Font":this.setFont(t,s[0],s[1]);break;case"CA":this.dependencyTracker?.recordSimpleData("strokeAlpha",t),this.current.strokeAlpha=s;break;case"ca":this.dependencyTracker?.recordSimpleData("fillAlpha",t),this.ctx.globalAlpha=this.current.fillAlpha=s;break;case"BM":this.dependencyTracker?.recordSimpleData("globalCompositeOperation",t),this.ctx.globalCompositeOperation=s;break;case"SMask":this.dependencyTracker?.recordSimpleData("SMask",t),this.current.activeSMask=s?this.tempSMask:null,this.tempSMask=null,this.checkSMaskState();break;case"TR":this.dependencyTracker?.recordSimpleData("filter",t),this.ctx.filter=this.current.transferMaps=this.filterFactory.addFilter(s);break}}get inSMaskMode(){return!!this.suspendedCtx}checkSMaskState(){const t=this.inSMaskMode;this.current.activeSMask&&!t?this.beginSMaskMode():!this.current.activeSMask&&t&&this.endSMaskMode()}beginSMaskMode(t){if(this.inSMaskMode)throw new Error("beginSMaskMode called while already in smask mode");const e=this.ctx.canvas.width,i=this.ctx.canvas.height,s="smaskGroupAt"+this.groupLevel,n=this.cachedCanvases.getCanvas(s,e,i);this.suspendedCtx=this.ctx;const r=this.ctx=n.context;r.setTransform(this.suspendedCtx.getTransform()),Mi(this.suspendedCtx,r),xi(r,this.suspendedCtx),this.setGState(t,[["BM","source-over"]])}endSMaskMode(){if(!this.inSMaskMode)throw new Error("endSMaskMode called while not in smask mode");this.ctx._removeMirroring(),Mi(this.ctx,this.suspendedCtx),this.ctx=this.suspendedCtx,this.suspendedCtx=null}compose(t){if(!this.current.activeSMask)return;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])):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(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.ctx.restore()}composeSMask(t,e,i,s){const n=s[0],r=s[1],a=s[2]-n,o=s[3]-r;0!==a&&0!==o&&(this.genericComposeSMask(e.context,i,a,o,e.subtype,e.backdrop,e.transferMap,n,r,e.offsetX,e.offsetY),t.save(),t.globalAlpha=1,t.globalCompositeOperation="source-over",t.setTransform(1,0,0,1,0,0),t.drawImage(i.canvas,0,0),t.restore())}genericComposeSMask(t,e,i,s,n,r,a,o,l,h,c){let d=t.canvas,u=o-h,p=l-c;if(r)if(u<0||p<0||u+i>d.width||p+s>d.height){const t=this.cachedCanvases.getCanvas("maskExtension",i,s),e=t.context;e.drawImage(d,-u,-p),e.globalCompositeOperation="destination-atop",e.fillStyle=r,e.fillRect(0,0,i,s),e.globalCompositeOperation="source-over",d=t.canvas,u=p=0}else{t.save(),t.globalAlpha=1,t.setTransform(1,0,0,1,0,0);const e=new Path2D;e.rect(u,p,i,s),t.clip(e),t.globalCompositeOperation="destination-atop",t.fillStyle=r,t.fillRect(u,p,i,s),t.restore()}e.save(),e.globalAlpha=1,e.setTransform(1,0,0,1,0,0),"Alpha"===n&&a?e.filter=this.filterFactory.addAlphaFilter(a):"Luminosity"===n&&(e.filter=this.filterFactory.addLuminosityFilter(a));const g=new Path2D;g.rect(o,l,i,s),e.clip(g),e.globalCompositeOperation="destination-in",e.drawImage(d,u,p,i,s,o,l,i,s),e.restore()}save(t){this.inSMaskMode&&Mi(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),0!==this.stateStack.length?(this.current=this.stateStack.pop(),this.ctx.restore(),this.inSMaskMode&&Mi(this.suspendedCtx,this.ctx),this.checkSMaskState(),this.pendingClip=null,this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null):this.inSMaskMode&&this.endSMaskMode()}transform(t,e,i,s,n,r,a){this.dependencyTracker?.recordIncrementalData("transform",t),this.ctx.transform(e,i,s,n,r,a),this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null}constructPath(t,e,i,s){let[n]=i;if(!s)return n||=i[0]=new Path2D,void this[e](t,n);if(null!==this.dependencyTracker){const i=e===x.stroke?this.current.lineWidth/2:0;this.dependencyTracker.resetBBox(t).recordBBox(t,this.ctx,s[0]-i,s[2]+i,s[1]-i,s[3]+i).recordDependencies(t,["transform"])}n instanceof Path2D||(n=i[0]=Ht(n)),K.axialAlignedBoundingBox(s,Tt(this.ctx),this.current.minMax),this[e](t,n),this._pathStartIdx=t}closePath(t){this.ctx.closePath()}stroke(t,e,i=!0){const s=this.ctx,n=this.current.strokeColor;if(s.globalAlpha=this.current.strokeAlpha,this.contentVisible)if("object"===typeof n&&n?.getPattern){const i=n.isModifyingCurrentTransform()?s.getTransform():null;if(s.save(),s.strokeStyle=n.getPattern(s,this,Mt(s),ii.STROKE,t),i){const t=new Path2D;t.addPath(e,s.getTransform().invertSelf().multiplySelf(i)),e=t}this.rescaleAndStroke(e,!1),s.restore()}else this.rescaleAndStroke(e,!0);this.dependencyTracker?.recordDependencies(t,ei.stroke),i&&this.consumePath(t,e,this.current.getClippedPathBoundingBox(ii.STROKE,Tt(this.ctx))),s.globalAlpha=this.current.fillAlpha}closeStroke(t,e){this.stroke(t,e)}fill(t,e,i=!0){const s=this.ctx,n=this.current.fillColor,r=this.current.patternFill;let a=!1;if(r){const i=n.isModifyingCurrentTransform()?s.getTransform():null;if(this.dependencyTracker?.save(t),s.save(),s.fillStyle=n.getPattern(s,this,Mt(s),ii.FILL,t),i){const t=new Path2D;t.addPath(e,s.getTransform().invertSelf().multiplySelf(i)),e=t}a=!0}const o=this.current.getClippedPathBoundingBox();this.contentVisible&&null!==o&&(this.pendingEOFill?(s.fill(e,"evenodd"),this.pendingEOFill=!1):s.fill(e)),this.dependencyTracker?.recordDependencies(t,ei.fill),a&&(s.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,ei.rawFillPath).recordOperation(t)}clip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t),this.pendingClip=Ri}eoClip(t){this.dependencyTracker?.recordFutureForcedDependency("clipMode",t),this.pendingClip=Li}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,s=i.getTransform().invertSelf();for(const{transform:i,x:n,y:r,fontSize:a,path:o}of e)o&&t.addPath(o,new DOMMatrix(i).preMultiplySelf(s).translate(n,r).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 s=this.commonObjs.get(e),n=this.current;if(!s)throw new Error(`Can't find font for ${e}`);if(n.fontMatrix=s.fontMatrix||l,0!==n.fontMatrix[0]&&0!==n.fontMatrix[3]||D("Invalid font matrix for font "+e),i<0?(i=-i,n.fontDirection=-1):n.fontDirection=1,this.current.font=s,this.current.fontSize=i,s.isType3Font)return;const r=s.loadedName||"sans-serif",a=s.systemFontInfo?.css||`"${r}", ${s.fallbackName}`;let o="normal";s.black?o="900":s.bold&&(o="bold");const h=s.italic?"italic":"normal";let c=i;i<gi?c=gi:i>mi&&(c=mi),this.current.fontSizeScale=i/c,this.ctx.font=`${h} ${o} ${c}px ${a}`}setTextRenderingMode(t,e){this.dependencyTracker?.recordSimpleData("textRenderingMode",t),this.current.textRenderingMode=e}setTextRise(t,e){this.dependencyTracker?.recordSimpleData("textRise",t),this.current.textRise=e}moveText(t,e,i){this.dependencyTracker?.resetIncrementalData("sameLineText").recordIncrementalData("moveText",t),this.current.x=this.current.lineX+=e,this.current.y=this.current.lineY+=i}setLeadingMoveText(t,e,i){this.setLeading(t,-i),this.moveText(t,e,i)}setTextMatrix(t,e){this.dependencyTracker?.resetIncrementalData("sameLineText").recordSimpleData("textMatrix",t);const{current:i}=this;i.textMatrix=e,i.textMatrixScale=Math.hypot(e[0],e[1]),i.x=i.lineX=0,i.y=i.lineY=0}nextLine(t){this.moveText(t,0,this.current.leading),this.dependencyTracker?.recordIncrementalData("moveText",this.dependencyTracker.getSimpleIndex("leading")??t)}#Gs(t,e,i){const s=new Path2D;return s.addPath(t,new DOMMatrix(i).invertSelf().multiplySelf(e)),s}paintChar(t,e,i,s,n,r){const a=this.ctx,o=this.current,l=o.font,h=o.textRenderingMode,c=o.fontSize/o.fontSizeScale,d=h&b.FILL_STROKE_MASK,u=!!(h&b.ADD_TO_PATH_FLAG),p=o.patternFill&&!l.missingFile,g=o.patternStroke&&!l.missingFile;let m;if((l.disableFontFace||u||p||g)&&!l.missingFile&&(m=l.getPathGenerator(this.commonObjs,e)),m&&(l.disableFontFace||p||g)){let e;if(a.save(),a.translate(i,s),a.scale(c,-c),this.dependencyTracker?.recordCharacterBBox(t,a,l),d===b.FILL||d===b.FILL_STROKE)if(n){e=a.getTransform(),a.setTransform(...n);const t=this.#Gs(m,e,n);a.fill(t)}else a.fill(m);if(d===b.STROKE||d===b.FILL_STROKE)if(r){e||=a.getTransform(),a.setTransform(...r);const{a:t,b:i,c:s,d:n}=e,o=K.inverseTransform(r),l=K.transform([t,i,s,n,0,0],o);K.singularValueDecompose2dScale(l,wi),a.lineWidth*=Math.max(wi[0],wi[1])/c,a.stroke(this.#Gs(m,e,r))}else a.lineWidth/=c,a.stroke(m);a.restore()}else d!==b.FILL&&d!==b.FILL_STROKE||(a.fillText(e,i,s),this.dependencyTracker?.recordCharacterBBox(t,a,l,c,i,s,()=>a.measureText(e))),d!==b.STROKE&&d!==b.FILL_STROKE||(this.dependencyTracker&&this.dependencyTracker?.recordCharacterBBox(t,a,l,c,i,s,()=>a.measureText(e)).recordDependencies(t,ei.stroke),a.strokeText(e,i,s));if(u){const e=this.pendingTextPaths||=[];e.push({transform:Tt(a),x:i,y:s,fontSize:c,path:m}),this.dependencyTracker?.recordCharacterBBox(t,a,l,c,i,s)}}get isFontSubpixelAAEnabled(){const{context:t}=this.cachedCanvases.getCanvas("isFontSubpixelAAEnabled",10,10);t.scale(1.5,1),t.fillText("I",0,10);const e=t.getImageData(0,0,10,10).data;let i=!1;for(let s=3;s<e.length;s+=4)if(e[s]>0&&e[s]<255){i=!0;break}return F(this,"isFontSubpixelAAEnabled",i)}showText(t,e){this.dependencyTracker&&(this.dependencyTracker.recordDependencies(t,ei.showText).resetBBox(t),this.current.textRenderingMode&b.ADD_TO_PATH_FLAG&&this.dependencyTracker.recordFutureForcedDependency("textClip",t).inheritPendingDependenciesAsFutureForcedDependencies());const i=this.current,s=i.font;if(s.isType3Font)return this.showType3Text(t,e),void this.dependencyTracker?.recordShowTextOperation(t);const n=i.fontSize;if(0===n)return void this.dependencyTracker?.recordOperation(t);const r=this.ctx,a=i.fontSizeScale,o=i.charSpacing,l=i.wordSpacing,h=i.fontDirection,c=i.textHScale*h,d=e.length,u=s.vertical,p=u?1:-1,g=s.defaultVMetrics,m=n*i.fontMatrix[0],f=i.textRenderingMode===b.FILL&&!s.disableFontFace&&!i.patternFill;let v,y;r.save(),i.textMatrix&&r.transform(...i.textMatrix),r.translate(i.x,i.y+i.textRise),h>0?r.scale(c,-1):r.scale(c,1);const w=i.textRenderingMode&b.FILL_STROKE_MASK,A=w===b.FILL||w===b.FILL_STROKE,x=w===b.STROKE||w===b.FILL_STROKE;if(A&&i.patternFill){r.save();const e=i.fillColor.getPattern(r,this,Mt(r),ii.FILL,t);v=Tt(r),r.restore(),r.fillStyle=e}if(x&&i.patternStroke){r.save();const e=i.strokeColor.getPattern(r,this,Mt(r),ii.STROKE,t);y=Tt(r),r.restore(),r.strokeStyle=e}let _=i.lineWidth;const S=i.textMatrixScale;if(0===S||0===_?x&&(_=this.getSinglePixelWidth()):_/=S,1!==a&&(r.scale(a,a),_/=a),r.lineWidth=_,s.isInvalidPDFjsFont){const s=[];let n=0;for(const t of e)s.push(t.unicode),n+=t.width;const a=s.join("");if(r.fillText(a,0,0),null!==this.dependencyTracker){const e=r.measureText(a);this.dependencyTracker.recordBBox(t,this.ctx,-e.actualBoundingBoxLeft,e.actualBoundingBoxRight,-e.actualBoundingBoxAscent,e.actualBoundingBoxDescent).recordShowTextOperation(t)}return i.x+=n*m*c,r.restore(),void this.compose()}let E,C=0;for(E=0;E<d;++E){const i=e[E];if("number"===typeof i){C+=p*i*n/1e3;continue}let c=!1;const d=(i.isSpace?l:0)+o,b=i.fontChar,w=i.accent;let A,x,_,S=i.width;if(u){const t=i.vmetric||g,e=-(i.vmetric?t[1]:.5*S)*m,s=t[2]*m;S=t?-t[0]:S,A=e/a,x=(C+s)/a}else A=C/a,x=0;if(s.remeasure&&S>0){_=r.measureText(b);const t=1e3*_.width/n*a;if(S<t&&this.isFontSubpixelAAEnabled){const e=S/t;c=!0,r.save(),r.scale(e,1),A/=e}else S!==t&&(A+=(S-t)/2e3*n/a)}if(this.contentVisible&&(i.isInFont||s.missingFile))if(f&&!w)r.fillText(b,A,x),this.dependencyTracker?.recordCharacterBBox(t,r,_?{bbox:null}:s,n/a,A,x,()=>_??r.measureText(b));else if(this.paintChar(t,b,A,x,v,y),w){const e=A+n*w.offset.x/a,i=x-n*w.offset.y/a;this.paintChar(t,w.fontChar,e,i,v,y)}const T=u?S*m-d*h:S*m+d*h;C+=T,c&&r.restore()}u?i.y-=C:i.x+=C*c,r.restore(),this.compose(),this.dependencyTracker?.recordShowTextOperation(t)}showType3Text(t,e){const i=this.ctx,s=this.current,n=s.font,r=s.fontSize,a=s.fontDirection,o=n.vertical?1:-1,h=s.charSpacing,c=s.wordSpacing,d=s.textHScale*a,u=s.fontMatrix||l,p=e.length,g=s.textRenderingMode===b.INVISIBLE;let m,f,v,y;if(g||0===r)return;this._cachedScaleForStroking[0]=-1,this._cachedGetSinglePixelWidth=null,i.save(),s.textMatrix&&i.transform(...s.textMatrix),i.translate(s.x,s.y+s.textRise),i.scale(d,a);const w=this.dependencyTracker;for(this.dependencyTracker=w?new ti(w,t):null,m=0;m<p;++m){if(f=e[m],"number"===typeof f){y=o*f*r/1e3,this.ctx.translate(y,0),s.x+=y*d;continue}const t=(f.isSpace?c:0)+h,a=n.charProcOperatorList[f.operatorListId];a?this.contentVisible&&(this.save(),i.scale(r,r),i.transform(...u),this.executeOperatorList(a),this.restore()):D(`Type3 character "${f.operatorListId}" is not available.`);const l=[f.width,0];K.applyTransform(l,u),v=l[0]*r+t,i.translate(v,0),s.x+=v*d}i.restore(),w&&(this.dependencyTracker=w)}setCharWidth(t,e,i){}setCharWidthAndBounds(t,e,i,s,n,r,a){const o=new Path2D;o.rect(s,n,r-s,a-n),this.ctx.clip(o),this.dependencyTracker?.recordBBox(t,this.ctx,s,r,n,a).recordClipBox(t,this.ctx,s,r,n,a),this.endPath(t)}getColorN_Pattern(t,e){let i;if("TilingPattern"===e[0]){const t=this.baseTransform||Tt(this.ctx),s={createCanvasGraphics:(t,e)=>new Fi(t,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:this.optionalContentConfig,markedContentStack:this.markedContentStack},void 0,void 0,this.dependencyTracker?new ti(this.dependencyTracker,e,!0):null)};i=new ui(e,this.ctx,s,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),this.current.fillColor=this.getColorN_Pattern(t,e),this.current.patternFill=!0}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}setFillTransparent(t){this.dependencyTracker?.recordSimpleData("fillColor",t),this.ctx.fillStyle=this.current.fillColor="transparent",this.current.patternFill=!1}_getPattern(t,e,i=null){let s;return this.cachedPatterns.has(e)?s=this.cachedPatterns.get(e):(s=ci(this.getObject(t,e)),this.cachedPatterns.set(e,s)),i&&(s.matrix=i),s}shadingFill(t,e){if(!this.contentVisible)return;const i=this.ctx;this.save(t);const s=this._getPattern(t,e);i.fillStyle=s.getPattern(i,this,Mt(i),ii.SHADING,t);const n=Mt(i);if(n){const{width:t,height:e}=i.canvas,s=Ai.slice();K.axialAlignedBoundingBox([0,0,t,e],n,s);const[r,a,o,l]=s;this.ctx.fillRect(r,a,o-r,l-a)}else this.ctx.fillRect(-1e10,-1e10,2e10,2e10);this.dependencyTracker?.resetBBox(t).recordFullPageBBox(t).recordDependencies(t,ei.transform).recordDependencies(t,ei.fill).recordOperation(t),this.compose(this.current.getClippedPathBoundingBox()),this.restore(t)}beginInlineImage(){P("Should not call beginInlineImage")}beginImageData(){P("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=Tt(this.ctx),i)){K.axialAlignedBoundingBox(i,this.baseTransform,this.current.minMax);const[e,s,n,r]=i,a=new Path2D;a.rect(e,s,n-e,r-s),this.ctx.clip(a),this.dependencyTracker?.recordClipBox(t,this.ctx,e,n,s,r),this.endPath(t)}}paintFormXObjectEnd(t){this.contentVisible&&(this.restore(t),this.baseTransform=this.baseTransformStack.pop())}beginGroup(t,e){if(!this.contentVisible)return;this.save(t),this.inSMaskMode&&(this.endSMaskMode(),this.current.activeSMask=null);const i=this.ctx;e.isolated||M("TODO: Support non-isolated groups."),e.knockout&&D("Knockout groups not supported.");const s=Tt(i);if(e.matrix&&i.transform(...e.matrix),!e.bbox)throw new Error("Bounding box is required.");let n=Ai.slice();K.axialAlignedBoundingBox(e.bbox,Tt(i),n);const r=[0,0,i.canvas.width,i.canvas.height];n=K.intersect(n,r)||[0,0,0,0];const a=Math.floor(n[0]),o=Math.floor(n[1]),l=Math.max(Math.ceil(n[2])-a,1),h=Math.max(Math.ceil(n[3])-o,1);this.current.startNewPathAndClipBox([0,0,l,h]);let c="groupAt"+this.groupLevel;e.smask&&(c+="_smask_"+this.smaskCounter++%2);const d=this.cachedCanvases.getCanvas(c,l,h),u=d.context;u.translate(-a,-o),u.transform(...s);let p=new Path2D;const[g,m,f,b]=e.bbox;if(p.rect(g,m,f-g,b-m),e.matrix){const t=new Path2D;t.addPath(p,new DOMMatrix(e.matrix)),p=t}u.clip(p),e.smask&&this.smaskStack.push({canvas:d.canvas,context:u,offsetX:a,offsetY:o,subtype:e.smask.subtype,backdrop:e.smask.backdrop,transferMap:e.smask.transferMap||null,startTransformInverse:null}),e.smask&&!this.dependencyTracker||(i.setTransform(1,0,0,1,0,0),i.translate(a,o),i.save()),Mi(i,u),this.ctx=u,this.dependencyTracker?.inheritSimpleDataAsFutureForcedDependencies(["fillAlpha","strokeAlpha","globalCompositeOperation"]).pushBaseTransform(i),this.setGState(t,[["BM","source-over"],["ca",1],["CA",1]]),this.groupStack.push(i),this.groupLevel++}endGroup(t,e){if(!this.contentVisible)return;this.groupLevel--;const i=this.ctx,s=this.groupStack.pop();if(this.ctx=s,this.ctx.imageSmoothingEnabled=!1,this.dependencyTracker?.popBaseTransform(),e.smask)this.tempSMask=this.smaskStack.pop(),this.restore(t),this.dependencyTracker&&this.ctx.restore();else{this.ctx.restore();const e=Tt(this.ctx);this.restore(t),this.ctx.save(),this.ctx.setTransform(...e);const s=Ai.slice();K.axialAlignedBoundingBox([0,0,i.canvas.width,i.canvas.height],e,s),this.ctx.drawImage(i.canvas,0,0),this.ctx.restore(),this.compose(s)}}beginAnnotation(t,e,i,s,n,r){if(this.#Hs(),Di(this.ctx),this.ctx.save(),this.save(t),this.baseTransform&&this.ctx.setTransform(...this.baseTransform),i){const n=i[2]-i[0],a=i[3]-i[1];if(r&&this.annotationCanvasMap){s=s.slice(),s[4]-=i[0],s[5]-=i[1],i=i.slice(),i[0]=i[1]=0,i[2]=n,i[3]=a,K.singularValueDecompose2dScale(Tt(this.ctx),wi);const{viewportScale:t}=this,r=Math.ceil(n*this.outputScaleX*t),o=Math.ceil(a*this.outputScaleY*t);this.annotationCanvas=this.canvasFactory.create(r,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(wi[0],0,0,-wi[1],0,a*wi[1]),Di(this.ctx)}else{Di(this.ctx),this.endPath(t);const e=new Path2D;e.rect(i[0],i[1],n,a),this.ctx.clip(e)}}this.current=new Ei(this.ctx.canvas.width,this.ctx.canvas.height),this.transform(t,...s),this.transform(t,...n)}endAnnotation(t){this.annotationCanvas&&(this.ctx.restore(),this.#$s(),this.ctx=this.annotationCanvas.savedCtx,delete this.annotationCanvas.savedCtx,delete this.annotationCanvas)}paintImageMaskXObject(t,e){if(!this.contentVisible)return;const i=e.count;e=this.getObject(t,e.data,e),e.count=i;const s=this.ctx,n=this._createMaskCanvas(t,e),r=n.canvas;s.save(),s.setTransform(1,0,0,1,0,0),s.drawImage(r,n.offsetX,n.offsetY),this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,n.offsetX,n.offsetX+r.width,n.offsetY,n.offsetY+r.height).recordOperation(t),s.restore(),this.compose()}paintImageMaskXObjectRepeat(t,e,i,s=0,n=0,r,a){if(!this.contentVisible)return;e=this.getObject(t,e.data,e);const o=this.ctx;o.save();const l=Tt(o);o.transform(i,s,n,r,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 c=0,d=a.length;c<d;c+=2){const e=K.transform(l,[i,s,n,r,a[c],a[c+1]]);o.drawImage(h.canvas,e[4],e[5]),this.dependencyTracker?.recordBBox(t,this.ctx,e[4],e[4]+h.canvas.width,e[5],e[5]+h.canvas.height)}o.restore(),this.compose(),this.dependencyTracker?.recordOperation(t)}paintImageMaskXObjectGroup(t,e){if(!this.contentVisible)return;const i=this.ctx,s=this.current.fillColor,n=this.current.patternFill;this.dependencyTracker?.resetBBox(t).recordDependencies(t,ei.transformAndFill);for(const r of e){const{data:e,width:a,height:o,transform:l}=r,h=this.cachedCanvases.getCanvas("maskCanvas",a,o),c=h.context;c.save();const d=this.getObject(t,e,r);Ti(c,d),c.globalCompositeOperation="source-in",c.fillStyle=n?s.getPattern(c,this,Mt(i),ii.FILL,t):s,c.fillRect(0,0,a,o),c.restore(),i.save(),i.transform(...l),i.scale(1,-1),Si(i,h.canvas,0,0,a,o,0,-1,1,1),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):D("Dependent image isn't ready yet")}paintImageXObjectRepeat(t,e,i,s,n){if(!this.contentVisible)return;const r=this.getObject(t,e);if(!r)return void D("Dependent image isn't ready yet");const a=r.width,o=r.height,l=[];for(let h=0,c=n.length;h<c;h+=2)l.push({transform:[i,0,0,s,n[h],n[h+1]],x:0,y:0,w:a,h:o});this.paintInlineImageXObjectGroup(t,r,l)}applyTransferMapsToCanvas(t){return"none"!==this.current.transferMaps&&(t.filter=this.current.transferMaps,t.drawImage(t.canvas,0,0),t.filter="none"),t.canvas}applyTransferMapsToBitmap(t){if("none"===this.current.transferMaps)return t.bitmap;const{bitmap:e,width:i,height:s}=t,n=this.cachedCanvases.getCanvas("inlineImage",i,s),r=n.context;return r.filter=this.current.transferMaps,r.drawImage(e,0,0),r.filter="none",n.canvas}paintInlineImageXObject(t,e){if(!this.contentVisible)return;const i=e.width,s=e.height,n=this.ctx;this.save(t);const{filter:r}=n;let a;if("none"!==r&&""!==r&&(n.filter="none"),n.scale(1/i,-1/s),e.bitmap)a=this.applyTransferMapsToBitmap(e);else if("function"===typeof HTMLElement&&e instanceof HTMLElement||!e.data)a=e;else{const t=this.cachedCanvases.getCanvas("inlineImage",i,s),n=t.context;Ci(n,e),a=this.applyTransferMapsToCanvas(n)}const o=this._scaleImage(a,Mt(n));n.imageSmoothingEnabled=Pi(Tt(n),e.interpolate),this.dependencyTracker?.resetBBox(t).recordBBox(t,n,0,i,-s,0).recordDependencies(t,ei.imageXObject).recordOperation(t),Si(n,o.img,0,0,o.paintWidth,o.paintHeight,0,-s,i,s),this.compose(),this.restore(t)}paintInlineImageXObjectGroup(t,e,i){if(!this.contentVisible)return;const s=this.ctx;let n;if(e.bitmap)n=e.bitmap;else{const t=e.width,i=e.height,s=this.cachedCanvases.getCanvas("inlineImage",t,i),r=s.context;Ci(r,e),n=this.applyTransferMapsToCanvas(r)}this.dependencyTracker?.resetBBox(t);for(const r of i)s.save(),s.transform(...r.transform),s.scale(1,-1),Si(s,n,r.x,r.y,r.w,r.h,0,-1,1,1),this.dependencyTracker?.recordBBox(t,s,0,1,-1,0),s.restore();this.dependencyTracker?.recordOperation(t),this.compose()}paintSolidColorImageMask(t){this.contentVisible&&(this.dependencyTracker?.resetBBox(t).recordBBox(t,this.ctx,0,1,0,1).recordDependencies(t,ei.fill).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 s=this.current.isEmptyClip();this.pendingClip&&this.current.updateClipFromPath(),this.pendingClip||this.compose(i);const n=this.ctx;this.pendingClip?(s||(this.pendingClip===Li?n.clip(e,"evenodd"):n.clip(e)),this.pendingClip=null,this.dependencyTracker?.bboxToClipBoxDropOperation(t).recordFutureForcedDependency("clipPath",t)):this.dependencyTracker?.recordOperation(t),this.current.startNewPathAndClipBox(this.current.clipBox)}getSinglePixelWidth(){if(!this._cachedGetSinglePixelWidth){const t=Tt(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]),s=Math.hypot(t[1],t[3]);this._cachedGetSinglePixelWidth=Math.max(i,s)/e}}return this._cachedGetSinglePixelWidth}getScaleForStroking(){if(-1===this._cachedScaleForStroking[0]){const{lineWidth:t}=this.current,{a:e,b:i,c:s,d:n}=this.ctx.getTransform();let r,a;if(0===i&&0===s){const i=Math.abs(e),s=Math.abs(n);if(i===s)if(0===t)r=a=1/i;else{const e=i*t;r=a=e<1?1/e:1}else if(0===t)r=1/i,a=1/s;else{const e=i*t,n=s*t;r=e<1?1/e:1,a=n<1?1/n:1}}else{const o=Math.abs(e*n-i*s),l=Math.hypot(e,i),h=Math.hypot(s,n);if(0===t)r=h/o,a=l/o;else{const e=t*o;r=h>e?h/e:1,a=l>e?l/e:1}}this._cachedScaleForStroking[0]=r,this._cachedScaleForStroking[1]=a}return this._cachedScaleForStroking}rescaleAndStroke(t,e){const{ctx:i,current:{lineWidth:s}}=this,[n,r]=this.getScaleForStroking();if(n===r)return i.lineWidth=(s||1)*n,void i.stroke(t);const a=i.getLineDash();e&&i.save(),i.scale(n,r),yi.a=1/n,yi.d=1/r;const o=new Path2D;if(o.addPath(t,yi),a.length>0){const t=Math.max(n,r);i.setLineDash(a.map(e=>e/t)),i.lineDashOffset/=t}i.lineWidth=s||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 gr in x)void 0!==Fi.prototype[gr]&&(Fi.prototype[x[gr]]=Fi.prototype[gr]);class Oi{static#Ws=null;static#Vs="";static get workerPort(){return this.#Ws}static set workerPort(t){if(!("undefined"!==typeof Worker&&t instanceof Worker)&&null!==t)throw new Error("Invalid `workerPort` type.");this.#Ws=t}static get workerSrc(){return this.#Vs}static set workerSrc(t){if("string"!==typeof t)throw new Error("Invalid `workerSrc` type.");this.#Vs=t}}class Bi{#qs;#Xs;constructor({parsedData:t,rawData:e}){this.#qs=t,this.#Xs=e}getRaw(){return this.#Xs}get(t){return this.#qs.get(t)??null}[Symbol.iterator](){return this.#qs.entries()}}const Ni=Symbol("INTERNAL");class Ui{#Ys=!1;#Ks=!1;#Qs=!1;#Zs=!0;constructor(t,{name:e,intent:i,usage:s,rbGroups:n}){this.#Ys=!!(t&c.DISPLAY),this.#Ks=!!(t&c.PRINT),this.name=e,this.intent=i,this.usage=s,this.rbGroups=n}get visible(){if(this.#Qs)return this.#Zs;if(!this.#Zs)return!1;const{print:t,view:e}=this.usage;return this.#Ys?"OFF"!==e?.viewState:!this.#Ks||"OFF"!==t?.printState}_setVisible(t,e,i=!1){t!==Ni&&P("Internal method `_setVisible` called."),this.#Qs=i,this.#Zs=e}}class ji{#Js=null;#tn=new Map;#en=null;#in=null;constructor(t,e=c.DISPLAY){if(this.renderingIntent=e,this.name=null,this.creator=null,null!==t){this.name=t.name,this.creator=t.creator,this.#in=t.order;for(const i of t.groups)this.#tn.set(i.id,new Ui(e,i));if("OFF"===t.baseState)for(const t of this.#tn.values())t._setVisible(Ni,!1);for(const e of t.on)this.#tn.get(e)._setVisible(Ni,!0);for(const e of t.off)this.#tn.get(e)._setVisible(Ni,!1);this.#en=this.getHash()}}#sn(t){const e=t.length;if(e<2)return!0;const i=t[0];for(let s=1;s<e;s++){const e=t[s];let n;if(Array.isArray(e))n=this.#sn(e);else{if(!this.#tn.has(e))return D(`Optional content group not found: ${e}`),!0;n=this.#tn.get(e).visible}switch(i){case"And":if(!n)return!1;break;case"Or":if(n)return!0;break;case"Not":return!n;default:return!0}}return"And"===i}isVisible(t){if(0===this.#tn.size)return!0;if(!t)return M("Optional content group not defined."),!0;if("OCG"===t.type)return this.#tn.has(t.id)?this.#tn.get(t.id).visible:(D(`Optional content group not found: ${t.id}`),!0);if("OCMD"===t.type){if(t.expression)return this.#sn(t.expression);if(!t.policy||"AnyOn"===t.policy){for(const e of t.ids){if(!this.#tn.has(e))return D(`Optional content group not found: ${e}`),!0;if(this.#tn.get(e).visible)return!0}return!1}if("AllOn"===t.policy){for(const e of t.ids){if(!this.#tn.has(e))return D(`Optional content group not found: ${e}`),!0;if(!this.#tn.get(e).visible)return!1}return!0}if("AnyOff"===t.policy){for(const e of t.ids){if(!this.#tn.has(e))return D(`Optional content group not found: ${e}`),!0;if(!this.#tn.get(e).visible)return!0}return!1}if("AllOff"===t.policy){for(const e of t.ids){if(!this.#tn.has(e))return D(`Optional content group not found: ${e}`),!0;if(this.#tn.get(e).visible)return!1}return!0}return D(`Unknown optional content policy ${t.policy}.`),!0}return D(`Unknown group type ${t.type}.`),!0}setVisibility(t,e=!0,i=!0){const s=this.#tn.get(t);if(s){if(i&&e&&s.rbGroups.length)for(const e of s.rbGroups)for(const i of e)i!==t&&this.#tn.get(i)?._setVisible(Ni,!1,!0);s._setVisible(Ni,!!e,!0),this.#Js=null}else D(`Optional content group not found: ${t}`)}setOCGState({state:t,preserveRB:e}){let i;for(const s of t){switch(s){case"ON":case"OFF":case"Toggle":i=s;continue}const t=this.#tn.get(s);if(t)switch(i){case"ON":this.setVisibility(s,!0,e);break;case"OFF":this.setVisibility(s,!1,e);break;case"Toggle":this.setVisibility(s,!t.visible,e);break}}this.#Js=null}get hasInitialVisibility(){return null===this.#en||this.getHash()===this.#en}getOrder(){return this.#tn.size?this.#in?this.#in.slice():[...this.#tn.keys()]:null}getGroup(t){return this.#tn.get(t)||null}getHash(){if(null!==this.#Js)return this.#Js;const t=new oe;for(const[e,i]of this.#tn)t.update(`${e}:${i.visible}`);return this.#Js=t.hexdigest()}[Symbol.iterator](){return this.#tn.entries()}}class zi{constructor(t,{disableRange:e=!1,disableStream:i=!1}){I(t,'PDFDataTransportStream - missing required "pdfDataRangeTransport" argument.');const{length:s,initialData:n,progressiveDone:r,contentDispositionFilename:a}=t;if(this._queuedChunks=[],this._progressiveDone=r,this._contentDispositionFilename=a,n?.length>0){const t=n instanceof Uint8Array&&n.byteLength===n.buffer.byteLength?n.buffer:new Uint8Array(n).buffer;this._queuedChunks.push(t)}this._pdfDataRangeTransport=t,this._isStreamingSupported=!i,this._isRangeSupported=!e,this._contentLength=s,this._fullRequestReader=null,this._rangeReaders=[],t.addRangeListener((t,e)=>{this._onReceiveData({begin:t,chunk:e})}),t.addProgressListener((t,e)=>{this._onProgress({loaded:t,total:e})}),t.addProgressiveReadListener(t=>{this._onReceiveData({chunk:t})}),t.addProgressiveDoneListener(()=>{this._onProgressiveDone()}),t.transportReady()}_onReceiveData({begin:t,chunk:e}){const i=e instanceof Uint8Array&&e.byteLength===e.buffer.byteLength?e.buffer:new Uint8Array(e).buffer;if(void 0===t)this._fullRequestReader?this._fullRequestReader._enqueue(i):this._queuedChunks.push(i);else{const e=this._rangeReaders.some(function(e){return e._begin===t&&(e._enqueue(i),!0)});I(e,"_onReceiveData - no `PDFDataTransportStreamRangeReader` instance found.")}}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}_onProgress(t){void 0===t.total?this._rangeReaders[0]?.onProgress?.({loaded:t.loaded}):this._fullRequestReader?.onProgress?.({loaded:t.loaded,total:t.total})}_onProgressiveDone(){this._fullRequestReader?.progressiveDone(),this._progressiveDone=!0}_removeRangeReader(t){const e=this._rangeReaders.indexOf(t);e>=0&&this._rangeReaders.splice(e,1)}getFullReader(){I(!this._fullRequestReader,"PDFDataTransportStream.getFullReader can only be called once.");const t=this._queuedChunks;return this._queuedChunks=null,new Hi(this,t,this._progressiveDone,this._contentDispositionFilename)}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const i=new $i(this,t,e);return this._pdfDataRangeTransport.requestDataRange(t,e),this._rangeReaders.push(i),i}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(const e of this._rangeReaders.slice(0))e.cancel(t);this._pdfDataRangeTransport.abort()}}class Hi{constructor(t,e,i=!1,s=null){this._stream=t,this._done=i||!1,this._filename=mt(s)?s:null,this._queuedChunks=e||[],this._loaded=0;for(const n of this._queuedChunks)this._loaded+=n.byteLength;this._requests=[],this._headersReady=Promise.resolve(),t._fullRequestReader=this,this.onProgress=null}_enqueue(t){if(!this._done){if(this._requests.length>0){const e=this._requests.shift();e.resolve({value:t,done:!1})}else this._queuedChunks.push(t);this._loaded+=t.byteLength}}get headersReady(){return this._headersReady}get filename(){return this._filename}get isRangeSupported(){return this._stream._isRangeSupported}get isStreamingSupported(){return this._stream._isStreamingSupported}get contentLength(){return this._stream._contentLength}async read(){if(this._queuedChunks.length>0){const t=this._queuedChunks.shift();return{value:t,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0}progressiveDone(){this._done||(this._done=!0)}}class $i{constructor(t,e,i){this._stream=t,this._begin=e,this._end=i,this._queuedChunk=null,this._requests=[],this._done=!1,this.onProgress=null}_enqueue(t){if(!this._done){if(0===this._requests.length)this._queuedChunk=t;else{const e=this._requests.shift();e.resolve({value:t,done:!1});for(const t of this._requests)t.resolve({value:void 0,done:!0});this._requests.length=0}this._done=!0,this._stream._removeRangeReader(this)}}get isStreamingSupported(){return!1}async read(){if(this._queuedChunk){const t=this._queuedChunk;return this._queuedChunk=null,{value:t,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._stream._removeRangeReader(this)}}function Gi(t){let e=!0,i=s("filename\\*","i").exec(t);if(i){i=i[1];let t=o(i);return t=unescape(t),t=l(t),t=h(t),r(t)}if(i=a(t),i){const t=h(i);return r(t)}if(i=s("filename","i").exec(t),i){i=i[1];let t=o(i);return t=h(t),r(t)}function s(t,e){return new RegExp("(?:^|;)\\s*"+t+'\\s*=\\s*([^";\\s][^;\\s]*|"(?:[^"\\\\]|\\\\"?)+"?)',e)}function n(t,i){if(t){if(!/^[\x00-\xFF]+$/.test(i))return i;try{const s=new TextDecoder(t,{fatal:!0}),n=G(i);i=s.decode(n),e=!1}catch{}}return i}function r(t){return e&&/[\x80-\xff]/.test(t)&&(t=n("utf-8",t),e&&(t=n("iso-8859-1",t))),t}function a(t){const e=[];let i;const n=s("filename\\*((?!0\\d)\\d+)(\\*?)","ig");while(null!==(i=n.exec(t))){let[,t,s,n]=i;if(t=parseInt(t,10),t in e){if(0===t)break}else e[t]=[s,n]}const r=[];for(let s=0;s<e.length;++s){if(!(s in e))break;let[t,i]=e[s];i=o(i),t&&(i=unescape(i),0===s&&(i=l(i))),r.push(i)}return r.join("")}function o(t){if(t.startsWith('"')){const e=t.slice(1).split('\\"');for(let t=0;t<e.length;++t){const i=e[t].indexOf('"');-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 l(t){const e=t.indexOf("'");if(-1===e)return t;const i=t.slice(0,e),s=t.slice(e+1),r=s.replace(/^[^']*'/,"");return n(i,r)}function h(t){return!t.startsWith("=?")||/[\x00-\x19\x80-\xff]/.test(t)?t:t.replaceAll(/=\?([\w-]*)\?([QqBb])\?((?:[^?]|\?(?!=))*)\?=/g,function(t,e,i,s){if("q"===i||"Q"===i)return s=s.replaceAll("_"," "),s=s.replaceAll(/=([0-9a-fA-F]{2})/g,function(t,e){return String.fromCharCode(parseInt(e,16))}),n(e,s);try{s=atob(s)}catch{}return n(e,s)})}return""}function Wi(t,e){const i=new Headers;if(!t||!e||"object"!==typeof e)return i;for(const s in e){const t=e[s];void 0!==t&&i.append(s,t)}return i}function Vi(t){return URL.parse(t)?.origin??null}function qi({responseHeaders:t,isHttp:e,rangeChunkSize:i,disableRange:s}){const n={allowRangeRequests:!1,suggestedLength:void 0},r=parseInt(t.get("Content-Length"),10);if(!Number.isInteger(r))return n;if(n.suggestedLength=r,r<=2*i)return n;if(s||!e)return n;if("bytes"!==t.get("Accept-Ranges"))return n;const a=t.get("Content-Encoding")||"identity";return"identity"!==a||(n.allowRangeRequests=!0),n}function Xi(t){const e=t.get("Content-Disposition");if(e){let t=Gi(e);if(t.includes("%"))try{t=decodeURIComponent(t)}catch{}if(mt(t))return t}return null}function Yi(t,e){return new j(`Unexpected server response (${t}) while retrieving PDF "${e}".`,t,404===t||0===t&&e.startsWith("file:"))}function Ki(t){return 200===t||206===t}function Qi(t,e,i){return{method:"GET",headers:t,signal:i.signal,mode:"cors",credentials:e?"include":"same-origin",redirect:"follow"}}function Zi(t){return t instanceof Uint8Array?t.buffer:t instanceof ArrayBuffer?t:(D(`getArrayBuffer - unexpected data format: ${t}`),new Uint8Array(t).buffer)}class Ji{_responseOrigin=null;constructor(t){this.source=t,this.isHttp=/^https?:/i.test(t.url),this.headers=Wi(this.isHttp,t.httpHeaders),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}getFullReader(){return I(!this._fullRequestReader,"PDFFetchStream.getFullReader can only be called once."),this._fullRequestReader=new ts(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const i=new es(this,t,e);return this._rangeRequestReaders.push(i),i}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(const e of this._rangeRequestReaders.slice(0))e.cancel(t)}}class ts{constructor(t){this._stream=t,this._reader=null,this._loaded=0,this._filename=null;const e=t.source;this._withCredentials=e.withCredentials||!1,this._contentLength=e.length,this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,this._rangeChunkSize||this._disableRange||(this._disableRange=!0),this._abortController=new AbortController,this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange;const i=new Headers(t.headers),s=e.url;fetch(s,Qi(i,this._withCredentials,this._abortController)).then(e=>{if(t._responseOrigin=Vi(e.url),!Ki(e.status))throw Yi(e.status,s);this._reader=e.body.getReader(),this._headersCapability.resolve();const i=e.headers,{allowRangeRequests:n,suggestedLength:r}=qi({responseHeaders:i,isHttp:t.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});this._isRangeSupported=n,this._contentLength=r||this._contentLength,this._filename=Xi(i),!this._isStreamingSupported&&this._isRangeSupported&&this.cancel(new H("Streaming is disabled."))}).catch(this._headersCapability.reject),this.onProgress=null}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(){await this._headersCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,this.onProgress?.({loaded:this._loaded,total:this._contentLength}),{value:Zi(t),done:!1})}cancel(t){this._reader?.cancel(t),this._abortController.abort()}}class es{constructor(t,e,i){this._stream=t,this._reader=null,this._loaded=0;const s=t.source;this._withCredentials=s.withCredentials||!1,this._readCapability=Promise.withResolvers(),this._isStreamingSupported=!s.disableStream,this._abortController=new AbortController;const n=new Headers(t.headers);n.append("Range",`bytes=${e}-${i-1}`);const r=s.url;fetch(r,Qi(n,this._withCredentials,this._abortController)).then(e=>{const i=Vi(e.url);if(i!==t._responseOrigin)throw new Error(`Expected range response-origin "${i}" to match "${t._responseOrigin}".`);if(!Ki(e.status))throw Yi(e.status,r);this._readCapability.resolve(),this._reader=e.body.getReader()}).catch(this._readCapability.reject),this.onProgress=null}get isStreamingSupported(){return this._isStreamingSupported}async read(){await this._readCapability.promise;const{value:t,done:e}=await this._reader.read();return e?{value:t,done:e}:(this._loaded+=t.byteLength,this.onProgress?.({loaded:this._loaded}),{value:Zi(t),done:!1})}cancel(t){this._reader?.cancel(t),this._abortController.abort()}}const is=200,ss=206;function ns(t){const e=t.response;return"string"!==typeof e?e:G(e).buffer}class rs{_responseOrigin=null;constructor({url:t,httpHeaders:e,withCredentials:i}){this.url=t,this.isHttp=/^https?:/i.test(t),this.headers=Wi(this.isHttp,e),this.withCredentials=i||!1,this.currXhrId=0,this.pendingRequests=Object.create(null)}request(t){const e=new XMLHttpRequest,i=this.currXhrId++,s=this.pendingRequests[i]={xhr:e};e.open("GET",this.url),e.withCredentials=this.withCredentials;for(const[n,r]of this.headers)e.setRequestHeader(n,r);return this.isHttp&&"begin"in t&&"end"in t?(e.setRequestHeader("Range",`bytes=${t.begin}-${t.end-1}`),s.expectedStatus=ss):s.expectedStatus=is,e.responseType="arraybuffer",I(t.onError,"Expected `onError` callback to be provided."),e.onerror=()=>{t.onError(e.status)},e.onreadystatechange=this.onStateChange.bind(this,i),e.onprogress=this.onProgress.bind(this,i),s.onHeadersReceived=t.onHeadersReceived,s.onDone=t.onDone,s.onError=t.onError,s.onProgress=t.onProgress,e.send(null),i}onProgress(t,e){const i=this.pendingRequests[t];i&&i.onProgress?.(e)}onStateChange(t,e){const i=this.pendingRequests[t];if(!i)return;const s=i.xhr;if(s.readyState>=2&&i.onHeadersReceived&&(i.onHeadersReceived(),delete i.onHeadersReceived),4!==s.readyState)return;if(!(t in this.pendingRequests))return;if(delete this.pendingRequests[t],0===s.status&&this.isHttp)return void i.onError(s.status);const n=s.status||is,r=n===is&&i.expectedStatus===ss;if(!r&&n!==i.expectedStatus)return void i.onError(s.status);const a=ns(s);if(n===ss){const t=s.getResponseHeader("Content-Range"),e=/bytes (\d+)-(\d+)\/(\d+)/.exec(t);e?i.onDone({begin:parseInt(e[1],10),chunk:a}):(D('Missing or invalid "Content-Range" header.'),i.onError(0))}else a?i.onDone({begin:0,chunk:a}):i.onError(s.status)}getRequestXhr(t){return this.pendingRequests[t].xhr}isPendingRequest(t){return t in this.pendingRequests}abortRequest(t){const e=this.pendingRequests[t].xhr;delete this.pendingRequests[t],e.abort()}}class as{constructor(t){this._source=t,this._manager=new rs(t),this._rangeChunkSize=t.rangeChunkSize,this._fullRequestReader=null,this._rangeRequestReaders=[]}_onRangeRequestReaderClosed(t){const e=this._rangeRequestReaders.indexOf(t);e>=0&&this._rangeRequestReaders.splice(e,1)}getFullReader(){return I(!this._fullRequestReader,"PDFNetworkStream.getFullReader can only be called once."),this._fullRequestReader=new os(this._manager,this._source),this._fullRequestReader}getRangeReader(t,e){const i=new ls(this._manager,t,e);return i.onClosed=this._onRangeRequestReaderClosed.bind(this),this._rangeRequestReaders.push(i),i}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(const e of this._rangeRequestReaders.slice(0))e.cancel(t)}}class os{constructor(t,e){this._manager=t,this._url=e.url,this._fullRequestId=t.request({onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._headersCapability=Promise.withResolvers(),this._disableRange=e.disableRange||!1,this._contentLength=e.length,this._rangeChunkSize=e.rangeChunkSize,this._rangeChunkSize||this._disableRange||(this._disableRange=!0),this._isStreamingSupported=!1,this._isRangeSupported=!1,this._cachedChunks=[],this._requests=[],this._done=!1,this._storedError=void 0,this._filename=null,this.onProgress=null}_onHeadersReceived(){const t=this._fullRequestId,e=this._manager.getRequestXhr(t);this._manager._responseOrigin=Vi(e.responseURL);const i=e.getAllResponseHeaders(),s=new Headers(i?i.trimStart().replace(/[^\S ]+$/,"").split(/[\r\n]+/).map(t=>{const[e,...i]=t.split(": ");return[e,i.join(": ")]}):[]),{allowRangeRequests:n,suggestedLength:r}=qi({responseHeaders:s,isHttp:this._manager.isHttp,rangeChunkSize:this._rangeChunkSize,disableRange:this._disableRange});n&&(this._isRangeSupported=!0),this._contentLength=r||this._contentLength,this._filename=Xi(s),this._isRangeSupported&&this._manager.abortRequest(t),this._headersCapability.resolve()}_onDone(t){if(t)if(this._requests.length>0){const e=this._requests.shift();e.resolve({value:t.chunk,done:!1})}else this._cachedChunks.push(t.chunk);if(this._done=!0,!(this._cachedChunks.length>0)){for(const t of this._requests)t.resolve({value:void 0,done:!0});this._requests.length=0}}_onError(t){this._storedError=Yi(t,this._url),this._headersCapability.reject(this._storedError);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._cachedChunks.length=0}_onProgress(t){this.onProgress?.({loaded:t.loaded,total:t.lengthComputable?t.total:this._contentLength})}get filename(){return this._filename}get isRangeSupported(){return this._isRangeSupported}get isStreamingSupported(){return this._isStreamingSupported}get contentLength(){return this._contentLength}get headersReady(){return this._headersCapability.promise}async read(){if(await this._headersCapability.promise,this._storedError)throw this._storedError;if(this._cachedChunks.length>0){const t=this._cachedChunks.shift();return{value:t,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0,this._headersCapability.reject(t);for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._fullRequestId)&&this._manager.abortRequest(this._fullRequestId),this._fullRequestReader=null}}class ls{constructor(t,e,i){this._manager=t,this._url=t.url,this._requestId=t.request({begin:e,end:i,onHeadersReceived:this._onHeadersReceived.bind(this),onDone:this._onDone.bind(this),onError:this._onError.bind(this),onProgress:this._onProgress.bind(this)}),this._requests=[],this._queuedChunk=null,this._done=!1,this._storedError=void 0,this.onProgress=null,this.onClosed=null}_onHeadersReceived(){const t=Vi(this._manager.getRequestXhr(this._requestId)?.responseURL);t!==this._manager._responseOrigin&&(this._storedError=new Error(`Expected range response-origin "${t}" to match "${this._manager._responseOrigin}".`),this._onError(0))}_close(){this.onClosed?.(this)}_onDone(t){const e=t.chunk;if(this._requests.length>0){const t=this._requests.shift();t.resolve({value:e,done:!1})}else this._queuedChunk=e;this._done=!0;for(const i of this._requests)i.resolve({value:void 0,done:!0});this._requests.length=0,this._close()}_onError(t){this._storedError??=Yi(t,this._url);for(const e of this._requests)e.reject(this._storedError);this._requests.length=0,this._queuedChunk=null}_onProgress(t){this.isStreamingSupported||this.onProgress?.({loaded:t.loaded})}get isStreamingSupported(){return!1}async read(){if(this._storedError)throw this._storedError;if(null!==this._queuedChunk){const t=this._queuedChunk;return this._queuedChunk=null,{value:t,done:!1}}if(this._done)return{value:void 0,done:!0};const t=Promise.withResolvers();return this._requests.push(t),t.promise}cancel(t){this._done=!0;for(const e of this._requests)e.resolve({value:void 0,done:!0});this._requests.length=0,this._manager.isPendingRequest(this._requestId)&&this._manager.abortRequest(this._requestId),this._close()}}const hs=/^[a-z][a-z0-9\-+.]+:/i;function cs(t){if(hs.test(t))return new URL(t);const e=process.getBuiltinModule("url");return new URL(e.pathToFileURL(t))}class ds{constructor(t){this.source=t,this.url=cs(t.url),I("file:"===this.url.protocol,"PDFNodeStream only supports file:// URLs."),this._fullRequestReader=null,this._rangeRequestReaders=[]}get _progressiveDataLength(){return this._fullRequestReader?._loaded??0}getFullReader(){return I(!this._fullRequestReader,"PDFNodeStream.getFullReader can only be called once."),this._fullRequestReader=new us(this),this._fullRequestReader}getRangeReader(t,e){if(e<=this._progressiveDataLength)return null;const i=new ps(this,t,e);return this._rangeRequestReaders.push(i),i}cancelAllRequests(t){this._fullRequestReader?.cancel(t);for(const e of this._rangeRequestReaders.slice(0))e.cancel(t)}}class us{constructor(t){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null;const e=t.source;this._contentLength=e.length,this._loaded=0,this._filename=null,this._disableRange=e.disableRange||!1,this._rangeChunkSize=e.rangeChunkSize,this._rangeChunkSize||this._disableRange||(this._disableRange=!0),this._isStreamingSupported=!e.disableStream,this._isRangeSupported=!e.disableRange,this._readableStream=null,this._readCapability=Promise.withResolvers(),this._headersCapability=Promise.withResolvers();const i=process.getBuiltinModule("fs");i.promises.lstat(this._url).then(t=>{this._contentLength=t.size,this._setReadableStream(i.createReadStream(this._url)),this._headersCapability.resolve()},t=>{"ENOENT"===t.code&&(t=Yi(0,this._url.href)),this._storedError=t,this._headersCapability.reject(t)})}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(){if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();if(null===t)return this._readCapability=Promise.withResolvers(),this.read();this._loaded+=t.length,this.onProgress?.({loaded:this._loaded,total:this._contentLength});const e=new Uint8Array(t).buffer;return{value:e,done:!1}}cancel(t){this._readableStream?this._readableStream.destroy(t):this._error(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",t=>{this._error(t)}),!this._isStreamingSupported&&this._isRangeSupported&&this._error(new H("streaming is disabled")),this._storedError&&this._readableStream.destroy(this._storedError)}}class ps{constructor(t,e,i){this._url=t.url,this._done=!1,this._storedError=null,this.onProgress=null,this._loaded=0,this._readableStream=null,this._readCapability=Promise.withResolvers();const s=t.source;this._isStreamingSupported=!s.disableStream;const n=process.getBuiltinModule("fs");this._setReadableStream(n.createReadStream(this._url,{start:e,end:i-1}))}get isStreamingSupported(){return this._isStreamingSupported}async read(){if(await this._readCapability.promise,this._done)return{value:void 0,done:!0};if(this._storedError)throw this._storedError;const t=this._readableStream.read();if(null===t)return this._readCapability=Promise.withResolvers(),this.read();this._loaded+=t.length,this.onProgress?.({loaded:this._loaded});const e=new Uint8Array(t).buffer;return{value:e,done:!1}}cancel(t){this._readableStream?this._readableStream.destroy(t):this._error(t)}_error(t){this._storedError=t,this._readCapability.resolve()}_setReadableStream(t){this._readableStream=t,t.on("readable",()=>{this._readCapability.resolve()}),t.on("end",()=>{t.destroy(),this._done=!0,this._readCapability.resolve()}),t.on("error",t=>{this._error(t)}),this._storedError&&this._readableStream.destroy(this._storedError)}}const gs=Symbol("INITIAL_DATA");class ms{#nn=Object.create(null);#rn(t){return this.#nn[t]||={...Promise.withResolvers(),data:gs}}get(t,e=null){if(e){const i=this.#rn(t);return i.promise.then(()=>e(i.data)),null}const i=this.#nn[t];if(!i||i.data===gs)throw new Error(`Requesting object that isn't resolved yet ${t}.`);return i.data}has(t){const e=this.#nn[t];return!!e&&e.data!==gs}delete(t){const e=this.#nn[t];return!(!e||e.data===gs)&&(delete this.#nn[t],!0)}resolve(t,e=null){const i=this.#rn(t);i.data=e,i.resolve()}clear(){for(const t in this.#nn){const{data:e}=this.#nn[t];e?.bitmap?.close()}this.#nn=Object.create(null)}*[Symbol.iterator](){for(const t in this.#nn){const{data:e}=this.#nn[t];e!==gs&&(yield[t,e])}}}const fs=1e5,bs=30;class vs{#an=Promise.withResolvers();#Et=null;#on=!1;#ln=!!globalThis.FontInspector?.enabled;#hn=null;#cn=null;#dn=0;#un=0;#pn=null;#gn=null;#mn=0;#fn=0;#bn=Object.create(null);#vn=[];#yn=null;#wn=[];#An=new WeakMap;#xn=null;static#_n=new Map;static#Sn=new Map;static#En=new WeakMap;static#Cn=null;static#Tn=new Set;constructor({textContentSource:t,container:e,viewport:i}){if(t instanceof ReadableStream)this.#yn=t;else{if("object"!==typeof t)throw new Error('No "textContentSource" parameter specified.');this.#yn=new ReadableStream({start(e){e.enqueue(t),e.close()}})}this.#Et=this.#gn=e,this.#fn=i.scale*Pt.pixelRatio,this.#mn=i.rotation,this.#cn={div:null,properties:null,ctx:null};const{pageWidth:s,pageHeight:n,pageX:r,pageY:a}=i.rawDims;this.#xn=[1,0,0,-1,-r,a+n],this.#un=s,this.#dn=n,vs.#Mn(),e.style.setProperty("--min-font-size",vs.#Cn),Dt(e,i),this.#an.promise.finally(()=>{vs.#Tn.delete(this),this.#cn=null,this.#bn=null}).catch(()=>{})}static get fontFamilyMap(){const{isWindows:t,isFirefox:e}=X.platform;return F(this,"fontFamilyMap",new Map([["sans-serif",(t&&e?"Calibri, ":"")+"sans-serif"],["monospace",(t&&e?"Lucida Console, ":"")+"monospace"]]))}render(){const t=()=>{this.#pn.read().then(({value:e,done:i})=>{i?this.#an.resolve():(this.#hn??=e.lang,Object.assign(this.#bn,e.styles),this.#Dn(e.items),t())},this.#an.reject)};return this.#pn=this.#yn.getReader(),vs.#Tn.add(this),t(),this.#an.promise}update({viewport:t,onBefore:e=null}){const i=t.scale*Pt.pixelRatio,s=t.rotation;if(s!==this.#mn&&(e?.(),this.#mn=s,Dt(this.#gn,{rotation:s})),i!==this.#fn){e?.(),this.#fn=i;const t={div:null,properties:null,ctx:vs.#Pn(this.#hn)};for(const e of this.#wn)t.properties=this.#An.get(e),t.div=e,this.#In(t)}}cancel(){const t=new H("TextLayer task cancelled.");this.#pn?.cancel(t).catch(()=>{}),this.#pn=null,this.#an.reject(t)}get textDivs(){return this.#wn}get textContentItemsStr(){return this.#vn}#Dn(t){if(this.#on)return;this.#cn.ctx??=vs.#Pn(this.#hn);const e=this.#wn,i=this.#vn;for(const s of t){if(e.length>fs)return D("Ignoring additional textDivs for performance reasons."),void(this.#on=!0);if(void 0!==s.str)i.push(s.str),this.#kn(s);else if("beginMarkedContentProps"===s.type||"beginMarkedContent"===s.type){const t=this.#Et;this.#Et=document.createElement("span"),this.#Et.classList.add("markedContent"),s.id&&this.#Et.setAttribute("id",`${s.id}`),t.append(this.#Et)}else"endMarkedContent"===s.type&&(this.#Et=this.#Et.parentNode)}}#kn(t){const e=document.createElement("span"),i={angle:0,canvasWidth:0,hasText:""!==t.str,hasEOL:t.hasEOL,fontSize:0};this.#wn.push(e);const s=K.transform(this.#xn,t.transform);let n=Math.atan2(s[1],s[0]);const r=this.#bn[t.fontName];r.vertical&&(n+=Math.PI/2);let a=this.#ln&&r.fontSubstitution||r.fontFamily;a=vs.fontFamilyMap.get(a)||a;const o=Math.hypot(s[2],s[3]),l=o*vs.#Rn(a,r,this.#hn);let h,c;0===n?(h=s[4],c=s[5]-l):(h=s[4]+l*Math.sin(n),c=s[5]-l*Math.cos(n));const d=e.style;d.left=`${(100*h/this.#un).toFixed(2)}%`,d.top=`${(100*c/this.#dn).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.#ln&&(e.dataset.fontName=r.fontSubstitutionLoadedName||t.fontName),0!==n&&(i.angle=n*(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)}if(u&&(i.canvasWidth=r.vertical?t.height:t.width),this.#An.set(e,i),this.#cn.div=e,this.#cn.properties=i,this.#In(this.#cn),i.hasText&&this.#Et.append(e),i.hasEOL){const t=document.createElement("br");t.setAttribute("role","presentation"),this.#Et.append(t)}}#In(t){const{div:e,properties:i,ctx:s}=t,{style:n}=e;if(0!==i.canvasWidth&&i.hasText){const{fontFamily:t}=n,{canvasWidth:r,fontSize:a}=i;vs.#Ln(s,a*this.#fn,t);const{width:o}=s.measureText(e.textContent);o>0&&n.setProperty("--scale-x",r*this.#fn/o)}0!==i.angle&&n.setProperty("--rotate",`${i.angle}deg`)}static cleanup(){if(!(this.#Tn.size>0)){this.#_n.clear();for(const{canvas:t}of this.#Sn.values())t.remove();this.#Sn.clear()}}static#Pn(t=null){let e=this.#Sn.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.#Sn.set(t,e),this.#En.set(e,{size:0,family:""})}return e}static#Ln(t,e,i){const s=this.#En.get(t);e===s.size&&i===s.family||(t.font=`${e}px ${i}`,s.size=e,s.family=i)}static#Mn(){if(null!==this.#Cn)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.#Cn=t.getBoundingClientRect().height,t.remove()}static#Rn(t,e,i){const s=this.#_n.get(t);if(s)return s;const n=this.#Pn(i);n.canvas.width=n.canvas.height=bs,this.#Ln(n,bs,t);const r=n.measureText(""),a=r.fontBoundingBoxAscent,o=Math.abs(r.fontBoundingBoxDescent);n.canvas.width=n.canvas.height=0;let l=.8;return a?l=a/(a+o):(X.platform.isFirefox&&D("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.#_n.set(t,l),l}}const ys=100;function ws(t={}){"string"===typeof t||t instanceof URL?t={url:t}:(t instanceof ArrayBuffer||ArrayBuffer.isView(t))&&(t={data:t});const e=new As,{docId:i}=e,s=t.url?ve(t.url):null,n=t.data?ye(t.data):null,r=t.httpHeaders||null,a=!0===t.withCredentials,l=t.password??null,h=t.range instanceof xs?t.range:null,c=Number.isInteger(t.rangeChunkSize)&&t.rangeChunkSize>0?t.rangeChunkSize:65536;let d=t.worker instanceof Es?t.worker:null;const u=t.verbosity,p="string"!==typeof t.docBaseUrl||gt(t.docBaseUrl)?null:t.docBaseUrl,g=we(t.cMapUrl),m=!1!==t.cMapPacked,f=t.CMapReaderFactory||(o?$e:Re),b=we(t.iccUrl),v=we(t.standardFontDataUrl),y=t.StandardFontDataFactory||(o?Ge:Be),w=we(t.wasmUrl),A=t.WasmFactory||(o?We:Ue),x=!0!==t.stopAtErrors,_=Number.isInteger(t.maxImageSize)&&t.maxImageSize>-1?t.maxImageSize:-1,S=!1!==t.isEvalSupported,E="boolean"===typeof t.isOffscreenCanvasSupported?t.isOffscreenCanvasSupported:!o,T="boolean"===typeof t.isImageDecoderSupported?t.isImageDecoderSupported:!o&&(X.platform.isFirefox||!globalThis.chrome),M=Number.isInteger(t.canvasMaxAreaInBytes)?t.canvasMaxAreaInBytes:-1,D="boolean"===typeof t.disableFontFace?t.disableFontFace:o,P=!0===t.fontExtraProperties,I=!0===t.enableXfa,k=t.ownerDocument||globalThis.document,R=!0===t.disableRange,L=!0===t.disableStream,F=!0===t.disableAutoFetch,O=!0===t.pdfBug,B=t.CanvasFactory||(o?He:Ie),N=t.FilterFactory||(o?ze:Fe),U=!0===t.enableHWA,j=!1!==t.useWasm,z=h?h.length:t.length??NaN,H="boolean"===typeof t.useSystemFonts?t.useSystemFonts:!o&&!D,$="boolean"===typeof t.useWorkerFetch?t.useWorkerFetch:!!(f===Re&&y===Be&&A===Ue&&g&&v&&w&&yt(g,document.baseURI)&&yt(v,document.baseURI)&&yt(w,document.baseURI)),G=null;C(u);const W={canvasFactory:new B({ownerDocument:k,enableHWA:U}),filterFactory:new N({docId:i,ownerDocument:k}),cMapReaderFactory:$?null:new f({baseUrl:g,isCompressed:m}),standardFontDataFactory:$?null:new y({baseUrl:v}),wasmFactory:$?null:new A({baseUrl:w})};d||(d=Es.create({verbosity:u,port:Oi.workerPort}),e._worker=d);const V={docId:i,apiVersion:"5.4.530",data:n,password:l,disableAutoFetch:F,rangeChunkSize:c,length:z,docBaseUrl:p,enableXfa:I,evaluatorOptions:{maxImageSize:_,disableFontFace:D,ignoreErrors:x,isEvalSupported:S,isOffscreenCanvasSupported:E,isImageDecoderSupported:T,canvasMaxAreaInBytes:M,fontExtraProperties:P,useSystemFonts:H,useWasm:j,useWorkerFetch:$,cMapUrl:g,iccUrl:b,standardFontDataUrl:v,wasmUrl:w}},q={ownerDocument:k,pdfBug:O,styleElement:G,loadingParams:{disableAutoFetch:F,enableXfa:I}};return d.promise.then(function(){if(e.destroyed)throw new Error("Loading aborted");if(d.destroyed)throw new Error("Worker was destroyed");const t=d.messageHandler.sendWithPromise("GetDocRequest",V,n?[n.buffer]:null);let l;if(h)l=new zi(h,{disableRange:R,disableStream:L});else if(!n){if(!s)throw new Error("getDocument - no `url` parameter provided.");const t=yt(s)?Ji:o?ds:as;l=new t({url:s,length:z,httpHeaders:r,withCredentials:a,rangeChunkSize:c,disableRange:R,disableStream:L})}return t.then(t=>{if(e.destroyed)throw new Error("Loading aborted");if(d.destroyed)throw new Error("Worker was destroyed");const s=new De(i,t,d.port),n=new Cs(s,e,l,q,W,U);e._transport=n,s.send("Ready",null)})}).catch(e._capability.reject),e}class As{static#ns=0;_capability=Promise.withResolvers();_transport=null;_worker=null;docId="d"+As.#ns++;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){throw this._worker?.port&&delete this._worker._pendingDestroy,t}this._transport=null,this._worker?.destroy(),this._worker=null}async getData(){return this._transport.getData()}}class xs{#an=Promise.withResolvers();#Fn=[];#On=[];#Bn=[];#Nn=[];constructor(t,e,i=!1,s=null){this.length=t,this.initialData=e,this.progressiveDone=i,this.contentDispositionFilename=s}addRangeListener(t){this.#Nn.push(t)}addProgressListener(t){this.#Bn.push(t)}addProgressiveReadListener(t){this.#On.push(t)}addProgressiveDoneListener(t){this.#Fn.push(t)}onDataRange(t,e){for(const i of this.#Nn)i(t,e)}onDataProgress(t,e){this.#an.promise.then(()=>{for(const i of this.#Bn)i(t,e)})}onDataProgressiveRead(t){this.#an.promise.then(()=>{for(const e of this.#On)e(t)})}onDataProgressiveDone(){this.#an.promise.then(()=>{for(const t of this.#Fn)t()})}transportReady(){this.#an.resolve()}requestDataRange(t,e){P("Abstract method PDFDataRangeTransport.requestDataRange")}abort(){}}class _s{constructor(t,e){this._pdfInfo=t,this._transport=e}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 F(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}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 Ss{#Un=!1;constructor(t,e,i,s=!1){this._pageIndex=t,this._pageInfo=e,this._transport=i,this._stats=s?new vt:null,this._pdfBug=s,this.commonObjs=i.commonObjs,this.objs=new ms,this._intentStates=new Map,this.destroyed=!1,this.recordedBBoxes=null}get pageNumber(){return this._pageIndex+1}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:s=0,dontFlip:n=!1}={}){return new ut({viewBox:this.view,userUnit:this.userUnit,scale:t,rotation:e,offsetX:i,offsetY:s,dontFlip:n})}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 F(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:s="display",annotationMode:n=d.ENABLE,transform:r=null,background:a=null,optionalContentConfigPromise:o=null,annotationCanvasMap:l=null,pageColors:h=null,printAnnotationStorage:u=null,isEditing:p=!1,recordOperations:g=!1,operationsFilter:m=null}){this._stats?.time("Overall");const f=this._transport.getRenderingIntent(s,n,u,p),{renderingIntent:b,cacheKey:v}=f;this.#Un=!1,o||=this._transport.getOptionalContentConfig(b);let y=this._intentStates.get(v);y||(y=Object.create(null),this._intentStates.set(v,y)),y.streamReaderCancelTimeout&&(clearTimeout(y.streamReaderCancelTimeout),y.streamReaderCancelTimeout=null);const w=!!(b&c.PRINT);y.displayReadyCapability||(y.displayReadyCapability=Promise.withResolvers(),y.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time("Page Request"),this._pumpOperatorList(f));const A=Boolean(this._pdfBug&&globalThis.StepperManager?.enabled),x=!this.recordedBBoxes&&(g||A),_=t=>{if(y.renderTasks.delete(S),x){const t=S.gfx?.dependencyTracker.take();t&&(S.stepper&&S.stepper.setOperatorBBoxes(t,S.gfx.dependencyTracker.takeDebugMetadata()),g&&(this.recordedBBoxes=t))}w&&(this.#Un=!0),this.#jn(),t?(S.capability.reject(t),this._abortOperatorList({intentState:y,reason:t instanceof Error?t:new Error(t)})):S.capability.resolve(),this._stats&&(this._stats.timeEnd("Rendering"),this._stats.timeEnd("Overall"),globalThis.Stats?.enabled&&globalThis.Stats.add(this.pageNumber,this._stats))},S=new Ms({callback:_,params:{canvas:e,canvasContext:t,dependencyTracker:x?new Je(e,y.operatorList.length,A):null,viewport:i,transform:r,background:a},objs:this.objs,commonObjs:this.commonObjs,annotationCanvasMap:l,operatorList:y.operatorList,pageIndex:this._pageIndex,canvasFactory:this._transport.canvasFactory,filterFactory:this._transport.filterFactory,useRequestAnimationFrame:!w,pdfBug:this._pdfBug,pageColors:h,enableHWA:this._transport.enableHWA,operationsFilter:m});(y.renderTasks||=new Set).add(S);const E=S.task;return Promise.all([y.displayReadyCapability.promise,o]).then(([t,e])=>{if(this.destroyed)_();else{if(this._stats?.time("Rendering"),!(e.renderingIntent&b))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(_),E}getOperatorList({intent:t="display",annotationMode:e=d.ENABLE,printAnnotationStorage:i=null,isEditing:s=!1}={}){function n(){o.operatorList.lastChunk&&(o.opListReadCapability.resolve(o.operatorList),o.renderTasks.delete(a))}const r=this._transport.getRenderingIntent(t,e,i,s,!0);let a,o=this._intentStates.get(r.cacheKey);return o||(o=Object.create(null),this._intentStates.set(r.cacheKey,o)),o.opListReadCapability||(a=Object.create(null),a.operatorListChanged=n,o.opListReadCapability=Promise.withResolvers(),(o.renderTasks||=new Set).add(a),o.operatorList={fnArray:[],argsArray:[],lastChunk:!1,separateAnnots:null},this._stats?.time("Page Request"),this._pumpOperatorList(r)),o.opListReadCapability.promise}streamTextContent({includeMarkedContent:t=!1,disableNormalization:e=!1}={}){const i=100;return this._transport.messageHandler.sendWithStream("GetTextContent",{pageIndex:this._pageIndex,includeMarkedContent:!0===t,disableNormalization:!0===e},{highWaterMark:i,size(t){return t.items.length}})}getTextContent(t={}){if(this._transport._htmlForXfa)return this.getXfa().then(t=>ot.textContent(t));const e=this.streamTextContent(t);return new Promise(function(t,i){function s(){n.read().then(function({value:e,done:i}){i?t(r):(r.lang??=e.lang,Object.assign(r.styles,e.styles),r.items.push(...e.items),s())},i)}const n=e.getReader(),r={items:[],styles:Object.create(null),lang:null};s()})}getStructTree(){return this._transport.getStructTree(this._pageIndex)}_destroy(){this.destroyed=!0;const t=[];for(const e of this._intentStates.values())if(this._abortOperatorList({intentState:e,reason:new Error("Page was destroyed."),force:!0}),!e.opListReadCapability)for(const i of e.renderTasks)t.push(i.completed),i.cancel();return this.objs.clear(),this.#Un=!1,Promise.all(t)}cleanup(t=!1){this.#Un=!0;const e=this.#jn();return t&&e&&(this._stats&&=new vt),e}#jn(){if(!this.#Un||this.destroyed)return!1;for(const{renderTasks:t,operatorList:e}of this._intentStates.values())if(t.size>0||!e.lastChunk)return!1;return this._intentStates.clear(),this.objs.clear(),this.#Un=!1,!0}_startRenderPage(t,e){const i=this._intentStates.get(e);i&&(this._stats?.timeEnd("Page Request"),i.displayReadyCapability?.resolve(t))}_renderPageChunk(t,e){for(let i=0,s=t.length;i<s;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 i of e.renderTasks)i.operatorListChanged();t.lastChunk&&this.#jn()}_pumpOperatorList({renderingIntent:t,cacheKey:e,annotationStorageSerializable:i,modifiedIds:s}){const{map:n,transfer:r}=i,a=this._transport.messageHandler.sendWithStream("GetOperatorList",{pageIndex:this._pageIndex,intent:t,cacheKey:e,annotationStorage:n,modifiedIds:s},r),o=a.getReader(),l=this._intentStates.get(e);l.streamReader=o;const h=()=>{o.read().then(({value:t,done:e})=>{e?l.streamReader=null:this._transport.destroyed||(this._renderPageChunk(t,l),h())},t=>{if(l.streamReader=null,!this._transport.destroyed){if(l.operatorList){l.operatorList.lastChunk=!0;for(const t of l.renderTasks)t.operatorListChanged();this.#jn()}if(l.displayReadyCapability)l.displayReadyCapability.reject(t);else{if(!l.opListReadCapability)throw t;l.opListReadCapability.reject(t)}}})};h()}_abortOperatorList({intentState:t,reason:e,force:i=!1}){if(t.streamReader){if(t.streamReaderCancelTimeout&&(clearTimeout(t.streamReaderCancelTimeout),t.streamReaderCancelTimeout=null),!i){if(t.renderTasks.size>0)return;if(e instanceof pt){let i=ys;return e.extraDelay>0&&e.extraDelay<1e3&&(i+=e.extraDelay),void(t.streamReaderCancelTimeout=setTimeout(()=>{t.streamReaderCancelTimeout=null,this._abortOperatorList({intentState:t,reason:e,force:!0})},i))}}if(t.streamReader.cancel(new H(e.message)).catch(()=>{}),t.streamReader=null,!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 Es{#an=Promise.withResolvers();#zn=null;#Ws=null;#Hn=null;static#$n=0;static#Gn=!1;static#Wn=new WeakMap;static{o&&(this.#Gn=!0,Oi.workerSrc||="./pdf.worker.mjs"),this._isSameOrigin=(t,e)=>{const i=URL.parse(t);if(!i?.origin||"null"===i.origin)return!1;const s=new URL(e,i);return i.origin===s.origin},this._createCDNWrapper=t=>{const e=`await import("${t}");`;return URL.createObjectURL(new Blob([e],{type:"text/javascript"}))},this.fromPort=t=>{if(xt("`PDFWorker.fromPort` - please use `PDFWorker.create` instead."),!t?.port)throw new Error("PDFWorker.fromPort - invalid method signature.");return this.create(t)}}constructor({name:t=null,port:e=null,verbosity:i=T()}={}){if(this.name=t,this.destroyed=!1,this.verbosity=i,e){if(Es.#Wn.has(e))throw new Error("Cannot use more than one PDFWorker per port.");Es.#Wn.set(e,this),this.#Vn(e)}else this.#qn()}get promise(){return this.#an.promise}#Xn(){this.#an.resolve(),this.#zn.send("configure",{verbosity:this.verbosity})}get port(){return this.#Ws}get messageHandler(){return this.#zn}#Vn(t){this.#Ws=t,this.#zn=new De("main","worker",t),this.#zn.on("ready",()=>{}),this.#Xn()}#qn(){if(Es.#Gn||Es.#Yn)return void this.#Kn();let{workerSrc:t}=Es;try{Es._isSameOrigin(window.location,t)||(t=Es._createCDNWrapper(new URL(t,window.location).href));const e=new Worker(t,{type:"module"}),i=new De("main","worker",e),s=()=>{n.abort(),i.destroy(),e.terminate(),this.destroyed?this.#an.reject(new Error("Worker was destroyed")):this.#Kn()},n=new AbortController;e.addEventListener("error",()=>{this.#Hn||s()},{signal:n.signal}),i.on("test",t=>{n.abort(),!this.destroyed&&t?(this.#zn=i,this.#Ws=e,this.#Hn=e,this.#Xn()):s()}),i.on("ready",t=>{if(n.abort(),this.destroyed)s();else try{r()}catch{this.#Kn()}});const r=()=>{const t=new Uint8Array;i.send("test",t,[t.buffer])};return void r()}catch{M("The worker has been disabled.")}this.#Kn()}#Kn(){Es.#Gn||(D("Setting up fake worker."),Es.#Gn=!0),Es._setupFakeWorkerGlobal.then(t=>{if(this.destroyed)return void this.#an.reject(new Error("Worker was destroyed"));const e=new Se;this.#Ws=e;const i="fake"+Es.#$n++,s=new De(i+"_worker",i,e);t.setup(s,e),this.#zn=new De(i,i+"_worker",e),this.#Xn()}).catch(t=>{this.#an.reject(new Error(`Setting up fake worker failed: "${t.message}".`))})}destroy(){this.destroyed=!0,this.#Hn?.terminate(),this.#Hn=null,Es.#Wn.delete(this.#Ws),this.#Ws=null,this.#zn?.destroy(),this.#zn=null}static create(t){const e=this.#Wn.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 Es(t)}static get workerSrc(){if(Oi.workerSrc)return Oi.workerSrc;throw new Error('No "GlobalWorkerOptions.workerSrc" specified.')}static get#Yn(){try{return globalThis.pdfjsWorker?.WorkerMessageHandler||null}catch{return null}}static get _setupFakeWorkerGlobal(){const t=async()=>{if(this.#Yn)return this.#Yn;const t=await import(this.workerSrc);return t.WorkerMessageHandler};return F(this,"_setupFakeWorkerGlobal",t())}}class Cs{#Qn=new Map;#Zn=new Map;#Jn=new Map;#tr=new Map;#er=null;constructor(t,e,i,s,n,r){this.messageHandler=t,this.loadingTask=e,this.commonObjs=new ms,this.fontLoader=new de({ownerDocument:s.ownerDocument,styleElement:s.styleElement}),this.loadingParams=s.loadingParams,this._params=s,this.canvasFactory=n.canvasFactory,this.filterFactory=n.filterFactory,this.cMapReaderFactory=n.cMapReaderFactory,this.standardFontDataFactory=n.standardFontDataFactory,this.wasmFactory=n.wasmFactory,this.destroyed=!1,this.destroyCapability=null,this._networkStream=i,this._fullReader=null,this._lastProgress=null,this.downloadInfoCapability=Promise.withResolvers(),this.enableHWA=r,this.setupMessageHandler()}#ir(t,e=null){const i=this.#Qn.get(t);if(i)return i;const s=this.messageHandler.sendWithPromise(t,e);return this.#Qn.set(t,s),s}get annotationStorage(){return F(this,"annotationStorage",new he)}getRenderingIntent(t,e=d.ENABLE,i=null,s=!1,n=!1){let r=c.DISPLAY,a=le;switch(t){case"any":r=c.ANY;break;case"display":break;case"print":r=c.PRINT;break;default:D(`getRenderingIntent - invalid intent: ${t}`)}const o=r&c.PRINT&&i instanceof ce?i:this.annotationStorage;switch(e){case d.DISABLE:r+=c.ANNOTATIONS_DISABLE;break;case d.ENABLE:break;case d.ENABLE_FORMS:r+=c.ANNOTATIONS_FORMS;break;case d.ENABLE_STORAGE:r+=c.ANNOTATIONS_STORAGE,a=o.serializable;break;default:D(`getRenderingIntent - invalid annotationMode: ${e}`)}s&&(r+=c.IS_EDITING),n&&(r+=c.OPLIST);const{ids:l,hash:h}=o.modifiedIds,u=[r,a.hash,h];return{renderingIntent:r,cacheKey:u.join("_"),annotationStorageSerializable:a,modifiedIds:l}}destroy(){if(this.destroyCapability)return this.destroyCapability.promise;this.destroyed=!0,this.destroyCapability=Promise.withResolvers(),this.#er?.reject(new Error("Worker was destroyed during onPassword callback"));const t=[];for(const i of this.#Zn.values())t.push(i._destroy());this.#Zn.clear(),this.#Jn.clear(),this.#tr.clear(),this.hasOwnProperty("annotationStorage")&&this.annotationStorage.resetModified();const e=this.messageHandler.sendWithPromise("Terminate",null);return t.push(e),Promise.all(t).then(()=>{this.commonObjs.clear(),this.fontLoader.clear(),this.#Qn.clear(),this.filterFactory.destroy(),vs.cleanup(),this._networkStream?.cancelAllRequests(new H("Worker was terminated.")),this.messageHandler?.destroy(),this.messageHandler=null,this.destroyCapability.resolve()},this.destroyCapability.reject),this.destroyCapability.promise}setupMessageHandler(){const{messageHandler:t,loadingTask:e}=this;t.on("GetReader",(t,e)=>{I(this._networkStream,"GetReader - no `IPDFStream` instance available."),this._fullReader=this._networkStream.getFullReader(),this._fullReader.onProgress=t=>{this._lastProgress={loaded:t.loaded,total:t.total}},e.onPull=()=>{this._fullReader.read().then(function({value:t,done:i}){i?e.close():(I(t instanceof ArrayBuffer,"GetReader - expected an ArrayBuffer."),e.enqueue(new Uint8Array(t),1,[t]))}).catch(t=>{e.error(t)})},e.onCancel=t=>{this._fullReader.cancel(t),e.ready.catch(t=>{if(!this.destroyed)throw t})}}),t.on("ReaderHeadersReady",async t=>{await this._fullReader.headersReady;const{isStreamingSupported:i,isRangeSupported:s,contentLength:n}=this._fullReader;return i&&s||(this._lastProgress&&e.onProgress?.(this._lastProgress),this._fullReader.onProgress=t=>{e.onProgress?.({loaded:t.loaded,total:t.total})}),{isStreamingSupported:i,isRangeSupported:s,contentLength:n}}),t.on("GetRangeReader",(t,e)=>{I(this._networkStream,"GetRangeReader - no `IPDFStream` instance available.");const i=this._networkStream.getRangeReader(t.begin,t.end);i?(e.onPull=()=>{i.read().then(function({value:t,done:i}){i?e.close():(I(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})}):e.close()}),t.on("GetDoc",({pdfInfo:t})=>{this._numPages=t.numPages,this._htmlForXfa=t.htmlForXfa,delete t.htmlForXfa,e._capability.resolve(new _s(t,this))}),t.on("DocException",t=>{e._capability.reject(Me(t))}),t.on("PasswordRequest",t=>{this.#er=Promise.withResolvers();try{if(!e.onPassword)throw Me(t);const i=t=>{t instanceof Error?this.#er.reject(t):this.#er.resolve({password:t})};e.onPassword(i,t.code)}catch(i){this.#er.reject(i)}return this.#er.promise}),t.on("DataLoaded",t=>{e.onProgress?.({loaded:t.length,total:t.length}),this.downloadInfoCapability.resolve(t)}),t.on("StartRenderPage",t=>{if(this.destroyed)return;const e=this.#Zn.get(t.pageIndex);e._startRenderPage(t.transparency,t.cacheKey)}),t.on("commonobj",([e,i,s])=>{if(this.destroyed)return null;if(this.commonObjs.has(e))return null;switch(i){case"Font":if("error"in s){const t=s.error;D(`Error during font loading: ${t}`),this.commonObjs.resolve(e,t);break}const n=new me(s),r=this._params.pdfBug&&globalThis.FontInspector?.enabled?(t,e)=>globalThis.FontInspector.fontAdded(t,e):null,a=new ue(n,r,s.extra,s.charProcOperatorList);this.fontLoader.bind(a).catch(()=>t.sendWithPromise("FontFallback",{id:e})).finally(()=>{!a.fontExtraProperties&&a.data&&a.clearData(),this.commonObjs.resolve(e,a)});break;case"CopyLocalImage":const{imageRef:o}=s;I(o,"The imageRef must be defined.");for(const t of this.#Zn.values())for(const[,i]of t.objs)if(i?.ref===o)return i.dataLen?(this.commonObjs.resolve(e,structuredClone(i)),i.dataLen):null;break;case"FontPath":this.commonObjs.resolve(e,new be(s));break;case"Image":this.commonObjs.resolve(e,s);break;case"Pattern":const l=new fe(s);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,s])=>{if(this.destroyed)return;const n=this.#Zn.get(e);if(!n.objs.has(t))if(0!==n._intentStates.size)switch(i){case"Image":case"Pattern":n.objs.resolve(t,s);break;default:throw new Error(`Got unknown object type ${i}`)}else s?.bitmap?.close()}),t.on("DocProgress",t=>{this.destroyed||e.onProgress?.({loaded:t.loaded,total:t.total})}),t.on("FetchBinaryData",async t=>{if(this.destroyed)throw new Error("Worker was destroyed.");const e=this[t.type];if(!e)throw new Error(`${t.type} not initialized, see the \`useWorkerFetch\` parameter.`);return e.fetch(t)})}getData(){return this.messageHandler.sendWithPromise("GetData",null)}saveDocument(){this.annotationStorage.size<=0&&D("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._fullReader?.filename??null},e).finally(()=>{this.annotationStorage.resetModified()})}extractPages(t){return this.messageHandler.sendWithPromise("ExtractPages",{pageInfos:t})}getPage(t){if(!Number.isInteger(t)||t<=0||t>this._numPages)return Promise.reject(new Error("Invalid page request."));const e=t-1,i=this.#Jn.get(e);if(i)return i;const s=this.messageHandler.sendWithPromise("GetPage",{pageIndex:e}).then(i=>{if(this.destroyed)throw new Error("Transport destroyed");i.refStr&&this.#tr.set(i.refStr,t);const s=new Ss(e,i,this,this._params.pdfBug);return this.#Zn.set(e,s),s});return this.#Jn.set(e,s),s}getPageIndex(t){return Ae(t)?this.messageHandler.sendWithPromise("GetPageIndex",{num:t.num,gen:t.gen}):Promise.reject(new Error("Invalid pageIndex request."))}getAnnotations(t,e){return this.messageHandler.sendWithPromise("GetAnnotations",{pageIndex:t,intent:e})}getFieldObjects(){return this.#ir("GetFieldObjects")}hasJSActions(){return this.#ir("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.#ir("GetDocJSActions")}getPageJSActions(t){return this.messageHandler.sendWithPromise("GetPageJSActions",{pageIndex:t})}getStructTree(t){return this.messageHandler.sendWithPromise("GetStructTree",{pageIndex:t})}getOutline(){return this.messageHandler.sendWithPromise("GetOutline",null)}getOptionalContentConfig(t){return this.#ir("GetOptionalContentConfig").then(e=>new ji(e,t))}getPermissions(){return this.messageHandler.sendWithPromise("GetPermissions",null)}getMetadata(){const t="GetMetadata",e=this.#Qn.get(t);if(e)return e;const i=this.messageHandler.sendWithPromise(t,null).then(t=>({info:t[0],metadata:t[1]?new Bi(t[1]):null,contentDispositionFilename:this._fullReader?.filename??null,contentLength:this._fullReader?.contentLength??null,hasStructTree:t[2]}));return this.#Qn.set(t,i),i}getMarkInfo(){return this.messageHandler.sendWithPromise("GetMarkInfo",null)}async startCleanup(t=!1){if(!this.destroyed){await this.messageHandler.sendWithPromise("Cleanup",null);for(const t of this.#Zn.values()){const e=t.cleanup();if(!e)throw new Error(`startCleanup: Page ${t.pageNumber} is currently rendering.`)}this.commonObjs.clear(),t||this.fontLoader.clear(),this.#Qn.clear(),this.filterFactory.destroy(!0),vs.cleanup()}}cachedPageNumber(t){if(!Ae(t))return null;const e=0===t.gen?`${t.num}R`:`${t.num}R${t.gen}`;return this.#tr.get(e)??null}}class Ts{#sr=null;onContinue=null;onError=null;constructor(t){this.#sr=t}get promise(){return this.#sr.capability.promise}cancel(t=0){this.#sr.cancel(null,t)}get separateAnnots(){const{separateAnnots:t}=this.#sr.operatorList;if(!t)return!1;const{annotationCanvasMap:e}=this.#sr;return t.form||t.canvas&&e?.size>0}}class Ms{#nr=null;static#rr=new WeakSet;constructor({callback:t,params:e,objs:i,commonObjs:s,annotationCanvasMap:n,operatorList:r,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=s,this.annotationCanvasMap=n,this.operatorListIdx=null,this.operatorList=r,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 Ts(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._operationsFilter=p}get completed(){return this.capability.promise.catch(function(){})}initializeGraphics({transparency:t=!1,optionalContentConfig:e}){if(this.cancelled)return;if(this._canvas){if(Ms.#rr.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.");Ms.#rr.add(this._canvas)}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:s,background:n,dependencyTracker:r}=this.params,a=this._canvasContext||this._canvas.getContext("2d",{alpha:!1,willReadFrequently:!this._enableHWA});this.gfx=new Fi(a,this.commonObjs,this.objs,this.canvasFactory,this.filterFactory,{optionalContentConfig:e},this.annotationCanvasMap,this.pageColors,r),this.gfx.beginDrawing({transform:s,viewport:i,transparency:t,background:n}),this.operatorListIdx=0,this.graphicsReady=!0,this.graphicsReadyCallback?.()}cancel(t=null,e=0){this.running=!1,this.cancelled=!0,this.gfx?.endDrawing(),this.#nr&&(window.cancelAnimationFrame(this.#nr),this.#nr=null),Ms.#rr.delete(this._canvas),t||=new pt(`Rendering cancelled, page ${this._pageIndex+1}`,e),this.callback(t),this.task.onError?.(t)}operatorListChanged(){this.graphicsReady?(this.gfx.dependencyTracker?.growOperationsCount(this.operatorList.fnArray.length),this.stepper?.updateOperatorList(this.operatorList),this.running||this._continue()):this.graphicsReadyCallback||=this._continueBound}_continue(){this.running=!0,this.cancelled||(this.task.onContinue?this.task.onContinue(this._scheduleNextBound):this._scheduleNext())}_scheduleNext(){this._useRequestAnimationFrame?this.#nr=window.requestAnimationFrame(()=>{this.#nr=null,this._nextBound().catch(this._cancelBound)}):Promise.resolve().then(this._nextBound).catch(this._cancelBound)}async _next(){this.cancelled||(this.operatorListIdx=this.gfx.executeOperatorList(this.operatorList,this.operatorListIdx,this._continueBound,this.stepper,this._operationsFilter),this.operatorListIdx===this.operatorList.argsArray.length&&(this.running=!1,this.operatorList.lastChunk&&(this.gfx.endDrawing(),Ms.#rr.delete(this._canvas),this.callback())))}}const Ds="5.4.530",Ps="50cc4adac";class Is{#ar=null;#or=null;#lr;#hr=null;#cr=!1;#dr=!1;#r=null;#ur;#pr=null;#b=null;static#gr=null;static get _keyboardManager(){return F(this,"_keyboardManager",new Kt([[["Escape","mac+Escape"],Is.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Is.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Is.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Is.prototype._moveToPrevious],[["Home","mac+Home"],Is.prototype._moveToBeginning],[["End","mac+End"],Is.prototype._moveToEnd]]))}constructor({editor:t=null,uiManager:e=null}){t?(this.#dr=!1,this.#r=t):this.#dr=!0,this.#b=t?._uiManager||e,this.#ur=this.#b._eventBus,this.#lr=t?.color?.toUpperCase()||this.#b?.highlightColors.values().next().value||"#FFFF98",Is.#gr||=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.#ar=document.createElement("button");t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.ariaHasPopup="true",this.#r&&(t.ariaControls=`${this.#r.id}_colorpicker_dropdown`);const e=this.#b._signal;t.addEventListener("click",this.#mr.bind(this),{signal:e}),t.addEventListener("keydown",this.#fr.bind(this),{signal:e});const i=this.#or=document.createElement("span");return i.className="swatch",i.ariaHidden="true",i.style.backgroundColor=this.#lr,t.append(i),t}renderMainDropdown(){const t=this.#hr=this.#br();return t.ariaOrientation="horizontal",t.ariaLabelledBy="highlightColorPickerLabel",t}#br(){const t=document.createElement("div"),e=this.#b._signal;t.addEventListener("contextmenu",wt,{signal:e}),t.className="dropdown",t.role="listbox",t.ariaMultiSelectable="false",t.ariaOrientation="vertical",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown"),this.#r&&(t.id=`${this.#r.id}_colorpicker_dropdown`);for(const[i,s]of this.#b.highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",s),n.title=i,n.setAttribute("data-l10n-id",Is.#gr[i]);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=s,n.ariaSelected=s===this.#lr,n.addEventListener("click",this.#vr.bind(this,s),{signal:e}),t.append(n)}return t.addEventListener("keydown",this.#fr.bind(this),{signal:e}),t}#vr(t,e){e.stopPropagation(),this.#ur.dispatch("switchannotationeditorparams",{source:this,type:g.HIGHLIGHT_COLOR,value:t}),this.updateColor(t)}_colorSelectFromKeyboard(t){if(t.target===this.#ar)return void this.#mr(t);const e=t.target.getAttribute("data-color");e&&this.#vr(e,t)}_moveToNext(t){this.#yr?t.target!==this.#ar?t.target.nextSibling?.focus():this.#hr.firstElementChild?.focus():this.#mr(t)}_moveToPrevious(t){t.target!==this.#hr?.firstElementChild&&t.target!==this.#ar?(this.#yr||this.#mr(t),t.target.previousSibling?.focus()):this.#yr&&this._hideDropdownFromKeyboard()}_moveToBeginning(t){this.#yr?this.#hr.firstElementChild?.focus():this.#mr(t)}_moveToEnd(t){this.#yr?this.#hr.lastElementChild?.focus():this.#mr(t)}#fr(t){Is._keyboardManager.exec(this,t)}#mr(t){if(this.#yr)return void this.hideDropdown();if(this.#cr=0===t.detail,this.#pr||(this.#pr=new AbortController,window.addEventListener("pointerdown",this.#u.bind(this),{signal:this.#b.combinedSignal(this.#pr)})),this.#ar.ariaExpanded="true",this.#hr)return void this.#hr.classList.remove("hidden");const e=this.#hr=this.#br();this.#ar.append(e)}#u(t){this.#hr?.contains(t.target)||this.hideDropdown()}hideDropdown(){this.#hr?.classList.add("hidden"),this.#ar.ariaExpanded="false",this.#pr?.abort(),this.#pr=null}get#yr(){return this.#hr&&!this.#hr.classList.contains("hidden")}_hideDropdownFromKeyboard(){this.#dr||(this.#yr?(this.hideDropdown(),this.#ar.focus({preventScroll:!0,focusVisible:this.#cr})):this.#r?.unselect())}updateColor(t){if(this.#or&&(this.#or.style.backgroundColor=t),!this.#hr)return;const e=this.#b.highlightColors.values();for(const i of this.#hr.children)i.ariaSelected=e.next().value===t.toUpperCase()}destroy(){this.#ar?.remove(),this.#ar=null,this.#or=null,this.#hr?.remove(),this.#hr=null}}class ks{#wr=null;#r=null;#b=null;static#gr=null;constructor(t){this.#r=t,this.#b=t._uiManager,ks.#gr||=Object.freeze({freetext:"pdfjs-editor-color-picker-free-text-input",ink:"pdfjs-editor-color-picker-ink-input"})}renderButton(){if(this.#wr)return this.#wr;const{editorType:t,colorType:e,color:i}=this.#r,s=this.#wr=document.createElement("input");return s.type="color",s.value=i||"#000000",s.className="basicColorPicker",s.tabIndex=0,s.setAttribute("data-l10n-id",ks.#gr[t]),s.addEventListener("input",()=>{this.#b.updateParams(e,s.value)},{signal:this.#b._signal}),s}update(t){this.#wr&&(this.#wr.value=t)}destroy(){this.#wr?.remove(),this.#wr=null}hideDropdown(){}}function Rs(t){return Math.floor(255*Math.max(0,Math.min(1,t))).toString(16).padStart(2,"0")}function Ls(t){return Math.max(0,Math.min(255,255*t))}class Fs{static CMYK_G([t,e,i,s]){return["G",1-Math.min(1,.3*t+.59*i+.11*e+s)]}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=Ls(t),[t,t,t]}static G_HTML([t]){const e=Rs(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(Ls)}static RGB_HTML(t){return`#${t.map(Rs).join("")}`}static T_HTML(){return"#00000000"}static T_rgb(){return[null]}static CMYK_RGB([t,e,i,s]){return["RGB",1-Math.min(1,t+s),1-Math.min(1,i+s),1-Math.min(1,e+s)]}static CMYK_rgb([t,e,i,s]){return[Ls(1-Math.min(1,t+s)),Ls(1-Math.min(1,i+s)),Ls(1-Math.min(1,e+s))]}static CMYK_HTML(t){const e=this.CMYK_RGB(t).slice(1);return this.RGB_HTML(e)}static RGB_CMYK([t,e,i]){const s=1-t,n=1-e,r=1-i,a=Math.min(s,n,r);return["CMYK",s,n,r,a]}}class Os{create(t,e,i=!1){if(t<=0||e<=0)throw new Error("Invalid SVG dimensions");const s=this._createSVG("svg:svg");return s.setAttribute("version","1.1"),i||(s.setAttribute("width",`${t}px`),s.setAttribute("height",`${e}px`)),s.setAttribute("preserveAspectRatio","none"),s.setAttribute("viewBox",`0 0 ${t} ${e}`),s}createElement(t){if("string"!==typeof t)throw new Error("Invalid SVG element type");return this._createSVG(t)}_createSVG(t){P("Abstract method `_createSVG` called.")}}class Bs extends Os{_createSVG(t){return document.createElementNS(ht,t)}}const Ns=9,Us=new WeakSet,js=60*(new Date).getTimezoneOffset()*1e3;class zs{static create(t){const e=t.data.annotationType;switch(e){case y.LINK:return new Gs(t);case y.TEXT:return new Ws(t);case y.WIDGET:const e=t.data.fieldType;switch(e){case"Tx":return new qs(t);case"Btn":return t.data.radioButton?new Ks(t):t.data.checkBox?new Ys(t):new Qs(t);case"Ch":return new Zs(t);case"Sig":return new Xs(t)}return new Vs(t);case y.POPUP:return new Js(t);case y.FREETEXT:return new en(t);case y.LINE:return new sn(t);case y.SQUARE:return new nn(t);case y.CIRCLE:return new rn(t);case y.POLYLINE:return new an(t);case y.CARET:return new ln(t);case y.INK:return new hn(t);case y.POLYGON:return new on(t);case y.HIGHLIGHT:return new cn(t);case y.UNDERLINE:return new dn(t);case y.SQUIGGLY:return new un(t);case y.STRIKEOUT:return new pn(t);case y.STAMP:return new gn(t);case y.FILEATTACHMENT:return new mn(t);default:return new Hs(t)}}}class Hs{#Ar=null;#xr=!1;#_r=null;constructor(t,{isRenderable:e=!1,ignoreBorder:i=!1,createQuadrilaterals:s=!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)),s&&this._createQuadrilaterals()}static _hasPopupData({contentsObj:t,richText:e}){return!(!t?.str&&!e?.str)}get _isEditable(){return this.data.isEditable}get hasPopupData(){return Hs._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:s}=this.data;let n=-1/0,r=-1/0;if(e?.length>=8){for(let t=0;t<e.length;t+=8)e[t+1]>r?(r=e[t+1],n=e[t+2]):e[t+1]===r&&(n=Math.max(n,e[t+2]));return[n,r]}if(i?.length>=1){for(const t of i)for(let e=0,i=t.length;e<i;e+=2)t[e+1]>r?(r=t[e+1],n=t[e]):t[e+1]===r&&(n=Math.max(n,t[e]));if(n!==1/0)return[n,r]}return s?[s[2],s[3]]:null}_normalizePoint(t){const{page:{view:e},viewport:{rawDims:{pageWidth:i,pageHeight:s,pageX:n,pageY:r}}}=this.parent;return t[1]=e[3]-t[1]+e[1],t[0]=100*(t[0]-n)/i,t[1]=100*(t[1]-r)/s,t}get commentText(){const{data:t}=this;return this.annotationStorage.getRawValue(`${u}${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(`${u}${e.id}`,{id:e.id,annotationType:e.annotationType,pageIndex:this.parent.page._pageIndex,popup:i,popupRef:e.popupRef,modificationDate:new Date}),t||this.removePopup()}removePopup(){(this.#_r?.popup||this.popup)?.remove(),this.#_r=this.popup=null}updateEdited(t){if(!this.container)return;t.rect&&(this.#Ar||={rect:this.data.rect.slice(0)});const{rect:e,popup:i}=t;e&&this.#Sr(e);let s=this.#_r?.popup||this.popup;!s&&i?.text&&(this._createPopup(i),s=this.#_r.popup),s&&(s.updateEdited(t),i?.deleted&&(s.remove(),this.#_r=null,this.popup=null))}resetEdited(){this.#Ar&&(this.#Sr(this.#Ar.rect),this.#_r?.popup.resetEdited(),this.#Ar=null)}#Sr(t){const{container:{style:e},data:{rect:i,rotation:s},parent:{viewport:{rawDims:{pageWidth:n,pageHeight:r,pageX:a,pageY:o}}}}=this;i?.splice(0,4,...t),e.left=100*(t[0]-a)/n+"%",e.top=100*(r-t[3]+o)/r+"%",0===s?(e.width=100*(t[2]-t[0])/n+"%",e.height=100*(t[3]-t[1])/r+"%"):this.setRotation(s)}_createContainer(t){const{data:e,parent:{page:i,viewport:s}}=this,n=document.createElement("section");n.setAttribute("data-annotation-id",e.id),this instanceof Vs||this instanceof Gs||(n.tabIndex=0);const{style:r}=n;if(r.zIndex=this.parent.zIndex,this.parent.zIndex+=2,e.alternativeText&&(n.title=e.alternativeText),e.noRotate&&n.classList.add("norotate"),!e.rect||this instanceof Js){const{rotation:t}=e;return e.hasOwnCanvas||0===t||this.setRotation(t,n),n}const{width:a,height:o}=this;if(!t&&e.borderStyle.width>0){r.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))`;r.borderRadius=e}else if(this instanceof Ks){const t=`calc(${a}px * var(--total-scale-factor)) / calc(${o}px * var(--total-scale-factor))`;r.borderRadius=t}switch(e.borderStyle.style){case w.SOLID:r.borderStyle="solid";break;case w.DASHED:r.borderStyle="dashed";break;case w.BEVELED:D("Unimplemented border style: beveled");break;case w.INSET:D("Unimplemented border style: inset");break;case w.UNDERLINE:r.borderBottomStyle="solid";break;default:break}const s=e.borderColor||null;s?(this.#xr=!0,r.borderColor=K.makeHexColor(0|s[0],0|s[1],0|s[2])):r.borderWidth=0}const l=K.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}=s.rawDims;r.left=100*(l[0]-d)/h+"%",r.top=100*(l[1]-u)/c+"%";const{rotation:p}=e;return e.hasOwnCanvas||0===p?(r.width=100*a/h+"%",r.height=100*o/c+"%"):this.setRotation(p,n),n}setRotation(t,e=this.container){if(!this.data.rect)return;const{pageWidth:i,pageHeight:s}=this.parent.viewport.rawDims;let{width:n,height:r}=this;t%180!==0&&([n,r]=[r,n]),e.style.width=100*n/i+"%",e.style.height=100*r/s+"%",e.setAttribute("data-main-rotation",(360-t)%360)}get _commonActions(){const t=(t,e,i)=>{const s=i.detail[t],n=s[0],r=s.slice(1);i.target.style[e]=Fs[`${n}_HTML`](r),this.annotationStorage.setValue(this.data.id,{[e]:Fs[`${n}_rgb`](r)})};return F(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:e=>{t("bgColor","backgroundColor",e)},fillColor:e=>{t("fillColor","backgroundColor",e)},fgColor:e=>{t("fgColor","color",e)},textColor:e=>{t("textColor","color",e)},borderColor:e=>{t("borderColor","borderColor",e)},strokeColor:e=>{t("strokeColor","borderColor",e)},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 s of Object.keys(e.detail)){const n=t[s]||i[s];n?.(e)}}_setDefaultPropertiesFromJS(t){if(!this.enableScripting)return;const e=this.annotationStorage.getRawValue(this.data.id);if(!e)return;const i=this._commonActions;for(const[s,n]of Object.entries(e)){const r=i[s];if(r){const i={detail:{[s]:n},target:t};r(i),delete e[s]}}}_createQuadrilaterals(){if(!this.container)return;const{quadPoints:t}=this.data;if(!t)return;const[e,i,s,n]=this.data.rect.map(t=>Math.fround(t));if(8===t.length){const[r,a,o,l]=t.subarray(2,6);if(s===r&&n===a&&e===o&&i===l)return}const{style:r}=this.container;let a;if(this.#xr){const{borderColor:t,borderWidth:e}=r;r.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=s-e,l=n-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 g=2,m=t.length;g<m;g+=8){const i=t[g],s=t[g+1],r=t[g+2],c=t[g+3],d=h.createElement("rect"),p=(r-e)/o,m=(n-s)/l,f=(i-r)/o,b=(s-c)/l;d.setAttribute("x",p),d.setAttribute("y",m),d.setAttribute("width",f),d.setAttribute("height",b),u.append(d),a?.push(`<rect vector-effect="non-scaling-stroke" x="${p}" y="${m}" width="${f}" height="${b}"/>`)}this.#xr&&(a.push("</g></svg>')"),r.backgroundImage=a.join("")),this.container.append(c),this.container.style.clipPath=`url(#${p})`}_createPopup(t=null){const{data:e}=this;let i,s;t?(i={str:t.text},s=t.date):(i=e.contentsObj,s=e.modificationDate),this.#_r=new Js({data:{color:e.color,titleObj:e.titleObj,modificationDate:s,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.#_r||this.popup||this.data.popupRef)}get extraPopupElement(){return this.#_r}render(){P("Abstract method `AnnotationElement.render` called")}_getElementsByName(t,e=null){const i=[];if(this._fieldObjects){const s=this._fieldObjects[t];if(s)for(const{page:t,id:n,exportValues:r}of s){if(-1===t)continue;if(n===e)continue;const s="string"===typeof r?r:null,a=document.querySelector(`[data-element-id="${n}"]`);!a||Us.has(a)?i.push({id:n,exportValue:s,domElement:a}):D(`_getElementsByName - element not allowed: ${n}`)}return i}for(const s of document.getElementsByName(t)){const{exportValue:t}=s,n=s.getAttribute("data-element-id");n!==e&&(Us.has(s)&&i.push({id:n,exportValue:t,domElement:s}))}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 $s extends Hs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.editor=t.editor}render(){return this.container.className="editorAnnotation",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 Gs extends Hs{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 s=!1;return t.url?(e.addLinkAttributes(i,t.url,t.newWindow),s=!0):t.action?(this._bindNamedAction(i,t.action,t.overlaidText),s=!0):t.attachment?(this.#Er(i,t.attachment,t.overlaidText,t.attachmentDest),s=!0):t.setOCGState?(this.#Cr(i,t.setOCGState,t.overlaidText),s=!0):t.dest?(this._bindLink(i,t.dest,t.overlaidText),s=!0):(t.actions&&(t.actions.Action||t.actions["Mouse Up"]||t.actions["Mouse Down"])&&this.enableScripting&&this.hasJSActions&&(this._bindJSAction(i,t),s=!0),t.resetForm?(this._bindResetFormAction(i,t.resetForm),s=!0):this.isTooltipOnly&&!s&&(this._bindLink(i,""),s=!0)),this.container.classList.add("linkAnnotation"),s&&(this.contentElement=i,this.container.append(i)),this.container}#Tr(){this.container.setAttribute("data-internal-link","")}_bindLink(t,e,i=""){t.href=this.linkService.getDestinationHash(e),t.onclick=()=>(e&&this.linkService.goToDestination(e),!1),(e||""===e)&&this.#Tr(),i&&(t.title=i)}_bindNamedAction(t,e,i=""){t.href=this.linkService.getAnchorUrl(""),t.onclick=()=>(this.linkService.executeNamedAction(e),!1),i&&(t.title=i),this.#Tr()}#Er(t,e,i="",s=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,s),!1),this.#Tr()}#Cr(t,e,i=""){t.href=this.linkService.getAnchorUrl(""),t.onclick=()=>(this.linkService.executeSetOCGState(e),!1),i&&(t.title=i),this.#Tr()}_bindJSAction(t,e){t.href=this.linkService.getAnchorUrl("");const i=new Map([["Action","onclick"],["Mouse Up","onmouseup"],["Mouse Down","onmousedown"]]);for(const s of Object.keys(e.actions)){const n=i.get(s);n&&(t[n]=()=>(this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e.id,name:s}}),!1))}e.overlaidText&&(t.title=e.overlaidText),t.onclick||(t.onclick=()=>!1),this.#Tr()}_bindResetFormAction(t,e){const i=t.onclick;if(i||(t.href=this.linkService.getAnchorUrl("")),this.#Tr(),!this._fieldObjects)return D('_bindResetFormAction - "resetForm" action not supported, ensure that the `fieldObjects` parameter is provided.'),void(i||(t.onclick=()=>!1));t.onclick=()=>{i?.();const{fields:t,refs:s,include:n}=e,r=[];if(0!==t.length||0!==s.length){const e=new Set(s);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)===n&&r.push(i)}else for(const e of Object.values(this._fieldObjects))r.push(...e);const a=this.annotationStorage,o=[];for(const e of r){const{id:t}=e;switch(o.push(t),e.type){case"text":{const i=e.defaultValue||"";a.setValue(t,{value:i});break}case"checkbox":case"radiobutton":{const i=e.defaultValue===e.exportValues;a.setValue(t,{value:i});break}case"combobox":case"listbox":{const i=e.defaultValue||"";a.setValue(t,{value:i});break}default:continue}const i=document.querySelector(`[data-element-id="${t}"]`);i&&(Us.has(i)?i.dispatchEvent(new Event("resetform")):D(`_bindResetFormAction - element not allowed: ${t}`))}return this.enableScripting&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:"app",ids:o,name:"ResetForm"}}),!1}}}class Ws extends Hs{constructor(t){super(t,{isRenderable:!0})}render(){this.container.classList.add("textAnnotation");const t=document.createElement("img");return 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})),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.append(t),this.container}}class Vs extends Hs{render(){return this.container}showElementAndHideCanvas(t){this.data.hasOwnCanvas&&("CANVAS"===t.previousSibling?.nodeName&&(t.previousSibling.hidden=!0),t.hidden=!1)}_getKeyModifier(t){return X.platform.isMac?t.metaKey:t.ctrlKey}_setEventListener(t,e,i,s,n){i.includes("mouse")?t.addEventListener(i,t=>{this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:s,value:n(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}n&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:this.data.id,name:s,value:n(t)}})})}_setEventListeners(t,e,i,s){for(const[n,r]of i)("Action"===r||this.data.actions?.[r])&&("Focus"!==r&&"Blur"!==r||(e||={focused:!1}),this._setEventListener(t,e,n,r,s),"Focus"!==r||this.data.actions?.Blur?"Blur"!==r||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":K.makeHexColor(e[0],e[1],e[2])}_setTextStyle(t){const e=["left","center","right"],{fontColor:i}=this.data.defaultAppearanceData,s=this.data.defaultAppearanceData.fontSize||Ns,n=t.style;let r;const a=2,o=t=>Math.round(10*t)/10;if(this.data.multiLine){const t=Math.abs(this.data.rect[3]-this.data.rect[1]-a),e=Math.round(t/(h*s))||1,i=t/e;r=Math.min(s,o(i/h))}else{const t=Math.abs(this.data.rect[3]-this.data.rect[1]-a);r=Math.min(s,o(t/h))}n.fontSize=`calc(${r}px * var(--total-scale-factor))`,n.color=K.makeHexColor(i[0],i[1],i[2]),null!==this.data.textAlignment&&(n.textAlign=e[this.data.textAlignment])}_setRequired(t,e){e?t.setAttribute("required",!0):t.removeAttribute("required"),t.setAttribute("aria-required",e)}}class qs extends Vs{constructor(t){const e=t.renderForms||t.data.hasOwnCanvas||!t.data.hasAppearance&&!!t.data.fieldValue;super(t,{isRenderable:e})}setPropertyOnSiblings(t,e,i,s){const n=this.annotationStorage;for(const r of this._getElementsByName(t.name,t.id))r.domElement&&(r.domElement[e]=i),n.setValue(r.id,{[s]:i})}render(){const t=this.annotationStorage,e=this.data.id;this.container.classList.add("textWidgetAnnotation");let i=null;if(this.renderForms){const s=t.getValue(e,{value:this.data.fieldValue});let n=s.value||"";const r=t.getValue(e,{charLimit:this.data.maxLen}).charLimit;r&&n.length>r&&(n=n.slice(0,r));let a=s.formattedValue||this.data.textContent?.join("\n")||null;a&&this.data.comb&&(a=a.replaceAll(/\s+/g,""));const o={userValue:n,formattedValue:a,lastCommittedValue:null,commitKey:1,focused:!1};this.data.multiLine?(i=document.createElement("textarea"),i.textContent=a??n,this.data.doNotScroll&&(i.style.overflowY="hidden")):(i=document.createElement("input"),i.type=this.data.password?"password":"text",i.setAttribute("value",a??n),this.data.doNotScroll&&(i.style.overflowX="hidden")),this.data.hasOwnCanvas&&(i.hidden=!0),Us.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),r&&(i.maxLength=r),i.addEventListener("input",s=>{t.setValue(e,{value:s.target.value}),this.setPropertyOnSiblings(i,"value",s.target.value,"value"),o.formattedValue=null}),i.addEventListener("resetform",t=>{const e=this.data.defaultFieldValue??"";i.value=o.userValue=e,o.formattedValue=null});let u=t=>{const{formattedValue:e}=o;null!==e&&void 0!==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)),o.userValue){const t=o.userValue;if(d)if("time"===h){const i=new Date(t),s=[i.getHours(),i.getMinutes(),i.getSeconds()];e.value=s.map(t=>t.toString().padStart(2,"0")).join(":")}else e.value=new Date(t-js).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 s={value(i){o.userValue=i.detail.value??"",d||t.setValue(e,{value:o.userValue.toString()}),i.target.value=o.userValue},formattedValue(i){const{formattedValue:s}=i.detail;o.formattedValue=s,null!==s&&void 0!==s&&i.target!==document.activeElement&&(i.target.value=s);const n={formattedValue:s};d&&(n.value=s),t.setValue(e,n)},selRange(t){t.target.setSelectionRange(...t.detail.selRange)},charLimit:i=>{const{charLimit:s}=i.detail,{target:n}=i;if(0===s)return void n.removeAttribute("maxLength");n.setAttribute("maxLength",s);let r=o.userValue;!r||r.length<=s||(r=r.slice(0,s),n.value=o.userValue=r,t.setValue(e,{value:r}),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:r,willCommit:!0,commitKey:1,selStart:n.selectionStart,selEnd:n.selectionEnd}}))}};this._dispatchEventFromSandbox(s,i)}),i.addEventListener("keydown",t=>{o.commitKey=1;let i=-1;if("Escape"===t.key?i=0:"Enter"!==t.key||this.data.multiLine?"Tab"===t.key&&(o.commitKey=3):i=2,-1===i)return;const{value:s}=t.target;o.lastCommittedValue!==s&&(o.lastCommittedValue=s,o.userValue=s,this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:s,willCommit:!0,commitKey:i,selStart:t.target.selectionStart,selEnd:t.target.selectionEnd}}))});const s=u;u=null,i.addEventListener("blur",t=>{if(!o.focused||!t.relatedTarget)return;this.data.actions?.Blur||(o.focused=!1);const{target:i}=t;let{value:n}=i;if(d){if(n&&"time"===h){const t=n.split(":").map(t=>parseInt(t,10));n=new Date(2e3,0,1,t[0],t[1],t[2]||0).valueOf(),i.step=""}else n.includes("T")||(n=`${n}T00:00`),n=new Date(n).valueOf();i.type="text"}o.userValue=n,o.lastCommittedValue!==n&&this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:n,willCommit:!0,commitKey:o.commitKey,selStart:t.target.selectionStart,selEnd:t.target.selectionEnd}}),s(t)}),this.data.actions?.Keystroke&&i.addEventListener("beforeinput",t=>{o.lastCommittedValue=null;const{data:i,target:s}=t,{value:n,selectionStart:r,selectionEnd:a}=s;let l=r,h=a;switch(t.inputType){case"deleteWordBackward":{const t=n.substring(0,r).match(/\w*[^\w]*$/);t&&(l-=t[0].length);break}case"deleteWordForward":{const t=n.substring(r).match(/^[^\w]*\w*/);t&&(h+=t[0].length);break}case"deleteContentBackward":r===a&&(l-=1);break;case"deleteContentForward":r===a&&(h+=1);break}t.preventDefault(),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:n,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)}if(u&&i.addEventListener("blur",u),this.data.comb){const t=this.data.rect[2]-this.data.rect[0],e=t/r;i.classList.add("comb"),i.style.letterSpacing=`calc(${e}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);return this._setTextStyle(i),this._setBackgroundColor(i),this._setDefaultPropertiesFromJS(i),this.container.append(i),this.container}}class Xs extends Vs{constructor(t){super(t,{isRenderable:!!t.data.hasOwnCanvas})}}class Ys extends Vs{constructor(t){super(t,{isRenderable:t.renderForms})}render(){const t=this.annotationStorage,e=this.data,i=e.id;let s=t.getValue(i,{value:e.exportValue===e.fieldValue}).value;"string"===typeof s&&(s="Off"!==s,t.setValue(i,{value:s})),this.container.classList.add("buttonWidgetAnnotation","checkBox");const n=document.createElement("input");return Us.add(n),n.setAttribute("data-element-id",i),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="checkbox",n.name=e.fieldName,s&&n.setAttribute("checked",!0),n.setAttribute("exportValue",e.exportValue),n.tabIndex=0,n.addEventListener("change",s=>{const{name:n,checked:r}=s.target;for(const a of this._getElementsByName(n,i)){const i=r&&a.exportValue===e.exportValue;a.domElement&&(a.domElement.checked=i),t.setValue(a.id,{value:i})}t.setValue(i,{value:r})}),n.addEventListener("resetform",t=>{const i=e.defaultFieldValue||"Off";t.target.checked=i===e.exportValue}),this.enableScripting&&this.hasJSActions&&(n.addEventListener("updatefromsandbox",e=>{const s={value(e){e.target.checked="Off"!==e.detail.value,t.setValue(i,{value:e.target.checked})}};this._dispatchEventFromSandbox(s,e)}),this._setEventListeners(n,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(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class Ks extends Vs{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 s=t.getValue(i,{value:e.fieldValue===e.buttonValue}).value;if("string"===typeof s&&(s=s!==e.buttonValue,t.setValue(i,{value:s})),s)for(const r of this._getElementsByName(e.fieldName,i))t.setValue(r.id,{value:!1});const n=document.createElement("input");if(Us.add(n),n.setAttribute("data-element-id",i),n.disabled=e.readOnly,this._setRequired(n,this.data.required),n.type="radio",n.name=e.fieldName,s&&n.setAttribute("checked",!0),n.tabIndex=0,n.addEventListener("change",e=>{const{name:s,checked:n}=e.target;for(const r of this._getElementsByName(s,i))t.setValue(r.id,{value:!1});t.setValue(i,{value:n})}),n.addEventListener("resetform",t=>{const i=e.defaultFieldValue;t.target.checked=null!==i&&void 0!==i&&i===e.buttonValue}),this.enableScripting&&this.hasJSActions){const s=e.buttonValue;n.addEventListener("updatefromsandbox",e=>{const n={value:e=>{const n=s===e.detail.value;for(const s of this._getElementsByName(e.target.name)){const e=n&&s.id===i;s.domElement&&(s.domElement.checked=e),t.setValue(s.id,{value:e})}}};this._dispatchEventFromSandbox(n,e)}),this._setEventListeners(n,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)}return this._setBackgroundColor(n),this._setDefaultPropertiesFromJS(n),this.container.append(n),this.container}}class Qs extends Gs{constructor(t){super(t,{ignoreBorder:t.data.hasAppearance})}render(){const t=super.render();t.classList.add("buttonWidgetAnnotation","pushButton");const e=t.lastChild;return this.enableScripting&&this.hasJSActions&&e&&(this._setDefaultPropertiesFromJS(e),e.addEventListener("updatefromsandbox",t=>{this._dispatchEventFromSandbox({},t)})),t}}class Zs extends Vs{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}),s=document.createElement("select");Us.add(s),s.setAttribute("data-element-id",e),s.disabled=this.data.readOnly,this._setRequired(s,this.data.required),s.name=this.data.fieldName,s.tabIndex=0;let n=this.data.combo&&this.data.options.length>0;this.data.combo||(s.size=this.data.options.length,this.data.multiSelect&&(s.multiple=!0)),s.addEventListener("resetform",t=>{const e=this.data.defaultFieldValue;for(const i of s.options)i.selected=i.value===e});for(const h of this.data.options){const t=document.createElement("option");t.textContent=h.displayValue,t.value=h.exportValue,i.value.includes(h.exportValue)&&(t.setAttribute("selected",!0),n=!1),s.append(t)}let r=null;if(n){const t=document.createElement("option");t.value=" ",t.setAttribute("hidden",!0),t.setAttribute("selected",!0),s.prepend(t),r=()=>{t.remove(),s.removeEventListener("input",r),r=null},s.addEventListener("input",r)}const a=t=>{const e=t?"value":"textContent",{options:i,multiple:n}=s;return n?Array.prototype.filter.call(i,t=>t.selected).map(t=>t[e]):-1===i.selectedIndex?null:i[i.selectedIndex][e]};let o=a(!1);const l=t=>{const e=t.target.options;return Array.prototype.map.call(e,t=>({displayValue:t.textContent,exportValue:t.value}))};return this.enableScripting&&this.hasJSActions?(s.addEventListener("updatefromsandbox",i=>{const n={value(i){r?.();const n=i.detail.value,l=new Set(Array.isArray(n)?n:[n]);for(const t of s.options)t.selected=l.has(t.value);t.setValue(e,{value:a(!0)}),o=a(!1)},multipleSelection(t){s.multiple=!0},remove(i){const n=s.options,r=i.detail.remove;if(n[r].selected=!1,s.remove(r),n.length>0){const t=Array.prototype.findIndex.call(n,t=>t.selected);-1===t&&(n[0].selected=!0)}t.setValue(e,{value:a(!0),items:l(i)}),o=a(!1)},clear(i){while(0!==s.length)s.remove(0);t.setValue(e,{value:null,items:[]}),o=a(!1)},insert(i){const{index:n,displayValue:r,exportValue:h}=i.detail.insert,c=s.children[n],d=document.createElement("option");d.textContent=r,d.value=h,c?c.before(d):s.append(d),t.setValue(e,{value:a(!0),items:l(i)}),o=a(!1)},items(i){const{items:n}=i.detail;while(0!==s.length)s.remove(0);for(const t of n){const{displayValue:e,exportValue:i}=t,n=document.createElement("option");n.textContent=e,n.value=i,s.append(n)}s.options.length>0&&(s.options[0].selected=!0),t.setValue(e,{value:a(!0),items:l(i)}),o=a(!1)},indices(i){const s=new Set(i.detail.indices);for(const t of i.target.options)t.selected=s.has(t.index);t.setValue(e,{value:a(!0)}),o=a(!1)},editable(t){t.target.disabled=!t.detail.editable}};this._dispatchEventFromSandbox(n,i)}),s.addEventListener("input",i=>{const s=a(!0),n=a(!1);t.setValue(e,{value:s}),i.preventDefault(),this.linkService.eventBus?.dispatch("dispatcheventinsandbox",{source:this,detail:{id:e,name:"Keystroke",value:o,change:n,changeEx:s,willCommit:!1,commitKey:1,keyDown:!1}})}),this._setEventListeners(s,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)):s.addEventListener("input",function(i){t.setValue(e,{value:a(!0)})}),this.data.combo&&this._setTextStyle(s),this._setBackgroundColor(s),this._setDefaultPropertiesFromJS(s),this.container.append(s),this.container}}class Js extends Hs{constructor(t){const{data:e,elements:i,parent:s}=t,n=!!s._commentManager;if(super(t,{isRenderable:!n&&Hs._hasPopupData(e)}),this.elements=i,n&&Hs._hasPopupData(e)){const t=this.popup=this.#Mr();for(const e of i)e.popup=t}else this.popup=null}#Mr(){return new tn({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.#Mr(),i=[];for(const s of this.elements)s.popup=e,s.container.ariaHasPopup="dialog",i.push(s.data.id),s.addHighlightArea();return this.container.setAttribute("aria-controls",i.map(t=>`${it}${t}`).join(",")),this.container}}class tn{#$=null;#Dr=this.#fr.bind(this);#Pr=this.#Ir.bind(this);#kr=this.#Rr.bind(this);#Lr=this.#Fr.bind(this);#Or=null;#Et=null;#Br=null;#Nr=null;#Ur=null;#jr=null;#zr=null;#Hr=!1;#$r=null;#Gr=null;#k=null;#Wr=null;#Vr=null;#be=null;#qr=null;#pe=null;#Xr=null;#Ar=null;#Yr=!1;#Kr=null;#Qr=null;constructor({container:t,color:e,elements:i,titleObj:s,modificationDate:n,contentsObj:r,richText:a,parent:o,rect:l,parentRect:h,open:c,commentManager:d=null}){this.#Et=t,this.#Xr=s,this.#Br=r,this.#pe=a,this.#jr=o,this.#Or=e,this.#qr=l,this.#zr=h,this.#Ur=i,this.#$=d,this.#Kr=i[0],this.#Nr=_t.toDateObject(n),this.trigger=i.flatMap(t=>t.getElementsToTriggerPopup()),d||(this.#Zr(),this.#Et.hidden=!0,c&&this.#Fr())}#Zr(){if(this.#Gr)return;this.#Gr=new AbortController;const{signal:t}=this.#Gr;for(const e of this.trigger)e.addEventListener("click",this.#Lr,{signal:t}),e.addEventListener("pointerenter",this.#kr,{signal:t}),e.addEventListener("pointerleave",this.#Pr,{signal:t}),e.classList.add("popupTriggerArea");for(const e of this.#Ur)e.container?.addEventListener("keydown",this.#Dr,{signal:t})}#Jr(){const t=this.#Ur.find(t=>t.hasCommentButton);t&&(this.#Vr=t._normalizePoint(t.commentButtonPosition))}renderCommentButton(){if(this.#Wr)return void(this.#Wr.parentNode||this.#Kr.container.after(this.#Wr));if(this.#Vr||this.#Jr(),!this.#Vr)return;const{signal:t}=this.#Gr=new AbortController,e=this.#Kr.hasOwnCommentButton,i=()=>{this.#$.toggleCommentPopup(this,!0,void 0,!e)},s=()=>{this.#$.toggleCommentPopup(this,!1,!0,!e)},n=()=>{this.#$.toggleCommentPopup(this,!1,!1)};if(e){this.#Wr=this.#Kr.container;for(const e of this.trigger)e.ariaHasPopup="dialog",e.ariaControls="commentPopup",e.addEventListener("keydown",this.#Dr,{signal:t}),e.addEventListener("click",i,{signal:t}),e.addEventListener("pointerenter",s,{signal:t}),e.addEventListener("pointerleave",n,{signal:t}),e.classList.add("popupTriggerArea")}else{const e=this.#Wr=document.createElement("button");e.className="annotationCommentButton";const r=this.#Kr.container;e.style.zIndex=r.style.zIndex+1,e.tabIndex=0,e.ariaHasPopup="dialog",e.ariaControls="commentPopup",e.setAttribute("data-l10n-id","pdfjs-show-comment-button"),this.#ta(),this.#ea(),e.addEventListener("keydown",this.#Dr,{signal:t}),e.addEventListener("click",i,{signal:t}),e.addEventListener("pointerenter",s,{signal:t}),e.addEventListener("pointerleave",n,{signal:t}),r.after(e)}}#ea(){if(this.#Kr.extraPopupElement&&!this.#Kr.editor)return;this.#Wr||this.renderCommentButton();const[t,e]=this.#Vr,{style:i}=this.#Wr;i.left=`calc(${t}%)`,i.top=`calc(${e}% - var(--comment-button-dim))`}#ta(){this.#Kr.extraPopupElement||(this.#Wr||this.renderCommentButton(),this.#Wr.style.backgroundColor=this.commentButtonColor||"")}get commentButtonColor(){const{color:t,opacity:e}=this.#Kr.commentData;return t?this.#jr._commentManager.makeCommentColor(t,e):null}focusCommentButton(){setTimeout(()=>{this.#Wr?.focus()},0)}getData(){const{richText:t,color:e,opacity:i,creationDate:s,modificationDate:n}=this.#Kr.commentData;return{contentsObj:{str:this.comment},richText:t,color:e,opacity:i,creationDate:s,modificationDate:n}}get elementBeforePopup(){return this.#Wr}get comment(){return this.#Qr||=this.#Kr.commentText,this.#Qr}set comment(t){t!==this.comment&&(this.#Kr.commentText=this.#Qr=t)}focus(){this.#Kr.container?.focus()}get parentBoundingClientRect(){return this.#Kr.layer.getBoundingClientRect()}setCommentButtonStates({selected:t,hasPopup:e}){this.#Wr&&(this.#Wr.classList.toggle("selected",t),this.#Wr.ariaExpanded=e)}setSelectedCommentButton(t){this.#Wr.classList.toggle("selected",t)}get commentPopupPosition(){if(this.#be)return this.#be;const{x:t,y:e,height:i}=this.#Wr.getBoundingClientRect(),{x:s,y:n,width:r,height:a}=this.#Kr.layer.getBoundingClientRect();return[(t-s)/r,(e+i-n)/a]}set commentPopupPosition(t){this.#be=t}hasDefaultPopupPosition(){return null===this.#be}get commentButtonPosition(){return this.#Vr}get commentButtonWidth(){return this.#Wr.getBoundingClientRect().width/this.parentBoundingClientRect.width}editComment(t){const[e,i]=this.#be||this.commentButtonPosition.map(t=>t/100),s=this.parentBoundingClientRect,{x:n,y:r,width:a,height:o}=s;this.#$.showDialog(null,this,n+e*a,r+i*o,{...t,parentDimensions:s})}render(){if(this.#$r)return;const t=this.#$r=document.createElement("div");if(t.className="popup",this.#Or){const e=t.style.outlineColor=K.makeHexColor(...this.#Or);t.style.backgroundColor=`color-mix(in srgb, ${e} 30%, white)`}const e=document.createElement("span");if(e.className="header",this.#Xr?.str){const t=document.createElement("span");t.className="title",e.append(t),({dir:t.dir,str:t.textContent}=this.#Xr)}if(t.append(e),this.#Nr){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.#Nr.valueOf()})),t.dateTime=this.#Nr.toISOString(),e.append(t)}zt({html:this.#ia||this.#Br.str,dir:this.#Br?.dir,className:"popupContent"},t),this.#Et.append(t)}get#ia(){const t=this.#pe,e=this.#Br;return!t?.str||e?.str&&e.str!==t.str?null:this.#pe.html||null}get#sa(){return this.#ia?.attributes?.style?.fontSize||0}get#na(){return this.#ia?.attributes?.style?.color||null}#ra(t){const e=[],i={str:t,html:{name:"div",attributes:{dir:"auto"},children:[{name:"p",children:e}]}},s={style:{color:this.#na,fontSize:this.#sa?`calc(${this.#sa}px * var(--total-scale-factor))`:""}};for(const n of t.split("\n"))e.push({name:"span",value:n,attributes:s});return i}#fr(t){t.altKey||t.shiftKey||t.ctrlKey||t.metaKey||("Enter"===t.key||"Escape"===t.key&&this.#Hr)&&this.#Fr()}updateEdited({rect:t,popup:e,deleted:i}){if(this.#$)return i?(this.remove(),this.#Qr=null):e&&(e.deleted?this.remove():(this.#ta(),this.#Qr=e.text)),void(t&&(this.#Vr=null,this.#Jr(),this.#ea()));i||e?.deleted?this.remove():(this.#Zr(),this.#Ar||={contentsObj:this.#Br,richText:this.#pe},t&&(this.#k=null),e&&e.text&&(this.#pe=this.#ra(e.text),this.#Nr=_t.toDateObject(e.date),this.#Br=null),this.#$r?.remove(),this.#$r=null)}resetEdited(){this.#Ar&&(({contentsObj:this.#Br,richText:this.#pe}=this.#Ar),this.#Ar=null,this.#$r?.remove(),this.#$r=null,this.#k=null)}remove(){if(this.#Gr?.abort(),this.#Gr=null,this.#$r?.remove(),this.#$r=null,this.#Yr=!1,this.#Hr=!1,this.#Wr?.remove(),this.#Wr=null,this.trigger)for(const t of this.trigger)t.classList.remove("popupTriggerArea")}#aa(){if(null!==this.#k)return;const{page:{view:t},viewport:{rawDims:{pageWidth:e,pageHeight:i,pageX:s,pageY:n}}}=this.#jr;let r=!!this.#zr,a=r?this.#zr:this.#qr;for(const p of this.#Ur)if(!a||null!==K.intersect(p.data.rect,a)){a=p.data.rect,r=!0;break}const o=K.normalizeRect([a[0],t[3]-a[1]+t[1],a[2],t[3]-a[3]+t[1]]),l=5,h=r?a[2]-a[0]+l:0,c=o[0]+h,d=o[1];this.#k=[100*(c-s)/e,100*(d-n)/i];const{style:u}=this.#Et;u.left=`${this.#k[0]}%`,u.top=`${this.#k[1]}%`}#Fr(){this.#$?this.#$.toggleCommentPopup(this,!1):(this.#Hr=!this.#Hr,this.#Hr?(this.#Rr(),this.#Et.addEventListener("click",this.#Lr),this.#Et.addEventListener("keydown",this.#Dr)):(this.#Ir(),this.#Et.removeEventListener("click",this.#Lr),this.#Et.removeEventListener("keydown",this.#Dr)))}#Rr(){this.#$r||this.render(),this.isVisible?this.#Hr&&this.#Et.classList.add("focused"):(this.#aa(),this.#Et.hidden=!1,this.#Et.style.zIndex=parseInt(this.#Et.style.zIndex)+1e3)}#Ir(){this.#Et.classList.remove("focused"),!this.#Hr&&this.isVisible&&(this.#Et.hidden=!0,this.#Et.style.zIndex=parseInt(this.#Et.style.zIndex)-1e3)}forceHide(){this.#Yr=this.isVisible,this.#Yr&&(this.#Et.hidden=!0)}maybeShow(){this.#$||(this.#Zr(),this.#Yr&&(this.#$r||this.#Rr(),this.#Yr=!1,this.#Et.hidden=!1))}get isVisible(){return!this.#$&&!1===this.#Et.hidden}}class en extends Hs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.textContent=t.data.textContent,this.textPosition=t.data.textPosition,this.annotationEditorType=p.FREETEXT}render(){if(this.container.classList.add("freeTextAnnotation"),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)}return!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this._editOnDoubleClick(),this.container}}class sn extends Hs{#oa=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("lineAnnotation");const{data:t,width:e,height:i}=this,s=this.svgFactory.create(e,i,!0),n=this.#oa=this.svgFactory.createElement("svg:line");return n.setAttribute("x1",t.rect[2]-t.lineCoordinates[0]),n.setAttribute("y1",t.rect[3]-t.lineCoordinates[1]),n.setAttribute("x2",t.rect[2]-t.lineCoordinates[2]),n.setAttribute("y2",t.rect[3]-t.lineCoordinates[3]),n.setAttribute("stroke-width",t.borderStyle.width||1),n.setAttribute("stroke","transparent"),n.setAttribute("fill","transparent"),s.append(n),this.container.append(s),!t.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#oa}addHighlightArea(){this.container.classList.add("highlightArea")}}class nn extends Hs{#la=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("squareAnnotation");const{data:t,width:e,height:i}=this,s=this.svgFactory.create(e,i,!0),n=t.borderStyle.width,r=this.#la=this.svgFactory.createElement("svg:rect");return r.setAttribute("x",n/2),r.setAttribute("y",n/2),r.setAttribute("width",e-n),r.setAttribute("height",i-n),r.setAttribute("stroke-width",n||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),s.append(r),this.container.append(s),!t.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#la}addHighlightArea(){this.container.classList.add("highlightArea")}}class rn extends Hs{#ha=null;constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){this.container.classList.add("circleAnnotation");const{data:t,width:e,height:i}=this,s=this.svgFactory.create(e,i,!0),n=t.borderStyle.width,r=this.#ha=this.svgFactory.createElement("svg:ellipse");return r.setAttribute("cx",e/2),r.setAttribute("cy",i/2),r.setAttribute("rx",e/2-n/2),r.setAttribute("ry",i/2-n/2),r.setAttribute("stroke-width",n||1),r.setAttribute("stroke","transparent"),r.setAttribute("fill","transparent"),s.append(r),this.container.append(s),!t.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#ha}addHighlightArea(){this.container.classList.add("highlightArea")}}class an extends Hs{#ca=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:s},width:n,height:r}=this;if(!e)return this.container;const a=this.svgFactory.create(n,r,!0);let o=[];for(let h=0,c=e.length;h<c;h+=2){const i=e[h]-t[0],s=t[3]-e[h+1];o.push(`${i},${s}`)}o=o.join(" ");const l=this.#ca=this.svgFactory.createElement(this.svgElementName);return 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),!s&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}getElementsToTriggerPopup(){return this.#ca}addHighlightArea(){this.container.classList.add("highlightArea")}}class on extends an{constructor(t){super(t),this.containerClassName="polygonAnnotation",this.svgElementName="svg:polygon"}}class ln extends Hs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0})}render(){return this.container.classList.add("caretAnnotation"),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container}}class hn extends Hs{#da=null;#ua=[];constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.containerClassName="inkAnnotation",this.svgElementName="svg:polyline",this.annotationEditorType="InkHighlight"===this.data.it?p.HIGHLIGHT:p.INK}#pa(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:s,popupRef:n}}=this,{transform:r,width:a,height:o}=this.#pa(e,t),l=this.svgFactory.create(a,o,!0),h=this.#da=this.svgFactory.createElement("svg:g");l.append(h),h.setAttribute("stroke-width",s.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",r);for(let c=0,d=i.length;c<d;c++){const t=this.svgFactory.createElement(this.svgElementName);this.#ua.push(t),t.setAttribute("points",i[c].join(",")),h.append(t)}return!n&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this.container.append(l),this._editOnDoubleClick(),this.container}updateEdited(t){super.updateEdited(t);const{thickness:e,points:i,rect:s}=t,n=this.#da;if(e>=0&&n.setAttribute("stroke-width",e||1),i)for(let r=0,a=this.#ua.length;r<a;r++)this.#ua[r].setAttribute("points",i[r].join(","));if(s){const{transform:t,width:e,height:i}=this.#pa(this.data.rotation,s),r=n.parentElement;r.setAttribute("viewBox",`0 0 ${e} ${i}`),n.setAttribute("transform",t)}}getElementsToTriggerPopup(){return this.#ua}addHighlightArea(){this.container.classList.add("highlightArea")}}class cn extends Hs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0,createQuadrilaterals:!0}),this.annotationEditorType=p.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(),t){const e=document.createElement("mark");e.classList.add("overlaidText"),e.textContent=t,this.container.append(e)}return this.container}}class dn extends Hs{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"),t){const e=document.createElement("u");e.classList.add("overlaidText"),e.textContent=t,this.container.append(e)}return this.container}}class un extends Hs{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"),t){const e=document.createElement("u");e.classList.add("overlaidText"),e.textContent=t,this.container.append(e)}return this.container}}class pn extends Hs{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"),t){const e=document.createElement("s");e.classList.add("overlaidText"),e.textContent=t,this.container.append(e)}return this.container}}class gn extends Hs{constructor(t){super(t,{isRenderable:!0,ignoreBorder:!0}),this.annotationEditorType=p.STAMP}render(){return this.container.classList.add("stampAnnotation"),this.container.setAttribute("role","img"),!this.data.popupRef&&this.hasPopupData&&(this.hasOwnCommentButton=!0,this._createPopup()),this._editOnDoubleClick(),this.container}}class mn extends Hs{#ga=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;e.hasAppearance||0===e.fillAlpha?i=document.createElement("div"):(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.#ma.bind(this)),this.#ga=i;const{isMac:s}=X.platform;return t.addEventListener("keydown",t=>{"Enter"===t.key&&(s?t.metaKey:t.ctrlKey)&&this.#ma()}),!e.popupRef&&this.hasPopupData?(this.hasOwnCommentButton=!0,this._createPopup()):i.classList.add("popupTriggerArea"),t.append(i),t}getElementsToTriggerPopup(){return this.#ga}addHighlightArea(){this.container.classList.add("highlightArea")}#ma(){this.downloadManager?.openOrDownloadData(this.content,this.filename)}}class fn{#fa=null;#ba=null;#j=null;#va=new Map;#ya=null;#wa=null;#Ur=[];#Aa=!1;constructor({div:t,accessibilityManager:e,annotationCanvasMap:i,annotationEditorUIManager:s,page:n,viewport:r,structTreeLayer:a,commentManager:o,linkService:l,annotationStorage:h}){this.div=t,this.#fa=e,this.#ba=i,this.#ya=a||null,this.#wa=l||null,this.#j=h||new he,this.page=n,this.viewport=r,this.zIndex=0,this._annotationEditorUIManager=s,this._commentManager=o||null}hasEditableAnnotations(){return this.#va.size>0}async render(t){const{annotations:e}=t,i=this.div;Dt(i,this.viewport);const s=new Map,n=[],r={data:null,layer:i,linkService:this.#wa,downloadManager:t.downloadManager,imageResourcesPath:t.imageResourcesPath||"",renderForms:!1!==t.renderForms,svgFactory:new Bs,annotationStorage:this.#j,enableComment:!0===t.enableComment,enableScripting:!0===t.enableScripting,hasJSActions:t.hasJSActions,fieldObjects:t.fieldObjects,parent:this,elements:null};for(const a of e){if(a.noHTML)continue;const t=a.annotationType===y.POPUP;if(t){const t=s.get(a.id);if(!t)continue;if(!this._commentManager){n.push(a);continue}r.elements=t}else if(a.rect[2]===a.rect[0]||a.rect[3]===a.rect[1])continue;r.data=a;const e=zs.create(r);if(!e.isRenderable)continue;if(!t&&(this.#Ur.push(e),a.popupRef)){const t=s.get(a.popupRef);t?t.push(e):s.set(a.popupRef,[e])}const i=e.render();a.hidden&&(i.style.visibility="hidden"),e._isEditable&&(this.#va.set(e.data.id,e),this._annotationEditorUIManager?.renderAnnotationElement(e))}await this.#xa();for(const a of n){const t=r.elements=s.get(a.id);r.data=a;const e=zs.create(r);if(!e.isRenderable)continue;const i=e.render();e.contentElement.id=`${it}${a.id}`,a.hidden&&(i.style.visibility="hidden"),t.at(-1).container.after(i)}this.#_a()}async#xa(){if(0===this.#Ur.length)return;this.div.replaceChildren();const t=[];if(!this.#Aa){this.#Aa=!0;for(const{contentElement:e,data:{id:i}}of this.#Ur){const s=e.id=`${it}${i}`;t.push(this.#ya?.getAriaAttributes(s).then(t=>{if(t)for(const[i,s]of t)e.setAttribute(i,s)}))}}this.#Ur.sort(({data:{rect:[t,e,i,s]}},{data:{rect:[n,r,a,o]}})=>{if(t===i&&e===s)return 1;if(n===a&&r===o)return-1;const l=s,h=e,c=(e+s)/2,d=o,u=r,p=(r+o)/2;if(c>=d&&p<=h)return-1;if(p>=l&&c<=u)return 1;const g=(t+i)/2,m=(n+a)/2;return g-m});const e=document.createDocumentFragment();for(const i of this.#Ur)e.append(i.container),this._commentManager?(i.extraPopupElement?.popup||i.popup)?.renderCommentButton():i.extraPopupElement&&e.append(i.extraPopupElement.render());if(this.div.append(e),await Promise.all(t),this.#fa)for(const i of this.#Ur)this.#fa.addPointerInTextLayer(i.contentElement,!1)}async addLinkAnnotations(t){const e={data:null,layer:this.div,linkService:this.#wa,svgFactory:new Bs,parent:this};for(const i of t){i.borderStyle||=fn._defaultBorderStyle,e.data=i;const t=zs.create(e);t.isRenderable&&(t.render(),t.contentElement.id=`${it}${i.id}`,this.#Ur.push(t))}await this.#xa()}update({viewport:t}){const e=this.div;this.viewport=t,Dt(e,{rotation:t.rotation}),this.#_a(),e.hidden=!1}#_a(){if(!this.#ba)return;const t=this.div;for(const[e,i]of this.#ba){const s=t.querySelector(`[data-annotation-id="${e}"]`);if(!s)continue;i.className="annotationContent";const{firstChild:n}=s;n?"CANVAS"===n.nodeName?n.replaceWith(i):n.classList.contains("annotationContent")?n.after(i):n.before(i):s.append(i);const r=this.#va.get(e);r&&(r._hasNoCanvas?(this._annotationEditorUIManager?.setMissingCanvas(e,s.id,i),r._hasNoCanvas=!1):r.canvas=i)}this.#ba.clear()}getEditableAnnotations(){return Array.from(this.#va.values())}getEditableAnnotation(t){return this.#va.get(t)}addFakeAnnotation(t){const{div:e}=this,{id:i,rotation:s}=t,n=new $s({data:{id:i,rect:t.getPDFRect(),rotation:s},editor:t,layer:e,parent:this,enableComment:!!this._commentManager,linkService:this.#wa,annotationStorage:this.#j});return n.render(),n.contentElement.id=`${it}${i}`,n.createOrUpdatePopup(),this.#Ur.push(n),n}removeAnnotation(t){const e=this.#Ur.findIndex(e=>e.data.id===t);if(e<0)return;const[i]=this.#Ur.splice(e,1);this.#fa?.removePointerInTextLayer(i.contentElement)}updateFakeAnnotations(t){if(0!==t.length){for(const e of t)e.updateFakeAnnotationElement(this);this.#xa()}}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}static get _defaultBorderStyle(){return F(this,"_defaultBorderStyle",Object.freeze({width:1,rawWidth:1,style:w.SOLID,dashArray:[3],horizontalCornerRadius:0,verticalCornerRadius:0}))}}const bn=/\r\n?|\n/g;class vn extends ie{#Sa="";#Ea=`${this.id}-editor`;#Ca=null;#sa;_colorPicker=null;static _freeTextDefaultContent="";static _internalPadding=0;static _defaultColor=null;static _defaultFontSize=10;static get _keyboardManager(){const t=vn.prototype,e=t=>t.isEmpty(),i=Zt.TRANSLATE_SMALL,s=Zt.TRANSLATE_BIG;return F(this,"_keyboardManager",new Kt([[["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:[-i,0],checker:e}],[["ctrl+ArrowLeft","mac+shift+ArrowLeft"],t._translateEmpty,{args:[-s,0],checker:e}],[["ArrowRight","mac+ArrowRight"],t._translateEmpty,{args:[i,0],checker:e}],[["ctrl+ArrowRight","mac+shift+ArrowRight"],t._translateEmpty,{args:[s,0],checker:e}],[["ArrowUp","mac+ArrowUp"],t._translateEmpty,{args:[0,-i],checker:e}],[["ctrl+ArrowUp","mac+shift+ArrowUp"],t._translateEmpty,{args:[0,-s],checker:e}],[["ArrowDown","mac+ArrowDown"],t._translateEmpty,{args:[0,i],checker:e}],[["ctrl+ArrowDown","mac+shift+ArrowDown"],t._translateEmpty,{args:[0,s],checker:e}]]))}static _type="freetext";static _editorType=p.FREETEXT;constructor(t){super({...t,name:"freeTextEditor"}),this.color=t.color||vn._defaultColor||ie._defaultLineColor,this.#sa=t.fontSize||vn._defaultFontSize,this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-freetext-added-alert"),this.canAddComment=!1}static initialize(t,e){ie.initialize(t,e);const i=getComputedStyle(document.documentElement);this._internalPadding=parseFloat(i.getPropertyValue("--freetext-padding"))}static updateDefaultParams(t,e){switch(t){case g.FREETEXT_SIZE:vn._defaultFontSize=e;break;case g.FREETEXT_COLOR:vn._defaultColor=e;break}}updateParams(t,e){switch(t){case g.FREETEXT_SIZE:this.#Ta(e);break;case g.FREETEXT_COLOR:this.#ta(e);break}}static get defaultPropertiesToUpdate(){return[[g.FREETEXT_SIZE,vn._defaultFontSize],[g.FREETEXT_COLOR,vn._defaultColor||ie._defaultLineColor]]}get propertiesToUpdate(){return[[g.FREETEXT_SIZE,this.#sa],[g.FREETEXT_COLOR,this.color]]}get toolbarButtons(){return this._colorPicker||=new ks(this),[["colorPicker",this._colorPicker]]}get colorType(){return g.FREETEXT_COLOR}#Ta(t){const e=t=>{this.editorDiv.style.fontSize=`calc(${t}px * var(--total-scale-factor))`,this.translate(0,-(t-this.#sa)*this.parentScale),this.#sa=t,this.#Ma()},i=this.#sa;this.addCommands({cmd:e.bind(this,t),undo:e.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:g.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})}onUpdatedColor(){this.editorDiv.style.color=this.color,this._colorPicker?.update(this.color),super.onUpdatedColor()}#ta(t){const e=t=>{this.color=t,this.onUpdatedColor()},i=this.color;this.addCommands({cmd:e.bind(this,t),undo:e.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:g.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})}_translateEmpty(t,e){this._uiManager.translateSelectedEditors(t,e,!0)}getInitialTranslation(){const t=this.parentScale;return[-vn._internalPadding*t,-(vn._internalPadding+this.#sa)*t]}rebuild(){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.#Ca=new AbortController;const t=this._uiManager.combinedSignal(this.#Ca);return 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}),!0}disableEditMode(){return!!super.disableEditMode()&&(this.overlayDiv.classList.add("enabled"),this.editorDiv.contentEditable=!1,this.div.setAttribute("aria-activedescendant",this.#Ea),this._isDraggable=!0,this.#Ca?.abort(),this.#Ca=null,this.div.focus({preventScroll:!0}),this.isEditing=!1,this.parent.div.classList.add("freetextEditing"),!0)}focusin(t){this._focusEventsAllowed&&(super.focusin(t),t.target!==this.editorDiv&&this.editorDiv.focus())}onceAdded(t){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,this.parent&&(this.parent.setEditingState(!0),this.parent.div.classList.add("freetextEditing")),super.remove()}#Da(){const t=[];this.editorDiv.normalize();let e=null;for(const i of this.editorDiv.childNodes)e?.nodeType===Node.TEXT_NODE&&"BR"===i.nodeName||(t.push(vn.#Pa(i)),e=i);return t.join("\n")}#Ma(){const[t,e]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:t,div:e}=this,s=e.style.display,n=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=s,e.classList.toggle("hidden",n)}this.rotation%180===this.parentRotation%180?(this.width=i.width/t,this.height=i.height/e):(this.width=i.height/t,this.height=i.width/e),this.fixAndSetPosition()}commit(){if(!this.isInEditMode())return;super.commit(),this.disableEditMode();const t=this.#Sa,e=this.#Sa=this.#Da().trimEnd();if(t===e)return;const i=t=>{this.#Sa=t,t?(this.#Ia(),this._uiManager.rebuild(this),this.#Ma()):this.remove()};this.addCommands({cmd:()=>{i(e)},undo:()=>{i(t)},mustExec:!1}),this.#Ma()}shouldGetKeyboardEvents(){return this.isInEditMode()}enterInEditMode(){this.enableEditMode(),this.editorDiv.focus()}keydown(t){t.target===this.div&&"Enter"===t.key&&(this.enterInEditMode(),t.preventDefault())}editorDivKeydown(t){vn._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;(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.#Ea),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;if(i.fontSize=`calc(${this.#sa}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),this._isCopy||this.annotationElementId){const[i,s]=this.parentDimensions;if(this.annotationElementId){const{position:n}=this._initialData;let[r,a]=this.getInitialTranslation();[r,a]=this.pageTranslationToScreen(r,a);const[o,l]=this.pageDimensions,[h,c]=this.pageTranslation;let d,u;switch(this.rotation){case 0:d=t+(n[0]-h)/o,u=e+this.height-(n[1]-c)/l;break;case 90:d=t+(n[0]-h)/o,u=e-(n[1]-c)/l,[r,a]=[a,-r];break;case 180:d=t-this.width+(n[0]-h)/o,u=e-(n[1]-c)/l,[r,a]=[-r,-a];break;case 270:d=t+(n[0]-h-this.height*l)/o,u=e+(n[1]-c-this.width*o)/l,[r,a]=[-a,r];break}this.setAt(d*i,u*s,r,a)}else this._moveAfterPaste(t,e);this.#Ia(),this._isDraggable=!0,this.editorDiv.contentEditable=!1}else this._isDraggable=!1,this.editorDiv.contentEditable=!0;return this.div}static#Pa(t){return(t.nodeType===Node.TEXT_NODE?t.nodeValue:t.innerText).replaceAll(bn,"")}editorDivPaste(t){const e=t.clipboardData||window.clipboardData,{types:i}=e;if(1===i.length&&"text/plain"===i[0])return;t.preventDefault();const s=vn.#ka(e.getData("text")||"").replaceAll(bn,"\n");if(!s)return;const n=window.getSelection();if(!n.rangeCount)return;this.editorDiv.normalize(),n.deleteFromDocument();const r=n.getRangeAt(0);if(!s.includes("\n"))return r.insertNode(document.createTextNode(s)),this.editorDiv.normalize(),void n.collapseToStart();const{startContainer:a,startOffset:o}=r,l=[],h=[];if(a.nodeType===Node.TEXT_NODE){const t=a.parentElement;if(h.push(a.nodeValue.slice(o).replaceAll(bn,"")),t!==this.editorDiv){let e=l;for(const i of this.editorDiv.childNodes)i!==t?e.push(vn.#Pa(i)):e=h}l.push(a.nodeValue.slice(0,o).replaceAll(bn,""))}else if(a===this.editorDiv){let t=l,e=0;for(const i of this.editorDiv.childNodes)e++===o&&(t=h),t.push(vn.#Pa(i))}this.#Sa=`${l.join("\n")}${s}${h.join("\n")}`,this.#Ia();const c=new Range;let d=Math.sumPrecise(l.map(t=>t.length));for(const{firstChild:u}of this.editorDiv.childNodes)if(u.nodeType===Node.TEXT_NODE){const t=u.nodeValue.length;if(d<=t){c.setStart(u,d),c.setEnd(u,d);break}d-=t}n.removeAllRanges(),n.addRange(c)}#Ia(){if(this.editorDiv.replaceChildren(),this.#Sa)for(const t of this.#Sa.split("\n")){const e=document.createElement("div");e.append(t?document.createTextNode(t):document.createElement("br")),this.editorDiv.append(e)}}#Ra(){return this.#Sa.replaceAll(" "," ")}static#ka(t){return t.replaceAll(" "," ")}get contentDiv(){return this.editorDiv}getPDFRect(){const t=vn._internalPadding*this.parentScale;return this.getRect(t,t)}static async deserialize(t,e,i){let s=null;if(t instanceof en){const{data:{defaultAppearanceData:{fontSize:e,fontColor:i},rect:n,rotation:r,id:a,popupRef:o,richText:l,contentsObj:h,creationDate:c,modificationDate:d},textContent:u,textPosition:g,parent:{page:{pageNumber:m}}}=t;if(!u||0===u.length)return null;s=t={annotationType:p.FREETEXT,color:Array.from(i),fontSize:e,value:u.join("\n"),position:g,pageIndex:m-1,rect:n.slice(0),rotation:r,annotationElementId:a,id:a,deleted:!1,popupRef:o,comment:h?.str||null,richText:l,creationDate:c,modificationDate:d}}const n=await super.deserialize(t,e,i);return n.#sa=t.fontSize,n.color=K.makeHexColor(...t.color),n.#Sa=vn.#ka(t.value),n._initialData=s,t.comment&&n.setCommentData(t),n}serialize(t=!1){if(this.isEmpty())return null;if(this.deleted)return this.serializeDeleted();const e=ie._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:this.color),i=Object.assign(super.serialize(t),{color:e,fontSize:this.#sa,value:this.#Ra()});return this.addComment(i),t?(i.isCopy=!0,i):this.annotationElementId&&!this.#La(i)?null:(i.id=this.annotationElementId,i)}#La(t){const{value:e,fontSize:i,color:s,pageIndex:n}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||t.value!==e||t.fontSize!==i||t.color.some((t,e)=>t!==s[e])||t.pageIndex!==n}renderAnnotationElement(t){const e=super.renderAnnotationElement(t);if(!e)return null;const{style:i}=e;i.fontSize=`calc(${this.#sa}px * var(--total-scale-factor))`,i.color=this.color,e.replaceChildren();for(const s of this.#Sa.split("\n")){const t=document.createElement("div");t.append(s?document.createTextNode(s):document.createElement("br")),e.append(t)}return t.updateEdited({rect:this.getPDFRect(),popup:this._uiManager.hasCommentManager()||this.hasEditedComment?this.comment:{text:this.#Sa}}),e}resetAnnotationElement(t){super.resetAnnotationElement(t),t.resetEdited()}}class yn{static PRECISION=1e-4;toSVGPath(){P("Abstract method `toSVGPath` must be implemented.")}get box(){P("Abstract getter `box` must be implemented.")}serialize(t,e){P("Abstract method `serialize` must be implemented.")}static _rescale(t,e,i,s,n,r){r||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)r[a]=e+t[a]*s,r[a+1]=i+t[a+1]*n;return r}static _rescaleAndSwap(t,e,i,s,n,r){r||=new Float32Array(t.length);for(let a=0,o=t.length;a<o;a+=2)r[a]=e+t[a+1]*s,r[a+1]=i+t[a]*n;return r}static _translate(t,e,i,s){s||=new Float32Array(t.length);for(let n=0,r=t.length;n<r;n+=2)s[n]=e+t[n],s[n+1]=i+t[n+1];return s}static svgRound(t){return Math.round(1e4*t)}static _normalizePoint(t,e,i,s,n){switch(n){case 90:return[1-e/i,t/s];case 180:return[1-t/i,1-e/s];case 270:return[e/i,1-t/s];default:return[t/i,e/s]}}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,s,n,r){return[(t+5*i)/6,(e+5*s)/6,(5*i+n)/6,(5*s+r)/6,(i+n)/2,(s+r)/2]}}class wn{#Fa;#Oa=[];#Ba;#Na;#Ua=[];#ja=new Float32Array(18);#za;#Ha;#$a;#Ga;#Wa;#Va;#qa=[];static#Xa=8;static#Ya=2;static#Ka=wn.#Xa+wn.#Ya;constructor({x:t,y:e},i,s,n,r,a=0){this.#Fa=i,this.#Va=n*s,this.#Na=r,this.#ja.set([NaN,NaN,NaN,NaN,t,e],6),this.#Ba=a,this.#Ga=wn.#Xa*s,this.#$a=wn.#Ka*s,this.#Wa=s,this.#qa.push(t,e)}isEmpty(){return isNaN(this.#ja[8])}#Qa(){const t=this.#ja.subarray(4,6),e=this.#ja.subarray(16,18),[i,s,n,r]=this.#Fa;return[(this.#za+(t[0]-e[0])/2-i)/n,(this.#Ha+(t[1]-e[1])/2-s)/r,(this.#za+(e[0]-t[0])/2-i)/n,(this.#Ha+(e[1]-t[1])/2-s)/r]}add({x:t,y:e}){this.#za=t,this.#Ha=e;const[i,s,n,r]=this.#Fa;let[a,o,l,h]=this.#ja.subarray(8,12);const c=t-l,d=e-h,u=Math.hypot(c,d);if(u<this.#$a)return!1;const p=u-this.#Ga,g=p/u,m=g*c,f=g*d;let b=a,v=o;a=l,o=h,l+=m,h+=f,this.#qa?.push(t,e);const y=-f/p,w=m/p,A=y*this.#Va,x=w*this.#Va;if(this.#ja.set(this.#ja.subarray(2,8),0),this.#ja.set([l+A,h+x],4),this.#ja.set(this.#ja.subarray(14,18),12),this.#ja.set([l-A,h-x],16),isNaN(this.#ja[6]))return 0===this.#Ua.length&&(this.#ja.set([a+A,o+x],2),this.#Ua.push(NaN,NaN,NaN,NaN,(a+A-i)/n,(o+x-s)/r),this.#ja.set([a-A,o-x],14),this.#Oa.push(NaN,NaN,NaN,NaN,(a-A-i)/n,(o-x-s)/r)),this.#ja.set([b,v,a,o,l,h],6),!this.isEmpty();this.#ja.set([b,v,a,o,l,h],6);const _=Math.abs(Math.atan2(v-o,b-a)-Math.atan2(f,m));return _<Math.PI/2?([a,o,l,h]=this.#ja.subarray(2,6),this.#Ua.push(NaN,NaN,NaN,NaN,((a+l)/2-i)/n,((o+h)/2-s)/r),[a,o,b,v]=this.#ja.subarray(14,18),this.#Oa.push(NaN,NaN,NaN,NaN,((b+a)/2-i)/n,((v+o)/2-s)/r),!0):([b,v,a,o,l,h]=this.#ja.subarray(0,6),this.#Ua.push(((b+5*a)/6-i)/n,((v+5*o)/6-s)/r,((5*a+l)/6-i)/n,((5*o+h)/6-s)/r,((a+l)/2-i)/n,((o+h)/2-s)/r),[l,h,a,o,b,v]=this.#ja.subarray(12,18),this.#Oa.push(((b+5*a)/6-i)/n,((v+5*o)/6-s)/r,((5*a+l)/6-i)/n,((5*o+h)/6-s)/r,((a+l)/2-i)/n,((o+h)/2-s)/r),!0)}toSVGPath(){if(this.isEmpty())return"";const t=this.#Ua,e=this.#Oa;if(isNaN(this.#ja[6])&&!this.isEmpty())return this.#Za();const i=[];i.push(`M${t[4]} ${t[5]}`);for(let s=6;s<t.length;s+=6)isNaN(t[s])?i.push(`L${t[s+4]} ${t[s+5]}`):i.push(`C${t[s]} ${t[s+1]} ${t[s+2]} ${t[s+3]} ${t[s+4]} ${t[s+5]}`);this.#Ja(i);for(let s=e.length-6;s>=6;s-=6)isNaN(e[s])?i.push(`L${e[s+4]} ${e[s+5]}`):i.push(`C${e[s]} ${e[s+1]} ${e[s+2]} ${e[s+3]} ${e[s+4]} ${e[s+5]}`);return this.#to(i),i.join(" ")}#Za(){const[t,e,i,s]=this.#Fa,[n,r,a,o]=this.#Qa();return`M${(this.#ja[2]-t)/i} ${(this.#ja[3]-e)/s} L${(this.#ja[4]-t)/i} ${(this.#ja[5]-e)/s} L${n} ${r} L${a} ${o} L${(this.#ja[16]-t)/i} ${(this.#ja[17]-e)/s} L${(this.#ja[14]-t)/i} ${(this.#ja[15]-e)/s} Z`}#to(t){const e=this.#Oa;t.push(`L${e[4]} ${e[5]} Z`)}#Ja(t){const[e,i,s,n]=this.#Fa,r=this.#ja.subarray(4,6),a=this.#ja.subarray(16,18),[o,l,h,c]=this.#Qa();t.push(`L${(r[0]-e)/s} ${(r[1]-i)/n} L${o} ${l} L${h} ${c} L${(a[0]-e)/s} ${(a[1]-i)/n}`)}newFreeDrawOutline(t,e,i,s,n,r){return new An(t,e,i,s,n,r)}getOutlines(){const t=this.#Ua,e=this.#Oa,i=this.#ja,[s,n,r,a]=this.#Fa,o=new Float32Array((this.#qa?.length??0)+2);for(let c=0,d=o.length-2;c<d;c+=2)o[c]=(this.#qa[c]-s)/r,o[c+1]=(this.#qa[c+1]-n)/a;if(o[o.length-2]=(this.#za-s)/r,o[o.length-1]=(this.#Ha-n)/a,isNaN(i[6])&&!this.isEmpty())return this.#eo(o);const l=new Float32Array(this.#Ua.length+24+this.#Oa.length);let h=t.length;for(let c=0;c<h;c+=2)isNaN(t[c])?l[c]=l[c+1]=NaN:(l[c]=t[c],l[c+1]=t[c+1]);h=this.#io(l,h);for(let c=e.length-6;c>=6;c-=6)for(let t=0;t<6;t+=2)isNaN(e[c+t])?(l[h]=l[h+1]=NaN,h+=2):(l[h]=e[c+t],l[h+1]=e[c+t+1],h+=2);return this.#so(l,h),this.newFreeDrawOutline(l,o,this.#Fa,this.#Wa,this.#Ba,this.#Na)}#eo(t){const e=this.#ja,[i,s,n,r]=this.#Fa,[a,o,l,h]=this.#Qa(),c=new Float32Array(36);return c.set([NaN,NaN,NaN,NaN,(e[2]-i)/n,(e[3]-s)/r,NaN,NaN,NaN,NaN,(e[4]-i)/n,(e[5]-s)/r,NaN,NaN,NaN,NaN,a,o,NaN,NaN,NaN,NaN,l,h,NaN,NaN,NaN,NaN,(e[16]-i)/n,(e[17]-s)/r,NaN,NaN,NaN,NaN,(e[14]-i)/n,(e[15]-s)/r],0),this.newFreeDrawOutline(c,t,this.#Fa,this.#Wa,this.#Ba,this.#Na)}#so(t,e){const i=this.#Oa;return t.set([NaN,NaN,NaN,NaN,i[4],i[5]],e),e+6}#io(t,e){const i=this.#ja.subarray(4,6),s=this.#ja.subarray(16,18),[n,r,a,o]=this.#Fa,[l,h,c,d]=this.#Qa();return t.set([NaN,NaN,NaN,NaN,(i[0]-n)/a,(i[1]-r)/o,NaN,NaN,NaN,NaN,l,h,NaN,NaN,NaN,NaN,c,d,NaN,NaN,NaN,NaN,(s[0]-n)/a,(s[1]-r)/o],e),e+24}}class An extends yn{#Fa;#no=new Float32Array(4);#Ba;#Na;#qa;#Wa;#ro;constructor(t,e,i,s,n,r){super(),this.#ro=t,this.#qa=e,this.#Fa=i,this.#Wa=s,this.#Ba=n,this.#Na=r,this.firstPoint=[NaN,NaN],this.lastPoint=[NaN,NaN],this.#ao(r);const[a,o,l,h]=this.#no;for(let c=0,d=t.length;c<d;c+=2)t[c]=(t[c]-a)/l,t[c+1]=(t[c+1]-o)/h;for(let c=0,d=e.length;c<d;c+=2)e[c]=(e[c]-a)/l,e[c+1]=(e[c+1]-o)/h}toSVGPath(){const t=[`M${this.#ro[4]} ${this.#ro[5]}`];for(let e=6,i=this.#ro.length;e<i;e+=6)isNaN(this.#ro[e])?t.push(`L${this.#ro[e+4]} ${this.#ro[e+5]}`):t.push(`C${this.#ro[e]} ${this.#ro[e+1]} ${this.#ro[e+2]} ${this.#ro[e+3]} ${this.#ro[e+4]} ${this.#ro[e+5]}`);return t.push("Z"),t.join(" ")}serialize([t,e,i,s],n){const r=i-t,a=s-e;let o,l;switch(n){case 0:o=yn._rescale(this.#ro,t,s,r,-a),l=yn._rescale(this.#qa,t,s,r,-a);break;case 90:o=yn._rescaleAndSwap(this.#ro,t,e,r,a),l=yn._rescaleAndSwap(this.#qa,t,e,r,a);break;case 180:o=yn._rescale(this.#ro,i,e,-r,a),l=yn._rescale(this.#qa,i,e,-r,a);break;case 270:o=yn._rescaleAndSwap(this.#ro,i,s,-r,-a),l=yn._rescaleAndSwap(this.#qa,i,s,-r,-a);break}return{outline:Array.from(o),points:[Array.from(l)]}}#ao(t){const e=this.#ro;let i=e[4],s=e[5];const n=[i,s,i,s];let r=i,a=s,o=i,l=s;const h=t?Math.max:Math.min,c=new Float32Array(4);for(let u=6,p=e.length;u<p;u+=6){const t=e[u+4],d=e[u+5];isNaN(e[u])?(K.pointBoundingBox(t,d,n),a>d?(r=t,a=d):a===d&&(r=h(r,t)),l<d?(o=t,l=d):l===d&&(o=h(o,t))):(c[0]=c[1]=1/0,c[2]=c[3]=-1/0,K.bezierBoundingBox(i,s,...e.slice(u,u+6),c),K.rectBoundingBox(c[0],c[1],c[2],c[3],n),a>c[1]?(r=c[0],a=c[1]):a===c[1]&&(r=h(r,c[0])),l<c[3]?(o=c[2],l=c[3]):l===c[3]&&(o=h(o,c[2]))),i=t,s=d}const d=this.#no;d[0]=n[0]-this.#Ba,d[1]=n[1]-this.#Ba,d[2]=n[2]-n[0]+2*this.#Ba,d[3]=n[3]-n[1]+2*this.#Ba,this.firstPoint=[r,a],this.lastPoint=[o,l]}get box(){return this.#no}newOutliner(t,e,i,s,n,r=0){return new wn(t,e,i,s,n,r)}getNewOutline(t,e){const[i,s,n,r]=this.#no,[a,o,l,h]=this.#Fa,c=n*l,d=r*h,u=i*l+a,p=s*h+o,g=this.newOutliner({x:this.#qa[0]*c+u,y:this.#qa[1]*d+p},this.#Fa,this.#Wa,t,this.#Na,e??this.#Ba);for(let m=2;m<this.#qa.length;m+=2)g.add({x:this.#qa[m]*c+u,y:this.#qa[m+1]*d+p});return g.getOutlines()}}class xn{#Fa;#oo;#lo;#ho=[];#co=[];constructor(t,e=0,i=0,s=!0){const n=[1/0,1/0,-1/0,-1/0],r=4,a=10**-r;for(const{x:m,y:f,width:b,height:v}of t){const t=Math.floor((m-e)/a)*a,i=Math.ceil((m+b+e)/a)*a,s=Math.floor((f-e)/a)*a,r=Math.ceil((f+v+e)/a)*a,o=[t,s,r,!0],l=[i,s,r,!1];this.#ho.push(o,l),K.rectBoundingBox(t,s,i,r,n)}const o=n[2]-n[0]+2*i,l=n[3]-n[1]+2*i,h=n[0]-i,c=n[1]-i;let d=s?-1/0:1/0,u=1/0;const p=this.#ho.at(s?-1:-2),g=[p[0],p[2]];for(const m of this.#ho){const[t,e,i,n]=m;!n&&s?e<u?(u=e,d=t):e===u&&(d=Math.max(d,t)):n&&!s&&(e<u?(u=e,d=t):e===u&&(d=Math.min(d,t))),m[0]=(t-h)/o,m[1]=(e-c)/l,m[2]=(i-c)/l}this.#Fa=new Float32Array([h,c,o,l]),this.#oo=[d,u],this.#lo=g}getOutlines(){this.#ho.sort((t,e)=>t[0]-e[0]||t[1]-e[1]||t[2]-e[2]);const t=[];for(const e of this.#ho)e[3]?(t.push(...this.#do(e)),this.#uo(e)):(this.#po(e),t.push(...this.#do(e)));return this.#go(t)}#go(t){const e=[],i=new Set;for(const r of t){const[t,i,s]=r;e.push([t,i,r],[t,s,r])}e.sort((t,e)=>t[1]-e[1]||t[0]-e[0]);for(let r=0,a=e.length;r<a;r+=2){const t=e[r][2],s=e[r+1][2];t.push(s),s.push(t),i.add(t),i.add(s)}const s=[];let n;while(i.size>0){const t=i.values().next().value;let[e,r,a,o,l]=t;i.delete(t);let h=e,c=r;n=[e,a],s.push(n);while(1){let t;if(i.has(o))t=o;else{if(!i.has(l))break;t=l}i.delete(t),[e,r,a,o,l]=t,h!==e&&(n.push(h,c,e,c===r?r:a),h=e),c=c===r?a:r}n.push(h,c)}return new _n(s,this.#Fa,this.#oo,this.#lo)}#mo(t){const e=this.#co;let i=0,s=e.length-1;while(i<=s){const n=i+s>>1,r=e[n][0];if(r===t)return n;r<t?i=n+1:s=n-1}return s+1}#uo([,t,e]){const i=this.#mo(t);this.#co.splice(i,0,[t,e])}#po([,t,e]){const i=this.#mo(t);for(let s=i;s<this.#co.length;s++){const[i,n]=this.#co[s];if(i!==t)break;if(i===t&&n===e)return void this.#co.splice(s,1)}for(let s=i-1;s>=0;s--){const[i,n]=this.#co[s];if(i!==t)break;if(i===t&&n===e)return void this.#co.splice(s,1)}}#do(t){const[e,i,s]=t,n=[[e,i,s]],r=this.#mo(s);for(let a=0;a<r;a++){const[t,i]=this.#co[a];for(let s=0,r=n.length;s<r;s++){const[,a,o]=n[s];if(!(i<=a||o<=t))if(a>=t)if(o>i)n[s][1]=i;else{if(1===r)return[];n.splice(s,1),s--,r--}else n[s][2]=t,o>i&&n.push([e,i,o])}}return n}}class _n extends yn{#Fa;#fo;constructor(t,e,i,s){super(),this.#fo=t,this.#Fa=e,this.firstPoint=i,this.lastPoint=s}toSVGPath(){const t=[];for(const e of this.#fo){let[i,s]=e;t.push(`M${i} ${s}`);for(let n=2;n<e.length;n+=2){const r=e[n],a=e[n+1];r===i?(t.push(`V${a}`),s=a):a===s&&(t.push(`H${r}`),i=r)}t.push("Z")}return t.join(" ")}serialize([t,e,i,s],n){const r=[],a=i-t,o=s-e;for(const l of this.#fo){const e=new Array(l.length);for(let i=0;i<l.length;i+=2)e[i]=t+l[i]*a,e[i+1]=s-l[i+1]*o;r.push(e)}return r}get box(){return this.#Fa}get classNamesForOutlining(){return["highlightOutline"]}}class Sn extends wn{newFreeDrawOutline(t,e,i,s,n,r){return new En(t,e,i,s,n,r)}}class En extends An{newOutliner(t,e,i,s,n,r=0){return new Sn(t,e,i,s,n,r)}}class Cn extends ie{#bo=null;#vo=0;#yo;#wo=null;#n=null;#Ao=null;#xo=null;#_o=0;#So=null;#Eo=null;#E=null;#Co=!1;#oo=null;#lo=null;#To=null;#ge="";#Va;#Mo="";static _defaultColor=null;static _defaultOpacity=1;static _defaultThickness=12;static _type="highlight";static _editorType=p.HIGHLIGHT;static _freeHighlightId=-1;static _freeHighlight=null;static _freeHighlightClipId="";static get _keyboardManager(){const t=Cn.prototype;return F(this,"_keyboardManager",new Kt([[["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||Cn._defaultColor,this.#Va=t.thickness||Cn._defaultThickness,this.opacity=t.opacity||Cn._defaultOpacity,this.#yo=t.boxes||null,this.#Mo=t.methodOfCreation||"",this.#ge=t.text||"",this._isDraggable=!1,this.defaultL10nId="pdfjs-editor-highlight-editor",t.highlightId>-1?(this.#Co=!0,this.#Do(t),this.#Po()):this.#yo&&(this.#bo=t.anchorNode,this.#vo=t.anchorOffset,this.#xo=t.focusNode,this.#_o=t.focusOffset,this.#Io(),this.#Po(),this.rotate(this.rotation)),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert")}get telemetryInitialData(){return{action:"added",type:this.#Co?"free_highlight":"highlight",color:this._uiManager.getNonHCMColorName(this.color),thickness:this.#Va,methodOfCreation:this.#Mo}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.getNonHCMColorName(this.color)}}static computeTelemetryFinalData(t){return{numberOfColors:t.get("color").size}}#Io(){const t=new xn(this.#yo,.001);this.#Eo=t.getOutlines(),[this.x,this.y,this.width,this.height]=this.#Eo.box;const e=new xn(this.#yo,.0025,.001,"ltr"===this._uiManager.direction);this.#Ao=e.getOutlines();const{firstPoint:i}=this.#Eo;this.#oo=[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height];const{lastPoint:s}=this.#Ao;this.#lo=[(s[0]-this.x)/this.width,(s[1]-this.y)/this.height]}#Do({highlightOutlines:t,highlightId:e,clipPathId:i}){this.#Eo=t;const s=1.5;if(this.#Ao=t.getNewOutline(this.#Va/2+s,.0025),e>=0)this.#E=e,this.#wo=i,this.parent.drawLayer.finalizeDraw(e,{bbox:t.box,path:{d:t.toSVGPath()}}),this.#To=this.parent.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:!0},bbox:this.#Ao.box,path:{d:this.#Ao.toSVGPath()}},!0);else if(this.parent){const e=this.parent.viewport.rotation;this.parent.drawLayer.updateProperties(this.#E,{bbox:Cn.#ko(this.#Eo.box,(e-this.rotation+360)%360),path:{d:t.toSVGPath()}}),this.parent.drawLayer.updateProperties(this.#To,{bbox:Cn.#ko(this.#Ao.box,e),path:{d:this.#Ao.toSVGPath()}})}const[n,r,a,o]=t.box;switch(this.rotation){case 0:this.x=n,this.y=r,this.width=a,this.height=o;break;case 90:{const[t,e]=this.parentDimensions;this.x=r,this.y=1-n,this.width=a*e/t,this.height=o*t/e;break}case 180:this.x=1-n,this.y=1-r,this.width=a,this.height=o;break;case 270:{const[t,e]=this.parentDimensions;this.x=1-r,this.y=n,this.width=a*e/t,this.height=o*t/e;break}}const{firstPoint:l}=t;this.#oo=[(l[0]-n)/a,(l[1]-r)/o];const{lastPoint:h}=this.#Ao;this.#lo=[(h[0]-n)/a,(h[1]-r)/o]}static initialize(t,e){ie.initialize(t,e),Cn._defaultColor||=e.highlightColors?.values().next().value||"#fff066"}static updateDefaultParams(t,e){switch(t){case g.HIGHLIGHT_COLOR:Cn._defaultColor=e;break;case g.HIGHLIGHT_THICKNESS:Cn._defaultThickness=e;break}}translateInPage(t,e){}get toolbarPosition(){return this.#lo}get commentButtonPosition(){return this.#oo}updateParams(t,e){switch(t){case g.HIGHLIGHT_COLOR:this.#ta(e);break;case g.HIGHLIGHT_THICKNESS:this.#Ro(e);break}}static get defaultPropertiesToUpdate(){return[[g.HIGHLIGHT_COLOR,Cn._defaultColor],[g.HIGHLIGHT_THICKNESS,Cn._defaultThickness]]}get propertiesToUpdate(){return[[g.HIGHLIGHT_COLOR,this.color||Cn._defaultColor],[g.HIGHLIGHT_THICKNESS,this.#Va||Cn._defaultThickness],[g.HIGHLIGHT_FREE,this.#Co]]}onUpdatedColor(){this.parent?.drawLayer.updateProperties(this.#E,{root:{fill:this.color,"fill-opacity":this.opacity}}),this.#n?.updateColor(this.color),super.onUpdatedColor()}#ta(t){const e=(t,e)=>{this.color=t,this.opacity=e,this.onUpdatedColor()},i=this.color,s=this.opacity;this.addCommands({cmd:e.bind(this,t,Cn._defaultOpacity),undo:e.bind(this,i,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:g.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.getNonHCMColorName(t)},!0)}#Ro(t){const e=this.#Va,i=t=>{this.#Va=t,this.#Lo(t)};this.addCommands({cmd:i.bind(this,t),undo:i.bind(this,e),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:g.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:t},!0)}get toolbarButtons(){if(this._uiManager.highlightColors){const t=this.#n=new Is({editor:this});return[["colorPicker",t]]}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.#Fo())}getBaseTranslation(){return[0,0]}getRect(t,e){return super.getRect(t,e,this.#Fo())}onceAdded(t){this.annotationElementId||this.parent.addUndoableEditor(this),t&&this.div.focus()}remove(){this.#Oo(),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),null!==this.div&&(this.#Po(),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?this.#Oo():t&&(this.#Po(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),this.show(this._isVisible),e&&this.select()}#Lo(t){this.#Co&&(this.#Do({highlightOutlines:this.#Eo.getNewOutline(t/2)}),this.fixAndSetPosition(),this.setDims())}#Oo(){null!==this.#E&&this.parent&&(this.parent.drawLayer.remove(this.#E),this.#E=null,this.parent.drawLayer.remove(this.#To),this.#To=null)}#Po(t=this.parent){null===this.#E&&(({id:this.#E,clipPathId:this.#wo}=t.drawLayer.draw({bbox:this.#Eo.box,root:{viewBox:"0 0 1 1",fill:this.color,"fill-opacity":this.opacity},rootClass:{highlight:!0,free:this.#Co},path:{d:this.#Eo.toSVGPath()}},!1,!0)),this.#To=t.drawLayer.drawOutline({rootClass:{highlightOutline:!0,free:this.#Co},bbox:this.#Ao.box,path:{d:this.#Ao.toSVGPath()}},this.#Co),this.#So&&(this.#So.style.clipPath=this.#wo))}static#ko([t,e,i,s],n){switch(n){case 90:return[1-e-s,t,s,i];case 180:return[1-t-i,1-e-s,i,s];case 270:return[e,1-t-i,s,i]}return[t,e,i,s]}rotate(t){const{drawLayer:e}=this.parent;let i;this.#Co?(t=(t-this.rotation+360)%360,i=Cn.#ko(this.#Eo.box,t)):i=Cn.#ko([this.x,this.y,this.width,this.height],t),e.updateProperties(this.#E,{bbox:i,root:{"data-main-rotation":t}}),e.updateProperties(this.#To,{bbox:Cn.#ko(this.#Ao.box,t),root:{"data-main-rotation":t}})}render(){if(this.div)return this.div;const t=super.render();this.#ge&&(t.setAttribute("aria-label",this.#ge),t.setAttribute("role","mark")),this.#Co?t.classList.add("free"):this.div.addEventListener("keydown",this.#Bo.bind(this),{signal:this._uiManager._signal});const e=this.#So=document.createElement("div");return t.append(e),e.setAttribute("aria-hidden","true"),e.className="internal",e.style.clipPath=this.#wo,this.setDims(),Wt(this,this.#So,["pointerover","pointerleave"]),this.enableEditing(),t}pointerover(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#To,{rootClass:{hovered:!0}})}pointerleave(){this.isSelected||this.parent?.drawLayer.updateProperties(this.#To,{rootClass:{hovered:!1}})}#Bo(t){Cn._keyboardManager.exec(this,t)}_moveCaret(t){switch(this.parent.unselect(this),t){case 0:case 2:this.#No(!0);break;case 1:case 3:this.#No(!1);break}}#No(t){if(!this.#bo)return;const e=window.getSelection();t?e.setPosition(this.#bo,this.#vo):e.setPosition(this.#xo,this.#_o)}select(){super.select(),this.#To&&this.parent?.drawLayer.updateProperties(this.#To,{rootClass:{hovered:!1,selected:!0}})}unselect(){super.unselect(),this.#To&&(this.parent?.drawLayer.updateProperties(this.#To,{rootClass:{selected:!1}}),this.#Co||this.#No(!1))}get _mustFixPosition(){return!this.#Co}show(t=this._isVisible){super.show(t),this.parent&&(this.parent.drawLayer.updateProperties(this.#E,{rootClass:{hidden:!t}}),this.parent.drawLayer.updateProperties(this.#To,{rootClass:{hidden:!t}}))}#Fo(){return this.#Co?this.rotation:0}#Uo(){if(this.#Co)return null;const[t,e]=this.pageDimensions,[i,s]=this.pageTranslation,n=this.#yo,r=new Float32Array(8*n.length);let a=0;for(const{x:o,y:l,width:h,height:c}of n){const n=o*t+i,d=(1-l)*e+s;r[a]=r[a+4]=n,r[a+1]=r[a+3]=d,r[a+2]=r[a+6]=n+h*t,r[a+5]=r[a+7]=d-c*e,a+=8}return r}#jo(t){return this.#Eo.serialize(t,this.#Fo())}static startHighlighting(t,e,{target:i,x:s,y:n}){const{x:r,y:a,width:o,height:l}=i.getBoundingClientRect(),h=new AbortController,c=t.combinedSignal(h),d=e=>{h.abort(),this.#zo(t,e)};window.addEventListener("blur",d,{signal:c}),window.addEventListener("pointerup",d,{signal:c}),window.addEventListener("pointerdown",At,{capture:!0,passive:!1,signal:c}),window.addEventListener("contextmenu",wt,{signal:c}),i.addEventListener("pointermove",this.#Ho.bind(this,t),{signal:c}),this._freeHighlight=new Sn({x:s,y:n},[r,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#Ho(t,e){this._freeHighlight.add(e)&&t.drawLayer.updateProperties(this._freeHighlightId,{path:{d:this._freeHighlight.toSVGPath()}})}static#zo(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 s=null;if(t instanceof cn){const{data:{quadPoints:e,rect:i,rotation:n,id:r,color:a,opacity:o,popupRef:l,richText:h,contentsObj:c,creationDate:d,modificationDate:u},parent:{page:{pageNumber:g}}}=t;s=t={annotationType:p.HIGHLIGHT,color:Array.from(a),opacity:o,quadPoints:e,boxes:null,pageIndex:g-1,rect:i.slice(0),rotation:n,annotationElementId:r,id:r,deleted:!1,popupRef:l,richText:h,comment:c?.str||null,creationDate:d,modificationDate:u}}else if(t instanceof hn){const{data:{inkLists:e,rect:i,rotation:n,id:r,color:a,borderStyle:{rawWidth:o},popupRef:l,richText:h,contentsObj:c,creationDate:d,modificationDate:u},parent:{page:{pageNumber:g}}}=t;s=t={annotationType:p.HIGHLIGHT,color:Array.from(a),thickness:o,inkLists:e,boxes:null,pageIndex:g-1,rect:i.slice(0),rotation:n,annotationElementId:r,id:r,deleted:!1,popupRef:l,richText:h,comment:c?.str||null,creationDate:d,modificationDate:u}}const{color:n,quadPoints:r,inkLists:a,opacity:o}=t,l=await super.deserialize(t,e,i);l.color=K.makeHexColor(...n),l.opacity=o||1,a&&(l.#Va=t.thickness),l._initialData=s,t.comment&&l.setCommentData(t);const[h,c]=l.pageDimensions,[d,u]=l.pageTranslation;if(r){const t=l.#yo=[];for(let e=0;e<r.length;e+=8)t.push({x:(r[e]-d)/h,y:1-(r[e+1]-u)/c,width:(r[e+2]-r[e])/h,height:(r[e+1]-r[e+5])/c});l.#Io(),l.#Po(),l.rotate(l.rotation)}else if(a){l.#Co=!0;const t=a[0],i={x:t[0]-d,y:c-(t[1]-u)},s=new Sn(i,[0,0,h,c],1,l.#Va/2,!0,.001);for(let e=0,a=t.length;e<a;e+=2)i.x=t[e]-d,i.y=c-(t[e+1]-u),s.add(i);const{id:n,clipPathId:r}=e.drawLayer.draw({bbox:[0,0,1,1],root:{viewBox:"0 0 1 1",fill:l.color,"fill-opacity":l._defaultOpacity},rootClass:{highlight:!0,free:!0},path:{d:s.toSVGPath()}},!0,!0);l.#Do({highlightOutlines:s.getOutlines(),highlightId:n,clipPathId:r}),l.#Po(),l.rotate(l.parentRotation)}return l}serialize(t=!1){if(this.isEmpty()||t)return null;if(this.deleted)return this.serializeDeleted();const e=ie._colorManager.convert(this._uiManager.getNonHCMColor(this.color)),i=super.serialize(t);return Object.assign(i,{color:e,opacity:this.opacity,thickness:this.#Va,quadPoints:this.#Uo(),outlines:this.#jo(i.rect)}),this.addComment(i),this.annotationElementId&&!this.#La(i)?null:(i.id=this.annotationElementId,i)}#La(t){const{color:e}=this._initialData;return this.hasEditedComment||t.color.some((t,i)=>t!==e[i])}renderAnnotationElement(t){return this.deleted?(t.hide(),null):(t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}static canCreateNewEmptyEditor(){return!1}}class Tn{#$o=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.#$o[t]=e}toSVGProperties(){const t=this.#$o;return this.#$o=Object.create(null),{root:t}}reset(){this.#$o=Object.create(null)}updateAll(t=this){this.updateProperties(t)}clone(){P("Not implemented")}}class Mn extends ie{#Go=null;#Wo;_colorPicker=null;_drawId=null;static _currentDrawId=-1;static _currentParent=null;static#Vo=null;static#qo=null;static#Xo=null;static _INNER_MARGIN=3;constructor(t){super(t),this.#Wo=t.mustBeCommitted||!1,this._addOutlines(t)}onUpdatedColor(){this._colorPicker?.update(this.color),super.onUpdatedColor()}_addOutlines(t){t.drawOutlines&&(this.#Yo(t),this.#Po())}#Yo({drawOutlines:t,drawId:e,drawingOptions:i}){this.#Go=t,this._drawingOptions||=i,this.annotationElementId||this._uiManager.a11yAlert(`pdfjs-editor-${this.editorType}-added-alert`),e>=0?(this._drawId=e,this.parent.drawLayer.finalizeDraw(e,t.defaultProperties)):this._drawId=this.#Ko(t,this.parent),this.#Qo(t.box)}#Ko(t,e){const{id:i}=e.drawLayer.draw(Mn._mergeSVGProperties(this._drawingOptions.toSVGProperties(),t.defaultSVGProperties),!1,!1);return i}static _mergeSVGProperties(t,e){const i=new Set(Object.keys(t));for(const[s,n]of Object.entries(e))i.has(s)?Object.assign(t[s],n):t[s]=n;return t}static getDefaultDrawingOptions(t){P("Not implemented")}static get typesMap(){P("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),this._currentParent&&(Mn.#Vo.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,s]of this.typesMap)t.push([i,e[s]]);return t}get propertiesToUpdate(){const t=[],{_drawingOptions:e}=this;for(const[i,s]of this.constructor.typesMap)t.push([i,e[s]]);return t}_updateProperty(t,e,i){const s=this._drawingOptions,n=s[e],r=i=>{s.updateProperty(e,i);const n=this.#Go.updateProperty(e,i);n&&this.#Qo(n),this.parent?.drawLayer.updateProperties(this._drawId,s.toSVGProperties()),t===this.colorType&&this.onUpdatedColor()};this.addCommands({cmd:r.bind(this,i),undo:r.bind(this,n),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:t,overwriteIfSameType:!0,keepUndo:!0})}_onResizing(){this.parent?.drawLayer.updateProperties(this._drawId,Mn._mergeSVGProperties(this.#Go.getPathResizingSVGProperties(this.#Zo()),{bbox:this.#Jo()}))}_onResized(){this.parent?.drawLayer.updateProperties(this._drawId,Mn._mergeSVGProperties(this.#Go.getPathResizedSVGProperties(this.#Zo()),{bbox:this.#Jo()}))}_onTranslating(t,e){this.parent?.drawLayer.updateProperties(this._drawId,{bbox:this.#Jo()})}_onTranslated(){this.parent?.drawLayer.updateProperties(this._drawId,Mn._mergeSVGProperties(this.#Go.getPathTranslatedSVGProperties(this.#Zo(),this.parentDimensions),{bbox:this.#Jo()}))}_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,this.#Wo&&(this.#Wo=!1,this.commit(),this.parent.setSelected(this),t&&this.isOnScreen&&this.div.focus())}remove(){this.#Oo(),super.remove()}rebuild(){this.parent&&(super.rebuild(),null!==this.div&&(this.#Po(),this.#Qo(this.#Go.box),this.isAttachedToDOM||this.parent.add(this)))}setParent(t){let e=!1;this.parent&&!t?(this._uiManager.removeShouldRescale(this),this.#Oo()):t&&(this._uiManager.addShouldRescale(this),this.#Po(t),e=!this.parent&&this.div?.classList.contains("selectedEditor")),super.setParent(t),e&&this.select()}#Oo(){null!==this._drawId&&this.parent&&(this.parent.drawLayer.remove(this._drawId),this._drawId=null,this._drawingOptions.reset())}#Po(t=this.parent){null!==this._drawId&&this.parent===t||(null===this._drawId?(this._drawingOptions.updateAll(),this._drawId=this.#Ko(this.#Go,t)):this.parent.drawLayer.updateParent(this._drawId,t.drawLayer))}#tl([t,e,i,s]){const{parentDimensions:[n,r],rotation:a}=this;switch(a){case 90:return[e,1-t,i*(r/n),s*(n/r)];case 180:return[1-t,1-e,i,s];case 270:return[1-e,t,i*(r/n),s*(n/r)];default:return[t,e,i,s]}}#Zo(){const{x:t,y:e,width:i,height:s,parentDimensions:[n,r],rotation:a}=this;switch(a){case 90:return[1-e,t,i*(n/r),s*(r/n)];case 180:return[1-t,1-e,i,s];case 270:return[e,1-t,i*(n/r),s*(r/n)];default:return[t,e,i,s]}}#Qo(t){[this.x,this.y,this.width,this.height]=this.#tl(t),this.div&&(this.fixAndSetPosition(),this.setDims()),this._onResized()}#Jo(){const{x:t,y:e,width:i,height:s,rotation:n,parentRotation:r,parentDimensions:[a,o]}=this;switch((4*n+r)/90){case 1:return[1-e-s,t,s,i];case 2:return[1-t-i,1-e-s,i,s];case 3:return[e,1-t-i,s,i];case 4:return[t,e-i*(a/o),s*(o/a),i*(a/o)];case 5:return[1-e,t,i*(a/o),s*(o/a)];case 6:return[1-t-s*(o/a),1-e,s*(o/a),i*(a/o)];case 7:return[e-i*(a/o),1-t-s*(o/a),i*(a/o),s*(o/a)];case 8:return[t-i,e-s,i,s];case 9:return[1-e,t-i,s,i];case 10:return[1-t,1-e,i,s];case 11:return[e-s,1-t,s,i];case 12:return[t-s*(o/a),e,s*(o/a),i*(a/o)];case 13:return[1-e-i*(a/o),t-s*(o/a),i*(a/o),s*(o/a)];case 14:return[1-t,1-e-i*(a/o),s*(o/a),i*(a/o)];case 15:return[e,1-t,i*(a/o),s*(o/a)];default:return[t,e,i,s]}}rotate(){this.parent&&this.parent.drawLayer.updateProperties(this._drawId,Mn._mergeSVGProperties({bbox:this.#Jo()},this.#Go.updateRotation((this.parentRotation-this.rotation+360)%360)))}onScaleChanging(){this.parent&&this.#Qo(this.#Go.updateParentDimensions(this.parentDimensions,this.parent.scale))}static onScaleChangingWhenDrawing(){}render(){if(this.div)return this.div;let t,e;this._isCopy&&(t=this.x,e=this.y);const i=super.render();i.classList.add("draw");const s=document.createElement("div");return i.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",this.setDims(),this._uiManager.addShouldRescale(this),this.disableEditing(),this._isCopy&&this._moveAfterPaste(t,e),i}static createDrawerInstance(t,e,i,s,n){P("Not implemented")}static startDrawing(t,e,i,s){const{target:n,offsetX:r,offsetY:a,pointerId:o,pointerType:l}=s;if(Vt.isInitializedAndDifferentPointerType(l))return;const{viewport:{rotation:h}}=t,{width:c,height:d}=n.getBoundingClientRect(),u=Mn.#qo=new AbortController,p=t.combinedSignal(u);Vt.setPointer(l,o),window.addEventListener("pointerup",t=>{Vt.isSamePointerIdOrRemove(t.pointerId)&&this._endDraw(t)},{signal:p}),window.addEventListener("pointercancel",t=>{Vt.isSamePointerIdOrRemove(t.pointerId)&&this._currentParent.endDrawingSession()},{signal:p}),window.addEventListener("pointerdown",t=>{Vt.isSamePointerType(t.pointerType)&&(Vt.initializeAndAddPointerId(t.pointerId),Mn.#Vo.isCancellable()&&(Mn.#Vo.removeLastElement(),Mn.#Vo.isEmpty()?this._currentParent.endDrawingSession(!0):this._endDraw(null)))},{capture:!0,passive:!1,signal:p}),window.addEventListener("contextmenu",wt,{signal:p}),n.addEventListener("pointermove",this._drawMove.bind(this),{signal:p}),n.addEventListener("touchmove",t=>{Vt.isSameTimeStamp(t.timeStamp)&&At(t)},{signal:p}),t.toggleDrawing(),e._editorUndoBar?.hide(),Mn.#Vo?t.drawLayer.updateProperties(this._currentDrawId,Mn.#Vo.startNew(r,a,c,d,h)):(e.updateUIForDefaultProperties(this),Mn.#Vo=this.createDrawerInstance(r,a,c,d,h),Mn.#Xo=this.getDefaultDrawingOptions(),this._currentParent=t,({id:this._currentDrawId}=t.drawLayer.draw(this._mergeSVGProperties(Mn.#Xo.toSVGProperties(),Mn.#Vo.defaultSVGProperties),!0,!1)))}static _drawMove(t){if(Vt.isSameTimeStamp(t.timeStamp),!Mn.#Vo)return;const{offsetX:e,offsetY:i,pointerId:s}=t;Vt.isSamePointerId(s)&&(Vt.isUsingMultiplePointers()?this._endDraw(t):(this._currentParent.drawLayer.updateProperties(this._currentDrawId,Mn.#Vo.add(e,i)),Vt.setTimeStamp(t.timeStamp),At(t)))}static _cleanup(t){t&&(this._currentDrawId=-1,this._currentParent=null,Mn.#Vo=null,Mn.#Xo=null,Vt.clearTimeStamp()),Mn.#qo&&(Mn.#qo.abort(),Mn.#qo=null,Vt.clearPointerIds())}static _endDraw(t){const e=this._currentParent;if(e){if(e.toggleDrawing(!0),this._cleanup(!1),t?.target===e.div&&e.drawLayer.updateProperties(this._currentDrawId,Mn.#Vo.end(t.offsetX,t.offsetY)),this.supportMultipleDrawings){const t=Mn.#Vo,i=this._currentDrawId,s=t.getLastElement();return void e.addCommands({cmd:()=>{e.drawLayer.updateProperties(i,t.setLastElement(s))},undo:()=>{e.drawLayer.updateProperties(i,t.removeLastElement())},mustExec:!1,type:g.DRAW_STEP})}this.endDrawing(!1)}}static endDrawing(t){const e=this._currentParent;if(!e)return null;if(e.toggleDrawing(!0),e.cleanUndoStack(g.DRAW_STEP),!Mn.#Vo.isEmpty()){const{pageDimensions:[i,s],scale:n}=e,r=e.createAndAddNewEditor({offsetX:0,offsetY:0},!1,{drawId:this._currentDrawId,drawOutlines:Mn.#Vo.getOutlines(i*n,s*n,n,this._INNER_MARGIN),drawingOptions:Mn.#Xo,mustBeCommitted:!t});return this._cleanup(!0),r}return e.drawLayer.remove(this._currentDrawId),this._cleanup(!0),null}createDrawingOptions(t){}static deserializeDraw(t,e,i,s,n,r){P("Not implemented")}static async deserialize(t,e,i){const{rawDims:{pageWidth:s,pageHeight:n,pageX:r,pageY:a}}=e.viewport,o=this.deserializeDraw(r,a,s,n,this._INNER_MARGIN,t),l=await super.deserialize(t,e,i);return l.createDrawingOptions(t),l.#Yo({drawOutlines:o}),l.#Po(),l.onScaleChanging(),l.rotate(),l}serializeDraw(t){const[e,i]=this.pageTranslation,[s,n]=this.pageDimensions;return this.#Go.serialize([e,i,s,n],t)}renderAnnotationElement(t){return t.updateEdited({rect:this.getPDFRect()}),null}static canCreateNewEmptyEditor(){return!1}}class Dn{#ja=new Float64Array(6);#oa;#el;#mn;#Va;#qa;#il="";#sl=0;#fo=new Pn;#nl;#rl;constructor(t,e,i,s,n,r){this.#nl=i,this.#rl=s,this.#mn=n,this.#Va=r,[t,e]=this.#al(t,e);const a=this.#oa=[NaN,NaN,NaN,NaN,t,e];this.#qa=[t,e],this.#el=[{line:a,points:this.#qa}],this.#ja.set(a,0)}updateProperty(t,e){"stroke-width"===t&&(this.#Va=e)}#al(t,e){return yn._normalizePoint(t,e,this.#nl,this.#rl,this.#mn)}isEmpty(){return!this.#el||0===this.#el.length}isCancellable(){return this.#qa.length<=10}add(t,e){[t,e]=this.#al(t,e);const[i,s,n,r]=this.#ja.subarray(2,6),a=t-n,o=e-r,l=Math.hypot(this.#nl*a,this.#rl*o);return l<=2?null:(this.#qa.push(t,e),isNaN(i)?(this.#ja.set([n,r,t,e],2),this.#oa.push(NaN,NaN,NaN,NaN,t,e),{path:{d:this.toSVGPath()}}):(isNaN(this.#ja[0])&&this.#oa.splice(6,6),this.#ja.set([i,s,n,r,t,e],0),this.#oa.push(...yn.createBezierPoints(i,s,n,r,t,e)),{path:{d:this.toSVGPath()}}))}end(t,e){const i=this.add(t,e);return i||(2===this.#qa.length?{path:{d:this.toSVGPath()}}:null)}startNew(t,e,i,s,n){this.#nl=i,this.#rl=s,this.#mn=n,[t,e]=this.#al(t,e);const r=this.#oa=[NaN,NaN,NaN,NaN,t,e];this.#qa=[t,e];const a=this.#el.at(-1);return a&&(a.line=new Float32Array(a.line),a.points=new Float32Array(a.points)),this.#el.push({line:r,points:this.#qa}),this.#ja.set(r,0),this.#sl=0,this.toSVGPath(),null}getLastElement(){return this.#el.at(-1)}setLastElement(t){return this.#el?(this.#el.push(t),this.#oa=t.line,this.#qa=t.points,this.#sl=0,{path:{d:this.toSVGPath()}}):this.#fo.setLastElement(t)}removeLastElement(){if(!this.#el)return this.#fo.removeLastElement();this.#el.pop(),this.#il="";for(let t=0,e=this.#el.length;t<e;t++){const{line:e,points:i}=this.#el[t];this.#oa=e,this.#qa=i,this.#sl=0,this.toSVGPath()}return{path:{d:this.#il}}}toSVGPath(){const t=yn.svgRound(this.#oa[4]),e=yn.svgRound(this.#oa[5]);if(2===this.#qa.length)return this.#il=`${this.#il} M ${t} ${e} Z`,this.#il;if(this.#qa.length<=6){const i=this.#il.lastIndexOf("M");this.#il=`${this.#il.slice(0,i)} M ${t} ${e}`,this.#sl=6}if(4===this.#qa.length){const t=yn.svgRound(this.#oa[10]),e=yn.svgRound(this.#oa[11]);return this.#il=`${this.#il} L ${t} ${e}`,this.#sl=12,this.#il}const i=[];0===this.#sl&&(i.push(`M ${t} ${e}`),this.#sl=6);for(let s=this.#sl,n=this.#oa.length;s<n;s+=6){const[t,e,n,r,a,o]=this.#oa.slice(s,s+6).map(yn.svgRound);i.push(`C${t} ${e} ${n} ${r} ${a} ${o}`)}return this.#il+=i.join(" "),this.#sl=this.#oa.length,this.#il}getOutlines(t,e,i,s){const n=this.#el.at(-1);return n.line=new Float32Array(n.line),n.points=new Float32Array(n.points),this.#fo.build(this.#el,t,e,i,this.#mn,this.#Va,s),this.#ja=null,this.#oa=null,this.#el=null,this.#il=null,this.#fo}get defaultSVGProperties(){return{root:{viewBox:"0 0 10000 10000"},rootClass:{draw:!0},bbox:[0,0,1,1]}}}class Pn extends yn{#no;#ol=0;#Ba;#el;#nl;#rl;#ll;#mn;#Va;build(t,e,i,s,n,r,a){this.#nl=e,this.#rl=i,this.#ll=s,this.#mn=n,this.#Va=r,this.#Ba=a??0,this.#el=t,this.#hl()}get thickness(){return this.#Va}setLastElement(t){return this.#el.push(t),{path:{d:this.toSVGPath()}}}removeLastElement(){return this.#el.pop(),{path:{d:this.toSVGPath()}}}toSVGPath(){const t=[];for(const{line:e}of this.#el)if(t.push(`M${yn.svgRound(e[4])} ${yn.svgRound(e[5])}`),6!==e.length)if(12===e.length&&isNaN(e[6]))t.push(`L${yn.svgRound(e[10])} ${yn.svgRound(e[11])}`);else for(let i=6,s=e.length;i<s;i+=6){const[s,n,r,a,o,l]=e.subarray(i,i+6).map(yn.svgRound);t.push(`C${s} ${n} ${r} ${a} ${o} ${l}`)}else t.push("Z");return t.join("")}serialize([t,e,i,s],n){const r=[],a=[],[o,l,h,c]=this.#cl();let d,u,p,g,m,f,b,v,y;switch(this.#mn){case 0:y=yn._rescale,d=t,u=e+s,p=i,g=-s,m=t+o*i,f=e+(1-l-c)*s,b=t+(o+h)*i,v=e+(1-l)*s;break;case 90:y=yn._rescaleAndSwap,d=t,u=e,p=i,g=s,m=t+l*i,f=e+o*s,b=t+(l+c)*i,v=e+(o+h)*s;break;case 180:y=yn._rescale,d=t+i,u=e,p=-i,g=s,m=t+(1-o-h)*i,f=e+l*s,b=t+(1-o)*i,v=e+(l+c)*s;break;case 270:y=yn._rescaleAndSwap,d=t+i,u=e+s,p=-i,g=-s,m=t+(1-l-c)*i,f=e+(1-o-h)*s,b=t+(1-l)*i,v=e+(1-o)*s;break}for(const{line:w,points:A}of this.#el)r.push(y(w,d,u,p,g,n?new Array(w.length):null)),a.push(y(A,d,u,p,g,n?new Array(A.length):null));return{lines:r,points:a,rect:[m,f,b,v]}}static deserialize(t,e,i,s,n,{paths:{lines:r,points:a},rotation:o,thickness:l}){const h=[];let c,d,u,p,g;switch(o){case 0:g=yn._rescale,c=-t/i,d=e/s+1,u=1/i,p=-1/s;break;case 90:g=yn._rescaleAndSwap,c=-e/s,d=-t/i,u=1/s,p=1/i;break;case 180:g=yn._rescale,c=t/i+1,d=-e/s,u=-1/i,p=1/s;break;case 270:g=yn._rescaleAndSwap,c=e/s+1,d=t/i+1,u=-1/s,p=-1/i;break}if(!r){r=[];for(const t of a){const e=t.length;if(2===e){r.push(new Float32Array([NaN,NaN,NaN,NaN,t[0],t[1]]));continue}if(4===e){r.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));r.push(i);let[s,n,a,o]=t.subarray(0,4);i.set([NaN,NaN,NaN,NaN,s,n],0);for(let r=4;r<e;r+=2){const e=t[r],l=t[r+1];i.set(yn.createBezierPoints(s,n,a,o,e,l),3*(r-2)),[s,n,a,o]=[a,o,e,l]}}}for(let f=0,b=r.length;f<b;f++)h.push({line:g(r[f].map(t=>t??NaN),c,d,u,p),points:g(a[f].map(t=>t??NaN),c,d,u,p)});const m=new this.prototype.constructor;return m.build(h,i,s,1,o,l,n),m}#dl(t=this.#Va){const e=this.#Ba+t/2*this.#ll;return this.#mn%180===0?[e/this.#nl,e/this.#rl]:[e/this.#rl,e/this.#nl]}#cl(){const[t,e,i,s]=this.#no,[n,r]=this.#dl(0);return[t+n,e+r,i-2*n,s-2*r]}#hl(){const t=this.#no=new Float32Array([1/0,1/0,-1/0,-1/0]);for(const{line:s}of this.#el){if(s.length<=12){for(let e=4,i=s.length;e<i;e+=6)K.pointBoundingBox(s[e],s[e+1],t);continue}let e=s[4],i=s[5];for(let n=6,r=s.length;n<r;n+=6){const[r,a,o,l,h,c]=s.subarray(n,n+6);K.bezierBoundingBox(e,i,r,a,o,l,h,c,t),e=h,i=c}}const[e,i]=this.#dl();t[0]=nt(t[0]-e,0,1),t[1]=nt(t[1]-i,0,1),t[2]=nt(t[2]+e,0,1),t[3]=nt(t[3]+i,0,1),t[2]-=t[0],t[3]-=t[1]}get box(){return this.#no}updateProperty(t,e){return"stroke-width"===t?this.#Ro(e):null}#Ro(t){const[e,i]=this.#dl();this.#Va=t;const[s,n]=this.#dl(),[r,a]=[s-e,n-i],o=this.#no;return o[0]-=r,o[1]-=a,o[2]+=2*r,o[3]+=2*a,o}updateParentDimensions([t,e],i){const[s,n]=this.#dl();this.#nl=t,this.#rl=e,this.#ll=i;const[r,a]=this.#dl(),o=r-s,l=a-n,h=this.#no;return h[0]-=o,h[1]-=l,h[2]+=2*o,h[3]+=2*l,h}updateRotation(t){return this.#ol=t,{path:{transform:this.rotationTransform}}}get viewBox(){return this.#no.map(yn.svgRound).join(" ")}get defaultProperties(){const[t,e]=this.#no;return{root:{viewBox:this.viewBox},path:{"transform-origin":`${yn.svgRound(t)} ${yn.svgRound(e)}`}}}get rotationTransform(){const[,,t,e]=this.#no;let i=0,s=0,n=0,r=0,a=0,o=0;switch(this.#ol){case 90:s=e/t,n=-t/e,a=t;break;case 180:i=-1,r=-1,a=t,o=e;break;case 270:s=-e/t,n=t/e,o=e;break;default:return""}return`matrix(${i} ${s} ${n} ${r} ${yn.svgRound(a)} ${yn.svgRound(o)})`}getPathResizingSVGProperties([t,e,i,s]){const[n,r]=this.#dl(),[a,o,l,h]=this.#no;if(Math.abs(l-n)<=yn.PRECISION||Math.abs(h-r)<=yn.PRECISION){const n=t+i/2-(a+l/2),r=e+s/2-(o+h/2);return{path:{"transform-origin":`${yn.svgRound(t)} ${yn.svgRound(e)}`,transform:`${this.rotationTransform} translate(${n} ${r})`}}}const c=(i-2*n)/(l-2*n),d=(s-2*r)/(h-2*r),u=l/i,p=h/s;return{path:{"transform-origin":`${yn.svgRound(a)} ${yn.svgRound(o)}`,transform:`${this.rotationTransform} scale(${u} ${p}) translate(${yn.svgRound(n)} ${yn.svgRound(r)}) scale(${c} ${d}) translate(${yn.svgRound(-n)} ${yn.svgRound(-r)})`}}}getPathResizedSVGProperties([t,e,i,s]){const[n,r]=this.#dl(),a=this.#no,[o,l,h,c]=a;if(a[0]=t,a[1]=e,a[2]=i,a[3]=s,Math.abs(h-n)<=yn.PRECISION||Math.abs(c-r)<=yn.PRECISION){const n=t+i/2-(o+h/2),r=e+s/2-(l+c/2);for(const{line:t,points:e}of this.#el)yn._translate(t,n,r,t),yn._translate(e,n,r,e);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${yn.svgRound(t)} ${yn.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}const d=(i-2*n)/(h-2*n),u=(s-2*r)/(c-2*r),p=-d*(o+n)+t+n,g=-u*(l+r)+e+r;if(1!==d||1!==u||0!==p||0!==g)for(const{line:m,points:f}of this.#el)yn._rescale(m,p,g,d,u,m),yn._rescale(f,p,g,d,u,f);return{root:{viewBox:this.viewBox},path:{"transform-origin":`${yn.svgRound(t)} ${yn.svgRound(e)}`,transform:this.rotationTransform||null,d:this.toSVGPath()}}}getPathTranslatedSVGProperties([t,e],i){const[s,n]=i,r=this.#no,a=t-r[0],o=e-r[1];if(this.#nl===s&&this.#rl===n)for(const{line:l,points:h}of this.#el)yn._translate(l,a,o,l),yn._translate(h,a,o,h);else{const t=this.#nl/s,e=this.#rl/n;this.#nl=s,this.#rl=n;for(const{line:i,points:s}of this.#el)yn._rescale(i,a,o,t,e,i),yn._rescale(s,a,o,t,e,s);r[2]*=t,r[3]*=e}return r[0]=t,r[1]=e,{root:{viewBox:this.viewBox},path:{d:this.toSVGPath(),"transform-origin":`${yn.svgRound(t)} ${yn.svgRound(e)}`}}}get defaultSVGProperties(){const t=this.#no;return{root:{viewBox:this.viewBox},rootClass:{draw:!0},path:{d:this.toSVGPath(),"transform-origin":`${yn.svgRound(t[0])} ${yn.svgRound(t[1])}`,transform:this.rotationTransform||null},bbox:t}}}class In extends Tn{constructor(t){super(),this._viewParameters=t,super.updateProperties({fill:"none",stroke:ie._defaultLineColor,"stroke-opacity":1,"stroke-width":1,"stroke-linecap":"round","stroke-linejoin":"round","stroke-miterlimit":10})}updateSVGProperty(t,e){"stroke-width"===t&&(e??=this["stroke-width"],e*=this._viewParameters.realScale),super.updateSVGProperty(t,e)}clone(){const t=new In(this._viewParameters);return t.updateAll(this),t}}class kn extends Mn{static _type="ink";static _editorType=p.INK;static _defaultDrawingOptions=null;constructor(t){super({...t,name:"inkEditor"}),this._willKeepAspectRatio=!0,this.defaultL10nId="pdfjs-editor-ink-editor"}static initialize(t,e){ie.initialize(t,e),this._defaultDrawingOptions=new In(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!0}static get typesMap(){return F(this,"typesMap",new Map([[g.INK_THICKNESS,"stroke-width"],[g.INK_COLOR,"stroke"],[g.INK_OPACITY,"stroke-opacity"]]))}static createDrawerInstance(t,e,i,s,n){return new Dn(t,e,i,s,n,this._defaultDrawingOptions["stroke-width"])}static deserializeDraw(t,e,i,s,n,r){return Pn.deserialize(t,e,i,s,n,r)}static async deserialize(t,e,i){let s=null;if(t instanceof hn){const{data:{inkLists:e,rect:i,rotation:n,id:r,color:a,opacity:o,borderStyle:{rawWidth:l},popupRef:h,richText:c,contentsObj:d,creationDate:u,modificationDate:g},parent:{page:{pageNumber:m}}}=t;s=t={annotationType:p.INK,color:Array.from(a),thickness:l,opacity:o,paths:{points:e},boxes:null,pageIndex:m-1,rect:i.slice(0),rotation:n,annotationElementId:r,id:r,deleted:!1,popupRef:h,richText:c,comment:d?.str||null,creationDate:u,modificationDate:g}}const n=await super.deserialize(t,e,i);return n._initialData=s,t.comment&&n.setCommentData(t),n}get toolbarButtons(){return this._colorPicker||=new ks(this),[["colorPicker",this._colorPicker]]}get colorType(){return g.INK_COLOR}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;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=kn.getDefaultDrawingOptions({stroke:K.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:s,"stroke-opacity":n,"stroke-width":r}}=this,a=Object.assign(super.serialize(t),{color:ie._colorManager.convert(s),opacity:n,thickness:r,paths:{lines:e,points:i}});return this.addComment(a),t?(a.isCopy=!0,a):this.annotationElementId&&!this.#La(a)?null:(a.id=this.annotationElementId,a)}#La(t){const{color:e,thickness:i,opacity:s,pageIndex:n}=this._initialData;return this.hasEditedComment||this._hasBeenMoved||this._hasBeenResized||t.color.some((t,i)=>t!==e[i])||t.thickness!==i||t.opacity!==s||t.pageIndex!==n}renderAnnotationElement(t){if(this.deleted)return t.hide(),null;const{points:e,rect:i}=this.serializeDraw(!1);return t.updateEdited({rect:i,thickness:this._drawingOptions["stroke-width"],points:e,popup:this.comment}),null}}class Rn extends Pn{toSVGPath(){let t=super.toSVGPath();return t.endsWith("Z")||(t+="Z"),t}}const Ln=8,Fn=3;class On{static#ul={maxDim:512,sigmaSFactor:.02,sigmaR:25,kernelSize:16};static#pl(t,e,i,s){return i-=t,s-=e,0===i?s>0?0:4:1===i?s+6:2-s}static#gl=new Int32Array([0,1,-1,1,-1,0,-1,-1,0,-1,1,-1,1,0,1,1]);static#ml(t,e,i,s,n,r,a){const o=this.#pl(i,s,n,r);for(let l=0;l<8;l++){const n=(-l+o-a+16)%8,r=this.#gl[2*n],h=this.#gl[2*n+1];if(0!==t[(i+r)*e+(s+h)])return n}return-1}static#fl(t,e,i,s,n,r,a){const o=this.#pl(i,s,n,r);for(let l=0;l<8;l++){const n=(l+o+a+16)%8,r=this.#gl[2*n],h=this.#gl[2*n+1];if(0!==t[(i+r)*e+(s+h)])return n}return-1}static#bl(t,e,i,s){const n=t.length,r=new Int32Array(n);for(let h=0;h<n;h++)r[h]=t[h]<=s?1:0;for(let h=1;h<i-1;h++)r[h*e]=r[h*e+e-1]=0;for(let h=0;h<e;h++)r[h]=r[e*i-1-h]=0;let a,o=1;const l=[];for(let h=1;h<i-1;h++){a=1;for(let t=1;t<e-1;t++){const i=h*e+t,s=r[i];if(0===s)continue;let n=h,c=t;if(1===s&&0===r[i-1])o+=1,c-=1;else{if(!(s>=1&&0===r[i+1])){1!==s&&(a=Math.abs(s));continue}o+=1,c+=1,s>1&&(a=s)}const d=[t,h],u=c===t+1,p={isHole:u,points:d,id:o,parent:0};let g;l.push(p);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.#ml(r,e,h,t,n,c,0);if(-1===m){r[i]=-o,1!==r[i]&&(a=Math.abs(r[i]));continue}let f=this.#gl[2*m],b=this.#gl[2*m+1];const v=h+f,y=t+b;n=v,c=y;let w=h,A=t;while(1){const s=this.#fl(r,e,w,A,n,c,1);f=this.#gl[2*s],b=this.#gl[2*s+1];const l=w+f,u=A+b;d.push(u,l);const p=w*e+A;if(0===r[p+1]?r[p]=-o:1===r[p]&&(r[p]=o),l===h&&u===t&&w===v&&A===y){1!==r[i]&&(a=Math.abs(r[i]));break}n=w,c=A,w=l,A=u}}}return l}static#vl(t,e,i,s){if(i-e<=4){for(let n=e;n<i-2;n+=2)s.push(t[n],t[n+1]);return}const n=t[e],r=t[e+1],a=t[i-4]-n,o=t[i-3]-r,l=Math.hypot(a,o),h=a/l,c=o/l,d=h*r-c*n,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)),v=p*(1-b+b**2),y=Math.max(Math.atan(Math.abs(f+m)*v),Math.atan(Math.abs(f-m)*v));let w=0,A=e;for(let x=e+2;x<i-2;x+=2){const e=Math.abs(d-h*t[x+1]+c*t[x]);e>w&&(A=x,w=e)}w>(l*y)**2?(this.#vl(t,e,A+2,s),this.#vl(t,A,i,s)):s.push(n,r)}static#yl(t){const e=[],i=t.length;return this.#vl(t,0,i,e),e.push(t[i-2],t[i-1]),e.length<=4?null:e}static#wl(t,e,i,s,n,r){const a=new Float32Array(r**2),o=-2*s**2,l=r>>1;for(let g=0;g<r;g++){const t=(g-l)**2;for(let e=0;e<r;e++)a[g*r+e]=Math.exp((t+(e-l)**2)/o)}const h=new Float32Array(256),c=-2*n**2;for(let g=0;g<256;g++)h[g]=Math.exp(g**2/c);const d=t.length,u=new Uint8Array(d),p=new Uint32Array(256);for(let g=0;g<i;g++)for(let s=0;s<e;s++){const n=g*e+s,o=t[n];let c=0,d=0;for(let u=0;u<r;u++){const n=g+u-l;if(!(n<0||n>=i))for(let i=0;i<r;i++){const p=s+i-l;if(p<0||p>=e)continue;const g=t[n*e+p],m=a[u*r+i]*h[Math.abs(g-o)];c+=g*m,d+=m}}const m=u[n]=Math.round(c/d);p[m]++}return[u,p]}static#Al(t){const e=new Uint32Array(256);for(const i of t)e[i]++;return e}static#xl(t){const e=t.length,i=new Uint8ClampedArray(e>>2);let s=-1/0,n=1/0;for(let a=0,o=i.length;a<o;a++){const e=i[a]=t[a<<2];s=Math.max(s,e),n=Math.min(n,e)}const r=255/(s-n);for(let a=0,o=i.length;a<o;a++)i[a]=(i[a]-n)*r;return i}static#_l(t){let e,i=-1/0,s=-1/0;const n=t.findIndex(t=>0!==t);let r=n,a=n;for(e=n;e<256;e++){const n=t[e];n>i&&(e-r>s&&(s=e-r,a=e-1),i=n,r=e)}for(e=a-1;e>=0;e--)if(t[e]>t[e+1])break;return e}static#Sl(t){const e=t,{width:i,height:s}=t,{maxDim:n}=this.#ul;let r=i,a=s;if(i>n||s>n){let o=i,l=s,h=Math.log2(Math.max(i,s)/n);const c=Math.floor(h);h=h===c?c-1:c;for(let i=0;i<h;i++){r=Math.ceil(o/2),a=Math.ceil(l/2);const i=new OffscreenCanvas(r,a),s=i.getContext("2d");s.drawImage(t,0,0,o,l,0,0,r,a),o=r,l=a,t!==e&&t.close(),t=i.transferToImageBitmap()}const d=Math.min(n/r,n/a);r=Math.round(r*d),a=Math.round(a*d)}const o=new OffscreenCanvas(r,a),l=o.getContext("2d",{willReadFrequently:!0});l.fillStyle="white",l.fillRect(0,0,r,a),l.filter="grayscale(1)",l.drawImage(t,0,0,t.width,t.height,0,0,r,a);const h=l.getImageData(0,0,r,a).data,c=this.#xl(h);return[c,r,a]}static extractContoursFromText(t,{fontFamily:e,fontStyle:i,fontWeight:s},n,r,a,o){let l=new OffscreenCanvas(1,1),h=l.getContext("2d",{alpha:!1});const c=200,d=h.font=`${i} ${s} ${c}px ${e}`,{actualBoundingBoxLeft:u,actualBoundingBoxRight:p,actualBoundingBoxAscent:g,actualBoundingBoxDescent:m,fontBoundingBoxAscent:f,fontBoundingBoxDescent:b,width:v}=h.measureText(t),y=1.5,w=Math.ceil(Math.max(Math.abs(u)+Math.abs(p)||0,v)*y),A=Math.ceil(Math.max(Math.abs(g)+Math.abs(m)||c,Math.abs(f)+Math.abs(b)||c)*y);l=new OffscreenCanvas(w,A),h=l.getContext("2d",{alpha:!0,willReadFrequently:!0}),h.font=d,h.filter="grayscale(1)",h.fillStyle="white",h.fillRect(0,0,w,A),h.fillStyle="black",h.fillText(t,w*(y-1)/2,A*(3-y)/2);const x=this.#xl(h.getImageData(0,0,w,A).data),_=this.#Al(x),S=this.#_l(_),E=this.#bl(x,w,A,S);return this.processDrawnLines({lines:{curves:E,width:w,height:A},pageWidth:n,pageHeight:r,rotation:a,innerMargin:o,mustSmooth:!0,areContours:!0})}static process(t,e,i,s,n){const[r,a,o]=this.#Sl(t),[l,h]=this.#wl(r,a,o,Math.hypot(a,o)*this.#ul.sigmaSFactor,this.#ul.sigmaR,this.#ul.kernelSize),c=this.#_l(h),d=this.#bl(l,a,o,c);return this.processDrawnLines({lines:{curves:d,width:a,height:o},pageWidth:e,pageHeight:i,rotation:s,innerMargin:n,mustSmooth:!0,areContours:!0})}static processDrawnLines({lines:t,pageWidth:e,pageHeight:i,rotation:s,innerMargin:n,mustSmooth:r,areContours:a}){s%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:b}of o){const t=r?this.#yl(b):b;if(!t)continue;m.push(t);const e=t.length,i=new Float32Array(e),s=new Float32Array(3*(2===e?2:e-2));if(d.push({line:s,points:i}),2===e){i[0]=t[0]*p,i[1]=t[1]*g,s.set([NaN,NaN,NaN,NaN,i[0],i[1]],0);continue}let[n,a,o,l]=t;n*=p,a*=g,o*=p,l*=g,i.set([n,a,o,l],0),s.set([NaN,NaN,NaN,NaN,n,a],0);for(let r=4;r<e;r+=2){const e=i[r]=t[r]*p,h=i[r+1]=t[r+1]*g;s.set(yn.createBezierPoints(n,a,o,l,e,h),3*(r-2)),[n,a,o,l]=[o,l,e,h]}}if(0===d.length)return null;const f=a?new Rn:new Pn;return f.build(d,e,i,1,s,a?0:c,n),{outline:f,newCurves:m,areContours:a,thickness:c,width:l,height:h}}static async compressSignature({outlines:t,areContours:e,thickness:i,width:s,height:n}){let r,a=1/0,o=-1/0,l=0;for(const v of t){l+=v.length;for(let t=2,e=v.length;t<e;t++){const e=v[t]-v[t-2];a=Math.min(a,e),o=Math.max(o,e)}}r=a>=-128&&o<=127?Int8Array:a>=-32768&&o<=32767?Int16Array:Int32Array;const h=t.length,c=Ln+Fn*h,d=new Uint32Array(c);let u=0;d[u++]=c*Uint32Array.BYTES_PER_ELEMENT+(l-2*h)*r.BYTES_PER_ELEMENT,d[u++]=0,d[u++]=s,d[u++]=n,d[u++]=e?0:1,d[u++]=Math.max(0,Math.floor(i??0)),d[u++]=h,d[u++]=r.BYTES_PER_ELEMENT;for(const v of t)d[u++]=v.length-2,d[u++]=v[0],d[u++]=v[1];const p=new CompressionStream("deflate-raw"),g=p.writable.getWriter();await g.ready,g.write(d);const m=r.prototype.constructor;for(const v of t){const t=new m(v.length-2);for(let e=2,i=v.length;e<i;e++)t[e-2]=v[e]-v[e-2];g.write(t)}g.close();const f=await new Response(p.readable).arrayBuffer(),b=new Uint8Array(f);return rt(b)}static async decompressSignature(t){try{const e=at(t),{readable:i,writable:s}=new DecompressionStream("deflate-raw"),n=s.getWriter();await n.ready,n.write(e).then(async()=>{await n.ready,await n.close()}).catch(()=>{});let r=null,a=0;for await(const t of i)r||=new Uint8Array(new Uint32Array(t.buffer,0,4)[0]),r.set(t,a),a+=t.length;const o=new Uint32Array(r.buffer,0,r.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=(Ln+Fn*p)*Uint32Array.BYTES_PER_ELEMENT;let b;switch(g){case Int8Array.BYTES_PER_ELEMENT:b=new Int8Array(r.buffer,f);break;case Int16Array.BYTES_PER_ELEMENT:b=new Int16Array(r.buffer,f);break;case Int32Array.BYTES_PER_ELEMENT:b=new Int32Array(r.buffer,f);break}a=0;for(let t=0;t<p;t++){const e=o[Fn*t+Ln],i=new Float32Array(e+2);m.push(i);for(let s=0;s<Fn-1;s++)i[s]=o[Fn*t+Ln+s+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(e){return D(`decompressSignature: ${e}`),null}}}class Bn extends Tn{constructor(){super(),super.updateProperties({fill:ie._defaultLineColor,"stroke-width":0})}clone(){const t=new Bn;return t.updateAll(this),t}}class Nn extends In{constructor(t){super(t),super.updateProperties({stroke:ie._defaultLineColor,"stroke-width":1})}clone(){const t=new Nn(this._viewParameters);return t.updateAll(this),t}}class Un extends Mn{#El=!1;#Cl=null;#Tl=null;#Ml=null;static _type="signature";static _editorType=p.SIGNATURE;static _defaultDrawingOptions=null;constructor(t){super({...t,mustBeCommitted:!0,name:"signatureEditor"}),this._willKeepAspectRatio=!0,this.#Tl=t.signatureData||null,this.#Cl=null,this.defaultL10nId="pdfjs-editor-signature-editor1"}static initialize(t,e){ie.initialize(t,e),this._defaultDrawingOptions=new Bn,this._defaultDrawnSignatureOptions=new Nn(e.viewParameters)}static getDefaultDrawingOptions(t){const e=this._defaultDrawingOptions.clone();return e.updateProperties(t),e}static get supportMultipleDrawings(){return!1}static get typesMap(){return F(this,"typesMap",new Map)}static get isDrawer(){return!1}get telemetryFinalData(){return{type:"signature",hasDescription:!!this.#Cl}}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(),null===this._drawId)if(this.#Tl){const{lines:t,mustSmooth:e,areContours:i,description:s,uuid:n,heightInPage:r}=this.#Tl,{rawDims:{pageWidth:a,pageHeight:o},rotation:l}=this.parent.viewport,h=On.processDrawnLines({lines:t,pageWidth:a,pageHeight:o,rotation:l,innerMargin:Un._INNER_MARGIN,mustSmooth:e,areContours:i});this.addSignature(h,r,s,n)}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.#Cl||""}));return i&&(this._isCopy=!0,this._moveAfterPaste(t,e)),this.div}setUuid(t){this.#Ml=t,this.addEditToolbar()}getUuid(){return this.#Ml}get description(){return this.#Cl}set description(t){this.#Cl=t,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:s,height:n}=this.#Tl,r=Math.max(s,n),a=On.processDrawnLines({lines:{curves:t.map(t=>({points:t})),thickness:i,width:s,height:n},pageWidth:r,pageHeight:r,rotation:0,innerMargin:0,mustSmooth:!1,areContours:e});return{areContours:e,outline:a.outline}}get toolbarButtons(){return this._uiManager.signatureManager?[["editSignature",this._uiManager.signatureManager]]:super.toolbarButtons}addSignature(t,e,i,s){const{x:n,y:r}=this,{outline:a}=this.#Tl=t;let o;this.#El=a instanceof Rn,this.description=i,this.#El?o=Un.getDefaultDrawingOptions():(o=Un._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,this.width>=1&&(h*=.9/this.width,this.width=.9),this.height=h,this.setDims(),this.x=n,this.y=r,this.center(),this._onResized(),this.onScaleChanging(),this.rotate(),this._uiManager.addToAnnotationStorage(this),this.setUuid(s),this._reportTelemetry({action:"pdfjs.signature.inserted",data:{hasBeenSaved:!!s,hasDescription:!!i}}),this.div.hidden=!1}getFromImage(t){const{rawDims:{pageWidth:e,pageHeight:i},rotation:s}=this.parent.viewport;return On.process(t,e,i,s,Un._INNER_MARGIN)}getFromText(t,e){const{rawDims:{pageWidth:i,pageHeight:s},rotation:n}=this.parent.viewport;return On.extractContoursFromText(t,e,i,s,n,Un._INNER_MARGIN)}getDrawnSignature(t){const{rawDims:{pageWidth:e,pageHeight:i},rotation:s}=this.parent.viewport;return On.processDrawnLines({lines:t,pageWidth:e,pageHeight:i,rotation:s,innerMargin:Un._INNER_MARGIN,mustSmooth:!1,areContours:!1})}createDrawingOptions({areContours:t,thickness:e}){t?this._drawingOptions=Un.getDefaultDrawingOptions():(this._drawingOptions=Un._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":s}}=this,n=Object.assign(super.serialize(t),{isSignature:!0,areContours:this.#El,color:[0,0,0],thickness:this.#El?0:s});return this.addComment(n),t?(n.paths={lines:e,points:i},n.uuid=this.#Ml,n.isCopy=!0):n.lines=e,this.#Cl&&(n.accessibilityData={type:"Figure",alt:this.#Cl}),n}static deserializeDraw(t,e,i,s,n,r){return r.areContours?Rn.deserialize(t,e,i,s,n,r):Pn.deserialize(t,e,i,s,n,r)}static async deserialize(t,e,i){const s=await super.deserialize(t,e,i);return s.#El=t.areContours,s.description=t.accessibilityData?.alt||"",s.#Ml=t.uuid,s}}class jn extends ie{#Dl=null;#Pl=null;#Il=null;#kl=null;#Rl=null;#Ll="";#Fl=null;#Ol=!1;#Bl=null;#Nl=!1;#Ul=!1;static _type="stamp";static _editorType=p.STAMP;constructor(t){super({...t,name:"stampEditor"}),this.#kl=t.bitmapUrl,this.#Rl=t.bitmapFile,this.defaultL10nId="pdfjs-editor-stamp-editor"}static initialize(t,e){ie.initialize(t,e)}static isHandlingMimeForPasting(t){return It.includes(t)}static paste(t,e){e.pasteEditor({mode:p.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}}#jl(t,e=!1){t?(this.#Dl=t.bitmap,e||(this.#Pl=t.id,this.#Nl=t.isSvg),t.file&&(this.#Ll=t.file.name),this.#zl()):this.remove()}#Hl(){if(this.#Il=null,this._uiManager.enableWaiting(!1),this.#Fl)if(this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#Dl)this.addEditToolbar().then(()=>{this._editToolbar.hide(),this._uiManager.editAltText(this,!0)});else{if(!this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&this.#Dl){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:s,width:n,height:r}=t||this.copyCanvas(null,null,!0).imageData,a=await i.guess({name:"altText",request:{data:s,width:n,height:r,channels:s.length/(n*r)}});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;return await this.setGuessedAltText(o),e&&!this.hasAltTextData()&&(this.altTextData={alt:o,decorative:!1}),o}#$l(){if(this.#Pl)return this._uiManager.enableWaiting(!0),void this._uiManager.imageManager.getFromId(this.#Pl).then(t=>this.#jl(t,!0)).finally(()=>this.#Hl());if(this.#kl){const t=this.#kl;return this.#kl=null,this._uiManager.enableWaiting(!0),void(this.#Il=this._uiManager.imageManager.getFromUrl(t).then(t=>this.#jl(t)).finally(()=>this.#Hl()))}if(this.#Rl){const t=this.#Rl;return this.#Rl=null,this._uiManager.enableWaiting(!0),void(this.#Il=this._uiManager.imageManager.getFromFile(t).then(t=>this.#jl(t)).finally(()=>this.#Hl()))}const t=document.createElement("input");t.type="file",t.accept=It.join(",");const e=this._uiManager._signal;this.#Il=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.#jl(e)}else this.remove();i()},{signal:e}),t.addEventListener("cancel",()=>{this.remove(),i()},{signal:e})}).finally(()=>this.#Hl()),t.click()}remove(){this.#Pl&&(this.#Dl=null,this._uiManager.imageManager.deleteId(this.#Pl),this.#Fl?.remove(),this.#Fl=null,this.#Bl&&(clearTimeout(this.#Bl),this.#Bl=null)),super.remove()}rebuild(){this.parent?(super.rebuild(),null!==this.div&&(this.#Pl&&null===this.#Fl&&this.#$l(),this.isAttachedToDOM||this.parent.add(this))):this.#Pl&&this.#$l()}onceAdded(t){this._isDraggable=!0,t&&this.div.focus()}isEmpty(){return!(this.#Il||this.#Dl||this.#kl||this.#Rl||this.#Pl||this.#Ol)}get toolbarButtons(){return[["altText",this.createAltText()]]}get isResizable(){return!0}render(){if(this.div)return this.div;let t,e;return this._isCopy&&(t=this.x,e=this.y),super.render(),this.div.hidden=!0,this.createAltText(),this.#Ol||(this.#Dl?this.#zl():this.#$l()),this._isCopy&&this._moveAfterPaste(t,e),this._uiManager.addShouldRescale(this),this.div}setCanvas(t,e){const{id:i,bitmap:s}=this._uiManager.imageManager.getFromCanvas(t,e);e.remove(),i&&this._uiManager.imageManager.isValidId(i)&&(this.#Pl=i,s&&(this.#Dl=s),this.#Ol=!1,this.#zl())}_onResized(){this.onScaleChanging()}onScaleChanging(){if(!this.parent)return;null!==this.#Bl&&clearTimeout(this.#Bl);const t=200;this.#Bl=setTimeout(()=>{this.#Bl=null,this.#Gl()},t)}#zl(){const{div:t}=this;let{width:e,height:i}=this.#Dl;const[s,n]=this.pageDimensions,r=.75;if(this.width)e=this.width*s,i=this.height*n;else if(e>r*s||i>r*n){const t=Math.min(r*s/e,r*n/i);e*=t,i*=t}this._uiManager.enableWaiting(!1);const a=this.#Fl=document.createElement("canvas");a.setAttribute("role","img"),this.addContainer(a),this.width=e/s,this.height=i/n,this.setDims(),this._initialOptions?.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,this._uiManager.useNewAltTextWhenAddingImage&&this._uiManager.useNewAltTextFlow&&!this.annotationElementId||(t.hidden=!1),this.#Gl(),this.#Ul||(this.parent.addUndoableEditor(this),this.#Ul=!0),this._reportTelemetry({action:"inserted_image"}),this.#Ll&&this.div.setAttribute("aria-description",this.#Ll),this.annotationElementId||this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert")}copyCanvas(t,e,i=!1){t||(t=224);const{width:s,height:n}=this.#Dl,r=new Pt;let a=this.#Dl,o=s,l=n,h=null;if(e){if(s>e||n>e){const t=Math.min(e/s,e/n);o=Math.floor(s*t),l=Math.floor(n*t)}h=document.createElement("canvas");const t=h.width=Math.ceil(o*r.sx),i=h.height=Math.ceil(l*r.sy);this.#Nl||(a=this.#Wl(t,i));const c=h.getContext("2d");c.filter=this._uiManager.hcmFilter;let d="white",u="#cfcfd8";"none"!==this._uiManager.hcmFilter?u="black":kt.isDarkMode&&(d="#8f8f9d",u="#42414d");const p=15,g=p*r.sx,m=p*r.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(r.symmetric&&a.width<t&&a.height<t)e=a.width,i=a.height;else if(a=this.#Dl,s>t||n>t){const r=Math.min(t/s,t/n);e=Math.floor(s*r),i=Math.floor(n*r),this.#Nl||(a=this.#Wl(e,i))}const o=new OffscreenCanvas(e,i),l=o.getContext("2d",{willReadFrequently:!0});l.drawImage(a,0,0,a.width,a.height,0,0,e,i),c={width:e,height:i,data:l.getImageData(0,0,e,i).data}}return{canvas:h,width:o,height:l,imageData:c}}#Wl(t,e){const{width:i,height:s}=this.#Dl;let n=i,r=s,a=this.#Dl;while(n>2*t||r>2*e){const i=n,s=r;n>2*t&&(n=n>=16384?Math.floor(n/2)-1:Math.ceil(n/2)),r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2));const o=new OffscreenCanvas(n,r),l=o.getContext("2d");l.drawImage(a,0,0,i,s,0,0,n,r),a=o.transferToImageBitmap()}return a}#Gl(){const[t,e]=this.parentDimensions,{width:i,height:s}=this,n=new Pt,r=Math.ceil(i*t*n.sx),a=Math.ceil(s*e*n.sy),o=this.#Fl;if(!o||o.width===r&&o.height===a)return;o.width=r,o.height=a;const l=this.#Nl?this.#Dl:this.#Wl(r,a),h=o.getContext("2d");h.filter=this._uiManager.hcmFilter,h.drawImage(l,0,0,l.width,l.height,0,0,r,a)}#Vl(t){if(t){if(this.#Nl){const t=this._uiManager.imageManager.getSvgUrl(this.#Pl);if(t)return t}const t=document.createElement("canvas");({width:t.width,height:t.height}=this.#Dl);const e=t.getContext("2d");return e.drawImage(this.#Dl,0,0),t.toDataURL()}if(this.#Nl){const[t,e]=this.pageDimensions,i=Math.round(this.width*t*ct.PDF_TO_CSS_UNITS),s=Math.round(this.height*e*ct.PDF_TO_CSS_UNITS),n=new OffscreenCanvas(i,s),r=n.getContext("2d");return r.drawImage(this.#Dl,0,0,this.#Dl.width,this.#Dl.height,0,0,i,s),n.transferToImageBitmap()}return structuredClone(this.#Dl)}static async deserialize(t,e,i){let s=null,n=!1;if(t instanceof gn){const{data:{rect:r,rotation:a,id:o,structParent:l,popupRef:h,richText:c,contentsObj:d,creationDate:u,modificationDate:g},container:m,parent:{page:{pageNumber:f}},canvas:b}=t;let v,y;b?(delete t.canvas,({id:v,bitmap:y}=i.imageManager.getFromCanvas(m.id,b)),b.remove()):(n=!0,t._hasNoCanvas=!0);const w=(await e._structTree.getAriaAttributes(`${it}${o}`))?.get("aria-label")||"";s=t={annotationType:p.STAMP,bitmapId:v,bitmap:y,pageIndex:f-1,rect:r.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:g}}const r=await super.deserialize(t,e,i),{rect:a,bitmap:o,bitmapUrl:l,bitmapId:h,isSvg:c,accessibilityData:d}=t;n?(i.addMissingCanvas(t.id,r),r.#Ol=!0):h&&i.imageManager.isValidId(h)?(r.#Pl=h,o&&(r.#Dl=o)):r.#kl=l,r.#Nl=c;const[u,g]=r.pageDimensions;return r.width=(a[2]-a[0])/u,r.height=(a[3]-a[1])/g,d&&(r.altTextData=d),r._initialData=s,t.comment&&r.setCommentData(t),r.#Ul=!!s,r}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.#Pl,isSvg:this.#Nl});if(this.addComment(i),t)return i.bitmapUrl=this.#Vl(!0),i.accessibilityData=this.serializeAltText(!0),i.isCopy=!0,i;const{decorative:s,altText:n}=this.serializeAltText(!1);if(!s&&n&&(i.accessibilityData={type:"Figure",alt:n}),this.annotationElementId){const t=this.#La(i);return t.isSame?null:(t.isSameAltText?delete i.accessibilityData:i.accessibilityData.structParent=this._initialData.structParent??-1,i.id=this.annotationElementId,delete i.bitmapId,i)}if(null===e)return i;e.stamps||=new Map;const r=this.#Nl?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(e.stamps.has(this.#Pl)){if(this.#Nl){const t=e.stamps.get(this.#Pl);r>t.area&&(t.area=r,t.serialized.bitmap.close(),t.serialized.bitmap=this.#Vl(!1))}}else e.stamps.set(this.#Pl,{area:r,serialized:i}),i.bitmap=this.#Vl(!1);return i}#La(t){const{pageIndex:e,accessibilityData:{altText:i}}=this._initialData,s=t.pageIndex===e,n=(t.accessibilityData?.alt||"")===i;return{isSame:!this.hasEditedComment&&!this._hasBeenMoved&&!this._hasBeenResized&&s&&n,isSameAltText:n}}renderAnnotationElement(t){return this.deleted?(t.hide(),null):(t.updateEdited({rect:this.getPDFRect(),popup:this.comment}),null)}}class zn{#fa;#ql=!1;#Xl=null;#Yl=null;#Kl=null;#Ql=new Map;#Zl=!1;#Jl=!1;#th=!1;#eh=null;#ih=null;#sh=null;#nh=null;#rh=null;#ah=-1;#b;static _initialized=!1;static#Y=new Map([vn,kn,jn,Cn,Un].map(t=>[t._editorType,t]));constructor({uiManager:t,pageIndex:e,div:i,structTreeLayer:s,accessibilityManager:n,annotationLayer:r,drawLayer:a,textLayer:o,viewport:l,l10n:h}){const c=[...zn.#Y.values()];if(!zn._initialized){zn._initialized=!0;for(const e of c)e.initialize(h,t)}t.registerEditorTypes(c),this.#b=t,this.pageIndex=e,this.div=i,this.#fa=n,this.#Xl=r,this.viewport=l,this.#sh=o,this.drawLayer=a,this._structTree=s,this.#b.addLayer(this)}get isEmpty(){return 0===this.#Ql.size}get isInvisible(){return this.isEmpty&&this.#b.getMode()===p.NONE}updateToolbar(t){this.#b.updateToolbar(t)}updateMode(t=this.#b.getMode()){switch(this.#oh(),t){case p.NONE:return this.div.classList.toggle("nonEditing",!0),this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),void this.disableClick();case p.INK:this.disableTextSelection(),this.togglePointerEvents(!0),this.enableClick();break;case p.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;if(e.toggle("nonEditing",!1),t===p.POPUP)e.toggle("commentEditing",!0);else{e.toggle("commentEditing",!1);for(const i of zn.#Y.values())e.toggle(`${i._type}Editing`,t===i._editorType)}this.div.hidden=!1}hasTextLayer(t){return t===this.#sh?.div}setEditingState(t){this.#b.setEditingState(t)}addCommands(t){this.#b.addCommands(t)}cleanUndoStack(t){this.#b.cleanUndoStack(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){this.#Xl?.togglePointerEvents(t)}get#lh(){return 0!==this.#Ql.size?this.#Ql.values():this.#b.getEditors(this.pageIndex)}async enable(){this.#th=!0,this.div.tabIndex=0,this.togglePointerEvents(!0),this.div.classList.toggle("nonEditing",!1),this.#rh?.abort(),this.#rh=null;const t=new Set;for(const i of this.#lh)i.enableEditing(),i.show(!0),i.annotationElementId&&(this.#b.removeChangedExistingAnnotation(i),t.add(i.annotationElementId));const e=this.#Xl;if(e)for(const i of e.getEditableAnnotations()){if(i.hide(),this.#b.isDeletedAnnotationElement(i.data.id))continue;if(t.has(i.data.id))continue;const e=await this.deserialize(i);e&&(this.addOrRebuild(e),e.enableEditing())}this.#th=!1,this.#b._eventBus.dispatch("editorsrendered",{source:this,pageNumber:this.pageIndex+1})}disable(){if(this.#Jl=!0,this.div.tabIndex=-1,this.togglePointerEvents(!1),this.div.classList.toggle("nonEditing",!0),this.#sh&&!this.#rh){this.#rh=new AbortController;const t=this.#b.combinedSignal(this.#rh);this.#sh.div.addEventListener("pointerdown",t=>{const e=500,{clientX:i,clientY:s,timeStamp:n}=t,r=this.#ah;if(n-r>e)return void(this.#ah=n);this.#ah=-1;const{classList:a}=this.div;a.toggle("getElements",!0);const o=document.elementsFromPoint(i,s);if(a.toggle("getElements",!1),!this.div.contains(o[0]))return;let l;const h=new RegExp(`^${u}[0-9]+$`);for(const d of o)if(h.test(d.id)){l=d.id;break}if(!l)return;const c=this.#Ql.get(l);null===c?.annotationElementId&&(t.stopPropagation(),t.preventDefault(),c.dblclick(t))},{signal:t,capture:!0})}const t=this.#Xl,e=[];if(t){const i=new Map,s=new Map;for(const t of this.#lh)t.disableEditing(),t.annotationElementId?null===t.serialize()?(s.set(t.annotationElementId,t),this.getEditableAnnotation(t.annotationElementId)?.show(),t.remove()):i.set(t.annotationElementId,t):e.push(t);const n=t.getEditableAnnotations();for(const t of n){const{id:e}=t.data;if(this.#b.isDeletedAnnotationElement(e)){t.updateEdited({deleted:!0});continue}let n=s.get(e);n?(n.resetAnnotationElement(t),n.show(!1),t.show()):(n=i.get(e),n&&(this.#b.addChangedExistingAnnotation(n),n.renderAnnotationElement(t)&&n.show(!1)),t.show())}}this.#oh(),this.isEmpty&&(this.div.hidden=!0);const{classList:i}=this.div;for(const s of zn.#Y.values())i.remove(`${s._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),t?.updateFakeAnnotations(e),this.#Jl=!1}getEditableAnnotation(t){return this.#Xl?.getEditableAnnotation(t)||null}setActiveEditor(t){const e=this.#b.getActive();e!==t&&this.#b.setActiveEditor(t)}enableTextSelection(){if(this.div.tabIndex=-1,this.#sh?.div&&!this.#nh){this.#nh=new AbortController;const t=this.#b.combinedSignal(this.#nh);this.#sh.div.addEventListener("pointerdown",this.#hh.bind(this),{signal:t}),this.#sh.div.classList.add("highlighting")}}disableTextSelection(){this.div.tabIndex=0,this.#sh?.div&&this.#nh&&(this.#nh.abort(),this.#nh=null,this.#sh.div.classList.remove("highlighting"))}#hh(t){this.#b.unselectAll();const{target:e}=t;if(e===this.#sh.div||("img"===e.getAttribute("role")||e.classList.contains("endOfContent"))&&this.#sh.div.contains(e)){const{isMac:e}=X.platform;if(0!==t.button||t.ctrlKey&&e)return;this.#b.showAllEditors("highlight",!0,!0),this.#sh.div.classList.add("free"),this.toggleDrawing(),Cn.startHighlighting(this,"ltr"===this.#b.direction,{target:this.#sh.div,x:t.x,y:t.y}),this.#sh.div.addEventListener("pointerup",()=>{this.#sh.div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:this.#b._signal}),t.preventDefault()}}enableClick(){if(this.#Yl)return;this.#Yl=new AbortController;const t=this.#b.combinedSignal(this.#Yl);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.#Yl?.abort(),this.#Yl=null}attach(t){this.#Ql.set(t.id,t);const{annotationElementId:e}=t;e&&this.#b.isDeletedAnnotationElement(e)&&this.#b.removeDeletedAnnotationElement(t)}detach(t){this.#Ql.delete(t.id),this.#fa?.removePointerInTextLayer(t.contentDiv),!this.#Jl&&t.annotationElementId&&this.#b.addDeletedAnnotationElement(t)}remove(t){this.detach(t),this.#b.removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1}changeParent(t){t.parent!==this&&(t.parent&&t.annotationElementId&&(this.#b.addDeletedAnnotationElement(t),ie.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),t.parent?.detach(t),t.setParent(this),t.div&&t.isAttachedToDOM&&(t.div.remove(),this.div.append(t.div)))}add(t){if(t.parent!==this||!t.isAttachedToDOM){if(this.changeParent(t),this.#b.addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(!this.#th),this.#b.addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!this.#Kl&&(t._focusEventsAllowed=!1,this.#Kl=setTimeout(()=>{this.#Kl=null,t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:this.#b._signal}),e.focus())},0)),t._structTreeParentId=this.#fa?.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||=this,t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),i=()=>{t.remove()};this.addCommands({cmd:e,undo:i,mustExec:!1})}getEditorByUID(t){for(const e of this.#Ql.values())if(e.uid===t)return e;return null}getNextId(){return this.#b.getId()}get#ch(){return zn.#Y.get(this.#b.getMode())}combinedSignal(t){return this.#b.combinedSignal(t)}#dh(t){const e=this.#ch;return e?new e.prototype.constructor(t):null}canCreateNewEmptyEditor(){return this.#ch?.canCreateNewEmptyEditor()}async pasteEditor(t,e){this.updateToolbar(t),await this.#b.updateMode(t.mode);const{offsetX:i,offsetY:s}=this.#uh(),n=this.getNextId(),r=this.#dh({parent:this,id:n,x:i,y:s,uiManager:this.#b,isCentered:!0,...e});r&&this.add(r)}async deserialize(t){return await(zn.#Y.get(t.annotationType??t.annotationEditorType)?.deserialize(t,this,this.#b))||null}createAndAddNewEditor(t,e,i={}){const s=this.getNextId(),n=this.#dh({parent:this,id:s,x:t.offsetX,y:t.offsetY,uiManager:this.#b,isCentered:e,...i});return n&&this.add(n),n}get boundingClientRect(){return this.div.getBoundingClientRect()}#uh(){const{x:t,y:e,width:i,height:s}=this.boundingClientRect,n=Math.max(0,t),r=Math.max(0,e),a=Math.min(window.innerWidth,t+i),o=Math.min(window.innerHeight,e+s),l=(n+a)/2-t,h=(r+o)/2-e,[c,d]=this.viewport.rotation%180===0?[l,h]:[h,l];return{offsetX:c,offsetY:d}}addNewEditor(t={}){this.createAndAddNewEditor(this.#uh(),!0,t)}setSelected(t){this.#b.setSelected(t)}toggleSelected(t){this.#b.toggleSelected(t)}unselect(t){this.#b.unselect(t)}pointerup(t){const{isMac:e}=X.platform;if(0!==t.button||t.ctrlKey&&e)return;if(t.target!==this.div)return;if(!this.#Zl)return;if(this.#Zl=!1,this.#ch?.isDrawer&&this.#ch.supportMultipleDrawings)return;if(!this.#ql)return void(this.#ql=!0);const i=this.#b.getMode();i!==p.STAMP&&i!==p.SIGNATURE?this.createAndAddNewEditor(t,!1):this.#b.unselectAll()}pointerdown(t){if(this.#b.getMode()===p.HIGHLIGHT&&this.enableTextSelection(),this.#Zl)return void(this.#Zl=!1);const{isMac:e}=X.platform;if(0!==t.button||t.ctrlKey&&e)return;if(t.target!==this.div)return;if(this.#Zl=!0,this.#ch?.isDrawer)return void this.startDrawingSession(t);const i=this.#b.getActive();this.#ql=!i||i.isEmpty()}startDrawingSession(t){if(this.div.focus({preventScroll:!0}),this.#eh)return void this.#ch.startDrawing(this,this.#b,!1,t);this.#b.setCurrentDrawingSession(this),this.#eh=new AbortController;const e=this.#b.combinedSignal(this.#eh);this.div.addEventListener("blur",({relatedTarget:t})=>{t&&!this.div.contains(t)&&(this.#ih=null,this.commitOrRemove())},{signal:e}),this.#ch.startDrawing(this,this.#b,!1,t)}pause(t){if(t){const{activeElement:t}=document;return void(this.div.contains(t)&&(this.#ih=t))}this.#ih&&setTimeout(()=>{this.#ih?.focus(),this.#ih=null},0)}endDrawingSession(t=!1){return this.#eh?(this.#b.setCurrentDrawingSession(null),this.#eh.abort(),this.#eh=null,this.#ih=null,this.#ch.endDrawing(t)):null}findNewParent(t,e,i){const s=this.#b.findParent(e,i);return null!==s&&s!==this&&(s.changeParent(t),!0)}commitOrRemove(){return!!this.#eh&&(this.endDrawingSession(),!0)}onScaleChanging(){this.#eh&&this.#ch.onScaleChangingWhenDrawing(this)}destroy(){this.commitOrRemove(),this.#b.getActive()?.parent===this&&(this.#b.commitOrRemove(),this.#b.setActiveEditor(null)),this.#Kl&&(clearTimeout(this.#Kl),this.#Kl=null);for(const t of this.#Ql.values())this.#fa?.removePointerInTextLayer(t.contentDiv),t.setParent(null),t.isAttachedToDOM=!1,t.div.remove();this.div=null,this.#Ql.clear(),this.#b.removeLayer(this)}#oh(){for(const t of this.#Ql.values())t.isEmpty()&&t.remove()}render({viewport:t}){this.viewport=t,Dt(this.div,t);for(const e of this.#b.getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){this.#b.commitOrRemove(),this.#oh();const e=this.viewport.rotation,i=t.rotation;if(this.viewport=t,Dt(this.div,{rotation:i}),e!==i)for(const s of this.#Ql.values())s.rotate(i)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return this.#b.viewParameters.realScale}}class Hn{#jr=null;#ph=new Map;#gh=new Map;static#E=0;constructor({pageIndex:t}){this.pageIndex=t}setParent(t){if(this.#jr){if(this.#jr!==t){if(this.#ph.size>0)for(const e of this.#ph.values())e.remove(),t.append(e);this.#jr=t}}else this.#jr=t}static get _svgFactory(){return F(this,"_svgFactory",new Bs)}static#mh(t,[e,i,s,n]){const{style:r}=t;r.top=100*i+"%",r.left=100*e+"%",r.width=100*s+"%",r.height=100*n+"%"}#fh(){const t=Hn._svgFactory.create(1,1,!0);return this.#jr.append(t),t.setAttribute("aria-hidden",!0),t}#bh(t,e){const i=Hn._svgFactory.createElement("clipPath");t.append(i);const s=`clip_${e}`;i.setAttribute("id",s),i.setAttribute("clipPathUnits","objectBoundingBox");const n=Hn._svgFactory.createElement("use");return i.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),s}#vh(t,e){for(const[i,s]of Object.entries(e))null===s?t.removeAttribute(i):t.setAttribute(i,s)}draw(t,e=!1,i=!1){const s=Hn.#E++,n=this.#fh(),r=Hn._svgFactory.createElement("defs");n.append(r);const a=Hn._svgFactory.createElement("path");r.append(a);const o=`path_p${this.pageIndex}_${s}`;a.setAttribute("id",o),a.setAttribute("vector-effect","non-scaling-stroke"),e&&this.#gh.set(s,a);const l=i?this.#bh(r,o):null,h=Hn._svgFactory.createElement("use");return n.append(h),h.setAttribute("href",`#${o}`),this.updateProperties(n,t),this.#ph.set(s,n),{id:s,clipPathId:`url(#${l})`}}drawOutline(t,e){const i=Hn.#E++,s=this.#fh(),n=Hn._svgFactory.createElement("defs");s.append(n);const r=Hn._svgFactory.createElement("path");n.append(r);const a=`path_p${this.pageIndex}_${i}`;let o;if(r.setAttribute("id",a),r.setAttribute("vector-effect","non-scaling-stroke"),e){const t=Hn._svgFactory.createElement("mask");n.append(t),o=`mask_p${this.pageIndex}_${i}`,t.setAttribute("id",o),t.setAttribute("maskUnits","objectBoundingBox");const e=Hn._svgFactory.createElement("rect");t.append(e),e.setAttribute("width","1"),e.setAttribute("height","1"),e.setAttribute("fill","white");const s=Hn._svgFactory.createElement("use");t.append(s),s.setAttribute("href",`#${a}`),s.setAttribute("stroke","none"),s.setAttribute("fill","black"),s.setAttribute("fill-rule","nonzero"),s.classList.add("mask")}const l=Hn._svgFactory.createElement("use");s.append(l),l.setAttribute("href",`#${a}`),o&&l.setAttribute("mask",`url(#${o})`);const h=l.cloneNode();return s.append(h),l.classList.add("mainOutline"),h.classList.add("secondaryOutline"),this.updateProperties(s,t),this.#ph.set(i,s),i}finalizeDraw(t,e){this.#gh.delete(t),this.updateProperties(t,e)}updateProperties(t,e){if(!e)return;const{root:i,bbox:s,rootClass:n,path:r}=e,a="number"===typeof t?this.#ph.get(t):t;if(a){if(i&&this.#vh(a,i),s&&Hn.#mh(a,s),n){const{classList:t}=a;for(const[e,i]of Object.entries(n))t.toggle(e,i)}if(r){const t=a.firstElementChild,e=t.firstElementChild;this.#vh(e,r)}}}updateParent(t,e){if(e===this)return;const i=this.#ph.get(t);i&&(e.#jr.append(i),this.#ph.delete(t),e.#ph.set(t,i))}remove(t){this.#gh.delete(t),null!==this.#jr&&(this.#ph.get(t).remove(),this.#ph.delete(t))}destroy(){this.#jr=null;for(const t of this.#ph.values())t.remove();this.#ph.clear(),this.#gh.clear()}}globalThis._pdfjsTestingUtils={HighlightOutliner:xn},globalThis.pdfjsLib={AbortException:H,AnnotationEditorLayer:zn,AnnotationEditorParamsType:g,AnnotationEditorType:p,AnnotationEditorUIManager:Zt,AnnotationLayer:fn,AnnotationMode:d,AnnotationType:y,applyOpacity:Lt,build:Ps,ColorPicker:Is,createValidAbsoluteUrl:R,CSSConstants:Rt,DOMSVGFactory:Bs,DrawLayer:Hn,FeatureTest:X,fetchData:dt,findContrastColor:jt,getDocument:ws,getFilenameFromUrl:ft,getPdfFilenameFromUrl:bt,getRGB:Et,getUuid:et,getXfaPageViewport:St,GlobalWorkerOptions:Oi,ImageKind:v,InvalidPDFException:U,isDataScheme:gt,isPdfFile:mt,isValidExplicitDest:_e,MathClamp:nt,noContextMenu:wt,normalizeUnicode:tt,OPS:x,OutputScale:Pt,PasswordResponses:S,PDFDataRangeTransport:xs,PDFDateString:_t,PDFWorker:Es,PermissionFlag:m,PixelsPerInch:ct,RenderingCancelledException:pt,renderRichText:zt,ResponseException:j,setLayerDimensions:Dt,shadow:F,SignatureExtractor:On,stopEvent:At,SupportedImageMimeTypes:It,TextLayer:vs,TouchManager:ee,updateUrlHash:L,Util:K,VerbosityLevel:A,version:Ds,XfaLayer:lt};const $n=i.p+"pdf.worker.min.mjs";var Gn=function(){var t=this,e=t._self._c;return e("div",{staticClass:"pdf-elements-root",style:{width:t.width,height:t.height}},[t.pdfDocuments.length?e("div",{staticClass:"pages-container",style:{transform:`scale(${t.visualScale/t.scale})`,transformOrigin:"top center"}},t._l(t.pdfDocuments,function(i,s){return e("div",{key:s},t._l(i.pages,function(n,r){return e("div",{key:`${s}-${r}`,staticClass:"page-slot"},[e("div",{staticClass:"page-wrapper",on:{mousedown:function(e){return t.selectPage(s,r)},touchstart:function(e){return t.selectPage(s,r)}}},[e("div",{staticClass:"page-canvas",class:{"shadow-outline":s===t.selectedDocIndex&&r===t.selectedPageIndex}},[e("PDFPage",{ref:`page${s}-${r}`,refInFor:!0,attrs:{page:n,scale:t.scale},on:{onMeasure:function(e){return t.onMeasure(e,s,r)}}}),e("div",{staticClass:"overlay"},[t.isAddingMode&&t.previewPageDocIndex===s&&t.previewPageIndex===r&&t.previewElement&&t.previewVisible?e("div",{staticClass:"preview-element",style:{left:t.previewPosition.x*t.previewScale.x+"px",top:t.previewPosition.y*t.previewScale.y+"px",width:t.previewElement.width*t.previewScale.x+"px",height:t.previewElement.height*t.previewScale.y+"px"}},[t._t("custom",null,{object:t.previewElement,isSelected:!1})],2):t._e(),t._l(i.allObjects[r],function(i){return e("DraggableElement",{key:i.id,ref:`draggable${s}-${r}-${i.id}`,refInFor:!0,attrs:{object:i,"pages-scale":t.getRenderPageScale(s,r),"page-width":t.getPageWidth(s,r),"page-height":t.getPageHeight(s,r),"on-update":e=>t.updateObject(s,i.id,e),"on-delete":()=>t.deleteObject(s,i.id),"on-drag-start":(e,n,a,o)=>t.startDraggingElement(s,r,i,e,n,a,o),"on-drag-move":t.updateDraggingPosition,"on-drag-end":t.stopDraggingElement,"is-being-dragged-globally":t.isDraggingElement&&t.draggingObject&&t.draggingObject.id===i.id,"dragging-client-pos":t.draggingClientPosition,"current-doc-index":s,"current-page-index":r,"global-drag-doc-index":t.draggingDocIndex,"global-drag-page-index":t.draggingPageIndex,"show-selection-ui":t.showSelectionHandles&&!t.hideSelectionUI&&!1!==i.resizable,"show-default-actions":t.showElementActions&&!t.hideSelectionUI},scopedSlots:t._u([{key:"default",fn:function(e){return[t._t(e.object.type?`element-${e.object.type}`:"custom",function(){return[t._t("custom",null,{object:e.object,onDelete:e.onDelete,onResize:e.onResize})]},{object:e.object,onDelete:e.onDelete,onResize:e.onResize})]}},{key:"actions",fn:function(e){return[t._t("actions",null,{object:e.object,onDelete:e.onDelete})]}}],null,!0)})})],2)],1),t.showPageFooter?e("div",{staticClass:"page-footer"},[e("span",[t._v(t._s(i.name))]),e("span",[t._v(t._s(t.formatPageNumber(r+1,i.numPages)))])]):t._e()])])}),0)}),0):t._e(),t.isDraggingElement&&t.draggingObject?e("div",{staticClass:"drag-portal",style:{position:"fixed",left:`${t.draggingClientPosition.x}px`,top:`${t.draggingClientPosition.y}px`,width:t.draggingObject.width*t.draggingScale+"px",height:t.draggingObject.height*t.draggingScale+"px",pointerEvents:"none"}},[t._t(t.draggingObject.type?`element-${t.draggingObject.type}`:"custom",function(){return[t._t("custom",null,{object:t.draggingObject,isSelected:!1})]},{object:t.draggingObject,isSelected:!1})],2):t._e()])},Wn=[];i(4114),i(8111),i(2489),i(116),i(531),i(7588),i(1701);function Vn(t,e=100,i={}){if("function"!==typeof t)throw new TypeError(`Expected the first parameter to be a function, got \`${typeof t}\`.`);if(e<0)throw new RangeError("`wait` must not be negative.");if("boolean"===typeof i)throw new TypeError("The `options` parameter must be an object, not a boolean. Use `{immediate: true}` instead.");const{immediate:s}=i;let n,r,a,o,l;function h(){const e=n,i=r;return n=void 0,r=void 0,l=t.apply(e,i),l}function c(){const t=Date.now()-o;t<e&&t>=0?a=setTimeout(c,e-t):(a=void 0,s||(l=h()))}const d=function(...t){if(n&&this!==n&&Object.getPrototypeOf(this)===Object.getPrototypeOf(n))throw new Error("Debounced method called with different contexts of the same prototype.");n=this,r=t,o=Date.now();const i=s&&!a;if(a||(a=setTimeout(c,e)),i)return l=h(),l};return Object.defineProperty(d,"isPending",{get(){return void 0!==a}}),d.clear=()=>{a&&(clearTimeout(a),a=void 0,n=void 0,r=void 0)},d.flush=()=>{a&&d.trigger()},d.trigger=()=>{l=h(),d.clear()},d}var qn=function(){var t=this,e=t._self._c;return e("canvas",{ref:"canvas"})},Xn=[];const Yn={name:"PDFPage",props:{page:{type:Promise,required:!0},scale:{type:Number,default:1}},data(){return{dynamicScale:this.scale,isRendering:!1,boundMeasure:null}},watch:{scale(t){this.dynamicScale=t,this.render()}},mounted(){this.boundMeasure=this.measure.bind(this),window.addEventListener("resize",this.boundMeasure),this.render()},beforeUnmount(){this.boundMeasure&&window.removeEventListener("resize",this.boundMeasure)},methods:{getCanvasMeasurement(){return{canvasWidth:this.$refs.canvas.width,canvasHeight:this.$refs.canvas.height}},measure(){this.$emit("onMeasure",{scale:this.dynamicScale})},async render(){if(!this.isRendering){this.isRendering=!0;try{const t=await this.page,e=this.$refs.canvas,i=e.getContext("2d"),s=t.getViewport({scale:this.dynamicScale});e.width=s.width,e.height=s.height,await t.render({canvasContext:i,viewport:s}).promise,this.measure()}finally{this.isRendering=!1}}}}},Kn=Yn;function Qn(t,e,i,s,n,r,a,o){var l,h="function"===typeof t?t.options:t;if(e&&(h.render=e,h.staticRenderFns=i,h._compiled=!0),s&&(h.functional=!0),r&&(h._scopeId="data-v-"+r),a?(l=function(t){t=t||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,t||"undefined"===typeof __VUE_SSR_CONTEXT__||(t=__VUE_SSR_CONTEXT__),n&&n.call(this,t),t&&t._registeredComponents&&t._registeredComponents.add(a)},h._ssrRegister=l):n&&(l=o?function(){n.call(this,(h.functional?this.parent:this).$root.$options.shadowRoot)}:n),l)if(h.functional){h._injectStyles=l;var c=h.render;h.render=function(t,e){return l.call(e),c(t,e)}}else{var d=h.beforeCreate;h.beforeCreate=d?[].concat(d,l):[l]}return{exports:t,options:h}}var Zn=Qn(Kn,qn,Xn,!1,null,"2c9e224a",null);const Jn=Zn.exports;var tr=function(){var t=this,e=t._self._c;return e("div",{staticClass:"draggable-wrapper"},[t.isSelected&&!t.isBeingDraggedGlobally&&t.showSelectionUi&&t.showDefaultActions?e("div",{staticClass:"actions-toolbar",style:t.toolbarStyle},[t._t("actions",function(){return[e("button",{staticClass:"action-btn",attrs:{type:"button",title:"Delete"},on:{click:function(e){return e.stopPropagation(),t.onDelete.apply(null,arguments)}}},[e("svg",{attrs:{width:"16",height:"16",viewBox:"0 0 16 16",fill:"currentColor"}},[e("path",{attrs:{d:"M6.5 1h3a.5.5 0 0 1 .5.5v1H6v-1a.5.5 0 0 1 .5-.5ZM11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3A1.5 1.5 0 0 0 5 1.5v1H2.5a.5.5 0 0 0 0 1h.5v10.5A1.5 1.5 0 0 0 4.5 15h7a1.5 1.5 0 0 0 1.5-1.5V3.5h.5a.5.5 0 0 0 0-1H11Zm1 1v10.5a.5.5 0 0 1-.5.5h-7a.5.5 0 0 1-.5-.5V3.5h8Z"}})])])]},{object:t.object,onDelete:t.onDelete})],2):t._e(),e("div",{staticClass:"draggable-element",class:{selected:t.isSelected&&t.showSelectionUi},style:[t.elementStyle,t.dragElementStyle],attrs:{draggable:"false"},on:{dragstart:function(t){t.preventDefault()},mousedown:t.handleElementClick,touchstart:t.handleElementClick}},[t._t("default",null,{object:t.object,isSelected:t.isSelected,onDelete:t.onDelete,onResize:t.startResizeFromSlot}),t.isSelected&&t.showSelectionUi?t._l(t.resizeDirections,function(i){return e("button",{key:i,staticClass:"resize-handle",class:`handle-${i}`,attrs:{type:"button"},on:{mousedown:function(e){return e.stopPropagation(),e.preventDefault(),t.startResize(i,e)},touchstart:function(e){return e.stopPropagation(),e.preventDefault(),t.startResize(i,e)}}})}):t._e()],2)])},er=[];const ir={name:"DraggableElement",props:{object:{type:Object,required:!0},pagesScale:{type:Number,default:1},pageWidth:{type:Number,required:!0},pageHeight:{type:Number,required:!0},onUpdate:{type:Function,default:()=>{}},onDelete:{type:Function,default:()=>{}},onDragStart:{type:Function,default:()=>{}},onDragMove:{type:Function,default:()=>{}},onDragEnd:{type:Function,default:()=>{}},isBeingDraggedGlobally:{type:Boolean,default:!1},draggingClientPos:{type:Object,default:()=>({x:0,y:0})},currentDocIndex:{type:Number,default:-1},currentPageIndex:{type:Number,default:-1},globalDragDocIndex:{type:Number,default:-1},globalDragPageIndex:{type:Number,default:-1},showSelectionUi:{type:Boolean,default:!0},showDefaultActions:{type:Boolean,default:!0}},data(){return{isSelected:!1,mode:"idle",direction:"",startX:0,startY:0,startLeft:0,startTop:0,startWidth:0,startHeight:0,offsetX:0,offsetY:0,resizeOffsetX:0,resizeOffsetY:0,resizeOffsetW:0,resizeOffsetH:0,aspectRatio:1,lastMouseX:0,lastMouseY:0,pointerOffsetDoc:{x:0,y:0},currentPageRect:null,rafId:null}},computed:{resizeDirections(){return["top-left","top-right","bottom-left","bottom-right"]},elementStyle(){const t=this.pagesScale||1,e=this.object.x+this.offsetX+this.resizeOffsetX,i=this.object.y+this.offsetY+this.resizeOffsetY,s=this.object.width+this.resizeOffsetW,n=this.object.height+this.resizeOffsetH;return{left:e*t+"px",top:i*t+"px",width:s*t+"px",height:n*t+"px"}},toolbarStyle(){const t=this.pagesScale||1,e=this.object.x+this.offsetX+this.resizeOffsetX,i=this.object.y+this.offsetY+this.resizeOffsetY,s=this.object.width+this.resizeOffsetW;return{left:(e+s/2)*t+"px",top:(i-48)*t+"px",transform:"translateX(-50%)"}},dragElementStyle(){return this.isBeingDraggedGlobally&&this.draggingClientPos?{opacity:0,pointerEvents:"none"}:{}}},mounted(){this.handleClickOutside=this.handleClickOutside.bind(this),this.boundHandleMove=this.handleMove.bind(this),this.boundStopInteraction=this.stopInteraction.bind(this),document.addEventListener("mousedown",this.handleClickOutside),document.addEventListener("touchstart",this.handleClickOutside)},beforeUnmount(){document.removeEventListener("mousedown",this.handleClickOutside),document.removeEventListener("touchstart",this.handleClickOutside),window.removeEventListener("mousemove",this.boundHandleMove),window.removeEventListener("mouseup",this.boundStopInteraction),window.removeEventListener("touchmove",this.boundHandleMove),window.removeEventListener("touchend",this.boundStopInteraction),this.rafId&&cancelAnimationFrame(this.rafId)},methods:{handleElementClick(t){t.target.closest(".delete-handle")||t.target.closest("[data-stop-drag]")||t.target.closest(".actions-toolbar")||(t.preventDefault(),this.isSelected=!0,this.startDrag(t))},handleClickOutside(t){this.$el&&!this.$el.contains(t.target)&&(this.isSelected=!1)},startResizeFromSlot(t,e){t&&e&&this.startResize(t,e)},startDrag(t){if(t.target.classList.contains("delete"))return;if(t.target.classList.contains("resize-handle"))return;this.mode="drag",this.startX=t.type.includes("touch")?t.touches[0].clientX:t.clientX,this.startY=t.type.includes("touch")?t.touches[0].clientY:t.clientY,this.startLeft=this.object.x,this.startTop=this.object.y,this.offsetX=0,this.offsetY=0,this.resetResizeOffsets();const e=this.$el.querySelector(".draggable-element").getBoundingClientRect();this.pointerOffsetDoc.x=this.startX-e.left,this.pointerOffsetDoc.y=this.startY-e.top;const i=this.capturePageRect();this.currentPageRect=i;let s={x:0,y:0};if(i){const t=i.left+this.object.x*this.pagesScale,n=i.top+this.object.y*this.pagesScale;s={x:e.left-t,y:e.top-n}}this.onDragStart(this.startX,this.startY,{...this.pointerOffsetDoc},s),window.addEventListener("mousemove",this.boundHandleMove),window.addEventListener("mouseup",this.boundStopInteraction),window.addEventListener("touchmove",this.boundHandleMove),window.addEventListener("touchend",this.boundStopInteraction)},startResize(t,e){this.mode="resize",this.direction=t,this.startX=e.type.includes("touch")?e.touches[0].clientX:e.clientX,this.startY=e.type.includes("touch")?e.touches[0].clientY:e.clientY,this.startLeft=this.object.x,this.startTop=this.object.y,this.startWidth=this.object.width,this.startHeight=this.object.height,this.aspectRatio=this.startWidth/this.startHeight,this.offsetX=0,this.offsetY=0,this.resetResizeOffsets(),window.addEventListener("mousemove",this.boundHandleMove),window.addEventListener("mouseup",this.boundStopInteraction),window.addEventListener("touchmove",this.boundHandleMove),window.addEventListener("touchend",this.boundStopInteraction)},handleMove(t){"idle"!==this.mode&&(t.preventDefault(),this.rafId||(this.rafId=requestAnimationFrame(()=>{const e=t.type.includes("touch")?t.touches[0]?.clientX:t.clientX,i=t.type.includes("touch")?t.touches[0]?.clientY:t.clientY;if(void 0===e||void 0===i)return;this.lastMouseX=e,this.lastMouseY=i;const s=(e-this.startX)/this.pagesScale,n=(i-this.startY)/this.pagesScale;if("drag"===this.mode){const t=this.currentPageRect;if(t){const s=e-this.pointerOffsetDoc.x,n=i-this.pointerOffsetDoc.y,r=(s-t.left)/this.pagesScale,a=(n-t.top)/this.pagesScale;this.offsetX=r-this.object.x,this.offsetY=a-this.object.y}else this.offsetX=s,this.offsetY=n;return this.onDragMove(e,i),this.isBeingDraggedGlobally&&this.onUpdate({_globalDrag:!0,_mouseX:e,_mouseY:i}),void(this.rafId=null)}const r=16;let a=this.startWidth,o=this.startHeight,l=this.startLeft,h=this.startTop;const c=this.direction.includes("right")?s:this.direction.includes("left")?-s:0;if(a=this.startWidth+c,a<r&&(a=r),o=a/this.aspectRatio,this.direction.includes("left")&&(l=this.startLeft+(this.startWidth-a),l<0)){const t=-l;l=0,a-=t,o=a/this.aspectRatio}if(this.direction.includes("top")&&(h=this.startTop+(this.startHeight-o),h<0)){const t=-h;h=0,o-=t,a=o*this.aspectRatio,this.direction.includes("left")&&(l=this.startLeft+(this.startWidth-a))}if(l+a>this.pageWidth){const t=l+a-this.pageWidth;a-=t,o=a/this.aspectRatio}if(h+o>this.pageHeight){const t=h+o-this.pageHeight;o-=t,a=o*this.aspectRatio,this.direction.includes("left")&&(l=this.startLeft+(this.startWidth-a))}this.resizeOffsetX=l-this.object.x,this.resizeOffsetY=h-this.object.y,this.resizeOffsetW=a-this.object.width,this.resizeOffsetH=o-this.object.height,this.rafId=null})))},stopInteraction(){if("idle"!==this.mode){if("drag"===this.mode&&(0!==this.offsetX||0!==this.offsetY))if(this.isBeingDraggedGlobally)this.onUpdate({_globalDrag:!0,_mouseX:this.lastMouseX,_mouseY:this.lastMouseY});else{const t=Math.max(0,Math.min(this.object.x+this.offsetX,this.pageWidth-this.object.width)),e=Math.max(0,Math.min(this.object.y+this.offsetY,this.pageHeight-this.object.height));this.onUpdate({x:t,y:e})}if("resize"===this.mode&&(0!==this.resizeOffsetW||0!==this.resizeOffsetH||0!==this.resizeOffsetX||0!==this.resizeOffsetY)){const t=this.object.x+this.resizeOffsetX,e=this.object.y+this.resizeOffsetY,i=this.object.width+this.resizeOffsetW,s=this.object.height+this.resizeOffsetH;this.onUpdate({x:t,y:e,width:i,height:s})}this.resetOffsets(),this.onDragEnd(),window.removeEventListener("mousemove",this.boundHandleMove),window.removeEventListener("mouseup",this.boundStopInteraction),window.removeEventListener("touchmove",this.boundHandleMove),window.removeEventListener("touchend",this.boundStopInteraction)}},capturePageRect(){const t=this.$el.closest(".page-wrapper");if(!t)return null;const e=t.querySelector("canvas");return e?e.getBoundingClientRect():null},resetResizeOffsets(){this.resizeOffsetX=0,this.resizeOffsetY=0,this.resizeOffsetW=0,this.resizeOffsetH=0},resetOffsets(){this.mode="idle",this.offsetX=0,this.offsetY=0,this.resetResizeOffsets(),this.pointerOffsetDoc={x:0,y:0},this.currentPageRect=null}}},sr=ir;var nr=Qn(sr,tr,er,!1,null,"55db89ce",null);const rr=nr.exports;function ar(t){return new Promise((e,i)=>{const s=new FileReader;s.onload=()=>e(s.result),s.onerror=i,s.readAsArrayBuffer(t)})}function or(t){return ws(t).promise}Oi.workerSrc=$n;const lr={name:"PDFElements",components:{PDFPage:Jn,DraggableElement:rr},props:{width:{type:String,default:"100%"},height:{type:String,default:"100%"},initFiles:{type:Array,default:()=>[]},initFileNames:{type:Array,default:()=>[]},initialScale:{type:Number,default:1},showPageFooter:{type:Boolean,default:!0},hideSelectionUI:{type:Boolean,default:!1},showSelectionHandles:{type:Boolean,default:!0},showElementActions:{type:Boolean,default:!0},pageCountFormat:{type:String,default:"{currentPage} of {totalPages}"},autoFitZoom:{type:Boolean,default:!1}},data(){return{scale:this.initialScale,pdfDocuments:[],selectedDocIndex:-1,selectedPageIndex:-1,isAddingMode:!1,previewElement:null,previewPosition:{x:0,y:0},previewScale:{x:1,y:1},previewPageDocIndex:-1,previewPageIndex:-1,previewVisible:!1,pagesBoundingRects:{},isDraggingElement:!1,draggingObject:null,draggingDocIndex:-1,draggingPageIndex:-1,draggingClientPosition:{x:0,y:0},draggingScale:1,draggingInitialMouseOffset:{x:0,y:0},draggingElementShift:{x:0,y:0},lastMouseClientPos:{x:0,y:0},viewportRafId:0,objectIndexCache:{},zoomRafId:null,boundHandleWheel:null,debouncedApplyZoom:null,visualScale:this.initialScale,resizeObserver:null}},mounted(){this.boundHandleWheel=this.handleWheel.bind(this),this.debouncedApplyZoom=Vn(this.commitZoom,150),this.init(),document.addEventListener("mousemove",this.handleMouseMove),document.addEventListener("touchmove",this.handleMouseMove,{passive:!0}),document.addEventListener("mouseup",this.finishAdding),document.addEventListener("touchend",this.finishAdding),document.addEventListener("keydown",this.handleKeyDown),window.addEventListener("scroll",this.onViewportScroll,{passive:!0}),window.addEventListener("resize",this.onViewportScroll),this.$el?.addEventListener("scroll",this.onViewportScroll,{passive:!0}),this.$el?.addEventListener("wheel",this.boundHandleWheel,{passive:!1}),this.autoFitZoom&&(window.addEventListener("resize",this.adjustZoomToFit),"undefined"!==typeof ResizeObserver&&(this.resizeObserver=new ResizeObserver(()=>{this.scheduleAutoFitZoom()}),this.$el&&this.resizeObserver.observe(this.$el)))},beforeUnmount(){this.zoomRafId&&cancelAnimationFrame(this.zoomRafId),this.debouncedApplyZoom?.clear?.(),this.boundHandleWheel&&this.$el?.removeEventListener("wheel",this.boundHandleWheel),document.removeEventListener("mousemove",this.handleMouseMove),document.removeEventListener("touchmove",this.handleMouseMove),document.removeEventListener("mouseup",this.finishAdding),document.removeEventListener("touchend",this.finishAdding),document.removeEventListener("keydown",this.handleKeyDown),window.removeEventListener("scroll",this.onViewportScroll),window.removeEventListener("resize",this.onViewportScroll),this.$el?.removeEventListener("scroll",this.onViewportScroll),this.autoFitZoom&&(window.removeEventListener("resize",this.adjustZoomToFit),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)),this.viewportRafId&&(window.cancelAnimationFrame(this.viewportRafId),this.viewportRafId=0)},methods:{async init(){if(!this.initFiles||0===this.initFiles.length)return;const t=[];for(let e=0;e<this.initFiles.length;e++){const i=this.initFiles[e],s=this.initFileNames[e]||`document-${e+1}.pdf`;let n;if(i instanceof Blob){const t=await ar(i);n=await or({data:t})}else n=await or(i);const r=[],a=Array(n.numPages).fill(0);for(let t=1;t<=n.numPages;t++){const e=n.getPage(t);e.then(e=>{a[t-1]=e.getViewport({scale:1}).width,this.autoFitZoom&&this.scheduleAutoFitZoom()}),r.push(e)}t.push({name:s,file:i,pdfDoc:n,numPages:n.numPages,pages:r,pageWidths:a,pagesScale:Array(n.numPages).fill(this.scale),allObjects:Array(n.numPages).fill(0).map(()=>[])})}this.pdfDocuments=t,t.length&&(this.selectedDocIndex=0,this.selectedPageIndex=0,this.$emit("pdf-elements:end-init",{docsCount:t.length}),this.$nextTick(()=>{this.autoFitZoom&&this.scheduleAutoFitZoom()}))},selectPage(t,e){this.selectedDocIndex=t,this.selectedPageIndex=e},startDraggingElement(t,e,i,s,n,r,a){this.isDraggingElement=!0,this.draggingObject={...i},this.draggingDocIndex=t,this.draggingPageIndex=e,this.draggingScale=this.getDisplayedPageScale(t,e),this.lastMouseClientPos.x=s,this.lastMouseClientPos.y=n,this.draggingElementShift=a&&"number"===typeof a.x&&"number"===typeof a.y?a:{x:0,y:0};const o=`${t}-${e}`;this.pagesBoundingRects[o]||this.cachePageBounds();const l=this.pagesBoundingRects[o]?.rect;if(r&&"number"===typeof r.x&&"number"===typeof r.y)this.draggingInitialMouseOffset.x=r.x,this.draggingInitialMouseOffset.y=r.y,this.draggingClientPosition.x=s-this.draggingInitialMouseOffset.x,this.draggingClientPosition.y=n-this.draggingInitialMouseOffset.y;else if(l){const t=l.left+i.x*this.draggingScale,e=l.top+i.y*this.draggingScale;this.draggingInitialMouseOffset.x=s-t,this.draggingInitialMouseOffset.y=n-e,this.draggingClientPosition.x=s-this.draggingInitialMouseOffset.x,this.draggingClientPosition.y=n-this.draggingInitialMouseOffset.y}this.cachePageBounds()},updateDraggingPosition(t,e){this.isDraggingElement&&(this.lastMouseClientPos.x=t,this.lastMouseClientPos.y=e,this.draggingClientPosition.x=t-this.draggingInitialMouseOffset.x,this.draggingClientPosition.y=e-this.draggingInitialMouseOffset.y)},stopDraggingElement(){if(this.draggingObject){const t=this.draggingObject.id,e=this.draggingDocIndex,i=this.checkAndMoveObjectPage(this.draggingDocIndex,t,this.lastMouseClientPos.x,this.lastMouseClientPos.y);void 0!==i&&this.$nextTick(()=>{this.selectPage(e,i);const s=`draggable${e}-${i}-${t}`,n=this.$refs[s];n&&Array.isArray(n)&&n[0]&&(n[0].isSelected=!0)})}this.isDraggingElement=!1,this.draggingObject=null,this.draggingDocIndex=-1,this.draggingPageIndex=-1,this.draggingElementShift={x:0,y:0}},startAddingElement(t){this.pdfDocuments.length&&(this.isAddingMode=!0,this.previewElement={...t},this.previewPageDocIndex=0,this.previewPageIndex=0,this.previewVisible=!1,this.previewScale={x:1,y:1},this.cachePageBounds())},cachePageBounds(){this.pagesBoundingRects={};for(let t=0;t<this.pdfDocuments.length;t++)for(let e=0;e<this.pdfDocuments[t].pages.length;e++){const i=this.getPageCanvasElement(t,e);if(!i)continue;const s=i.getBoundingClientRect();this.pagesBoundingRects[`${t}-${e}`]={docIndex:t,pageIndex:e,rect:s}}},getDisplayedPageScale(t,e){const i=this.pdfDocuments[t];if(!i)return 1;const s=i.pagesScale[e]||1,n=this.visualScale&&this.scale?this.visualScale/this.scale:1;return s*n},getRenderPageScale(t,e){const i=this.pdfDocuments[t];return i&&i.pagesScale[e]||1},getPageComponent(t,e){const i=this.$refs[`page${t}-${e}`];return i&&Array.isArray(i)&&i[0]?i[0]:null},getPageCanvasElement(t,e){const i=this.getPageComponent(t,e);return i?i.$el||i:null},onViewportScroll(){this.viewportRafId||(this.viewportRafId=window.requestAnimationFrame(()=>{(this.isAddingMode||this.isDraggingElement)&&this.cachePageBounds(),this.viewportRafId=0}))},handleMouseMove(t){if(!this.isAddingMode||!this.previewElement)return;const e=t.type.includes("touch")?t.touches[0].clientX:t.clientX,i=t.type.includes("touch")?t.touches[0].clientY:t.clientY;let s=!1;for(const n in this.pagesBoundingRects){const{docIndex:t,pageIndex:r,rect:a}=this.pagesBoundingRects[n];if(e>=a.left&&e<=a.right&&i>=a.top&&i<=a.bottom){this.previewPageDocIndex=t,this.previewPageIndex=r,s=!0;const n=this.getPageCanvasElement(t,r),o=this.pdfDocuments[t]?.pagesScale?.[r]||1,l=n?.offsetWidth||a.width,h=n?.offsetHeight||a.height,c=l?a.width/l:1,d=h?a.height/h:1,u=(e-a.left)/c/o,p=(i-a.top)/d/o,g=l/o,m=h/o;this.previewScale.x=o*c,this.previewScale.y=o*d;let f=u-this.previewElement.width/2,b=p-this.previewElement.height/2;f=Math.max(0,Math.min(f,g-this.previewElement.width)),b=Math.max(0,Math.min(b,m-this.previewElement.height)),this.previewPosition.x=f,this.previewPosition.y=b,this.previewVisible=!0;break}}s||(this.previewVisible=!1,this.previewScale={x:1,y:1})},handleKeyDown(t){"Escape"===t.key&&this.isAddingMode&&this.cancelAdding()},handleWheel(t){if(!t.ctrlKey)return;t.preventDefault();const e=1-.002*t.deltaY,i=Math.max(.5,Math.min(3,this.visualScale*e));this.visualScale=i,this.debouncedApplyZoom()},commitZoom(){const t=this.visualScale;this.scale=t,this.pdfDocuments.forEach(t=>{t.pagesScale=t.pagesScale.map(()=>this.scale)}),this.cachePageBounds()},finishAdding(){if(!this.isAddingMode||!this.previewElement)return;if(!this.previewVisible)return;const t={...this.previewElement,id:`obj-${Date.now()}`,x:Math.round(this.previewPosition.x),y:Math.round(this.previewPosition.y)},e=this.pdfDocuments[this.previewPageDocIndex],i=this.getPageWidth(this.previewPageDocIndex,this.previewPageIndex),s=this.getPageHeight(this.previewPageDocIndex,this.previewPageIndex);if(t.x<0||t.y<0||t.x+t.width>i||t.y+t.height>s)return void this.cancelAdding();e.allObjects[this.previewPageIndex].push(t);const n=this.previewPageIndex,r=this.previewPageDocIndex,a=t.id;this.cancelAdding(),this.$nextTick(()=>{const t=`draggable${r}-${n}-${a}`,e=this.$refs[t];e&&Array.isArray(e)&&e[0]&&(e[0].isSelected=!0)})},cancelAdding(){this.isAddingMode=!1,this.previewElement=null,this.previewVisible=!1},addObjectToPage(t,e=this.selectedPageIndex,i=this.selectedDocIndex){if(i<0||i>=this.pdfDocuments.length)return!1;if(e<0||e>=this.pdfDocuments[i].pages.length)return!1;const s=this.pdfDocuments[i],n=this.getPageComponent(i,e);if(!n)return!1;const r=this.getPageWidth(i,e),a=this.getPageHeight(i,e);return!(t.x<0||t.y<0||t.x+t.width>r||t.y+t.height>a)&&(s.allObjects=s.allObjects.map((i,s)=>s===e?[...i,t]:i),!0)},getAllObjects(t=this.selectedDocIndex){if(t<0||t>=this.pdfDocuments.length)return[];const e=this.pdfDocuments[t],i=this.scale||1,s=[];return e.allObjects.forEach((e,n)=>{const r=this.getPageComponent(t,n);if(!r)return;const a=r.getCanvasMeasurement(),o=a.canvasHeight/i;e.forEach(t=>{s.push({...t,pageIndex:n,pageNumber:n+1,scale:i,normalizedCoordinates:{llx:parseInt(t.x,10),lly:parseInt(o-t.y,10),ury:parseInt(o-t.y-t.height,10)}})})}),s},updateObject(t,e,i){if(t<0||t>=this.pdfDocuments.length)return;const s=this.pdfDocuments[t],n=`${t}-${e}`;let r=this.objectIndexCache[n];if(void 0===r&&s.allObjects.forEach((t,i)=>{t.find(t=>t.id===e)&&(r=i,this.objectIndexCache[n]=i)}),void 0===r)return;const a=s.allObjects[r]?.find(t=>t.id===e);if(a){if(i._globalDrag&&void 0!==i._mouseX&&void 0!==i._mouseY){const n=i._mouseX,a=i._mouseY;this.pagesBoundingRects&&0!==Object.keys(this.pagesBoundingRects).length||this.cachePageBounds();const o=this.pagesBoundingRects[`${t}-${r}`]?.rect;if(o){const i=this.getDisplayedPageScale(t,r),l=(n-o.left-this.draggingElementShift.x)/i-this.draggingInitialMouseOffset.x/i,h=(a-o.top-this.draggingElementShift.y)/i-this.draggingInitialMouseOffset.y/i;s.allObjects[r]=s.allObjects[r].map(t=>t.id===e?{...t,x:l,y:h}:t)}return}if(void 0!==i.x||void 0!==i.y){const n=void 0!==i.x?i.x:a.x,o=void 0!==i.y?i.y:a.y,l=void 0!==i.width?i.width:a.width,h=void 0!==i.height?i.height:a.height;let c=r,d=0;for(let e=0;e<s.pages.length;e++){const i=this.getPageWidth(t,e),s=this.getPageHeight(t,e),r=Math.max(0,n),a=Math.max(0,o),u=Math.min(i,n+l),p=Math.min(s,o+h);if(u>r&&p>a){const t=(u-r)*(p-a);t>d&&(d=t,c=e)}}if(c!==r){const d=this.getPageWidth(t,c),u=this.getPageHeight(t,c),p=Math.max(0,Math.min(n,d-l)),g=Math.max(0,Math.min(o,u-h));s.allObjects[r]=s.allObjects[r].filter(t=>t.id!==e);const m={...a,...i,x:p,y:g};return s.allObjects[c].push(m),void(this.objectIndexCache[`${t}-${e}`]=c)}const u=this.getPageWidth(t,r),p=this.getPageHeight(t,r);if(n<0||o<0||n+l>u||o+h>p)return}s.allObjects=s.allObjects.map(t=>t.map(t=>t.id===e?{...t,...i}:t))}},deleteObject(t,e){if(t<0||t>=this.pdfDocuments.length)return;const i=this.pdfDocuments[t];i.allObjects=i.allObjects.map(t=>t.filter(t=>t.id!==e)),delete this.objectIndexCache[`${t}-${e}`]},checkAndMoveObjectPage(t,e,i,s){if(t<0||t>=this.pdfDocuments.length)return;const n=this.pdfDocuments[t],r=`${t}-${e}`;let a=this.objectIndexCache[r];if(void 0===a&&n.allObjects.forEach((t,i)=>{t.find(t=>t.id===e)&&(a=i,this.objectIndexCache[r]=i)}),void 0===a)return;const o=n.allObjects[a]?.find(t=>t.id===e);if(!o)return a;let l=a;for(const b in this.pagesBoundingRects){const{docIndex:e,pageIndex:n,rect:r}=this.pagesBoundingRects[b];if(e===t&&i>=r.left&&i<=r.right&&s>=r.top&&s<=r.bottom){l=n;break}}const h=this.pagesBoundingRects[`${t}-${l}`]?.rect;if(!h)return a;const c=this.getDisplayedPageScale(t,l),d=(i-h.left-this.draggingElementShift.x)/c-this.draggingInitialMouseOffset.x/c,u=(s-h.top-this.draggingElementShift.y)/c-this.draggingInitialMouseOffset.y/c,p=this.getPageWidth(t,l),g=this.getPageHeight(t,l),m=Math.max(0,Math.min(d,p-o.width)),f=Math.max(0,Math.min(u,g-o.height));return l!==a?(n.allObjects[a]=n.allObjects[a].filter(t=>t.id!==e),n.allObjects[l].push({...o,x:m,y:f}),this.objectIndexCache[r]=l):m===o.x&&f===o.y||(n.allObjects[a]=n.allObjects[a].map(t=>t.id===e?{...t,x:m,y:f}:t)),l},onMeasure(t,e,i){e<0||e>=this.pdfDocuments.length||(this.pdfDocuments[e].pagesScale[i]=t.scale,this.cachePageBounds(),this.autoFitZoom&&this.scheduleAutoFitZoom())},formatPageNumber(t,e){return this.pageCountFormat.replace("{currentPage}",t).replace("{totalPages}",e)},getPageWidth(t,e){const i=this.getPageComponent(t,e);if(!i)return 0;const s=this.pdfDocuments[t],n=s.pagesScale[e]||1;return i.getCanvasMeasurement().canvasWidth/n},getPageHeight(t,e){const i=this.getPageComponent(t,e);if(!i)return 0;const s=this.pdfDocuments[t],n=s.pagesScale[e]||1;return i.getCanvasMeasurement().canvasHeight/n},calculateOptimalScale(t){const e=this.$el?.clientWidth||0;if(!e||!t)return 1;const i=e-40;return Math.max(.1,Math.min(2,i/t))},scheduleAutoFitZoom(){this.zoomRafId||(this.zoomRafId=window.requestAnimationFrame(()=>{this.zoomRafId=0,this.adjustZoomToFit()}))},adjustZoomToFit(){if(!this.autoFitZoom||!this.pdfDocuments.length)return;const t=this.pdfDocuments.flatMap(t=>t.pageWidths||[]).filter(t=>t>0);let e=0;if(t.length)e=Math.max(...t);else{if(this.autoFitZoom)return void this.scheduleAutoFitZoom();const t=this.$el?.querySelectorAll("canvas");if(!t?.length)return;e=Math.max(...Array.from(t).map(t=>t.width/(this.scale||1)))}const i=this.calculateOptimalScale(e);Math.abs(i-this.scale)>.01&&(this.scale=i,this.visualScale=i,this.pdfDocuments.forEach(t=>{t.pagesScale=t.pagesScale.map(()=>this.scale)}),this.cachePageBounds())}}},hr=lr;var cr=Qn(hr,Gn,Wn,!1,null,"ddd8aa14",null);const dr=cr.exports;Oi.workerSrc=$n,dr.install=function(t){dr.install.installed||t.component(dr.name,dr)},"undefined"!==typeof window&&window.Vue&&dr.install(window.Vue);const ur=dr,pr=ur;return s=s["default"],s})());
23
23
  //# sourceMappingURL=pdf-elements.umd.min.js.map