@component-hook/pdf-canvas 0.1.3-alpha.2 → 0.1.3-alpha.3
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.
- package/dist/pdf-canvas.es.js +815 -795
- package/dist/pdf-canvas.umd.js +2 -2
- package/package.json +1 -1
package/dist/pdf-canvas.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(st,U){typeof exports=="object"&&typeof module<"u"?U(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],U):(st=typeof globalThis<"u"?globalThis:st||self,U(st["pdf-canvas"]={},st.Vue))})(this,function(st,U){"use strict";var
|
|
1
|
+
(function(st,U){typeof exports=="object"&&typeof module<"u"?U(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],U):(st=typeof globalThis<"u"?globalThis:st||self,U(st["pdf-canvas"]={},st.Vue))})(this,function(st,U){"use strict";var CS=Object.defineProperty;var nv=st=>{throw TypeError(st)};var AS=(st,U,Et)=>U in st?CS(st,U,{enumerable:!0,configurable:!0,writable:!0,value:Et}):st[U]=Et;var K=(st,U,Et)=>AS(st,typeof U!="symbol"?U+"":U,Et),sf=(st,U,Et)=>U.has(st)||nv("Cannot "+Et);var c=(st,U,Et)=>(sf(st,U,"read from private field"),Et?Et.call(st):U.get(st)),w=(st,U,Et)=>U.has(st)?nv("Cannot add the same private member more than once"):U instanceof WeakSet?U.add(st):U.set(st,Et),b=(st,U,Et,C)=>(sf(st,U,"write to private field"),C?C.call(st,Et):U.set(st,Et),Et),y=(st,U,Et)=>(sf(st,U,"access private method"),Et);var Je=(st,U,Et,C)=>({set _(tc){b(st,U,tc,Et)},get _(){return c(st,U,C)}});var Si,Gd,rf,oh,nr,rr,zs,Ci,ce,Td,or,B,me,Sa,Ca,Ud,Aa,rv,of,Ta,Wl,Xl,af,zl,ar,hr,We,lr,Ed,ov,Ce,av,hv,Yd,lv,hf,ah,cr,dr,dn,cv,dv,uv,Md,hh,Dd,is,lh,lf,qt,un,ch,$t,Od,gv,Eo,Xe,zt,Jt,ko,Ai,Mo,bs,Do,ur,Vs,ys,gr,dh,uh,gh,Gs,Oo,gn,Us,Ld,fn,fh,fr,ph,Po,Kt,gt,Ti,pr,mh,vh,bh,yh,_h,wh,xh,Sh,Ch,Ah,Th,Eh,kh,pn,Ys,Ei,Mh,j,qd,cf,fv,pv,$d,mv,vv,bv,df,yv,uf,gf,_v,Ee,Rn,wv,xv,ff,Sv,Vl,pf,ki,Mi,_s,Di,ze,Fo,ws,Dh,mf,mr,xs,de,Ro,vr,Zt,br,Io,jo,ue,Oh,yr,mn,Ph,_r,Pi,qs,No,Bo,ns,Lh,Fd,tt,vf,Fh,bf,yf,Cv,Av,_f,wf,xf,Tv,Ev,kv,Mv,Sf,Gl,wr,xr,Qt,Rd,Dv,Rh,Ho,vn,Cf,Af,Ih,jh,$s,Ov,Pv,Kd,Sr,Nh,Bh,Hh,Wh,Wo,bn,pt,Xo,zo,Xh,Tf,iv,yn,Fe,zh,Vh,Cr,Li,Gh,Uh,Ar,Vo,Go,_n,Uo,Yh,Yo,Tr,qh,$h,Er,kr,wn,qo,Fi,Lv,Fv,Ef,Ks,Qd,Rv,Iv,jd,xn,Ri,rs,Ea,Jd,Mr,Bd,Dr,$o,Zd,Ko,tu,Ii,Qs,Qo,Jo,Js,Or,Ul,Ss,Kh,kf,Sn,Cn,Pr,Fr,Zo,ta,Qh,Mf,Ge,ro,jv,Nv,ea,Hd,Wd,sa,Rr,Mt,ji,Ir,Jh,Zh,ia,Ni,Cs,Bi,tl,Hi,el,jr,Nr,mt,eu,Df,Bv,Hv,Wv,Xv,su,iu,Of,sl,il,nl,rl,ol,al,hl,Pf,ll,Br,Hr,Wr,zv,Lf,cl,dl,ul,gl,fl,As,Ue,pl,Ye,na,Bt,Vv,Gv,Uv,nu,Wi,ru,ou,Yv,Ff,qv,ml,An,Ts,Ae,$v,au,Kv,Qv,Rf,vl,ra,Zs,Xi,oa,aa,ti,rt,Xr,zr,bl,yl,ha,la,Tn,_l,Xd,zd,wl,If,ca,Vr,Vi,xl,qe,Sl,Rt,Re,Yl,ql,Jv,Cl,Al,Es,Gr,da,Vt,Tl,ua,El,kl,ks,ga,yt,jf,Nf,Zv,oo,tb,In,fa,Ml,En,Ur,pa,os,Dl,Ol,Yr,Ms,Te,$e,Vd,ma,qr,Gt,va,ei,Pl,et,Bf,Hf,eb,sb,ib,Wf,$l,as,ka,nb,hu,Kl,rb,ob,ab,hb,$r,Kr,Ll,Fl,Rl,Qr,si,Ui,hs,Jr,Zr,Yi,to,eo,kn,N,lb,cb,db,ub,Xf,gb,zf,fb,pb,mb,vb,bb,ao,Vf,lu,cu,Ma,Gf,du,qi,yb,Uf,_b,wb,Yf,uu,Ql,te,ee,Mn,$i,Dn,ba,ii,Il,Ki,ni,Ds,jl,ht,Jl,Zl,gu,qf,xb,Sb,Cb,$f,fu,Ab,so,ya,ri,io,Qi,Ji,Zi,Ke,On,_a,wa,fe,G,Pn,se,Tb,Kf,Qf,Jf,pu,oi,Bl,Ut,Ln,Hl,Zf,no,tp,Eb;var Et=typeof document<"u"?document.currentScript:null;function C(a,t,e){return(t=function(s){var i=function(n,r){if(typeof n!="object"||!n)return n;var o=n[Symbol.toPrimitive];if(o!==void 0){var h=o.call(n,r||"default");if(typeof h!="object")return h;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(n)}(s,"string");return typeof i=="symbol"?i:i+""}(t))in a?Object.defineProperty(a,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):a[t]=e,a}function tc(a,t){var e=Object.keys(a);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(a);t&&(s=s.filter(function(i){return Object.getOwnPropertyDescriptor(a,i).enumerable})),e.push.apply(e,s)}return e}function A(a){for(var t=1;t<arguments.length;t++){var e=arguments[t]!=null?arguments[t]:{};t%2?tc(Object(e),!0).forEach(function(s){C(a,s,e[s])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(e)):tc(Object(e)).forEach(function(s){Object.defineProperty(a,s,Object.getOwnPropertyDescriptor(e,s))})}return a}function xt(a,t){if(a==null)return{};var e,s,i=function(r,o){if(r==null)return{};var h={};for(var l in r)if({}.hasOwnProperty.call(r,l)){if(o.indexOf(l)>=0)continue;h[l]=r[l]}return h}(a,t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(a);for(s=0;s<n.length;s++)e=n[s],t.indexOf(e)>=0||{}.propertyIsEnumerable.call(a,e)&&(i[e]=a[e])}return i}function Ls(a,t){return t||(t=a.slice(0)),Object.freeze(Object.defineProperties(a,{raw:{value:Object.freeze(t)}}))}class ep{constructor(){C(this,"browserShadowBlurConstant",1),C(this,"DPI",96),C(this,"devicePixelRatio",typeof window<"u"?window.devicePixelRatio:1),C(this,"perfLimitSizeTotal",2097152),C(this,"maxCacheSideLimit",4096),C(this,"minCacheSideLimit",256),C(this,"disableStyleCopyPaste",!1),C(this,"enableGLFiltering",!0),C(this,"textureSize",4096),C(this,"forceGLPutImageData",!1),C(this,"cachesBoundsOfCurve",!0),C(this,"fontPaths",{}),C(this,"NUM_FRACTION_DIGITS",4)}}const ot=new class extends ep{constructor(a){super(),this.configure(a)}configure(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Object.assign(this,a)}addFonts(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};this.fontPaths=A(A({},this.fontPaths),a)}removeFonts(){(arguments.length>0&&arguments[0]!==void 0?arguments[0]:[]).forEach(a=>{delete this.fontPaths[a]})}clearFonts(){this.fontPaths={}}restoreDefaults(a){const t=new ep,e=(a==null?void 0:a.reduce((s,i)=>(s[i]=t[i],s),{}))||t;this.configure(e)}},hi=function(a){for(var t=arguments.length,e=new Array(t>1?t-1:0),s=1;s<t;s++)e[s-1]=arguments[s];return console[a]("fabric",...e)};class Fs extends Error{constructor(t,e){super("fabric: ".concat(t),e)}}class mu extends Fs{constructor(t){super("".concat(t," 'options.signal' is in 'aborted' state"))}}class kb{}class Mb extends kb{testPrecision(t,e){const s="precision ".concat(e,` float;
|
|
2
2
|
void main(){}`),i=t.createShader(t.FRAGMENT_SHADER);return!!i&&(t.shaderSource(i,s),t.compileShader(i),!!t.getShaderParameter(i,t.COMPILE_STATUS))}queryWebGL(t){const e=t.getContext("webgl");e&&(this.maxTextureSize=e.getParameter(e.MAX_TEXTURE_SIZE),this.GLPrecision=["highp","mediump","lowp"].find(s=>this.testPrecision(e,s)),e.getExtension("WEBGL_lose_context").loseContext(),hi("log","WebGL: max texture size ".concat(this.maxTextureSize)))}isSupported(t){return!!this.maxTextureSize&&this.maxTextureSize>=t}}const Db={};let sp;const Rs=()=>sp||(sp={document,window,isTouchSupported:"ontouchstart"in window||"ontouchstart"in document||window&&window.navigator&&window.navigator.maxTouchPoints>0,WebGLProbe:new Mb,dispose(){},copyPasteData:Db}),ho=()=>Rs().document,ec=()=>Rs().window,ip=()=>{var a;return Math.max((a=ot.devicePixelRatio)!==null&&a!==void 0?a:ec().devicePixelRatio,1)},Da=new class{constructor(){C(this,"charWidthsCache",{}),C(this,"boundsOfCurveCache",{})}getFontCache(a){let{fontFamily:t,fontStyle:e,fontWeight:s}=a;t=t.toLowerCase(),this.charWidthsCache[t]||(this.charWidthsCache[t]={});const i=this.charWidthsCache[t],n="".concat(e.toLowerCase(),"_").concat((s+"").toLowerCase());return i[n]||(i[n]={}),i[n]}clearFontCache(a){(a=(a||"").toLowerCase())?this.charWidthsCache[a]&&delete this.charWidthsCache[a]:this.charWidthsCache={}}limitDimsByArea(a){const{perfLimitSizeTotal:t}=ot,e=Math.sqrt(t*a);return[Math.floor(e),Math.floor(t/e)]}},vu="6.3.0";function jn(){}const tn=Math.PI/2,li=2*Math.PI,bu=Math.PI/180,ve=Object.freeze([1,0,0,1,0,0]),yu=16,en=.4477152502,Q="center",ct="left",ke="top",_u="bottom",Dt="right",be="none",wu=/\r?\n/,np="moving",sc="scaling",rp="rotating",xu="rotate",op="skewing",Oa="resizing",Ob="modifyPoly",Pb="modifyPath",ic="changed",nc="scale",ye="scaleX",je="scaleY",lo="skewX",co="skewY",Ot="fill",_e="stroke",rc="modified",uo="json",Su="svg",H=new class{constructor(){this[uo]=new Map,this[Su]=new Map}has(a){return this[uo].has(a)}getClass(a){const t=this[uo].get(a);if(!t)throw new Fs("No class registered for ".concat(a));return t}setClass(a,t){t?this[uo].set(t,a):(this[uo].set(a.type,a),this[uo].set(a.type.toLowerCase(),a))}getSVGClass(a){return this[Su].get(a)}setSVGClass(a,t){this[Su].set(t??a.type.toLowerCase(),a)}},oc=new class extends Array{remove(a){const t=this.indexOf(a);t>-1&&this.splice(t,1)}cancelAll(){const a=this.splice(0);return a.forEach(t=>t.abort()),a}cancelByCanvas(a){if(!a)return[];const t=this.filter(e=>{var s;return e.target===a||typeof e.target=="object"&&((s=e.target)===null||s===void 0?void 0:s.canvas)===a});return t.forEach(e=>e.abort()),t}cancelByTarget(a){if(!a)return[];const t=this.filter(e=>e.target===a);return t.forEach(e=>e.abort()),t}};class Lb{constructor(){C(this,"__eventListeners",{})}on(t,e){if(this.__eventListeners||(this.__eventListeners={}),typeof t=="object")return Object.entries(t).forEach(s=>{let[i,n]=s;this.on(i,n)}),()=>this.off(t);if(e){const s=t;return this.__eventListeners[s]||(this.__eventListeners[s]=[]),this.__eventListeners[s].push(e),()=>this.off(s,e)}return()=>!1}once(t,e){if(typeof t=="object"){const s=[];return Object.entries(t).forEach(i=>{let[n,r]=i;s.push(this.once(n,r))}),()=>s.forEach(i=>i())}if(e){const s=this.on(t,function(){for(var i=arguments.length,n=new Array(i),r=0;r<i;r++)n[r]=arguments[r];e.call(this,...n),s()});return s}return()=>!1}_removeEventListener(t,e){if(this.__eventListeners[t])if(e){const s=this.__eventListeners[t],i=s.indexOf(e);i>-1&&s.splice(i,1)}else this.__eventListeners[t]=[]}off(t,e){if(this.__eventListeners)if(t===void 0)for(const s in this.__eventListeners)this._removeEventListener(s);else typeof t=="object"?Object.entries(t).forEach(s=>{let[i,n]=s;this._removeEventListener(i,n)}):this._removeEventListener(t,e)}fire(t,e){var s;if(!this.__eventListeners)return;const i=(s=this.__eventListeners[t])===null||s===void 0?void 0:s.concat();if(i)for(let n=0;n<i.length;n++)i[n].call(this,e||{})}}const Nn=(a,t)=>{const e=a.indexOf(t);return e!==-1&&a.splice(e,1),a},cs=a=>{if(a===0)return 1;switch(Math.abs(a)/tn){case 1:case 3:return 0;case 2:return-1}return Math.cos(a)},ds=a=>{if(a===0)return 0;const t=a/tn,e=Math.sign(a);switch(t){case 1:return e;case 2:return 0;case 3:return-e}return Math.sin(a)};class k{constructor(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0;typeof t=="object"?(this.x=t.x,this.y=t.y):(this.x=t,this.y=e)}add(t){return new k(this.x+t.x,this.y+t.y)}addEquals(t){return this.x+=t.x,this.y+=t.y,this}scalarAdd(t){return new k(this.x+t,this.y+t)}scalarAddEquals(t){return this.x+=t,this.y+=t,this}subtract(t){return new k(this.x-t.x,this.y-t.y)}subtractEquals(t){return this.x-=t.x,this.y-=t.y,this}scalarSubtract(t){return new k(this.x-t,this.y-t)}scalarSubtractEquals(t){return this.x-=t,this.y-=t,this}multiply(t){return new k(this.x*t.x,this.y*t.y)}scalarMultiply(t){return new k(this.x*t,this.y*t)}scalarMultiplyEquals(t){return this.x*=t,this.y*=t,this}divide(t){return new k(this.x/t.x,this.y/t.y)}scalarDivide(t){return new k(this.x/t,this.y/t)}scalarDivideEquals(t){return this.x/=t,this.y/=t,this}eq(t){return this.x===t.x&&this.y===t.y}lt(t){return this.x<t.x&&this.y<t.y}lte(t){return this.x<=t.x&&this.y<=t.y}gt(t){return this.x>t.x&&this.y>t.y}gte(t){return this.x>=t.x&&this.y>=t.y}lerp(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:.5;return e=Math.max(Math.min(1,e),0),new k(this.x+(t.x-this.x)*e,this.y+(t.y-this.y)*e)}distanceFrom(t){const e=this.x-t.x,s=this.y-t.y;return Math.sqrt(e*e+s*s)}midPointFrom(t){return this.lerp(t)}min(t){return new k(Math.min(this.x,t.x),Math.min(this.y,t.y))}max(t){return new k(Math.max(this.x,t.x),Math.max(this.y,t.y))}toString(){return"".concat(this.x,",").concat(this.y)}setXY(t,e){return this.x=t,this.y=e,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setFromPoint(t){return this.x=t.x,this.y=t.y,this}swap(t){const e=this.x,s=this.y;this.x=t.x,this.y=t.y,t.x=e,t.y=s}clone(){return new k(this.x,this.y)}rotate(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Cu;const s=ds(t),i=cs(t),n=this.subtract(e);return new k(n.x*i-n.y*s,n.x*s+n.y*i).add(e)}transform(t){let e=arguments.length>1&&arguments[1]!==void 0&&arguments[1];return new k(t[0]*this.x+t[2]*this.y+(e?0:t[4]),t[1]*this.x+t[3]*this.y+(e?0:t[5]))}}const Cu=new k(0,0),ac=a=>!!a&&Array.isArray(a._objects);function ap(a){class t extends a{constructor(){super(...arguments),C(this,"_objects",[])}_onObjectAdded(s){}_onObjectRemoved(s){}_onStackOrderChanged(s){}add(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];const r=this._objects.push(...i);return i.forEach(o=>this._onObjectAdded(o)),r}insertAt(s){for(var i=arguments.length,n=new Array(i>1?i-1:0),r=1;r<i;r++)n[r-1]=arguments[r];return this._objects.splice(s,0,...n),n.forEach(o=>this._onObjectAdded(o)),this._objects.length}remove(){const s=this._objects,i=[];for(var n=arguments.length,r=new Array(n),o=0;o<n;o++)r[o]=arguments[o];return r.forEach(h=>{const l=s.indexOf(h);l!==-1&&(s.splice(l,1),i.push(h),this._onObjectRemoved(h))}),i}forEachObject(s){this.getObjects().forEach((i,n,r)=>s(i,n,r))}getObjects(){for(var s=arguments.length,i=new Array(s),n=0;n<s;n++)i[n]=arguments[n];return i.length===0?[...this._objects]:this._objects.filter(r=>r.isType(...i))}item(s){return this._objects[s]}isEmpty(){return this._objects.length===0}size(){return this._objects.length}contains(s,i){return!!this._objects.includes(s)||!!i&&this._objects.some(n=>n instanceof t&&n.contains(s,!0))}complexity(){return this._objects.reduce((s,i)=>s+=i.complexity?i.complexity():0,0)}sendObjectToBack(s){return!(!s||s===this._objects[0])&&(Nn(this._objects,s),this._objects.unshift(s),this._onStackOrderChanged(s),!0)}bringObjectToFront(s){return!(!s||s===this._objects[this._objects.length-1])&&(Nn(this._objects,s),this._objects.push(s),this._onStackOrderChanged(s),!0)}sendObjectBackwards(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==0){const r=this.findNewLowerIndex(s,n,i);return Nn(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}bringObjectForward(s,i){if(!s)return!1;const n=this._objects.indexOf(s);if(n!==this._objects.length-1){const r=this.findNewUpperIndex(s,n,i);return Nn(this._objects,s),this._objects.splice(r,0,s),this._onStackOrderChanged(s),!0}return!1}moveObjectTo(s,i){return s!==this._objects[i]&&(Nn(this._objects,s),this._objects.splice(i,0,s),this._onStackOrderChanged(s),!0)}findNewLowerIndex(s,i,n){let r;if(n){r=i;for(let o=i-1;o>=0;--o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i-1;return r}findNewUpperIndex(s,i,n){let r;if(n){r=i;for(let o=i+1;o<this._objects.length;++o)if(s.isOverlapping(this._objects[o])){r=o;break}}else r=i+1;return r}collectObjects(s){let{left:i,top:n,width:r,height:o}=s,{includeIntersecting:h=!0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const l=[],d=new k(i,n),u=d.add(new k(r,o));for(let g=this._objects.length-1;g>=0;g--){const f=this._objects[g];f.selectable&&f.visible&&(h&&f.intersectsWithRect(d,u)||f.isContainedWithinRect(d,u)||h&&f.containsPoint(d)||h&&f.containsPoint(u))&&l.push(f)}return l}}return t}class hp extends Lb{_setOptions(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};for(const e in t)this.set(e,t[e])}_setObject(t){for(const e in t)this._set(e,t[e])}set(t,e){return typeof t=="object"?this._setObject(t):this._set(t,e),this}_set(t,e){this[t]=e}toggle(t){const e=this.get(t);return typeof e=="boolean"&&this.set(t,!e),this}get(t){return this[t]}}function Pa(a){return ec().requestAnimationFrame(a)}function lp(a){return ec().cancelAnimationFrame(a)}let Fb=0;const sn=()=>Fb++,Pt=()=>{const a=ho().createElement("canvas");if(!a||a.getContext===void 0)throw new Fs("Failed to create `canvas` element");return a},cp=()=>ho().createElement("img"),Au=(a,t,e)=>a.toDataURL("image/".concat(t),e),kt=a=>a*bu,nn=a=>a/bu,dp=a=>a.every((t,e)=>t===ve[e]),ne=(a,t,e)=>new k(a).transform(t,e),Me=a=>{const t=1/(a[0]*a[3]-a[1]*a[2]),e=[t*a[3],-t*a[1],-t*a[2],t*a[0],0,0],{x:s,y:i}=new k(a[4],a[5]).transform(e,!0);return e[4]=-s,e[5]=-i,e},Lt=(a,t,e)=>[a[0]*t[0]+a[2]*t[1],a[1]*t[0]+a[3]*t[1],a[0]*t[2]+a[2]*t[3],a[1]*t[2]+a[3]*t[3],e?0:a[0]*t[4]+a[2]*t[5]+a[4],e?0:a[1]*t[4]+a[3]*t[5]+a[5]],hc=(a,t)=>a.reduceRight((e,s)=>s&&e?Lt(s,e,t):s||e,void 0)||ve.concat(),up=a=>{let[t,e]=a;return Math.atan2(e,t)},Bn=a=>{const t=up(a),e=Math.pow(a[0],2)+Math.pow(a[1],2),s=Math.sqrt(e),i=(a[0]*a[3]-a[2]*a[1])/s,n=Math.atan2(a[0]*a[2]+a[1]*a[3],e);return{angle:nn(t),scaleX:s,scaleY:i,skewX:nn(n),skewY:0,translateX:a[4]||0,translateY:a[5]||0}},go=function(a){return[1,0,0,1,a,arguments.length>1&&arguments[1]!==void 0?arguments[1]:0]};function fo(){let{angle:a=0}=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},{x:t=0,y:e=0}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};const s=kt(a),i=cs(s),n=ds(s);return[i,n,-n,i,t?t-(i*t-n*e):0,e?e-(n*t+i*e):0]}const lc=function(a){return[a,0,0,arguments.length>1&&arguments[1]!==void 0?arguments[1]:a,0,0]},gp=a=>Math.tan(kt(a)),Tu=a=>[1,0,gp(a),1,0,0],Eu=a=>[1,gp(a),0,1,0,0],La=a=>{let{scaleX:t=1,scaleY:e=1,flipX:s=!1,flipY:i=!1,skewX:n=0,skewY:r=0}=a,o=lc(s?-t:t,i?-e:e);return n&&(o=Lt(o,Tu(n),!0)),r&&(o=Lt(o,Eu(r),!0)),o},fp=a=>{const{translateX:t=0,translateY:e=0,angle:s=0}=a;let i=go(t,e);s&&(i=Lt(i,fo({angle:s})));const n=La(a);return dp(n)||(i=Lt(i,n)),i},Fa=function(a){let{signal:t,crossOrigin:e=null}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise(function(s,i){if(t&&t.aborted)return i(new mu("loadImage"));const n=cp();let r;t&&(r=function(h){n.src="",i(h)},t.addEventListener("abort",r,{once:!0}));const o=function(){n.onload=n.onerror=null,r&&(t==null||t.removeEventListener("abort",r)),s(n)};a?(n.onload=o,n.onerror=function(){r&&(t==null||t.removeEventListener("abort",r)),i(new Fs("Error loading ".concat(n.src)))},e&&(n.crossOrigin=e),n.src=a):o()})},po=function(a){let{signal:t,reviver:e=jn}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((s,i)=>{const n=[];t&&t.addEventListener("abort",i,{once:!0}),Promise.all(a.map(r=>H.getClass(r.type).fromObject(r,{signal:t}).then(o=>(e(r,o),n.push(o),o)))).then(s).catch(r=>{n.forEach(o=>{o.dispose&&o.dispose()}),i(r)}).finally(()=>{t&&t.removeEventListener("abort",i)})})},Ra=function(a){let{signal:t}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return new Promise((e,s)=>{const i=[];t&&t.addEventListener("abort",s,{once:!0});const n=Object.values(a).map(o=>o&&o.type&&H.has(o.type)?po([o],{signal:t}).then(h=>{let[l]=h;return i.push(l),l}):o),r=Object.keys(a);Promise.all(n).then(o=>o.reduce((h,l,d)=>(h[r[d]]=l,h),{})).then(e).catch(o=>{i.forEach(h=>{h.dispose&&h.dispose()}),s(o)}).finally(()=>{t&&t.removeEventListener("abort",s)})})},Hn=function(a){return(arguments.length>1&&arguments[1]!==void 0?arguments[1]:[]).reduce((t,e)=>(e in a&&(t[e]=a[e]),t),{})},ku=(a,t)=>Object.keys(a).reduce((e,s)=>(t(a[s],s,a)&&(e[s]=a[s]),e),{}),pp={aliceblue:"#F0F8FF",antiquewhite:"#FAEBD7",aqua:"#0FF",aquamarine:"#7FFFD4",azure:"#F0FFFF",beige:"#F5F5DC",bisque:"#FFE4C4",black:"#000",blanchedalmond:"#FFEBCD",blue:"#00F",blueviolet:"#8A2BE2",brown:"#A52A2A",burlywood:"#DEB887",cadetblue:"#5F9EA0",chartreuse:"#7FFF00",chocolate:"#D2691E",coral:"#FF7F50",cornflowerblue:"#6495ED",cornsilk:"#FFF8DC",crimson:"#DC143C",cyan:"#0FF",darkblue:"#00008B",darkcyan:"#008B8B",darkgoldenrod:"#B8860B",darkgray:"#A9A9A9",darkgrey:"#A9A9A9",darkgreen:"#006400",darkkhaki:"#BDB76B",darkmagenta:"#8B008B",darkolivegreen:"#556B2F",darkorange:"#FF8C00",darkorchid:"#9932CC",darkred:"#8B0000",darksalmon:"#E9967A",darkseagreen:"#8FBC8F",darkslateblue:"#483D8B",darkslategray:"#2F4F4F",darkslategrey:"#2F4F4F",darkturquoise:"#00CED1",darkviolet:"#9400D3",deeppink:"#FF1493",deepskyblue:"#00BFFF",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1E90FF",firebrick:"#B22222",floralwhite:"#FFFAF0",forestgreen:"#228B22",fuchsia:"#F0F",gainsboro:"#DCDCDC",ghostwhite:"#F8F8FF",gold:"#FFD700",goldenrod:"#DAA520",gray:"#808080",grey:"#808080",green:"#008000",greenyellow:"#ADFF2F",honeydew:"#F0FFF0",hotpink:"#FF69B4",indianred:"#CD5C5C",indigo:"#4B0082",ivory:"#FFFFF0",khaki:"#F0E68C",lavender:"#E6E6FA",lavenderblush:"#FFF0F5",lawngreen:"#7CFC00",lemonchiffon:"#FFFACD",lightblue:"#ADD8E6",lightcoral:"#F08080",lightcyan:"#E0FFFF",lightgoldenrodyellow:"#FAFAD2",lightgray:"#D3D3D3",lightgrey:"#D3D3D3",lightgreen:"#90EE90",lightpink:"#FFB6C1",lightsalmon:"#FFA07A",lightseagreen:"#20B2AA",lightskyblue:"#87CEFA",lightslategray:"#789",lightslategrey:"#789",lightsteelblue:"#B0C4DE",lightyellow:"#FFFFE0",lime:"#0F0",limegreen:"#32CD32",linen:"#FAF0E6",magenta:"#F0F",maroon:"#800000",mediumaquamarine:"#66CDAA",mediumblue:"#0000CD",mediumorchid:"#BA55D3",mediumpurple:"#9370DB",mediumseagreen:"#3CB371",mediumslateblue:"#7B68EE",mediumspringgreen:"#00FA9A",mediumturquoise:"#48D1CC",mediumvioletred:"#C71585",midnightblue:"#191970",mintcream:"#F5FFFA",mistyrose:"#FFE4E1",moccasin:"#FFE4B5",navajowhite:"#FFDEAD",navy:"#000080",oldlace:"#FDF5E6",olive:"#808000",olivedrab:"#6B8E23",orange:"#FFA500",orangered:"#FF4500",orchid:"#DA70D6",palegoldenrod:"#EEE8AA",palegreen:"#98FB98",paleturquoise:"#AFEEEE",palevioletred:"#DB7093",papayawhip:"#FFEFD5",peachpuff:"#FFDAB9",peru:"#CD853F",pink:"#FFC0CB",plum:"#DDA0DD",powderblue:"#B0E0E6",purple:"#800080",rebeccapurple:"#639",red:"#F00",rosybrown:"#BC8F8F",royalblue:"#4169E1",saddlebrown:"#8B4513",salmon:"#FA8072",sandybrown:"#F4A460",seagreen:"#2E8B57",seashell:"#FFF5EE",sienna:"#A0522D",silver:"#C0C0C0",skyblue:"#87CEEB",slateblue:"#6A5ACD",slategray:"#708090",slategrey:"#708090",snow:"#FFFAFA",springgreen:"#00FF7F",steelblue:"#4682B4",tan:"#D2B48C",teal:"#008080",thistle:"#D8BFD8",tomato:"#FF6347",turquoise:"#40E0D0",violet:"#EE82EE",wheat:"#F5DEB3",white:"#FFF",whitesmoke:"#F5F5F5",yellow:"#FF0",yellowgreen:"#9ACD32"},Mu=(a,t,e)=>(e<0&&(e+=1),e>1&&(e-=1),e<1/6?a+6*(t-a)*e:e<.5?t:e<2/3?a+(t-a)*(2/3-e)*6:a),mp=(a,t,e,s)=>{a/=255,t/=255,e/=255;const i=Math.max(a,t,e),n=Math.min(a,t,e);let r,o;const h=(i+n)/2;if(i===n)r=o=0;else{const l=i-n;switch(o=h>.5?l/(2-i-n):l/(i+n),i){case a:r=(t-e)/l+(t<e?6:0);break;case t:r=(e-a)/l+2;break;case e:r=(a-t)/l+4}r/=6}return[Math.round(360*r),Math.round(100*o),Math.round(100*h),s]},vp=function(){let a=arguments.length>0&&arguments[0]!==void 0?arguments[0]:"1";return parseFloat(a)/(a.endsWith("%")?100:1)},cc=a=>Math.min(Math.round(a),255).toString(16).toUpperCase().padStart(2,"0"),bp=a=>{let[t,e,s,i=1]=a;const n=Math.round(.3*t+.59*e+.11*s);return[n,n,n,i]};class ut{constructor(t){if(C(this,"isUnrecognised",!1),t)if(t instanceof ut)this.setSource([...t._source]);else if(Array.isArray(t)){const[e,s,i,n=1]=t;this.setSource([e,s,i,n])}else this.setSource(this._tryParsingColor(t));else this.setSource([0,0,0,1])}_tryParsingColor(t){return t in pp&&(t=pp[t]),t==="transparent"?[255,255,255,0]:ut.sourceFromHex(t)||ut.sourceFromRgb(t)||ut.sourceFromHsl(t)||(this.isUnrecognised=!0)&&[0,0,0,1]}getSource(){return this._source}setSource(t){this._source=t}toRgb(){const[t,e,s]=this.getSource();return"rgb(".concat(t,",").concat(e,",").concat(s,")")}toRgba(){return"rgba(".concat(this.getSource().join(","),")")}toHsl(){const[t,e,s]=mp(...this.getSource());return"hsl(".concat(t,",").concat(e,"%,").concat(s,"%)")}toHsla(){const[t,e,s,i]=mp(...this.getSource());return"hsla(".concat(t,",").concat(e,"%,").concat(s,"%,").concat(i,")")}toHex(){return this.toHexa().slice(0,6)}toHexa(){const[t,e,s,i]=this.getSource();return"".concat(cc(t)).concat(cc(e)).concat(cc(s)).concat(cc(Math.round(255*i)))}getAlpha(){return this.getSource()[3]}setAlpha(t){return this._source[3]=t,this}toGrayscale(){return this.setSource(bp(this.getSource())),this}toBlackWhite(t){const[e,,,s]=bp(this.getSource()),i=e<(t||127)?0:255;return this.setSource([i,i,i,s]),this}overlayWith(t){t instanceof ut||(t=new ut(t));const e=this.getSource(),s=t.getSource(),[i,n,r]=e.map((o,h)=>Math.round(.5*o+.5*s[h]));return this.setSource([i,n,r,e[3]]),this}static fromRgb(t){return ut.fromRgba(t)}static fromRgba(t){return new ut(ut.sourceFromRgb(t))}static sourceFromRgb(t){const e=t.match(/^rgba?\(\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d{0,3}(?:\.\d+)?%?)\s*)?\)$/i);if(e){const[s,i,n]=e.slice(1,4).map(r=>{const o=parseFloat(r);return r.endsWith("%")?Math.round(2.55*o):o});return[s,i,n,vp(e[4])]}}static fromHsl(t){return ut.fromHsla(t)}static fromHsla(t){return new ut(ut.sourceFromHsl(t))}static sourceFromHsl(t){const e=t.match(/^hsla?\(\s*([+-]?\d{0,3}(?:\.\d+)?(?:deg|turn|rad)?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*[\s|,]\s*(\d{0,3}(?:\.\d+)?%?)\s*(?:\s*[,/]\s*(\d*(?:\.\d+)?%?)\s*)?\)$/i);if(!e)return;const s=(ut.parseAngletoDegrees(e[1])%360+360)%360/360,i=parseFloat(e[2])/100,n=parseFloat(e[3])/100;let r,o,h;if(i===0)r=o=h=n;else{const l=n<=.5?n*(i+1):n+i-n*i,d=2*n-l;r=Mu(d,l,s+1/3),o=Mu(d,l,s),h=Mu(d,l,s-1/3)}return[Math.round(255*r),Math.round(255*o),Math.round(255*h),vp(e[4])]}static fromHex(t){return new ut(ut.sourceFromHex(t))}static sourceFromHex(t){if(t.match(/^#?(([0-9a-f]){3,4}|([0-9a-f]{2}){3,4})$/i)){const e=t.slice(t.indexOf("#")+1);let s;s=e.length<=4?e.split("").map(h=>h+h):e.match(/.{2}/g);const[i,n,r,o=255]=s.map(h=>parseInt(h,16));return[i,n,r,o/255]}}static parseAngletoDegrees(t){const e=t.toLowerCase(),s=parseFloat(e);return e.includes("rad")?nn(s):e.includes("turn")?360*s:s}}const it=(a,t)=>parseFloat(Number(a).toFixed(t)),we=function(a){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:yu;const e=/\D{0,2}$/.exec(a),s=parseFloat(a),i=ot.DPI;switch(e==null?void 0:e[0]){case"mm":return s*i/25.4;case"cm":return s*i/2.54;case"in":return s*i;case"pt":return s*i/72;case"pc":return s*i/72*12;case"em":return s*t;default:return s}},Du=a=>{const[t,e]=a.trim().split(" "),[s,i]=(n=t)&&n!==be?[n.slice(1,4),n.slice(5,8)]:n===be?[n,n]:["Mid","Mid"];var n;return{meetOrSlice:e||"meet",alignX:s,alignY:i}},Ia=a=>"matrix("+a.map(t=>it(t,ot.NUM_FRACTION_DIGITS)).join(" ")+")",ja=function(a,t){let e,s,i=!(arguments.length>2&&arguments[2]!==void 0)||arguments[2];if(t)if(t.toLive)e="url(#SVGID_".concat(t.id,")");else{const n=new ut(t),r=n.getAlpha();e=n.toRgb(),r!==1&&(s=r.toString())}else e="none";return i?"".concat(a,": ").concat(e,"; ").concat(s?"".concat(a,"-opacity: ").concat(s,"; "):""):"".concat(a,'="').concat(e,'" ').concat(s?"".concat(a,'-opacity="').concat(s,'" '):"")},Ze=a=>!!a&&a.toLive!==void 0,yp=a=>!!a&&typeof a.toObject=="function",_p=a=>!!a&&a.offsetX!==void 0&&"source"in a,wp=a=>!!a&&typeof a._renderText=="function",Wn=a=>!!a&&"multiSelectionStacking"in a;function xp(a){const t=a&&us(a);let e=0,s=0;if(!a||!t)return{left:e,top:s};let i=a;const n=t.documentElement,r=t.body||{scrollLeft:0,scrollTop:0};for(;i&&(i.parentNode||i.host)&&(i=i.parentNode||i.host,i===t?(e=r.scrollLeft||n.scrollLeft||0,s=r.scrollTop||n.scrollTop||0):(e+=i.scrollLeft||0,s+=i.scrollTop||0),i.nodeType!==1||i.style.position!=="fixed"););return{left:e,top:s}}const us=a=>a.ownerDocument||null,Sp=a=>{var t;return((t=a.ownerDocument)===null||t===void 0?void 0:t.defaultView)||null};function Na(a,t){const e=a.style;e&&(typeof t=="string"?a.style.cssText+=";"+t:Object.entries(t).forEach(s=>{let[i,n]=s;return e.setProperty(i,n)}))}const Cp=function(a,t,e){let{width:s,height:i}=e,n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:1;a.width=s,a.height=i,n>1&&(a.setAttribute("width",(s*n).toString()),a.setAttribute("height",(i*n).toString()),t.scale(n,n))},Ou=(a,t)=>{let{width:e,height:s}=t;e&&(a.style.width=typeof e=="number"?"".concat(e,"px"):e),s&&(a.style.height=typeof s=="number"?"".concat(s,"px"):s)};function Ap(a){return a.onselectstart!==void 0&&(a.onselectstart=()=>!1),a.style.userSelect=be,a}class Tp{constructor(t){C(this,"_originalCanvasStyle",void 0),C(this,"lower",void 0);const e=this.createLowerCanvas(t);this.lower={el:e,ctx:e.getContext("2d")}}createLowerCanvas(t){const e=(s=t)&&s.getContext!==void 0?t:t&&ho().getElementById(t)||Pt();var s;if(e.hasAttribute("data-fabric"))throw new Fs("Trying to initialize a canvas that has already been initialized. Did you forget to dispose the canvas?");return this._originalCanvasStyle=e.style.cssText,e.setAttribute("data-fabric","main"),e.classList.add("lower-canvas"),e}cleanupDOM(t){let{width:e,height:s}=t;const{el:i}=this.lower;i.classList.remove("lower-canvas"),i.removeAttribute("data-fabric"),i.setAttribute("width","".concat(e)),i.setAttribute("height","".concat(s)),i.style.cssText=this._originalCanvasStyle||"",this._originalCanvasStyle=void 0}setDimensions(t,e){const{el:s,ctx:i}=this.lower;Cp(s,i,t,e)}setCSSDimensions(t){Ou(this.lower.el,t)}calcOffset(){return function(t){var e;const s=t&&us(t),i={left:0,top:0};if(!s)return i;const n=((e=Sp(t))===null||e===void 0?void 0:e.getComputedStyle(t,null))||{};i.left+=parseInt(n.borderLeftWidth,10)||0,i.top+=parseInt(n.borderTopWidth,10)||0,i.left+=parseInt(n.paddingLeft,10)||0,i.top+=parseInt(n.paddingTop,10)||0;let r={left:0,top:0};const o=s.documentElement;t.getBoundingClientRect!==void 0&&(r=t.getBoundingClientRect());const h=xp(t);return{left:r.left+h.left-(o.clientLeft||0)+i.left,top:r.top+h.top-(o.clientTop||0)+i.top}}(this.lower.el)}dispose(){Rs().dispose(this.lower.el),delete this.lower}}const Rb={backgroundVpt:!0,backgroundColor:"",overlayVpt:!0,overlayColor:"",includeDefaultValues:!0,svgViewportTransformation:!0,renderOnAddRemove:!0,skipOffscreen:!0,enableRetinaScaling:!0,imageSmoothingEnabled:!0,controlsAboveOverlay:!1,allowTouchScrolling:!1,viewportTransform:[...ve]};class Ba extends ap(hp){get lowerCanvasEl(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.el}get contextContainer(){var t;return(t=this.elements.lower)===null||t===void 0?void 0:t.ctx}static getDefaults(){return Ba.ownDefaults}constructor(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};super(),Object.assign(this,this.constructor.getDefaults()),this.set(e),this.initElements(t),this._setDimensionsImpl({width:this.width||this.elements.lower.el.width||0,height:this.height||this.elements.lower.el.height||0}),this.skipControlsDrawing=!1,this.viewportTransform=[...this.viewportTransform],this.calcViewportBoundaries()}initElements(t){this.elements=new Tp(t)}add(){const t=super.add(...arguments);return arguments.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}insertAt(t){for(var e=arguments.length,s=new Array(e>1?e-1:0),i=1;i<e;i++)s[i-1]=arguments[i];const n=super.insertAt(t,...s);return s.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),n}remove(){const t=super.remove(...arguments);return t.length>0&&this.renderOnAddRemove&&this.requestRenderAll(),t}_onObjectAdded(t){t.canvas&&t.canvas!==this&&(hi("warn",`Canvas is trying to add an object that belongs to a different canvas.
|
|
3
3
|
Resulting to default behavior: removing object from previous canvas and adding to new canvas`),t.canvas.remove(t)),t._set("canvas",this),t.setCoords(),this.fire("object:added",{target:t}),t.fire("added",{target:this})}_onObjectRemoved(t){t._set("canvas",void 0),this.fire("object:removed",{target:t}),t.fire("removed",{target:this})}_onStackOrderChanged(){this.renderOnAddRemove&&this.requestRenderAll()}getRetinaScaling(){return this.enableRetinaScaling?ip():1}calcOffset(){return this._offset=this.elements.calcOffset()}getWidth(){return this.width}getHeight(){return this.height}setWidth(t,e){return this.setDimensions({width:t},e)}setHeight(t,e){return this.setDimensions({height:t},e)}_setDimensionsImpl(t){let{cssOnly:e=!1,backstoreOnly:s=!1}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(!e){const i=A({width:this.width,height:this.height},t);this.elements.setDimensions(i,this.getRetinaScaling()),this.hasLostContext=!0,this.width=i.width,this.height=i.height}s||this.elements.setCSSDimensions(t),this.calcOffset()}setDimensions(t,e){this._setDimensionsImpl(t,e),e&&e.cssOnly||this.requestRenderAll()}getZoom(){return this.viewportTransform[0]}setViewportTransform(t){this.viewportTransform=t,this.calcViewportBoundaries(),this.renderOnAddRemove&&this.requestRenderAll()}zoomToPoint(t,e){const s=t,i=[...this.viewportTransform],n=ne(t,Me(i));i[0]=e,i[3]=e;const r=ne(n,i);i[4]+=s.x-r.x,i[5]+=s.y-r.y,this.setViewportTransform(i)}setZoom(t){this.zoomToPoint(new k(0,0),t)}absolutePan(t){const e=[...this.viewportTransform];return e[4]=-t.x,e[5]=-t.y,this.setViewportTransform(e)}relativePan(t){return this.absolutePan(new k(-t.x-this.viewportTransform[4],-t.y-this.viewportTransform[5]))}getElement(){return this.elements.lower.el}clearContext(t){t.clearRect(0,0,this.width,this.height)}getContext(){return this.elements.lower.ctx}clear(){this.remove(...this.getObjects()),this.backgroundImage=void 0,this.overlayImage=void 0,this.backgroundColor="",this.overlayColor="",this.clearContext(this.getContext()),this.fire("canvas:cleared"),this.renderOnAddRemove&&this.requestRenderAll()}renderAll(){this.cancelRequestedRender(),this.destroyed||this.renderCanvas(this.getContext(),this._objects)}renderAndReset(){this.nextRenderHandle=0,this.renderAll()}requestRenderAll(){this.nextRenderHandle||this.disposed||this.destroyed||(this.nextRenderHandle=Pa(()=>this.renderAndReset()))}calcViewportBoundaries(){const t=this.width,e=this.height,s=Me(this.viewportTransform),i=ne({x:0,y:0},s),n=ne({x:t,y:e},s),r=i.min(n),o=i.max(n);return this.vptCoords={tl:r,tr:new k(o.x,r.y),bl:new k(r.x,o.y),br:o}}cancelRequestedRender(){this.nextRenderHandle&&(lp(this.nextRenderHandle),this.nextRenderHandle=0)}drawControls(t){}renderCanvas(t,e){if(this.destroyed)return;const s=this.viewportTransform,i=this.clipPath;this.calcViewportBoundaries(),this.clearContext(t),t.imageSmoothingEnabled=this.imageSmoothingEnabled,t.patternQuality="best",this.fire("before:render",{ctx:t}),this._renderBackground(t),t.save(),t.transform(s[0],s[1],s[2],s[3],s[4],s[5]),this._renderObjects(t,e),t.restore(),this.controlsAboveOverlay||this.skipControlsDrawing||this.drawControls(t),i&&(i._set("canvas",this),i.shouldCache(),i._transformDone=!0,i.renderCache({forClipping:!0}),this.drawClipPathOnCanvas(t,i)),this._renderOverlay(t),this.controlsAboveOverlay&&!this.skipControlsDrawing&&this.drawControls(t),this.fire("after:render",{ctx:t}),this.__cleanupTask&&(this.__cleanupTask(),this.__cleanupTask=void 0)}drawClipPathOnCanvas(t,e){const s=this.viewportTransform;t.save(),t.transform(...s),t.globalCompositeOperation="destination-in",e.transform(t),t.scale(1/e.zoomX,1/e.zoomY),t.drawImage(e._cacheCanvas,-e.cacheTranslationX,-e.cacheTranslationY),t.restore()}_renderObjects(t,e){for(let s=0,i=e.length;s<i;++s)e[s]&&e[s].render(t)}_renderBackgroundOrOverlay(t,e){const s=this["".concat(e,"Color")],i=this["".concat(e,"Image")],n=this.viewportTransform,r=this["".concat(e,"Vpt")];if(!s&&!i)return;const o=Ze(s);if(s){if(t.save(),t.beginPath(),t.moveTo(0,0),t.lineTo(this.width,0),t.lineTo(this.width,this.height),t.lineTo(0,this.height),t.closePath(),t.fillStyle=o?s.toLive(t):s,r&&t.transform(...n),o){t.transform(1,0,0,1,s.offsetX||0,s.offsetY||0);const h=s.gradientTransform||s.patternTransform;h&&t.transform(...h)}t.fill(),t.restore()}if(i){t.save();const{skipOffscreen:h}=this;this.skipOffscreen=r,r&&t.transform(...n),i.render(t),this.skipOffscreen=h,t.restore()}}_renderBackground(t){this._renderBackgroundOrOverlay(t,"background")}_renderOverlay(t){this._renderBackgroundOrOverlay(t,"overlay")}getCenter(){return{top:this.height/2,left:this.width/2}}getCenterPoint(){return new k(this.width/2,this.height/2)}centerObjectH(t){return this._centerObject(t,new k(this.getCenterPoint().x,t.getCenterPoint().y))}centerObjectV(t){return this._centerObject(t,new k(t.getCenterPoint().x,this.getCenterPoint().y))}centerObject(t){return this._centerObject(t,this.getCenterPoint())}viewportCenterObject(t){return this._centerObject(t,this.getVpCenter())}viewportCenterObjectH(t){return this._centerObject(t,new k(this.getVpCenter().x,t.getCenterPoint().y))}viewportCenterObjectV(t){return this._centerObject(t,new k(t.getCenterPoint().x,this.getVpCenter().y))}getVpCenter(){return ne(this.getCenterPoint(),Me(this.viewportTransform))}_centerObject(t,e){t.setXY(e,Q,Q),t.setCoords(),this.renderOnAddRemove&&this.requestRenderAll()}toDatalessJSON(t){return this.toDatalessObject(t)}toObject(t){return this._toObjectMethod("toObject",t)}toJSON(){return this.toObject()}toDatalessObject(t){return this._toObjectMethod("toDatalessObject",t)}_toObjectMethod(t,e){const s=this.clipPath,i=s&&!s.excludeFromExport?this._toObject(s,t,e):null;return A(A(A({version:vu},Hn(this,e)),{},{objects:this._objects.filter(n=>!n.excludeFromExport).map(n=>this._toObject(n,t,e))},this.__serializeBgOverlay(t,e)),i?{clipPath:i}:null)}_toObject(t,e,s){let i;this.includeDefaultValues||(i=t.includeDefaultValues,t.includeDefaultValues=!1);const n=t[e](s);return this.includeDefaultValues||(t.includeDefaultValues=!!i),n}__serializeBgOverlay(t,e){const s={},i=this.backgroundImage,n=this.overlayImage,r=this.backgroundColor,o=this.overlayColor;return Ze(r)?r.excludeFromExport||(s.background=r.toObject(e)):r&&(s.background=r),Ze(o)?o.excludeFromExport||(s.overlay=o.toObject(e)):o&&(s.overlay=o),i&&!i.excludeFromExport&&(s.backgroundImage=this._toObject(i,t,e)),n&&!n.excludeFromExport&&(s.overlayImage=this._toObject(n,t,e)),s}toSVG(){let t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;t.reviver=e;const s=[];return this._setSVGPreamble(s,t),this._setSVGHeader(s,t),this.clipPath&&s.push('<g clip-path="url(#'.concat(this.clipPath.clipPathId,`)" >
|
|
4
4
|
`)),this._setSVGBgOverlayColor(s,"background"),this._setSVGBgOverlayImage(s,"backgroundImage",e),this._setSVGObjects(s,e),this.clipPath&&s.push(`</g>
|
|
@@ -506,4 +506,4 @@ void main() {
|
|
|
506
506
|
`),position:p,pageIndex:m-1,rect:d.slice(0),rotation:u,id:g,deleted:!1}}const r=super.deserialize(e,s,i);return b(r,Ye,e.fontSize),b(r,As,z.makeHexColor(...e.color)),b(r,Ue,y(o=_t,Wi,Ff).call(o,e.value)),r.annotationElementId=e.id||null,b(r,na,n),r}serialize(e=!1){if(this.isEmpty())return null;if(this.deleted)return{pageIndex:this.pageIndex,id:this.annotationElementId,deleted:!0};const s=_t._internalPadding*this.parentScale,i=this.getRect(s,s),n=dt._colorManager.convert(this.isAttachedToDOM?getComputedStyle(this.editorDiv).color:c(this,As)),r={annotationType:nt.FREETEXT,color:n,fontSize:c(this,Ye),value:y(this,Bt,Yv).call(this),pageIndex:this.pageIndex,rect:i,rotation:this.rotation,structTreeParentId:this._structTreeParentId};return e?r:this.annotationElementId&&!y(this,Bt,qv).call(this,r)?null:(r.id=this.annotationElementId,r)}renderAnnotationElement(e){const s=super.renderAnnotationElement(e);if(this.deleted)return s;const{style:i}=s;i.fontSize=`calc(${c(this,Ye)}px * var(--scale-factor))`,i.color=c(this,As),s.replaceChildren();for(const r of c(this,Ue).split(`
|
|
507
507
|
`)){const o=document.createElement("div");o.append(r?document.createTextNode(r):document.createElement("br")),s.append(o)}const n=_t._internalPadding*this.parentScale;return e.updateEdited({rect:this.getRect(n,n),popupContent:c(this,Ue)}),s}resetAnnotationElement(e){super.resetAnnotationElement(e),e.resetEdited()}};cl=new WeakMap,dl=new WeakMap,ul=new WeakMap,gl=new WeakMap,fl=new WeakMap,As=new WeakMap,Ue=new WeakMap,pl=new WeakMap,Ye=new WeakMap,na=new WeakMap,Bt=new WeakSet,Vv=function(e){const s=n=>{this.editorDiv.style.fontSize=`calc(${n}px * var(--scale-factor))`,this.translate(0,-(n-c(this,Ye))*this.parentScale),b(this,Ye,n),y(this,Bt,nu).call(this)},i=c(this,Ye);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.FREETEXT_SIZE,overwriteIfSameType:!0,keepUndo:!0})},Gv=function(e){const s=n=>{b(this,As,this.editorDiv.style.color=n)},i=c(this,As);this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.FREETEXT_COLOR,overwriteIfSameType:!0,keepUndo:!0})},Uv=function(){var s;const e=[];this.editorDiv.normalize();for(const i of this.editorDiv.childNodes)e.push(y(s=_t,Wi,ru).call(s,i));return e.join(`
|
|
508
508
|
`)},nu=function(){const[e,s]=this.parentDimensions;let i;if(this.isAttachedToDOM)i=this.div.getBoundingClientRect();else{const{currentLayer:n,div:r}=this,o=r.style.display,h=r.classList.contains("hidden");r.classList.remove("hidden"),r.style.display="hidden",n.div.append(this.div),i=r.getBoundingClientRect(),r.remove(),r.style.display=o,r.classList.toggle("hidden",h)}this.rotation%180===this.parentRotation%180?(this.width=i.width/e,this.height=i.height/s):(this.width=i.height/e,this.height=i.width/s),this.fixAndSetPosition()},Wi=new WeakSet,ru=function(e){return(e.nodeType===Node.TEXT_NODE?e.nodeValue:e.innerText).replaceAll(wd,"")},ou=function(){if(this.editorDiv.replaceChildren(),!!c(this,Ue))for(const e of c(this,Ue).split(`
|
|
509
|
-
`)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Yv=function(){return c(this,Ue).replaceAll(" "," ")},Ff=function(e){return e.replaceAll(" "," ")},qv=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=c(this,na);return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((o,h)=>o!==n[h])||e.pageIndex!==r},w(_t,Wi),K(_t,"_freeTextDefaultContent",""),K(_t,"_internalPadding",0),K(_t,"_defaultColor",null),K(_t,"_defaultFontSize",10),K(_t,"_type","freetext"),K(_t,"_editorType",nt.FREETEXT);let Gg=_t;class Z0{constructor(t,e=0,s=0,i=!0){w(this,Ae);w(this,ml);w(this,An,[]);w(this,Ts,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const d=10**-4;for(const{x:v,y:x,width:S,height:T}of t){const E=Math.floor((v-e)/d)*d,M=Math.ceil((v+S+e)/d)*d,P=Math.floor((x-e)/d)*d,O=Math.ceil((x+T+e)/d)*d,R=[E,P,O,!0],D=[M,P,O,!1];c(this,An).push(R,D),n=Math.min(n,E),r=Math.max(r,M),o=Math.min(o,P),h=Math.max(h,O)}const u=r-n+2*s,g=h-o+2*s,f=n-s,p=o-s,m=c(this,An).at(i?-1:-2),_=[m[0],m[2]];for(const v of c(this,An)){const[x,S,T]=v;v[0]=(x-f)/u,v[1]=(S-p)/g,v[2]=(T-p)/g}b(this,ml,{x:f,y:p,width:u,height:g,lastPoint:_})}getOutlines(){c(this,An).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of c(this,An))e[3]?(t.push(...y(this,Ae,Rf).call(this,e)),y(this,Ae,Kv).call(this,e)):(y(this,Ae,Qv).call(this,e),t.push(...y(this,Ae,Rf).call(this,e)));return y(this,Ae,$v).call(this,t)}}ml=new WeakMap,An=new WeakMap,Ts=new WeakMap,Ae=new WeakSet,$v=function(t){const e=[],s=new Set;for(const r of t){const[o,h,l]=r;e.push([o,h,r],[o,l,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],l=e[r+1][2];h.push(l),l.push(h),s.add(h),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,l,d,u]=r;s.delete(r);let g=o,f=h;for(n=[o,l],i.push(n);;){let p;if(s.has(d))p=d;else if(s.has(u))p=u;else break;s.delete(p),[o,h,l,d,u]=p,g!==o&&(n.push(g,f,o,f===h?h:l),g=o),f=f===h?l:h}n.push(g,f)}return new rS(i,c(this,ml))},au=function(t){const e=c(this,Ts);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},Kv=function([,t,e]){const s=y(this,Ae,au).call(this,t);c(this,Ts).splice(s,0,[t,e])},Qv=function([,t,e]){const s=y(this,Ae,au).call(this,t);for(let i=s;i<c(this,Ts).length;i++){const[n,r]=c(this,Ts)[i];if(n!==t)break;if(n===t&&r===e){c(this,Ts).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=c(this,Ts)[i];if(n!==t)break;if(n===t&&r===e){c(this,Ts).splice(i,1);return}}},Rf=function(t){const[e,s,i]=t,n=[[e,s,i]],r=y(this,Ae,au).call(this,i);for(let o=0;o<r;o++){const[h,l]=c(this,Ts)[o];for(let d=0,u=n.length;d<u;d++){const[,g,f]=n[d];if(!(l<=g||f<=h)){if(g>=h){if(f>l)n[d][1]=l;else{if(u===1)return[];n.splice(d,1),d--,u--}continue}n[d][2]=h,f>l&&n.push([e,l,f])}}}return n};class tv{toSVGPath(){throw new Error("Abstract method `toSVGPath` must be implemented.")}get box(){throw new Error("Abstract getter `box` must be implemented.")}serialize(t,e){throw new Error("Abstract method `serialize` must be implemented.")}get free(){return this instanceof Ug}}class rS extends tv{constructor(e,s){super();w(this,vl);w(this,ra);b(this,ra,e),b(this,vl,s)}toSVGPath(){const e=[];for(const s of c(this,ra)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const o=s[r],h=s[r+1];o===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${o}`),i=o)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const o=[],h=i-e,l=n-s;for(const d of c(this,ra)){const u=new Array(d.length);for(let g=0;g<d.length;g+=2)u[g]=e+d[g]*h,u[g+1]=n-d[g+1]*l;o.push(u)}return o}get box(){return c(this,vl)}}vl=new WeakMap,ra=new WeakMap;const zi=class zi{constructor({x:t,y:e},s,i,n,r,o=0){w(this,wl);w(this,Zs);w(this,Xi,[]);w(this,oa);w(this,aa);w(this,ti,[]);w(this,rt,new Float64Array(18));w(this,Xr);w(this,zr);w(this,bl);w(this,yl);w(this,ha);w(this,la);w(this,Tn,[]);b(this,Zs,s),b(this,la,n*i),b(this,aa,r),c(this,rt).set([NaN,NaN,NaN,NaN,t,e],6),b(this,oa,o),b(this,yl,c(zi,_l)*i),b(this,bl,c(zi,zd)*i),b(this,ha,i),c(this,Tn).push(t,e)}get free(){return!0}isEmpty(){return isNaN(c(this,rt)[8])}add({x:t,y:e}){var R;b(this,Xr,t),b(this,zr,e);const[s,i,n,r]=c(this,Zs);let[o,h,l,d]=c(this,rt).subarray(8,12);const u=t-l,g=e-d,f=Math.hypot(u,g);if(f<c(this,bl))return!1;const p=f-c(this,yl),m=p/f,_=m*u,v=m*g;let x=o,S=h;o=l,h=d,l+=_,d+=v,(R=c(this,Tn))==null||R.push(t,e);const T=-v/p,E=_/p,M=T*c(this,la),P=E*c(this,la);return c(this,rt).set(c(this,rt).subarray(2,8),0),c(this,rt).set([l+M,d+P],4),c(this,rt).set(c(this,rt).subarray(14,18),12),c(this,rt).set([l-M,d-P],16),isNaN(c(this,rt)[6])?(c(this,ti).length===0&&(c(this,rt).set([o+M,h+P],2),c(this,ti).push(NaN,NaN,NaN,NaN,(o+M-s)/n,(h+P-i)/r),c(this,rt).set([o-M,h-P],14),c(this,Xi).push(NaN,NaN,NaN,NaN,(o-M-s)/n,(h-P-i)/r)),c(this,rt).set([x,S,o,h,l,d],6),!this.isEmpty()):(c(this,rt).set([x,S,o,h,l,d],6),Math.abs(Math.atan2(S-h,x-o)-Math.atan2(v,_))<Math.PI/2?([o,h,l,d]=c(this,rt).subarray(2,6),c(this,ti).push(NaN,NaN,NaN,NaN,((o+l)/2-s)/n,((h+d)/2-i)/r),[o,h,x,S]=c(this,rt).subarray(14,18),c(this,Xi).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,o,h,l,d]=c(this,rt).subarray(0,6),c(this,ti).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+d)/6-i)/r,((o+l)/2-s)/n,((h+d)/2-i)/r),[l,d,o,h,x,S]=c(this,rt).subarray(12,18),c(this,Xi).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+d)/6-i)/r,((o+l)/2-s)/n,((h+d)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=c(this,ti),e=c(this,Xi),s=c(this,rt).subarray(4,6),i=c(this,rt).subarray(16,18),[n,r,o,h]=c(this,Zs),[l,d,u,g]=y(this,wl,If).call(this);if(isNaN(c(this,rt)[6])&&!this.isEmpty())return`M${(c(this,rt)[2]-n)/o} ${(c(this,rt)[3]-r)/h} L${(c(this,rt)[4]-n)/o} ${(c(this,rt)[5]-r)/h} L${l} ${d} L${u} ${g} L${(c(this,rt)[16]-n)/o} ${(c(this,rt)[17]-r)/h} L${(c(this,rt)[14]-n)/o} ${(c(this,rt)[15]-r)/h} Z`;const f=[];f.push(`M${t[4]} ${t[5]}`);for(let p=6;p<t.length;p+=6)isNaN(t[p])?f.push(`L${t[p+4]} ${t[p+5]}`):f.push(`C${t[p]} ${t[p+1]} ${t[p+2]} ${t[p+3]} ${t[p+4]} ${t[p+5]}`);f.push(`L${(s[0]-n)/o} ${(s[1]-r)/h} L${l} ${d} L${u} ${g} L${(i[0]-n)/o} ${(i[1]-r)/h}`);for(let p=e.length-6;p>=6;p-=6)isNaN(e[p])?f.push(`L${e[p+4]} ${e[p+5]}`):f.push(`C${e[p]} ${e[p+1]} ${e[p+2]} ${e[p+3]} ${e[p+4]} ${e[p+5]}`);return f.push(`L${e[4]} ${e[5]} Z`),f.join(" ")}getOutlines(){var v;const t=c(this,ti),e=c(this,Xi),s=c(this,rt),i=s.subarray(4,6),n=s.subarray(16,18),[r,o,h,l]=c(this,Zs),d=new Float64Array((((v=c(this,Tn))==null?void 0:v.length)??0)+2);for(let x=0,S=d.length-2;x<S;x+=2)d[x]=(c(this,Tn)[x]-r)/h,d[x+1]=(c(this,Tn)[x+1]-o)/l;d[d.length-2]=(c(this,Xr)-r)/h,d[d.length-1]=(c(this,zr)-o)/l;const[u,g,f,p]=y(this,wl,If).call(this);if(isNaN(s[6])&&!this.isEmpty()){const x=new Float64Array(36);return x.set([NaN,NaN,NaN,NaN,(s[2]-r)/h,(s[3]-o)/l,NaN,NaN,NaN,NaN,(s[4]-r)/h,(s[5]-o)/l,NaN,NaN,NaN,NaN,u,g,NaN,NaN,NaN,NaN,f,p,NaN,NaN,NaN,NaN,(s[16]-r)/h,(s[17]-o)/l,NaN,NaN,NaN,NaN,(s[14]-r)/h,(s[15]-o)/l],0),new Ug(x,d,c(this,Zs),c(this,ha),c(this,oa),c(this,aa))}const m=new Float64Array(c(this,ti).length+24+c(this,Xi).length);let _=t.length;for(let x=0;x<_;x+=2){if(isNaN(t[x])){m[x]=m[x+1]=NaN;continue}m[x]=t[x],m[x+1]=t[x+1]}m.set([NaN,NaN,NaN,NaN,(i[0]-r)/h,(i[1]-o)/l,NaN,NaN,NaN,NaN,u,g,NaN,NaN,NaN,NaN,f,p,NaN,NaN,NaN,NaN,(n[0]-r)/h,(n[1]-o)/l],_),_+=24;for(let x=e.length-6;x>=6;x-=6)for(let S=0;S<6;S+=2){if(isNaN(e[x+S])){m[_]=m[_+1]=NaN,_+=2;continue}m[_]=e[x+S],m[_+1]=e[x+S+1],_+=2}return m.set([NaN,NaN,NaN,NaN,e[4],e[5]],_),new Ug(m,d,c(this,Zs),c(this,ha),c(this,oa),c(this,aa))}};Zs=new WeakMap,Xi=new WeakMap,oa=new WeakMap,aa=new WeakMap,ti=new WeakMap,rt=new WeakMap,Xr=new WeakMap,zr=new WeakMap,bl=new WeakMap,yl=new WeakMap,ha=new WeakMap,la=new WeakMap,Tn=new WeakMap,_l=new WeakMap,Xd=new WeakMap,zd=new WeakMap,wl=new WeakSet,If=function(){const t=c(this,rt).subarray(4,6),e=c(this,rt).subarray(16,18),[s,i,n,r]=c(this,Zs);return[(c(this,Xr)+(t[0]-e[0])/2-s)/n,(c(this,zr)+(t[1]-e[1])/2-i)/r,(c(this,Xr)+(e[0]-t[0])/2-s)/n,(c(this,zr)+(e[1]-t[1])/2-i)/r]},w(zi,_l,8),w(zi,Xd,2),w(zi,zd,c(zi,_l)+c(zi,Xd));let xd=zi;class Ug extends tv{constructor(e,s,i,n,r,o){super();w(this,Re);w(this,ca);w(this,Vr,null);w(this,Vi);w(this,xl);w(this,qe);w(this,Sl);w(this,Rt);b(this,Rt,e),b(this,qe,s),b(this,ca,i),b(this,Sl,n),b(this,Vi,r),b(this,xl,o),y(this,Re,Jv).call(this,o);const{x:h,y:l,width:d,height:u}=c(this,Vr);for(let g=0,f=e.length;g<f;g+=2)e[g]=(e[g]-h)/d,e[g+1]=(e[g+1]-l)/u;for(let g=0,f=s.length;g<f;g+=2)s[g]=(s[g]-h)/d,s[g+1]=(s[g+1]-l)/u}toSVGPath(){const e=[`M${c(this,Rt)[4]} ${c(this,Rt)[5]}`];for(let s=6,i=c(this,Rt).length;s<i;s+=6){if(isNaN(c(this,Rt)[s])){e.push(`L${c(this,Rt)[s+4]} ${c(this,Rt)[s+5]}`);continue}e.push(`C${c(this,Rt)[s]} ${c(this,Rt)[s+1]} ${c(this,Rt)[s+2]} ${c(this,Rt)[s+3]} ${c(this,Rt)[s+4]} ${c(this,Rt)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let l,d;switch(r){case 0:l=y(this,Re,Yl).call(this,c(this,Rt),e,n,o,-h),d=y(this,Re,Yl).call(this,c(this,qe),e,n,o,-h);break;case 90:l=y(this,Re,ql).call(this,c(this,Rt),e,s,o,h),d=y(this,Re,ql).call(this,c(this,qe),e,s,o,h);break;case 180:l=y(this,Re,Yl).call(this,c(this,Rt),i,s,-o,h),d=y(this,Re,Yl).call(this,c(this,qe),i,s,-o,h);break;case 270:l=y(this,Re,ql).call(this,c(this,Rt),i,n,-o,-h),d=y(this,Re,ql).call(this,c(this,qe),i,n,-o,-h);break}return{outline:Array.from(l),points:[Array.from(d)]}}get box(){return c(this,Vr)}getNewOutline(e,s){const{x:i,y:n,width:r,height:o}=c(this,Vr),[h,l,d,u]=c(this,ca),g=r*d,f=o*u,p=i*d+h,m=n*u+l,_=new xd({x:c(this,qe)[0]*g+p,y:c(this,qe)[1]*f+m},c(this,ca),c(this,Sl),e,c(this,xl),s??c(this,Vi));for(let v=2;v<c(this,qe).length;v+=2)_.add({x:c(this,qe)[v]*g+p,y:c(this,qe)[v+1]*f+m});return _.getOutlines()}}ca=new WeakMap,Vr=new WeakMap,Vi=new WeakMap,xl=new WeakMap,qe=new WeakMap,Sl=new WeakMap,Rt=new WeakMap,Re=new WeakSet,Yl=function(e,s,i,n,r){const o=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)o[h]=s+e[h]*n,o[h+1]=i+e[h+1]*r;return o},ql=function(e,s,i,n,r){const o=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)o[h]=s+e[h+1]*n,o[h+1]=i+e[h]*r;return o},Jv=function(e){const s=c(this,Rt);let i=s[4],n=s[5],r=i,o=n,h=i,l=n,d=i,u=n;const g=e?Math.max:Math.min;for(let v=6,x=s.length;v<x;v+=6){if(isNaN(s[v]))r=Math.min(r,s[v+4]),o=Math.min(o,s[v+5]),h=Math.max(h,s[v+4]),l=Math.max(l,s[v+5]),u<s[v+5]?(d=s[v+4],u=s[v+5]):u===s[v+5]&&(d=g(d,s[v+4]));else{const S=z.bezierBoundingBox(i,n,...s.slice(v,v+6));r=Math.min(r,S[0]),o=Math.min(o,S[1]),h=Math.max(h,S[2]),l=Math.max(l,S[3]),u<S[3]?(d=S[2],u=S[3]):u===S[3]&&(d=g(d,S[2]))}i=s[v+4],n=s[v+5]}const f=r-c(this,Vi),p=o-c(this,Vi),m=h-r+2*c(this,Vi),_=l-o+2*c(this,Vi);b(this,Vr,{x:f,y:p,width:m,height:_,lastPoint:[d,u]})};const Gi=class Gi{constructor({editor:t=null,uiManager:e=null}){w(this,yt);w(this,Cl,y(this,yt,Zv).bind(this));w(this,Al,y(this,yt,tb).bind(this));w(this,Es,null);w(this,Gr,null);w(this,da);w(this,Vt,null);w(this,Tl,!1);w(this,ua,!1);w(this,El,null);w(this,kl);w(this,ks,null);w(this,ga);var s;t?(b(this,ua,!1),b(this,ga,q.HIGHLIGHT_COLOR),b(this,El,t)):(b(this,ua,!0),b(this,ga,q.HIGHLIGHT_DEFAULT_COLOR)),b(this,ks,(t==null?void 0:t._uiManager)||e),b(this,kl,c(this,ks)._eventBus),b(this,da,(t==null?void 0:t.color)||((s=c(this,ks))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98")}static get _keyboardManager(){return at(this,"_keyboardManager",new Qa([[["Escape","mac+Escape"],Gi.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Gi.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Gi.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Gi.prototype._moveToPrevious],[["Home","mac+Home"],Gi.prototype._moveToBeginning],[["End","mac+End"],Gi.prototype._moveToEnd]]))}renderButton(){const t=b(this,Es,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=c(this,ks)._signal;t.addEventListener("click",y(this,yt,oo).bind(this),{signal:e}),t.addEventListener("keydown",c(this,Cl),{signal:e});const s=b(this,Gr,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=c(this,da),t.append(s),t}renderMainDropdown(){const t=b(this,Vt,y(this,yt,jf).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===c(this,Es)){y(this,yt,oo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&y(this,yt,Nf).call(this,e,t)}_moveToNext(t){var e,s;if(!c(this,yt,In)){y(this,yt,oo).call(this,t);return}if(t.target===c(this,Es)){(e=c(this,Vt).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=c(this,Vt))==null?void 0:e.firstChild)||t.target===c(this,Es)){c(this,yt,In)&&this._hideDropdownFromKeyboard();return}c(this,yt,In)||y(this,yt,oo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!c(this,yt,In)){y(this,yt,oo).call(this,t);return}(e=c(this,Vt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!c(this,yt,In)){y(this,yt,oo).call(this,t);return}(e=c(this,Vt).lastChild)==null||e.focus()}hideDropdown(){var t;(t=c(this,Vt))==null||t.classList.add("hidden"),window.removeEventListener("pointerdown",c(this,Al))}_hideDropdownFromKeyboard(){var t;if(!c(this,ua)){if(!c(this,yt,In)){(t=c(this,El))==null||t.unselect();return}this.hideDropdown(),c(this,Es).focus({preventScroll:!0,focusVisible:c(this,Tl)})}}updateColor(t){if(c(this,Gr)&&(c(this,Gr).style.backgroundColor=t),!c(this,Vt))return;const e=c(this,ks).highlightColors.values();for(const s of c(this,Vt).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=c(this,Es))==null||t.remove(),b(this,Es,null),b(this,Gr,null),(e=c(this,Vt))==null||e.remove(),b(this,Vt,null)}};Cl=new WeakMap,Al=new WeakMap,Es=new WeakMap,Gr=new WeakMap,da=new WeakMap,Vt=new WeakMap,Tl=new WeakMap,ua=new WeakMap,El=new WeakMap,kl=new WeakMap,ks=new WeakMap,ga=new WeakMap,yt=new WeakSet,jf=function(){const t=document.createElement("div"),e=c(this,ks)._signal;t.addEventListener("contextmenu",Oe,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of c(this,ks).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",`pdfjs-editor-colorpicker-${s}`);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===c(this,da)),n.addEventListener("click",y(this,yt,Nf).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",c(this,Cl),{signal:e}),t},Nf=function(t,e){e.stopPropagation(),c(this,kl).dispatch("switchannotationeditorparams",{source:this,type:c(this,ga),value:t})},Zv=function(t){Gi._keyboardManager.exec(this,t)},oo=function(t){if(c(this,yt,In)){this.hideDropdown();return}if(b(this,Tl,t.detail===0),window.addEventListener("pointerdown",c(this,Al),{signal:c(this,ks)._signal}),c(this,Vt)){c(this,Vt).classList.remove("hidden");return}const e=b(this,Vt,y(this,yt,jf).call(this));c(this,Es).append(e)},tb=function(t){var e;(e=c(this,Vt))!=null&&e.contains(t.target)||this.hideDropdown()},In=function(){return c(this,Vt)&&!c(this,Vt).classList.contains("hidden")};let Sd=Gi;const lt=class lt extends dt{constructor(e){super({...e,name:"highlightEditor"});w(this,et);w(this,fa,null);w(this,Ml,0);w(this,En);w(this,Ur,null);w(this,pa,null);w(this,os,null);w(this,Dl,null);w(this,Ol,0);w(this,Yr,null);w(this,Ms,null);w(this,Te,null);w(this,$e,!1);w(this,Vd,y(this,et,nb).bind(this));w(this,ma,null);w(this,qr);w(this,Gt,null);w(this,va,"");w(this,ei);w(this,Pl,"");this.color=e.color||lt._defaultColor,b(this,ei,e.thickness||lt._defaultThickness),b(this,qr,e.opacity||lt._defaultOpacity),b(this,En,e.boxes||null),b(this,Pl,e.methodOfCreation||""),b(this,va,e.text||""),this._isDraggable=!1,e.highlightId>-1?(b(this,$e,!0),y(this,et,Hf).call(this,e),y(this,et,$l).call(this)):(b(this,fa,e.anchorNode),b(this,Ml,e.anchorOffset),b(this,Dl,e.focusNode),b(this,Ol,e.focusOffset),y(this,et,Bf).call(this),y(this,et,$l).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=lt.prototype;return at(this,"_keyboardManager",new Qa([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:c(this,$e)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:c(this,ei),methodOfCreation:c(this,Pl)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,s){var i;dt.initialize(e,s),lt._defaultColor||(lt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case q.HIGHLIGHT_DEFAULT_COLOR:lt._defaultColor=s;break;case q.HIGHLIGHT_THICKNESS:lt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return c(this,ma)}updateParams(e,s){switch(e){case q.HIGHLIGHT_COLOR:y(this,et,eb).call(this,s);break;case q.HIGHLIGHT_THICKNESS:y(this,et,sb).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[q.HIGHLIGHT_DEFAULT_COLOR,lt._defaultColor],[q.HIGHLIGHT_THICKNESS,lt._defaultThickness]]}get propertiesToUpdate(){return[[q.HIGHLIGHT_COLOR,this.color||lt._defaultColor],[q.HIGHLIGHT_THICKNESS,c(this,ei)||lt._defaultThickness],[q.HIGHLIGHT_FREE,c(this,$e)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(b(this,pa,new Sd({editor:this})),e.addColorPicker(c(this,pa))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(y(this,et,Kl).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,y(this,et,Kl).call(this))}onceAdded(){this.parent.addUndoableEditor(this),this.div.focus()}remove(){y(this,et,Wf).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(y(this,et,$l).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?y(this,et,Wf).call(this):e&&(y(this,et,$l).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,o;const{drawLayer:s}=this.parent;let i;c(this,$e)?(e=(e-this.rotation+360)%360,i=y(n=lt,as,ka).call(n,c(this,Ms).box,e)):i=y(r=lt,as,ka).call(r,this,e),s.rotate(c(this,Te),e),s.rotate(c(this,Gt),e),s.updateBox(c(this,Te),i),s.updateBox(c(this,Gt),y(o=lt,as,ka).call(o,c(this,os).box,e))}render(){if(this.div)return this.div;const e=super.render();c(this,va)&&(e.setAttribute("aria-label",c(this,va)),e.setAttribute("role","mark")),c(this,$e)?e.classList.add("free"):this.div.addEventListener("keydown",c(this,Vd),{signal:this._uiManager._signal});const s=b(this,Yr,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=c(this,Ur);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),gd(this,c(this,Yr),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.parent.drawLayer.addClass(c(this,Gt),"hovered")}pointerleave(){this.parent.drawLayer.removeClass(c(this,Gt),"hovered")}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:y(this,et,hu).call(this,!0);break;case 1:case 3:y(this,et,hu).call(this,!1);break}}select(){var e,s;super.select(),c(this,Gt)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,Gt),"hovered"),(s=this.parent)==null||s.drawLayer.addClass(c(this,Gt),"selected"))}unselect(){var e;super.unselect(),c(this,Gt)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,Gt),"selected"),c(this,$e)||y(this,et,hu).call(this,!1))}get _mustFixPosition(){return!c(this,$e)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.show(c(this,Te),e),this.parent.drawLayer.show(c(this,Gt),e))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:l,height:d}=i.getBoundingClientRect(),u=_=>{y(this,as,ab).call(this,e,_)},g=e._signal,f={capture:!0,passive:!1,signal:g},p=_=>{_.preventDefault(),_.stopPropagation()},m=_=>{i.removeEventListener("pointermove",u),window.removeEventListener("blur",m),window.removeEventListener("pointerup",m),window.removeEventListener("pointerdown",p,f),window.removeEventListener("contextmenu",Oe),y(this,as,hb).call(this,e,_)};window.addEventListener("blur",m,{signal:g}),window.addEventListener("pointerup",m,{signal:g}),window.addEventListener("pointerdown",p,f),window.addEventListener("contextmenu",Oe,{signal:g}),i.addEventListener("pointermove",u,{signal:g}),this._freeHighlight=new xd({x:n,y:r},[o,h,l,d],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.highlight(this._freeHighlight,this._defaultColor,this._defaultOpacity,!0)}static deserialize(e,s,i){var m;const n=super.deserialize(e,s,i),{rect:[r,o,h,l],color:d,quadPoints:u}=e;n.color=z.makeHexColor(...d),b(n,qr,e.opacity);const[g,f]=n.pageDimensions;n.width=(h-r)/g,n.height=(l-o)/f;const p=b(n,En,[]);for(let _=0;_<u.length;_+=8)p.push({x:(u[4]-h)/g,y:(l-(1-u[_+5]))/f,width:(u[_+2]-u[_])/g,height:(u[_+5]-u[_+1])/f});return y(m=n,et,Bf).call(m),n}serialize(e=!1){if(this.isEmpty()||e)return null;const s=this.getRect(0,0),i=dt._colorManager.convert(this.color);return{annotationType:nt.HIGHLIGHT,color:i,opacity:c(this,qr),thickness:c(this,ei),quadPoints:y(this,et,rb).call(this),outlines:y(this,et,ob).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:y(this,et,Kl).call(this),structTreeParentId:this._structTreeParentId}}static canCreateNewEmptyEditor(){return!1}};fa=new WeakMap,Ml=new WeakMap,En=new WeakMap,Ur=new WeakMap,pa=new WeakMap,os=new WeakMap,Dl=new WeakMap,Ol=new WeakMap,Yr=new WeakMap,Ms=new WeakMap,Te=new WeakMap,$e=new WeakMap,Vd=new WeakMap,ma=new WeakMap,qr=new WeakMap,Gt=new WeakMap,va=new WeakMap,ei=new WeakMap,Pl=new WeakMap,et=new WeakSet,Bf=function(){const e=new Z0(c(this,En),.001);b(this,Ms,e.getOutlines()),{x:this.x,y:this.y,width:this.width,height:this.height}=c(this,Ms).box;const s=new Z0(c(this,En),.0025,.001,this._uiManager.direction==="ltr");b(this,os,s.getOutlines());const{lastPoint:i}=c(this,os).box;b(this,ma,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},Hf=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var u,g;if(b(this,Ms,e),b(this,os,e.getNewOutline(c(this,ei)/2+1.5,.0025)),s>=0)b(this,Te,s),b(this,Ur,i),this.parent.drawLayer.finalizeLine(s,e),b(this,Gt,this.parent.drawLayer.highlightOutline(c(this,os)));else if(this.parent){const f=this.parent.viewport.rotation;this.parent.drawLayer.updateLine(c(this,Te),e),this.parent.drawLayer.updateBox(c(this,Te),y(u=lt,as,ka).call(u,c(this,Ms).box,(f-this.rotation+360)%360)),this.parent.drawLayer.updateLine(c(this,Gt),c(this,os)),this.parent.drawLayer.updateBox(c(this,Gt),y(g=lt,as,ka).call(g,c(this,os).box,f))}const{x:r,y:o,width:h,height:l}=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=l;break;case 90:{const[f,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/f,this.height=l*f/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=l;break;case 270:{const[f,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/f,this.height=l*f/p;break}}const{lastPoint:d}=c(this,os).box;b(this,ma,[(d[0]-r)/h,(d[1]-o)/l])},eb=function(e){const s=n=>{var r,o;this.color=n,(r=this.parent)==null||r.drawLayer.changeColor(c(this,Te),n),(o=c(this,pa))==null||o.updateColor(n)},i=this.color;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},sb=function(e){const s=c(this,ei),i=n=>{b(this,ei,n),y(this,et,ib).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},ib=function(e){if(!c(this,$e))return;y(this,et,Hf).call(this,{highlightOutlines:c(this,Ms).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Wf=function(){c(this,Te)===null||!this.parent||(this.parent.drawLayer.remove(c(this,Te)),b(this,Te,null),this.parent.drawLayer.remove(c(this,Gt)),b(this,Gt,null))},$l=function(e=this.parent){c(this,Te)===null&&({id:Je(this,Te)._,clipPathId:Je(this,Ur)._}=e.drawLayer.highlight(c(this,Ms),this.color,c(this,qr)),b(this,Gt,e.drawLayer.highlightOutline(c(this,os))),c(this,Yr)&&(c(this,Yr).style.clipPath=c(this,Ur)))},as=new WeakSet,ka=function({x:e,y:s,width:i,height:n},r){switch(r){case 90:return{x:1-s-n,y:e,width:n,height:i};case 180:return{x:1-e-i,y:1-s-n,width:i,height:n};case 270:return{x:s,y:1-e-i,width:n,height:i}}return{x:e,y:s,width:i,height:n}},nb=function(e){lt._keyboardManager.exec(this,e)},hu=function(e){if(!c(this,fa))return;const s=window.getSelection();e?s.setPosition(c(this,fa),c(this,Ml)):s.setPosition(c(this,Dl),c(this,Ol))},Kl=function(){return c(this,$e)?this.rotation:0},rb=function(){if(c(this,$e))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=c(this,En),o=new Float32Array(r.length*8);let h=0;for(const{x:l,y:d,width:u,height:g}of r){const f=l*e+i,p=(1-d-g)*s+n;o[h]=o[h+4]=f,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=f+u*e,o[h+5]=o[h+7]=p+g*s,h+=8}return o},ob=function(e){return c(this,Ms).serialize(e,y(this,et,Kl).call(this))},ab=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updatePath(this._freeHighlightId,this._freeHighlight)},hb=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.removeFreeHighlight(this._freeHighlightId):e.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},w(lt,as),K(lt,"_defaultColor",null),K(lt,"_defaultOpacity",1),K(lt,"_defaultThickness",12),K(lt,"_l10nPromise"),K(lt,"_type","highlight"),K(lt,"_editorType",nt.HIGHLIGHT),K(lt,"_freeHighlightId",-1),K(lt,"_freeHighlight",null),K(lt,"_freeHighlightClipId","");let Cd=lt;const At=class At extends dt{constructor(e){super({...e,name:"inkEditor"});w(this,N);w(this,$r,0);w(this,Kr,0);w(this,Ll,this.canvasPointermove.bind(this));w(this,Fl,this.canvasPointerleave.bind(this));w(this,Rl,this.canvasPointerup.bind(this));w(this,Qr,this.canvasPointerdown.bind(this));w(this,si,null);w(this,Ui,new Path2D);w(this,hs,!1);w(this,Jr,!1);w(this,Zr,!1);w(this,Yi,null);w(this,to,0);w(this,eo,0);w(this,kn,null);this.color=e.color||null,this.thickness=e.thickness||null,this.opacity=e.opacity||null,this.paths=[],this.bezierPath2D=[],this.allRawPaths=[],this.currentPath=[],this.scaleFactor=1,this.translationX=this.translationY=0,this.x=0,this.y=0,this._willKeepAspectRatio=!0}static initialize(e,s){dt.initialize(e,s)}static updateDefaultParams(e,s){switch(e){case q.INK_THICKNESS:At._defaultThickness=s;break;case q.INK_COLOR:At._defaultColor=s;break;case q.INK_OPACITY:At._defaultOpacity=s/100;break}}updateParams(e,s){switch(e){case q.INK_THICKNESS:y(this,N,lb).call(this,s);break;case q.INK_COLOR:y(this,N,cb).call(this,s);break;case q.INK_OPACITY:y(this,N,db).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[q.INK_THICKNESS,At._defaultThickness],[q.INK_COLOR,At._defaultColor||dt._defaultLineColor],[q.INK_OPACITY,Math.round(At._defaultOpacity*100)]]}get propertiesToUpdate(){return[[q.INK_THICKNESS,this.thickness||At._defaultThickness],[q.INK_COLOR,this.color||At._defaultColor||dt._defaultLineColor],[q.INK_OPACITY,Math.round(100*(this.opacity??At._defaultOpacity))]]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.canvas||(y(this,N,lu).call(this),y(this,N,cu).call(this)),this.isAttachedToDOM||(this.parent.add(this),y(this,N,Ma).call(this)),y(this,N,Ql).call(this)))}remove(){var e;this.canvas!==null&&(this.isEmpty()||this.commit(),this.canvas.width=this.canvas.height=0,this.canvas.remove(),this.canvas=null,c(this,si)&&(clearTimeout(c(this,si)),b(this,si,null)),(e=c(this,Yi))==null||e.disconnect(),b(this,Yi,null),super.remove())}setParent(e){!this.parent&&e?this._uiManager.removeShouldRescale(this):this.parent&&e===null&&this._uiManager.addShouldRescale(this),super.setParent(e)}onScaleChanging(){const[e,s]=this.parentDimensions,i=this.width*e,n=this.height*s;this.setDimensions(i,n)}enableEditMode(){c(this,hs)||this.canvas===null||(super.enableEditMode(),this._isDraggable=!1,this.canvas.addEventListener("pointerdown",c(this,Qr),{signal:this._uiManager._signal}))}disableEditMode(){!this.isInEditMode()||this.canvas===null||(super.disableEditMode(),this._isDraggable=!this.isEmpty(),this.div.classList.remove("editing"),this.canvas.removeEventListener("pointerdown",c(this,Qr)))}onceAdded(){this._isDraggable=!this.isEmpty()}isEmpty(){return this.paths.length===0||this.paths.length===1&&this.paths[0].length===0}commit(){c(this,hs)||(super.commit(),this.isEditing=!1,this.disableEditMode(),this.setInForeground(),b(this,hs,!0),this.div.classList.add("disabled"),y(this,N,Ql).call(this,!0),this.select(),this.parent.addInkEditorIfNeeded(!0),this.moveInDOM(),this.div.focus({preventScroll:!0}))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),this.enableEditMode())}canvasPointerdown(e){e.button!==0||!this.isInEditMode()||c(this,hs)||(this.setInForeground(),e.preventDefault(),this.div.contains(document.activeElement)||this.div.focus({preventScroll:!0}),y(this,N,gb).call(this,e.offsetX,e.offsetY))}canvasPointermove(e){e.preventDefault(),y(this,N,zf).call(this,e.offsetX,e.offsetY)}canvasPointerup(e){e.preventDefault(),y(this,N,Vf).call(this,e)}canvasPointerleave(e){y(this,N,Vf).call(this,e)}get isResizable(){return!this.isEmpty()&&c(this,hs)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.div.setAttribute("data-l10n-id","pdfjs-ink");const[i,n,r,o]=y(this,N,ub).call(this);if(this.setAt(i,n,0,0),this.setDims(r,o),y(this,N,lu).call(this),this.width){const[h,l]=this.parentDimensions;this.setAspectRatio(this.width*h,this.height*l),this.setAt(e*h,s*l,this.width*h,this.height*l),b(this,Zr,!0),y(this,N,Ma).call(this),this.setDims(this.width*h,this.height*l),y(this,N,ao).call(this),this.div.classList.add("disabled")}else this.div.classList.add("editing"),this.enableEditMode();return y(this,N,cu).call(this),this.div}setDimensions(e,s){const i=Math.round(e),n=Math.round(s);if(c(this,to)===i&&c(this,eo)===n)return;b(this,to,i),b(this,eo,n),this.canvas.style.visibility="hidden";const[r,o]=this.parentDimensions;this.width=e/r,this.height=s/o,this.fixAndSetPosition(),c(this,hs)&&y(this,N,Gf).call(this,e,s),y(this,N,Ma).call(this),y(this,N,ao).call(this),this.canvas.style.visibility="visible",this.fixDims()}static deserialize(e,s,i){var _,v,x;if(e instanceof Q0)return null;const n=super.deserialize(e,s,i);n.thickness=e.thickness,n.color=z.makeHexColor(...e.color),n.opacity=e.opacity;const[r,o]=n.pageDimensions,h=n.width*r,l=n.height*o,d=n.parentScale,u=e.thickness/2;b(n,hs,!0),b(n,to,Math.round(h)),b(n,eo,Math.round(l));const{paths:g,rect:f,rotation:p}=e;for(let{bezier:S}of g){S=y(_=At,qi,_b).call(_,S,f,p);const T=[];n.paths.push(T);let E=d*(S[0]-u),M=d*(S[1]-u);for(let O=2,R=S.length;O<R;O+=6){const D=d*(S[O]-u),L=d*(S[O+1]-u),F=d*(S[O+2]-u),I=d*(S[O+3]-u),X=d*(S[O+4]-u),Y=d*(S[O+5]-u);T.push([[E,M],[D,L],[F,I],[X,Y]]),E=X,M=Y}const P=y(this,qi,yb).call(this,T);n.bezierPath2D.push(P)}const m=y(v=n,N,Yf).call(v);return b(n,Kr,Math.max(dt.MIN_SIZE,m[2]-m[0])),b(n,$r,Math.max(dt.MIN_SIZE,m[3]-m[1])),y(x=n,N,Gf).call(x,h,l),n}serialize(){if(this.isEmpty())return null;const e=this.getRect(0,0),s=dt._colorManager.convert(this.ctx.strokeStyle);return{annotationType:nt.INK,color:s,thickness:this.thickness,opacity:this.opacity,paths:y(this,N,wb).call(this,this.scaleFactor/this.parentScale,this.translationX,this.translationY,e),pageIndex:this.pageIndex,rect:e,rotation:this.rotation,structTreeParentId:this._structTreeParentId}}};$r=new WeakMap,Kr=new WeakMap,Ll=new WeakMap,Fl=new WeakMap,Rl=new WeakMap,Qr=new WeakMap,si=new WeakMap,Ui=new WeakMap,hs=new WeakMap,Jr=new WeakMap,Zr=new WeakMap,Yi=new WeakMap,to=new WeakMap,eo=new WeakMap,kn=new WeakMap,N=new WeakSet,lb=function(e){const s=n=>{this.thickness=n,y(this,N,Ql).call(this)},i=this.thickness;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0})},cb=function(e){const s=n=>{this.color=n,y(this,N,ao).call(this)},i=this.color;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.INK_COLOR,overwriteIfSameType:!0,keepUndo:!0})},db=function(e){const s=n=>{this.opacity=n,y(this,N,ao).call(this)};e/=100;const i=this.opacity;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.INK_OPACITY,overwriteIfSameType:!0,keepUndo:!0})},ub=function(){const{parentRotation:e,parentDimensions:[s,i]}=this;switch(e){case 90:return[0,i,i,s];case 180:return[s,i,s,i];case 270:return[s,0,i,s];default:return[0,0,s,i]}},Xf=function(){const{ctx:e,color:s,opacity:i,thickness:n,parentScale:r,scaleFactor:o}=this;e.lineWidth=n*r/o,e.lineCap="round",e.lineJoin="round",e.miterLimit=10,e.strokeStyle=`${s}${Ow(i)}`},gb=function(e,s){const i=this._uiManager._signal;this.canvas.addEventListener("contextmenu",Oe,{signal:i}),this.canvas.addEventListener("pointerleave",c(this,Fl),{signal:i}),this.canvas.addEventListener("pointermove",c(this,Ll),{signal:i}),this.canvas.addEventListener("pointerup",c(this,Rl),{signal:i}),this.canvas.removeEventListener("pointerdown",c(this,Qr)),this.isEditing=!0,c(this,Zr)||(b(this,Zr,!0),y(this,N,Ma).call(this),this.thickness||(this.thickness=At._defaultThickness),this.color||(this.color=At._defaultColor||dt._defaultLineColor),this.opacity??(this.opacity=At._defaultOpacity)),this.currentPath.push([e,s]),b(this,Jr,!1),y(this,N,Xf).call(this),b(this,kn,()=>{y(this,N,mb).call(this),c(this,kn)&&window.requestAnimationFrame(c(this,kn))}),window.requestAnimationFrame(c(this,kn))},zf=function(e,s){const[i,n]=this.currentPath.at(-1);if(this.currentPath.length>1&&e===i&&s===n)return;const r=this.currentPath;let o=c(this,Ui);if(r.push([e,s]),b(this,Jr,!0),r.length<=2){o.moveTo(...r[0]),o.lineTo(e,s);return}r.length===3&&(b(this,Ui,o=new Path2D),o.moveTo(...r[0])),y(this,N,vb).call(this,o,...r.at(-3),...r.at(-2),e,s)},fb=function(){if(this.currentPath.length===0)return;const e=this.currentPath.at(-1);c(this,Ui).lineTo(...e)},pb=function(e,s){b(this,kn,null),e=Math.min(Math.max(e,0),this.canvas.width),s=Math.min(Math.max(s,0),this.canvas.height),y(this,N,zf).call(this,e,s),y(this,N,fb).call(this);let i;if(this.currentPath.length!==1)i=y(this,N,bb).call(this);else{const l=[e,s];i=[[l,l.slice(),l.slice(),l]]}const n=c(this,Ui),r=this.currentPath;this.currentPath=[],b(this,Ui,new Path2D);const o=()=>{this.allRawPaths.push(r),this.paths.push(i),this.bezierPath2D.push(n),this._uiManager.rebuild(this)},h=()=>{this.allRawPaths.pop(),this.paths.pop(),this.bezierPath2D.pop(),this.paths.length===0?this.remove():(this.canvas||(y(this,N,lu).call(this),y(this,N,cu).call(this)),y(this,N,Ql).call(this))};this.addCommands({cmd:o,undo:h,mustExec:!0})},mb=function(){if(!c(this,Jr))return;b(this,Jr,!1);const e=Math.ceil(this.thickness*this.parentScale),s=this.currentPath.slice(-3),i=s.map(o=>o[0]),n=s.map(o=>o[1]);Math.min(...i)-e,Math.max(...i)+e,Math.min(...n)-e,Math.max(...n)+e;const{ctx:r}=this;r.save(),r.clearRect(0,0,this.canvas.width,this.canvas.height);for(const o of this.bezierPath2D)r.stroke(o);r.stroke(c(this,Ui)),r.restore()},vb=function(e,s,i,n,r,o,h){const l=(s+n)/2,d=(i+r)/2,u=(n+o)/2,g=(r+h)/2;e.bezierCurveTo(l+2*(n-l)/3,d+2*(r-d)/3,u+2*(n-u)/3,g+2*(r-g)/3,u,g)},bb=function(){const e=this.currentPath;if(e.length<=2)return[[e[0],e[0],e.at(-1),e.at(-1)]];const s=[];let i,[n,r]=e[0];for(i=1;i<e.length-2;i++){const[f,p]=e[i],[m,_]=e[i+1],v=(f+m)/2,x=(p+_)/2,S=[n+2*(f-n)/3,r+2*(p-r)/3],T=[v+2*(f-v)/3,x+2*(p-x)/3];s.push([[n,r],S,T,[v,x]]),[n,r]=[v,x]}const[o,h]=e[i],[l,d]=e[i+1],u=[n+2*(o-n)/3,r+2*(h-r)/3],g=[l+2*(o-l)/3,d+2*(h-d)/3];return s.push([[n,r],u,g,[l,d]]),s},ao=function(){if(this.isEmpty()){y(this,N,du).call(this);return}y(this,N,Xf).call(this);const{canvas:e,ctx:s}=this;s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),y(this,N,du).call(this);for(const i of this.bezierPath2D)s.stroke(i)},Vf=function(e){this.canvas.removeEventListener("pointerleave",c(this,Fl)),this.canvas.removeEventListener("pointermove",c(this,Ll)),this.canvas.removeEventListener("pointerup",c(this,Rl)),this.canvas.addEventListener("pointerdown",c(this,Qr),{signal:this._uiManager._signal}),c(this,si)&&clearTimeout(c(this,si)),b(this,si,setTimeout(()=>{b(this,si,null),this.canvas.removeEventListener("contextmenu",Oe)},10)),y(this,N,pb).call(this,e.offsetX,e.offsetY),this.addToAnnotationStorage(),this.setInBackground()},lu=function(){this.canvas=document.createElement("canvas"),this.canvas.width=this.canvas.height=0,this.canvas.className="inkEditorCanvas",this.canvas.setAttribute("data-l10n-id","pdfjs-ink-canvas"),this.div.append(this.canvas),this.ctx=this.canvas.getContext("2d")},cu=function(){b(this,Yi,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&this.setDimensions(s.width,s.height)})),c(this,Yi).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,Yi))==null||e.disconnect(),b(this,Yi,null)},{once:!0})},Ma=function(){if(!c(this,Zr))return;const[e,s]=this.parentDimensions;this.canvas.width=Math.ceil(this.width*e),this.canvas.height=Math.ceil(this.height*s),y(this,N,du).call(this)},Gf=function(e,s){const i=y(this,N,uu).call(this),n=(e-i)/c(this,Kr),r=(s-i)/c(this,$r);this.scaleFactor=Math.min(n,r)},du=function(){const e=y(this,N,uu).call(this)/2;this.ctx.setTransform(this.scaleFactor,0,0,this.scaleFactor,this.translationX*this.scaleFactor+e,this.translationY*this.scaleFactor+e)},qi=new WeakSet,yb=function(e){const s=new Path2D;for(let i=0,n=e.length;i<n;i++){const[r,o,h,l]=e[i];i===0&&s.moveTo(...r),s.bezierCurveTo(o[0],o[1],h[0],h[1],l[0],l[1])}return s},Uf=function(e,s,i){const[n,r,o,h]=s;switch(i){case 0:for(let l=0,d=e.length;l<d;l+=2)e[l]+=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=e[l+1]+n,e[l+1]=u+r}break;case 180:for(let l=0,d=e.length;l<d;l+=2)e[l]=o-e[l],e[l+1]+=r;break;case 270:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=o-e[l+1],e[l+1]=h-u}break;default:throw new Error("Invalid rotation")}return e},_b=function(e,s,i){const[n,r,o,h]=s;switch(i){case 0:for(let l=0,d=e.length;l<d;l+=2)e[l]-=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=e[l+1]-r,e[l+1]=u-n}break;case 180:for(let l=0,d=e.length;l<d;l+=2)e[l]=o-e[l],e[l+1]-=r;break;case 270:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=h-e[l+1],e[l+1]=o-u}break;default:throw new Error("Invalid rotation")}return e},wb=function(e,s,i,n){var d,u;const r=[],o=this.thickness/2,h=e*s+o,l=e*i+o;for(const g of this.paths){const f=[],p=[];for(let m=0,_=g.length;m<_;m++){const[v,x,S,T]=g[m];if(v[0]===T[0]&&v[1]===T[1]&&_===1){const I=e*v[0]+h,X=e*v[1]+l;f.push(I,X),p.push(I,X);break}const E=e*v[0]+h,M=e*v[1]+l,P=e*x[0]+h,O=e*x[1]+l,R=e*S[0]+h,D=e*S[1]+l,L=e*T[0]+h,F=e*T[1]+l;m===0&&(f.push(E,M),p.push(E,M)),f.push(P,O,R,D,L,F),p.push(P,O),m===_-1&&p.push(L,F)}r.push({bezier:y(d=At,qi,Uf).call(d,f,n,this.rotation),points:y(u=At,qi,Uf).call(u,p,n,this.rotation)})}return r},Yf=function(){let e=1/0,s=-1/0,i=1/0,n=-1/0;for(const r of this.paths)for(const[o,h,l,d]of r){const u=z.bezierBoundingBox(...o,...h,...l,...d);e=Math.min(e,u[0]),i=Math.min(i,u[1]),s=Math.max(s,u[2]),n=Math.max(n,u[3])}return[e,i,s,n]},uu=function(){return c(this,hs)?Math.ceil(this.thickness*this.parentScale):0},Ql=function(e=!1){if(this.isEmpty())return;if(!c(this,hs)){y(this,N,ao).call(this);return}const s=y(this,N,Yf).call(this),i=y(this,N,uu).call(this);b(this,Kr,Math.max(dt.MIN_SIZE,s[2]-s[0])),b(this,$r,Math.max(dt.MIN_SIZE,s[3]-s[1]));const n=Math.ceil(i+c(this,Kr)*this.scaleFactor),r=Math.ceil(i+c(this,$r)*this.scaleFactor),[o,h]=this.parentDimensions;this.width=n/o,this.height=r/h,this.setAspectRatio(n,r);const l=this.translationX,d=this.translationY;this.translationX=-s[0],this.translationY=-s[1],y(this,N,Ma).call(this),y(this,N,ao).call(this),b(this,to,n),b(this,eo,r),this.setDims(n,r);const u=e?i/this.scaleFactor/2:0;this.translate(l-this.translationX-u,d-this.translationY-u)},w(At,qi),K(At,"_defaultColor",null),K(At,"_defaultOpacity",1),K(At,"_defaultThickness",1),K(At,"_type","ink"),K(At,"_editorType",nt.INK);let Yg=At;const Nl=class Nl extends dt{constructor(e){super({...e,name:"stampEditor"});w(this,ht);w(this,te,null);w(this,ee,null);w(this,Mn,null);w(this,$i,null);w(this,Dn,null);w(this,ba,"");w(this,ii,null);w(this,Il,!1);w(this,Ki,null);w(this,ni,null);w(this,Ds,!1);w(this,jl,!1);b(this,$i,e.bitmapUrl),b(this,Dn,e.bitmapFile)}static initialize(e,s){dt.initialize(e,s)}static get supportedTypes(){return at(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return at(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(nt.STAMP,{bitmapFile:e.getAsFile()})}remove(){var e,s;c(this,ee)&&(b(this,te,null),this._uiManager.imageManager.deleteId(c(this,ee)),(e=c(this,ii))==null||e.remove(),b(this,ii,null),(s=c(this,Ki))==null||s.disconnect(),b(this,Ki,null),c(this,ni)&&(clearTimeout(c(this,ni)),b(this,ni,null))),super.remove()}rebuild(){if(!this.parent){c(this,ee)&&y(this,ht,gu).call(this);return}super.rebuild(),this.div!==null&&(c(this,ee)&&c(this,ii)===null&&y(this,ht,gu).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(){this._isDraggable=!0,this.div.focus()}isEmpty(){return!(c(this,Mn)||c(this,te)||c(this,$i)||c(this,Dn)||c(this,ee))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.addAltTextButton(),c(this,te)?y(this,ht,qf).call(this):y(this,ht,gu).call(this),this.width){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this.div}getImageForAltText(){return c(this,ii)}static deserialize(e,s,i){if(e instanceof J0)return null;const n=super.deserialize(e,s,i),{rect:r,bitmapUrl:o,bitmapId:h,isSvg:l,accessibilityData:d}=e;h&&i.imageManager.isValidId(h)?b(n,ee,h):b(n,$i,o),b(n,Ds,l);const[u,g]=n.pageDimensions;return n.width=(r[2]-r[0])/u,n.height=(r[3]-r[1])/g,d&&(n.altTextData=d),n}serialize(e=!1,s=null){if(this.isEmpty())return null;const i={annotationType:nt.STAMP,bitmapId:c(this,ee),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:c(this,Ds),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=y(this,ht,fu).call(this,!0),i.accessibilityData=this.altTextData,i;const{decorative:n,altText:r}=this.altTextData;if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),s===null)return i;s.stamps||(s.stamps=new Map);const o=c(this,Ds)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(c(this,ee)))s.stamps.set(c(this,ee),{area:o,serialized:i}),i.bitmap=y(this,ht,fu).call(this,!1);else if(c(this,Ds)){const h=s.stamps.get(c(this,ee));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=y(this,ht,fu).call(this,!1))}return i}};te=new WeakMap,ee=new WeakMap,Mn=new WeakMap,$i=new WeakMap,Dn=new WeakMap,ba=new WeakMap,ii=new WeakMap,Il=new WeakMap,Ki=new WeakMap,ni=new WeakMap,Ds=new WeakMap,jl=new WeakMap,ht=new WeakSet,Jl=function(e,s=!1){if(!e){this.remove();return}b(this,te,e.bitmap),s||(b(this,ee,e.id),b(this,Ds,e.isSvg)),e.file&&b(this,ba,e.file.name),y(this,ht,qf).call(this)},Zl=function(){b(this,Mn,null),this._uiManager.enableWaiting(!1),c(this,ii)&&this.div.focus()},gu=function(){if(c(this,ee)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(c(this,ee)).then(i=>y(this,ht,Jl).call(this,i,!0)).finally(()=>y(this,ht,Zl).call(this));return}if(c(this,$i)){const i=c(this,$i);b(this,$i,null),this._uiManager.enableWaiting(!0),b(this,Mn,this._uiManager.imageManager.getFromUrl(i).then(n=>y(this,ht,Jl).call(this,n)).finally(()=>y(this,ht,Zl).call(this)));return}if(c(this,Dn)){const i=c(this,Dn);b(this,Dn,null),this._uiManager.enableWaiting(!0),b(this,Mn,this._uiManager.imageManager.getFromFile(i).then(n=>y(this,ht,Jl).call(this,n)).finally(()=>y(this,ht,Zl).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Nl.supportedTypesStr;const s=this._uiManager._signal;b(this,Mn,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);y(this,ht,Jl).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>y(this,ht,Zl).call(this))),e.click()},qf=function(){const{div:e}=this;let{width:s,height:i}=c(this,te);const[n,r]=this.pageDimensions,o=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>o*n||i>o*r){const u=Math.min(o*n/s,o*r/i);s*=u,i*=u}const[h,l]=this.parentDimensions;this.setDims(s*h/n,i*l/r),this._uiManager.enableWaiting(!1);const d=b(this,ii,document.createElement("canvas"));e.append(d),e.hidden=!1,y(this,ht,$f).call(this,s,i),y(this,ht,Ab).call(this),c(this,jl)||(this.parent.addUndoableEditor(this),b(this,jl,!0)),this._reportTelemetry({action:"inserted_image"}),c(this,ba)&&d.setAttribute("aria-label",c(this,ba))},xb=function(e,s){var o;const[i,n]=this.parentDimensions;this.width=e/i,this.height=s/n,this.setDims(e,s),(o=this._initialOptions)!=null&&o.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,c(this,ni)!==null&&clearTimeout(c(this,ni)),b(this,ni,setTimeout(()=>{b(this,ni,null),y(this,ht,$f).call(this,e,s)},200))},Sb=function(e,s){const{width:i,height:n}=c(this,te);let r=i,o=n,h=c(this,te);for(;r>2*e||o>2*s;){const l=r,d=o;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),o>2*s&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const u=new OffscreenCanvas(r,o);u.getContext("2d").drawImage(h,0,0,l,d,0,0,r,o),h=u.transferToImageBitmap()}return h},Cb=async function(e,s,i){if(c(this,Il)||(b(this,Il,!0),!await this._uiManager.isMLEnabledFor("altText")||this.hasAltText()))return;const o=new OffscreenCanvas(s,i).getContext("2d",{willReadFrequently:!0});o.drawImage(e,0,0,e.width,e.height,0,0,s,i);const h=await this._uiManager.mlGuess({service:"moz-image-to-text",request:{data:o.getImageData(0,0,s,i).data,width:s,height:i,channels:4}}),l=(h==null?void 0:h.output)||"";this.parent&&l&&!this.hasAltText()&&(this.altTextData={altText:l,decorative:!1})},$f=function(e,s){e=Math.ceil(e),s=Math.ceil(s);const i=c(this,ii);if(!i||i.width===e&&i.height===s)return;i.width=e,i.height=s;const n=c(this,Ds)?c(this,te):y(this,ht,Sb).call(this,e,s);y(this,ht,Cb).call(this,n,e,s);const r=i.getContext("2d");r.filter=this._uiManager.hcmFilter,r.drawImage(n,0,0,n.width,n.height,0,0,e,s)},fu=function(e){if(e){if(c(this,Ds)){const n=this._uiManager.imageManager.getSvgUrl(c(this,ee));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=c(this,te),s.getContext("2d").drawImage(c(this,te),0,0),s.toDataURL()}if(c(this,Ds)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*ln.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*ln.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(c(this,te),0,0,c(this,te).width,c(this,te).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(c(this,te))},Ab=function(){this._uiManager._signal&&(b(this,Ki,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&y(this,ht,xb).call(this,s.width,s.height)})),c(this,Ki).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,Ki))==null||e.disconnect(),b(this,Ki,null)},{once:!0}))},K(Nl,"_type","stamp"),K(Nl,"_editorType",nt.STAMP);let qg=Nl;const Os=class Os{constructor({uiManager:t,pageIndex:e,div:s,accessibilityManager:i,annotationLayer:n,drawLayer:r,textLayer:o,viewport:h,l10n:l}){w(this,se);w(this,so);w(this,ya,!1);w(this,ri,null);w(this,io,null);w(this,Qi,null);w(this,Ji,null);w(this,Zi,null);w(this,Ke,new Map);w(this,On,!1);w(this,_a,!1);w(this,wa,!1);w(this,fe,null);w(this,G);const d=[...c(Os,Pn).values()];if(!Os._initialized){Os._initialized=!0;for(const u of d)u.initialize(l,t)}t.registerEditorTypes(d),b(this,G,t),this.pageIndex=e,this.div=s,b(this,so,i),b(this,ri,n),this.viewport=h,b(this,fe,o),this.drawLayer=r,c(this,G).addLayer(this)}get isEmpty(){return c(this,Ke).size===0}get isInvisible(){return this.isEmpty&&c(this,G).getMode()===nt.NONE}updateToolbar(t){c(this,G).updateToolbar(t)}updateMode(t=c(this,G).getMode()){switch(y(this,se,pu).call(this),t){case nt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case nt.INK:this.addInkEditorIfNeeded(!1),this.disableTextSelection(),this.togglePointerEvents(!0),this.disableClick();break;case nt.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;for(const s of c(Os,Pn).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=c(this,fe))==null?void 0:e.div)}addInkEditorIfNeeded(t){if(c(this,G).getMode()!==nt.INK)return;if(!t){for(const s of c(this,Ke).values())if(s.isEmpty()){s.setInBackground();return}}this.createAndAddNewEditor({offsetX:0,offsetY:0},!1).setInBackground()}setEditingState(t){c(this,G).setEditingState(t)}addCommands(t){c(this,G).addCommands(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=c(this,ri))==null||e.div.classList.toggle("disabled",!t)}enable(){this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of c(this,Ke).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(c(this,G).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!c(this,ri))return;const e=c(this,ri).getEditableAnnotations();for(const s of e){if(s.hide(),c(this,G).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}}disable(){var i;b(this,wa,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of c(this,Ke).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(c(this,ri)){const n=c(this,ri).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(c(this,G).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(c(this,G).addChangedExistingAnnotation(h),h.renderAnnotationElement(r),h.show(!1)),r.show()}}y(this,se,pu).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of c(Os,Pn).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),b(this,wa,!1)}getEditableAnnotation(t){var e;return((e=c(this,ri))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){c(this,G).getActive()!==t&&c(this,G).setActiveEditor(t)}enableTextSelection(){var t;this.div.tabIndex=-1,(t=c(this,fe))!=null&&t.div&&!c(this,Ji)&&(b(this,Ji,y(this,se,Tb).bind(this)),c(this,fe).div.addEventListener("pointerdown",c(this,Ji),{signal:c(this,G)._signal}),c(this,fe).div.classList.add("highlighting"))}disableTextSelection(){var t;this.div.tabIndex=0,(t=c(this,fe))!=null&&t.div&&c(this,Ji)&&(c(this,fe).div.removeEventListener("pointerdown",c(this,Ji)),b(this,Ji,null),c(this,fe).div.classList.remove("highlighting"))}enableClick(){if(c(this,Qi))return;const t=c(this,G)._signal;b(this,Qi,this.pointerdown.bind(this)),b(this,io,this.pointerup.bind(this)),this.div.addEventListener("pointerdown",c(this,Qi),{signal:t}),this.div.addEventListener("pointerup",c(this,io),{signal:t})}disableClick(){c(this,Qi)&&(this.div.removeEventListener("pointerdown",c(this,Qi)),this.div.removeEventListener("pointerup",c(this,io)),b(this,Qi,null),b(this,io,null))}attach(t){c(this,Ke).set(t.id,t);const{annotationElementId:e}=t;e&&c(this,G).isDeletedAnnotationElement(e)&&c(this,G).removeDeletedAnnotationElement(t)}detach(t){var e;c(this,Ke).delete(t.id),(e=c(this,so))==null||e.removePointerInTextLayer(t.contentDiv),!c(this,wa)&&t.annotationElementId&&c(this,G).addDeletedAnnotationElement(t)}remove(t){this.detach(t),c(this,G).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1,c(this,_a)||this.addInkEditorIfNeeded(!1)}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(c(this,G).addDeletedAnnotationElement(t.annotationElementId),dt.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.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),c(this,G).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(),c(this,G).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!c(this,Zi)&&(t._focusEventsAllowed=!1,b(this,Zi,setTimeout(()=>{b(this,Zi,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:c(this,G)._signal}),e.focus())},0))),t._structTreeParentId=(s=c(this,so))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return c(this,G).getId()}get _signal(){return c(this,G)._signal}canCreateNewEmptyEditor(){var t;return(t=c(this,se,Kf))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){c(this,G).updateToolbar(t),c(this,G).updateMode(t);const{offsetX:s,offsetY:i}=y(this,se,Jf).call(this),n=this.getNextId(),r=y(this,se,Qf).call(this,{parent:this,id:n,x:s,y:i,uiManager:c(this,G),isCentered:!0,...e});r&&this.add(r)}deserialize(t){var e;return((e=c(Os,Pn).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,c(this,G)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=y(this,se,Qf).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:c(this,G),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(y(this,se,Jf).call(this),!0)}setSelected(t){c(this,G).setSelected(t)}toggleSelected(t){c(this,G).toggleSelected(t)}isSelected(t){return c(this,G).isSelected(t)}unselect(t){c(this,G).unselect(t)}pointerup(t){const{isMac:e}=De.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&c(this,On)){if(b(this,On,!1),!c(this,ya)){b(this,ya,!0);return}if(c(this,G).getMode()===nt.STAMP){c(this,G).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(c(this,G).getMode()===nt.HIGHLIGHT&&this.enableTextSelection(),c(this,On)){b(this,On,!1);return}const{isMac:e}=De.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;b(this,On,!0);const s=c(this,G).getActive();b(this,ya,!s||s.isEmpty())}findNewParent(t,e,s){const i=c(this,G).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}destroy(){var t,e;((t=c(this,G).getActive())==null?void 0:t.parent)===this&&(c(this,G).commitOrRemove(),c(this,G).setActiveEditor(null)),c(this,Zi)&&(clearTimeout(c(this,Zi)),b(this,Zi,null));for(const s of c(this,Ke).values())(e=c(this,so))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,c(this,Ke).clear(),c(this,G).removeLayer(this)}render({viewport:t}){this.viewport=t,Zn(this.div,t);for(const e of c(this,G).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){c(this,G).commitOrRemove(),y(this,se,pu).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Zn(this.div,{rotation:s}),e!==s)for(const i of c(this,Ke).values())i.rotate(s);this.addInkEditorIfNeeded(!1)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return c(this,G).viewParameters.realScale}};so=new WeakMap,ya=new WeakMap,ri=new WeakMap,io=new WeakMap,Qi=new WeakMap,Ji=new WeakMap,Zi=new WeakMap,Ke=new WeakMap,On=new WeakMap,_a=new WeakMap,wa=new WeakMap,fe=new WeakMap,G=new WeakMap,Pn=new WeakMap,se=new WeakSet,Tb=function(t){c(this,G).unselectAll();const{target:e}=t;if(e===c(this,fe).div||e.classList.contains("endOfContent")&&c(this,fe).div.contains(e)){const{isMac:s}=De.platform;if(t.button!==0||t.ctrlKey&&s)return;c(this,G).showAllEditors("highlight",!0,!0),c(this,fe).div.classList.add("free"),this.toggleDrawing(),Cd.startHighlighting(this,c(this,G).direction==="ltr",t),c(this,fe).div.addEventListener("pointerup",()=>{c(this,fe).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:c(this,G)._signal}),t.preventDefault()}},Kf=function(){return c(Os,Pn).get(c(this,G).getMode())},Qf=function(t){const e=c(this,se,Kf);return e?new e.prototype.constructor(t):null},Jf=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),l=(n+o)/2-t,d=(r+h)/2-e,[u,g]=this.viewport.rotation%180===0?[l,d]:[d,l];return{offsetX:u,offsetY:g}},pu=function(){b(this,_a,!0);for(const t of c(this,Ke).values())t.isEmpty()&&t.remove();b(this,_a,!1)},K(Os,"_initialized",!1),w(Os,Pn,new Map([Gg,Yg,qg,Cd].map(t=>[t._editorType,t])));let $g=Os;const ie=class ie{constructor({pageIndex:t}){w(this,no);w(this,oi,null);w(this,Bl,0);w(this,Ut,new Map);w(this,Ln,new Map);this.pageIndex=t}setParent(t){if(!c(this,oi)){b(this,oi,t);return}if(c(this,oi)!==t){if(c(this,Ut).size>0)for(const e of c(this,Ut).values())e.remove(),t.append(e);b(this,oi,t)}}static get _svgFactory(){return at(this,"_svgFactory",new Ag)}highlight(t,e,s,i=!1){const n=Je(this,Bl)._++,r=y(this,no,tp).call(this,t.box);r.classList.add("highlight"),t.free&&r.classList.add("free");const o=ie._svgFactory.createElement("defs");r.append(o);const h=ie._svgFactory.createElement("path");o.append(h);const l=`path_p${this.pageIndex}_${n}`;h.setAttribute("id",l),h.setAttribute("d",t.toSVGPath()),i&&c(this,Ln).set(n,h);const d=y(this,no,Eb).call(this,o,l),u=ie._svgFactory.createElement("use");return r.append(u),r.setAttribute("fill",e),r.setAttribute("fill-opacity",s),u.setAttribute("href",`#${l}`),c(this,Ut).set(n,r),{id:n,clipPathId:`url(#${d})`}}highlightOutline(t){const e=Je(this,Bl)._++,s=y(this,no,tp).call(this,t.box);s.classList.add("highlightOutline");const i=ie._svgFactory.createElement("defs");s.append(i);const n=ie._svgFactory.createElement("path");i.append(n);const r=`path_p${this.pageIndex}_${e}`;n.setAttribute("id",r),n.setAttribute("d",t.toSVGPath()),n.setAttribute("vector-effect","non-scaling-stroke");let o;if(t.free){s.classList.add("free");const d=ie._svgFactory.createElement("mask");i.append(d),o=`mask_p${this.pageIndex}_${e}`,d.setAttribute("id",o),d.setAttribute("maskUnits","objectBoundingBox");const u=ie._svgFactory.createElement("rect");d.append(u),u.setAttribute("width","1"),u.setAttribute("height","1"),u.setAttribute("fill","white");const g=ie._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${r}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const h=ie._svgFactory.createElement("use");s.append(h),h.setAttribute("href",`#${r}`),o&&h.setAttribute("mask",`url(#${o})`);const l=h.cloneNode();return s.append(l),h.classList.add("mainOutline"),l.classList.add("secondaryOutline"),c(this,Ut).set(e,s),e}finalizeLine(t,e){const s=c(this,Ln).get(t);c(this,Ln).delete(t),this.updateBox(t,e.box),s.setAttribute("d",e.toSVGPath())}updateLine(t,e){c(this,Ut).get(t).firstChild.firstChild.setAttribute("d",e.toSVGPath())}removeFreeHighlight(t){this.remove(t),c(this,Ln).delete(t)}updatePath(t,e){c(this,Ln).get(t).setAttribute("d",e.toSVGPath())}updateBox(t,e){var s;y(s=ie,Hl,Zf).call(s,c(this,Ut).get(t),e)}show(t,e){c(this,Ut).get(t).classList.toggle("hidden",!e)}rotate(t,e){c(this,Ut).get(t).setAttribute("data-main-rotation",e)}changeColor(t,e){c(this,Ut).get(t).setAttribute("fill",e)}changeOpacity(t,e){c(this,Ut).get(t).setAttribute("fill-opacity",e)}addClass(t,e){c(this,Ut).get(t).classList.add(e)}removeClass(t,e){c(this,Ut).get(t).classList.remove(e)}remove(t){c(this,oi)!==null&&(c(this,Ut).get(t).remove(),c(this,Ut).delete(t))}destroy(){b(this,oi,null);for(const t of c(this,Ut).values())t.remove();c(this,Ut).clear()}};oi=new WeakMap,Bl=new WeakMap,Ut=new WeakMap,Ln=new WeakMap,Hl=new WeakSet,Zf=function(t,{x:e=0,y:s=0,width:i=1,height:n=1}={}){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},no=new WeakSet,tp=function(t){var s;const e=ie._svgFactory.create(1,1,!0);return c(this,oi).append(e),e.setAttribute("aria-hidden",!0),y(s=ie,Hl,Zf).call(s,e,t),e},Eb=function(t,e){const s=ie._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=ie._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},w(ie,Hl);let Kg=ie;$.AbortException,$.AnnotationEditorLayer,$.AnnotationEditorParamsType,$.AnnotationEditorType,$.AnnotationEditorUIManager,$.AnnotationLayer,$.AnnotationMode,$.CMapCompressionType,$.ColorPicker,$.DOMSVGFactory,$.DrawLayer,$.FeatureTest;var oS=$.GlobalWorkerOptions;$.ImageKind,$.InvalidPDFException,$.MissingPDFException,$.OPS,$.PDFDataRangeTransport,$.PDFDateString,$.PDFWorker,$.PasswordResponses,$.PermissionFlag,$.PixelsPerInch,$.RenderingCancelledException,$.TextLayer,$.UnexpectedResponseException,$.Util,$.VerbosityLevel,$.XfaLayer,$.build,$.createValidAbsoluteUrl,$.fetchData;var aS=$.getDocument;$.getFilenameFromUrl,$.getPdfFilenameFromUrl,$.getXfaPageViewport,$.isDataScheme,$.isPdfFile,$.noContextMenu,$.normalizeUnicode,$.setLayerDimensions,$.shadow,$.version;const hS={fabric:"^6.3.0","pdfjs-dist":"^4.5.136"};function lS(a){return new Promise((t,e)=>{const s=new FileReader;s.onload=()=>t(s.result),s.onerror=e,s.readAsDataURL(a)})}const cS=hS["pdfjs-dist"].replace("^","");oS.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${cS}/pdf.worker.min.mjs`;async function dS(a){const t="data:application/pdf;base64,",e=await lS(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function uS(a,t){return aS({data:a,password:t}).promise}const gS="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function fS(a){return new URL(Object.assign({"../assets/close.svg":gS})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Et&&Et.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function pS(a){return new Promise((t,e)=>{const s=window.URL.createObjectURL(a),i=new Image;i.src=s,i.onload=async()=>{window.URL.revokeObjectURL(s),t(await mS(i))},i.onerror=n=>{window.URL.revokeObjectURL(s),e(n)}})}function mS(a){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=a;e.width=i,e.height=n,s==null||s.drawImage(a,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let ev=null;function vS(){const a=document.createElement("div");a.style.width="1in",document.body.appendChild(a);const t=a.offsetWidth;return document.body.removeChild(a),t}function bS(){const a=ev??vS();return ev=a,a/72}const yS={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},_S={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},wS={stroke:"#000",hoverStroke:"#B7EC5D",src:""},ss=new Map;function sv(a=""){let t=0,e=null,s=null,i=1,n={...wS};function r(){if(!a||ss.has(a))return;const D=new ig(a);return ss.set(a,D),D.on("selection:cleared",()=>P(D)),D}function o(D,L){const F=D.type;return{"application/pdf":h,"image/png":g,"image/jpeg":g}[F](D,L)??Promise.reject(new Error(`Unsupported ${F} file type.`))}async function h(D,L){const F=await dS(D);if(!F)return;const I=Date.now(),Y={PDFId:`${D.name}-${I}`,name:D.name.replace(/.pdf/,""),updateDate:I,PDFBase64:F};try{return await l({page:1,PDFBase64:F,scale:.8,password:L}),{...Y,pages:t}}catch(J){return Promise.reject(J)}}async function l({page:D,PDFBase64:L,scale:F,password:I}){try{const X=await uS(L,I),Y=await U.toRaw(X).getPage(D),J=Y.getViewport({scale:F}),W=document.createElement("canvas"),V=W.getContext("2d"),It=bS()/window.devicePixelRatio;W.width=Math.floor(J.width*It),W.height=Math.floor(J.height*It),t=X.numPages;const Ie={canvasContext:V,viewport:J,transform:[It,0,0,It,0,0]};return Y.render(Ie).promise.then(()=>d(W))}catch(X){return Promise.reject(X)}}function d(D){if(!ss.get(a))return;const F=1/3,I=u(D,F);p(I,F)}function u(D,L){return new ae(D,{scaleX:L,scaleY:L})}async function g(D){const L=await pS(D),F=Date.now(),X={PDFId:`${D.name}${F}`,name:D.name.replace(/.png|.jpg|.jpeg/,""),updateDate:F,PDFBase64:L};return f({url:L}),{...X,pages:1}}async function f({url:D,scale:L=.5}){if(!ss.get(a))return;const I=await ae.fromURL(D);I.scale(L),p(I,L)}function p(D,L){const F=ss.get(a);F&&(F.setWidth(D.width*L),F.setHeight(D.height*L),F.backgroundImage=D,F.renderAll())}async function m(D,L){const F=ss.get(a);if(!F)return;const I=await ae.fromURL(D,{},{...yS,...L});F.add(I),v(F,I)}function _(D,L){const F=ss.get(a);if(!F)return;const I=new oe(D,{..._S,...L});F.add(I),v(F,I)}function v(D,L){L.on("selected",F=>x({canvas:D,target:F.target})),L.on("modified",F=>T(F.target)),L.on("scaling",F=>T(F.transform.target)),L.on("moving",F=>T(F.transform.target)),L.on("rotating",F=>T(F.transform.target))}async function x({canvas:D,target:L,stroke:F=n.stroke,uuid:I=Date.now()}){if((e==null?void 0:e.stroke)===`${F}-${I}`)return;const X=n.src||fS("close.svg"),{objects:Y,options:J}=await Z_(X),W=Y.filter(It=>It!==null),V=g_.groupSVGElements(W,J);W.forEach(It=>{It.stroke=F}),V.hoverCursor="pointer",V.stroke=`${F}-${I}`,P(D),e=V,s=L,S(D,L,I),E(i,!0),D.add(V)}function S(D,L,F){e&&(e.on("selected",()=>{D.remove(L),P(D)}),e.on("mouseover",()=>{x({canvas:D,target:L,stroke:n.hoverStroke,uuid:F})}),e.on("mouseout",()=>{x({canvas:D,target:L,stroke:n.stroke,uuid:F})}))}function T(D){if(!e)return;const{oCoords:L}=D;if(!L)return;const{x:F,y:I}=L.tl.touchCorner.tl,{height:X,width:Y,scaleY:J,scaleX:W}=e;e.top=I-X*J/2,e.left=F-Y*W/2,e.setCoords()}function E(D,L=!1){var F;i=D,!(!e||!s)&&(e.scale(1/D),T(s),!L&&((F=ss.get(a))==null||F.renderAll()))}function M(D){if(!D)return;n={...n,...D};const L=ss.get(a);!e||!s||!L||x({target:s,canvas:L})}function P(D){e&&(D.remove(e),e=s=null)}function O(){const D=ss.get(a);D&&(D.discardActiveObject(),D.renderAll())}function R(){const D=ss.get(a);D&&(D.clear(),ss.delete(a))}return{createCanvas:r,loadFile:o,specifyPage:l,renderImage:f,addFabric:m,addTextFabric:_,clearActive:O,deleteCanvas:R,scaleCloseFabric:E,setCloseSvgOptions:M}}const Qg=U.defineComponent({__name:"PdfCanvas",props:{file:{},page:{default:1},canvasId:{default:"PDF-canvas"},fileZoom:{default:1},fileScale:{default:1},canvasScale:{default:1},canvasClass:{default:""},isDrop:{type:Boolean,default:!1},password:{},dropTextOptions:{},dropImageOptions:{},closeSvgOptions:{}},setup(a,{expose:t}){const e=a,s=U.ref(null),i=`${e.canvasId}-${e.page-1}`,n=U.computed(()=>e.fileZoom*e.canvasScale),{createCanvas:r,specifyPage:o,addFabric:h,addTextFabric:l,renderImage:d,clearActive:u,deleteCanvas:g,scaleCloseFabric:f,setCloseSvgOptions:p}=sv(i);m();async function m(){const{file:S,page:T,fileScale:E}=e;window.requestAnimationFrame(async()=>{if(await U.nextTick(),r(),S.PDFBase64.startsWith("data:image")||S.canvas){const{canvas:M}=S,P=M?7:3,O=M!=null&&M.length?M[T-1]:S.PDFBase64;d({url:O,scale:E/P});return}await o({page:T,PDFBase64:S.PDFBase64,scale:E,password:e.password})})}function _(S){if(!e.isDrop||!S.dataTransfer)return;const{dataTransfer:T,offsetX:E,offsetY:M}=S,P=T.getData("text"),O=T.getData("image"),R={left:E-71,top:M-55};O&&v(O,R),P&&x(P,R)}function v(S,T){h(S,{...T,...e.dropImageOptions})}function x(S,T){l(S,{...T,...e.dropTextOptions})}return U.watch([()=>e.fileScale,()=>e.page,()=>e.file,()=>e.password],m),U.watch(n,S=>f(S),{immediate:!0}),U.watch(()=>e.closeSvgOptions,p,{immediate:!0}),U.onBeforeUnmount(g),t({addImage:v,addText:x,clearActive:u,deleteCanvas:g,canvasRef:s}),(S,T)=>(U.openBlock(),U.createElementBlock("div",{style:U.normalizeStyle({transform:`scale(${n.value})`}),onDragover:T[0]||(T[0]=U.withModifiers(()=>{},["stop","prevent"])),onDragenter:T[1]||(T[1]=U.withModifiers(()=>{},["stop","prevent"])),onDrop:U.withModifiers(_,["stop","prevent"])},[U.createElementVNode("canvas",{id:i,ref_key:"canvasRef",ref:s,class:U.normalizeClass(S.canvasClass)},null,2)],36))}});Qg.install=function(a){a.component("PdfCanvas",Qg)};const Ad=Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"}));st.default=Qg,st.useFabric=sv,Object.defineProperties(st,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
509
|
+
`)){const s=document.createElement("div");s.append(e?document.createTextNode(e):document.createElement("br")),this.editorDiv.append(s)}},Yv=function(){return c(this,Ue).replaceAll(" "," ")},Ff=function(e){return e.replaceAll(" "," ")},qv=function(e){const{value:s,fontSize:i,color:n,pageIndex:r}=c(this,na);return this._hasBeenMoved||e.value!==s||e.fontSize!==i||e.color.some((o,h)=>o!==n[h])||e.pageIndex!==r},w(_t,Wi),K(_t,"_freeTextDefaultContent",""),K(_t,"_internalPadding",0),K(_t,"_defaultColor",null),K(_t,"_defaultFontSize",10),K(_t,"_type","freetext"),K(_t,"_editorType",nt.FREETEXT);let Gg=_t;class Z0{constructor(t,e=0,s=0,i=!0){w(this,Ae);w(this,ml);w(this,An,[]);w(this,Ts,[]);let n=1/0,r=-1/0,o=1/0,h=-1/0;const d=10**-4;for(const{x:v,y:x,width:S,height:T}of t){const E=Math.floor((v-e)/d)*d,M=Math.ceil((v+S+e)/d)*d,P=Math.floor((x-e)/d)*d,O=Math.ceil((x+T+e)/d)*d,R=[E,P,O,!0],D=[M,P,O,!1];c(this,An).push(R,D),n=Math.min(n,E),r=Math.max(r,M),o=Math.min(o,P),h=Math.max(h,O)}const u=r-n+2*s,g=h-o+2*s,f=n-s,p=o-s,m=c(this,An).at(i?-1:-2),_=[m[0],m[2]];for(const v of c(this,An)){const[x,S,T]=v;v[0]=(x-f)/u,v[1]=(S-p)/g,v[2]=(T-p)/g}b(this,ml,{x:f,y:p,width:u,height:g,lastPoint:_})}getOutlines(){c(this,An).sort((e,s)=>e[0]-s[0]||e[1]-s[1]||e[2]-s[2]);const t=[];for(const e of c(this,An))e[3]?(t.push(...y(this,Ae,Rf).call(this,e)),y(this,Ae,Kv).call(this,e)):(y(this,Ae,Qv).call(this,e),t.push(...y(this,Ae,Rf).call(this,e)));return y(this,Ae,$v).call(this,t)}}ml=new WeakMap,An=new WeakMap,Ts=new WeakMap,Ae=new WeakSet,$v=function(t){const e=[],s=new Set;for(const r of t){const[o,h,l]=r;e.push([o,h,r],[o,l,r])}e.sort((r,o)=>r[1]-o[1]||r[0]-o[0]);for(let r=0,o=e.length;r<o;r+=2){const h=e[r][2],l=e[r+1][2];h.push(l),l.push(h),s.add(h),s.add(l)}const i=[];let n;for(;s.size>0;){const r=s.values().next().value;let[o,h,l,d,u]=r;s.delete(r);let g=o,f=h;for(n=[o,l],i.push(n);;){let p;if(s.has(d))p=d;else if(s.has(u))p=u;else break;s.delete(p),[o,h,l,d,u]=p,g!==o&&(n.push(g,f,o,f===h?h:l),g=o),f=f===h?l:h}n.push(g,f)}return new rS(i,c(this,ml))},au=function(t){const e=c(this,Ts);let s=0,i=e.length-1;for(;s<=i;){const n=s+i>>1,r=e[n][0];if(r===t)return n;r<t?s=n+1:i=n-1}return i+1},Kv=function([,t,e]){const s=y(this,Ae,au).call(this,t);c(this,Ts).splice(s,0,[t,e])},Qv=function([,t,e]){const s=y(this,Ae,au).call(this,t);for(let i=s;i<c(this,Ts).length;i++){const[n,r]=c(this,Ts)[i];if(n!==t)break;if(n===t&&r===e){c(this,Ts).splice(i,1);return}}for(let i=s-1;i>=0;i--){const[n,r]=c(this,Ts)[i];if(n!==t)break;if(n===t&&r===e){c(this,Ts).splice(i,1);return}}},Rf=function(t){const[e,s,i]=t,n=[[e,s,i]],r=y(this,Ae,au).call(this,i);for(let o=0;o<r;o++){const[h,l]=c(this,Ts)[o];for(let d=0,u=n.length;d<u;d++){const[,g,f]=n[d];if(!(l<=g||f<=h)){if(g>=h){if(f>l)n[d][1]=l;else{if(u===1)return[];n.splice(d,1),d--,u--}continue}n[d][2]=h,f>l&&n.push([e,l,f])}}}return n};class tv{toSVGPath(){throw new Error("Abstract method `toSVGPath` must be implemented.")}get box(){throw new Error("Abstract getter `box` must be implemented.")}serialize(t,e){throw new Error("Abstract method `serialize` must be implemented.")}get free(){return this instanceof Ug}}class rS extends tv{constructor(e,s){super();w(this,vl);w(this,ra);b(this,ra,e),b(this,vl,s)}toSVGPath(){const e=[];for(const s of c(this,ra)){let[i,n]=s;e.push(`M${i} ${n}`);for(let r=2;r<s.length;r+=2){const o=s[r],h=s[r+1];o===i?(e.push(`V${h}`),n=h):h===n&&(e.push(`H${o}`),i=o)}e.push("Z")}return e.join(" ")}serialize([e,s,i,n],r){const o=[],h=i-e,l=n-s;for(const d of c(this,ra)){const u=new Array(d.length);for(let g=0;g<d.length;g+=2)u[g]=e+d[g]*h,u[g+1]=n-d[g+1]*l;o.push(u)}return o}get box(){return c(this,vl)}}vl=new WeakMap,ra=new WeakMap;const zi=class zi{constructor({x:t,y:e},s,i,n,r,o=0){w(this,wl);w(this,Zs);w(this,Xi,[]);w(this,oa);w(this,aa);w(this,ti,[]);w(this,rt,new Float64Array(18));w(this,Xr);w(this,zr);w(this,bl);w(this,yl);w(this,ha);w(this,la);w(this,Tn,[]);b(this,Zs,s),b(this,la,n*i),b(this,aa,r),c(this,rt).set([NaN,NaN,NaN,NaN,t,e],6),b(this,oa,o),b(this,yl,c(zi,_l)*i),b(this,bl,c(zi,zd)*i),b(this,ha,i),c(this,Tn).push(t,e)}get free(){return!0}isEmpty(){return isNaN(c(this,rt)[8])}add({x:t,y:e}){var R;b(this,Xr,t),b(this,zr,e);const[s,i,n,r]=c(this,Zs);let[o,h,l,d]=c(this,rt).subarray(8,12);const u=t-l,g=e-d,f=Math.hypot(u,g);if(f<c(this,bl))return!1;const p=f-c(this,yl),m=p/f,_=m*u,v=m*g;let x=o,S=h;o=l,h=d,l+=_,d+=v,(R=c(this,Tn))==null||R.push(t,e);const T=-v/p,E=_/p,M=T*c(this,la),P=E*c(this,la);return c(this,rt).set(c(this,rt).subarray(2,8),0),c(this,rt).set([l+M,d+P],4),c(this,rt).set(c(this,rt).subarray(14,18),12),c(this,rt).set([l-M,d-P],16),isNaN(c(this,rt)[6])?(c(this,ti).length===0&&(c(this,rt).set([o+M,h+P],2),c(this,ti).push(NaN,NaN,NaN,NaN,(o+M-s)/n,(h+P-i)/r),c(this,rt).set([o-M,h-P],14),c(this,Xi).push(NaN,NaN,NaN,NaN,(o-M-s)/n,(h-P-i)/r)),c(this,rt).set([x,S,o,h,l,d],6),!this.isEmpty()):(c(this,rt).set([x,S,o,h,l,d],6),Math.abs(Math.atan2(S-h,x-o)-Math.atan2(v,_))<Math.PI/2?([o,h,l,d]=c(this,rt).subarray(2,6),c(this,ti).push(NaN,NaN,NaN,NaN,((o+l)/2-s)/n,((h+d)/2-i)/r),[o,h,x,S]=c(this,rt).subarray(14,18),c(this,Xi).push(NaN,NaN,NaN,NaN,((x+o)/2-s)/n,((S+h)/2-i)/r),!0):([x,S,o,h,l,d]=c(this,rt).subarray(0,6),c(this,ti).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+d)/6-i)/r,((o+l)/2-s)/n,((h+d)/2-i)/r),[l,d,o,h,x,S]=c(this,rt).subarray(12,18),c(this,Xi).push(((x+5*o)/6-s)/n,((S+5*h)/6-i)/r,((5*o+l)/6-s)/n,((5*h+d)/6-i)/r,((o+l)/2-s)/n,((h+d)/2-i)/r),!0))}toSVGPath(){if(this.isEmpty())return"";const t=c(this,ti),e=c(this,Xi),s=c(this,rt).subarray(4,6),i=c(this,rt).subarray(16,18),[n,r,o,h]=c(this,Zs),[l,d,u,g]=y(this,wl,If).call(this);if(isNaN(c(this,rt)[6])&&!this.isEmpty())return`M${(c(this,rt)[2]-n)/o} ${(c(this,rt)[3]-r)/h} L${(c(this,rt)[4]-n)/o} ${(c(this,rt)[5]-r)/h} L${l} ${d} L${u} ${g} L${(c(this,rt)[16]-n)/o} ${(c(this,rt)[17]-r)/h} L${(c(this,rt)[14]-n)/o} ${(c(this,rt)[15]-r)/h} Z`;const f=[];f.push(`M${t[4]} ${t[5]}`);for(let p=6;p<t.length;p+=6)isNaN(t[p])?f.push(`L${t[p+4]} ${t[p+5]}`):f.push(`C${t[p]} ${t[p+1]} ${t[p+2]} ${t[p+3]} ${t[p+4]} ${t[p+5]}`);f.push(`L${(s[0]-n)/o} ${(s[1]-r)/h} L${l} ${d} L${u} ${g} L${(i[0]-n)/o} ${(i[1]-r)/h}`);for(let p=e.length-6;p>=6;p-=6)isNaN(e[p])?f.push(`L${e[p+4]} ${e[p+5]}`):f.push(`C${e[p]} ${e[p+1]} ${e[p+2]} ${e[p+3]} ${e[p+4]} ${e[p+5]}`);return f.push(`L${e[4]} ${e[5]} Z`),f.join(" ")}getOutlines(){var v;const t=c(this,ti),e=c(this,Xi),s=c(this,rt),i=s.subarray(4,6),n=s.subarray(16,18),[r,o,h,l]=c(this,Zs),d=new Float64Array((((v=c(this,Tn))==null?void 0:v.length)??0)+2);for(let x=0,S=d.length-2;x<S;x+=2)d[x]=(c(this,Tn)[x]-r)/h,d[x+1]=(c(this,Tn)[x+1]-o)/l;d[d.length-2]=(c(this,Xr)-r)/h,d[d.length-1]=(c(this,zr)-o)/l;const[u,g,f,p]=y(this,wl,If).call(this);if(isNaN(s[6])&&!this.isEmpty()){const x=new Float64Array(36);return x.set([NaN,NaN,NaN,NaN,(s[2]-r)/h,(s[3]-o)/l,NaN,NaN,NaN,NaN,(s[4]-r)/h,(s[5]-o)/l,NaN,NaN,NaN,NaN,u,g,NaN,NaN,NaN,NaN,f,p,NaN,NaN,NaN,NaN,(s[16]-r)/h,(s[17]-o)/l,NaN,NaN,NaN,NaN,(s[14]-r)/h,(s[15]-o)/l],0),new Ug(x,d,c(this,Zs),c(this,ha),c(this,oa),c(this,aa))}const m=new Float64Array(c(this,ti).length+24+c(this,Xi).length);let _=t.length;for(let x=0;x<_;x+=2){if(isNaN(t[x])){m[x]=m[x+1]=NaN;continue}m[x]=t[x],m[x+1]=t[x+1]}m.set([NaN,NaN,NaN,NaN,(i[0]-r)/h,(i[1]-o)/l,NaN,NaN,NaN,NaN,u,g,NaN,NaN,NaN,NaN,f,p,NaN,NaN,NaN,NaN,(n[0]-r)/h,(n[1]-o)/l],_),_+=24;for(let x=e.length-6;x>=6;x-=6)for(let S=0;S<6;S+=2){if(isNaN(e[x+S])){m[_]=m[_+1]=NaN,_+=2;continue}m[_]=e[x+S],m[_+1]=e[x+S+1],_+=2}return m.set([NaN,NaN,NaN,NaN,e[4],e[5]],_),new Ug(m,d,c(this,Zs),c(this,ha),c(this,oa),c(this,aa))}};Zs=new WeakMap,Xi=new WeakMap,oa=new WeakMap,aa=new WeakMap,ti=new WeakMap,rt=new WeakMap,Xr=new WeakMap,zr=new WeakMap,bl=new WeakMap,yl=new WeakMap,ha=new WeakMap,la=new WeakMap,Tn=new WeakMap,_l=new WeakMap,Xd=new WeakMap,zd=new WeakMap,wl=new WeakSet,If=function(){const t=c(this,rt).subarray(4,6),e=c(this,rt).subarray(16,18),[s,i,n,r]=c(this,Zs);return[(c(this,Xr)+(t[0]-e[0])/2-s)/n,(c(this,zr)+(t[1]-e[1])/2-i)/r,(c(this,Xr)+(e[0]-t[0])/2-s)/n,(c(this,zr)+(e[1]-t[1])/2-i)/r]},w(zi,_l,8),w(zi,Xd,2),w(zi,zd,c(zi,_l)+c(zi,Xd));let xd=zi;class Ug extends tv{constructor(e,s,i,n,r,o){super();w(this,Re);w(this,ca);w(this,Vr,null);w(this,Vi);w(this,xl);w(this,qe);w(this,Sl);w(this,Rt);b(this,Rt,e),b(this,qe,s),b(this,ca,i),b(this,Sl,n),b(this,Vi,r),b(this,xl,o),y(this,Re,Jv).call(this,o);const{x:h,y:l,width:d,height:u}=c(this,Vr);for(let g=0,f=e.length;g<f;g+=2)e[g]=(e[g]-h)/d,e[g+1]=(e[g+1]-l)/u;for(let g=0,f=s.length;g<f;g+=2)s[g]=(s[g]-h)/d,s[g+1]=(s[g+1]-l)/u}toSVGPath(){const e=[`M${c(this,Rt)[4]} ${c(this,Rt)[5]}`];for(let s=6,i=c(this,Rt).length;s<i;s+=6){if(isNaN(c(this,Rt)[s])){e.push(`L${c(this,Rt)[s+4]} ${c(this,Rt)[s+5]}`);continue}e.push(`C${c(this,Rt)[s]} ${c(this,Rt)[s+1]} ${c(this,Rt)[s+2]} ${c(this,Rt)[s+3]} ${c(this,Rt)[s+4]} ${c(this,Rt)[s+5]}`)}return e.push("Z"),e.join(" ")}serialize([e,s,i,n],r){const o=i-e,h=n-s;let l,d;switch(r){case 0:l=y(this,Re,Yl).call(this,c(this,Rt),e,n,o,-h),d=y(this,Re,Yl).call(this,c(this,qe),e,n,o,-h);break;case 90:l=y(this,Re,ql).call(this,c(this,Rt),e,s,o,h),d=y(this,Re,ql).call(this,c(this,qe),e,s,o,h);break;case 180:l=y(this,Re,Yl).call(this,c(this,Rt),i,s,-o,h),d=y(this,Re,Yl).call(this,c(this,qe),i,s,-o,h);break;case 270:l=y(this,Re,ql).call(this,c(this,Rt),i,n,-o,-h),d=y(this,Re,ql).call(this,c(this,qe),i,n,-o,-h);break}return{outline:Array.from(l),points:[Array.from(d)]}}get box(){return c(this,Vr)}getNewOutline(e,s){const{x:i,y:n,width:r,height:o}=c(this,Vr),[h,l,d,u]=c(this,ca),g=r*d,f=o*u,p=i*d+h,m=n*u+l,_=new xd({x:c(this,qe)[0]*g+p,y:c(this,qe)[1]*f+m},c(this,ca),c(this,Sl),e,c(this,xl),s??c(this,Vi));for(let v=2;v<c(this,qe).length;v+=2)_.add({x:c(this,qe)[v]*g+p,y:c(this,qe)[v+1]*f+m});return _.getOutlines()}}ca=new WeakMap,Vr=new WeakMap,Vi=new WeakMap,xl=new WeakMap,qe=new WeakMap,Sl=new WeakMap,Rt=new WeakMap,Re=new WeakSet,Yl=function(e,s,i,n,r){const o=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)o[h]=s+e[h]*n,o[h+1]=i+e[h+1]*r;return o},ql=function(e,s,i,n,r){const o=new Float64Array(e.length);for(let h=0,l=e.length;h<l;h+=2)o[h]=s+e[h+1]*n,o[h+1]=i+e[h]*r;return o},Jv=function(e){const s=c(this,Rt);let i=s[4],n=s[5],r=i,o=n,h=i,l=n,d=i,u=n;const g=e?Math.max:Math.min;for(let v=6,x=s.length;v<x;v+=6){if(isNaN(s[v]))r=Math.min(r,s[v+4]),o=Math.min(o,s[v+5]),h=Math.max(h,s[v+4]),l=Math.max(l,s[v+5]),u<s[v+5]?(d=s[v+4],u=s[v+5]):u===s[v+5]&&(d=g(d,s[v+4]));else{const S=z.bezierBoundingBox(i,n,...s.slice(v,v+6));r=Math.min(r,S[0]),o=Math.min(o,S[1]),h=Math.max(h,S[2]),l=Math.max(l,S[3]),u<S[3]?(d=S[2],u=S[3]):u===S[3]&&(d=g(d,S[2]))}i=s[v+4],n=s[v+5]}const f=r-c(this,Vi),p=o-c(this,Vi),m=h-r+2*c(this,Vi),_=l-o+2*c(this,Vi);b(this,Vr,{x:f,y:p,width:m,height:_,lastPoint:[d,u]})};const Gi=class Gi{constructor({editor:t=null,uiManager:e=null}){w(this,yt);w(this,Cl,y(this,yt,Zv).bind(this));w(this,Al,y(this,yt,tb).bind(this));w(this,Es,null);w(this,Gr,null);w(this,da);w(this,Vt,null);w(this,Tl,!1);w(this,ua,!1);w(this,El,null);w(this,kl);w(this,ks,null);w(this,ga);var s;t?(b(this,ua,!1),b(this,ga,q.HIGHLIGHT_COLOR),b(this,El,t)):(b(this,ua,!0),b(this,ga,q.HIGHLIGHT_DEFAULT_COLOR)),b(this,ks,(t==null?void 0:t._uiManager)||e),b(this,kl,c(this,ks)._eventBus),b(this,da,(t==null?void 0:t.color)||((s=c(this,ks))==null?void 0:s.highlightColors.values().next().value)||"#FFFF98")}static get _keyboardManager(){return at(this,"_keyboardManager",new Qa([[["Escape","mac+Escape"],Gi.prototype._hideDropdownFromKeyboard],[[" ","mac+ "],Gi.prototype._colorSelectFromKeyboard],[["ArrowDown","ArrowRight","mac+ArrowDown","mac+ArrowRight"],Gi.prototype._moveToNext],[["ArrowUp","ArrowLeft","mac+ArrowUp","mac+ArrowLeft"],Gi.prototype._moveToPrevious],[["Home","mac+Home"],Gi.prototype._moveToBeginning],[["End","mac+End"],Gi.prototype._moveToEnd]]))}renderButton(){const t=b(this,Es,document.createElement("button"));t.className="colorPicker",t.tabIndex="0",t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-button"),t.setAttribute("aria-haspopup",!0);const e=c(this,ks)._signal;t.addEventListener("click",y(this,yt,oo).bind(this),{signal:e}),t.addEventListener("keydown",c(this,Cl),{signal:e});const s=b(this,Gr,document.createElement("span"));return s.className="swatch",s.setAttribute("aria-hidden",!0),s.style.backgroundColor=c(this,da),t.append(s),t}renderMainDropdown(){const t=b(this,Vt,y(this,yt,jf).call(this));return t.setAttribute("aria-orientation","horizontal"),t.setAttribute("aria-labelledby","highlightColorPickerLabel"),t}_colorSelectFromKeyboard(t){if(t.target===c(this,Es)){y(this,yt,oo).call(this,t);return}const e=t.target.getAttribute("data-color");e&&y(this,yt,Nf).call(this,e,t)}_moveToNext(t){var e,s;if(!c(this,yt,In)){y(this,yt,oo).call(this,t);return}if(t.target===c(this,Es)){(e=c(this,Vt).firstChild)==null||e.focus();return}(s=t.target.nextSibling)==null||s.focus()}_moveToPrevious(t){var e,s;if(t.target===((e=c(this,Vt))==null?void 0:e.firstChild)||t.target===c(this,Es)){c(this,yt,In)&&this._hideDropdownFromKeyboard();return}c(this,yt,In)||y(this,yt,oo).call(this,t),(s=t.target.previousSibling)==null||s.focus()}_moveToBeginning(t){var e;if(!c(this,yt,In)){y(this,yt,oo).call(this,t);return}(e=c(this,Vt).firstChild)==null||e.focus()}_moveToEnd(t){var e;if(!c(this,yt,In)){y(this,yt,oo).call(this,t);return}(e=c(this,Vt).lastChild)==null||e.focus()}hideDropdown(){var t;(t=c(this,Vt))==null||t.classList.add("hidden"),window.removeEventListener("pointerdown",c(this,Al))}_hideDropdownFromKeyboard(){var t;if(!c(this,ua)){if(!c(this,yt,In)){(t=c(this,El))==null||t.unselect();return}this.hideDropdown(),c(this,Es).focus({preventScroll:!0,focusVisible:c(this,Tl)})}}updateColor(t){if(c(this,Gr)&&(c(this,Gr).style.backgroundColor=t),!c(this,Vt))return;const e=c(this,ks).highlightColors.values();for(const s of c(this,Vt).children)s.setAttribute("aria-selected",e.next().value===t)}destroy(){var t,e;(t=c(this,Es))==null||t.remove(),b(this,Es,null),b(this,Gr,null),(e=c(this,Vt))==null||e.remove(),b(this,Vt,null)}};Cl=new WeakMap,Al=new WeakMap,Es=new WeakMap,Gr=new WeakMap,da=new WeakMap,Vt=new WeakMap,Tl=new WeakMap,ua=new WeakMap,El=new WeakMap,kl=new WeakMap,ks=new WeakMap,ga=new WeakMap,yt=new WeakSet,jf=function(){const t=document.createElement("div"),e=c(this,ks)._signal;t.addEventListener("contextmenu",Oe,{signal:e}),t.className="dropdown",t.role="listbox",t.setAttribute("aria-multiselectable",!1),t.setAttribute("aria-orientation","vertical"),t.setAttribute("data-l10n-id","pdfjs-editor-colorpicker-dropdown");for(const[s,i]of c(this,ks).highlightColors){const n=document.createElement("button");n.tabIndex="0",n.role="option",n.setAttribute("data-color",i),n.title=s,n.setAttribute("data-l10n-id",`pdfjs-editor-colorpicker-${s}`);const r=document.createElement("span");n.append(r),r.className="swatch",r.style.backgroundColor=i,n.setAttribute("aria-selected",i===c(this,da)),n.addEventListener("click",y(this,yt,Nf).bind(this,i),{signal:e}),t.append(n)}return t.addEventListener("keydown",c(this,Cl),{signal:e}),t},Nf=function(t,e){e.stopPropagation(),c(this,kl).dispatch("switchannotationeditorparams",{source:this,type:c(this,ga),value:t})},Zv=function(t){Gi._keyboardManager.exec(this,t)},oo=function(t){if(c(this,yt,In)){this.hideDropdown();return}if(b(this,Tl,t.detail===0),window.addEventListener("pointerdown",c(this,Al),{signal:c(this,ks)._signal}),c(this,Vt)){c(this,Vt).classList.remove("hidden");return}const e=b(this,Vt,y(this,yt,jf).call(this));c(this,Es).append(e)},tb=function(t){var e;(e=c(this,Vt))!=null&&e.contains(t.target)||this.hideDropdown()},In=function(){return c(this,Vt)&&!c(this,Vt).classList.contains("hidden")};let Sd=Gi;const lt=class lt extends dt{constructor(e){super({...e,name:"highlightEditor"});w(this,et);w(this,fa,null);w(this,Ml,0);w(this,En);w(this,Ur,null);w(this,pa,null);w(this,os,null);w(this,Dl,null);w(this,Ol,0);w(this,Yr,null);w(this,Ms,null);w(this,Te,null);w(this,$e,!1);w(this,Vd,y(this,et,nb).bind(this));w(this,ma,null);w(this,qr);w(this,Gt,null);w(this,va,"");w(this,ei);w(this,Pl,"");this.color=e.color||lt._defaultColor,b(this,ei,e.thickness||lt._defaultThickness),b(this,qr,e.opacity||lt._defaultOpacity),b(this,En,e.boxes||null),b(this,Pl,e.methodOfCreation||""),b(this,va,e.text||""),this._isDraggable=!1,e.highlightId>-1?(b(this,$e,!0),y(this,et,Hf).call(this,e),y(this,et,$l).call(this)):(b(this,fa,e.anchorNode),b(this,Ml,e.anchorOffset),b(this,Dl,e.focusNode),b(this,Ol,e.focusOffset),y(this,et,Bf).call(this),y(this,et,$l).call(this),this.rotate(this.rotation))}static get _keyboardManager(){const e=lt.prototype;return at(this,"_keyboardManager",new Qa([[["ArrowLeft","mac+ArrowLeft"],e._moveCaret,{args:[0]}],[["ArrowRight","mac+ArrowRight"],e._moveCaret,{args:[1]}],[["ArrowUp","mac+ArrowUp"],e._moveCaret,{args:[2]}],[["ArrowDown","mac+ArrowDown"],e._moveCaret,{args:[3]}]]))}get telemetryInitialData(){return{action:"added",type:c(this,$e)?"free_highlight":"highlight",color:this._uiManager.highlightColorNames.get(this.color),thickness:c(this,ei),methodOfCreation:c(this,Pl)}}get telemetryFinalData(){return{type:"highlight",color:this._uiManager.highlightColorNames.get(this.color)}}static computeTelemetryFinalData(e){return{numberOfColors:e.get("color").size}}static initialize(e,s){var i;dt.initialize(e,s),lt._defaultColor||(lt._defaultColor=((i=s.highlightColors)==null?void 0:i.values().next().value)||"#fff066")}static updateDefaultParams(e,s){switch(e){case q.HIGHLIGHT_DEFAULT_COLOR:lt._defaultColor=s;break;case q.HIGHLIGHT_THICKNESS:lt._defaultThickness=s;break}}translateInPage(e,s){}get toolbarPosition(){return c(this,ma)}updateParams(e,s){switch(e){case q.HIGHLIGHT_COLOR:y(this,et,eb).call(this,s);break;case q.HIGHLIGHT_THICKNESS:y(this,et,sb).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[q.HIGHLIGHT_DEFAULT_COLOR,lt._defaultColor],[q.HIGHLIGHT_THICKNESS,lt._defaultThickness]]}get propertiesToUpdate(){return[[q.HIGHLIGHT_COLOR,this.color||lt._defaultColor],[q.HIGHLIGHT_THICKNESS,c(this,ei)||lt._defaultThickness],[q.HIGHLIGHT_FREE,c(this,$e)]]}async addEditToolbar(){const e=await super.addEditToolbar();return e?(this._uiManager.highlightColors&&(b(this,pa,new Sd({editor:this})),e.addColorPicker(c(this,pa))),e):null}disableEditing(){super.disableEditing(),this.div.classList.toggle("disabled",!0)}enableEditing(){super.enableEditing(),this.div.classList.toggle("disabled",!1)}fixAndSetPosition(){return super.fixAndSetPosition(y(this,et,Kl).call(this))}getBaseTranslation(){return[0,0]}getRect(e,s){return super.getRect(e,s,y(this,et,Kl).call(this))}onceAdded(){this.parent.addUndoableEditor(this),this.div.focus()}remove(){y(this,et,Wf).call(this),this._reportTelemetry({action:"deleted"}),super.remove()}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(y(this,et,$l).call(this),this.isAttachedToDOM||this.parent.add(this)))}setParent(e){var i;let s=!1;this.parent&&!e?y(this,et,Wf).call(this):e&&(y(this,et,$l).call(this,e),s=!this.parent&&((i=this.div)==null?void 0:i.classList.contains("selectedEditor"))),super.setParent(e),this.show(this._isVisible),s&&this.select()}rotate(e){var n,r,o;const{drawLayer:s}=this.parent;let i;c(this,$e)?(e=(e-this.rotation+360)%360,i=y(n=lt,as,ka).call(n,c(this,Ms).box,e)):i=y(r=lt,as,ka).call(r,this,e),s.rotate(c(this,Te),e),s.rotate(c(this,Gt),e),s.updateBox(c(this,Te),i),s.updateBox(c(this,Gt),y(o=lt,as,ka).call(o,c(this,os).box,e))}render(){if(this.div)return this.div;const e=super.render();c(this,va)&&(e.setAttribute("aria-label",c(this,va)),e.setAttribute("role","mark")),c(this,$e)?e.classList.add("free"):this.div.addEventListener("keydown",c(this,Vd),{signal:this._uiManager._signal});const s=b(this,Yr,document.createElement("div"));e.append(s),s.setAttribute("aria-hidden","true"),s.className="internal",s.style.clipPath=c(this,Ur);const[i,n]=this.parentDimensions;return this.setDims(this.width*i,this.height*n),gd(this,c(this,Yr),["pointerover","pointerleave"]),this.enableEditing(),e}pointerover(){this.parent.drawLayer.addClass(c(this,Gt),"hovered")}pointerleave(){this.parent.drawLayer.removeClass(c(this,Gt),"hovered")}_moveCaret(e){switch(this.parent.unselect(this),e){case 0:case 2:y(this,et,hu).call(this,!0);break;case 1:case 3:y(this,et,hu).call(this,!1);break}}select(){var e,s;super.select(),c(this,Gt)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,Gt),"hovered"),(s=this.parent)==null||s.drawLayer.addClass(c(this,Gt),"selected"))}unselect(){var e;super.unselect(),c(this,Gt)&&((e=this.parent)==null||e.drawLayer.removeClass(c(this,Gt),"selected"),c(this,$e)||y(this,et,hu).call(this,!1))}get _mustFixPosition(){return!c(this,$e)}show(e=this._isVisible){super.show(e),this.parent&&(this.parent.drawLayer.show(c(this,Te),e),this.parent.drawLayer.show(c(this,Gt),e))}static startHighlighting(e,s,{target:i,x:n,y:r}){const{x:o,y:h,width:l,height:d}=i.getBoundingClientRect(),u=_=>{y(this,as,ab).call(this,e,_)},g=e._signal,f={capture:!0,passive:!1,signal:g},p=_=>{_.preventDefault(),_.stopPropagation()},m=_=>{i.removeEventListener("pointermove",u),window.removeEventListener("blur",m),window.removeEventListener("pointerup",m),window.removeEventListener("pointerdown",p,f),window.removeEventListener("contextmenu",Oe),y(this,as,hb).call(this,e,_)};window.addEventListener("blur",m,{signal:g}),window.addEventListener("pointerup",m,{signal:g}),window.addEventListener("pointerdown",p,f),window.addEventListener("contextmenu",Oe,{signal:g}),i.addEventListener("pointermove",u,{signal:g}),this._freeHighlight=new xd({x:n,y:r},[o,h,l,d],e.scale,this._defaultThickness/2,s,.001),{id:this._freeHighlightId,clipPathId:this._freeHighlightClipId}=e.drawLayer.highlight(this._freeHighlight,this._defaultColor,this._defaultOpacity,!0)}static deserialize(e,s,i){var m;const n=super.deserialize(e,s,i),{rect:[r,o,h,l],color:d,quadPoints:u}=e;n.color=z.makeHexColor(...d),b(n,qr,e.opacity);const[g,f]=n.pageDimensions;n.width=(h-r)/g,n.height=(l-o)/f;const p=b(n,En,[]);for(let _=0;_<u.length;_+=8)p.push({x:(u[4]-h)/g,y:(l-(1-u[_+5]))/f,width:(u[_+2]-u[_])/g,height:(u[_+5]-u[_+1])/f});return y(m=n,et,Bf).call(m),n}serialize(e=!1){if(this.isEmpty()||e)return null;const s=this.getRect(0,0),i=dt._colorManager.convert(this.color);return{annotationType:nt.HIGHLIGHT,color:i,opacity:c(this,qr),thickness:c(this,ei),quadPoints:y(this,et,rb).call(this),outlines:y(this,et,ob).call(this,s),pageIndex:this.pageIndex,rect:s,rotation:y(this,et,Kl).call(this),structTreeParentId:this._structTreeParentId}}static canCreateNewEmptyEditor(){return!1}};fa=new WeakMap,Ml=new WeakMap,En=new WeakMap,Ur=new WeakMap,pa=new WeakMap,os=new WeakMap,Dl=new WeakMap,Ol=new WeakMap,Yr=new WeakMap,Ms=new WeakMap,Te=new WeakMap,$e=new WeakMap,Vd=new WeakMap,ma=new WeakMap,qr=new WeakMap,Gt=new WeakMap,va=new WeakMap,ei=new WeakMap,Pl=new WeakMap,et=new WeakSet,Bf=function(){const e=new Z0(c(this,En),.001);b(this,Ms,e.getOutlines()),{x:this.x,y:this.y,width:this.width,height:this.height}=c(this,Ms).box;const s=new Z0(c(this,En),.0025,.001,this._uiManager.direction==="ltr");b(this,os,s.getOutlines());const{lastPoint:i}=c(this,os).box;b(this,ma,[(i[0]-this.x)/this.width,(i[1]-this.y)/this.height])},Hf=function({highlightOutlines:e,highlightId:s,clipPathId:i}){var u,g;if(b(this,Ms,e),b(this,os,e.getNewOutline(c(this,ei)/2+1.5,.0025)),s>=0)b(this,Te,s),b(this,Ur,i),this.parent.drawLayer.finalizeLine(s,e),b(this,Gt,this.parent.drawLayer.highlightOutline(c(this,os)));else if(this.parent){const f=this.parent.viewport.rotation;this.parent.drawLayer.updateLine(c(this,Te),e),this.parent.drawLayer.updateBox(c(this,Te),y(u=lt,as,ka).call(u,c(this,Ms).box,(f-this.rotation+360)%360)),this.parent.drawLayer.updateLine(c(this,Gt),c(this,os)),this.parent.drawLayer.updateBox(c(this,Gt),y(g=lt,as,ka).call(g,c(this,os).box,f))}const{x:r,y:o,width:h,height:l}=e.box;switch(this.rotation){case 0:this.x=r,this.y=o,this.width=h,this.height=l;break;case 90:{const[f,p]=this.parentDimensions;this.x=o,this.y=1-r,this.width=h*p/f,this.height=l*f/p;break}case 180:this.x=1-r,this.y=1-o,this.width=h,this.height=l;break;case 270:{const[f,p]=this.parentDimensions;this.x=1-o,this.y=r,this.width=h*p/f,this.height=l*f/p;break}}const{lastPoint:d}=c(this,os).box;b(this,ma,[(d[0]-r)/h,(d[1]-o)/l])},eb=function(e){const s=n=>{var r,o;this.color=n,(r=this.parent)==null||r.drawLayer.changeColor(c(this,Te),n),(o=c(this,pa))==null||o.updateColor(n)},i=this.color;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.HIGHLIGHT_COLOR,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"color_changed",color:this._uiManager.highlightColorNames.get(e)},!0)},sb=function(e){const s=c(this,ei),i=n=>{b(this,ei,n),y(this,et,ib).call(this,n)};this.addCommands({cmd:i.bind(this,e),undo:i.bind(this,s),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0}),this._reportTelemetry({action:"thickness_changed",thickness:e},!0)},ib=function(e){if(!c(this,$e))return;y(this,et,Hf).call(this,{highlightOutlines:c(this,Ms).getNewOutline(e/2)}),this.fixAndSetPosition();const[s,i]=this.parentDimensions;this.setDims(this.width*s,this.height*i)},Wf=function(){c(this,Te)===null||!this.parent||(this.parent.drawLayer.remove(c(this,Te)),b(this,Te,null),this.parent.drawLayer.remove(c(this,Gt)),b(this,Gt,null))},$l=function(e=this.parent){c(this,Te)===null&&({id:Je(this,Te)._,clipPathId:Je(this,Ur)._}=e.drawLayer.highlight(c(this,Ms),this.color,c(this,qr)),b(this,Gt,e.drawLayer.highlightOutline(c(this,os))),c(this,Yr)&&(c(this,Yr).style.clipPath=c(this,Ur)))},as=new WeakSet,ka=function({x:e,y:s,width:i,height:n},r){switch(r){case 90:return{x:1-s-n,y:e,width:n,height:i};case 180:return{x:1-e-i,y:1-s-n,width:i,height:n};case 270:return{x:s,y:1-e-i,width:n,height:i}}return{x:e,y:s,width:i,height:n}},nb=function(e){lt._keyboardManager.exec(this,e)},hu=function(e){if(!c(this,fa))return;const s=window.getSelection();e?s.setPosition(c(this,fa),c(this,Ml)):s.setPosition(c(this,Dl),c(this,Ol))},Kl=function(){return c(this,$e)?this.rotation:0},rb=function(){if(c(this,$e))return null;const[e,s]=this.pageDimensions,[i,n]=this.pageTranslation,r=c(this,En),o=new Float32Array(r.length*8);let h=0;for(const{x:l,y:d,width:u,height:g}of r){const f=l*e+i,p=(1-d-g)*s+n;o[h]=o[h+4]=f,o[h+1]=o[h+3]=p,o[h+2]=o[h+6]=f+u*e,o[h+5]=o[h+7]=p+g*s,h+=8}return o},ob=function(e){return c(this,Ms).serialize(e,y(this,et,Kl).call(this))},ab=function(e,s){this._freeHighlight.add(s)&&e.drawLayer.updatePath(this._freeHighlightId,this._freeHighlight)},hb=function(e,s){this._freeHighlight.isEmpty()?e.drawLayer.removeFreeHighlight(this._freeHighlightId):e.createAndAddNewEditor(s,!1,{highlightId:this._freeHighlightId,highlightOutlines:this._freeHighlight.getOutlines(),clipPathId:this._freeHighlightClipId,methodOfCreation:"main_toolbar"}),this._freeHighlightId=-1,this._freeHighlight=null,this._freeHighlightClipId=""},w(lt,as),K(lt,"_defaultColor",null),K(lt,"_defaultOpacity",1),K(lt,"_defaultThickness",12),K(lt,"_l10nPromise"),K(lt,"_type","highlight"),K(lt,"_editorType",nt.HIGHLIGHT),K(lt,"_freeHighlightId",-1),K(lt,"_freeHighlight",null),K(lt,"_freeHighlightClipId","");let Cd=lt;const At=class At extends dt{constructor(e){super({...e,name:"inkEditor"});w(this,N);w(this,$r,0);w(this,Kr,0);w(this,Ll,this.canvasPointermove.bind(this));w(this,Fl,this.canvasPointerleave.bind(this));w(this,Rl,this.canvasPointerup.bind(this));w(this,Qr,this.canvasPointerdown.bind(this));w(this,si,null);w(this,Ui,new Path2D);w(this,hs,!1);w(this,Jr,!1);w(this,Zr,!1);w(this,Yi,null);w(this,to,0);w(this,eo,0);w(this,kn,null);this.color=e.color||null,this.thickness=e.thickness||null,this.opacity=e.opacity||null,this.paths=[],this.bezierPath2D=[],this.allRawPaths=[],this.currentPath=[],this.scaleFactor=1,this.translationX=this.translationY=0,this.x=0,this.y=0,this._willKeepAspectRatio=!0}static initialize(e,s){dt.initialize(e,s)}static updateDefaultParams(e,s){switch(e){case q.INK_THICKNESS:At._defaultThickness=s;break;case q.INK_COLOR:At._defaultColor=s;break;case q.INK_OPACITY:At._defaultOpacity=s/100;break}}updateParams(e,s){switch(e){case q.INK_THICKNESS:y(this,N,lb).call(this,s);break;case q.INK_COLOR:y(this,N,cb).call(this,s);break;case q.INK_OPACITY:y(this,N,db).call(this,s);break}}static get defaultPropertiesToUpdate(){return[[q.INK_THICKNESS,At._defaultThickness],[q.INK_COLOR,At._defaultColor||dt._defaultLineColor],[q.INK_OPACITY,Math.round(At._defaultOpacity*100)]]}get propertiesToUpdate(){return[[q.INK_THICKNESS,this.thickness||At._defaultThickness],[q.INK_COLOR,this.color||At._defaultColor||dt._defaultLineColor],[q.INK_OPACITY,Math.round(100*(this.opacity??At._defaultOpacity))]]}rebuild(){this.parent&&(super.rebuild(),this.div!==null&&(this.canvas||(y(this,N,lu).call(this),y(this,N,cu).call(this)),this.isAttachedToDOM||(this.parent.add(this),y(this,N,Ma).call(this)),y(this,N,Ql).call(this)))}remove(){var e;this.canvas!==null&&(this.isEmpty()||this.commit(),this.canvas.width=this.canvas.height=0,this.canvas.remove(),this.canvas=null,c(this,si)&&(clearTimeout(c(this,si)),b(this,si,null)),(e=c(this,Yi))==null||e.disconnect(),b(this,Yi,null),super.remove())}setParent(e){!this.parent&&e?this._uiManager.removeShouldRescale(this):this.parent&&e===null&&this._uiManager.addShouldRescale(this),super.setParent(e)}onScaleChanging(){const[e,s]=this.parentDimensions,i=this.width*e,n=this.height*s;this.setDimensions(i,n)}enableEditMode(){c(this,hs)||this.canvas===null||(super.enableEditMode(),this._isDraggable=!1,this.canvas.addEventListener("pointerdown",c(this,Qr),{signal:this._uiManager._signal}))}disableEditMode(){!this.isInEditMode()||this.canvas===null||(super.disableEditMode(),this._isDraggable=!this.isEmpty(),this.div.classList.remove("editing"),this.canvas.removeEventListener("pointerdown",c(this,Qr)))}onceAdded(){this._isDraggable=!this.isEmpty()}isEmpty(){return this.paths.length===0||this.paths.length===1&&this.paths[0].length===0}commit(){c(this,hs)||(super.commit(),this.isEditing=!1,this.disableEditMode(),this.setInForeground(),b(this,hs,!0),this.div.classList.add("disabled"),y(this,N,Ql).call(this,!0),this.select(),this.parent.addInkEditorIfNeeded(!0),this.moveInDOM(),this.div.focus({preventScroll:!0}))}focusin(e){this._focusEventsAllowed&&(super.focusin(e),this.enableEditMode())}canvasPointerdown(e){e.button!==0||!this.isInEditMode()||c(this,hs)||(this.setInForeground(),e.preventDefault(),this.div.contains(document.activeElement)||this.div.focus({preventScroll:!0}),y(this,N,gb).call(this,e.offsetX,e.offsetY))}canvasPointermove(e){e.preventDefault(),y(this,N,zf).call(this,e.offsetX,e.offsetY)}canvasPointerup(e){e.preventDefault(),y(this,N,Vf).call(this,e)}canvasPointerleave(e){y(this,N,Vf).call(this,e)}get isResizable(){return!this.isEmpty()&&c(this,hs)}render(){if(this.div)return this.div;let e,s;this.width&&(e=this.x,s=this.y),super.render(),this.div.setAttribute("data-l10n-id","pdfjs-ink");const[i,n,r,o]=y(this,N,ub).call(this);if(this.setAt(i,n,0,0),this.setDims(r,o),y(this,N,lu).call(this),this.width){const[h,l]=this.parentDimensions;this.setAspectRatio(this.width*h,this.height*l),this.setAt(e*h,s*l,this.width*h,this.height*l),b(this,Zr,!0),y(this,N,Ma).call(this),this.setDims(this.width*h,this.height*l),y(this,N,ao).call(this),this.div.classList.add("disabled")}else this.div.classList.add("editing"),this.enableEditMode();return y(this,N,cu).call(this),this.div}setDimensions(e,s){const i=Math.round(e),n=Math.round(s);if(c(this,to)===i&&c(this,eo)===n)return;b(this,to,i),b(this,eo,n),this.canvas.style.visibility="hidden";const[r,o]=this.parentDimensions;this.width=e/r,this.height=s/o,this.fixAndSetPosition(),c(this,hs)&&y(this,N,Gf).call(this,e,s),y(this,N,Ma).call(this),y(this,N,ao).call(this),this.canvas.style.visibility="visible",this.fixDims()}static deserialize(e,s,i){var _,v,x;if(e instanceof Q0)return null;const n=super.deserialize(e,s,i);n.thickness=e.thickness,n.color=z.makeHexColor(...e.color),n.opacity=e.opacity;const[r,o]=n.pageDimensions,h=n.width*r,l=n.height*o,d=n.parentScale,u=e.thickness/2;b(n,hs,!0),b(n,to,Math.round(h)),b(n,eo,Math.round(l));const{paths:g,rect:f,rotation:p}=e;for(let{bezier:S}of g){S=y(_=At,qi,_b).call(_,S,f,p);const T=[];n.paths.push(T);let E=d*(S[0]-u),M=d*(S[1]-u);for(let O=2,R=S.length;O<R;O+=6){const D=d*(S[O]-u),L=d*(S[O+1]-u),F=d*(S[O+2]-u),I=d*(S[O+3]-u),X=d*(S[O+4]-u),Y=d*(S[O+5]-u);T.push([[E,M],[D,L],[F,I],[X,Y]]),E=X,M=Y}const P=y(this,qi,yb).call(this,T);n.bezierPath2D.push(P)}const m=y(v=n,N,Yf).call(v);return b(n,Kr,Math.max(dt.MIN_SIZE,m[2]-m[0])),b(n,$r,Math.max(dt.MIN_SIZE,m[3]-m[1])),y(x=n,N,Gf).call(x,h,l),n}serialize(){if(this.isEmpty())return null;const e=this.getRect(0,0),s=dt._colorManager.convert(this.ctx.strokeStyle);return{annotationType:nt.INK,color:s,thickness:this.thickness,opacity:this.opacity,paths:y(this,N,wb).call(this,this.scaleFactor/this.parentScale,this.translationX,this.translationY,e),pageIndex:this.pageIndex,rect:e,rotation:this.rotation,structTreeParentId:this._structTreeParentId}}};$r=new WeakMap,Kr=new WeakMap,Ll=new WeakMap,Fl=new WeakMap,Rl=new WeakMap,Qr=new WeakMap,si=new WeakMap,Ui=new WeakMap,hs=new WeakMap,Jr=new WeakMap,Zr=new WeakMap,Yi=new WeakMap,to=new WeakMap,eo=new WeakMap,kn=new WeakMap,N=new WeakSet,lb=function(e){const s=n=>{this.thickness=n,y(this,N,Ql).call(this)},i=this.thickness;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.INK_THICKNESS,overwriteIfSameType:!0,keepUndo:!0})},cb=function(e){const s=n=>{this.color=n,y(this,N,ao).call(this)},i=this.color;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.INK_COLOR,overwriteIfSameType:!0,keepUndo:!0})},db=function(e){const s=n=>{this.opacity=n,y(this,N,ao).call(this)};e/=100;const i=this.opacity;this.addCommands({cmd:s.bind(this,e),undo:s.bind(this,i),post:this._uiManager.updateUI.bind(this._uiManager,this),mustExec:!0,type:q.INK_OPACITY,overwriteIfSameType:!0,keepUndo:!0})},ub=function(){const{parentRotation:e,parentDimensions:[s,i]}=this;switch(e){case 90:return[0,i,i,s];case 180:return[s,i,s,i];case 270:return[s,0,i,s];default:return[0,0,s,i]}},Xf=function(){const{ctx:e,color:s,opacity:i,thickness:n,parentScale:r,scaleFactor:o}=this;e.lineWidth=n*r/o,e.lineCap="round",e.lineJoin="round",e.miterLimit=10,e.strokeStyle=`${s}${Ow(i)}`},gb=function(e,s){const i=this._uiManager._signal;this.canvas.addEventListener("contextmenu",Oe,{signal:i}),this.canvas.addEventListener("pointerleave",c(this,Fl),{signal:i}),this.canvas.addEventListener("pointermove",c(this,Ll),{signal:i}),this.canvas.addEventListener("pointerup",c(this,Rl),{signal:i}),this.canvas.removeEventListener("pointerdown",c(this,Qr)),this.isEditing=!0,c(this,Zr)||(b(this,Zr,!0),y(this,N,Ma).call(this),this.thickness||(this.thickness=At._defaultThickness),this.color||(this.color=At._defaultColor||dt._defaultLineColor),this.opacity??(this.opacity=At._defaultOpacity)),this.currentPath.push([e,s]),b(this,Jr,!1),y(this,N,Xf).call(this),b(this,kn,()=>{y(this,N,mb).call(this),c(this,kn)&&window.requestAnimationFrame(c(this,kn))}),window.requestAnimationFrame(c(this,kn))},zf=function(e,s){const[i,n]=this.currentPath.at(-1);if(this.currentPath.length>1&&e===i&&s===n)return;const r=this.currentPath;let o=c(this,Ui);if(r.push([e,s]),b(this,Jr,!0),r.length<=2){o.moveTo(...r[0]),o.lineTo(e,s);return}r.length===3&&(b(this,Ui,o=new Path2D),o.moveTo(...r[0])),y(this,N,vb).call(this,o,...r.at(-3),...r.at(-2),e,s)},fb=function(){if(this.currentPath.length===0)return;const e=this.currentPath.at(-1);c(this,Ui).lineTo(...e)},pb=function(e,s){b(this,kn,null),e=Math.min(Math.max(e,0),this.canvas.width),s=Math.min(Math.max(s,0),this.canvas.height),y(this,N,zf).call(this,e,s),y(this,N,fb).call(this);let i;if(this.currentPath.length!==1)i=y(this,N,bb).call(this);else{const l=[e,s];i=[[l,l.slice(),l.slice(),l]]}const n=c(this,Ui),r=this.currentPath;this.currentPath=[],b(this,Ui,new Path2D);const o=()=>{this.allRawPaths.push(r),this.paths.push(i),this.bezierPath2D.push(n),this._uiManager.rebuild(this)},h=()=>{this.allRawPaths.pop(),this.paths.pop(),this.bezierPath2D.pop(),this.paths.length===0?this.remove():(this.canvas||(y(this,N,lu).call(this),y(this,N,cu).call(this)),y(this,N,Ql).call(this))};this.addCommands({cmd:o,undo:h,mustExec:!0})},mb=function(){if(!c(this,Jr))return;b(this,Jr,!1);const e=Math.ceil(this.thickness*this.parentScale),s=this.currentPath.slice(-3),i=s.map(o=>o[0]),n=s.map(o=>o[1]);Math.min(...i)-e,Math.max(...i)+e,Math.min(...n)-e,Math.max(...n)+e;const{ctx:r}=this;r.save(),r.clearRect(0,0,this.canvas.width,this.canvas.height);for(const o of this.bezierPath2D)r.stroke(o);r.stroke(c(this,Ui)),r.restore()},vb=function(e,s,i,n,r,o,h){const l=(s+n)/2,d=(i+r)/2,u=(n+o)/2,g=(r+h)/2;e.bezierCurveTo(l+2*(n-l)/3,d+2*(r-d)/3,u+2*(n-u)/3,g+2*(r-g)/3,u,g)},bb=function(){const e=this.currentPath;if(e.length<=2)return[[e[0],e[0],e.at(-1),e.at(-1)]];const s=[];let i,[n,r]=e[0];for(i=1;i<e.length-2;i++){const[f,p]=e[i],[m,_]=e[i+1],v=(f+m)/2,x=(p+_)/2,S=[n+2*(f-n)/3,r+2*(p-r)/3],T=[v+2*(f-v)/3,x+2*(p-x)/3];s.push([[n,r],S,T,[v,x]]),[n,r]=[v,x]}const[o,h]=e[i],[l,d]=e[i+1],u=[n+2*(o-n)/3,r+2*(h-r)/3],g=[l+2*(o-l)/3,d+2*(h-d)/3];return s.push([[n,r],u,g,[l,d]]),s},ao=function(){if(this.isEmpty()){y(this,N,du).call(this);return}y(this,N,Xf).call(this);const{canvas:e,ctx:s}=this;s.setTransform(1,0,0,1,0,0),s.clearRect(0,0,e.width,e.height),y(this,N,du).call(this);for(const i of this.bezierPath2D)s.stroke(i)},Vf=function(e){this.canvas.removeEventListener("pointerleave",c(this,Fl)),this.canvas.removeEventListener("pointermove",c(this,Ll)),this.canvas.removeEventListener("pointerup",c(this,Rl)),this.canvas.addEventListener("pointerdown",c(this,Qr),{signal:this._uiManager._signal}),c(this,si)&&clearTimeout(c(this,si)),b(this,si,setTimeout(()=>{b(this,si,null),this.canvas.removeEventListener("contextmenu",Oe)},10)),y(this,N,pb).call(this,e.offsetX,e.offsetY),this.addToAnnotationStorage(),this.setInBackground()},lu=function(){this.canvas=document.createElement("canvas"),this.canvas.width=this.canvas.height=0,this.canvas.className="inkEditorCanvas",this.canvas.setAttribute("data-l10n-id","pdfjs-ink-canvas"),this.div.append(this.canvas),this.ctx=this.canvas.getContext("2d")},cu=function(){b(this,Yi,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&this.setDimensions(s.width,s.height)})),c(this,Yi).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,Yi))==null||e.disconnect(),b(this,Yi,null)},{once:!0})},Ma=function(){if(!c(this,Zr))return;const[e,s]=this.parentDimensions;this.canvas.width=Math.ceil(this.width*e),this.canvas.height=Math.ceil(this.height*s),y(this,N,du).call(this)},Gf=function(e,s){const i=y(this,N,uu).call(this),n=(e-i)/c(this,Kr),r=(s-i)/c(this,$r);this.scaleFactor=Math.min(n,r)},du=function(){const e=y(this,N,uu).call(this)/2;this.ctx.setTransform(this.scaleFactor,0,0,this.scaleFactor,this.translationX*this.scaleFactor+e,this.translationY*this.scaleFactor+e)},qi=new WeakSet,yb=function(e){const s=new Path2D;for(let i=0,n=e.length;i<n;i++){const[r,o,h,l]=e[i];i===0&&s.moveTo(...r),s.bezierCurveTo(o[0],o[1],h[0],h[1],l[0],l[1])}return s},Uf=function(e,s,i){const[n,r,o,h]=s;switch(i){case 0:for(let l=0,d=e.length;l<d;l+=2)e[l]+=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=e[l+1]+n,e[l+1]=u+r}break;case 180:for(let l=0,d=e.length;l<d;l+=2)e[l]=o-e[l],e[l+1]+=r;break;case 270:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=o-e[l+1],e[l+1]=h-u}break;default:throw new Error("Invalid rotation")}return e},_b=function(e,s,i){const[n,r,o,h]=s;switch(i){case 0:for(let l=0,d=e.length;l<d;l+=2)e[l]-=n,e[l+1]=h-e[l+1];break;case 90:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=e[l+1]-r,e[l+1]=u-n}break;case 180:for(let l=0,d=e.length;l<d;l+=2)e[l]=o-e[l],e[l+1]-=r;break;case 270:for(let l=0,d=e.length;l<d;l+=2){const u=e[l];e[l]=h-e[l+1],e[l+1]=o-u}break;default:throw new Error("Invalid rotation")}return e},wb=function(e,s,i,n){var d,u;const r=[],o=this.thickness/2,h=e*s+o,l=e*i+o;for(const g of this.paths){const f=[],p=[];for(let m=0,_=g.length;m<_;m++){const[v,x,S,T]=g[m];if(v[0]===T[0]&&v[1]===T[1]&&_===1){const I=e*v[0]+h,X=e*v[1]+l;f.push(I,X),p.push(I,X);break}const E=e*v[0]+h,M=e*v[1]+l,P=e*x[0]+h,O=e*x[1]+l,R=e*S[0]+h,D=e*S[1]+l,L=e*T[0]+h,F=e*T[1]+l;m===0&&(f.push(E,M),p.push(E,M)),f.push(P,O,R,D,L,F),p.push(P,O),m===_-1&&p.push(L,F)}r.push({bezier:y(d=At,qi,Uf).call(d,f,n,this.rotation),points:y(u=At,qi,Uf).call(u,p,n,this.rotation)})}return r},Yf=function(){let e=1/0,s=-1/0,i=1/0,n=-1/0;for(const r of this.paths)for(const[o,h,l,d]of r){const u=z.bezierBoundingBox(...o,...h,...l,...d);e=Math.min(e,u[0]),i=Math.min(i,u[1]),s=Math.max(s,u[2]),n=Math.max(n,u[3])}return[e,i,s,n]},uu=function(){return c(this,hs)?Math.ceil(this.thickness*this.parentScale):0},Ql=function(e=!1){if(this.isEmpty())return;if(!c(this,hs)){y(this,N,ao).call(this);return}const s=y(this,N,Yf).call(this),i=y(this,N,uu).call(this);b(this,Kr,Math.max(dt.MIN_SIZE,s[2]-s[0])),b(this,$r,Math.max(dt.MIN_SIZE,s[3]-s[1]));const n=Math.ceil(i+c(this,Kr)*this.scaleFactor),r=Math.ceil(i+c(this,$r)*this.scaleFactor),[o,h]=this.parentDimensions;this.width=n/o,this.height=r/h,this.setAspectRatio(n,r);const l=this.translationX,d=this.translationY;this.translationX=-s[0],this.translationY=-s[1],y(this,N,Ma).call(this),y(this,N,ao).call(this),b(this,to,n),b(this,eo,r),this.setDims(n,r);const u=e?i/this.scaleFactor/2:0;this.translate(l-this.translationX-u,d-this.translationY-u)},w(At,qi),K(At,"_defaultColor",null),K(At,"_defaultOpacity",1),K(At,"_defaultThickness",1),K(At,"_type","ink"),K(At,"_editorType",nt.INK);let Yg=At;const Nl=class Nl extends dt{constructor(e){super({...e,name:"stampEditor"});w(this,ht);w(this,te,null);w(this,ee,null);w(this,Mn,null);w(this,$i,null);w(this,Dn,null);w(this,ba,"");w(this,ii,null);w(this,Il,!1);w(this,Ki,null);w(this,ni,null);w(this,Ds,!1);w(this,jl,!1);b(this,$i,e.bitmapUrl),b(this,Dn,e.bitmapFile)}static initialize(e,s){dt.initialize(e,s)}static get supportedTypes(){return at(this,"supportedTypes",["apng","avif","bmp","gif","jpeg","png","svg+xml","webp","x-icon"].map(s=>`image/${s}`))}static get supportedTypesStr(){return at(this,"supportedTypesStr",this.supportedTypes.join(","))}static isHandlingMimeForPasting(e){return this.supportedTypes.includes(e)}static paste(e,s){s.pasteEditor(nt.STAMP,{bitmapFile:e.getAsFile()})}remove(){var e,s;c(this,ee)&&(b(this,te,null),this._uiManager.imageManager.deleteId(c(this,ee)),(e=c(this,ii))==null||e.remove(),b(this,ii,null),(s=c(this,Ki))==null||s.disconnect(),b(this,Ki,null),c(this,ni)&&(clearTimeout(c(this,ni)),b(this,ni,null))),super.remove()}rebuild(){if(!this.parent){c(this,ee)&&y(this,ht,gu).call(this);return}super.rebuild(),this.div!==null&&(c(this,ee)&&c(this,ii)===null&&y(this,ht,gu).call(this),this.isAttachedToDOM||this.parent.add(this))}onceAdded(){this._isDraggable=!0,this.div.focus()}isEmpty(){return!(c(this,Mn)||c(this,te)||c(this,$i)||c(this,Dn)||c(this,ee))}get isResizable(){return!0}render(){if(this.div)return this.div;let e,s;if(this.width&&(e=this.x,s=this.y),super.render(),this.div.hidden=!0,this.addAltTextButton(),c(this,te)?y(this,ht,qf).call(this):y(this,ht,gu).call(this),this.width){const[i,n]=this.parentDimensions;this.setAt(e*i,s*n,this.width*i,this.height*n)}return this.div}getImageForAltText(){return c(this,ii)}static deserialize(e,s,i){if(e instanceof J0)return null;const n=super.deserialize(e,s,i),{rect:r,bitmapUrl:o,bitmapId:h,isSvg:l,accessibilityData:d}=e;h&&i.imageManager.isValidId(h)?b(n,ee,h):b(n,$i,o),b(n,Ds,l);const[u,g]=n.pageDimensions;return n.width=(r[2]-r[0])/u,n.height=(r[3]-r[1])/g,d&&(n.altTextData=d),n}serialize(e=!1,s=null){if(this.isEmpty())return null;const i={annotationType:nt.STAMP,bitmapId:c(this,ee),pageIndex:this.pageIndex,rect:this.getRect(0,0),rotation:this.rotation,isSvg:c(this,Ds),structTreeParentId:this._structTreeParentId};if(e)return i.bitmapUrl=y(this,ht,fu).call(this,!0),i.accessibilityData=this.altTextData,i;const{decorative:n,altText:r}=this.altTextData;if(!n&&r&&(i.accessibilityData={type:"Figure",alt:r}),s===null)return i;s.stamps||(s.stamps=new Map);const o=c(this,Ds)?(i.rect[2]-i.rect[0])*(i.rect[3]-i.rect[1]):null;if(!s.stamps.has(c(this,ee)))s.stamps.set(c(this,ee),{area:o,serialized:i}),i.bitmap=y(this,ht,fu).call(this,!1);else if(c(this,Ds)){const h=s.stamps.get(c(this,ee));o>h.area&&(h.area=o,h.serialized.bitmap.close(),h.serialized.bitmap=y(this,ht,fu).call(this,!1))}return i}};te=new WeakMap,ee=new WeakMap,Mn=new WeakMap,$i=new WeakMap,Dn=new WeakMap,ba=new WeakMap,ii=new WeakMap,Il=new WeakMap,Ki=new WeakMap,ni=new WeakMap,Ds=new WeakMap,jl=new WeakMap,ht=new WeakSet,Jl=function(e,s=!1){if(!e){this.remove();return}b(this,te,e.bitmap),s||(b(this,ee,e.id),b(this,Ds,e.isSvg)),e.file&&b(this,ba,e.file.name),y(this,ht,qf).call(this)},Zl=function(){b(this,Mn,null),this._uiManager.enableWaiting(!1),c(this,ii)&&this.div.focus()},gu=function(){if(c(this,ee)){this._uiManager.enableWaiting(!0),this._uiManager.imageManager.getFromId(c(this,ee)).then(i=>y(this,ht,Jl).call(this,i,!0)).finally(()=>y(this,ht,Zl).call(this));return}if(c(this,$i)){const i=c(this,$i);b(this,$i,null),this._uiManager.enableWaiting(!0),b(this,Mn,this._uiManager.imageManager.getFromUrl(i).then(n=>y(this,ht,Jl).call(this,n)).finally(()=>y(this,ht,Zl).call(this)));return}if(c(this,Dn)){const i=c(this,Dn);b(this,Dn,null),this._uiManager.enableWaiting(!0),b(this,Mn,this._uiManager.imageManager.getFromFile(i).then(n=>y(this,ht,Jl).call(this,n)).finally(()=>y(this,ht,Zl).call(this)));return}const e=document.createElement("input");e.type="file",e.accept=Nl.supportedTypesStr;const s=this._uiManager._signal;b(this,Mn,new Promise(i=>{e.addEventListener("change",async()=>{if(!e.files||e.files.length===0)this.remove();else{this._uiManager.enableWaiting(!0);const n=await this._uiManager.imageManager.getFromFile(e.files[0]);y(this,ht,Jl).call(this,n)}i()},{signal:s}),e.addEventListener("cancel",()=>{this.remove(),i()},{signal:s})}).finally(()=>y(this,ht,Zl).call(this))),e.click()},qf=function(){const{div:e}=this;let{width:s,height:i}=c(this,te);const[n,r]=this.pageDimensions,o=.75;if(this.width)s=this.width*n,i=this.height*r;else if(s>o*n||i>o*r){const u=Math.min(o*n/s,o*r/i);s*=u,i*=u}const[h,l]=this.parentDimensions;this.setDims(s*h/n,i*l/r),this._uiManager.enableWaiting(!1);const d=b(this,ii,document.createElement("canvas"));e.append(d),e.hidden=!1,y(this,ht,$f).call(this,s,i),y(this,ht,Ab).call(this),c(this,jl)||(this.parent.addUndoableEditor(this),b(this,jl,!0)),this._reportTelemetry({action:"inserted_image"}),c(this,ba)&&d.setAttribute("aria-label",c(this,ba))},xb=function(e,s){var o;const[i,n]=this.parentDimensions;this.width=e/i,this.height=s/n,this.setDims(e,s),(o=this._initialOptions)!=null&&o.isCentered?this.center():this.fixAndSetPosition(),this._initialOptions=null,c(this,ni)!==null&&clearTimeout(c(this,ni)),b(this,ni,setTimeout(()=>{b(this,ni,null),y(this,ht,$f).call(this,e,s)},200))},Sb=function(e,s){const{width:i,height:n}=c(this,te);let r=i,o=n,h=c(this,te);for(;r>2*e||o>2*s;){const l=r,d=o;r>2*e&&(r=r>=16384?Math.floor(r/2)-1:Math.ceil(r/2)),o>2*s&&(o=o>=16384?Math.floor(o/2)-1:Math.ceil(o/2));const u=new OffscreenCanvas(r,o);u.getContext("2d").drawImage(h,0,0,l,d,0,0,r,o),h=u.transferToImageBitmap()}return h},Cb=async function(e,s,i){if(c(this,Il)||(b(this,Il,!0),!await this._uiManager.isMLEnabledFor("altText")||this.hasAltText()))return;const o=new OffscreenCanvas(s,i).getContext("2d",{willReadFrequently:!0});o.drawImage(e,0,0,e.width,e.height,0,0,s,i);const h=await this._uiManager.mlGuess({service:"moz-image-to-text",request:{data:o.getImageData(0,0,s,i).data,width:s,height:i,channels:4}}),l=(h==null?void 0:h.output)||"";this.parent&&l&&!this.hasAltText()&&(this.altTextData={altText:l,decorative:!1})},$f=function(e,s){e=Math.ceil(e),s=Math.ceil(s);const i=c(this,ii);if(!i||i.width===e&&i.height===s)return;i.width=e,i.height=s;const n=c(this,Ds)?c(this,te):y(this,ht,Sb).call(this,e,s);y(this,ht,Cb).call(this,n,e,s);const r=i.getContext("2d");r.filter=this._uiManager.hcmFilter,r.drawImage(n,0,0,n.width,n.height,0,0,e,s)},fu=function(e){if(e){if(c(this,Ds)){const n=this._uiManager.imageManager.getSvgUrl(c(this,ee));if(n)return n}const s=document.createElement("canvas");return{width:s.width,height:s.height}=c(this,te),s.getContext("2d").drawImage(c(this,te),0,0),s.toDataURL()}if(c(this,Ds)){const[s,i]=this.pageDimensions,n=Math.round(this.width*s*ln.PDF_TO_CSS_UNITS),r=Math.round(this.height*i*ln.PDF_TO_CSS_UNITS),o=new OffscreenCanvas(n,r);return o.getContext("2d").drawImage(c(this,te),0,0,c(this,te).width,c(this,te).height,0,0,n,r),o.transferToImageBitmap()}return structuredClone(c(this,te))},Ab=function(){this._uiManager._signal&&(b(this,Ki,new ResizeObserver(e=>{const s=e[0].contentRect;s.width&&s.height&&y(this,ht,xb).call(this,s.width,s.height)})),c(this,Ki).observe(this.div),this._uiManager._signal.addEventListener("abort",()=>{var e;(e=c(this,Ki))==null||e.disconnect(),b(this,Ki,null)},{once:!0}))},K(Nl,"_type","stamp"),K(Nl,"_editorType",nt.STAMP);let qg=Nl;const Os=class Os{constructor({uiManager:t,pageIndex:e,div:s,accessibilityManager:i,annotationLayer:n,drawLayer:r,textLayer:o,viewport:h,l10n:l}){w(this,se);w(this,so);w(this,ya,!1);w(this,ri,null);w(this,io,null);w(this,Qi,null);w(this,Ji,null);w(this,Zi,null);w(this,Ke,new Map);w(this,On,!1);w(this,_a,!1);w(this,wa,!1);w(this,fe,null);w(this,G);const d=[...c(Os,Pn).values()];if(!Os._initialized){Os._initialized=!0;for(const u of d)u.initialize(l,t)}t.registerEditorTypes(d),b(this,G,t),this.pageIndex=e,this.div=s,b(this,so,i),b(this,ri,n),this.viewport=h,b(this,fe,o),this.drawLayer=r,c(this,G).addLayer(this)}get isEmpty(){return c(this,Ke).size===0}get isInvisible(){return this.isEmpty&&c(this,G).getMode()===nt.NONE}updateToolbar(t){c(this,G).updateToolbar(t)}updateMode(t=c(this,G).getMode()){switch(y(this,se,pu).call(this),t){case nt.NONE:this.disableTextSelection(),this.togglePointerEvents(!1),this.toggleAnnotationLayerPointerEvents(!0),this.disableClick();return;case nt.INK:this.addInkEditorIfNeeded(!1),this.disableTextSelection(),this.togglePointerEvents(!0),this.disableClick();break;case nt.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;for(const s of c(Os,Pn).values())e.toggle(`${s._type}Editing`,t===s._editorType);this.div.hidden=!1}hasTextLayer(t){var e;return t===((e=c(this,fe))==null?void 0:e.div)}addInkEditorIfNeeded(t){if(c(this,G).getMode()!==nt.INK)return;if(!t){for(const s of c(this,Ke).values())if(s.isEmpty()){s.setInBackground();return}}this.createAndAddNewEditor({offsetX:0,offsetY:0},!1).setInBackground()}setEditingState(t){c(this,G).setEditingState(t)}addCommands(t){c(this,G).addCommands(t)}toggleDrawing(t=!1){this.div.classList.toggle("drawing",!t)}togglePointerEvents(t=!1){this.div.classList.toggle("disabled",!t)}toggleAnnotationLayerPointerEvents(t=!1){var e;(e=c(this,ri))==null||e.div.classList.toggle("disabled",!t)}enable(){this.div.tabIndex=0,this.togglePointerEvents(!0);const t=new Set;for(const s of c(this,Ke).values())s.enableEditing(),s.show(!0),s.annotationElementId&&(c(this,G).removeChangedExistingAnnotation(s),t.add(s.annotationElementId));if(!c(this,ri))return;const e=c(this,ri).getEditableAnnotations();for(const s of e){if(s.hide(),c(this,G).isDeletedAnnotationElement(s.data.id)||t.has(s.data.id))continue;const i=this.deserialize(s);i&&(this.addOrRebuild(i),i.enableEditing())}}disable(){var i;b(this,wa,!0),this.div.tabIndex=-1,this.togglePointerEvents(!1);const t=new Map,e=new Map;for(const n of c(this,Ke).values())if(n.disableEditing(),!!n.annotationElementId){if(n.serialize()!==null){t.set(n.annotationElementId,n);continue}else e.set(n.annotationElementId,n);(i=this.getEditableAnnotation(n.annotationElementId))==null||i.show(),n.remove()}if(c(this,ri)){const n=c(this,ri).getEditableAnnotations();for(const r of n){const{id:o}=r.data;if(c(this,G).isDeletedAnnotationElement(o))continue;let h=e.get(o);if(h){h.resetAnnotationElement(r),h.show(!1),r.show();continue}h=t.get(o),h&&(c(this,G).addChangedExistingAnnotation(h),h.renderAnnotationElement(r),h.show(!1)),r.show()}}y(this,se,pu).call(this),this.isEmpty&&(this.div.hidden=!0);const{classList:s}=this.div;for(const n of c(Os,Pn).values())s.remove(`${n._type}Editing`);this.disableTextSelection(),this.toggleAnnotationLayerPointerEvents(!0),b(this,wa,!1)}getEditableAnnotation(t){var e;return((e=c(this,ri))==null?void 0:e.getEditableAnnotation(t))||null}setActiveEditor(t){c(this,G).getActive()!==t&&c(this,G).setActiveEditor(t)}enableTextSelection(){var t;this.div.tabIndex=-1,(t=c(this,fe))!=null&&t.div&&!c(this,Ji)&&(b(this,Ji,y(this,se,Tb).bind(this)),c(this,fe).div.addEventListener("pointerdown",c(this,Ji),{signal:c(this,G)._signal}),c(this,fe).div.classList.add("highlighting"))}disableTextSelection(){var t;this.div.tabIndex=0,(t=c(this,fe))!=null&&t.div&&c(this,Ji)&&(c(this,fe).div.removeEventListener("pointerdown",c(this,Ji)),b(this,Ji,null),c(this,fe).div.classList.remove("highlighting"))}enableClick(){if(c(this,Qi))return;const t=c(this,G)._signal;b(this,Qi,this.pointerdown.bind(this)),b(this,io,this.pointerup.bind(this)),this.div.addEventListener("pointerdown",c(this,Qi),{signal:t}),this.div.addEventListener("pointerup",c(this,io),{signal:t})}disableClick(){c(this,Qi)&&(this.div.removeEventListener("pointerdown",c(this,Qi)),this.div.removeEventListener("pointerup",c(this,io)),b(this,Qi,null),b(this,io,null))}attach(t){c(this,Ke).set(t.id,t);const{annotationElementId:e}=t;e&&c(this,G).isDeletedAnnotationElement(e)&&c(this,G).removeDeletedAnnotationElement(t)}detach(t){var e;c(this,Ke).delete(t.id),(e=c(this,so))==null||e.removePointerInTextLayer(t.contentDiv),!c(this,wa)&&t.annotationElementId&&c(this,G).addDeletedAnnotationElement(t)}remove(t){this.detach(t),c(this,G).removeEditor(t),t.div.remove(),t.isAttachedToDOM=!1,c(this,_a)||this.addInkEditorIfNeeded(!1)}changeParent(t){var e;t.parent!==this&&(t.parent&&t.annotationElementId&&(c(this,G).addDeletedAnnotationElement(t.annotationElementId),dt.deleteAnnotationElement(t),t.annotationElementId=null),this.attach(t),(e=t.parent)==null||e.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),c(this,G).addEditor(t),this.attach(t),!t.isAttachedToDOM){const e=t.render();this.div.append(e),t.isAttachedToDOM=!0}t.fixAndSetPosition(),t.onceAdded(),c(this,G).addToAnnotationStorage(t),t._reportTelemetry(t.telemetryInitialData)}}moveEditorInDOM(t){var s;if(!t.isAttachedToDOM)return;const{activeElement:e}=document;t.div.contains(e)&&!c(this,Zi)&&(t._focusEventsAllowed=!1,b(this,Zi,setTimeout(()=>{b(this,Zi,null),t.div.contains(document.activeElement)?t._focusEventsAllowed=!0:(t.div.addEventListener("focusin",()=>{t._focusEventsAllowed=!0},{once:!0,signal:c(this,G)._signal}),e.focus())},0))),t._structTreeParentId=(s=c(this,so))==null?void 0:s.moveElementInDOM(this.div,t.div,t.contentDiv,!0)}addOrRebuild(t){t.needsToBeRebuilt()?(t.parent||(t.parent=this),t.rebuild(),t.show()):this.add(t)}addUndoableEditor(t){const e=()=>t._uiManager.rebuild(t),s=()=>{t.remove()};this.addCommands({cmd:e,undo:s,mustExec:!1})}getNextId(){return c(this,G).getId()}get _signal(){return c(this,G)._signal}canCreateNewEmptyEditor(){var t;return(t=c(this,se,Kf))==null?void 0:t.canCreateNewEmptyEditor()}pasteEditor(t,e){c(this,G).updateToolbar(t),c(this,G).updateMode(t);const{offsetX:s,offsetY:i}=y(this,se,Jf).call(this),n=this.getNextId(),r=y(this,se,Qf).call(this,{parent:this,id:n,x:s,y:i,uiManager:c(this,G),isCentered:!0,...e});r&&this.add(r)}deserialize(t){var e;return((e=c(Os,Pn).get(t.annotationType??t.annotationEditorType))==null?void 0:e.deserialize(t,this,c(this,G)))||null}createAndAddNewEditor(t,e,s={}){const i=this.getNextId(),n=y(this,se,Qf).call(this,{parent:this,id:i,x:t.offsetX,y:t.offsetY,uiManager:c(this,G),isCentered:e,...s});return n&&this.add(n),n}addNewEditor(){this.createAndAddNewEditor(y(this,se,Jf).call(this),!0)}setSelected(t){c(this,G).setSelected(t)}toggleSelected(t){c(this,G).toggleSelected(t)}isSelected(t){return c(this,G).isSelected(t)}unselect(t){c(this,G).unselect(t)}pointerup(t){const{isMac:e}=De.platform;if(!(t.button!==0||t.ctrlKey&&e)&&t.target===this.div&&c(this,On)){if(b(this,On,!1),!c(this,ya)){b(this,ya,!0);return}if(c(this,G).getMode()===nt.STAMP){c(this,G).unselectAll();return}this.createAndAddNewEditor(t,!1)}}pointerdown(t){if(c(this,G).getMode()===nt.HIGHLIGHT&&this.enableTextSelection(),c(this,On)){b(this,On,!1);return}const{isMac:e}=De.platform;if(t.button!==0||t.ctrlKey&&e||t.target!==this.div)return;b(this,On,!0);const s=c(this,G).getActive();b(this,ya,!s||s.isEmpty())}findNewParent(t,e,s){const i=c(this,G).findParent(e,s);return i===null||i===this?!1:(i.changeParent(t),!0)}destroy(){var t,e;((t=c(this,G).getActive())==null?void 0:t.parent)===this&&(c(this,G).commitOrRemove(),c(this,G).setActiveEditor(null)),c(this,Zi)&&(clearTimeout(c(this,Zi)),b(this,Zi,null));for(const s of c(this,Ke).values())(e=c(this,so))==null||e.removePointerInTextLayer(s.contentDiv),s.setParent(null),s.isAttachedToDOM=!1,s.div.remove();this.div=null,c(this,Ke).clear(),c(this,G).removeLayer(this)}render({viewport:t}){this.viewport=t,Zn(this.div,t);for(const e of c(this,G).getEditors(this.pageIndex))this.add(e),e.rebuild();this.updateMode()}update({viewport:t}){c(this,G).commitOrRemove(),y(this,se,pu).call(this);const e=this.viewport.rotation,s=t.rotation;if(this.viewport=t,Zn(this.div,{rotation:s}),e!==s)for(const i of c(this,Ke).values())i.rotate(s);this.addInkEditorIfNeeded(!1)}get pageDimensions(){const{pageWidth:t,pageHeight:e}=this.viewport.rawDims;return[t,e]}get scale(){return c(this,G).viewParameters.realScale}};so=new WeakMap,ya=new WeakMap,ri=new WeakMap,io=new WeakMap,Qi=new WeakMap,Ji=new WeakMap,Zi=new WeakMap,Ke=new WeakMap,On=new WeakMap,_a=new WeakMap,wa=new WeakMap,fe=new WeakMap,G=new WeakMap,Pn=new WeakMap,se=new WeakSet,Tb=function(t){c(this,G).unselectAll();const{target:e}=t;if(e===c(this,fe).div||e.classList.contains("endOfContent")&&c(this,fe).div.contains(e)){const{isMac:s}=De.platform;if(t.button!==0||t.ctrlKey&&s)return;c(this,G).showAllEditors("highlight",!0,!0),c(this,fe).div.classList.add("free"),this.toggleDrawing(),Cd.startHighlighting(this,c(this,G).direction==="ltr",t),c(this,fe).div.addEventListener("pointerup",()=>{c(this,fe).div.classList.remove("free"),this.toggleDrawing(!0)},{once:!0,signal:c(this,G)._signal}),t.preventDefault()}},Kf=function(){return c(Os,Pn).get(c(this,G).getMode())},Qf=function(t){const e=c(this,se,Kf);return e?new e.prototype.constructor(t):null},Jf=function(){const{x:t,y:e,width:s,height:i}=this.div.getBoundingClientRect(),n=Math.max(0,t),r=Math.max(0,e),o=Math.min(window.innerWidth,t+s),h=Math.min(window.innerHeight,e+i),l=(n+o)/2-t,d=(r+h)/2-e,[u,g]=this.viewport.rotation%180===0?[l,d]:[d,l];return{offsetX:u,offsetY:g}},pu=function(){b(this,_a,!0);for(const t of c(this,Ke).values())t.isEmpty()&&t.remove();b(this,_a,!1)},K(Os,"_initialized",!1),w(Os,Pn,new Map([Gg,Yg,qg,Cd].map(t=>[t._editorType,t])));let $g=Os;const ie=class ie{constructor({pageIndex:t}){w(this,no);w(this,oi,null);w(this,Bl,0);w(this,Ut,new Map);w(this,Ln,new Map);this.pageIndex=t}setParent(t){if(!c(this,oi)){b(this,oi,t);return}if(c(this,oi)!==t){if(c(this,Ut).size>0)for(const e of c(this,Ut).values())e.remove(),t.append(e);b(this,oi,t)}}static get _svgFactory(){return at(this,"_svgFactory",new Ag)}highlight(t,e,s,i=!1){const n=Je(this,Bl)._++,r=y(this,no,tp).call(this,t.box);r.classList.add("highlight"),t.free&&r.classList.add("free");const o=ie._svgFactory.createElement("defs");r.append(o);const h=ie._svgFactory.createElement("path");o.append(h);const l=`path_p${this.pageIndex}_${n}`;h.setAttribute("id",l),h.setAttribute("d",t.toSVGPath()),i&&c(this,Ln).set(n,h);const d=y(this,no,Eb).call(this,o,l),u=ie._svgFactory.createElement("use");return r.append(u),r.setAttribute("fill",e),r.setAttribute("fill-opacity",s),u.setAttribute("href",`#${l}`),c(this,Ut).set(n,r),{id:n,clipPathId:`url(#${d})`}}highlightOutline(t){const e=Je(this,Bl)._++,s=y(this,no,tp).call(this,t.box);s.classList.add("highlightOutline");const i=ie._svgFactory.createElement("defs");s.append(i);const n=ie._svgFactory.createElement("path");i.append(n);const r=`path_p${this.pageIndex}_${e}`;n.setAttribute("id",r),n.setAttribute("d",t.toSVGPath()),n.setAttribute("vector-effect","non-scaling-stroke");let o;if(t.free){s.classList.add("free");const d=ie._svgFactory.createElement("mask");i.append(d),o=`mask_p${this.pageIndex}_${e}`,d.setAttribute("id",o),d.setAttribute("maskUnits","objectBoundingBox");const u=ie._svgFactory.createElement("rect");d.append(u),u.setAttribute("width","1"),u.setAttribute("height","1"),u.setAttribute("fill","white");const g=ie._svgFactory.createElement("use");d.append(g),g.setAttribute("href",`#${r}`),g.setAttribute("stroke","none"),g.setAttribute("fill","black"),g.setAttribute("fill-rule","nonzero"),g.classList.add("mask")}const h=ie._svgFactory.createElement("use");s.append(h),h.setAttribute("href",`#${r}`),o&&h.setAttribute("mask",`url(#${o})`);const l=h.cloneNode();return s.append(l),h.classList.add("mainOutline"),l.classList.add("secondaryOutline"),c(this,Ut).set(e,s),e}finalizeLine(t,e){const s=c(this,Ln).get(t);c(this,Ln).delete(t),this.updateBox(t,e.box),s.setAttribute("d",e.toSVGPath())}updateLine(t,e){c(this,Ut).get(t).firstChild.firstChild.setAttribute("d",e.toSVGPath())}removeFreeHighlight(t){this.remove(t),c(this,Ln).delete(t)}updatePath(t,e){c(this,Ln).get(t).setAttribute("d",e.toSVGPath())}updateBox(t,e){var s;y(s=ie,Hl,Zf).call(s,c(this,Ut).get(t),e)}show(t,e){c(this,Ut).get(t).classList.toggle("hidden",!e)}rotate(t,e){c(this,Ut).get(t).setAttribute("data-main-rotation",e)}changeColor(t,e){c(this,Ut).get(t).setAttribute("fill",e)}changeOpacity(t,e){c(this,Ut).get(t).setAttribute("fill-opacity",e)}addClass(t,e){c(this,Ut).get(t).classList.add(e)}removeClass(t,e){c(this,Ut).get(t).classList.remove(e)}remove(t){c(this,oi)!==null&&(c(this,Ut).get(t).remove(),c(this,Ut).delete(t))}destroy(){b(this,oi,null);for(const t of c(this,Ut).values())t.remove();c(this,Ut).clear()}};oi=new WeakMap,Bl=new WeakMap,Ut=new WeakMap,Ln=new WeakMap,Hl=new WeakSet,Zf=function(t,{x:e=0,y:s=0,width:i=1,height:n=1}={}){const{style:r}=t;r.top=`${100*s}%`,r.left=`${100*e}%`,r.width=`${100*i}%`,r.height=`${100*n}%`},no=new WeakSet,tp=function(t){var s;const e=ie._svgFactory.create(1,1,!0);return c(this,oi).append(e),e.setAttribute("aria-hidden",!0),y(s=ie,Hl,Zf).call(s,e,t),e},Eb=function(t,e){const s=ie._svgFactory.createElement("clipPath");t.append(s);const i=`clip_${e}`;s.setAttribute("id",i),s.setAttribute("clipPathUnits","objectBoundingBox");const n=ie._svgFactory.createElement("use");return s.append(n),n.setAttribute("href",`#${e}`),n.classList.add("clip"),i},w(ie,Hl);let Kg=ie;$.AbortException,$.AnnotationEditorLayer,$.AnnotationEditorParamsType,$.AnnotationEditorType,$.AnnotationEditorUIManager,$.AnnotationLayer,$.AnnotationMode,$.CMapCompressionType,$.ColorPicker,$.DOMSVGFactory,$.DrawLayer,$.FeatureTest;var oS=$.GlobalWorkerOptions;$.ImageKind,$.InvalidPDFException,$.MissingPDFException,$.OPS,$.PDFDataRangeTransport,$.PDFDateString,$.PDFWorker,$.PasswordResponses,$.PermissionFlag,$.PixelsPerInch,$.RenderingCancelledException,$.TextLayer,$.UnexpectedResponseException,$.Util,$.VerbosityLevel,$.XfaLayer,$.build,$.createValidAbsoluteUrl,$.fetchData;var aS=$.getDocument;$.getFilenameFromUrl,$.getPdfFilenameFromUrl,$.getXfaPageViewport,$.isDataScheme,$.isPdfFile,$.noContextMenu,$.normalizeUnicode,$.setLayerDimensions,$.shadow,$.version;const hS={fabric:"^6.3.0","pdfjs-dist":"^4.5.136"};function lS(a){return new Promise((t,e)=>{const s=new FileReader;s.onload=()=>t(s.result),s.onerror=e,s.readAsDataURL(a)})}const cS=hS["pdfjs-dist"].replace("^","");oS.workerSrc=`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${cS}/pdf.worker.min.mjs`;async function dS(a){const t="data:application/pdf;base64,",e=await lS(a);if(typeof e=="string")return window.atob(e.slice(t.length))}function uS(a,t){return aS({data:a,password:t}).promise}const gS="data:image/svg+xml,%3csvg%20width='24'%20height='24'%20viewBox='0%200%2040%2040'%20fill='none'%20xmlns='http://www.w3.org/2000/svg'%3e%3ccircle%20cx='20'%20cy='20'%20r='10.75'%20stroke='currentColor'%20stroke-width='2.5'/%3e%3cpath%20d='M16%2024L23.7782%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3cpath%20d='M24%2024L16.2218%2016.2218'%20stroke='currentColor'%20stroke-width='2.5'%20stroke-linecap='round'/%3e%3c/svg%3e";function fS(a){return new URL(Object.assign({"../assets/close.svg":gS})[`../assets/${a}`],typeof document>"u"&&typeof location>"u"?require("url").pathToFileURL(__filename).href:typeof document>"u"?location.href:Et&&Et.src||new URL("pdf-canvas.umd.js",document.baseURI).href).href}function pS(a){return new Promise((t,e)=>{const s=window.URL.createObjectURL(a),i=new Image;i.src=s,i.onload=async()=>{window.URL.revokeObjectURL(s),t(await mS(i))},i.onerror=n=>{window.URL.revokeObjectURL(s),e(n)}})}function mS(a){return new Promise(t=>{const e=document.createElement("canvas"),s=e.getContext("2d"),{naturalWidth:i,naturalHeight:n}=a;e.width=i,e.height=n,s==null||s.drawImage(a,0,0,i,n),t(e.toDataURL("image/jpeg",.8))})}let ev=null;function vS(){const a=document.createElement("div");a.style.width="1in",document.body.appendChild(a);const t=a.offsetWidth;return document.body.removeChild(a),t}function bS(){const a=ev??vS();return ev=a,a/72}function yS(a,t=500){if(typeof a!="function")throw new TypeError("The first argument is not a function.");let e=null;return function(...s){e&&clearTimeout(e),e=setTimeout(()=>{e=null,a.apply(this,s)},t)}}const _S={top:100,left:50,scaleX:.5,scaleY:.5,borderColor:"black",cornerStrokeColor:"black",cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},wS={top:100,left:50,fontFamily:"helvetica",borderColor:"black",cornerStrokeColor:"black",scaleX:.7,scaleY:.7,cornerSize:8,selectionBackgroundColor:"rgba(245, 245, 245, 0.8)"},xS={stroke:"#000",hoverStroke:"#B7EC5D",src:""},ss=new Map;function sv(a=""){let t=0,e=null,s=null,i=1,n={...xS};function r(){if(!a||ss.has(a))return;const D=new ig(a);return ss.set(a,D),D.on("selection:cleared",()=>P(D)),D}function o(D,L){const F=D.type;return{"application/pdf":h,"image/png":g,"image/jpeg":g}[F](D,L)??Promise.reject(new Error(`Unsupported ${F} file type.`))}async function h(D,L){const F=await dS(D);if(!F)return;const I=Date.now(),Y={PDFId:`${D.name}-${I}`,name:D.name.replace(/.pdf/,""),updateDate:I,PDFBase64:F};try{return await l({page:1,PDFBase64:F,scale:.8,password:L}),{...Y,pages:t}}catch(J){return Promise.reject(J)}}async function l({page:D,PDFBase64:L,scale:F,password:I}){try{const X=await uS(L,I),Y=await U.toRaw(X).getPage(D),J=Y.getViewport({scale:F}),W=document.createElement("canvas"),V=W.getContext("2d"),It=bS()/window.devicePixelRatio;W.width=Math.floor(J.width*It),W.height=Math.floor(J.height*It),t=X.numPages;const Ie={canvasContext:V,viewport:J,transform:[It,0,0,It,0,0]};return Y.render(Ie).promise.then(()=>d(W))}catch(X){return Promise.reject(X)}}function d(D){if(!ss.get(a))return;const F=1/3,I=u(D,F);p(I,F)}function u(D,L){return new ae(D,{scaleX:L,scaleY:L})}async function g(D){const L=await pS(D),F=Date.now(),X={PDFId:`${D.name}${F}`,name:D.name.replace(/.png|.jpg|.jpeg/,""),updateDate:F,PDFBase64:L};return f({url:L}),{...X,pages:1}}async function f({url:D,scale:L=.5}){if(!ss.get(a))return;const I=await ae.fromURL(D);I.scale(L),p(I,L)}function p(D,L){const F=ss.get(a);F&&(F.setWidth(D.width*L),F.setHeight(D.height*L),F.backgroundImage=D,F.renderAll())}async function m(D,L){const F=ss.get(a);if(!F)return;const I=await ae.fromURL(D,{},{..._S,...L});F.add(I),v(F,I)}function _(D,L){const F=ss.get(a);if(!F)return;const I=new oe(D,{...wS,...L});F.add(I),v(F,I)}function v(D,L){L.on("selected",F=>x({canvas:D,target:F.target})),L.on("modified",F=>T(F.target)),L.on("scaling",F=>T(F.transform.target)),L.on("moving",F=>T(F.transform.target)),L.on("rotating",F=>T(F.transform.target))}async function x({canvas:D,target:L,stroke:F=n.stroke,uuid:I=Date.now()}){if((e==null?void 0:e.stroke)===`${F}-${I}`)return;const X=n.src||fS("close.svg"),{objects:Y,options:J}=await Z_(X),W=Y.filter(It=>It!==null),V=g_.groupSVGElements(W,J);W.forEach(It=>{It.stroke=F}),V.hoverCursor="pointer",V.stroke=`${F}-${I}`,P(D),e=V,s=L,S(D,L,I),E(i,!0),D.add(V)}function S(D,L,F){e&&(e.on("selected",()=>{D.remove(L),P(D)}),e.on("mouseover",()=>{x({canvas:D,target:L,stroke:n.hoverStroke,uuid:F})}),e.on("mouseout",()=>{x({canvas:D,target:L,stroke:n.stroke,uuid:F})}))}function T(D){if(!e)return;const{oCoords:L}=D;if(!L)return;const{x:F,y:I}=L.tl.touchCorner.tl,{height:X,width:Y,scaleY:J,scaleX:W}=e;e.top=I-X*J/2,e.left=F-Y*W/2,e.setCoords()}function E(D,L=!1){var F;i=D,!(!e||!s)&&(e.scale(1/D),T(s),!L&&((F=ss.get(a))==null||F.renderAll()))}function M(D){if(!D)return;n={...n,...D};const L=ss.get(a);!e||!s||!L||x({target:s,canvas:L})}function P(D){e&&(D.remove(e),e=s=null)}function O(){const D=ss.get(a);D&&(D.discardActiveObject(),D.renderAll())}function R(){const D=ss.get(a);D&&(D.clear(),ss.delete(a))}return{createCanvas:r,loadFile:o,specifyPage:l,renderImage:f,addFabric:m,addTextFabric:_,clearActive:O,deleteCanvas:R,scaleCloseFabric:E,setCloseSvgOptions:M}}function SS(a){let t=0;const e=yS(()=>{t!==window.innerWidth&&(t=window.innerWidth,a())});U.onMounted(()=>{window.addEventListener("resize",e)}),U.onBeforeUnmount(()=>{window.removeEventListener("resize",e)})}const Qg=U.defineComponent({__name:"PdfCanvas",props:{file:{},page:{default:1},canvasId:{default:"PDF-canvas"},fileZoom:{default:1},fileScale:{default:1},canvasScale:{default:1},canvasClass:{default:""},isDrop:{type:Boolean,default:!1},password:{},dropTextOptions:{},dropImageOptions:{},closeSvgOptions:{}},setup(a,{expose:t}){const e=a,s=U.ref(null),i=`${e.canvasId}-${e.page-1}`,n=U.computed(()=>e.fileZoom*e.canvasScale),{createCanvas:r,specifyPage:o,addFabric:h,addTextFabric:l,renderImage:d,clearActive:u,deleteCanvas:g,scaleCloseFabric:f,setCloseSvgOptions:p}=sv(i);m(),SS(m);async function m(){const{file:S,page:T,fileScale:E}=e;window.requestAnimationFrame(async()=>{if(await U.nextTick(),r(),S.PDFBase64.startsWith("data:image")||S.canvas){const{canvas:M}=S,P=M?7:3,O=M!=null&&M.length?M[T-1]:S.PDFBase64;d({url:O,scale:E/P});return}await o({page:T,PDFBase64:S.PDFBase64,scale:E,password:e.password})})}function _(S){if(!e.isDrop||!S.dataTransfer)return;const{dataTransfer:T,offsetX:E,offsetY:M}=S,P=T.getData("text"),O=T.getData("image"),R={left:E-71,top:M-55};O&&v(O,R),P&&x(P,R)}function v(S,T){h(S,{...T,...e.dropImageOptions})}function x(S,T){l(S,{...T,...e.dropTextOptions})}return U.watch([()=>e.fileScale,()=>e.page,()=>e.file,()=>e.password],m),U.watch(n,S=>f(S),{immediate:!0}),U.watch(()=>e.closeSvgOptions,p,{immediate:!0}),U.onBeforeUnmount(g),t({addImage:v,addText:x,clearActive:u,deleteCanvas:g,canvasRef:s}),(S,T)=>(U.openBlock(),U.createElementBlock("div",{style:U.normalizeStyle({transform:`scale(${n.value})`}),onDragover:T[0]||(T[0]=U.withModifiers(()=>{},["stop","prevent"])),onDragenter:T[1]||(T[1]=U.withModifiers(()=>{},["stop","prevent"])),onDrop:U.withModifiers(_,["stop","prevent"])},[U.createElementVNode("canvas",{id:i,ref_key:"canvasRef",ref:s,class:U.normalizeClass(S.canvasClass)},null,2)],36))}});Qg.install=function(a){a.component("PdfCanvas",Qg)};const Ad=Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"}));st.default=Qg,st.useFabric=sv,Object.defineProperties(st,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|